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; |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 21 | import android.annotation.UnsupportedAppUsage; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 22 | import android.app.ActivityManager; |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 23 | import android.bluetooth.BluetoothActivityEnergyInfo; |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 24 | import android.bluetooth.UidTraffic; |
Mike Ma | fbc01fc | 2018-04-02 10:28:28 -0700 | [diff] [blame] | 25 | import android.content.BroadcastReceiver; |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 26 | import android.content.ContentResolver; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 27 | import android.content.Context; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 28 | import android.content.Intent; |
Mike Ma | fbc01fc | 2018-04-02 10:28:28 -0700 | [diff] [blame] | 29 | import android.content.IntentFilter; |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 30 | import android.database.ContentObserver; |
Mike Ma | fbc01fc | 2018-04-02 10:28:28 -0700 | [diff] [blame] | 31 | import android.hardware.usb.UsbManager; |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 32 | import android.net.ConnectivityManager; |
| 33 | import android.net.NetworkStats; |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 34 | import android.net.Uri; |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 35 | import android.net.wifi.WifiActivityEnergyInfo; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 36 | import android.net.wifi.WifiManager; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 37 | import android.os.BatteryManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | import android.os.BatteryStats; |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 39 | import android.os.Build; |
Dianne Hackborn | 8bdf593 | 2010-10-15 12:54:40 -0700 | [diff] [blame] | 40 | import android.os.FileUtils; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 41 | import android.os.Handler; |
Adam Lesinski | e1f480d | 2017-02-15 18:51:23 -0800 | [diff] [blame] | 42 | import android.os.IBatteryPropertiesRegistrar; |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 43 | import android.os.Looper; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 44 | import android.os.Message; |
Bookatz | 1a1b046 | 2018-01-12 11:47:03 -0800 | [diff] [blame] | 45 | import android.os.OsProtoEnums; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 46 | import android.os.Parcel; |
| 47 | import android.os.ParcelFormatException; |
| 48 | import android.os.Parcelable; |
Bookatz | 1a1b046 | 2018-01-12 11:47:03 -0800 | [diff] [blame] | 49 | import android.os.PowerManager; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 50 | import android.os.Process; |
Adam Lesinski | e1f480d | 2017-02-15 18:51:23 -0800 | [diff] [blame] | 51 | import android.os.RemoteException; |
| 52 | import android.os.ServiceManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 53 | import android.os.SystemClock; |
Suprabh Shukla | e6e723d | 2017-06-14 16:14:43 -0700 | [diff] [blame] | 54 | import android.os.UserHandle; |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 55 | import android.os.WorkSource; |
Narayan Kamath | 8182202 | 2017-12-08 11:56:01 +0000 | [diff] [blame] | 56 | import android.os.WorkSource.WorkChain; |
Mike Ma | 234d182 | 2018-03-13 18:53:21 -0700 | [diff] [blame] | 57 | import android.os.connectivity.CellularBatteryStats; |
| 58 | import android.os.connectivity.GpsBatteryStats; |
| 59 | import android.os.connectivity.WifiBatteryStats; |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 60 | import android.provider.Settings; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 61 | import android.telephony.DataConnectionRealTimeInfo; |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 62 | import android.telephony.ModemActivityInfo; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 63 | import android.telephony.ServiceState; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 64 | import android.telephony.SignalStrength; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 65 | import android.telephony.TelephonyManager; |
Jeff Sharkey | 9da2f1e | 2014-08-14 12:55:00 -0700 | [diff] [blame] | 66 | import android.text.TextUtils; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 67 | import android.util.ArrayMap; |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 68 | import android.util.IntArray; |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 69 | import android.util.KeyValueListParser; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 70 | import android.util.Log; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 71 | import android.util.LogWriter; |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 72 | import android.util.LongSparseArray; |
| 73 | import android.util.LongSparseLongArray; |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 74 | import android.util.MutableInt; |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 75 | import android.util.Pools; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 76 | import android.util.PrintWriterPrinter; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 77 | import android.util.Printer; |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 78 | import android.util.Slog; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 79 | import android.util.SparseArray; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 80 | import android.util.SparseIntArray; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 81 | import android.util.SparseLongArray; |
Bookatz | c1a050a | 2017-10-10 15:49:28 -0700 | [diff] [blame] | 82 | import android.util.StatsLog; |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 83 | import android.util.TimeUtils; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 84 | import android.util.Xml; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 85 | import android.view.Display; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 86 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 87 | import com.android.internal.annotations.GuardedBy; |
Adam Lesinski | 98f0d46 | 2016-04-19 16:46:20 -0700 | [diff] [blame] | 88 | import com.android.internal.annotations.VisibleForTesting; |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 89 | import com.android.internal.location.gnssmetrics.GnssMetrics; |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 90 | import com.android.internal.net.NetworkStatsFactory; |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 91 | import com.android.internal.util.ArrayUtils; |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 92 | import com.android.internal.util.FastPrintWriter; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 93 | import com.android.internal.util.FastXmlSerializer; |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 94 | import com.android.internal.util.JournaledFile; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 95 | import com.android.internal.util.XmlUtils; |
Suprabh Shukla | e6e723d | 2017-06-14 16:14:43 -0700 | [diff] [blame] | 96 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 97 | import libcore.util.EmptyArray; |
Mike Ma | 234d182 | 2018-03-13 18:53:21 -0700 | [diff] [blame] | 98 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 99 | import org.xmlpull.v1.XmlPullParser; |
| 100 | import org.xmlpull.v1.XmlPullParserException; |
| 101 | import org.xmlpull.v1.XmlSerializer; |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 102 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 103 | import java.io.ByteArrayOutputStream; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 104 | import java.io.File; |
| 105 | import java.io.FileInputStream; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 106 | import java.io.FileNotFoundException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 107 | import java.io.FileOutputStream; |
| 108 | import java.io.IOException; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 109 | import java.io.PrintWriter; |
Wojciech Staszkiewicz | 9e9e2e7 | 2015-05-08 14:58:46 +0100 | [diff] [blame] | 110 | import java.nio.charset.StandardCharsets; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 111 | import java.util.ArrayList; |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 112 | import java.util.Arrays; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 113 | import java.util.Calendar; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 114 | import java.util.HashMap; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 115 | import java.util.Iterator; |
Mike Ma | 234d182 | 2018-03-13 18:53:21 -0700 | [diff] [blame] | 116 | import java.util.LinkedList; |
| 117 | import java.util.List; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 118 | import java.util.Map; |
Mike Ma | 234d182 | 2018-03-13 18:53:21 -0700 | [diff] [blame] | 119 | import java.util.Queue; |
Adam Lesinski | b3a1bad | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 120 | import java.util.concurrent.Future; |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 121 | import java.util.concurrent.atomic.AtomicInteger; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 122 | import java.util.concurrent.locks.ReentrantLock; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 123 | |
| 124 | /** |
| 125 | * All information we are collecting about things that can happen that impact |
| 126 | * battery life. All times are represented in microseconds except where indicated |
| 127 | * otherwise. |
| 128 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 129 | public class BatteryStatsImpl extends BatteryStats { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 130 | private static final String TAG = "BatteryStatsImpl"; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 131 | private static final boolean DEBUG = false; |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 132 | public static final boolean DEBUG_ENERGY = false; |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 133 | private static final boolean DEBUG_ENERGY_CPU = DEBUG_ENERGY; |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 134 | private static final boolean DEBUG_MEMORY = false; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 135 | private static final boolean DEBUG_HISTORY = false; |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 136 | private static final boolean USE_OLD_HISTORY = false; // for debugging. |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 137 | |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 138 | // TODO: remove "tcp" from network methods, since we measure total stats. |
| 139 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 140 | // 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] | 141 | private static final int MAGIC = 0xBA757475; // 'BATSTATS' |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 142 | |
| 143 | // Current on-disk Parcel version |
Mike Ma | 561a8d9 | 2018-03-20 18:24:05 -0700 | [diff] [blame] | 144 | private static final int VERSION = 177 + (USE_OLD_HISTORY ? 1000 : 0); |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 145 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 146 | // Maximum number of items we will record in the history. |
Narayan Kamath | b59b7c3 | 2017-06-12 14:11:03 +0100 | [diff] [blame] | 147 | private static final int MAX_HISTORY_ITEMS; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 148 | |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 149 | // 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] | 150 | private static final int MAX_MAX_HISTORY_ITEMS; |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 151 | |
Dianne Hackborn | 9e0f5d9 | 2010-02-22 15:05:42 -0800 | [diff] [blame] | 152 | // The maximum number of names wakelocks we will keep track of |
| 153 | // per uid; once the limit is reached, we batch the remaining wakelocks |
| 154 | // in to one common name. |
Narayan Kamath | b59b7c3 | 2017-06-12 14:11:03 +0100 | [diff] [blame] | 155 | private static final int MAX_WAKELOCKS_PER_UID; |
| 156 | |
| 157 | static final int MAX_HISTORY_BUFFER; // 256KB |
| 158 | static final int MAX_MAX_HISTORY_BUFFER; // 320KB |
| 159 | |
| 160 | static { |
| 161 | if (ActivityManager.isLowRamDeviceStatic()) { |
| 162 | MAX_HISTORY_ITEMS = 800; |
| 163 | MAX_MAX_HISTORY_ITEMS = 1200; |
| 164 | MAX_WAKELOCKS_PER_UID = 40; |
| 165 | MAX_HISTORY_BUFFER = 96*1024; // 96KB |
| 166 | MAX_MAX_HISTORY_BUFFER = 128*1024; // 128KB |
| 167 | } else { |
Makoto Onuki | 44d6460 | 2018-01-18 08:44:28 -0800 | [diff] [blame] | 168 | MAX_HISTORY_ITEMS = 4000; |
| 169 | MAX_MAX_HISTORY_ITEMS = 6000; |
| 170 | MAX_WAKELOCKS_PER_UID = 200; |
| 171 | MAX_HISTORY_BUFFER = 512*1024; // 512KB |
| 172 | MAX_MAX_HISTORY_BUFFER = 640*1024; // 640KB |
Narayan Kamath | b59b7c3 | 2017-06-12 14:11:03 +0100 | [diff] [blame] | 173 | } |
| 174 | } |
Dianne Hackborn | c24ab86 | 2011-10-18 15:55:03 -0700 | [diff] [blame] | 175 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 176 | // Number of transmit power states the Wifi controller can be in. |
| 177 | private static final int NUM_WIFI_TX_LEVELS = 1; |
| 178 | |
| 179 | // Number of transmit power states the Bluetooth controller can be in. |
| 180 | private static final int NUM_BT_TX_LEVELS = 1; |
| 181 | |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 182 | /** |
| 183 | * Holding a wakelock costs more than just using the cpu. |
| 184 | * Currently, we assign only half the cpu time to an app that is running but |
| 185 | * not holding a wakelock. The apps holding wakelocks get the rest of the blame. |
| 186 | * If no app is holding a wakelock, then the distribution is normal. |
| 187 | */ |
| 188 | @VisibleForTesting |
| 189 | public static final int WAKE_LOCK_WEIGHT = 50; |
| 190 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 191 | protected Clocks mClocks; |
| 192 | |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 193 | private final JournaledFile mFile; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 194 | public final AtomicFile mCheckinFile; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 195 | public final AtomicFile mDailyFile; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 196 | |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 197 | static final int MSG_REPORT_CPU_UPDATE_NEEDED = 1; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 198 | static final int MSG_REPORT_POWER_CHANGE = 2; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 199 | static final int MSG_REPORT_CHARGING = 3; |
Fyodor Kupolov | 8aa5124 | 2018-04-23 12:44:51 -0700 | [diff] [blame] | 200 | static final int MSG_REPORT_RESET_STATS = 4; |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 201 | static final long DELAY_UPDATE_WAKELOCKS = 5*1000; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 202 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 203 | private final KernelWakelockReader mKernelWakelockReader = new KernelWakelockReader(); |
| 204 | private final KernelWakelockStats mTmpWakelockStats = new KernelWakelockStats(); |
| 205 | |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 206 | @VisibleForTesting |
| 207 | protected KernelUidCpuTimeReader mKernelUidCpuTimeReader = new KernelUidCpuTimeReader(); |
| 208 | @VisibleForTesting |
| 209 | protected KernelCpuSpeedReader[] mKernelCpuSpeedReaders; |
| 210 | @VisibleForTesting |
| 211 | protected KernelUidCpuFreqTimeReader mKernelUidCpuFreqTimeReader = |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 212 | new KernelUidCpuFreqTimeReader(); |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 213 | @VisibleForTesting |
Mike Ma | 3d422c3 | 2017-10-25 11:08:57 -0700 | [diff] [blame] | 214 | protected KernelUidCpuActiveTimeReader mKernelUidCpuActiveTimeReader = |
| 215 | new KernelUidCpuActiveTimeReader(); |
| 216 | @VisibleForTesting |
| 217 | protected KernelUidCpuClusterTimeReader mKernelUidCpuClusterTimeReader = |
| 218 | new KernelUidCpuClusterTimeReader(); |
| 219 | @VisibleForTesting |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 220 | protected KernelSingleUidTimeReader mKernelSingleUidTimeReader; |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 221 | |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 222 | private final KernelMemoryBandwidthStats mKernelMemoryBandwidthStats |
| 223 | = new KernelMemoryBandwidthStats(); |
| 224 | private final LongSparseArray<SamplingTimer> mKernelMemoryStats = new LongSparseArray<>(); |
| 225 | public LongSparseArray<SamplingTimer> getKernelMemoryStats() { |
| 226 | return mKernelMemoryStats; |
| 227 | } |
| 228 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 229 | @GuardedBy("this") |
| 230 | public boolean mPerProcStateCpuTimesAvailable = true; |
| 231 | |
| 232 | /** |
| 233 | * Uids for which per-procstate cpu times need to be updated. |
| 234 | * |
| 235 | * Contains uid -> procState mappings. |
| 236 | */ |
| 237 | @GuardedBy("this") |
| 238 | @VisibleForTesting |
| 239 | protected final SparseIntArray mPendingUids = new SparseIntArray(); |
| 240 | |
Sudheer Shanka | c20379e | 2018-02-15 00:06:21 -0800 | [diff] [blame] | 241 | @GuardedBy("this") |
Mike Ma | 234d182 | 2018-03-13 18:53:21 -0700 | [diff] [blame] | 242 | private long mNumSingleUidCpuTimeReads; |
Sudheer Shanka | c20379e | 2018-02-15 00:06:21 -0800 | [diff] [blame] | 243 | @GuardedBy("this") |
Mike Ma | 234d182 | 2018-03-13 18:53:21 -0700 | [diff] [blame] | 244 | private long mNumBatchedSingleUidCpuTimeReads; |
Sudheer Shanka | c20379e | 2018-02-15 00:06:21 -0800 | [diff] [blame] | 245 | @GuardedBy("this") |
| 246 | private long mCpuTimeReadsTrackingStartTime = SystemClock.uptimeMillis(); |
Mike Ma | 234d182 | 2018-03-13 18:53:21 -0700 | [diff] [blame] | 247 | @GuardedBy("this") |
| 248 | private int mNumUidsRemoved; |
| 249 | @GuardedBy("this") |
| 250 | private int mNumAllUidCpuTimeReads; |
Sudheer Shanka | c20379e | 2018-02-15 00:06:21 -0800 | [diff] [blame] | 251 | |
Bookatz | 0b8a050 | 2017-09-13 11:51:52 -0700 | [diff] [blame] | 252 | /** Container for Resource Power Manager stats. Updated by updateRpmStatsLocked. */ |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 253 | private final RpmStats mTmpRpmStats = new RpmStats(); |
Bookatz | 0b8a050 | 2017-09-13 11:51:52 -0700 | [diff] [blame] | 254 | /** The soonest the RPM stats can be updated after it was last updated. */ |
| 255 | private static final long RPM_STATS_UPDATE_FREQ_MS = 1000; |
| 256 | /** Last time that RPM stats were updated by updateRpmStatsLocked. */ |
| 257 | private long mLastRpmStatsUpdateTimeMs = -RPM_STATS_UPDATE_FREQ_MS; |
Mike Ma | 234d182 | 2018-03-13 18:53:21 -0700 | [diff] [blame] | 258 | /** |
| 259 | * Use a queue to delay removing UIDs from {@link KernelUidCpuTimeReader}, |
| 260 | * {@link KernelUidCpuActiveTimeReader}, {@link KernelUidCpuClusterTimeReader}, |
| 261 | * {@link KernelUidCpuFreqTimeReader} and from the Kernel. |
| 262 | * |
| 263 | * Isolated and invalid UID info must be removed to conserve memory. However, STATSD and |
| 264 | * Batterystats both need to access UID cpu time. To resolve this race condition, only |
| 265 | * Batterystats shall remove UIDs, and a delay {@link Constants#UID_REMOVE_DELAY_MS} is |
| 266 | * implemented so that STATSD can capture those UID times before they are deleted. |
| 267 | */ |
| 268 | @GuardedBy("this") |
| 269 | @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 270 | protected Queue<UidToRemove> mPendingRemovedUids = new LinkedList<>(); |
| 271 | |
| 272 | @VisibleForTesting |
| 273 | public final class UidToRemove { |
| 274 | int startUid; |
| 275 | int endUid; |
| 276 | long timeAddedInQueue; |
| 277 | |
| 278 | /** Remove just one UID */ |
| 279 | public UidToRemove(int uid, long timestamp) { |
| 280 | this(uid, uid, timestamp); |
| 281 | } |
| 282 | |
| 283 | /** Remove a range of UIDs, startUid must be smaller than endUid. */ |
| 284 | public UidToRemove(int startUid, int endUid, long timestamp) { |
| 285 | this.startUid = startUid; |
| 286 | this.endUid = endUid; |
| 287 | timeAddedInQueue = timestamp; |
| 288 | } |
| 289 | |
| 290 | void remove() { |
| 291 | if (startUid == endUid) { |
| 292 | mKernelUidCpuTimeReader.removeUid(startUid); |
| 293 | mKernelUidCpuFreqTimeReader.removeUid(startUid); |
| 294 | if (mConstants.TRACK_CPU_ACTIVE_CLUSTER_TIME) { |
| 295 | mKernelUidCpuActiveTimeReader.removeUid(startUid); |
| 296 | mKernelUidCpuClusterTimeReader.removeUid(startUid); |
| 297 | } |
| 298 | if (mKernelSingleUidTimeReader != null) { |
| 299 | mKernelSingleUidTimeReader.removeUid(startUid); |
| 300 | } |
| 301 | mNumUidsRemoved++; |
| 302 | } else if (startUid < endUid) { |
| 303 | mKernelUidCpuFreqTimeReader.removeUidsInRange(startUid, endUid); |
| 304 | mKernelUidCpuTimeReader.removeUidsInRange(startUid, endUid); |
| 305 | if (mConstants.TRACK_CPU_ACTIVE_CLUSTER_TIME) { |
| 306 | mKernelUidCpuActiveTimeReader.removeUidsInRange(startUid, endUid); |
| 307 | mKernelUidCpuClusterTimeReader.removeUidsInRange(startUid, endUid); |
| 308 | } |
| 309 | if (mKernelSingleUidTimeReader != null) { |
| 310 | mKernelSingleUidTimeReader.removeUidsInRange(startUid, endUid); |
| 311 | } |
| 312 | // Treat as one. We don't know how many uids there are in between. |
| 313 | mNumUidsRemoved++; |
| 314 | } else { |
| 315 | Slog.w(TAG, "End UID " + endUid + " is smaller than start UID " + startUid); |
| 316 | } |
| 317 | } |
| 318 | } |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 319 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 320 | public interface BatteryCallback { |
| 321 | public void batteryNeedsCpuUpdate(); |
| 322 | public void batteryPowerChanged(boolean onBattery); |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 323 | public void batterySendBroadcast(Intent intent); |
Fyodor Kupolov | 8aa5124 | 2018-04-23 12:44:51 -0700 | [diff] [blame] | 324 | public void batteryStatsReset(); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 325 | } |
| 326 | |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 327 | public interface PlatformIdleStateCallback { |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 328 | public void fillLowPowerStats(RpmStats rpmStats); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 329 | public String getPlatformLowPowerStats(); |
Ahmed ElArabawy | d8b4411 | 2017-05-23 21:25:02 +0000 | [diff] [blame] | 330 | public String getSubsystemLowPowerStats(); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 331 | } |
| 332 | |
Suprabh Shukla | e6e723d | 2017-06-14 16:14:43 -0700 | [diff] [blame] | 333 | public static abstract class UserInfoProvider { |
| 334 | private int[] userIds; |
| 335 | protected abstract @Nullable int[] getUserIds(); |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 336 | @VisibleForTesting |
| 337 | public final void refreshUserIds() { |
Suprabh Shukla | e6e723d | 2017-06-14 16:14:43 -0700 | [diff] [blame] | 338 | userIds = getUserIds(); |
| 339 | } |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 340 | @VisibleForTesting |
| 341 | public boolean exists(int userId) { |
Suprabh Shukla | e6e723d | 2017-06-14 16:14:43 -0700 | [diff] [blame] | 342 | return userIds != null ? ArrayUtils.contains(userIds, userId) : true; |
| 343 | } |
| 344 | } |
| 345 | |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 346 | private final PlatformIdleStateCallback mPlatformIdleStateCallback; |
| 347 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 348 | final class MyHandler extends Handler { |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 349 | public MyHandler(Looper looper) { |
| 350 | super(looper, null, true); |
| 351 | } |
| 352 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 353 | @Override |
| 354 | public void handleMessage(Message msg) { |
| 355 | BatteryCallback cb = mCallback; |
| 356 | switch (msg.what) { |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 357 | case MSG_REPORT_CPU_UPDATE_NEEDED: |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 358 | if (cb != null) { |
| 359 | cb.batteryNeedsCpuUpdate(); |
| 360 | } |
| 361 | break; |
| 362 | case MSG_REPORT_POWER_CHANGE: |
| 363 | if (cb != null) { |
| 364 | cb.batteryPowerChanged(msg.arg1 != 0); |
| 365 | } |
| 366 | break; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 367 | case MSG_REPORT_CHARGING: |
| 368 | if (cb != null) { |
| 369 | final String action; |
| 370 | synchronized (BatteryStatsImpl.this) { |
| 371 | action = mCharging ? BatteryManager.ACTION_CHARGING |
| 372 | : BatteryManager.ACTION_DISCHARGING; |
| 373 | } |
| 374 | Intent intent = new Intent(action); |
| 375 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); |
| 376 | cb.batterySendBroadcast(intent); |
| 377 | } |
| 378 | break; |
Fyodor Kupolov | 8aa5124 | 2018-04-23 12:44:51 -0700 | [diff] [blame] | 379 | case MSG_REPORT_RESET_STATS: |
| 380 | if (cb != null) { |
| 381 | cb.batteryStatsReset(); |
| 382 | } |
| 383 | } |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 384 | } |
| 385 | } |
| 386 | |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 387 | public void postBatteryNeedsCpuUpdateMsg() { |
| 388 | mHandler.sendEmptyMessage(MSG_REPORT_CPU_UPDATE_NEEDED); |
| 389 | } |
| 390 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 391 | /** |
| 392 | * Update per-freq cpu times for all the uids in {@link #mPendingUids}. |
| 393 | */ |
Sudheer Shanka | e544d16 | 2017-12-28 17:06:20 -0800 | [diff] [blame] | 394 | public void updateProcStateCpuTimes(boolean onBattery, boolean onBatteryScreenOff) { |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 395 | final SparseIntArray uidStates; |
| 396 | synchronized (BatteryStatsImpl.this) { |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 397 | if (!mConstants.TRACK_CPU_TIMES_BY_PROC_STATE) { |
| 398 | return; |
| 399 | } |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 400 | if(!initKernelSingleUidTimeReaderLocked()) { |
| 401 | return; |
| 402 | } |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 403 | // If the KernelSingleUidTimeReader has stale cpu times, then we shouldn't try to |
| 404 | // compute deltas since it might result in mis-attributing cpu times to wrong states. |
| 405 | if (mKernelSingleUidTimeReader.hasStaleData()) { |
| 406 | mPendingUids.clear(); |
| 407 | return; |
| 408 | } |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 409 | |
| 410 | if (mPendingUids.size() == 0) { |
| 411 | return; |
| 412 | } |
| 413 | uidStates = mPendingUids.clone(); |
| 414 | mPendingUids.clear(); |
| 415 | } |
| 416 | for (int i = uidStates.size() - 1; i >= 0; --i) { |
| 417 | final int uid = uidStates.keyAt(i); |
| 418 | final int procState = uidStates.valueAt(i); |
| 419 | final int[] isolatedUids; |
| 420 | final Uid u; |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 421 | synchronized (BatteryStatsImpl.this) { |
| 422 | // It's possible that uid no longer exists and any internal references have |
| 423 | // already been deleted, so using {@link #getAvailableUidStatsLocked} to avoid |
| 424 | // creating an UidStats object if it doesn't already exist. |
| 425 | u = getAvailableUidStatsLocked(uid); |
| 426 | if (u == null) { |
| 427 | continue; |
| 428 | } |
| 429 | if (u.mChildUids == null) { |
| 430 | isolatedUids = null; |
| 431 | } else { |
| 432 | isolatedUids = u.mChildUids.toArray(); |
| 433 | for (int j = isolatedUids.length - 1; j >= 0; --j) { |
| 434 | isolatedUids[j] = u.mChildUids.get(j); |
| 435 | } |
| 436 | } |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 437 | } |
| 438 | long[] cpuTimesMs = mKernelSingleUidTimeReader.readDeltaMs(uid); |
| 439 | if (isolatedUids != null) { |
| 440 | for (int j = isolatedUids.length - 1; j >= 0; --j) { |
| 441 | cpuTimesMs = addCpuTimes(cpuTimesMs, |
| 442 | mKernelSingleUidTimeReader.readDeltaMs(isolatedUids[j])); |
| 443 | } |
| 444 | } |
| 445 | if (onBattery && cpuTimesMs != null) { |
| 446 | synchronized (BatteryStatsImpl.this) { |
Sudheer Shanka | e544d16 | 2017-12-28 17:06:20 -0800 | [diff] [blame] | 447 | u.addProcStateTimesMs(procState, cpuTimesMs, onBattery); |
| 448 | u.addProcStateScreenOffTimesMs(procState, cpuTimesMs, onBatteryScreenOff); |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 449 | } |
| 450 | } |
| 451 | } |
| 452 | } |
| 453 | |
Mike Ma | 234d182 | 2018-03-13 18:53:21 -0700 | [diff] [blame] | 454 | public void clearPendingRemovedUids() { |
| 455 | long cutOffTime = mClocks.elapsedRealtime() - mConstants.UID_REMOVE_DELAY_MS; |
| 456 | while (!mPendingRemovedUids.isEmpty() |
| 457 | && mPendingRemovedUids.peek().timeAddedInQueue < cutOffTime) { |
| 458 | mPendingRemovedUids.poll().remove(); |
| 459 | } |
| 460 | } |
| 461 | |
Sudheer Shanka | e544d16 | 2017-12-28 17:06:20 -0800 | [diff] [blame] | 462 | public void copyFromAllUidsCpuTimes() { |
| 463 | synchronized (BatteryStatsImpl.this) { |
| 464 | copyFromAllUidsCpuTimes( |
| 465 | mOnBatteryTimeBase.isRunning(), mOnBatteryScreenOffTimeBase.isRunning()); |
| 466 | } |
| 467 | } |
| 468 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 469 | /** |
| 470 | * When the battery/screen state changes, we don't attribute the cpu times to any process |
| 471 | * but we still need to snapshots of all uids to get correct deltas later on. Since we |
| 472 | * already read this data for updating per-freq cpu times, we can use the same data for |
| 473 | * per-procstate cpu times. |
| 474 | */ |
Sudheer Shanka | e544d16 | 2017-12-28 17:06:20 -0800 | [diff] [blame] | 475 | public void copyFromAllUidsCpuTimes(boolean onBattery, boolean onBatteryScreenOff) { |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 476 | synchronized (BatteryStatsImpl.this) { |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 477 | if (!mConstants.TRACK_CPU_TIMES_BY_PROC_STATE) { |
| 478 | return; |
| 479 | } |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 480 | if(!initKernelSingleUidTimeReaderLocked()) { |
| 481 | return; |
| 482 | } |
| 483 | |
| 484 | final SparseArray<long[]> allUidCpuFreqTimesMs = |
| 485 | mKernelUidCpuFreqTimeReader.getAllUidCpuFreqTimeMs(); |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 486 | // If the KernelSingleUidTimeReader has stale cpu times, then we shouldn't try to |
| 487 | // compute deltas since it might result in mis-attributing cpu times to wrong states. |
| 488 | if (mKernelSingleUidTimeReader.hasStaleData()) { |
| 489 | mKernelSingleUidTimeReader.setAllUidsCpuTimesMs(allUidCpuFreqTimesMs); |
| 490 | mKernelSingleUidTimeReader.markDataAsStale(false); |
| 491 | mPendingUids.clear(); |
| 492 | return; |
| 493 | } |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 494 | for (int i = allUidCpuFreqTimesMs.size() - 1; i >= 0; --i) { |
| 495 | final int uid = allUidCpuFreqTimesMs.keyAt(i); |
| 496 | final Uid u = getAvailableUidStatsLocked(mapUid(uid)); |
| 497 | if (u == null) { |
| 498 | continue; |
| 499 | } |
| 500 | final long[] cpuTimesMs = allUidCpuFreqTimesMs.valueAt(i); |
| 501 | if (cpuTimesMs == null) { |
| 502 | continue; |
| 503 | } |
| 504 | final long[] deltaTimesMs = mKernelSingleUidTimeReader.computeDelta( |
| 505 | uid, cpuTimesMs.clone()); |
Sudheer Shanka | e544d16 | 2017-12-28 17:06:20 -0800 | [diff] [blame] | 506 | if (onBattery && deltaTimesMs != null) { |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 507 | final int procState; |
| 508 | final int idx = mPendingUids.indexOfKey(uid); |
| 509 | if (idx >= 0) { |
| 510 | procState = mPendingUids.valueAt(idx); |
| 511 | mPendingUids.removeAt(idx); |
| 512 | } else { |
| 513 | procState = u.mProcessState; |
| 514 | } |
| 515 | if (procState >= 0 && procState < Uid.NUM_PROCESS_STATE) { |
Sudheer Shanka | e544d16 | 2017-12-28 17:06:20 -0800 | [diff] [blame] | 516 | u.addProcStateTimesMs(procState, deltaTimesMs, onBattery); |
| 517 | u.addProcStateScreenOffTimesMs(procState, deltaTimesMs, onBatteryScreenOff); |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 518 | } |
| 519 | } |
| 520 | } |
| 521 | } |
| 522 | } |
| 523 | |
| 524 | @VisibleForTesting |
| 525 | public long[] addCpuTimes(long[] timesA, long[] timesB) { |
| 526 | if (timesA != null && timesB != null) { |
| 527 | for (int i = timesA.length - 1; i >= 0; --i) { |
| 528 | timesA[i] += timesB[i]; |
| 529 | } |
| 530 | return timesA; |
| 531 | } |
| 532 | return timesA == null ? (timesB == null ? null : timesB) : timesA; |
| 533 | } |
| 534 | |
| 535 | @GuardedBy("this") |
| 536 | private boolean initKernelSingleUidTimeReaderLocked() { |
| 537 | if (mKernelSingleUidTimeReader == null) { |
| 538 | if (mPowerProfile == null) { |
| 539 | return false; |
| 540 | } |
| 541 | if (mCpuFreqs == null) { |
| 542 | mCpuFreqs = mKernelUidCpuFreqTimeReader.readFreqs(mPowerProfile); |
| 543 | } |
| 544 | if (mCpuFreqs != null) { |
| 545 | mKernelSingleUidTimeReader = new KernelSingleUidTimeReader(mCpuFreqs.length); |
| 546 | } else { |
| 547 | mPerProcStateCpuTimesAvailable = mKernelUidCpuFreqTimeReader.allUidTimesAvailable(); |
| 548 | return false; |
| 549 | } |
| 550 | } |
| 551 | mPerProcStateCpuTimesAvailable = mKernelUidCpuFreqTimeReader.allUidTimesAvailable() |
| 552 | && mKernelSingleUidTimeReader.singleUidCpuTimesAvailable(); |
| 553 | return true; |
| 554 | } |
| 555 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 556 | public interface Clocks { |
| 557 | public long elapsedRealtime(); |
| 558 | public long uptimeMillis(); |
| 559 | } |
| 560 | |
| 561 | public static class SystemClocks implements Clocks { |
| 562 | public long elapsedRealtime() { |
| 563 | return SystemClock.elapsedRealtime(); |
| 564 | } |
| 565 | |
| 566 | public long uptimeMillis() { |
| 567 | return SystemClock.uptimeMillis(); |
| 568 | } |
| 569 | } |
| 570 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 571 | public interface ExternalStatsSync { |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 572 | int UPDATE_CPU = 0x01; |
| 573 | int UPDATE_WIFI = 0x02; |
| 574 | int UPDATE_RADIO = 0x04; |
| 575 | int UPDATE_BT = 0x08; |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 576 | int UPDATE_RPM = 0x10; // 16 |
| 577 | 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] | 578 | |
Adam Lesinski | b3a1bad | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 579 | Future<?> scheduleSync(String reason, int flags); |
| 580 | Future<?> scheduleCpuSyncDueToRemovedUid(int uid); |
Sudheer Shanka | c20379e | 2018-02-15 00:06:21 -0800 | [diff] [blame] | 581 | Future<?> scheduleReadProcStateCpuTimes(boolean onBattery, boolean onBatteryScreenOff, |
| 582 | long delayMillis); |
Sudheer Shanka | e544d16 | 2017-12-28 17:06:20 -0800 | [diff] [blame] | 583 | Future<?> scheduleCopyFromAllUidsCpuTimes(boolean onBattery, boolean onBatteryScreenOff); |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 584 | Future<?> scheduleCpuSyncDueToSettingChange(); |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 585 | Future<?> scheduleCpuSyncDueToScreenStateChange(boolean onBattery, |
| 586 | boolean onBatteryScreenOff); |
| 587 | Future<?> scheduleCpuSyncDueToWakelockChange(long delayMillis); |
| 588 | void cancelCpuSyncDueToWakelockChange(); |
Sudheer Shanka | 0719c6a | 2018-04-24 11:12:11 -0700 | [diff] [blame] | 589 | Future<?> scheduleSyncDueToBatteryLevelChange(long delayMillis); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 590 | } |
| 591 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 592 | public Handler mHandler; |
Adam Lesinski | b3a1bad | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 593 | private ExternalStatsSync mExternalSync = null; |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 594 | @VisibleForTesting |
| 595 | protected UserInfoProvider mUserInfoProvider = null; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 596 | |
| 597 | private BatteryCallback mCallback; |
| 598 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 599 | /** |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 600 | * Mapping isolated uids to the actual owning app uid. |
| 601 | */ |
| 602 | final SparseIntArray mIsolatedUids = new SparseIntArray(); |
| 603 | |
| 604 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 605 | * The statistics we have collected organized by uids. |
| 606 | */ |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 607 | final SparseArray<BatteryStatsImpl.Uid> mUidStats = new SparseArray<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 608 | |
| 609 | // A set of pools of currently active timers. When a timer is queried, we will divide the |
| 610 | // elapsed time by the number of active timers to arrive at that timer's share of the time. |
| 611 | // In order to do this, we must refresh each timer whenever the number of active timers |
| 612 | // changes. |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 613 | @VisibleForTesting |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 614 | @UnsupportedAppUsage |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 615 | protected ArrayList<StopwatchTimer> mPartialTimers = new ArrayList<>(); |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 616 | @UnsupportedAppUsage |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 617 | final ArrayList<StopwatchTimer> mFullTimers = new ArrayList<>(); |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 618 | @UnsupportedAppUsage |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 619 | final ArrayList<StopwatchTimer> mWindowTimers = new ArrayList<>(); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 620 | final ArrayList<StopwatchTimer> mDrawTimers = new ArrayList<>(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 621 | final SparseArray<ArrayList<StopwatchTimer>> mSensorTimers = new SparseArray<>(); |
| 622 | final ArrayList<StopwatchTimer> mWifiRunningTimers = new ArrayList<>(); |
| 623 | final ArrayList<StopwatchTimer> mFullWifiLockTimers = new ArrayList<>(); |
| 624 | final ArrayList<StopwatchTimer> mWifiMulticastTimers = new ArrayList<>(); |
| 625 | final ArrayList<StopwatchTimer> mWifiScanTimers = new ArrayList<>(); |
| 626 | final SparseArray<ArrayList<StopwatchTimer>> mWifiBatchedScanTimers = new SparseArray<>(); |
| 627 | final ArrayList<StopwatchTimer> mAudioTurnedOnTimers = new ArrayList<>(); |
| 628 | final ArrayList<StopwatchTimer> mVideoTurnedOnTimers = new ArrayList<>(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 629 | final ArrayList<StopwatchTimer> mFlashlightTurnedOnTimers = new ArrayList<>(); |
| 630 | final ArrayList<StopwatchTimer> mCameraTurnedOnTimers = new ArrayList<>(); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 631 | final ArrayList<StopwatchTimer> mBluetoothScanOnTimers = new ArrayList<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 632 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 633 | // Last partial timers we use for distributing CPU usage. |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 634 | @VisibleForTesting |
| 635 | protected ArrayList<StopwatchTimer> mLastPartialTimers = new ArrayList<>(); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 636 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 637 | // These are the objects that will want to do something when the device |
| 638 | // is unplugged from power. |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 639 | protected final TimeBase mOnBatteryTimeBase = new TimeBase(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 640 | |
| 641 | // 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] | 642 | // is unplugged from power *and* the screen is off or doze. |
| 643 | protected final TimeBase mOnBatteryScreenOffTimeBase = new TimeBase(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 644 | |
| 645 | // Set to true when we want to distribute CPU across wakelocks for the next |
| 646 | // CPU update, even if we aren't currently running wake locks. |
| 647 | boolean mDistributeWakelockCpu; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 648 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 649 | boolean mShuttingDown; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 650 | |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 651 | final HistoryEventTracker mActiveEvents = new HistoryEventTracker(); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 652 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 653 | long mHistoryBaseTime; |
Narayan Kamath | 695cf72 | 2017-12-21 18:32:47 +0000 | [diff] [blame] | 654 | protected boolean mHaveBatteryLevel = false; |
| 655 | protected boolean mRecordingHistory = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 656 | int mNumHistoryItems; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 657 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 658 | final Parcel mHistoryBuffer = Parcel.obtain(); |
| 659 | final HistoryItem mHistoryLastWritten = new HistoryItem(); |
| 660 | final HistoryItem mHistoryLastLastWritten = new HistoryItem(); |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 661 | final HistoryItem mHistoryReadTmp = new HistoryItem(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 662 | final HistoryItem mHistoryAddTmp = new HistoryItem(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 663 | final HashMap<HistoryTag, Integer> mHistoryTagPool = new HashMap<>(); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 664 | String[] mReadHistoryStrings; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 665 | int[] mReadHistoryUids; |
| 666 | int mReadHistoryChars; |
| 667 | int mNextHistoryTagIdx = 0; |
| 668 | int mNumHistoryTagChars = 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 669 | int mHistoryBufferLastPos = -1; |
| 670 | boolean mHistoryOverflow = false; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 671 | int mActiveHistoryStates = 0xffffffff; |
| 672 | int mActiveHistoryStates2 = 0xffffffff; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 673 | long mLastHistoryElapsedRealtime = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 674 | long mTrackRunningHistoryElapsedRealtime = 0; |
| 675 | long mTrackRunningHistoryUptime = 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 676 | |
| 677 | final HistoryItem mHistoryCur = new HistoryItem(); |
| 678 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 679 | HistoryItem mHistory; |
| 680 | HistoryItem mHistoryEnd; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 681 | HistoryItem mHistoryLastEnd; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 682 | HistoryItem mHistoryCache; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 683 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 684 | // Used by computeHistoryStepDetails |
| 685 | HistoryStepDetails mLastHistoryStepDetails = null; |
| 686 | byte mLastHistoryStepLevel = 0; |
| 687 | final HistoryStepDetails mCurHistoryStepDetails = new HistoryStepDetails(); |
| 688 | final HistoryStepDetails mReadHistoryStepDetails = new HistoryStepDetails(); |
| 689 | final HistoryStepDetails mTmpHistoryStepDetails = new HistoryStepDetails(); |
Adam Lesinski | 7b83b0c | 2015-06-05 12:59:36 -0700 | [diff] [blame] | 690 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 691 | /** |
Adam Lesinski | 7b83b0c | 2015-06-05 12:59:36 -0700 | [diff] [blame] | 692 | * Total time (in milliseconds) spent executing in user code. |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 693 | */ |
| 694 | long mLastStepCpuUserTime; |
| 695 | long mCurStepCpuUserTime; |
| 696 | /** |
Adam Lesinski | 7b83b0c | 2015-06-05 12:59:36 -0700 | [diff] [blame] | 697 | * Total time (in milliseconds) spent executing in kernel code. |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 698 | */ |
| 699 | long mLastStepCpuSystemTime; |
| 700 | long mCurStepCpuSystemTime; |
| 701 | /** |
Adam Lesinski | 7b83b0c | 2015-06-05 12:59:36 -0700 | [diff] [blame] | 702 | * Times from /proc/stat (but measured in milliseconds). |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 703 | */ |
| 704 | long mLastStepStatUserTime; |
| 705 | long mLastStepStatSystemTime; |
| 706 | long mLastStepStatIOWaitTime; |
| 707 | long mLastStepStatIrqTime; |
| 708 | long mLastStepStatSoftIrqTime; |
| 709 | long mLastStepStatIdleTime; |
| 710 | long mCurStepStatUserTime; |
| 711 | long mCurStepStatSystemTime; |
| 712 | long mCurStepStatIOWaitTime; |
| 713 | long mCurStepStatIrqTime; |
| 714 | long mCurStepStatSoftIrqTime; |
| 715 | long mCurStepStatIdleTime; |
| 716 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 717 | private HistoryItem mHistoryIterator; |
| 718 | private boolean mReadOverflow; |
| 719 | private boolean mIteratingHistory; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 720 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 721 | int mStartCount; |
| 722 | |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 723 | long mStartClockTime; |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 724 | String mStartPlatformVersion; |
| 725 | String mEndPlatformVersion; |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 726 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 727 | long mUptime; |
| 728 | long mUptimeStart; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 729 | long mRealtime; |
| 730 | long mRealtimeStart; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 731 | |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 732 | int mWakeLockNesting; |
| 733 | boolean mWakeLockImportant; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 734 | public boolean mRecordAllHistory; |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 735 | boolean mNoAutoReset; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 736 | |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 737 | @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 738 | protected int mScreenState = Display.STATE_UNKNOWN; |
| 739 | @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 740 | protected StopwatchTimer mScreenOnTimer; |
| 741 | @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 742 | protected StopwatchTimer mScreenDozeTimer; |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 743 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 744 | int mScreenBrightnessBin = -1; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 745 | final StopwatchTimer[] mScreenBrightnessTimer = new StopwatchTimer[NUM_SCREEN_BRIGHTNESS_BINS]; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 746 | |
Amith Yamasani | 674c9bb | 2017-02-01 09:45:17 -0800 | [diff] [blame] | 747 | boolean mPretendScreenOff; |
| 748 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 749 | boolean mInteractive; |
| 750 | StopwatchTimer mInteractiveTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 751 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 752 | boolean mPowerSaveModeEnabled; |
| 753 | StopwatchTimer mPowerSaveModeEnabledTimer; |
| 754 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 755 | boolean mDeviceIdling; |
| 756 | StopwatchTimer mDeviceIdlingTimer; |
| 757 | |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 758 | boolean mDeviceLightIdling; |
| 759 | StopwatchTimer mDeviceLightIdlingTimer; |
| 760 | |
| 761 | int mDeviceIdleMode; |
| 762 | long mLastIdleTimeStart; |
| 763 | long mLongestLightIdleTime; |
| 764 | long mLongestFullIdleTime; |
| 765 | StopwatchTimer mDeviceIdleModeLightTimer; |
| 766 | StopwatchTimer mDeviceIdleModeFullTimer; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 767 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 768 | boolean mPhoneOn; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 769 | StopwatchTimer mPhoneOnTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 770 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 771 | int mAudioOnNesting; |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 772 | StopwatchTimer mAudioOnTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 773 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 774 | int mVideoOnNesting; |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 775 | StopwatchTimer mVideoOnTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 776 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 777 | int mFlashlightOnNesting; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 778 | StopwatchTimer mFlashlightOnTimer; |
| 779 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 780 | int mCameraOnNesting; |
| 781 | StopwatchTimer mCameraOnTimer; |
| 782 | |
Mike Ma | fbc01fc | 2018-04-02 10:28:28 -0700 | [diff] [blame] | 783 | private static final int USB_DATA_UNKNOWN = 0; |
| 784 | private static final int USB_DATA_DISCONNECTED = 1; |
| 785 | private static final int USB_DATA_CONNECTED = 2; |
| 786 | int mUsbDataState = USB_DATA_UNKNOWN; |
Mike Ma | 926a97c | 2018-03-25 02:32:35 -0700 | [diff] [blame] | 787 | |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 788 | int mGpsSignalQualityBin = -1; |
Narayan Kamath | efa0fe6 | 2018-02-05 16:04:43 +0000 | [diff] [blame] | 789 | @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 790 | protected final StopwatchTimer[] mGpsSignalQualityTimer = |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 791 | new StopwatchTimer[GnssMetrics.NUM_GPS_SIGNAL_QUALITY_LEVELS]; |
| 792 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 793 | int mPhoneSignalStrengthBin = -1; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 794 | int mPhoneSignalStrengthBinRaw = -1; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 795 | final StopwatchTimer[] mPhoneSignalStrengthsTimer = |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 796 | new StopwatchTimer[SignalStrength.NUM_SIGNAL_STRENGTH_BINS]; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 797 | |
| 798 | StopwatchTimer mPhoneSignalScanningTimer; |
| 799 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 800 | int mPhoneDataConnectionType = -1; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 801 | final StopwatchTimer[] mPhoneDataConnectionsTimer = |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 802 | new StopwatchTimer[NUM_DATA_CONNECTION_TYPES]; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 803 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 804 | final LongSamplingCounter[] mNetworkByteActivityCounters = |
| 805 | new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
| 806 | final LongSamplingCounter[] mNetworkPacketActivityCounters = |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 807 | new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
| 808 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 809 | /** |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 810 | * The WiFi Overall wakelock timer |
| 811 | * This timer tracks the actual aggregate time for which MC wakelocks are enabled |
| 812 | * since addition of per UID timers would not result in an accurate value due to overlapp of |
| 813 | * per uid wakelock timers |
| 814 | */ |
| 815 | StopwatchTimer mWifiMulticastWakelockTimer; |
| 816 | |
| 817 | /** |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 818 | * The WiFi controller activity (time in tx, rx, idle, and power consumed) for the device. |
| 819 | */ |
| 820 | ControllerActivityCounterImpl mWifiActivity; |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 821 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 822 | /** |
| 823 | * The Bluetooth controller activity (time in tx, rx, idle, and power consumed) for the device. |
| 824 | */ |
| 825 | ControllerActivityCounterImpl mBluetoothActivity; |
| 826 | |
| 827 | /** |
| 828 | * The Modem controller activity (time in tx, rx, idle, and power consumed) for the device. |
| 829 | */ |
| 830 | ControllerActivityCounterImpl mModemActivity; |
| 831 | |
| 832 | /** |
| 833 | * Whether the device supports WiFi controller energy reporting. This is set to true on |
| 834 | * the first WiFi energy report. See {@link #mWifiActivity}. |
| 835 | */ |
| 836 | boolean mHasWifiReporting = false; |
| 837 | |
| 838 | /** |
| 839 | * Whether the device supports Bluetooth controller energy reporting. This is set to true on |
| 840 | * the first Bluetooth energy report. See {@link #mBluetoothActivity}. |
| 841 | */ |
| 842 | boolean mHasBluetoothReporting = false; |
| 843 | |
| 844 | /** |
| 845 | * Whether the device supports Modem controller energy reporting. This is set to true on |
| 846 | * the first Modem energy report. See {@link #mModemActivity}. |
| 847 | */ |
| 848 | boolean mHasModemReporting = false; |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 849 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 850 | boolean mWifiOn; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 851 | StopwatchTimer mWifiOnTimer; |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 852 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 853 | boolean mGlobalWifiRunning; |
| 854 | StopwatchTimer mGlobalWifiRunningTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 855 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 856 | int mWifiState = -1; |
| 857 | final StopwatchTimer[] mWifiStateTimer = new StopwatchTimer[NUM_WIFI_STATES]; |
| 858 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 859 | int mWifiSupplState = -1; |
| 860 | final StopwatchTimer[] mWifiSupplStateTimer = new StopwatchTimer[NUM_WIFI_SUPPL_STATES]; |
| 861 | |
| 862 | int mWifiSignalStrengthBin = -1; |
| 863 | final StopwatchTimer[] mWifiSignalStrengthsTimer = |
| 864 | new StopwatchTimer[NUM_WIFI_SIGNAL_STRENGTH_BINS]; |
| 865 | |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 866 | StopwatchTimer mWifiActiveTimer; |
| 867 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 868 | int mBluetoothScanNesting; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 869 | @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 870 | protected StopwatchTimer mBluetoothScanTimer; |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 871 | |
Siddharth Ray | f5e796a | 2018-01-22 18:18:17 -0800 | [diff] [blame] | 872 | boolean mIsCellularTxPowerHigh = false; |
| 873 | |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 874 | int mMobileRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
Dianne Hackborn | f7097a5 | 2014-05-13 09:56:14 -0700 | [diff] [blame] | 875 | long mMobileRadioActiveStartTime; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 876 | StopwatchTimer mMobileRadioActiveTimer; |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 877 | StopwatchTimer mMobileRadioActivePerAppTimer; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 878 | LongSamplingCounter mMobileRadioActiveAdjustedTime; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 879 | LongSamplingCounter mMobileRadioActiveUnknownTime; |
| 880 | LongSamplingCounter mMobileRadioActiveUnknownCount; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 881 | |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 882 | int mWifiRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
| 883 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 884 | /** |
| 885 | * These provide time bases that discount the time the device is plugged |
| 886 | * in to power. |
| 887 | */ |
| 888 | boolean mOnBattery; |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 889 | @VisibleForTesting |
| 890 | protected boolean mOnBatteryInternal; |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 891 | |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 892 | /** |
| 893 | * External reporting of whether the device is actually charging. |
| 894 | */ |
| 895 | boolean mCharging = true; |
| 896 | int mLastChargingStateLevel; |
| 897 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 898 | /* |
| 899 | * These keep track of battery levels (1-100) at the last plug event and the last unplug event. |
| 900 | */ |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 901 | int mDischargeStartLevel; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 902 | int mDischargeUnplugLevel; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 903 | int mDischargePlugLevel; |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 904 | int mDischargeCurrentLevel; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 905 | int mCurrentBatteryLevel; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 906 | int mLowDischargeAmountSinceCharge; |
| 907 | int mHighDischargeAmountSinceCharge; |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 908 | int mDischargeScreenOnUnplugLevel; |
| 909 | int mDischargeScreenOffUnplugLevel; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 910 | int mDischargeScreenDozeUnplugLevel; |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 911 | int mDischargeAmountScreenOn; |
| 912 | int mDischargeAmountScreenOnSinceCharge; |
| 913 | int mDischargeAmountScreenOff; |
| 914 | int mDischargeAmountScreenOffSinceCharge; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 915 | int mDischargeAmountScreenDoze; |
| 916 | int mDischargeAmountScreenDozeSinceCharge; |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 917 | |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 918 | private LongSamplingCounter mDischargeScreenOffCounter; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 919 | private LongSamplingCounter mDischargeScreenDozeCounter; |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 920 | private LongSamplingCounter mDischargeCounter; |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 921 | private LongSamplingCounter mDischargeLightDozeCounter; |
| 922 | private LongSamplingCounter mDischargeDeepDozeCounter; |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 923 | |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 924 | static final int MAX_LEVEL_STEPS = 200; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 925 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 926 | int mInitStepMode = 0; |
| 927 | int mCurStepMode = 0; |
| 928 | int mModStepMode = 0; |
| 929 | |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 930 | int mLastDischargeStepLevel; |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 931 | int mMinDischargeStepLevel; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 932 | final LevelStepTracker mDischargeStepTracker = new LevelStepTracker(MAX_LEVEL_STEPS); |
| 933 | final LevelStepTracker mDailyDischargeStepTracker = new LevelStepTracker(MAX_LEVEL_STEPS*2); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 934 | ArrayList<PackageChange> mDailyPackageChanges; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 935 | |
| 936 | int mLastChargeStepLevel; |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 937 | int mMaxChargeStepLevel; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 938 | final LevelStepTracker mChargeStepTracker = new LevelStepTracker(MAX_LEVEL_STEPS); |
| 939 | final LevelStepTracker mDailyChargeStepTracker = new LevelStepTracker(MAX_LEVEL_STEPS*2); |
| 940 | |
| 941 | static final int MAX_DAILY_ITEMS = 10; |
| 942 | |
| 943 | long mDailyStartTime = 0; |
| 944 | long mNextMinDailyDeadline = 0; |
| 945 | long mNextMaxDailyDeadline = 0; |
| 946 | |
| 947 | final ArrayList<DailyItem> mDailyItems = new ArrayList<>(); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 948 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 949 | long mLastWriteTime = 0; // Milliseconds |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 950 | |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 951 | private int mPhoneServiceState = -1; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 952 | private int mPhoneServiceStateRaw = -1; |
| 953 | private int mPhoneSimStateRaw = -1; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 954 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 955 | private int mNumConnectivityChange; |
| 956 | private int mLoadedNumConnectivityChange; |
| 957 | private int mUnpluggedNumConnectivityChange; |
| 958 | |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 959 | private int mEstimatedBatteryCapacity = -1; |
| 960 | |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 961 | private int mMinLearnedBatteryCapacity = -1; |
| 962 | private int mMaxLearnedBatteryCapacity = -1; |
Adam Lesinski | 041d917 | 2016-12-12 12:03:56 -0800 | [diff] [blame] | 963 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 964 | private long[] mCpuFreqs; |
| 965 | |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 966 | @VisibleForTesting |
| 967 | protected PowerProfile mPowerProfile; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 968 | |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 969 | @GuardedBy("this") |
| 970 | private final Constants mConstants; |
| 971 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 972 | /* |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 973 | * Holds a SamplingTimer associated with each Resource Power Manager state and voter, |
| 974 | * recording their times when on-battery (regardless of screen state). |
| 975 | */ |
| 976 | private final HashMap<String, SamplingTimer> mRpmStats = new HashMap<>(); |
| 977 | /** Times for each Resource Power Manager state and voter when screen-off and on-battery. */ |
| 978 | private final HashMap<String, SamplingTimer> mScreenOffRpmStats = new HashMap<>(); |
| 979 | |
| 980 | @Override |
| 981 | public Map<String, ? extends Timer> getRpmStats() { |
| 982 | return mRpmStats; |
| 983 | } |
| 984 | |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 985 | // TODO: Note: screenOffRpmStats has been disabled via SCREEN_OFF_RPM_STATS_ENABLED. |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 986 | @Override |
| 987 | public Map<String, ? extends Timer> getScreenOffRpmStats() { |
| 988 | return mScreenOffRpmStats; |
| 989 | } |
| 990 | |
| 991 | /* |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 992 | * Holds a SamplingTimer associated with each kernel wakelock name being tracked. |
| 993 | */ |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 994 | private final HashMap<String, SamplingTimer> mKernelWakelockStats = new HashMap<>(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 995 | |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 996 | @UnsupportedAppUsage |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 997 | public Map<String, ? extends Timer> getKernelWakelockStats() { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 998 | return mKernelWakelockStats; |
| 999 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1000 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1001 | String mLastWakeupReason = null; |
| 1002 | long mLastWakeupUptimeMs = 0; |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 1003 | private final HashMap<String, SamplingTimer> mWakeupReasonStats = new HashMap<>(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1004 | |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 1005 | public Map<String, ? extends Timer> getWakeupReasonStats() { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1006 | return mWakeupReasonStats; |
| 1007 | } |
| 1008 | |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 1009 | @Override |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 1010 | public long getUahDischarge(int which) { |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 1011 | return mDischargeCounter.getCountLocked(which); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 1012 | } |
| 1013 | |
| 1014 | @Override |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 1015 | public long getUahDischargeScreenOff(int which) { |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 1016 | return mDischargeScreenOffCounter.getCountLocked(which); |
| 1017 | } |
| 1018 | |
| 1019 | @Override |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 1020 | public long getUahDischargeScreenDoze(int which) { |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 1021 | return mDischargeScreenDozeCounter.getCountLocked(which); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 1022 | } |
| 1023 | |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 1024 | @Override |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 1025 | public long getUahDischargeLightDoze(int which) { |
| 1026 | return mDischargeLightDozeCounter.getCountLocked(which); |
| 1027 | } |
| 1028 | |
| 1029 | @Override |
| 1030 | public long getUahDischargeDeepDoze(int which) { |
| 1031 | return mDischargeDeepDozeCounter.getCountLocked(which); |
| 1032 | } |
| 1033 | |
| 1034 | @Override |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 1035 | public int getEstimatedBatteryCapacity() { |
| 1036 | return mEstimatedBatteryCapacity; |
| 1037 | } |
| 1038 | |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 1039 | @Override |
| 1040 | public int getMinLearnedBatteryCapacity() { |
| 1041 | return mMinLearnedBatteryCapacity; |
| 1042 | } |
| 1043 | |
| 1044 | @Override |
| 1045 | public int getMaxLearnedBatteryCapacity() { |
| 1046 | return mMaxLearnedBatteryCapacity; |
| 1047 | } |
| 1048 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1049 | public BatteryStatsImpl() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1050 | this(new SystemClocks()); |
| 1051 | } |
| 1052 | |
| 1053 | public BatteryStatsImpl(Clocks clocks) { |
| 1054 | init(clocks); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 1055 | mFile = null; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 1056 | mCheckinFile = null; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1057 | mDailyFile = null; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1058 | mHandler = null; |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 1059 | mPlatformIdleStateCallback = null; |
Suprabh Shukla | e6e723d | 2017-06-14 16:14:43 -0700 | [diff] [blame] | 1060 | mUserInfoProvider = null; |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 1061 | mConstants = new Constants(mHandler); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 1062 | clearHistoryLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1063 | } |
| 1064 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1065 | private void init(Clocks clocks) { |
| 1066 | mClocks = clocks; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1067 | } |
| 1068 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 1069 | public interface TimeBaseObs { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1070 | void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime); |
| 1071 | void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime); |
| 1072 | } |
| 1073 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1074 | // methods are protected not private to be VisibleForTesting |
| 1075 | public static class TimeBase { |
| 1076 | protected final ArrayList<TimeBaseObs> mObservers = new ArrayList<>(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1077 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1078 | protected long mUptime; |
| 1079 | protected long mRealtime; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1080 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1081 | protected boolean mRunning; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1082 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1083 | protected long mPastUptime; |
| 1084 | protected long mUptimeStart; |
| 1085 | protected long mPastRealtime; |
| 1086 | protected long mRealtimeStart; |
| 1087 | protected long mUnpluggedUptime; |
| 1088 | protected long mUnpluggedRealtime; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1089 | |
| 1090 | public void dump(PrintWriter pw, String prefix) { |
| 1091 | StringBuilder sb = new StringBuilder(128); |
| 1092 | pw.print(prefix); pw.print("mRunning="); pw.println(mRunning); |
| 1093 | sb.setLength(0); |
| 1094 | sb.append(prefix); |
| 1095 | sb.append("mUptime="); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 1096 | formatTimeMs(sb, mUptime / 1000); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1097 | pw.println(sb.toString()); |
| 1098 | sb.setLength(0); |
| 1099 | sb.append(prefix); |
| 1100 | sb.append("mRealtime="); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 1101 | formatTimeMs(sb, mRealtime / 1000); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1102 | pw.println(sb.toString()); |
| 1103 | sb.setLength(0); |
| 1104 | sb.append(prefix); |
| 1105 | sb.append("mPastUptime="); |
| 1106 | formatTimeMs(sb, mPastUptime / 1000); sb.append("mUptimeStart="); |
| 1107 | formatTimeMs(sb, mUptimeStart / 1000); |
| 1108 | sb.append("mUnpluggedUptime="); formatTimeMs(sb, mUnpluggedUptime / 1000); |
| 1109 | pw.println(sb.toString()); |
| 1110 | sb.setLength(0); |
| 1111 | sb.append(prefix); |
| 1112 | sb.append("mPastRealtime="); |
| 1113 | formatTimeMs(sb, mPastRealtime / 1000); sb.append("mRealtimeStart="); |
| 1114 | formatTimeMs(sb, mRealtimeStart / 1000); |
| 1115 | sb.append("mUnpluggedRealtime="); formatTimeMs(sb, mUnpluggedRealtime / 1000); |
| 1116 | pw.println(sb.toString()); |
| 1117 | } |
| 1118 | |
| 1119 | public void add(TimeBaseObs observer) { |
| 1120 | mObservers.add(observer); |
| 1121 | } |
| 1122 | |
| 1123 | public void remove(TimeBaseObs observer) { |
| 1124 | if (!mObservers.remove(observer)) { |
| 1125 | Slog.wtf(TAG, "Removed unknown observer: " + observer); |
| 1126 | } |
| 1127 | } |
| 1128 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1129 | public boolean hasObserver(TimeBaseObs observer) { |
| 1130 | return mObservers.contains(observer); |
| 1131 | } |
| 1132 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1133 | public void init(long uptime, long realtime) { |
| 1134 | mRealtime = 0; |
| 1135 | mUptime = 0; |
| 1136 | mPastUptime = 0; |
| 1137 | mPastRealtime = 0; |
| 1138 | mUptimeStart = uptime; |
| 1139 | mRealtimeStart = realtime; |
| 1140 | mUnpluggedUptime = getUptime(mUptimeStart); |
| 1141 | mUnpluggedRealtime = getRealtime(mRealtimeStart); |
| 1142 | } |
| 1143 | |
| 1144 | public void reset(long uptime, long realtime) { |
| 1145 | if (!mRunning) { |
| 1146 | mPastUptime = 0; |
| 1147 | mPastRealtime = 0; |
| 1148 | } else { |
| 1149 | mUptimeStart = uptime; |
| 1150 | mRealtimeStart = realtime; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1151 | // TODO: Since mUptimeStart was just reset and we are running, getUptime will |
| 1152 | // 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] | 1153 | mUnpluggedUptime = getUptime(uptime); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1154 | // TODO: likewise. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1155 | mUnpluggedRealtime = getRealtime(realtime); |
| 1156 | } |
| 1157 | } |
| 1158 | |
| 1159 | public long computeUptime(long curTime, int which) { |
| 1160 | switch (which) { |
| 1161 | case STATS_SINCE_CHARGED: |
| 1162 | return mUptime + getUptime(curTime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1163 | case STATS_CURRENT: |
| 1164 | return getUptime(curTime); |
| 1165 | case STATS_SINCE_UNPLUGGED: |
| 1166 | return getUptime(curTime) - mUnpluggedUptime; |
| 1167 | } |
| 1168 | return 0; |
| 1169 | } |
| 1170 | |
| 1171 | public long computeRealtime(long curTime, int which) { |
| 1172 | switch (which) { |
| 1173 | case STATS_SINCE_CHARGED: |
| 1174 | return mRealtime + getRealtime(curTime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1175 | case STATS_CURRENT: |
| 1176 | return getRealtime(curTime); |
| 1177 | case STATS_SINCE_UNPLUGGED: |
| 1178 | return getRealtime(curTime) - mUnpluggedRealtime; |
| 1179 | } |
| 1180 | return 0; |
| 1181 | } |
| 1182 | |
| 1183 | public long getUptime(long curTime) { |
| 1184 | long time = mPastUptime; |
| 1185 | if (mRunning) { |
| 1186 | time += curTime - mUptimeStart; |
| 1187 | } |
| 1188 | return time; |
| 1189 | } |
| 1190 | |
| 1191 | public long getRealtime(long curTime) { |
| 1192 | long time = mPastRealtime; |
| 1193 | if (mRunning) { |
| 1194 | time += curTime - mRealtimeStart; |
| 1195 | } |
| 1196 | return time; |
| 1197 | } |
| 1198 | |
| 1199 | public long getUptimeStart() { |
| 1200 | return mUptimeStart; |
| 1201 | } |
| 1202 | |
| 1203 | public long getRealtimeStart() { |
| 1204 | return mRealtimeStart; |
| 1205 | } |
| 1206 | |
| 1207 | public boolean isRunning() { |
| 1208 | return mRunning; |
| 1209 | } |
| 1210 | |
| 1211 | public boolean setRunning(boolean running, long uptime, long realtime) { |
| 1212 | if (mRunning != running) { |
| 1213 | mRunning = running; |
| 1214 | if (running) { |
| 1215 | mUptimeStart = uptime; |
| 1216 | mRealtimeStart = realtime; |
| 1217 | long batteryUptime = mUnpluggedUptime = getUptime(uptime); |
| 1218 | long batteryRealtime = mUnpluggedRealtime = getRealtime(realtime); |
| 1219 | |
| 1220 | for (int i = mObservers.size() - 1; i >= 0; i--) { |
| 1221 | mObservers.get(i).onTimeStarted(realtime, batteryUptime, batteryRealtime); |
| 1222 | } |
| 1223 | } else { |
| 1224 | mPastUptime += uptime - mUptimeStart; |
| 1225 | mPastRealtime += realtime - mRealtimeStart; |
| 1226 | |
| 1227 | long batteryUptime = getUptime(uptime); |
| 1228 | long batteryRealtime = getRealtime(realtime); |
| 1229 | |
| 1230 | for (int i = mObservers.size() - 1; i >= 0; i--) { |
| 1231 | mObservers.get(i).onTimeStopped(realtime, batteryUptime, batteryRealtime); |
| 1232 | } |
| 1233 | } |
| 1234 | return true; |
| 1235 | } |
| 1236 | return false; |
| 1237 | } |
| 1238 | |
| 1239 | public void readSummaryFromParcel(Parcel in) { |
| 1240 | mUptime = in.readLong(); |
| 1241 | mRealtime = in.readLong(); |
| 1242 | } |
| 1243 | |
| 1244 | public void writeSummaryToParcel(Parcel out, long uptime, long realtime) { |
| 1245 | out.writeLong(computeUptime(uptime, STATS_SINCE_CHARGED)); |
| 1246 | out.writeLong(computeRealtime(realtime, STATS_SINCE_CHARGED)); |
| 1247 | } |
| 1248 | |
| 1249 | public void readFromParcel(Parcel in) { |
| 1250 | mRunning = false; |
| 1251 | mUptime = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1252 | mPastUptime = in.readLong(); |
| 1253 | mUptimeStart = in.readLong(); |
Dianne Hackborn | ef640cd | 2014-03-25 14:41:05 -0700 | [diff] [blame] | 1254 | mRealtime = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1255 | mPastRealtime = in.readLong(); |
| 1256 | mRealtimeStart = in.readLong(); |
| 1257 | mUnpluggedUptime = in.readLong(); |
| 1258 | mUnpluggedRealtime = in.readLong(); |
| 1259 | } |
| 1260 | |
| 1261 | public void writeToParcel(Parcel out, long uptime, long realtime) { |
| 1262 | final long runningUptime = getUptime(uptime); |
| 1263 | final long runningRealtime = getRealtime(realtime); |
| 1264 | out.writeLong(mUptime); |
| 1265 | out.writeLong(runningUptime); |
| 1266 | out.writeLong(mUptimeStart); |
Dianne Hackborn | ef640cd | 2014-03-25 14:41:05 -0700 | [diff] [blame] | 1267 | out.writeLong(mRealtime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1268 | out.writeLong(runningRealtime); |
| 1269 | out.writeLong(mRealtimeStart); |
| 1270 | out.writeLong(mUnpluggedUptime); |
| 1271 | out.writeLong(mUnpluggedRealtime); |
| 1272 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1273 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1274 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1275 | /** |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1276 | * State for keeping track of counting information. |
| 1277 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1278 | public static class Counter extends BatteryStats.Counter implements TimeBaseObs { |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 1279 | @UnsupportedAppUsage |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 1280 | final AtomicInteger mCount = new AtomicInteger(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1281 | final TimeBase mTimeBase; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1282 | int mLoadedCount; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1283 | int mUnpluggedCount; |
| 1284 | int mPluggedCount; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1285 | |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 1286 | public Counter(TimeBase timeBase, Parcel in) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1287 | mTimeBase = timeBase; |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 1288 | mPluggedCount = in.readInt(); |
| 1289 | mCount.set(mPluggedCount); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1290 | mLoadedCount = in.readInt(); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1291 | mUnpluggedCount = in.readInt(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1292 | timeBase.add(this); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1293 | } |
| 1294 | |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 1295 | public Counter(TimeBase timeBase) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1296 | mTimeBase = timeBase; |
| 1297 | timeBase.add(this); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1298 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1299 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1300 | public void writeToParcel(Parcel out) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 1301 | out.writeInt(mCount.get()); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1302 | out.writeInt(mLoadedCount); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1303 | out.writeInt(mUnpluggedCount); |
| 1304 | } |
| 1305 | |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 1306 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1307 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 1308 | mUnpluggedCount = mPluggedCount; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1309 | } |
| 1310 | |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 1311 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1312 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 1313 | mPluggedCount = mCount.get(); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1314 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1315 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1316 | /** |
| 1317 | * Writes a possibly null Counter to a Parcel. |
| 1318 | * |
| 1319 | * @param out the Parcel to be written to. |
| 1320 | * @param counter a Counter, or null. |
| 1321 | */ |
Amith Yamasani | 977e11f | 2018-02-16 11:29:54 -0800 | [diff] [blame] | 1322 | public static void writeCounterToParcel(Parcel out, @Nullable Counter counter) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1323 | if (counter == null) { |
| 1324 | out.writeInt(0); // indicates null |
| 1325 | return; |
| 1326 | } |
| 1327 | out.writeInt(1); // indicates non-null |
| 1328 | |
| 1329 | counter.writeToParcel(out); |
| 1330 | } |
| 1331 | |
Amith Yamasani | 977e11f | 2018-02-16 11:29:54 -0800 | [diff] [blame] | 1332 | /** |
| 1333 | * Reads a Counter that was written using {@link #writeCounterToParcel(Parcel, Counter)}. |
| 1334 | * @param timeBase the timebase to assign to the Counter |
| 1335 | * @param in the parcel to read from |
| 1336 | * @return the Counter or null. |
| 1337 | */ |
| 1338 | public static @Nullable Counter readCounterFromParcel(TimeBase timeBase, Parcel in) { |
| 1339 | if (in.readInt() == 0) { |
| 1340 | return null; |
| 1341 | } |
| 1342 | return new Counter(timeBase, in); |
| 1343 | } |
| 1344 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1345 | @Override |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1346 | public int getCountLocked(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 1347 | int val = mCount.get(); |
| 1348 | if (which == STATS_SINCE_UNPLUGGED) { |
| 1349 | val -= mUnpluggedCount; |
| 1350 | } else if (which != STATS_SINCE_CHARGED) { |
| 1351 | val -= mLoadedCount; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1352 | } |
| 1353 | |
| 1354 | return val; |
| 1355 | } |
| 1356 | |
| 1357 | public void logState(Printer pw, String prefix) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 1358 | pw.println(prefix + "mCount=" + mCount.get() |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 1359 | + " mLoadedCount=" + mLoadedCount |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1360 | + " mUnpluggedCount=" + mUnpluggedCount |
| 1361 | + " mPluggedCount=" + mPluggedCount); |
| 1362 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1363 | |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 1364 | @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 1365 | public void stepAtomic() { |
| 1366 | if (mTimeBase.isRunning()) { |
| 1367 | mCount.incrementAndGet(); |
| 1368 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1369 | } |
| 1370 | |
Bookatz | 4ebc064 | 2017-05-11 12:21:19 -0700 | [diff] [blame] | 1371 | void addAtomic(int delta) { |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 1372 | if (mTimeBase.isRunning()) { |
| 1373 | mCount.addAndGet(delta); |
| 1374 | } |
Bookatz | 4ebc064 | 2017-05-11 12:21:19 -0700 | [diff] [blame] | 1375 | } |
| 1376 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1377 | /** |
| 1378 | * Clear state of this counter. |
| 1379 | */ |
| 1380 | void reset(boolean detachIfReset) { |
| 1381 | mCount.set(0); |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 1382 | mLoadedCount = mPluggedCount = mUnpluggedCount = 0; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1383 | if (detachIfReset) { |
| 1384 | detach(); |
| 1385 | } |
| 1386 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1387 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1388 | void detach() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1389 | mTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1390 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1391 | |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 1392 | @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 1393 | public void writeSummaryFromParcelLocked(Parcel out) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 1394 | int count = mCount.get(); |
| 1395 | out.writeInt(count); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1396 | } |
| 1397 | |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 1398 | @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 1399 | public void readSummaryFromParcelLocked(Parcel in) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 1400 | mLoadedCount = in.readInt(); |
| 1401 | mCount.set(mLoadedCount); |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 1402 | mUnpluggedCount = mPluggedCount = mLoadedCount; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1403 | } |
| 1404 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 1405 | |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 1406 | @VisibleForTesting |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1407 | public static class LongSamplingCounterArray extends LongCounterArray implements TimeBaseObs { |
| 1408 | final TimeBase mTimeBase; |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 1409 | public long[] mCounts; |
| 1410 | public long[] mLoadedCounts; |
| 1411 | public long[] mUnpluggedCounts; |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1412 | |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 1413 | private LongSamplingCounterArray(TimeBase timeBase, Parcel in) { |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1414 | mTimeBase = timeBase; |
Sudheer Shanka | e544d16 | 2017-12-28 17:06:20 -0800 | [diff] [blame] | 1415 | mCounts = in.createLongArray(); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1416 | mLoadedCounts = in.createLongArray(); |
| 1417 | mUnpluggedCounts = in.createLongArray(); |
| 1418 | timeBase.add(this); |
| 1419 | } |
| 1420 | |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 1421 | public LongSamplingCounterArray(TimeBase timeBase) { |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1422 | mTimeBase = timeBase; |
| 1423 | timeBase.add(this); |
| 1424 | } |
| 1425 | |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 1426 | private void writeToParcel(Parcel out) { |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1427 | out.writeLongArray(mCounts); |
| 1428 | out.writeLongArray(mLoadedCounts); |
| 1429 | out.writeLongArray(mUnpluggedCounts); |
| 1430 | } |
| 1431 | |
| 1432 | @Override |
| 1433 | public void onTimeStarted(long elapsedRealTime, long baseUptime, long baseRealtime) { |
Sudheer Shanka | e544d16 | 2017-12-28 17:06:20 -0800 | [diff] [blame] | 1434 | mUnpluggedCounts = copyArray(mCounts, mUnpluggedCounts); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1435 | } |
| 1436 | |
| 1437 | @Override |
| 1438 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1439 | } |
| 1440 | |
| 1441 | @Override |
| 1442 | public long[] getCountsLocked(int which) { |
Sudheer Shanka | e544d16 | 2017-12-28 17:06:20 -0800 | [diff] [blame] | 1443 | long[] val = copyArray(mCounts, null); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1444 | if (which == STATS_SINCE_UNPLUGGED) { |
| 1445 | subtract(val, mUnpluggedCounts); |
| 1446 | } else if (which != STATS_SINCE_CHARGED) { |
| 1447 | subtract(val, mLoadedCounts); |
| 1448 | } |
| 1449 | return val; |
| 1450 | } |
| 1451 | |
| 1452 | @Override |
| 1453 | public void logState(Printer pw, String prefix) { |
| 1454 | pw.println(prefix + "mCounts=" + Arrays.toString(mCounts) |
| 1455 | + " mLoadedCounts=" + Arrays.toString(mLoadedCounts) |
Sudheer Shanka | e544d16 | 2017-12-28 17:06:20 -0800 | [diff] [blame] | 1456 | + " mUnpluggedCounts=" + Arrays.toString(mUnpluggedCounts)); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1457 | } |
| 1458 | |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 1459 | public void addCountLocked(long[] counts) { |
Sudheer Shanka | e544d16 | 2017-12-28 17:06:20 -0800 | [diff] [blame] | 1460 | addCountLocked(counts, mTimeBase.isRunning()); |
| 1461 | } |
| 1462 | |
| 1463 | public void addCountLocked(long[] counts, boolean isRunning) { |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1464 | if (counts == null) { |
| 1465 | return; |
| 1466 | } |
Sudheer Shanka | e544d16 | 2017-12-28 17:06:20 -0800 | [diff] [blame] | 1467 | if (isRunning) { |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 1468 | if (mCounts == null) { |
| 1469 | mCounts = new long[counts.length]; |
| 1470 | } |
| 1471 | for (int i = 0; i < counts.length; ++i) { |
| 1472 | mCounts[i] += counts[i]; |
| 1473 | } |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1474 | } |
| 1475 | } |
| 1476 | |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 1477 | public int getSize() { |
| 1478 | return mCounts == null ? 0 : mCounts.length; |
| 1479 | } |
| 1480 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1481 | /** |
| 1482 | * Clear state of this counter. |
| 1483 | */ |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 1484 | public void reset(boolean detachIfReset) { |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1485 | fillArray(mCounts, 0); |
| 1486 | fillArray(mLoadedCounts, 0); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1487 | fillArray(mUnpluggedCounts, 0); |
| 1488 | if (detachIfReset) { |
| 1489 | detach(); |
| 1490 | } |
| 1491 | } |
| 1492 | |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 1493 | public void detach() { |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1494 | mTimeBase.remove(this); |
| 1495 | } |
| 1496 | |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 1497 | private void writeSummaryToParcelLocked(Parcel out) { |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1498 | out.writeLongArray(mCounts); |
| 1499 | } |
| 1500 | |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 1501 | private void readSummaryFromParcelLocked(Parcel in) { |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1502 | mCounts = in.createLongArray(); |
| 1503 | mLoadedCounts = copyArray(mCounts, mLoadedCounts); |
| 1504 | mUnpluggedCounts = copyArray(mCounts, mUnpluggedCounts); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1505 | } |
| 1506 | |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 1507 | public static void writeToParcel(Parcel out, LongSamplingCounterArray counterArray) { |
| 1508 | if (counterArray != null) { |
| 1509 | out.writeInt(1); |
| 1510 | counterArray.writeToParcel(out); |
| 1511 | } else { |
| 1512 | out.writeInt(0); |
| 1513 | } |
| 1514 | } |
| 1515 | |
| 1516 | public static LongSamplingCounterArray readFromParcel(Parcel in, TimeBase timeBase) { |
| 1517 | if (in.readInt() != 0) { |
| 1518 | return new LongSamplingCounterArray(timeBase, in); |
| 1519 | } else { |
| 1520 | return null; |
| 1521 | } |
| 1522 | } |
| 1523 | |
| 1524 | public static void writeSummaryToParcelLocked(Parcel out, |
| 1525 | LongSamplingCounterArray counterArray) { |
| 1526 | if (counterArray != null) { |
| 1527 | out.writeInt(1); |
| 1528 | counterArray.writeSummaryToParcelLocked(out); |
| 1529 | } else { |
| 1530 | out.writeInt(0); |
| 1531 | } |
| 1532 | } |
| 1533 | |
| 1534 | public static LongSamplingCounterArray readSummaryFromParcelLocked(Parcel in, |
| 1535 | TimeBase timeBase) { |
| 1536 | if (in.readInt() != 0) { |
| 1537 | final LongSamplingCounterArray counterArray |
| 1538 | = new LongSamplingCounterArray(timeBase); |
| 1539 | counterArray.readSummaryFromParcelLocked(in); |
| 1540 | return counterArray; |
| 1541 | } else { |
| 1542 | return null; |
| 1543 | } |
| 1544 | } |
| 1545 | |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 1546 | private static void fillArray(long[] a, long val) { |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1547 | if (a != null) { |
| 1548 | Arrays.fill(a, val); |
| 1549 | } |
| 1550 | } |
| 1551 | |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 1552 | private static void subtract(@NonNull long[] val, long[] toSubtract) { |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1553 | if (toSubtract == null) { |
| 1554 | return; |
| 1555 | } |
| 1556 | for (int i = 0; i < val.length; i++) { |
| 1557 | val[i] -= toSubtract[i]; |
| 1558 | } |
| 1559 | } |
| 1560 | |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 1561 | private static long[] copyArray(long[] src, long[] dest) { |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1562 | if (src == null) { |
| 1563 | return null; |
| 1564 | } else { |
| 1565 | if (dest == null) { |
| 1566 | dest = new long[src.length]; |
| 1567 | } |
| 1568 | System.arraycopy(src, 0, dest, 0, src.length); |
| 1569 | return dest; |
| 1570 | } |
| 1571 | } |
| 1572 | } |
| 1573 | |
Mike Ma | 561a8d9 | 2018-03-20 18:24:05 -0700 | [diff] [blame] | 1574 | @VisibleForTesting |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1575 | public static class LongSamplingCounter extends LongCounter implements TimeBaseObs { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1576 | final TimeBase mTimeBase; |
Mike Ma | 561a8d9 | 2018-03-20 18:24:05 -0700 | [diff] [blame] | 1577 | public long mCount; |
| 1578 | public long mCurrentCount; |
| 1579 | public long mLoadedCount; |
| 1580 | public long mUnpluggedCount; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1581 | |
Mike Ma | 561a8d9 | 2018-03-20 18:24:05 -0700 | [diff] [blame] | 1582 | public LongSamplingCounter(TimeBase timeBase, Parcel in) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1583 | mTimeBase = timeBase; |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 1584 | mCount = in.readLong(); |
Mike Ma | 561a8d9 | 2018-03-20 18:24:05 -0700 | [diff] [blame] | 1585 | mCurrentCount = in.readLong(); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1586 | mLoadedCount = in.readLong(); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1587 | mUnpluggedCount = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1588 | timeBase.add(this); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1589 | } |
| 1590 | |
Mike Ma | 561a8d9 | 2018-03-20 18:24:05 -0700 | [diff] [blame] | 1591 | public LongSamplingCounter(TimeBase timeBase) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1592 | mTimeBase = timeBase; |
| 1593 | timeBase.add(this); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1594 | } |
| 1595 | |
| 1596 | public void writeToParcel(Parcel out) { |
| 1597 | out.writeLong(mCount); |
Mike Ma | 561a8d9 | 2018-03-20 18:24:05 -0700 | [diff] [blame] | 1598 | out.writeLong(mCurrentCount); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1599 | out.writeLong(mLoadedCount); |
| 1600 | out.writeLong(mUnpluggedCount); |
| 1601 | } |
| 1602 | |
| 1603 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1604 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 1605 | mUnpluggedCount = mCount; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1606 | } |
| 1607 | |
| 1608 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1609 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1610 | } |
| 1611 | |
| 1612 | public long getCountLocked(int which) { |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 1613 | long val = mCount; |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 1614 | if (which == STATS_SINCE_UNPLUGGED) { |
| 1615 | val -= mUnpluggedCount; |
| 1616 | } else if (which != STATS_SINCE_CHARGED) { |
| 1617 | val -= mLoadedCount; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1618 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1619 | return val; |
| 1620 | } |
| 1621 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1622 | @Override |
| 1623 | public void logState(Printer pw, String prefix) { |
| 1624 | pw.println(prefix + "mCount=" + mCount |
Mike Ma | 561a8d9 | 2018-03-20 18:24:05 -0700 | [diff] [blame] | 1625 | + " mCurrentCount=" + mCurrentCount |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 1626 | + " mLoadedCount=" + mLoadedCount |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 1627 | + " mUnpluggedCount=" + mUnpluggedCount); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1628 | } |
| 1629 | |
Mike Ma | 561a8d9 | 2018-03-20 18:24:05 -0700 | [diff] [blame] | 1630 | public void addCountLocked(long count) { |
| 1631 | update(mCurrentCount + count, mTimeBase.isRunning()); |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 1632 | } |
| 1633 | |
Mike Ma | 561a8d9 | 2018-03-20 18:24:05 -0700 | [diff] [blame] | 1634 | public void addCountLocked(long count, boolean isRunning) { |
| 1635 | update(mCurrentCount + count, isRunning); |
| 1636 | } |
| 1637 | |
| 1638 | public void update(long count) { |
| 1639 | update(count, mTimeBase.isRunning()); |
| 1640 | } |
| 1641 | |
| 1642 | public void update(long count, boolean isRunning) { |
| 1643 | if (count < mCurrentCount) { |
| 1644 | mCurrentCount = 0; |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 1645 | } |
Mike Ma | 561a8d9 | 2018-03-20 18:24:05 -0700 | [diff] [blame] | 1646 | if (isRunning) { |
| 1647 | mCount += count - mCurrentCount; |
| 1648 | } |
| 1649 | mCurrentCount = count; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1650 | } |
| 1651 | |
| 1652 | /** |
| 1653 | * Clear state of this counter. |
| 1654 | */ |
Mike Ma | 561a8d9 | 2018-03-20 18:24:05 -0700 | [diff] [blame] | 1655 | public void reset(boolean detachIfReset) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1656 | mCount = 0; |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 1657 | mLoadedCount = mUnpluggedCount = 0; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1658 | if (detachIfReset) { |
| 1659 | detach(); |
| 1660 | } |
| 1661 | } |
| 1662 | |
Mike Ma | 561a8d9 | 2018-03-20 18:24:05 -0700 | [diff] [blame] | 1663 | public void detach() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1664 | mTimeBase.remove(this); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1665 | } |
| 1666 | |
Mike Ma | 561a8d9 | 2018-03-20 18:24:05 -0700 | [diff] [blame] | 1667 | public void writeSummaryFromParcelLocked(Parcel out) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1668 | out.writeLong(mCount); |
| 1669 | } |
| 1670 | |
Mike Ma | 561a8d9 | 2018-03-20 18:24:05 -0700 | [diff] [blame] | 1671 | public void readSummaryFromParcelLocked(Parcel in) { |
| 1672 | mCount = mUnpluggedCount= mLoadedCount = in.readLong(); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1673 | } |
| 1674 | } |
| 1675 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1676 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1677 | * State for keeping track of timing information. |
| 1678 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1679 | public static abstract class Timer extends BatteryStats.Timer implements TimeBaseObs { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1680 | protected final Clocks mClocks; |
| 1681 | protected final int mType; |
| 1682 | protected final TimeBase mTimeBase; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1683 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1684 | protected int mCount; |
| 1685 | protected int mLoadedCount; |
| 1686 | protected int mLastCount; |
| 1687 | protected int mUnpluggedCount; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1688 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1689 | // Times are in microseconds for better accuracy when dividing by the |
| 1690 | // lock count, and are in "battery realtime" units. |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1691 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1692 | /** |
| 1693 | * The total time we have accumulated since the start of the original |
| 1694 | * boot, to the last time something interesting happened in the |
| 1695 | * current run. |
| 1696 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1697 | protected long mTotalTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1698 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1699 | /** |
| 1700 | * The total time we loaded for the previous runs. Subtract this from |
| 1701 | * mTotalTime to find the time for the current run of the system. |
| 1702 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1703 | protected long mLoadedTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1704 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1705 | /** |
| 1706 | * The run time of the last run of the system, as loaded from the |
| 1707 | * saved data. |
| 1708 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1709 | protected long mLastTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1710 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1711 | /** |
| 1712 | * The value of mTotalTime when unplug() was last called. Subtract |
| 1713 | * this from mTotalTime to find the time since the last unplug from |
| 1714 | * power. |
| 1715 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1716 | protected long mUnpluggedTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1717 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 1718 | /** |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1719 | * The total time this timer has been running until the latest mark has been set. |
| 1720 | * Subtract this from mTotalTime to get the time spent running since the mark was set. |
| 1721 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1722 | protected long mTimeBeforeMark; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1723 | |
| 1724 | /** |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 1725 | * Constructs from a parcel. |
| 1726 | * @param type |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1727 | * @param timeBase |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 1728 | * @param in |
| 1729 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1730 | public Timer(Clocks clocks, int type, TimeBase timeBase, Parcel in) { |
| 1731 | mClocks = clocks; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1732 | mType = type; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1733 | mTimeBase = timeBase; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1734 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1735 | mCount = in.readInt(); |
| 1736 | mLoadedCount = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1737 | mLastCount = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1738 | mUnpluggedCount = in.readInt(); |
| 1739 | mTotalTime = in.readLong(); |
| 1740 | mLoadedTime = in.readLong(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1741 | mLastTime = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1742 | mUnpluggedTime = in.readLong(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1743 | mTimeBeforeMark = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1744 | timeBase.add(this); |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 1745 | 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] | 1746 | } |
| 1747 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1748 | public Timer(Clocks clocks, int type, TimeBase timeBase) { |
| 1749 | mClocks = clocks; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1750 | mType = type; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1751 | mTimeBase = timeBase; |
| 1752 | timeBase.add(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1753 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1754 | |
| 1755 | protected abstract long computeRunTimeLocked(long curBatteryRealtime); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1756 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1757 | protected abstract int computeCurrentCountLocked(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1758 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1759 | /** |
| 1760 | * Clear state of this timer. Returns true if the timer is inactive |
| 1761 | * so can be completely dropped. |
| 1762 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1763 | public boolean reset(boolean detachIfReset) { |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1764 | mTotalTime = mLoadedTime = mLastTime = mTimeBeforeMark = 0; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1765 | mCount = mLoadedCount = mLastCount = 0; |
| 1766 | if (detachIfReset) { |
| 1767 | detach(); |
| 1768 | } |
| 1769 | return true; |
| 1770 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1771 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1772 | public void detach() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1773 | mTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1774 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1775 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1776 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 1777 | if (DEBUG) Log.i(TAG, "**** WRITING TIMER #" + mType + ": mTotalTime=" |
| 1778 | + computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs))); |
Adam Lesinski | 98f0d46 | 2016-04-19 16:46:20 -0700 | [diff] [blame] | 1779 | out.writeInt(computeCurrentCountLocked()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1780 | out.writeInt(mLoadedCount); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1781 | out.writeInt(mUnpluggedCount); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1782 | out.writeLong(computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs))); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1783 | out.writeLong(mLoadedTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1784 | out.writeLong(mUnpluggedTime); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1785 | out.writeLong(mTimeBeforeMark); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1786 | } |
| 1787 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1788 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1789 | public void onTimeStarted(long elapsedRealtime, long timeBaseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1790 | if (DEBUG && mType < 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1791 | Log.v(TAG, "unplug #" + mType + ": realtime=" + baseRealtime |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1792 | + " old mUnpluggedTime=" + mUnpluggedTime |
| 1793 | + " old mUnpluggedCount=" + mUnpluggedCount); |
| 1794 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1795 | mUnpluggedTime = computeRunTimeLocked(baseRealtime); |
Adam Lesinski | 98f0d46 | 2016-04-19 16:46:20 -0700 | [diff] [blame] | 1796 | mUnpluggedCount = computeCurrentCountLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1797 | if (DEBUG && mType < 0) { |
| 1798 | Log.v(TAG, "unplug #" + mType |
| 1799 | + ": new mUnpluggedTime=" + mUnpluggedTime |
| 1800 | + " new mUnpluggedCount=" + mUnpluggedCount); |
| 1801 | } |
| 1802 | } |
| 1803 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1804 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1805 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1806 | if (DEBUG && mType < 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1807 | Log.v(TAG, "plug #" + mType + ": realtime=" + baseRealtime |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1808 | + " old mTotalTime=" + mTotalTime); |
| 1809 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1810 | mTotalTime = computeRunTimeLocked(baseRealtime); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1811 | mCount = computeCurrentCountLocked(); |
| 1812 | if (DEBUG && mType < 0) { |
| 1813 | Log.v(TAG, "plug #" + mType |
| 1814 | + ": new mTotalTime=" + mTotalTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1815 | } |
| 1816 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1817 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1818 | /** |
| 1819 | * Writes a possibly null Timer to a Parcel. |
| 1820 | * |
| 1821 | * @param out the Parcel to be written to. |
| 1822 | * @param timer a Timer, or null. |
| 1823 | */ |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 1824 | @UnsupportedAppUsage |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1825 | 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] | 1826 | if (timer == null) { |
| 1827 | out.writeInt(0); // indicates null |
| 1828 | return; |
| 1829 | } |
| 1830 | out.writeInt(1); // indicates non-null |
| 1831 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1832 | timer.writeToParcel(out, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1833 | } |
| 1834 | |
| 1835 | @Override |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 1836 | @UnsupportedAppUsage |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1837 | public long getTotalTimeLocked(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 1838 | long val = computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs)); |
| 1839 | if (which == STATS_SINCE_UNPLUGGED) { |
| 1840 | val -= mUnpluggedTime; |
| 1841 | } else if (which != STATS_SINCE_CHARGED) { |
| 1842 | val -= mLoadedTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1843 | } |
| 1844 | |
| 1845 | return val; |
| 1846 | } |
| 1847 | |
| 1848 | @Override |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 1849 | @UnsupportedAppUsage |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1850 | public int getCountLocked(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 1851 | int val = computeCurrentCountLocked(); |
| 1852 | if (which == STATS_SINCE_UNPLUGGED) { |
| 1853 | val -= mUnpluggedCount; |
| 1854 | } else if (which != STATS_SINCE_CHARGED) { |
| 1855 | val -= mLoadedCount; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1856 | } |
| 1857 | |
| 1858 | return val; |
| 1859 | } |
| 1860 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1861 | @Override |
| 1862 | public long getTimeSinceMarkLocked(long elapsedRealtimeUs) { |
| 1863 | long val = computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs)); |
| 1864 | return val - mTimeBeforeMark; |
| 1865 | } |
| 1866 | |
| 1867 | @Override |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1868 | public void logState(Printer pw, String prefix) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 1869 | pw.println(prefix + "mCount=" + mCount |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1870 | + " mLoadedCount=" + mLoadedCount + " mLastCount=" + mLastCount |
| 1871 | + " mUnpluggedCount=" + mUnpluggedCount); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1872 | pw.println(prefix + "mTotalTime=" + mTotalTime |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1873 | + " mLoadedTime=" + mLoadedTime); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1874 | pw.println(prefix + "mLastTime=" + mLastTime |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1875 | + " mUnpluggedTime=" + mUnpluggedTime); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1876 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1877 | |
| 1878 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1879 | public void writeSummaryFromParcelLocked(Parcel out, long elapsedRealtimeUs) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1880 | long runTime = computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs)); |
| 1881 | out.writeLong(runTime); |
Adam Lesinski | 98f0d46 | 2016-04-19 16:46:20 -0700 | [diff] [blame] | 1882 | out.writeInt(computeCurrentCountLocked()); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1883 | } |
| 1884 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1885 | public void readSummaryFromParcelLocked(Parcel in) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1886 | // Multiply by 1000 for backwards compatibility |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1887 | mTotalTime = mLoadedTime = in.readLong(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1888 | mLastTime = 0; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1889 | mUnpluggedTime = mTotalTime; |
| 1890 | mCount = mLoadedCount = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1891 | mLastCount = 0; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1892 | mUnpluggedCount = mCount; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1893 | |
| 1894 | // When reading the summary, we set the mark to be the latest information. |
| 1895 | mTimeBeforeMark = mTotalTime; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1896 | } |
| 1897 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1898 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1899 | /** |
| 1900 | * A counter meant to accept monotonically increasing values to its {@link #update(long, int)} |
| 1901 | * method. The state of the timer according to its {@link TimeBase} will determine how much |
| 1902 | * of the value is recorded. |
| 1903 | * |
| 1904 | * If the value being recorded resets, {@link #endSample()} can be called in order to |
| 1905 | * account for the change. If the value passed in to {@link #update(long, int)} decreased |
| 1906 | * between calls, the {@link #endSample()} is automatically called and the new value is |
| 1907 | * expected to increase monotonically from that point on. |
| 1908 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1909 | public static class SamplingTimer extends Timer { |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1910 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1911 | /** |
| 1912 | * The most recent reported count from /proc/wakelocks. |
| 1913 | */ |
| 1914 | int mCurrentReportedCount; |
| 1915 | |
| 1916 | /** |
| 1917 | * The reported count from /proc/wakelocks when unplug() was last |
| 1918 | * called. |
| 1919 | */ |
| 1920 | int mUnpluggedReportedCount; |
| 1921 | |
| 1922 | /** |
| 1923 | * The most recent reported total_time from /proc/wakelocks. |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1924 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1925 | long mCurrentReportedTotalTime; |
| 1926 | |
| 1927 | |
| 1928 | /** |
| 1929 | * The reported total_time from /proc/wakelocks when unplug() was last |
| 1930 | * called. |
| 1931 | */ |
| 1932 | long mUnpluggedReportedTotalTime; |
| 1933 | |
| 1934 | /** |
| 1935 | * Whether we are currently in a discharge cycle. |
| 1936 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1937 | boolean mTimeBaseRunning; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1938 | |
| 1939 | /** |
| 1940 | * Whether we are currently recording reported values. |
| 1941 | */ |
| 1942 | boolean mTrackingReportedValues; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1943 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1944 | /* |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1945 | * A sequence counter, incremented once for each update of the stats. |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1946 | */ |
| 1947 | int mUpdateVersion; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1948 | |
Adam Lesinski | 98f0d46 | 2016-04-19 16:46:20 -0700 | [diff] [blame] | 1949 | @VisibleForTesting |
| 1950 | public SamplingTimer(Clocks clocks, TimeBase timeBase, Parcel in) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1951 | super(clocks, 0, timeBase, in); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1952 | mCurrentReportedCount = in.readInt(); |
| 1953 | mUnpluggedReportedCount = in.readInt(); |
| 1954 | mCurrentReportedTotalTime = in.readLong(); |
| 1955 | mUnpluggedReportedTotalTime = in.readLong(); |
| 1956 | mTrackingReportedValues = in.readInt() == 1; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1957 | mTimeBaseRunning = timeBase.isRunning(); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1958 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1959 | |
Adam Lesinski | 98f0d46 | 2016-04-19 16:46:20 -0700 | [diff] [blame] | 1960 | @VisibleForTesting |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1961 | public SamplingTimer(Clocks clocks, TimeBase timeBase) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1962 | super(clocks, 0, timeBase); |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1963 | mTrackingReportedValues = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1964 | mTimeBaseRunning = timeBase.isRunning(); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1965 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1966 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1967 | /** |
| 1968 | * Ends the current sample, allowing subsequent values to {@link #update(long, int)} to |
| 1969 | * be less than the values used for a previous invocation. |
| 1970 | */ |
| 1971 | public void endSample() { |
| 1972 | mTotalTime = computeRunTimeLocked(0 /* unused by us */); |
| 1973 | mCount = computeCurrentCountLocked(); |
| 1974 | mUnpluggedReportedTotalTime = mCurrentReportedTotalTime = 0; |
| 1975 | mUnpluggedReportedCount = mCurrentReportedCount = 0; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1976 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1977 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1978 | public void setUpdateVersion(int version) { |
| 1979 | mUpdateVersion = version; |
| 1980 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1981 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1982 | public int getUpdateVersion() { |
| 1983 | return mUpdateVersion; |
| 1984 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1985 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1986 | /** |
| 1987 | * Updates the current recorded values. These are meant to be monotonically increasing |
| 1988 | * and cumulative. If you are dealing with deltas, use {@link #add(long, int)}. |
| 1989 | * |
| 1990 | * If the values being recorded have been reset, the monotonically increasing requirement |
| 1991 | * will be broken. In this case, {@link #endSample()} is automatically called and |
| 1992 | * the total value of totalTime and count are recorded, starting a new monotonically |
| 1993 | * increasing sample. |
| 1994 | * |
| 1995 | * @param totalTime total time of sample in microseconds. |
| 1996 | * @param count total number of times the event being sampled occurred. |
| 1997 | */ |
| 1998 | public void update(long totalTime, int count) { |
| 1999 | if (mTimeBaseRunning && !mTrackingReportedValues) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2000 | // Updating the reported value for the first time. |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 2001 | mUnpluggedReportedTotalTime = totalTime; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2002 | mUnpluggedReportedCount = count; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2003 | } |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 2004 | |
| 2005 | mTrackingReportedValues = true; |
| 2006 | |
| 2007 | if (totalTime < mCurrentReportedTotalTime || count < mCurrentReportedCount) { |
| 2008 | endSample(); |
| 2009 | } |
| 2010 | |
| 2011 | mCurrentReportedTotalTime = totalTime; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2012 | mCurrentReportedCount = count; |
| 2013 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2014 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 2015 | /** |
| 2016 | * Adds deltaTime and deltaCount to the current sample. |
| 2017 | * |
| 2018 | * @param deltaTime additional time recorded since the last sampled event, in microseconds. |
| 2019 | * @param deltaCount additional number of times the event being sampled occurred. |
| 2020 | */ |
| 2021 | public void add(long deltaTime, int deltaCount) { |
| 2022 | update(mCurrentReportedTotalTime + deltaTime, mCurrentReportedCount + deltaCount); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 2023 | } |
| 2024 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 2025 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2026 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
| 2027 | super.onTimeStarted(elapsedRealtime, baseUptime, baseRealtime); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2028 | if (mTrackingReportedValues) { |
| 2029 | mUnpluggedReportedTotalTime = mCurrentReportedTotalTime; |
| 2030 | mUnpluggedReportedCount = mCurrentReportedCount; |
| 2031 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2032 | mTimeBaseRunning = true; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2033 | } |
| 2034 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 2035 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2036 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
| 2037 | super.onTimeStopped(elapsedRealtime, baseUptime, baseRealtime); |
| 2038 | mTimeBaseRunning = false; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2039 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2040 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 2041 | @Override |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2042 | public void logState(Printer pw, String prefix) { |
| 2043 | super.logState(pw, prefix); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2044 | pw.println(prefix + "mCurrentReportedCount=" + mCurrentReportedCount |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2045 | + " mUnpluggedReportedCount=" + mUnpluggedReportedCount |
| 2046 | + " mCurrentReportedTotalTime=" + mCurrentReportedTotalTime |
| 2047 | + " mUnpluggedReportedTotalTime=" + mUnpluggedReportedTotalTime); |
| 2048 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2049 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 2050 | @Override |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2051 | protected long computeRunTimeLocked(long curBatteryRealtime) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2052 | return mTotalTime + (mTimeBaseRunning && mTrackingReportedValues |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2053 | ? mCurrentReportedTotalTime - mUnpluggedReportedTotalTime : 0); |
| 2054 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2055 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 2056 | @Override |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2057 | protected int computeCurrentCountLocked() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2058 | return mCount + (mTimeBaseRunning && mTrackingReportedValues |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2059 | ? mCurrentReportedCount - mUnpluggedReportedCount : 0); |
| 2060 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2061 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 2062 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2063 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
| 2064 | super.writeToParcel(out, elapsedRealtimeUs); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2065 | out.writeInt(mCurrentReportedCount); |
| 2066 | out.writeInt(mUnpluggedReportedCount); |
| 2067 | out.writeLong(mCurrentReportedTotalTime); |
| 2068 | out.writeLong(mUnpluggedReportedTotalTime); |
| 2069 | out.writeInt(mTrackingReportedValues ? 1 : 0); |
| 2070 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2071 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 2072 | @Override |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2073 | public boolean reset(boolean detachIfReset) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2074 | super.reset(detachIfReset); |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 2075 | mTrackingReportedValues = false; |
| 2076 | mUnpluggedReportedTotalTime = 0; |
| 2077 | mUnpluggedReportedCount = 0; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2078 | return true; |
| 2079 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2080 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2081 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2082 | /** |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 2083 | * A timer that increments in batches. It does not run for durations, but just jumps |
| 2084 | * for a pre-determined amount. |
| 2085 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2086 | public static class BatchTimer extends Timer { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 2087 | final Uid mUid; |
| 2088 | |
| 2089 | /** |
| 2090 | * The last time at which we updated the timer. This is in elapsed realtime microseconds. |
| 2091 | */ |
| 2092 | long mLastAddedTime; |
| 2093 | |
| 2094 | /** |
| 2095 | * The last duration that we added to the timer. This is in microseconds. |
| 2096 | */ |
| 2097 | long mLastAddedDuration; |
| 2098 | |
| 2099 | /** |
| 2100 | * Whether we are currently in a discharge cycle. |
| 2101 | */ |
| 2102 | boolean mInDischarge; |
| 2103 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2104 | BatchTimer(Clocks clocks, Uid uid, int type, TimeBase timeBase, Parcel in) { |
| 2105 | super(clocks, type, timeBase, in); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 2106 | mUid = uid; |
| 2107 | mLastAddedTime = in.readLong(); |
| 2108 | mLastAddedDuration = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2109 | mInDischarge = timeBase.isRunning(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 2110 | } |
| 2111 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2112 | BatchTimer(Clocks clocks, Uid uid, int type, TimeBase timeBase) { |
| 2113 | super(clocks, type, timeBase); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 2114 | mUid = uid; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2115 | mInDischarge = timeBase.isRunning(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 2116 | } |
| 2117 | |
| 2118 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2119 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
| 2120 | super.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 2121 | out.writeLong(mLastAddedTime); |
| 2122 | out.writeLong(mLastAddedDuration); |
| 2123 | } |
| 2124 | |
| 2125 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2126 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2127 | recomputeLastDuration(mClocks.elapsedRealtime() * 1000, false); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 2128 | mInDischarge = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2129 | super.onTimeStopped(elapsedRealtime, baseUptime, baseRealtime); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 2130 | } |
| 2131 | |
| 2132 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2133 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 2134 | recomputeLastDuration(elapsedRealtime, false); |
| 2135 | mInDischarge = true; |
| 2136 | // If we are still within the last added duration, then re-added whatever remains. |
| 2137 | if (mLastAddedTime == elapsedRealtime) { |
| 2138 | mTotalTime += mLastAddedDuration; |
| 2139 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2140 | super.onTimeStarted(elapsedRealtime, baseUptime, baseRealtime); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 2141 | } |
| 2142 | |
| 2143 | @Override |
| 2144 | public void logState(Printer pw, String prefix) { |
| 2145 | super.logState(pw, prefix); |
| 2146 | pw.println(prefix + "mLastAddedTime=" + mLastAddedTime |
| 2147 | + " mLastAddedDuration=" + mLastAddedDuration); |
| 2148 | } |
| 2149 | |
| 2150 | private long computeOverage(long curTime) { |
| 2151 | if (mLastAddedTime > 0) { |
| 2152 | return mLastTime + mLastAddedDuration - curTime; |
| 2153 | } |
| 2154 | return 0; |
| 2155 | } |
| 2156 | |
| 2157 | private void recomputeLastDuration(long curTime, boolean abort) { |
| 2158 | final long overage = computeOverage(curTime); |
| 2159 | if (overage > 0) { |
| 2160 | // Aborting before the duration ran out -- roll back the remaining |
| 2161 | // duration. Only do this if currently discharging; otherwise we didn't |
| 2162 | // actually add the time. |
| 2163 | if (mInDischarge) { |
| 2164 | mTotalTime -= overage; |
| 2165 | } |
| 2166 | if (abort) { |
| 2167 | mLastAddedTime = 0; |
| 2168 | } else { |
| 2169 | mLastAddedTime = curTime; |
| 2170 | mLastAddedDuration -= overage; |
| 2171 | } |
| 2172 | } |
| 2173 | } |
| 2174 | |
| 2175 | public void addDuration(BatteryStatsImpl stats, long durationMillis) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2176 | final long now = mClocks.elapsedRealtime() * 1000; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 2177 | recomputeLastDuration(now, true); |
| 2178 | mLastAddedTime = now; |
| 2179 | mLastAddedDuration = durationMillis * 1000; |
| 2180 | if (mInDischarge) { |
| 2181 | mTotalTime += mLastAddedDuration; |
| 2182 | mCount++; |
| 2183 | } |
| 2184 | } |
| 2185 | |
| 2186 | public void abortLastDuration(BatteryStatsImpl stats) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2187 | final long now = mClocks.elapsedRealtime() * 1000; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 2188 | recomputeLastDuration(now, true); |
| 2189 | } |
| 2190 | |
| 2191 | @Override |
| 2192 | protected int computeCurrentCountLocked() { |
| 2193 | return mCount; |
| 2194 | } |
| 2195 | |
| 2196 | @Override |
| 2197 | protected long computeRunTimeLocked(long curBatteryRealtime) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2198 | final long overage = computeOverage(mClocks.elapsedRealtime() * 1000); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 2199 | if (overage > 0) { |
| 2200 | return mTotalTime = overage; |
| 2201 | } |
| 2202 | return mTotalTime; |
| 2203 | } |
| 2204 | |
| 2205 | @Override |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2206 | public boolean reset(boolean detachIfReset) { |
| 2207 | final long now = mClocks.elapsedRealtime() * 1000; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 2208 | recomputeLastDuration(now, true); |
| 2209 | boolean stillActive = mLastAddedTime == now; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2210 | super.reset(!stillActive && detachIfReset); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 2211 | return !stillActive; |
| 2212 | } |
| 2213 | } |
| 2214 | |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2215 | |
| 2216 | /** |
| 2217 | * A StopwatchTimer that also tracks the total and max individual |
| 2218 | * time spent active according to the given timebase. Whereas |
| 2219 | * StopwatchTimer apportions the time amongst all in the pool, |
| 2220 | * the total and max durations are not apportioned. |
| 2221 | */ |
| 2222 | public static class DurationTimer extends StopwatchTimer { |
| 2223 | /** |
| 2224 | * The time (in ms) that the timer was last acquired or the time base |
| 2225 | * last (re-)started. Increasing the nesting depth does not reset this time. |
| 2226 | * |
| 2227 | * -1 if the timer is currently not running or the time base is not running. |
| 2228 | * |
| 2229 | * If written to a parcel, the start time is reset, as is mNesting in the base class |
| 2230 | * StopwatchTimer. |
| 2231 | */ |
| 2232 | long mStartTimeMs = -1; |
| 2233 | |
| 2234 | /** |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2235 | * 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] | 2236 | */ |
| 2237 | long mMaxDurationMs; |
| 2238 | |
| 2239 | /** |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2240 | * The time (in ms) that that the timer has been active since most recent |
| 2241 | * stopRunningLocked() or reset(). Not pooled. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2242 | */ |
| 2243 | long mCurrentDurationMs; |
| 2244 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2245 | /** |
| 2246 | * The total time (in ms) that that the timer has been active since most recent reset() |
| 2247 | * prior to the current startRunningLocked. This is the sum of all past currentDurations |
| 2248 | * (but not including the present currentDuration) since reset. Not pooled. |
| 2249 | */ |
| 2250 | long mTotalDurationMs; |
| 2251 | |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2252 | public DurationTimer(Clocks clocks, Uid uid, int type, ArrayList<StopwatchTimer> timerPool, |
| 2253 | TimeBase timeBase, Parcel in) { |
| 2254 | super(clocks, uid, type, timerPool, timeBase, in); |
| 2255 | mMaxDurationMs = in.readLong(); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2256 | mTotalDurationMs = in.readLong(); |
jackqdyulei | 610a0a0 | 2017-08-09 14:02:01 -0700 | [diff] [blame] | 2257 | mCurrentDurationMs = in.readLong(); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2258 | } |
| 2259 | |
| 2260 | public DurationTimer(Clocks clocks, Uid uid, int type, ArrayList<StopwatchTimer> timerPool, |
| 2261 | TimeBase timeBase) { |
| 2262 | super(clocks, uid, type, timerPool, timeBase); |
| 2263 | } |
| 2264 | |
| 2265 | @Override |
| 2266 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
| 2267 | super.writeToParcel(out, elapsedRealtimeUs); |
Kweku Adams | 47db5a8 | 2016-12-09 19:04:50 -0800 | [diff] [blame] | 2268 | out.writeLong(getMaxDurationMsLocked(elapsedRealtimeUs / 1000)); |
jackqdyulei | 610a0a0 | 2017-08-09 14:02:01 -0700 | [diff] [blame] | 2269 | out.writeLong(mTotalDurationMs); |
| 2270 | out.writeLong(getCurrentDurationMsLocked(elapsedRealtimeUs / 1000)); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2271 | } |
| 2272 | |
| 2273 | /** |
| 2274 | * Write the summary to the parcel. |
| 2275 | * |
| 2276 | * Since the time base is probably meaningless after we come back, reading |
| 2277 | * 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] | 2278 | * is the max and total durations. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2279 | */ |
| 2280 | @Override |
| 2281 | public void writeSummaryFromParcelLocked(Parcel out, long elapsedRealtimeUs) { |
| 2282 | super.writeSummaryFromParcelLocked(out, elapsedRealtimeUs); |
Kweku Adams | 47db5a8 | 2016-12-09 19:04:50 -0800 | [diff] [blame] | 2283 | out.writeLong(getMaxDurationMsLocked(elapsedRealtimeUs / 1000)); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2284 | out.writeLong(getTotalDurationMsLocked(elapsedRealtimeUs / 1000)); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2285 | } |
| 2286 | |
| 2287 | /** |
| 2288 | * Read the summary parcel. |
| 2289 | * |
| 2290 | * Has the side effect of stopping the timer. |
| 2291 | */ |
| 2292 | @Override |
| 2293 | public void readSummaryFromParcelLocked(Parcel in) { |
| 2294 | super.readSummaryFromParcelLocked(in); |
| 2295 | mMaxDurationMs = in.readLong(); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2296 | mTotalDurationMs = in.readLong(); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2297 | mStartTimeMs = -1; |
| 2298 | mCurrentDurationMs = 0; |
| 2299 | } |
| 2300 | |
| 2301 | /** |
| 2302 | * The TimeBase time started (again). |
| 2303 | * |
| 2304 | * If the timer is also running, store the start time. |
| 2305 | */ |
| 2306 | public void onTimeStarted(long elapsedRealtimeUs, long baseUptime, long baseRealtime) { |
| 2307 | super.onTimeStarted(elapsedRealtimeUs, baseUptime, baseRealtime); |
| 2308 | if (mNesting > 0) { |
Kweku Adams | 47db5a8 | 2016-12-09 19:04:50 -0800 | [diff] [blame] | 2309 | mStartTimeMs = baseRealtime / 1000; |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2310 | } |
| 2311 | } |
| 2312 | |
| 2313 | /** |
| 2314 | * The TimeBase stopped running. |
| 2315 | * |
| 2316 | * If the timer is running, add the duration into mCurrentDurationMs. |
| 2317 | */ |
| 2318 | @Override |
Kweku Adams | 47db5a8 | 2016-12-09 19:04:50 -0800 | [diff] [blame] | 2319 | public void onTimeStopped(long elapsedRealtimeUs, long baseUptime, long baseRealtimeUs) { |
| 2320 | super.onTimeStopped(elapsedRealtimeUs, baseUptime, baseRealtimeUs); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2321 | if (mNesting > 0) { |
Kweku Adams | 47db5a8 | 2016-12-09 19:04:50 -0800 | [diff] [blame] | 2322 | // baseRealtimeUs has already been converted to the timebase's realtime. |
| 2323 | mCurrentDurationMs += (baseRealtimeUs / 1000) - mStartTimeMs; |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2324 | } |
| 2325 | mStartTimeMs = -1; |
| 2326 | } |
| 2327 | |
| 2328 | @Override |
| 2329 | public void logState(Printer pw, String prefix) { |
| 2330 | super.logState(pw, prefix); |
| 2331 | } |
| 2332 | |
| 2333 | @Override |
| 2334 | public void startRunningLocked(long elapsedRealtimeMs) { |
| 2335 | super.startRunningLocked(elapsedRealtimeMs); |
| 2336 | if (mNesting == 1 && mTimeBase.isRunning()) { |
| 2337 | // Just started |
Kweku Adams | 47db5a8 | 2016-12-09 19:04:50 -0800 | [diff] [blame] | 2338 | mStartTimeMs = mTimeBase.getRealtime(elapsedRealtimeMs * 1000) / 1000; |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2339 | } |
| 2340 | } |
| 2341 | |
| 2342 | /** |
| 2343 | * Decrements the mNesting ref-count on this timer. |
| 2344 | * |
| 2345 | * If it actually stopped (mNesting went to 0), then possibly update |
| 2346 | * mMaxDuration if the current duration was the longest ever. |
| 2347 | */ |
| 2348 | @Override |
| 2349 | public void stopRunningLocked(long elapsedRealtimeMs) { |
Kweku Adams | 47db5a8 | 2016-12-09 19:04:50 -0800 | [diff] [blame] | 2350 | if (mNesting == 1) { |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2351 | final long durationMs = getCurrentDurationMsLocked(elapsedRealtimeMs); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2352 | mTotalDurationMs += durationMs; |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2353 | if (durationMs > mMaxDurationMs) { |
| 2354 | mMaxDurationMs = durationMs; |
| 2355 | } |
| 2356 | mStartTimeMs = -1; |
| 2357 | mCurrentDurationMs = 0; |
| 2358 | } |
Kweku Adams | 47db5a8 | 2016-12-09 19:04:50 -0800 | [diff] [blame] | 2359 | // super method decrements mNesting, which getCurrentDurationMsLocked relies on, |
| 2360 | // so call super.stopRunningLocked after calling getCurrentDurationMsLocked. |
| 2361 | super.stopRunningLocked(elapsedRealtimeMs); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2362 | } |
| 2363 | |
| 2364 | @Override |
| 2365 | public boolean reset(boolean detachIfReset) { |
| 2366 | boolean result = super.reset(detachIfReset); |
| 2367 | mMaxDurationMs = 0; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2368 | mTotalDurationMs = 0; |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2369 | mCurrentDurationMs = 0; |
| 2370 | if (mNesting > 0) { |
| 2371 | mStartTimeMs = mTimeBase.getRealtime(mClocks.elapsedRealtime()*1000) / 1000; |
| 2372 | } else { |
| 2373 | mStartTimeMs = -1; |
| 2374 | } |
| 2375 | return result; |
| 2376 | } |
| 2377 | |
| 2378 | /** |
| 2379 | * Returns the max duration that this timer has ever seen. |
| 2380 | * |
| 2381 | * Note that this time is NOT split between the timers in the timer group that |
| 2382 | * this timer is attached to. It is the TOTAL time. |
| 2383 | */ |
| 2384 | @Override |
| 2385 | public long getMaxDurationMsLocked(long elapsedRealtimeMs) { |
| 2386 | if (mNesting > 0) { |
| 2387 | final long durationMs = getCurrentDurationMsLocked(elapsedRealtimeMs); |
| 2388 | if (durationMs > mMaxDurationMs) { |
| 2389 | return durationMs; |
| 2390 | } |
| 2391 | } |
| 2392 | return mMaxDurationMs; |
| 2393 | } |
| 2394 | |
| 2395 | /** |
| 2396 | * Returns the time since the timer was started. |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2397 | * Returns 0 if the timer is not currently running. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2398 | * |
| 2399 | * Note that this time is NOT split between the timers in the timer group that |
| 2400 | * this timer is attached to. It is the TOTAL time. |
jackqdyulei | 610a0a0 | 2017-08-09 14:02:01 -0700 | [diff] [blame] | 2401 | * |
| 2402 | * Note that if running timer is parceled and unparceled, this method will return |
| 2403 | * current duration value at the time of parceling even though timer may not be |
| 2404 | * currently running. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2405 | */ |
| 2406 | @Override |
| 2407 | public long getCurrentDurationMsLocked(long elapsedRealtimeMs) { |
| 2408 | long durationMs = mCurrentDurationMs; |
Kweku Adams | 47db5a8 | 2016-12-09 19:04:50 -0800 | [diff] [blame] | 2409 | if (mNesting > 0 && mTimeBase.isRunning()) { |
| 2410 | durationMs += (mTimeBase.getRealtime(elapsedRealtimeMs*1000)/1000) |
| 2411 | - mStartTimeMs; |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2412 | } |
| 2413 | return durationMs; |
| 2414 | } |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2415 | |
| 2416 | /** |
| 2417 | * Returns the total cumulative duration that this timer has been on since reset(). |
| 2418 | * If mTimerPool == null, this should be the same |
| 2419 | * as getTotalTimeLocked(elapsedRealtimeMs*1000, STATS_SINCE_CHARGED)/1000. |
| 2420 | * |
| 2421 | * Note that this time is NOT split between the timers in the timer group that |
| 2422 | * this timer is attached to. It is the TOTAL time. For this reason, if mTimerPool != null, |
| 2423 | * the result will not be equivalent to getTotalTimeLocked. |
| 2424 | */ |
| 2425 | @Override |
| 2426 | public long getTotalDurationMsLocked(long elapsedRealtimeMs) { |
| 2427 | return mTotalDurationMs + getCurrentDurationMsLocked(elapsedRealtimeMs); |
| 2428 | } |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2429 | } |
| 2430 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 2431 | /** |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2432 | * State for keeping track of timing information. |
| 2433 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2434 | public static class StopwatchTimer extends Timer { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 2435 | final Uid mUid; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2436 | final ArrayList<StopwatchTimer> mTimerPool; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 2437 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2438 | int mNesting; |
| 2439 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2440 | /** |
| 2441 | * The last time at which we updated the timer. If mNesting is > 0, |
| 2442 | * subtract this from the current battery time to find the amount of |
| 2443 | * time we have been running since we last computed an update. |
| 2444 | */ |
| 2445 | long mUpdateTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2446 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2447 | /** |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2448 | * The total time at which the timer was acquired, to determine if it |
Bookatz | ceebafe | 2017-04-06 11:59:13 -0700 | [diff] [blame] | 2449 | * was actually held for an interesting duration. If time base was not running when timer |
| 2450 | * was acquired, will be -1. |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2451 | */ |
Bookatz | ceebafe | 2017-04-06 11:59:13 -0700 | [diff] [blame] | 2452 | long mAcquireTime = -1; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2453 | |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 2454 | long mTimeout; |
| 2455 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 2456 | /** |
| 2457 | * For partial wake locks, keep track of whether we are in the list |
| 2458 | * to consume CPU cycles. |
| 2459 | */ |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 2460 | @VisibleForTesting |
| 2461 | public boolean mInList; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 2462 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2463 | public StopwatchTimer(Clocks clocks, Uid uid, int type, ArrayList<StopwatchTimer> timerPool, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2464 | TimeBase timeBase, Parcel in) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2465 | super(clocks, type, timeBase, in); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 2466 | mUid = uid; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2467 | mTimerPool = timerPool; |
| 2468 | mUpdateTime = in.readLong(); |
| 2469 | } |
| 2470 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2471 | public StopwatchTimer(Clocks clocks, Uid uid, int type, ArrayList<StopwatchTimer> timerPool, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2472 | TimeBase timeBase) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2473 | super(clocks, type, timeBase); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 2474 | mUid = uid; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2475 | mTimerPool = timerPool; |
| 2476 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2477 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2478 | public void setTimeout(long timeout) { |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 2479 | mTimeout = timeout; |
| 2480 | } |
| 2481 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2482 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
| 2483 | super.writeToParcel(out, elapsedRealtimeUs); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2484 | out.writeLong(mUpdateTime); |
| 2485 | } |
| 2486 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2487 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2488 | if (mNesting > 0) { |
| 2489 | if (DEBUG && mType < 0) { |
| 2490 | Log.v(TAG, "old mUpdateTime=" + mUpdateTime); |
| 2491 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2492 | super.onTimeStopped(elapsedRealtime, baseUptime, baseRealtime); |
| 2493 | mUpdateTime = baseRealtime; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2494 | if (DEBUG && mType < 0) { |
| 2495 | Log.v(TAG, "new mUpdateTime=" + mUpdateTime); |
| 2496 | } |
| 2497 | } |
| 2498 | } |
| 2499 | |
| 2500 | public void logState(Printer pw, String prefix) { |
| 2501 | super.logState(pw, prefix); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 2502 | pw.println(prefix + "mNesting=" + mNesting + " mUpdateTime=" + mUpdateTime |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2503 | + " mAcquireTime=" + mAcquireTime); |
| 2504 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2505 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2506 | public void startRunningLocked(long elapsedRealtimeMs) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2507 | if (mNesting++ == 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2508 | final long batteryRealtime = mTimeBase.getRealtime(elapsedRealtimeMs * 1000); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 2509 | mUpdateTime = batteryRealtime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2510 | if (mTimerPool != null) { |
| 2511 | // Accumulate time to all currently active timers before adding |
| 2512 | // this new one to the pool. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2513 | refreshTimersLocked(batteryRealtime, mTimerPool, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2514 | // Add this timer to the active pool |
| 2515 | mTimerPool.add(this); |
| 2516 | } |
Bookatz | ceebafe | 2017-04-06 11:59:13 -0700 | [diff] [blame] | 2517 | if (mTimeBase.isRunning()) { |
| 2518 | // Increment the count |
| 2519 | mCount++; |
| 2520 | mAcquireTime = mTotalTime; |
| 2521 | } else { |
| 2522 | mAcquireTime = -1; |
| 2523 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2524 | if (DEBUG && mType < 0) { |
| 2525 | Log.v(TAG, "start #" + mType + ": mUpdateTime=" + mUpdateTime |
| 2526 | + " mTotalTime=" + mTotalTime + " mCount=" + mCount |
| 2527 | + " mAcquireTime=" + mAcquireTime); |
| 2528 | } |
| 2529 | } |
| 2530 | } |
| 2531 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2532 | public boolean isRunningLocked() { |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 2533 | return mNesting > 0; |
| 2534 | } |
| 2535 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2536 | public void stopRunningLocked(long elapsedRealtimeMs) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2537 | // Ignore attempt to stop a timer that isn't running |
| 2538 | if (mNesting == 0) { |
| 2539 | return; |
| 2540 | } |
| 2541 | if (--mNesting == 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2542 | final long batteryRealtime = mTimeBase.getRealtime(elapsedRealtimeMs * 1000); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2543 | if (mTimerPool != null) { |
| 2544 | // Accumulate time to all active counters, scaled by the total |
| 2545 | // active in the pool, before taking this one out of the pool. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2546 | refreshTimersLocked(batteryRealtime, mTimerPool, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2547 | // Remove this timer from the active pool |
| 2548 | mTimerPool.remove(this); |
| 2549 | } else { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2550 | mNesting = 1; |
| 2551 | mTotalTime = computeRunTimeLocked(batteryRealtime); |
| 2552 | mNesting = 0; |
| 2553 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2554 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2555 | if (DEBUG && mType < 0) { |
| 2556 | Log.v(TAG, "stop #" + mType + ": mUpdateTime=" + mUpdateTime |
| 2557 | + " mTotalTime=" + mTotalTime + " mCount=" + mCount |
| 2558 | + " mAcquireTime=" + mAcquireTime); |
| 2559 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2560 | |
Bookatz | ceebafe | 2017-04-06 11:59:13 -0700 | [diff] [blame] | 2561 | if (mAcquireTime >= 0 && mTotalTime == mAcquireTime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2562 | // If there was no change in the time, then discard this |
| 2563 | // count. A somewhat cheezy strategy, but hey. |
| 2564 | mCount--; |
| 2565 | } |
| 2566 | } |
| 2567 | } |
| 2568 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2569 | public void stopAllRunningLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 2570 | if (mNesting > 0) { |
| 2571 | mNesting = 1; |
| 2572 | stopRunningLocked(elapsedRealtimeMs); |
| 2573 | } |
| 2574 | } |
| 2575 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2576 | // Update the total time for all other running Timers with the same type as this Timer |
| 2577 | // due to a change in timer count |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2578 | private static long refreshTimersLocked(long batteryRealtime, |
| 2579 | final ArrayList<StopwatchTimer> pool, StopwatchTimer self) { |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 2580 | long selfTime = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2581 | final int N = pool.size(); |
| 2582 | for (int i=N-1; i>= 0; i--) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2583 | final StopwatchTimer t = pool.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2584 | long heldTime = batteryRealtime - t.mUpdateTime; |
| 2585 | if (heldTime > 0) { |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 2586 | final long myTime = heldTime / N; |
| 2587 | if (t == self) { |
| 2588 | selfTime = myTime; |
| 2589 | } |
| 2590 | t.mTotalTime += myTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2591 | } |
| 2592 | t.mUpdateTime = batteryRealtime; |
| 2593 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 2594 | return selfTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2595 | } |
| 2596 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2597 | @Override |
| 2598 | protected long computeRunTimeLocked(long curBatteryRealtime) { |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 2599 | if (mTimeout > 0 && curBatteryRealtime > mUpdateTime + mTimeout) { |
| 2600 | curBatteryRealtime = mUpdateTime + mTimeout; |
| 2601 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2602 | return mTotalTime + (mNesting > 0 |
| 2603 | ? (curBatteryRealtime - mUpdateTime) |
| 2604 | / (mTimerPool != null ? mTimerPool.size() : 1) |
| 2605 | : 0); |
| 2606 | } |
| 2607 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2608 | @Override |
| 2609 | protected int computeCurrentCountLocked() { |
| 2610 | return mCount; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2611 | } |
| 2612 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 2613 | @Override |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2614 | public boolean reset(boolean detachIfReset) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2615 | boolean canDetach = mNesting <= 0; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2616 | super.reset(canDetach && detachIfReset); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2617 | if (mNesting > 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2618 | mUpdateTime = mTimeBase.getRealtime(mClocks.elapsedRealtime() * 1000); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2619 | } |
Bookatz | ceebafe | 2017-04-06 11:59:13 -0700 | [diff] [blame] | 2620 | 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] | 2621 | return canDetach; |
| 2622 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2623 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 2624 | @Override |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 2625 | @UnsupportedAppUsage |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2626 | public void detach() { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2627 | super.detach(); |
| 2628 | if (mTimerPool != null) { |
| 2629 | mTimerPool.remove(this); |
| 2630 | } |
| 2631 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2632 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 2633 | @Override |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2634 | public void readSummaryFromParcelLocked(Parcel in) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2635 | super.readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2636 | mNesting = 0; |
| 2637 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 2638 | |
| 2639 | /** |
| 2640 | * Set the mark so that we can query later for the total time the timer has |
| 2641 | * accumulated since this point. The timer can be running or not. |
| 2642 | * |
| 2643 | * @param elapsedRealtimeMs the current elapsed realtime in milliseconds. |
| 2644 | */ |
| 2645 | public void setMark(long elapsedRealtimeMs) { |
| 2646 | final long batteryRealtime = mTimeBase.getRealtime(elapsedRealtimeMs * 1000); |
| 2647 | if (mNesting > 0) { |
| 2648 | // We are running. |
| 2649 | if (mTimerPool != null) { |
| 2650 | refreshTimersLocked(batteryRealtime, mTimerPool, this); |
| 2651 | } else { |
| 2652 | mTotalTime += batteryRealtime - mUpdateTime; |
| 2653 | mUpdateTime = batteryRealtime; |
| 2654 | } |
| 2655 | } |
| 2656 | mTimeBeforeMark = mTotalTime; |
| 2657 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2658 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2659 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2660 | /** |
| 2661 | * State for keeping track of two DurationTimers with different TimeBases, presumably where one |
| 2662 | * TimeBase is effectively a subset of the other. |
| 2663 | */ |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2664 | public static class DualTimer extends DurationTimer { |
| 2665 | // This class both is a DurationTimer and also holds a second DurationTimer. |
| 2666 | // The main timer (this) typically tracks the total time. It may be pooled (but since it's a |
| 2667 | // durationTimer, it also has the unpooled getTotalDurationMsLocked() for |
| 2668 | // STATS_SINCE_CHARGED). |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2669 | // mSubTimer typically tracks only part of the total time, such as background time, as |
| 2670 | // determined by a subTimeBase. It is NOT pooled. |
| 2671 | private final DurationTimer mSubTimer; |
| 2672 | |
| 2673 | /** |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2674 | * Creates a DualTimer to hold a main timer (this) and a mSubTimer. |
| 2675 | * The main timer (this) is based on the given timeBase and timerPool. |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2676 | * 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] | 2677 | * the main timer is. |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2678 | */ |
| 2679 | public DualTimer(Clocks clocks, Uid uid, int type, ArrayList<StopwatchTimer> timerPool, |
| 2680 | TimeBase timeBase, TimeBase subTimeBase, Parcel in) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2681 | super(clocks, uid, type, timerPool, timeBase, in); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2682 | mSubTimer = new DurationTimer(clocks, uid, type, null, subTimeBase, in); |
| 2683 | } |
| 2684 | |
| 2685 | /** |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2686 | * Creates a DualTimer to hold a main timer (this) and a mSubTimer. |
| 2687 | * The main timer (this) is based on the given timeBase and timerPool. |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2688 | * 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] | 2689 | * the main timer is. |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2690 | */ |
| 2691 | public DualTimer(Clocks clocks, Uid uid, int type, ArrayList<StopwatchTimer> timerPool, |
| 2692 | TimeBase timeBase, TimeBase subTimeBase) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2693 | super(clocks, uid, type, timerPool, timeBase); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2694 | mSubTimer = new DurationTimer(clocks, uid, type, null, subTimeBase); |
| 2695 | } |
| 2696 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2697 | /** Get the secondary timer. */ |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2698 | @Override |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2699 | public DurationTimer getSubTimer() { |
| 2700 | return mSubTimer; |
| 2701 | } |
| 2702 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2703 | @Override |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2704 | public void startRunningLocked(long elapsedRealtimeMs) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2705 | super.startRunningLocked(elapsedRealtimeMs); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2706 | mSubTimer.startRunningLocked(elapsedRealtimeMs); |
| 2707 | } |
| 2708 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2709 | @Override |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2710 | public void stopRunningLocked(long elapsedRealtimeMs) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2711 | super.stopRunningLocked(elapsedRealtimeMs); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2712 | mSubTimer.stopRunningLocked(elapsedRealtimeMs); |
| 2713 | } |
| 2714 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2715 | @Override |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2716 | public void stopAllRunningLocked(long elapsedRealtimeMs) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2717 | super.stopAllRunningLocked(elapsedRealtimeMs); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2718 | mSubTimer.stopAllRunningLocked(elapsedRealtimeMs); |
| 2719 | } |
| 2720 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2721 | @Override |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2722 | public boolean reset(boolean detachIfReset) { |
| 2723 | boolean active = false; |
Bookatz | 4a3eda9 | 2017-04-10 13:10:46 -0700 | [diff] [blame] | 2724 | // Do not detach the subTimer explicitly since that'll be done by DualTimer.detach(). |
| 2725 | active |= !mSubTimer.reset(false); |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2726 | active |= !super.reset(detachIfReset); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2727 | return !active; |
| 2728 | } |
| 2729 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2730 | @Override |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2731 | public void detach() { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2732 | mSubTimer.detach(); |
Bookatz | 4a3eda9 | 2017-04-10 13:10:46 -0700 | [diff] [blame] | 2733 | super.detach(); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2734 | } |
| 2735 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2736 | @Override |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2737 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2738 | super.writeToParcel(out, elapsedRealtimeUs); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2739 | mSubTimer.writeToParcel(out, elapsedRealtimeUs); |
| 2740 | } |
| 2741 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2742 | @Override |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2743 | public void writeSummaryFromParcelLocked(Parcel out, long elapsedRealtimeUs) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2744 | super.writeSummaryFromParcelLocked(out, elapsedRealtimeUs); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2745 | mSubTimer.writeSummaryFromParcelLocked(out, elapsedRealtimeUs); |
| 2746 | } |
| 2747 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2748 | @Override |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2749 | public void readSummaryFromParcelLocked(Parcel in) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2750 | super.readSummaryFromParcelLocked(in); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2751 | mSubTimer.readSummaryFromParcelLocked(in); |
| 2752 | } |
| 2753 | } |
| 2754 | |
| 2755 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2756 | public abstract class OverflowArrayMap<T> { |
| 2757 | private static final String OVERFLOW_NAME = "*overflow*"; |
| 2758 | |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame] | 2759 | final int mUid; |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2760 | final ArrayMap<String, T> mMap = new ArrayMap<>(); |
| 2761 | T mCurOverflow; |
| 2762 | ArrayMap<String, MutableInt> mActiveOverflow; |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame] | 2763 | long mLastOverflowTime; |
| 2764 | long mLastOverflowFinishTime; |
| 2765 | long mLastClearTime; |
| 2766 | long mLastCleanupTime; |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2767 | |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame] | 2768 | public OverflowArrayMap(int uid) { |
| 2769 | mUid = uid; |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2770 | } |
| 2771 | |
| 2772 | public ArrayMap<String, T> getMap() { |
| 2773 | return mMap; |
| 2774 | } |
| 2775 | |
| 2776 | public void clear() { |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame] | 2777 | mLastClearTime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2778 | mMap.clear(); |
| 2779 | mCurOverflow = null; |
| 2780 | mActiveOverflow = null; |
| 2781 | } |
| 2782 | |
| 2783 | public void add(String name, T obj) { |
Joe Onorato | 388fc33 | 2016-04-12 17:06:47 -0700 | [diff] [blame] | 2784 | if (name == null) { |
| 2785 | name = ""; |
| 2786 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2787 | mMap.put(name, obj); |
| 2788 | if (OVERFLOW_NAME.equals(name)) { |
| 2789 | mCurOverflow = obj; |
| 2790 | } |
| 2791 | } |
| 2792 | |
| 2793 | public void cleanup() { |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame] | 2794 | mLastCleanupTime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2795 | if (mActiveOverflow != null) { |
| 2796 | if (mActiveOverflow.size() == 0) { |
| 2797 | mActiveOverflow = null; |
| 2798 | } |
| 2799 | } |
| 2800 | if (mActiveOverflow == null) { |
| 2801 | // There is no currently active overflow, so we should no longer have |
| 2802 | // an overflow entry. |
| 2803 | if (mMap.containsKey(OVERFLOW_NAME)) { |
| 2804 | Slog.wtf(TAG, "Cleaning up with no active overflow, but have overflow entry " |
| 2805 | + mMap.get(OVERFLOW_NAME)); |
| 2806 | mMap.remove(OVERFLOW_NAME); |
| 2807 | } |
| 2808 | mCurOverflow = null; |
| 2809 | } else { |
| 2810 | // There is currently active overflow, so we should still have an overflow entry. |
| 2811 | if (mCurOverflow == null || !mMap.containsKey(OVERFLOW_NAME)) { |
| 2812 | Slog.wtf(TAG, "Cleaning up with active overflow, but no overflow entry: cur=" |
| 2813 | + mCurOverflow + " map=" + mMap.get(OVERFLOW_NAME)); |
| 2814 | } |
| 2815 | } |
| 2816 | } |
| 2817 | |
| 2818 | public T startObject(String name) { |
Joe Onorato | 388fc33 | 2016-04-12 17:06:47 -0700 | [diff] [blame] | 2819 | if (name == null) { |
| 2820 | name = ""; |
| 2821 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2822 | T obj = mMap.get(name); |
| 2823 | if (obj != null) { |
| 2824 | return obj; |
| 2825 | } |
| 2826 | |
| 2827 | // No object exists for the given name, but do we currently have it |
| 2828 | // running as part of the overflow? |
| 2829 | if (mActiveOverflow != null) { |
| 2830 | MutableInt over = mActiveOverflow.get(name); |
| 2831 | if (over != null) { |
| 2832 | // We are already actively counting this name in the overflow object. |
| 2833 | obj = mCurOverflow; |
| 2834 | if (obj == null) { |
| 2835 | // Shouldn't be here, but we'll try to recover. |
| 2836 | Slog.wtf(TAG, "Have active overflow " + name + " but null overflow"); |
| 2837 | obj = mCurOverflow = instantiateObject(); |
| 2838 | mMap.put(OVERFLOW_NAME, obj); |
| 2839 | } |
| 2840 | over.value++; |
| 2841 | return obj; |
| 2842 | } |
| 2843 | } |
| 2844 | |
| 2845 | // No object exists for given name nor in the overflow; we need to make |
| 2846 | // a new one. |
| 2847 | final int N = mMap.size(); |
| 2848 | if (N >= MAX_WAKELOCKS_PER_UID) { |
| 2849 | // Went over the limit on number of objects to track; this one goes |
| 2850 | // in to the overflow. |
| 2851 | obj = mCurOverflow; |
| 2852 | if (obj == null) { |
| 2853 | // Need to start overflow now... |
| 2854 | obj = mCurOverflow = instantiateObject(); |
| 2855 | mMap.put(OVERFLOW_NAME, obj); |
| 2856 | } |
| 2857 | if (mActiveOverflow == null) { |
| 2858 | mActiveOverflow = new ArrayMap<>(); |
| 2859 | } |
| 2860 | mActiveOverflow.put(name, new MutableInt(1)); |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame] | 2861 | mLastOverflowTime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2862 | return obj; |
| 2863 | } |
| 2864 | |
| 2865 | // Normal case where we just need to make a new object. |
| 2866 | obj = instantiateObject(); |
| 2867 | mMap.put(name, obj); |
| 2868 | return obj; |
| 2869 | } |
| 2870 | |
| 2871 | public T stopObject(String name) { |
Joe Onorato | 388fc33 | 2016-04-12 17:06:47 -0700 | [diff] [blame] | 2872 | if (name == null) { |
| 2873 | name = ""; |
| 2874 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2875 | T obj = mMap.get(name); |
| 2876 | if (obj != null) { |
| 2877 | return obj; |
| 2878 | } |
| 2879 | |
| 2880 | // No object exists for the given name, but do we currently have it |
| 2881 | // running as part of the overflow? |
| 2882 | if (mActiveOverflow != null) { |
| 2883 | MutableInt over = mActiveOverflow.get(name); |
| 2884 | if (over != null) { |
| 2885 | // We are already actively counting this name in the overflow object. |
| 2886 | obj = mCurOverflow; |
| 2887 | if (obj != null) { |
| 2888 | over.value--; |
| 2889 | if (over.value <= 0) { |
| 2890 | mActiveOverflow.remove(name); |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame] | 2891 | mLastOverflowFinishTime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2892 | } |
| 2893 | return obj; |
| 2894 | } |
| 2895 | } |
| 2896 | } |
| 2897 | |
| 2898 | // Huh, they are stopping an active operation but we can't find one! |
| 2899 | // That's not good. |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame] | 2900 | StringBuilder sb = new StringBuilder(); |
| 2901 | sb.append("Unable to find object for "); |
| 2902 | sb.append(name); |
| 2903 | sb.append(" in uid "); |
| 2904 | sb.append(mUid); |
| 2905 | sb.append(" mapsize="); |
| 2906 | sb.append(mMap.size()); |
| 2907 | sb.append(" activeoverflow="); |
| 2908 | sb.append(mActiveOverflow); |
| 2909 | sb.append(" curoverflow="); |
| 2910 | sb.append(mCurOverflow); |
| 2911 | long now = SystemClock.elapsedRealtime(); |
| 2912 | if (mLastOverflowTime != 0) { |
| 2913 | sb.append(" lastOverflowTime="); |
| 2914 | TimeUtils.formatDuration(mLastOverflowTime-now, sb); |
| 2915 | } |
| 2916 | if (mLastOverflowFinishTime != 0) { |
| 2917 | sb.append(" lastOverflowFinishTime="); |
| 2918 | TimeUtils.formatDuration(mLastOverflowFinishTime-now, sb); |
| 2919 | } |
| 2920 | if (mLastClearTime != 0) { |
| 2921 | sb.append(" lastClearTime="); |
| 2922 | TimeUtils.formatDuration(mLastClearTime-now, sb); |
| 2923 | } |
| 2924 | if (mLastCleanupTime != 0) { |
| 2925 | sb.append(" lastCleanupTime="); |
| 2926 | TimeUtils.formatDuration(mLastCleanupTime-now, sb); |
| 2927 | } |
| 2928 | Slog.wtf(TAG, sb.toString()); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2929 | return null; |
| 2930 | } |
| 2931 | |
| 2932 | public abstract T instantiateObject(); |
| 2933 | } |
| 2934 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2935 | public static class ControllerActivityCounterImpl extends ControllerActivityCounter |
| 2936 | implements Parcelable { |
| 2937 | private final LongSamplingCounter mIdleTimeMillis; |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 2938 | private final LongSamplingCounter mScanTimeMillis; |
Siddharth Ray | ed75470 | 2018-02-15 12:44:37 -0800 | [diff] [blame] | 2939 | private final LongSamplingCounter mSleepTimeMillis; |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2940 | private final LongSamplingCounter mRxTimeMillis; |
| 2941 | private final LongSamplingCounter[] mTxTimeMillis; |
| 2942 | private final LongSamplingCounter mPowerDrainMaMs; |
| 2943 | |
| 2944 | public ControllerActivityCounterImpl(TimeBase timeBase, int numTxStates) { |
| 2945 | mIdleTimeMillis = new LongSamplingCounter(timeBase); |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 2946 | mScanTimeMillis = new LongSamplingCounter(timeBase); |
Siddharth Ray | ed75470 | 2018-02-15 12:44:37 -0800 | [diff] [blame] | 2947 | mSleepTimeMillis = new LongSamplingCounter(timeBase); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2948 | mRxTimeMillis = new LongSamplingCounter(timeBase); |
| 2949 | mTxTimeMillis = new LongSamplingCounter[numTxStates]; |
| 2950 | for (int i = 0; i < numTxStates; i++) { |
| 2951 | mTxTimeMillis[i] = new LongSamplingCounter(timeBase); |
| 2952 | } |
| 2953 | mPowerDrainMaMs = new LongSamplingCounter(timeBase); |
| 2954 | } |
| 2955 | |
| 2956 | public ControllerActivityCounterImpl(TimeBase timeBase, int numTxStates, Parcel in) { |
| 2957 | mIdleTimeMillis = new LongSamplingCounter(timeBase, in); |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 2958 | mScanTimeMillis = new LongSamplingCounter(timeBase, in); |
Siddharth Ray | ed75470 | 2018-02-15 12:44:37 -0800 | [diff] [blame] | 2959 | mSleepTimeMillis = new LongSamplingCounter(timeBase, in); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2960 | mRxTimeMillis = new LongSamplingCounter(timeBase, in); |
| 2961 | final int recordedTxStates = in.readInt(); |
| 2962 | if (recordedTxStates != numTxStates) { |
| 2963 | throw new ParcelFormatException("inconsistent tx state lengths"); |
| 2964 | } |
| 2965 | |
| 2966 | mTxTimeMillis = new LongSamplingCounter[numTxStates]; |
| 2967 | for (int i = 0; i < numTxStates; i++) { |
| 2968 | mTxTimeMillis[i] = new LongSamplingCounter(timeBase, in); |
| 2969 | } |
| 2970 | mPowerDrainMaMs = new LongSamplingCounter(timeBase, in); |
| 2971 | } |
| 2972 | |
| 2973 | public void readSummaryFromParcel(Parcel in) { |
| 2974 | mIdleTimeMillis.readSummaryFromParcelLocked(in); |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 2975 | mScanTimeMillis.readSummaryFromParcelLocked(in); |
Siddharth Ray | ed75470 | 2018-02-15 12:44:37 -0800 | [diff] [blame] | 2976 | mSleepTimeMillis.readSummaryFromParcelLocked(in); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2977 | mRxTimeMillis.readSummaryFromParcelLocked(in); |
| 2978 | final int recordedTxStates = in.readInt(); |
| 2979 | if (recordedTxStates != mTxTimeMillis.length) { |
| 2980 | throw new ParcelFormatException("inconsistent tx state lengths"); |
| 2981 | } |
| 2982 | for (LongSamplingCounter counter : mTxTimeMillis) { |
| 2983 | counter.readSummaryFromParcelLocked(in); |
| 2984 | } |
| 2985 | mPowerDrainMaMs.readSummaryFromParcelLocked(in); |
| 2986 | } |
| 2987 | |
| 2988 | @Override |
| 2989 | public int describeContents() { |
| 2990 | return 0; |
| 2991 | } |
| 2992 | |
| 2993 | public void writeSummaryToParcel(Parcel dest) { |
| 2994 | mIdleTimeMillis.writeSummaryFromParcelLocked(dest); |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 2995 | mScanTimeMillis.writeSummaryFromParcelLocked(dest); |
Siddharth Ray | ed75470 | 2018-02-15 12:44:37 -0800 | [diff] [blame] | 2996 | mSleepTimeMillis.writeSummaryFromParcelLocked(dest); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2997 | mRxTimeMillis.writeSummaryFromParcelLocked(dest); |
| 2998 | dest.writeInt(mTxTimeMillis.length); |
| 2999 | for (LongSamplingCounter counter : mTxTimeMillis) { |
| 3000 | counter.writeSummaryFromParcelLocked(dest); |
| 3001 | } |
| 3002 | mPowerDrainMaMs.writeSummaryFromParcelLocked(dest); |
| 3003 | } |
| 3004 | |
| 3005 | @Override |
| 3006 | public void writeToParcel(Parcel dest, int flags) { |
| 3007 | mIdleTimeMillis.writeToParcel(dest); |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 3008 | mScanTimeMillis.writeToParcel(dest); |
Siddharth Ray | ed75470 | 2018-02-15 12:44:37 -0800 | [diff] [blame] | 3009 | mSleepTimeMillis.writeToParcel(dest); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3010 | mRxTimeMillis.writeToParcel(dest); |
| 3011 | dest.writeInt(mTxTimeMillis.length); |
| 3012 | for (LongSamplingCounter counter : mTxTimeMillis) { |
| 3013 | counter.writeToParcel(dest); |
| 3014 | } |
| 3015 | mPowerDrainMaMs.writeToParcel(dest); |
| 3016 | } |
| 3017 | |
| 3018 | public void reset(boolean detachIfReset) { |
| 3019 | mIdleTimeMillis.reset(detachIfReset); |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 3020 | mScanTimeMillis.reset(detachIfReset); |
Siddharth Ray | ed75470 | 2018-02-15 12:44:37 -0800 | [diff] [blame] | 3021 | mSleepTimeMillis.reset(detachIfReset); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3022 | mRxTimeMillis.reset(detachIfReset); |
| 3023 | for (LongSamplingCounter counter : mTxTimeMillis) { |
| 3024 | counter.reset(detachIfReset); |
| 3025 | } |
| 3026 | mPowerDrainMaMs.reset(detachIfReset); |
| 3027 | } |
| 3028 | |
| 3029 | public void detach() { |
| 3030 | mIdleTimeMillis.detach(); |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 3031 | mScanTimeMillis.detach(); |
Siddharth Ray | ed75470 | 2018-02-15 12:44:37 -0800 | [diff] [blame] | 3032 | mSleepTimeMillis.detach(); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3033 | mRxTimeMillis.detach(); |
| 3034 | for (LongSamplingCounter counter : mTxTimeMillis) { |
| 3035 | counter.detach(); |
| 3036 | } |
| 3037 | mPowerDrainMaMs.detach(); |
| 3038 | } |
| 3039 | |
| 3040 | /** |
| 3041 | * @return a LongSamplingCounter, measuring time spent in the idle state in |
| 3042 | * milliseconds. |
| 3043 | */ |
| 3044 | @Override |
| 3045 | public LongSamplingCounter getIdleTimeCounter() { |
Roshan Pius | 8164330 | 2016-03-14 16:45:55 -0700 | [diff] [blame] | 3046 | return mIdleTimeMillis; |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3047 | } |
| 3048 | |
| 3049 | /** |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 3050 | * @return a LongSamplingCounter, measuring time spent in the scan state in |
| 3051 | * milliseconds. |
| 3052 | */ |
| 3053 | @Override |
| 3054 | public LongSamplingCounter getScanTimeCounter() { |
| 3055 | return mScanTimeMillis; |
| 3056 | } |
| 3057 | |
| 3058 | /** |
Siddharth Ray | ed75470 | 2018-02-15 12:44:37 -0800 | [diff] [blame] | 3059 | * @return a LongSamplingCounter, measuring time spent in the sleep state in |
| 3060 | * milliseconds. |
| 3061 | */ |
| 3062 | @Override |
| 3063 | public LongSamplingCounter getSleepTimeCounter() { |
| 3064 | return mSleepTimeMillis; |
| 3065 | } |
| 3066 | |
| 3067 | /** |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3068 | * @return a LongSamplingCounter, measuring time spent in the receive state in |
| 3069 | * milliseconds. |
| 3070 | */ |
| 3071 | @Override |
| 3072 | public LongSamplingCounter getRxTimeCounter() { |
| 3073 | return mRxTimeMillis; |
| 3074 | } |
| 3075 | |
| 3076 | /** |
| 3077 | * @return a LongSamplingCounter[], measuring time spent in various transmit states in |
| 3078 | * milliseconds. |
| 3079 | */ |
| 3080 | @Override |
| 3081 | public LongSamplingCounter[] getTxTimeCounters() { |
| 3082 | return mTxTimeMillis; |
| 3083 | } |
| 3084 | |
| 3085 | /** |
| 3086 | * @return a LongSamplingCounter, measuring power use in milli-ampere milliseconds (mAmS). |
| 3087 | */ |
| 3088 | @Override |
| 3089 | public LongSamplingCounter getPowerCounter() { |
| 3090 | return mPowerDrainMaMs; |
| 3091 | } |
| 3092 | } |
| 3093 | |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 3094 | /** Get Resource Power Manager stats. Create a new one if it doesn't already exist. */ |
| 3095 | public SamplingTimer getRpmTimerLocked(String name) { |
| 3096 | SamplingTimer rpmt = mRpmStats.get(name); |
| 3097 | if (rpmt == null) { |
| 3098 | rpmt = new SamplingTimer(mClocks, mOnBatteryTimeBase); |
| 3099 | mRpmStats.put(name, rpmt); |
| 3100 | } |
| 3101 | return rpmt; |
| 3102 | } |
| 3103 | |
| 3104 | /** Get Screen-off Resource Power Manager stats. Create new one if it doesn't already exist. */ |
| 3105 | public SamplingTimer getScreenOffRpmTimerLocked(String name) { |
| 3106 | SamplingTimer rpmt = mScreenOffRpmStats.get(name); |
| 3107 | if (rpmt == null) { |
| 3108 | rpmt = new SamplingTimer(mClocks, mOnBatteryScreenOffTimeBase); |
| 3109 | mScreenOffRpmStats.put(name, rpmt); |
| 3110 | } |
| 3111 | return rpmt; |
| 3112 | } |
| 3113 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3114 | /* |
| 3115 | * Get the wakeup reason counter, and create a new one if one |
| 3116 | * doesn't already exist. |
| 3117 | */ |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 3118 | public SamplingTimer getWakeupReasonTimerLocked(String name) { |
| 3119 | SamplingTimer timer = mWakeupReasonStats.get(name); |
| 3120 | if (timer == null) { |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 3121 | timer = new SamplingTimer(mClocks, mOnBatteryTimeBase); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 3122 | mWakeupReasonStats.put(name, timer); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3123 | } |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 3124 | return timer; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3125 | } |
| 3126 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 3127 | /* |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3128 | * 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] | 3129 | * doesn't already exist. |
| 3130 | */ |
| 3131 | public SamplingTimer getKernelWakelockTimerLocked(String name) { |
| 3132 | SamplingTimer kwlt = mKernelWakelockStats.get(name); |
| 3133 | if (kwlt == null) { |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 3134 | kwlt = new SamplingTimer(mClocks, mOnBatteryScreenOffTimeBase); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 3135 | mKernelWakelockStats.put(name, kwlt); |
| 3136 | } |
| 3137 | return kwlt; |
| 3138 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 3139 | |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 3140 | public SamplingTimer getKernelMemoryTimerLocked(long bucket) { |
| 3141 | SamplingTimer kmt = mKernelMemoryStats.get(bucket); |
| 3142 | if (kmt == null) { |
| 3143 | kmt = new SamplingTimer(mClocks, mOnBatteryTimeBase); |
| 3144 | mKernelMemoryStats.put(bucket, kmt); |
| 3145 | } |
| 3146 | return kmt; |
| 3147 | } |
| 3148 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3149 | private int writeHistoryTag(HistoryTag tag) { |
| 3150 | Integer idxObj = mHistoryTagPool.get(tag); |
| 3151 | int idx; |
| 3152 | if (idxObj != null) { |
| 3153 | idx = idxObj; |
| 3154 | } else { |
| 3155 | idx = mNextHistoryTagIdx; |
| 3156 | HistoryTag key = new HistoryTag(); |
| 3157 | key.setTo(tag); |
| 3158 | tag.poolIdx = idx; |
| 3159 | mHistoryTagPool.put(key, idx); |
| 3160 | mNextHistoryTagIdx++; |
| 3161 | mNumHistoryTagChars += key.string.length() + 1; |
| 3162 | } |
| 3163 | return idx; |
| 3164 | } |
| 3165 | |
| 3166 | private void readHistoryTag(int index, HistoryTag tag) { |
| 3167 | tag.string = mReadHistoryStrings[index]; |
| 3168 | tag.uid = mReadHistoryUids[index]; |
| 3169 | tag.poolIdx = index; |
| 3170 | } |
| 3171 | |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 3172 | /* |
| 3173 | The history delta format uses flags to denote further data in subsequent ints in the parcel. |
| 3174 | |
| 3175 | There is always the first token, which may contain the delta time, or an indicator of |
| 3176 | the length of the time (int or long) following this token. |
| 3177 | |
| 3178 | First token: always present, |
| 3179 | 31 23 15 7 0 |
| 3180 | â–ˆ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â–ˆ |
| 3181 | |
| 3182 | T: the delta time if it is <= 0x7fffd. Otherwise 0x7fffe indicates an int immediately |
| 3183 | follows containing the time, and 0x7ffff indicates a long immediately follows with the |
| 3184 | delta time. |
| 3185 | A: battery level changed and an int follows with battery data. |
| 3186 | B: state changed and an int follows with state change data. |
| 3187 | C: state2 has changed and an int follows with state2 change data. |
| 3188 | D: wakelock/wakereason has changed and an wakelock/wakereason struct follows. |
| 3189 | E: event data has changed and an event struct follows. |
| 3190 | F: battery charge in coulombs has changed and an int with the charge follows. |
| 3191 | G: state flag denoting that the mobile radio was active. |
| 3192 | H: state flag denoting that the wifi radio was active. |
| 3193 | I: state flag denoting that a wifi scan occurred. |
| 3194 | J: state flag denoting that a wifi full lock was held. |
| 3195 | K: state flag denoting that the gps was on. |
| 3196 | L: state flag denoting that a wakelock was held. |
| 3197 | M: state flag denoting that the cpu was running. |
| 3198 | |
| 3199 | Time int/long: if T in the first token is 0x7ffff or 0x7fffe, then an int or long follows |
| 3200 | with the time delta. |
| 3201 | |
| 3202 | Battery level int: if A in the first token is set, |
| 3203 | 31 23 15 7 0 |
| 3204 | â–ˆ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â–ˆ |
| 3205 | |
| 3206 | D: indicates that extra history details follow. |
| 3207 | V: the battery voltage. |
| 3208 | T: the battery temperature. |
| 3209 | L: the battery level (out of 100). |
| 3210 | |
| 3211 | State change int: if B in the first token is set, |
| 3212 | 31 23 15 7 0 |
| 3213 | â–ˆS|S|S|H|H|H|P|Pâ–ˆF|E|D|C|B| | |Aâ–ˆ | | | | | | | â–ˆ | | | | | | | â–ˆ |
| 3214 | |
| 3215 | A: wifi multicast was on. |
| 3216 | B: battery was plugged in. |
| 3217 | C: screen was on. |
| 3218 | D: phone was scanning for signal. |
| 3219 | E: audio was on. |
| 3220 | F: a sensor was active. |
| 3221 | |
| 3222 | State2 change int: if C in the first token is set, |
| 3223 | 31 23 15 7 0 |
| 3224 | â–ˆM|L|K|J|I|H|H|Gâ–ˆF|E|D|C| | | | â–ˆ | | | | | | | â–ˆ |B|B|B|A|A|A|Aâ–ˆ |
| 3225 | |
| 3226 | A: 4 bits indicating the wifi supplicant state: {@link BatteryStats#WIFI_SUPPL_STATE_NAMES}. |
| 3227 | B: 3 bits indicating the wifi signal strength: 0, 1, 2, 3, 4. |
| 3228 | C: a bluetooth scan was active. |
| 3229 | D: the camera was active. |
| 3230 | E: bluetooth was on. |
| 3231 | F: a phone call was active. |
| 3232 | G: the device was charging. |
| 3233 | H: 2 bits indicating the device-idle (doze) state: off, light, full |
| 3234 | I: the flashlight was on. |
| 3235 | J: wifi was on. |
| 3236 | K: wifi was running. |
| 3237 | L: video was playing. |
| 3238 | M: power save mode was on. |
| 3239 | |
| 3240 | Wakelock/wakereason struct: if D in the first token is set, |
| 3241 | TODO(adamlesinski): describe wakelock/wakereason struct. |
| 3242 | |
| 3243 | Event struct: if E in the first token is set, |
| 3244 | TODO(adamlesinski): describe the event struct. |
| 3245 | |
| 3246 | History step details struct: if D in the battery level int is set, |
| 3247 | TODO(adamlesinski): describe the history step details struct. |
| 3248 | |
| 3249 | Battery charge int: if F in the first token is set, an int representing the battery charge |
| 3250 | in coulombs follows. |
| 3251 | */ |
| 3252 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3253 | // Part of initial delta int that specifies the time delta. |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 3254 | static final int DELTA_TIME_MASK = 0x7ffff; |
| 3255 | static final int DELTA_TIME_LONG = 0x7ffff; // The delta is a following long |
| 3256 | static final int DELTA_TIME_INT = 0x7fffe; // The delta is a following int |
| 3257 | 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] | 3258 | // Flag in delta int: a new battery level int follows. |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 3259 | static final int DELTA_BATTERY_LEVEL_FLAG = 0x00080000; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3260 | // 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] | 3261 | static final int DELTA_STATE_FLAG = 0x00100000; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 3262 | // Flag in delta int: a new full state2 int follows. |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 3263 | static final int DELTA_STATE2_FLAG = 0x00200000; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3264 | // Flag in delta int: contains a wakelock or wakeReason tag. |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 3265 | static final int DELTA_WAKELOCK_FLAG = 0x00400000; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3266 | // Flag in delta int: contains an event description. |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 3267 | static final int DELTA_EVENT_FLAG = 0x00800000; |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 3268 | // Flag in delta int: contains the battery charge count in uAh. |
| 3269 | static final int DELTA_BATTERY_CHARGE_FLAG = 0x01000000; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3270 | // These upper bits are the frequently changing state bits. |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 3271 | static final int DELTA_STATE_MASK = 0xfe000000; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 3272 | |
| 3273 | // These are the pieces of battery state that are packed in to the upper bits of |
| 3274 | // 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] | 3275 | // in STATE_BATTERY_MASK. |
| 3276 | static final int STATE_BATTERY_MASK = 0xff000000; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 3277 | static final int STATE_BATTERY_STATUS_MASK = 0x00000007; |
| 3278 | static final int STATE_BATTERY_STATUS_SHIFT = 29; |
| 3279 | static final int STATE_BATTERY_HEALTH_MASK = 0x00000007; |
| 3280 | static final int STATE_BATTERY_HEALTH_SHIFT = 26; |
| 3281 | static final int STATE_BATTERY_PLUG_MASK = 0x00000003; |
| 3282 | static final int STATE_BATTERY_PLUG_SHIFT = 24; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3283 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 3284 | // We use the low bit of the battery state int to indicate that we have full details |
| 3285 | // from a battery level change. |
| 3286 | static final int BATTERY_DELTA_LEVEL_FLAG = 0x00000001; |
| 3287 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3288 | public void writeHistoryDelta(Parcel dest, HistoryItem cur, HistoryItem last) { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3289 | if (last == null || cur.cmd != HistoryItem.CMD_UPDATE) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3290 | dest.writeInt(DELTA_TIME_ABS); |
| 3291 | cur.writeToParcel(dest, 0); |
| 3292 | return; |
| 3293 | } |
| 3294 | |
| 3295 | final long deltaTime = cur.time - last.time; |
| 3296 | final int lastBatteryLevelInt = buildBatteryLevelInt(last); |
| 3297 | final int lastStateInt = buildStateInt(last); |
| 3298 | |
| 3299 | int deltaTimeToken; |
| 3300 | if (deltaTime < 0 || deltaTime > Integer.MAX_VALUE) { |
| 3301 | deltaTimeToken = DELTA_TIME_LONG; |
| 3302 | } else if (deltaTime >= DELTA_TIME_ABS) { |
| 3303 | deltaTimeToken = DELTA_TIME_INT; |
| 3304 | } else { |
| 3305 | deltaTimeToken = (int)deltaTime; |
| 3306 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3307 | int firstToken = deltaTimeToken | (cur.states&DELTA_STATE_MASK); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 3308 | final int includeStepDetails = mLastHistoryStepLevel > cur.batteryLevel |
| 3309 | ? BATTERY_DELTA_LEVEL_FLAG : 0; |
| 3310 | final boolean computeStepDetails = includeStepDetails != 0 |
| 3311 | || mLastHistoryStepDetails == null; |
| 3312 | final int batteryLevelInt = buildBatteryLevelInt(cur) | includeStepDetails; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3313 | final boolean batteryLevelIntChanged = batteryLevelInt != lastBatteryLevelInt; |
| 3314 | if (batteryLevelIntChanged) { |
| 3315 | firstToken |= DELTA_BATTERY_LEVEL_FLAG; |
| 3316 | } |
| 3317 | final int stateInt = buildStateInt(cur); |
| 3318 | final boolean stateIntChanged = stateInt != lastStateInt; |
| 3319 | if (stateIntChanged) { |
| 3320 | firstToken |= DELTA_STATE_FLAG; |
| 3321 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3322 | final boolean state2IntChanged = cur.states2 != last.states2; |
| 3323 | if (state2IntChanged) { |
| 3324 | firstToken |= DELTA_STATE2_FLAG; |
| 3325 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3326 | if (cur.wakelockTag != null || cur.wakeReasonTag != null) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3327 | firstToken |= DELTA_WAKELOCK_FLAG; |
| 3328 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3329 | if (cur.eventCode != HistoryItem.EVENT_NONE) { |
| 3330 | firstToken |= DELTA_EVENT_FLAG; |
| 3331 | } |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 3332 | |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 3333 | final boolean batteryChargeChanged = cur.batteryChargeUAh != last.batteryChargeUAh; |
| 3334 | if (batteryChargeChanged) { |
| 3335 | firstToken |= DELTA_BATTERY_CHARGE_FLAG; |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 3336 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3337 | dest.writeInt(firstToken); |
| 3338 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: firstToken=0x" + Integer.toHexString(firstToken) |
| 3339 | + " deltaTime=" + deltaTime); |
| 3340 | |
| 3341 | if (deltaTimeToken >= DELTA_TIME_INT) { |
| 3342 | if (deltaTimeToken == DELTA_TIME_INT) { |
| 3343 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: int deltaTime=" + (int)deltaTime); |
| 3344 | dest.writeInt((int)deltaTime); |
| 3345 | } else { |
| 3346 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: long deltaTime=" + deltaTime); |
| 3347 | dest.writeLong(deltaTime); |
| 3348 | } |
| 3349 | } |
| 3350 | if (batteryLevelIntChanged) { |
| 3351 | dest.writeInt(batteryLevelInt); |
| 3352 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: batteryToken=0x" |
| 3353 | + Integer.toHexString(batteryLevelInt) |
| 3354 | + " batteryLevel=" + cur.batteryLevel |
| 3355 | + " batteryTemp=" + cur.batteryTemperature |
| 3356 | + " batteryVolt=" + (int)cur.batteryVoltage); |
| 3357 | } |
| 3358 | if (stateIntChanged) { |
| 3359 | dest.writeInt(stateInt); |
| 3360 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: stateToken=0x" |
| 3361 | + Integer.toHexString(stateInt) |
| 3362 | + " batteryStatus=" + cur.batteryStatus |
| 3363 | + " batteryHealth=" + cur.batteryHealth |
| 3364 | + " batteryPlugType=" + cur.batteryPlugType |
| 3365 | + " states=0x" + Integer.toHexString(cur.states)); |
| 3366 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3367 | if (state2IntChanged) { |
| 3368 | dest.writeInt(cur.states2); |
| 3369 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: states2=0x" |
| 3370 | + Integer.toHexString(cur.states2)); |
| 3371 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3372 | if (cur.wakelockTag != null || cur.wakeReasonTag != null) { |
| 3373 | int wakeLockIndex; |
| 3374 | int wakeReasonIndex; |
| 3375 | if (cur.wakelockTag != null) { |
| 3376 | wakeLockIndex = writeHistoryTag(cur.wakelockTag); |
| 3377 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: wakelockTag=#" + cur.wakelockTag.poolIdx |
| 3378 | + " " + cur.wakelockTag.uid + ":" + cur.wakelockTag.string); |
| 3379 | } else { |
| 3380 | wakeLockIndex = 0xffff; |
| 3381 | } |
| 3382 | if (cur.wakeReasonTag != null) { |
| 3383 | wakeReasonIndex = writeHistoryTag(cur.wakeReasonTag); |
| 3384 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: wakeReasonTag=#" + cur.wakeReasonTag.poolIdx |
| 3385 | + " " + cur.wakeReasonTag.uid + ":" + cur.wakeReasonTag.string); |
| 3386 | } else { |
| 3387 | wakeReasonIndex = 0xffff; |
| 3388 | } |
| 3389 | dest.writeInt((wakeReasonIndex<<16) | wakeLockIndex); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3390 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3391 | if (cur.eventCode != HistoryItem.EVENT_NONE) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3392 | int index = writeHistoryTag(cur.eventTag); |
| 3393 | int codeAndIndex = (cur.eventCode&0xffff) | (index<<16); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3394 | dest.writeInt(codeAndIndex); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3395 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: event=" + cur.eventCode + " tag=#" |
| 3396 | + cur.eventTag.poolIdx + " " + cur.eventTag.uid + ":" |
| 3397 | + cur.eventTag.string); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3398 | } |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 3399 | if (computeStepDetails) { |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 3400 | if (mPlatformIdleStateCallback != null) { |
| 3401 | mCurHistoryStepDetails.statPlatformIdleState = |
| 3402 | mPlatformIdleStateCallback.getPlatformLowPowerStats(); |
| 3403 | if (DEBUG) Slog.i(TAG, "WRITE PlatformIdleState:" + |
| 3404 | mCurHistoryStepDetails.statPlatformIdleState); |
Ahmed ElArabawy | d8b4411 | 2017-05-23 21:25:02 +0000 | [diff] [blame] | 3405 | |
| 3406 | mCurHistoryStepDetails.statSubsystemPowerState = |
| 3407 | mPlatformIdleStateCallback.getSubsystemLowPowerStats(); |
| 3408 | if (DEBUG) Slog.i(TAG, "WRITE SubsystemPowerState:" + |
| 3409 | mCurHistoryStepDetails.statSubsystemPowerState); |
| 3410 | |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 3411 | } |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 3412 | computeHistoryStepDetails(mCurHistoryStepDetails, mLastHistoryStepDetails); |
| 3413 | if (includeStepDetails != 0) { |
| 3414 | mCurHistoryStepDetails.writeToParcel(dest); |
| 3415 | } |
| 3416 | cur.stepDetails = mCurHistoryStepDetails; |
| 3417 | mLastHistoryStepDetails = mCurHistoryStepDetails; |
| 3418 | } else { |
| 3419 | cur.stepDetails = null; |
| 3420 | } |
| 3421 | if (mLastHistoryStepLevel < cur.batteryLevel) { |
| 3422 | mLastHistoryStepDetails = null; |
| 3423 | } |
| 3424 | mLastHistoryStepLevel = cur.batteryLevel; |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 3425 | |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 3426 | if (batteryChargeChanged) { |
| 3427 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: batteryChargeUAh=" + cur.batteryChargeUAh); |
| 3428 | dest.writeInt(cur.batteryChargeUAh); |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 3429 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3430 | } |
| 3431 | |
| 3432 | private int buildBatteryLevelInt(HistoryItem h) { |
| 3433 | return ((((int)h.batteryLevel)<<25)&0xfe000000) |
Adam Lesinski | 3944c81 | 2015-11-13 15:54:59 -0800 | [diff] [blame] | 3434 | | ((((int)h.batteryTemperature)<<15)&0x01ff8000) |
| 3435 | | ((((int)h.batteryVoltage)<<1)&0x00007ffe); |
| 3436 | } |
| 3437 | |
| 3438 | private void readBatteryLevelInt(int batteryLevelInt, HistoryItem out) { |
| 3439 | out.batteryLevel = (byte)((batteryLevelInt & 0xfe000000) >>> 25); |
| 3440 | out.batteryTemperature = (short)((batteryLevelInt & 0x01ff8000) >>> 15); |
| 3441 | out.batteryVoltage = (char)((batteryLevelInt & 0x00007ffe) >>> 1); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3442 | } |
| 3443 | |
| 3444 | private int buildStateInt(HistoryItem h) { |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 3445 | int plugType = 0; |
| 3446 | if ((h.batteryPlugType&BatteryManager.BATTERY_PLUGGED_AC) != 0) { |
| 3447 | plugType = 1; |
| 3448 | } else if ((h.batteryPlugType&BatteryManager.BATTERY_PLUGGED_USB) != 0) { |
| 3449 | plugType = 2; |
| 3450 | } else if ((h.batteryPlugType&BatteryManager.BATTERY_PLUGGED_WIRELESS) != 0) { |
| 3451 | plugType = 3; |
| 3452 | } |
| 3453 | return ((h.batteryStatus&STATE_BATTERY_STATUS_MASK)<<STATE_BATTERY_STATUS_SHIFT) |
| 3454 | | ((h.batteryHealth&STATE_BATTERY_HEALTH_MASK)<<STATE_BATTERY_HEALTH_SHIFT) |
| 3455 | | ((plugType&STATE_BATTERY_PLUG_MASK)<<STATE_BATTERY_PLUG_SHIFT) |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 3456 | | (h.states&(~STATE_BATTERY_MASK)); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3457 | } |
| 3458 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 3459 | private void computeHistoryStepDetails(final HistoryStepDetails out, |
| 3460 | final HistoryStepDetails last) { |
| 3461 | final HistoryStepDetails tmp = last != null ? mTmpHistoryStepDetails : out; |
| 3462 | |
| 3463 | // Perform a CPU update right after we do this collection, so we have started |
| 3464 | // collecting good data for the next step. |
| 3465 | requestImmediateCpuUpdate(); |
| 3466 | |
| 3467 | if (last == null) { |
| 3468 | // We are not generating a delta, so all we need to do is reset the stats |
| 3469 | // we will later be doing a delta from. |
| 3470 | final int NU = mUidStats.size(); |
| 3471 | for (int i=0; i<NU; i++) { |
| 3472 | final BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 3473 | uid.mLastStepUserTime = uid.mCurStepUserTime; |
| 3474 | uid.mLastStepSystemTime = uid.mCurStepSystemTime; |
| 3475 | } |
| 3476 | mLastStepCpuUserTime = mCurStepCpuUserTime; |
| 3477 | mLastStepCpuSystemTime = mCurStepCpuSystemTime; |
| 3478 | mLastStepStatUserTime = mCurStepStatUserTime; |
| 3479 | mLastStepStatSystemTime = mCurStepStatSystemTime; |
| 3480 | mLastStepStatIOWaitTime = mCurStepStatIOWaitTime; |
| 3481 | mLastStepStatIrqTime = mCurStepStatIrqTime; |
| 3482 | mLastStepStatSoftIrqTime = mCurStepStatSoftIrqTime; |
| 3483 | mLastStepStatIdleTime = mCurStepStatIdleTime; |
| 3484 | tmp.clear(); |
| 3485 | return; |
| 3486 | } |
| 3487 | if (DEBUG) { |
| 3488 | Slog.d(TAG, "Step stats last: user=" + mLastStepCpuUserTime + " sys=" |
| 3489 | + mLastStepStatSystemTime + " io=" + mLastStepStatIOWaitTime |
| 3490 | + " irq=" + mLastStepStatIrqTime + " sirq=" |
| 3491 | + mLastStepStatSoftIrqTime + " idle=" + mLastStepStatIdleTime); |
| 3492 | Slog.d(TAG, "Step stats cur: user=" + mCurStepCpuUserTime + " sys=" |
| 3493 | + mCurStepStatSystemTime + " io=" + mCurStepStatIOWaitTime |
| 3494 | + " irq=" + mCurStepStatIrqTime + " sirq=" |
| 3495 | + mCurStepStatSoftIrqTime + " idle=" + mCurStepStatIdleTime); |
| 3496 | } |
| 3497 | out.userTime = (int)(mCurStepCpuUserTime - mLastStepCpuUserTime); |
| 3498 | out.systemTime = (int)(mCurStepCpuSystemTime - mLastStepCpuSystemTime); |
| 3499 | out.statUserTime = (int)(mCurStepStatUserTime - mLastStepStatUserTime); |
| 3500 | out.statSystemTime = (int)(mCurStepStatSystemTime - mLastStepStatSystemTime); |
| 3501 | out.statIOWaitTime = (int)(mCurStepStatIOWaitTime - mLastStepStatIOWaitTime); |
| 3502 | out.statIrqTime = (int)(mCurStepStatIrqTime - mLastStepStatIrqTime); |
| 3503 | out.statSoftIrqTime = (int)(mCurStepStatSoftIrqTime - mLastStepStatSoftIrqTime); |
| 3504 | out.statIdlTime = (int)(mCurStepStatIdleTime - mLastStepStatIdleTime); |
| 3505 | out.appCpuUid1 = out.appCpuUid2 = out.appCpuUid3 = -1; |
| 3506 | out.appCpuUTime1 = out.appCpuUTime2 = out.appCpuUTime3 = 0; |
| 3507 | out.appCpuSTime1 = out.appCpuSTime2 = out.appCpuSTime3 = 0; |
| 3508 | final int NU = mUidStats.size(); |
| 3509 | for (int i=0; i<NU; i++) { |
| 3510 | final BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 3511 | final int totalUTime = (int)(uid.mCurStepUserTime - uid.mLastStepUserTime); |
| 3512 | final int totalSTime = (int)(uid.mCurStepSystemTime - uid.mLastStepSystemTime); |
| 3513 | final int totalTime = totalUTime + totalSTime; |
| 3514 | uid.mLastStepUserTime = uid.mCurStepUserTime; |
| 3515 | uid.mLastStepSystemTime = uid.mCurStepSystemTime; |
| 3516 | if (totalTime <= (out.appCpuUTime3+out.appCpuSTime3)) { |
| 3517 | continue; |
| 3518 | } |
| 3519 | if (totalTime <= (out.appCpuUTime2+out.appCpuSTime2)) { |
| 3520 | out.appCpuUid3 = uid.mUid; |
| 3521 | out.appCpuUTime3 = totalUTime; |
| 3522 | out.appCpuSTime3 = totalSTime; |
| 3523 | } else { |
| 3524 | out.appCpuUid3 = out.appCpuUid2; |
| 3525 | out.appCpuUTime3 = out.appCpuUTime2; |
| 3526 | out.appCpuSTime3 = out.appCpuSTime2; |
| 3527 | if (totalTime <= (out.appCpuUTime1+out.appCpuSTime1)) { |
| 3528 | out.appCpuUid2 = uid.mUid; |
| 3529 | out.appCpuUTime2 = totalUTime; |
| 3530 | out.appCpuSTime2 = totalSTime; |
| 3531 | } else { |
| 3532 | out.appCpuUid2 = out.appCpuUid1; |
| 3533 | out.appCpuUTime2 = out.appCpuUTime1; |
| 3534 | out.appCpuSTime2 = out.appCpuSTime1; |
| 3535 | out.appCpuUid1 = uid.mUid; |
| 3536 | out.appCpuUTime1 = totalUTime; |
| 3537 | out.appCpuSTime1 = totalSTime; |
| 3538 | } |
| 3539 | } |
| 3540 | } |
| 3541 | mLastStepCpuUserTime = mCurStepCpuUserTime; |
| 3542 | mLastStepCpuSystemTime = mCurStepCpuSystemTime; |
| 3543 | mLastStepStatUserTime = mCurStepStatUserTime; |
| 3544 | mLastStepStatSystemTime = mCurStepStatSystemTime; |
| 3545 | mLastStepStatIOWaitTime = mCurStepStatIOWaitTime; |
| 3546 | mLastStepStatIrqTime = mCurStepStatIrqTime; |
| 3547 | mLastStepStatSoftIrqTime = mCurStepStatSoftIrqTime; |
| 3548 | mLastStepStatIdleTime = mCurStepStatIdleTime; |
| 3549 | } |
| 3550 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3551 | public void readHistoryDelta(Parcel src, HistoryItem cur) { |
| 3552 | int firstToken = src.readInt(); |
| 3553 | int deltaTimeToken = firstToken&DELTA_TIME_MASK; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3554 | cur.cmd = HistoryItem.CMD_UPDATE; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3555 | cur.numReadInts = 1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3556 | if (DEBUG) Slog.i(TAG, "READ DELTA: firstToken=0x" + Integer.toHexString(firstToken) |
| 3557 | + " deltaTimeToken=" + deltaTimeToken); |
| 3558 | |
| 3559 | if (deltaTimeToken < DELTA_TIME_ABS) { |
| 3560 | cur.time += deltaTimeToken; |
| 3561 | } else if (deltaTimeToken == DELTA_TIME_ABS) { |
| 3562 | cur.time = src.readLong(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3563 | cur.numReadInts += 2; |
| 3564 | if (DEBUG) Slog.i(TAG, "READ DELTA: ABS time=" + cur.time); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3565 | cur.readFromParcel(src); |
| 3566 | return; |
| 3567 | } else if (deltaTimeToken == DELTA_TIME_INT) { |
| 3568 | int delta = src.readInt(); |
| 3569 | cur.time += delta; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3570 | cur.numReadInts += 1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3571 | if (DEBUG) Slog.i(TAG, "READ DELTA: time delta=" + delta + " new time=" + cur.time); |
| 3572 | } else { |
| 3573 | long delta = src.readLong(); |
| 3574 | if (DEBUG) Slog.i(TAG, "READ DELTA: time delta=" + delta + " new time=" + cur.time); |
| 3575 | cur.time += delta; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3576 | cur.numReadInts += 2; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3577 | } |
| 3578 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 3579 | final int batteryLevelInt; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3580 | if ((firstToken&DELTA_BATTERY_LEVEL_FLAG) != 0) { |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 3581 | batteryLevelInt = src.readInt(); |
Adam Lesinski | 3944c81 | 2015-11-13 15:54:59 -0800 | [diff] [blame] | 3582 | readBatteryLevelInt(batteryLevelInt, cur); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3583 | cur.numReadInts += 1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3584 | if (DEBUG) Slog.i(TAG, "READ DELTA: batteryToken=0x" |
| 3585 | + Integer.toHexString(batteryLevelInt) |
| 3586 | + " batteryLevel=" + cur.batteryLevel |
| 3587 | + " batteryTemp=" + cur.batteryTemperature |
| 3588 | + " batteryVolt=" + (int)cur.batteryVoltage); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 3589 | } else { |
| 3590 | batteryLevelInt = 0; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3591 | } |
| 3592 | |
| 3593 | if ((firstToken&DELTA_STATE_FLAG) != 0) { |
| 3594 | int stateInt = src.readInt(); |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 3595 | cur.states = (firstToken&DELTA_STATE_MASK) | (stateInt&(~STATE_BATTERY_MASK)); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 3596 | cur.batteryStatus = (byte)((stateInt>>STATE_BATTERY_STATUS_SHIFT) |
| 3597 | & STATE_BATTERY_STATUS_MASK); |
| 3598 | cur.batteryHealth = (byte)((stateInt>>STATE_BATTERY_HEALTH_SHIFT) |
| 3599 | & STATE_BATTERY_HEALTH_MASK); |
| 3600 | cur.batteryPlugType = (byte)((stateInt>>STATE_BATTERY_PLUG_SHIFT) |
| 3601 | & STATE_BATTERY_PLUG_MASK); |
| 3602 | switch (cur.batteryPlugType) { |
| 3603 | case 1: |
| 3604 | cur.batteryPlugType = BatteryManager.BATTERY_PLUGGED_AC; |
| 3605 | break; |
| 3606 | case 2: |
| 3607 | cur.batteryPlugType = BatteryManager.BATTERY_PLUGGED_USB; |
| 3608 | break; |
| 3609 | case 3: |
| 3610 | cur.batteryPlugType = BatteryManager.BATTERY_PLUGGED_WIRELESS; |
| 3611 | break; |
| 3612 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3613 | cur.numReadInts += 1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3614 | if (DEBUG) Slog.i(TAG, "READ DELTA: stateToken=0x" |
| 3615 | + Integer.toHexString(stateInt) |
| 3616 | + " batteryStatus=" + cur.batteryStatus |
| 3617 | + " batteryHealth=" + cur.batteryHealth |
| 3618 | + " batteryPlugType=" + cur.batteryPlugType |
| 3619 | + " states=0x" + Integer.toHexString(cur.states)); |
| 3620 | } else { |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 3621 | cur.states = (firstToken&DELTA_STATE_MASK) | (cur.states&(~STATE_BATTERY_MASK)); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3622 | } |
| 3623 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3624 | if ((firstToken&DELTA_STATE2_FLAG) != 0) { |
| 3625 | cur.states2 = src.readInt(); |
| 3626 | if (DEBUG) Slog.i(TAG, "READ DELTA: states2=0x" |
| 3627 | + Integer.toHexString(cur.states2)); |
| 3628 | } |
| 3629 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3630 | if ((firstToken&DELTA_WAKELOCK_FLAG) != 0) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3631 | int indexes = src.readInt(); |
| 3632 | int wakeLockIndex = indexes&0xffff; |
| 3633 | int wakeReasonIndex = (indexes>>16)&0xffff; |
| 3634 | if (wakeLockIndex != 0xffff) { |
| 3635 | cur.wakelockTag = cur.localWakelockTag; |
| 3636 | readHistoryTag(wakeLockIndex, cur.wakelockTag); |
| 3637 | if (DEBUG) Slog.i(TAG, "READ DELTA: wakelockTag=#" + cur.wakelockTag.poolIdx |
| 3638 | + " " + cur.wakelockTag.uid + ":" + cur.wakelockTag.string); |
| 3639 | } else { |
| 3640 | cur.wakelockTag = null; |
| 3641 | } |
| 3642 | if (wakeReasonIndex != 0xffff) { |
| 3643 | cur.wakeReasonTag = cur.localWakeReasonTag; |
| 3644 | readHistoryTag(wakeReasonIndex, cur.wakeReasonTag); |
| 3645 | if (DEBUG) Slog.i(TAG, "READ DELTA: wakeReasonTag=#" + cur.wakeReasonTag.poolIdx |
| 3646 | + " " + cur.wakeReasonTag.uid + ":" + cur.wakeReasonTag.string); |
| 3647 | } else { |
| 3648 | cur.wakeReasonTag = null; |
| 3649 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3650 | cur.numReadInts += 1; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3651 | } else { |
| 3652 | cur.wakelockTag = null; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3653 | cur.wakeReasonTag = null; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3654 | } |
| 3655 | |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3656 | if ((firstToken&DELTA_EVENT_FLAG) != 0) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3657 | cur.eventTag = cur.localEventTag; |
| 3658 | final int codeAndIndex = src.readInt(); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3659 | cur.eventCode = (codeAndIndex&0xffff); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3660 | final int index = ((codeAndIndex>>16)&0xffff); |
| 3661 | readHistoryTag(index, cur.eventTag); |
| 3662 | cur.numReadInts += 1; |
| 3663 | if (DEBUG) Slog.i(TAG, "READ DELTA: event=" + cur.eventCode + " tag=#" |
| 3664 | + cur.eventTag.poolIdx + " " + cur.eventTag.uid + ":" |
| 3665 | + cur.eventTag.string); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3666 | } else { |
| 3667 | cur.eventCode = HistoryItem.EVENT_NONE; |
| 3668 | } |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 3669 | |
| 3670 | if ((batteryLevelInt&BATTERY_DELTA_LEVEL_FLAG) != 0) { |
| 3671 | cur.stepDetails = mReadHistoryStepDetails; |
| 3672 | cur.stepDetails.readFromParcel(src); |
| 3673 | } else { |
| 3674 | cur.stepDetails = null; |
| 3675 | } |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 3676 | |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 3677 | if ((firstToken&DELTA_BATTERY_CHARGE_FLAG) != 0) { |
| 3678 | cur.batteryChargeUAh = src.readInt(); |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 3679 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3680 | } |
| 3681 | |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 3682 | @Override |
| 3683 | public void commitCurrentHistoryBatchLocked() { |
| 3684 | mHistoryLastWritten.cmd = HistoryItem.CMD_NULL; |
| 3685 | } |
| 3686 | |
Narayan Kamath | 5a5a7fe | 2018-02-05 17:30:06 +0000 | [diff] [blame] | 3687 | void addHistoryBufferLocked(long elapsedRealtimeMs, HistoryItem cur) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3688 | if (!mHaveBatteryLevel || !mRecordingHistory) { |
| 3689 | return; |
| 3690 | } |
| 3691 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3692 | final long timeDiff = (mHistoryBaseTime+elapsedRealtimeMs) - mHistoryLastWritten.time; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3693 | final int diffStates = mHistoryLastWritten.states^(cur.states&mActiveHistoryStates); |
| 3694 | final int diffStates2 = mHistoryLastWritten.states2^(cur.states2&mActiveHistoryStates2); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3695 | final int lastDiffStates = mHistoryLastWritten.states^mHistoryLastLastWritten.states; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3696 | final int lastDiffStates2 = mHistoryLastWritten.states2^mHistoryLastLastWritten.states2; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3697 | if (DEBUG) Slog.i(TAG, "ADD: tdelta=" + timeDiff + " diff=" |
| 3698 | + Integer.toHexString(diffStates) + " lastDiff=" |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3699 | + Integer.toHexString(lastDiffStates) + " diff2=" |
| 3700 | + Integer.toHexString(diffStates2) + " lastDiff2=" |
| 3701 | + Integer.toHexString(lastDiffStates2)); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3702 | if (mHistoryBufferLastPos >= 0 && mHistoryLastWritten.cmd == HistoryItem.CMD_UPDATE |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3703 | && timeDiff < 1000 && (diffStates&lastDiffStates) == 0 |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3704 | && (diffStates2&lastDiffStates2) == 0 |
| 3705 | && (mHistoryLastWritten.wakelockTag == null || cur.wakelockTag == null) |
| 3706 | && (mHistoryLastWritten.wakeReasonTag == null || cur.wakeReasonTag == null) |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 3707 | && mHistoryLastWritten.stepDetails == null |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3708 | && (mHistoryLastWritten.eventCode == HistoryItem.EVENT_NONE |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3709 | || cur.eventCode == HistoryItem.EVENT_NONE) |
| 3710 | && mHistoryLastWritten.batteryLevel == cur.batteryLevel |
| 3711 | && mHistoryLastWritten.batteryStatus == cur.batteryStatus |
| 3712 | && mHistoryLastWritten.batteryHealth == cur.batteryHealth |
| 3713 | && mHistoryLastWritten.batteryPlugType == cur.batteryPlugType |
| 3714 | && mHistoryLastWritten.batteryTemperature == cur.batteryTemperature |
| 3715 | && mHistoryLastWritten.batteryVoltage == cur.batteryVoltage) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3716 | // 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] | 3717 | // 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] | 3718 | // as long as no bit has changed both between now and the last entry, as |
| 3719 | // well as the last entry and the one before it (so we capture any toggles). |
| 3720 | if (DEBUG) Slog.i(TAG, "ADD: rewinding back to " + mHistoryBufferLastPos); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3721 | mHistoryBuffer.setDataSize(mHistoryBufferLastPos); |
| 3722 | mHistoryBuffer.setDataPosition(mHistoryBufferLastPos); |
| 3723 | mHistoryBufferLastPos = -1; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3724 | elapsedRealtimeMs = mHistoryLastWritten.time - mHistoryBaseTime; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3725 | // If the last written history had a wakelock tag, we need to retain it. |
| 3726 | // Note that the condition above made sure that we aren't in a case where |
| 3727 | // both it and the current history item have a wakelock tag. |
| 3728 | if (mHistoryLastWritten.wakelockTag != null) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3729 | cur.wakelockTag = cur.localWakelockTag; |
| 3730 | cur.wakelockTag.setTo(mHistoryLastWritten.wakelockTag); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3731 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3732 | // If the last written history had a wake reason tag, we need to retain it. |
| 3733 | // Note that the condition above made sure that we aren't in a case where |
| 3734 | // both it and the current history item have a wakelock tag. |
| 3735 | if (mHistoryLastWritten.wakeReasonTag != null) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3736 | cur.wakeReasonTag = cur.localWakeReasonTag; |
| 3737 | cur.wakeReasonTag.setTo(mHistoryLastWritten.wakeReasonTag); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3738 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3739 | // If the last written history had an event, we need to retain it. |
| 3740 | // Note that the condition above made sure that we aren't in a case where |
| 3741 | // both it and the current history item have an event. |
| 3742 | if (mHistoryLastWritten.eventCode != HistoryItem.EVENT_NONE) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3743 | cur.eventCode = mHistoryLastWritten.eventCode; |
| 3744 | cur.eventTag = cur.localEventTag; |
| 3745 | cur.eventTag.setTo(mHistoryLastWritten.eventTag); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3746 | } |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 3747 | mHistoryLastWritten.setTo(mHistoryLastLastWritten); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3748 | } |
| 3749 | |
Adam Lesinski | 4548978 | 2016-12-15 23:45:17 -0800 | [diff] [blame] | 3750 | boolean recordResetDueToOverflow = false; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3751 | final int dataSize = mHistoryBuffer.dataSize(); |
Adam Lesinski | 4548978 | 2016-12-15 23:45:17 -0800 | [diff] [blame] | 3752 | if (dataSize >= MAX_MAX_HISTORY_BUFFER*3) { |
| 3753 | // Clients can't deal with history buffers this large. This only |
| 3754 | // really happens when the device is on charger and interacted with |
| 3755 | // for long periods of time, like in retail mode. Since the device is |
| 3756 | // most likely charged, when unplugged, stats would have reset anyways. |
| 3757 | // Reset the stats and mark that we overflowed. |
| 3758 | // b/32540341 |
| 3759 | resetAllStatsLocked(); |
| 3760 | |
| 3761 | // Mark that we want to set *OVERFLOW* event and the RESET:START |
| 3762 | // events. |
| 3763 | recordResetDueToOverflow = true; |
| 3764 | |
| 3765 | } else if (dataSize >= MAX_HISTORY_BUFFER) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3766 | if (!mHistoryOverflow) { |
| 3767 | mHistoryOverflow = true; |
Narayan Kamath | 5a5a7fe | 2018-02-05 17:30:06 +0000 | [diff] [blame] | 3768 | addHistoryBufferLocked(elapsedRealtimeMs, HistoryItem.CMD_UPDATE, cur); |
| 3769 | addHistoryBufferLocked(elapsedRealtimeMs, HistoryItem.CMD_OVERFLOW, cur); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3770 | return; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3771 | } |
| 3772 | |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3773 | // After overflow, we allow various bit-wise states to settle to 0. |
| 3774 | boolean writeAnyway = false; |
| 3775 | final int curStates = cur.states & HistoryItem.SETTLE_TO_ZERO_STATES |
| 3776 | & mActiveHistoryStates; |
| 3777 | if (mHistoryLastWritten.states != curStates) { |
| 3778 | // mActiveHistoryStates keeps track of which bits in .states are now being |
| 3779 | // forced to 0. |
| 3780 | int old = mActiveHistoryStates; |
| 3781 | mActiveHistoryStates &= curStates | ~HistoryItem.SETTLE_TO_ZERO_STATES; |
| 3782 | writeAnyway |= old != mActiveHistoryStates; |
| 3783 | } |
| 3784 | final int curStates2 = cur.states2 & HistoryItem.SETTLE_TO_ZERO_STATES2 |
| 3785 | & mActiveHistoryStates2; |
| 3786 | if (mHistoryLastWritten.states2 != curStates2) { |
| 3787 | // mActiveHistoryStates2 keeps track of which bits in .states2 are now being |
| 3788 | // forced to 0. |
| 3789 | int old = mActiveHistoryStates2; |
| 3790 | mActiveHistoryStates2 &= curStates2 | ~HistoryItem.SETTLE_TO_ZERO_STATES2; |
| 3791 | writeAnyway |= old != mActiveHistoryStates2; |
| 3792 | } |
| 3793 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3794 | // Once we've reached the maximum number of items, we only |
| 3795 | // record changes to the battery level and the most interesting states. |
| 3796 | // Once we've reached the maximum maximum number of items, we only |
| 3797 | // record changes to the battery level. |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3798 | if (!writeAnyway && mHistoryLastWritten.batteryLevel == cur.batteryLevel && |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3799 | (dataSize >= MAX_MAX_HISTORY_BUFFER |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3800 | || ((mHistoryLastWritten.states^cur.states) |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3801 | & HistoryItem.MOST_INTERESTING_STATES) == 0 |
| 3802 | || ((mHistoryLastWritten.states2^cur.states2) |
| 3803 | & HistoryItem.MOST_INTERESTING_STATES2) == 0)) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3804 | return; |
| 3805 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3806 | |
Narayan Kamath | 5a5a7fe | 2018-02-05 17:30:06 +0000 | [diff] [blame] | 3807 | addHistoryBufferLocked(elapsedRealtimeMs, HistoryItem.CMD_UPDATE, cur); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3808 | return; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3809 | } |
| 3810 | |
Adam Lesinski | 4548978 | 2016-12-15 23:45:17 -0800 | [diff] [blame] | 3811 | if (dataSize == 0 || recordResetDueToOverflow) { |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 3812 | // The history is currently empty; we need it to start with a time stamp. |
| 3813 | cur.currentTime = System.currentTimeMillis(); |
Adam Lesinski | 4548978 | 2016-12-15 23:45:17 -0800 | [diff] [blame] | 3814 | if (recordResetDueToOverflow) { |
Narayan Kamath | 5a5a7fe | 2018-02-05 17:30:06 +0000 | [diff] [blame] | 3815 | addHistoryBufferLocked(elapsedRealtimeMs, HistoryItem.CMD_OVERFLOW, cur); |
Adam Lesinski | 4548978 | 2016-12-15 23:45:17 -0800 | [diff] [blame] | 3816 | } |
Narayan Kamath | 5a5a7fe | 2018-02-05 17:30:06 +0000 | [diff] [blame] | 3817 | addHistoryBufferLocked(elapsedRealtimeMs, HistoryItem.CMD_RESET, cur); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 3818 | } |
Narayan Kamath | 5a5a7fe | 2018-02-05 17:30:06 +0000 | [diff] [blame] | 3819 | addHistoryBufferLocked(elapsedRealtimeMs, HistoryItem.CMD_UPDATE, cur); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3820 | } |
| 3821 | |
Narayan Kamath | 5a5a7fe | 2018-02-05 17:30:06 +0000 | [diff] [blame] | 3822 | private void addHistoryBufferLocked(long elapsedRealtimeMs, byte cmd, HistoryItem cur) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3823 | if (mIteratingHistory) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3824 | throw new IllegalStateException("Can't do this while iterating history!"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3825 | } |
| 3826 | mHistoryBufferLastPos = mHistoryBuffer.dataPosition(); |
| 3827 | mHistoryLastLastWritten.setTo(mHistoryLastWritten); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3828 | mHistoryLastWritten.setTo(mHistoryBaseTime + elapsedRealtimeMs, cmd, cur); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3829 | mHistoryLastWritten.states &= mActiveHistoryStates; |
| 3830 | mHistoryLastWritten.states2 &= mActiveHistoryStates2; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3831 | writeHistoryDelta(mHistoryBuffer, mHistoryLastWritten, mHistoryLastLastWritten); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3832 | mLastHistoryElapsedRealtime = elapsedRealtimeMs; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3833 | cur.wakelockTag = null; |
| 3834 | cur.wakeReasonTag = null; |
| 3835 | cur.eventCode = HistoryItem.EVENT_NONE; |
| 3836 | cur.eventTag = null; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3837 | if (DEBUG_HISTORY) Slog.i(TAG, "Writing history buffer: was " + mHistoryBufferLastPos |
| 3838 | + " now " + mHistoryBuffer.dataPosition() |
| 3839 | + " size is now " + mHistoryBuffer.dataSize()); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3840 | } |
| 3841 | |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 3842 | int mChangedStates = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3843 | int mChangedStates2 = 0; |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 3844 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3845 | void addHistoryRecordLocked(long elapsedRealtimeMs, long uptimeMs) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3846 | if (mTrackRunningHistoryElapsedRealtime != 0) { |
| 3847 | final long diffElapsed = elapsedRealtimeMs - mTrackRunningHistoryElapsedRealtime; |
| 3848 | final long diffUptime = uptimeMs - mTrackRunningHistoryUptime; |
| 3849 | if (diffUptime < (diffElapsed-20)) { |
| 3850 | final long wakeElapsedTime = elapsedRealtimeMs - (diffElapsed - diffUptime); |
| 3851 | mHistoryAddTmp.setTo(mHistoryLastWritten); |
| 3852 | mHistoryAddTmp.wakelockTag = null; |
| 3853 | mHistoryAddTmp.wakeReasonTag = null; |
| 3854 | mHistoryAddTmp.eventCode = HistoryItem.EVENT_NONE; |
| 3855 | mHistoryAddTmp.states &= ~HistoryItem.STATE_CPU_RUNNING_FLAG; |
Narayan Kamath | 5a5a7fe | 2018-02-05 17:30:06 +0000 | [diff] [blame] | 3856 | addHistoryRecordInnerLocked(wakeElapsedTime, mHistoryAddTmp); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3857 | } |
| 3858 | } |
| 3859 | mHistoryCur.states |= HistoryItem.STATE_CPU_RUNNING_FLAG; |
| 3860 | mTrackRunningHistoryElapsedRealtime = elapsedRealtimeMs; |
| 3861 | mTrackRunningHistoryUptime = uptimeMs; |
Narayan Kamath | 5a5a7fe | 2018-02-05 17:30:06 +0000 | [diff] [blame] | 3862 | addHistoryRecordInnerLocked(elapsedRealtimeMs, mHistoryCur); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3863 | } |
| 3864 | |
Narayan Kamath | 5a5a7fe | 2018-02-05 17:30:06 +0000 | [diff] [blame] | 3865 | void addHistoryRecordInnerLocked(long elapsedRealtimeMs, HistoryItem cur) { |
| 3866 | addHistoryBufferLocked(elapsedRealtimeMs, cur); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3867 | |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 3868 | if (!USE_OLD_HISTORY) { |
| 3869 | return; |
| 3870 | } |
| 3871 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3872 | if (!mHaveBatteryLevel || !mRecordingHistory) { |
| 3873 | return; |
| 3874 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3875 | |
| 3876 | // If the current time is basically the same as the last time, |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 3877 | // and no states have since the last recorded entry changed and |
| 3878 | // are now resetting back to their original value, then just collapse |
| 3879 | // into one record. |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3880 | if (mHistoryEnd != null && mHistoryEnd.cmd == HistoryItem.CMD_UPDATE |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3881 | && (mHistoryBaseTime+elapsedRealtimeMs) < (mHistoryEnd.time+1000) |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3882 | && ((mHistoryEnd.states^cur.states)&mChangedStates&mActiveHistoryStates) == 0 |
| 3883 | && ((mHistoryEnd.states2^cur.states2)&mChangedStates2&mActiveHistoryStates2) == 0) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3884 | // If the current is the same as the one before, then we no |
| 3885 | // longer need the entry. |
| 3886 | if (mHistoryLastEnd != null && mHistoryLastEnd.cmd == HistoryItem.CMD_UPDATE |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3887 | && (mHistoryBaseTime+elapsedRealtimeMs) < (mHistoryEnd.time+500) |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3888 | && mHistoryLastEnd.sameNonEvent(cur)) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3889 | mHistoryLastEnd.next = null; |
| 3890 | mHistoryEnd.next = mHistoryCache; |
| 3891 | mHistoryCache = mHistoryEnd; |
| 3892 | mHistoryEnd = mHistoryLastEnd; |
| 3893 | mHistoryLastEnd = null; |
| 3894 | } else { |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3895 | mChangedStates |= mHistoryEnd.states^(cur.states&mActiveHistoryStates); |
| 3896 | mChangedStates2 |= mHistoryEnd.states^(cur.states2&mActiveHistoryStates2); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3897 | mHistoryEnd.setTo(mHistoryEnd.time, HistoryItem.CMD_UPDATE, cur); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3898 | } |
| 3899 | return; |
| 3900 | } |
| 3901 | |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 3902 | mChangedStates = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3903 | mChangedStates2 = 0; |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 3904 | |
| 3905 | if (mNumHistoryItems == MAX_HISTORY_ITEMS |
| 3906 | || mNumHistoryItems == MAX_MAX_HISTORY_ITEMS) { |
Narayan Kamath | 5a5a7fe | 2018-02-05 17:30:06 +0000 | [diff] [blame] | 3907 | addHistoryBufferLocked(elapsedRealtimeMs, HistoryItem.CMD_OVERFLOW, cur); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 3908 | } |
| 3909 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3910 | if (mNumHistoryItems >= MAX_HISTORY_ITEMS) { |
| 3911 | // Once we've reached the maximum number of items, we only |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 3912 | // record changes to the battery level and the most interesting states. |
| 3913 | // Once we've reached the maximum maximum number of items, we only |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3914 | // record changes to the battery level. |
| 3915 | if (mHistoryEnd != null && mHistoryEnd.batteryLevel |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3916 | == cur.batteryLevel && |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 3917 | (mNumHistoryItems >= MAX_MAX_HISTORY_ITEMS |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3918 | || ((mHistoryEnd.states^(cur.states&mActiveHistoryStates)) |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 3919 | & HistoryItem.MOST_INTERESTING_STATES) == 0)) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3920 | return; |
| 3921 | } |
| 3922 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3923 | |
Narayan Kamath | 5a5a7fe | 2018-02-05 17:30:06 +0000 | [diff] [blame] | 3924 | addHistoryBufferLocked(elapsedRealtimeMs, HistoryItem.CMD_UPDATE, cur); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3925 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3926 | |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3927 | public void addHistoryEventLocked(long elapsedRealtimeMs, long uptimeMs, int code, |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3928 | String name, int uid) { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3929 | mHistoryCur.eventCode = code; |
| 3930 | mHistoryCur.eventTag = mHistoryCur.localEventTag; |
| 3931 | mHistoryCur.eventTag.string = name; |
| 3932 | mHistoryCur.eventTag.uid = uid; |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 3933 | addHistoryRecordLocked(elapsedRealtimeMs, uptimeMs); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3934 | } |
| 3935 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3936 | void addHistoryRecordLocked(long elapsedRealtimeMs, long uptimeMs, byte cmd, HistoryItem cur) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3937 | HistoryItem rec = mHistoryCache; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3938 | if (rec != null) { |
| 3939 | mHistoryCache = rec.next; |
| 3940 | } else { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3941 | rec = new HistoryItem(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3942 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3943 | rec.setTo(mHistoryBaseTime + elapsedRealtimeMs, cmd, cur); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3944 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3945 | addHistoryRecordLocked(rec); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3946 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3947 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3948 | void addHistoryRecordLocked(HistoryItem rec) { |
| 3949 | mNumHistoryItems++; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3950 | rec.next = null; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3951 | mHistoryLastEnd = mHistoryEnd; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3952 | if (mHistoryEnd != null) { |
| 3953 | mHistoryEnd.next = rec; |
| 3954 | mHistoryEnd = rec; |
| 3955 | } else { |
| 3956 | mHistory = mHistoryEnd = rec; |
| 3957 | } |
| 3958 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3959 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3960 | void clearHistoryLocked() { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3961 | if (DEBUG_HISTORY) Slog.i(TAG, "********** CLEARING HISTORY!"); |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 3962 | if (USE_OLD_HISTORY) { |
| 3963 | if (mHistory != null) { |
| 3964 | mHistoryEnd.next = mHistoryCache; |
| 3965 | mHistoryCache = mHistory; |
| 3966 | mHistory = mHistoryLastEnd = mHistoryEnd = null; |
| 3967 | } |
| 3968 | mNumHistoryItems = 0; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3969 | } |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 3970 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3971 | mHistoryBaseTime = 0; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3972 | mLastHistoryElapsedRealtime = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3973 | mTrackRunningHistoryElapsedRealtime = 0; |
| 3974 | mTrackRunningHistoryUptime = 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3975 | |
| 3976 | mHistoryBuffer.setDataSize(0); |
| 3977 | mHistoryBuffer.setDataPosition(0); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3978 | mHistoryBuffer.setDataCapacity(MAX_HISTORY_BUFFER / 2); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3979 | mHistoryLastLastWritten.clear(); |
| 3980 | mHistoryLastWritten.clear(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3981 | mHistoryTagPool.clear(); |
| 3982 | mNextHistoryTagIdx = 0; |
| 3983 | mNumHistoryTagChars = 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3984 | mHistoryBufferLastPos = -1; |
| 3985 | mHistoryOverflow = false; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3986 | mActiveHistoryStates = 0xffffffff; |
| 3987 | mActiveHistoryStates2 = 0xffffffff; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3988 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3989 | |
Andreas Gampe | 3f24e69 | 2018-02-05 13:24:28 -0800 | [diff] [blame] | 3990 | @GuardedBy("this") |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 3991 | public void updateTimeBasesLocked(boolean unplugged, int screenState, long uptime, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3992 | long realtime) { |
Mike Ma | a772475 | 2017-10-10 15:29:25 -0700 | [diff] [blame] | 3993 | final boolean screenOff = !isScreenOn(screenState); |
Sudheer Shanka | 9d4ed7c | 2017-07-08 22:10:45 -0700 | [diff] [blame] | 3994 | final boolean updateOnBatteryTimeBase = unplugged != mOnBatteryTimeBase.isRunning(); |
| 3995 | final boolean updateOnBatteryScreenOffTimeBase = |
| 3996 | (unplugged && screenOff) != mOnBatteryScreenOffTimeBase.isRunning(); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3997 | |
Sudheer Shanka | 9d4ed7c | 2017-07-08 22:10:45 -0700 | [diff] [blame] | 3998 | if (updateOnBatteryScreenOffTimeBase || updateOnBatteryTimeBase) { |
| 3999 | if (updateOnBatteryScreenOffTimeBase) { |
| 4000 | updateKernelWakelocksLocked(); |
| 4001 | updateBatteryPropertiesLocked(); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4002 | } |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 4003 | // This if{} is only necessary due to SCREEN_OFF_RPM_STATS_ENABLED, which exists because |
| 4004 | // updateRpmStatsLocked is too slow to run each screen change. When the speed is |
| 4005 | // improved, remove the surrounding if{}. |
| 4006 | if (SCREEN_OFF_RPM_STATS_ENABLED || updateOnBatteryTimeBase) { |
| 4007 | updateRpmStatsLocked(); // if either OnBattery or OnBatteryScreenOff timebase changes. |
| 4008 | } |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 4009 | if (DEBUG_ENERGY_CPU) { |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4010 | Slog.d(TAG, "Updating cpu time because screen is now " |
| 4011 | + Display.stateToString(screenState) |
Sudheer Shanka | 9d4ed7c | 2017-07-08 22:10:45 -0700 | [diff] [blame] | 4012 | + " and battery is " + (unplugged ? "on" : "off")); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4013 | } |
Sudheer Shanka | 9d4ed7c | 2017-07-08 22:10:45 -0700 | [diff] [blame] | 4014 | |
| 4015 | mOnBatteryTimeBase.setRunning(unplugged, uptime, realtime); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4016 | if (updateOnBatteryTimeBase) { |
| 4017 | for (int i = mUidStats.size() - 1; i >= 0; --i) { |
| 4018 | mUidStats.valueAt(i).updateOnBatteryBgTimeBase(uptime, realtime); |
Sudheer Shanka | 9d4ed7c | 2017-07-08 22:10:45 -0700 | [diff] [blame] | 4019 | } |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4020 | } |
| 4021 | if (updateOnBatteryScreenOffTimeBase) { |
| 4022 | mOnBatteryScreenOffTimeBase.setRunning(unplugged && screenOff, uptime, realtime); |
| 4023 | for (int i = mUidStats.size() - 1; i >= 0; --i) { |
| 4024 | mUidStats.valueAt(i).updateOnBatteryScreenOffBgTimeBase(uptime, realtime); |
Sudheer Shanka | 9d4ed7c | 2017-07-08 22:10:45 -0700 | [diff] [blame] | 4025 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 4026 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4027 | } |
| 4028 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 4029 | |
Adam Lesinski | e1f480d | 2017-02-15 18:51:23 -0800 | [diff] [blame] | 4030 | private void updateBatteryPropertiesLocked() { |
| 4031 | try { |
| 4032 | IBatteryPropertiesRegistrar registrar = IBatteryPropertiesRegistrar.Stub.asInterface( |
| 4033 | ServiceManager.getService("batteryproperties")); |
| 4034 | registrar.scheduleUpdate(); |
| 4035 | } catch (RemoteException e) { |
| 4036 | // Ignore. |
| 4037 | } |
| 4038 | } |
| 4039 | |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4040 | public void addIsolatedUidLocked(int isolatedUid, int appUid) { |
| 4041 | mIsolatedUids.put(isolatedUid, appUid); |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 4042 | StatsLog.write(StatsLog.ISOLATED_UID_CHANGED, appUid, isolatedUid, |
| 4043 | StatsLog.ISOLATED_UID_CHANGED__EVENT__CREATED); |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 4044 | final Uid u = getUidStatsLocked(appUid); |
| 4045 | u.addIsolatedUid(isolatedUid); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4046 | } |
| 4047 | |
Adam Lesinski | 61db88f | 2015-07-01 15:05:07 -0700 | [diff] [blame] | 4048 | /** |
| 4049 | * Schedules a read of the latest cpu times before removing the isolated UID. |
| 4050 | * @see #removeIsolatedUidLocked(int) |
| 4051 | */ |
| 4052 | public void scheduleRemoveIsolatedUidLocked(int isolatedUid, int appUid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4053 | int curUid = mIsolatedUids.get(isolatedUid, -1); |
| 4054 | if (curUid == appUid) { |
Adam Lesinski | 61db88f | 2015-07-01 15:05:07 -0700 | [diff] [blame] | 4055 | if (mExternalSync != null) { |
| 4056 | mExternalSync.scheduleCpuSyncDueToRemovedUid(isolatedUid); |
| 4057 | } |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4058 | } |
| 4059 | } |
| 4060 | |
Adam Lesinski | 61db88f | 2015-07-01 15:05:07 -0700 | [diff] [blame] | 4061 | /** |
| 4062 | * This should only be called after the cpu times have been read. |
| 4063 | * @see #scheduleRemoveIsolatedUidLocked(int, int) |
| 4064 | */ |
Andreas Gampe | 3f24e69 | 2018-02-05 13:24:28 -0800 | [diff] [blame] | 4065 | @GuardedBy("this") |
Adam Lesinski | 61db88f | 2015-07-01 15:05:07 -0700 | [diff] [blame] | 4066 | public void removeIsolatedUidLocked(int isolatedUid) { |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 4067 | StatsLog.write( |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 4068 | StatsLog.ISOLATED_UID_CHANGED, mIsolatedUids.get(isolatedUid, -1), |
| 4069 | isolatedUid, StatsLog.ISOLATED_UID_CHANGED__EVENT__REMOVED); |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 4070 | final int idx = mIsolatedUids.indexOfKey(isolatedUid); |
| 4071 | if (idx >= 0) { |
| 4072 | final int ownerUid = mIsolatedUids.valueAt(idx); |
| 4073 | final Uid u = getUidStatsLocked(ownerUid); |
| 4074 | u.removeIsolatedUid(isolatedUid); |
| 4075 | mIsolatedUids.removeAt(idx); |
| 4076 | } |
Mike Ma | 234d182 | 2018-03-13 18:53:21 -0700 | [diff] [blame] | 4077 | mPendingRemovedUids.add(new UidToRemove(isolatedUid, mClocks.elapsedRealtime())); |
Adam Lesinski | 61db88f | 2015-07-01 15:05:07 -0700 | [diff] [blame] | 4078 | } |
| 4079 | |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4080 | public int mapUid(int uid) { |
| 4081 | int isolated = mIsolatedUids.get(uid, -1); |
| 4082 | return isolated > 0 ? isolated : uid; |
| 4083 | } |
| 4084 | |
| 4085 | public void noteEventLocked(int code, String name, int uid) { |
| 4086 | uid = mapUid(uid); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 4087 | if (!mActiveEvents.updateState(code, name, uid, 0)) { |
| 4088 | return; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 4089 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4090 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4091 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4092 | addHistoryEventLocked(elapsedRealtime, uptime, code, name, uid); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4093 | } |
| 4094 | |
Dianne Hackborn | d48954f | 2015-07-22 17:20:33 -0700 | [diff] [blame] | 4095 | boolean ensureStartClockTime(final long currentTime) { |
| 4096 | final long ABOUT_ONE_YEAR = 365*24*60*60*1000L; |
Makoto Onuki | 62b3c92 | 2018-04-25 14:51:56 -0700 | [diff] [blame] | 4097 | if ((currentTime > ABOUT_ONE_YEAR && mStartClockTime < (currentTime-ABOUT_ONE_YEAR)) |
| 4098 | || (mStartClockTime > currentTime)) { |
Dianne Hackborn | d48954f | 2015-07-22 17:20:33 -0700 | [diff] [blame] | 4099 | // If the start clock time has changed by more than a year, then presumably |
| 4100 | // the previous time was completely bogus. So we are going to figure out a |
| 4101 | // 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] | 4102 | mStartClockTime = currentTime - (mClocks.elapsedRealtime()-(mRealtimeStart/1000)); |
Dianne Hackborn | d48954f | 2015-07-22 17:20:33 -0700 | [diff] [blame] | 4103 | return true; |
| 4104 | } |
| 4105 | return false; |
| 4106 | } |
| 4107 | |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 4108 | public void noteCurrentTimeChangedLocked() { |
| 4109 | final long currentTime = System.currentTimeMillis(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4110 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4111 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 4112 | recordCurrentTimeChangeLocked(currentTime, elapsedRealtime, uptime); |
Dianne Hackborn | d48954f | 2015-07-22 17:20:33 -0700 | [diff] [blame] | 4113 | ensureStartClockTime(currentTime); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 4114 | } |
| 4115 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4116 | public void noteProcessStartLocked(String name, int uid) { |
| 4117 | uid = mapUid(uid); |
| 4118 | if (isOnBattery()) { |
| 4119 | Uid u = getUidStatsLocked(uid); |
| 4120 | u.getProcessStatsLocked(name).incStartsLocked(); |
| 4121 | } |
| 4122 | if (!mActiveEvents.updateState(HistoryItem.EVENT_PROC_START, name, uid, 0)) { |
| 4123 | return; |
| 4124 | } |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 4125 | if (!mRecordAllHistory) { |
| 4126 | return; |
| 4127 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4128 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4129 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4130 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_PROC_START, name, uid); |
| 4131 | } |
| 4132 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 4133 | public void noteProcessCrashLocked(String name, int uid) { |
| 4134 | uid = mapUid(uid); |
| 4135 | if (isOnBattery()) { |
| 4136 | Uid u = getUidStatsLocked(uid); |
| 4137 | u.getProcessStatsLocked(name).incNumCrashesLocked(); |
| 4138 | } |
| 4139 | } |
| 4140 | |
| 4141 | public void noteProcessAnrLocked(String name, int uid) { |
| 4142 | uid = mapUid(uid); |
| 4143 | if (isOnBattery()) { |
| 4144 | Uid u = getUidStatsLocked(uid); |
| 4145 | u.getProcessStatsLocked(name).incNumAnrsLocked(); |
| 4146 | } |
| 4147 | } |
| 4148 | |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 4149 | public void noteUidProcessStateLocked(int uid, int state) { |
Amith Yamasani | fd3caf6 | 2017-07-26 11:48:35 -0700 | [diff] [blame] | 4150 | int parentUid = mapUid(uid); |
| 4151 | if (uid != parentUid) { |
| 4152 | // Isolated UIDs process state is already rolled up into parent, so no need to track |
| 4153 | // Otherwise the parent's process state will get downgraded incorrectly |
| 4154 | return; |
| 4155 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 4156 | getUidStatsLocked(uid).updateUidProcessStateLocked(state); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4157 | } |
| 4158 | |
| 4159 | public void noteProcessFinishLocked(String name, int uid) { |
| 4160 | uid = mapUid(uid); |
| 4161 | if (!mActiveEvents.updateState(HistoryItem.EVENT_PROC_FINISH, name, uid, 0)) { |
| 4162 | return; |
| 4163 | } |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 4164 | if (!mRecordAllHistory) { |
| 4165 | return; |
| 4166 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4167 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4168 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 4169 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_PROC_FINISH, name, uid); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4170 | } |
| 4171 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4172 | public void noteSyncStartLocked(String name, int uid) { |
| 4173 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4174 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4175 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4176 | getUidStatsLocked(uid).noteStartSyncLocked(name, elapsedRealtime); |
| 4177 | if (!mActiveEvents.updateState(HistoryItem.EVENT_SYNC_START, name, uid, 0)) { |
| 4178 | return; |
| 4179 | } |
| 4180 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_SYNC_START, name, uid); |
| 4181 | } |
| 4182 | |
| 4183 | public void noteSyncFinishLocked(String name, int uid) { |
| 4184 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4185 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4186 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4187 | getUidStatsLocked(uid).noteStopSyncLocked(name, elapsedRealtime); |
| 4188 | if (!mActiveEvents.updateState(HistoryItem.EVENT_SYNC_FINISH, name, uid, 0)) { |
| 4189 | return; |
| 4190 | } |
| 4191 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_SYNC_FINISH, name, uid); |
| 4192 | } |
| 4193 | |
| 4194 | public void noteJobStartLocked(String name, int uid) { |
| 4195 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4196 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4197 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4198 | getUidStatsLocked(uid).noteStartJobLocked(name, elapsedRealtime); |
| 4199 | if (!mActiveEvents.updateState(HistoryItem.EVENT_JOB_START, name, uid, 0)) { |
| 4200 | return; |
| 4201 | } |
| 4202 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_JOB_START, name, uid); |
| 4203 | } |
| 4204 | |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 4205 | public void noteJobFinishLocked(String name, int uid, int stopReason) { |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4206 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4207 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4208 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 4209 | getUidStatsLocked(uid).noteStopJobLocked(name, elapsedRealtime, stopReason); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4210 | if (!mActiveEvents.updateState(HistoryItem.EVENT_JOB_FINISH, name, uid, 0)) { |
| 4211 | return; |
| 4212 | } |
| 4213 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_JOB_FINISH, name, uid); |
| 4214 | } |
| 4215 | |
Amith Yamasani | 977e11f | 2018-02-16 11:29:54 -0800 | [diff] [blame] | 4216 | public void noteJobsDeferredLocked(int uid, int numDeferred, long sinceLast) { |
| 4217 | uid = mapUid(uid); |
| 4218 | getUidStatsLocked(uid).noteJobsDeferredLocked(numDeferred, sinceLast); |
| 4219 | } |
| 4220 | |
Narayan Kamath | 695cf72 | 2017-12-21 18:32:47 +0000 | [diff] [blame] | 4221 | public void noteAlarmStartLocked(String name, WorkSource workSource, int uid) { |
| 4222 | noteAlarmStartOrFinishLocked(HistoryItem.EVENT_ALARM_START, name, workSource, uid); |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 4223 | } |
| 4224 | |
Narayan Kamath | 695cf72 | 2017-12-21 18:32:47 +0000 | [diff] [blame] | 4225 | public void noteAlarmFinishLocked(String name, WorkSource workSource, int uid) { |
| 4226 | noteAlarmStartOrFinishLocked(HistoryItem.EVENT_ALARM_FINISH, name, workSource, uid); |
| 4227 | } |
| 4228 | |
| 4229 | private void noteAlarmStartOrFinishLocked(int historyItem, String name, WorkSource workSource, |
| 4230 | int uid) { |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 4231 | if (!mRecordAllHistory) { |
| 4232 | return; |
| 4233 | } |
Narayan Kamath | 695cf72 | 2017-12-21 18:32:47 +0000 | [diff] [blame] | 4234 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4235 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4236 | final long uptime = mClocks.uptimeMillis(); |
Narayan Kamath | 695cf72 | 2017-12-21 18:32:47 +0000 | [diff] [blame] | 4237 | |
| 4238 | if (workSource != null) { |
| 4239 | for (int i = 0; i < workSource.size(); ++i) { |
| 4240 | uid = mapUid(workSource.get(i)); |
| 4241 | if (mActiveEvents.updateState(historyItem, name, uid, 0)) { |
| 4242 | addHistoryEventLocked(elapsedRealtime, uptime, historyItem, name, uid); |
| 4243 | } |
| 4244 | } |
| 4245 | |
| 4246 | List<WorkChain> workChains = workSource.getWorkChains(); |
| 4247 | if (workChains != null) { |
| 4248 | for (int i = 0; i < workChains.size(); ++i) { |
| 4249 | uid = mapUid(workChains.get(i).getAttributionUid()); |
| 4250 | if (mActiveEvents.updateState(historyItem, name, uid, 0)) { |
| 4251 | addHistoryEventLocked(elapsedRealtime, uptime, historyItem, name, uid); |
| 4252 | } |
| 4253 | } |
| 4254 | } |
| 4255 | } else { |
| 4256 | uid = mapUid(uid); |
| 4257 | |
| 4258 | if (mActiveEvents.updateState(historyItem, name, uid, 0)) { |
| 4259 | addHistoryEventLocked(elapsedRealtime, uptime, historyItem, name, uid); |
| 4260 | } |
| 4261 | } |
| 4262 | } |
| 4263 | |
| 4264 | public void noteWakupAlarmLocked(String packageName, int uid, WorkSource workSource, |
| 4265 | String tag) { |
Narayan Kamath | 695cf72 | 2017-12-21 18:32:47 +0000 | [diff] [blame] | 4266 | if (workSource != null) { |
| 4267 | for (int i = 0; i < workSource.size(); ++i) { |
| 4268 | uid = workSource.get(i); |
| 4269 | final String workSourceName = workSource.getName(i); |
| 4270 | |
Tej Singh | 6f724c4 | 2018-01-03 20:02:03 -0800 | [diff] [blame] | 4271 | if (isOnBattery()) { |
| 4272 | BatteryStatsImpl.Uid.Pkg pkg = getPackageStatsLocked(uid, |
| 4273 | workSourceName != null ? workSourceName : packageName); |
| 4274 | pkg.noteWakeupAlarmLocked(tag); |
| 4275 | } |
Yangster-mac | 2f5daec | 2018-01-16 10:23:15 -0800 | [diff] [blame] | 4276 | StatsLog.write_non_chained(StatsLog.WAKEUP_ALARM_OCCURRED, workSource.get(i), |
| 4277 | workSource.getName(i), tag); |
Narayan Kamath | 695cf72 | 2017-12-21 18:32:47 +0000 | [diff] [blame] | 4278 | } |
| 4279 | |
| 4280 | ArrayList<WorkChain> workChains = workSource.getWorkChains(); |
| 4281 | if (workChains != null) { |
| 4282 | for (int i = 0; i < workChains.size(); ++i) { |
| 4283 | final WorkChain wc = workChains.get(i); |
| 4284 | uid = wc.getAttributionUid(); |
| 4285 | |
Tej Singh | 6f724c4 | 2018-01-03 20:02:03 -0800 | [diff] [blame] | 4286 | if (isOnBattery()) { |
| 4287 | BatteryStatsImpl.Uid.Pkg pkg = getPackageStatsLocked(uid, packageName); |
| 4288 | pkg.noteWakeupAlarmLocked(tag); |
| 4289 | } |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 4290 | StatsLog.write(StatsLog.WAKEUP_ALARM_OCCURRED, wc.getUids(), wc.getTags(), tag); |
Narayan Kamath | 695cf72 | 2017-12-21 18:32:47 +0000 | [diff] [blame] | 4291 | } |
| 4292 | } |
| 4293 | } else { |
Tej Singh | 6f724c4 | 2018-01-03 20:02:03 -0800 | [diff] [blame] | 4294 | if (isOnBattery()) { |
| 4295 | BatteryStatsImpl.Uid.Pkg pkg = getPackageStatsLocked(uid, packageName); |
| 4296 | pkg.noteWakeupAlarmLocked(tag); |
| 4297 | } |
Yangster-mac | 2f5daec | 2018-01-16 10:23:15 -0800 | [diff] [blame] | 4298 | StatsLog.write_non_chained(StatsLog.WAKEUP_ALARM_OCCURRED, uid, null, tag); |
Narayan Kamath | 695cf72 | 2017-12-21 18:32:47 +0000 | [diff] [blame] | 4299 | } |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 4300 | } |
| 4301 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4302 | private void requestWakelockCpuUpdate() { |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 4303 | mExternalSync.scheduleCpuSyncDueToWakelockChange(DELAY_UPDATE_WAKELOCKS); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4304 | } |
| 4305 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 4306 | private void requestImmediateCpuUpdate() { |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 4307 | mExternalSync.scheduleCpuSyncDueToWakelockChange(0 /* delayMillis */); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 4308 | } |
| 4309 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 4310 | public void setRecordAllHistoryLocked(boolean enabled) { |
| 4311 | mRecordAllHistory = enabled; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4312 | if (!enabled) { |
| 4313 | // Clear out any existing state. |
| 4314 | mActiveEvents.removeEvents(HistoryItem.EVENT_WAKE_LOCK); |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 4315 | mActiveEvents.removeEvents(HistoryItem.EVENT_ALARM); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 4316 | // Record the currently running processes as stopping, now that we are no |
| 4317 | // longer tracking them. |
| 4318 | HashMap<String, SparseIntArray> active = mActiveEvents.getStateForEvent( |
| 4319 | HistoryItem.EVENT_PROC); |
| 4320 | if (active != null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4321 | long mSecRealtime = mClocks.elapsedRealtime(); |
| 4322 | final long mSecUptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 4323 | for (HashMap.Entry<String, SparseIntArray> ent : active.entrySet()) { |
| 4324 | SparseIntArray uids = ent.getValue(); |
| 4325 | for (int j=0; j<uids.size(); j++) { |
| 4326 | addHistoryEventLocked(mSecRealtime, mSecUptime, |
| 4327 | HistoryItem.EVENT_PROC_FINISH, ent.getKey(), uids.keyAt(j)); |
| 4328 | } |
| 4329 | } |
| 4330 | } |
| 4331 | } else { |
| 4332 | // Record the currently running processes as starting, now that we are tracking them. |
| 4333 | HashMap<String, SparseIntArray> active = mActiveEvents.getStateForEvent( |
| 4334 | HistoryItem.EVENT_PROC); |
| 4335 | if (active != null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4336 | long mSecRealtime = mClocks.elapsedRealtime(); |
| 4337 | final long mSecUptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 4338 | for (HashMap.Entry<String, SparseIntArray> ent : active.entrySet()) { |
| 4339 | SparseIntArray uids = ent.getValue(); |
| 4340 | for (int j=0; j<uids.size(); j++) { |
| 4341 | addHistoryEventLocked(mSecRealtime, mSecUptime, |
| 4342 | HistoryItem.EVENT_PROC_START, ent.getKey(), uids.keyAt(j)); |
| 4343 | } |
| 4344 | } |
| 4345 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4346 | } |
| 4347 | } |
| 4348 | |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 4349 | public void setNoAutoReset(boolean enabled) { |
| 4350 | mNoAutoReset = enabled; |
| 4351 | } |
| 4352 | |
Amith Yamasani | 674c9bb | 2017-02-01 09:45:17 -0800 | [diff] [blame] | 4353 | public void setPretendScreenOff(boolean pretendScreenOff) { |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4354 | if (mPretendScreenOff != pretendScreenOff) { |
| 4355 | mPretendScreenOff = pretendScreenOff; |
| 4356 | noteScreenStateLocked(pretendScreenOff ? Display.STATE_OFF : Display.STATE_ON); |
| 4357 | } |
Amith Yamasani | 674c9bb | 2017-02-01 09:45:17 -0800 | [diff] [blame] | 4358 | } |
| 4359 | |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 4360 | private String mInitialAcquireWakeName; |
| 4361 | private int mInitialAcquireWakeUid = -1; |
| 4362 | |
Narayan Kamath | 8182202 | 2017-12-08 11:56:01 +0000 | [diff] [blame] | 4363 | public void noteStartWakeLocked(int uid, int pid, WorkChain wc, String name, String historyName, |
| 4364 | int type, boolean unimportantForLogging, long elapsedRealtime, long uptime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4365 | uid = mapUid(uid); |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 4366 | if (type == WAKE_TYPE_PARTIAL) { |
| 4367 | // Only care about partial wake locks, since full wake locks |
| 4368 | // will be canceled when the user puts the screen to sleep. |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4369 | aggregateLastWakeupUptimeLocked(uptime); |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 4370 | if (historyName == null) { |
| 4371 | historyName = name; |
| 4372 | } |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 4373 | if (mRecordAllHistory) { |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 4374 | if (mActiveEvents.updateState(HistoryItem.EVENT_WAKE_LOCK_START, historyName, |
| 4375 | uid, 0)) { |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 4376 | addHistoryEventLocked(elapsedRealtime, uptime, |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 4377 | HistoryItem.EVENT_WAKE_LOCK_START, historyName, uid); |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 4378 | } |
| 4379 | } |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 4380 | if (mWakeLockNesting == 0) { |
| 4381 | mHistoryCur.states |= HistoryItem.STATE_WAKE_LOCK_FLAG; |
| 4382 | if (DEBUG_HISTORY) Slog.v(TAG, "Start wake lock to: " |
| 4383 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4384 | mHistoryCur.wakelockTag = mHistoryCur.localWakelockTag; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4385 | mHistoryCur.wakelockTag.string = mInitialAcquireWakeName = historyName; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 4386 | mHistoryCur.wakelockTag.uid = mInitialAcquireWakeUid = uid; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 4387 | mWakeLockImportant = !unimportantForLogging; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4388 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 4389 | } else if (!mWakeLockImportant && !unimportantForLogging |
| 4390 | && mHistoryLastWritten.cmd == HistoryItem.CMD_UPDATE) { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 4391 | if (mHistoryLastWritten.wakelockTag != null) { |
| 4392 | // We'll try to update the last tag. |
| 4393 | mHistoryLastWritten.wakelockTag = null; |
| 4394 | mHistoryCur.wakelockTag = mHistoryCur.localWakelockTag; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4395 | mHistoryCur.wakelockTag.string = mInitialAcquireWakeName = historyName; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 4396 | mHistoryCur.wakelockTag.uid = mInitialAcquireWakeUid = uid; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4397 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 4398 | } |
| 4399 | mWakeLockImportant = true; |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 4400 | } |
| 4401 | mWakeLockNesting++; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4402 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4403 | if (uid >= 0) { |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 4404 | if (mOnBatteryScreenOffTimeBase.isRunning()) { |
| 4405 | // We only update the cpu time when a wake lock is acquired if the screen is off. |
| 4406 | // If the screen is on, we don't distribute the power amongst partial wakelocks. |
| 4407 | if (DEBUG_ENERGY_CPU) { |
| 4408 | Slog.d(TAG, "Updating cpu time because of +wake_lock"); |
| 4409 | } |
| 4410 | requestWakelockCpuUpdate(); |
| 4411 | } |
Narayan Kamath | 8182202 | 2017-12-08 11:56:01 +0000 | [diff] [blame] | 4412 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4413 | getUidStatsLocked(uid).noteStartWakeLocked(pid, name, type, elapsedRealtime); |
Narayan Kamath | 8182202 | 2017-12-08 11:56:01 +0000 | [diff] [blame] | 4414 | |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 4415 | if (wc != null) { |
Bookatz | 1a1b046 | 2018-01-12 11:47:03 -0800 | [diff] [blame] | 4416 | StatsLog.write(StatsLog.WAKELOCK_STATE_CHANGED, wc.getUids(), wc.getTags(), |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 4417 | getPowerManagerWakeLockLevel(type), name, |
| 4418 | StatsLog.WAKELOCK_STATE_CHANGED__STATE__ACQUIRE); |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 4419 | } else { |
Bookatz | 1a1b046 | 2018-01-12 11:47:03 -0800 | [diff] [blame] | 4420 | StatsLog.write_non_chained(StatsLog.WAKELOCK_STATE_CHANGED, uid, null, |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 4421 | getPowerManagerWakeLockLevel(type), name, |
| 4422 | StatsLog.WAKELOCK_STATE_CHANGED__STATE__ACQUIRE); |
Narayan Kamath | 8182202 | 2017-12-08 11:56:01 +0000 | [diff] [blame] | 4423 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4424 | } |
| 4425 | } |
| 4426 | |
Narayan Kamath | 8182202 | 2017-12-08 11:56:01 +0000 | [diff] [blame] | 4427 | public void noteStopWakeLocked(int uid, int pid, WorkChain wc, String name, String historyName, |
| 4428 | int type, long elapsedRealtime, long uptime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4429 | uid = mapUid(uid); |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 4430 | if (type == WAKE_TYPE_PARTIAL) { |
| 4431 | mWakeLockNesting--; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 4432 | if (mRecordAllHistory) { |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 4433 | if (historyName == null) { |
| 4434 | historyName = name; |
| 4435 | } |
| 4436 | if (mActiveEvents.updateState(HistoryItem.EVENT_WAKE_LOCK_FINISH, historyName, |
| 4437 | uid, 0)) { |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 4438 | addHistoryEventLocked(elapsedRealtime, uptime, |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 4439 | HistoryItem.EVENT_WAKE_LOCK_FINISH, historyName, uid); |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 4440 | } |
| 4441 | } |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 4442 | if (mWakeLockNesting == 0) { |
| 4443 | mHistoryCur.states &= ~HistoryItem.STATE_WAKE_LOCK_FLAG; |
| 4444 | if (DEBUG_HISTORY) Slog.v(TAG, "Stop wake lock to: " |
| 4445 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 4446 | mInitialAcquireWakeName = null; |
| 4447 | mInitialAcquireWakeUid = -1; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4448 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 4449 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4450 | } |
| 4451 | if (uid >= 0) { |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 4452 | if (mOnBatteryScreenOffTimeBase.isRunning()) { |
| 4453 | if (DEBUG_ENERGY_CPU) { |
| 4454 | Slog.d(TAG, "Updating cpu time because of -wake_lock"); |
| 4455 | } |
| 4456 | requestWakelockCpuUpdate(); |
| 4457 | } |
Narayan Kamath | 8182202 | 2017-12-08 11:56:01 +0000 | [diff] [blame] | 4458 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4459 | getUidStatsLocked(uid).noteStopWakeLocked(pid, name, type, elapsedRealtime); |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 4460 | if (wc != null) { |
Bookatz | 1a1b046 | 2018-01-12 11:47:03 -0800 | [diff] [blame] | 4461 | StatsLog.write(StatsLog.WAKELOCK_STATE_CHANGED, wc.getUids(), wc.getTags(), |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 4462 | getPowerManagerWakeLockLevel(type), name, |
| 4463 | StatsLog.WAKELOCK_STATE_CHANGED__STATE__RELEASE); |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 4464 | } else { |
Bookatz | 1a1b046 | 2018-01-12 11:47:03 -0800 | [diff] [blame] | 4465 | StatsLog.write_non_chained(StatsLog.WAKELOCK_STATE_CHANGED, uid, null, |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 4466 | getPowerManagerWakeLockLevel(type), name, |
| 4467 | StatsLog.WAKELOCK_STATE_CHANGED__STATE__RELEASE); |
Narayan Kamath | 8182202 | 2017-12-08 11:56:01 +0000 | [diff] [blame] | 4468 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4469 | } |
| 4470 | } |
| 4471 | |
Bookatz | 1a1b046 | 2018-01-12 11:47:03 -0800 | [diff] [blame] | 4472 | /** |
| 4473 | * Converts BatteryStats wakelock types back into PowerManager wakelock levels. |
| 4474 | * This is the inverse map of Notifier.getBatteryStatsWakeLockMonitorType(). |
| 4475 | * These are estimations, since batterystats loses some of the original data. |
| 4476 | * TODO: Delete this. Instead, StatsLog.write should be called from PowerManager's Notifier. |
| 4477 | */ |
| 4478 | private int getPowerManagerWakeLockLevel(int battertStatsWakelockType) { |
| 4479 | switch (battertStatsWakelockType) { |
| 4480 | // PowerManager.PARTIAL_WAKE_LOCK or PROXIMITY_SCREEN_OFF_WAKE_LOCK |
| 4481 | case BatteryStats.WAKE_TYPE_PARTIAL: |
| 4482 | return PowerManager.PARTIAL_WAKE_LOCK; |
| 4483 | |
| 4484 | // PowerManager.SCREEN_DIM_WAKE_LOCK or SCREEN_BRIGHT_WAKE_LOCK |
| 4485 | case BatteryStats.WAKE_TYPE_FULL: |
| 4486 | return PowerManager.FULL_WAKE_LOCK; |
| 4487 | |
| 4488 | case BatteryStats.WAKE_TYPE_DRAW: |
| 4489 | return PowerManager.DRAW_WAKE_LOCK; |
| 4490 | |
| 4491 | // It appears that nothing can ever make a Window and PowerManager lacks an equivalent. |
| 4492 | case BatteryStats.WAKE_TYPE_WINDOW: |
| 4493 | Slog.e(TAG, "Illegal window wakelock type observed in batterystats."); |
| 4494 | return -1; |
| 4495 | |
| 4496 | default: |
| 4497 | Slog.e(TAG, "Illegal wakelock type in batterystats: " + battertStatsWakelockType); |
| 4498 | return -1; |
| 4499 | } |
| 4500 | } |
| 4501 | |
Dianne Hackborn | a1f1a3c | 2014-02-24 18:12:28 -0800 | [diff] [blame] | 4502 | public void noteStartWakeFromSourceLocked(WorkSource ws, int pid, String name, |
| 4503 | String historyName, int type, boolean unimportantForLogging) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4504 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4505 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 4506 | final int N = ws.size(); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 4507 | for (int i=0; i<N; i++) { |
Narayan Kamath | 8182202 | 2017-12-08 11:56:01 +0000 | [diff] [blame] | 4508 | noteStartWakeLocked(ws.get(i), pid, null, name, historyName, type, |
| 4509 | unimportantForLogging, elapsedRealtime, uptime); |
| 4510 | } |
| 4511 | |
| 4512 | List<WorkChain> wcs = ws.getWorkChains(); |
| 4513 | if (wcs != null) { |
| 4514 | for (int i = 0; i < wcs.size(); ++i) { |
| 4515 | final WorkChain wc = wcs.get(i); |
| 4516 | noteStartWakeLocked(wc.getAttributionUid(), pid, wc, name, historyName, type, |
| 4517 | unimportantForLogging, elapsedRealtime, uptime); |
| 4518 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 4519 | } |
| 4520 | } |
| 4521 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4522 | public void noteChangeWakelockFromSourceLocked(WorkSource ws, int pid, String name, |
| 4523 | String historyName, int type, WorkSource newWs, int newPid, String newName, |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 4524 | String newHistoryName, int newType, boolean newUnimportantForLogging) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4525 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4526 | final long uptime = mClocks.uptimeMillis(); |
Narayan Kamath | 8182202 | 2017-12-08 11:56:01 +0000 | [diff] [blame] | 4527 | |
| 4528 | List<WorkChain>[] wcs = WorkSource.diffChains(ws, newWs); |
| 4529 | |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 4530 | // For correct semantics, we start the need worksources first, so that we won't |
| 4531 | // make inappropriate history items as if all wake locks went away and new ones |
| 4532 | // appeared. This is okay because tracking of wake locks allows nesting. |
Narayan Kamath | 8182202 | 2017-12-08 11:56:01 +0000 | [diff] [blame] | 4533 | // |
| 4534 | // First the starts : |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4535 | final int NN = newWs.size(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 4536 | for (int i=0; i<NN; i++) { |
Narayan Kamath | 8182202 | 2017-12-08 11:56:01 +0000 | [diff] [blame] | 4537 | noteStartWakeLocked(newWs.get(i), newPid, null, newName, newHistoryName, newType, |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4538 | newUnimportantForLogging, elapsedRealtime, uptime); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 4539 | } |
Narayan Kamath | 8182202 | 2017-12-08 11:56:01 +0000 | [diff] [blame] | 4540 | if (wcs != null) { |
| 4541 | List<WorkChain> newChains = wcs[0]; |
| 4542 | if (newChains != null) { |
| 4543 | for (int i = 0; i < newChains.size(); ++i) { |
| 4544 | final WorkChain newChain = newChains.get(i); |
| 4545 | noteStartWakeLocked(newChain.getAttributionUid(), newPid, newChain, newName, |
| 4546 | newHistoryName, newType, newUnimportantForLogging, elapsedRealtime, |
| 4547 | uptime); |
| 4548 | } |
| 4549 | } |
| 4550 | } |
| 4551 | |
| 4552 | // Then the stops : |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 4553 | final int NO = ws.size(); |
| 4554 | for (int i=0; i<NO; i++) { |
Narayan Kamath | 8182202 | 2017-12-08 11:56:01 +0000 | [diff] [blame] | 4555 | noteStopWakeLocked(ws.get(i), pid, null, name, historyName, type, elapsedRealtime, |
| 4556 | uptime); |
| 4557 | } |
| 4558 | if (wcs != null) { |
| 4559 | List<WorkChain> goneChains = wcs[1]; |
| 4560 | if (goneChains != null) { |
| 4561 | for (int i = 0; i < goneChains.size(); ++i) { |
| 4562 | final WorkChain goneChain = goneChains.get(i); |
| 4563 | noteStopWakeLocked(goneChain.getAttributionUid(), pid, goneChain, name, |
| 4564 | historyName, type, elapsedRealtime, uptime); |
| 4565 | } |
| 4566 | } |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 4567 | } |
| 4568 | } |
| 4569 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4570 | public void noteStopWakeFromSourceLocked(WorkSource ws, int pid, String name, |
| 4571 | String historyName, int type) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4572 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4573 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 4574 | final int N = ws.size(); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 4575 | for (int i=0; i<N; i++) { |
Narayan Kamath | 8182202 | 2017-12-08 11:56:01 +0000 | [diff] [blame] | 4576 | noteStopWakeLocked(ws.get(i), pid, null, name, historyName, type, elapsedRealtime, |
| 4577 | uptime); |
| 4578 | } |
| 4579 | |
| 4580 | List<WorkChain> wcs = ws.getWorkChains(); |
| 4581 | if (wcs != null) { |
| 4582 | for (int i = 0; i < wcs.size(); ++i) { |
| 4583 | final WorkChain wc = wcs.get(i); |
| 4584 | noteStopWakeLocked(wc.getAttributionUid(), pid, wc, name, historyName, type, |
| 4585 | elapsedRealtime, uptime); |
| 4586 | } |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 4587 | } |
| 4588 | } |
| 4589 | |
Dianne Hackborn | d0db6f0 | 2016-07-18 14:14:20 -0700 | [diff] [blame] | 4590 | public void noteLongPartialWakelockStart(String name, String historyName, int uid) { |
Yangster-mac | 2f5daec | 2018-01-16 10:23:15 -0800 | [diff] [blame] | 4591 | StatsLog.write_non_chained(StatsLog.LONG_PARTIAL_WAKELOCK_STATE_CHANGED, |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 4592 | uid, null, name, historyName, |
| 4593 | StatsLog.LONG_PARTIAL_WAKELOCK_STATE_CHANGED__STATE__ON); |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 4594 | |
Dianne Hackborn | d0db6f0 | 2016-07-18 14:14:20 -0700 | [diff] [blame] | 4595 | uid = mapUid(uid); |
Narayan Kamath | 96a9256 | 2018-01-02 18:57:17 +0000 | [diff] [blame] | 4596 | noteLongPartialWakeLockStartInternal(name, historyName, uid); |
Narayan Kamath | 96a9256 | 2018-01-02 18:57:17 +0000 | [diff] [blame] | 4597 | } |
| 4598 | |
| 4599 | public void noteLongPartialWakelockStartFromSource(String name, String historyName, |
| 4600 | WorkSource workSource) { |
| 4601 | final int N = workSource.size(); |
| 4602 | for (int i = 0; i < N; ++i) { |
| 4603 | final int uid = mapUid(workSource.get(i)); |
| 4604 | noteLongPartialWakeLockStartInternal(name, historyName, uid); |
Yangster-mac | 2f5daec | 2018-01-16 10:23:15 -0800 | [diff] [blame] | 4605 | StatsLog.write_non_chained(StatsLog.LONG_PARTIAL_WAKELOCK_STATE_CHANGED, |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 4606 | workSource.get(i), workSource.getName(i), name, historyName, |
| 4607 | StatsLog.LONG_PARTIAL_WAKELOCK_STATE_CHANGED__STATE__ON); |
Narayan Kamath | 96a9256 | 2018-01-02 18:57:17 +0000 | [diff] [blame] | 4608 | } |
| 4609 | |
| 4610 | final ArrayList<WorkChain> workChains = workSource.getWorkChains(); |
| 4611 | if (workChains != null) { |
| 4612 | for (int i = 0; i < workChains.size(); ++i) { |
| 4613 | final WorkChain workChain = workChains.get(i); |
| 4614 | final int uid = workChain.getAttributionUid(); |
| 4615 | noteLongPartialWakeLockStartInternal(name, historyName, uid); |
| 4616 | |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 4617 | StatsLog.write(StatsLog.LONG_PARTIAL_WAKELOCK_STATE_CHANGED, |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 4618 | workChain.getUids(), workChain.getTags(), name, historyName, |
| 4619 | StatsLog.LONG_PARTIAL_WAKELOCK_STATE_CHANGED__STATE__ON); |
Narayan Kamath | 96a9256 | 2018-01-02 18:57:17 +0000 | [diff] [blame] | 4620 | } |
| 4621 | } |
| 4622 | } |
| 4623 | |
| 4624 | private void noteLongPartialWakeLockStartInternal(String name, String historyName, int uid) { |
Dianne Hackborn | d0db6f0 | 2016-07-18 14:14:20 -0700 | [diff] [blame] | 4625 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4626 | final long uptime = mClocks.uptimeMillis(); |
| 4627 | if (historyName == null) { |
| 4628 | historyName = name; |
| 4629 | } |
| 4630 | if (!mActiveEvents.updateState(HistoryItem.EVENT_LONG_WAKE_LOCK_START, historyName, uid, |
| 4631 | 0)) { |
| 4632 | return; |
| 4633 | } |
| 4634 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_LONG_WAKE_LOCK_START, |
| 4635 | historyName, uid); |
| 4636 | } |
| 4637 | |
| 4638 | public void noteLongPartialWakelockFinish(String name, String historyName, int uid) { |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 4639 | StatsLog.write_non_chained(StatsLog.LONG_PARTIAL_WAKELOCK_STATE_CHANGED, uid, null, |
| 4640 | name, historyName, StatsLog.LONG_PARTIAL_WAKELOCK_STATE_CHANGED__STATE__OFF); |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 4641 | |
Dianne Hackborn | d0db6f0 | 2016-07-18 14:14:20 -0700 | [diff] [blame] | 4642 | uid = mapUid(uid); |
Narayan Kamath | 96a9256 | 2018-01-02 18:57:17 +0000 | [diff] [blame] | 4643 | noteLongPartialWakeLockFinishInternal(name, historyName, uid); |
Narayan Kamath | 96a9256 | 2018-01-02 18:57:17 +0000 | [diff] [blame] | 4644 | } |
| 4645 | |
| 4646 | public void noteLongPartialWakelockFinishFromSource(String name, String historyName, |
| 4647 | WorkSource workSource) { |
| 4648 | final int N = workSource.size(); |
| 4649 | for (int i = 0; i < N; ++i) { |
| 4650 | final int uid = mapUid(workSource.get(i)); |
| 4651 | noteLongPartialWakeLockFinishInternal(name, historyName, uid); |
Yangster-mac | 2f5daec | 2018-01-16 10:23:15 -0800 | [diff] [blame] | 4652 | StatsLog.write_non_chained(StatsLog.LONG_PARTIAL_WAKELOCK_STATE_CHANGED, |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 4653 | workSource.get(i), workSource.getName(i), name, historyName, |
| 4654 | StatsLog.LONG_PARTIAL_WAKELOCK_STATE_CHANGED__STATE__OFF); |
Narayan Kamath | 96a9256 | 2018-01-02 18:57:17 +0000 | [diff] [blame] | 4655 | } |
| 4656 | |
| 4657 | final ArrayList<WorkChain> workChains = workSource.getWorkChains(); |
| 4658 | if (workChains != null) { |
| 4659 | for (int i = 0; i < workChains.size(); ++i) { |
| 4660 | final WorkChain workChain = workChains.get(i); |
| 4661 | final int uid = workChain.getAttributionUid(); |
Narayan Kamath | 96a9256 | 2018-01-02 18:57:17 +0000 | [diff] [blame] | 4662 | noteLongPartialWakeLockFinishInternal(name, historyName, uid); |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 4663 | StatsLog.write(StatsLog.LONG_PARTIAL_WAKELOCK_STATE_CHANGED, |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 4664 | workChain.getUids(), workChain.getTags(), name, historyName, |
| 4665 | StatsLog.LONG_PARTIAL_WAKELOCK_STATE_CHANGED__STATE__OFF); |
Narayan Kamath | 96a9256 | 2018-01-02 18:57:17 +0000 | [diff] [blame] | 4666 | } |
| 4667 | } |
| 4668 | } |
| 4669 | |
| 4670 | private void noteLongPartialWakeLockFinishInternal(String name, String historyName, int uid) { |
Dianne Hackborn | d0db6f0 | 2016-07-18 14:14:20 -0700 | [diff] [blame] | 4671 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4672 | final long uptime = mClocks.uptimeMillis(); |
| 4673 | if (historyName == null) { |
| 4674 | historyName = name; |
| 4675 | } |
| 4676 | if (!mActiveEvents.updateState(HistoryItem.EVENT_LONG_WAKE_LOCK_FINISH, historyName, uid, |
| 4677 | 0)) { |
| 4678 | return; |
| 4679 | } |
| 4680 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_LONG_WAKE_LOCK_FINISH, |
| 4681 | historyName, uid); |
| 4682 | } |
| 4683 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4684 | void aggregateLastWakeupUptimeLocked(long uptimeMs) { |
| 4685 | if (mLastWakeupReason != null) { |
| 4686 | long deltaUptime = uptimeMs - mLastWakeupUptimeMs; |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 4687 | SamplingTimer timer = getWakeupReasonTimerLocked(mLastWakeupReason); |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 4688 | timer.add(deltaUptime * 1000, 1); // time in in microseconds |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 4689 | StatsLog.write(StatsLog.KERNEL_WAKEUP_REPORTED, mLastWakeupReason, |
| 4690 | /* duration_usec */ deltaUptime * 1000); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4691 | mLastWakeupReason = null; |
| 4692 | } |
| 4693 | } |
| 4694 | |
| 4695 | public void noteWakeupReasonLocked(String reason) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4696 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4697 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 4698 | if (DEBUG_HISTORY) Slog.v(TAG, "Wakeup reason \"" + reason +"\": " |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4699 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4700 | aggregateLastWakeupUptimeLocked(uptime); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4701 | mHistoryCur.wakeReasonTag = mHistoryCur.localWakeReasonTag; |
| 4702 | mHistoryCur.wakeReasonTag.string = reason; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4703 | mHistoryCur.wakeReasonTag.uid = 0; |
| 4704 | mLastWakeupReason = reason; |
| 4705 | mLastWakeupUptimeMs = uptime; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4706 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4707 | } |
| 4708 | |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 4709 | public boolean startAddingCpuLocked() { |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 4710 | mExternalSync.cancelCpuSyncDueToWakelockChange(); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 4711 | return mOnBatteryInternal; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 4712 | } |
| 4713 | |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 4714 | public void finishAddingCpuLocked(int totalUTime, int totalSTime, int statUserTime, |
| 4715 | int statSystemTime, int statIOWaitTime, int statIrqTime, |
| 4716 | int statSoftIrqTime, int statIdleTime) { |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 4717 | if (DEBUG) Slog.d(TAG, "Adding cpu: tuser=" + totalUTime + " tsys=" + totalSTime |
| 4718 | + " user=" + statUserTime + " sys=" + statSystemTime |
| 4719 | + " io=" + statIOWaitTime + " irq=" + statIrqTime |
| 4720 | + " sirq=" + statSoftIrqTime + " idle=" + statIdleTime); |
| 4721 | mCurStepCpuUserTime += totalUTime; |
| 4722 | mCurStepCpuSystemTime += totalSTime; |
| 4723 | mCurStepStatUserTime += statUserTime; |
| 4724 | mCurStepStatSystemTime += statSystemTime; |
| 4725 | mCurStepStatIOWaitTime += statIOWaitTime; |
| 4726 | mCurStepStatIrqTime += statIrqTime; |
| 4727 | mCurStepStatSoftIrqTime += statSoftIrqTime; |
| 4728 | mCurStepStatIdleTime += statIdleTime; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 4729 | } |
| 4730 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4731 | public void noteProcessDiedLocked(int uid, int pid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4732 | uid = mapUid(uid); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4733 | Uid u = mUidStats.get(uid); |
| 4734 | if (u != null) { |
| 4735 | u.mPids.remove(pid); |
| 4736 | } |
| 4737 | } |
| 4738 | |
| 4739 | public long getProcessWakeTime(int uid, int pid, long realtime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4740 | uid = mapUid(uid); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4741 | Uid u = mUidStats.get(uid); |
| 4742 | if (u != null) { |
| 4743 | Uid.Pid p = u.mPids.get(pid); |
| 4744 | if (p != null) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 4745 | return p.mWakeSumMs + (p.mWakeNesting > 0 ? (realtime - p.mWakeStartMs) : 0); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4746 | } |
| 4747 | } |
| 4748 | return 0; |
| 4749 | } |
| 4750 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 4751 | public void reportExcessiveCpuLocked(int uid, String proc, long overTime, long usedTime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4752 | uid = mapUid(uid); |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 4753 | Uid u = mUidStats.get(uid); |
| 4754 | if (u != null) { |
| 4755 | u.reportExcessiveCpuLocked(proc, overTime, usedTime); |
| 4756 | } |
| 4757 | } |
| 4758 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4759 | int mSensorNesting; |
| 4760 | |
| 4761 | public void noteStartSensorLocked(int uid, int sensor) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4762 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4763 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4764 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4765 | if (mSensorNesting == 0) { |
| 4766 | mHistoryCur.states |= HistoryItem.STATE_SENSOR_ON_FLAG; |
| 4767 | if (DEBUG_HISTORY) Slog.v(TAG, "Start sensor to: " |
| 4768 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4769 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4770 | } |
| 4771 | mSensorNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4772 | getUidStatsLocked(uid).noteStartSensor(sensor, elapsedRealtime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4773 | } |
| 4774 | |
| 4775 | public void noteStopSensorLocked(int uid, int sensor) { |
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 | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4779 | mSensorNesting--; |
| 4780 | if (mSensorNesting == 0) { |
| 4781 | mHistoryCur.states &= ~HistoryItem.STATE_SENSOR_ON_FLAG; |
| 4782 | if (DEBUG_HISTORY) Slog.v(TAG, "Stop sensor to: " |
| 4783 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4784 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4785 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4786 | getUidStatsLocked(uid).noteStopSensor(sensor, elapsedRealtime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4787 | } |
| 4788 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4789 | int mGpsNesting; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4790 | |
Narayan Kamath | 32684dd | 2018-01-08 17:32:51 +0000 | [diff] [blame] | 4791 | public void noteGpsChangedLocked(WorkSource oldWs, WorkSource newWs) { |
| 4792 | for (int i = 0; i < newWs.size(); ++i) { |
| 4793 | noteStartGpsLocked(newWs.get(i), null); |
| 4794 | } |
| 4795 | |
| 4796 | for (int i = 0; i < oldWs.size(); ++i) { |
| 4797 | noteStopGpsLocked((oldWs.get(i)), null); |
| 4798 | } |
| 4799 | |
| 4800 | List<WorkChain>[] wcs = WorkSource.diffChains(oldWs, newWs); |
| 4801 | if (wcs != null) { |
| 4802 | if (wcs[0] != null) { |
| 4803 | final List<WorkChain> newChains = wcs[0]; |
| 4804 | for (int i = 0; i < newChains.size(); ++i) { |
| 4805 | noteStartGpsLocked(-1, newChains.get(i)); |
| 4806 | } |
| 4807 | } |
| 4808 | |
| 4809 | if (wcs[1] != null) { |
| 4810 | final List<WorkChain> goneChains = wcs[1]; |
| 4811 | for (int i = 0; i < goneChains.size(); ++i) { |
| 4812 | noteStopGpsLocked(-1, goneChains.get(i)); |
| 4813 | } |
| 4814 | } |
| 4815 | } |
| 4816 | } |
| 4817 | |
| 4818 | private void noteStartGpsLocked(int uid, WorkChain workChain) { |
| 4819 | uid = getAttributionUid(uid, workChain); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4820 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4821 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4822 | if (mGpsNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4823 | mHistoryCur.states |= HistoryItem.STATE_GPS_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4824 | if (DEBUG_HISTORY) Slog.v(TAG, "Start GPS to: " |
| 4825 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4826 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4827 | } |
| 4828 | mGpsNesting++; |
Narayan Kamath | 32684dd | 2018-01-08 17:32:51 +0000 | [diff] [blame] | 4829 | |
| 4830 | if (workChain == null) { |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 4831 | StatsLog.write_non_chained(StatsLog.GPS_SCAN_STATE_CHANGED, uid, null, |
| 4832 | StatsLog.GPS_SCAN_STATE_CHANGED__STATE__ON); |
Narayan Kamath | 32684dd | 2018-01-08 17:32:51 +0000 | [diff] [blame] | 4833 | } else { |
| 4834 | StatsLog.write(StatsLog.GPS_SCAN_STATE_CHANGED, |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 4835 | workChain.getUids(), workChain.getTags(), |
| 4836 | StatsLog.GPS_SCAN_STATE_CHANGED__STATE__ON); |
Narayan Kamath | 32684dd | 2018-01-08 17:32:51 +0000 | [diff] [blame] | 4837 | } |
| 4838 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4839 | getUidStatsLocked(uid).noteStartGps(elapsedRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4840 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4841 | |
Narayan Kamath | 32684dd | 2018-01-08 17:32:51 +0000 | [diff] [blame] | 4842 | private void noteStopGpsLocked(int uid, WorkChain workChain) { |
| 4843 | uid = getAttributionUid(uid, workChain); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4844 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4845 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4846 | mGpsNesting--; |
| 4847 | if (mGpsNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4848 | mHistoryCur.states &= ~HistoryItem.STATE_GPS_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4849 | if (DEBUG_HISTORY) Slog.v(TAG, "Stop GPS to: " |
| 4850 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4851 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 4852 | stopAllGpsSignalQualityTimersLocked(-1); |
| 4853 | mGpsSignalQualityBin = -1; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4854 | } |
Narayan Kamath | 32684dd | 2018-01-08 17:32:51 +0000 | [diff] [blame] | 4855 | |
| 4856 | if (workChain == null) { |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 4857 | StatsLog.write_non_chained(StatsLog.GPS_SCAN_STATE_CHANGED, uid, null, |
| 4858 | StatsLog.GPS_SCAN_STATE_CHANGED__STATE__OFF); |
Narayan Kamath | 32684dd | 2018-01-08 17:32:51 +0000 | [diff] [blame] | 4859 | } else { |
| 4860 | StatsLog.write(StatsLog.GPS_SCAN_STATE_CHANGED, workChain.getUids(), |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 4861 | workChain.getTags(), StatsLog.GPS_SCAN_STATE_CHANGED__STATE__OFF); |
Narayan Kamath | 32684dd | 2018-01-08 17:32:51 +0000 | [diff] [blame] | 4862 | } |
| 4863 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4864 | getUidStatsLocked(uid).noteStopGps(elapsedRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4865 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 4866 | |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 4867 | public void noteGpsSignalQualityLocked(int signalLevel) { |
| 4868 | if (mGpsNesting == 0) { |
| 4869 | return; |
| 4870 | } |
| 4871 | if (signalLevel < 0 || signalLevel >= GnssMetrics.NUM_GPS_SIGNAL_QUALITY_LEVELS) { |
| 4872 | stopAllGpsSignalQualityTimersLocked(-1); |
| 4873 | return; |
| 4874 | } |
| 4875 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4876 | final long uptime = mClocks.uptimeMillis(); |
| 4877 | if (mGpsSignalQualityBin != signalLevel) { |
| 4878 | if (mGpsSignalQualityBin >= 0) { |
| 4879 | mGpsSignalQualityTimer[mGpsSignalQualityBin].stopRunningLocked(elapsedRealtime); |
| 4880 | } |
| 4881 | if(!mGpsSignalQualityTimer[signalLevel].isRunningLocked()) { |
| 4882 | mGpsSignalQualityTimer[signalLevel].startRunningLocked(elapsedRealtime); |
| 4883 | } |
| 4884 | mHistoryCur.states2 = (mHistoryCur.states2&~HistoryItem.STATE2_GPS_SIGNAL_QUALITY_MASK) |
| 4885 | | (signalLevel << HistoryItem.STATE2_GPS_SIGNAL_QUALITY_SHIFT); |
| 4886 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4887 | mGpsSignalQualityBin = signalLevel; |
| 4888 | } |
| 4889 | return; |
| 4890 | } |
| 4891 | |
Andreas Gampe | 3f24e69 | 2018-02-05 13:24:28 -0800 | [diff] [blame] | 4892 | @GuardedBy("this") |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4893 | public void noteScreenStateLocked(int state) { |
Amith Yamasani | 674c9bb | 2017-02-01 09:45:17 -0800 | [diff] [blame] | 4894 | state = mPretendScreenOff ? Display.STATE_OFF : state; |
Santos Cordon | e94f050 | 2017-02-24 12:31:20 -0800 | [diff] [blame] | 4895 | |
| 4896 | // Battery stats relies on there being 4 states. To accommodate this, new states beyond the |
| 4897 | // original 4 are mapped to one of the originals. |
| 4898 | if (state > MAX_TRACKED_SCREEN_STATE) { |
| 4899 | switch (state) { |
| 4900 | case Display.STATE_VR: |
| 4901 | state = Display.STATE_ON; |
| 4902 | break; |
| 4903 | default: |
| 4904 | Slog.wtf(TAG, "Unknown screen state (not mapped): " + state); |
| 4905 | break; |
| 4906 | } |
| 4907 | } |
| 4908 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4909 | if (mScreenState != state) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 4910 | recordDailyStatsIfNeededLocked(true); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4911 | final int oldState = mScreenState; |
| 4912 | mScreenState = state; |
| 4913 | if (DEBUG) Slog.v(TAG, "Screen state: oldState=" + Display.stateToString(oldState) |
| 4914 | + ", newState=" + Display.stateToString(state)); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4915 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 4916 | if (state != Display.STATE_UNKNOWN) { |
| 4917 | int stepState = state-1; |
Santos Cordon | e94f050 | 2017-02-24 12:31:20 -0800 | [diff] [blame] | 4918 | if ((stepState & STEP_LEVEL_MODE_SCREEN_STATE) == stepState) { |
| 4919 | mModStepMode |= (mCurStepMode & STEP_LEVEL_MODE_SCREEN_STATE) ^ stepState; |
| 4920 | mCurStepMode = (mCurStepMode & ~STEP_LEVEL_MODE_SCREEN_STATE) | stepState; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 4921 | } else { |
| 4922 | Slog.wtf(TAG, "Unexpected screen state: " + state); |
| 4923 | } |
| 4924 | } |
| 4925 | |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4926 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4927 | final long uptime = mClocks.uptimeMillis(); |
| 4928 | |
| 4929 | boolean updateHistory = false; |
| 4930 | if (isScreenDoze(state)) { |
| 4931 | mHistoryCur.states |= HistoryItem.STATE_SCREEN_DOZE_FLAG; |
| 4932 | mScreenDozeTimer.startRunningLocked(elapsedRealtime); |
| 4933 | updateHistory = true; |
| 4934 | } else if (isScreenDoze(oldState)) { |
| 4935 | mHistoryCur.states &= ~HistoryItem.STATE_SCREEN_DOZE_FLAG; |
| 4936 | mScreenDozeTimer.stopRunningLocked(elapsedRealtime); |
| 4937 | updateHistory = true; |
| 4938 | } |
| 4939 | if (isScreenOn(state)) { |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4940 | mHistoryCur.states |= HistoryItem.STATE_SCREEN_ON_FLAG; |
| 4941 | if (DEBUG_HISTORY) Slog.v(TAG, "Screen on to: " |
| 4942 | + Integer.toHexString(mHistoryCur.states)); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4943 | mScreenOnTimer.startRunningLocked(elapsedRealtime); |
| 4944 | if (mScreenBrightnessBin >= 0) { |
| 4945 | mScreenBrightnessTimer[mScreenBrightnessBin].startRunningLocked(elapsedRealtime); |
| 4946 | } |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4947 | updateHistory = true; |
| 4948 | } else if (isScreenOn(oldState)) { |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4949 | mHistoryCur.states &= ~HistoryItem.STATE_SCREEN_ON_FLAG; |
| 4950 | if (DEBUG_HISTORY) Slog.v(TAG, "Screen off to: " |
| 4951 | + Integer.toHexString(mHistoryCur.states)); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4952 | mScreenOnTimer.stopRunningLocked(elapsedRealtime); |
| 4953 | if (mScreenBrightnessBin >= 0) { |
| 4954 | mScreenBrightnessTimer[mScreenBrightnessBin].stopRunningLocked(elapsedRealtime); |
| 4955 | } |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4956 | updateHistory = true; |
| 4957 | } |
| 4958 | if (updateHistory) { |
| 4959 | if (DEBUG_HISTORY) Slog.v(TAG, "Screen state to: " |
| 4960 | + Display.stateToString(state)); |
| 4961 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4962 | } |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 4963 | mExternalSync.scheduleCpuSyncDueToScreenStateChange( |
| 4964 | mOnBatteryTimeBase.isRunning(), mOnBatteryScreenOffTimeBase.isRunning()); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4965 | if (isScreenOn(state)) { |
| 4966 | updateTimeBasesLocked(mOnBatteryTimeBase.isRunning(), state, |
| 4967 | mClocks.uptimeMillis() * 1000, elapsedRealtime * 1000); |
| 4968 | // Fake a wake lock, so we consider the device waked as long as the screen is on. |
Narayan Kamath | 8182202 | 2017-12-08 11:56:01 +0000 | [diff] [blame] | 4969 | noteStartWakeLocked(-1, -1, null, "screen", null, WAKE_TYPE_PARTIAL, false, |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4970 | elapsedRealtime, uptime); |
| 4971 | } else if (isScreenOn(oldState)) { |
Narayan Kamath | 8182202 | 2017-12-08 11:56:01 +0000 | [diff] [blame] | 4972 | noteStopWakeLocked(-1, -1, null, "screen", "screen", WAKE_TYPE_PARTIAL, |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4973 | elapsedRealtime, uptime); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4974 | updateTimeBasesLocked(mOnBatteryTimeBase.isRunning(), state, |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4975 | mClocks.uptimeMillis() * 1000, elapsedRealtime * 1000); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4976 | } |
| 4977 | // Update discharge amounts. |
| 4978 | if (mOnBatteryInternal) { |
| 4979 | updateDischargeScreenLevelsLocked(oldState, state); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 4980 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4981 | } |
| 4982 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4983 | |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 4984 | @UnsupportedAppUsage |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4985 | public void noteScreenBrightnessLocked(int brightness) { |
| 4986 | // Bin the brightness. |
| 4987 | int bin = brightness / (256/NUM_SCREEN_BRIGHTNESS_BINS); |
| 4988 | if (bin < 0) bin = 0; |
| 4989 | else if (bin >= NUM_SCREEN_BRIGHTNESS_BINS) bin = NUM_SCREEN_BRIGHTNESS_BINS-1; |
| 4990 | if (mScreenBrightnessBin != bin) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4991 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4992 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4993 | mHistoryCur.states = (mHistoryCur.states&~HistoryItem.STATE_BRIGHTNESS_MASK) |
| 4994 | | (bin << HistoryItem.STATE_BRIGHTNESS_SHIFT); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4995 | if (DEBUG_HISTORY) Slog.v(TAG, "Screen brightness " + bin + " to: " |
| 4996 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4997 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4998 | if (mScreenState == Display.STATE_ON) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4999 | if (mScreenBrightnessBin >= 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5000 | mScreenBrightnessTimer[mScreenBrightnessBin].stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5001 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5002 | mScreenBrightnessTimer[bin].startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5003 | } |
| 5004 | mScreenBrightnessBin = bin; |
| 5005 | } |
| 5006 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5007 | |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 5008 | @UnsupportedAppUsage |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5009 | public void noteUserActivityLocked(int uid, int event) { |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 5010 | if (mOnBatteryInternal) { |
| 5011 | uid = mapUid(uid); |
| 5012 | getUidStatsLocked(uid).noteUserActivityLocked(event); |
| 5013 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5014 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5015 | |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 5016 | public void noteWakeUpLocked(String reason, int reasonUid) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5017 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5018 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 5019 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_SCREEN_WAKE_UP, |
| 5020 | reason, reasonUid); |
| 5021 | } |
| 5022 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 5023 | public void noteInteractiveLocked(boolean interactive) { |
| 5024 | if (mInteractive != interactive) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5025 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 5026 | mInteractive = interactive; |
| 5027 | if (DEBUG) Slog.v(TAG, "Interactive: " + interactive); |
| 5028 | if (interactive) { |
| 5029 | mInteractiveTimer.startRunningLocked(elapsedRealtime); |
| 5030 | } else { |
| 5031 | mInteractiveTimer.stopRunningLocked(elapsedRealtime); |
| 5032 | } |
| 5033 | } |
| 5034 | } |
| 5035 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 5036 | public void noteConnectivityChangedLocked(int type, String extra) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5037 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5038 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 5039 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_CONNECTIVITY_CHANGED, |
| 5040 | extra, type); |
| 5041 | mNumConnectivityChange++; |
| 5042 | } |
| 5043 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 5044 | private void noteMobileRadioApWakeupLocked(final long elapsedRealtimeMillis, |
| 5045 | final long uptimeMillis, int uid) { |
| 5046 | uid = mapUid(uid); |
| 5047 | addHistoryEventLocked(elapsedRealtimeMillis, uptimeMillis, HistoryItem.EVENT_WAKEUP_AP, "", |
| 5048 | uid); |
| 5049 | getUidStatsLocked(uid).noteMobileRadioApWakeupLocked(); |
| 5050 | } |
| 5051 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 5052 | /** |
| 5053 | * Updates the radio power state and returns true if an external stats collection should occur. |
| 5054 | */ |
| 5055 | public boolean noteMobileRadioPowerStateLocked(int powerState, long timestampNs, int uid) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5056 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5057 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 5058 | if (mMobileRadioPowerState != powerState) { |
| 5059 | long realElapsedRealtimeMs; |
| 5060 | final boolean active = |
| 5061 | powerState == DataConnectionRealTimeInfo.DC_POWER_STATE_MEDIUM |
| 5062 | || powerState == DataConnectionRealTimeInfo.DC_POWER_STATE_HIGH; |
| 5063 | if (active) { |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 5064 | if (uid > 0) { |
| 5065 | noteMobileRadioApWakeupLocked(elapsedRealtime, uptime, uid); |
| 5066 | } |
| 5067 | |
Adam Lesinski | 9acfd81 | 2016-04-19 18:29:50 -0700 | [diff] [blame] | 5068 | mMobileRadioActiveStartTime = realElapsedRealtimeMs = timestampNs / (1000 * 1000); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 5069 | mHistoryCur.states |= HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG; |
| 5070 | } else { |
| 5071 | realElapsedRealtimeMs = timestampNs / (1000*1000); |
Dianne Hackborn | f7097a5 | 2014-05-13 09:56:14 -0700 | [diff] [blame] | 5072 | long lastUpdateTimeMs = mMobileRadioActiveStartTime; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 5073 | if (realElapsedRealtimeMs < lastUpdateTimeMs) { |
| 5074 | Slog.wtf(TAG, "Data connection inactive timestamp " + realElapsedRealtimeMs |
| 5075 | + " is before start time " + lastUpdateTimeMs); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5076 | realElapsedRealtimeMs = elapsedRealtime; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 5077 | } else if (realElapsedRealtimeMs < elapsedRealtime) { |
| 5078 | mMobileRadioActiveAdjustedTime.addCountLocked(elapsedRealtime |
| 5079 | - realElapsedRealtimeMs); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5080 | } |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 5081 | mHistoryCur.states &= ~HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG; |
| 5082 | } |
| 5083 | if (DEBUG_HISTORY) Slog.v(TAG, "Mobile network active " + active + " to: " |
| 5084 | + Integer.toHexString(mHistoryCur.states)); |
| 5085 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 5086 | mMobileRadioPowerState = powerState; |
Yangster-mac | 4c7255f | 2018-05-07 13:41:47 -0700 | [diff] [blame] | 5087 | StatsLog.write_non_chained(StatsLog.MOBILE_RADIO_POWER_STATE_CHANGED, uid, null, |
| 5088 | powerState); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 5089 | if (active) { |
| 5090 | mMobileRadioActiveTimer.startRunningLocked(elapsedRealtime); |
| 5091 | mMobileRadioActivePerAppTimer.startRunningLocked(elapsedRealtime); |
| 5092 | } else { |
| 5093 | mMobileRadioActiveTimer.stopRunningLocked(realElapsedRealtimeMs); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 5094 | mMobileRadioActivePerAppTimer.stopRunningLocked(realElapsedRealtimeMs); |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 5095 | // Tell the caller to collect radio network/power stats. |
| 5096 | return true; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 5097 | } |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 5098 | } |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 5099 | return false; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 5100 | } |
| 5101 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 5102 | public void notePowerSaveModeLocked(boolean enabled) { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 5103 | if (mPowerSaveModeEnabled != enabled) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 5104 | int stepState = enabled ? STEP_LEVEL_MODE_POWER_SAVE : 0; |
| 5105 | mModStepMode |= (mCurStepMode&STEP_LEVEL_MODE_POWER_SAVE) ^ stepState; |
| 5106 | mCurStepMode = (mCurStepMode&~STEP_LEVEL_MODE_POWER_SAVE) | stepState; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5107 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5108 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 5109 | mPowerSaveModeEnabled = enabled; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 5110 | if (enabled) { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 5111 | mHistoryCur.states2 |= HistoryItem.STATE2_POWER_SAVE_FLAG; |
| 5112 | if (DEBUG_HISTORY) Slog.v(TAG, "Power save mode enabled to: " |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 5113 | + Integer.toHexString(mHistoryCur.states2)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 5114 | mPowerSaveModeEnabledTimer.startRunningLocked(elapsedRealtime); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 5115 | } else { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 5116 | mHistoryCur.states2 &= ~HistoryItem.STATE2_POWER_SAVE_FLAG; |
| 5117 | if (DEBUG_HISTORY) Slog.v(TAG, "Power save mode disabled to: " |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 5118 | + Integer.toHexString(mHistoryCur.states2)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 5119 | mPowerSaveModeEnabledTimer.stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 5120 | } |
| 5121 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 5122 | StatsLog.write(StatsLog.BATTERY_SAVER_MODE_STATE_CHANGED, enabled ? |
| 5123 | StatsLog.BATTERY_SAVER_MODE_STATE_CHANGED__STATE__ON : |
| 5124 | StatsLog.BATTERY_SAVER_MODE_STATE_CHANGED__STATE__OFF); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 5125 | } |
| 5126 | } |
| 5127 | |
Bookatz | ddccf0a | 2017-11-28 16:48:14 -0800 | [diff] [blame] | 5128 | public void noteDeviceIdleModeLocked(final int mode, String activeReason, int activeUid) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5129 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5130 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 5131 | boolean nowIdling = mode == DEVICE_IDLE_MODE_DEEP; |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 5132 | if (mDeviceIdling && !nowIdling && activeReason == null) { |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5133 | // We don't go out of general idling mode until explicitly taken out of |
| 5134 | // device idle through going active or significant motion. |
| 5135 | nowIdling = true; |
| 5136 | } |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 5137 | boolean nowLightIdling = mode == DEVICE_IDLE_MODE_LIGHT; |
| 5138 | if (mDeviceLightIdling && !nowLightIdling && !nowIdling && activeReason == null) { |
| 5139 | // We don't go out of general light idling mode until explicitly taken out of |
| 5140 | // device idle through going active or significant motion. |
| 5141 | nowLightIdling = true; |
| 5142 | } |
| 5143 | if (activeReason != null && (mDeviceIdling || mDeviceLightIdling)) { |
| 5144 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_ACTIVE, |
| 5145 | activeReason, activeUid); |
| 5146 | } |
Bookatz | ddccf0a | 2017-11-28 16:48:14 -0800 | [diff] [blame] | 5147 | if (mDeviceIdling != nowIdling || mDeviceLightIdling != nowLightIdling) { |
| 5148 | int statsmode; |
| 5149 | if (nowIdling) statsmode = DEVICE_IDLE_MODE_DEEP; |
| 5150 | else if (nowLightIdling) statsmode = DEVICE_IDLE_MODE_LIGHT; |
| 5151 | else statsmode = DEVICE_IDLE_MODE_OFF; |
| 5152 | StatsLog.write(StatsLog.DEVICE_IDLING_MODE_STATE_CHANGED, statsmode); |
| 5153 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5154 | if (mDeviceIdling != nowIdling) { |
| 5155 | mDeviceIdling = nowIdling; |
| 5156 | int stepState = nowIdling ? STEP_LEVEL_MODE_DEVICE_IDLE : 0; |
| 5157 | mModStepMode |= (mCurStepMode&STEP_LEVEL_MODE_DEVICE_IDLE) ^ stepState; |
| 5158 | mCurStepMode = (mCurStepMode&~STEP_LEVEL_MODE_DEVICE_IDLE) | stepState; |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 5159 | if (nowIdling) { |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5160 | mDeviceIdlingTimer.startRunningLocked(elapsedRealtime); |
| 5161 | } else { |
| 5162 | mDeviceIdlingTimer.stopRunningLocked(elapsedRealtime); |
| 5163 | } |
| 5164 | } |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 5165 | if (mDeviceLightIdling != nowLightIdling) { |
| 5166 | mDeviceLightIdling = nowLightIdling; |
| 5167 | if (nowLightIdling) { |
| 5168 | mDeviceLightIdlingTimer.startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 5169 | } else { |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 5170 | mDeviceLightIdlingTimer.stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 5171 | } |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 5172 | } |
| 5173 | if (mDeviceIdleMode != mode) { |
| 5174 | mHistoryCur.states2 = (mHistoryCur.states2 & ~HistoryItem.STATE2_DEVICE_IDLE_MASK) |
| 5175 | | (mode << HistoryItem.STATE2_DEVICE_IDLE_SHIFT); |
| 5176 | if (DEBUG_HISTORY) Slog.v(TAG, "Device idle mode changed to: " |
| 5177 | + Integer.toHexString(mHistoryCur.states2)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 5178 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 5179 | long lastDuration = elapsedRealtime - mLastIdleTimeStart; |
| 5180 | mLastIdleTimeStart = elapsedRealtime; |
| 5181 | if (mDeviceIdleMode == DEVICE_IDLE_MODE_LIGHT) { |
| 5182 | if (lastDuration > mLongestLightIdleTime) { |
| 5183 | mLongestLightIdleTime = lastDuration; |
| 5184 | } |
| 5185 | mDeviceIdleModeLightTimer.stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 5186 | } else if (mDeviceIdleMode == DEVICE_IDLE_MODE_DEEP) { |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 5187 | if (lastDuration > mLongestFullIdleTime) { |
| 5188 | mLongestFullIdleTime = lastDuration; |
| 5189 | } |
| 5190 | mDeviceIdleModeFullTimer.stopRunningLocked(elapsedRealtime); |
| 5191 | } |
| 5192 | if (mode == DEVICE_IDLE_MODE_LIGHT) { |
| 5193 | mDeviceIdleModeLightTimer.startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 5194 | } else if (mode == DEVICE_IDLE_MODE_DEEP) { |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 5195 | mDeviceIdleModeFullTimer.startRunningLocked(elapsedRealtime); |
| 5196 | } |
| 5197 | mDeviceIdleMode = mode; |
Bookatz | ddccf0a | 2017-11-28 16:48:14 -0800 | [diff] [blame] | 5198 | StatsLog.write(StatsLog.DEVICE_IDLE_MODE_STATE_CHANGED, mode); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 5199 | } |
| 5200 | } |
| 5201 | |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 5202 | public void notePackageInstalledLocked(String pkgName, long versionCode) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5203 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5204 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 5205 | // XXX need to figure out what to do with long version codes. |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 5206 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_PACKAGE_INSTALLED, |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 5207 | pkgName, (int)versionCode); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5208 | PackageChange pc = new PackageChange(); |
| 5209 | pc.mPackageName = pkgName; |
| 5210 | pc.mUpdate = true; |
| 5211 | pc.mVersionCode = versionCode; |
| 5212 | addPackageChange(pc); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 5213 | } |
| 5214 | |
| 5215 | public void notePackageUninstalledLocked(String pkgName) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5216 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5217 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 5218 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_PACKAGE_UNINSTALLED, |
| 5219 | pkgName, 0); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5220 | PackageChange pc = new PackageChange(); |
| 5221 | pc.mPackageName = pkgName; |
| 5222 | pc.mUpdate = true; |
| 5223 | addPackageChange(pc); |
| 5224 | } |
| 5225 | |
| 5226 | private void addPackageChange(PackageChange pc) { |
| 5227 | if (mDailyPackageChanges == null) { |
| 5228 | mDailyPackageChanges = new ArrayList<>(); |
| 5229 | } |
| 5230 | mDailyPackageChanges.add(pc); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 5231 | } |
| 5232 | |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 5233 | void stopAllGpsSignalQualityTimersLocked(int except) { |
| 5234 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5235 | for (int i = 0; i < GnssMetrics.NUM_GPS_SIGNAL_QUALITY_LEVELS; i++) { |
| 5236 | if (i == except) { |
| 5237 | continue; |
| 5238 | } |
| 5239 | while (mGpsSignalQualityTimer[i].isRunningLocked()) { |
| 5240 | mGpsSignalQualityTimer[i].stopRunningLocked(elapsedRealtime); |
| 5241 | } |
| 5242 | } |
| 5243 | } |
| 5244 | |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 5245 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5246 | public void notePhoneOnLocked() { |
| 5247 | if (!mPhoneOn) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5248 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5249 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 5250 | mHistoryCur.states2 |= HistoryItem.STATE2_PHONE_IN_CALL_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5251 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone on to: " |
| 5252 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 5253 | addHistoryRecordLocked(elapsedRealtime, uptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5254 | mPhoneOn = true; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5255 | mPhoneOnTimer.startRunningLocked(elapsedRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5256 | } |
| 5257 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5258 | |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 5259 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5260 | public void notePhoneOffLocked() { |
| 5261 | if (mPhoneOn) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5262 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5263 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 5264 | mHistoryCur.states2 &= ~HistoryItem.STATE2_PHONE_IN_CALL_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5265 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone off to: " |
| 5266 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 5267 | addHistoryRecordLocked(elapsedRealtime, uptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5268 | mPhoneOn = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5269 | mPhoneOnTimer.stopRunningLocked(elapsedRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5270 | } |
| 5271 | } |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 5272 | |
Mike Ma | fbc01fc | 2018-04-02 10:28:28 -0700 | [diff] [blame] | 5273 | private void registerUsbStateReceiver(Context context) { |
| 5274 | final IntentFilter usbStateFilter = new IntentFilter(); |
| 5275 | usbStateFilter.addAction(UsbManager.ACTION_USB_STATE); |
| 5276 | context.registerReceiver(new BroadcastReceiver() { |
| 5277 | @Override |
| 5278 | public void onReceive(Context context, Intent intent) { |
| 5279 | final boolean state = intent.getBooleanExtra(UsbManager.USB_CONNECTED, false); |
| 5280 | synchronized (BatteryStatsImpl.this) { |
| 5281 | noteUsbConnectionStateLocked(state); |
| 5282 | } |
| 5283 | } |
| 5284 | }, usbStateFilter); |
| 5285 | synchronized (this) { |
| 5286 | if (mUsbDataState == USB_DATA_UNKNOWN) { |
| 5287 | final Intent usbState = context.registerReceiver(null, usbStateFilter); |
| 5288 | final boolean initState = usbState != null && usbState.getBooleanExtra( |
| 5289 | UsbManager.USB_CONNECTED, false); |
| 5290 | noteUsbConnectionStateLocked(initState); |
| 5291 | } |
| 5292 | } |
| 5293 | } |
| 5294 | |
| 5295 | private void noteUsbConnectionStateLocked(boolean connected) { |
| 5296 | int newState = connected ? USB_DATA_CONNECTED : USB_DATA_DISCONNECTED; |
Mike Ma | 926a97c | 2018-03-25 02:32:35 -0700 | [diff] [blame] | 5297 | if (mUsbDataState != newState) { |
| 5298 | mUsbDataState = newState; |
| 5299 | if (connected) { |
| 5300 | mHistoryCur.states2 |= HistoryItem.STATE2_USB_DATA_LINK_FLAG; |
| 5301 | } else { |
| 5302 | mHistoryCur.states2 &= ~HistoryItem.STATE2_USB_DATA_LINK_FLAG; |
| 5303 | } |
| 5304 | addHistoryRecordLocked(mClocks.elapsedRealtime(), mClocks.uptimeMillis()); |
| 5305 | } |
| 5306 | } |
| 5307 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5308 | void stopAllPhoneSignalStrengthTimersLocked(int except) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5309 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 5310 | for (int i = 0; i < SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 5311 | if (i == except) { |
| 5312 | continue; |
| 5313 | } |
| 5314 | while (mPhoneSignalStrengthsTimer[i].isRunningLocked()) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5315 | mPhoneSignalStrengthsTimer[i].stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 5316 | } |
| 5317 | } |
| 5318 | } |
| 5319 | |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5320 | private int fixPhoneServiceState(int state, int signalBin) { |
| 5321 | if (mPhoneSimStateRaw == TelephonyManager.SIM_STATE_ABSENT) { |
| 5322 | // In this case we will always be STATE_OUT_OF_SERVICE, so need |
| 5323 | // to infer that we are scanning from other data. |
| 5324 | if (state == ServiceState.STATE_OUT_OF_SERVICE |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 5325 | && signalBin > SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5326 | state = ServiceState.STATE_IN_SERVICE; |
| 5327 | } |
| 5328 | } |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 5329 | |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5330 | return state; |
| 5331 | } |
| 5332 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5333 | private void updateAllPhoneStateLocked(int state, int simState, int strengthBin) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5334 | boolean scanning = false; |
| 5335 | boolean newHistory = false; |
| 5336 | |
| 5337 | mPhoneServiceStateRaw = state; |
| 5338 | mPhoneSimStateRaw = simState; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5339 | mPhoneSignalStrengthBinRaw = strengthBin; |
| 5340 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5341 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5342 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5343 | |
| 5344 | if (simState == TelephonyManager.SIM_STATE_ABSENT) { |
| 5345 | // In this case we will always be STATE_OUT_OF_SERVICE, so need |
| 5346 | // to infer that we are scanning from other data. |
| 5347 | if (state == ServiceState.STATE_OUT_OF_SERVICE |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5348 | && strengthBin > SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5349 | state = ServiceState.STATE_IN_SERVICE; |
| 5350 | } |
| 5351 | } |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 5352 | |
| 5353 | // If the phone is powered off, stop all timers. |
| 5354 | if (state == ServiceState.STATE_POWER_OFF) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5355 | strengthBin = -1; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 5356 | |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5357 | // If we are in service, make sure the correct signal string timer is running. |
| 5358 | } else if (state == ServiceState.STATE_IN_SERVICE) { |
| 5359 | // Bin will be changed below. |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 5360 | |
| 5361 | // If we're out of service, we are in the lowest signal strength |
| 5362 | // bin and have the scanning bit set. |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 5363 | } else if (state == ServiceState.STATE_OUT_OF_SERVICE) { |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 5364 | scanning = true; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5365 | strengthBin = SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 5366 | if (!mPhoneSignalScanningTimer.isRunningLocked()) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5367 | mHistoryCur.states |= HistoryItem.STATE_PHONE_SCANNING_FLAG; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5368 | newHistory = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5369 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone started scanning to: " |
| 5370 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5371 | mPhoneSignalScanningTimer.startRunningLocked(elapsedRealtime); |
Yangster | 4ccebea | 2018-10-09 17:09:02 -0700 | [diff] [blame^] | 5372 | StatsLog.write(StatsLog.PHONE_SERVICE_STATE_CHANGED, state, simState, strengthBin); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 5373 | } |
| 5374 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5375 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 5376 | if (!scanning) { |
| 5377 | // If we are no longer scanning, then stop the scanning timer. |
| 5378 | if (mPhoneSignalScanningTimer.isRunningLocked()) { |
| 5379 | mHistoryCur.states &= ~HistoryItem.STATE_PHONE_SCANNING_FLAG; |
| 5380 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone stopped scanning to: " |
| 5381 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5382 | newHistory = true; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5383 | mPhoneSignalScanningTimer.stopRunningLocked(elapsedRealtime); |
Yangster | 4ccebea | 2018-10-09 17:09:02 -0700 | [diff] [blame^] | 5384 | StatsLog.write(StatsLog.PHONE_SERVICE_STATE_CHANGED, state, simState, strengthBin); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 5385 | } |
| 5386 | } |
| 5387 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5388 | if (mPhoneServiceState != state) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5389 | mHistoryCur.states = (mHistoryCur.states&~HistoryItem.STATE_PHONE_STATE_MASK) |
| 5390 | | (state << HistoryItem.STATE_PHONE_STATE_SHIFT); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5391 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone state " + state + " to: " |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5392 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5393 | newHistory = true; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5394 | mPhoneServiceState = state; |
| 5395 | } |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5396 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5397 | if (mPhoneSignalStrengthBin != strengthBin) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5398 | if (mPhoneSignalStrengthBin >= 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5399 | mPhoneSignalStrengthsTimer[mPhoneSignalStrengthBin].stopRunningLocked( |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5400 | elapsedRealtime); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5401 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5402 | if (strengthBin >= 0) { |
| 5403 | if (!mPhoneSignalStrengthsTimer[strengthBin].isRunningLocked()) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5404 | mPhoneSignalStrengthsTimer[strengthBin].startRunningLocked(elapsedRealtime); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5405 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5406 | mHistoryCur.states = (mHistoryCur.states&~HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_MASK) |
| 5407 | | (strengthBin << HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_SHIFT); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5408 | if (DEBUG_HISTORY) Slog.v(TAG, "Signal strength " + strengthBin + " to: " |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5409 | + Integer.toHexString(mHistoryCur.states)); |
| 5410 | newHistory = true; |
Bookatz | e588524 | 2017-10-24 20:10:31 -0700 | [diff] [blame] | 5411 | StatsLog.write(StatsLog.PHONE_SIGNAL_STRENGTH_CHANGED, strengthBin); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5412 | } else { |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5413 | stopAllPhoneSignalStrengthTimersLocked(-1); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5414 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5415 | mPhoneSignalStrengthBin = strengthBin; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5416 | } |
| 5417 | |
| 5418 | if (newHistory) { |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 5419 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5420 | } |
| 5421 | } |
| 5422 | |
| 5423 | /** |
| 5424 | * Telephony stack updates the phone state. |
| 5425 | * @param state phone state from ServiceState.getState() |
| 5426 | */ |
| 5427 | public void notePhoneStateLocked(int state, int simState) { |
| 5428 | updateAllPhoneStateLocked(state, simState, mPhoneSignalStrengthBinRaw); |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 5429 | } |
| 5430 | |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 5431 | @UnsupportedAppUsage |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 5432 | public void notePhoneSignalStrengthLocked(SignalStrength signalStrength) { |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 5433 | // Bin the strength. |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 5434 | int bin = signalStrength.getLevel(); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5435 | updateAllPhoneStateLocked(mPhoneServiceStateRaw, mPhoneSimStateRaw, bin); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 5436 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5437 | |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 5438 | @UnsupportedAppUsage |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 5439 | public void notePhoneDataConnectionStateLocked(int dataType, boolean hasData) { |
Tej Singh | eee317b | 2018-03-07 19:28:05 -0800 | [diff] [blame] | 5440 | // BatteryStats uses 0 to represent no network type. |
| 5441 | // Telephony does not have a concept of no network type, and uses 0 to represent unknown. |
| 5442 | // Unknown is included in DATA_CONNECTION_OTHER. |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 5443 | int bin = DATA_CONNECTION_NONE; |
| 5444 | if (hasData) { |
Tej Singh | eee317b | 2018-03-07 19:28:05 -0800 | [diff] [blame] | 5445 | if (dataType > 0 && dataType <= TelephonyManager.MAX_NETWORK_TYPE) { |
| 5446 | bin = dataType; |
| 5447 | } else { |
| 5448 | bin = DATA_CONNECTION_OTHER; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 5449 | } |
| 5450 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 5451 | if (DEBUG) Log.i(TAG, "Phone Data Connection -> " + dataType + " = " + hasData); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 5452 | if (mPhoneDataConnectionType != bin) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5453 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5454 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5455 | mHistoryCur.states = (mHistoryCur.states&~HistoryItem.STATE_DATA_CONNECTION_MASK) |
| 5456 | | (bin << HistoryItem.STATE_DATA_CONNECTION_SHIFT); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5457 | if (DEBUG_HISTORY) Slog.v(TAG, "Data connection " + bin + " to: " |
| 5458 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 5459 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 5460 | if (mPhoneDataConnectionType >= 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5461 | mPhoneDataConnectionsTimer[mPhoneDataConnectionType].stopRunningLocked( |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5462 | elapsedRealtime); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 5463 | } |
| 5464 | mPhoneDataConnectionType = bin; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5465 | mPhoneDataConnectionsTimer[bin].startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 5466 | } |
| 5467 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5468 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5469 | public void noteWifiOnLocked() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5470 | if (!mWifiOn) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5471 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5472 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5473 | mHistoryCur.states2 |= HistoryItem.STATE2_WIFI_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5474 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI on to: " |
| 5475 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 5476 | addHistoryRecordLocked(elapsedRealtime, uptime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5477 | mWifiOn = true; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5478 | mWifiOnTimer.startRunningLocked(elapsedRealtime); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5479 | scheduleSyncExternalStatsLocked("wifi-off", ExternalStatsSync.UPDATE_WIFI); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5480 | } |
| 5481 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5482 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5483 | public void noteWifiOffLocked() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5484 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5485 | final long uptime = mClocks.uptimeMillis(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5486 | if (mWifiOn) { |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5487 | mHistoryCur.states2 &= ~HistoryItem.STATE2_WIFI_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5488 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI off to: " |
| 5489 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 5490 | addHistoryRecordLocked(elapsedRealtime, uptime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5491 | mWifiOn = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5492 | mWifiOnTimer.stopRunningLocked(elapsedRealtime); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5493 | scheduleSyncExternalStatsLocked("wifi-on", ExternalStatsSync.UPDATE_WIFI); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5494 | } |
| 5495 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 5496 | |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 5497 | @UnsupportedAppUsage |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 5498 | public void noteAudioOnLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5499 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5500 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5501 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 5502 | if (mAudioOnNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5503 | mHistoryCur.states |= HistoryItem.STATE_AUDIO_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5504 | if (DEBUG_HISTORY) Slog.v(TAG, "Audio on to: " |
| 5505 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 5506 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5507 | mAudioOnTimer.startRunningLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 5508 | } |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 5509 | mAudioOnNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5510 | getUidStatsLocked(uid).noteAudioTurnedOnLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 5511 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5512 | |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 5513 | @UnsupportedAppUsage |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 5514 | public void noteAudioOffLocked(int uid) { |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 5515 | if (mAudioOnNesting == 0) { |
| 5516 | return; |
| 5517 | } |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5518 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5519 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5520 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 5521 | if (--mAudioOnNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5522 | mHistoryCur.states &= ~HistoryItem.STATE_AUDIO_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5523 | if (DEBUG_HISTORY) Slog.v(TAG, "Audio off to: " |
| 5524 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 5525 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5526 | mAudioOnTimer.stopRunningLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 5527 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5528 | getUidStatsLocked(uid).noteAudioTurnedOffLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 5529 | } |
| 5530 | |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 5531 | @UnsupportedAppUsage |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 5532 | public void noteVideoOnLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5533 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5534 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5535 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 5536 | if (mVideoOnNesting == 0) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5537 | mHistoryCur.states2 |= HistoryItem.STATE2_VIDEO_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5538 | if (DEBUG_HISTORY) Slog.v(TAG, "Video on to: " |
| 5539 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 5540 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5541 | mVideoOnTimer.startRunningLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 5542 | } |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 5543 | mVideoOnNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5544 | getUidStatsLocked(uid).noteVideoTurnedOnLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 5545 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5546 | |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 5547 | @UnsupportedAppUsage |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 5548 | public void noteVideoOffLocked(int uid) { |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 5549 | if (mVideoOnNesting == 0) { |
| 5550 | return; |
| 5551 | } |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5552 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5553 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5554 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 5555 | if (--mVideoOnNesting == 0) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5556 | mHistoryCur.states2 &= ~HistoryItem.STATE2_VIDEO_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5557 | if (DEBUG_HISTORY) Slog.v(TAG, "Video off to: " |
| 5558 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 5559 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5560 | mVideoOnTimer.stopRunningLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 5561 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5562 | getUidStatsLocked(uid).noteVideoTurnedOffLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 5563 | } |
| 5564 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 5565 | public void noteResetAudioLocked() { |
| 5566 | if (mAudioOnNesting > 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5567 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5568 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 5569 | mAudioOnNesting = 0; |
| 5570 | mHistoryCur.states &= ~HistoryItem.STATE_AUDIO_ON_FLAG; |
| 5571 | if (DEBUG_HISTORY) Slog.v(TAG, "Audio off to: " |
| 5572 | + Integer.toHexString(mHistoryCur.states)); |
| 5573 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 5574 | mAudioOnTimer.stopAllRunningLocked(elapsedRealtime); |
| 5575 | for (int i=0; i<mUidStats.size(); i++) { |
| 5576 | BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 5577 | uid.noteResetAudioLocked(elapsedRealtime); |
| 5578 | } |
| 5579 | } |
| 5580 | } |
| 5581 | |
| 5582 | public void noteResetVideoLocked() { |
| 5583 | if (mVideoOnNesting > 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5584 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5585 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 5586 | mAudioOnNesting = 0; |
| 5587 | mHistoryCur.states2 &= ~HistoryItem.STATE2_VIDEO_ON_FLAG; |
| 5588 | if (DEBUG_HISTORY) Slog.v(TAG, "Video off to: " |
| 5589 | + Integer.toHexString(mHistoryCur.states)); |
| 5590 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 5591 | mVideoOnTimer.stopAllRunningLocked(elapsedRealtime); |
| 5592 | for (int i=0; i<mUidStats.size(); i++) { |
| 5593 | BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 5594 | uid.noteResetVideoLocked(elapsedRealtime); |
| 5595 | } |
| 5596 | } |
| 5597 | } |
| 5598 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5599 | public void noteActivityResumedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5600 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5601 | getUidStatsLocked(uid).noteActivityResumedLocked(mClocks.elapsedRealtime()); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5602 | } |
| 5603 | |
| 5604 | public void noteActivityPausedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5605 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5606 | getUidStatsLocked(uid).noteActivityPausedLocked(mClocks.elapsedRealtime()); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5607 | } |
| 5608 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5609 | public void noteVibratorOnLocked(int uid, long durationMillis) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5610 | uid = mapUid(uid); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5611 | getUidStatsLocked(uid).noteVibratorOnLocked(durationMillis); |
| 5612 | } |
| 5613 | |
| 5614 | public void noteVibratorOffLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5615 | uid = mapUid(uid); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5616 | getUidStatsLocked(uid).noteVibratorOffLocked(); |
| 5617 | } |
| 5618 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5619 | public void noteFlashlightOnLocked(int uid) { |
| 5620 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5621 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5622 | final long uptime = mClocks.uptimeMillis(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5623 | if (mFlashlightOnNesting++ == 0) { |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 5624 | mHistoryCur.states2 |= HistoryItem.STATE2_FLASHLIGHT_FLAG; |
| 5625 | if (DEBUG_HISTORY) Slog.v(TAG, "Flashlight on to: " |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5626 | + Integer.toHexString(mHistoryCur.states2)); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 5627 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 5628 | mFlashlightOnTimer.startRunningLocked(elapsedRealtime); |
| 5629 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5630 | getUidStatsLocked(uid).noteFlashlightTurnedOnLocked(elapsedRealtime); |
| 5631 | } |
| 5632 | |
| 5633 | public void noteFlashlightOffLocked(int uid) { |
| 5634 | if (mFlashlightOnNesting == 0) { |
| 5635 | return; |
| 5636 | } |
| 5637 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5638 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5639 | final long uptime = mClocks.uptimeMillis(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5640 | if (--mFlashlightOnNesting == 0) { |
| 5641 | mHistoryCur.states2 &= ~HistoryItem.STATE2_FLASHLIGHT_FLAG; |
| 5642 | if (DEBUG_HISTORY) Slog.v(TAG, "Flashlight off to: " |
| 5643 | + Integer.toHexString(mHistoryCur.states2)); |
| 5644 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 5645 | mFlashlightOnTimer.stopRunningLocked(elapsedRealtime); |
| 5646 | } |
| 5647 | getUidStatsLocked(uid).noteFlashlightTurnedOffLocked(elapsedRealtime); |
| 5648 | } |
| 5649 | |
| 5650 | public void noteCameraOnLocked(int uid) { |
| 5651 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5652 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5653 | final long uptime = mClocks.uptimeMillis(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5654 | if (mCameraOnNesting++ == 0) { |
| 5655 | mHistoryCur.states2 |= HistoryItem.STATE2_CAMERA_FLAG; |
| 5656 | if (DEBUG_HISTORY) Slog.v(TAG, "Camera on to: " |
| 5657 | + Integer.toHexString(mHistoryCur.states2)); |
| 5658 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 5659 | mCameraOnTimer.startRunningLocked(elapsedRealtime); |
| 5660 | } |
| 5661 | getUidStatsLocked(uid).noteCameraTurnedOnLocked(elapsedRealtime); |
| 5662 | } |
| 5663 | |
| 5664 | public void noteCameraOffLocked(int uid) { |
| 5665 | if (mCameraOnNesting == 0) { |
| 5666 | return; |
| 5667 | } |
| 5668 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5669 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5670 | final long uptime = mClocks.uptimeMillis(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5671 | if (--mCameraOnNesting == 0) { |
| 5672 | mHistoryCur.states2 &= ~HistoryItem.STATE2_CAMERA_FLAG; |
| 5673 | if (DEBUG_HISTORY) Slog.v(TAG, "Camera off to: " |
| 5674 | + Integer.toHexString(mHistoryCur.states2)); |
| 5675 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 5676 | mCameraOnTimer.stopRunningLocked(elapsedRealtime); |
| 5677 | } |
| 5678 | getUidStatsLocked(uid).noteCameraTurnedOffLocked(elapsedRealtime); |
| 5679 | } |
| 5680 | |
| 5681 | public void noteResetCameraLocked() { |
| 5682 | if (mCameraOnNesting > 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5683 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5684 | final long uptime = mClocks.uptimeMillis(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5685 | mCameraOnNesting = 0; |
| 5686 | mHistoryCur.states2 &= ~HistoryItem.STATE2_CAMERA_FLAG; |
| 5687 | if (DEBUG_HISTORY) Slog.v(TAG, "Camera off to: " |
| 5688 | + Integer.toHexString(mHistoryCur.states2)); |
| 5689 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 5690 | mCameraOnTimer.stopAllRunningLocked(elapsedRealtime); |
| 5691 | for (int i=0; i<mUidStats.size(); i++) { |
| 5692 | BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 5693 | uid.noteResetCameraLocked(elapsedRealtime); |
| 5694 | } |
| 5695 | } |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 5696 | } |
| 5697 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5698 | public void noteResetFlashlightLocked() { |
| 5699 | if (mFlashlightOnNesting > 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5700 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5701 | final long uptime = mClocks.uptimeMillis(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5702 | mFlashlightOnNesting = 0; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 5703 | mHistoryCur.states2 &= ~HistoryItem.STATE2_FLASHLIGHT_FLAG; |
| 5704 | if (DEBUG_HISTORY) Slog.v(TAG, "Flashlight off to: " |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5705 | + Integer.toHexString(mHistoryCur.states2)); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 5706 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5707 | mFlashlightOnTimer.stopAllRunningLocked(elapsedRealtime); |
| 5708 | for (int i=0; i<mUidStats.size(); i++) { |
| 5709 | BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 5710 | uid.noteResetFlashlightLocked(elapsedRealtime); |
| 5711 | } |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 5712 | } |
| 5713 | } |
| 5714 | |
Narayan Kamath | 0ebc96c | 2017-12-29 13:32:38 +0000 | [diff] [blame] | 5715 | private void noteBluetoothScanStartedLocked(WorkChain workChain, int uid, |
| 5716 | boolean isUnoptimized) { |
| 5717 | uid = getAttributionUid(uid, workChain); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5718 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5719 | final long uptime = mClocks.uptimeMillis(); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5720 | if (mBluetoothScanNesting == 0) { |
| 5721 | mHistoryCur.states2 |= HistoryItem.STATE2_BLUETOOTH_SCAN_FLAG; |
| 5722 | if (DEBUG_HISTORY) Slog.v(TAG, "BLE scan started for: " |
| 5723 | + Integer.toHexString(mHistoryCur.states2)); |
| 5724 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Adam Lesinski | d9b99be | 2016-03-30 16:58:51 -0700 | [diff] [blame] | 5725 | mBluetoothScanTimer.startRunningLocked(elapsedRealtime); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5726 | } |
| 5727 | mBluetoothScanNesting++; |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5728 | getUidStatsLocked(uid).noteBluetoothScanStartedLocked(elapsedRealtime, isUnoptimized); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5729 | } |
| 5730 | |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5731 | public void noteBluetoothScanStartedFromSourceLocked(WorkSource ws, boolean isUnoptimized) { |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5732 | final int N = ws.size(); |
| 5733 | for (int i = 0; i < N; i++) { |
Narayan Kamath | 0ebc96c | 2017-12-29 13:32:38 +0000 | [diff] [blame] | 5734 | noteBluetoothScanStartedLocked(null, ws.get(i), isUnoptimized); |
| 5735 | } |
| 5736 | |
| 5737 | final List<WorkChain> workChains = ws.getWorkChains(); |
| 5738 | if (workChains != null) { |
| 5739 | for (int i = 0; i < workChains.size(); ++i) { |
| 5740 | noteBluetoothScanStartedLocked(workChains.get(i), -1, isUnoptimized); |
| 5741 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5742 | } |
| 5743 | } |
| 5744 | |
Narayan Kamath | 0ebc96c | 2017-12-29 13:32:38 +0000 | [diff] [blame] | 5745 | private void noteBluetoothScanStoppedLocked(WorkChain workChain, int uid, |
| 5746 | boolean isUnoptimized) { |
| 5747 | uid = getAttributionUid(uid, workChain); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5748 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5749 | final long uptime = mClocks.uptimeMillis(); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5750 | mBluetoothScanNesting--; |
| 5751 | if (mBluetoothScanNesting == 0) { |
| 5752 | mHistoryCur.states2 &= ~HistoryItem.STATE2_BLUETOOTH_SCAN_FLAG; |
| 5753 | if (DEBUG_HISTORY) Slog.v(TAG, "BLE scan stopped for: " |
| 5754 | + Integer.toHexString(mHistoryCur.states2)); |
| 5755 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Adam Lesinski | d9b99be | 2016-03-30 16:58:51 -0700 | [diff] [blame] | 5756 | mBluetoothScanTimer.stopRunningLocked(elapsedRealtime); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5757 | } |
Bookatz | 94c5a31 | 2017-07-11 16:49:17 -0700 | [diff] [blame] | 5758 | getUidStatsLocked(uid).noteBluetoothScanStoppedLocked(elapsedRealtime, isUnoptimized); |
Narayan Kamath | 0ebc96c | 2017-12-29 13:32:38 +0000 | [diff] [blame] | 5759 | } |
| 5760 | |
| 5761 | private int getAttributionUid(int uid, WorkChain workChain) { |
| 5762 | if (workChain != null) { |
| 5763 | return mapUid(workChain.getAttributionUid()); |
| 5764 | } |
| 5765 | |
| 5766 | return mapUid(uid); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5767 | } |
| 5768 | |
Bookatz | 94c5a31 | 2017-07-11 16:49:17 -0700 | [diff] [blame] | 5769 | public void noteBluetoothScanStoppedFromSourceLocked(WorkSource ws, boolean isUnoptimized) { |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5770 | final int N = ws.size(); |
| 5771 | for (int i = 0; i < N; i++) { |
Narayan Kamath | 0ebc96c | 2017-12-29 13:32:38 +0000 | [diff] [blame] | 5772 | noteBluetoothScanStoppedLocked(null, ws.get(i), isUnoptimized); |
| 5773 | } |
| 5774 | |
| 5775 | final List<WorkChain> workChains = ws.getWorkChains(); |
| 5776 | if (workChains != null) { |
| 5777 | for (int i = 0; i < workChains.size(); ++i) { |
| 5778 | noteBluetoothScanStoppedLocked(workChains.get(i), -1, isUnoptimized); |
| 5779 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5780 | } |
| 5781 | } |
| 5782 | |
| 5783 | public void noteResetBluetoothScanLocked() { |
| 5784 | if (mBluetoothScanNesting > 0) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5785 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5786 | final long uptime = mClocks.uptimeMillis(); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5787 | mBluetoothScanNesting = 0; |
| 5788 | mHistoryCur.states2 &= ~HistoryItem.STATE2_BLUETOOTH_SCAN_FLAG; |
| 5789 | if (DEBUG_HISTORY) Slog.v(TAG, "BLE can stopped for: " |
| 5790 | + Integer.toHexString(mHistoryCur.states2)); |
| 5791 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 5792 | mBluetoothScanTimer.stopAllRunningLocked(elapsedRealtime); |
| 5793 | for (int i=0; i<mUidStats.size(); i++) { |
| 5794 | BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 5795 | uid.noteResetBluetoothScanLocked(elapsedRealtime); |
| 5796 | } |
| 5797 | } |
| 5798 | } |
| 5799 | |
Bookatz | 4ebc064 | 2017-05-11 12:21:19 -0700 | [diff] [blame] | 5800 | public void noteBluetoothScanResultsFromSourceLocked(WorkSource ws, int numNewResults) { |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 5801 | final int N = ws.size(); |
| 5802 | for (int i = 0; i < N; i++) { |
| 5803 | int uid = mapUid(ws.get(i)); |
Bookatz | 4ebc064 | 2017-05-11 12:21:19 -0700 | [diff] [blame] | 5804 | getUidStatsLocked(uid).noteBluetoothScanResultsLocked(numNewResults); |
Narayan Kamath | 0ebc96c | 2017-12-29 13:32:38 +0000 | [diff] [blame] | 5805 | } |
| 5806 | |
| 5807 | final List<WorkChain> workChains = ws.getWorkChains(); |
| 5808 | if (workChains != null) { |
| 5809 | for (int i = 0; i < workChains.size(); ++i) { |
| 5810 | final WorkChain wc = workChains.get(i); |
| 5811 | int uid = mapUid(wc.getAttributionUid()); |
| 5812 | getUidStatsLocked(uid).noteBluetoothScanResultsLocked(numNewResults); |
Narayan Kamath | 0ebc96c | 2017-12-29 13:32:38 +0000 | [diff] [blame] | 5813 | } |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 5814 | } |
| 5815 | } |
| 5816 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 5817 | private void noteWifiRadioApWakeupLocked(final long elapsedRealtimeMillis, |
| 5818 | final long uptimeMillis, int uid) { |
| 5819 | uid = mapUid(uid); |
| 5820 | addHistoryEventLocked(elapsedRealtimeMillis, uptimeMillis, HistoryItem.EVENT_WAKEUP_AP, "", |
| 5821 | uid); |
| 5822 | getUidStatsLocked(uid).noteWifiRadioApWakeupLocked(); |
| 5823 | } |
| 5824 | |
| 5825 | public void noteWifiRadioPowerState(int powerState, long timestampNs, int uid) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5826 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5827 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 5828 | if (mWifiRadioPowerState != powerState) { |
| 5829 | final boolean active = |
| 5830 | powerState == DataConnectionRealTimeInfo.DC_POWER_STATE_MEDIUM |
| 5831 | || powerState == DataConnectionRealTimeInfo.DC_POWER_STATE_HIGH; |
| 5832 | if (active) { |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 5833 | if (uid > 0) { |
| 5834 | noteWifiRadioApWakeupLocked(elapsedRealtime, uptime, uid); |
| 5835 | } |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 5836 | mHistoryCur.states |= HistoryItem.STATE_WIFI_RADIO_ACTIVE_FLAG; |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 5837 | mWifiActiveTimer.startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 5838 | } else { |
| 5839 | mHistoryCur.states &= ~HistoryItem.STATE_WIFI_RADIO_ACTIVE_FLAG; |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 5840 | mWifiActiveTimer.stopRunningLocked( |
| 5841 | timestampNs / (1000 * 1000)); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 5842 | } |
| 5843 | if (DEBUG_HISTORY) Slog.v(TAG, "Wifi network active " + active + " to: " |
| 5844 | + Integer.toHexString(mHistoryCur.states)); |
| 5845 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 5846 | mWifiRadioPowerState = powerState; |
Yangster-mac | 4c7255f | 2018-05-07 13:41:47 -0700 | [diff] [blame] | 5847 | StatsLog.write_non_chained(StatsLog.WIFI_RADIO_POWER_STATE_CHANGED, uid, null, |
| 5848 | powerState); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 5849 | } |
| 5850 | } |
| 5851 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5852 | public void noteWifiRunningLocked(WorkSource ws) { |
| 5853 | if (!mGlobalWifiRunning) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5854 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5855 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5856 | mHistoryCur.states2 |= HistoryItem.STATE2_WIFI_RUNNING_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5857 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI running to: " |
| 5858 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 5859 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5860 | mGlobalWifiRunning = true; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5861 | mGlobalWifiRunningTimer.startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5862 | int N = ws.size(); |
| 5863 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5864 | int uid = mapUid(ws.get(i)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5865 | getUidStatsLocked(uid).noteWifiRunningLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5866 | } |
Narayan Kamath | 728c8a0 | 2017-12-28 15:48:07 +0000 | [diff] [blame] | 5867 | |
| 5868 | List<WorkChain> workChains = ws.getWorkChains(); |
| 5869 | if (workChains != null) { |
| 5870 | for (int i = 0; i < workChains.size(); ++i) { |
| 5871 | int uid = mapUid(workChains.get(i).getAttributionUid()); |
| 5872 | getUidStatsLocked(uid).noteWifiRunningLocked(elapsedRealtime); |
| 5873 | } |
| 5874 | } |
| 5875 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5876 | scheduleSyncExternalStatsLocked("wifi-running", ExternalStatsSync.UPDATE_WIFI); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5877 | } else { |
| 5878 | Log.w(TAG, "noteWifiRunningLocked -- called while WIFI running"); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 5879 | } |
| 5880 | } |
| 5881 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5882 | public void noteWifiRunningChangedLocked(WorkSource oldWs, WorkSource newWs) { |
| 5883 | if (mGlobalWifiRunning) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5884 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5885 | int N = oldWs.size(); |
| 5886 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5887 | int uid = mapUid(oldWs.get(i)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5888 | getUidStatsLocked(uid).noteWifiStoppedLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5889 | } |
Narayan Kamath | 728c8a0 | 2017-12-28 15:48:07 +0000 | [diff] [blame] | 5890 | |
| 5891 | List<WorkChain> workChains = oldWs.getWorkChains(); |
| 5892 | if (workChains != null) { |
| 5893 | for (int i = 0; i < workChains.size(); ++i) { |
| 5894 | int uid = mapUid(workChains.get(i).getAttributionUid()); |
| 5895 | getUidStatsLocked(uid).noteWifiStoppedLocked(elapsedRealtime); |
| 5896 | } |
| 5897 | } |
| 5898 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5899 | N = newWs.size(); |
| 5900 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5901 | int uid = mapUid(newWs.get(i)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5902 | getUidStatsLocked(uid).noteWifiRunningLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5903 | } |
Narayan Kamath | 728c8a0 | 2017-12-28 15:48:07 +0000 | [diff] [blame] | 5904 | |
| 5905 | workChains = newWs.getWorkChains(); |
| 5906 | if (workChains != null) { |
| 5907 | for (int i = 0; i < workChains.size(); ++i) { |
| 5908 | int uid = mapUid(workChains.get(i).getAttributionUid()); |
| 5909 | getUidStatsLocked(uid).noteWifiRunningLocked(elapsedRealtime); |
| 5910 | } |
| 5911 | } |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5912 | } else { |
| 5913 | Log.w(TAG, "noteWifiRunningChangedLocked -- called while WIFI not running"); |
| 5914 | } |
| 5915 | } |
| 5916 | |
| 5917 | public void noteWifiStoppedLocked(WorkSource ws) { |
| 5918 | if (mGlobalWifiRunning) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5919 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5920 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5921 | mHistoryCur.states2 &= ~HistoryItem.STATE2_WIFI_RUNNING_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5922 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI stopped to: " |
| 5923 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 5924 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5925 | mGlobalWifiRunning = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5926 | mGlobalWifiRunningTimer.stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5927 | int N = ws.size(); |
| 5928 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5929 | int uid = mapUid(ws.get(i)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5930 | getUidStatsLocked(uid).noteWifiStoppedLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5931 | } |
Narayan Kamath | 728c8a0 | 2017-12-28 15:48:07 +0000 | [diff] [blame] | 5932 | |
| 5933 | List<WorkChain> workChains = ws.getWorkChains(); |
| 5934 | if (workChains != null) { |
| 5935 | for (int i = 0; i < workChains.size(); ++i) { |
| 5936 | int uid = mapUid(workChains.get(i).getAttributionUid()); |
| 5937 | getUidStatsLocked(uid).noteWifiStoppedLocked(elapsedRealtime); |
| 5938 | } |
| 5939 | } |
| 5940 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5941 | scheduleSyncExternalStatsLocked("wifi-stopped", ExternalStatsSync.UPDATE_WIFI); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5942 | } else { |
| 5943 | Log.w(TAG, "noteWifiStoppedLocked -- called while WIFI not running"); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 5944 | } |
| 5945 | } |
| 5946 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5947 | public void noteWifiStateLocked(int wifiState, String accessPoint) { |
| 5948 | if (DEBUG) Log.i(TAG, "WiFi state -> " + wifiState); |
| 5949 | if (mWifiState != wifiState) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5950 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5951 | if (mWifiState >= 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5952 | mWifiStateTimer[mWifiState].stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5953 | } |
| 5954 | mWifiState = wifiState; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5955 | mWifiStateTimer[wifiState].startRunningLocked(elapsedRealtime); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5956 | scheduleSyncExternalStatsLocked("wifi-state", ExternalStatsSync.UPDATE_WIFI); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5957 | } |
| 5958 | } |
| 5959 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5960 | public void noteWifiSupplicantStateChangedLocked(int supplState, boolean failedAuth) { |
| 5961 | if (DEBUG) Log.i(TAG, "WiFi suppl state -> " + supplState); |
| 5962 | if (mWifiSupplState != supplState) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5963 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5964 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5965 | if (mWifiSupplState >= 0) { |
| 5966 | mWifiSupplStateTimer[mWifiSupplState].stopRunningLocked(elapsedRealtime); |
| 5967 | } |
| 5968 | mWifiSupplState = supplState; |
| 5969 | mWifiSupplStateTimer[supplState].startRunningLocked(elapsedRealtime); |
| 5970 | mHistoryCur.states2 = |
| 5971 | (mHistoryCur.states2&~HistoryItem.STATE2_WIFI_SUPPL_STATE_MASK) |
| 5972 | | (supplState << HistoryItem.STATE2_WIFI_SUPPL_STATE_SHIFT); |
| 5973 | if (DEBUG_HISTORY) Slog.v(TAG, "Wifi suppl state " + supplState + " to: " |
| 5974 | + Integer.toHexString(mHistoryCur.states2)); |
| 5975 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 5976 | } |
| 5977 | } |
| 5978 | |
| 5979 | void stopAllWifiSignalStrengthTimersLocked(int except) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5980 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5981 | for (int i = 0; i < NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 5982 | if (i == except) { |
| 5983 | continue; |
| 5984 | } |
| 5985 | while (mWifiSignalStrengthsTimer[i].isRunningLocked()) { |
| 5986 | mWifiSignalStrengthsTimer[i].stopRunningLocked(elapsedRealtime); |
| 5987 | } |
| 5988 | } |
| 5989 | } |
| 5990 | |
| 5991 | public void noteWifiRssiChangedLocked(int newRssi) { |
| 5992 | int strengthBin = WifiManager.calculateSignalLevel(newRssi, NUM_WIFI_SIGNAL_STRENGTH_BINS); |
| 5993 | if (DEBUG) Log.i(TAG, "WiFi rssi -> " + newRssi + " bin=" + strengthBin); |
| 5994 | if (mWifiSignalStrengthBin != strengthBin) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5995 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5996 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5997 | if (mWifiSignalStrengthBin >= 0) { |
| 5998 | mWifiSignalStrengthsTimer[mWifiSignalStrengthBin].stopRunningLocked( |
| 5999 | elapsedRealtime); |
| 6000 | } |
| 6001 | if (strengthBin >= 0) { |
| 6002 | if (!mWifiSignalStrengthsTimer[strengthBin].isRunningLocked()) { |
| 6003 | mWifiSignalStrengthsTimer[strengthBin].startRunningLocked(elapsedRealtime); |
| 6004 | } |
| 6005 | mHistoryCur.states2 = |
| 6006 | (mHistoryCur.states2&~HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_MASK) |
| 6007 | | (strengthBin << HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_SHIFT); |
| 6008 | if (DEBUG_HISTORY) Slog.v(TAG, "Wifi signal strength " + strengthBin + " to: " |
| 6009 | + Integer.toHexString(mHistoryCur.states2)); |
| 6010 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 6011 | } else { |
| 6012 | stopAllWifiSignalStrengthTimersLocked(-1); |
| 6013 | } |
Bookatz | 235343d | 2018-03-26 13:03:50 -0700 | [diff] [blame] | 6014 | StatsLog.write(StatsLog.WIFI_SIGNAL_STRENGTH_CHANGED, strengthBin); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 6015 | mWifiSignalStrengthBin = strengthBin; |
| 6016 | } |
| 6017 | } |
| 6018 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 6019 | int mWifiFullLockNesting = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6020 | |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 6021 | @UnsupportedAppUsage |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6022 | public void noteFullWifiLockAcquiredLocked(int uid) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6023 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 6024 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 6025 | if (mWifiFullLockNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6026 | mHistoryCur.states |= HistoryItem.STATE_WIFI_FULL_LOCK_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 6027 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI full lock on to: " |
| 6028 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 6029 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 6030 | } |
| 6031 | mWifiFullLockNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 6032 | getUidStatsLocked(uid).noteFullWifiLockAcquiredLocked(elapsedRealtime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6033 | } |
| 6034 | |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 6035 | @UnsupportedAppUsage |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6036 | public void noteFullWifiLockReleasedLocked(int uid) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6037 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 6038 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 6039 | mWifiFullLockNesting--; |
| 6040 | if (mWifiFullLockNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6041 | mHistoryCur.states &= ~HistoryItem.STATE_WIFI_FULL_LOCK_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 6042 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI full lock off to: " |
| 6043 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 6044 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 6045 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 6046 | getUidStatsLocked(uid).noteFullWifiLockReleasedLocked(elapsedRealtime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6047 | } |
| 6048 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 6049 | int mWifiScanNesting = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6050 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 6051 | public void noteWifiScanStartedLocked(int uid) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6052 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 6053 | final long uptime = mClocks.uptimeMillis(); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 6054 | if (mWifiScanNesting == 0) { |
| 6055 | mHistoryCur.states |= HistoryItem.STATE_WIFI_SCAN_FLAG; |
| 6056 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI scan started for: " |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 6057 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 6058 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 6059 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 6060 | mWifiScanNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 6061 | getUidStatsLocked(uid).noteWifiScanStartedLocked(elapsedRealtime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6062 | } |
| 6063 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 6064 | public void noteWifiScanStoppedLocked(int uid) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6065 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 6066 | final long uptime = mClocks.uptimeMillis(); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 6067 | mWifiScanNesting--; |
| 6068 | if (mWifiScanNesting == 0) { |
| 6069 | mHistoryCur.states &= ~HistoryItem.STATE_WIFI_SCAN_FLAG; |
| 6070 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI scan stopped for: " |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 6071 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 6072 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 6073 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 6074 | getUidStatsLocked(uid).noteWifiScanStoppedLocked(elapsedRealtime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6075 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 6076 | |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6077 | public void noteWifiBatchedScanStartedLocked(int uid, int csph) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6078 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6079 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 6080 | getUidStatsLocked(uid).noteWifiBatchedScanStartedLocked(csph, elapsedRealtime); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6081 | } |
| 6082 | |
| 6083 | public void noteWifiBatchedScanStoppedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6084 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6085 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 6086 | getUidStatsLocked(uid).noteWifiBatchedScanStoppedLocked(elapsedRealtime); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6087 | } |
| 6088 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 6089 | int mWifiMulticastNesting = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6090 | |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 6091 | @UnsupportedAppUsage |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 6092 | public void noteWifiMulticastEnabledLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6093 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6094 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 6095 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 6096 | if (mWifiMulticastNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6097 | mHistoryCur.states |= HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 6098 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI multicast on to: " |
| 6099 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 6100 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 6101 | |
| 6102 | // Start Wifi Multicast overall timer |
| 6103 | if (!mWifiMulticastWakelockTimer.isRunningLocked()) { |
| 6104 | if (DEBUG_HISTORY) Slog.v(TAG, "WiFi Multicast Overall Timer Started"); |
| 6105 | mWifiMulticastWakelockTimer.startRunningLocked(elapsedRealtime); |
| 6106 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 6107 | } |
| 6108 | mWifiMulticastNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 6109 | getUidStatsLocked(uid).noteWifiMulticastEnabledLocked(elapsedRealtime); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 6110 | } |
| 6111 | |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 6112 | @UnsupportedAppUsage |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 6113 | public void noteWifiMulticastDisabledLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6114 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6115 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 6116 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 6117 | mWifiMulticastNesting--; |
| 6118 | if (mWifiMulticastNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6119 | mHistoryCur.states &= ~HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 6120 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI multicast off to: " |
| 6121 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 6122 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 6123 | |
| 6124 | // Stop Wifi Multicast overall timer |
| 6125 | if (mWifiMulticastWakelockTimer.isRunningLocked()) { |
| 6126 | if (DEBUG_HISTORY) Slog.v(TAG, "Multicast Overall Timer Stopped"); |
| 6127 | mWifiMulticastWakelockTimer.stopRunningLocked(elapsedRealtime); |
| 6128 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 6129 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 6130 | getUidStatsLocked(uid).noteWifiMulticastDisabledLocked(elapsedRealtime); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 6131 | } |
| 6132 | |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 6133 | public void noteFullWifiLockAcquiredFromSourceLocked(WorkSource ws) { |
| 6134 | int N = ws.size(); |
| 6135 | for (int i=0; i<N; i++) { |
Narayan Kamath | 728c8a0 | 2017-12-28 15:48:07 +0000 | [diff] [blame] | 6136 | final int uid = mapUid(ws.get(i)); |
| 6137 | noteFullWifiLockAcquiredLocked(uid); |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 6138 | StatsLog.write_non_chained(StatsLog.WIFI_LOCK_STATE_CHANGED, ws.get(i), ws.getName(i), |
| 6139 | StatsLog.WIFI_LOCK_STATE_CHANGED__STATE__ON); |
Narayan Kamath | 728c8a0 | 2017-12-28 15:48:07 +0000 | [diff] [blame] | 6140 | } |
| 6141 | |
| 6142 | final List<WorkChain> workChains = ws.getWorkChains(); |
| 6143 | if (workChains != null) { |
| 6144 | for (int i = 0; i < workChains.size(); ++i) { |
| 6145 | final WorkChain workChain = workChains.get(i); |
| 6146 | final int uid = mapUid(workChain.getAttributionUid()); |
| 6147 | noteFullWifiLockAcquiredLocked(uid); |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 6148 | StatsLog.write(StatsLog.WIFI_LOCK_STATE_CHANGED, |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 6149 | workChain.getUids(), workChain.getTags(), |
| 6150 | StatsLog.WIFI_LOCK_STATE_CHANGED__STATE__ON); |
Narayan Kamath | 728c8a0 | 2017-12-28 15:48:07 +0000 | [diff] [blame] | 6151 | } |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 6152 | } |
| 6153 | } |
| 6154 | |
| 6155 | public void noteFullWifiLockReleasedFromSourceLocked(WorkSource ws) { |
| 6156 | int N = ws.size(); |
| 6157 | for (int i=0; i<N; i++) { |
Narayan Kamath | 728c8a0 | 2017-12-28 15:48:07 +0000 | [diff] [blame] | 6158 | final int uid = mapUid(ws.get(i)); |
| 6159 | noteFullWifiLockReleasedLocked(uid); |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 6160 | StatsLog.write_non_chained(StatsLog.WIFI_LOCK_STATE_CHANGED, ws.get(i), ws.getName(i), |
| 6161 | StatsLog.WIFI_LOCK_STATE_CHANGED__STATE__OFF); |
Narayan Kamath | 728c8a0 | 2017-12-28 15:48:07 +0000 | [diff] [blame] | 6162 | } |
| 6163 | |
| 6164 | final List<WorkChain> workChains = ws.getWorkChains(); |
| 6165 | if (workChains != null) { |
| 6166 | for (int i = 0; i < workChains.size(); ++i) { |
| 6167 | final WorkChain workChain = workChains.get(i); |
| 6168 | final int uid = mapUid(workChain.getAttributionUid()); |
| 6169 | noteFullWifiLockReleasedLocked(uid); |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 6170 | StatsLog.write(StatsLog.WIFI_LOCK_STATE_CHANGED, |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 6171 | workChain.getUids(), workChain.getTags(), |
| 6172 | StatsLog.WIFI_LOCK_STATE_CHANGED__STATE__OFF); |
Narayan Kamath | 728c8a0 | 2017-12-28 15:48:07 +0000 | [diff] [blame] | 6173 | } |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 6174 | } |
| 6175 | } |
| 6176 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 6177 | public void noteWifiScanStartedFromSourceLocked(WorkSource ws) { |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 6178 | int N = ws.size(); |
| 6179 | for (int i=0; i<N; i++) { |
Narayan Kamath | 728c8a0 | 2017-12-28 15:48:07 +0000 | [diff] [blame] | 6180 | final int uid = mapUid(ws.get(i)); |
| 6181 | noteWifiScanStartedLocked(uid); |
Yangster-mac | 2f5daec | 2018-01-16 10:23:15 -0800 | [diff] [blame] | 6182 | StatsLog.write_non_chained(StatsLog.WIFI_SCAN_STATE_CHANGED, ws.get(i), ws.getName(i), |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 6183 | StatsLog.WIFI_SCAN_STATE_CHANGED__STATE__ON); |
Narayan Kamath | 728c8a0 | 2017-12-28 15:48:07 +0000 | [diff] [blame] | 6184 | } |
| 6185 | |
| 6186 | final List<WorkChain> workChains = ws.getWorkChains(); |
| 6187 | if (workChains != null) { |
| 6188 | for (int i = 0; i < workChains.size(); ++i) { |
| 6189 | final WorkChain workChain = workChains.get(i); |
| 6190 | final int uid = mapUid(workChain.getAttributionUid()); |
| 6191 | noteWifiScanStartedLocked(uid); |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 6192 | StatsLog.write(StatsLog.WIFI_SCAN_STATE_CHANGED, workChain.getUids(), |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 6193 | workChain.getTags(), StatsLog.WIFI_SCAN_STATE_CHANGED__STATE__ON); |
Narayan Kamath | 728c8a0 | 2017-12-28 15:48:07 +0000 | [diff] [blame] | 6194 | } |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 6195 | } |
| 6196 | } |
| 6197 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 6198 | public void noteWifiScanStoppedFromSourceLocked(WorkSource ws) { |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 6199 | int N = ws.size(); |
| 6200 | for (int i=0; i<N; i++) { |
Narayan Kamath | 728c8a0 | 2017-12-28 15:48:07 +0000 | [diff] [blame] | 6201 | final int uid = mapUid(ws.get(i)); |
| 6202 | noteWifiScanStoppedLocked(uid); |
Yangster-mac | 2f5daec | 2018-01-16 10:23:15 -0800 | [diff] [blame] | 6203 | StatsLog.write_non_chained(StatsLog.WIFI_SCAN_STATE_CHANGED, ws.get(i), ws.getName(i), |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 6204 | StatsLog.WIFI_SCAN_STATE_CHANGED__STATE__OFF); |
Narayan Kamath | 728c8a0 | 2017-12-28 15:48:07 +0000 | [diff] [blame] | 6205 | } |
| 6206 | |
| 6207 | final List<WorkChain> workChains = ws.getWorkChains(); |
| 6208 | if (workChains != null) { |
| 6209 | for (int i = 0; i < workChains.size(); ++i) { |
| 6210 | final WorkChain workChain = workChains.get(i); |
| 6211 | final int uid = mapUid(workChain.getAttributionUid()); |
| 6212 | noteWifiScanStoppedLocked(uid); |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 6213 | StatsLog.write(StatsLog.WIFI_SCAN_STATE_CHANGED, |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 6214 | workChain.getUids(), workChain.getTags(), |
| 6215 | StatsLog.WIFI_SCAN_STATE_CHANGED__STATE__OFF); |
Narayan Kamath | 728c8a0 | 2017-12-28 15:48:07 +0000 | [diff] [blame] | 6216 | } |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 6217 | } |
| 6218 | } |
| 6219 | |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6220 | public void noteWifiBatchedScanStartedFromSourceLocked(WorkSource ws, int csph) { |
| 6221 | int N = ws.size(); |
| 6222 | for (int i=0; i<N; i++) { |
| 6223 | noteWifiBatchedScanStartedLocked(ws.get(i), csph); |
| 6224 | } |
Narayan Kamath | 728c8a0 | 2017-12-28 15:48:07 +0000 | [diff] [blame] | 6225 | |
| 6226 | final List<WorkChain> workChains = ws.getWorkChains(); |
| 6227 | if (workChains != null) { |
| 6228 | for (int i = 0; i < workChains.size(); ++i) { |
| 6229 | noteWifiBatchedScanStartedLocked(workChains.get(i).getAttributionUid(), csph); |
| 6230 | } |
| 6231 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6232 | } |
| 6233 | |
| 6234 | public void noteWifiBatchedScanStoppedFromSourceLocked(WorkSource ws) { |
| 6235 | int N = ws.size(); |
| 6236 | for (int i=0; i<N; i++) { |
| 6237 | noteWifiBatchedScanStoppedLocked(ws.get(i)); |
| 6238 | } |
Narayan Kamath | 728c8a0 | 2017-12-28 15:48:07 +0000 | [diff] [blame] | 6239 | |
| 6240 | final List<WorkChain> workChains = ws.getWorkChains(); |
| 6241 | if (workChains != null) { |
| 6242 | for (int i = 0; i < workChains.size(); ++i) { |
| 6243 | noteWifiBatchedScanStoppedLocked(workChains.get(i).getAttributionUid()); |
| 6244 | } |
| 6245 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6246 | } |
| 6247 | |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 6248 | private static String[] includeInStringArray(String[] array, String str) { |
| 6249 | if (ArrayUtils.indexOf(array, str) >= 0) { |
| 6250 | return array; |
| 6251 | } |
| 6252 | String[] newArray = new String[array.length+1]; |
| 6253 | System.arraycopy(array, 0, newArray, 0, array.length); |
| 6254 | newArray[array.length] = str; |
| 6255 | return newArray; |
| 6256 | } |
| 6257 | |
| 6258 | private static String[] excludeFromStringArray(String[] array, String str) { |
| 6259 | int index = ArrayUtils.indexOf(array, str); |
| 6260 | if (index >= 0) { |
| 6261 | String[] newArray = new String[array.length-1]; |
| 6262 | if (index > 0) { |
| 6263 | System.arraycopy(array, 0, newArray, 0, index); |
| 6264 | } |
| 6265 | if (index < array.length-1) { |
| 6266 | System.arraycopy(array, index+1, newArray, index, array.length-index-1); |
| 6267 | } |
| 6268 | return newArray; |
| 6269 | } |
| 6270 | return array; |
| 6271 | } |
| 6272 | |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 6273 | public void noteNetworkInterfaceTypeLocked(String iface, int networkType) { |
Jeff Sharkey | 9da2f1e | 2014-08-14 12:55:00 -0700 | [diff] [blame] | 6274 | if (TextUtils.isEmpty(iface)) return; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6275 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 6276 | synchronized (mModemNetworkLock) { |
| 6277 | if (ConnectivityManager.isNetworkTypeMobile(networkType)) { |
| 6278 | mModemIfaces = includeInStringArray(mModemIfaces, iface); |
| 6279 | if (DEBUG) Slog.d(TAG, "Note mobile iface " + iface + ": " + mModemIfaces); |
| 6280 | } else { |
| 6281 | mModemIfaces = excludeFromStringArray(mModemIfaces, iface); |
| 6282 | if (DEBUG) Slog.d(TAG, "Note non-mobile iface " + iface + ": " + mModemIfaces); |
| 6283 | } |
| 6284 | } |
| 6285 | |
| 6286 | synchronized (mWifiNetworkLock) { |
| 6287 | if (ConnectivityManager.isNetworkTypeWifi(networkType)) { |
| 6288 | mWifiIfaces = includeInStringArray(mWifiIfaces, iface); |
| 6289 | if (DEBUG) Slog.d(TAG, "Note wifi iface " + iface + ": " + mWifiIfaces); |
| 6290 | } else { |
| 6291 | mWifiIfaces = excludeFromStringArray(mWifiIfaces, iface); |
| 6292 | if (DEBUG) Slog.d(TAG, "Note non-wifi iface " + iface + ": " + mWifiIfaces); |
| 6293 | } |
| 6294 | } |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 6295 | } |
| 6296 | |
David Chen | c8a4324 | 2017-10-17 16:23:28 -0700 | [diff] [blame] | 6297 | public String[] getWifiIfaces() { |
| 6298 | synchronized (mWifiNetworkLock) { |
| 6299 | return mWifiIfaces; |
| 6300 | } |
| 6301 | } |
| 6302 | |
| 6303 | public String[] getMobileIfaces() { |
| 6304 | synchronized (mModemNetworkLock) { |
| 6305 | return mModemIfaces; |
| 6306 | } |
| 6307 | } |
| 6308 | |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 6309 | @UnsupportedAppUsage |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6310 | @Override public long getScreenOnTime(long elapsedRealtimeUs, int which) { |
| 6311 | return mScreenOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6312 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6313 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 6314 | @Override public int getScreenOnCount(int which) { |
| 6315 | return mScreenOnTimer.getCountLocked(which); |
| 6316 | } |
| 6317 | |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 6318 | @Override public long getScreenDozeTime(long elapsedRealtimeUs, int which) { |
| 6319 | return mScreenDozeTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 6320 | } |
| 6321 | |
| 6322 | @Override public int getScreenDozeCount(int which) { |
| 6323 | return mScreenDozeTimer.getCountLocked(which); |
| 6324 | } |
| 6325 | |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 6326 | @UnsupportedAppUsage |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6327 | @Override public long getScreenBrightnessTime(int brightnessBin, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6328 | long elapsedRealtimeUs, int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6329 | return mScreenBrightnessTimer[brightnessBin].getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6330 | elapsedRealtimeUs, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6331 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 6332 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 6333 | @Override public Timer getScreenBrightnessTimer(int brightnessBin) { |
| 6334 | return mScreenBrightnessTimer[brightnessBin]; |
| 6335 | } |
| 6336 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 6337 | @Override public long getInteractiveTime(long elapsedRealtimeUs, int which) { |
| 6338 | return mInteractiveTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6339 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6340 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 6341 | @Override public long getPowerSaveModeEnabledTime(long elapsedRealtimeUs, int which) { |
| 6342 | return mPowerSaveModeEnabledTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 6343 | } |
| 6344 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 6345 | @Override public int getPowerSaveModeEnabledCount(int which) { |
| 6346 | return mPowerSaveModeEnabledTimer.getCountLocked(which); |
| 6347 | } |
| 6348 | |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 6349 | @Override public long getDeviceIdleModeTime(int mode, long elapsedRealtimeUs, |
| 6350 | int which) { |
| 6351 | switch (mode) { |
| 6352 | case DEVICE_IDLE_MODE_LIGHT: |
| 6353 | return mDeviceIdleModeLightTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 6354 | case DEVICE_IDLE_MODE_DEEP: |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 6355 | return mDeviceIdleModeFullTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 6356 | } |
| 6357 | return 0; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 6358 | } |
| 6359 | |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 6360 | @Override public int getDeviceIdleModeCount(int mode, int which) { |
| 6361 | switch (mode) { |
| 6362 | case DEVICE_IDLE_MODE_LIGHT: |
| 6363 | return mDeviceIdleModeLightTimer.getCountLocked(which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 6364 | case DEVICE_IDLE_MODE_DEEP: |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 6365 | return mDeviceIdleModeFullTimer.getCountLocked(which); |
| 6366 | } |
| 6367 | return 0; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 6368 | } |
| 6369 | |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 6370 | @Override public long getLongestDeviceIdleModeTime(int mode) { |
| 6371 | switch (mode) { |
| 6372 | case DEVICE_IDLE_MODE_LIGHT: |
| 6373 | return mLongestLightIdleTime; |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 6374 | case DEVICE_IDLE_MODE_DEEP: |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 6375 | return mLongestFullIdleTime; |
| 6376 | } |
| 6377 | return 0; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6378 | } |
| 6379 | |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 6380 | @Override public long getDeviceIdlingTime(int mode, long elapsedRealtimeUs, int which) { |
| 6381 | switch (mode) { |
| 6382 | case DEVICE_IDLE_MODE_LIGHT: |
| 6383 | return mDeviceLightIdlingTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 6384 | case DEVICE_IDLE_MODE_DEEP: |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 6385 | return mDeviceIdlingTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 6386 | } |
| 6387 | return 0; |
| 6388 | } |
| 6389 | |
| 6390 | @Override public int getDeviceIdlingCount(int mode, int which) { |
| 6391 | switch (mode) { |
| 6392 | case DEVICE_IDLE_MODE_LIGHT: |
| 6393 | return mDeviceLightIdlingTimer.getCountLocked(which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 6394 | case DEVICE_IDLE_MODE_DEEP: |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 6395 | return mDeviceIdlingTimer.getCountLocked(which); |
| 6396 | } |
| 6397 | return 0; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6398 | } |
| 6399 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6400 | @Override public int getNumConnectivityChange(int which) { |
| 6401 | int val = mNumConnectivityChange; |
| 6402 | if (which == STATS_CURRENT) { |
| 6403 | val -= mLoadedNumConnectivityChange; |
| 6404 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 6405 | val -= mUnpluggedNumConnectivityChange; |
| 6406 | } |
| 6407 | return val; |
| 6408 | } |
| 6409 | |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 6410 | @Override public long getGpsSignalQualityTime(int strengthBin, |
| 6411 | long elapsedRealtimeUs, int which) { |
| 6412 | if (strengthBin < 0 || strengthBin >= GnssMetrics.NUM_GPS_SIGNAL_QUALITY_LEVELS) { |
| 6413 | return 0; |
| 6414 | } |
| 6415 | return mGpsSignalQualityTimer[strengthBin].getTotalTimeLocked( |
| 6416 | elapsedRealtimeUs, which); |
| 6417 | } |
| 6418 | |
| 6419 | @Override public long getGpsBatteryDrainMaMs() { |
Siddharth Ray | 0ed2e95 | 2018-01-22 11:32:14 -0800 | [diff] [blame] | 6420 | final double opVolt = mPowerProfile.getAveragePower( |
| 6421 | PowerProfile.POWER_GPS_OPERATING_VOLTAGE) / 1000.0; |
| 6422 | if (opVolt == 0) { |
| 6423 | return 0; |
| 6424 | } |
| 6425 | double energyUsedMaMs = 0.0; |
| 6426 | final int which = STATS_SINCE_CHARGED; |
| 6427 | final long rawRealtime = SystemClock.elapsedRealtime() * 1000; |
| 6428 | for(int i=0; i < GnssMetrics.NUM_GPS_SIGNAL_QUALITY_LEVELS; i++) { |
| 6429 | energyUsedMaMs |
| 6430 | += mPowerProfile.getAveragePower(PowerProfile.POWER_GPS_SIGNAL_QUALITY_BASED, i) |
| 6431 | * (getGpsSignalQualityTime(i, rawRealtime, which) / 1000); |
| 6432 | } |
| 6433 | return (long) energyUsedMaMs; |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 6434 | } |
| 6435 | |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 6436 | @UnsupportedAppUsage |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6437 | @Override public long getPhoneOnTime(long elapsedRealtimeUs, int which) { |
| 6438 | return mPhoneOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6439 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 6440 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 6441 | @Override public int getPhoneOnCount(int which) { |
| 6442 | return mPhoneOnTimer.getCountLocked(which); |
| 6443 | } |
| 6444 | |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 6445 | @UnsupportedAppUsage |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 6446 | @Override public long getPhoneSignalStrengthTime(int strengthBin, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6447 | long elapsedRealtimeUs, int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6448 | return mPhoneSignalStrengthsTimer[strengthBin].getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6449 | elapsedRealtimeUs, which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 6450 | } |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 6451 | |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 6452 | @UnsupportedAppUsage |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 6453 | @Override public long getPhoneSignalScanningTime( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6454 | long elapsedRealtimeUs, int which) { |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 6455 | return mPhoneSignalScanningTimer.getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6456 | elapsedRealtimeUs, which); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 6457 | } |
| 6458 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 6459 | @Override public Timer getPhoneSignalScanningTimer() { |
| 6460 | return mPhoneSignalScanningTimer; |
| 6461 | } |
| 6462 | |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 6463 | @UnsupportedAppUsage |
Catherine Liu | fb90081 | 2012-07-17 14:12:56 -0500 | [diff] [blame] | 6464 | @Override public int getPhoneSignalStrengthCount(int strengthBin, int which) { |
| 6465 | return mPhoneSignalStrengthsTimer[strengthBin].getCountLocked(which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6466 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6467 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 6468 | @Override public Timer getPhoneSignalStrengthTimer(int strengthBin) { |
| 6469 | return mPhoneSignalStrengthsTimer[strengthBin]; |
| 6470 | } |
| 6471 | |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 6472 | @UnsupportedAppUsage |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 6473 | @Override public long getPhoneDataConnectionTime(int dataType, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6474 | long elapsedRealtimeUs, int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6475 | return mPhoneDataConnectionsTimer[dataType].getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6476 | elapsedRealtimeUs, which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 6477 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6478 | |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 6479 | @UnsupportedAppUsage |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6480 | @Override public int getPhoneDataConnectionCount(int dataType, int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6481 | return mPhoneDataConnectionsTimer[dataType].getCountLocked(which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6482 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6483 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 6484 | @Override public Timer getPhoneDataConnectionTimer(int dataType) { |
| 6485 | return mPhoneDataConnectionsTimer[dataType]; |
| 6486 | } |
| 6487 | |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 6488 | @UnsupportedAppUsage |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6489 | @Override public long getMobileRadioActiveTime(long elapsedRealtimeUs, int which) { |
| 6490 | return mMobileRadioActiveTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 6491 | } |
| 6492 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 6493 | @Override public int getMobileRadioActiveCount(int which) { |
| 6494 | return mMobileRadioActiveTimer.getCountLocked(which); |
| 6495 | } |
| 6496 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 6497 | @Override public long getMobileRadioActiveAdjustedTime(int which) { |
| 6498 | return mMobileRadioActiveAdjustedTime.getCountLocked(which); |
| 6499 | } |
| 6500 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 6501 | @Override public long getMobileRadioActiveUnknownTime(int which) { |
| 6502 | return mMobileRadioActiveUnknownTime.getCountLocked(which); |
| 6503 | } |
| 6504 | |
| 6505 | @Override public int getMobileRadioActiveUnknownCount(int which) { |
| 6506 | return (int)mMobileRadioActiveUnknownCount.getCountLocked(which); |
| 6507 | } |
| 6508 | |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 6509 | @Override public long getWifiMulticastWakelockTime( |
| 6510 | long elapsedRealtimeUs, int which) { |
| 6511 | return mWifiMulticastWakelockTimer.getTotalTimeLocked( |
| 6512 | elapsedRealtimeUs, which); |
| 6513 | } |
| 6514 | |
| 6515 | @Override public int getWifiMulticastWakelockCount(int which) { |
| 6516 | return mWifiMulticastWakelockTimer.getCountLocked(which); |
| 6517 | } |
| 6518 | |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 6519 | @UnsupportedAppUsage |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6520 | @Override public long getWifiOnTime(long elapsedRealtimeUs, int which) { |
| 6521 | return mWifiOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6522 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6523 | |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 6524 | @Override public long getWifiActiveTime(long elapsedRealtimeUs, int which) { |
| 6525 | return mWifiActiveTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 6526 | } |
| 6527 | |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 6528 | @UnsupportedAppUsage |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6529 | @Override public long getGlobalWifiRunningTime(long elapsedRealtimeUs, int which) { |
| 6530 | return mGlobalWifiRunningTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 6531 | } |
| 6532 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 6533 | @Override public long getWifiStateTime(int wifiState, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6534 | long elapsedRealtimeUs, int which) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 6535 | return mWifiStateTimer[wifiState].getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6536 | elapsedRealtimeUs, which); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 6537 | } |
| 6538 | |
| 6539 | @Override public int getWifiStateCount(int wifiState, int which) { |
| 6540 | return mWifiStateTimer[wifiState].getCountLocked(which); |
| 6541 | } |
| 6542 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 6543 | @Override public Timer getWifiStateTimer(int wifiState) { |
| 6544 | return mWifiStateTimer[wifiState]; |
| 6545 | } |
| 6546 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 6547 | @Override public long getWifiSupplStateTime(int state, |
| 6548 | long elapsedRealtimeUs, int which) { |
| 6549 | return mWifiSupplStateTimer[state].getTotalTimeLocked( |
| 6550 | elapsedRealtimeUs, which); |
| 6551 | } |
| 6552 | |
| 6553 | @Override public int getWifiSupplStateCount(int state, int which) { |
| 6554 | return mWifiSupplStateTimer[state].getCountLocked(which); |
| 6555 | } |
| 6556 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 6557 | @Override public Timer getWifiSupplStateTimer(int state) { |
| 6558 | return mWifiSupplStateTimer[state]; |
| 6559 | } |
| 6560 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 6561 | @Override public long getWifiSignalStrengthTime(int strengthBin, |
| 6562 | long elapsedRealtimeUs, int which) { |
| 6563 | return mWifiSignalStrengthsTimer[strengthBin].getTotalTimeLocked( |
| 6564 | elapsedRealtimeUs, which); |
| 6565 | } |
| 6566 | |
| 6567 | @Override public int getWifiSignalStrengthCount(int strengthBin, int which) { |
| 6568 | return mWifiSignalStrengthsTimer[strengthBin].getCountLocked(which); |
| 6569 | } |
| 6570 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 6571 | @Override public Timer getWifiSignalStrengthTimer(int strengthBin) { |
| 6572 | return mWifiSignalStrengthsTimer[strengthBin]; |
| 6573 | } |
| 6574 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6575 | @Override |
| 6576 | public ControllerActivityCounter getBluetoothControllerActivity() { |
| 6577 | return mBluetoothActivity; |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 6578 | } |
| 6579 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6580 | @Override |
| 6581 | public ControllerActivityCounter getWifiControllerActivity() { |
| 6582 | return mWifiActivity; |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 6583 | } |
| 6584 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6585 | @Override |
| 6586 | public ControllerActivityCounter getModemControllerActivity() { |
| 6587 | return mModemActivity; |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 6588 | } |
| 6589 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6590 | @Override |
| 6591 | public boolean hasBluetoothActivityReporting() { |
| 6592 | return mHasBluetoothReporting; |
| 6593 | } |
| 6594 | |
| 6595 | @Override |
| 6596 | public boolean hasWifiActivityReporting() { |
| 6597 | return mHasWifiReporting; |
| 6598 | } |
| 6599 | |
| 6600 | @Override |
| 6601 | public boolean hasModemActivityReporting() { |
| 6602 | return mHasModemReporting; |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 6603 | } |
| 6604 | |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 6605 | @Override |
| 6606 | public long getFlashlightOnTime(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 6607 | return mFlashlightOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 6608 | } |
| 6609 | |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 6610 | @Override |
| 6611 | public long getFlashlightOnCount(int which) { |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 6612 | return mFlashlightOnTimer.getCountLocked(which); |
| 6613 | } |
| 6614 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6615 | @Override |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 6616 | public long getCameraOnTime(long elapsedRealtimeUs, int which) { |
| 6617 | return mCameraOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 6618 | } |
| 6619 | |
| 6620 | @Override |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 6621 | public long getBluetoothScanTime(long elapsedRealtimeUs, int which) { |
| 6622 | return mBluetoothScanTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 6623 | } |
| 6624 | |
| 6625 | @Override |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 6626 | @UnsupportedAppUsage |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6627 | public long getNetworkActivityBytes(int type, int which) { |
| 6628 | if (type >= 0 && type < mNetworkByteActivityCounters.length) { |
| 6629 | return mNetworkByteActivityCounters[type].getCountLocked(which); |
| 6630 | } else { |
| 6631 | return 0; |
| 6632 | } |
| 6633 | } |
| 6634 | |
| 6635 | @Override |
| 6636 | public long getNetworkActivityPackets(int type, int which) { |
| 6637 | if (type >= 0 && type < mNetworkPacketActivityCounters.length) { |
| 6638 | return mNetworkPacketActivityCounters[type].getCountLocked(which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6639 | } else { |
| 6640 | return 0; |
| 6641 | } |
| 6642 | } |
| 6643 | |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 6644 | @Override public long getStartClockTime() { |
Dianne Hackborn | d48954f | 2015-07-22 17:20:33 -0700 | [diff] [blame] | 6645 | final long currentTime = System.currentTimeMillis(); |
| 6646 | if (ensureStartClockTime(currentTime)) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6647 | recordCurrentTimeChangeLocked(currentTime, mClocks.elapsedRealtime(), |
| 6648 | mClocks.uptimeMillis()); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 6649 | } |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 6650 | return mStartClockTime; |
| 6651 | } |
| 6652 | |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 6653 | @Override public String getStartPlatformVersion() { |
| 6654 | return mStartPlatformVersion; |
| 6655 | } |
| 6656 | |
| 6657 | @Override public String getEndPlatformVersion() { |
| 6658 | return mEndPlatformVersion; |
| 6659 | } |
| 6660 | |
| 6661 | @Override public int getParcelVersion() { |
| 6662 | return VERSION; |
| 6663 | } |
| 6664 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6665 | @Override public boolean getIsOnBattery() { |
| 6666 | return mOnBattery; |
| 6667 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6668 | |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 6669 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6670 | @Override public SparseArray<? extends BatteryStats.Uid> getUidStats() { |
| 6671 | return mUidStats; |
| 6672 | } |
| 6673 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 6674 | private static void detachTimerIfNotNull(BatteryStatsImpl.Timer timer) { |
| 6675 | if (timer != null) { |
| 6676 | timer.detach(); |
| 6677 | } |
| 6678 | } |
| 6679 | |
| 6680 | private static boolean resetTimerIfNotNull(BatteryStatsImpl.Timer timer, |
| 6681 | boolean detachIfReset) { |
| 6682 | if (timer != null) { |
| 6683 | return timer.reset(detachIfReset); |
| 6684 | } |
| 6685 | return true; |
| 6686 | } |
| 6687 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 6688 | private static boolean resetTimerIfNotNull(DualTimer timer, boolean detachIfReset) { |
| 6689 | if (timer != null) { |
| 6690 | return timer.reset(detachIfReset); |
| 6691 | } |
| 6692 | return true; |
| 6693 | } |
| 6694 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 6695 | private static void detachLongCounterIfNotNull(LongSamplingCounter counter) { |
| 6696 | if (counter != null) { |
| 6697 | counter.detach(); |
| 6698 | } |
| 6699 | } |
| 6700 | |
| 6701 | private static void resetLongCounterIfNotNull(LongSamplingCounter counter, |
| 6702 | boolean detachIfReset) { |
| 6703 | if (counter != null) { |
| 6704 | counter.reset(detachIfReset); |
| 6705 | } |
| 6706 | } |
| 6707 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6708 | /** |
| 6709 | * The statistics associated with a particular uid. |
| 6710 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6711 | public static class Uid extends BatteryStats.Uid { |
| 6712 | /** |
| 6713 | * BatteryStatsImpl that we are associated with. |
| 6714 | */ |
| 6715 | protected BatteryStatsImpl mBsi; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6716 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6717 | final int mUid; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6718 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 6719 | /** TimeBase for when uid is in background and device is on battery. */ |
| 6720 | @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 6721 | public final TimeBase mOnBatteryBackgroundTimeBase; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 6722 | @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 6723 | public final TimeBase mOnBatteryScreenOffBackgroundTimeBase; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 6724 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 6725 | boolean mWifiRunning; |
| 6726 | StopwatchTimer mWifiRunningTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6727 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6728 | boolean mFullWifiLockOut; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6729 | StopwatchTimer mFullWifiLockTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6730 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 6731 | boolean mWifiScanStarted; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 6732 | DualTimer mWifiScanTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6733 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 6734 | static final int NO_BATCHED_SCAN_STARTED = -1; |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6735 | int mWifiBatchedScanBinStarted = NO_BATCHED_SCAN_STARTED; |
| 6736 | StopwatchTimer[] mWifiBatchedScanTimer; |
| 6737 | |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 6738 | boolean mWifiMulticastEnabled; |
| 6739 | StopwatchTimer mWifiMulticastTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6740 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 6741 | StopwatchTimer mAudioTurnedOnTimer; |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 6742 | StopwatchTimer mVideoTurnedOnTimer; |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 6743 | StopwatchTimer mFlashlightTurnedOnTimer; |
| 6744 | StopwatchTimer mCameraTurnedOnTimer; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6745 | StopwatchTimer mForegroundActivityTimer; |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 6746 | StopwatchTimer mForegroundServiceTimer; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 6747 | /** Total time spent by the uid holding any partial wakelocks. */ |
| 6748 | DualTimer mAggregatedPartialWakelockTimer; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 6749 | DualTimer mBluetoothScanTimer; |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 6750 | DualTimer mBluetoothUnoptimizedScanTimer; |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 6751 | Counter mBluetoothScanResultCounter; |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 6752 | Counter mBluetoothScanResultBgCounter; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6753 | |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 6754 | int mProcessState = ActivityManager.PROCESS_STATE_NONEXISTENT; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 6755 | StopwatchTimer[] mProcessStateTimer; |
| 6756 | |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 6757 | boolean mInForegroundService = false; |
| 6758 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 6759 | BatchTimer mVibratorOnTimer; |
| 6760 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6761 | Counter[] mUserActivityCounters; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6762 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6763 | LongSamplingCounter[] mNetworkByteActivityCounters; |
| 6764 | LongSamplingCounter[] mNetworkPacketActivityCounters; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 6765 | LongSamplingCounter mMobileRadioActiveTime; |
| 6766 | LongSamplingCounter mMobileRadioActiveCount; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6767 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6768 | /** |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 6769 | * How many times this UID woke up the Application Processor due to a Mobile radio packet. |
| 6770 | */ |
| 6771 | private LongSamplingCounter mMobileRadioApWakeupCount; |
| 6772 | |
| 6773 | /** |
| 6774 | * How many times this UID woke up the Application Processor due to a Wifi packet. |
| 6775 | */ |
| 6776 | private LongSamplingCounter mWifiRadioApWakeupCount; |
| 6777 | |
| 6778 | /** |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6779 | * 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] | 6780 | * Can be null if the UID has had no such activity. |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6781 | */ |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6782 | private ControllerActivityCounterImpl mWifiControllerActivity; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6783 | |
| 6784 | /** |
| 6785 | * 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] | 6786 | * Can be null if the UID has had no such activity. |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6787 | */ |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6788 | private ControllerActivityCounterImpl mBluetoothControllerActivity; |
| 6789 | |
| 6790 | /** |
| 6791 | * The amount of time this uid has kept the Modem controller in idle, tx, and rx mode. |
| 6792 | * Can be null if the UID has had no such activity. |
| 6793 | */ |
| 6794 | private ControllerActivityCounterImpl mModemControllerActivity; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6795 | |
| 6796 | /** |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 6797 | * The CPU times we had at the last history details update. |
| 6798 | */ |
| 6799 | long mLastStepUserTime; |
| 6800 | long mLastStepSystemTime; |
| 6801 | long mCurStepUserTime; |
| 6802 | long mCurStepSystemTime; |
| 6803 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6804 | LongSamplingCounter mUserCpuTime; |
| 6805 | LongSamplingCounter mSystemCpuTime; |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 6806 | LongSamplingCounter[][] mCpuClusterSpeedTimesUs; |
Mike Ma | 3d422c3 | 2017-10-25 11:08:57 -0700 | [diff] [blame] | 6807 | LongSamplingCounter mCpuActiveTimeMs; |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 6808 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 6809 | LongSamplingCounterArray mCpuFreqTimeMs; |
| 6810 | LongSamplingCounterArray mScreenOffCpuFreqTimeMs; |
Mike Ma | 3d422c3 | 2017-10-25 11:08:57 -0700 | [diff] [blame] | 6811 | LongSamplingCounterArray mCpuClusterTimesMs; |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 6812 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 6813 | LongSamplingCounterArray[] mProcStateTimeMs; |
| 6814 | LongSamplingCounterArray[] mProcStateScreenOffTimeMs; |
| 6815 | |
| 6816 | IntArray mChildUids; |
| 6817 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 6818 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6819 | * The statistics we have collected for this uid's wake locks. |
| 6820 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6821 | final OverflowArrayMap<Wakelock> mWakelockStats; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6822 | |
| 6823 | /** |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6824 | * The statistics we have collected for this uid's syncs. |
| 6825 | */ |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 6826 | final OverflowArrayMap<DualTimer> mSyncStats; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6827 | |
| 6828 | /** |
| 6829 | * The statistics we have collected for this uid's jobs. |
| 6830 | */ |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 6831 | final OverflowArrayMap<DualTimer> mJobStats; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6832 | |
| 6833 | /** |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 6834 | * Count of the jobs that have completed and the reasons why they completed. |
| 6835 | */ |
| 6836 | final ArrayMap<String, SparseIntArray> mJobCompletions = new ArrayMap<>(); |
| 6837 | |
| 6838 | /** |
Amith Yamasani | 977e11f | 2018-02-16 11:29:54 -0800 | [diff] [blame] | 6839 | * Count of app launch events that had associated deferred job counts or info about |
| 6840 | * last time a job was run. |
| 6841 | */ |
| 6842 | Counter mJobsDeferredEventCount; |
| 6843 | |
| 6844 | /** |
| 6845 | * Count of deferred jobs that were pending when the app was launched or brought to |
| 6846 | * the foreground through a user interaction. |
| 6847 | */ |
| 6848 | Counter mJobsDeferredCount; |
| 6849 | |
| 6850 | /** |
| 6851 | * Sum of time since the last time a job was run for this app before it was launched. |
| 6852 | */ |
| 6853 | LongSamplingCounter mJobsFreshnessTimeMs; |
| 6854 | |
| 6855 | /** |
| 6856 | * Array of counts of instances where the time since the last job was run for the app |
| 6857 | * fell within one of the thresholds in {@link #JOB_FRESHNESS_BUCKETS}. |
| 6858 | */ |
| 6859 | final Counter[] mJobsFreshnessBuckets; |
| 6860 | |
| 6861 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6862 | * The statistics we have collected for this uid's sensor activations. |
| 6863 | */ |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6864 | final SparseArray<Sensor> mSensorStats = new SparseArray<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6865 | |
| 6866 | /** |
| 6867 | * The statistics we have collected for this uid's processes. |
| 6868 | */ |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6869 | final ArrayMap<String, Proc> mProcessStats = new ArrayMap<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6870 | |
| 6871 | /** |
| 6872 | * The statistics we have collected for this uid's processes. |
| 6873 | */ |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6874 | final ArrayMap<String, Pkg> mPackageStats = new ArrayMap<>(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6875 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6876 | /** |
| 6877 | * The transient wake stats we have collected for this uid's pids. |
| 6878 | */ |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6879 | final SparseArray<Pid> mPids = new SparseArray<>(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6880 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6881 | public Uid(BatteryStatsImpl bsi, int uid) { |
| 6882 | mBsi = bsi; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6883 | mUid = uid; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6884 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 6885 | mOnBatteryBackgroundTimeBase = new TimeBase(); |
| 6886 | mOnBatteryBackgroundTimeBase.init(mBsi.mClocks.uptimeMillis() * 1000, |
| 6887 | mBsi.mClocks.elapsedRealtime() * 1000); |
| 6888 | |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 6889 | mOnBatteryScreenOffBackgroundTimeBase = new TimeBase(); |
| 6890 | mOnBatteryScreenOffBackgroundTimeBase.init(mBsi.mClocks.uptimeMillis() * 1000, |
| 6891 | mBsi.mClocks.elapsedRealtime() * 1000); |
| 6892 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6893 | mUserCpuTime = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
| 6894 | mSystemCpuTime = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
Mike Ma | 3d422c3 | 2017-10-25 11:08:57 -0700 | [diff] [blame] | 6895 | mCpuActiveTimeMs = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
| 6896 | mCpuClusterTimesMs = new LongSamplingCounterArray(mBsi.mOnBatteryTimeBase); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6897 | |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame] | 6898 | mWakelockStats = mBsi.new OverflowArrayMap<Wakelock>(uid) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6899 | @Override public Wakelock instantiateObject() { |
| 6900 | return new Wakelock(mBsi, Uid.this); |
| 6901 | } |
| 6902 | }; |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 6903 | mSyncStats = mBsi.new OverflowArrayMap<DualTimer>(uid) { |
| 6904 | @Override public DualTimer instantiateObject() { |
| 6905 | return new DualTimer(mBsi.mClocks, Uid.this, SYNC, null, |
| 6906 | mBsi.mOnBatteryTimeBase, mOnBatteryBackgroundTimeBase); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6907 | } |
| 6908 | }; |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 6909 | mJobStats = mBsi.new OverflowArrayMap<DualTimer>(uid) { |
| 6910 | @Override public DualTimer instantiateObject() { |
| 6911 | return new DualTimer(mBsi.mClocks, Uid.this, JOB, null, |
| 6912 | mBsi.mOnBatteryTimeBase, mOnBatteryBackgroundTimeBase); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6913 | } |
| 6914 | }; |
| 6915 | |
| 6916 | mWifiRunningTimer = new StopwatchTimer(mBsi.mClocks, this, WIFI_RUNNING, |
| 6917 | mBsi.mWifiRunningTimers, mBsi.mOnBatteryTimeBase); |
| 6918 | mFullWifiLockTimer = new StopwatchTimer(mBsi.mClocks, this, FULL_WIFI_LOCK, |
| 6919 | mBsi.mFullWifiLockTimers, mBsi.mOnBatteryTimeBase); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 6920 | mWifiScanTimer = new DualTimer(mBsi.mClocks, this, WIFI_SCAN, |
| 6921 | mBsi.mWifiScanTimers, mBsi.mOnBatteryTimeBase, mOnBatteryBackgroundTimeBase); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6922 | mWifiBatchedScanTimer = new StopwatchTimer[NUM_WIFI_BATCHED_SCAN_BINS]; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6923 | mWifiMulticastTimer = new StopwatchTimer(mBsi.mClocks, this, WIFI_MULTICAST_ENABLED, |
| 6924 | mBsi.mWifiMulticastTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 6925 | mProcessStateTimer = new StopwatchTimer[NUM_PROCESS_STATE]; |
Amith Yamasani | 977e11f | 2018-02-16 11:29:54 -0800 | [diff] [blame] | 6926 | mJobsDeferredEventCount = new Counter(mBsi.mOnBatteryTimeBase); |
| 6927 | mJobsDeferredCount = new Counter(mBsi.mOnBatteryTimeBase); |
| 6928 | mJobsFreshnessTimeMs = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
| 6929 | mJobsFreshnessBuckets = new Counter[JOB_FRESHNESS_BUCKETS.length]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6930 | } |
| 6931 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 6932 | @VisibleForTesting |
| 6933 | public void setProcessStateForTest(int procState) { |
| 6934 | mProcessState = procState; |
| 6935 | } |
| 6936 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6937 | @Override |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 6938 | public long[] getCpuFreqTimes(int which) { |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 6939 | return nullIfAllZeros(mCpuFreqTimeMs, which); |
| 6940 | } |
| 6941 | |
| 6942 | @Override |
| 6943 | public long[] getScreenOffCpuFreqTimes(int which) { |
| 6944 | return nullIfAllZeros(mScreenOffCpuFreqTimeMs, which); |
| 6945 | } |
| 6946 | |
| 6947 | @Override |
Mike Ma | 3d422c3 | 2017-10-25 11:08:57 -0700 | [diff] [blame] | 6948 | public long getCpuActiveTime() { |
| 6949 | return mCpuActiveTimeMs.getCountLocked(STATS_SINCE_CHARGED); |
| 6950 | } |
| 6951 | |
| 6952 | @Override |
| 6953 | public long[] getCpuClusterTimes() { |
| 6954 | return nullIfAllZeros(mCpuClusterTimesMs, STATS_SINCE_CHARGED); |
| 6955 | } |
| 6956 | |
| 6957 | |
| 6958 | @Override |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 6959 | public long[] getCpuFreqTimes(int which, int procState) { |
| 6960 | if (which < 0 || which >= NUM_PROCESS_STATE) { |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 6961 | return null; |
| 6962 | } |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 6963 | if (mProcStateTimeMs == null) { |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 6964 | return null; |
| 6965 | } |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 6966 | if (!mBsi.mPerProcStateCpuTimesAvailable) { |
| 6967 | mProcStateTimeMs = null; |
| 6968 | return null; |
| 6969 | } |
| 6970 | return nullIfAllZeros(mProcStateTimeMs[procState], which); |
| 6971 | } |
| 6972 | |
| 6973 | @Override |
| 6974 | public long[] getScreenOffCpuFreqTimes(int which, int procState) { |
| 6975 | if (which < 0 || which >= NUM_PROCESS_STATE) { |
| 6976 | return null; |
| 6977 | } |
| 6978 | if (mProcStateScreenOffTimeMs == null) { |
| 6979 | return null; |
| 6980 | } |
| 6981 | if (!mBsi.mPerProcStateCpuTimesAvailable) { |
| 6982 | mProcStateScreenOffTimeMs = null; |
| 6983 | return null; |
| 6984 | } |
| 6985 | return nullIfAllZeros(mProcStateScreenOffTimeMs[procState], which); |
| 6986 | } |
| 6987 | |
| 6988 | public void addIsolatedUid(int isolatedUid) { |
| 6989 | if (mChildUids == null) { |
| 6990 | mChildUids = new IntArray(); |
| 6991 | } else if (mChildUids.indexOf(isolatedUid) >= 0) { |
| 6992 | return; |
| 6993 | } |
| 6994 | mChildUids.add(isolatedUid); |
| 6995 | } |
| 6996 | |
| 6997 | public void removeIsolatedUid(int isolatedUid) { |
| 6998 | final int idx = mChildUids == null ? -1 : mChildUids.indexOf(isolatedUid); |
| 6999 | if (idx < 0) { |
| 7000 | return; |
| 7001 | } |
| 7002 | mChildUids.remove(idx); |
| 7003 | } |
| 7004 | |
| 7005 | private long[] nullIfAllZeros(LongSamplingCounterArray cpuTimesMs, int which) { |
| 7006 | if (cpuTimesMs == null) { |
| 7007 | return null; |
| 7008 | } |
| 7009 | final long[] counts = cpuTimesMs.getCountsLocked(which); |
| 7010 | if (counts == null) { |
| 7011 | return null; |
| 7012 | } |
| 7013 | // Return counts only if at least one of the elements is non-zero. |
| 7014 | for (int i = counts.length - 1; i >= 0; --i) { |
| 7015 | if (counts[i] != 0) { |
| 7016 | return counts; |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 7017 | } |
| 7018 | } |
| 7019 | return null; |
| 7020 | } |
| 7021 | |
Sudheer Shanka | e544d16 | 2017-12-28 17:06:20 -0800 | [diff] [blame] | 7022 | private void addProcStateTimesMs(int procState, long[] cpuTimesMs, boolean onBattery) { |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 7023 | if (mProcStateTimeMs == null) { |
| 7024 | mProcStateTimeMs = new LongSamplingCounterArray[NUM_PROCESS_STATE]; |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 7025 | } |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 7026 | if (mProcStateTimeMs[procState] == null |
| 7027 | || mProcStateTimeMs[procState].getSize() != cpuTimesMs.length) { |
| 7028 | mProcStateTimeMs[procState] = new LongSamplingCounterArray( |
| 7029 | mBsi.mOnBatteryTimeBase); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 7030 | } |
Sudheer Shanka | e544d16 | 2017-12-28 17:06:20 -0800 | [diff] [blame] | 7031 | mProcStateTimeMs[procState].addCountLocked(cpuTimesMs, onBattery); |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 7032 | } |
| 7033 | |
Sudheer Shanka | e544d16 | 2017-12-28 17:06:20 -0800 | [diff] [blame] | 7034 | private void addProcStateScreenOffTimesMs(int procState, long[] cpuTimesMs, |
| 7035 | boolean onBatteryScreenOff) { |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 7036 | if (mProcStateScreenOffTimeMs == null) { |
| 7037 | mProcStateScreenOffTimeMs = new LongSamplingCounterArray[NUM_PROCESS_STATE]; |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 7038 | } |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 7039 | if (mProcStateScreenOffTimeMs[procState] == null |
| 7040 | || mProcStateScreenOffTimeMs[procState].getSize() != cpuTimesMs.length) { |
| 7041 | mProcStateScreenOffTimeMs[procState] = new LongSamplingCounterArray( |
| 7042 | mBsi.mOnBatteryScreenOffTimeBase); |
| 7043 | } |
Sudheer Shanka | e544d16 | 2017-12-28 17:06:20 -0800 | [diff] [blame] | 7044 | mProcStateScreenOffTimeMs[procState].addCountLocked(cpuTimesMs, onBatteryScreenOff); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 7045 | } |
| 7046 | |
| 7047 | @Override |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 7048 | public Timer getAggregatedPartialWakelockTimer() { |
| 7049 | return mAggregatedPartialWakelockTimer; |
| 7050 | } |
| 7051 | |
| 7052 | @Override |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 7053 | @UnsupportedAppUsage |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 7054 | public ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> getWakelockStats() { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7055 | return mWakelockStats.getMap(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7056 | } |
| 7057 | |
| 7058 | @Override |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 7059 | public Timer getMulticastWakelockStats() { |
| 7060 | return mWifiMulticastTimer; |
| 7061 | } |
| 7062 | |
| 7063 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 7064 | public ArrayMap<String, ? extends BatteryStats.Timer> getSyncStats() { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7065 | return mSyncStats.getMap(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 7066 | } |
| 7067 | |
| 7068 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 7069 | public ArrayMap<String, ? extends BatteryStats.Timer> getJobStats() { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7070 | return mJobStats.getMap(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 7071 | } |
| 7072 | |
| 7073 | @Override |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 7074 | public ArrayMap<String, SparseIntArray> getJobCompletionStats() { |
| 7075 | return mJobCompletions; |
| 7076 | } |
| 7077 | |
| 7078 | @Override |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 7079 | @UnsupportedAppUsage |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 7080 | public SparseArray<? extends BatteryStats.Uid.Sensor> getSensorStats() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7081 | return mSensorStats; |
| 7082 | } |
| 7083 | |
| 7084 | @Override |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 7085 | @UnsupportedAppUsage |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 7086 | public ArrayMap<String, ? extends BatteryStats.Uid.Proc> getProcessStats() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7087 | return mProcessStats; |
| 7088 | } |
| 7089 | |
| 7090 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 7091 | public ArrayMap<String, ? extends BatteryStats.Uid.Pkg> getPackageStats() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7092 | return mPackageStats; |
| 7093 | } |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 7094 | |
| 7095 | @Override |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 7096 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7097 | public int getUid() { |
| 7098 | return mUid; |
| 7099 | } |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 7100 | |
| 7101 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7102 | public void noteWifiRunningLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 7103 | if (!mWifiRunning) { |
| 7104 | mWifiRunning = true; |
| 7105 | if (mWifiRunningTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7106 | mWifiRunningTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, WIFI_RUNNING, |
| 7107 | mBsi.mWifiRunningTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7108 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7109 | mWifiRunningTimer.startRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 7110 | } |
| 7111 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7112 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 7113 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7114 | public void noteWifiStoppedLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 7115 | if (mWifiRunning) { |
| 7116 | mWifiRunning = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7117 | mWifiRunningTimer.stopRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 7118 | } |
| 7119 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7120 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 7121 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7122 | public void noteFullWifiLockAcquiredLocked(long elapsedRealtimeMs) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7123 | if (!mFullWifiLockOut) { |
| 7124 | mFullWifiLockOut = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7125 | if (mFullWifiLockTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7126 | mFullWifiLockTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, FULL_WIFI_LOCK, |
| 7127 | mBsi.mFullWifiLockTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7128 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7129 | mFullWifiLockTimer.startRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7130 | } |
| 7131 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7132 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7133 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7134 | public void noteFullWifiLockReleasedLocked(long elapsedRealtimeMs) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7135 | if (mFullWifiLockOut) { |
| 7136 | mFullWifiLockOut = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7137 | mFullWifiLockTimer.stopRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7138 | } |
| 7139 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7140 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7141 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7142 | public void noteWifiScanStartedLocked(long elapsedRealtimeMs) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 7143 | if (!mWifiScanStarted) { |
| 7144 | mWifiScanStarted = true; |
| 7145 | if (mWifiScanTimer == null) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 7146 | mWifiScanTimer = new DualTimer(mBsi.mClocks, Uid.this, WIFI_SCAN, |
| 7147 | mBsi.mWifiScanTimers, mBsi.mOnBatteryTimeBase, |
| 7148 | mOnBatteryBackgroundTimeBase); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7149 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7150 | mWifiScanTimer.startRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7151 | } |
| 7152 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7153 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7154 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7155 | public void noteWifiScanStoppedLocked(long elapsedRealtimeMs) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 7156 | if (mWifiScanStarted) { |
| 7157 | mWifiScanStarted = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7158 | mWifiScanTimer.stopRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7159 | } |
| 7160 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 7161 | |
| 7162 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7163 | public void noteWifiBatchedScanStartedLocked(int csph, long elapsedRealtimeMs) { |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 7164 | int bin = 0; |
Navtej Singh Mann | 3c0ce5c | 2015-06-11 16:53:11 -0700 | [diff] [blame] | 7165 | while (csph > 8 && bin < NUM_WIFI_BATCHED_SCAN_BINS-1) { |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 7166 | csph = csph >> 3; |
| 7167 | bin++; |
| 7168 | } |
| 7169 | |
| 7170 | if (mWifiBatchedScanBinStarted == bin) return; |
| 7171 | |
| 7172 | if (mWifiBatchedScanBinStarted != NO_BATCHED_SCAN_STARTED) { |
| 7173 | mWifiBatchedScanTimer[mWifiBatchedScanBinStarted]. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7174 | stopRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 7175 | } |
| 7176 | mWifiBatchedScanBinStarted = bin; |
| 7177 | if (mWifiBatchedScanTimer[bin] == null) { |
| 7178 | makeWifiBatchedScanBin(bin, null); |
| 7179 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7180 | mWifiBatchedScanTimer[bin].startRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 7181 | } |
| 7182 | |
| 7183 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7184 | public void noteWifiBatchedScanStoppedLocked(long elapsedRealtimeMs) { |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 7185 | if (mWifiBatchedScanBinStarted != NO_BATCHED_SCAN_STARTED) { |
| 7186 | mWifiBatchedScanTimer[mWifiBatchedScanBinStarted]. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7187 | stopRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 7188 | mWifiBatchedScanBinStarted = NO_BATCHED_SCAN_STARTED; |
| 7189 | } |
| 7190 | } |
| 7191 | |
| 7192 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7193 | public void noteWifiMulticastEnabledLocked(long elapsedRealtimeMs) { |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 7194 | if (!mWifiMulticastEnabled) { |
| 7195 | mWifiMulticastEnabled = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7196 | if (mWifiMulticastTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7197 | mWifiMulticastTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, |
| 7198 | WIFI_MULTICAST_ENABLED, mBsi.mWifiMulticastTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7199 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7200 | mWifiMulticastTimer.startRunningLocked(elapsedRealtimeMs); |
Tej Singh | 4503e10 | 2018-01-04 14:35:01 -0800 | [diff] [blame] | 7201 | StatsLog.write_non_chained( |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 7202 | StatsLog.WIFI_MULTICAST_LOCK_STATE_CHANGED, getUid(), null, |
| 7203 | StatsLog.WIFI_MULTICAST_LOCK_STATE_CHANGED__STATE__ON); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 7204 | } |
| 7205 | } |
| 7206 | |
| 7207 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7208 | public void noteWifiMulticastDisabledLocked(long elapsedRealtimeMs) { |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 7209 | if (mWifiMulticastEnabled) { |
| 7210 | mWifiMulticastEnabled = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7211 | mWifiMulticastTimer.stopRunningLocked(elapsedRealtimeMs); |
Tej Singh | 4503e10 | 2018-01-04 14:35:01 -0800 | [diff] [blame] | 7212 | StatsLog.write_non_chained( |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 7213 | StatsLog.WIFI_MULTICAST_LOCK_STATE_CHANGED, getUid(), null, |
| 7214 | StatsLog.WIFI_MULTICAST_LOCK_STATE_CHANGED__STATE__OFF); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 7215 | } |
| 7216 | } |
| 7217 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 7218 | @Override |
| 7219 | public ControllerActivityCounter getWifiControllerActivity() { |
| 7220 | return mWifiControllerActivity; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7221 | } |
| 7222 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 7223 | @Override |
| 7224 | public ControllerActivityCounter getBluetoothControllerActivity() { |
| 7225 | return mBluetoothControllerActivity; |
| 7226 | } |
| 7227 | |
| 7228 | @Override |
| 7229 | public ControllerActivityCounter getModemControllerActivity() { |
| 7230 | return mModemControllerActivity; |
| 7231 | } |
| 7232 | |
| 7233 | public ControllerActivityCounterImpl getOrCreateWifiControllerActivityLocked() { |
| 7234 | if (mWifiControllerActivity == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7235 | mWifiControllerActivity = new ControllerActivityCounterImpl(mBsi.mOnBatteryTimeBase, |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 7236 | NUM_BT_TX_LEVELS); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 7237 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 7238 | return mWifiControllerActivity; |
| 7239 | } |
| 7240 | |
| 7241 | public ControllerActivityCounterImpl getOrCreateBluetoothControllerActivityLocked() { |
| 7242 | if (mBluetoothControllerActivity == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7243 | mBluetoothControllerActivity = new ControllerActivityCounterImpl(mBsi.mOnBatteryTimeBase, |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 7244 | NUM_BT_TX_LEVELS); |
| 7245 | } |
| 7246 | return mBluetoothControllerActivity; |
| 7247 | } |
| 7248 | |
| 7249 | public ControllerActivityCounterImpl getOrCreateModemControllerActivityLocked() { |
| 7250 | if (mModemControllerActivity == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7251 | mModemControllerActivity = new ControllerActivityCounterImpl(mBsi.mOnBatteryTimeBase, |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 7252 | ModemActivityInfo.TX_POWER_LEVELS); |
| 7253 | } |
| 7254 | return mModemControllerActivity; |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 7255 | } |
| 7256 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 7257 | public StopwatchTimer createAudioTurnedOnTimerLocked() { |
| 7258 | if (mAudioTurnedOnTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7259 | mAudioTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, AUDIO_TURNED_ON, |
| 7260 | mBsi.mAudioTurnedOnTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 7261 | } |
| 7262 | return mAudioTurnedOnTimer; |
| 7263 | } |
| 7264 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7265 | public void noteAudioTurnedOnLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 7266 | createAudioTurnedOnTimerLocked().startRunningLocked(elapsedRealtimeMs); |
| 7267 | } |
| 7268 | |
| 7269 | public void noteAudioTurnedOffLocked(long elapsedRealtimeMs) { |
| 7270 | if (mAudioTurnedOnTimer != null) { |
| 7271 | mAudioTurnedOnTimer.stopRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7272 | } |
| 7273 | } |
| 7274 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 7275 | public void noteResetAudioLocked(long elapsedRealtimeMs) { |
| 7276 | if (mAudioTurnedOnTimer != null) { |
| 7277 | mAudioTurnedOnTimer.stopAllRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7278 | } |
| 7279 | } |
| 7280 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 7281 | public StopwatchTimer createVideoTurnedOnTimerLocked() { |
| 7282 | if (mVideoTurnedOnTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7283 | mVideoTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, VIDEO_TURNED_ON, |
| 7284 | mBsi.mVideoTurnedOnTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 7285 | } |
| 7286 | return mVideoTurnedOnTimer; |
| 7287 | } |
| 7288 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7289 | public void noteVideoTurnedOnLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 7290 | createVideoTurnedOnTimerLocked().startRunningLocked(elapsedRealtimeMs); |
| 7291 | } |
| 7292 | |
| 7293 | public void noteVideoTurnedOffLocked(long elapsedRealtimeMs) { |
| 7294 | if (mVideoTurnedOnTimer != null) { |
| 7295 | mVideoTurnedOnTimer.stopRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7296 | } |
| 7297 | } |
| 7298 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 7299 | public void noteResetVideoLocked(long elapsedRealtimeMs) { |
| 7300 | if (mVideoTurnedOnTimer != null) { |
| 7301 | mVideoTurnedOnTimer.stopAllRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 7302 | } |
| 7303 | } |
| 7304 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 7305 | public StopwatchTimer createFlashlightTurnedOnTimerLocked() { |
| 7306 | if (mFlashlightTurnedOnTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7307 | mFlashlightTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, |
| 7308 | FLASHLIGHT_TURNED_ON, mBsi.mFlashlightTurnedOnTimers, mBsi.mOnBatteryTimeBase); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 7309 | } |
| 7310 | return mFlashlightTurnedOnTimer; |
| 7311 | } |
| 7312 | |
| 7313 | public void noteFlashlightTurnedOnLocked(long elapsedRealtimeMs) { |
| 7314 | createFlashlightTurnedOnTimerLocked().startRunningLocked(elapsedRealtimeMs); |
| 7315 | } |
| 7316 | |
| 7317 | public void noteFlashlightTurnedOffLocked(long elapsedRealtimeMs) { |
| 7318 | if (mFlashlightTurnedOnTimer != null) { |
| 7319 | mFlashlightTurnedOnTimer.stopRunningLocked(elapsedRealtimeMs); |
| 7320 | } |
| 7321 | } |
| 7322 | |
| 7323 | public void noteResetFlashlightLocked(long elapsedRealtimeMs) { |
| 7324 | if (mFlashlightTurnedOnTimer != null) { |
| 7325 | mFlashlightTurnedOnTimer.stopAllRunningLocked(elapsedRealtimeMs); |
| 7326 | } |
| 7327 | } |
| 7328 | |
| 7329 | public StopwatchTimer createCameraTurnedOnTimerLocked() { |
| 7330 | if (mCameraTurnedOnTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7331 | mCameraTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, CAMERA_TURNED_ON, |
| 7332 | mBsi.mCameraTurnedOnTimers, mBsi.mOnBatteryTimeBase); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 7333 | } |
| 7334 | return mCameraTurnedOnTimer; |
| 7335 | } |
| 7336 | |
| 7337 | public void noteCameraTurnedOnLocked(long elapsedRealtimeMs) { |
| 7338 | createCameraTurnedOnTimerLocked().startRunningLocked(elapsedRealtimeMs); |
| 7339 | } |
| 7340 | |
| 7341 | public void noteCameraTurnedOffLocked(long elapsedRealtimeMs) { |
| 7342 | if (mCameraTurnedOnTimer != null) { |
| 7343 | mCameraTurnedOnTimer.stopRunningLocked(elapsedRealtimeMs); |
| 7344 | } |
| 7345 | } |
| 7346 | |
| 7347 | public void noteResetCameraLocked(long elapsedRealtimeMs) { |
| 7348 | if (mCameraTurnedOnTimer != null) { |
| 7349 | mCameraTurnedOnTimer.stopAllRunningLocked(elapsedRealtimeMs); |
| 7350 | } |
| 7351 | } |
| 7352 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 7353 | public StopwatchTimer createForegroundActivityTimerLocked() { |
| 7354 | if (mForegroundActivityTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7355 | mForegroundActivityTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, |
| 7356 | FOREGROUND_ACTIVITY, null, mBsi.mOnBatteryTimeBase); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 7357 | } |
| 7358 | return mForegroundActivityTimer; |
| 7359 | } |
| 7360 | |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 7361 | public StopwatchTimer createForegroundServiceTimerLocked() { |
| 7362 | if (mForegroundServiceTimer == null) { |
| 7363 | mForegroundServiceTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, |
| 7364 | FOREGROUND_SERVICE, null, mBsi.mOnBatteryTimeBase); |
| 7365 | } |
| 7366 | return mForegroundServiceTimer; |
| 7367 | } |
| 7368 | |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 7369 | public DualTimer createAggregatedPartialWakelockTimerLocked() { |
| 7370 | if (mAggregatedPartialWakelockTimer == null) { |
| 7371 | mAggregatedPartialWakelockTimer = new DualTimer(mBsi.mClocks, this, |
| 7372 | AGGREGATED_WAKE_TYPE_PARTIAL, null, |
| 7373 | mBsi.mOnBatteryScreenOffTimeBase, mOnBatteryScreenOffBackgroundTimeBase); |
| 7374 | } |
| 7375 | return mAggregatedPartialWakelockTimer; |
| 7376 | } |
| 7377 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 7378 | public DualTimer createBluetoothScanTimerLocked() { |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 7379 | if (mBluetoothScanTimer == null) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 7380 | mBluetoothScanTimer = new DualTimer(mBsi.mClocks, Uid.this, BLUETOOTH_SCAN_ON, |
| 7381 | mBsi.mBluetoothScanOnTimers, mBsi.mOnBatteryTimeBase, |
| 7382 | mOnBatteryBackgroundTimeBase); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 7383 | } |
| 7384 | return mBluetoothScanTimer; |
| 7385 | } |
| 7386 | |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 7387 | public DualTimer createBluetoothUnoptimizedScanTimerLocked() { |
| 7388 | if (mBluetoothUnoptimizedScanTimer == null) { |
| 7389 | mBluetoothUnoptimizedScanTimer = new DualTimer(mBsi.mClocks, Uid.this, |
| 7390 | BLUETOOTH_UNOPTIMIZED_SCAN_ON, null, |
| 7391 | mBsi.mOnBatteryTimeBase, mOnBatteryBackgroundTimeBase); |
| 7392 | } |
| 7393 | return mBluetoothUnoptimizedScanTimer; |
| 7394 | } |
| 7395 | |
Narayan Kamath | 0ebc96c | 2017-12-29 13:32:38 +0000 | [diff] [blame] | 7396 | public void noteBluetoothScanStartedLocked(long elapsedRealtimeMs, |
| 7397 | boolean isUnoptimized) { |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 7398 | createBluetoothScanTimerLocked().startRunningLocked(elapsedRealtimeMs); |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 7399 | if (isUnoptimized) { |
| 7400 | createBluetoothUnoptimizedScanTimerLocked().startRunningLocked(elapsedRealtimeMs); |
| 7401 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 7402 | } |
| 7403 | |
Bookatz | 94c5a31 | 2017-07-11 16:49:17 -0700 | [diff] [blame] | 7404 | public void noteBluetoothScanStoppedLocked(long elapsedRealtimeMs, boolean isUnoptimized) { |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 7405 | if (mBluetoothScanTimer != null) { |
| 7406 | mBluetoothScanTimer.stopRunningLocked(elapsedRealtimeMs); |
| 7407 | } |
Bookatz | 94c5a31 | 2017-07-11 16:49:17 -0700 | [diff] [blame] | 7408 | if (isUnoptimized && mBluetoothUnoptimizedScanTimer != null) { |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 7409 | mBluetoothUnoptimizedScanTimer.stopRunningLocked(elapsedRealtimeMs); |
| 7410 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 7411 | } |
| 7412 | |
| 7413 | public void noteResetBluetoothScanLocked(long elapsedRealtimeMs) { |
| 7414 | if (mBluetoothScanTimer != null) { |
| 7415 | mBluetoothScanTimer.stopAllRunningLocked(elapsedRealtimeMs); |
| 7416 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 7417 | if (mBluetoothUnoptimizedScanTimer != null) { |
| 7418 | mBluetoothUnoptimizedScanTimer.stopAllRunningLocked(elapsedRealtimeMs); |
| 7419 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 7420 | } |
| 7421 | |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 7422 | public Counter createBluetoothScanResultCounterLocked() { |
| 7423 | if (mBluetoothScanResultCounter == null) { |
| 7424 | mBluetoothScanResultCounter = new Counter(mBsi.mOnBatteryTimeBase); |
| 7425 | } |
| 7426 | return mBluetoothScanResultCounter; |
| 7427 | } |
| 7428 | |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 7429 | public Counter createBluetoothScanResultBgCounterLocked() { |
| 7430 | if (mBluetoothScanResultBgCounter == null) { |
| 7431 | mBluetoothScanResultBgCounter = new Counter(mOnBatteryBackgroundTimeBase); |
| 7432 | } |
| 7433 | return mBluetoothScanResultBgCounter; |
| 7434 | } |
| 7435 | |
Bookatz | 4ebc064 | 2017-05-11 12:21:19 -0700 | [diff] [blame] | 7436 | public void noteBluetoothScanResultsLocked(int numNewResults) { |
| 7437 | createBluetoothScanResultCounterLocked().addAtomic(numNewResults); |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 7438 | // Uses background timebase, so the count will only be incremented if uid in background. |
| 7439 | createBluetoothScanResultBgCounterLocked().addAtomic(numNewResults); |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 7440 | } |
| 7441 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 7442 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7443 | public void noteActivityResumedLocked(long elapsedRealtimeMs) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 7444 | // We always start, since we want multiple foreground PIDs to nest |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7445 | createForegroundActivityTimerLocked().startRunningLocked(elapsedRealtimeMs); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 7446 | } |
| 7447 | |
| 7448 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7449 | public void noteActivityPausedLocked(long elapsedRealtimeMs) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 7450 | if (mForegroundActivityTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7451 | mForegroundActivityTimer.stopRunningLocked(elapsedRealtimeMs); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 7452 | } |
| 7453 | } |
| 7454 | |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 7455 | public void noteForegroundServiceResumedLocked(long elapsedRealtimeMs) { |
| 7456 | createForegroundServiceTimerLocked().startRunningLocked(elapsedRealtimeMs); |
| 7457 | } |
| 7458 | |
| 7459 | public void noteForegroundServicePausedLocked(long elapsedRealtimeMs) { |
| 7460 | if (mForegroundServiceTimer != null) { |
| 7461 | mForegroundServiceTimer.stopRunningLocked(elapsedRealtimeMs); |
| 7462 | } |
| 7463 | } |
| 7464 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 7465 | public BatchTimer createVibratorOnTimerLocked() { |
| 7466 | if (mVibratorOnTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7467 | mVibratorOnTimer = new BatchTimer(mBsi.mClocks, Uid.this, VIBRATOR_ON, |
| 7468 | mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 7469 | } |
| 7470 | return mVibratorOnTimer; |
| 7471 | } |
| 7472 | |
| 7473 | public void noteVibratorOnLocked(long durationMillis) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7474 | createVibratorOnTimerLocked().addDuration(mBsi, durationMillis); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 7475 | } |
| 7476 | |
| 7477 | public void noteVibratorOffLocked() { |
| 7478 | if (mVibratorOnTimer != null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7479 | mVibratorOnTimer.abortLastDuration(mBsi); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7480 | } |
| 7481 | } |
| 7482 | |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7483 | @Override |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 7484 | @UnsupportedAppUsage |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7485 | public long getWifiRunningTime(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 7486 | if (mWifiRunningTimer == null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7487 | return 0; |
| 7488 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7489 | return mWifiRunningTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 7490 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 7491 | |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7492 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7493 | public long getFullWifiLockTime(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7494 | if (mFullWifiLockTimer == null) { |
| 7495 | return 0; |
| 7496 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7497 | return mFullWifiLockTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7498 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7499 | |
| 7500 | @Override |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 7501 | @UnsupportedAppUsage |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7502 | public long getWifiScanTime(long elapsedRealtimeUs, int which) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 7503 | if (mWifiScanTimer == null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7504 | return 0; |
| 7505 | } |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 7506 | return mWifiScanTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7507 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 7508 | |
| 7509 | @Override |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 7510 | public int getWifiScanCount(int which) { |
| 7511 | if (mWifiScanTimer == null) { |
| 7512 | return 0; |
| 7513 | } |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 7514 | return mWifiScanTimer.getCountLocked(which); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 7515 | } |
| 7516 | |
| 7517 | @Override |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7518 | public Timer getWifiScanTimer() { |
| 7519 | return mWifiScanTimer; |
| 7520 | } |
| 7521 | |
| 7522 | @Override |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 7523 | public int getWifiScanBackgroundCount(int which) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 7524 | if (mWifiScanTimer == null || mWifiScanTimer.getSubTimer() == null) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 7525 | return 0; |
| 7526 | } |
| 7527 | return mWifiScanTimer.getSubTimer().getCountLocked(which); |
| 7528 | } |
| 7529 | |
| 7530 | @Override |
| 7531 | public long getWifiScanActualTime(final long elapsedRealtimeUs) { |
| 7532 | if (mWifiScanTimer == null) { |
| 7533 | return 0; |
| 7534 | } |
| 7535 | final long elapsedRealtimeMs = (elapsedRealtimeUs + 500) / 1000; |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 7536 | return mWifiScanTimer.getTotalDurationMsLocked(elapsedRealtimeMs) * 1000; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 7537 | } |
| 7538 | |
| 7539 | @Override |
| 7540 | public long getWifiScanBackgroundTime(final long elapsedRealtimeUs) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 7541 | if (mWifiScanTimer == null || mWifiScanTimer.getSubTimer() == null) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 7542 | return 0; |
| 7543 | } |
| 7544 | final long elapsedRealtimeMs = (elapsedRealtimeUs + 500) / 1000; |
| 7545 | return mWifiScanTimer.getSubTimer().getTotalDurationMsLocked(elapsedRealtimeMs) * 1000; |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 7546 | } |
| 7547 | |
| 7548 | @Override |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7549 | public Timer getWifiScanBackgroundTimer() { |
| 7550 | if (mWifiScanTimer == null) { |
| 7551 | return null; |
| 7552 | } |
| 7553 | return mWifiScanTimer.getSubTimer(); |
| 7554 | } |
| 7555 | |
| 7556 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7557 | public long getWifiBatchedScanTime(int csphBin, long elapsedRealtimeUs, int which) { |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 7558 | if (csphBin < 0 || csphBin >= NUM_WIFI_BATCHED_SCAN_BINS) return 0; |
| 7559 | if (mWifiBatchedScanTimer[csphBin] == null) { |
| 7560 | return 0; |
| 7561 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7562 | return mWifiBatchedScanTimer[csphBin].getTotalTimeLocked(elapsedRealtimeUs, which); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 7563 | } |
| 7564 | |
| 7565 | @Override |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 7566 | public int getWifiBatchedScanCount(int csphBin, int which) { |
| 7567 | if (csphBin < 0 || csphBin >= NUM_WIFI_BATCHED_SCAN_BINS) return 0; |
| 7568 | if (mWifiBatchedScanTimer[csphBin] == null) { |
| 7569 | return 0; |
| 7570 | } |
| 7571 | return mWifiBatchedScanTimer[csphBin].getCountLocked(which); |
| 7572 | } |
| 7573 | |
| 7574 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7575 | public long getWifiMulticastTime(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7576 | if (mWifiMulticastTimer == null) { |
| 7577 | return 0; |
| 7578 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7579 | return mWifiMulticastTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 7580 | } |
| 7581 | |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7582 | @Override |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 7583 | public Timer getAudioTurnedOnTimer() { |
| 7584 | return mAudioTurnedOnTimer; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7585 | } |
| 7586 | |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7587 | @Override |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 7588 | public Timer getVideoTurnedOnTimer() { |
| 7589 | return mVideoTurnedOnTimer; |
| 7590 | } |
| 7591 | |
| 7592 | @Override |
| 7593 | public Timer getFlashlightTurnedOnTimer() { |
| 7594 | return mFlashlightTurnedOnTimer; |
| 7595 | } |
| 7596 | |
| 7597 | @Override |
| 7598 | public Timer getCameraTurnedOnTimer() { |
| 7599 | return mCameraTurnedOnTimer; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7600 | } |
| 7601 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 7602 | @Override |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 7603 | public Timer getForegroundActivityTimer() { |
| 7604 | return mForegroundActivityTimer; |
| 7605 | } |
| 7606 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 7607 | @Override |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 7608 | public Timer getForegroundServiceTimer() { |
| 7609 | return mForegroundServiceTimer; |
| 7610 | } |
| 7611 | |
| 7612 | @Override |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 7613 | public Timer getBluetoothScanTimer() { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 7614 | return mBluetoothScanTimer; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 7615 | } |
| 7616 | |
| 7617 | @Override |
| 7618 | public Timer getBluetoothScanBackgroundTimer() { |
| 7619 | if (mBluetoothScanTimer == null) { |
| 7620 | return null; |
| 7621 | } |
| 7622 | return mBluetoothScanTimer.getSubTimer(); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 7623 | } |
| 7624 | |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 7625 | @Override |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 7626 | public Timer getBluetoothUnoptimizedScanTimer() { |
| 7627 | return mBluetoothUnoptimizedScanTimer; |
| 7628 | } |
| 7629 | |
| 7630 | @Override |
| 7631 | public Timer getBluetoothUnoptimizedScanBackgroundTimer() { |
| 7632 | if (mBluetoothUnoptimizedScanTimer == null) { |
| 7633 | return null; |
| 7634 | } |
| 7635 | return mBluetoothUnoptimizedScanTimer.getSubTimer(); |
| 7636 | } |
| 7637 | |
| 7638 | @Override |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 7639 | public Counter getBluetoothScanResultCounter() { |
| 7640 | return mBluetoothScanResultCounter; |
| 7641 | } |
| 7642 | |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 7643 | @Override |
| 7644 | public Counter getBluetoothScanResultBgCounter() { |
| 7645 | return mBluetoothScanResultBgCounter; |
| 7646 | } |
| 7647 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 7648 | void makeProcessState(int i, Parcel in) { |
| 7649 | if (i < 0 || i >= NUM_PROCESS_STATE) return; |
| 7650 | |
| 7651 | if (in == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7652 | mProcessStateTimer[i] = new StopwatchTimer(mBsi.mClocks, this, PROCESS_STATE, null, |
| 7653 | mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 7654 | } else { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7655 | mProcessStateTimer[i] = new StopwatchTimer(mBsi.mClocks, this, PROCESS_STATE, null, |
| 7656 | mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 7657 | } |
| 7658 | } |
| 7659 | |
| 7660 | @Override |
| 7661 | public long getProcessStateTime(int state, long elapsedRealtimeUs, int which) { |
| 7662 | if (state < 0 || state >= NUM_PROCESS_STATE) return 0; |
| 7663 | if (mProcessStateTimer[state] == null) { |
| 7664 | return 0; |
| 7665 | } |
| 7666 | return mProcessStateTimer[state].getTotalTimeLocked(elapsedRealtimeUs, which); |
| 7667 | } |
| 7668 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 7669 | @Override |
Joe Onorato | 713fec8 | 2016-03-04 10:34:02 -0800 | [diff] [blame] | 7670 | public Timer getProcessStateTimer(int state) { |
| 7671 | if (state < 0 || state >= NUM_PROCESS_STATE) return null; |
| 7672 | return mProcessStateTimer[state]; |
| 7673 | } |
| 7674 | |
| 7675 | @Override |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 7676 | public Timer getVibratorOnTimer() { |
| 7677 | return mVibratorOnTimer; |
| 7678 | } |
| 7679 | |
| 7680 | @Override |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 7681 | public void noteUserActivityLocked(int type) { |
| 7682 | if (mUserActivityCounters == null) { |
| 7683 | initUserActivityLocked(); |
| 7684 | } |
Jeff Brown | df693de | 2012-07-27 12:03:38 -0700 | [diff] [blame] | 7685 | if (type >= 0 && type < NUM_USER_ACTIVITY_TYPES) { |
| 7686 | mUserActivityCounters[type].stepAtomic(); |
| 7687 | } else { |
| 7688 | Slog.w(TAG, "Unknown user activity type " + type + " was specified.", |
| 7689 | new Throwable()); |
| 7690 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 7691 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7692 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 7693 | @Override |
| 7694 | public boolean hasUserActivity() { |
| 7695 | return mUserActivityCounters != null; |
| 7696 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7697 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 7698 | @Override |
| 7699 | public int getUserActivityCount(int type, int which) { |
| 7700 | if (mUserActivityCounters == null) { |
| 7701 | return 0; |
| 7702 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 7703 | return mUserActivityCounters[type].getCountLocked(which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 7704 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7705 | |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 7706 | void makeWifiBatchedScanBin(int i, Parcel in) { |
| 7707 | if (i < 0 || i >= NUM_WIFI_BATCHED_SCAN_BINS) return; |
| 7708 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7709 | ArrayList<StopwatchTimer> collected = mBsi.mWifiBatchedScanTimers.get(i); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 7710 | if (collected == null) { |
| 7711 | collected = new ArrayList<StopwatchTimer>(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7712 | mBsi.mWifiBatchedScanTimers.put(i, collected); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 7713 | } |
| 7714 | if (in == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7715 | mWifiBatchedScanTimer[i] = new StopwatchTimer(mBsi.mClocks, this, WIFI_BATCHED_SCAN, |
| 7716 | collected, mBsi.mOnBatteryTimeBase); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 7717 | } else { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7718 | mWifiBatchedScanTimer[i] = new StopwatchTimer(mBsi.mClocks, this, WIFI_BATCHED_SCAN, |
| 7719 | collected, mBsi.mOnBatteryTimeBase, in); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 7720 | } |
| 7721 | } |
| 7722 | |
| 7723 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 7724 | void initUserActivityLocked() { |
| 7725 | mUserActivityCounters = new Counter[NUM_USER_ACTIVITY_TYPES]; |
| 7726 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7727 | mUserActivityCounters[i] = new Counter(mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 7728 | } |
| 7729 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7730 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 7731 | void noteNetworkActivityLocked(int type, long deltaBytes, long deltaPackets) { |
| 7732 | if (mNetworkByteActivityCounters == null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7733 | initNetworkActivityLocked(); |
| 7734 | } |
| 7735 | if (type >= 0 && type < NUM_NETWORK_ACTIVITY_TYPES) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 7736 | mNetworkByteActivityCounters[type].addCountLocked(deltaBytes); |
| 7737 | mNetworkPacketActivityCounters[type].addCountLocked(deltaPackets); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7738 | } else { |
| 7739 | Slog.w(TAG, "Unknown network activity type " + type + " was specified.", |
| 7740 | new Throwable()); |
| 7741 | } |
| 7742 | } |
| 7743 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 7744 | void noteMobileRadioActiveTimeLocked(long batteryUptime) { |
| 7745 | if (mNetworkByteActivityCounters == null) { |
| 7746 | initNetworkActivityLocked(); |
| 7747 | } |
| 7748 | mMobileRadioActiveTime.addCountLocked(batteryUptime); |
| 7749 | mMobileRadioActiveCount.addCountLocked(1); |
| 7750 | } |
| 7751 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7752 | @Override |
| 7753 | public boolean hasNetworkActivity() { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 7754 | return mNetworkByteActivityCounters != null; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7755 | } |
| 7756 | |
| 7757 | @Override |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 7758 | public long getNetworkActivityBytes(int type, int which) { |
| 7759 | if (mNetworkByteActivityCounters != null && type >= 0 |
| 7760 | && type < mNetworkByteActivityCounters.length) { |
| 7761 | return mNetworkByteActivityCounters[type].getCountLocked(which); |
| 7762 | } else { |
| 7763 | return 0; |
| 7764 | } |
| 7765 | } |
| 7766 | |
| 7767 | @Override |
| 7768 | public long getNetworkActivityPackets(int type, int which) { |
| 7769 | if (mNetworkPacketActivityCounters != null && type >= 0 |
| 7770 | && type < mNetworkPacketActivityCounters.length) { |
| 7771 | return mNetworkPacketActivityCounters[type].getCountLocked(which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7772 | } else { |
| 7773 | return 0; |
| 7774 | } |
| 7775 | } |
| 7776 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 7777 | @Override |
| 7778 | public long getMobileRadioActiveTime(int which) { |
| 7779 | return mMobileRadioActiveTime != null |
| 7780 | ? mMobileRadioActiveTime.getCountLocked(which) : 0; |
| 7781 | } |
| 7782 | |
| 7783 | @Override |
| 7784 | public int getMobileRadioActiveCount(int which) { |
| 7785 | return mMobileRadioActiveCount != null |
| 7786 | ? (int)mMobileRadioActiveCount.getCountLocked(which) : 0; |
| 7787 | } |
| 7788 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7789 | @Override |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 7790 | public long getUserCpuTimeUs(int which) { |
| 7791 | return mUserCpuTime.getCountLocked(which); |
| 7792 | } |
| 7793 | |
| 7794 | @Override |
| 7795 | public long getSystemCpuTimeUs(int which) { |
| 7796 | return mSystemCpuTime.getCountLocked(which); |
| 7797 | } |
| 7798 | |
| 7799 | @Override |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 7800 | public long getTimeAtCpuSpeed(int cluster, int step, int which) { |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 7801 | if (mCpuClusterSpeedTimesUs != null) { |
| 7802 | if (cluster >= 0 && cluster < mCpuClusterSpeedTimesUs.length) { |
| 7803 | final LongSamplingCounter[] cpuSpeedTimesUs = mCpuClusterSpeedTimesUs[cluster]; |
| 7804 | if (cpuSpeedTimesUs != null) { |
| 7805 | if (step >= 0 && step < cpuSpeedTimesUs.length) { |
| 7806 | final LongSamplingCounter c = cpuSpeedTimesUs[step]; |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 7807 | if (c != null) { |
| 7808 | return c.getCountLocked(which); |
| 7809 | } |
| 7810 | } |
| 7811 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 7812 | } |
| 7813 | } |
| 7814 | return 0; |
| 7815 | } |
| 7816 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 7817 | public void noteMobileRadioApWakeupLocked() { |
| 7818 | if (mMobileRadioApWakeupCount == null) { |
| 7819 | mMobileRadioApWakeupCount = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
| 7820 | } |
| 7821 | mMobileRadioApWakeupCount.addCountLocked(1); |
| 7822 | } |
| 7823 | |
| 7824 | @Override |
| 7825 | public long getMobileRadioApWakeupCount(int which) { |
| 7826 | if (mMobileRadioApWakeupCount != null) { |
| 7827 | return mMobileRadioApWakeupCount.getCountLocked(which); |
| 7828 | } |
| 7829 | return 0; |
| 7830 | } |
| 7831 | |
| 7832 | public void noteWifiRadioApWakeupLocked() { |
| 7833 | if (mWifiRadioApWakeupCount == null) { |
| 7834 | mWifiRadioApWakeupCount = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
| 7835 | } |
| 7836 | mWifiRadioApWakeupCount.addCountLocked(1); |
| 7837 | } |
| 7838 | |
| 7839 | @Override |
| 7840 | public long getWifiRadioApWakeupCount(int which) { |
| 7841 | if (mWifiRadioApWakeupCount != null) { |
| 7842 | return mWifiRadioApWakeupCount.getCountLocked(which); |
| 7843 | } |
| 7844 | return 0; |
| 7845 | } |
| 7846 | |
Amith Yamasani | 977e11f | 2018-02-16 11:29:54 -0800 | [diff] [blame] | 7847 | @Override |
| 7848 | public void getDeferredJobsCheckinLineLocked(StringBuilder sb, int which) { |
| 7849 | sb.setLength(0); |
| 7850 | final int deferredEventCount = mJobsDeferredEventCount.getCountLocked(which); |
| 7851 | if (deferredEventCount == 0) { |
| 7852 | return; |
| 7853 | } |
| 7854 | final int deferredCount = mJobsDeferredCount.getCountLocked(which); |
Amith Yamasani | 0ca706b | 2018-03-01 17:28:59 -0800 | [diff] [blame] | 7855 | final long totalLatency = mJobsFreshnessTimeMs.getCountLocked(which); |
Amith Yamasani | 977e11f | 2018-02-16 11:29:54 -0800 | [diff] [blame] | 7856 | sb.append(deferredEventCount); sb.append(','); |
| 7857 | sb.append(deferredCount); sb.append(','); |
Amith Yamasani | 0ca706b | 2018-03-01 17:28:59 -0800 | [diff] [blame] | 7858 | sb.append(totalLatency); |
Amith Yamasani | 977e11f | 2018-02-16 11:29:54 -0800 | [diff] [blame] | 7859 | for (int i = 0; i < JOB_FRESHNESS_BUCKETS.length; i++) { |
| 7860 | if (mJobsFreshnessBuckets[i] == null) { |
| 7861 | sb.append(",0"); |
| 7862 | } else { |
| 7863 | sb.append(","); |
| 7864 | sb.append(mJobsFreshnessBuckets[i].getCountLocked(which)); |
| 7865 | } |
| 7866 | } |
| 7867 | } |
| 7868 | |
| 7869 | @Override |
| 7870 | public void getDeferredJobsLineLocked(StringBuilder sb, int which) { |
| 7871 | sb.setLength(0); |
| 7872 | final int deferredEventCount = mJobsDeferredEventCount.getCountLocked(which); |
| 7873 | if (deferredEventCount == 0) { |
| 7874 | return; |
| 7875 | } |
| 7876 | final int deferredCount = mJobsDeferredCount.getCountLocked(which); |
Amith Yamasani | 0ca706b | 2018-03-01 17:28:59 -0800 | [diff] [blame] | 7877 | final long totalLatency = mJobsFreshnessTimeMs.getCountLocked(which); |
Amith Yamasani | 977e11f | 2018-02-16 11:29:54 -0800 | [diff] [blame] | 7878 | sb.append("times="); sb.append(deferredEventCount); sb.append(", "); |
| 7879 | sb.append("count="); sb.append(deferredCount); sb.append(", "); |
Amith Yamasani | 0ca706b | 2018-03-01 17:28:59 -0800 | [diff] [blame] | 7880 | sb.append("totalLatencyMs="); sb.append(totalLatency); sb.append(", "); |
Amith Yamasani | 977e11f | 2018-02-16 11:29:54 -0800 | [diff] [blame] | 7881 | for (int i = 0; i < JOB_FRESHNESS_BUCKETS.length; i++) { |
| 7882 | sb.append("<"); sb.append(JOB_FRESHNESS_BUCKETS[i]); sb.append("ms="); |
| 7883 | if (mJobsFreshnessBuckets[i] == null) { |
| 7884 | sb.append("0"); |
| 7885 | } else { |
| 7886 | sb.append(mJobsFreshnessBuckets[i].getCountLocked(which)); |
| 7887 | } |
| 7888 | sb.append(" "); |
| 7889 | } |
| 7890 | } |
| 7891 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7892 | void initNetworkActivityLocked() { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 7893 | mNetworkByteActivityCounters = new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
| 7894 | mNetworkPacketActivityCounters = new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7895 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7896 | mNetworkByteActivityCounters[i] = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
| 7897 | mNetworkPacketActivityCounters[i] = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7898 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7899 | mMobileRadioActiveTime = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
| 7900 | mMobileRadioActiveCount = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7901 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 7902 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7903 | /** |
| 7904 | * Clear all stats for this uid. Returns true if the uid is completely |
| 7905 | * inactive so can be dropped. |
| 7906 | */ |
Adam Lesinski | 5f212c8 | 2017-03-13 12:25:13 -0700 | [diff] [blame] | 7907 | @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
Bookatz | 993a0be | 2017-07-21 09:03:23 -0700 | [diff] [blame] | 7908 | public boolean reset(long uptime, long realtime) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7909 | boolean active = false; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7910 | |
Bookatz | 993a0be | 2017-07-21 09:03:23 -0700 | [diff] [blame] | 7911 | mOnBatteryBackgroundTimeBase.init(uptime, realtime); |
| 7912 | mOnBatteryScreenOffBackgroundTimeBase.init(uptime, realtime); |
| 7913 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 7914 | if (mWifiRunningTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7915 | active |= !mWifiRunningTimer.reset(false); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 7916 | active |= mWifiRunning; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7917 | } |
| 7918 | if (mFullWifiLockTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7919 | active |= !mFullWifiLockTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7920 | active |= mFullWifiLockOut; |
| 7921 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 7922 | if (mWifiScanTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7923 | active |= !mWifiScanTimer.reset(false); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 7924 | active |= mWifiScanStarted; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7925 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 7926 | if (mWifiBatchedScanTimer != null) { |
| 7927 | for (int i = 0; i < NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 7928 | if (mWifiBatchedScanTimer[i] != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7929 | active |= !mWifiBatchedScanTimer[i].reset(false); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 7930 | } |
| 7931 | } |
| 7932 | active |= (mWifiBatchedScanBinStarted != NO_BATCHED_SCAN_STARTED); |
| 7933 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7934 | if (mWifiMulticastTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7935 | active |= !mWifiMulticastTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7936 | active |= mWifiMulticastEnabled; |
| 7937 | } |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 7938 | |
| 7939 | active |= !resetTimerIfNotNull(mAudioTurnedOnTimer, false); |
| 7940 | active |= !resetTimerIfNotNull(mVideoTurnedOnTimer, false); |
| 7941 | active |= !resetTimerIfNotNull(mFlashlightTurnedOnTimer, false); |
| 7942 | active |= !resetTimerIfNotNull(mCameraTurnedOnTimer, false); |
| 7943 | active |= !resetTimerIfNotNull(mForegroundActivityTimer, false); |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 7944 | active |= !resetTimerIfNotNull(mForegroundServiceTimer, false); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 7945 | active |= !resetTimerIfNotNull(mAggregatedPartialWakelockTimer, false); |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 7946 | active |= !resetTimerIfNotNull(mBluetoothScanTimer, false); |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 7947 | active |= !resetTimerIfNotNull(mBluetoothUnoptimizedScanTimer, false); |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 7948 | if (mBluetoothScanResultCounter != null) { |
| 7949 | mBluetoothScanResultCounter.reset(false); |
| 7950 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 7951 | if (mBluetoothScanResultBgCounter != null) { |
| 7952 | mBluetoothScanResultBgCounter.reset(false); |
| 7953 | } |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 7954 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 7955 | if (mProcessStateTimer != null) { |
| 7956 | for (int i = 0; i < NUM_PROCESS_STATE; i++) { |
| 7957 | if (mProcessStateTimer[i] != null) { |
| 7958 | active |= !mProcessStateTimer[i].reset(false); |
| 7959 | } |
| 7960 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 7961 | active |= (mProcessState != ActivityManager.PROCESS_STATE_NONEXISTENT); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 7962 | } |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 7963 | if (mVibratorOnTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7964 | if (mVibratorOnTimer.reset(false)) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 7965 | mVibratorOnTimer.detach(); |
| 7966 | mVibratorOnTimer = null; |
| 7967 | } else { |
| 7968 | active = true; |
| 7969 | } |
| 7970 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7971 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7972 | if (mUserActivityCounters != null) { |
| 7973 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
| 7974 | mUserActivityCounters[i].reset(false); |
| 7975 | } |
| 7976 | } |
| 7977 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 7978 | if (mNetworkByteActivityCounters != null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7979 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 7980 | mNetworkByteActivityCounters[i].reset(false); |
| 7981 | mNetworkPacketActivityCounters[i].reset(false); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7982 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 7983 | mMobileRadioActiveTime.reset(false); |
| 7984 | mMobileRadioActiveCount.reset(false); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7985 | } |
| 7986 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 7987 | if (mWifiControllerActivity != null) { |
| 7988 | mWifiControllerActivity.reset(false); |
| 7989 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7990 | |
Adam Lesinski | 1a2b39e | 2016-04-29 17:56:58 -0700 | [diff] [blame] | 7991 | if (mBluetoothControllerActivity != null) { |
| 7992 | mBluetoothControllerActivity.reset(false); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 7993 | } |
| 7994 | |
Adam Lesinski | 1a2b39e | 2016-04-29 17:56:58 -0700 | [diff] [blame] | 7995 | if (mModemControllerActivity != null) { |
| 7996 | mModemControllerActivity.reset(false); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7997 | } |
| 7998 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 7999 | mUserCpuTime.reset(false); |
| 8000 | mSystemCpuTime.reset(false); |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 8001 | |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 8002 | if (mCpuClusterSpeedTimesUs != null) { |
| 8003 | for (LongSamplingCounter[] speeds : mCpuClusterSpeedTimesUs) { |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 8004 | if (speeds != null) { |
| 8005 | for (LongSamplingCounter speed : speeds) { |
| 8006 | if (speed != null) { |
| 8007 | speed.reset(false); |
| 8008 | } |
| 8009 | } |
| 8010 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 8011 | } |
| 8012 | } |
| 8013 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 8014 | if (mCpuFreqTimeMs != null) { |
| 8015 | mCpuFreqTimeMs.reset(false); |
| 8016 | } |
| 8017 | if (mScreenOffCpuFreqTimeMs != null) { |
| 8018 | mScreenOffCpuFreqTimeMs.reset(false); |
| 8019 | } |
| 8020 | |
Mike Ma | 3d422c3 | 2017-10-25 11:08:57 -0700 | [diff] [blame] | 8021 | mCpuActiveTimeMs.reset(false); |
| 8022 | mCpuClusterTimesMs.reset(false); |
| 8023 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 8024 | if (mProcStateTimeMs != null) { |
| 8025 | for (LongSamplingCounterArray counters : mProcStateTimeMs) { |
| 8026 | if (counters != null) { |
| 8027 | counters.reset(false); |
| 8028 | } |
| 8029 | } |
| 8030 | } |
| 8031 | if (mProcStateScreenOffTimeMs != null) { |
| 8032 | for (LongSamplingCounterArray counters : mProcStateScreenOffTimeMs) { |
| 8033 | if (counters != null) { |
| 8034 | counters.reset(false); |
| 8035 | } |
| 8036 | } |
| 8037 | } |
| 8038 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 8039 | resetLongCounterIfNotNull(mMobileRadioApWakeupCount, false); |
| 8040 | resetLongCounterIfNotNull(mWifiRadioApWakeupCount, false); |
| 8041 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8042 | final ArrayMap<String, Wakelock> wakeStats = mWakelockStats.getMap(); |
| 8043 | for (int iw=wakeStats.size()-1; iw>=0; iw--) { |
| 8044 | Wakelock wl = wakeStats.valueAt(iw); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 8045 | if (wl.reset()) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8046 | wakeStats.removeAt(iw); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 8047 | } else { |
| 8048 | active = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8049 | } |
| 8050 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8051 | mWakelockStats.cleanup(); |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 8052 | final ArrayMap<String, DualTimer> syncStats = mSyncStats.getMap(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8053 | for (int is=syncStats.size()-1; is>=0; is--) { |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 8054 | DualTimer timer = syncStats.valueAt(is); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 8055 | if (timer.reset(false)) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8056 | syncStats.removeAt(is); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 8057 | timer.detach(); |
| 8058 | } else { |
| 8059 | active = true; |
| 8060 | } |
| 8061 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8062 | mSyncStats.cleanup(); |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 8063 | final ArrayMap<String, DualTimer> jobStats = mJobStats.getMap(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8064 | for (int ij=jobStats.size()-1; ij>=0; ij--) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 8065 | DualTimer timer = jobStats.valueAt(ij); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 8066 | if (timer.reset(false)) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8067 | jobStats.removeAt(ij); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 8068 | timer.detach(); |
| 8069 | } else { |
| 8070 | active = true; |
| 8071 | } |
| 8072 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8073 | mJobStats.cleanup(); |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 8074 | mJobCompletions.clear(); |
Amith Yamasani | 977e11f | 2018-02-16 11:29:54 -0800 | [diff] [blame] | 8075 | |
| 8076 | mJobsDeferredEventCount.reset(false); |
| 8077 | mJobsDeferredCount.reset(false); |
| 8078 | mJobsFreshnessTimeMs.reset(false); |
| 8079 | for (int ij = 0; ij < JOB_FRESHNESS_BUCKETS.length; ij++) { |
| 8080 | if (mJobsFreshnessBuckets[ij] != null) { |
| 8081 | mJobsFreshnessBuckets[ij].reset(false); |
| 8082 | } |
| 8083 | } |
| 8084 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 8085 | for (int ise=mSensorStats.size()-1; ise>=0; ise--) { |
| 8086 | Sensor s = mSensorStats.valueAt(ise); |
| 8087 | if (s.reset()) { |
| 8088 | mSensorStats.removeAt(ise); |
| 8089 | } else { |
| 8090 | active = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8091 | } |
| 8092 | } |
Amith Yamasani | 977e11f | 2018-02-16 11:29:54 -0800 | [diff] [blame] | 8093 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 8094 | for (int ip=mProcessStats.size()-1; ip>=0; ip--) { |
| 8095 | Proc proc = mProcessStats.valueAt(ip); |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 8096 | proc.detach(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8097 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 8098 | mProcessStats.clear(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 8099 | if (mPids.size() > 0) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 8100 | for (int i=mPids.size()-1; i>=0; i--) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 8101 | Pid pid = mPids.valueAt(i); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 8102 | if (pid.mWakeNesting > 0) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 8103 | active = true; |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 8104 | } else { |
| 8105 | mPids.removeAt(i); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 8106 | } |
| 8107 | } |
| 8108 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8109 | if (mPackageStats.size() > 0) { |
| 8110 | Iterator<Map.Entry<String, Pkg>> it = mPackageStats.entrySet().iterator(); |
| 8111 | while (it.hasNext()) { |
| 8112 | Map.Entry<String, Pkg> pkgEntry = it.next(); |
| 8113 | Pkg p = pkgEntry.getValue(); |
| 8114 | p.detach(); |
| 8115 | if (p.mServiceStats.size() > 0) { |
| 8116 | Iterator<Map.Entry<String, Pkg.Serv>> it2 |
| 8117 | = p.mServiceStats.entrySet().iterator(); |
| 8118 | while (it2.hasNext()) { |
| 8119 | Map.Entry<String, Pkg.Serv> servEntry = it2.next(); |
| 8120 | servEntry.getValue().detach(); |
| 8121 | } |
| 8122 | } |
| 8123 | } |
| 8124 | mPackageStats.clear(); |
| 8125 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8126 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 8127 | mLastStepUserTime = mLastStepSystemTime = 0; |
| 8128 | mCurStepUserTime = mCurStepSystemTime = 0; |
| 8129 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8130 | if (!active) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 8131 | if (mWifiRunningTimer != null) { |
| 8132 | mWifiRunningTimer.detach(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8133 | } |
| 8134 | if (mFullWifiLockTimer != null) { |
| 8135 | mFullWifiLockTimer.detach(); |
| 8136 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 8137 | if (mWifiScanTimer != null) { |
| 8138 | mWifiScanTimer.detach(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8139 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 8140 | for (int i = 0; i < NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 8141 | if (mWifiBatchedScanTimer[i] != null) { |
| 8142 | mWifiBatchedScanTimer[i].detach(); |
| 8143 | } |
| 8144 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8145 | if (mWifiMulticastTimer != null) { |
| 8146 | mWifiMulticastTimer.detach(); |
| 8147 | } |
| 8148 | if (mAudioTurnedOnTimer != null) { |
| 8149 | mAudioTurnedOnTimer.detach(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 8150 | mAudioTurnedOnTimer = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8151 | } |
| 8152 | if (mVideoTurnedOnTimer != null) { |
| 8153 | mVideoTurnedOnTimer.detach(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 8154 | mVideoTurnedOnTimer = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8155 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 8156 | if (mFlashlightTurnedOnTimer != null) { |
| 8157 | mFlashlightTurnedOnTimer.detach(); |
| 8158 | mFlashlightTurnedOnTimer = null; |
| 8159 | } |
| 8160 | if (mCameraTurnedOnTimer != null) { |
| 8161 | mCameraTurnedOnTimer.detach(); |
| 8162 | mCameraTurnedOnTimer = null; |
| 8163 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 8164 | if (mForegroundActivityTimer != null) { |
| 8165 | mForegroundActivityTimer.detach(); |
| 8166 | mForegroundActivityTimer = null; |
| 8167 | } |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 8168 | if (mForegroundServiceTimer != null) { |
| 8169 | mForegroundServiceTimer.detach(); |
| 8170 | mForegroundServiceTimer = null; |
| 8171 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 8172 | if (mAggregatedPartialWakelockTimer != null) { |
| 8173 | mAggregatedPartialWakelockTimer.detach(); |
| 8174 | mAggregatedPartialWakelockTimer = null; |
| 8175 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 8176 | if (mBluetoothScanTimer != null) { |
| 8177 | mBluetoothScanTimer.detach(); |
| 8178 | mBluetoothScanTimer = null; |
| 8179 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 8180 | if (mBluetoothUnoptimizedScanTimer != null) { |
| 8181 | mBluetoothUnoptimizedScanTimer.detach(); |
| 8182 | mBluetoothUnoptimizedScanTimer = null; |
| 8183 | } |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 8184 | if (mBluetoothScanResultCounter != null) { |
| 8185 | mBluetoothScanResultCounter.detach(); |
| 8186 | mBluetoothScanResultCounter = null; |
| 8187 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 8188 | if (mBluetoothScanResultBgCounter != null) { |
| 8189 | mBluetoothScanResultBgCounter.detach(); |
| 8190 | mBluetoothScanResultBgCounter = null; |
| 8191 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8192 | if (mUserActivityCounters != null) { |
| 8193 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
| 8194 | mUserActivityCounters[i].detach(); |
| 8195 | } |
| 8196 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 8197 | if (mNetworkByteActivityCounters != null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 8198 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 8199 | mNetworkByteActivityCounters[i].detach(); |
| 8200 | mNetworkPacketActivityCounters[i].detach(); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 8201 | } |
| 8202 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8203 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8204 | if (mWifiControllerActivity != null) { |
| 8205 | mWifiControllerActivity.detach(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8206 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8207 | |
| 8208 | if (mBluetoothControllerActivity != null) { |
| 8209 | mBluetoothControllerActivity.detach(); |
| 8210 | } |
| 8211 | |
| 8212 | if (mModemControllerActivity != null) { |
| 8213 | mModemControllerActivity.detach(); |
| 8214 | } |
| 8215 | |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 8216 | mPids.clear(); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 8217 | |
| 8218 | mUserCpuTime.detach(); |
| 8219 | mSystemCpuTime.detach(); |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 8220 | |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 8221 | if (mCpuClusterSpeedTimesUs != null) { |
| 8222 | for (LongSamplingCounter[] cpuSpeeds : mCpuClusterSpeedTimesUs) { |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 8223 | if (cpuSpeeds != null) { |
| 8224 | for (LongSamplingCounter c : cpuSpeeds) { |
| 8225 | if (c != null) { |
| 8226 | c.detach(); |
| 8227 | } |
| 8228 | } |
| 8229 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 8230 | } |
| 8231 | } |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 8232 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 8233 | if (mCpuFreqTimeMs != null) { |
| 8234 | mCpuFreqTimeMs.detach(); |
| 8235 | } |
| 8236 | if (mScreenOffCpuFreqTimeMs != null) { |
| 8237 | mScreenOffCpuFreqTimeMs.detach(); |
| 8238 | } |
Mike Ma | 3d422c3 | 2017-10-25 11:08:57 -0700 | [diff] [blame] | 8239 | mCpuActiveTimeMs.detach(); |
| 8240 | mCpuClusterTimesMs.detach(); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 8241 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 8242 | if (mProcStateTimeMs != null) { |
| 8243 | for (LongSamplingCounterArray counters : mProcStateTimeMs) { |
| 8244 | if (counters != null) { |
| 8245 | counters.detach(); |
| 8246 | } |
| 8247 | } |
| 8248 | } |
| 8249 | if (mProcStateScreenOffTimeMs != null) { |
| 8250 | for (LongSamplingCounterArray counters : mProcStateScreenOffTimeMs) { |
| 8251 | if (counters != null) { |
| 8252 | counters.detach(); |
| 8253 | } |
| 8254 | } |
| 8255 | } |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 8256 | detachLongCounterIfNotNull(mMobileRadioApWakeupCount); |
| 8257 | detachLongCounterIfNotNull(mWifiRadioApWakeupCount); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8258 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8259 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8260 | return !active; |
| 8261 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8262 | |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 8263 | void writeJobCompletionsToParcelLocked(Parcel out) { |
| 8264 | int NJC = mJobCompletions.size(); |
| 8265 | out.writeInt(NJC); |
| 8266 | for (int ijc=0; ijc<NJC; ijc++) { |
| 8267 | out.writeString(mJobCompletions.keyAt(ijc)); |
| 8268 | SparseIntArray types = mJobCompletions.valueAt(ijc); |
| 8269 | int NT = types.size(); |
| 8270 | out.writeInt(NT); |
| 8271 | for (int it=0; it<NT; it++) { |
| 8272 | out.writeInt(types.keyAt(it)); |
| 8273 | out.writeInt(types.valueAt(it)); |
| 8274 | } |
| 8275 | } |
| 8276 | } |
| 8277 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 8278 | void writeToParcelLocked(Parcel out, long uptimeUs, long elapsedRealtimeUs) { |
| 8279 | mOnBatteryBackgroundTimeBase.writeToParcel(out, uptimeUs, elapsedRealtimeUs); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 8280 | mOnBatteryScreenOffBackgroundTimeBase.writeToParcel(out, uptimeUs, elapsedRealtimeUs); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 8281 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8282 | final ArrayMap<String, Wakelock> wakeStats = mWakelockStats.getMap(); |
| 8283 | int NW = wakeStats.size(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 8284 | out.writeInt(NW); |
| 8285 | for (int iw=0; iw<NW; iw++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8286 | out.writeString(wakeStats.keyAt(iw)); |
| 8287 | Uid.Wakelock wakelock = wakeStats.valueAt(iw); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8288 | wakelock.writeToParcelLocked(out, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8289 | } |
| 8290 | |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 8291 | final ArrayMap<String, DualTimer> syncStats = mSyncStats.getMap(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8292 | int NS = syncStats.size(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 8293 | out.writeInt(NS); |
| 8294 | for (int is=0; is<NS; is++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8295 | out.writeString(syncStats.keyAt(is)); |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 8296 | DualTimer timer = syncStats.valueAt(is); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 8297 | Timer.writeTimerToParcel(out, timer, elapsedRealtimeUs); |
| 8298 | } |
| 8299 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 8300 | final ArrayMap<String, DualTimer> jobStats = mJobStats.getMap(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8301 | int NJ = jobStats.size(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 8302 | out.writeInt(NJ); |
| 8303 | for (int ij=0; ij<NJ; ij++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8304 | out.writeString(jobStats.keyAt(ij)); |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 8305 | DualTimer timer = jobStats.valueAt(ij); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 8306 | Timer.writeTimerToParcel(out, timer, elapsedRealtimeUs); |
| 8307 | } |
| 8308 | |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 8309 | writeJobCompletionsToParcelLocked(out); |
| 8310 | |
Amith Yamasani | 977e11f | 2018-02-16 11:29:54 -0800 | [diff] [blame] | 8311 | mJobsDeferredEventCount.writeToParcel(out); |
| 8312 | mJobsDeferredCount.writeToParcel(out); |
| 8313 | mJobsFreshnessTimeMs.writeToParcel(out); |
| 8314 | for (int i = 0; i < JOB_FRESHNESS_BUCKETS.length; i++) { |
| 8315 | Counter.writeCounterToParcel(out, mJobsFreshnessBuckets[i]); |
| 8316 | } |
| 8317 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 8318 | int NSE = mSensorStats.size(); |
| 8319 | out.writeInt(NSE); |
| 8320 | for (int ise=0; ise<NSE; ise++) { |
| 8321 | out.writeInt(mSensorStats.keyAt(ise)); |
| 8322 | Uid.Sensor sensor = mSensorStats.valueAt(ise); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8323 | sensor.writeToParcelLocked(out, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8324 | } |
| 8325 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 8326 | int NP = mProcessStats.size(); |
| 8327 | out.writeInt(NP); |
| 8328 | for (int ip=0; ip<NP; ip++) { |
| 8329 | out.writeString(mProcessStats.keyAt(ip)); |
| 8330 | Uid.Proc proc = mProcessStats.valueAt(ip); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8331 | proc.writeToParcelLocked(out); |
| 8332 | } |
| 8333 | |
| 8334 | out.writeInt(mPackageStats.size()); |
| 8335 | for (Map.Entry<String, Uid.Pkg> pkgEntry : mPackageStats.entrySet()) { |
| 8336 | out.writeString(pkgEntry.getKey()); |
| 8337 | Uid.Pkg pkg = pkgEntry.getValue(); |
| 8338 | pkg.writeToParcelLocked(out); |
| 8339 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8340 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 8341 | if (mWifiRunningTimer != null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8342 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8343 | mWifiRunningTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 8344 | } else { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8345 | out.writeInt(0); |
| 8346 | } |
| 8347 | if (mFullWifiLockTimer != null) { |
| 8348 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8349 | mFullWifiLockTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8350 | } else { |
| 8351 | out.writeInt(0); |
| 8352 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 8353 | if (mWifiScanTimer != null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8354 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8355 | mWifiScanTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8356 | } else { |
| 8357 | out.writeInt(0); |
| 8358 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 8359 | for (int i = 0; i < NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 8360 | if (mWifiBatchedScanTimer[i] != null) { |
| 8361 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8362 | mWifiBatchedScanTimer[i].writeToParcel(out, elapsedRealtimeUs); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 8363 | } else { |
| 8364 | out.writeInt(0); |
| 8365 | } |
| 8366 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8367 | if (mWifiMulticastTimer != null) { |
| 8368 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8369 | mWifiMulticastTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8370 | } else { |
| 8371 | out.writeInt(0); |
| 8372 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8373 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8374 | if (mAudioTurnedOnTimer != null) { |
| 8375 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8376 | mAudioTurnedOnTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8377 | } else { |
| 8378 | out.writeInt(0); |
| 8379 | } |
| 8380 | if (mVideoTurnedOnTimer != null) { |
| 8381 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8382 | mVideoTurnedOnTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8383 | } else { |
| 8384 | out.writeInt(0); |
| 8385 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 8386 | if (mFlashlightTurnedOnTimer != null) { |
| 8387 | out.writeInt(1); |
| 8388 | mFlashlightTurnedOnTimer.writeToParcel(out, elapsedRealtimeUs); |
| 8389 | } else { |
| 8390 | out.writeInt(0); |
| 8391 | } |
| 8392 | if (mCameraTurnedOnTimer != null) { |
| 8393 | out.writeInt(1); |
| 8394 | mCameraTurnedOnTimer.writeToParcel(out, elapsedRealtimeUs); |
| 8395 | } else { |
| 8396 | out.writeInt(0); |
| 8397 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 8398 | if (mForegroundActivityTimer != null) { |
| 8399 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8400 | mForegroundActivityTimer.writeToParcel(out, elapsedRealtimeUs); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 8401 | } else { |
| 8402 | out.writeInt(0); |
| 8403 | } |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 8404 | if (mForegroundServiceTimer != null) { |
| 8405 | out.writeInt(1); |
| 8406 | mForegroundServiceTimer.writeToParcel(out, elapsedRealtimeUs); |
| 8407 | } else { |
| 8408 | out.writeInt(0); |
| 8409 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 8410 | if (mAggregatedPartialWakelockTimer != null) { |
| 8411 | out.writeInt(1); |
| 8412 | mAggregatedPartialWakelockTimer.writeToParcel(out, elapsedRealtimeUs); |
| 8413 | } else { |
| 8414 | out.writeInt(0); |
| 8415 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 8416 | if (mBluetoothScanTimer != null) { |
| 8417 | out.writeInt(1); |
| 8418 | mBluetoothScanTimer.writeToParcel(out, elapsedRealtimeUs); |
| 8419 | } else { |
| 8420 | out.writeInt(0); |
| 8421 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 8422 | if (mBluetoothUnoptimizedScanTimer != null) { |
| 8423 | out.writeInt(1); |
| 8424 | mBluetoothUnoptimizedScanTimer.writeToParcel(out, elapsedRealtimeUs); |
| 8425 | } else { |
| 8426 | out.writeInt(0); |
| 8427 | } |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 8428 | if (mBluetoothScanResultCounter != null) { |
| 8429 | out.writeInt(1); |
| 8430 | mBluetoothScanResultCounter.writeToParcel(out); |
| 8431 | } else { |
| 8432 | out.writeInt(0); |
| 8433 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 8434 | if (mBluetoothScanResultBgCounter != null) { |
| 8435 | out.writeInt(1); |
| 8436 | mBluetoothScanResultBgCounter.writeToParcel(out); |
| 8437 | } else { |
| 8438 | out.writeInt(0); |
| 8439 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 8440 | for (int i = 0; i < NUM_PROCESS_STATE; i++) { |
| 8441 | if (mProcessStateTimer[i] != null) { |
| 8442 | out.writeInt(1); |
| 8443 | mProcessStateTimer[i].writeToParcel(out, elapsedRealtimeUs); |
| 8444 | } else { |
| 8445 | out.writeInt(0); |
| 8446 | } |
| 8447 | } |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 8448 | if (mVibratorOnTimer != null) { |
| 8449 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8450 | mVibratorOnTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 8451 | } else { |
| 8452 | out.writeInt(0); |
| 8453 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8454 | if (mUserActivityCounters != null) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 8455 | out.writeInt(1); |
| 8456 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
| 8457 | mUserActivityCounters[i].writeToParcel(out); |
| 8458 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8459 | } else { |
| 8460 | out.writeInt(0); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 8461 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 8462 | if (mNetworkByteActivityCounters != null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 8463 | out.writeInt(1); |
| 8464 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 8465 | mNetworkByteActivityCounters[i].writeToParcel(out); |
| 8466 | mNetworkPacketActivityCounters[i].writeToParcel(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 8467 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 8468 | mMobileRadioActiveTime.writeToParcel(out); |
| 8469 | mMobileRadioActiveCount.writeToParcel(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 8470 | } else { |
| 8471 | out.writeInt(0); |
| 8472 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8473 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8474 | if (mWifiControllerActivity != null) { |
| 8475 | out.writeInt(1); |
| 8476 | mWifiControllerActivity.writeToParcel(out, 0); |
| 8477 | } else { |
| 8478 | out.writeInt(0); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8479 | } |
| 8480 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8481 | if (mBluetoothControllerActivity != null) { |
| 8482 | out.writeInt(1); |
| 8483 | mBluetoothControllerActivity.writeToParcel(out, 0); |
| 8484 | } else { |
| 8485 | out.writeInt(0); |
| 8486 | } |
| 8487 | |
| 8488 | if (mModemControllerActivity != null) { |
| 8489 | out.writeInt(1); |
| 8490 | mModemControllerActivity.writeToParcel(out, 0); |
| 8491 | } else { |
| 8492 | out.writeInt(0); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8493 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 8494 | |
| 8495 | mUserCpuTime.writeToParcel(out); |
| 8496 | mSystemCpuTime.writeToParcel(out); |
| 8497 | |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 8498 | if (mCpuClusterSpeedTimesUs != null) { |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 8499 | out.writeInt(1); |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 8500 | out.writeInt(mCpuClusterSpeedTimesUs.length); |
| 8501 | for (LongSamplingCounter[] cpuSpeeds : mCpuClusterSpeedTimesUs) { |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 8502 | if (cpuSpeeds != null) { |
| 8503 | out.writeInt(1); |
| 8504 | out.writeInt(cpuSpeeds.length); |
| 8505 | for (LongSamplingCounter c : cpuSpeeds) { |
| 8506 | if (c != null) { |
| 8507 | out.writeInt(1); |
| 8508 | c.writeToParcel(out); |
| 8509 | } else { |
| 8510 | out.writeInt(0); |
| 8511 | } |
| 8512 | } |
| 8513 | } else { |
| 8514 | out.writeInt(0); |
| 8515 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 8516 | } |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 8517 | } else { |
| 8518 | out.writeInt(0); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 8519 | } |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 8520 | |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 8521 | LongSamplingCounterArray.writeToParcel(out, mCpuFreqTimeMs); |
| 8522 | LongSamplingCounterArray.writeToParcel(out, mScreenOffCpuFreqTimeMs); |
Mike Ma | 3d422c3 | 2017-10-25 11:08:57 -0700 | [diff] [blame] | 8523 | |
| 8524 | mCpuActiveTimeMs.writeToParcel(out); |
| 8525 | mCpuClusterTimesMs.writeToParcel(out); |
| 8526 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 8527 | if (mProcStateTimeMs != null) { |
| 8528 | out.writeInt(mProcStateTimeMs.length); |
| 8529 | for (LongSamplingCounterArray counters : mProcStateTimeMs) { |
| 8530 | LongSamplingCounterArray.writeToParcel(out, counters); |
| 8531 | } |
| 8532 | } else { |
| 8533 | out.writeInt(0); |
| 8534 | } |
| 8535 | if (mProcStateScreenOffTimeMs != null) { |
| 8536 | out.writeInt(mProcStateScreenOffTimeMs.length); |
| 8537 | for (LongSamplingCounterArray counters : mProcStateScreenOffTimeMs) { |
| 8538 | LongSamplingCounterArray.writeToParcel(out, counters); |
| 8539 | } |
| 8540 | } else { |
| 8541 | out.writeInt(0); |
| 8542 | } |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 8543 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 8544 | if (mMobileRadioApWakeupCount != null) { |
| 8545 | out.writeInt(1); |
| 8546 | mMobileRadioApWakeupCount.writeToParcel(out); |
| 8547 | } else { |
| 8548 | out.writeInt(0); |
| 8549 | } |
| 8550 | |
| 8551 | if (mWifiRadioApWakeupCount != null) { |
| 8552 | out.writeInt(1); |
| 8553 | mWifiRadioApWakeupCount.writeToParcel(out); |
| 8554 | } else { |
| 8555 | out.writeInt(0); |
| 8556 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8557 | } |
| 8558 | |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 8559 | void readJobCompletionsFromParcelLocked(Parcel in) { |
| 8560 | int numJobCompletions = in.readInt(); |
| 8561 | mJobCompletions.clear(); |
| 8562 | for (int j = 0; j < numJobCompletions; j++) { |
| 8563 | String jobName = in.readString(); |
| 8564 | int numTypes = in.readInt(); |
| 8565 | if (numTypes > 0) { |
| 8566 | SparseIntArray types = new SparseIntArray(); |
| 8567 | for (int k = 0; k < numTypes; k++) { |
| 8568 | int type = in.readInt(); |
| 8569 | int count = in.readInt(); |
| 8570 | types.put(type, count); |
| 8571 | } |
| 8572 | mJobCompletions.put(jobName, types); |
| 8573 | } |
| 8574 | } |
| 8575 | } |
| 8576 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8577 | void readFromParcelLocked(TimeBase timeBase, TimeBase screenOffTimeBase, Parcel in) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 8578 | mOnBatteryBackgroundTimeBase.readFromParcel(in); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 8579 | mOnBatteryScreenOffBackgroundTimeBase.readFromParcel(in); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 8580 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8581 | int numWakelocks = in.readInt(); |
| 8582 | mWakelockStats.clear(); |
| 8583 | for (int j = 0; j < numWakelocks; j++) { |
| 8584 | String wakelockName = in.readString(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8585 | Uid.Wakelock wakelock = new Wakelock(mBsi, this); |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 8586 | wakelock.readFromParcelLocked( |
| 8587 | timeBase, screenOffTimeBase, mOnBatteryScreenOffBackgroundTimeBase, in); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8588 | mWakelockStats.add(wakelockName, wakelock); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8589 | } |
| 8590 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 8591 | int numSyncs = in.readInt(); |
| 8592 | mSyncStats.clear(); |
| 8593 | for (int j = 0; j < numSyncs; j++) { |
| 8594 | String syncName = in.readString(); |
| 8595 | if (in.readInt() != 0) { |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 8596 | mSyncStats.add(syncName, new DualTimer(mBsi.mClocks, Uid.this, SYNC, null, |
| 8597 | mBsi.mOnBatteryTimeBase, mOnBatteryBackgroundTimeBase, in)); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 8598 | } |
| 8599 | } |
| 8600 | |
| 8601 | int numJobs = in.readInt(); |
| 8602 | mJobStats.clear(); |
| 8603 | for (int j = 0; j < numJobs; j++) { |
| 8604 | String jobName = in.readString(); |
| 8605 | if (in.readInt() != 0) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 8606 | mJobStats.add(jobName, new DualTimer(mBsi.mClocks, Uid.this, JOB, null, |
| 8607 | mBsi.mOnBatteryTimeBase, mOnBatteryBackgroundTimeBase, in)); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 8608 | } |
| 8609 | } |
| 8610 | |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 8611 | readJobCompletionsFromParcelLocked(in); |
| 8612 | |
Amith Yamasani | 977e11f | 2018-02-16 11:29:54 -0800 | [diff] [blame] | 8613 | mJobsDeferredEventCount = new Counter(mBsi.mOnBatteryTimeBase, in); |
| 8614 | mJobsDeferredCount = new Counter(mBsi.mOnBatteryTimeBase, in); |
| 8615 | mJobsFreshnessTimeMs = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
| 8616 | for (int i = 0; i < JOB_FRESHNESS_BUCKETS.length; i++) { |
| 8617 | mJobsFreshnessBuckets[i] = Counter.readCounterFromParcel(mBsi.mOnBatteryTimeBase, |
| 8618 | in); |
| 8619 | } |
| 8620 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8621 | int numSensors = in.readInt(); |
| 8622 | mSensorStats.clear(); |
| 8623 | for (int k = 0; k < numSensors; k++) { |
| 8624 | int sensorNumber = in.readInt(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8625 | Uid.Sensor sensor = new Sensor(mBsi, this, sensorNumber); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 8626 | sensor.readFromParcelLocked(mBsi.mOnBatteryTimeBase, mOnBatteryBackgroundTimeBase, |
| 8627 | in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8628 | mSensorStats.put(sensorNumber, sensor); |
| 8629 | } |
| 8630 | |
| 8631 | int numProcs = in.readInt(); |
| 8632 | mProcessStats.clear(); |
| 8633 | for (int k = 0; k < numProcs; k++) { |
| 8634 | String processName = in.readString(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8635 | Uid.Proc proc = new Proc(mBsi, processName); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8636 | proc.readFromParcelLocked(in); |
| 8637 | mProcessStats.put(processName, proc); |
| 8638 | } |
| 8639 | |
| 8640 | int numPkgs = in.readInt(); |
| 8641 | mPackageStats.clear(); |
| 8642 | for (int l = 0; l < numPkgs; l++) { |
| 8643 | String packageName = in.readString(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8644 | Uid.Pkg pkg = new Pkg(mBsi); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8645 | pkg.readFromParcelLocked(in); |
| 8646 | mPackageStats.put(packageName, pkg); |
| 8647 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8648 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 8649 | mWifiRunning = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8650 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8651 | mWifiRunningTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, WIFI_RUNNING, |
| 8652 | mBsi.mWifiRunningTimers, mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 8653 | } else { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 8654 | mWifiRunningTimer = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8655 | } |
| 8656 | mFullWifiLockOut = false; |
| 8657 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8658 | mFullWifiLockTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, FULL_WIFI_LOCK, |
| 8659 | mBsi.mFullWifiLockTimers, mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8660 | } else { |
| 8661 | mFullWifiLockTimer = null; |
| 8662 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 8663 | mWifiScanStarted = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8664 | if (in.readInt() != 0) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 8665 | mWifiScanTimer = new DualTimer(mBsi.mClocks, Uid.this, WIFI_SCAN, |
| 8666 | mBsi.mWifiScanTimers, mBsi.mOnBatteryTimeBase, mOnBatteryBackgroundTimeBase, |
| 8667 | in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8668 | } else { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 8669 | mWifiScanTimer = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8670 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 8671 | mWifiBatchedScanBinStarted = NO_BATCHED_SCAN_STARTED; |
| 8672 | for (int i = 0; i < NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 8673 | if (in.readInt() != 0) { |
| 8674 | makeWifiBatchedScanBin(i, in); |
| 8675 | } else { |
| 8676 | mWifiBatchedScanTimer[i] = null; |
| 8677 | } |
| 8678 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8679 | mWifiMulticastEnabled = false; |
| 8680 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8681 | mWifiMulticastTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, WIFI_MULTICAST_ENABLED, |
| 8682 | mBsi.mWifiMulticastTimers, mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8683 | } else { |
| 8684 | mWifiMulticastTimer = null; |
| 8685 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8686 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8687 | mAudioTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, AUDIO_TURNED_ON, |
| 8688 | mBsi.mAudioTurnedOnTimers, mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8689 | } else { |
| 8690 | mAudioTurnedOnTimer = null; |
| 8691 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8692 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8693 | mVideoTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, VIDEO_TURNED_ON, |
| 8694 | mBsi.mVideoTurnedOnTimers, mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8695 | } else { |
| 8696 | mVideoTurnedOnTimer = null; |
| 8697 | } |
| 8698 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8699 | mFlashlightTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, |
| 8700 | FLASHLIGHT_TURNED_ON, mBsi.mFlashlightTurnedOnTimers, mBsi.mOnBatteryTimeBase, in); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 8701 | } else { |
| 8702 | mFlashlightTurnedOnTimer = null; |
| 8703 | } |
| 8704 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8705 | mCameraTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, CAMERA_TURNED_ON, |
| 8706 | mBsi.mCameraTurnedOnTimers, mBsi.mOnBatteryTimeBase, in); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 8707 | } else { |
| 8708 | mCameraTurnedOnTimer = null; |
| 8709 | } |
| 8710 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8711 | mForegroundActivityTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, |
| 8712 | FOREGROUND_ACTIVITY, null, mBsi.mOnBatteryTimeBase, in); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 8713 | } else { |
| 8714 | mForegroundActivityTimer = null; |
| 8715 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 8716 | if (in.readInt() != 0) { |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 8717 | mForegroundServiceTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, |
| 8718 | FOREGROUND_SERVICE, null, mBsi.mOnBatteryTimeBase, in); |
| 8719 | } else { |
| 8720 | mForegroundServiceTimer = null; |
| 8721 | } |
| 8722 | if (in.readInt() != 0) { |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 8723 | mAggregatedPartialWakelockTimer = new DualTimer(mBsi.mClocks, this, |
| 8724 | AGGREGATED_WAKE_TYPE_PARTIAL, null, |
| 8725 | mBsi.mOnBatteryScreenOffTimeBase, mOnBatteryScreenOffBackgroundTimeBase, |
| 8726 | in); |
| 8727 | } else { |
| 8728 | mAggregatedPartialWakelockTimer = null; |
| 8729 | } |
| 8730 | if (in.readInt() != 0) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 8731 | mBluetoothScanTimer = new DualTimer(mBsi.mClocks, Uid.this, BLUETOOTH_SCAN_ON, |
| 8732 | mBsi.mBluetoothScanOnTimers, mBsi.mOnBatteryTimeBase, |
| 8733 | mOnBatteryBackgroundTimeBase, in); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 8734 | } else { |
| 8735 | mBluetoothScanTimer = null; |
| 8736 | } |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 8737 | if (in.readInt() != 0) { |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 8738 | mBluetoothUnoptimizedScanTimer = new DualTimer(mBsi.mClocks, Uid.this, |
| 8739 | BLUETOOTH_UNOPTIMIZED_SCAN_ON, null, |
| 8740 | mBsi.mOnBatteryTimeBase, mOnBatteryBackgroundTimeBase, in); |
| 8741 | } else { |
| 8742 | mBluetoothUnoptimizedScanTimer = null; |
| 8743 | } |
| 8744 | if (in.readInt() != 0) { |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 8745 | mBluetoothScanResultCounter = new Counter(mBsi.mOnBatteryTimeBase, in); |
| 8746 | } else { |
| 8747 | mBluetoothScanResultCounter = null; |
| 8748 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 8749 | if (in.readInt() != 0) { |
| 8750 | mBluetoothScanResultBgCounter = new Counter(mOnBatteryBackgroundTimeBase, in); |
| 8751 | } else { |
| 8752 | mBluetoothScanResultBgCounter = null; |
| 8753 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 8754 | mProcessState = ActivityManager.PROCESS_STATE_NONEXISTENT; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 8755 | for (int i = 0; i < NUM_PROCESS_STATE; i++) { |
| 8756 | if (in.readInt() != 0) { |
| 8757 | makeProcessState(i, in); |
| 8758 | } else { |
| 8759 | mProcessStateTimer[i] = null; |
| 8760 | } |
| 8761 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 8762 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8763 | mVibratorOnTimer = new BatchTimer(mBsi.mClocks, Uid.this, VIBRATOR_ON, |
| 8764 | mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 8765 | } else { |
| 8766 | mVibratorOnTimer = null; |
| 8767 | } |
| 8768 | if (in.readInt() != 0) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 8769 | mUserActivityCounters = new Counter[NUM_USER_ACTIVITY_TYPES]; |
| 8770 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8771 | mUserActivityCounters[i] = new Counter(mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 8772 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8773 | } else { |
| 8774 | mUserActivityCounters = null; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 8775 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 8776 | if (in.readInt() != 0) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 8777 | mNetworkByteActivityCounters = new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
| 8778 | mNetworkPacketActivityCounters |
| 8779 | = new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 8780 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8781 | mNetworkByteActivityCounters[i] |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8782 | = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8783 | mNetworkPacketActivityCounters[i] |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8784 | = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 8785 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8786 | mMobileRadioActiveTime = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
| 8787 | mMobileRadioActiveCount = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 8788 | } else { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 8789 | mNetworkByteActivityCounters = null; |
| 8790 | mNetworkPacketActivityCounters = null; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 8791 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8792 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8793 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8794 | mWifiControllerActivity = new ControllerActivityCounterImpl(mBsi.mOnBatteryTimeBase, |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8795 | NUM_WIFI_TX_LEVELS, in); |
| 8796 | } else { |
| 8797 | mWifiControllerActivity = null; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8798 | } |
| 8799 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8800 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8801 | mBluetoothControllerActivity = new ControllerActivityCounterImpl(mBsi.mOnBatteryTimeBase, |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8802 | NUM_BT_TX_LEVELS, in); |
| 8803 | } else { |
| 8804 | mBluetoothControllerActivity = null; |
| 8805 | } |
| 8806 | |
| 8807 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8808 | mModemControllerActivity = new ControllerActivityCounterImpl(mBsi.mOnBatteryTimeBase, |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8809 | ModemActivityInfo.TX_POWER_LEVELS, in); |
| 8810 | } else { |
| 8811 | mModemControllerActivity = null; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8812 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 8813 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8814 | mUserCpuTime = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
| 8815 | mSystemCpuTime = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 8816 | |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 8817 | if (in.readInt() != 0) { |
| 8818 | int numCpuClusters = in.readInt(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8819 | if (mBsi.mPowerProfile != null && mBsi.mPowerProfile.getNumCpuClusters() != numCpuClusters) { |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 8820 | throw new ParcelFormatException("Incompatible number of cpu clusters"); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 8821 | } |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 8822 | |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 8823 | mCpuClusterSpeedTimesUs = new LongSamplingCounter[numCpuClusters][]; |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 8824 | for (int cluster = 0; cluster < numCpuClusters; cluster++) { |
| 8825 | if (in.readInt() != 0) { |
| 8826 | int numSpeeds = in.readInt(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8827 | if (mBsi.mPowerProfile != null && |
| 8828 | mBsi.mPowerProfile.getNumSpeedStepsInCpuCluster(cluster) != numSpeeds) { |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 8829 | throw new ParcelFormatException("Incompatible number of cpu speeds"); |
| 8830 | } |
| 8831 | |
| 8832 | final LongSamplingCounter[] cpuSpeeds = new LongSamplingCounter[numSpeeds]; |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 8833 | mCpuClusterSpeedTimesUs[cluster] = cpuSpeeds; |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 8834 | for (int speed = 0; speed < numSpeeds; speed++) { |
| 8835 | if (in.readInt() != 0) { |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 8836 | cpuSpeeds[speed] = new LongSamplingCounter( |
| 8837 | mBsi.mOnBatteryTimeBase, in); |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 8838 | } |
| 8839 | } |
Adam Lesinski | a57a540 | 2015-09-28 10:21:33 -0700 | [diff] [blame] | 8840 | } else { |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 8841 | mCpuClusterSpeedTimesUs[cluster] = null; |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 8842 | } |
| 8843 | } |
| 8844 | } else { |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 8845 | mCpuClusterSpeedTimesUs = null; |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 8846 | } |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 8847 | |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 8848 | mCpuFreqTimeMs = LongSamplingCounterArray.readFromParcel(in, mBsi.mOnBatteryTimeBase); |
| 8849 | mScreenOffCpuFreqTimeMs = LongSamplingCounterArray.readFromParcel( |
| 8850 | in, mBsi.mOnBatteryScreenOffTimeBase); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 8851 | |
Mike Ma | 3d422c3 | 2017-10-25 11:08:57 -0700 | [diff] [blame] | 8852 | mCpuActiveTimeMs = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
| 8853 | mCpuClusterTimesMs = new LongSamplingCounterArray(mBsi.mOnBatteryTimeBase, in); |
| 8854 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 8855 | int length = in.readInt(); |
| 8856 | if (length == NUM_PROCESS_STATE) { |
| 8857 | mProcStateTimeMs = new LongSamplingCounterArray[length]; |
| 8858 | for (int procState = 0; procState < length; ++procState) { |
| 8859 | mProcStateTimeMs[procState] = LongSamplingCounterArray.readFromParcel( |
| 8860 | in, mBsi.mOnBatteryTimeBase); |
| 8861 | } |
| 8862 | } else { |
| 8863 | mProcStateTimeMs = null; |
| 8864 | } |
| 8865 | length = in.readInt(); |
| 8866 | if (length == NUM_PROCESS_STATE) { |
| 8867 | mProcStateScreenOffTimeMs = new LongSamplingCounterArray[length]; |
| 8868 | for (int procState = 0; procState < length; ++procState) { |
| 8869 | mProcStateScreenOffTimeMs[procState] = LongSamplingCounterArray.readFromParcel( |
| 8870 | in, mBsi.mOnBatteryScreenOffTimeBase); |
| 8871 | } |
| 8872 | } else { |
| 8873 | mProcStateScreenOffTimeMs = null; |
| 8874 | } |
| 8875 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 8876 | if (in.readInt() != 0) { |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 8877 | mMobileRadioApWakeupCount = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
| 8878 | } else { |
| 8879 | mMobileRadioApWakeupCount = null; |
| 8880 | } |
| 8881 | |
| 8882 | if (in.readInt() != 0) { |
| 8883 | mWifiRadioApWakeupCount = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
| 8884 | } else { |
| 8885 | mWifiRadioApWakeupCount = null; |
| 8886 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8887 | } |
| 8888 | |
Amith Yamasani | 977e11f | 2018-02-16 11:29:54 -0800 | [diff] [blame] | 8889 | public void noteJobsDeferredLocked(int numDeferred, long sinceLast) { |
| 8890 | mJobsDeferredEventCount.addAtomic(1); |
| 8891 | mJobsDeferredCount.addAtomic(numDeferred); |
| 8892 | if (sinceLast != 0) { |
| 8893 | // Add the total time, which can be divided by the event count to get an average |
| 8894 | mJobsFreshnessTimeMs.addCountLocked(sinceLast); |
| 8895 | // Also keep track of how many times there were in these different buckets. |
| 8896 | for (int i = 0; i < JOB_FRESHNESS_BUCKETS.length; i++) { |
| 8897 | if (sinceLast < JOB_FRESHNESS_BUCKETS[i]) { |
| 8898 | if (mJobsFreshnessBuckets[i] == null) { |
| 8899 | mJobsFreshnessBuckets[i] = new Counter( |
| 8900 | mBsi.mOnBatteryTimeBase); |
| 8901 | } |
| 8902 | mJobsFreshnessBuckets[i].addAtomic(1); |
| 8903 | break; |
| 8904 | } |
| 8905 | } |
| 8906 | } |
| 8907 | } |
| 8908 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8909 | /** |
| 8910 | * The statistics associated with a particular wake lock. |
| 8911 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8912 | public static class Wakelock extends BatteryStats.Uid.Wakelock { |
| 8913 | /** |
| 8914 | * BatteryStatsImpl that we are associated with. |
| 8915 | */ |
| 8916 | protected BatteryStatsImpl mBsi; |
| 8917 | |
| 8918 | /** |
| 8919 | * BatteryStatsImpl that we are associated with. |
| 8920 | */ |
| 8921 | protected Uid mUid; |
| 8922 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8923 | /** |
| 8924 | * How long (in ms) this uid has been keeping the device partially awake. |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 8925 | * 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] | 8926 | */ |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 8927 | DualTimer mTimerPartial; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8928 | |
| 8929 | /** |
| 8930 | * How long (in ms) this uid has been keeping the device fully awake. |
| 8931 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 8932 | StopwatchTimer mTimerFull; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8933 | |
| 8934 | /** |
| 8935 | * How long (in ms) this uid has had a window keeping the device awake. |
| 8936 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 8937 | StopwatchTimer mTimerWindow; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8938 | |
| 8939 | /** |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 8940 | * How long (in ms) this uid has had a draw wake lock. |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 8941 | */ |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 8942 | StopwatchTimer mTimerDraw; |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 8943 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8944 | public Wakelock(BatteryStatsImpl bsi, Uid uid) { |
| 8945 | mBsi = bsi; |
| 8946 | mUid = uid; |
| 8947 | } |
| 8948 | |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 8949 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8950 | * Reads a possibly null Timer from a Parcel. The timer is associated with the |
| 8951 | * proper timer pool from the given BatteryStatsImpl object. |
| 8952 | * |
| 8953 | * @param in the Parcel to be read from. |
| 8954 | * return a new Timer, or null. |
| 8955 | */ |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 8956 | private StopwatchTimer readStopwatchTimerFromParcel(int type, |
| 8957 | ArrayList<StopwatchTimer> pool, TimeBase timeBase, Parcel in) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8958 | if (in.readInt() == 0) { |
| 8959 | return null; |
| 8960 | } |
| 8961 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8962 | 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] | 8963 | } |
| 8964 | |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 8965 | /** |
| 8966 | * Reads a possibly null Timer from a Parcel. The timer is associated with the |
| 8967 | * proper timer pool from the given BatteryStatsImpl object. |
| 8968 | * |
| 8969 | * @param in the Parcel to be read from. |
| 8970 | * return a new Timer, or null. |
| 8971 | */ |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 8972 | private DualTimer readDualTimerFromParcel(int type, ArrayList<StopwatchTimer> pool, |
| 8973 | TimeBase timeBase, TimeBase bgTimeBase, Parcel in) { |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 8974 | if (in.readInt() == 0) { |
| 8975 | return null; |
| 8976 | } |
| 8977 | |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 8978 | return new DualTimer(mBsi.mClocks, mUid, type, pool, timeBase, bgTimeBase, in); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 8979 | } |
| 8980 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8981 | boolean reset() { |
| 8982 | boolean wlactive = false; |
| 8983 | if (mTimerFull != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8984 | wlactive |= !mTimerFull.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8985 | } |
| 8986 | if (mTimerPartial != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8987 | wlactive |= !mTimerPartial.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8988 | } |
| 8989 | if (mTimerWindow != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8990 | wlactive |= !mTimerWindow.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8991 | } |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 8992 | if (mTimerDraw != null) { |
| 8993 | wlactive |= !mTimerDraw.reset(false); |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 8994 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8995 | if (!wlactive) { |
| 8996 | if (mTimerFull != null) { |
| 8997 | mTimerFull.detach(); |
| 8998 | mTimerFull = null; |
| 8999 | } |
| 9000 | if (mTimerPartial != null) { |
| 9001 | mTimerPartial.detach(); |
| 9002 | mTimerPartial = null; |
| 9003 | } |
| 9004 | if (mTimerWindow != null) { |
| 9005 | mTimerWindow.detach(); |
| 9006 | mTimerWindow = null; |
| 9007 | } |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 9008 | if (mTimerDraw != null) { |
| 9009 | mTimerDraw.detach(); |
| 9010 | mTimerDraw = null; |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 9011 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9012 | } |
| 9013 | return !wlactive; |
| 9014 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9015 | |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 9016 | void readFromParcelLocked(TimeBase timeBase, TimeBase screenOffTimeBase, |
| 9017 | TimeBase screenOffBgTimeBase, Parcel in) { |
| 9018 | mTimerPartial = readDualTimerFromParcel(WAKE_TYPE_PARTIAL, |
| 9019 | mBsi.mPartialTimers, screenOffTimeBase, screenOffBgTimeBase, in); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 9020 | mTimerFull = readStopwatchTimerFromParcel(WAKE_TYPE_FULL, |
| 9021 | mBsi.mFullTimers, timeBase, in); |
| 9022 | mTimerWindow = readStopwatchTimerFromParcel(WAKE_TYPE_WINDOW, |
| 9023 | mBsi.mWindowTimers, timeBase, in); |
| 9024 | mTimerDraw = readStopwatchTimerFromParcel(WAKE_TYPE_DRAW, |
| 9025 | mBsi.mDrawTimers, timeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9026 | } |
| 9027 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9028 | void writeToParcelLocked(Parcel out, long elapsedRealtimeUs) { |
| 9029 | Timer.writeTimerToParcel(out, mTimerPartial, elapsedRealtimeUs); |
| 9030 | Timer.writeTimerToParcel(out, mTimerFull, elapsedRealtimeUs); |
| 9031 | Timer.writeTimerToParcel(out, mTimerWindow, elapsedRealtimeUs); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 9032 | Timer.writeTimerToParcel(out, mTimerDraw, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9033 | } |
| 9034 | |
| 9035 | @Override |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 9036 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9037 | public Timer getWakeTime(int type) { |
| 9038 | switch (type) { |
| 9039 | case WAKE_TYPE_FULL: return mTimerFull; |
| 9040 | case WAKE_TYPE_PARTIAL: return mTimerPartial; |
| 9041 | case WAKE_TYPE_WINDOW: return mTimerWindow; |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 9042 | case WAKE_TYPE_DRAW: return mTimerDraw; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9043 | default: throw new IllegalArgumentException("type = " + type); |
| 9044 | } |
| 9045 | } |
| 9046 | } |
| 9047 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9048 | public static class Sensor extends BatteryStats.Uid.Sensor { |
| 9049 | /** |
| 9050 | * BatteryStatsImpl that we are associated with. |
| 9051 | */ |
| 9052 | protected BatteryStatsImpl mBsi; |
| 9053 | |
| 9054 | /** |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 9055 | * Uid that we are associated with. |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9056 | */ |
| 9057 | protected Uid mUid; |
| 9058 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9059 | final int mHandle; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 9060 | DualTimer mTimer; |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 9061 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9062 | public Sensor(BatteryStatsImpl bsi, Uid uid, int handle) { |
| 9063 | mBsi = bsi; |
| 9064 | mUid = uid; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9065 | mHandle = handle; |
| 9066 | } |
| 9067 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 9068 | private DualTimer readTimersFromParcel( |
| 9069 | TimeBase timeBase, TimeBase bgTimeBase, Parcel in) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9070 | if (in.readInt() == 0) { |
| 9071 | return null; |
| 9072 | } |
| 9073 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9074 | ArrayList<StopwatchTimer> pool = mBsi.mSensorTimers.get(mHandle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9075 | if (pool == null) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 9076 | pool = new ArrayList<StopwatchTimer>(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9077 | mBsi.mSensorTimers.put(mHandle, pool); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9078 | } |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 9079 | return new DualTimer(mBsi.mClocks, mUid, 0, pool, timeBase, bgTimeBase, in); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 9080 | } |
| 9081 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9082 | boolean reset() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9083 | if (mTimer.reset(true)) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9084 | mTimer = null; |
| 9085 | return true; |
| 9086 | } |
| 9087 | return false; |
| 9088 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9089 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 9090 | void readFromParcelLocked(TimeBase timeBase, TimeBase bgTimeBase, Parcel in) { |
| 9091 | mTimer = readTimersFromParcel(timeBase, bgTimeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9092 | } |
| 9093 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9094 | void writeToParcelLocked(Parcel out, long elapsedRealtimeUs) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 9095 | Timer.writeTimerToParcel(out, mTimer, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9096 | } |
| 9097 | |
| 9098 | @Override |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 9099 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9100 | public Timer getSensorTime() { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 9101 | return mTimer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9102 | } |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 9103 | |
| 9104 | @Override |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 9105 | public Timer getSensorBackgroundTime() { |
| 9106 | if (mTimer == null) { |
| 9107 | return null; |
| 9108 | } |
| 9109 | return mTimer.getSubTimer(); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 9110 | } |
| 9111 | |
| 9112 | @Override |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 9113 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9114 | public int getHandle() { |
| 9115 | return mHandle; |
| 9116 | } |
| 9117 | } |
| 9118 | |
| 9119 | /** |
| 9120 | * The statistics associated with a particular process. |
| 9121 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9122 | public static class Proc extends BatteryStats.Uid.Proc implements TimeBaseObs { |
| 9123 | /** |
| 9124 | * BatteryStatsImpl that we are associated with. |
| 9125 | */ |
| 9126 | protected BatteryStatsImpl mBsi; |
| 9127 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9128 | /** |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 9129 | * The name of this process. |
| 9130 | */ |
| 9131 | final String mName; |
| 9132 | |
| 9133 | /** |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 9134 | * Remains true until removed from the stats. |
| 9135 | */ |
| 9136 | boolean mActive = true; |
| 9137 | |
| 9138 | /** |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 9139 | * Total time (in ms) spent executing in user code. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9140 | */ |
| 9141 | long mUserTime; |
| 9142 | |
| 9143 | /** |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 9144 | * Total time (in ms) spent executing in kernel code. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9145 | */ |
| 9146 | long mSystemTime; |
| 9147 | |
| 9148 | /** |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 9149 | * Amount of time (in ms) the process was running in the foreground. |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 9150 | */ |
| 9151 | long mForegroundTime; |
| 9152 | |
| 9153 | /** |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 9154 | * Number of times the process has been started. |
| 9155 | */ |
| 9156 | int mStarts; |
| 9157 | |
| 9158 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9159 | * Number of times the process has crashed. |
| 9160 | */ |
| 9161 | int mNumCrashes; |
| 9162 | |
| 9163 | /** |
| 9164 | * Number of times the process has had an ANR. |
| 9165 | */ |
| 9166 | int mNumAnrs; |
| 9167 | |
| 9168 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9169 | * The amount of user time loaded from a previous save. |
| 9170 | */ |
| 9171 | long mLoadedUserTime; |
| 9172 | |
| 9173 | /** |
| 9174 | * The amount of system time loaded from a previous save. |
| 9175 | */ |
| 9176 | long mLoadedSystemTime; |
| 9177 | |
| 9178 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 9179 | * The amount of foreground time loaded from a previous save. |
| 9180 | */ |
| 9181 | long mLoadedForegroundTime; |
| 9182 | |
| 9183 | /** |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 9184 | * The number of times the process has started from a previous save. |
| 9185 | */ |
| 9186 | int mLoadedStarts; |
| 9187 | |
| 9188 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9189 | * 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] | 9190 | */ |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9191 | int mLoadedNumCrashes; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9192 | |
| 9193 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9194 | * 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] | 9195 | */ |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9196 | int mLoadedNumAnrs; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 9197 | |
| 9198 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9199 | * The amount of user time when last unplugged. |
| 9200 | */ |
| 9201 | long mUnpluggedUserTime; |
| 9202 | |
| 9203 | /** |
| 9204 | * The amount of system time when last unplugged. |
| 9205 | */ |
| 9206 | long mUnpluggedSystemTime; |
| 9207 | |
| 9208 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 9209 | * The amount of foreground time since unplugged. |
| 9210 | */ |
| 9211 | long mUnpluggedForegroundTime; |
| 9212 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 9213 | /** |
| 9214 | * The number of times the process has started before unplugged. |
| 9215 | */ |
| 9216 | int mUnpluggedStarts; |
| 9217 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 9218 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9219 | * Number of times the process has crashed before unplugged. |
| 9220 | */ |
| 9221 | int mUnpluggedNumCrashes; |
| 9222 | |
| 9223 | /** |
| 9224 | * Number of times the process has had an ANR before unplugged. |
| 9225 | */ |
| 9226 | int mUnpluggedNumAnrs; |
| 9227 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 9228 | ArrayList<ExcessivePower> mExcessivePower; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 9229 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9230 | public Proc(BatteryStatsImpl bsi, String name) { |
| 9231 | mBsi = bsi; |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 9232 | mName = name; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9233 | mBsi.mOnBatteryTimeBase.add(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9234 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 9235 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9236 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9237 | mUnpluggedUserTime = mUserTime; |
| 9238 | mUnpluggedSystemTime = mSystemTime; |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 9239 | mUnpluggedForegroundTime = mForegroundTime; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 9240 | mUnpluggedStarts = mStarts; |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9241 | mUnpluggedNumCrashes = mNumCrashes; |
| 9242 | mUnpluggedNumAnrs = mNumAnrs; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9243 | } |
| 9244 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9245 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9246 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9247 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9248 | void detach() { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 9249 | mActive = false; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9250 | mBsi.mOnBatteryTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9251 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9252 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 9253 | public int countExcessivePowers() { |
| 9254 | return mExcessivePower != null ? mExcessivePower.size() : 0; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 9255 | } |
| 9256 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 9257 | public ExcessivePower getExcessivePower(int i) { |
| 9258 | if (mExcessivePower != null) { |
| 9259 | return mExcessivePower.get(i); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 9260 | } |
| 9261 | return null; |
| 9262 | } |
| 9263 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 9264 | public void addExcessiveCpu(long overTime, long usedTime) { |
| 9265 | if (mExcessivePower == null) { |
| 9266 | mExcessivePower = new ArrayList<ExcessivePower>(); |
| 9267 | } |
| 9268 | ExcessivePower ew = new ExcessivePower(); |
| 9269 | ew.type = ExcessivePower.TYPE_CPU; |
| 9270 | ew.overTime = overTime; |
| 9271 | ew.usedTime = usedTime; |
| 9272 | mExcessivePower.add(ew); |
| 9273 | } |
| 9274 | |
| 9275 | void writeExcessivePowerToParcelLocked(Parcel out) { |
| 9276 | if (mExcessivePower == null) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 9277 | out.writeInt(0); |
| 9278 | return; |
| 9279 | } |
| 9280 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 9281 | final int N = mExcessivePower.size(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 9282 | out.writeInt(N); |
| 9283 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 9284 | ExcessivePower ew = mExcessivePower.get(i); |
| 9285 | out.writeInt(ew.type); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 9286 | out.writeLong(ew.overTime); |
| 9287 | out.writeLong(ew.usedTime); |
| 9288 | } |
| 9289 | } |
| 9290 | |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 9291 | void readExcessivePowerFromParcelLocked(Parcel in) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 9292 | final int N = in.readInt(); |
| 9293 | if (N == 0) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 9294 | mExcessivePower = null; |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 9295 | return; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 9296 | } |
| 9297 | |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 9298 | if (N > 10000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 9299 | throw new ParcelFormatException( |
| 9300 | "File corrupt: too many excessive power entries " + N); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 9301 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9302 | |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 9303 | mExcessivePower = new ArrayList<>(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 9304 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 9305 | ExcessivePower ew = new ExcessivePower(); |
| 9306 | ew.type = in.readInt(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 9307 | ew.overTime = in.readLong(); |
| 9308 | ew.usedTime = in.readLong(); |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 9309 | mExcessivePower.add(ew); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 9310 | } |
| 9311 | } |
| 9312 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9313 | void writeToParcelLocked(Parcel out) { |
| 9314 | out.writeLong(mUserTime); |
| 9315 | out.writeLong(mSystemTime); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 9316 | out.writeLong(mForegroundTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9317 | out.writeInt(mStarts); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9318 | out.writeInt(mNumCrashes); |
| 9319 | out.writeInt(mNumAnrs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9320 | out.writeLong(mLoadedUserTime); |
| 9321 | out.writeLong(mLoadedSystemTime); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 9322 | out.writeLong(mLoadedForegroundTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9323 | out.writeInt(mLoadedStarts); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9324 | out.writeInt(mLoadedNumCrashes); |
| 9325 | out.writeInt(mLoadedNumAnrs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9326 | out.writeLong(mUnpluggedUserTime); |
| 9327 | out.writeLong(mUnpluggedSystemTime); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 9328 | out.writeLong(mUnpluggedForegroundTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9329 | out.writeInt(mUnpluggedStarts); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9330 | out.writeInt(mUnpluggedNumCrashes); |
| 9331 | out.writeInt(mUnpluggedNumAnrs); |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 9332 | writeExcessivePowerToParcelLocked(out); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9333 | } |
| 9334 | |
| 9335 | void readFromParcelLocked(Parcel in) { |
| 9336 | mUserTime = in.readLong(); |
| 9337 | mSystemTime = in.readLong(); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 9338 | mForegroundTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9339 | mStarts = in.readInt(); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9340 | mNumCrashes = in.readInt(); |
| 9341 | mNumAnrs = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9342 | mLoadedUserTime = in.readLong(); |
| 9343 | mLoadedSystemTime = in.readLong(); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 9344 | mLoadedForegroundTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9345 | mLoadedStarts = in.readInt(); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9346 | mLoadedNumCrashes = in.readInt(); |
| 9347 | mLoadedNumAnrs = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9348 | mUnpluggedUserTime = in.readLong(); |
| 9349 | mUnpluggedSystemTime = in.readLong(); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 9350 | mUnpluggedForegroundTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9351 | mUnpluggedStarts = in.readInt(); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9352 | mUnpluggedNumCrashes = in.readInt(); |
| 9353 | mUnpluggedNumAnrs = in.readInt(); |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 9354 | readExcessivePowerFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9355 | } |
| 9356 | |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 9357 | @UnsupportedAppUsage |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 9358 | public void addCpuTimeLocked(int utime, int stime) { |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 9359 | addCpuTimeLocked(utime, stime, mBsi.mOnBatteryTimeBase.isRunning()); |
| 9360 | } |
| 9361 | |
| 9362 | public void addCpuTimeLocked(int utime, int stime, boolean isRunning) { |
| 9363 | if (isRunning) { |
| 9364 | mUserTime += utime; |
| 9365 | mSystemTime += stime; |
| 9366 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9367 | } |
| 9368 | |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 9369 | @UnsupportedAppUsage |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 9370 | public void addForegroundTimeLocked(long ttime) { |
| 9371 | mForegroundTime += ttime; |
| 9372 | } |
| 9373 | |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 9374 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9375 | public void incStartsLocked() { |
| 9376 | mStarts++; |
| 9377 | } |
| 9378 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9379 | public void incNumCrashesLocked() { |
| 9380 | mNumCrashes++; |
| 9381 | } |
| 9382 | |
| 9383 | public void incNumAnrsLocked() { |
| 9384 | mNumAnrs++; |
| 9385 | } |
| 9386 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9387 | @Override |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 9388 | public boolean isActive() { |
| 9389 | return mActive; |
| 9390 | } |
| 9391 | |
| 9392 | @Override |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 9393 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9394 | public long getUserTime(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 9395 | long val = mUserTime; |
| 9396 | if (which == STATS_CURRENT) { |
| 9397 | val -= mLoadedUserTime; |
| 9398 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 9399 | val -= mUnpluggedUserTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9400 | } |
| 9401 | return val; |
| 9402 | } |
| 9403 | |
| 9404 | @Override |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 9405 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9406 | public long getSystemTime(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 9407 | long val = mSystemTime; |
| 9408 | if (which == STATS_CURRENT) { |
| 9409 | val -= mLoadedSystemTime; |
| 9410 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 9411 | val -= mUnpluggedSystemTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9412 | } |
| 9413 | return val; |
| 9414 | } |
| 9415 | |
| 9416 | @Override |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 9417 | @UnsupportedAppUsage |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 9418 | public long getForegroundTime(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 9419 | long val = mForegroundTime; |
| 9420 | if (which == STATS_CURRENT) { |
| 9421 | val -= mLoadedForegroundTime; |
| 9422 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 9423 | val -= mUnpluggedForegroundTime; |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 9424 | } |
| 9425 | return val; |
| 9426 | } |
| 9427 | |
| 9428 | @Override |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 9429 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9430 | public int getStarts(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 9431 | int val = mStarts; |
| 9432 | if (which == STATS_CURRENT) { |
| 9433 | val -= mLoadedStarts; |
| 9434 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 9435 | val -= mUnpluggedStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9436 | } |
| 9437 | return val; |
| 9438 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 9439 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9440 | @Override |
| 9441 | public int getNumCrashes(int which) { |
| 9442 | int val = mNumCrashes; |
| 9443 | if (which == STATS_CURRENT) { |
| 9444 | val -= mLoadedNumCrashes; |
| 9445 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 9446 | val -= mUnpluggedNumCrashes; |
| 9447 | } |
| 9448 | return val; |
| 9449 | } |
| 9450 | |
| 9451 | @Override |
| 9452 | public int getNumAnrs(int which) { |
| 9453 | int val = mNumAnrs; |
| 9454 | if (which == STATS_CURRENT) { |
| 9455 | val -= mLoadedNumAnrs; |
| 9456 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 9457 | val -= mUnpluggedNumAnrs; |
| 9458 | } |
| 9459 | return val; |
| 9460 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9461 | } |
| 9462 | |
| 9463 | /** |
| 9464 | * The statistics associated with a particular package. |
| 9465 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9466 | public static class Pkg extends BatteryStats.Uid.Pkg implements TimeBaseObs { |
| 9467 | /** |
| 9468 | * BatteryStatsImpl that we are associated with. |
| 9469 | */ |
| 9470 | protected BatteryStatsImpl mBsi; |
| 9471 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9472 | /** |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 9473 | * Number of times wakeup alarms have occurred for this app. |
Bookatz | 98d4d5c | 2017-08-01 19:07:54 -0700 | [diff] [blame] | 9474 | * On screen-off timebase starting in report v25. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9475 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 9476 | ArrayMap<String, Counter> mWakeupAlarms = new ArrayMap<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9477 | |
| 9478 | /** |
| 9479 | * The statics we have collected for this package's services. |
| 9480 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 9481 | final ArrayMap<String, Serv> mServiceStats = new ArrayMap<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9482 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9483 | public Pkg(BatteryStatsImpl bsi) { |
| 9484 | mBsi = bsi; |
| 9485 | mBsi.mOnBatteryScreenOffTimeBase.add(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9486 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9487 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9488 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9489 | } |
| 9490 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9491 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9492 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9493 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9494 | void detach() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9495 | mBsi.mOnBatteryScreenOffTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9496 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9497 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9498 | void readFromParcelLocked(Parcel in) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 9499 | int numWA = in.readInt(); |
| 9500 | mWakeupAlarms.clear(); |
| 9501 | for (int i=0; i<numWA; i++) { |
| 9502 | String tag = in.readString(); |
Bookatz | 98d4d5c | 2017-08-01 19:07:54 -0700 | [diff] [blame] | 9503 | mWakeupAlarms.put(tag, new Counter(mBsi.mOnBatteryScreenOffTimeBase, in)); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 9504 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9505 | |
| 9506 | int numServs = in.readInt(); |
| 9507 | mServiceStats.clear(); |
| 9508 | for (int m = 0; m < numServs; m++) { |
| 9509 | String serviceName = in.readString(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9510 | Uid.Pkg.Serv serv = new Serv(mBsi); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9511 | mServiceStats.put(serviceName, serv); |
| 9512 | |
| 9513 | serv.readFromParcelLocked(in); |
| 9514 | } |
| 9515 | } |
| 9516 | |
| 9517 | void writeToParcelLocked(Parcel out) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 9518 | int numWA = mWakeupAlarms.size(); |
| 9519 | out.writeInt(numWA); |
| 9520 | for (int i=0; i<numWA; i++) { |
| 9521 | out.writeString(mWakeupAlarms.keyAt(i)); |
| 9522 | mWakeupAlarms.valueAt(i).writeToParcel(out); |
| 9523 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9524 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 9525 | final int NS = mServiceStats.size(); |
| 9526 | out.writeInt(NS); |
| 9527 | for (int i=0; i<NS; i++) { |
| 9528 | out.writeString(mServiceStats.keyAt(i)); |
| 9529 | Uid.Pkg.Serv serv = mServiceStats.valueAt(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9530 | serv.writeToParcelLocked(out); |
| 9531 | } |
| 9532 | } |
| 9533 | |
| 9534 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 9535 | public ArrayMap<String, ? extends BatteryStats.Counter> getWakeupAlarmStats() { |
| 9536 | return mWakeupAlarms; |
| 9537 | } |
| 9538 | |
| 9539 | public void noteWakeupAlarmLocked(String tag) { |
| 9540 | Counter c = mWakeupAlarms.get(tag); |
| 9541 | if (c == null) { |
Bookatz | 98d4d5c | 2017-08-01 19:07:54 -0700 | [diff] [blame] | 9542 | c = new Counter(mBsi.mOnBatteryScreenOffTimeBase); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 9543 | mWakeupAlarms.put(tag, c); |
| 9544 | } |
| 9545 | c.stepAtomic(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9546 | } |
| 9547 | |
| 9548 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 9549 | public ArrayMap<String, ? extends BatteryStats.Uid.Pkg.Serv> getServiceStats() { |
| 9550 | return mServiceStats; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9551 | } |
| 9552 | |
| 9553 | /** |
| 9554 | * The statistics associated with a particular service. |
| 9555 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9556 | public static class Serv extends BatteryStats.Uid.Pkg.Serv implements TimeBaseObs { |
| 9557 | /** |
| 9558 | * BatteryStatsImpl that we are associated with. |
| 9559 | */ |
| 9560 | protected BatteryStatsImpl mBsi; |
| 9561 | |
| 9562 | /** |
| 9563 | * The android package in which this service resides. |
| 9564 | */ |
| 9565 | protected Pkg mPkg; |
| 9566 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9567 | /** |
| 9568 | * Total time (ms in battery uptime) the service has been left started. |
| 9569 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9570 | protected long mStartTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9571 | |
| 9572 | /** |
| 9573 | * If service has been started and not yet stopped, this is |
| 9574 | * when it was started. |
| 9575 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9576 | protected long mRunningSince; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9577 | |
| 9578 | /** |
| 9579 | * True if we are currently running. |
| 9580 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9581 | protected boolean mRunning; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9582 | |
| 9583 | /** |
| 9584 | * Total number of times startService() has been called. |
| 9585 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9586 | protected int mStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9587 | |
| 9588 | /** |
| 9589 | * Total time (ms in battery uptime) the service has been left launched. |
| 9590 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9591 | protected long mLaunchedTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9592 | |
| 9593 | /** |
| 9594 | * If service has been launched and not yet exited, this is |
| 9595 | * when it was launched (ms in battery uptime). |
| 9596 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9597 | protected long mLaunchedSince; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9598 | |
| 9599 | /** |
| 9600 | * True if we are currently launched. |
| 9601 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9602 | protected boolean mLaunched; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9603 | |
| 9604 | /** |
| 9605 | * Total number times the service has been launched. |
| 9606 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9607 | protected int mLaunches; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9608 | |
| 9609 | /** |
| 9610 | * The amount of time spent started loaded from a previous save |
| 9611 | * (ms in battery uptime). |
| 9612 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9613 | protected long mLoadedStartTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9614 | |
| 9615 | /** |
| 9616 | * The number of starts loaded from a previous save. |
| 9617 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9618 | protected int mLoadedStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9619 | |
| 9620 | /** |
| 9621 | * The number of launches loaded from a previous save. |
| 9622 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9623 | protected int mLoadedLaunches; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9624 | |
| 9625 | /** |
| 9626 | * The amount of time spent started as of the last run (ms |
| 9627 | * in battery uptime). |
| 9628 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9629 | protected long mLastStartTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9630 | |
| 9631 | /** |
| 9632 | * The number of starts as of the last run. |
| 9633 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9634 | protected int mLastStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9635 | |
| 9636 | /** |
| 9637 | * The number of launches as of the last run. |
| 9638 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9639 | protected int mLastLaunches; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9640 | |
| 9641 | /** |
| 9642 | * The amount of time spent started when last unplugged (ms |
| 9643 | * in battery uptime). |
| 9644 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9645 | protected long mUnpluggedStartTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9646 | |
| 9647 | /** |
| 9648 | * The number of starts when last unplugged. |
| 9649 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9650 | protected int mUnpluggedStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9651 | |
| 9652 | /** |
| 9653 | * The number of launches when last unplugged. |
| 9654 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9655 | protected int mUnpluggedLaunches; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9656 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9657 | /** |
| 9658 | * Construct a Serv. Also adds it to the on-battery time base as a listener. |
| 9659 | */ |
| 9660 | public Serv(BatteryStatsImpl bsi) { |
| 9661 | mBsi = bsi; |
| 9662 | mBsi.mOnBatteryTimeBase.add(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9663 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9664 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9665 | public void onTimeStarted(long elapsedRealtime, long baseUptime, |
| 9666 | long baseRealtime) { |
| 9667 | mUnpluggedStartTime = getStartTimeToNowLocked(baseUptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9668 | mUnpluggedStarts = mStarts; |
| 9669 | mUnpluggedLaunches = mLaunches; |
| 9670 | } |
| 9671 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9672 | public void onTimeStopped(long elapsedRealtime, long baseUptime, |
| 9673 | long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9674 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9675 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9676 | /** |
| 9677 | * Remove this Serv as a listener from the time base. |
| 9678 | */ |
| 9679 | public void detach() { |
| 9680 | mBsi.mOnBatteryTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9681 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9682 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9683 | public void readFromParcelLocked(Parcel in) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9684 | mStartTime = in.readLong(); |
| 9685 | mRunningSince = in.readLong(); |
| 9686 | mRunning = in.readInt() != 0; |
| 9687 | mStarts = in.readInt(); |
| 9688 | mLaunchedTime = in.readLong(); |
| 9689 | mLaunchedSince = in.readLong(); |
| 9690 | mLaunched = in.readInt() != 0; |
| 9691 | mLaunches = in.readInt(); |
| 9692 | mLoadedStartTime = in.readLong(); |
| 9693 | mLoadedStarts = in.readInt(); |
| 9694 | mLoadedLaunches = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 9695 | mLastStartTime = 0; |
| 9696 | mLastStarts = 0; |
| 9697 | mLastLaunches = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9698 | mUnpluggedStartTime = in.readLong(); |
| 9699 | mUnpluggedStarts = in.readInt(); |
| 9700 | mUnpluggedLaunches = in.readInt(); |
| 9701 | } |
| 9702 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9703 | public void writeToParcelLocked(Parcel out) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9704 | out.writeLong(mStartTime); |
| 9705 | out.writeLong(mRunningSince); |
| 9706 | out.writeInt(mRunning ? 1 : 0); |
| 9707 | out.writeInt(mStarts); |
| 9708 | out.writeLong(mLaunchedTime); |
| 9709 | out.writeLong(mLaunchedSince); |
| 9710 | out.writeInt(mLaunched ? 1 : 0); |
| 9711 | out.writeInt(mLaunches); |
| 9712 | out.writeLong(mLoadedStartTime); |
| 9713 | out.writeInt(mLoadedStarts); |
| 9714 | out.writeInt(mLoadedLaunches); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9715 | out.writeLong(mUnpluggedStartTime); |
| 9716 | out.writeInt(mUnpluggedStarts); |
| 9717 | out.writeInt(mUnpluggedLaunches); |
| 9718 | } |
| 9719 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9720 | public long getLaunchTimeToNowLocked(long batteryUptime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9721 | if (!mLaunched) return mLaunchedTime; |
| 9722 | return mLaunchedTime + batteryUptime - mLaunchedSince; |
| 9723 | } |
| 9724 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9725 | public long getStartTimeToNowLocked(long batteryUptime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9726 | if (!mRunning) return mStartTime; |
| 9727 | return mStartTime + batteryUptime - mRunningSince; |
| 9728 | } |
| 9729 | |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 9730 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9731 | public void startLaunchedLocked() { |
| 9732 | if (!mLaunched) { |
| 9733 | mLaunches++; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9734 | mLaunchedSince = mBsi.getBatteryUptimeLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9735 | mLaunched = true; |
| 9736 | } |
| 9737 | } |
| 9738 | |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 9739 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9740 | public void stopLaunchedLocked() { |
| 9741 | if (mLaunched) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9742 | long time = mBsi.getBatteryUptimeLocked() - mLaunchedSince; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9743 | if (time > 0) { |
| 9744 | mLaunchedTime += time; |
| 9745 | } else { |
| 9746 | mLaunches--; |
| 9747 | } |
| 9748 | mLaunched = false; |
| 9749 | } |
| 9750 | } |
| 9751 | |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 9752 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9753 | public void startRunningLocked() { |
| 9754 | if (!mRunning) { |
| 9755 | mStarts++; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9756 | mRunningSince = mBsi.getBatteryUptimeLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9757 | mRunning = true; |
| 9758 | } |
| 9759 | } |
| 9760 | |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 9761 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9762 | public void stopRunningLocked() { |
| 9763 | if (mRunning) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9764 | long time = mBsi.getBatteryUptimeLocked() - mRunningSince; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9765 | if (time > 0) { |
| 9766 | mStartTime += time; |
| 9767 | } else { |
| 9768 | mStarts--; |
| 9769 | } |
| 9770 | mRunning = false; |
| 9771 | } |
| 9772 | } |
| 9773 | |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 9774 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9775 | public BatteryStatsImpl getBatteryStats() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9776 | return mBsi; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9777 | } |
| 9778 | |
| 9779 | @Override |
| 9780 | public int getLaunches(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 9781 | int val = mLaunches; |
| 9782 | if (which == STATS_CURRENT) { |
| 9783 | val -= mLoadedLaunches; |
| 9784 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 9785 | val -= mUnpluggedLaunches; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9786 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9787 | return val; |
| 9788 | } |
| 9789 | |
| 9790 | @Override |
| 9791 | public long getStartTime(long now, int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 9792 | long val = getStartTimeToNowLocked(now); |
| 9793 | if (which == STATS_CURRENT) { |
| 9794 | val -= mLoadedStartTime; |
| 9795 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 9796 | val -= mUnpluggedStartTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9797 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9798 | return val; |
| 9799 | } |
| 9800 | |
| 9801 | @Override |
| 9802 | public int getStarts(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 9803 | int val = mStarts; |
| 9804 | if (which == STATS_CURRENT) { |
| 9805 | val -= mLoadedStarts; |
| 9806 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 9807 | val -= mUnpluggedStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9808 | } |
| 9809 | |
| 9810 | return val; |
| 9811 | } |
| 9812 | } |
| 9813 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9814 | final Serv newServiceStatsLocked() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9815 | return new Serv(mBsi); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9816 | } |
| 9817 | } |
| 9818 | |
| 9819 | /** |
| 9820 | * Retrieve the statistics object for a particular process, creating |
| 9821 | * if needed. |
| 9822 | */ |
| 9823 | public Proc getProcessStatsLocked(String name) { |
| 9824 | Proc ps = mProcessStats.get(name); |
| 9825 | if (ps == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9826 | ps = new Proc(mBsi, name); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9827 | mProcessStats.put(name, ps); |
| 9828 | } |
| 9829 | |
| 9830 | return ps; |
| 9831 | } |
| 9832 | |
Andreas Gampe | 3f24e69 | 2018-02-05 13:24:28 -0800 | [diff] [blame] | 9833 | @GuardedBy("mBsi") |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 9834 | public void updateUidProcessStateLocked(int procState) { |
| 9835 | int uidRunningState; |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 9836 | // Make special note of Foreground Services |
| 9837 | final boolean userAwareService = |
| 9838 | (procState == ActivityManager.PROCESS_STATE_FOREGROUND_SERVICE); |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 9839 | uidRunningState = BatteryStats.mapToInternalProcessState(procState); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 9840 | |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 9841 | if (mProcessState == uidRunningState && userAwareService == mInForegroundService) { |
| 9842 | return; |
| 9843 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 9844 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 9845 | final long elapsedRealtimeMs = mBsi.mClocks.elapsedRealtime(); |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 9846 | if (mProcessState != uidRunningState) { |
| 9847 | final long uptimeMs = mBsi.mClocks.uptimeMillis(); |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 9848 | |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 9849 | if (mProcessState != ActivityManager.PROCESS_STATE_NONEXISTENT) { |
| 9850 | mProcessStateTimer[mProcessState].stopRunningLocked(elapsedRealtimeMs); |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 9851 | |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 9852 | if (mBsi.trackPerProcStateCpuTimes()) { |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 9853 | if (mBsi.mPendingUids.size() == 0) { |
Sudheer Shanka | e544d16 | 2017-12-28 17:06:20 -0800 | [diff] [blame] | 9854 | mBsi.mExternalSync.scheduleReadProcStateCpuTimes( |
| 9855 | mBsi.mOnBatteryTimeBase.isRunning(), |
Sudheer Shanka | c20379e | 2018-02-15 00:06:21 -0800 | [diff] [blame] | 9856 | mBsi.mOnBatteryScreenOffTimeBase.isRunning(), |
| 9857 | mBsi.mConstants.PROC_STATE_CPU_TIMES_READ_DELAY_MS); |
Mike Ma | 234d182 | 2018-03-13 18:53:21 -0700 | [diff] [blame] | 9858 | mBsi.mNumSingleUidCpuTimeReads++; |
Sudheer Shanka | c20379e | 2018-02-15 00:06:21 -0800 | [diff] [blame] | 9859 | } else { |
Mike Ma | 234d182 | 2018-03-13 18:53:21 -0700 | [diff] [blame] | 9860 | mBsi.mNumBatchedSingleUidCpuTimeReads++; |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 9861 | } |
| 9862 | if (mBsi.mPendingUids.indexOfKey(mUid) < 0 |
| 9863 | || ArrayUtils.contains(CRITICAL_PROC_STATES, mProcessState)) { |
| 9864 | mBsi.mPendingUids.put(mUid, mProcessState); |
| 9865 | } |
| 9866 | } else { |
| 9867 | mBsi.mPendingUids.clear(); |
| 9868 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 9869 | } |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 9870 | mProcessState = uidRunningState; |
| 9871 | if (uidRunningState != ActivityManager.PROCESS_STATE_NONEXISTENT) { |
| 9872 | if (mProcessStateTimer[uidRunningState] == null) { |
| 9873 | makeProcessState(uidRunningState, null); |
| 9874 | } |
| 9875 | mProcessStateTimer[uidRunningState].startRunningLocked(elapsedRealtimeMs); |
| 9876 | } |
| 9877 | |
| 9878 | updateOnBatteryBgTimeBase(uptimeMs * 1000, elapsedRealtimeMs * 1000); |
| 9879 | updateOnBatteryScreenOffBgTimeBase(uptimeMs * 1000, elapsedRealtimeMs * 1000); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 9880 | } |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 9881 | |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 9882 | if (userAwareService != mInForegroundService) { |
| 9883 | if (userAwareService) { |
| 9884 | noteForegroundServiceResumedLocked(elapsedRealtimeMs); |
| 9885 | } else { |
| 9886 | noteForegroundServicePausedLocked(elapsedRealtimeMs); |
| 9887 | } |
| 9888 | mInForegroundService = userAwareService; |
| 9889 | } |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 9890 | } |
| 9891 | |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 9892 | /** Whether to consider Uid to be in the background for background timebase purposes. */ |
| 9893 | public boolean isInBackground() { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 9894 | // Note that PROCESS_STATE_CACHED and ActivityManager.PROCESS_STATE_NONEXISTENT is |
| 9895 | // also considered to be 'background' for our purposes, because it's not foreground. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 9896 | return mProcessState >= PROCESS_STATE_BACKGROUND; |
| 9897 | } |
| 9898 | |
| 9899 | public boolean updateOnBatteryBgTimeBase(long uptimeUs, long realtimeUs) { |
| 9900 | boolean on = mBsi.mOnBatteryTimeBase.isRunning() && isInBackground(); |
| 9901 | return mOnBatteryBackgroundTimeBase.setRunning(on, uptimeUs, realtimeUs); |
| 9902 | } |
| 9903 | |
| 9904 | public boolean updateOnBatteryScreenOffBgTimeBase(long uptimeUs, long realtimeUs) { |
| 9905 | boolean on = mBsi.mOnBatteryScreenOffTimeBase.isRunning() && isInBackground(); |
| 9906 | return mOnBatteryScreenOffBackgroundTimeBase.setRunning(on, uptimeUs, realtimeUs); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 9907 | } |
| 9908 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 9909 | public SparseArray<? extends Pid> getPidStats() { |
| 9910 | return mPids; |
| 9911 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9912 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 9913 | public Pid getPidStatsLocked(int pid) { |
| 9914 | Pid p = mPids.get(pid); |
| 9915 | if (p == null) { |
| 9916 | p = new Pid(); |
| 9917 | mPids.put(pid, p); |
| 9918 | } |
| 9919 | return p; |
| 9920 | } |
| 9921 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9922 | /** |
| 9923 | * Retrieve the statistics object for a particular service, creating |
| 9924 | * if needed. |
| 9925 | */ |
| 9926 | public Pkg getPackageStatsLocked(String name) { |
| 9927 | Pkg ps = mPackageStats.get(name); |
| 9928 | if (ps == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9929 | ps = new Pkg(mBsi); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9930 | mPackageStats.put(name, ps); |
| 9931 | } |
| 9932 | |
| 9933 | return ps; |
| 9934 | } |
| 9935 | |
| 9936 | /** |
| 9937 | * Retrieve the statistics object for a particular service, creating |
| 9938 | * if needed. |
| 9939 | */ |
| 9940 | public Pkg.Serv getServiceStatsLocked(String pkg, String serv) { |
| 9941 | Pkg ps = getPackageStatsLocked(pkg); |
| 9942 | Pkg.Serv ss = ps.mServiceStats.get(serv); |
| 9943 | if (ss == null) { |
| 9944 | ss = ps.newServiceStatsLocked(); |
| 9945 | ps.mServiceStats.put(serv, ss); |
| 9946 | } |
| 9947 | |
| 9948 | return ss; |
| 9949 | } |
| 9950 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 9951 | public void readSyncSummaryFromParcelLocked(String name, Parcel in) { |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 9952 | DualTimer timer = mSyncStats.instantiateObject(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 9953 | timer.readSummaryFromParcelLocked(in); |
| 9954 | mSyncStats.add(name, timer); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 9955 | } |
| 9956 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 9957 | public void readJobSummaryFromParcelLocked(String name, Parcel in) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 9958 | DualTimer timer = mJobStats.instantiateObject(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 9959 | timer.readSummaryFromParcelLocked(in); |
| 9960 | mJobStats.add(name, timer); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 9961 | } |
| 9962 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 9963 | public void readWakeSummaryFromParcelLocked(String wlName, Parcel in) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9964 | Wakelock wl = new Wakelock(mBsi, this); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 9965 | mWakelockStats.add(wlName, wl); |
| 9966 | if (in.readInt() != 0) { |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 9967 | getWakelockTimerLocked(wl, WAKE_TYPE_FULL).readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9968 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 9969 | if (in.readInt() != 0) { |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 9970 | getWakelockTimerLocked(wl, WAKE_TYPE_PARTIAL).readSummaryFromParcelLocked(in); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 9971 | } |
| 9972 | if (in.readInt() != 0) { |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 9973 | getWakelockTimerLocked(wl, WAKE_TYPE_WINDOW).readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9974 | } |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 9975 | if (in.readInt() != 0) { |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 9976 | getWakelockTimerLocked(wl, WAKE_TYPE_DRAW).readSummaryFromParcelLocked(in); |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 9977 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9978 | } |
| 9979 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 9980 | public DualTimer getSensorTimerLocked(int sensor, boolean create) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9981 | Sensor se = mSensorStats.get(sensor); |
| 9982 | if (se == null) { |
| 9983 | if (!create) { |
| 9984 | return null; |
| 9985 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9986 | se = new Sensor(mBsi, this, sensor); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9987 | mSensorStats.put(sensor, se); |
| 9988 | } |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 9989 | DualTimer t = se.mTimer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9990 | if (t != null) { |
| 9991 | return t; |
| 9992 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9993 | ArrayList<StopwatchTimer> timers = mBsi.mSensorTimers.get(sensor); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9994 | if (timers == null) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 9995 | timers = new ArrayList<StopwatchTimer>(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9996 | mBsi.mSensorTimers.put(sensor, timers); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9997 | } |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 9998 | t = new DualTimer(mBsi.mClocks, this, BatteryStats.SENSOR, timers, |
| 9999 | mBsi.mOnBatteryTimeBase, mOnBatteryBackgroundTimeBase); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10000 | se.mTimer = t; |
| 10001 | return t; |
| 10002 | } |
| 10003 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 10004 | public void noteStartSyncLocked(String name, long elapsedRealtimeMs) { |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 10005 | DualTimer t = mSyncStats.startObject(name); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 10006 | if (t != null) { |
| 10007 | t.startRunningLocked(elapsedRealtimeMs); |
| 10008 | } |
| 10009 | } |
| 10010 | |
| 10011 | public void noteStopSyncLocked(String name, long elapsedRealtimeMs) { |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 10012 | DualTimer t = mSyncStats.stopObject(name); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 10013 | if (t != null) { |
| 10014 | t.stopRunningLocked(elapsedRealtimeMs); |
| 10015 | } |
| 10016 | } |
| 10017 | |
| 10018 | public void noteStartJobLocked(String name, long elapsedRealtimeMs) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 10019 | DualTimer t = mJobStats.startObject(name); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 10020 | if (t != null) { |
| 10021 | t.startRunningLocked(elapsedRealtimeMs); |
| 10022 | } |
| 10023 | } |
| 10024 | |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 10025 | public void noteStopJobLocked(String name, long elapsedRealtimeMs, int stopReason) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 10026 | DualTimer t = mJobStats.stopObject(name); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 10027 | if (t != null) { |
| 10028 | t.stopRunningLocked(elapsedRealtimeMs); |
| 10029 | } |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 10030 | if (mBsi.mOnBatteryTimeBase.isRunning()) { |
| 10031 | SparseIntArray types = mJobCompletions.get(name); |
| 10032 | if (types == null) { |
| 10033 | types = new SparseIntArray(); |
| 10034 | mJobCompletions.put(name, types); |
| 10035 | } |
| 10036 | int last = types.get(stopReason, 0); |
| 10037 | types.put(stopReason, last + 1); |
| 10038 | } |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 10039 | } |
| 10040 | |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 10041 | public StopwatchTimer getWakelockTimerLocked(Wakelock wl, int type) { |
| 10042 | if (wl == null) { |
| 10043 | return null; |
| 10044 | } |
| 10045 | switch (type) { |
| 10046 | case WAKE_TYPE_PARTIAL: { |
| 10047 | DualTimer t = wl.mTimerPartial; |
| 10048 | if (t == null) { |
| 10049 | t = new DualTimer(mBsi.mClocks, this, WAKE_TYPE_PARTIAL, |
| 10050 | mBsi.mPartialTimers, mBsi.mOnBatteryScreenOffTimeBase, |
| 10051 | mOnBatteryScreenOffBackgroundTimeBase); |
| 10052 | wl.mTimerPartial = t; |
| 10053 | } |
| 10054 | return t; |
| 10055 | } |
| 10056 | case WAKE_TYPE_FULL: { |
| 10057 | StopwatchTimer t = wl.mTimerFull; |
| 10058 | if (t == null) { |
| 10059 | t = new StopwatchTimer(mBsi.mClocks, this, WAKE_TYPE_FULL, |
| 10060 | mBsi.mFullTimers, mBsi.mOnBatteryTimeBase); |
| 10061 | wl.mTimerFull = t; |
| 10062 | } |
| 10063 | return t; |
| 10064 | } |
| 10065 | case WAKE_TYPE_WINDOW: { |
| 10066 | StopwatchTimer t = wl.mTimerWindow; |
| 10067 | if (t == null) { |
| 10068 | t = new StopwatchTimer(mBsi.mClocks, this, WAKE_TYPE_WINDOW, |
| 10069 | mBsi.mWindowTimers, mBsi.mOnBatteryTimeBase); |
| 10070 | wl.mTimerWindow = t; |
| 10071 | } |
| 10072 | return t; |
| 10073 | } |
| 10074 | case WAKE_TYPE_DRAW: { |
| 10075 | StopwatchTimer t = wl.mTimerDraw; |
| 10076 | if (t == null) { |
| 10077 | t = new StopwatchTimer(mBsi.mClocks, this, WAKE_TYPE_DRAW, |
| 10078 | mBsi.mDrawTimers, mBsi.mOnBatteryTimeBase); |
| 10079 | wl.mTimerDraw = t; |
| 10080 | } |
| 10081 | return t; |
| 10082 | } |
| 10083 | default: |
| 10084 | throw new IllegalArgumentException("type=" + type); |
| 10085 | } |
| 10086 | } |
| 10087 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10088 | public void noteStartWakeLocked(int pid, String name, int type, long elapsedRealtimeMs) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 10089 | Wakelock wl = mWakelockStats.startObject(name); |
| 10090 | if (wl != null) { |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 10091 | getWakelockTimerLocked(wl, type).startRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10092 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 10093 | if (type == WAKE_TYPE_PARTIAL) { |
| 10094 | createAggregatedPartialWakelockTimerLocked().startRunningLocked(elapsedRealtimeMs); |
| 10095 | if (pid >= 0) { |
| 10096 | Pid p = getPidStatsLocked(pid); |
| 10097 | if (p.mWakeNesting++ == 0) { |
| 10098 | p.mWakeStartMs = elapsedRealtimeMs; |
| 10099 | } |
Dianne Hackborn | b8071d79 | 2010-09-09 16:45:15 -0700 | [diff] [blame] | 10100 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 10101 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10102 | } |
| 10103 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10104 | public void noteStopWakeLocked(int pid, String name, int type, long elapsedRealtimeMs) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 10105 | Wakelock wl = mWakelockStats.stopObject(name); |
| 10106 | if (wl != null) { |
Bookatz | d674624 | 2017-10-24 18:39:35 -0700 | [diff] [blame] | 10107 | StopwatchTimer wlt = getWakelockTimerLocked(wl, type); |
| 10108 | wlt.stopRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10109 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 10110 | if (type == WAKE_TYPE_PARTIAL) { |
| 10111 | if (mAggregatedPartialWakelockTimer != null) { |
| 10112 | mAggregatedPartialWakelockTimer.stopRunningLocked(elapsedRealtimeMs); |
| 10113 | } |
| 10114 | if (pid >= 0) { |
| 10115 | Pid p = mPids.get(pid); |
| 10116 | if (p != null && p.mWakeNesting > 0) { |
| 10117 | if (p.mWakeNesting-- == 1) { |
| 10118 | p.mWakeSumMs += elapsedRealtimeMs - p.mWakeStartMs; |
| 10119 | p.mWakeStartMs = 0; |
| 10120 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 10121 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 10122 | } |
| 10123 | } |
| 10124 | } |
| 10125 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 10126 | public void reportExcessiveCpuLocked(String proc, long overTime, long usedTime) { |
| 10127 | Proc p = getProcessStatsLocked(proc); |
| 10128 | if (p != null) { |
| 10129 | p.addExcessiveCpu(overTime, usedTime); |
| 10130 | } |
| 10131 | } |
| 10132 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10133 | public void noteStartSensor(int sensor, long elapsedRealtimeMs) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 10134 | DualTimer t = getSensorTimerLocked(sensor, /* create= */ true); |
Amith Yamasani | 154d124 | 2017-02-16 10:01:48 -0800 | [diff] [blame] | 10135 | t.startRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10136 | } |
| 10137 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10138 | public void noteStopSensor(int sensor, long elapsedRealtimeMs) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10139 | // Don't create a timer if one doesn't already exist |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 10140 | DualTimer t = getSensorTimerLocked(sensor, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10141 | if (t != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10142 | t.stopRunningLocked(elapsedRealtimeMs); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10143 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10144 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10145 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10146 | public void noteStartGps(long elapsedRealtimeMs) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 10147 | noteStartSensor(Sensor.GPS, elapsedRealtimeMs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10148 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10149 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10150 | public void noteStopGps(long elapsedRealtimeMs) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 10151 | noteStopSensor(Sensor.GPS, elapsedRealtimeMs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10152 | } |
| 10153 | |
| 10154 | public BatteryStatsImpl getBatteryStats() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10155 | return mBsi; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10156 | } |
| 10157 | } |
| 10158 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 10159 | public long[] getCpuFreqs() { |
| 10160 | return mCpuFreqs; |
| 10161 | } |
| 10162 | |
Suprabh Shukla | e6e723d | 2017-06-14 16:14:43 -0700 | [diff] [blame] | 10163 | public BatteryStatsImpl(File systemDir, Handler handler, PlatformIdleStateCallback cb, |
| 10164 | UserInfoProvider userInfoProvider) { |
| 10165 | this(new SystemClocks(), systemDir, handler, cb, userInfoProvider); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 10166 | } |
| 10167 | |
Suprabh Shukla | e6e723d | 2017-06-14 16:14:43 -0700 | [diff] [blame] | 10168 | private BatteryStatsImpl(Clocks clocks, File systemDir, Handler handler, |
| 10169 | PlatformIdleStateCallback cb, |
| 10170 | UserInfoProvider userInfoProvider) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10171 | init(clocks); |
| 10172 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 10173 | if (systemDir != null) { |
| 10174 | mFile = new JournaledFile(new File(systemDir, "batterystats.bin"), |
| 10175 | new File(systemDir, "batterystats.bin.tmp")); |
| 10176 | } else { |
| 10177 | mFile = null; |
| 10178 | } |
| 10179 | mCheckinFile = new AtomicFile(new File(systemDir, "batterystats-checkin.bin")); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10180 | mDailyFile = new AtomicFile(new File(systemDir, "batterystats-daily.xml")); |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 10181 | mHandler = new MyHandler(handler.getLooper()); |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 10182 | mConstants = new Constants(mHandler); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10183 | mStartCount++; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10184 | mScreenOnTimer = new StopwatchTimer(mClocks, null, -1, null, mOnBatteryTimeBase); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 10185 | mScreenDozeTimer = new StopwatchTimer(mClocks, null, -1, null, mOnBatteryTimeBase); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 10186 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10187 | mScreenBrightnessTimer[i] = new StopwatchTimer(mClocks, null, -100-i, null, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10188 | mOnBatteryTimeBase); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 10189 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10190 | mInteractiveTimer = new StopwatchTimer(mClocks, null, -10, null, mOnBatteryTimeBase); |
| 10191 | mPowerSaveModeEnabledTimer = new StopwatchTimer(mClocks, null, -2, null, |
| 10192 | mOnBatteryTimeBase); |
| 10193 | mDeviceIdleModeLightTimer = new StopwatchTimer(mClocks, null, -11, null, |
| 10194 | mOnBatteryTimeBase); |
| 10195 | mDeviceIdleModeFullTimer = new StopwatchTimer(mClocks, null, -14, null, mOnBatteryTimeBase); |
| 10196 | mDeviceLightIdlingTimer = new StopwatchTimer(mClocks, null, -15, null, mOnBatteryTimeBase); |
| 10197 | mDeviceIdlingTimer = new StopwatchTimer(mClocks, null, -12, null, mOnBatteryTimeBase); |
| 10198 | mPhoneOnTimer = new StopwatchTimer(mClocks, null, -3, null, mOnBatteryTimeBase); |
| 10199 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
| 10200 | mPhoneSignalStrengthsTimer[i] = new StopwatchTimer(mClocks, null, -200-i, null, |
| 10201 | mOnBatteryTimeBase); |
| 10202 | } |
| 10203 | mPhoneSignalScanningTimer = new StopwatchTimer(mClocks, null, -200+1, null, |
| 10204 | mOnBatteryTimeBase); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 10205 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10206 | mPhoneDataConnectionsTimer[i] = new StopwatchTimer(mClocks, null, -300-i, null, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10207 | mOnBatteryTimeBase); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 10208 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 10209 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10210 | mNetworkByteActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase); |
| 10211 | mNetworkPacketActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 10212 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 10213 | mWifiActivity = new ControllerActivityCounterImpl(mOnBatteryTimeBase, NUM_WIFI_TX_LEVELS); |
| 10214 | mBluetoothActivity = new ControllerActivityCounterImpl(mOnBatteryTimeBase, |
| 10215 | NUM_BT_TX_LEVELS); |
| 10216 | mModemActivity = new ControllerActivityCounterImpl(mOnBatteryTimeBase, |
| 10217 | ModemActivityInfo.TX_POWER_LEVELS); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10218 | mMobileRadioActiveTimer = new StopwatchTimer(mClocks, null, -400, null, mOnBatteryTimeBase); |
| 10219 | mMobileRadioActivePerAppTimer = new StopwatchTimer(mClocks, null, -401, null, |
| 10220 | mOnBatteryTimeBase); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10221 | mMobileRadioActiveAdjustedTime = new LongSamplingCounter(mOnBatteryTimeBase); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10222 | mMobileRadioActiveUnknownTime = new LongSamplingCounter(mOnBatteryTimeBase); |
| 10223 | mMobileRadioActiveUnknownCount = new LongSamplingCounter(mOnBatteryTimeBase); |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 10224 | mWifiMulticastWakelockTimer = new StopwatchTimer(mClocks, null, |
| 10225 | WIFI_AGGREGATE_MULTICAST_ENABLED, null, mOnBatteryTimeBase); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10226 | mWifiOnTimer = new StopwatchTimer(mClocks, null, -4, null, mOnBatteryTimeBase); |
| 10227 | mGlobalWifiRunningTimer = new StopwatchTimer(mClocks, null, -5, null, mOnBatteryTimeBase); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 10228 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10229 | mWifiStateTimer[i] = new StopwatchTimer(mClocks, null, -600-i, null, |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 10230 | mOnBatteryTimeBase); |
| 10231 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10232 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 10233 | mWifiSupplStateTimer[i] = new StopwatchTimer(mClocks, null, -700-i, null, |
| 10234 | mOnBatteryTimeBase); |
| 10235 | } |
| 10236 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 10237 | mWifiSignalStrengthsTimer[i] = new StopwatchTimer(mClocks, null, -800-i, null, |
| 10238 | mOnBatteryTimeBase); |
| 10239 | } |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 10240 | mWifiActiveTimer = new StopwatchTimer(mClocks, null, -900, null, mOnBatteryTimeBase); |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 10241 | for (int i=0; i< GnssMetrics.NUM_GPS_SIGNAL_QUALITY_LEVELS; i++) { |
| 10242 | mGpsSignalQualityTimer[i] = new StopwatchTimer(mClocks, null, -1000-i, null, |
| 10243 | mOnBatteryTimeBase); |
| 10244 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10245 | mAudioOnTimer = new StopwatchTimer(mClocks, null, -7, null, mOnBatteryTimeBase); |
| 10246 | mVideoOnTimer = new StopwatchTimer(mClocks, null, -8, null, mOnBatteryTimeBase); |
| 10247 | mFlashlightOnTimer = new StopwatchTimer(mClocks, null, -9, null, mOnBatteryTimeBase); |
| 10248 | mCameraOnTimer = new StopwatchTimer(mClocks, null, -13, null, mOnBatteryTimeBase); |
| 10249 | mBluetoothScanTimer = new StopwatchTimer(mClocks, null, -14, null, mOnBatteryTimeBase); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 10250 | mDischargeScreenOffCounter = new LongSamplingCounter(mOnBatteryScreenOffTimeBase); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 10251 | mDischargeScreenDozeCounter = new LongSamplingCounter(mOnBatteryTimeBase); |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 10252 | mDischargeLightDozeCounter = new LongSamplingCounter(mOnBatteryTimeBase); |
| 10253 | mDischargeDeepDozeCounter = new LongSamplingCounter(mOnBatteryTimeBase); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 10254 | mDischargeCounter = new LongSamplingCounter(mOnBatteryTimeBase); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10255 | mOnBattery = mOnBatteryInternal = false; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10256 | long uptime = mClocks.uptimeMillis() * 1000; |
| 10257 | long realtime = mClocks.elapsedRealtime() * 1000; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10258 | initTimes(uptime, realtime); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 10259 | mStartPlatformVersion = mEndPlatformVersion = Build.ID; |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 10260 | mDischargeStartLevel = 0; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10261 | mDischargeUnplugLevel = 0; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 10262 | mDischargePlugLevel = -1; |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 10263 | mDischargeCurrentLevel = 0; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 10264 | mCurrentBatteryLevel = 0; |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 10265 | initDischarge(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10266 | clearHistoryLocked(); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10267 | updateDailyDeadlineLocked(); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 10268 | mPlatformIdleStateCallback = cb; |
Suprabh Shukla | e6e723d | 2017-06-14 16:14:43 -0700 | [diff] [blame] | 10269 | mUserInfoProvider = userInfoProvider; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10270 | } |
| 10271 | |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 10272 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10273 | public BatteryStatsImpl(Parcel p) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10274 | this(new SystemClocks(), p); |
| 10275 | } |
| 10276 | |
| 10277 | public BatteryStatsImpl(Clocks clocks, Parcel p) { |
| 10278 | init(clocks); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10279 | mFile = null; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 10280 | mCheckinFile = null; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10281 | mDailyFile = null; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 10282 | mHandler = null; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 10283 | mExternalSync = null; |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 10284 | mConstants = new Constants(mHandler); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10285 | clearHistoryLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10286 | readFromParcel(p); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 10287 | mPlatformIdleStateCallback = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10288 | } |
| 10289 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 10290 | public void setPowerProfileLocked(PowerProfile profile) { |
| 10291 | mPowerProfile = profile; |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 10292 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 10293 | // We need to initialize the KernelCpuSpeedReaders to read from |
| 10294 | // the first cpu of each core. Once we have the PowerProfile, we have access to this |
| 10295 | // information. |
| 10296 | final int numClusters = mPowerProfile.getNumCpuClusters(); |
| 10297 | mKernelCpuSpeedReaders = new KernelCpuSpeedReader[numClusters]; |
| 10298 | int firstCpuOfCluster = 0; |
| 10299 | for (int i = 0; i < numClusters; i++) { |
| 10300 | final int numSpeedSteps = mPowerProfile.getNumSpeedStepsInCpuCluster(i); |
| 10301 | mKernelCpuSpeedReaders[i] = new KernelCpuSpeedReader(firstCpuOfCluster, |
| 10302 | numSpeedSteps); |
| 10303 | firstCpuOfCluster += mPowerProfile.getNumCoresInCpuCluster(i); |
| 10304 | } |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 10305 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 10306 | if (mEstimatedBatteryCapacity == -1) { |
| 10307 | // Initialize the estimated battery capacity to a known preset one. |
| 10308 | mEstimatedBatteryCapacity = (int) mPowerProfile.getBatteryCapacity(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 10309 | } |
| 10310 | } |
| 10311 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 10312 | public void setCallback(BatteryCallback cb) { |
| 10313 | mCallback = cb; |
| 10314 | } |
| 10315 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 10316 | public void setRadioScanningTimeoutLocked(long timeout) { |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 10317 | if (mPhoneSignalScanningTimer != null) { |
| 10318 | mPhoneSignalScanningTimer.setTimeout(timeout); |
| 10319 | } |
| 10320 | } |
| 10321 | |
Adam Lesinski | b3a1bad | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 10322 | public void setExternalStatsSyncLocked(ExternalStatsSync sync) { |
| 10323 | mExternalSync = sync; |
| 10324 | } |
| 10325 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10326 | public void updateDailyDeadlineLocked() { |
| 10327 | // Get the current time. |
| 10328 | long currentTime = mDailyStartTime = System.currentTimeMillis(); |
| 10329 | Calendar calDeadline = Calendar.getInstance(); |
| 10330 | calDeadline.setTimeInMillis(currentTime); |
| 10331 | |
| 10332 | // Move time up to the next day, ranging from 1am to 3pm. |
| 10333 | calDeadline.set(Calendar.DAY_OF_YEAR, calDeadline.get(Calendar.DAY_OF_YEAR) + 1); |
| 10334 | calDeadline.set(Calendar.MILLISECOND, 0); |
| 10335 | calDeadline.set(Calendar.SECOND, 0); |
| 10336 | calDeadline.set(Calendar.MINUTE, 0); |
| 10337 | calDeadline.set(Calendar.HOUR_OF_DAY, 1); |
| 10338 | mNextMinDailyDeadline = calDeadline.getTimeInMillis(); |
| 10339 | calDeadline.set(Calendar.HOUR_OF_DAY, 3); |
| 10340 | mNextMaxDailyDeadline = calDeadline.getTimeInMillis(); |
| 10341 | } |
| 10342 | |
| 10343 | public void recordDailyStatsIfNeededLocked(boolean settled) { |
| 10344 | long currentTime = System.currentTimeMillis(); |
| 10345 | if (currentTime >= mNextMaxDailyDeadline) { |
| 10346 | recordDailyStatsLocked(); |
| 10347 | } else if (settled && currentTime >= mNextMinDailyDeadline) { |
| 10348 | recordDailyStatsLocked(); |
| 10349 | } else if (currentTime < (mDailyStartTime-(1000*60*60*24))) { |
| 10350 | recordDailyStatsLocked(); |
| 10351 | } |
| 10352 | } |
| 10353 | |
| 10354 | public void recordDailyStatsLocked() { |
| 10355 | DailyItem item = new DailyItem(); |
| 10356 | item.mStartTime = mDailyStartTime; |
| 10357 | item.mEndTime = System.currentTimeMillis(); |
| 10358 | boolean hasData = false; |
| 10359 | if (mDailyDischargeStepTracker.mNumStepDurations > 0) { |
| 10360 | hasData = true; |
| 10361 | item.mDischargeSteps = new LevelStepTracker( |
| 10362 | mDailyDischargeStepTracker.mNumStepDurations, |
| 10363 | mDailyDischargeStepTracker.mStepDurations); |
| 10364 | } |
| 10365 | if (mDailyChargeStepTracker.mNumStepDurations > 0) { |
| 10366 | hasData = true; |
| 10367 | item.mChargeSteps = new LevelStepTracker( |
| 10368 | mDailyChargeStepTracker.mNumStepDurations, |
| 10369 | mDailyChargeStepTracker.mStepDurations); |
| 10370 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 10371 | if (mDailyPackageChanges != null) { |
| 10372 | hasData = true; |
| 10373 | item.mPackageChanges = mDailyPackageChanges; |
| 10374 | mDailyPackageChanges = null; |
| 10375 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10376 | mDailyDischargeStepTracker.init(); |
| 10377 | mDailyChargeStepTracker.init(); |
| 10378 | updateDailyDeadlineLocked(); |
| 10379 | |
| 10380 | if (hasData) { |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 10381 | final long startTime = SystemClock.uptimeMillis(); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10382 | mDailyItems.add(item); |
| 10383 | while (mDailyItems.size() > MAX_DAILY_ITEMS) { |
| 10384 | mDailyItems.remove(0); |
| 10385 | } |
| 10386 | final ByteArrayOutputStream memStream = new ByteArrayOutputStream(); |
| 10387 | try { |
| 10388 | XmlSerializer out = new FastXmlSerializer(); |
Wojciech Staszkiewicz | 9e9e2e7 | 2015-05-08 14:58:46 +0100 | [diff] [blame] | 10389 | out.setOutput(memStream, StandardCharsets.UTF_8.name()); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10390 | writeDailyItemsLocked(out); |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 10391 | final long initialTime = SystemClock.uptimeMillis() - startTime; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10392 | BackgroundThread.getHandler().post(new Runnable() { |
| 10393 | @Override |
| 10394 | public void run() { |
| 10395 | synchronized (mCheckinFile) { |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 10396 | final long startTime2 = SystemClock.uptimeMillis(); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10397 | FileOutputStream stream = null; |
| 10398 | try { |
| 10399 | stream = mDailyFile.startWrite(); |
| 10400 | memStream.writeTo(stream); |
| 10401 | stream.flush(); |
| 10402 | FileUtils.sync(stream); |
| 10403 | stream.close(); |
| 10404 | mDailyFile.finishWrite(stream); |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 10405 | com.android.internal.logging.EventLogTags.writeCommitSysConfigFile( |
| 10406 | "batterystats-daily", |
| 10407 | initialTime + SystemClock.uptimeMillis() - startTime2); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10408 | } catch (IOException e) { |
| 10409 | Slog.w("BatteryStats", |
| 10410 | "Error writing battery daily items", e); |
| 10411 | mDailyFile.failWrite(stream); |
| 10412 | } |
| 10413 | } |
| 10414 | } |
| 10415 | }); |
| 10416 | } catch (IOException e) { |
| 10417 | } |
| 10418 | } |
| 10419 | } |
| 10420 | |
| 10421 | private void writeDailyItemsLocked(XmlSerializer out) throws IOException { |
| 10422 | StringBuilder sb = new StringBuilder(64); |
| 10423 | out.startDocument(null, true); |
| 10424 | out.startTag(null, "daily-items"); |
| 10425 | for (int i=0; i<mDailyItems.size(); i++) { |
| 10426 | final DailyItem dit = mDailyItems.get(i); |
| 10427 | out.startTag(null, "item"); |
| 10428 | out.attribute(null, "start", Long.toString(dit.mStartTime)); |
| 10429 | out.attribute(null, "end", Long.toString(dit.mEndTime)); |
| 10430 | writeDailyLevelSteps(out, "dis", dit.mDischargeSteps, sb); |
| 10431 | writeDailyLevelSteps(out, "chg", dit.mChargeSteps, sb); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 10432 | if (dit.mPackageChanges != null) { |
| 10433 | for (int j=0; j<dit.mPackageChanges.size(); j++) { |
| 10434 | PackageChange pc = dit.mPackageChanges.get(j); |
| 10435 | if (pc.mUpdate) { |
| 10436 | out.startTag(null, "upd"); |
| 10437 | out.attribute(null, "pkg", pc.mPackageName); |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 10438 | out.attribute(null, "ver", Long.toString(pc.mVersionCode)); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 10439 | out.endTag(null, "upd"); |
| 10440 | } else { |
| 10441 | out.startTag(null, "rem"); |
| 10442 | out.attribute(null, "pkg", pc.mPackageName); |
| 10443 | out.endTag(null, "rem"); |
| 10444 | } |
| 10445 | } |
| 10446 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10447 | out.endTag(null, "item"); |
| 10448 | } |
| 10449 | out.endTag(null, "daily-items"); |
| 10450 | out.endDocument(); |
| 10451 | } |
| 10452 | |
| 10453 | private void writeDailyLevelSteps(XmlSerializer out, String tag, LevelStepTracker steps, |
| 10454 | StringBuilder tmpBuilder) throws IOException { |
| 10455 | if (steps != null) { |
| 10456 | out.startTag(null, tag); |
| 10457 | out.attribute(null, "n", Integer.toString(steps.mNumStepDurations)); |
| 10458 | for (int i=0; i<steps.mNumStepDurations; i++) { |
| 10459 | out.startTag(null, "s"); |
| 10460 | tmpBuilder.setLength(0); |
| 10461 | steps.encodeEntryAt(i, tmpBuilder); |
| 10462 | out.attribute(null, "v", tmpBuilder.toString()); |
| 10463 | out.endTag(null, "s"); |
| 10464 | } |
| 10465 | out.endTag(null, tag); |
| 10466 | } |
| 10467 | } |
| 10468 | |
| 10469 | public void readDailyStatsLocked() { |
| 10470 | Slog.d(TAG, "Reading daily items from " + mDailyFile.getBaseFile()); |
| 10471 | mDailyItems.clear(); |
| 10472 | FileInputStream stream; |
| 10473 | try { |
| 10474 | stream = mDailyFile.openRead(); |
| 10475 | } catch (FileNotFoundException e) { |
| 10476 | return; |
| 10477 | } |
| 10478 | try { |
| 10479 | XmlPullParser parser = Xml.newPullParser(); |
Wojciech Staszkiewicz | 9e9e2e7 | 2015-05-08 14:58:46 +0100 | [diff] [blame] | 10480 | parser.setInput(stream, StandardCharsets.UTF_8.name()); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10481 | readDailyItemsLocked(parser); |
| 10482 | } catch (XmlPullParserException e) { |
| 10483 | } finally { |
| 10484 | try { |
| 10485 | stream.close(); |
| 10486 | } catch (IOException e) { |
| 10487 | } |
| 10488 | } |
| 10489 | } |
| 10490 | |
| 10491 | private void readDailyItemsLocked(XmlPullParser parser) { |
| 10492 | try { |
| 10493 | int type; |
| 10494 | while ((type = parser.next()) != XmlPullParser.START_TAG |
| 10495 | && type != XmlPullParser.END_DOCUMENT) { |
| 10496 | ; |
| 10497 | } |
| 10498 | |
| 10499 | if (type != XmlPullParser.START_TAG) { |
| 10500 | throw new IllegalStateException("no start tag found"); |
| 10501 | } |
| 10502 | |
| 10503 | int outerDepth = parser.getDepth(); |
| 10504 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 10505 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 10506 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 10507 | continue; |
| 10508 | } |
| 10509 | |
| 10510 | String tagName = parser.getName(); |
| 10511 | if (tagName.equals("item")) { |
| 10512 | readDailyItemTagLocked(parser); |
| 10513 | } else { |
| 10514 | Slog.w(TAG, "Unknown element under <daily-items>: " |
| 10515 | + parser.getName()); |
| 10516 | XmlUtils.skipCurrentTag(parser); |
| 10517 | } |
| 10518 | } |
| 10519 | |
| 10520 | } catch (IllegalStateException e) { |
| 10521 | Slog.w(TAG, "Failed parsing daily " + e); |
| 10522 | } catch (NullPointerException e) { |
| 10523 | Slog.w(TAG, "Failed parsing daily " + e); |
| 10524 | } catch (NumberFormatException e) { |
| 10525 | Slog.w(TAG, "Failed parsing daily " + e); |
| 10526 | } catch (XmlPullParserException e) { |
| 10527 | Slog.w(TAG, "Failed parsing daily " + e); |
| 10528 | } catch (IOException e) { |
| 10529 | Slog.w(TAG, "Failed parsing daily " + e); |
| 10530 | } catch (IndexOutOfBoundsException e) { |
| 10531 | Slog.w(TAG, "Failed parsing daily " + e); |
| 10532 | } |
| 10533 | } |
| 10534 | |
| 10535 | void readDailyItemTagLocked(XmlPullParser parser) throws NumberFormatException, |
| 10536 | XmlPullParserException, IOException { |
| 10537 | DailyItem dit = new DailyItem(); |
| 10538 | String attr = parser.getAttributeValue(null, "start"); |
| 10539 | if (attr != null) { |
| 10540 | dit.mStartTime = Long.parseLong(attr); |
| 10541 | } |
| 10542 | attr = parser.getAttributeValue(null, "end"); |
| 10543 | if (attr != null) { |
| 10544 | dit.mEndTime = Long.parseLong(attr); |
| 10545 | } |
| 10546 | int outerDepth = parser.getDepth(); |
| 10547 | int type; |
| 10548 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 10549 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 10550 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 10551 | continue; |
| 10552 | } |
| 10553 | |
| 10554 | String tagName = parser.getName(); |
| 10555 | if (tagName.equals("dis")) { |
| 10556 | readDailyItemTagDetailsLocked(parser, dit, false, "dis"); |
| 10557 | } else if (tagName.equals("chg")) { |
| 10558 | readDailyItemTagDetailsLocked(parser, dit, true, "chg"); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 10559 | } else if (tagName.equals("upd")) { |
| 10560 | if (dit.mPackageChanges == null) { |
| 10561 | dit.mPackageChanges = new ArrayList<>(); |
| 10562 | } |
| 10563 | PackageChange pc = new PackageChange(); |
| 10564 | pc.mUpdate = true; |
| 10565 | pc.mPackageName = parser.getAttributeValue(null, "pkg"); |
| 10566 | String verStr = parser.getAttributeValue(null, "ver"); |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 10567 | pc.mVersionCode = verStr != null ? Long.parseLong(verStr) : 0; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 10568 | dit.mPackageChanges.add(pc); |
| 10569 | XmlUtils.skipCurrentTag(parser); |
| 10570 | } else if (tagName.equals("rem")) { |
| 10571 | if (dit.mPackageChanges == null) { |
| 10572 | dit.mPackageChanges = new ArrayList<>(); |
| 10573 | } |
| 10574 | PackageChange pc = new PackageChange(); |
| 10575 | pc.mUpdate = false; |
| 10576 | pc.mPackageName = parser.getAttributeValue(null, "pkg"); |
| 10577 | dit.mPackageChanges.add(pc); |
| 10578 | XmlUtils.skipCurrentTag(parser); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10579 | } else { |
| 10580 | Slog.w(TAG, "Unknown element under <item>: " |
| 10581 | + parser.getName()); |
| 10582 | XmlUtils.skipCurrentTag(parser); |
| 10583 | } |
| 10584 | } |
| 10585 | mDailyItems.add(dit); |
| 10586 | } |
| 10587 | |
| 10588 | void readDailyItemTagDetailsLocked(XmlPullParser parser, DailyItem dit, boolean isCharge, |
| 10589 | String tag) |
| 10590 | throws NumberFormatException, XmlPullParserException, IOException { |
| 10591 | final String numAttr = parser.getAttributeValue(null, "n"); |
| 10592 | if (numAttr == null) { |
| 10593 | Slog.w(TAG, "Missing 'n' attribute at " + parser.getPositionDescription()); |
| 10594 | XmlUtils.skipCurrentTag(parser); |
| 10595 | return; |
| 10596 | } |
| 10597 | final int num = Integer.parseInt(numAttr); |
| 10598 | LevelStepTracker steps = new LevelStepTracker(num); |
| 10599 | if (isCharge) { |
| 10600 | dit.mChargeSteps = steps; |
| 10601 | } else { |
| 10602 | dit.mDischargeSteps = steps; |
| 10603 | } |
| 10604 | int i = 0; |
| 10605 | int outerDepth = parser.getDepth(); |
| 10606 | int type; |
| 10607 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 10608 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 10609 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 10610 | continue; |
| 10611 | } |
| 10612 | |
| 10613 | String tagName = parser.getName(); |
| 10614 | if ("s".equals(tagName)) { |
| 10615 | if (i < num) { |
| 10616 | String valueAttr = parser.getAttributeValue(null, "v"); |
| 10617 | if (valueAttr != null) { |
| 10618 | steps.decodeEntryAt(i, valueAttr); |
| 10619 | i++; |
| 10620 | } |
| 10621 | } |
| 10622 | } else { |
| 10623 | Slog.w(TAG, "Unknown element under <" + tag + ">: " |
| 10624 | + parser.getName()); |
| 10625 | XmlUtils.skipCurrentTag(parser); |
| 10626 | } |
| 10627 | } |
| 10628 | steps.mNumStepDurations = i; |
| 10629 | } |
| 10630 | |
| 10631 | @Override |
| 10632 | public DailyItem getDailyItemLocked(int daysAgo) { |
| 10633 | int index = mDailyItems.size()-1-daysAgo; |
| 10634 | return index >= 0 ? mDailyItems.get(index) : null; |
| 10635 | } |
| 10636 | |
| 10637 | @Override |
| 10638 | public long getCurrentDailyStartTime() { |
| 10639 | return mDailyStartTime; |
| 10640 | } |
| 10641 | |
| 10642 | @Override |
| 10643 | public long getNextMinDailyDeadline() { |
| 10644 | return mNextMinDailyDeadline; |
| 10645 | } |
| 10646 | |
| 10647 | @Override |
| 10648 | public long getNextMaxDailyDeadline() { |
| 10649 | return mNextMaxDailyDeadline; |
| 10650 | } |
| 10651 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10652 | @Override |
| 10653 | public boolean startIteratingOldHistoryLocked() { |
| 10654 | if (DEBUG_HISTORY) Slog.i(TAG, "ITERATING: buff size=" + mHistoryBuffer.dataSize() |
| 10655 | + " pos=" + mHistoryBuffer.dataPosition()); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 10656 | if ((mHistoryIterator = mHistory) == null) { |
| 10657 | return false; |
| 10658 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10659 | mHistoryBuffer.setDataPosition(0); |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 10660 | mHistoryReadTmp.clear(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10661 | mReadOverflow = false; |
| 10662 | mIteratingHistory = true; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 10663 | return true; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 10664 | } |
| 10665 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10666 | @Override |
| 10667 | public boolean getNextOldHistoryLocked(HistoryItem out) { |
| 10668 | boolean end = mHistoryBuffer.dataPosition() >= mHistoryBuffer.dataSize(); |
| 10669 | if (!end) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 10670 | readHistoryDelta(mHistoryBuffer, mHistoryReadTmp); |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 10671 | mReadOverflow |= mHistoryReadTmp.cmd == HistoryItem.CMD_OVERFLOW; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10672 | } |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 10673 | HistoryItem cur = mHistoryIterator; |
| 10674 | if (cur == null) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10675 | if (!mReadOverflow && !end) { |
| 10676 | Slog.w(TAG, "Old history ends before new history!"); |
| 10677 | } |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 10678 | return false; |
| 10679 | } |
| 10680 | out.setTo(cur); |
| 10681 | mHistoryIterator = cur.next; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10682 | if (!mReadOverflow) { |
| 10683 | if (end) { |
| 10684 | Slog.w(TAG, "New history ends before old history!"); |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 10685 | } else if (!out.same(mHistoryReadTmp)) { |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 10686 | PrintWriter pw = new FastPrintWriter(new LogWriter(android.util.Log.WARN, TAG)); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10687 | pw.println("Histories differ!"); |
| 10688 | pw.println("Old history:"); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 10689 | (new HistoryPrinter()).printNextItem(pw, out, 0, false, true); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10690 | pw.println("New history:"); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 10691 | (new HistoryPrinter()).printNextItem(pw, mHistoryReadTmp, 0, false, |
| 10692 | true); |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 10693 | pw.flush(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10694 | } |
| 10695 | } |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 10696 | return true; |
| 10697 | } |
| 10698 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10699 | @Override |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10700 | public void finishIteratingOldHistoryLocked() { |
| 10701 | mIteratingHistory = false; |
| 10702 | mHistoryBuffer.setDataPosition(mHistoryBuffer.dataSize()); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 10703 | mHistoryIterator = null; |
| 10704 | } |
| 10705 | |
| 10706 | public int getHistoryTotalSize() { |
| 10707 | return MAX_HISTORY_BUFFER; |
| 10708 | } |
| 10709 | |
| 10710 | public int getHistoryUsedSize() { |
| 10711 | return mHistoryBuffer.dataSize(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10712 | } |
| 10713 | |
| 10714 | @Override |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 10715 | @UnsupportedAppUsage |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10716 | public boolean startIteratingHistoryLocked() { |
| 10717 | if (DEBUG_HISTORY) Slog.i(TAG, "ITERATING: buff size=" + mHistoryBuffer.dataSize() |
| 10718 | + " pos=" + mHistoryBuffer.dataPosition()); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 10719 | if (mHistoryBuffer.dataSize() <= 0) { |
| 10720 | return false; |
| 10721 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10722 | mHistoryBuffer.setDataPosition(0); |
| 10723 | mReadOverflow = false; |
| 10724 | mIteratingHistory = true; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 10725 | mReadHistoryStrings = new String[mHistoryTagPool.size()]; |
| 10726 | mReadHistoryUids = new int[mHistoryTagPool.size()]; |
| 10727 | mReadHistoryChars = 0; |
| 10728 | for (HashMap.Entry<HistoryTag, Integer> ent : mHistoryTagPool.entrySet()) { |
| 10729 | final HistoryTag tag = ent.getKey(); |
| 10730 | final int idx = ent.getValue(); |
| 10731 | mReadHistoryStrings[idx] = tag.string; |
| 10732 | mReadHistoryUids[idx] = tag.uid; |
| 10733 | mReadHistoryChars += tag.string.length() + 1; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 10734 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 10735 | return true; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10736 | } |
| 10737 | |
| 10738 | @Override |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 10739 | public int getHistoryStringPoolSize() { |
| 10740 | return mReadHistoryStrings.length; |
| 10741 | } |
| 10742 | |
| 10743 | @Override |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 10744 | public int getHistoryStringPoolBytes() { |
| 10745 | // Each entry is a fixed 12 bytes: 4 for index, 4 for uid, 4 for string size |
| 10746 | // Each string character is 2 bytes. |
| 10747 | return (mReadHistoryStrings.length * 12) + (mReadHistoryChars * 2); |
| 10748 | } |
| 10749 | |
| 10750 | @Override |
| 10751 | public String getHistoryTagPoolString(int index) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 10752 | return mReadHistoryStrings[index]; |
| 10753 | } |
| 10754 | |
| 10755 | @Override |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 10756 | public int getHistoryTagPoolUid(int index) { |
| 10757 | return mReadHistoryUids[index]; |
| 10758 | } |
| 10759 | |
| 10760 | @Override |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 10761 | @UnsupportedAppUsage |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10762 | public boolean getNextHistoryLocked(HistoryItem out) { |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 10763 | final int pos = mHistoryBuffer.dataPosition(); |
| 10764 | if (pos == 0) { |
| 10765 | out.clear(); |
| 10766 | } |
| 10767 | boolean end = pos >= mHistoryBuffer.dataSize(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10768 | if (end) { |
| 10769 | return false; |
| 10770 | } |
| 10771 | |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 10772 | final long lastRealtime = out.time; |
| 10773 | final long lastWalltime = out.currentTime; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 10774 | readHistoryDelta(mHistoryBuffer, out); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 10775 | if (out.cmd != HistoryItem.CMD_CURRENT_TIME |
| 10776 | && out.cmd != HistoryItem.CMD_RESET && lastWalltime != 0) { |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 10777 | out.currentTime = lastWalltime + (out.time - lastRealtime); |
| 10778 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10779 | return true; |
| 10780 | } |
| 10781 | |
| 10782 | @Override |
| 10783 | public void finishIteratingHistoryLocked() { |
| 10784 | mIteratingHistory = false; |
| 10785 | mHistoryBuffer.setDataPosition(mHistoryBuffer.dataSize()); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 10786 | mReadHistoryStrings = null; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 10787 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10788 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 10789 | @Override |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 10790 | public long getHistoryBaseTime() { |
| 10791 | return mHistoryBaseTime; |
| 10792 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10793 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 10794 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10795 | public int getStartCount() { |
| 10796 | return mStartCount; |
| 10797 | } |
| 10798 | |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 10799 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10800 | public boolean isOnBattery() { |
| 10801 | return mOnBattery; |
| 10802 | } |
| 10803 | |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 10804 | public boolean isCharging() { |
| 10805 | return mCharging; |
| 10806 | } |
| 10807 | |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 10808 | public boolean isScreenOn(int state) { |
Chris Phoenix | 10a4a64 | 2017-09-25 13:21:00 -0700 | [diff] [blame] | 10809 | return state == Display.STATE_ON || state == Display.STATE_VR |
| 10810 | || state == Display.STATE_ON_SUSPEND; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 10811 | } |
| 10812 | |
| 10813 | public boolean isScreenOff(int state) { |
| 10814 | return state == Display.STATE_OFF; |
| 10815 | } |
| 10816 | |
| 10817 | public boolean isScreenDoze(int state) { |
| 10818 | return state == Display.STATE_DOZE || state == Display.STATE_DOZE_SUSPEND; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 10819 | } |
| 10820 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10821 | void initTimes(long uptime, long realtime) { |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 10822 | mStartClockTime = System.currentTimeMillis(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10823 | mOnBatteryTimeBase.init(uptime, realtime); |
| 10824 | mOnBatteryScreenOffTimeBase.init(uptime, realtime); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 10825 | mRealtime = 0; |
| 10826 | mUptime = 0; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10827 | mRealtimeStart = realtime; |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 10828 | mUptimeStart = uptime; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10829 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10830 | |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 10831 | void initDischarge() { |
| 10832 | mLowDischargeAmountSinceCharge = 0; |
| 10833 | mHighDischargeAmountSinceCharge = 0; |
| 10834 | mDischargeAmountScreenOn = 0; |
| 10835 | mDischargeAmountScreenOnSinceCharge = 0; |
| 10836 | mDischargeAmountScreenOff = 0; |
| 10837 | mDischargeAmountScreenOffSinceCharge = 0; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 10838 | mDischargeAmountScreenDoze = 0; |
| 10839 | mDischargeAmountScreenDozeSinceCharge = 0; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10840 | mDischargeStepTracker.init(); |
| 10841 | mChargeStepTracker.init(); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 10842 | mDischargeScreenOffCounter.reset(false); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 10843 | mDischargeScreenDozeCounter.reset(false); |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 10844 | mDischargeLightDozeCounter.reset(false); |
| 10845 | mDischargeDeepDozeCounter.reset(false); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 10846 | mDischargeCounter.reset(false); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 10847 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 10848 | |
| 10849 | public void resetAllStatsCmdLocked() { |
| 10850 | resetAllStatsLocked(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10851 | final long mSecUptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 10852 | long uptime = mSecUptime * 1000; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10853 | long mSecRealtime = mClocks.elapsedRealtime(); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 10854 | long realtime = mSecRealtime * 1000; |
| 10855 | mDischargeStartLevel = mHistoryCur.batteryLevel; |
| 10856 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 10857 | addHistoryRecordLocked(mSecRealtime, mSecUptime); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 10858 | mDischargeCurrentLevel = mDischargeUnplugLevel = mDischargePlugLevel |
| 10859 | = mCurrentBatteryLevel = mHistoryCur.batteryLevel; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10860 | mOnBatteryTimeBase.reset(uptime, realtime); |
| 10861 | mOnBatteryScreenOffTimeBase.reset(uptime, realtime); |
| 10862 | if ((mHistoryCur.states&HistoryItem.STATE_BATTERY_PLUGGED_FLAG) == 0) { |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 10863 | if (isScreenOn(mScreenState)) { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 10864 | mDischargeScreenOnUnplugLevel = mHistoryCur.batteryLevel; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 10865 | mDischargeScreenDozeUnplugLevel = 0; |
| 10866 | mDischargeScreenOffUnplugLevel = 0; |
| 10867 | } else if (isScreenDoze(mScreenState)) { |
| 10868 | mDischargeScreenOnUnplugLevel = 0; |
| 10869 | mDischargeScreenDozeUnplugLevel = mHistoryCur.batteryLevel; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 10870 | mDischargeScreenOffUnplugLevel = 0; |
| 10871 | } else { |
| 10872 | mDischargeScreenOnUnplugLevel = 0; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 10873 | mDischargeScreenDozeUnplugLevel = 0; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 10874 | mDischargeScreenOffUnplugLevel = mHistoryCur.batteryLevel; |
| 10875 | } |
| 10876 | mDischargeAmountScreenOn = 0; |
| 10877 | mDischargeAmountScreenOff = 0; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 10878 | mDischargeAmountScreenDoze = 0; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 10879 | } |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 10880 | initActiveHistoryEventsLocked(mSecRealtime, mSecUptime); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 10881 | } |
| 10882 | |
| 10883 | private void resetAllStatsLocked() { |
Adam Lesinski | 8ce3694 | 2016-05-26 16:05:35 -0700 | [diff] [blame] | 10884 | final long uptimeMillis = mClocks.uptimeMillis(); |
| 10885 | final long elapsedRealtimeMillis = mClocks.elapsedRealtime(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10886 | mStartCount = 0; |
Adam Lesinski | 8ce3694 | 2016-05-26 16:05:35 -0700 | [diff] [blame] | 10887 | initTimes(uptimeMillis * 1000, elapsedRealtimeMillis * 1000); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10888 | mScreenOnTimer.reset(false); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 10889 | mScreenDozeTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10890 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10891 | mScreenBrightnessTimer[i].reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10892 | } |
Adam Lesinski | 1a76a62 | 2016-06-22 10:28:47 -0700 | [diff] [blame] | 10893 | |
| 10894 | if (mPowerProfile != null) { |
| 10895 | mEstimatedBatteryCapacity = (int) mPowerProfile.getBatteryCapacity(); |
| 10896 | } else { |
| 10897 | mEstimatedBatteryCapacity = -1; |
| 10898 | } |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 10899 | mMinLearnedBatteryCapacity = -1; |
| 10900 | mMaxLearnedBatteryCapacity = -1; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 10901 | mInteractiveTimer.reset(false); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 10902 | mPowerSaveModeEnabledTimer.reset(false); |
Adam Lesinski | 8ce3694 | 2016-05-26 16:05:35 -0700 | [diff] [blame] | 10903 | mLastIdleTimeStart = elapsedRealtimeMillis; |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 10904 | mLongestLightIdleTime = 0; |
| 10905 | mLongestFullIdleTime = 0; |
| 10906 | mDeviceIdleModeLightTimer.reset(false); |
| 10907 | mDeviceIdleModeFullTimer.reset(false); |
| 10908 | mDeviceLightIdlingTimer.reset(false); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 10909 | mDeviceIdlingTimer.reset(false); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10910 | mPhoneOnTimer.reset(false); |
| 10911 | mAudioOnTimer.reset(false); |
| 10912 | mVideoOnTimer.reset(false); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 10913 | mFlashlightOnTimer.reset(false); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 10914 | mCameraOnTimer.reset(false); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 10915 | mBluetoothScanTimer.reset(false); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 10916 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10917 | mPhoneSignalStrengthsTimer[i].reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10918 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10919 | mPhoneSignalScanningTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10920 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10921 | mPhoneDataConnectionsTimer[i].reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10922 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 10923 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 10924 | mNetworkByteActivityCounters[i].reset(false); |
| 10925 | mNetworkPacketActivityCounters[i].reset(false); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 10926 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10927 | mMobileRadioActiveTimer.reset(false); |
| 10928 | mMobileRadioActivePerAppTimer.reset(false); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10929 | mMobileRadioActiveAdjustedTime.reset(false); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 10930 | mMobileRadioActiveUnknownTime.reset(false); |
| 10931 | mMobileRadioActiveUnknownCount.reset(false); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10932 | mWifiOnTimer.reset(false); |
| 10933 | mGlobalWifiRunningTimer.reset(false); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 10934 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10935 | mWifiStateTimer[i].reset(false); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 10936 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 10937 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 10938 | mWifiSupplStateTimer[i].reset(false); |
| 10939 | } |
| 10940 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 10941 | mWifiSignalStrengthsTimer[i].reset(false); |
| 10942 | } |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 10943 | mWifiMulticastWakelockTimer.reset(false); |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 10944 | mWifiActiveTimer.reset(false); |
| 10945 | mWifiActivity.reset(false); |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 10946 | for (int i=0; i< GnssMetrics.NUM_GPS_SIGNAL_QUALITY_LEVELS; i++) { |
| 10947 | mGpsSignalQualityTimer[i].reset(false); |
| 10948 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 10949 | mBluetoothActivity.reset(false); |
| 10950 | mModemActivity.reset(false); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 10951 | mNumConnectivityChange = mLoadedNumConnectivityChange = mUnpluggedNumConnectivityChange = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10952 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10953 | for (int i=0; i<mUidStats.size(); i++) { |
Bookatz | 993a0be | 2017-07-21 09:03:23 -0700 | [diff] [blame] | 10954 | if (mUidStats.valueAt(i).reset(uptimeMillis * 1000, elapsedRealtimeMillis * 1000)) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10955 | mUidStats.remove(mUidStats.keyAt(i)); |
| 10956 | i--; |
| 10957 | } |
| 10958 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10959 | |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 10960 | if (mRpmStats.size() > 0) { |
| 10961 | for (SamplingTimer timer : mRpmStats.values()) { |
| 10962 | mOnBatteryTimeBase.remove(timer); |
| 10963 | } |
| 10964 | mRpmStats.clear(); |
| 10965 | } |
| 10966 | if (mScreenOffRpmStats.size() > 0) { |
| 10967 | for (SamplingTimer timer : mScreenOffRpmStats.values()) { |
| 10968 | mOnBatteryScreenOffTimeBase.remove(timer); |
| 10969 | } |
| 10970 | mScreenOffRpmStats.clear(); |
| 10971 | } |
| 10972 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10973 | if (mKernelWakelockStats.size() > 0) { |
| 10974 | for (SamplingTimer timer : mKernelWakelockStats.values()) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10975 | mOnBatteryScreenOffTimeBase.remove(timer); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10976 | } |
| 10977 | mKernelWakelockStats.clear(); |
| 10978 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10979 | |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 10980 | if (mKernelMemoryStats.size() > 0) { |
| 10981 | for (int i = 0; i < mKernelMemoryStats.size(); i++) { |
| 10982 | mOnBatteryTimeBase.remove(mKernelMemoryStats.valueAt(i)); |
| 10983 | } |
| 10984 | mKernelMemoryStats.clear(); |
| 10985 | } |
| 10986 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10987 | if (mWakeupReasonStats.size() > 0) { |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 10988 | for (SamplingTimer timer : mWakeupReasonStats.values()) { |
| 10989 | mOnBatteryTimeBase.remove(timer); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10990 | } |
| 10991 | mWakeupReasonStats.clear(); |
| 10992 | } |
| 10993 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 10994 | mLastHistoryStepDetails = null; |
| 10995 | mLastStepCpuUserTime = mLastStepCpuSystemTime = 0; |
| 10996 | mCurStepCpuUserTime = mCurStepCpuSystemTime = 0; |
| 10997 | mLastStepCpuUserTime = mCurStepCpuUserTime = 0; |
| 10998 | mLastStepCpuSystemTime = mCurStepCpuSystemTime = 0; |
| 10999 | mLastStepStatUserTime = mCurStepStatUserTime = 0; |
| 11000 | mLastStepStatSystemTime = mCurStepStatSystemTime = 0; |
| 11001 | mLastStepStatIOWaitTime = mCurStepStatIOWaitTime = 0; |
| 11002 | mLastStepStatIrqTime = mCurStepStatIrqTime = 0; |
| 11003 | mLastStepStatSoftIrqTime = mCurStepStatSoftIrqTime = 0; |
| 11004 | mLastStepStatIdleTime = mCurStepStatIdleTime = 0; |
| 11005 | |
Mike Ma | 234d182 | 2018-03-13 18:53:21 -0700 | [diff] [blame] | 11006 | mNumAllUidCpuTimeReads = 0; |
| 11007 | mNumUidsRemoved = 0; |
| 11008 | |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 11009 | initDischarge(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 11010 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 11011 | clearHistoryLocked(); |
Fyodor Kupolov | 8aa5124 | 2018-04-23 12:44:51 -0700 | [diff] [blame] | 11012 | mHandler.sendEmptyMessage(MSG_REPORT_RESET_STATS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 11013 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 11014 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 11015 | private void initActiveHistoryEventsLocked(long elapsedRealtimeMs, long uptimeMs) { |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 11016 | for (int i=0; i<HistoryItem.EVENT_COUNT; i++) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 11017 | if (!mRecordAllHistory && i == HistoryItem.EVENT_PROC) { |
| 11018 | // Not recording process starts/stops. |
| 11019 | continue; |
| 11020 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 11021 | HashMap<String, SparseIntArray> active = mActiveEvents.getStateForEvent(i); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 11022 | if (active == null) { |
| 11023 | continue; |
| 11024 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 11025 | for (HashMap.Entry<String, SparseIntArray> ent : active.entrySet()) { |
| 11026 | SparseIntArray uids = ent.getValue(); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 11027 | for (int j=0; j<uids.size(); j++) { |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 11028 | addHistoryEventLocked(elapsedRealtimeMs, uptimeMs, i, ent.getKey(), |
| 11029 | uids.keyAt(j)); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 11030 | } |
| 11031 | } |
| 11032 | } |
| 11033 | } |
| 11034 | |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 11035 | void updateDischargeScreenLevelsLocked(int oldState, int newState) { |
| 11036 | updateOldDischargeScreenLevelLocked(oldState); |
| 11037 | updateNewDischargeScreenLevelLocked(newState); |
| 11038 | } |
| 11039 | |
| 11040 | private void updateOldDischargeScreenLevelLocked(int state) { |
| 11041 | if (isScreenOn(state)) { |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 11042 | int diff = mDischargeScreenOnUnplugLevel - mDischargeCurrentLevel; |
| 11043 | if (diff > 0) { |
| 11044 | mDischargeAmountScreenOn += diff; |
| 11045 | mDischargeAmountScreenOnSinceCharge += diff; |
| 11046 | } |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 11047 | } else if (isScreenDoze(state)) { |
| 11048 | int diff = mDischargeScreenDozeUnplugLevel - mDischargeCurrentLevel; |
| 11049 | if (diff > 0) { |
| 11050 | mDischargeAmountScreenDoze += diff; |
| 11051 | mDischargeAmountScreenDozeSinceCharge += diff; |
| 11052 | } |
| 11053 | } else if (isScreenOff(state)){ |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 11054 | int diff = mDischargeScreenOffUnplugLevel - mDischargeCurrentLevel; |
| 11055 | if (diff > 0) { |
| 11056 | mDischargeAmountScreenOff += diff; |
| 11057 | mDischargeAmountScreenOffSinceCharge += diff; |
| 11058 | } |
| 11059 | } |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 11060 | } |
| 11061 | |
| 11062 | private void updateNewDischargeScreenLevelLocked(int state) { |
| 11063 | if (isScreenOn(state)) { |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 11064 | mDischargeScreenOnUnplugLevel = mDischargeCurrentLevel; |
| 11065 | mDischargeScreenOffUnplugLevel = 0; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 11066 | mDischargeScreenDozeUnplugLevel = 0; |
| 11067 | } else if (isScreenDoze(state)){ |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 11068 | mDischargeScreenOnUnplugLevel = 0; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 11069 | mDischargeScreenDozeUnplugLevel = mDischargeCurrentLevel; |
| 11070 | mDischargeScreenOffUnplugLevel = 0; |
| 11071 | } else if (isScreenOff(state)) { |
| 11072 | mDischargeScreenOnUnplugLevel = 0; |
| 11073 | mDischargeScreenDozeUnplugLevel = 0; |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 11074 | mDischargeScreenOffUnplugLevel = mDischargeCurrentLevel; |
| 11075 | } |
| 11076 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11077 | |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 11078 | public void pullPendingStateUpdatesLocked() { |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 11079 | if (mOnBatteryInternal) { |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 11080 | updateDischargeScreenLevelsLocked(mScreenState, mScreenState); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 11081 | } |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 11082 | } |
| 11083 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11084 | private final NetworkStatsFactory mNetworkStatsFactory = new NetworkStatsFactory(); |
| 11085 | private final Pools.Pool<NetworkStats> mNetworkStatsPool = new Pools.SynchronizedPool<>(6); |
| 11086 | |
| 11087 | private final Object mWifiNetworkLock = new Object(); |
| 11088 | |
| 11089 | @GuardedBy("mWifiNetworkLock") |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11090 | private String[] mWifiIfaces = EmptyArray.STRING; |
| 11091 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11092 | @GuardedBy("mWifiNetworkLock") |
| 11093 | private NetworkStats mLastWifiNetworkStats = new NetworkStats(0, -1); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11094 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11095 | private final Object mModemNetworkLock = new Object(); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11096 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11097 | @GuardedBy("mModemNetworkLock") |
| 11098 | private String[] mModemIfaces = EmptyArray.STRING; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11099 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11100 | @GuardedBy("mModemNetworkLock") |
| 11101 | private NetworkStats mLastModemNetworkStats = new NetworkStats(0, -1); |
| 11102 | |
| 11103 | private NetworkStats readNetworkStatsLocked(String[] ifaces) { |
| 11104 | try { |
| 11105 | if (!ArrayUtils.isEmpty(ifaces)) { |
| 11106 | return mNetworkStatsFactory.readNetworkStatsDetail(NetworkStats.UID_ALL, ifaces, |
| 11107 | NetworkStats.TAG_NONE, mNetworkStatsPool.acquire()); |
| 11108 | } |
| 11109 | } catch (IOException e) { |
| 11110 | 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] | 11111 | } |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11112 | return null; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11113 | } |
| 11114 | |
Chenjie Yu | 8908339 | 2018-01-11 14:53:31 -0800 | [diff] [blame] | 11115 | /** |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11116 | * Distribute WiFi energy info and network traffic to apps. |
| 11117 | * @param info The energy information from the WiFi controller. |
| 11118 | */ |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11119 | public void updateWifiState(@Nullable final WifiActivityEnergyInfo info) { |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 11120 | if (DEBUG_ENERGY) { |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11121 | Slog.d(TAG, "Updating wifi stats: " + Arrays.toString(mWifiIfaces)); |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 11122 | } |
| 11123 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11124 | // 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] | 11125 | NetworkStats delta = null; |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11126 | synchronized (mWifiNetworkLock) { |
| 11127 | final NetworkStats latestStats = readNetworkStatsLocked(mWifiIfaces); |
| 11128 | if (latestStats != null) { |
| 11129 | delta = NetworkStats.subtract(latestStats, mLastWifiNetworkStats, null, null, |
| 11130 | mNetworkStatsPool.acquire()); |
| 11131 | mNetworkStatsPool.release(mLastWifiNetworkStats); |
| 11132 | mLastWifiNetworkStats = latestStats; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 11133 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11134 | } |
| 11135 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11136 | synchronized (this) { |
| 11137 | if (!mOnBatteryInternal) { |
| 11138 | if (delta != null) { |
| 11139 | mNetworkStatsPool.release(delta); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11140 | } |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11141 | return; |
| 11142 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11143 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11144 | final long elapsedRealtimeMs = mClocks.elapsedRealtime(); |
| 11145 | SparseLongArray rxPackets = new SparseLongArray(); |
| 11146 | SparseLongArray txPackets = new SparseLongArray(); |
| 11147 | long totalTxPackets = 0; |
| 11148 | long totalRxPackets = 0; |
| 11149 | if (delta != null) { |
| 11150 | NetworkStats.Entry entry = new NetworkStats.Entry(); |
| 11151 | final int size = delta.size(); |
| 11152 | for (int i = 0; i < size; i++) { |
| 11153 | entry = delta.getValues(i, entry); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11154 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11155 | if (DEBUG_ENERGY) { |
| 11156 | Slog.d(TAG, "Wifi uid " + entry.uid + ": delta rx=" + entry.rxBytes |
| 11157 | + " tx=" + entry.txBytes + " rxPackets=" + entry.rxPackets |
| 11158 | + " txPackets=" + entry.txPackets); |
| 11159 | } |
| 11160 | |
| 11161 | if (entry.rxBytes == 0 && entry.txBytes == 0) { |
| 11162 | // Skip the lookup below since there is no work to do. |
| 11163 | continue; |
| 11164 | } |
| 11165 | |
| 11166 | final Uid u = getUidStatsLocked(mapUid(entry.uid)); |
| 11167 | if (entry.rxBytes != 0) { |
| 11168 | u.noteNetworkActivityLocked(NETWORK_WIFI_RX_DATA, entry.rxBytes, |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 11169 | entry.rxPackets); |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11170 | if (entry.set == NetworkStats.SET_DEFAULT) { // Background transfers |
| 11171 | u.noteNetworkActivityLocked(NETWORK_WIFI_BG_RX_DATA, entry.rxBytes, |
| 11172 | entry.rxPackets); |
| 11173 | } |
| 11174 | mNetworkByteActivityCounters[NETWORK_WIFI_RX_DATA].addCountLocked( |
| 11175 | entry.rxBytes); |
| 11176 | mNetworkPacketActivityCounters[NETWORK_WIFI_RX_DATA].addCountLocked( |
| 11177 | entry.rxPackets); |
| 11178 | |
| 11179 | rxPackets.put(u.getUid(), entry.rxPackets); |
| 11180 | |
| 11181 | // Sum the total number of packets so that the Rx Power can |
| 11182 | // be evenly distributed amongst the apps. |
| 11183 | totalRxPackets += entry.rxPackets; |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 11184 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 11185 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11186 | if (entry.txBytes != 0) { |
| 11187 | u.noteNetworkActivityLocked(NETWORK_WIFI_TX_DATA, entry.txBytes, |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 11188 | entry.txPackets); |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11189 | if (entry.set == NetworkStats.SET_DEFAULT) { // Background transfers |
| 11190 | u.noteNetworkActivityLocked(NETWORK_WIFI_BG_TX_DATA, entry.txBytes, |
| 11191 | entry.txPackets); |
| 11192 | } |
| 11193 | mNetworkByteActivityCounters[NETWORK_WIFI_TX_DATA].addCountLocked( |
| 11194 | entry.txBytes); |
| 11195 | mNetworkPacketActivityCounters[NETWORK_WIFI_TX_DATA].addCountLocked( |
| 11196 | entry.txPackets); |
| 11197 | |
| 11198 | txPackets.put(u.getUid(), entry.txPackets); |
| 11199 | |
| 11200 | // Sum the total number of packets so that the Tx Power can |
| 11201 | // be evenly distributed amongst the apps. |
| 11202 | totalTxPackets += entry.txPackets; |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 11203 | } |
Adam Lesinski | ba88e68 | 2015-12-08 12:06:55 -0800 | [diff] [blame] | 11204 | } |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11205 | mNetworkStatsPool.release(delta); |
| 11206 | delta = null; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 11207 | } |
| 11208 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11209 | if (info != null) { |
| 11210 | mHasWifiReporting = true; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 11211 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11212 | // Measured in mAms |
| 11213 | final long txTimeMs = info.getControllerTxTimeMillis(); |
| 11214 | final long rxTimeMs = info.getControllerRxTimeMillis(); |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 11215 | final long scanTimeMs = info.getControllerScanTimeMillis(); |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11216 | final long idleTimeMs = info.getControllerIdleTimeMillis(); |
| 11217 | final long totalTimeMs = txTimeMs + rxTimeMs + idleTimeMs; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 11218 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11219 | long leftOverRxTimeMs = rxTimeMs; |
| 11220 | long leftOverTxTimeMs = txTimeMs; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 11221 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 11222 | if (DEBUG_ENERGY) { |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11223 | Slog.d(TAG, "------ BEGIN WiFi power blaming ------"); |
| 11224 | Slog.d(TAG, " Tx Time: " + txTimeMs + " ms"); |
| 11225 | Slog.d(TAG, " Rx Time: " + rxTimeMs + " ms"); |
| 11226 | Slog.d(TAG, " Idle Time: " + idleTimeMs + " ms"); |
| 11227 | Slog.d(TAG, " Total Time: " + totalTimeMs + " ms"); |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 11228 | Slog.d(TAG, " Scan Time: " + scanTimeMs + " ms"); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 11229 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 11230 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11231 | long totalWifiLockTimeMs = 0; |
| 11232 | long totalScanTimeMs = 0; |
| 11233 | |
| 11234 | // On the first pass, collect some totals so that we can normalize power |
| 11235 | // calculations if we need to. |
| 11236 | final int uidStatsSize = mUidStats.size(); |
| 11237 | for (int i = 0; i < uidStatsSize; i++) { |
| 11238 | final Uid uid = mUidStats.valueAt(i); |
| 11239 | |
| 11240 | // Sum the total scan power for all apps. |
| 11241 | totalScanTimeMs += uid.mWifiScanTimer.getTimeSinceMarkLocked( |
| 11242 | elapsedRealtimeMs * 1000) / 1000; |
| 11243 | |
| 11244 | // Sum the total time holding wifi lock for all apps. |
| 11245 | totalWifiLockTimeMs += uid.mFullWifiLockTimer.getTimeSinceMarkLocked( |
| 11246 | elapsedRealtimeMs * 1000) / 1000; |
| 11247 | } |
| 11248 | |
| 11249 | if (DEBUG_ENERGY && totalScanTimeMs > rxTimeMs) { |
| 11250 | Slog.d(TAG, |
| 11251 | " !Estimated scan time > Actual rx time (" + totalScanTimeMs + " ms > " |
| 11252 | + rxTimeMs + " ms). Normalizing scan time."); |
| 11253 | } |
| 11254 | if (DEBUG_ENERGY && totalScanTimeMs > txTimeMs) { |
| 11255 | Slog.d(TAG, |
| 11256 | " !Estimated scan time > Actual tx time (" + totalScanTimeMs + " ms > " |
| 11257 | + txTimeMs + " ms). Normalizing scan time."); |
| 11258 | } |
| 11259 | |
| 11260 | // Actually assign and distribute power usage to apps. |
| 11261 | for (int i = 0; i < uidStatsSize; i++) { |
| 11262 | final Uid uid = mUidStats.valueAt(i); |
| 11263 | |
| 11264 | long scanTimeSinceMarkMs = uid.mWifiScanTimer.getTimeSinceMarkLocked( |
| 11265 | elapsedRealtimeMs * 1000) / 1000; |
| 11266 | if (scanTimeSinceMarkMs > 0) { |
| 11267 | // Set the new mark so that next time we get new data since this point. |
| 11268 | uid.mWifiScanTimer.setMark(elapsedRealtimeMs); |
| 11269 | |
| 11270 | long scanRxTimeSinceMarkMs = scanTimeSinceMarkMs; |
| 11271 | long scanTxTimeSinceMarkMs = scanTimeSinceMarkMs; |
| 11272 | |
| 11273 | // Our total scan time is more than the reported Tx/Rx time. |
| 11274 | // This is possible because the cost of a scan is approximate. |
| 11275 | // Let's normalize the result so that we evenly blame each app |
| 11276 | // scanning. |
| 11277 | // |
| 11278 | // This means that we may have apps that transmitted/received packets not be |
| 11279 | // blamed for this, but this is fine as scans are relatively more expensive. |
| 11280 | if (totalScanTimeMs > rxTimeMs) { |
| 11281 | scanRxTimeSinceMarkMs = (rxTimeMs * scanRxTimeSinceMarkMs) / |
| 11282 | totalScanTimeMs; |
| 11283 | } |
| 11284 | if (totalScanTimeMs > txTimeMs) { |
| 11285 | scanTxTimeSinceMarkMs = (txTimeMs * scanTxTimeSinceMarkMs) / |
| 11286 | totalScanTimeMs; |
| 11287 | } |
| 11288 | |
| 11289 | if (DEBUG_ENERGY) { |
| 11290 | Slog.d(TAG, " ScanTime for UID " + uid.getUid() + ": Rx:" |
| 11291 | + scanRxTimeSinceMarkMs + " ms Tx:" |
| 11292 | + scanTxTimeSinceMarkMs + " ms)"); |
| 11293 | } |
| 11294 | |
| 11295 | ControllerActivityCounterImpl activityCounter = |
| 11296 | uid.getOrCreateWifiControllerActivityLocked(); |
| 11297 | activityCounter.getRxTimeCounter().addCountLocked(scanRxTimeSinceMarkMs); |
| 11298 | activityCounter.getTxTimeCounters()[0].addCountLocked( |
| 11299 | scanTxTimeSinceMarkMs); |
| 11300 | leftOverRxTimeMs -= scanRxTimeSinceMarkMs; |
| 11301 | leftOverTxTimeMs -= scanTxTimeSinceMarkMs; |
| 11302 | } |
| 11303 | |
| 11304 | // Distribute evenly the power consumed while Idle to each app holding a WiFi |
| 11305 | // lock. |
| 11306 | final long wifiLockTimeSinceMarkMs = |
| 11307 | uid.mFullWifiLockTimer.getTimeSinceMarkLocked( |
| 11308 | elapsedRealtimeMs * 1000) / 1000; |
| 11309 | if (wifiLockTimeSinceMarkMs > 0) { |
| 11310 | // Set the new mark so that next time we get new data since this point. |
| 11311 | uid.mFullWifiLockTimer.setMark(elapsedRealtimeMs); |
| 11312 | |
| 11313 | final long myIdleTimeMs = (wifiLockTimeSinceMarkMs * idleTimeMs) |
| 11314 | / totalWifiLockTimeMs; |
| 11315 | if (DEBUG_ENERGY) { |
| 11316 | Slog.d(TAG, " IdleTime for UID " + uid.getUid() + ": " |
| 11317 | + myIdleTimeMs + " ms"); |
| 11318 | } |
| 11319 | uid.getOrCreateWifiControllerActivityLocked().getIdleTimeCounter() |
| 11320 | .addCountLocked(myIdleTimeMs); |
| 11321 | } |
| 11322 | } |
| 11323 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 11324 | if (DEBUG_ENERGY) { |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11325 | Slog.d(TAG, " New RxPower: " + leftOverRxTimeMs + " ms"); |
| 11326 | Slog.d(TAG, " New TxPower: " + leftOverTxTimeMs + " ms"); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 11327 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 11328 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11329 | // Distribute the remaining Tx power appropriately between all apps that transmitted |
| 11330 | // packets. |
| 11331 | for (int i = 0; i < txPackets.size(); i++) { |
| 11332 | final Uid uid = getUidStatsLocked(txPackets.keyAt(i)); |
| 11333 | final long myTxTimeMs = (txPackets.valueAt(i) * leftOverTxTimeMs) |
| 11334 | / totalTxPackets; |
| 11335 | if (DEBUG_ENERGY) { |
| 11336 | Slog.d(TAG, " TxTime for UID " + uid.getUid() + ": " + myTxTimeMs + " ms"); |
| 11337 | } |
| 11338 | uid.getOrCreateWifiControllerActivityLocked().getTxTimeCounters()[0] |
| 11339 | .addCountLocked(myTxTimeMs); |
| 11340 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 11341 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11342 | // Distribute the remaining Rx power appropriately between all apps that received |
| 11343 | // packets. |
| 11344 | for (int i = 0; i < rxPackets.size(); i++) { |
| 11345 | final Uid uid = getUidStatsLocked(rxPackets.keyAt(i)); |
| 11346 | final long myRxTimeMs = (rxPackets.valueAt(i) * leftOverRxTimeMs) |
| 11347 | / totalRxPackets; |
| 11348 | if (DEBUG_ENERGY) { |
| 11349 | Slog.d(TAG, " RxTime for UID " + uid.getUid() + ": " + myRxTimeMs + " ms"); |
| 11350 | } |
| 11351 | uid.getOrCreateWifiControllerActivityLocked().getRxTimeCounter() |
| 11352 | .addCountLocked(myRxTimeMs); |
| 11353 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 11354 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11355 | // Any left over power use will be picked up by the WiFi category in BatteryStatsHelper. |
| 11356 | |
| 11357 | |
| 11358 | // Update WiFi controller stats. |
| 11359 | mWifiActivity.getRxTimeCounter().addCountLocked(info.getControllerRxTimeMillis()); |
| 11360 | mWifiActivity.getTxTimeCounters()[0].addCountLocked( |
| 11361 | info.getControllerTxTimeMillis()); |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 11362 | mWifiActivity.getScanTimeCounter().addCountLocked( |
| 11363 | info.getControllerScanTimeMillis()); |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11364 | mWifiActivity.getIdleTimeCounter().addCountLocked( |
| 11365 | info.getControllerIdleTimeMillis()); |
| 11366 | |
| 11367 | // POWER_WIFI_CONTROLLER_OPERATING_VOLTAGE is measured in mV, so convert to V. |
| 11368 | final double opVolt = mPowerProfile.getAveragePower( |
| 11369 | PowerProfile.POWER_WIFI_CONTROLLER_OPERATING_VOLTAGE) / 1000.0; |
| 11370 | if (opVolt != 0) { |
| 11371 | // We store the power drain as mAms. |
| 11372 | mWifiActivity.getPowerCounter().addCountLocked( |
| 11373 | (long) (info.getControllerEnergyUsed() / opVolt)); |
| 11374 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 11375 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11376 | } |
| 11377 | } |
| 11378 | |
Chenjie Yu | 8908339 | 2018-01-11 14:53:31 -0800 | [diff] [blame] | 11379 | private ModemActivityInfo mLastModemActivityInfo = |
| 11380 | new ModemActivityInfo(0, 0, 0, new int[0], 0, 0); |
| 11381 | |
Chenjie Yu | a54e54d | 2018-02-14 20:12:52 -0800 | [diff] [blame] | 11382 | private ModemActivityInfo getDeltaModemActivityInfo(ModemActivityInfo activityInfo) { |
| 11383 | if (activityInfo == null) { |
| 11384 | return null; |
| 11385 | } |
| 11386 | int[] txTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS]; |
| 11387 | for (int i = 0; i < ModemActivityInfo.TX_POWER_LEVELS; i++) { |
| 11388 | txTimeMs[i] = activityInfo.getTxTimeMillis()[i] |
| 11389 | - mLastModemActivityInfo.getTxTimeMillis()[i]; |
| 11390 | } |
| 11391 | ModemActivityInfo deltaInfo = new ModemActivityInfo(activityInfo.getTimestamp(), |
| 11392 | activityInfo.getSleepTimeMillis() - mLastModemActivityInfo.getSleepTimeMillis(), |
| 11393 | activityInfo.getIdleTimeMillis() - mLastModemActivityInfo.getIdleTimeMillis(), |
| 11394 | txTimeMs, |
| 11395 | activityInfo.getRxTimeMillis() - mLastModemActivityInfo.getRxTimeMillis(), |
| 11396 | activityInfo.getEnergyUsed() - mLastModemActivityInfo.getEnergyUsed()); |
| 11397 | mLastModemActivityInfo = activityInfo; |
| 11398 | return deltaInfo; |
| 11399 | } |
| 11400 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11401 | /** |
| 11402 | * Distribute Cell radio energy info and network traffic to apps. |
| 11403 | */ |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11404 | public void updateMobileRadioState(@Nullable final ModemActivityInfo activityInfo) { |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 11405 | if (DEBUG_ENERGY) { |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 11406 | Slog.d(TAG, "Updating mobile radio stats with " + activityInfo); |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 11407 | } |
Chenjie Yu | a54e54d | 2018-02-14 20:12:52 -0800 | [diff] [blame] | 11408 | ModemActivityInfo deltaInfo = getDeltaModemActivityInfo(activityInfo); |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 11409 | |
Siddharth Ray | f5e796a | 2018-01-22 18:18:17 -0800 | [diff] [blame] | 11410 | // Add modem tx power to history. |
Chenjie Yu | a54e54d | 2018-02-14 20:12:52 -0800 | [diff] [blame] | 11411 | addModemTxPowerToHistory(deltaInfo); |
Siddharth Ray | f5e796a | 2018-01-22 18:18:17 -0800 | [diff] [blame] | 11412 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11413 | // 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] | 11414 | NetworkStats delta = null; |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11415 | synchronized (mModemNetworkLock) { |
| 11416 | final NetworkStats latestStats = readNetworkStatsLocked(mModemIfaces); |
| 11417 | if (latestStats != null) { |
| 11418 | delta = NetworkStats.subtract(latestStats, mLastModemNetworkStats, null, null, |
| 11419 | mNetworkStatsPool.acquire()); |
| 11420 | mNetworkStatsPool.release(mLastModemNetworkStats); |
| 11421 | mLastModemNetworkStats = latestStats; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 11422 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11423 | } |
| 11424 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11425 | synchronized (this) { |
| 11426 | if (!mOnBatteryInternal) { |
| 11427 | if (delta != null) { |
| 11428 | mNetworkStatsPool.release(delta); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 11429 | } |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11430 | return; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 11431 | } |
| 11432 | |
Chenjie Yu | a54e54d | 2018-02-14 20:12:52 -0800 | [diff] [blame] | 11433 | if (deltaInfo != null) { |
Siddharth Ray | 2038af8 | 2018-01-17 17:40:26 -0800 | [diff] [blame] | 11434 | mHasModemReporting = true; |
| 11435 | mModemActivity.getIdleTimeCounter().addCountLocked( |
Chenjie Yu | a54e54d | 2018-02-14 20:12:52 -0800 | [diff] [blame] | 11436 | deltaInfo.getIdleTimeMillis()); |
Siddharth Ray | ed75470 | 2018-02-15 12:44:37 -0800 | [diff] [blame] | 11437 | mModemActivity.getSleepTimeCounter().addCountLocked( |
| 11438 | deltaInfo.getSleepTimeMillis()); |
Chenjie Yu | a54e54d | 2018-02-14 20:12:52 -0800 | [diff] [blame] | 11439 | mModemActivity.getRxTimeCounter().addCountLocked(deltaInfo.getRxTimeMillis()); |
Siddharth Ray | 2038af8 | 2018-01-17 17:40:26 -0800 | [diff] [blame] | 11440 | for (int lvl = 0; lvl < ModemActivityInfo.TX_POWER_LEVELS; lvl++) { |
| 11441 | mModemActivity.getTxTimeCounters()[lvl] |
Chenjie Yu | a54e54d | 2018-02-14 20:12:52 -0800 | [diff] [blame] | 11442 | .addCountLocked(deltaInfo.getTxTimeMillis()[lvl]); |
Siddharth Ray | 2038af8 | 2018-01-17 17:40:26 -0800 | [diff] [blame] | 11443 | } |
| 11444 | |
| 11445 | // POWER_MODEM_CONTROLLER_OPERATING_VOLTAGE is measured in mV, so convert to V. |
| 11446 | final double opVolt = mPowerProfile.getAveragePower( |
| 11447 | PowerProfile.POWER_MODEM_CONTROLLER_OPERATING_VOLTAGE) / 1000.0; |
| 11448 | if (opVolt != 0) { |
| 11449 | double energyUsed = |
Chenjie Yu | a54e54d | 2018-02-14 20:12:52 -0800 | [diff] [blame] | 11450 | deltaInfo.getSleepTimeMillis() * |
Siddharth Ray | 2038af8 | 2018-01-17 17:40:26 -0800 | [diff] [blame] | 11451 | mPowerProfile.getAveragePower(PowerProfile.POWER_MODEM_CONTROLLER_SLEEP) |
Chenjie Yu | a54e54d | 2018-02-14 20:12:52 -0800 | [diff] [blame] | 11452 | + deltaInfo.getIdleTimeMillis() * |
Siddharth Ray | 2038af8 | 2018-01-17 17:40:26 -0800 | [diff] [blame] | 11453 | mPowerProfile.getAveragePower(PowerProfile.POWER_MODEM_CONTROLLER_IDLE) |
Chenjie Yu | a54e54d | 2018-02-14 20:12:52 -0800 | [diff] [blame] | 11454 | + deltaInfo.getRxTimeMillis() * |
Siddharth Ray | 2038af8 | 2018-01-17 17:40:26 -0800 | [diff] [blame] | 11455 | mPowerProfile.getAveragePower(PowerProfile.POWER_MODEM_CONTROLLER_RX); |
Chenjie Yu | a54e54d | 2018-02-14 20:12:52 -0800 | [diff] [blame] | 11456 | int[] txTimeMs = deltaInfo.getTxTimeMillis(); |
Chenjie Yu | 8908339 | 2018-01-11 14:53:31 -0800 | [diff] [blame] | 11457 | for (int i = 0; i < Math.min(txTimeMs.length, |
Chenjie Yu | a54e54d | 2018-02-14 20:12:52 -0800 | [diff] [blame] | 11458 | SignalStrength.NUM_SIGNAL_STRENGTH_BINS); i++) { |
Chenjie Yu | 8908339 | 2018-01-11 14:53:31 -0800 | [diff] [blame] | 11459 | energyUsed += txTimeMs[i] * mPowerProfile.getAveragePower( |
Chenjie Yu | a54e54d | 2018-02-14 20:12:52 -0800 | [diff] [blame] | 11460 | PowerProfile.POWER_MODEM_CONTROLLER_TX, i); |
Siddharth Ray | 2038af8 | 2018-01-17 17:40:26 -0800 | [diff] [blame] | 11461 | } |
| 11462 | |
| 11463 | // We store the power drain as mAms. |
| 11464 | mModemActivity.getPowerCounter().addCountLocked((long) energyUsed); |
| 11465 | } |
| 11466 | } |
| 11467 | |
Adam Lesinski | b3a1bad | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11468 | final long elapsedRealtimeMs = mClocks.elapsedRealtime(); |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11469 | long radioTime = mMobileRadioActivePerAppTimer.getTimeSinceMarkLocked( |
| 11470 | elapsedRealtimeMs * 1000); |
| 11471 | mMobileRadioActivePerAppTimer.setMark(elapsedRealtimeMs); |
| 11472 | |
| 11473 | long totalRxPackets = 0; |
| 11474 | long totalTxPackets = 0; |
| 11475 | if (delta != null) { |
| 11476 | NetworkStats.Entry entry = new NetworkStats.Entry(); |
| 11477 | final int size = delta.size(); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 11478 | for (int i = 0; i < size; i++) { |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11479 | entry = delta.getValues(i, entry); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 11480 | if (entry.rxPackets == 0 && entry.txPackets == 0) { |
| 11481 | continue; |
| 11482 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11483 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11484 | if (DEBUG_ENERGY) { |
| 11485 | Slog.d(TAG, "Mobile uid " + entry.uid + ": delta rx=" + entry.rxBytes |
| 11486 | + " tx=" + entry.txBytes + " rxPackets=" + entry.rxPackets |
| 11487 | + " txPackets=" + entry.txPackets); |
| 11488 | } |
| 11489 | |
| 11490 | totalRxPackets += entry.rxPackets; |
| 11491 | totalTxPackets += entry.txPackets; |
| 11492 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 11493 | final Uid u = getUidStatsLocked(mapUid(entry.uid)); |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11494 | u.noteNetworkActivityLocked(NETWORK_MOBILE_RX_DATA, entry.rxBytes, |
| 11495 | entry.rxPackets); |
| 11496 | u.noteNetworkActivityLocked(NETWORK_MOBILE_TX_DATA, entry.txBytes, |
| 11497 | entry.txPackets); |
| 11498 | if (entry.set == NetworkStats.SET_DEFAULT) { // Background transfers |
| 11499 | u.noteNetworkActivityLocked(NETWORK_MOBILE_BG_RX_DATA, |
| 11500 | entry.rxBytes, entry.rxPackets); |
| 11501 | u.noteNetworkActivityLocked(NETWORK_MOBILE_BG_TX_DATA, |
| 11502 | entry.txBytes, entry.txPackets); |
| 11503 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 11504 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11505 | mNetworkByteActivityCounters[NETWORK_MOBILE_RX_DATA].addCountLocked( |
| 11506 | entry.rxBytes); |
| 11507 | mNetworkByteActivityCounters[NETWORK_MOBILE_TX_DATA].addCountLocked( |
| 11508 | entry.txBytes); |
| 11509 | mNetworkPacketActivityCounters[NETWORK_MOBILE_RX_DATA].addCountLocked( |
| 11510 | entry.rxPackets); |
| 11511 | mNetworkPacketActivityCounters[NETWORK_MOBILE_TX_DATA].addCountLocked( |
| 11512 | entry.txPackets); |
| 11513 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 11514 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11515 | // Now distribute proportional blame to the apps that did networking. |
| 11516 | long totalPackets = totalRxPackets + totalTxPackets; |
| 11517 | if (totalPackets > 0) { |
| 11518 | for (int i = 0; i < size; i++) { |
| 11519 | entry = delta.getValues(i, entry); |
| 11520 | if (entry.rxPackets == 0 && entry.txPackets == 0) { |
| 11521 | continue; |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 11522 | } |
| 11523 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11524 | final Uid u = getUidStatsLocked(mapUid(entry.uid)); |
| 11525 | |
| 11526 | // Distribute total radio active time in to this app. |
| 11527 | final long appPackets = entry.rxPackets + entry.txPackets; |
| 11528 | final long appRadioTime = (radioTime * appPackets) / totalPackets; |
| 11529 | u.noteMobileRadioActiveTimeLocked(appRadioTime); |
| 11530 | |
| 11531 | // Remove this app from the totals, so that we don't lose any time |
| 11532 | // due to rounding. |
| 11533 | radioTime -= appRadioTime; |
| 11534 | totalPackets -= appPackets; |
| 11535 | |
Chenjie Yu | a54e54d | 2018-02-14 20:12:52 -0800 | [diff] [blame] | 11536 | if (deltaInfo != null) { |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11537 | ControllerActivityCounterImpl activityCounter = |
| 11538 | u.getOrCreateModemControllerActivityLocked(); |
| 11539 | if (totalRxPackets > 0 && entry.rxPackets > 0) { |
Chenjie Yu | a54e54d | 2018-02-14 20:12:52 -0800 | [diff] [blame] | 11540 | final long rxMs = (entry.rxPackets * deltaInfo.getRxTimeMillis()) |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11541 | / totalRxPackets; |
| 11542 | activityCounter.getRxTimeCounter().addCountLocked(rxMs); |
| 11543 | } |
| 11544 | |
| 11545 | if (totalTxPackets > 0 && entry.txPackets > 0) { |
| 11546 | for (int lvl = 0; lvl < ModemActivityInfo.TX_POWER_LEVELS; lvl++) { |
| 11547 | long txMs = |
Chenjie Yu | a54e54d | 2018-02-14 20:12:52 -0800 | [diff] [blame] | 11548 | entry.txPackets * deltaInfo.getTxTimeMillis()[lvl]; |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11549 | txMs /= totalTxPackets; |
| 11550 | activityCounter.getTxTimeCounters()[lvl].addCountLocked(txMs); |
| 11551 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 11552 | } |
| 11553 | } |
| 11554 | } |
| 11555 | } |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11556 | |
| 11557 | if (radioTime > 0) { |
| 11558 | // Whoops, there is some radio time we can't blame on an app! |
| 11559 | mMobileRadioActiveUnknownTime.addCountLocked(radioTime); |
| 11560 | mMobileRadioActiveUnknownCount.addCountLocked(1); |
| 11561 | } |
| 11562 | |
| 11563 | mNetworkStatsPool.release(delta); |
| 11564 | delta = null; |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 11565 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11566 | } |
| 11567 | } |
| 11568 | |
| 11569 | /** |
Siddharth Ray | f5e796a | 2018-01-22 18:18:17 -0800 | [diff] [blame] | 11570 | * Add modem tx power to history |
| 11571 | * Device is said to be in high cellular transmit power when it has spent most of the transmit |
| 11572 | * time at the highest power level. |
| 11573 | * @param activityInfo |
| 11574 | */ |
Siddharth Ray | a67fb56 | 2018-02-28 13:46:16 -0800 | [diff] [blame] | 11575 | private synchronized void addModemTxPowerToHistory(final ModemActivityInfo activityInfo) { |
Siddharth Ray | f5e796a | 2018-01-22 18:18:17 -0800 | [diff] [blame] | 11576 | if (activityInfo == null) { |
| 11577 | return; |
| 11578 | } |
| 11579 | int[] txTimeMs = activityInfo.getTxTimeMillis(); |
| 11580 | if (txTimeMs == null || txTimeMs.length != ModemActivityInfo.TX_POWER_LEVELS) { |
| 11581 | return; |
| 11582 | } |
| 11583 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 11584 | final long uptime = mClocks.uptimeMillis(); |
| 11585 | int levelMaxTimeSpent = 0; |
| 11586 | for (int i = 1; i < txTimeMs.length; i++) { |
| 11587 | if (txTimeMs[i] > txTimeMs[levelMaxTimeSpent]) { |
| 11588 | levelMaxTimeSpent = i; |
| 11589 | } |
| 11590 | } |
| 11591 | if (levelMaxTimeSpent == ModemActivityInfo.TX_POWER_LEVELS - 1) { |
| 11592 | if (!mIsCellularTxPowerHigh) { |
| 11593 | mHistoryCur.states2 |= HistoryItem.STATE2_CELLULAR_HIGH_TX_POWER_FLAG; |
| 11594 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 11595 | mIsCellularTxPowerHigh = true; |
| 11596 | } |
| 11597 | return; |
| 11598 | } |
| 11599 | if (mIsCellularTxPowerHigh) { |
| 11600 | mHistoryCur.states2 &= ~HistoryItem.STATE2_CELLULAR_HIGH_TX_POWER_FLAG; |
| 11601 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 11602 | mIsCellularTxPowerHigh = false; |
| 11603 | } |
| 11604 | return; |
| 11605 | } |
| 11606 | |
Mike Ma | 561a8d9 | 2018-03-20 18:24:05 -0700 | [diff] [blame] | 11607 | private final class BluetoothActivityInfoCache { |
| 11608 | long idleTimeMs; |
| 11609 | long rxTimeMs; |
| 11610 | long txTimeMs; |
| 11611 | long energy; |
| 11612 | |
| 11613 | SparseLongArray uidRxBytes = new SparseLongArray(); |
| 11614 | SparseLongArray uidTxBytes = new SparseLongArray(); |
| 11615 | |
| 11616 | void set(BluetoothActivityEnergyInfo info) { |
| 11617 | idleTimeMs = info.getControllerIdleTimeMillis(); |
| 11618 | rxTimeMs = info.getControllerRxTimeMillis(); |
| 11619 | txTimeMs = info.getControllerTxTimeMillis(); |
| 11620 | energy = info.getControllerEnergyUsed(); |
| 11621 | if (info.getUidTraffic() != null) { |
| 11622 | for (UidTraffic traffic : info.getUidTraffic()) { |
| 11623 | uidRxBytes.put(traffic.getUid(), traffic.getRxBytes()); |
| 11624 | uidTxBytes.put(traffic.getUid(), traffic.getTxBytes()); |
| 11625 | } |
| 11626 | } |
| 11627 | } |
| 11628 | } |
| 11629 | |
| 11630 | private final BluetoothActivityInfoCache mLastBluetoothActivityInfo |
| 11631 | = new BluetoothActivityInfoCache(); |
| 11632 | |
Siddharth Ray | f5e796a | 2018-01-22 18:18:17 -0800 | [diff] [blame] | 11633 | /** |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11634 | * Distribute Bluetooth energy info and network traffic to apps. |
Mike Ma | 561a8d9 | 2018-03-20 18:24:05 -0700 | [diff] [blame] | 11635 | * |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11636 | * @param info The energy information from the bluetooth controller. |
| 11637 | */ |
| 11638 | public void updateBluetoothStateLocked(@Nullable final BluetoothActivityEnergyInfo info) { |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 11639 | if (DEBUG_ENERGY) { |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 11640 | Slog.d(TAG, "Updating bluetooth stats: " + info); |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 11641 | } |
| 11642 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 11643 | if (info == null || !mOnBatteryInternal) { |
| 11644 | return; |
| 11645 | } |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 11646 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 11647 | mHasBluetoothReporting = true; |
| 11648 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 11649 | final long elapsedRealtimeMs = mClocks.elapsedRealtime(); |
Mike Ma | 561a8d9 | 2018-03-20 18:24:05 -0700 | [diff] [blame] | 11650 | final long rxTimeMs = |
| 11651 | info.getControllerRxTimeMillis() - mLastBluetoothActivityInfo.rxTimeMs; |
| 11652 | final long txTimeMs = |
| 11653 | info.getControllerTxTimeMillis() - mLastBluetoothActivityInfo.txTimeMs; |
| 11654 | final long idleTimeMs = |
| 11655 | info.getControllerIdleTimeMillis() - mLastBluetoothActivityInfo.idleTimeMs; |
| 11656 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 11657 | if (DEBUG_ENERGY) { |
| 11658 | Slog.d(TAG, "------ BEGIN BLE power blaming ------"); |
| 11659 | Slog.d(TAG, " Tx Time: " + txTimeMs + " ms"); |
| 11660 | Slog.d(TAG, " Rx Time: " + rxTimeMs + " ms"); |
Chenjie Yu | 8908339 | 2018-01-11 14:53:31 -0800 | [diff] [blame] | 11661 | Slog.d(TAG, " Idle Time: " + idleTimeMs + " ms"); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 11662 | } |
| 11663 | |
| 11664 | long totalScanTimeMs = 0; |
| 11665 | |
| 11666 | final int uidCount = mUidStats.size(); |
| 11667 | for (int i = 0; i < uidCount; i++) { |
| 11668 | final Uid u = mUidStats.valueAt(i); |
| 11669 | if (u.mBluetoothScanTimer == null) { |
| 11670 | continue; |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 11671 | } |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 11672 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 11673 | totalScanTimeMs += u.mBluetoothScanTimer.getTimeSinceMarkLocked( |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 11674 | elapsedRealtimeMs * 1000) / 1000; |
| 11675 | } |
| 11676 | |
| 11677 | final boolean normalizeScanRxTime = (totalScanTimeMs > rxTimeMs); |
| 11678 | final boolean normalizeScanTxTime = (totalScanTimeMs > txTimeMs); |
| 11679 | |
| 11680 | if (DEBUG_ENERGY) { |
| 11681 | Slog.d(TAG, "Normalizing scan power for RX=" + normalizeScanRxTime |
| 11682 | + " TX=" + normalizeScanTxTime); |
| 11683 | } |
| 11684 | |
| 11685 | long leftOverRxTimeMs = rxTimeMs; |
| 11686 | long leftOverTxTimeMs = txTimeMs; |
| 11687 | |
| 11688 | for (int i = 0; i < uidCount; i++) { |
| 11689 | final Uid u = mUidStats.valueAt(i); |
| 11690 | if (u.mBluetoothScanTimer == null) { |
| 11691 | continue; |
| 11692 | } |
| 11693 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 11694 | long scanTimeSinceMarkMs = u.mBluetoothScanTimer.getTimeSinceMarkLocked( |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 11695 | elapsedRealtimeMs * 1000) / 1000; |
| 11696 | if (scanTimeSinceMarkMs > 0) { |
| 11697 | // Set the new mark so that next time we get new data since this point. |
| 11698 | u.mBluetoothScanTimer.setMark(elapsedRealtimeMs); |
| 11699 | |
| 11700 | long scanTimeRxSinceMarkMs = scanTimeSinceMarkMs; |
| 11701 | long scanTimeTxSinceMarkMs = scanTimeSinceMarkMs; |
| 11702 | |
| 11703 | if (normalizeScanRxTime) { |
| 11704 | // Scan time is longer than the total rx time in the controller, |
| 11705 | // so distribute the scan time proportionately. This means regular traffic |
| 11706 | // will not blamed, but scans are more expensive anyways. |
| 11707 | scanTimeRxSinceMarkMs = (rxTimeMs * scanTimeRxSinceMarkMs) / totalScanTimeMs; |
| 11708 | } |
| 11709 | |
| 11710 | if (normalizeScanTxTime) { |
| 11711 | // Scan time is longer than the total tx time in the controller, |
| 11712 | // so distribute the scan time proportionately. This means regular traffic |
| 11713 | // will not blamed, but scans are more expensive anyways. |
| 11714 | scanTimeTxSinceMarkMs = (txTimeMs * scanTimeTxSinceMarkMs) / totalScanTimeMs; |
| 11715 | } |
| 11716 | |
| 11717 | final ControllerActivityCounterImpl counter = |
| 11718 | u.getOrCreateBluetoothControllerActivityLocked(); |
| 11719 | counter.getRxTimeCounter().addCountLocked(scanTimeRxSinceMarkMs); |
| 11720 | counter.getTxTimeCounters()[0].addCountLocked(scanTimeTxSinceMarkMs); |
| 11721 | |
| 11722 | leftOverRxTimeMs -= scanTimeRxSinceMarkMs; |
| 11723 | leftOverTxTimeMs -= scanTimeTxSinceMarkMs; |
| 11724 | } |
| 11725 | } |
| 11726 | |
| 11727 | if (DEBUG_ENERGY) { |
Mike Ma | 561a8d9 | 2018-03-20 18:24:05 -0700 | [diff] [blame] | 11728 | Slog.d(TAG, "Left over time for traffic RX=" + leftOverRxTimeMs + " TX=" |
| 11729 | + leftOverTxTimeMs); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 11730 | } |
| 11731 | |
| 11732 | // |
| 11733 | // Now distribute blame to apps that did bluetooth traffic. |
| 11734 | // |
| 11735 | |
| 11736 | long totalTxBytes = 0; |
| 11737 | long totalRxBytes = 0; |
| 11738 | |
| 11739 | final UidTraffic[] uidTraffic = info.getUidTraffic(); |
Mike Ma | 561a8d9 | 2018-03-20 18:24:05 -0700 | [diff] [blame] | 11740 | final int numUids = uidTraffic != null ? uidTraffic.length : 0; |
| 11741 | for (int i = 0; i < numUids; i++) { |
| 11742 | final UidTraffic traffic = uidTraffic[i]; |
| 11743 | final long rxBytes = traffic.getRxBytes() - mLastBluetoothActivityInfo.uidRxBytes.get( |
| 11744 | traffic.getUid()); |
| 11745 | final long txBytes = traffic.getTxBytes() - mLastBluetoothActivityInfo.uidTxBytes.get( |
| 11746 | traffic.getUid()); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 11747 | |
| 11748 | // Add to the global counters. |
Mike Ma | 561a8d9 | 2018-03-20 18:24:05 -0700 | [diff] [blame] | 11749 | mNetworkByteActivityCounters[NETWORK_BT_RX_DATA].addCountLocked(rxBytes); |
| 11750 | mNetworkByteActivityCounters[NETWORK_BT_TX_DATA].addCountLocked(txBytes); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 11751 | |
| 11752 | // Add to the UID counters. |
| 11753 | final Uid u = getUidStatsLocked(mapUid(traffic.getUid())); |
Mike Ma | 561a8d9 | 2018-03-20 18:24:05 -0700 | [diff] [blame] | 11754 | u.noteNetworkActivityLocked(NETWORK_BT_RX_DATA, rxBytes, 0); |
| 11755 | u.noteNetworkActivityLocked(NETWORK_BT_TX_DATA, txBytes, 0); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 11756 | |
| 11757 | // Calculate the total traffic. |
Mike Ma | 561a8d9 | 2018-03-20 18:24:05 -0700 | [diff] [blame] | 11758 | totalRxBytes += rxBytes; |
| 11759 | totalTxBytes += txBytes; |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 11760 | } |
| 11761 | |
Mike Ma | 561a8d9 | 2018-03-20 18:24:05 -0700 | [diff] [blame] | 11762 | if ((totalTxBytes != 0 || totalRxBytes != 0) && (leftOverRxTimeMs != 0 |
| 11763 | || leftOverTxTimeMs != 0)) { |
| 11764 | for (int i = 0; i < numUids; i++) { |
| 11765 | final UidTraffic traffic = uidTraffic[i]; |
| 11766 | final int uid = traffic.getUid(); |
| 11767 | final long rxBytes = |
| 11768 | traffic.getRxBytes() - mLastBluetoothActivityInfo.uidRxBytes.get(uid); |
| 11769 | final long txBytes = |
| 11770 | traffic.getTxBytes() - mLastBluetoothActivityInfo.uidTxBytes.get(uid); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 11771 | |
Mike Ma | 561a8d9 | 2018-03-20 18:24:05 -0700 | [diff] [blame] | 11772 | final Uid u = getUidStatsLocked(mapUid(uid)); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 11773 | final ControllerActivityCounterImpl counter = |
| 11774 | u.getOrCreateBluetoothControllerActivityLocked(); |
| 11775 | |
Mike Ma | 561a8d9 | 2018-03-20 18:24:05 -0700 | [diff] [blame] | 11776 | if (totalRxBytes > 0 && rxBytes > 0) { |
| 11777 | final long timeRxMs = (leftOverRxTimeMs * rxBytes) / totalRxBytes; |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 11778 | if (DEBUG_ENERGY) { |
Mike Ma | 561a8d9 | 2018-03-20 18:24:05 -0700 | [diff] [blame] | 11779 | Slog.d(TAG, "UID=" + uid + " rx_bytes=" + rxBytes + " rx_time=" + timeRxMs); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 11780 | } |
| 11781 | counter.getRxTimeCounter().addCountLocked(timeRxMs); |
| 11782 | leftOverRxTimeMs -= timeRxMs; |
| 11783 | } |
| 11784 | |
Mike Ma | 561a8d9 | 2018-03-20 18:24:05 -0700 | [diff] [blame] | 11785 | if (totalTxBytes > 0 && txBytes > 0) { |
| 11786 | final long timeTxMs = (leftOverTxTimeMs * txBytes) / totalTxBytes; |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 11787 | if (DEBUG_ENERGY) { |
Mike Ma | 561a8d9 | 2018-03-20 18:24:05 -0700 | [diff] [blame] | 11788 | Slog.d(TAG, "UID=" + uid + " tx_bytes=" + txBytes + " tx_time=" + timeTxMs); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 11789 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 11790 | counter.getTxTimeCounters()[0].addCountLocked(timeTxMs); |
| 11791 | leftOverTxTimeMs -= timeTxMs; |
| 11792 | } |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 11793 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11794 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 11795 | |
Chenjie Yu | 8908339 | 2018-01-11 14:53:31 -0800 | [diff] [blame] | 11796 | mBluetoothActivity.getRxTimeCounter().addCountLocked(rxTimeMs); |
| 11797 | mBluetoothActivity.getTxTimeCounters()[0].addCountLocked(txTimeMs); |
| 11798 | mBluetoothActivity.getIdleTimeCounter().addCountLocked(idleTimeMs); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 11799 | |
| 11800 | // POWER_BLUETOOTH_CONTROLLER_OPERATING_VOLTAGE is measured in mV, so convert to V. |
| 11801 | final double opVolt = mPowerProfile.getAveragePower( |
| 11802 | PowerProfile.POWER_BLUETOOTH_CONTROLLER_OPERATING_VOLTAGE) / 1000.0; |
| 11803 | if (opVolt != 0) { |
| 11804 | // We store the power drain as mAms. |
| 11805 | mBluetoothActivity.getPowerCounter().addCountLocked( |
Mike Ma | 561a8d9 | 2018-03-20 18:24:05 -0700 | [diff] [blame] | 11806 | (long) ((info.getControllerEnergyUsed() - mLastBluetoothActivityInfo.energy) |
| 11807 | / opVolt)); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 11808 | } |
Mike Ma | 561a8d9 | 2018-03-20 18:24:05 -0700 | [diff] [blame] | 11809 | mLastBluetoothActivityInfo.set(info); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11810 | } |
| 11811 | |
| 11812 | /** |
Bookatz | 0b8a050 | 2017-09-13 11:51:52 -0700 | [diff] [blame] | 11813 | * Read and record Resource Power Manager (RPM) state and voter times. |
| 11814 | * If RPM stats were fetched more recently than RPM_STATS_UPDATE_FREQ_MS ago, uses the old data |
| 11815 | * instead of fetching it anew. |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 11816 | */ |
| 11817 | public void updateRpmStatsLocked() { |
| 11818 | if (mPlatformIdleStateCallback == null) return; |
Bookatz | 0b8a050 | 2017-09-13 11:51:52 -0700 | [diff] [blame] | 11819 | long now = SystemClock.elapsedRealtime(); |
| 11820 | if (now - mLastRpmStatsUpdateTimeMs >= RPM_STATS_UPDATE_FREQ_MS) { |
| 11821 | mPlatformIdleStateCallback.fillLowPowerStats(mTmpRpmStats); |
| 11822 | mLastRpmStatsUpdateTimeMs = now; |
| 11823 | } |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 11824 | |
| 11825 | for (Map.Entry<String, RpmStats.PowerStatePlatformSleepState> pstate |
| 11826 | : mTmpRpmStats.mPlatformLowPowerStats.entrySet()) { |
| 11827 | |
| 11828 | // Update values for this platform state. |
| 11829 | final String pName = pstate.getKey(); |
| 11830 | final long pTimeUs = pstate.getValue().mTimeMs * 1000; |
| 11831 | final int pCount = pstate.getValue().mCount; |
| 11832 | getRpmTimerLocked(pName).update(pTimeUs, pCount); |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 11833 | if (SCREEN_OFF_RPM_STATS_ENABLED) { |
| 11834 | getScreenOffRpmTimerLocked(pName).update(pTimeUs, pCount); |
| 11835 | } |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 11836 | |
| 11837 | // Update values for each voter of this platform state. |
| 11838 | for (Map.Entry<String, RpmStats.PowerStateElement> voter |
| 11839 | : pstate.getValue().mVoters.entrySet()) { |
| 11840 | final String vName = pName + "." + voter.getKey(); |
| 11841 | final long vTimeUs = voter.getValue().mTimeMs * 1000; |
| 11842 | final int vCount = voter.getValue().mCount; |
| 11843 | getRpmTimerLocked(vName).update(vTimeUs, vCount); |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 11844 | if (SCREEN_OFF_RPM_STATS_ENABLED) { |
| 11845 | getScreenOffRpmTimerLocked(vName).update(vTimeUs, vCount); |
| 11846 | } |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 11847 | } |
| 11848 | } |
| 11849 | |
| 11850 | for (Map.Entry<String, RpmStats.PowerStateSubsystem> subsys |
| 11851 | : mTmpRpmStats.mSubsystemLowPowerStats.entrySet()) { |
| 11852 | |
| 11853 | final String subsysName = subsys.getKey(); |
| 11854 | for (Map.Entry<String, RpmStats.PowerStateElement> sstate |
| 11855 | : subsys.getValue().mStates.entrySet()) { |
| 11856 | final String name = subsysName + "." + sstate.getKey(); |
| 11857 | final long timeUs = sstate.getValue().mTimeMs * 1000; |
| 11858 | final int count = sstate.getValue().mCount; |
| 11859 | getRpmTimerLocked(name).update(timeUs, count); |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 11860 | if (SCREEN_OFF_RPM_STATS_ENABLED) { |
| 11861 | getScreenOffRpmTimerLocked(name).update(timeUs, count); |
| 11862 | } |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 11863 | } |
| 11864 | } |
| 11865 | } |
| 11866 | |
| 11867 | /** |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11868 | * Read and distribute kernel wake lock use across apps. |
| 11869 | */ |
| 11870 | public void updateKernelWakelocksLocked() { |
| 11871 | final KernelWakelockStats wakelockStats = mKernelWakelockReader.readKernelWakelockStats( |
| 11872 | mTmpWakelockStats); |
| 11873 | if (wakelockStats == null) { |
| 11874 | // Not crashing might make board bringup easier. |
| 11875 | Slog.w(TAG, "Couldn't get kernel wake lock stats"); |
| 11876 | return; |
| 11877 | } |
| 11878 | |
| 11879 | for (Map.Entry<String, KernelWakelockStats.Entry> ent : wakelockStats.entrySet()) { |
| 11880 | String name = ent.getKey(); |
| 11881 | KernelWakelockStats.Entry kws = ent.getValue(); |
| 11882 | |
| 11883 | SamplingTimer kwlt = mKernelWakelockStats.get(name); |
| 11884 | if (kwlt == null) { |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 11885 | kwlt = new SamplingTimer(mClocks, mOnBatteryScreenOffTimeBase); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11886 | mKernelWakelockStats.put(name, kwlt); |
| 11887 | } |
Adam Lesinski | d84ad30 | 2016-05-17 18:31:02 -0700 | [diff] [blame] | 11888 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 11889 | kwlt.update(kws.mTotalTime, kws.mCount); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11890 | kwlt.setUpdateVersion(kws.mVersion); |
| 11891 | } |
| 11892 | |
Adam Lesinski | fbabe7d | 2015-08-03 14:37:38 -0700 | [diff] [blame] | 11893 | int numWakelocksSetStale = 0; |
Adam Lesinski | d84ad30 | 2016-05-17 18:31:02 -0700 | [diff] [blame] | 11894 | // Set timers to stale if they didn't appear in /d/wakeup_sources (or /proc/wakelocks) |
| 11895 | // this time. |
| 11896 | for (Map.Entry<String, SamplingTimer> ent : mKernelWakelockStats.entrySet()) { |
| 11897 | SamplingTimer st = ent.getValue(); |
| 11898 | if (st.getUpdateVersion() != wakelockStats.kernelWakelockVersion) { |
| 11899 | st.endSample(); |
| 11900 | numWakelocksSetStale++; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11901 | } |
| 11902 | } |
Adam Lesinski | fbabe7d | 2015-08-03 14:37:38 -0700 | [diff] [blame] | 11903 | |
Adam Lesinski | d84ad30 | 2016-05-17 18:31:02 -0700 | [diff] [blame] | 11904 | // Record whether we've seen a non-zero time (for debugging b/22716723). |
| 11905 | if (wakelockStats.isEmpty()) { |
Adam Lesinski | fbabe7d | 2015-08-03 14:37:38 -0700 | [diff] [blame] | 11906 | Slog.wtf(TAG, "All kernel wakelocks had time of zero"); |
| 11907 | } |
| 11908 | |
| 11909 | if (numWakelocksSetStale == mKernelWakelockStats.size()) { |
| 11910 | Slog.wtf(TAG, "All kernel wakelocks were set stale. new version=" + |
| 11911 | wakelockStats.kernelWakelockVersion); |
| 11912 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11913 | } |
| 11914 | |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 11915 | // We use an anonymous class to access these variables, |
| 11916 | // so they can't live on the stack or they'd have to be |
| 11917 | // final MutableLong objects (more allocations). |
| 11918 | // Used in updateCpuTimeLocked(). |
| 11919 | long mTempTotalCpuUserTimeUs; |
| 11920 | long mTempTotalCpuSystemTimeUs; |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 11921 | long[][] mWakeLockAllocationsUs; |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 11922 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 11923 | /** |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 11924 | * Reads the newest memory stats from the kernel. |
| 11925 | */ |
| 11926 | public void updateKernelMemoryBandwidthLocked() { |
| 11927 | mKernelMemoryBandwidthStats.updateStats(); |
| 11928 | LongSparseLongArray bandwidthEntries = mKernelMemoryBandwidthStats.getBandwidthEntries(); |
| 11929 | final int bandwidthEntryCount = bandwidthEntries.size(); |
| 11930 | int index; |
| 11931 | for (int i = 0; i < bandwidthEntryCount; i++) { |
| 11932 | SamplingTimer timer; |
| 11933 | if ((index = mKernelMemoryStats.indexOfKey(bandwidthEntries.keyAt(i))) >= 0) { |
| 11934 | timer = mKernelMemoryStats.valueAt(index); |
| 11935 | } else { |
| 11936 | timer = new SamplingTimer(mClocks, mOnBatteryTimeBase); |
| 11937 | mKernelMemoryStats.put(bandwidthEntries.keyAt(i), timer); |
| 11938 | } |
| 11939 | timer.update(bandwidthEntries.valueAt(i), 1); |
| 11940 | if (DEBUG_MEMORY) { |
| 11941 | Slog.d(TAG, String.format("Added entry %d and updated timer to: " |
| 11942 | + "mUnpluggedReportedTotalTime %d size %d", bandwidthEntries.keyAt(i), |
| 11943 | mKernelMemoryStats.get( |
| 11944 | bandwidthEntries.keyAt(i)).mUnpluggedReportedTotalTime, |
| 11945 | mKernelMemoryStats.size())); |
| 11946 | } |
| 11947 | } |
| 11948 | } |
| 11949 | |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 11950 | public boolean isOnBatteryLocked() { |
| 11951 | return mOnBatteryTimeBase.isRunning(); |
| 11952 | } |
| 11953 | |
| 11954 | public boolean isOnBatteryScreenOffLocked() { |
| 11955 | return mOnBatteryScreenOffTimeBase.isRunning(); |
| 11956 | } |
| 11957 | |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 11958 | /** |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 11959 | * Read and distribute CPU usage across apps. If their are partial wakelocks being held |
| 11960 | * and we are on battery with screen off, we give more of the cpu time to those apps holding |
| 11961 | * wakelocks. If the screen is on, we just assign the actual cpu time an app used. |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 11962 | * It's possible this will be invoked after the internal battery/screen states are updated, so |
| 11963 | * passing the appropriate battery/screen states to try attribute the cpu times to correct |
| 11964 | * buckets. |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 11965 | */ |
Andreas Gampe | 3f24e69 | 2018-02-05 13:24:28 -0800 | [diff] [blame] | 11966 | @GuardedBy("this") |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 11967 | public void updateCpuTimeLocked(boolean onBattery, boolean onBatteryScreenOff) { |
Adam Lesinski | 52290c9c | 2015-09-21 16:54:52 -0700 | [diff] [blame] | 11968 | if (mPowerProfile == null) { |
| 11969 | return; |
| 11970 | } |
| 11971 | |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 11972 | if (DEBUG_ENERGY_CPU) { |
| 11973 | Slog.d(TAG, "!Cpu updating!"); |
| 11974 | } |
| 11975 | |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 11976 | if (mCpuFreqs == null) { |
| 11977 | mCpuFreqs = mKernelUidCpuFreqTimeReader.readFreqs(mPowerProfile); |
| 11978 | } |
| 11979 | |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 11980 | // Calculate the wakelocks we have to distribute amongst. The system is excluded as it is |
| 11981 | // usually holding the wakelock on behalf of an app. |
| 11982 | // And Only distribute cpu power to wakelocks if the screen is off and we're on battery. |
| 11983 | ArrayList<StopwatchTimer> partialTimersToConsider = null; |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 11984 | if (onBatteryScreenOff) { |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 11985 | partialTimersToConsider = new ArrayList<>(); |
| 11986 | for (int i = mPartialTimers.size() - 1; i >= 0; --i) { |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 11987 | final StopwatchTimer timer = mPartialTimers.get(i); |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 11988 | // Since the collection and blaming of wakelocks can be scheduled to run after |
| 11989 | // some delay, the mPartialTimers list may have new entries. We can't blame |
| 11990 | // the newly added timer for past cpu time, so we only consider timers that |
| 11991 | // were present for one round of collection. Once a timer has gone through |
| 11992 | // a round of collection, its mInList field is set to true. |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 11993 | if (timer.mInList && timer.mUid != null && timer.mUid.mUid != Process.SYSTEM_UID) { |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 11994 | partialTimersToConsider.add(timer); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 11995 | } |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 11996 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 11997 | } |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 11998 | markPartialTimersAsEligible(); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 11999 | |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 12000 | // When the battery is not on, we don't attribute the cpu times to any timers but we still |
| 12001 | // need to take the snapshots. |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 12002 | if (!onBattery) { |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 12003 | mKernelUidCpuTimeReader.readDelta(null); |
| 12004 | mKernelUidCpuFreqTimeReader.readDelta(null); |
Mike Ma | 234d182 | 2018-03-13 18:53:21 -0700 | [diff] [blame] | 12005 | mNumAllUidCpuTimeReads += 2; |
Mike Ma | fae87da | 2018-01-19 20:07:20 -0800 | [diff] [blame] | 12006 | if (mConstants.TRACK_CPU_ACTIVE_CLUSTER_TIME) { |
| 12007 | mKernelUidCpuActiveTimeReader.readDelta(null); |
| 12008 | mKernelUidCpuClusterTimeReader.readDelta(null); |
Mike Ma | 234d182 | 2018-03-13 18:53:21 -0700 | [diff] [blame] | 12009 | mNumAllUidCpuTimeReads += 2; |
Mike Ma | fae87da | 2018-01-19 20:07:20 -0800 | [diff] [blame] | 12010 | } |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 12011 | for (int cluster = mKernelCpuSpeedReaders.length - 1; cluster >= 0; --cluster) { |
| 12012 | mKernelCpuSpeedReaders[cluster].readDelta(); |
| 12013 | } |
| 12014 | return; |
| 12015 | } |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 12016 | |
Suprabh Shukla | e6e723d | 2017-06-14 16:14:43 -0700 | [diff] [blame] | 12017 | mUserInfoProvider.refreshUserIds(); |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 12018 | final SparseLongArray updatedUids = mKernelUidCpuFreqTimeReader.perClusterTimesAvailable() |
| 12019 | ? null : new SparseLongArray(); |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 12020 | readKernelUidCpuTimesLocked(partialTimersToConsider, updatedUids, onBattery); |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 12021 | // updatedUids=null means /proc/uid_time_in_state provides snapshots of per-cluster cpu |
| 12022 | // freqs, so no need to approximate these values. |
| 12023 | if (updatedUids != null) { |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 12024 | updateClusterSpeedTimes(updatedUids, onBattery); |
Sudheer Shanka | 671985f | 2017-05-19 11:33:42 -0700 | [diff] [blame] | 12025 | } |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 12026 | readKernelUidCpuFreqTimesLocked(partialTimersToConsider, onBattery, onBatteryScreenOff); |
Mike Ma | 234d182 | 2018-03-13 18:53:21 -0700 | [diff] [blame] | 12027 | mNumAllUidCpuTimeReads += 2; |
Mike Ma | fae87da | 2018-01-19 20:07:20 -0800 | [diff] [blame] | 12028 | if (mConstants.TRACK_CPU_ACTIVE_CLUSTER_TIME) { |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 12029 | readKernelUidCpuActiveTimesLocked(onBattery); |
| 12030 | readKernelUidCpuClusterTimesLocked(onBattery); |
Mike Ma | 234d182 | 2018-03-13 18:53:21 -0700 | [diff] [blame] | 12031 | mNumAllUidCpuTimeReads += 2; |
Mike Ma | fae87da | 2018-01-19 20:07:20 -0800 | [diff] [blame] | 12032 | } |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 12033 | } |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 12034 | |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 12035 | /** |
| 12036 | * Mark the current partial timers as gone through a collection so that they will be |
| 12037 | * considered in the next cpu times distribution to wakelock holders. |
| 12038 | */ |
| 12039 | @VisibleForTesting |
| 12040 | public void markPartialTimersAsEligible() { |
| 12041 | if (ArrayUtils.referenceEquals(mPartialTimers, mLastPartialTimers)) { |
| 12042 | // No difference, so each timer is now considered for the next collection. |
| 12043 | for (int i = mPartialTimers.size() - 1; i >= 0; --i) { |
| 12044 | mPartialTimers.get(i).mInList = true; |
| 12045 | } |
| 12046 | } else { |
| 12047 | // The lists are different, meaning we added (or removed a timer) since the last |
| 12048 | // collection. |
| 12049 | for (int i = mLastPartialTimers.size() - 1; i >= 0; --i) { |
| 12050 | mLastPartialTimers.get(i).mInList = false; |
| 12051 | } |
| 12052 | mLastPartialTimers.clear(); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 12053 | |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 12054 | // Mark the current timers as gone through a collection. |
| 12055 | final int numPartialTimers = mPartialTimers.size(); |
| 12056 | for (int i = 0; i < numPartialTimers; ++i) { |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 12057 | final StopwatchTimer timer = mPartialTimers.get(i); |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 12058 | timer.mInList = true; |
| 12059 | mLastPartialTimers.add(timer); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 12060 | } |
| 12061 | } |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 12062 | } |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 12063 | |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 12064 | /** |
| 12065 | * Take snapshot of cpu times (aggregated over all uids) at different frequencies and |
| 12066 | * calculate cpu times spent by each uid at different frequencies. |
| 12067 | * |
| 12068 | * @param updatedUids The uids for which times spent at different frequencies are calculated. |
| 12069 | */ |
| 12070 | @VisibleForTesting |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 12071 | public void updateClusterSpeedTimes(@NonNull SparseLongArray updatedUids, boolean onBattery) { |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 12072 | long totalCpuClustersTimeMs = 0; |
Sudheer Shanka | 2fc52d4 | 2017-06-16 17:29:19 -0700 | [diff] [blame] | 12073 | // Read the time spent for each cluster at various cpu frequencies. |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 12074 | final long[][] clusterSpeedTimesMs = new long[mKernelCpuSpeedReaders.length][]; |
Sudheer Shanka | 2fc52d4 | 2017-06-16 17:29:19 -0700 | [diff] [blame] | 12075 | for (int cluster = 0; cluster < mKernelCpuSpeedReaders.length; cluster++) { |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 12076 | clusterSpeedTimesMs[cluster] = mKernelCpuSpeedReaders[cluster].readDelta(); |
| 12077 | if (clusterSpeedTimesMs[cluster] != null) { |
| 12078 | for (int speed = clusterSpeedTimesMs[cluster].length - 1; speed >= 0; --speed) { |
| 12079 | totalCpuClustersTimeMs += clusterSpeedTimesMs[cluster][speed]; |
Sudheer Shanka | 2fc52d4 | 2017-06-16 17:29:19 -0700 | [diff] [blame] | 12080 | } |
| 12081 | } |
| 12082 | } |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 12083 | if (totalCpuClustersTimeMs != 0) { |
Sudheer Shanka | 2fc52d4 | 2017-06-16 17:29:19 -0700 | [diff] [blame] | 12084 | // We have cpu times per freq aggregated over all uids but we need the times per uid. |
| 12085 | // So, we distribute total time spent by an uid to different cpu freqs based on the |
| 12086 | // amount of time cpu was running at that freq. |
| 12087 | final int updatedUidsCount = updatedUids.size(); |
| 12088 | for (int i = 0; i < updatedUidsCount; ++i) { |
| 12089 | final Uid u = getUidStatsLocked(updatedUids.keyAt(i)); |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 12090 | final long appCpuTimeUs = updatedUids.valueAt(i); |
Sudheer Shanka | 2fc52d4 | 2017-06-16 17:29:19 -0700 | [diff] [blame] | 12091 | // Add the cpu speeds to this UID. |
| 12092 | final int numClusters = mPowerProfile.getNumCpuClusters(); |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 12093 | if (u.mCpuClusterSpeedTimesUs == null || |
| 12094 | u.mCpuClusterSpeedTimesUs.length != numClusters) { |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 12095 | u.mCpuClusterSpeedTimesUs = new LongSamplingCounter[numClusters][]; |
Sudheer Shanka | 2fc52d4 | 2017-06-16 17:29:19 -0700 | [diff] [blame] | 12096 | } |
| 12097 | |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 12098 | for (int cluster = 0; cluster < clusterSpeedTimesMs.length; cluster++) { |
| 12099 | final int speedsInCluster = clusterSpeedTimesMs[cluster].length; |
| 12100 | if (u.mCpuClusterSpeedTimesUs[cluster] == null || speedsInCluster != |
| 12101 | u.mCpuClusterSpeedTimesUs[cluster].length) { |
| 12102 | u.mCpuClusterSpeedTimesUs[cluster] |
| 12103 | = new LongSamplingCounter[speedsInCluster]; |
Sudheer Shanka | 2fc52d4 | 2017-06-16 17:29:19 -0700 | [diff] [blame] | 12104 | } |
| 12105 | |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 12106 | final LongSamplingCounter[] cpuSpeeds = u.mCpuClusterSpeedTimesUs[cluster]; |
Sudheer Shanka | 2fc52d4 | 2017-06-16 17:29:19 -0700 | [diff] [blame] | 12107 | for (int speed = 0; speed < speedsInCluster; speed++) { |
| 12108 | if (cpuSpeeds[speed] == null) { |
| 12109 | cpuSpeeds[speed] = new LongSamplingCounter(mOnBatteryTimeBase); |
| 12110 | } |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 12111 | cpuSpeeds[speed].addCountLocked(appCpuTimeUs |
| 12112 | * clusterSpeedTimesMs[cluster][speed] |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 12113 | / totalCpuClustersTimeMs, onBattery); |
Sudheer Shanka | 2fc52d4 | 2017-06-16 17:29:19 -0700 | [diff] [blame] | 12114 | } |
| 12115 | } |
| 12116 | } |
| 12117 | } |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 12118 | } |
Sudheer Shanka | 2fc52d4 | 2017-06-16 17:29:19 -0700 | [diff] [blame] | 12119 | |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 12120 | /** |
| 12121 | * Take a snapshot of the cpu times spent by each uid and update the corresponding counters. |
| 12122 | * If {@param partialTimers} is not null and empty, then we assign a portion of cpu times to |
| 12123 | * wakelock holders. |
| 12124 | * |
| 12125 | * @param partialTimers The wakelock holders among which the cpu times will be distributed. |
| 12126 | * @param updatedUids If not null, then the uids found in the snapshot will be added to this. |
| 12127 | */ |
| 12128 | @VisibleForTesting |
| 12129 | public void readKernelUidCpuTimesLocked(@Nullable ArrayList<StopwatchTimer> partialTimers, |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 12130 | @Nullable SparseLongArray updatedUids, boolean onBattery) { |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 12131 | mTempTotalCpuUserTimeUs = mTempTotalCpuSystemTimeUs = 0; |
| 12132 | final int numWakelocks = partialTimers == null ? 0 : partialTimers.size(); |
| 12133 | final long startTimeMs = mClocks.uptimeMillis(); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 12134 | |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 12135 | mKernelUidCpuTimeReader.readDelta((uid, userTimeUs, systemTimeUs) -> { |
| 12136 | uid = mapUid(uid); |
| 12137 | if (Process.isIsolated(uid)) { |
| 12138 | // This could happen if the isolated uid mapping was removed before that process |
| 12139 | // was actually killed. |
| 12140 | mKernelUidCpuTimeReader.removeUid(uid); |
| 12141 | Slog.d(TAG, "Got readings for an isolated uid with no mapping: " + uid); |
| 12142 | return; |
| 12143 | } |
| 12144 | if (!mUserInfoProvider.exists(UserHandle.getUserId(uid))) { |
| 12145 | Slog.d(TAG, "Got readings for an invalid user's uid " + uid); |
| 12146 | mKernelUidCpuTimeReader.removeUid(uid); |
| 12147 | return; |
| 12148 | } |
| 12149 | final Uid u = getUidStatsLocked(uid); |
| 12150 | |
| 12151 | // Accumulate the total system and user time. |
| 12152 | mTempTotalCpuUserTimeUs += userTimeUs; |
| 12153 | mTempTotalCpuSystemTimeUs += systemTimeUs; |
| 12154 | |
| 12155 | StringBuilder sb = null; |
| 12156 | if (DEBUG_ENERGY_CPU) { |
| 12157 | sb = new StringBuilder(); |
| 12158 | sb.append(" got time for uid=").append(u.mUid).append(": u="); |
| 12159 | TimeUtils.formatDuration(userTimeUs / 1000, sb); |
| 12160 | sb.append(" s="); |
| 12161 | TimeUtils.formatDuration(systemTimeUs / 1000, sb); |
| 12162 | sb.append("\n"); |
| 12163 | } |
| 12164 | |
| 12165 | if (numWakelocks > 0) { |
| 12166 | // We have wakelocks being held, so only give a portion of the |
| 12167 | // time to the process. The rest will be distributed among wakelock |
| 12168 | // holders. |
| 12169 | userTimeUs = (userTimeUs * WAKE_LOCK_WEIGHT) / 100; |
| 12170 | systemTimeUs = (systemTimeUs * WAKE_LOCK_WEIGHT) / 100; |
| 12171 | } |
| 12172 | |
| 12173 | if (sb != null) { |
| 12174 | sb.append(" adding to uid=").append(u.mUid).append(": u="); |
| 12175 | TimeUtils.formatDuration(userTimeUs / 1000, sb); |
| 12176 | sb.append(" s="); |
| 12177 | TimeUtils.formatDuration(systemTimeUs / 1000, sb); |
| 12178 | Slog.d(TAG, sb.toString()); |
| 12179 | } |
| 12180 | |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 12181 | u.mUserCpuTime.addCountLocked(userTimeUs, onBattery); |
| 12182 | u.mSystemCpuTime.addCountLocked(systemTimeUs, onBattery); |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 12183 | if (updatedUids != null) { |
| 12184 | updatedUids.put(u.getUid(), userTimeUs + systemTimeUs); |
| 12185 | } |
| 12186 | }); |
| 12187 | |
| 12188 | final long elapsedTimeMs = mClocks.uptimeMillis() - startTimeMs; |
| 12189 | if (DEBUG_ENERGY_CPU || elapsedTimeMs >= 100) { |
| 12190 | Slog.d(TAG, "Reading cpu stats took " + elapsedTimeMs + "ms"); |
| 12191 | } |
| 12192 | |
| 12193 | if (numWakelocks > 0) { |
| 12194 | // Distribute a portion of the total cpu time to wakelock holders. |
| 12195 | mTempTotalCpuUserTimeUs = (mTempTotalCpuUserTimeUs * (100 - WAKE_LOCK_WEIGHT)) / 100; |
| 12196 | mTempTotalCpuSystemTimeUs = |
| 12197 | (mTempTotalCpuSystemTimeUs * (100 - WAKE_LOCK_WEIGHT)) / 100; |
| 12198 | |
| 12199 | for (int i = 0; i < numWakelocks; ++i) { |
| 12200 | final StopwatchTimer timer = partialTimers.get(i); |
| 12201 | final int userTimeUs = (int) (mTempTotalCpuUserTimeUs / (numWakelocks - i)); |
| 12202 | final int systemTimeUs = (int) (mTempTotalCpuSystemTimeUs / (numWakelocks - i)); |
| 12203 | |
| 12204 | if (DEBUG_ENERGY_CPU) { |
| 12205 | final StringBuilder sb = new StringBuilder(); |
| 12206 | sb.append(" Distributing wakelock uid=").append(timer.mUid.mUid) |
| 12207 | .append(": u="); |
| 12208 | TimeUtils.formatDuration(userTimeUs / 1000, sb); |
| 12209 | sb.append(" s="); |
| 12210 | TimeUtils.formatDuration(systemTimeUs / 1000, sb); |
| 12211 | Slog.d(TAG, sb.toString()); |
| 12212 | } |
| 12213 | |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 12214 | timer.mUid.mUserCpuTime.addCountLocked(userTimeUs, onBattery); |
| 12215 | timer.mUid.mSystemCpuTime.addCountLocked(systemTimeUs, onBattery); |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 12216 | if (updatedUids != null) { |
| 12217 | final int uid = timer.mUid.getUid(); |
| 12218 | updatedUids.put(uid, updatedUids.get(uid, 0) + userTimeUs + systemTimeUs); |
| 12219 | } |
| 12220 | |
| 12221 | final Uid.Proc proc = timer.mUid.getProcessStatsLocked("*wakelock*"); |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 12222 | proc.addCpuTimeLocked(userTimeUs / 1000, systemTimeUs / 1000, onBattery); |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 12223 | |
| 12224 | mTempTotalCpuUserTimeUs -= userTimeUs; |
| 12225 | mTempTotalCpuSystemTimeUs -= systemTimeUs; |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 12226 | } |
| 12227 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 12228 | } |
| 12229 | |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 12230 | /** |
| 12231 | * Take a snapshot of the cpu times spent by each uid in each freq and update the |
| 12232 | * corresponding counters. |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 12233 | * |
| 12234 | * @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] | 12235 | */ |
| 12236 | @VisibleForTesting |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 12237 | public void readKernelUidCpuFreqTimesLocked(@Nullable ArrayList<StopwatchTimer> partialTimers, |
| 12238 | boolean onBattery, boolean onBatteryScreenOff) { |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 12239 | final boolean perClusterTimesAvailable = |
| 12240 | mKernelUidCpuFreqTimeReader.perClusterTimesAvailable(); |
| 12241 | final int numWakelocks = partialTimers == null ? 0 : partialTimers.size(); |
| 12242 | final int numClusters = mPowerProfile.getNumCpuClusters(); |
| 12243 | mWakeLockAllocationsUs = null; |
Sudheer Shanka | ac5b88f | 2017-12-11 15:36:35 -0800 | [diff] [blame] | 12244 | final long startTimeMs = mClocks.uptimeMillis(); |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 12245 | mKernelUidCpuFreqTimeReader.readDelta((uid, cpuFreqTimeMs) -> { |
| 12246 | uid = mapUid(uid); |
| 12247 | if (Process.isIsolated(uid)) { |
| 12248 | mKernelUidCpuFreqTimeReader.removeUid(uid); |
| 12249 | Slog.d(TAG, "Got freq readings for an isolated uid with no mapping: " + uid); |
| 12250 | return; |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 12251 | } |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 12252 | if (!mUserInfoProvider.exists(UserHandle.getUserId(uid))) { |
| 12253 | Slog.d(TAG, "Got freq readings for an invalid user's uid " + uid); |
| 12254 | mKernelUidCpuFreqTimeReader.removeUid(uid); |
| 12255 | return; |
| 12256 | } |
| 12257 | final Uid u = getUidStatsLocked(uid); |
| 12258 | if (u.mCpuFreqTimeMs == null || u.mCpuFreqTimeMs.getSize() != cpuFreqTimeMs.length) { |
| 12259 | u.mCpuFreqTimeMs = new LongSamplingCounterArray(mOnBatteryTimeBase); |
| 12260 | } |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 12261 | u.mCpuFreqTimeMs.addCountLocked(cpuFreqTimeMs, onBattery); |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 12262 | if (u.mScreenOffCpuFreqTimeMs == null || |
| 12263 | u.mScreenOffCpuFreqTimeMs.getSize() != cpuFreqTimeMs.length) { |
| 12264 | u.mScreenOffCpuFreqTimeMs = new LongSamplingCounterArray( |
| 12265 | mOnBatteryScreenOffTimeBase); |
| 12266 | } |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 12267 | u.mScreenOffCpuFreqTimeMs.addCountLocked(cpuFreqTimeMs, onBatteryScreenOff); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 12268 | |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 12269 | if (perClusterTimesAvailable) { |
| 12270 | if (u.mCpuClusterSpeedTimesUs == null || |
| 12271 | u.mCpuClusterSpeedTimesUs.length != numClusters) { |
| 12272 | u.mCpuClusterSpeedTimesUs = new LongSamplingCounter[numClusters][]; |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 12273 | } |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 12274 | if (numWakelocks > 0 && mWakeLockAllocationsUs == null) { |
| 12275 | mWakeLockAllocationsUs = new long[numClusters][]; |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 12276 | } |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 12277 | |
| 12278 | int freqIndex = 0; |
| 12279 | for (int cluster = 0; cluster < numClusters; ++cluster) { |
| 12280 | final int speedsInCluster = mPowerProfile.getNumSpeedStepsInCpuCluster(cluster); |
| 12281 | if (u.mCpuClusterSpeedTimesUs[cluster] == null || |
| 12282 | u.mCpuClusterSpeedTimesUs[cluster].length != speedsInCluster) { |
| 12283 | u.mCpuClusterSpeedTimesUs[cluster] |
| 12284 | = new LongSamplingCounter[speedsInCluster]; |
| 12285 | } |
| 12286 | if (numWakelocks > 0 && mWakeLockAllocationsUs[cluster] == null) { |
| 12287 | mWakeLockAllocationsUs[cluster] = new long[speedsInCluster]; |
| 12288 | } |
| 12289 | final LongSamplingCounter[] cpuTimesUs = u.mCpuClusterSpeedTimesUs[cluster]; |
| 12290 | for (int speed = 0; speed < speedsInCluster; ++speed) { |
| 12291 | if (cpuTimesUs[speed] == null) { |
| 12292 | cpuTimesUs[speed] = new LongSamplingCounter(mOnBatteryTimeBase); |
| 12293 | } |
| 12294 | final long appAllocationUs; |
| 12295 | if (mWakeLockAllocationsUs != null) { |
| 12296 | appAllocationUs = |
| 12297 | (cpuFreqTimeMs[freqIndex] * 1000 * WAKE_LOCK_WEIGHT) / 100; |
| 12298 | mWakeLockAllocationsUs[cluster][speed] += |
| 12299 | (cpuFreqTimeMs[freqIndex] * 1000 - appAllocationUs); |
| 12300 | } else { |
| 12301 | appAllocationUs = cpuFreqTimeMs[freqIndex] * 1000; |
| 12302 | } |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 12303 | cpuTimesUs[speed].addCountLocked(appAllocationUs, onBattery); |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 12304 | freqIndex++; |
| 12305 | } |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 12306 | } |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 12307 | } |
| 12308 | }); |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 12309 | |
Sudheer Shanka | ac5b88f | 2017-12-11 15:36:35 -0800 | [diff] [blame] | 12310 | final long elapsedTimeMs = mClocks.uptimeMillis() - startTimeMs; |
| 12311 | if (DEBUG_ENERGY_CPU || elapsedTimeMs >= 100) { |
| 12312 | Slog.d(TAG, "Reading cpu freq times took " + elapsedTimeMs + "ms"); |
| 12313 | } |
| 12314 | |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 12315 | if (mWakeLockAllocationsUs != null) { |
| 12316 | for (int i = 0; i < numWakelocks; ++i) { |
| 12317 | final Uid u = partialTimers.get(i).mUid; |
| 12318 | if (u.mCpuClusterSpeedTimesUs == null || |
| 12319 | u.mCpuClusterSpeedTimesUs.length != numClusters) { |
| 12320 | u.mCpuClusterSpeedTimesUs = new LongSamplingCounter[numClusters][]; |
| 12321 | } |
| 12322 | |
| 12323 | for (int cluster = 0; cluster < numClusters; ++cluster) { |
| 12324 | final int speedsInCluster = mPowerProfile.getNumSpeedStepsInCpuCluster(cluster); |
| 12325 | if (u.mCpuClusterSpeedTimesUs[cluster] == null || |
| 12326 | u.mCpuClusterSpeedTimesUs[cluster].length != speedsInCluster) { |
| 12327 | u.mCpuClusterSpeedTimesUs[cluster] |
| 12328 | = new LongSamplingCounter[speedsInCluster]; |
| 12329 | } |
| 12330 | final LongSamplingCounter[] cpuTimeUs = u.mCpuClusterSpeedTimesUs[cluster]; |
| 12331 | for (int speed = 0; speed < speedsInCluster; ++speed) { |
| 12332 | if (cpuTimeUs[speed] == null) { |
| 12333 | cpuTimeUs[speed] = new LongSamplingCounter(mOnBatteryTimeBase); |
| 12334 | } |
| 12335 | final long allocationUs = |
| 12336 | mWakeLockAllocationsUs[cluster][speed] / (numWakelocks - i); |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 12337 | cpuTimeUs[speed].addCountLocked(allocationUs, onBattery); |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 12338 | mWakeLockAllocationsUs[cluster][speed] -= allocationUs; |
| 12339 | } |
| 12340 | } |
| 12341 | } |
| 12342 | } |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 12343 | } |
| 12344 | |
Mike Ma | 3d422c3 | 2017-10-25 11:08:57 -0700 | [diff] [blame] | 12345 | /** |
| 12346 | * Take a snapshot of the cpu active times spent by each uid and update the corresponding |
| 12347 | * counters. |
| 12348 | */ |
| 12349 | @VisibleForTesting |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 12350 | public void readKernelUidCpuActiveTimesLocked(boolean onBattery) { |
Mike Ma | 3d422c3 | 2017-10-25 11:08:57 -0700 | [diff] [blame] | 12351 | final long startTimeMs = mClocks.uptimeMillis(); |
Mike Ma | 2ab0144 | 2018-02-13 14:22:47 -0800 | [diff] [blame] | 12352 | mKernelUidCpuActiveTimeReader.readDelta((uid, cpuActiveTimesMs) -> { |
Mike Ma | 3d422c3 | 2017-10-25 11:08:57 -0700 | [diff] [blame] | 12353 | uid = mapUid(uid); |
| 12354 | if (Process.isIsolated(uid)) { |
| 12355 | mKernelUidCpuActiveTimeReader.removeUid(uid); |
| 12356 | Slog.w(TAG, "Got active times for an isolated uid with no mapping: " + uid); |
| 12357 | return; |
| 12358 | } |
| 12359 | if (!mUserInfoProvider.exists(UserHandle.getUserId(uid))) { |
| 12360 | Slog.w(TAG, "Got active times for an invalid user's uid " + uid); |
| 12361 | mKernelUidCpuActiveTimeReader.removeUid(uid); |
| 12362 | return; |
| 12363 | } |
| 12364 | final Uid u = getUidStatsLocked(uid); |
Mike Ma | 2ab0144 | 2018-02-13 14:22:47 -0800 | [diff] [blame] | 12365 | u.mCpuActiveTimeMs.addCountLocked(cpuActiveTimesMs, onBattery); |
Mike Ma | 3d422c3 | 2017-10-25 11:08:57 -0700 | [diff] [blame] | 12366 | }); |
| 12367 | |
| 12368 | final long elapsedTimeMs = mClocks.uptimeMillis() - startTimeMs; |
| 12369 | if (DEBUG_ENERGY_CPU || elapsedTimeMs >= 100) { |
| 12370 | Slog.d(TAG, "Reading cpu active times took " + elapsedTimeMs + "ms"); |
| 12371 | } |
| 12372 | } |
| 12373 | |
| 12374 | /** |
| 12375 | * Take a snapshot of the cpu cluster times spent by each uid and update the corresponding |
| 12376 | * counters. |
| 12377 | */ |
| 12378 | @VisibleForTesting |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 12379 | public void readKernelUidCpuClusterTimesLocked(boolean onBattery) { |
Mike Ma | 3d422c3 | 2017-10-25 11:08:57 -0700 | [diff] [blame] | 12380 | final long startTimeMs = mClocks.uptimeMillis(); |
Mike Ma | 2ab0144 | 2018-02-13 14:22:47 -0800 | [diff] [blame] | 12381 | mKernelUidCpuClusterTimeReader.readDelta((uid, cpuClusterTimesMs) -> { |
Mike Ma | 3d422c3 | 2017-10-25 11:08:57 -0700 | [diff] [blame] | 12382 | uid = mapUid(uid); |
| 12383 | if (Process.isIsolated(uid)) { |
| 12384 | mKernelUidCpuClusterTimeReader.removeUid(uid); |
| 12385 | Slog.w(TAG, "Got cluster times for an isolated uid with no mapping: " + uid); |
| 12386 | return; |
| 12387 | } |
| 12388 | if (!mUserInfoProvider.exists(UserHandle.getUserId(uid))) { |
| 12389 | Slog.w(TAG, "Got cluster times for an invalid user's uid " + uid); |
| 12390 | mKernelUidCpuClusterTimeReader.removeUid(uid); |
| 12391 | return; |
| 12392 | } |
| 12393 | final Uid u = getUidStatsLocked(uid); |
Mike Ma | 2ab0144 | 2018-02-13 14:22:47 -0800 | [diff] [blame] | 12394 | u.mCpuClusterTimesMs.addCountLocked(cpuClusterTimesMs, onBattery); |
Mike Ma | 3d422c3 | 2017-10-25 11:08:57 -0700 | [diff] [blame] | 12395 | }); |
| 12396 | |
| 12397 | final long elapsedTimeMs = mClocks.uptimeMillis() - startTimeMs; |
| 12398 | if (DEBUG_ENERGY_CPU || elapsedTimeMs >= 100) { |
| 12399 | Slog.d(TAG, "Reading cpu cluster times took " + elapsedTimeMs + "ms"); |
| 12400 | } |
| 12401 | } |
| 12402 | |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 12403 | boolean setChargingLocked(boolean charging) { |
| 12404 | if (mCharging != charging) { |
| 12405 | mCharging = charging; |
| 12406 | if (charging) { |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 12407 | mHistoryCur.states2 |= HistoryItem.STATE2_CHARGING_FLAG; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 12408 | } else { |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 12409 | mHistoryCur.states2 &= ~HistoryItem.STATE2_CHARGING_FLAG; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 12410 | } |
| 12411 | mHandler.sendEmptyMessage(MSG_REPORT_CHARGING); |
| 12412 | return true; |
| 12413 | } |
| 12414 | return false; |
| 12415 | } |
| 12416 | |
Andreas Gampe | 3f24e69 | 2018-02-05 13:24:28 -0800 | [diff] [blame] | 12417 | @GuardedBy("this") |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 12418 | protected void setOnBatteryLocked(final long mSecRealtime, final long mSecUptime, |
| 12419 | final boolean onBattery, final int oldStatus, final int level, final int chargeUAh) { |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 12420 | boolean doWrite = false; |
| 12421 | Message m = mHandler.obtainMessage(MSG_REPORT_POWER_CHANGE); |
| 12422 | m.arg1 = onBattery ? 1 : 0; |
| 12423 | mHandler.sendMessage(m); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 12424 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 12425 | final long uptime = mSecUptime * 1000; |
| 12426 | final long realtime = mSecRealtime * 1000; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 12427 | final int screenState = mScreenState; |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 12428 | if (onBattery) { |
| 12429 | // We will reset our status if we are unplugging after the |
| 12430 | // battery was last full, or the level is at 100, or |
| 12431 | // we have gone through a significant charge (from a very low |
| 12432 | // level to a now very high level). |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 12433 | boolean reset = false; |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 12434 | if (!mNoAutoReset && (oldStatus == BatteryManager.BATTERY_STATUS_FULL |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 12435 | || level >= 90 |
Dianne Hackborn | fb3809c | 2014-09-29 18:31:22 -0700 | [diff] [blame] | 12436 | || (mDischargeCurrentLevel < 20 && level >= 80) |
| 12437 | || (getHighDischargeAmountSinceCharge() >= 200 |
| 12438 | && mHistoryBuffer.dataSize() >= MAX_HISTORY_BUFFER))) { |
Dianne Hackborn | 73d6a82 | 2014-09-29 10:52:47 -0700 | [diff] [blame] | 12439 | Slog.i(TAG, "Resetting battery stats: level=" + level + " status=" + oldStatus |
Dianne Hackborn | fb3809c | 2014-09-29 18:31:22 -0700 | [diff] [blame] | 12440 | + " dischargeLevel=" + mDischargeCurrentLevel |
Dianne Hackborn | 73d6a82 | 2014-09-29 10:52:47 -0700 | [diff] [blame] | 12441 | + " lowAmount=" + getLowDischargeAmountSinceCharge() |
| 12442 | + " highAmount=" + getHighDischargeAmountSinceCharge()); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 12443 | // Before we write, collect a snapshot of the final aggregated |
| 12444 | // stats to be reported in the next checkin. Only do this if we have |
| 12445 | // a sufficient amount of data to make it interesting. |
| 12446 | if (getLowDischargeAmountSinceCharge() >= 20) { |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 12447 | final long startTime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 12448 | final Parcel parcel = Parcel.obtain(); |
| 12449 | writeSummaryToParcel(parcel, true); |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 12450 | final long initialTime = SystemClock.uptimeMillis() - startTime; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 12451 | BackgroundThread.getHandler().post(new Runnable() { |
| 12452 | @Override public void run() { |
| 12453 | synchronized (mCheckinFile) { |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 12454 | final long startTime2 = SystemClock.uptimeMillis(); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 12455 | FileOutputStream stream = null; |
| 12456 | try { |
| 12457 | stream = mCheckinFile.startWrite(); |
| 12458 | stream.write(parcel.marshall()); |
| 12459 | stream.flush(); |
| 12460 | FileUtils.sync(stream); |
| 12461 | stream.close(); |
| 12462 | mCheckinFile.finishWrite(stream); |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 12463 | com.android.internal.logging.EventLogTags.writeCommitSysConfigFile( |
| 12464 | "batterystats-checkin", |
| 12465 | initialTime + SystemClock.uptimeMillis() - startTime2); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 12466 | } catch (IOException e) { |
| 12467 | Slog.w("BatteryStats", |
| 12468 | "Error writing checkin battery statistics", e); |
| 12469 | mCheckinFile.failWrite(stream); |
| 12470 | } finally { |
| 12471 | parcel.recycle(); |
| 12472 | } |
| 12473 | } |
| 12474 | } |
| 12475 | }); |
| 12476 | } |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 12477 | doWrite = true; |
| 12478 | resetAllStatsLocked(); |
Ying Wai (Daniel) Fan | 442ab76 | 2017-01-31 22:00:10 -0800 | [diff] [blame] | 12479 | if (chargeUAh > 0 && level > 0) { |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 12480 | // 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] | 12481 | mEstimatedBatteryCapacity = (int) ((chargeUAh / 1000) / (level / 100.0)); |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 12482 | } |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 12483 | mDischargeStartLevel = level; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 12484 | reset = true; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 12485 | mDischargeStepTracker.init(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 12486 | } |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 12487 | if (mCharging) { |
| 12488 | setChargingLocked(false); |
| 12489 | } |
| 12490 | mLastChargingStateLevel = level; |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 12491 | mOnBattery = mOnBatteryInternal = true; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 12492 | mLastDischargeStepLevel = level; |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 12493 | mMinDischargeStepLevel = level; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 12494 | mDischargeStepTracker.clearTime(); |
| 12495 | mDailyDischargeStepTracker.clearTime(); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 12496 | mInitStepMode = mCurStepMode; |
| 12497 | mModStepMode = 0; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 12498 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 12499 | mHistoryCur.batteryLevel = (byte)level; |
| 12500 | mHistoryCur.states &= ~HistoryItem.STATE_BATTERY_PLUGGED_FLAG; |
| 12501 | if (DEBUG_HISTORY) Slog.v(TAG, "Battery unplugged to: " |
| 12502 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 12503 | if (reset) { |
| 12504 | mRecordingHistory = true; |
| 12505 | startRecordingHistory(mSecRealtime, mSecUptime, reset); |
| 12506 | } |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 12507 | addHistoryRecordLocked(mSecRealtime, mSecUptime); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 12508 | mDischargeCurrentLevel = mDischargeUnplugLevel = level; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 12509 | if (isScreenOn(screenState)) { |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 12510 | mDischargeScreenOnUnplugLevel = level; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 12511 | mDischargeScreenDozeUnplugLevel = 0; |
| 12512 | mDischargeScreenOffUnplugLevel = 0; |
| 12513 | } else if (isScreenDoze(screenState)) { |
| 12514 | mDischargeScreenOnUnplugLevel = 0; |
| 12515 | mDischargeScreenDozeUnplugLevel = level; |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 12516 | mDischargeScreenOffUnplugLevel = 0; |
| 12517 | } else { |
| 12518 | mDischargeScreenOnUnplugLevel = 0; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 12519 | mDischargeScreenDozeUnplugLevel = 0; |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 12520 | mDischargeScreenOffUnplugLevel = level; |
| 12521 | } |
| 12522 | mDischargeAmountScreenOn = 0; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 12523 | mDischargeAmountScreenDoze = 0; |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 12524 | mDischargeAmountScreenOff = 0; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 12525 | updateTimeBasesLocked(true, screenState, uptime, realtime); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 12526 | } else { |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 12527 | mLastChargingStateLevel = level; |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 12528 | mOnBattery = mOnBatteryInternal = false; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 12529 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 12530 | mHistoryCur.batteryLevel = (byte)level; |
| 12531 | mHistoryCur.states |= HistoryItem.STATE_BATTERY_PLUGGED_FLAG; |
| 12532 | if (DEBUG_HISTORY) Slog.v(TAG, "Battery plugged to: " |
| 12533 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 12534 | addHistoryRecordLocked(mSecRealtime, mSecUptime); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 12535 | mDischargeCurrentLevel = mDischargePlugLevel = level; |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 12536 | if (level < mDischargeUnplugLevel) { |
| 12537 | mLowDischargeAmountSinceCharge += mDischargeUnplugLevel-level-1; |
| 12538 | mHighDischargeAmountSinceCharge += mDischargeUnplugLevel-level; |
| 12539 | } |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 12540 | updateDischargeScreenLevelsLocked(screenState, screenState); |
| 12541 | updateTimeBasesLocked(false, screenState, uptime, realtime); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 12542 | mChargeStepTracker.init(); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 12543 | mLastChargeStepLevel = level; |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 12544 | mMaxChargeStepLevel = level; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 12545 | mInitStepMode = mCurStepMode; |
| 12546 | mModStepMode = 0; |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 12547 | } |
| 12548 | if (doWrite || (mLastWriteTime + (60 * 1000)) < mSecRealtime) { |
| 12549 | if (mFile != null) { |
| 12550 | writeAsyncLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12551 | } |
| 12552 | } |
| 12553 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 12554 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 12555 | private void startRecordingHistory(final long elapsedRealtimeMs, final long uptimeMs, |
| 12556 | boolean reset) { |
| 12557 | mRecordingHistory = true; |
| 12558 | mHistoryCur.currentTime = System.currentTimeMillis(); |
Narayan Kamath | 5a5a7fe | 2018-02-05 17:30:06 +0000 | [diff] [blame] | 12559 | addHistoryBufferLocked(elapsedRealtimeMs, |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 12560 | reset ? HistoryItem.CMD_RESET : HistoryItem.CMD_CURRENT_TIME, |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 12561 | mHistoryCur); |
| 12562 | mHistoryCur.currentTime = 0; |
| 12563 | if (reset) { |
| 12564 | initActiveHistoryEventsLocked(elapsedRealtimeMs, uptimeMs); |
| 12565 | } |
| 12566 | } |
| 12567 | |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 12568 | private void recordCurrentTimeChangeLocked(final long currentTime, final long elapsedRealtimeMs, |
| 12569 | final long uptimeMs) { |
| 12570 | if (mRecordingHistory) { |
| 12571 | mHistoryCur.currentTime = currentTime; |
Narayan Kamath | 5a5a7fe | 2018-02-05 17:30:06 +0000 | [diff] [blame] | 12572 | addHistoryBufferLocked(elapsedRealtimeMs, HistoryItem.CMD_CURRENT_TIME, mHistoryCur); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 12573 | mHistoryCur.currentTime = 0; |
| 12574 | } |
| 12575 | } |
| 12576 | |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 12577 | private void recordShutdownLocked(final long elapsedRealtimeMs, final long uptimeMs) { |
| 12578 | if (mRecordingHistory) { |
| 12579 | mHistoryCur.currentTime = System.currentTimeMillis(); |
Narayan Kamath | 5a5a7fe | 2018-02-05 17:30:06 +0000 | [diff] [blame] | 12580 | addHistoryBufferLocked(elapsedRealtimeMs, HistoryItem.CMD_SHUTDOWN, mHistoryCur); |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 12581 | mHistoryCur.currentTime = 0; |
| 12582 | } |
| 12583 | } |
| 12584 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 12585 | private void scheduleSyncExternalStatsLocked(String reason, int updateFlags) { |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 12586 | if (mExternalSync != null) { |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 12587 | mExternalSync.scheduleSync(reason, updateFlags); |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 12588 | } |
| 12589 | } |
| 12590 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 12591 | // This should probably be exposed in the API, though it's not critical |
Bookatz | 1a1b046 | 2018-01-12 11:47:03 -0800 | [diff] [blame] | 12592 | public static final int BATTERY_PLUGGED_NONE = OsProtoEnums.BATTERY_PLUGGED_NONE; // = 0 |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 12593 | |
Andreas Gampe | 3f24e69 | 2018-02-05 13:24:28 -0800 | [diff] [blame] | 12594 | @GuardedBy("this") |
Bookatz | 8c6571b | 2017-10-24 15:04:41 -0700 | [diff] [blame] | 12595 | public void setBatteryStateLocked(final int status, final int health, final int plugType, |
| 12596 | final int level, /* not final */ int temp, final int volt, final int chargeUAh, |
| 12597 | final int chargeFullUAh) { |
Adam Lesinski | 29ddfe5 | 2017-03-29 19:29:00 -0700 | [diff] [blame] | 12598 | // Temperature is encoded without the signed bit, so clamp any negative temperatures to 0. |
| 12599 | temp = Math.max(0, temp); |
| 12600 | |
Bookatz | 8c6571b | 2017-10-24 15:04:41 -0700 | [diff] [blame] | 12601 | reportChangesToStatsLog(mHaveBatteryLevel ? mHistoryCur : null, |
Tej Singh | 4029831 | 2018-02-16 00:15:09 -0800 | [diff] [blame] | 12602 | status, plugType, level); |
Bookatz | 8c6571b | 2017-10-24 15:04:41 -0700 | [diff] [blame] | 12603 | |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 12604 | final boolean onBattery = isOnBattery(plugType, status); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 12605 | final long uptime = mClocks.uptimeMillis(); |
| 12606 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 12607 | if (!mHaveBatteryLevel) { |
| 12608 | mHaveBatteryLevel = true; |
| 12609 | // We start out assuming that the device is plugged in (not |
| 12610 | // on battery). If our first report is now that we are indeed |
| 12611 | // plugged in, then twiddle our state to correctly reflect that |
| 12612 | // since we won't be going through the full setOnBattery(). |
| 12613 | if (onBattery == mOnBattery) { |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 12614 | if (onBattery) { |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 12615 | mHistoryCur.states &= ~HistoryItem.STATE_BATTERY_PLUGGED_FLAG; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 12616 | } else { |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 12617 | mHistoryCur.states |= HistoryItem.STATE_BATTERY_PLUGGED_FLAG; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 12618 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 12619 | } |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 12620 | // Always start out assuming charging, that will be updated later. |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 12621 | mHistoryCur.states2 |= HistoryItem.STATE2_CHARGING_FLAG; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 12622 | mHistoryCur.batteryStatus = (byte)status; |
| 12623 | mHistoryCur.batteryLevel = (byte)level; |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 12624 | mHistoryCur.batteryChargeUAh = chargeUAh; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 12625 | mMaxChargeStepLevel = mMinDischargeStepLevel = |
| 12626 | mLastChargeStepLevel = mLastDischargeStepLevel = level; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 12627 | mLastChargingStateLevel = level; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 12628 | } else if (mCurrentBatteryLevel != level || mOnBattery != onBattery) { |
| 12629 | recordDailyStatsIfNeededLocked(level >= 100 && onBattery); |
| 12630 | } |
| 12631 | int oldStatus = mHistoryCur.batteryStatus; |
| 12632 | if (onBattery) { |
| 12633 | mDischargeCurrentLevel = level; |
| 12634 | if (!mRecordingHistory) { |
| 12635 | mRecordingHistory = true; |
| 12636 | startRecordingHistory(elapsedRealtime, uptime, true); |
| 12637 | } |
Todd Poynor | 1acf06a | 2017-12-07 19:19:35 -0800 | [diff] [blame] | 12638 | } else if (level < 96 && |
| 12639 | status != BatteryManager.BATTERY_STATUS_UNKNOWN) { |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 12640 | if (!mRecordingHistory) { |
| 12641 | mRecordingHistory = true; |
| 12642 | startRecordingHistory(elapsedRealtime, uptime, true); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 12643 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 12644 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 12645 | mCurrentBatteryLevel = level; |
| 12646 | if (mDischargePlugLevel < 0) { |
| 12647 | mDischargePlugLevel = level; |
Marco Nelissen | d859331 | 2009-04-30 14:45:06 -0700 | [diff] [blame] | 12648 | } |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 12649 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 12650 | if (onBattery != mOnBattery) { |
| 12651 | mHistoryCur.batteryLevel = (byte)level; |
| 12652 | mHistoryCur.batteryStatus = (byte)status; |
| 12653 | mHistoryCur.batteryHealth = (byte)health; |
| 12654 | mHistoryCur.batteryPlugType = (byte)plugType; |
| 12655 | mHistoryCur.batteryTemperature = (short)temp; |
| 12656 | mHistoryCur.batteryVoltage = (char)volt; |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 12657 | if (chargeUAh < mHistoryCur.batteryChargeUAh) { |
| 12658 | // Only record discharges |
| 12659 | final long chargeDiff = mHistoryCur.batteryChargeUAh - chargeUAh; |
| 12660 | mDischargeCounter.addCountLocked(chargeDiff); |
| 12661 | mDischargeScreenOffCounter.addCountLocked(chargeDiff); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 12662 | if (isScreenDoze(mScreenState)) { |
| 12663 | mDischargeScreenDozeCounter.addCountLocked(chargeDiff); |
| 12664 | } |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 12665 | if (mDeviceIdleMode == DEVICE_IDLE_MODE_LIGHT) { |
| 12666 | mDischargeLightDozeCounter.addCountLocked(chargeDiff); |
| 12667 | } else if (mDeviceIdleMode == DEVICE_IDLE_MODE_DEEP) { |
| 12668 | mDischargeDeepDozeCounter.addCountLocked(chargeDiff); |
| 12669 | } |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 12670 | } |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 12671 | mHistoryCur.batteryChargeUAh = chargeUAh; |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 12672 | setOnBatteryLocked(elapsedRealtime, uptime, onBattery, oldStatus, level, chargeUAh); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 12673 | } else { |
| 12674 | boolean changed = false; |
| 12675 | if (mHistoryCur.batteryLevel != level) { |
| 12676 | mHistoryCur.batteryLevel = (byte)level; |
| 12677 | changed = true; |
Marco Nelissen | d859331 | 2009-04-30 14:45:06 -0700 | [diff] [blame] | 12678 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 12679 | // TODO(adamlesinski): Schedule the creation of a HistoryStepDetails record |
| 12680 | // which will pull external stats. |
Sudheer Shanka | 0719c6a | 2018-04-24 11:12:11 -0700 | [diff] [blame] | 12681 | mExternalSync.scheduleSyncDueToBatteryLevelChange( |
| 12682 | mConstants.BATTERY_LEVEL_COLLECTION_DELAY_MS); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 12683 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 12684 | if (mHistoryCur.batteryStatus != status) { |
| 12685 | mHistoryCur.batteryStatus = (byte)status; |
| 12686 | changed = true; |
| 12687 | } |
| 12688 | if (mHistoryCur.batteryHealth != health) { |
| 12689 | mHistoryCur.batteryHealth = (byte)health; |
| 12690 | changed = true; |
| 12691 | } |
| 12692 | if (mHistoryCur.batteryPlugType != plugType) { |
| 12693 | mHistoryCur.batteryPlugType = (byte)plugType; |
| 12694 | changed = true; |
| 12695 | } |
| 12696 | if (temp >= (mHistoryCur.batteryTemperature+10) |
| 12697 | || temp <= (mHistoryCur.batteryTemperature-10)) { |
| 12698 | mHistoryCur.batteryTemperature = (short)temp; |
| 12699 | changed = true; |
| 12700 | } |
| 12701 | if (volt > (mHistoryCur.batteryVoltage+20) |
| 12702 | || volt < (mHistoryCur.batteryVoltage-20)) { |
| 12703 | mHistoryCur.batteryVoltage = (char)volt; |
| 12704 | changed = true; |
| 12705 | } |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 12706 | if (chargeUAh >= (mHistoryCur.batteryChargeUAh+10) |
| 12707 | || chargeUAh <= (mHistoryCur.batteryChargeUAh-10)) { |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 12708 | if (chargeUAh < mHistoryCur.batteryChargeUAh) { |
| 12709 | // Only record discharges |
| 12710 | final long chargeDiff = mHistoryCur.batteryChargeUAh - chargeUAh; |
| 12711 | mDischargeCounter.addCountLocked(chargeDiff); |
| 12712 | mDischargeScreenOffCounter.addCountLocked(chargeDiff); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 12713 | if (isScreenDoze(mScreenState)) { |
| 12714 | mDischargeScreenDozeCounter.addCountLocked(chargeDiff); |
| 12715 | } |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 12716 | if (mDeviceIdleMode == DEVICE_IDLE_MODE_LIGHT) { |
| 12717 | mDischargeLightDozeCounter.addCountLocked(chargeDiff); |
| 12718 | } else if (mDeviceIdleMode == DEVICE_IDLE_MODE_DEEP) { |
| 12719 | mDischargeDeepDozeCounter.addCountLocked(chargeDiff); |
| 12720 | } |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 12721 | } |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 12722 | mHistoryCur.batteryChargeUAh = chargeUAh; |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 12723 | changed = true; |
| 12724 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 12725 | long modeBits = (((long)mInitStepMode) << STEP_LEVEL_INITIAL_MODE_SHIFT) |
| 12726 | | (((long)mModStepMode) << STEP_LEVEL_MODIFIED_MODE_SHIFT) |
| 12727 | | (((long)(level&0xff)) << STEP_LEVEL_LEVEL_SHIFT); |
| 12728 | if (onBattery) { |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 12729 | changed |= setChargingLocked(false); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 12730 | if (mLastDischargeStepLevel != level && mMinDischargeStepLevel > level) { |
| 12731 | mDischargeStepTracker.addLevelSteps(mLastDischargeStepLevel - level, |
| 12732 | modeBits, elapsedRealtime); |
| 12733 | mDailyDischargeStepTracker.addLevelSteps(mLastDischargeStepLevel - level, |
| 12734 | modeBits, elapsedRealtime); |
| 12735 | mLastDischargeStepLevel = level; |
| 12736 | mMinDischargeStepLevel = level; |
| 12737 | mInitStepMode = mCurStepMode; |
| 12738 | mModStepMode = 0; |
| 12739 | } |
| 12740 | } else { |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 12741 | if (level >= 90) { |
| 12742 | // If the battery level is at least 90%, always consider the device to be |
| 12743 | // charging even if it happens to go down a level. |
| 12744 | changed |= setChargingLocked(true); |
| 12745 | mLastChargeStepLevel = level; |
| 12746 | } if (!mCharging) { |
| 12747 | if (mLastChargeStepLevel < level) { |
| 12748 | // We have not reporting that we are charging, but the level has now |
| 12749 | // gone up, so consider the state to be charging. |
| 12750 | changed |= setChargingLocked(true); |
| 12751 | mLastChargeStepLevel = level; |
| 12752 | } |
| 12753 | } else { |
| 12754 | if (mLastChargeStepLevel > level) { |
| 12755 | // We had reported that the device was charging, but here we are with |
| 12756 | // power connected and the level going down. Looks like the current |
| 12757 | // power supplied isn't enough, so consider the device to now be |
| 12758 | // discharging. |
| 12759 | changed |= setChargingLocked(false); |
| 12760 | mLastChargeStepLevel = level; |
| 12761 | } |
| 12762 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 12763 | if (mLastChargeStepLevel != level && mMaxChargeStepLevel < level) { |
| 12764 | mChargeStepTracker.addLevelSteps(level - mLastChargeStepLevel, |
| 12765 | modeBits, elapsedRealtime); |
| 12766 | mDailyChargeStepTracker.addLevelSteps(level - mLastChargeStepLevel, |
| 12767 | modeBits, elapsedRealtime); |
| 12768 | mLastChargeStepLevel = level; |
| 12769 | mMaxChargeStepLevel = level; |
| 12770 | mInitStepMode = mCurStepMode; |
| 12771 | mModStepMode = 0; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 12772 | } |
| 12773 | } |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 12774 | if (changed) { |
| 12775 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 12776 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 12777 | } |
Todd Poynor | 1acf06a | 2017-12-07 19:19:35 -0800 | [diff] [blame] | 12778 | if (!onBattery && |
| 12779 | (status == BatteryManager.BATTERY_STATUS_FULL || |
| 12780 | status == BatteryManager.BATTERY_STATUS_UNKNOWN)) { |
| 12781 | // We don't record history while we are plugged in and fully charged |
| 12782 | // (or when battery is not present). The next time we are |
| 12783 | // unplugged, history will be cleared. |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 12784 | mRecordingHistory = DEBUG; |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 12785 | } |
Adam Lesinski | 041d917 | 2016-12-12 12:03:56 -0800 | [diff] [blame] | 12786 | |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 12787 | if (mMinLearnedBatteryCapacity == -1) { |
| 12788 | mMinLearnedBatteryCapacity = chargeFullUAh; |
| 12789 | } else { |
| 12790 | Math.min(mMinLearnedBatteryCapacity, chargeFullUAh); |
Adam Lesinski | 041d917 | 2016-12-12 12:03:56 -0800 | [diff] [blame] | 12791 | } |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 12792 | mMaxLearnedBatteryCapacity = Math.max(mMaxLearnedBatteryCapacity, chargeFullUAh); |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 12793 | } |
| 12794 | |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 12795 | public static boolean isOnBattery(int plugType, int status) { |
| 12796 | return plugType == BATTERY_PLUGGED_NONE && status != BatteryManager.BATTERY_STATUS_UNKNOWN; |
| 12797 | } |
| 12798 | |
Bookatz | 8c6571b | 2017-10-24 15:04:41 -0700 | [diff] [blame] | 12799 | // Inform StatsLog of setBatteryState changes. |
| 12800 | // If this is the first reporting, pass in recentPast == null. |
| 12801 | private void reportChangesToStatsLog(HistoryItem recentPast, |
Tej Singh | 4029831 | 2018-02-16 00:15:09 -0800 | [diff] [blame] | 12802 | final int status, final int plugType, final int level) { |
Bookatz | 8c6571b | 2017-10-24 15:04:41 -0700 | [diff] [blame] | 12803 | |
| 12804 | if (recentPast == null || recentPast.batteryStatus != status) { |
| 12805 | StatsLog.write(StatsLog.CHARGING_STATE_CHANGED, status); |
| 12806 | } |
| 12807 | if (recentPast == null || recentPast.batteryPlugType != plugType) { |
| 12808 | StatsLog.write(StatsLog.PLUGGED_STATE_CHANGED, plugType); |
| 12809 | } |
| 12810 | if (recentPast == null || recentPast.batteryLevel != level) { |
| 12811 | StatsLog.write(StatsLog.BATTERY_LEVEL_CHANGED, level); |
| 12812 | } |
Bookatz | 8c6571b | 2017-10-24 15:04:41 -0700 | [diff] [blame] | 12813 | } |
| 12814 | |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 12815 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12816 | public long getAwakeTimeBattery() { |
| 12817 | return computeBatteryUptime(getBatteryUptimeLocked(), STATS_CURRENT); |
| 12818 | } |
| 12819 | |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 12820 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12821 | public long getAwakeTimePlugged() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 12822 | return (mClocks.uptimeMillis() * 1000) - getAwakeTimeBattery(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12823 | } |
| 12824 | |
| 12825 | @Override |
| 12826 | public long computeUptime(long curTime, int which) { |
| 12827 | switch (which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 12828 | case STATS_SINCE_CHARGED: return mUptime + (curTime-mUptimeStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12829 | case STATS_CURRENT: return (curTime-mUptimeStart); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 12830 | case STATS_SINCE_UNPLUGGED: return (curTime-mOnBatteryTimeBase.getUptimeStart()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12831 | } |
| 12832 | return 0; |
| 12833 | } |
| 12834 | |
| 12835 | @Override |
| 12836 | public long computeRealtime(long curTime, int which) { |
| 12837 | switch (which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 12838 | case STATS_SINCE_CHARGED: return mRealtime + (curTime-mRealtimeStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12839 | case STATS_CURRENT: return (curTime-mRealtimeStart); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 12840 | case STATS_SINCE_UNPLUGGED: return (curTime-mOnBatteryTimeBase.getRealtimeStart()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12841 | } |
| 12842 | return 0; |
| 12843 | } |
| 12844 | |
| 12845 | @Override |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 12846 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12847 | public long computeBatteryUptime(long curTime, int which) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 12848 | return mOnBatteryTimeBase.computeUptime(curTime, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12849 | } |
| 12850 | |
| 12851 | @Override |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 12852 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12853 | public long computeBatteryRealtime(long curTime, int which) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 12854 | return mOnBatteryTimeBase.computeRealtime(curTime, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12855 | } |
| 12856 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 12857 | @Override |
| 12858 | public long computeBatteryScreenOffUptime(long curTime, int which) { |
| 12859 | return mOnBatteryScreenOffTimeBase.computeUptime(curTime, which); |
| 12860 | } |
| 12861 | |
| 12862 | @Override |
| 12863 | public long computeBatteryScreenOffRealtime(long curTime, int which) { |
| 12864 | return mOnBatteryScreenOffTimeBase.computeRealtime(curTime, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12865 | } |
| 12866 | |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 12867 | private long computeTimePerLevel(long[] steps, int numSteps) { |
| 12868 | // For now we'll do a simple average across all steps. |
| 12869 | if (numSteps <= 0) { |
| 12870 | return -1; |
| 12871 | } |
| 12872 | long total = 0; |
| 12873 | for (int i=0; i<numSteps; i++) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 12874 | total += steps[i] & STEP_LEVEL_TIME_MASK; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 12875 | } |
| 12876 | return total / numSteps; |
| 12877 | /* |
| 12878 | long[] buckets = new long[numSteps]; |
| 12879 | int numBuckets = 0; |
| 12880 | int numToAverage = 4; |
| 12881 | int i = 0; |
| 12882 | while (i < numSteps) { |
| 12883 | long totalTime = 0; |
| 12884 | int num = 0; |
| 12885 | for (int j=0; j<numToAverage && (i+j)<numSteps; j++) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 12886 | totalTime += steps[i+j] & STEP_LEVEL_TIME_MASK; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 12887 | num++; |
| 12888 | } |
| 12889 | buckets[numBuckets] = totalTime / num; |
| 12890 | numBuckets++; |
| 12891 | numToAverage *= 2; |
| 12892 | i += num; |
| 12893 | } |
| 12894 | if (numBuckets < 1) { |
| 12895 | return -1; |
| 12896 | } |
| 12897 | long averageTime = buckets[numBuckets-1]; |
| 12898 | for (i=numBuckets-2; i>=0; i--) { |
| 12899 | averageTime = (averageTime + buckets[i]) / 2; |
| 12900 | } |
| 12901 | return averageTime; |
| 12902 | */ |
| 12903 | } |
| 12904 | |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 12905 | @Override |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 12906 | @UnsupportedAppUsage |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 12907 | public long computeBatteryTimeRemaining(long curTime) { |
| 12908 | if (!mOnBattery) { |
| 12909 | return -1; |
| 12910 | } |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 12911 | /* Simple implementation just looks at the average discharge per level across the |
| 12912 | entire sample period. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 12913 | int discharge = (getLowDischargeAmountSinceCharge()+getHighDischargeAmountSinceCharge())/2; |
| 12914 | if (discharge < 2) { |
| 12915 | return -1; |
| 12916 | } |
| 12917 | long duration = computeBatteryRealtime(curTime, STATS_SINCE_CHARGED); |
| 12918 | if (duration < 1000*1000) { |
| 12919 | return -1; |
| 12920 | } |
| 12921 | long usPerLevel = duration/discharge; |
| 12922 | return usPerLevel * mCurrentBatteryLevel; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 12923 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 12924 | if (mDischargeStepTracker.mNumStepDurations < 1) { |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 12925 | return -1; |
| 12926 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 12927 | long msPerLevel = mDischargeStepTracker.computeTimePerLevel(); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 12928 | if (msPerLevel <= 0) { |
| 12929 | return -1; |
| 12930 | } |
| 12931 | return (msPerLevel * mCurrentBatteryLevel) * 1000; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 12932 | } |
| 12933 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 12934 | @Override |
| 12935 | public LevelStepTracker getDischargeLevelStepTracker() { |
| 12936 | return mDischargeStepTracker; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 12937 | } |
| 12938 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 12939 | @Override |
| 12940 | public LevelStepTracker getDailyDischargeLevelStepTracker() { |
| 12941 | return mDailyDischargeStepTracker; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 12942 | } |
| 12943 | |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 12944 | @Override |
| 12945 | public long computeChargeTimeRemaining(long curTime) { |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 12946 | if (mOnBattery) { |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 12947 | // Not yet working. |
| 12948 | return -1; |
| 12949 | } |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 12950 | /* Broken |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 12951 | int curLevel = mCurrentBatteryLevel; |
| 12952 | int plugLevel = mDischargePlugLevel; |
| 12953 | if (plugLevel < 0 || curLevel < (plugLevel+1)) { |
| 12954 | return -1; |
| 12955 | } |
| 12956 | long duration = computeBatteryRealtime(curTime, STATS_SINCE_UNPLUGGED); |
| 12957 | if (duration < 1000*1000) { |
| 12958 | return -1; |
| 12959 | } |
| 12960 | long usPerLevel = duration/(curLevel-plugLevel); |
| 12961 | return usPerLevel * (100-curLevel); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 12962 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 12963 | if (mChargeStepTracker.mNumStepDurations < 1) { |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 12964 | return -1; |
| 12965 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 12966 | long msPerLevel = mChargeStepTracker.computeTimePerLevel(); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 12967 | if (msPerLevel <= 0) { |
| 12968 | return -1; |
| 12969 | } |
| 12970 | return (msPerLevel * (100-mCurrentBatteryLevel)) * 1000; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 12971 | } |
| 12972 | |
Siddharth Ray | a1fd057 | 2017-11-13 14:20:47 -0800 | [diff] [blame] | 12973 | /*@hide */ |
| 12974 | public CellularBatteryStats getCellularBatteryStats() { |
| 12975 | CellularBatteryStats s = new CellularBatteryStats(); |
| 12976 | final int which = STATS_SINCE_CHARGED; |
| 12977 | final long rawRealTime = SystemClock.elapsedRealtime() * 1000; |
| 12978 | final ControllerActivityCounter counter = getModemControllerActivity(); |
Siddharth Ray | ed75470 | 2018-02-15 12:44:37 -0800 | [diff] [blame] | 12979 | final long sleepTimeMs = counter.getSleepTimeCounter().getCountLocked(which); |
Siddharth Ray | a1fd057 | 2017-11-13 14:20:47 -0800 | [diff] [blame] | 12980 | final long idleTimeMs = counter.getIdleTimeCounter().getCountLocked(which); |
| 12981 | final long rxTimeMs = counter.getRxTimeCounter().getCountLocked(which); |
| 12982 | final long energyConsumedMaMs = counter.getPowerCounter().getCountLocked(which); |
| 12983 | long[] timeInRatMs = new long[BatteryStats.NUM_DATA_CONNECTION_TYPES]; |
| 12984 | for (int i = 0; i < timeInRatMs.length; i++) { |
| 12985 | timeInRatMs[i] = getPhoneDataConnectionTime(i, rawRealTime, which) / 1000; |
| 12986 | } |
| 12987 | long[] timeInRxSignalStrengthLevelMs = new long[SignalStrength.NUM_SIGNAL_STRENGTH_BINS]; |
| 12988 | for (int i = 0; i < timeInRxSignalStrengthLevelMs.length; i++) { |
| 12989 | timeInRxSignalStrengthLevelMs[i] |
| 12990 | = getPhoneSignalStrengthTime(i, rawRealTime, which) / 1000; |
| 12991 | } |
| 12992 | long[] txTimeMs = new long[Math.min(ModemActivityInfo.TX_POWER_LEVELS, |
| 12993 | counter.getTxTimeCounters().length)]; |
| 12994 | long totalTxTimeMs = 0; |
| 12995 | for (int i = 0; i < txTimeMs.length; i++) { |
| 12996 | txTimeMs[i] = counter.getTxTimeCounters()[i].getCountLocked(which); |
| 12997 | totalTxTimeMs += txTimeMs[i]; |
| 12998 | } |
Siddharth Ray | a1fd057 | 2017-11-13 14:20:47 -0800 | [diff] [blame] | 12999 | s.setLoggingDurationMs(computeBatteryRealtime(rawRealTime, which) / 1000); |
| 13000 | s.setKernelActiveTimeMs(getMobileRadioActiveTime(rawRealTime, which) / 1000); |
| 13001 | s.setNumPacketsTx(getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which)); |
| 13002 | s.setNumBytesTx(getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which)); |
| 13003 | s.setNumPacketsRx(getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which)); |
| 13004 | s.setNumBytesRx(getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which)); |
| 13005 | s.setSleepTimeMs(sleepTimeMs); |
| 13006 | s.setIdleTimeMs(idleTimeMs); |
| 13007 | s.setRxTimeMs(rxTimeMs); |
| 13008 | s.setEnergyConsumedMaMs(energyConsumedMaMs); |
| 13009 | s.setTimeInRatMs(timeInRatMs); |
| 13010 | s.setTimeInRxSignalStrengthLevelMs(timeInRxSignalStrengthLevelMs); |
| 13011 | s.setTxTimeMs(txTimeMs); |
| 13012 | return s; |
| 13013 | } |
| 13014 | |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 13015 | /*@hide */ |
| 13016 | public WifiBatteryStats getWifiBatteryStats() { |
| 13017 | WifiBatteryStats s = new WifiBatteryStats(); |
| 13018 | final int which = STATS_SINCE_CHARGED; |
| 13019 | final long rawRealTime = SystemClock.elapsedRealtime() * 1000; |
| 13020 | final ControllerActivityCounter counter = getWifiControllerActivity(); |
| 13021 | final long idleTimeMs = counter.getIdleTimeCounter().getCountLocked(which); |
| 13022 | final long scanTimeMs = counter.getScanTimeCounter().getCountLocked(which); |
| 13023 | final long rxTimeMs = counter.getRxTimeCounter().getCountLocked(which); |
| 13024 | final long txTimeMs = counter.getTxTimeCounters()[0].getCountLocked(which); |
| 13025 | final long totalControllerActivityTimeMs |
| 13026 | = computeBatteryRealtime(SystemClock.elapsedRealtime() * 1000, which) / 1000; |
| 13027 | final long sleepTimeMs |
| 13028 | = totalControllerActivityTimeMs - (idleTimeMs + rxTimeMs + txTimeMs); |
| 13029 | final long energyConsumedMaMs = counter.getPowerCounter().getCountLocked(which); |
| 13030 | long numAppScanRequest = 0; |
| 13031 | for (int i = 0; i < mUidStats.size(); i++) { |
| 13032 | numAppScanRequest += mUidStats.valueAt(i).mWifiScanTimer.getCountLocked(which); |
| 13033 | } |
| 13034 | long[] timeInStateMs = new long[NUM_WIFI_STATES]; |
| 13035 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 13036 | timeInStateMs[i] = getWifiStateTime(i, rawRealTime, which) / 1000; |
| 13037 | } |
| 13038 | long[] timeInSupplStateMs = new long[NUM_WIFI_SUPPL_STATES]; |
| 13039 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 13040 | timeInSupplStateMs[i] = getWifiSupplStateTime(i, rawRealTime, which) / 1000; |
| 13041 | } |
| 13042 | long[] timeSignalStrengthTimeMs = new long[NUM_WIFI_SIGNAL_STRENGTH_BINS]; |
| 13043 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 13044 | timeSignalStrengthTimeMs[i] = getWifiSignalStrengthTime(i, rawRealTime, which) / 1000; |
| 13045 | } |
| 13046 | s.setLoggingDurationMs(computeBatteryRealtime(rawRealTime, which) / 1000); |
| 13047 | s.setKernelActiveTimeMs(getWifiActiveTime(rawRealTime, which) / 1000); |
| 13048 | s.setNumPacketsTx(getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which)); |
| 13049 | s.setNumBytesTx(getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which)); |
| 13050 | s.setNumPacketsRx(getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which)); |
| 13051 | s.setNumBytesRx(getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which)); |
| 13052 | s.setSleepTimeMs(sleepTimeMs); |
| 13053 | s.setIdleTimeMs(idleTimeMs); |
| 13054 | s.setRxTimeMs(rxTimeMs); |
| 13055 | s.setTxTimeMs(txTimeMs); |
| 13056 | s.setScanTimeMs(scanTimeMs); |
| 13057 | s.setEnergyConsumedMaMs(energyConsumedMaMs); |
| 13058 | s.setNumAppScanRequest(numAppScanRequest); |
| 13059 | s.setTimeInStateMs(timeInStateMs); |
| 13060 | s.setTimeInSupplicantStateMs(timeInSupplStateMs); |
| 13061 | s.setTimeInRxSignalStrengthLevelMs(timeSignalStrengthTimeMs); |
| 13062 | return s; |
| 13063 | } |
| 13064 | |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 13065 | /*@hide */ |
| 13066 | public GpsBatteryStats getGpsBatteryStats() { |
| 13067 | GpsBatteryStats s = new GpsBatteryStats(); |
| 13068 | final int which = STATS_SINCE_CHARGED; |
| 13069 | final long rawRealTime = SystemClock.elapsedRealtime() * 1000; |
| 13070 | s.setLoggingDurationMs(computeBatteryRealtime(rawRealTime, which) / 1000); |
| 13071 | s.setEnergyConsumedMaMs(getGpsBatteryDrainMaMs()); |
| 13072 | long[] time = new long[GnssMetrics.NUM_GPS_SIGNAL_QUALITY_LEVELS]; |
| 13073 | for (int i=0; i<time.length; i++) { |
| 13074 | time[i] = getGpsSignalQualityTime(i, rawRealTime, which) / 1000; |
| 13075 | } |
| 13076 | s.setTimeInGpsSignalQualityLevel(time); |
| 13077 | return s; |
| 13078 | } |
| 13079 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 13080 | @Override |
| 13081 | public LevelStepTracker getChargeLevelStepTracker() { |
| 13082 | return mChargeStepTracker; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 13083 | } |
| 13084 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 13085 | @Override |
| 13086 | public LevelStepTracker getDailyChargeLevelStepTracker() { |
| 13087 | return mDailyChargeStepTracker; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 13088 | } |
| 13089 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 13090 | @Override |
| 13091 | public ArrayList<PackageChange> getDailyPackageChanges() { |
| 13092 | return mDailyPackageChanges; |
| 13093 | } |
| 13094 | |
Joe Onorato | e1acd63 | 2016-02-23 13:25:10 -0800 | [diff] [blame] | 13095 | protected long getBatteryUptimeLocked() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 13096 | return mOnBatteryTimeBase.getUptime(mClocks.uptimeMillis() * 1000); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13097 | } |
| 13098 | |
| 13099 | @Override |
| 13100 | public long getBatteryUptime(long curTime) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 13101 | return mOnBatteryTimeBase.getUptime(curTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13102 | } |
| 13103 | |
| 13104 | @Override |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 13105 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13106 | public long getBatteryRealtime(long curTime) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 13107 | return mOnBatteryTimeBase.getRealtime(curTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13108 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 13109 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 13110 | @Override |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 13111 | @UnsupportedAppUsage |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 13112 | public int getDischargeStartLevel() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 13113 | synchronized(this) { |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 13114 | return getDischargeStartLevelLocked(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 13115 | } |
| 13116 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 13117 | |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 13118 | public int getDischargeStartLevelLocked() { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 13119 | return mDischargeUnplugLevel; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 13120 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 13121 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 13122 | @Override |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 13123 | @UnsupportedAppUsage |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 13124 | public int getDischargeCurrentLevel() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 13125 | synchronized(this) { |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 13126 | return getDischargeCurrentLevelLocked(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 13127 | } |
| 13128 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 13129 | |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 13130 | public int getDischargeCurrentLevelLocked() { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 13131 | return mDischargeCurrentLevel; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 13132 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13133 | |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 13134 | @Override |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 13135 | public int getLowDischargeAmountSinceCharge() { |
| 13136 | synchronized(this) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 13137 | int val = mLowDischargeAmountSinceCharge; |
| 13138 | if (mOnBattery && mDischargeCurrentLevel < mDischargeUnplugLevel) { |
| 13139 | val += mDischargeUnplugLevel-mDischargeCurrentLevel-1; |
| 13140 | } |
| 13141 | return val; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 13142 | } |
| 13143 | } |
| 13144 | |
| 13145 | @Override |
| 13146 | public int getHighDischargeAmountSinceCharge() { |
| 13147 | synchronized(this) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 13148 | int val = mHighDischargeAmountSinceCharge; |
| 13149 | if (mOnBattery && mDischargeCurrentLevel < mDischargeUnplugLevel) { |
| 13150 | val += mDischargeUnplugLevel-mDischargeCurrentLevel; |
| 13151 | } |
| 13152 | return val; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 13153 | } |
| 13154 | } |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 13155 | |
| 13156 | @Override |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 13157 | @UnsupportedAppUsage |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 13158 | public int getDischargeAmount(int which) { |
| 13159 | int dischargeAmount = which == STATS_SINCE_CHARGED |
| 13160 | ? getHighDischargeAmountSinceCharge() |
| 13161 | : (getDischargeStartLevel() - getDischargeCurrentLevel()); |
| 13162 | if (dischargeAmount < 0) { |
| 13163 | dischargeAmount = 0; |
| 13164 | } |
| 13165 | return dischargeAmount; |
| 13166 | } |
| 13167 | |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 13168 | @Override |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 13169 | @UnsupportedAppUsage |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 13170 | public int getDischargeAmountScreenOn() { |
| 13171 | synchronized(this) { |
| 13172 | int val = mDischargeAmountScreenOn; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 13173 | if (mOnBattery && isScreenOn(mScreenState) |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 13174 | && mDischargeCurrentLevel < mDischargeScreenOnUnplugLevel) { |
| 13175 | val += mDischargeScreenOnUnplugLevel-mDischargeCurrentLevel; |
| 13176 | } |
| 13177 | return val; |
| 13178 | } |
| 13179 | } |
| 13180 | |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 13181 | @Override |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 13182 | public int getDischargeAmountScreenOnSinceCharge() { |
| 13183 | synchronized(this) { |
| 13184 | int val = mDischargeAmountScreenOnSinceCharge; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 13185 | if (mOnBattery && isScreenOn(mScreenState) |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 13186 | && mDischargeCurrentLevel < mDischargeScreenOnUnplugLevel) { |
| 13187 | val += mDischargeScreenOnUnplugLevel-mDischargeCurrentLevel; |
| 13188 | } |
| 13189 | return val; |
| 13190 | } |
| 13191 | } |
| 13192 | |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 13193 | @Override |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 13194 | @UnsupportedAppUsage |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 13195 | public int getDischargeAmountScreenOff() { |
| 13196 | synchronized(this) { |
| 13197 | int val = mDischargeAmountScreenOff; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 13198 | if (mOnBattery && isScreenOff(mScreenState) |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 13199 | && mDischargeCurrentLevel < mDischargeScreenOffUnplugLevel) { |
| 13200 | val += mDischargeScreenOffUnplugLevel-mDischargeCurrentLevel; |
| 13201 | } |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 13202 | // For backward compatibility, doze discharge is counted into screen off. |
| 13203 | return val + getDischargeAmountScreenDoze(); |
| 13204 | } |
| 13205 | } |
| 13206 | |
| 13207 | @Override |
| 13208 | public int getDischargeAmountScreenOffSinceCharge() { |
| 13209 | synchronized(this) { |
| 13210 | int val = mDischargeAmountScreenOffSinceCharge; |
| 13211 | if (mOnBattery && isScreenOff(mScreenState) |
| 13212 | && mDischargeCurrentLevel < mDischargeScreenOffUnplugLevel) { |
| 13213 | val += mDischargeScreenOffUnplugLevel-mDischargeCurrentLevel; |
| 13214 | } |
| 13215 | // For backward compatibility, doze discharge is counted into screen off. |
| 13216 | return val + getDischargeAmountScreenDozeSinceCharge(); |
| 13217 | } |
| 13218 | } |
| 13219 | |
| 13220 | @Override |
| 13221 | public int getDischargeAmountScreenDoze() { |
| 13222 | synchronized(this) { |
| 13223 | int val = mDischargeAmountScreenDoze; |
| 13224 | if (mOnBattery && isScreenDoze(mScreenState) |
| 13225 | && mDischargeCurrentLevel < mDischargeScreenDozeUnplugLevel) { |
| 13226 | val += mDischargeScreenDozeUnplugLevel-mDischargeCurrentLevel; |
| 13227 | } |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 13228 | return val; |
| 13229 | } |
| 13230 | } |
| 13231 | |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 13232 | @Override |
| 13233 | public int getDischargeAmountScreenDozeSinceCharge() { |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 13234 | synchronized(this) { |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 13235 | int val = mDischargeAmountScreenDozeSinceCharge; |
| 13236 | if (mOnBattery && isScreenDoze(mScreenState) |
| 13237 | && mDischargeCurrentLevel < mDischargeScreenDozeUnplugLevel) { |
| 13238 | val += mDischargeScreenDozeUnplugLevel-mDischargeCurrentLevel; |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 13239 | } |
| 13240 | return val; |
| 13241 | } |
| 13242 | } |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 13243 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13244 | /** |
| 13245 | * Retrieve the statistics object for a particular uid, creating if needed. |
| 13246 | */ |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 13247 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13248 | public Uid getUidStatsLocked(int uid) { |
| 13249 | Uid u = mUidStats.get(uid); |
| 13250 | if (u == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 13251 | u = new Uid(this, uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13252 | mUidStats.put(uid, u); |
| 13253 | } |
| 13254 | return u; |
| 13255 | } |
| 13256 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 13257 | /** |
| 13258 | * Retrieve the statistics object for a particular uid. Returns null if the object is not |
| 13259 | * available. |
| 13260 | */ |
| 13261 | public Uid getAvailableUidStatsLocked(int uid) { |
| 13262 | Uid u = mUidStats.get(uid); |
| 13263 | return u; |
| 13264 | } |
| 13265 | |
Suprabh Shukla | e6e723d | 2017-06-14 16:14:43 -0700 | [diff] [blame] | 13266 | public void onCleanupUserLocked(int userId) { |
| 13267 | final int firstUidForUser = UserHandle.getUid(userId, 0); |
| 13268 | final int lastUidForUser = UserHandle.getUid(userId, UserHandle.PER_USER_RANGE - 1); |
Mike Ma | 234d182 | 2018-03-13 18:53:21 -0700 | [diff] [blame] | 13269 | mPendingRemovedUids.add( |
| 13270 | new UidToRemove(firstUidForUser, lastUidForUser, mClocks.elapsedRealtime())); |
Suprabh Shukla | e6e723d | 2017-06-14 16:14:43 -0700 | [diff] [blame] | 13271 | } |
| 13272 | |
| 13273 | public void onUserRemovedLocked(int userId) { |
| 13274 | final int firstUidForUser = UserHandle.getUid(userId, 0); |
| 13275 | final int lastUidForUser = UserHandle.getUid(userId, UserHandle.PER_USER_RANGE - 1); |
| 13276 | mUidStats.put(firstUidForUser, null); |
| 13277 | mUidStats.put(lastUidForUser, null); |
| 13278 | final int firstIndex = mUidStats.indexOfKey(firstUidForUser); |
| 13279 | final int lastIndex = mUidStats.indexOfKey(lastUidForUser); |
| 13280 | mUidStats.removeAtRange(firstIndex, lastIndex - firstIndex + 1); |
| 13281 | } |
| 13282 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13283 | /** |
| 13284 | * Remove the statistics object for a particular uid. |
| 13285 | */ |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 13286 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13287 | public void removeUidStatsLocked(int uid) { |
| 13288 | mUidStats.remove(uid); |
Mike Ma | 234d182 | 2018-03-13 18:53:21 -0700 | [diff] [blame] | 13289 | mPendingRemovedUids.add(new UidToRemove(uid, mClocks.elapsedRealtime())); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13290 | } |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 13291 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13292 | /** |
| 13293 | * Retrieve the statistics object for a particular process, creating |
| 13294 | * if needed. |
| 13295 | */ |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 13296 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13297 | public Uid.Proc getProcessStatsLocked(int uid, String name) { |
Dianne Hackborn | bbb7472 | 2014-03-13 09:50:24 -0700 | [diff] [blame] | 13298 | uid = mapUid(uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13299 | Uid u = getUidStatsLocked(uid); |
| 13300 | return u.getProcessStatsLocked(name); |
| 13301 | } |
| 13302 | |
| 13303 | /** |
| 13304 | * Retrieve the statistics object for a particular process, creating |
| 13305 | * if needed. |
| 13306 | */ |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 13307 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13308 | public Uid.Pkg getPackageStatsLocked(int uid, String pkg) { |
Dianne Hackborn | bbb7472 | 2014-03-13 09:50:24 -0700 | [diff] [blame] | 13309 | uid = mapUid(uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13310 | Uid u = getUidStatsLocked(uid); |
| 13311 | return u.getPackageStatsLocked(pkg); |
| 13312 | } |
| 13313 | |
| 13314 | /** |
| 13315 | * Retrieve the statistics object for a particular service, creating |
| 13316 | * if needed. |
| 13317 | */ |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 13318 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13319 | public Uid.Pkg.Serv getServiceStatsLocked(int uid, String pkg, String name) { |
Dianne Hackborn | bbb7472 | 2014-03-13 09:50:24 -0700 | [diff] [blame] | 13320 | uid = mapUid(uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13321 | Uid u = getUidStatsLocked(uid); |
| 13322 | return u.getServiceStatsLocked(pkg, name); |
| 13323 | } |
| 13324 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 13325 | public void shutdownLocked() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 13326 | recordShutdownLocked(mClocks.elapsedRealtime(), mClocks.uptimeMillis()); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 13327 | writeSyncLocked(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 13328 | mShuttingDown = true; |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 13329 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 13330 | |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 13331 | public boolean trackPerProcStateCpuTimes() { |
| 13332 | return mConstants.TRACK_CPU_TIMES_BY_PROC_STATE && mPerProcStateCpuTimesAvailable; |
| 13333 | } |
| 13334 | |
| 13335 | public void systemServicesReady(Context context) { |
| 13336 | mConstants.startObserving(context.getContentResolver()); |
Mike Ma | fbc01fc | 2018-04-02 10:28:28 -0700 | [diff] [blame] | 13337 | registerUsbStateReceiver(context); |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 13338 | } |
| 13339 | |
| 13340 | @VisibleForTesting |
| 13341 | public final class Constants extends ContentObserver { |
| 13342 | public static final String KEY_TRACK_CPU_TIMES_BY_PROC_STATE |
| 13343 | = "track_cpu_times_by_proc_state"; |
Mike Ma | fae87da | 2018-01-19 20:07:20 -0800 | [diff] [blame] | 13344 | public static final String KEY_TRACK_CPU_ACTIVE_CLUSTER_TIME |
| 13345 | = "track_cpu_active_cluster_time"; |
Sudheer Shanka | c20379e | 2018-02-15 00:06:21 -0800 | [diff] [blame] | 13346 | public static final String KEY_PROC_STATE_CPU_TIMES_READ_DELAY_MS |
| 13347 | = "proc_state_cpu_times_read_delay_ms"; |
Mike Ma | 2ab0144 | 2018-02-13 14:22:47 -0800 | [diff] [blame] | 13348 | public static final String KEY_KERNEL_UID_READERS_THROTTLE_TIME |
| 13349 | = "kernel_uid_readers_throttle_time"; |
Mike Ma | 234d182 | 2018-03-13 18:53:21 -0700 | [diff] [blame] | 13350 | public static final String KEY_UID_REMOVE_DELAY_MS |
| 13351 | = "uid_remove_delay_ms"; |
Sudheer Shanka | e56013a | 2018-04-23 11:22:15 -0700 | [diff] [blame] | 13352 | public static final String KEY_EXTERNAL_STATS_COLLECTION_RATE_LIMIT_MS |
| 13353 | = "external_stats_collection_rate_limit_ms"; |
Sudheer Shanka | 0719c6a | 2018-04-24 11:12:11 -0700 | [diff] [blame] | 13354 | public static final String KEY_BATTERY_LEVEL_COLLECTION_DELAY_MS |
| 13355 | = "battery_level_collection_delay_ms"; |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 13356 | |
| 13357 | private static final boolean DEFAULT_TRACK_CPU_TIMES_BY_PROC_STATE = true; |
Mike Ma | fae87da | 2018-01-19 20:07:20 -0800 | [diff] [blame] | 13358 | private static final boolean DEFAULT_TRACK_CPU_ACTIVE_CLUSTER_TIME = true; |
Sudheer Shanka | c20379e | 2018-02-15 00:06:21 -0800 | [diff] [blame] | 13359 | private static final long DEFAULT_PROC_STATE_CPU_TIMES_READ_DELAY_MS = 5_000; |
Mike Ma | 2ab0144 | 2018-02-13 14:22:47 -0800 | [diff] [blame] | 13360 | private static final long DEFAULT_KERNEL_UID_READERS_THROTTLE_TIME = 10_000; |
Mike Ma | 234d182 | 2018-03-13 18:53:21 -0700 | [diff] [blame] | 13361 | private static final long DEFAULT_UID_REMOVE_DELAY_MS = 5L * 60L * 1000L; |
Sudheer Shanka | e56013a | 2018-04-23 11:22:15 -0700 | [diff] [blame] | 13362 | private static final long DEFAULT_EXTERNAL_STATS_COLLECTION_RATE_LIMIT_MS = 600_000; |
Sudheer Shanka | 0719c6a | 2018-04-24 11:12:11 -0700 | [diff] [blame] | 13363 | private static final long DEFAULT_BATTERY_LEVEL_COLLECTION_DELAY_MS = 300_000; |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 13364 | |
| 13365 | public boolean TRACK_CPU_TIMES_BY_PROC_STATE = DEFAULT_TRACK_CPU_TIMES_BY_PROC_STATE; |
Mike Ma | fae87da | 2018-01-19 20:07:20 -0800 | [diff] [blame] | 13366 | public boolean TRACK_CPU_ACTIVE_CLUSTER_TIME = DEFAULT_TRACK_CPU_ACTIVE_CLUSTER_TIME; |
Sudheer Shanka | c20379e | 2018-02-15 00:06:21 -0800 | [diff] [blame] | 13367 | public long PROC_STATE_CPU_TIMES_READ_DELAY_MS = DEFAULT_PROC_STATE_CPU_TIMES_READ_DELAY_MS; |
Mike Ma | 2ab0144 | 2018-02-13 14:22:47 -0800 | [diff] [blame] | 13368 | public long KERNEL_UID_READERS_THROTTLE_TIME = DEFAULT_KERNEL_UID_READERS_THROTTLE_TIME; |
Mike Ma | 234d182 | 2018-03-13 18:53:21 -0700 | [diff] [blame] | 13369 | public long UID_REMOVE_DELAY_MS = DEFAULT_UID_REMOVE_DELAY_MS; |
Sudheer Shanka | e56013a | 2018-04-23 11:22:15 -0700 | [diff] [blame] | 13370 | public long EXTERNAL_STATS_COLLECTION_RATE_LIMIT_MS |
| 13371 | = DEFAULT_EXTERNAL_STATS_COLLECTION_RATE_LIMIT_MS; |
Sudheer Shanka | 0719c6a | 2018-04-24 11:12:11 -0700 | [diff] [blame] | 13372 | public long BATTERY_LEVEL_COLLECTION_DELAY_MS |
| 13373 | = DEFAULT_BATTERY_LEVEL_COLLECTION_DELAY_MS; |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 13374 | |
| 13375 | private ContentResolver mResolver; |
| 13376 | private final KeyValueListParser mParser = new KeyValueListParser(','); |
| 13377 | |
| 13378 | public Constants(Handler handler) { |
| 13379 | super(handler); |
| 13380 | } |
| 13381 | |
| 13382 | public void startObserving(ContentResolver resolver) { |
| 13383 | mResolver = resolver; |
| 13384 | mResolver.registerContentObserver( |
| 13385 | Settings.Global.getUriFor(Settings.Global.BATTERY_STATS_CONSTANTS), |
| 13386 | false /* notifyForDescendants */, this); |
| 13387 | updateConstants(); |
| 13388 | } |
| 13389 | |
| 13390 | @Override |
| 13391 | public void onChange(boolean selfChange, Uri uri) { |
| 13392 | updateConstants(); |
| 13393 | } |
| 13394 | |
| 13395 | private void updateConstants() { |
| 13396 | synchronized (BatteryStatsImpl.this) { |
| 13397 | try { |
| 13398 | mParser.setString(Settings.Global.getString(mResolver, |
| 13399 | Settings.Global.BATTERY_STATS_CONSTANTS)); |
| 13400 | } catch (IllegalArgumentException e) { |
| 13401 | // Failed to parse the settings string, log this and move on |
| 13402 | // with defaults. |
| 13403 | Slog.e(TAG, "Bad batterystats settings", e); |
| 13404 | } |
| 13405 | |
| 13406 | updateTrackCpuTimesByProcStateLocked(TRACK_CPU_TIMES_BY_PROC_STATE, |
| 13407 | mParser.getBoolean(KEY_TRACK_CPU_TIMES_BY_PROC_STATE, |
| 13408 | DEFAULT_TRACK_CPU_TIMES_BY_PROC_STATE)); |
Mike Ma | fae87da | 2018-01-19 20:07:20 -0800 | [diff] [blame] | 13409 | TRACK_CPU_ACTIVE_CLUSTER_TIME = mParser.getBoolean( |
| 13410 | KEY_TRACK_CPU_ACTIVE_CLUSTER_TIME, DEFAULT_TRACK_CPU_ACTIVE_CLUSTER_TIME); |
Sudheer Shanka | c20379e | 2018-02-15 00:06:21 -0800 | [diff] [blame] | 13411 | updateProcStateCpuTimesReadDelayMs(PROC_STATE_CPU_TIMES_READ_DELAY_MS, |
| 13412 | mParser.getLong(KEY_PROC_STATE_CPU_TIMES_READ_DELAY_MS, |
Mike Ma | 2ab0144 | 2018-02-13 14:22:47 -0800 | [diff] [blame] | 13413 | DEFAULT_PROC_STATE_CPU_TIMES_READ_DELAY_MS)); |
| 13414 | updateKernelUidReadersThrottleTime(KERNEL_UID_READERS_THROTTLE_TIME, |
| 13415 | mParser.getLong(KEY_KERNEL_UID_READERS_THROTTLE_TIME, |
| 13416 | DEFAULT_KERNEL_UID_READERS_THROTTLE_TIME)); |
Mike Ma | 234d182 | 2018-03-13 18:53:21 -0700 | [diff] [blame] | 13417 | updateUidRemoveDelay( |
| 13418 | mParser.getLong(KEY_UID_REMOVE_DELAY_MS, DEFAULT_UID_REMOVE_DELAY_MS)); |
Sudheer Shanka | e56013a | 2018-04-23 11:22:15 -0700 | [diff] [blame] | 13419 | EXTERNAL_STATS_COLLECTION_RATE_LIMIT_MS = mParser.getLong( |
| 13420 | KEY_EXTERNAL_STATS_COLLECTION_RATE_LIMIT_MS, |
| 13421 | DEFAULT_EXTERNAL_STATS_COLLECTION_RATE_LIMIT_MS); |
Sudheer Shanka | 0719c6a | 2018-04-24 11:12:11 -0700 | [diff] [blame] | 13422 | BATTERY_LEVEL_COLLECTION_DELAY_MS = mParser.getLong( |
| 13423 | KEY_BATTERY_LEVEL_COLLECTION_DELAY_MS, |
| 13424 | DEFAULT_BATTERY_LEVEL_COLLECTION_DELAY_MS); |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 13425 | } |
| 13426 | } |
| 13427 | |
| 13428 | private void updateTrackCpuTimesByProcStateLocked(boolean wasEnabled, boolean isEnabled) { |
| 13429 | TRACK_CPU_TIMES_BY_PROC_STATE = isEnabled; |
| 13430 | if (isEnabled && !wasEnabled) { |
| 13431 | mKernelSingleUidTimeReader.markDataAsStale(true); |
| 13432 | mExternalSync.scheduleCpuSyncDueToSettingChange(); |
Sudheer Shanka | c20379e | 2018-02-15 00:06:21 -0800 | [diff] [blame] | 13433 | |
Mike Ma | 234d182 | 2018-03-13 18:53:21 -0700 | [diff] [blame] | 13434 | mNumSingleUidCpuTimeReads = 0; |
| 13435 | mNumBatchedSingleUidCpuTimeReads = 0; |
Sudheer Shanka | c20379e | 2018-02-15 00:06:21 -0800 | [diff] [blame] | 13436 | mCpuTimeReadsTrackingStartTime = mClocks.uptimeMillis(); |
| 13437 | } |
| 13438 | } |
| 13439 | |
| 13440 | private void updateProcStateCpuTimesReadDelayMs(long oldDelayMillis, long newDelayMillis) { |
| 13441 | PROC_STATE_CPU_TIMES_READ_DELAY_MS = newDelayMillis; |
| 13442 | if (oldDelayMillis != newDelayMillis) { |
Mike Ma | 234d182 | 2018-03-13 18:53:21 -0700 | [diff] [blame] | 13443 | mNumSingleUidCpuTimeReads = 0; |
| 13444 | mNumBatchedSingleUidCpuTimeReads = 0; |
Sudheer Shanka | c20379e | 2018-02-15 00:06:21 -0800 | [diff] [blame] | 13445 | mCpuTimeReadsTrackingStartTime = mClocks.uptimeMillis(); |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 13446 | } |
| 13447 | } |
| 13448 | |
Mike Ma | 2ab0144 | 2018-02-13 14:22:47 -0800 | [diff] [blame] | 13449 | private void updateKernelUidReadersThrottleTime(long oldTimeMs, long newTimeMs) { |
| 13450 | KERNEL_UID_READERS_THROTTLE_TIME = newTimeMs; |
| 13451 | if (oldTimeMs != newTimeMs) { |
Mike Ma | 69d8b3e | 2018-02-23 14:51:26 -0800 | [diff] [blame] | 13452 | mKernelUidCpuTimeReader.setThrottleInterval(KERNEL_UID_READERS_THROTTLE_TIME); |
Mike Ma | 2ab0144 | 2018-02-13 14:22:47 -0800 | [diff] [blame] | 13453 | mKernelUidCpuFreqTimeReader.setThrottleInterval(KERNEL_UID_READERS_THROTTLE_TIME); |
| 13454 | mKernelUidCpuActiveTimeReader.setThrottleInterval(KERNEL_UID_READERS_THROTTLE_TIME); |
| 13455 | mKernelUidCpuClusterTimeReader |
| 13456 | .setThrottleInterval(KERNEL_UID_READERS_THROTTLE_TIME); |
| 13457 | } |
| 13458 | } |
| 13459 | |
Mike Ma | 234d182 | 2018-03-13 18:53:21 -0700 | [diff] [blame] | 13460 | private void updateUidRemoveDelay(long newTimeMs) { |
| 13461 | UID_REMOVE_DELAY_MS = newTimeMs; |
| 13462 | clearPendingRemovedUids(); |
| 13463 | } |
| 13464 | |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 13465 | public void dumpLocked(PrintWriter pw) { |
| 13466 | pw.print(KEY_TRACK_CPU_TIMES_BY_PROC_STATE); pw.print("="); |
| 13467 | pw.println(TRACK_CPU_TIMES_BY_PROC_STATE); |
Mike Ma | fae87da | 2018-01-19 20:07:20 -0800 | [diff] [blame] | 13468 | pw.print(KEY_TRACK_CPU_ACTIVE_CLUSTER_TIME); pw.print("="); |
| 13469 | pw.println(TRACK_CPU_ACTIVE_CLUSTER_TIME); |
Sudheer Shanka | c20379e | 2018-02-15 00:06:21 -0800 | [diff] [blame] | 13470 | pw.print(KEY_PROC_STATE_CPU_TIMES_READ_DELAY_MS); pw.print("="); |
| 13471 | pw.println(PROC_STATE_CPU_TIMES_READ_DELAY_MS); |
Mike Ma | 2ab0144 | 2018-02-13 14:22:47 -0800 | [diff] [blame] | 13472 | pw.print(KEY_KERNEL_UID_READERS_THROTTLE_TIME); pw.print("="); |
| 13473 | pw.println(KERNEL_UID_READERS_THROTTLE_TIME); |
Sudheer Shanka | e56013a | 2018-04-23 11:22:15 -0700 | [diff] [blame] | 13474 | pw.print(KEY_EXTERNAL_STATS_COLLECTION_RATE_LIMIT_MS); pw.print("="); |
| 13475 | pw.println(EXTERNAL_STATS_COLLECTION_RATE_LIMIT_MS); |
Sudheer Shanka | 0719c6a | 2018-04-24 11:12:11 -0700 | [diff] [blame] | 13476 | pw.print(KEY_BATTERY_LEVEL_COLLECTION_DELAY_MS); pw.print("="); |
| 13477 | pw.println(BATTERY_LEVEL_COLLECTION_DELAY_MS); |
Sudheer Shanka | e56013a | 2018-04-23 11:22:15 -0700 | [diff] [blame] | 13478 | } |
| 13479 | } |
| 13480 | |
| 13481 | public long getExternalStatsCollectionRateLimitMs() { |
| 13482 | synchronized (this) { |
| 13483 | return mConstants.EXTERNAL_STATS_COLLECTION_RATE_LIMIT_MS; |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 13484 | } |
| 13485 | } |
| 13486 | |
Andreas Gampe | 3f24e69 | 2018-02-05 13:24:28 -0800 | [diff] [blame] | 13487 | @GuardedBy("this") |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 13488 | public void dumpConstantsLocked(PrintWriter pw) { |
| 13489 | mConstants.dumpLocked(pw); |
| 13490 | } |
| 13491 | |
Mike Ma | 234d182 | 2018-03-13 18:53:21 -0700 | [diff] [blame] | 13492 | @GuardedBy("this") |
| 13493 | public void dumpCpuStatsLocked(PrintWriter pw) { |
| 13494 | int size = mUidStats.size(); |
| 13495 | pw.println("Per UID CPU user & system time in ms:"); |
| 13496 | for (int i = 0; i < size; i++) { |
| 13497 | int u = mUidStats.keyAt(i); |
| 13498 | Uid uid = mUidStats.get(u); |
| 13499 | pw.print(" "); pw.print(u); pw.print(": "); |
| 13500 | pw.print(uid.getUserCpuTimeUs(STATS_SINCE_CHARGED) / 1000); pw.print(" "); |
| 13501 | pw.println(uid.getSystemCpuTimeUs(STATS_SINCE_CHARGED) / 1000); |
| 13502 | } |
| 13503 | pw.println("Per UID CPU active time in ms:"); |
| 13504 | for (int i = 0; i < size; i++) { |
| 13505 | int u = mUidStats.keyAt(i); |
| 13506 | Uid uid = mUidStats.get(u); |
| 13507 | if (uid.getCpuActiveTime() > 0) { |
| 13508 | pw.print(" "); pw.print(u); pw.print(": "); pw.println(uid.getCpuActiveTime()); |
| 13509 | } |
| 13510 | } |
| 13511 | pw.println("Per UID CPU cluster time in ms:"); |
| 13512 | for (int i = 0; i < size; i++) { |
| 13513 | int u = mUidStats.keyAt(i); |
| 13514 | long[] times = mUidStats.get(u).getCpuClusterTimes(); |
| 13515 | if (times != null) { |
| 13516 | pw.print(" "); pw.print(u); pw.print(": "); pw.println(Arrays.toString(times)); |
| 13517 | } |
| 13518 | } |
| 13519 | pw.println("Per UID CPU frequency time in ms:"); |
| 13520 | for (int i = 0; i < size; i++) { |
| 13521 | int u = mUidStats.keyAt(i); |
| 13522 | long[] times = mUidStats.get(u).getCpuFreqTimes(STATS_SINCE_CHARGED); |
| 13523 | if (times != null) { |
| 13524 | pw.print(" "); pw.print(u); pw.print(": "); pw.println(Arrays.toString(times)); |
| 13525 | } |
| 13526 | } |
| 13527 | } |
| 13528 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 13529 | Parcel mPendingWrite = null; |
| 13530 | final ReentrantLock mWriteLock = new ReentrantLock(); |
| 13531 | |
| 13532 | public void writeAsyncLocked() { |
| 13533 | writeLocked(false); |
| 13534 | } |
| 13535 | |
| 13536 | public void writeSyncLocked() { |
| 13537 | writeLocked(true); |
| 13538 | } |
| 13539 | |
| 13540 | void writeLocked(boolean sync) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 13541 | if (mFile == null) { |
| 13542 | 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] | 13543 | return; |
| 13544 | } |
| 13545 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 13546 | if (mShuttingDown) { |
| 13547 | return; |
| 13548 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 13549 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 13550 | Parcel out = Parcel.obtain(); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 13551 | writeSummaryToParcel(out, true); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 13552 | mLastWriteTime = mClocks.elapsedRealtime(); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 13553 | |
| 13554 | if (mPendingWrite != null) { |
| 13555 | mPendingWrite.recycle(); |
| 13556 | } |
| 13557 | mPendingWrite = out; |
| 13558 | |
| 13559 | if (sync) { |
| 13560 | commitPendingDataToDisk(); |
| 13561 | } else { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 13562 | BackgroundThread.getHandler().post(new Runnable() { |
| 13563 | @Override public void run() { |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 13564 | commitPendingDataToDisk(); |
| 13565 | } |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 13566 | }); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 13567 | } |
| 13568 | } |
| 13569 | |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 13570 | @UnsupportedAppUsage |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 13571 | public void commitPendingDataToDisk() { |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 13572 | final Parcel next; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 13573 | synchronized (this) { |
| 13574 | next = mPendingWrite; |
| 13575 | mPendingWrite = null; |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 13576 | if (next == null) { |
| 13577 | return; |
| 13578 | } |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 13579 | } |
| 13580 | |
Amith Yamasani | d245086 | 2017-02-07 15:58:24 -0800 | [diff] [blame] | 13581 | mWriteLock.lock(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13582 | try { |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 13583 | final long startTime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 13584 | FileOutputStream stream = new FileOutputStream(mFile.chooseForWrite()); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 13585 | stream.write(next.marshall()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13586 | stream.flush(); |
Dianne Hackborn | 8bdf593 | 2010-10-15 12:54:40 -0700 | [diff] [blame] | 13587 | FileUtils.sync(stream); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13588 | stream.close(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 13589 | mFile.commit(); |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 13590 | com.android.internal.logging.EventLogTags.writeCommitSysConfigFile( |
| 13591 | "batterystats", SystemClock.uptimeMillis() - startTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13592 | } catch (IOException e) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 13593 | Slog.w("BatteryStats", "Error writing battery statistics", e); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 13594 | mFile.rollback(); |
| 13595 | } finally { |
| 13596 | next.recycle(); |
| 13597 | mWriteLock.unlock(); |
Suchi Amalapurapu | 8550f25 | 2009-09-29 15:20:32 -0700 | [diff] [blame] | 13598 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13599 | } |
| 13600 | |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 13601 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13602 | public void readLocked() { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 13603 | if (mDailyFile != null) { |
| 13604 | readDailyStatsLocked(); |
| 13605 | } |
| 13606 | |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 13607 | if (mFile == null) { |
| 13608 | 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] | 13609 | return; |
| 13610 | } |
| 13611 | |
| 13612 | mUidStats.clear(); |
| 13613 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13614 | try { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 13615 | File file = mFile.chooseForRead(); |
| 13616 | if (!file.exists()) { |
| 13617 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13618 | } |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 13619 | FileInputStream stream = new FileInputStream(file); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13620 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 13621 | byte[] raw = BatteryStatsHelper.readFully(stream); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13622 | Parcel in = Parcel.obtain(); |
| 13623 | in.unmarshall(raw, 0, raw.length); |
| 13624 | in.setDataPosition(0); |
| 13625 | stream.close(); |
| 13626 | |
| 13627 | readSummaryFromParcel(in); |
Dianne Hackborn | 00e2521 | 2014-02-19 10:49:24 -0800 | [diff] [blame] | 13628 | } catch(Exception e) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 13629 | Slog.e("BatteryStats", "Error reading battery statistics", e); |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 13630 | resetAllStatsLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13631 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 13632 | |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 13633 | mEndPlatformVersion = Build.ID; |
| 13634 | |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 13635 | if (mHistoryBuffer.dataPosition() > 0) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 13636 | mRecordingHistory = true; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 13637 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 13638 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 13639 | if (USE_OLD_HISTORY) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 13640 | addHistoryRecordLocked(elapsedRealtime, uptime, HistoryItem.CMD_START, mHistoryCur); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 13641 | } |
Narayan Kamath | 5a5a7fe | 2018-02-05 17:30:06 +0000 | [diff] [blame] | 13642 | addHistoryBufferLocked(elapsedRealtime, HistoryItem.CMD_START, mHistoryCur); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 13643 | startRecordingHistory(elapsedRealtime, uptime, false); |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 13644 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 13645 | |
| 13646 | recordDailyStatsIfNeededLocked(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13647 | } |
| 13648 | |
| 13649 | public int describeContents() { |
| 13650 | return 0; |
| 13651 | } |
| 13652 | |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 13653 | void readHistory(Parcel in, boolean andOldHistory) throws ParcelFormatException { |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 13654 | final long historyBaseTime = in.readLong(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 13655 | |
| 13656 | mHistoryBuffer.setDataSize(0); |
| 13657 | mHistoryBuffer.setDataPosition(0); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 13658 | mHistoryTagPool.clear(); |
| 13659 | mNextHistoryTagIdx = 0; |
| 13660 | mNumHistoryTagChars = 0; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 13661 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 13662 | int numTags = in.readInt(); |
| 13663 | for (int i=0; i<numTags; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 13664 | int idx = in.readInt(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 13665 | String str = in.readString(); |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 13666 | if (str == null) { |
| 13667 | throw new ParcelFormatException("null history tag string"); |
| 13668 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 13669 | int uid = in.readInt(); |
| 13670 | HistoryTag tag = new HistoryTag(); |
| 13671 | tag.string = str; |
| 13672 | tag.uid = uid; |
| 13673 | tag.poolIdx = idx; |
| 13674 | mHistoryTagPool.put(tag, idx); |
| 13675 | if (idx >= mNextHistoryTagIdx) { |
| 13676 | mNextHistoryTagIdx = idx+1; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 13677 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 13678 | mNumHistoryTagChars += tag.string.length() + 1; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 13679 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 13680 | |
| 13681 | int bufSize = in.readInt(); |
| 13682 | int curPos = in.dataPosition(); |
| 13683 | if (bufSize >= (MAX_MAX_HISTORY_BUFFER*3)) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 13684 | throw new ParcelFormatException("File corrupt: history data buffer too large " + |
| 13685 | bufSize); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 13686 | } else if ((bufSize&~3) != bufSize) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 13687 | throw new ParcelFormatException("File corrupt: history data buffer not aligned " + |
| 13688 | bufSize); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 13689 | } else { |
| 13690 | if (DEBUG_HISTORY) Slog.i(TAG, "***************** READING NEW HISTORY: " + bufSize |
| 13691 | + " bytes at " + curPos); |
| 13692 | mHistoryBuffer.appendFrom(in, curPos, bufSize); |
| 13693 | in.setDataPosition(curPos + bufSize); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 13694 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 13695 | |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 13696 | if (andOldHistory) { |
| 13697 | readOldHistory(in); |
| 13698 | } |
| 13699 | |
| 13700 | if (DEBUG_HISTORY) { |
| 13701 | StringBuilder sb = new StringBuilder(128); |
| 13702 | sb.append("****************** OLD mHistoryBaseTime: "); |
| 13703 | TimeUtils.formatDuration(mHistoryBaseTime, sb); |
| 13704 | Slog.i(TAG, sb.toString()); |
| 13705 | } |
| 13706 | mHistoryBaseTime = historyBaseTime; |
| 13707 | if (DEBUG_HISTORY) { |
| 13708 | StringBuilder sb = new StringBuilder(128); |
| 13709 | sb.append("****************** NEW mHistoryBaseTime: "); |
| 13710 | TimeUtils.formatDuration(mHistoryBaseTime, sb); |
| 13711 | Slog.i(TAG, sb.toString()); |
| 13712 | } |
| 13713 | |
| 13714 | // We are just arbitrarily going to insert 1 minute from the sample of |
| 13715 | // the last run until samples in this run. |
| 13716 | if (mHistoryBaseTime > 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 13717 | long oldnow = mClocks.elapsedRealtime(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 13718 | mHistoryBaseTime = mHistoryBaseTime - oldnow + 1; |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 13719 | if (DEBUG_HISTORY) { |
| 13720 | StringBuilder sb = new StringBuilder(128); |
| 13721 | sb.append("****************** ADJUSTED mHistoryBaseTime: "); |
| 13722 | TimeUtils.formatDuration(mHistoryBaseTime, sb); |
| 13723 | Slog.i(TAG, sb.toString()); |
| 13724 | } |
Dianne Hackborn | 1e4b9f3 | 2010-06-23 14:10:57 -0700 | [diff] [blame] | 13725 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 13726 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 13727 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 13728 | void readOldHistory(Parcel in) { |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 13729 | if (!USE_OLD_HISTORY) { |
| 13730 | return; |
| 13731 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 13732 | mHistory = mHistoryEnd = mHistoryCache = null; |
| 13733 | long time; |
Conley Owens | 5e3357f | 2011-05-02 09:59:30 -0700 | [diff] [blame] | 13734 | while (in.dataAvail() > 0 && (time=in.readLong()) >= 0) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 13735 | HistoryItem rec = new HistoryItem(time, in); |
| 13736 | addHistoryRecordLocked(rec); |
| 13737 | } |
| 13738 | } |
| 13739 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 13740 | void writeHistory(Parcel out, boolean inclData, boolean andOldHistory) { |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 13741 | if (DEBUG_HISTORY) { |
| 13742 | StringBuilder sb = new StringBuilder(128); |
| 13743 | sb.append("****************** WRITING mHistoryBaseTime: "); |
| 13744 | TimeUtils.formatDuration(mHistoryBaseTime, sb); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 13745 | sb.append(" mLastHistoryElapsedRealtime: "); |
| 13746 | TimeUtils.formatDuration(mLastHistoryElapsedRealtime, sb); |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 13747 | Slog.i(TAG, sb.toString()); |
| 13748 | } |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 13749 | out.writeLong(mHistoryBaseTime + mLastHistoryElapsedRealtime); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 13750 | if (!inclData) { |
| 13751 | out.writeInt(0); |
| 13752 | out.writeInt(0); |
| 13753 | return; |
| 13754 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 13755 | out.writeInt(mHistoryTagPool.size()); |
| 13756 | for (HashMap.Entry<HistoryTag, Integer> ent : mHistoryTagPool.entrySet()) { |
| 13757 | HistoryTag tag = ent.getKey(); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 13758 | out.writeInt(ent.getValue()); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 13759 | out.writeString(tag.string); |
| 13760 | out.writeInt(tag.uid); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 13761 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 13762 | out.writeInt(mHistoryBuffer.dataSize()); |
| 13763 | if (DEBUG_HISTORY) Slog.i(TAG, "***************** WRITING HISTORY: " |
| 13764 | + mHistoryBuffer.dataSize() + " bytes at " + out.dataPosition()); |
| 13765 | out.appendFrom(mHistoryBuffer, 0, mHistoryBuffer.dataSize()); |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 13766 | |
| 13767 | if (andOldHistory) { |
| 13768 | writeOldHistory(out); |
| 13769 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 13770 | } |
| 13771 | |
| 13772 | void writeOldHistory(Parcel out) { |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 13773 | if (!USE_OLD_HISTORY) { |
| 13774 | return; |
| 13775 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 13776 | HistoryItem rec = mHistory; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 13777 | while (rec != null) { |
| 13778 | if (rec.time >= 0) rec.writeToParcel(out, 0); |
| 13779 | rec = rec.next; |
| 13780 | } |
| 13781 | out.writeLong(-1); |
| 13782 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 13783 | |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 13784 | public void readSummaryFromParcel(Parcel in) throws ParcelFormatException { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13785 | final int version = in.readInt(); |
| 13786 | if (version != VERSION) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 13787 | Slog.w("BatteryStats", "readFromParcel: version got " + version |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13788 | + ", expected " + VERSION + "; erasing old stats"); |
| 13789 | return; |
| 13790 | } |
| 13791 | |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 13792 | readHistory(in, true); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 13793 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13794 | mStartCount = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13795 | mUptime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13796 | mRealtime = in.readLong(); |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 13797 | mStartClockTime = in.readLong(); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 13798 | mStartPlatformVersion = in.readString(); |
| 13799 | mEndPlatformVersion = in.readString(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 13800 | mOnBatteryTimeBase.readSummaryFromParcel(in); |
| 13801 | mOnBatteryScreenOffTimeBase.readSummaryFromParcel(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 13802 | mDischargeUnplugLevel = in.readInt(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 13803 | mDischargePlugLevel = in.readInt(); |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 13804 | mDischargeCurrentLevel = in.readInt(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 13805 | mCurrentBatteryLevel = in.readInt(); |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 13806 | mEstimatedBatteryCapacity = in.readInt(); |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 13807 | mMinLearnedBatteryCapacity = in.readInt(); |
| 13808 | mMaxLearnedBatteryCapacity = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 13809 | mLowDischargeAmountSinceCharge = in.readInt(); |
| 13810 | mHighDischargeAmountSinceCharge = in.readInt(); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 13811 | mDischargeAmountScreenOnSinceCharge = in.readInt(); |
| 13812 | mDischargeAmountScreenOffSinceCharge = in.readInt(); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 13813 | mDischargeAmountScreenDozeSinceCharge = in.readInt(); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 13814 | mDischargeStepTracker.readFromParcel(in); |
| 13815 | mChargeStepTracker.readFromParcel(in); |
| 13816 | mDailyDischargeStepTracker.readFromParcel(in); |
| 13817 | mDailyChargeStepTracker.readFromParcel(in); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 13818 | mDischargeCounter.readSummaryFromParcelLocked(in); |
| 13819 | mDischargeScreenOffCounter.readSummaryFromParcelLocked(in); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 13820 | mDischargeScreenDozeCounter.readSummaryFromParcelLocked(in); |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 13821 | mDischargeLightDozeCounter.readSummaryFromParcelLocked(in); |
| 13822 | mDischargeDeepDozeCounter.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 13823 | int NPKG = in.readInt(); |
| 13824 | if (NPKG > 0) { |
| 13825 | mDailyPackageChanges = new ArrayList<>(NPKG); |
| 13826 | while (NPKG > 0) { |
| 13827 | NPKG--; |
| 13828 | PackageChange pc = new PackageChange(); |
| 13829 | pc.mPackageName = in.readString(); |
| 13830 | pc.mUpdate = in.readInt() != 0; |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 13831 | pc.mVersionCode = in.readLong(); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 13832 | mDailyPackageChanges.add(pc); |
| 13833 | } |
| 13834 | } else { |
| 13835 | mDailyPackageChanges = null; |
| 13836 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 13837 | mDailyStartTime = in.readLong(); |
| 13838 | mNextMinDailyDeadline = in.readLong(); |
| 13839 | mNextMaxDailyDeadline = in.readLong(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 13840 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13841 | mStartCount++; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 13842 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 13843 | mScreenState = Display.STATE_UNKNOWN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13844 | mScreenOnTimer.readSummaryFromParcelLocked(in); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 13845 | mScreenDozeTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 13846 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
| 13847 | mScreenBrightnessTimer[i].readSummaryFromParcelLocked(in); |
| 13848 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 13849 | mInteractive = false; |
| 13850 | mInteractiveTimer.readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13851 | mPhoneOn = false; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 13852 | mPowerSaveModeEnabledTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 13853 | mLongestLightIdleTime = in.readLong(); |
| 13854 | mLongestFullIdleTime = in.readLong(); |
| 13855 | mDeviceIdleModeLightTimer.readSummaryFromParcelLocked(in); |
| 13856 | mDeviceIdleModeFullTimer.readSummaryFromParcelLocked(in); |
| 13857 | mDeviceLightIdlingTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 13858 | mDeviceIdlingTimer.readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13859 | mPhoneOnTimer.readSummaryFromParcelLocked(in); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 13860 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 13861 | mPhoneSignalStrengthsTimer[i].readSummaryFromParcelLocked(in); |
| 13862 | } |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 13863 | mPhoneSignalScanningTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 13864 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
| 13865 | mPhoneDataConnectionsTimer[i].readSummaryFromParcelLocked(in); |
| 13866 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 13867 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 13868 | mNetworkByteActivityCounters[i].readSummaryFromParcelLocked(in); |
| 13869 | mNetworkPacketActivityCounters[i].readSummaryFromParcelLocked(in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 13870 | } |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 13871 | mMobileRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 13872 | mMobileRadioActiveTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 13873 | mMobileRadioActivePerAppTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 13874 | mMobileRadioActiveAdjustedTime.readSummaryFromParcelLocked(in); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 13875 | mMobileRadioActiveUnknownTime.readSummaryFromParcelLocked(in); |
| 13876 | mMobileRadioActiveUnknownCount.readSummaryFromParcelLocked(in); |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 13877 | mWifiMulticastWakelockTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 13878 | mWifiRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 13879 | mWifiOn = false; |
| 13880 | mWifiOnTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 13881 | mGlobalWifiRunning = false; |
| 13882 | mGlobalWifiRunningTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 13883 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 13884 | mWifiStateTimer[i].readSummaryFromParcelLocked(in); |
| 13885 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 13886 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 13887 | mWifiSupplStateTimer[i].readSummaryFromParcelLocked(in); |
| 13888 | } |
| 13889 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 13890 | mWifiSignalStrengthsTimer[i].readSummaryFromParcelLocked(in); |
| 13891 | } |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 13892 | mWifiActiveTimer.readSummaryFromParcelLocked(in); |
| 13893 | mWifiActivity.readSummaryFromParcel(in); |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 13894 | for (int i=0; i<GnssMetrics.NUM_GPS_SIGNAL_QUALITY_LEVELS; i++) { |
| 13895 | mGpsSignalQualityTimer[i].readSummaryFromParcelLocked(in); |
| 13896 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 13897 | mBluetoothActivity.readSummaryFromParcel(in); |
| 13898 | mModemActivity.readSummaryFromParcel(in); |
| 13899 | mHasWifiReporting = in.readInt() != 0; |
| 13900 | mHasBluetoothReporting = in.readInt() != 0; |
| 13901 | mHasModemReporting = in.readInt() != 0; |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 13902 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 13903 | mNumConnectivityChange = mLoadedNumConnectivityChange = in.readInt(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 13904 | mFlashlightOnNesting = 0; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 13905 | mFlashlightOnTimer.readSummaryFromParcelLocked(in); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 13906 | mCameraOnNesting = 0; |
| 13907 | mCameraOnTimer.readSummaryFromParcelLocked(in); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 13908 | mBluetoothScanNesting = 0; |
| 13909 | mBluetoothScanTimer.readSummaryFromParcelLocked(in); |
Siddharth Ray | f5e796a | 2018-01-22 18:18:17 -0800 | [diff] [blame] | 13910 | mIsCellularTxPowerHigh = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13911 | |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 13912 | int NRPMS = in.readInt(); |
| 13913 | if (NRPMS > 10000) { |
| 13914 | throw new ParcelFormatException("File corrupt: too many rpm stats " + NRPMS); |
| 13915 | } |
| 13916 | for (int irpm = 0; irpm < NRPMS; irpm++) { |
| 13917 | if (in.readInt() != 0) { |
| 13918 | String rpmName = in.readString(); |
| 13919 | getRpmTimerLocked(rpmName).readSummaryFromParcelLocked(in); |
| 13920 | } |
| 13921 | } |
| 13922 | int NSORPMS = in.readInt(); |
| 13923 | if (NSORPMS > 10000) { |
| 13924 | throw new ParcelFormatException("File corrupt: too many screen-off rpm stats " + NSORPMS); |
| 13925 | } |
| 13926 | for (int irpm = 0; irpm < NSORPMS; irpm++) { |
| 13927 | if (in.readInt() != 0) { |
| 13928 | String rpmName = in.readString(); |
| 13929 | getScreenOffRpmTimerLocked(rpmName).readSummaryFromParcelLocked(in); |
| 13930 | } |
| 13931 | } |
| 13932 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 13933 | int NKW = in.readInt(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 13934 | if (NKW > 10000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 13935 | throw new ParcelFormatException("File corrupt: too many kernel wake locks " + NKW); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 13936 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 13937 | for (int ikw = 0; ikw < NKW; ikw++) { |
| 13938 | if (in.readInt() != 0) { |
| 13939 | String kwltName = in.readString(); |
| 13940 | getKernelWakelockTimerLocked(kwltName).readSummaryFromParcelLocked(in); |
| 13941 | } |
| 13942 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 13943 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 13944 | int NWR = in.readInt(); |
| 13945 | if (NWR > 10000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 13946 | throw new ParcelFormatException("File corrupt: too many wakeup reasons " + NWR); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 13947 | } |
| 13948 | for (int iwr = 0; iwr < NWR; iwr++) { |
| 13949 | if (in.readInt() != 0) { |
| 13950 | String reasonName = in.readString(); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 13951 | getWakeupReasonTimerLocked(reasonName).readSummaryFromParcelLocked(in); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 13952 | } |
| 13953 | } |
| 13954 | |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 13955 | int NMS = in.readInt(); |
| 13956 | for (int ims = 0; ims < NMS; ims++) { |
| 13957 | if (in.readInt() != 0) { |
| 13958 | long kmstName = in.readLong(); |
| 13959 | getKernelMemoryTimerLocked(kmstName).readSummaryFromParcelLocked(in); |
| 13960 | } |
| 13961 | } |
| 13962 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13963 | final int NU = in.readInt(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 13964 | if (NU > 10000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 13965 | throw new ParcelFormatException("File corrupt: too many uids " + NU); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 13966 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13967 | for (int iu = 0; iu < NU; iu++) { |
| 13968 | int uid = in.readInt(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 13969 | Uid u = new Uid(this, uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13970 | mUidStats.put(uid, u); |
| 13971 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 13972 | u.mOnBatteryBackgroundTimeBase.readSummaryFromParcel(in); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 13973 | u.mOnBatteryScreenOffBackgroundTimeBase.readSummaryFromParcel(in); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 13974 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 13975 | u.mWifiRunning = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 13976 | if (in.readInt() != 0) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 13977 | u.mWifiRunningTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 13978 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 13979 | u.mFullWifiLockOut = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 13980 | if (in.readInt() != 0) { |
| 13981 | u.mFullWifiLockTimer.readSummaryFromParcelLocked(in); |
| 13982 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 13983 | u.mWifiScanStarted = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 13984 | if (in.readInt() != 0) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 13985 | u.mWifiScanTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 13986 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 13987 | u.mWifiBatchedScanBinStarted = Uid.NO_BATCHED_SCAN_STARTED; |
| 13988 | for (int i = 0; i < Uid.NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 13989 | if (in.readInt() != 0) { |
| 13990 | u.makeWifiBatchedScanBin(i, null); |
| 13991 | u.mWifiBatchedScanTimer[i].readSummaryFromParcelLocked(in); |
| 13992 | } |
| 13993 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 13994 | u.mWifiMulticastEnabled = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 13995 | if (in.readInt() != 0) { |
| 13996 | u.mWifiMulticastTimer.readSummaryFromParcelLocked(in); |
| 13997 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 13998 | if (in.readInt() != 0) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 13999 | u.createAudioTurnedOnTimerLocked().readSummaryFromParcelLocked(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 14000 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 14001 | if (in.readInt() != 0) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 14002 | u.createVideoTurnedOnTimerLocked().readSummaryFromParcelLocked(in); |
| 14003 | } |
| 14004 | if (in.readInt() != 0) { |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 14005 | u.createFlashlightTurnedOnTimerLocked().readSummaryFromParcelLocked(in); |
| 14006 | } |
| 14007 | if (in.readInt() != 0) { |
| 14008 | u.createCameraTurnedOnTimerLocked().readSummaryFromParcelLocked(in); |
| 14009 | } |
| 14010 | if (in.readInt() != 0) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 14011 | u.createForegroundActivityTimerLocked().readSummaryFromParcelLocked(in); |
| 14012 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 14013 | if (in.readInt() != 0) { |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 14014 | u.createForegroundServiceTimerLocked().readSummaryFromParcelLocked(in); |
| 14015 | } |
| 14016 | if (in.readInt() != 0) { |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 14017 | u.createAggregatedPartialWakelockTimerLocked().readSummaryFromParcelLocked(in); |
| 14018 | } |
| 14019 | if (in.readInt() != 0) { |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 14020 | u.createBluetoothScanTimerLocked().readSummaryFromParcelLocked(in); |
| 14021 | } |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 14022 | if (in.readInt() != 0) { |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 14023 | u.createBluetoothUnoptimizedScanTimerLocked().readSummaryFromParcelLocked(in); |
| 14024 | } |
| 14025 | if (in.readInt() != 0) { |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 14026 | u.createBluetoothScanResultCounterLocked().readSummaryFromParcelLocked(in); |
| 14027 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 14028 | if (in.readInt() != 0) { |
| 14029 | u.createBluetoothScanResultBgCounterLocked().readSummaryFromParcelLocked(in); |
| 14030 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 14031 | u.mProcessState = ActivityManager.PROCESS_STATE_NONEXISTENT; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 14032 | for (int i = 0; i < Uid.NUM_PROCESS_STATE; i++) { |
| 14033 | if (in.readInt() != 0) { |
| 14034 | u.makeProcessState(i, null); |
| 14035 | u.mProcessStateTimer[i].readSummaryFromParcelLocked(in); |
| 14036 | } |
| 14037 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 14038 | if (in.readInt() != 0) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 14039 | u.createVibratorOnTimerLocked().readSummaryFromParcelLocked(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 14040 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 14041 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 14042 | if (in.readInt() != 0) { |
| 14043 | if (u.mUserActivityCounters == null) { |
| 14044 | u.initUserActivityLocked(); |
| 14045 | } |
| 14046 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
| 14047 | u.mUserActivityCounters[i].readSummaryFromParcelLocked(in); |
| 14048 | } |
| 14049 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 14050 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 14051 | if (in.readInt() != 0) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 14052 | if (u.mNetworkByteActivityCounters == null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 14053 | u.initNetworkActivityLocked(); |
| 14054 | } |
| 14055 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 14056 | u.mNetworkByteActivityCounters[i].readSummaryFromParcelLocked(in); |
| 14057 | u.mNetworkPacketActivityCounters[i].readSummaryFromParcelLocked(in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 14058 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 14059 | u.mMobileRadioActiveTime.readSummaryFromParcelLocked(in); |
| 14060 | u.mMobileRadioActiveCount.readSummaryFromParcelLocked(in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 14061 | } |
| 14062 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 14063 | u.mUserCpuTime.readSummaryFromParcelLocked(in); |
| 14064 | u.mSystemCpuTime.readSummaryFromParcelLocked(in); |
| 14065 | |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 14066 | if (in.readInt() != 0) { |
| 14067 | final int numClusters = in.readInt(); |
| 14068 | if (mPowerProfile != null && mPowerProfile.getNumCpuClusters() != numClusters) { |
| 14069 | throw new ParcelFormatException("Incompatible cpu cluster arrangement"); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 14070 | } |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 14071 | |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 14072 | u.mCpuClusterSpeedTimesUs = new LongSamplingCounter[numClusters][]; |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 14073 | for (int cluster = 0; cluster < numClusters; cluster++) { |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 14074 | if (in.readInt() != 0) { |
Adam Lesinski | a57a540 | 2015-09-28 10:21:33 -0700 | [diff] [blame] | 14075 | final int NSB = in.readInt(); |
| 14076 | if (mPowerProfile != null && |
| 14077 | mPowerProfile.getNumSpeedStepsInCpuCluster(cluster) != NSB) { |
| 14078 | throw new ParcelFormatException("File corrupt: too many speed bins " + |
| 14079 | NSB); |
| 14080 | } |
| 14081 | |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 14082 | u.mCpuClusterSpeedTimesUs[cluster] = new LongSamplingCounter[NSB]; |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 14083 | for (int speed = 0; speed < NSB; speed++) { |
| 14084 | if (in.readInt() != 0) { |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 14085 | u.mCpuClusterSpeedTimesUs[cluster][speed] = new LongSamplingCounter( |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 14086 | mOnBatteryTimeBase); |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 14087 | u.mCpuClusterSpeedTimesUs[cluster][speed].readSummaryFromParcelLocked(in); |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 14088 | } |
| 14089 | } |
Adam Lesinski | a57a540 | 2015-09-28 10:21:33 -0700 | [diff] [blame] | 14090 | } else { |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 14091 | u.mCpuClusterSpeedTimesUs[cluster] = null; |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 14092 | } |
| 14093 | } |
| 14094 | } else { |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 14095 | u.mCpuClusterSpeedTimesUs = null; |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 14096 | } |
| 14097 | |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 14098 | u.mCpuFreqTimeMs = LongSamplingCounterArray.readSummaryFromParcelLocked( |
| 14099 | in, mOnBatteryTimeBase); |
| 14100 | u.mScreenOffCpuFreqTimeMs = LongSamplingCounterArray.readSummaryFromParcelLocked( |
| 14101 | in, mOnBatteryScreenOffTimeBase); |
Mike Ma | 3d422c3 | 2017-10-25 11:08:57 -0700 | [diff] [blame] | 14102 | |
| 14103 | u.mCpuActiveTimeMs.readSummaryFromParcelLocked(in); |
| 14104 | u.mCpuClusterTimesMs.readSummaryFromParcelLocked(in); |
| 14105 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 14106 | int length = in.readInt(); |
| 14107 | if (length == Uid.NUM_PROCESS_STATE) { |
| 14108 | u.mProcStateTimeMs = new LongSamplingCounterArray[length]; |
| 14109 | for (int procState = 0; procState < length; ++procState) { |
| 14110 | u.mProcStateTimeMs[procState] |
| 14111 | = LongSamplingCounterArray.readSummaryFromParcelLocked( |
| 14112 | in, mOnBatteryTimeBase); |
| 14113 | } |
| 14114 | } else { |
| 14115 | u.mProcStateTimeMs = null; |
| 14116 | } |
| 14117 | length = in.readInt(); |
| 14118 | if (length == Uid.NUM_PROCESS_STATE) { |
| 14119 | u.mProcStateScreenOffTimeMs = new LongSamplingCounterArray[length]; |
| 14120 | for (int procState = 0; procState < length; ++procState) { |
| 14121 | u.mProcStateScreenOffTimeMs[procState] |
| 14122 | = LongSamplingCounterArray.readSummaryFromParcelLocked( |
| 14123 | in, mOnBatteryScreenOffTimeBase); |
| 14124 | } |
| 14125 | } else { |
| 14126 | u.mProcStateScreenOffTimeMs = null; |
| 14127 | } |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 14128 | |
| 14129 | if (in.readInt() != 0) { |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 14130 | u.mMobileRadioApWakeupCount = new LongSamplingCounter(mOnBatteryTimeBase); |
| 14131 | u.mMobileRadioApWakeupCount.readSummaryFromParcelLocked(in); |
| 14132 | } else { |
| 14133 | u.mMobileRadioApWakeupCount = null; |
| 14134 | } |
| 14135 | |
| 14136 | if (in.readInt() != 0) { |
| 14137 | u.mWifiRadioApWakeupCount = new LongSamplingCounter(mOnBatteryTimeBase); |
| 14138 | u.mWifiRadioApWakeupCount.readSummaryFromParcelLocked(in); |
| 14139 | } else { |
| 14140 | u.mWifiRadioApWakeupCount = null; |
| 14141 | } |
| 14142 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14143 | int NW = in.readInt(); |
Dianne Hackborn | cb99a72 | 2016-10-03 17:00:02 -0700 | [diff] [blame] | 14144 | if (NW > (MAX_WAKELOCKS_PER_UID+1)) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 14145 | throw new ParcelFormatException("File corrupt: too many wake locks " + NW); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 14146 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14147 | for (int iw = 0; iw < NW; iw++) { |
| 14148 | String wlName = in.readString(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 14149 | u.readWakeSummaryFromParcelLocked(wlName, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14150 | } |
| 14151 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 14152 | int NS = in.readInt(); |
Dianne Hackborn | cb99a72 | 2016-10-03 17:00:02 -0700 | [diff] [blame] | 14153 | if (NS > (MAX_WAKELOCKS_PER_UID+1)) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 14154 | throw new ParcelFormatException("File corrupt: too many syncs " + NS); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 14155 | } |
| 14156 | for (int is = 0; is < NS; is++) { |
| 14157 | String name = in.readString(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 14158 | u.readSyncSummaryFromParcelLocked(name, in); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 14159 | } |
| 14160 | |
| 14161 | int NJ = in.readInt(); |
Dianne Hackborn | cb99a72 | 2016-10-03 17:00:02 -0700 | [diff] [blame] | 14162 | if (NJ > (MAX_WAKELOCKS_PER_UID+1)) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 14163 | throw new ParcelFormatException("File corrupt: too many job timers " + NJ); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 14164 | } |
| 14165 | for (int ij = 0; ij < NJ; ij++) { |
| 14166 | String name = in.readString(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 14167 | u.readJobSummaryFromParcelLocked(name, in); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 14168 | } |
| 14169 | |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 14170 | u.readJobCompletionsFromParcelLocked(in); |
| 14171 | |
Amith Yamasani | 977e11f | 2018-02-16 11:29:54 -0800 | [diff] [blame] | 14172 | u.mJobsDeferredEventCount.readSummaryFromParcelLocked(in); |
| 14173 | u.mJobsDeferredCount.readSummaryFromParcelLocked(in); |
| 14174 | u.mJobsFreshnessTimeMs.readSummaryFromParcelLocked(in); |
| 14175 | for (int i = 0; i < JOB_FRESHNESS_BUCKETS.length; i++) { |
| 14176 | if (in.readInt() != 0) { |
| 14177 | u.mJobsFreshnessBuckets[i] = new Counter(u.mBsi.mOnBatteryTimeBase); |
| 14178 | u.mJobsFreshnessBuckets[i].readSummaryFromParcelLocked(in); |
| 14179 | } |
| 14180 | } |
| 14181 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14182 | int NP = in.readInt(); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 14183 | if (NP > 1000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 14184 | throw new ParcelFormatException("File corrupt: too many sensors " + NP); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 14185 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14186 | for (int is = 0; is < NP; is++) { |
| 14187 | int seNumber = in.readInt(); |
| 14188 | if (in.readInt() != 0) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 14189 | u.getSensorTimerLocked(seNumber, true).readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14190 | } |
| 14191 | } |
| 14192 | |
| 14193 | NP = in.readInt(); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 14194 | if (NP > 1000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 14195 | throw new ParcelFormatException("File corrupt: too many processes " + NP); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 14196 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14197 | for (int ip = 0; ip < NP; ip++) { |
| 14198 | String procName = in.readString(); |
| 14199 | Uid.Proc p = u.getProcessStatsLocked(procName); |
| 14200 | p.mUserTime = p.mLoadedUserTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14201 | p.mSystemTime = p.mLoadedSystemTime = in.readLong(); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 14202 | p.mForegroundTime = p.mLoadedForegroundTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14203 | p.mStarts = p.mLoadedStarts = in.readInt(); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 14204 | p.mNumCrashes = p.mLoadedNumCrashes = in.readInt(); |
| 14205 | p.mNumAnrs = p.mLoadedNumAnrs = in.readInt(); |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 14206 | p.readExcessivePowerFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14207 | } |
| 14208 | |
| 14209 | NP = in.readInt(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 14210 | if (NP > 10000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 14211 | throw new ParcelFormatException("File corrupt: too many packages " + NP); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 14212 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14213 | for (int ip = 0; ip < NP; ip++) { |
| 14214 | String pkgName = in.readString(); |
| 14215 | Uid.Pkg p = u.getPackageStatsLocked(pkgName); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 14216 | final int NWA = in.readInt(); |
| 14217 | if (NWA > 1000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 14218 | throw new ParcelFormatException("File corrupt: too many wakeup alarms " + NWA); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 14219 | } |
| 14220 | p.mWakeupAlarms.clear(); |
| 14221 | for (int iwa=0; iwa<NWA; iwa++) { |
| 14222 | String tag = in.readString(); |
Bookatz | 98d4d5c | 2017-08-01 19:07:54 -0700 | [diff] [blame] | 14223 | Counter c = new Counter(mOnBatteryScreenOffTimeBase); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 14224 | c.readSummaryFromParcelLocked(in); |
| 14225 | p.mWakeupAlarms.put(tag, c); |
| 14226 | } |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 14227 | NS = in.readInt(); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 14228 | if (NS > 1000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 14229 | throw new ParcelFormatException("File corrupt: too many services " + NS); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 14230 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14231 | for (int is = 0; is < NS; is++) { |
| 14232 | String servName = in.readString(); |
| 14233 | Uid.Pkg.Serv s = u.getServiceStatsLocked(pkgName, servName); |
| 14234 | s.mStartTime = s.mLoadedStartTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14235 | s.mStarts = s.mLoadedStarts = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14236 | s.mLaunches = s.mLoadedLaunches = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14237 | } |
| 14238 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14239 | } |
| 14240 | } |
| 14241 | |
| 14242 | /** |
| 14243 | * Writes a summary of the statistics to a Parcel, in a format suitable to be written to |
| 14244 | * disk. This format does not allow a lossless round-trip. |
| 14245 | * |
| 14246 | * @param out the Parcel to be written to. |
| 14247 | */ |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 14248 | public void writeSummaryToParcel(Parcel out, boolean inclHistory) { |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 14249 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 14250 | |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 14251 | // Pull the clock time. This may update the time and make a new history entry |
| 14252 | // if we had originally pulled a time before the RTC was set. |
| 14253 | long startClockTime = getStartClockTime(); |
| 14254 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14255 | final long NOW_SYS = mClocks.uptimeMillis() * 1000; |
| 14256 | final long NOWREAL_SYS = mClocks.elapsedRealtime() * 1000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14257 | |
| 14258 | out.writeInt(VERSION); |
| 14259 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 14260 | writeHistory(out, inclHistory, true); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 14261 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14262 | out.writeInt(mStartCount); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 14263 | out.writeLong(computeUptime(NOW_SYS, STATS_SINCE_CHARGED)); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 14264 | out.writeLong(computeRealtime(NOWREAL_SYS, STATS_SINCE_CHARGED)); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 14265 | out.writeLong(startClockTime); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 14266 | out.writeString(mStartPlatformVersion); |
| 14267 | out.writeString(mEndPlatformVersion); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14268 | mOnBatteryTimeBase.writeSummaryToParcel(out, NOW_SYS, NOWREAL_SYS); |
| 14269 | mOnBatteryScreenOffTimeBase.writeSummaryToParcel(out, NOW_SYS, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 14270 | out.writeInt(mDischargeUnplugLevel); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 14271 | out.writeInt(mDischargePlugLevel); |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 14272 | out.writeInt(mDischargeCurrentLevel); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 14273 | out.writeInt(mCurrentBatteryLevel); |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 14274 | out.writeInt(mEstimatedBatteryCapacity); |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 14275 | out.writeInt(mMinLearnedBatteryCapacity); |
| 14276 | out.writeInt(mMaxLearnedBatteryCapacity); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 14277 | out.writeInt(getLowDischargeAmountSinceCharge()); |
| 14278 | out.writeInt(getHighDischargeAmountSinceCharge()); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 14279 | out.writeInt(getDischargeAmountScreenOnSinceCharge()); |
| 14280 | out.writeInt(getDischargeAmountScreenOffSinceCharge()); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 14281 | out.writeInt(getDischargeAmountScreenDozeSinceCharge()); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 14282 | mDischargeStepTracker.writeToParcel(out); |
| 14283 | mChargeStepTracker.writeToParcel(out); |
| 14284 | mDailyDischargeStepTracker.writeToParcel(out); |
| 14285 | mDailyChargeStepTracker.writeToParcel(out); |
Adam Lesinski | 67c134f | 2016-06-10 15:15:08 -0700 | [diff] [blame] | 14286 | mDischargeCounter.writeSummaryFromParcelLocked(out); |
| 14287 | mDischargeScreenOffCounter.writeSummaryFromParcelLocked(out); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 14288 | mDischargeScreenDozeCounter.writeSummaryFromParcelLocked(out); |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 14289 | mDischargeLightDozeCounter.writeSummaryFromParcelLocked(out); |
| 14290 | mDischargeDeepDozeCounter.writeSummaryFromParcelLocked(out); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 14291 | if (mDailyPackageChanges != null) { |
| 14292 | final int NPKG = mDailyPackageChanges.size(); |
| 14293 | out.writeInt(NPKG); |
| 14294 | for (int i=0; i<NPKG; i++) { |
| 14295 | PackageChange pc = mDailyPackageChanges.get(i); |
| 14296 | out.writeString(pc.mPackageName); |
| 14297 | out.writeInt(pc.mUpdate ? 1 : 0); |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 14298 | out.writeLong(pc.mVersionCode); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 14299 | } |
| 14300 | } else { |
| 14301 | out.writeInt(0); |
| 14302 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 14303 | out.writeLong(mDailyStartTime); |
| 14304 | out.writeLong(mNextMinDailyDeadline); |
| 14305 | out.writeLong(mNextMaxDailyDeadline); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14306 | |
| 14307 | mScreenOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 14308 | mScreenDozeTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 14309 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14310 | mScreenBrightnessTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 14311 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 14312 | mInteractiveTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 14313 | mPowerSaveModeEnabledTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 14314 | out.writeLong(mLongestLightIdleTime); |
| 14315 | out.writeLong(mLongestFullIdleTime); |
| 14316 | mDeviceIdleModeLightTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14317 | mDeviceIdleModeFullTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14318 | mDeviceLightIdlingTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 14319 | mDeviceIdlingTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14320 | mPhoneOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 14321 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14322 | mPhoneSignalStrengthsTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 14323 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14324 | mPhoneSignalScanningTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 14325 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14326 | mPhoneDataConnectionsTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 14327 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 14328 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 14329 | mNetworkByteActivityCounters[i].writeSummaryFromParcelLocked(out); |
| 14330 | mNetworkPacketActivityCounters[i].writeSummaryFromParcelLocked(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 14331 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14332 | mMobileRadioActiveTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14333 | mMobileRadioActivePerAppTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 14334 | mMobileRadioActiveAdjustedTime.writeSummaryFromParcelLocked(out); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 14335 | mMobileRadioActiveUnknownTime.writeSummaryFromParcelLocked(out); |
| 14336 | mMobileRadioActiveUnknownCount.writeSummaryFromParcelLocked(out); |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 14337 | mWifiMulticastWakelockTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14338 | mWifiOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14339 | mGlobalWifiRunningTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 14340 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14341 | mWifiStateTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 14342 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 14343 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 14344 | mWifiSupplStateTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14345 | } |
| 14346 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 14347 | mWifiSignalStrengthsTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14348 | } |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 14349 | mWifiActiveTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14350 | mWifiActivity.writeSummaryToParcel(out); |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 14351 | for (int i=0; i< GnssMetrics.NUM_GPS_SIGNAL_QUALITY_LEVELS; i++) { |
| 14352 | mGpsSignalQualityTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14353 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 14354 | mBluetoothActivity.writeSummaryToParcel(out); |
| 14355 | mModemActivity.writeSummaryToParcel(out); |
| 14356 | out.writeInt(mHasWifiReporting ? 1 : 0); |
| 14357 | out.writeInt(mHasBluetoothReporting ? 1 : 0); |
| 14358 | out.writeInt(mHasModemReporting ? 1 : 0); |
| 14359 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 14360 | out.writeInt(mNumConnectivityChange); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 14361 | mFlashlightOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 14362 | mCameraOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 14363 | mBluetoothScanTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14364 | |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 14365 | out.writeInt(mRpmStats.size()); |
| 14366 | for (Map.Entry<String, SamplingTimer> ent : mRpmStats.entrySet()) { |
| 14367 | Timer rpmt = ent.getValue(); |
| 14368 | if (rpmt != null) { |
| 14369 | out.writeInt(1); |
| 14370 | out.writeString(ent.getKey()); |
| 14371 | rpmt.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14372 | } else { |
| 14373 | out.writeInt(0); |
| 14374 | } |
| 14375 | } |
| 14376 | out.writeInt(mScreenOffRpmStats.size()); |
| 14377 | for (Map.Entry<String, SamplingTimer> ent : mScreenOffRpmStats.entrySet()) { |
| 14378 | Timer rpmt = ent.getValue(); |
| 14379 | if (rpmt != null) { |
| 14380 | out.writeInt(1); |
| 14381 | out.writeString(ent.getKey()); |
| 14382 | rpmt.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14383 | } else { |
| 14384 | out.writeInt(0); |
| 14385 | } |
| 14386 | } |
| 14387 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 14388 | out.writeInt(mKernelWakelockStats.size()); |
| 14389 | for (Map.Entry<String, SamplingTimer> ent : mKernelWakelockStats.entrySet()) { |
| 14390 | Timer kwlt = ent.getValue(); |
| 14391 | if (kwlt != null) { |
| 14392 | out.writeInt(1); |
| 14393 | out.writeString(ent.getKey()); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 14394 | kwlt.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14395 | } else { |
| 14396 | out.writeInt(0); |
| 14397 | } |
| 14398 | } |
| 14399 | |
| 14400 | out.writeInt(mWakeupReasonStats.size()); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 14401 | for (Map.Entry<String, SamplingTimer> ent : mWakeupReasonStats.entrySet()) { |
| 14402 | SamplingTimer timer = ent.getValue(); |
| 14403 | if (timer != null) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 14404 | out.writeInt(1); |
| 14405 | out.writeString(ent.getKey()); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 14406 | timer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 14407 | } else { |
| 14408 | out.writeInt(0); |
| 14409 | } |
| 14410 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 14411 | |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 14412 | out.writeInt(mKernelMemoryStats.size()); |
| 14413 | for (int i = 0; i < mKernelMemoryStats.size(); i++) { |
| 14414 | Timer kmt = mKernelMemoryStats.valueAt(i); |
| 14415 | if (kmt != null) { |
| 14416 | out.writeInt(1); |
| 14417 | out.writeLong(mKernelMemoryStats.keyAt(i)); |
| 14418 | kmt.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14419 | } else { |
| 14420 | out.writeInt(0); |
| 14421 | } |
| 14422 | } |
| 14423 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14424 | final int NU = mUidStats.size(); |
| 14425 | out.writeInt(NU); |
| 14426 | for (int iu = 0; iu < NU; iu++) { |
| 14427 | out.writeInt(mUidStats.keyAt(iu)); |
| 14428 | Uid u = mUidStats.valueAt(iu); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 14429 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 14430 | u.mOnBatteryBackgroundTimeBase.writeSummaryToParcel(out, NOW_SYS, NOWREAL_SYS); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 14431 | u.mOnBatteryScreenOffBackgroundTimeBase.writeSummaryToParcel(out, NOW_SYS, NOWREAL_SYS); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 14432 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 14433 | if (u.mWifiRunningTimer != null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 14434 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14435 | u.mWifiRunningTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 14436 | } else { |
| 14437 | out.writeInt(0); |
| 14438 | } |
| 14439 | if (u.mFullWifiLockTimer != null) { |
| 14440 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14441 | u.mFullWifiLockTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 14442 | } else { |
| 14443 | out.writeInt(0); |
| 14444 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 14445 | if (u.mWifiScanTimer != null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 14446 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14447 | u.mWifiScanTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 14448 | } else { |
| 14449 | out.writeInt(0); |
| 14450 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 14451 | for (int i = 0; i < Uid.NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 14452 | if (u.mWifiBatchedScanTimer[i] != null) { |
| 14453 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14454 | u.mWifiBatchedScanTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 14455 | } else { |
| 14456 | out.writeInt(0); |
| 14457 | } |
| 14458 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 14459 | if (u.mWifiMulticastTimer != null) { |
| 14460 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14461 | u.mWifiMulticastTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 14462 | } else { |
| 14463 | out.writeInt(0); |
| 14464 | } |
| 14465 | if (u.mAudioTurnedOnTimer != null) { |
| 14466 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14467 | u.mAudioTurnedOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 14468 | } else { |
| 14469 | out.writeInt(0); |
| 14470 | } |
| 14471 | if (u.mVideoTurnedOnTimer != null) { |
| 14472 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14473 | u.mVideoTurnedOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 14474 | } else { |
| 14475 | out.writeInt(0); |
| 14476 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 14477 | if (u.mFlashlightTurnedOnTimer != null) { |
| 14478 | out.writeInt(1); |
| 14479 | u.mFlashlightTurnedOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14480 | } else { |
| 14481 | out.writeInt(0); |
| 14482 | } |
| 14483 | if (u.mCameraTurnedOnTimer != null) { |
| 14484 | out.writeInt(1); |
| 14485 | u.mCameraTurnedOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14486 | } else { |
| 14487 | out.writeInt(0); |
| 14488 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 14489 | if (u.mForegroundActivityTimer != null) { |
| 14490 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14491 | u.mForegroundActivityTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 14492 | } else { |
| 14493 | out.writeInt(0); |
| 14494 | } |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 14495 | if (u.mForegroundServiceTimer != null) { |
| 14496 | out.writeInt(1); |
| 14497 | u.mForegroundServiceTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14498 | } else { |
| 14499 | out.writeInt(0); |
| 14500 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 14501 | if (u.mAggregatedPartialWakelockTimer != null) { |
| 14502 | out.writeInt(1); |
| 14503 | u.mAggregatedPartialWakelockTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14504 | } else { |
| 14505 | out.writeInt(0); |
| 14506 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 14507 | if (u.mBluetoothScanTimer != null) { |
| 14508 | out.writeInt(1); |
| 14509 | u.mBluetoothScanTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14510 | } else { |
| 14511 | out.writeInt(0); |
| 14512 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 14513 | if (u.mBluetoothUnoptimizedScanTimer != null) { |
| 14514 | out.writeInt(1); |
| 14515 | u.mBluetoothUnoptimizedScanTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14516 | } else { |
| 14517 | out.writeInt(0); |
| 14518 | } |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 14519 | if (u.mBluetoothScanResultCounter != null) { |
| 14520 | out.writeInt(1); |
| 14521 | u.mBluetoothScanResultCounter.writeSummaryFromParcelLocked(out); |
| 14522 | } else { |
| 14523 | out.writeInt(0); |
| 14524 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 14525 | if (u.mBluetoothScanResultBgCounter != null) { |
| 14526 | out.writeInt(1); |
| 14527 | u.mBluetoothScanResultBgCounter.writeSummaryFromParcelLocked(out); |
| 14528 | } else { |
| 14529 | out.writeInt(0); |
| 14530 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 14531 | for (int i = 0; i < Uid.NUM_PROCESS_STATE; i++) { |
| 14532 | if (u.mProcessStateTimer[i] != null) { |
| 14533 | out.writeInt(1); |
| 14534 | u.mProcessStateTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14535 | } else { |
| 14536 | out.writeInt(0); |
| 14537 | } |
| 14538 | } |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 14539 | if (u.mVibratorOnTimer != null) { |
| 14540 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14541 | u.mVibratorOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 14542 | } else { |
| 14543 | out.writeInt(0); |
| 14544 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14545 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 14546 | if (u.mUserActivityCounters == null) { |
| 14547 | out.writeInt(0); |
| 14548 | } else { |
| 14549 | out.writeInt(1); |
| 14550 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
| 14551 | u.mUserActivityCounters[i].writeSummaryFromParcelLocked(out); |
| 14552 | } |
| 14553 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 14554 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 14555 | if (u.mNetworkByteActivityCounters == null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 14556 | out.writeInt(0); |
| 14557 | } else { |
| 14558 | out.writeInt(1); |
| 14559 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 14560 | u.mNetworkByteActivityCounters[i].writeSummaryFromParcelLocked(out); |
| 14561 | u.mNetworkPacketActivityCounters[i].writeSummaryFromParcelLocked(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 14562 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 14563 | u.mMobileRadioActiveTime.writeSummaryFromParcelLocked(out); |
| 14564 | u.mMobileRadioActiveCount.writeSummaryFromParcelLocked(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 14565 | } |
| 14566 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 14567 | u.mUserCpuTime.writeSummaryFromParcelLocked(out); |
| 14568 | u.mSystemCpuTime.writeSummaryFromParcelLocked(out); |
| 14569 | |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 14570 | if (u.mCpuClusterSpeedTimesUs != null) { |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 14571 | out.writeInt(1); |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 14572 | out.writeInt(u.mCpuClusterSpeedTimesUs.length); |
| 14573 | for (LongSamplingCounter[] cpuSpeeds : u.mCpuClusterSpeedTimesUs) { |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 14574 | if (cpuSpeeds != null) { |
| 14575 | out.writeInt(1); |
| 14576 | out.writeInt(cpuSpeeds.length); |
| 14577 | for (LongSamplingCounter c : cpuSpeeds) { |
| 14578 | if (c != null) { |
| 14579 | out.writeInt(1); |
| 14580 | c.writeSummaryFromParcelLocked(out); |
| 14581 | } else { |
| 14582 | out.writeInt(0); |
| 14583 | } |
| 14584 | } |
| 14585 | } else { |
| 14586 | out.writeInt(0); |
| 14587 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 14588 | } |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 14589 | } else { |
| 14590 | out.writeInt(0); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 14591 | } |
| 14592 | |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 14593 | LongSamplingCounterArray.writeSummaryToParcelLocked(out, u.mCpuFreqTimeMs); |
| 14594 | LongSamplingCounterArray.writeSummaryToParcelLocked(out, u.mScreenOffCpuFreqTimeMs); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 14595 | |
Mike Ma | 3d422c3 | 2017-10-25 11:08:57 -0700 | [diff] [blame] | 14596 | u.mCpuActiveTimeMs.writeSummaryFromParcelLocked(out); |
| 14597 | u.mCpuClusterTimesMs.writeSummaryToParcelLocked(out); |
| 14598 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 14599 | if (u.mProcStateTimeMs != null) { |
| 14600 | out.writeInt(u.mProcStateTimeMs.length); |
| 14601 | for (LongSamplingCounterArray counters : u.mProcStateTimeMs) { |
| 14602 | LongSamplingCounterArray.writeSummaryToParcelLocked(out, counters); |
| 14603 | } |
| 14604 | } else { |
| 14605 | out.writeInt(0); |
| 14606 | } |
| 14607 | if (u.mProcStateScreenOffTimeMs != null) { |
| 14608 | out.writeInt(u.mProcStateScreenOffTimeMs.length); |
| 14609 | for (LongSamplingCounterArray counters : u.mProcStateScreenOffTimeMs) { |
| 14610 | LongSamplingCounterArray.writeSummaryToParcelLocked(out, counters); |
| 14611 | } |
| 14612 | } else { |
| 14613 | out.writeInt(0); |
| 14614 | } |
| 14615 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 14616 | if (u.mMobileRadioApWakeupCount != null) { |
| 14617 | out.writeInt(1); |
| 14618 | u.mMobileRadioApWakeupCount.writeSummaryFromParcelLocked(out); |
| 14619 | } else { |
| 14620 | out.writeInt(0); |
| 14621 | } |
| 14622 | |
| 14623 | if (u.mWifiRadioApWakeupCount != null) { |
| 14624 | out.writeInt(1); |
| 14625 | u.mWifiRadioApWakeupCount.writeSummaryFromParcelLocked(out); |
| 14626 | } else { |
| 14627 | out.writeInt(0); |
| 14628 | } |
| 14629 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 14630 | final ArrayMap<String, Uid.Wakelock> wakeStats = u.mWakelockStats.getMap(); |
| 14631 | int NW = wakeStats.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14632 | out.writeInt(NW); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 14633 | for (int iw=0; iw<NW; iw++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 14634 | out.writeString(wakeStats.keyAt(iw)); |
| 14635 | Uid.Wakelock wl = wakeStats.valueAt(iw); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 14636 | if (wl.mTimerFull != null) { |
| 14637 | out.writeInt(1); |
| 14638 | wl.mTimerFull.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14639 | } else { |
| 14640 | out.writeInt(0); |
| 14641 | } |
| 14642 | if (wl.mTimerPartial != null) { |
| 14643 | out.writeInt(1); |
| 14644 | wl.mTimerPartial.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14645 | } else { |
| 14646 | out.writeInt(0); |
| 14647 | } |
| 14648 | if (wl.mTimerWindow != null) { |
| 14649 | out.writeInt(1); |
| 14650 | wl.mTimerWindow.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14651 | } else { |
| 14652 | out.writeInt(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14653 | } |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 14654 | if (wl.mTimerDraw != null) { |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 14655 | out.writeInt(1); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 14656 | wl.mTimerDraw.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 14657 | } else { |
| 14658 | out.writeInt(0); |
| 14659 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14660 | } |
| 14661 | |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 14662 | final ArrayMap<String, DualTimer> syncStats = u.mSyncStats.getMap(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 14663 | int NS = syncStats.size(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 14664 | out.writeInt(NS); |
| 14665 | for (int is=0; is<NS; is++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 14666 | out.writeString(syncStats.keyAt(is)); |
| 14667 | syncStats.valueAt(is).writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 14668 | } |
| 14669 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 14670 | final ArrayMap<String, DualTimer> jobStats = u.mJobStats.getMap(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 14671 | int NJ = jobStats.size(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 14672 | out.writeInt(NJ); |
| 14673 | for (int ij=0; ij<NJ; ij++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 14674 | out.writeString(jobStats.keyAt(ij)); |
| 14675 | jobStats.valueAt(ij).writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 14676 | } |
| 14677 | |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 14678 | u.writeJobCompletionsToParcelLocked(out); |
| 14679 | |
Amith Yamasani | 977e11f | 2018-02-16 11:29:54 -0800 | [diff] [blame] | 14680 | u.mJobsDeferredEventCount.writeSummaryFromParcelLocked(out); |
| 14681 | u.mJobsDeferredCount.writeSummaryFromParcelLocked(out); |
| 14682 | u.mJobsFreshnessTimeMs.writeSummaryFromParcelLocked(out); |
| 14683 | for (int i = 0; i < JOB_FRESHNESS_BUCKETS.length; i++) { |
| 14684 | if (u.mJobsFreshnessBuckets[i] != null) { |
Adam Lesinski | 1408208 | 2018-02-23 12:35:55 -0800 | [diff] [blame] | 14685 | out.writeInt(1); |
Amith Yamasani | 977e11f | 2018-02-16 11:29:54 -0800 | [diff] [blame] | 14686 | u.mJobsFreshnessBuckets[i].writeSummaryFromParcelLocked(out); |
| 14687 | } else { |
| 14688 | out.writeInt(0); |
| 14689 | } |
| 14690 | } |
| 14691 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14692 | int NSE = u.mSensorStats.size(); |
| 14693 | out.writeInt(NSE); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 14694 | for (int ise=0; ise<NSE; ise++) { |
| 14695 | out.writeInt(u.mSensorStats.keyAt(ise)); |
| 14696 | Uid.Sensor se = u.mSensorStats.valueAt(ise); |
| 14697 | if (se.mTimer != null) { |
| 14698 | out.writeInt(1); |
| 14699 | se.mTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14700 | } else { |
| 14701 | out.writeInt(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14702 | } |
| 14703 | } |
| 14704 | |
| 14705 | int NP = u.mProcessStats.size(); |
| 14706 | out.writeInt(NP); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 14707 | for (int ip=0; ip<NP; ip++) { |
| 14708 | out.writeString(u.mProcessStats.keyAt(ip)); |
| 14709 | Uid.Proc ps = u.mProcessStats.valueAt(ip); |
| 14710 | out.writeLong(ps.mUserTime); |
| 14711 | out.writeLong(ps.mSystemTime); |
| 14712 | out.writeLong(ps.mForegroundTime); |
| 14713 | out.writeInt(ps.mStarts); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 14714 | out.writeInt(ps.mNumCrashes); |
| 14715 | out.writeInt(ps.mNumAnrs); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 14716 | ps.writeExcessivePowerToParcelLocked(out); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14717 | } |
| 14718 | |
| 14719 | NP = u.mPackageStats.size(); |
| 14720 | out.writeInt(NP); |
| 14721 | if (NP > 0) { |
| 14722 | for (Map.Entry<String, BatteryStatsImpl.Uid.Pkg> ent |
| 14723 | : u.mPackageStats.entrySet()) { |
| 14724 | out.writeString(ent.getKey()); |
| 14725 | Uid.Pkg ps = ent.getValue(); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 14726 | final int NWA = ps.mWakeupAlarms.size(); |
| 14727 | out.writeInt(NWA); |
| 14728 | for (int iwa=0; iwa<NWA; iwa++) { |
| 14729 | out.writeString(ps.mWakeupAlarms.keyAt(iwa)); |
| 14730 | ps.mWakeupAlarms.valueAt(iwa).writeSummaryFromParcelLocked(out); |
| 14731 | } |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 14732 | NS = ps.mServiceStats.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14733 | out.writeInt(NS); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 14734 | for (int is=0; is<NS; is++) { |
| 14735 | out.writeString(ps.mServiceStats.keyAt(is)); |
| 14736 | BatteryStatsImpl.Uid.Pkg.Serv ss = ps.mServiceStats.valueAt(is); |
| 14737 | long time = ss.getStartTimeToNowLocked( |
| 14738 | mOnBatteryTimeBase.getUptime(NOW_SYS)); |
| 14739 | out.writeLong(time); |
| 14740 | out.writeInt(ss.mStarts); |
| 14741 | out.writeInt(ss.mLaunches); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14742 | } |
| 14743 | } |
| 14744 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14745 | } |
| 14746 | } |
| 14747 | |
| 14748 | public void readFromParcel(Parcel in) { |
| 14749 | readFromParcelLocked(in); |
| 14750 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 14751 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14752 | void readFromParcelLocked(Parcel in) { |
| 14753 | int magic = in.readInt(); |
| 14754 | if (magic != MAGIC) { |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 14755 | throw new ParcelFormatException("Bad magic number: #" + Integer.toHexString(magic)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14756 | } |
| 14757 | |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 14758 | readHistory(in, false); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 14759 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14760 | mStartCount = in.readInt(); |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 14761 | mStartClockTime = in.readLong(); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 14762 | mStartPlatformVersion = in.readString(); |
| 14763 | mEndPlatformVersion = in.readString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14764 | mUptime = in.readLong(); |
| 14765 | mUptimeStart = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14766 | mRealtime = in.readLong(); |
| 14767 | mRealtimeStart = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14768 | mOnBattery = in.readInt() != 0; |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 14769 | mEstimatedBatteryCapacity = in.readInt(); |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 14770 | mMinLearnedBatteryCapacity = in.readInt(); |
| 14771 | mMaxLearnedBatteryCapacity = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14772 | mOnBatteryInternal = false; // we are no longer really running. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14773 | mOnBatteryTimeBase.readFromParcel(in); |
| 14774 | mOnBatteryScreenOffTimeBase.readFromParcel(in); |
| 14775 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 14776 | mScreenState = Display.STATE_UNKNOWN; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14777 | mScreenOnTimer = new StopwatchTimer(mClocks, null, -1, null, mOnBatteryTimeBase, in); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 14778 | mScreenDozeTimer = new StopwatchTimer(mClocks, null, -1, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14779 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14780 | mScreenBrightnessTimer[i] = new StopwatchTimer(mClocks, null, -100-i, null, |
| 14781 | mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14782 | } |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 14783 | mInteractive = false; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14784 | mInteractiveTimer = new StopwatchTimer(mClocks, null, -10, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14785 | mPhoneOn = false; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14786 | mPowerSaveModeEnabledTimer = new StopwatchTimer(mClocks, null, -2, null, |
| 14787 | mOnBatteryTimeBase, in); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 14788 | mLongestLightIdleTime = in.readLong(); |
| 14789 | mLongestFullIdleTime = in.readLong(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14790 | mDeviceIdleModeLightTimer = new StopwatchTimer(mClocks, null, -14, null, |
| 14791 | mOnBatteryTimeBase, in); |
| 14792 | mDeviceIdleModeFullTimer = new StopwatchTimer(mClocks, null, -11, null, |
| 14793 | mOnBatteryTimeBase, in); |
| 14794 | mDeviceLightIdlingTimer = new StopwatchTimer(mClocks, null, -15, null, |
| 14795 | mOnBatteryTimeBase, in); |
| 14796 | mDeviceIdlingTimer = new StopwatchTimer(mClocks, null, -12, null, mOnBatteryTimeBase, in); |
| 14797 | mPhoneOnTimer = new StopwatchTimer(mClocks, null, -3, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14798 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14799 | mPhoneSignalStrengthsTimer[i] = new StopwatchTimer(mClocks, null, -200-i, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14800 | null, mOnBatteryTimeBase, in); |
| 14801 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14802 | mPhoneSignalScanningTimer = new StopwatchTimer(mClocks, null, -200+1, null, |
| 14803 | mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14804 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14805 | mPhoneDataConnectionsTimer[i] = new StopwatchTimer(mClocks, null, -300-i, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14806 | null, mOnBatteryTimeBase, in); |
| 14807 | } |
| 14808 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
| 14809 | mNetworkByteActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 14810 | mNetworkPacketActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 14811 | } |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 14812 | mMobileRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14813 | mMobileRadioActiveTimer = new StopwatchTimer(mClocks, null, -400, null, |
| 14814 | mOnBatteryTimeBase, in); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 14815 | mMobileRadioActivePerAppTimer = new StopwatchTimer(mClocks, null, -401, null, |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14816 | mOnBatteryTimeBase, in); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 14817 | mMobileRadioActiveAdjustedTime = new LongSamplingCounter(mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14818 | mMobileRadioActiveUnknownTime = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 14819 | mMobileRadioActiveUnknownCount = new LongSamplingCounter(mOnBatteryTimeBase, in); |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 14820 | mWifiMulticastWakelockTimer = new StopwatchTimer(mClocks, null, -4, null, |
| 14821 | mOnBatteryTimeBase, in); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 14822 | mWifiRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14823 | mWifiOn = false; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14824 | mWifiOnTimer = new StopwatchTimer(mClocks, null, -4, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14825 | mGlobalWifiRunning = false; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14826 | mGlobalWifiRunningTimer = new StopwatchTimer(mClocks, null, -5, null, |
| 14827 | mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14828 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14829 | mWifiStateTimer[i] = new StopwatchTimer(mClocks, null, -600-i, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14830 | null, mOnBatteryTimeBase, in); |
| 14831 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 14832 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14833 | mWifiSupplStateTimer[i] = new StopwatchTimer(mClocks, null, -700-i, |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 14834 | null, mOnBatteryTimeBase, in); |
| 14835 | } |
| 14836 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14837 | mWifiSignalStrengthsTimer[i] = new StopwatchTimer(mClocks, null, -800-i, |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 14838 | null, mOnBatteryTimeBase, in); |
| 14839 | } |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 14840 | mWifiActiveTimer = new StopwatchTimer(mClocks, null, -900, null, |
| 14841 | mOnBatteryTimeBase, in); |
| 14842 | mWifiActivity = new ControllerActivityCounterImpl(mOnBatteryTimeBase, |
| 14843 | NUM_WIFI_TX_LEVELS, in); |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 14844 | for (int i=0; i<GnssMetrics.NUM_GPS_SIGNAL_QUALITY_LEVELS; i++) { |
| 14845 | mGpsSignalQualityTimer[i] = new StopwatchTimer(mClocks, null, -1000-i, |
| 14846 | null, mOnBatteryTimeBase, in); |
| 14847 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 14848 | mBluetoothActivity = new ControllerActivityCounterImpl(mOnBatteryTimeBase, |
| 14849 | NUM_BT_TX_LEVELS, in); |
| 14850 | mModemActivity = new ControllerActivityCounterImpl(mOnBatteryTimeBase, |
| 14851 | ModemActivityInfo.TX_POWER_LEVELS, in); |
| 14852 | mHasWifiReporting = in.readInt() != 0; |
| 14853 | mHasBluetoothReporting = in.readInt() != 0; |
| 14854 | mHasModemReporting = in.readInt() != 0; |
| 14855 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 14856 | mNumConnectivityChange = in.readInt(); |
| 14857 | mLoadedNumConnectivityChange = in.readInt(); |
| 14858 | mUnpluggedNumConnectivityChange = in.readInt(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 14859 | mAudioOnNesting = 0; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14860 | mAudioOnTimer = new StopwatchTimer(mClocks, null, -7, null, mOnBatteryTimeBase); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 14861 | mVideoOnNesting = 0; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14862 | mVideoOnTimer = new StopwatchTimer(mClocks, null, -8, null, mOnBatteryTimeBase); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 14863 | mFlashlightOnNesting = 0; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14864 | mFlashlightOnTimer = new StopwatchTimer(mClocks, null, -9, null, mOnBatteryTimeBase, in); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 14865 | mCameraOnNesting = 0; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14866 | mCameraOnTimer = new StopwatchTimer(mClocks, null, -13, null, mOnBatteryTimeBase, in); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 14867 | mBluetoothScanNesting = 0; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14868 | mBluetoothScanTimer = new StopwatchTimer(mClocks, null, -14, null, mOnBatteryTimeBase, in); |
Siddharth Ray | f5e796a | 2018-01-22 18:18:17 -0800 | [diff] [blame] | 14869 | mIsCellularTxPowerHigh = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 14870 | mDischargeUnplugLevel = in.readInt(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 14871 | mDischargePlugLevel = in.readInt(); |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 14872 | mDischargeCurrentLevel = in.readInt(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 14873 | mCurrentBatteryLevel = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 14874 | mLowDischargeAmountSinceCharge = in.readInt(); |
| 14875 | mHighDischargeAmountSinceCharge = in.readInt(); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 14876 | mDischargeAmountScreenOn = in.readInt(); |
| 14877 | mDischargeAmountScreenOnSinceCharge = in.readInt(); |
| 14878 | mDischargeAmountScreenOff = in.readInt(); |
| 14879 | mDischargeAmountScreenOffSinceCharge = in.readInt(); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 14880 | mDischargeAmountScreenDoze = in.readInt(); |
| 14881 | mDischargeAmountScreenDozeSinceCharge = in.readInt(); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 14882 | mDischargeStepTracker.readFromParcel(in); |
| 14883 | mChargeStepTracker.readFromParcel(in); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 14884 | mDischargeCounter = new LongSamplingCounter(mOnBatteryTimeBase, in); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 14885 | mDischargeScreenOffCounter = new LongSamplingCounter(mOnBatteryScreenOffTimeBase, in); |
| 14886 | mDischargeScreenDozeCounter = new LongSamplingCounter(mOnBatteryTimeBase, in); |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 14887 | mDischargeLightDozeCounter = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 14888 | mDischargeDeepDozeCounter = new LongSamplingCounter(mOnBatteryTimeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14889 | mLastWriteTime = in.readLong(); |
| 14890 | |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 14891 | mRpmStats.clear(); |
| 14892 | int NRPMS = in.readInt(); |
| 14893 | for (int irpm = 0; irpm < NRPMS; irpm++) { |
| 14894 | if (in.readInt() != 0) { |
| 14895 | String rpmName = in.readString(); |
| 14896 | SamplingTimer rpmt = new SamplingTimer(mClocks, mOnBatteryTimeBase, in); |
| 14897 | mRpmStats.put(rpmName, rpmt); |
| 14898 | } |
| 14899 | } |
| 14900 | mScreenOffRpmStats.clear(); |
| 14901 | int NSORPMS = in.readInt(); |
| 14902 | for (int irpm = 0; irpm < NSORPMS; irpm++) { |
| 14903 | if (in.readInt() != 0) { |
| 14904 | String rpmName = in.readString(); |
| 14905 | SamplingTimer rpmt = new SamplingTimer(mClocks, mOnBatteryScreenOffTimeBase, in); |
| 14906 | mScreenOffRpmStats.put(rpmName, rpmt); |
| 14907 | } |
| 14908 | } |
| 14909 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 14910 | mKernelWakelockStats.clear(); |
| 14911 | int NKW = in.readInt(); |
| 14912 | for (int ikw = 0; ikw < NKW; ikw++) { |
| 14913 | if (in.readInt() != 0) { |
| 14914 | String wakelockName = in.readString(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14915 | SamplingTimer kwlt = new SamplingTimer(mClocks, mOnBatteryScreenOffTimeBase, in); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 14916 | mKernelWakelockStats.put(wakelockName, kwlt); |
| 14917 | } |
| 14918 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 14919 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 14920 | mWakeupReasonStats.clear(); |
| 14921 | int NWR = in.readInt(); |
| 14922 | for (int iwr = 0; iwr < NWR; iwr++) { |
| 14923 | if (in.readInt() != 0) { |
| 14924 | String reasonName = in.readString(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14925 | SamplingTimer timer = new SamplingTimer(mClocks, mOnBatteryTimeBase, in); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 14926 | mWakeupReasonStats.put(reasonName, timer); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 14927 | } |
| 14928 | } |
| 14929 | |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 14930 | mKernelMemoryStats.clear(); |
| 14931 | int nmt = in.readInt(); |
| 14932 | for (int imt = 0; imt < nmt; imt++) { |
| 14933 | if (in.readInt() != 0) { |
| 14934 | Long bucket = in.readLong(); |
| 14935 | SamplingTimer kmt = new SamplingTimer(mClocks, mOnBatteryTimeBase, in); |
| 14936 | mKernelMemoryStats.put(bucket, kmt); |
| 14937 | } |
| 14938 | } |
| 14939 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14940 | mPartialTimers.clear(); |
| 14941 | mFullTimers.clear(); |
| 14942 | mWindowTimers.clear(); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 14943 | mWifiRunningTimers.clear(); |
| 14944 | mFullWifiLockTimers.clear(); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 14945 | mWifiScanTimers.clear(); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 14946 | mWifiBatchedScanTimers.clear(); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 14947 | mWifiMulticastTimers.clear(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 14948 | mAudioTurnedOnTimers.clear(); |
| 14949 | mVideoTurnedOnTimers.clear(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 14950 | mFlashlightTurnedOnTimers.clear(); |
| 14951 | mCameraTurnedOnTimers.clear(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14952 | |
| 14953 | int numUids = in.readInt(); |
| 14954 | mUidStats.clear(); |
| 14955 | for (int i = 0; i < numUids; i++) { |
| 14956 | int uid = in.readInt(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14957 | Uid u = new Uid(this, uid); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14958 | u.readFromParcelLocked(mOnBatteryTimeBase, mOnBatteryScreenOffTimeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14959 | mUidStats.append(uid, u); |
| 14960 | } |
| 14961 | } |
| 14962 | |
| 14963 | public void writeToParcel(Parcel out, int flags) { |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 14964 | writeToParcelLocked(out, true, flags); |
| 14965 | } |
| 14966 | |
| 14967 | public void writeToParcelWithoutUids(Parcel out, int flags) { |
| 14968 | writeToParcelLocked(out, false, flags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14969 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 14970 | |
| 14971 | @SuppressWarnings("unused") |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 14972 | void writeToParcelLocked(Parcel out, boolean inclUids, int flags) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 14973 | // Need to update with current kernel wake lock counts. |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 14974 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 14975 | |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 14976 | // Pull the clock time. This may update the time and make a new history entry |
| 14977 | // if we had originally pulled a time before the RTC was set. |
| 14978 | long startClockTime = getStartClockTime(); |
| 14979 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14980 | final long uSecUptime = mClocks.uptimeMillis() * 1000; |
| 14981 | final long uSecRealtime = mClocks.elapsedRealtime() * 1000; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14982 | final long batteryRealtime = mOnBatteryTimeBase.getRealtime(uSecRealtime); |
| 14983 | final long batteryScreenOffRealtime = mOnBatteryScreenOffTimeBase.getRealtime(uSecRealtime); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 14984 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14985 | out.writeInt(MAGIC); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 14986 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 14987 | writeHistory(out, true, false); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 14988 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14989 | out.writeInt(mStartCount); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 14990 | out.writeLong(startClockTime); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 14991 | out.writeString(mStartPlatformVersion); |
| 14992 | out.writeString(mEndPlatformVersion); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14993 | out.writeLong(mUptime); |
| 14994 | out.writeLong(mUptimeStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14995 | out.writeLong(mRealtime); |
| 14996 | out.writeLong(mRealtimeStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14997 | out.writeInt(mOnBattery ? 1 : 0); |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 14998 | out.writeInt(mEstimatedBatteryCapacity); |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 14999 | out.writeInt(mMinLearnedBatteryCapacity); |
| 15000 | out.writeInt(mMaxLearnedBatteryCapacity); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 15001 | mOnBatteryTimeBase.writeToParcel(out, uSecUptime, uSecRealtime); |
| 15002 | mOnBatteryScreenOffTimeBase.writeToParcel(out, uSecUptime, uSecRealtime); |
| 15003 | |
| 15004 | mScreenOnTimer.writeToParcel(out, uSecRealtime); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 15005 | mScreenDozeTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 15006 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
| 15007 | mScreenBrightnessTimer[i].writeToParcel(out, uSecRealtime); |
| 15008 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 15009 | mInteractiveTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 15010 | mPowerSaveModeEnabledTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 15011 | out.writeLong(mLongestLightIdleTime); |
| 15012 | out.writeLong(mLongestFullIdleTime); |
| 15013 | mDeviceIdleModeLightTimer.writeToParcel(out, uSecRealtime); |
| 15014 | mDeviceIdleModeFullTimer.writeToParcel(out, uSecRealtime); |
| 15015 | mDeviceLightIdlingTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 15016 | mDeviceIdlingTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 15017 | mPhoneOnTimer.writeToParcel(out, uSecRealtime); |
| 15018 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
| 15019 | mPhoneSignalStrengthsTimer[i].writeToParcel(out, uSecRealtime); |
| 15020 | } |
| 15021 | mPhoneSignalScanningTimer.writeToParcel(out, uSecRealtime); |
| 15022 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
| 15023 | mPhoneDataConnectionsTimer[i].writeToParcel(out, uSecRealtime); |
| 15024 | } |
| 15025 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
| 15026 | mNetworkByteActivityCounters[i].writeToParcel(out); |
| 15027 | mNetworkPacketActivityCounters[i].writeToParcel(out); |
| 15028 | } |
| 15029 | mMobileRadioActiveTimer.writeToParcel(out, uSecRealtime); |
| 15030 | mMobileRadioActivePerAppTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 15031 | mMobileRadioActiveAdjustedTime.writeToParcel(out); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 15032 | mMobileRadioActiveUnknownTime.writeToParcel(out); |
| 15033 | mMobileRadioActiveUnknownCount.writeToParcel(out); |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 15034 | mWifiMulticastWakelockTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 15035 | mWifiOnTimer.writeToParcel(out, uSecRealtime); |
| 15036 | mGlobalWifiRunningTimer.writeToParcel(out, uSecRealtime); |
| 15037 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 15038 | mWifiStateTimer[i].writeToParcel(out, uSecRealtime); |
| 15039 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 15040 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 15041 | mWifiSupplStateTimer[i].writeToParcel(out, uSecRealtime); |
| 15042 | } |
| 15043 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 15044 | mWifiSignalStrengthsTimer[i].writeToParcel(out, uSecRealtime); |
| 15045 | } |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 15046 | mWifiActiveTimer.writeToParcel(out, uSecRealtime); |
| 15047 | mWifiActivity.writeToParcel(out, 0); |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 15048 | for (int i=0; i< GnssMetrics.NUM_GPS_SIGNAL_QUALITY_LEVELS; i++) { |
| 15049 | mGpsSignalQualityTimer[i].writeToParcel(out, uSecRealtime); |
| 15050 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 15051 | mBluetoothActivity.writeToParcel(out, 0); |
| 15052 | mModemActivity.writeToParcel(out, 0); |
| 15053 | out.writeInt(mHasWifiReporting ? 1 : 0); |
| 15054 | out.writeInt(mHasBluetoothReporting ? 1 : 0); |
| 15055 | out.writeInt(mHasModemReporting ? 1 : 0); |
| 15056 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 15057 | out.writeInt(mNumConnectivityChange); |
| 15058 | out.writeInt(mLoadedNumConnectivityChange); |
| 15059 | out.writeInt(mUnpluggedNumConnectivityChange); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 15060 | mFlashlightOnTimer.writeToParcel(out, uSecRealtime); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 15061 | mCameraOnTimer.writeToParcel(out, uSecRealtime); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 15062 | mBluetoothScanTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 15063 | out.writeInt(mDischargeUnplugLevel); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 15064 | out.writeInt(mDischargePlugLevel); |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 15065 | out.writeInt(mDischargeCurrentLevel); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 15066 | out.writeInt(mCurrentBatteryLevel); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 15067 | out.writeInt(mLowDischargeAmountSinceCharge); |
| 15068 | out.writeInt(mHighDischargeAmountSinceCharge); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 15069 | out.writeInt(mDischargeAmountScreenOn); |
| 15070 | out.writeInt(mDischargeAmountScreenOnSinceCharge); |
| 15071 | out.writeInt(mDischargeAmountScreenOff); |
| 15072 | out.writeInt(mDischargeAmountScreenOffSinceCharge); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 15073 | out.writeInt(mDischargeAmountScreenDoze); |
| 15074 | out.writeInt(mDischargeAmountScreenDozeSinceCharge); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 15075 | mDischargeStepTracker.writeToParcel(out); |
| 15076 | mChargeStepTracker.writeToParcel(out); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 15077 | mDischargeCounter.writeToParcel(out); |
| 15078 | mDischargeScreenOffCounter.writeToParcel(out); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 15079 | mDischargeScreenDozeCounter.writeToParcel(out); |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 15080 | mDischargeLightDozeCounter.writeToParcel(out); |
| 15081 | mDischargeDeepDozeCounter.writeToParcel(out); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15082 | out.writeLong(mLastWriteTime); |
| 15083 | |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 15084 | out.writeInt(mRpmStats.size()); |
| 15085 | for (Map.Entry<String, SamplingTimer> ent : mRpmStats.entrySet()) { |
| 15086 | SamplingTimer rpmt = ent.getValue(); |
| 15087 | if (rpmt != null) { |
| 15088 | out.writeInt(1); |
| 15089 | out.writeString(ent.getKey()); |
| 15090 | rpmt.writeToParcel(out, uSecRealtime); |
| 15091 | } else { |
| 15092 | out.writeInt(0); |
| 15093 | } |
| 15094 | } |
| 15095 | out.writeInt(mScreenOffRpmStats.size()); |
| 15096 | for (Map.Entry<String, SamplingTimer> ent : mScreenOffRpmStats.entrySet()) { |
| 15097 | SamplingTimer rpmt = ent.getValue(); |
| 15098 | if (rpmt != null) { |
| 15099 | out.writeInt(1); |
| 15100 | out.writeString(ent.getKey()); |
| 15101 | rpmt.writeToParcel(out, uSecRealtime); |
| 15102 | } else { |
| 15103 | out.writeInt(0); |
| 15104 | } |
| 15105 | } |
| 15106 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 15107 | if (inclUids) { |
| 15108 | out.writeInt(mKernelWakelockStats.size()); |
| 15109 | for (Map.Entry<String, SamplingTimer> ent : mKernelWakelockStats.entrySet()) { |
| 15110 | SamplingTimer kwlt = ent.getValue(); |
| 15111 | if (kwlt != null) { |
| 15112 | out.writeInt(1); |
| 15113 | out.writeString(ent.getKey()); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 15114 | kwlt.writeToParcel(out, uSecRealtime); |
| 15115 | } else { |
| 15116 | out.writeInt(0); |
| 15117 | } |
| 15118 | } |
| 15119 | out.writeInt(mWakeupReasonStats.size()); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 15120 | for (Map.Entry<String, SamplingTimer> ent : mWakeupReasonStats.entrySet()) { |
| 15121 | SamplingTimer timer = ent.getValue(); |
| 15122 | if (timer != null) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 15123 | out.writeInt(1); |
| 15124 | out.writeString(ent.getKey()); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 15125 | timer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 15126 | } else { |
| 15127 | out.writeInt(0); |
| 15128 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 15129 | } |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 15130 | } else { |
Bookatz | ba78b2b | 2017-10-10 11:06:33 -0700 | [diff] [blame] | 15131 | out.writeInt(0); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 15132 | out.writeInt(0); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 15133 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 15134 | |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 15135 | out.writeInt(mKernelMemoryStats.size()); |
| 15136 | for (int i = 0; i < mKernelMemoryStats.size(); i++) { |
| 15137 | SamplingTimer kmt = mKernelMemoryStats.valueAt(i); |
| 15138 | if (kmt != null) { |
| 15139 | out.writeInt(1); |
| 15140 | out.writeLong(mKernelMemoryStats.keyAt(i)); |
| 15141 | kmt.writeToParcel(out, uSecRealtime); |
| 15142 | } else { |
| 15143 | out.writeInt(0); |
| 15144 | } |
| 15145 | } |
| 15146 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 15147 | if (inclUids) { |
| 15148 | int size = mUidStats.size(); |
| 15149 | out.writeInt(size); |
| 15150 | for (int i = 0; i < size; i++) { |
| 15151 | out.writeInt(mUidStats.keyAt(i)); |
| 15152 | Uid uid = mUidStats.valueAt(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15153 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 15154 | uid.writeToParcelLocked(out, uSecUptime, uSecRealtime); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 15155 | } |
| 15156 | } else { |
| 15157 | out.writeInt(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15158 | } |
| 15159 | } |
| 15160 | |
Mathew Inwood | c185f08 | 2018-08-20 14:28:54 +0100 | [diff] [blame] | 15161 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15162 | public static final Parcelable.Creator<BatteryStatsImpl> CREATOR = |
| 15163 | new Parcelable.Creator<BatteryStatsImpl>() { |
| 15164 | public BatteryStatsImpl createFromParcel(Parcel in) { |
| 15165 | return new BatteryStatsImpl(in); |
| 15166 | } |
| 15167 | |
| 15168 | public BatteryStatsImpl[] newArray(int size) { |
| 15169 | return new BatteryStatsImpl[size]; |
| 15170 | } |
| 15171 | }; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 15172 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 15173 | public void prepareForDumpLocked() { |
| 15174 | // Need to retrieve current kernel wake lock stats before printing. |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 15175 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 15176 | |
| 15177 | // Pull the clock time. This may update the time and make a new history entry |
| 15178 | // if we had originally pulled a time before the RTC was set. |
| 15179 | getStartClockTime(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 15180 | } |
| 15181 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 15182 | 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] | 15183 | if (DEBUG) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 15184 | pw.println("mOnBatteryTimeBase:"); |
| 15185 | mOnBatteryTimeBase.dump(pw, " "); |
| 15186 | pw.println("mOnBatteryScreenOffTimeBase:"); |
| 15187 | mOnBatteryScreenOffTimeBase.dump(pw, " "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 15188 | Printer pr = new PrintWriterPrinter(pw); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 15189 | pr.println("*** Screen on timer:"); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 15190 | mScreenOnTimer.logState(pr, " "); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 15191 | pr.println("*** Screen doze timer:"); |
| 15192 | mScreenDozeTimer.logState(pr, " "); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 15193 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 15194 | pr.println("*** Screen brightness #" + i + ":"); |
| 15195 | mScreenBrightnessTimer[i].logState(pr, " "); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 15196 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 15197 | pr.println("*** Interactive timer:"); |
| 15198 | mInteractiveTimer.logState(pr, " "); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 15199 | pr.println("*** Power save mode timer:"); |
| 15200 | mPowerSaveModeEnabledTimer.logState(pr, " "); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 15201 | pr.println("*** Device idle mode light timer:"); |
| 15202 | mDeviceIdleModeLightTimer.logState(pr, " "); |
| 15203 | pr.println("*** Device idle mode full timer:"); |
| 15204 | mDeviceIdleModeFullTimer.logState(pr, " "); |
| 15205 | pr.println("*** Device light idling timer:"); |
| 15206 | mDeviceLightIdlingTimer.logState(pr, " "); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 15207 | pr.println("*** Device idling timer:"); |
| 15208 | mDeviceIdlingTimer.logState(pr, " "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 15209 | pr.println("*** Phone timer:"); |
| 15210 | mPhoneOnTimer.logState(pr, " "); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 15211 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 15212 | pr.println("*** Phone signal strength #" + i + ":"); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 15213 | mPhoneSignalStrengthsTimer[i].logState(pr, " "); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 15214 | } |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 15215 | pr.println("*** Signal scanning :"); |
| 15216 | mPhoneSignalScanningTimer.logState(pr, " "); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 15217 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 15218 | pr.println("*** Data connection type #" + i + ":"); |
| 15219 | mPhoneDataConnectionsTimer[i].logState(pr, " "); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 15220 | } |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 15221 | pr.println("*** mMobileRadioPowerState=" + mMobileRadioPowerState); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 15222 | pr.println("*** Mobile network active timer:"); |
| 15223 | mMobileRadioActiveTimer.logState(pr, " "); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 15224 | pr.println("*** Mobile network active adjusted timer:"); |
| 15225 | mMobileRadioActiveAdjustedTime.logState(pr, " "); |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 15226 | pr.println("*** Wifi Multicast WakeLock Timer:"); |
| 15227 | mWifiMulticastWakelockTimer.logState(pr, " "); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 15228 | pr.println("*** mWifiRadioPowerState=" + mWifiRadioPowerState); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 15229 | pr.println("*** Wifi timer:"); |
| 15230 | mWifiOnTimer.logState(pr, " "); |
| 15231 | pr.println("*** WifiRunning timer:"); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 15232 | mGlobalWifiRunningTimer.logState(pr, " "); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 15233 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 15234 | pr.println("*** Wifi state #" + i + ":"); |
| 15235 | mWifiStateTimer[i].logState(pr, " "); |
| 15236 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 15237 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 15238 | pr.println("*** Wifi suppl state #" + i + ":"); |
| 15239 | mWifiSupplStateTimer[i].logState(pr, " "); |
| 15240 | } |
| 15241 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 15242 | pr.println("*** Wifi signal strength #" + i + ":"); |
| 15243 | mWifiSignalStrengthsTimer[i].logState(pr, " "); |
| 15244 | } |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 15245 | for (int i=0; i<GnssMetrics.NUM_GPS_SIGNAL_QUALITY_LEVELS; i++) { |
| 15246 | pr.println("*** GPS signal quality #" + i + ":"); |
| 15247 | mGpsSignalQualityTimer[i].logState(pr, " "); |
| 15248 | } |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 15249 | pr.println("*** Flashlight timer:"); |
| 15250 | mFlashlightOnTimer.logState(pr, " "); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 15251 | pr.println("*** Camera timer:"); |
| 15252 | mCameraOnTimer.logState(pr, " "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15253 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 15254 | super.dumpLocked(context, pw, flags, reqUid, histStart); |
Sudheer Shanka | c20379e | 2018-02-15 00:06:21 -0800 | [diff] [blame] | 15255 | pw.print("Total cpu time reads: "); |
Mike Ma | 234d182 | 2018-03-13 18:53:21 -0700 | [diff] [blame] | 15256 | pw.println(mNumSingleUidCpuTimeReads); |
Sudheer Shanka | c20379e | 2018-02-15 00:06:21 -0800 | [diff] [blame] | 15257 | pw.print("Batched cpu time reads: "); |
Mike Ma | 234d182 | 2018-03-13 18:53:21 -0700 | [diff] [blame] | 15258 | pw.println(mNumBatchedSingleUidCpuTimeReads); |
Sudheer Shanka | c20379e | 2018-02-15 00:06:21 -0800 | [diff] [blame] | 15259 | pw.print("Batching Duration (min): "); |
| 15260 | pw.println((mClocks.uptimeMillis() - mCpuTimeReadsTrackingStartTime) / (60 * 1000)); |
Mike Ma | 234d182 | 2018-03-13 18:53:21 -0700 | [diff] [blame] | 15261 | pw.print("All UID cpu time reads since the later of device start or stats reset: "); |
| 15262 | pw.println(mNumAllUidCpuTimeReads); |
| 15263 | pw.print("UIDs removed since the later of device start or stats reset: "); |
| 15264 | pw.println(mNumUidsRemoved); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15265 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15266 | } |