The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006-2007 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.internal.os; |
| 18 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 19 | import android.annotation.NonNull; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 20 | import android.annotation.Nullable; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 21 | import android.app.ActivityManager; |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 22 | import android.bluetooth.BluetoothActivityEnergyInfo; |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 23 | import android.bluetooth.UidTraffic; |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 24 | import android.content.ContentResolver; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 25 | import android.content.Context; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 26 | import android.content.Intent; |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 27 | import android.database.ContentObserver; |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 28 | import android.net.ConnectivityManager; |
| 29 | import android.net.NetworkStats; |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 30 | import android.net.Uri; |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 31 | import android.net.wifi.WifiActivityEnergyInfo; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 32 | import android.net.wifi.WifiManager; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 33 | import android.os.BatteryManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 34 | import android.os.BatteryStats; |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 35 | import android.os.Build; |
Siddharth Ray | a1fd057 | 2017-11-13 14:20:47 -0800 | [diff] [blame] | 36 | import android.os.connectivity.CellularBatteryStats; |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 37 | import android.os.connectivity.WifiBatteryStats; |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 38 | import android.os.connectivity.GpsBatteryStats; |
Dianne Hackborn | 8bdf593 | 2010-10-15 12:54:40 -0700 | [diff] [blame] | 39 | import android.os.FileUtils; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 40 | import android.os.Handler; |
Adam Lesinski | e1f480d | 2017-02-15 18:51:23 -0800 | [diff] [blame] | 41 | import android.os.IBatteryPropertiesRegistrar; |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 42 | import android.os.Looper; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 43 | import android.os.Message; |
Bookatz | 1a1b046 | 2018-01-12 11:47:03 -0800 | [diff] [blame] | 44 | import android.os.OsProtoEnums; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 45 | import android.os.Parcel; |
| 46 | import android.os.ParcelFormatException; |
| 47 | import android.os.Parcelable; |
Bookatz | 1a1b046 | 2018-01-12 11:47:03 -0800 | [diff] [blame] | 48 | import android.os.PowerManager; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 49 | import android.os.Process; |
Adam Lesinski | e1f480d | 2017-02-15 18:51:23 -0800 | [diff] [blame] | 50 | import android.os.RemoteException; |
| 51 | import android.os.ServiceManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 52 | import android.os.SystemClock; |
Suprabh Shukla | e6e723d | 2017-06-14 16:14:43 -0700 | [diff] [blame] | 53 | import android.os.UserHandle; |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 54 | import android.os.WorkSource; |
Narayan Kamath | 8182202 | 2017-12-08 11:56:01 +0000 | [diff] [blame] | 55 | import android.os.WorkSource.WorkChain; |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 56 | import android.provider.Settings; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 57 | import android.telephony.DataConnectionRealTimeInfo; |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 58 | import android.telephony.ModemActivityInfo; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 59 | import android.telephony.ServiceState; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 60 | import android.telephony.SignalStrength; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 61 | import android.telephony.TelephonyManager; |
Jeff Sharkey | 9da2f1e | 2014-08-14 12:55:00 -0700 | [diff] [blame] | 62 | import android.text.TextUtils; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 63 | import android.util.ArrayMap; |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 64 | import android.util.IntArray; |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 65 | import android.util.KeyValueListParser; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 66 | import android.util.Log; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 67 | import android.util.LogWriter; |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 68 | import android.util.LongSparseArray; |
| 69 | import android.util.LongSparseLongArray; |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 70 | import android.util.MutableInt; |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 71 | import android.util.Pools; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 72 | import android.util.PrintWriterPrinter; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 73 | import android.util.Printer; |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 74 | import android.util.Slog; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 75 | import android.util.SparseArray; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 76 | import android.util.SparseIntArray; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 77 | import android.util.SparseLongArray; |
Bookatz | c1a050a | 2017-10-10 15:49:28 -0700 | [diff] [blame] | 78 | import android.util.StatsLog; |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 79 | import android.util.TimeUtils; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 80 | import android.util.Xml; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 81 | import android.view.Display; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 82 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 83 | import com.android.internal.annotations.GuardedBy; |
Adam Lesinski | 98f0d46 | 2016-04-19 16:46:20 -0700 | [diff] [blame] | 84 | import com.android.internal.annotations.VisibleForTesting; |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 85 | import com.android.internal.location.gnssmetrics.GnssMetrics; |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 86 | import com.android.internal.net.NetworkStatsFactory; |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 87 | import com.android.internal.util.ArrayUtils; |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 88 | import com.android.internal.util.FastPrintWriter; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 89 | import com.android.internal.util.FastXmlSerializer; |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 90 | import com.android.internal.util.JournaledFile; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 91 | import com.android.internal.util.XmlUtils; |
Suprabh Shukla | e6e723d | 2017-06-14 16:14:43 -0700 | [diff] [blame] | 92 | |
Narayan Kamath | 8182202 | 2017-12-08 11:56:01 +0000 | [diff] [blame] | 93 | import java.util.List; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 94 | import libcore.util.EmptyArray; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 95 | import org.xmlpull.v1.XmlPullParser; |
| 96 | import org.xmlpull.v1.XmlPullParserException; |
| 97 | import org.xmlpull.v1.XmlSerializer; |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 98 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 99 | import java.io.ByteArrayOutputStream; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 100 | import java.io.File; |
| 101 | import java.io.FileInputStream; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 102 | import java.io.FileNotFoundException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 103 | import java.io.FileOutputStream; |
| 104 | import java.io.IOException; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 105 | import java.io.PrintWriter; |
Wojciech Staszkiewicz | 9e9e2e7 | 2015-05-08 14:58:46 +0100 | [diff] [blame] | 106 | import java.nio.charset.StandardCharsets; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 107 | import java.util.ArrayList; |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 108 | import java.util.Arrays; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 109 | import java.util.Calendar; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 110 | import java.util.HashMap; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 111 | import java.util.Iterator; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 112 | import java.util.Map; |
Adam Lesinski | b3a1bad | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 113 | import java.util.concurrent.Future; |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 114 | import java.util.concurrent.atomic.AtomicInteger; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 115 | import java.util.concurrent.locks.ReentrantLock; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 116 | |
| 117 | /** |
| 118 | * All information we are collecting about things that can happen that impact |
| 119 | * battery life. All times are represented in microseconds except where indicated |
| 120 | * otherwise. |
| 121 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 122 | public class BatteryStatsImpl extends BatteryStats { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 123 | private static final String TAG = "BatteryStatsImpl"; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 124 | private static final boolean DEBUG = false; |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 125 | public static final boolean DEBUG_ENERGY = false; |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 126 | private static final boolean DEBUG_ENERGY_CPU = DEBUG_ENERGY; |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 127 | private static final boolean DEBUG_MEMORY = false; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 128 | private static final boolean DEBUG_HISTORY = false; |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 129 | private static final boolean USE_OLD_HISTORY = false; // for debugging. |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 130 | |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 131 | // TODO: remove "tcp" from network methods, since we measure total stats. |
| 132 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 133 | // 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] | 134 | private static final int MAGIC = 0xBA757475; // 'BATSTATS' |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 135 | |
| 136 | // Current on-disk Parcel version |
Amith Yamasani | 977e11f | 2018-02-16 11:29:54 -0800 | [diff] [blame] | 137 | private static final int VERSION = 175 + (USE_OLD_HISTORY ? 1000 : 0); |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 138 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 139 | // Maximum number of items we will record in the history. |
Narayan Kamath | b59b7c3 | 2017-06-12 14:11:03 +0100 | [diff] [blame] | 140 | private static final int MAX_HISTORY_ITEMS; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 141 | |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 142 | // 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] | 143 | private static final int MAX_MAX_HISTORY_ITEMS; |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 144 | |
Dianne Hackborn | 9e0f5d9 | 2010-02-22 15:05:42 -0800 | [diff] [blame] | 145 | // The maximum number of names wakelocks we will keep track of |
| 146 | // per uid; once the limit is reached, we batch the remaining wakelocks |
| 147 | // in to one common name. |
Narayan Kamath | b59b7c3 | 2017-06-12 14:11:03 +0100 | [diff] [blame] | 148 | private static final int MAX_WAKELOCKS_PER_UID; |
| 149 | |
| 150 | static final int MAX_HISTORY_BUFFER; // 256KB |
| 151 | static final int MAX_MAX_HISTORY_BUFFER; // 320KB |
| 152 | |
| 153 | static { |
| 154 | if (ActivityManager.isLowRamDeviceStatic()) { |
| 155 | MAX_HISTORY_ITEMS = 800; |
| 156 | MAX_MAX_HISTORY_ITEMS = 1200; |
| 157 | MAX_WAKELOCKS_PER_UID = 40; |
| 158 | MAX_HISTORY_BUFFER = 96*1024; // 96KB |
| 159 | MAX_MAX_HISTORY_BUFFER = 128*1024; // 128KB |
| 160 | } else { |
Makoto Onuki | 44d6460 | 2018-01-18 08:44:28 -0800 | [diff] [blame] | 161 | MAX_HISTORY_ITEMS = 4000; |
| 162 | MAX_MAX_HISTORY_ITEMS = 6000; |
| 163 | MAX_WAKELOCKS_PER_UID = 200; |
| 164 | MAX_HISTORY_BUFFER = 512*1024; // 512KB |
| 165 | MAX_MAX_HISTORY_BUFFER = 640*1024; // 640KB |
Narayan Kamath | b59b7c3 | 2017-06-12 14:11:03 +0100 | [diff] [blame] | 166 | } |
| 167 | } |
Dianne Hackborn | c24ab86 | 2011-10-18 15:55:03 -0700 | [diff] [blame] | 168 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 169 | // Number of transmit power states the Wifi controller can be in. |
| 170 | private static final int NUM_WIFI_TX_LEVELS = 1; |
| 171 | |
| 172 | // Number of transmit power states the Bluetooth controller can be in. |
| 173 | private static final int NUM_BT_TX_LEVELS = 1; |
| 174 | |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 175 | /** |
| 176 | * Holding a wakelock costs more than just using the cpu. |
| 177 | * Currently, we assign only half the cpu time to an app that is running but |
| 178 | * not holding a wakelock. The apps holding wakelocks get the rest of the blame. |
| 179 | * If no app is holding a wakelock, then the distribution is normal. |
| 180 | */ |
| 181 | @VisibleForTesting |
| 182 | public static final int WAKE_LOCK_WEIGHT = 50; |
| 183 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 184 | protected Clocks mClocks; |
| 185 | |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 186 | private final JournaledFile mFile; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 187 | public final AtomicFile mCheckinFile; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 188 | public final AtomicFile mDailyFile; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 189 | |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 190 | static final int MSG_REPORT_CPU_UPDATE_NEEDED = 1; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 191 | static final int MSG_REPORT_POWER_CHANGE = 2; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 192 | static final int MSG_REPORT_CHARGING = 3; |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 193 | static final long DELAY_UPDATE_WAKELOCKS = 5*1000; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 194 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 195 | private final KernelWakelockReader mKernelWakelockReader = new KernelWakelockReader(); |
| 196 | private final KernelWakelockStats mTmpWakelockStats = new KernelWakelockStats(); |
| 197 | |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 198 | @VisibleForTesting |
| 199 | protected KernelUidCpuTimeReader mKernelUidCpuTimeReader = new KernelUidCpuTimeReader(); |
| 200 | @VisibleForTesting |
| 201 | protected KernelCpuSpeedReader[] mKernelCpuSpeedReaders; |
| 202 | @VisibleForTesting |
| 203 | protected KernelUidCpuFreqTimeReader mKernelUidCpuFreqTimeReader = |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 204 | new KernelUidCpuFreqTimeReader(); |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 205 | @VisibleForTesting |
Mike Ma | 3d422c3 | 2017-10-25 11:08:57 -0700 | [diff] [blame] | 206 | protected KernelUidCpuActiveTimeReader mKernelUidCpuActiveTimeReader = |
| 207 | new KernelUidCpuActiveTimeReader(); |
| 208 | @VisibleForTesting |
| 209 | protected KernelUidCpuClusterTimeReader mKernelUidCpuClusterTimeReader = |
| 210 | new KernelUidCpuClusterTimeReader(); |
| 211 | @VisibleForTesting |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 212 | protected KernelSingleUidTimeReader mKernelSingleUidTimeReader; |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 213 | |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 214 | private final KernelMemoryBandwidthStats mKernelMemoryBandwidthStats |
| 215 | = new KernelMemoryBandwidthStats(); |
| 216 | private final LongSparseArray<SamplingTimer> mKernelMemoryStats = new LongSparseArray<>(); |
| 217 | public LongSparseArray<SamplingTimer> getKernelMemoryStats() { |
| 218 | return mKernelMemoryStats; |
| 219 | } |
| 220 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 221 | @GuardedBy("this") |
| 222 | public boolean mPerProcStateCpuTimesAvailable = true; |
| 223 | |
| 224 | /** |
| 225 | * Uids for which per-procstate cpu times need to be updated. |
| 226 | * |
| 227 | * Contains uid -> procState mappings. |
| 228 | */ |
| 229 | @GuardedBy("this") |
| 230 | @VisibleForTesting |
| 231 | protected final SparseIntArray mPendingUids = new SparseIntArray(); |
| 232 | |
Sudheer Shanka | c20379e | 2018-02-15 00:06:21 -0800 | [diff] [blame] | 233 | @GuardedBy("this") |
| 234 | private long mNumCpuTimeReads; |
| 235 | @GuardedBy("this") |
| 236 | private long mNumBatchedCpuTimeReads; |
| 237 | @GuardedBy("this") |
| 238 | private long mCpuTimeReadsTrackingStartTime = SystemClock.uptimeMillis(); |
| 239 | |
Bookatz | 0b8a050 | 2017-09-13 11:51:52 -0700 | [diff] [blame] | 240 | /** Container for Resource Power Manager stats. Updated by updateRpmStatsLocked. */ |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 241 | private final RpmStats mTmpRpmStats = new RpmStats(); |
Bookatz | 0b8a050 | 2017-09-13 11:51:52 -0700 | [diff] [blame] | 242 | /** The soonest the RPM stats can be updated after it was last updated. */ |
| 243 | private static final long RPM_STATS_UPDATE_FREQ_MS = 1000; |
| 244 | /** Last time that RPM stats were updated by updateRpmStatsLocked. */ |
| 245 | private long mLastRpmStatsUpdateTimeMs = -RPM_STATS_UPDATE_FREQ_MS; |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 246 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 247 | public interface BatteryCallback { |
| 248 | public void batteryNeedsCpuUpdate(); |
| 249 | public void batteryPowerChanged(boolean onBattery); |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 250 | public void batterySendBroadcast(Intent intent); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 251 | } |
| 252 | |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 253 | public interface PlatformIdleStateCallback { |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 254 | public void fillLowPowerStats(RpmStats rpmStats); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 255 | public String getPlatformLowPowerStats(); |
Ahmed ElArabawy | d8b4411 | 2017-05-23 21:25:02 +0000 | [diff] [blame] | 256 | public String getSubsystemLowPowerStats(); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 257 | } |
| 258 | |
Suprabh Shukla | e6e723d | 2017-06-14 16:14:43 -0700 | [diff] [blame] | 259 | public static abstract class UserInfoProvider { |
| 260 | private int[] userIds; |
| 261 | protected abstract @Nullable int[] getUserIds(); |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 262 | @VisibleForTesting |
| 263 | public final void refreshUserIds() { |
Suprabh Shukla | e6e723d | 2017-06-14 16:14:43 -0700 | [diff] [blame] | 264 | userIds = getUserIds(); |
| 265 | } |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 266 | @VisibleForTesting |
| 267 | public boolean exists(int userId) { |
Suprabh Shukla | e6e723d | 2017-06-14 16:14:43 -0700 | [diff] [blame] | 268 | return userIds != null ? ArrayUtils.contains(userIds, userId) : true; |
| 269 | } |
| 270 | } |
| 271 | |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 272 | private final PlatformIdleStateCallback mPlatformIdleStateCallback; |
| 273 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 274 | final class MyHandler extends Handler { |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 275 | public MyHandler(Looper looper) { |
| 276 | super(looper, null, true); |
| 277 | } |
| 278 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 279 | @Override |
| 280 | public void handleMessage(Message msg) { |
| 281 | BatteryCallback cb = mCallback; |
| 282 | switch (msg.what) { |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 283 | case MSG_REPORT_CPU_UPDATE_NEEDED: |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 284 | if (cb != null) { |
| 285 | cb.batteryNeedsCpuUpdate(); |
| 286 | } |
| 287 | break; |
| 288 | case MSG_REPORT_POWER_CHANGE: |
| 289 | if (cb != null) { |
| 290 | cb.batteryPowerChanged(msg.arg1 != 0); |
| 291 | } |
| 292 | break; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 293 | case MSG_REPORT_CHARGING: |
| 294 | if (cb != null) { |
| 295 | final String action; |
| 296 | synchronized (BatteryStatsImpl.this) { |
| 297 | action = mCharging ? BatteryManager.ACTION_CHARGING |
| 298 | : BatteryManager.ACTION_DISCHARGING; |
| 299 | } |
| 300 | Intent intent = new Intent(action); |
| 301 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); |
| 302 | cb.batterySendBroadcast(intent); |
| 303 | } |
| 304 | break; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 305 | } |
| 306 | } |
| 307 | } |
| 308 | |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 309 | public void postBatteryNeedsCpuUpdateMsg() { |
| 310 | mHandler.sendEmptyMessage(MSG_REPORT_CPU_UPDATE_NEEDED); |
| 311 | } |
| 312 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 313 | /** |
| 314 | * Update per-freq cpu times for all the uids in {@link #mPendingUids}. |
| 315 | */ |
Sudheer Shanka | e544d16 | 2017-12-28 17:06:20 -0800 | [diff] [blame] | 316 | public void updateProcStateCpuTimes(boolean onBattery, boolean onBatteryScreenOff) { |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 317 | final SparseIntArray uidStates; |
| 318 | synchronized (BatteryStatsImpl.this) { |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 319 | if (!mConstants.TRACK_CPU_TIMES_BY_PROC_STATE) { |
| 320 | return; |
| 321 | } |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 322 | if(!initKernelSingleUidTimeReaderLocked()) { |
| 323 | return; |
| 324 | } |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 325 | // If the KernelSingleUidTimeReader has stale cpu times, then we shouldn't try to |
| 326 | // compute deltas since it might result in mis-attributing cpu times to wrong states. |
| 327 | if (mKernelSingleUidTimeReader.hasStaleData()) { |
| 328 | mPendingUids.clear(); |
| 329 | return; |
| 330 | } |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 331 | |
| 332 | if (mPendingUids.size() == 0) { |
| 333 | return; |
| 334 | } |
| 335 | uidStates = mPendingUids.clone(); |
| 336 | mPendingUids.clear(); |
| 337 | } |
| 338 | for (int i = uidStates.size() - 1; i >= 0; --i) { |
| 339 | final int uid = uidStates.keyAt(i); |
| 340 | final int procState = uidStates.valueAt(i); |
| 341 | final int[] isolatedUids; |
| 342 | final Uid u; |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 343 | synchronized (BatteryStatsImpl.this) { |
| 344 | // It's possible that uid no longer exists and any internal references have |
| 345 | // already been deleted, so using {@link #getAvailableUidStatsLocked} to avoid |
| 346 | // creating an UidStats object if it doesn't already exist. |
| 347 | u = getAvailableUidStatsLocked(uid); |
| 348 | if (u == null) { |
| 349 | continue; |
| 350 | } |
| 351 | if (u.mChildUids == null) { |
| 352 | isolatedUids = null; |
| 353 | } else { |
| 354 | isolatedUids = u.mChildUids.toArray(); |
| 355 | for (int j = isolatedUids.length - 1; j >= 0; --j) { |
| 356 | isolatedUids[j] = u.mChildUids.get(j); |
| 357 | } |
| 358 | } |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 359 | } |
| 360 | long[] cpuTimesMs = mKernelSingleUidTimeReader.readDeltaMs(uid); |
| 361 | if (isolatedUids != null) { |
| 362 | for (int j = isolatedUids.length - 1; j >= 0; --j) { |
| 363 | cpuTimesMs = addCpuTimes(cpuTimesMs, |
| 364 | mKernelSingleUidTimeReader.readDeltaMs(isolatedUids[j])); |
| 365 | } |
| 366 | } |
| 367 | if (onBattery && cpuTimesMs != null) { |
| 368 | synchronized (BatteryStatsImpl.this) { |
Sudheer Shanka | e544d16 | 2017-12-28 17:06:20 -0800 | [diff] [blame] | 369 | u.addProcStateTimesMs(procState, cpuTimesMs, onBattery); |
| 370 | u.addProcStateScreenOffTimesMs(procState, cpuTimesMs, onBatteryScreenOff); |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 371 | } |
| 372 | } |
| 373 | } |
| 374 | } |
| 375 | |
Sudheer Shanka | e544d16 | 2017-12-28 17:06:20 -0800 | [diff] [blame] | 376 | public void copyFromAllUidsCpuTimes() { |
| 377 | synchronized (BatteryStatsImpl.this) { |
| 378 | copyFromAllUidsCpuTimes( |
| 379 | mOnBatteryTimeBase.isRunning(), mOnBatteryScreenOffTimeBase.isRunning()); |
| 380 | } |
| 381 | } |
| 382 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 383 | /** |
| 384 | * When the battery/screen state changes, we don't attribute the cpu times to any process |
| 385 | * but we still need to snapshots of all uids to get correct deltas later on. Since we |
| 386 | * already read this data for updating per-freq cpu times, we can use the same data for |
| 387 | * per-procstate cpu times. |
| 388 | */ |
Sudheer Shanka | e544d16 | 2017-12-28 17:06:20 -0800 | [diff] [blame] | 389 | public void copyFromAllUidsCpuTimes(boolean onBattery, boolean onBatteryScreenOff) { |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 390 | synchronized (BatteryStatsImpl.this) { |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 391 | if (!mConstants.TRACK_CPU_TIMES_BY_PROC_STATE) { |
| 392 | return; |
| 393 | } |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 394 | if(!initKernelSingleUidTimeReaderLocked()) { |
| 395 | return; |
| 396 | } |
| 397 | |
| 398 | final SparseArray<long[]> allUidCpuFreqTimesMs = |
| 399 | mKernelUidCpuFreqTimeReader.getAllUidCpuFreqTimeMs(); |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 400 | // If the KernelSingleUidTimeReader has stale cpu times, then we shouldn't try to |
| 401 | // compute deltas since it might result in mis-attributing cpu times to wrong states. |
| 402 | if (mKernelSingleUidTimeReader.hasStaleData()) { |
| 403 | mKernelSingleUidTimeReader.setAllUidsCpuTimesMs(allUidCpuFreqTimesMs); |
| 404 | mKernelSingleUidTimeReader.markDataAsStale(false); |
| 405 | mPendingUids.clear(); |
| 406 | return; |
| 407 | } |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 408 | for (int i = allUidCpuFreqTimesMs.size() - 1; i >= 0; --i) { |
| 409 | final int uid = allUidCpuFreqTimesMs.keyAt(i); |
| 410 | final Uid u = getAvailableUidStatsLocked(mapUid(uid)); |
| 411 | if (u == null) { |
| 412 | continue; |
| 413 | } |
| 414 | final long[] cpuTimesMs = allUidCpuFreqTimesMs.valueAt(i); |
| 415 | if (cpuTimesMs == null) { |
| 416 | continue; |
| 417 | } |
| 418 | final long[] deltaTimesMs = mKernelSingleUidTimeReader.computeDelta( |
| 419 | uid, cpuTimesMs.clone()); |
Sudheer Shanka | e544d16 | 2017-12-28 17:06:20 -0800 | [diff] [blame] | 420 | if (onBattery && deltaTimesMs != null) { |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 421 | final int procState; |
| 422 | final int idx = mPendingUids.indexOfKey(uid); |
| 423 | if (idx >= 0) { |
| 424 | procState = mPendingUids.valueAt(idx); |
| 425 | mPendingUids.removeAt(idx); |
| 426 | } else { |
| 427 | procState = u.mProcessState; |
| 428 | } |
| 429 | if (procState >= 0 && procState < Uid.NUM_PROCESS_STATE) { |
Sudheer Shanka | e544d16 | 2017-12-28 17:06:20 -0800 | [diff] [blame] | 430 | u.addProcStateTimesMs(procState, deltaTimesMs, onBattery); |
| 431 | u.addProcStateScreenOffTimesMs(procState, deltaTimesMs, onBatteryScreenOff); |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 432 | } |
| 433 | } |
| 434 | } |
| 435 | } |
| 436 | } |
| 437 | |
| 438 | @VisibleForTesting |
| 439 | public long[] addCpuTimes(long[] timesA, long[] timesB) { |
| 440 | if (timesA != null && timesB != null) { |
| 441 | for (int i = timesA.length - 1; i >= 0; --i) { |
| 442 | timesA[i] += timesB[i]; |
| 443 | } |
| 444 | return timesA; |
| 445 | } |
| 446 | return timesA == null ? (timesB == null ? null : timesB) : timesA; |
| 447 | } |
| 448 | |
| 449 | @GuardedBy("this") |
| 450 | private boolean initKernelSingleUidTimeReaderLocked() { |
| 451 | if (mKernelSingleUidTimeReader == null) { |
| 452 | if (mPowerProfile == null) { |
| 453 | return false; |
| 454 | } |
| 455 | if (mCpuFreqs == null) { |
| 456 | mCpuFreqs = mKernelUidCpuFreqTimeReader.readFreqs(mPowerProfile); |
| 457 | } |
| 458 | if (mCpuFreqs != null) { |
| 459 | mKernelSingleUidTimeReader = new KernelSingleUidTimeReader(mCpuFreqs.length); |
| 460 | } else { |
| 461 | mPerProcStateCpuTimesAvailable = mKernelUidCpuFreqTimeReader.allUidTimesAvailable(); |
| 462 | return false; |
| 463 | } |
| 464 | } |
| 465 | mPerProcStateCpuTimesAvailable = mKernelUidCpuFreqTimeReader.allUidTimesAvailable() |
| 466 | && mKernelSingleUidTimeReader.singleUidCpuTimesAvailable(); |
| 467 | return true; |
| 468 | } |
| 469 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 470 | public interface Clocks { |
| 471 | public long elapsedRealtime(); |
| 472 | public long uptimeMillis(); |
| 473 | } |
| 474 | |
| 475 | public static class SystemClocks implements Clocks { |
| 476 | public long elapsedRealtime() { |
| 477 | return SystemClock.elapsedRealtime(); |
| 478 | } |
| 479 | |
| 480 | public long uptimeMillis() { |
| 481 | return SystemClock.uptimeMillis(); |
| 482 | } |
| 483 | } |
| 484 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 485 | public interface ExternalStatsSync { |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 486 | int UPDATE_CPU = 0x01; |
| 487 | int UPDATE_WIFI = 0x02; |
| 488 | int UPDATE_RADIO = 0x04; |
| 489 | int UPDATE_BT = 0x08; |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 490 | int UPDATE_RPM = 0x10; // 16 |
| 491 | 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] | 492 | |
Adam Lesinski | b3a1bad | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 493 | Future<?> scheduleSync(String reason, int flags); |
| 494 | Future<?> scheduleCpuSyncDueToRemovedUid(int uid); |
Sudheer Shanka | c20379e | 2018-02-15 00:06:21 -0800 | [diff] [blame] | 495 | Future<?> scheduleReadProcStateCpuTimes(boolean onBattery, boolean onBatteryScreenOff, |
| 496 | long delayMillis); |
Sudheer Shanka | e544d16 | 2017-12-28 17:06:20 -0800 | [diff] [blame] | 497 | Future<?> scheduleCopyFromAllUidsCpuTimes(boolean onBattery, boolean onBatteryScreenOff); |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 498 | Future<?> scheduleCpuSyncDueToSettingChange(); |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 499 | Future<?> scheduleCpuSyncDueToScreenStateChange(boolean onBattery, |
| 500 | boolean onBatteryScreenOff); |
| 501 | Future<?> scheduleCpuSyncDueToWakelockChange(long delayMillis); |
| 502 | void cancelCpuSyncDueToWakelockChange(); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 503 | } |
| 504 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 505 | public Handler mHandler; |
Adam Lesinski | b3a1bad | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 506 | private ExternalStatsSync mExternalSync = null; |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 507 | @VisibleForTesting |
| 508 | protected UserInfoProvider mUserInfoProvider = null; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 509 | |
| 510 | private BatteryCallback mCallback; |
| 511 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 512 | /** |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 513 | * Mapping isolated uids to the actual owning app uid. |
| 514 | */ |
| 515 | final SparseIntArray mIsolatedUids = new SparseIntArray(); |
| 516 | |
| 517 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 518 | * The statistics we have collected organized by uids. |
| 519 | */ |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 520 | final SparseArray<BatteryStatsImpl.Uid> mUidStats = new SparseArray<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 521 | |
| 522 | // A set of pools of currently active timers. When a timer is queried, we will divide the |
| 523 | // elapsed time by the number of active timers to arrive at that timer's share of the time. |
| 524 | // In order to do this, we must refresh each timer whenever the number of active timers |
| 525 | // changes. |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 526 | @VisibleForTesting |
| 527 | protected ArrayList<StopwatchTimer> mPartialTimers = new ArrayList<>(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 528 | final ArrayList<StopwatchTimer> mFullTimers = new ArrayList<>(); |
| 529 | final ArrayList<StopwatchTimer> mWindowTimers = new ArrayList<>(); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 530 | final ArrayList<StopwatchTimer> mDrawTimers = new ArrayList<>(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 531 | final SparseArray<ArrayList<StopwatchTimer>> mSensorTimers = new SparseArray<>(); |
| 532 | final ArrayList<StopwatchTimer> mWifiRunningTimers = new ArrayList<>(); |
| 533 | final ArrayList<StopwatchTimer> mFullWifiLockTimers = new ArrayList<>(); |
| 534 | final ArrayList<StopwatchTimer> mWifiMulticastTimers = new ArrayList<>(); |
| 535 | final ArrayList<StopwatchTimer> mWifiScanTimers = new ArrayList<>(); |
| 536 | final SparseArray<ArrayList<StopwatchTimer>> mWifiBatchedScanTimers = new SparseArray<>(); |
| 537 | final ArrayList<StopwatchTimer> mAudioTurnedOnTimers = new ArrayList<>(); |
| 538 | final ArrayList<StopwatchTimer> mVideoTurnedOnTimers = new ArrayList<>(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 539 | final ArrayList<StopwatchTimer> mFlashlightTurnedOnTimers = new ArrayList<>(); |
| 540 | final ArrayList<StopwatchTimer> mCameraTurnedOnTimers = new ArrayList<>(); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 541 | final ArrayList<StopwatchTimer> mBluetoothScanOnTimers = new ArrayList<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 542 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 543 | // Last partial timers we use for distributing CPU usage. |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 544 | @VisibleForTesting |
| 545 | protected ArrayList<StopwatchTimer> mLastPartialTimers = new ArrayList<>(); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 546 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 547 | // These are the objects that will want to do something when the device |
| 548 | // is unplugged from power. |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 549 | protected final TimeBase mOnBatteryTimeBase = new TimeBase(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 550 | |
| 551 | // 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] | 552 | // is unplugged from power *and* the screen is off or doze. |
| 553 | protected final TimeBase mOnBatteryScreenOffTimeBase = new TimeBase(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 554 | |
| 555 | // Set to true when we want to distribute CPU across wakelocks for the next |
| 556 | // CPU update, even if we aren't currently running wake locks. |
| 557 | boolean mDistributeWakelockCpu; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 558 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 559 | boolean mShuttingDown; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 560 | |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 561 | final HistoryEventTracker mActiveEvents = new HistoryEventTracker(); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 562 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 563 | long mHistoryBaseTime; |
Narayan Kamath | 695cf72 | 2017-12-21 18:32:47 +0000 | [diff] [blame] | 564 | protected boolean mHaveBatteryLevel = false; |
| 565 | protected boolean mRecordingHistory = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 566 | int mNumHistoryItems; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 567 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 568 | final Parcel mHistoryBuffer = Parcel.obtain(); |
| 569 | final HistoryItem mHistoryLastWritten = new HistoryItem(); |
| 570 | final HistoryItem mHistoryLastLastWritten = new HistoryItem(); |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 571 | final HistoryItem mHistoryReadTmp = new HistoryItem(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 572 | final HistoryItem mHistoryAddTmp = new HistoryItem(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 573 | final HashMap<HistoryTag, Integer> mHistoryTagPool = new HashMap<>(); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 574 | String[] mReadHistoryStrings; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 575 | int[] mReadHistoryUids; |
| 576 | int mReadHistoryChars; |
| 577 | int mNextHistoryTagIdx = 0; |
| 578 | int mNumHistoryTagChars = 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 579 | int mHistoryBufferLastPos = -1; |
| 580 | boolean mHistoryOverflow = false; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 581 | int mActiveHistoryStates = 0xffffffff; |
| 582 | int mActiveHistoryStates2 = 0xffffffff; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 583 | long mLastHistoryElapsedRealtime = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 584 | long mTrackRunningHistoryElapsedRealtime = 0; |
| 585 | long mTrackRunningHistoryUptime = 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 586 | |
| 587 | final HistoryItem mHistoryCur = new HistoryItem(); |
| 588 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 589 | HistoryItem mHistory; |
| 590 | HistoryItem mHistoryEnd; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 591 | HistoryItem mHistoryLastEnd; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 592 | HistoryItem mHistoryCache; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 593 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 594 | // Used by computeHistoryStepDetails |
| 595 | HistoryStepDetails mLastHistoryStepDetails = null; |
| 596 | byte mLastHistoryStepLevel = 0; |
| 597 | final HistoryStepDetails mCurHistoryStepDetails = new HistoryStepDetails(); |
| 598 | final HistoryStepDetails mReadHistoryStepDetails = new HistoryStepDetails(); |
| 599 | final HistoryStepDetails mTmpHistoryStepDetails = new HistoryStepDetails(); |
Adam Lesinski | 7b83b0c | 2015-06-05 12:59:36 -0700 | [diff] [blame] | 600 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 601 | /** |
Adam Lesinski | 7b83b0c | 2015-06-05 12:59:36 -0700 | [diff] [blame] | 602 | * Total time (in milliseconds) spent executing in user code. |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 603 | */ |
| 604 | long mLastStepCpuUserTime; |
| 605 | long mCurStepCpuUserTime; |
| 606 | /** |
Adam Lesinski | 7b83b0c | 2015-06-05 12:59:36 -0700 | [diff] [blame] | 607 | * Total time (in milliseconds) spent executing in kernel code. |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 608 | */ |
| 609 | long mLastStepCpuSystemTime; |
| 610 | long mCurStepCpuSystemTime; |
| 611 | /** |
Adam Lesinski | 7b83b0c | 2015-06-05 12:59:36 -0700 | [diff] [blame] | 612 | * Times from /proc/stat (but measured in milliseconds). |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 613 | */ |
| 614 | long mLastStepStatUserTime; |
| 615 | long mLastStepStatSystemTime; |
| 616 | long mLastStepStatIOWaitTime; |
| 617 | long mLastStepStatIrqTime; |
| 618 | long mLastStepStatSoftIrqTime; |
| 619 | long mLastStepStatIdleTime; |
| 620 | long mCurStepStatUserTime; |
| 621 | long mCurStepStatSystemTime; |
| 622 | long mCurStepStatIOWaitTime; |
| 623 | long mCurStepStatIrqTime; |
| 624 | long mCurStepStatSoftIrqTime; |
| 625 | long mCurStepStatIdleTime; |
| 626 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 627 | private HistoryItem mHistoryIterator; |
| 628 | private boolean mReadOverflow; |
| 629 | private boolean mIteratingHistory; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 630 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 631 | int mStartCount; |
| 632 | |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 633 | long mStartClockTime; |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 634 | String mStartPlatformVersion; |
| 635 | String mEndPlatformVersion; |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 636 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 637 | long mUptime; |
| 638 | long mUptimeStart; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 639 | long mRealtime; |
| 640 | long mRealtimeStart; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 641 | |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 642 | int mWakeLockNesting; |
| 643 | boolean mWakeLockImportant; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 644 | public boolean mRecordAllHistory; |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 645 | boolean mNoAutoReset; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 646 | |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 647 | @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 648 | protected int mScreenState = Display.STATE_UNKNOWN; |
| 649 | @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 650 | protected StopwatchTimer mScreenOnTimer; |
| 651 | @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 652 | protected StopwatchTimer mScreenDozeTimer; |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 653 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 654 | int mScreenBrightnessBin = -1; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 655 | final StopwatchTimer[] mScreenBrightnessTimer = new StopwatchTimer[NUM_SCREEN_BRIGHTNESS_BINS]; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 656 | |
Amith Yamasani | 674c9bb | 2017-02-01 09:45:17 -0800 | [diff] [blame] | 657 | boolean mPretendScreenOff; |
| 658 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 659 | boolean mInteractive; |
| 660 | StopwatchTimer mInteractiveTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 661 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 662 | boolean mPowerSaveModeEnabled; |
| 663 | StopwatchTimer mPowerSaveModeEnabledTimer; |
| 664 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 665 | boolean mDeviceIdling; |
| 666 | StopwatchTimer mDeviceIdlingTimer; |
| 667 | |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 668 | boolean mDeviceLightIdling; |
| 669 | StopwatchTimer mDeviceLightIdlingTimer; |
| 670 | |
| 671 | int mDeviceIdleMode; |
| 672 | long mLastIdleTimeStart; |
| 673 | long mLongestLightIdleTime; |
| 674 | long mLongestFullIdleTime; |
| 675 | StopwatchTimer mDeviceIdleModeLightTimer; |
| 676 | StopwatchTimer mDeviceIdleModeFullTimer; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 677 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 678 | boolean mPhoneOn; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 679 | StopwatchTimer mPhoneOnTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 680 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 681 | int mAudioOnNesting; |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 682 | StopwatchTimer mAudioOnTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 683 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 684 | int mVideoOnNesting; |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 685 | StopwatchTimer mVideoOnTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 686 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 687 | int mFlashlightOnNesting; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 688 | StopwatchTimer mFlashlightOnTimer; |
| 689 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 690 | int mCameraOnNesting; |
| 691 | StopwatchTimer mCameraOnTimer; |
| 692 | |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 693 | int mGpsSignalQualityBin = -1; |
Narayan Kamath | efa0fe6 | 2018-02-05 16:04:43 +0000 | [diff] [blame] | 694 | @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 695 | protected final StopwatchTimer[] mGpsSignalQualityTimer = |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 696 | new StopwatchTimer[GnssMetrics.NUM_GPS_SIGNAL_QUALITY_LEVELS]; |
| 697 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 698 | int mPhoneSignalStrengthBin = -1; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 699 | int mPhoneSignalStrengthBinRaw = -1; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 700 | final StopwatchTimer[] mPhoneSignalStrengthsTimer = |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 701 | new StopwatchTimer[SignalStrength.NUM_SIGNAL_STRENGTH_BINS]; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 702 | |
| 703 | StopwatchTimer mPhoneSignalScanningTimer; |
| 704 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 705 | int mPhoneDataConnectionType = -1; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 706 | final StopwatchTimer[] mPhoneDataConnectionsTimer = |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 707 | new StopwatchTimer[NUM_DATA_CONNECTION_TYPES]; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 708 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 709 | final LongSamplingCounter[] mNetworkByteActivityCounters = |
| 710 | new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
| 711 | final LongSamplingCounter[] mNetworkPacketActivityCounters = |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 712 | new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
| 713 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 714 | /** |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 715 | * The WiFi Overall wakelock timer |
| 716 | * This timer tracks the actual aggregate time for which MC wakelocks are enabled |
| 717 | * since addition of per UID timers would not result in an accurate value due to overlapp of |
| 718 | * per uid wakelock timers |
| 719 | */ |
| 720 | StopwatchTimer mWifiMulticastWakelockTimer; |
| 721 | |
| 722 | /** |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 723 | * The WiFi controller activity (time in tx, rx, idle, and power consumed) for the device. |
| 724 | */ |
| 725 | ControllerActivityCounterImpl mWifiActivity; |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 726 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 727 | /** |
| 728 | * The Bluetooth controller activity (time in tx, rx, idle, and power consumed) for the device. |
| 729 | */ |
| 730 | ControllerActivityCounterImpl mBluetoothActivity; |
| 731 | |
| 732 | /** |
| 733 | * The Modem controller activity (time in tx, rx, idle, and power consumed) for the device. |
| 734 | */ |
| 735 | ControllerActivityCounterImpl mModemActivity; |
| 736 | |
| 737 | /** |
| 738 | * Whether the device supports WiFi controller energy reporting. This is set to true on |
| 739 | * the first WiFi energy report. See {@link #mWifiActivity}. |
| 740 | */ |
| 741 | boolean mHasWifiReporting = false; |
| 742 | |
| 743 | /** |
| 744 | * Whether the device supports Bluetooth controller energy reporting. This is set to true on |
| 745 | * the first Bluetooth energy report. See {@link #mBluetoothActivity}. |
| 746 | */ |
| 747 | boolean mHasBluetoothReporting = false; |
| 748 | |
| 749 | /** |
| 750 | * Whether the device supports Modem controller energy reporting. This is set to true on |
| 751 | * the first Modem energy report. See {@link #mModemActivity}. |
| 752 | */ |
| 753 | boolean mHasModemReporting = false; |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 754 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 755 | boolean mWifiOn; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 756 | StopwatchTimer mWifiOnTimer; |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 757 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 758 | boolean mGlobalWifiRunning; |
| 759 | StopwatchTimer mGlobalWifiRunningTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 760 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 761 | int mWifiState = -1; |
| 762 | final StopwatchTimer[] mWifiStateTimer = new StopwatchTimer[NUM_WIFI_STATES]; |
| 763 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 764 | int mWifiSupplState = -1; |
| 765 | final StopwatchTimer[] mWifiSupplStateTimer = new StopwatchTimer[NUM_WIFI_SUPPL_STATES]; |
| 766 | |
| 767 | int mWifiSignalStrengthBin = -1; |
| 768 | final StopwatchTimer[] mWifiSignalStrengthsTimer = |
| 769 | new StopwatchTimer[NUM_WIFI_SIGNAL_STRENGTH_BINS]; |
| 770 | |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 771 | StopwatchTimer mWifiActiveTimer; |
| 772 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 773 | int mBluetoothScanNesting; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 774 | @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 775 | protected StopwatchTimer mBluetoothScanTimer; |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 776 | |
Siddharth Ray | f5e796a | 2018-01-22 18:18:17 -0800 | [diff] [blame] | 777 | boolean mIsCellularTxPowerHigh = false; |
| 778 | |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 779 | int mMobileRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
Dianne Hackborn | f7097a5 | 2014-05-13 09:56:14 -0700 | [diff] [blame] | 780 | long mMobileRadioActiveStartTime; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 781 | StopwatchTimer mMobileRadioActiveTimer; |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 782 | StopwatchTimer mMobileRadioActivePerAppTimer; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 783 | LongSamplingCounter mMobileRadioActiveAdjustedTime; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 784 | LongSamplingCounter mMobileRadioActiveUnknownTime; |
| 785 | LongSamplingCounter mMobileRadioActiveUnknownCount; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 786 | |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 787 | int mWifiRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
| 788 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 789 | /** |
| 790 | * These provide time bases that discount the time the device is plugged |
| 791 | * in to power. |
| 792 | */ |
| 793 | boolean mOnBattery; |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 794 | @VisibleForTesting |
| 795 | protected boolean mOnBatteryInternal; |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 796 | |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 797 | /** |
| 798 | * External reporting of whether the device is actually charging. |
| 799 | */ |
| 800 | boolean mCharging = true; |
| 801 | int mLastChargingStateLevel; |
| 802 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 803 | /* |
| 804 | * These keep track of battery levels (1-100) at the last plug event and the last unplug event. |
| 805 | */ |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 806 | int mDischargeStartLevel; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 807 | int mDischargeUnplugLevel; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 808 | int mDischargePlugLevel; |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 809 | int mDischargeCurrentLevel; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 810 | int mCurrentBatteryLevel; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 811 | int mLowDischargeAmountSinceCharge; |
| 812 | int mHighDischargeAmountSinceCharge; |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 813 | int mDischargeScreenOnUnplugLevel; |
| 814 | int mDischargeScreenOffUnplugLevel; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 815 | int mDischargeScreenDozeUnplugLevel; |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 816 | int mDischargeAmountScreenOn; |
| 817 | int mDischargeAmountScreenOnSinceCharge; |
| 818 | int mDischargeAmountScreenOff; |
| 819 | int mDischargeAmountScreenOffSinceCharge; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 820 | int mDischargeAmountScreenDoze; |
| 821 | int mDischargeAmountScreenDozeSinceCharge; |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 822 | |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 823 | private LongSamplingCounter mDischargeScreenOffCounter; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 824 | private LongSamplingCounter mDischargeScreenDozeCounter; |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 825 | private LongSamplingCounter mDischargeCounter; |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 826 | private LongSamplingCounter mDischargeLightDozeCounter; |
| 827 | private LongSamplingCounter mDischargeDeepDozeCounter; |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 828 | |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 829 | static final int MAX_LEVEL_STEPS = 200; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 830 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 831 | int mInitStepMode = 0; |
| 832 | int mCurStepMode = 0; |
| 833 | int mModStepMode = 0; |
| 834 | |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 835 | int mLastDischargeStepLevel; |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 836 | int mMinDischargeStepLevel; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 837 | final LevelStepTracker mDischargeStepTracker = new LevelStepTracker(MAX_LEVEL_STEPS); |
| 838 | final LevelStepTracker mDailyDischargeStepTracker = new LevelStepTracker(MAX_LEVEL_STEPS*2); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 839 | ArrayList<PackageChange> mDailyPackageChanges; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 840 | |
| 841 | int mLastChargeStepLevel; |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 842 | int mMaxChargeStepLevel; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 843 | final LevelStepTracker mChargeStepTracker = new LevelStepTracker(MAX_LEVEL_STEPS); |
| 844 | final LevelStepTracker mDailyChargeStepTracker = new LevelStepTracker(MAX_LEVEL_STEPS*2); |
| 845 | |
| 846 | static final int MAX_DAILY_ITEMS = 10; |
| 847 | |
| 848 | long mDailyStartTime = 0; |
| 849 | long mNextMinDailyDeadline = 0; |
| 850 | long mNextMaxDailyDeadline = 0; |
| 851 | |
| 852 | final ArrayList<DailyItem> mDailyItems = new ArrayList<>(); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 853 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 854 | long mLastWriteTime = 0; // Milliseconds |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 855 | |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 856 | private int mPhoneServiceState = -1; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 857 | private int mPhoneServiceStateRaw = -1; |
| 858 | private int mPhoneSimStateRaw = -1; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 859 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 860 | private int mNumConnectivityChange; |
| 861 | private int mLoadedNumConnectivityChange; |
| 862 | private int mUnpluggedNumConnectivityChange; |
| 863 | |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 864 | private int mEstimatedBatteryCapacity = -1; |
| 865 | |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 866 | private int mMinLearnedBatteryCapacity = -1; |
| 867 | private int mMaxLearnedBatteryCapacity = -1; |
Adam Lesinski | 041d917 | 2016-12-12 12:03:56 -0800 | [diff] [blame] | 868 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 869 | private long[] mCpuFreqs; |
| 870 | |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 871 | @VisibleForTesting |
| 872 | protected PowerProfile mPowerProfile; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 873 | |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 874 | @GuardedBy("this") |
| 875 | private final Constants mConstants; |
| 876 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 877 | /* |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 878 | * Holds a SamplingTimer associated with each Resource Power Manager state and voter, |
| 879 | * recording their times when on-battery (regardless of screen state). |
| 880 | */ |
| 881 | private final HashMap<String, SamplingTimer> mRpmStats = new HashMap<>(); |
| 882 | /** Times for each Resource Power Manager state and voter when screen-off and on-battery. */ |
| 883 | private final HashMap<String, SamplingTimer> mScreenOffRpmStats = new HashMap<>(); |
| 884 | |
| 885 | @Override |
| 886 | public Map<String, ? extends Timer> getRpmStats() { |
| 887 | return mRpmStats; |
| 888 | } |
| 889 | |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 890 | // TODO: Note: screenOffRpmStats has been disabled via SCREEN_OFF_RPM_STATS_ENABLED. |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 891 | @Override |
| 892 | public Map<String, ? extends Timer> getScreenOffRpmStats() { |
| 893 | return mScreenOffRpmStats; |
| 894 | } |
| 895 | |
| 896 | /* |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 897 | * Holds a SamplingTimer associated with each kernel wakelock name being tracked. |
| 898 | */ |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 899 | private final HashMap<String, SamplingTimer> mKernelWakelockStats = new HashMap<>(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 900 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 901 | public Map<String, ? extends Timer> getKernelWakelockStats() { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 902 | return mKernelWakelockStats; |
| 903 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 904 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 905 | String mLastWakeupReason = null; |
| 906 | long mLastWakeupUptimeMs = 0; |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 907 | private final HashMap<String, SamplingTimer> mWakeupReasonStats = new HashMap<>(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 908 | |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 909 | public Map<String, ? extends Timer> getWakeupReasonStats() { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 910 | return mWakeupReasonStats; |
| 911 | } |
| 912 | |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 913 | @Override |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 914 | public long getUahDischarge(int which) { |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 915 | return mDischargeCounter.getCountLocked(which); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 916 | } |
| 917 | |
| 918 | @Override |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 919 | public long getUahDischargeScreenOff(int which) { |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 920 | return mDischargeScreenOffCounter.getCountLocked(which); |
| 921 | } |
| 922 | |
| 923 | @Override |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 924 | public long getUahDischargeScreenDoze(int which) { |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 925 | return mDischargeScreenDozeCounter.getCountLocked(which); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 926 | } |
| 927 | |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 928 | @Override |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 929 | public long getUahDischargeLightDoze(int which) { |
| 930 | return mDischargeLightDozeCounter.getCountLocked(which); |
| 931 | } |
| 932 | |
| 933 | @Override |
| 934 | public long getUahDischargeDeepDoze(int which) { |
| 935 | return mDischargeDeepDozeCounter.getCountLocked(which); |
| 936 | } |
| 937 | |
| 938 | @Override |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 939 | public int getEstimatedBatteryCapacity() { |
| 940 | return mEstimatedBatteryCapacity; |
| 941 | } |
| 942 | |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 943 | @Override |
| 944 | public int getMinLearnedBatteryCapacity() { |
| 945 | return mMinLearnedBatteryCapacity; |
| 946 | } |
| 947 | |
| 948 | @Override |
| 949 | public int getMaxLearnedBatteryCapacity() { |
| 950 | return mMaxLearnedBatteryCapacity; |
| 951 | } |
| 952 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 953 | public BatteryStatsImpl() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 954 | this(new SystemClocks()); |
| 955 | } |
| 956 | |
| 957 | public BatteryStatsImpl(Clocks clocks) { |
| 958 | init(clocks); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 959 | mFile = null; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 960 | mCheckinFile = null; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 961 | mDailyFile = null; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 962 | mHandler = null; |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 963 | mPlatformIdleStateCallback = null; |
Suprabh Shukla | e6e723d | 2017-06-14 16:14:43 -0700 | [diff] [blame] | 964 | mUserInfoProvider = null; |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 965 | mConstants = new Constants(mHandler); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 966 | clearHistoryLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 967 | } |
| 968 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 969 | private void init(Clocks clocks) { |
| 970 | mClocks = clocks; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 971 | } |
| 972 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 973 | public interface TimeBaseObs { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 974 | void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime); |
| 975 | void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime); |
| 976 | } |
| 977 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 978 | // methods are protected not private to be VisibleForTesting |
| 979 | public static class TimeBase { |
| 980 | protected final ArrayList<TimeBaseObs> mObservers = new ArrayList<>(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 981 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 982 | protected long mUptime; |
| 983 | protected long mRealtime; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 984 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 985 | protected boolean mRunning; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 986 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 987 | protected long mPastUptime; |
| 988 | protected long mUptimeStart; |
| 989 | protected long mPastRealtime; |
| 990 | protected long mRealtimeStart; |
| 991 | protected long mUnpluggedUptime; |
| 992 | protected long mUnpluggedRealtime; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 993 | |
| 994 | public void dump(PrintWriter pw, String prefix) { |
| 995 | StringBuilder sb = new StringBuilder(128); |
| 996 | pw.print(prefix); pw.print("mRunning="); pw.println(mRunning); |
| 997 | sb.setLength(0); |
| 998 | sb.append(prefix); |
| 999 | sb.append("mUptime="); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 1000 | formatTimeMs(sb, mUptime / 1000); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1001 | pw.println(sb.toString()); |
| 1002 | sb.setLength(0); |
| 1003 | sb.append(prefix); |
| 1004 | sb.append("mRealtime="); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 1005 | formatTimeMs(sb, mRealtime / 1000); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1006 | pw.println(sb.toString()); |
| 1007 | sb.setLength(0); |
| 1008 | sb.append(prefix); |
| 1009 | sb.append("mPastUptime="); |
| 1010 | formatTimeMs(sb, mPastUptime / 1000); sb.append("mUptimeStart="); |
| 1011 | formatTimeMs(sb, mUptimeStart / 1000); |
| 1012 | sb.append("mUnpluggedUptime="); formatTimeMs(sb, mUnpluggedUptime / 1000); |
| 1013 | pw.println(sb.toString()); |
| 1014 | sb.setLength(0); |
| 1015 | sb.append(prefix); |
| 1016 | sb.append("mPastRealtime="); |
| 1017 | formatTimeMs(sb, mPastRealtime / 1000); sb.append("mRealtimeStart="); |
| 1018 | formatTimeMs(sb, mRealtimeStart / 1000); |
| 1019 | sb.append("mUnpluggedRealtime="); formatTimeMs(sb, mUnpluggedRealtime / 1000); |
| 1020 | pw.println(sb.toString()); |
| 1021 | } |
| 1022 | |
| 1023 | public void add(TimeBaseObs observer) { |
| 1024 | mObservers.add(observer); |
| 1025 | } |
| 1026 | |
| 1027 | public void remove(TimeBaseObs observer) { |
| 1028 | if (!mObservers.remove(observer)) { |
| 1029 | Slog.wtf(TAG, "Removed unknown observer: " + observer); |
| 1030 | } |
| 1031 | } |
| 1032 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1033 | public boolean hasObserver(TimeBaseObs observer) { |
| 1034 | return mObservers.contains(observer); |
| 1035 | } |
| 1036 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1037 | public void init(long uptime, long realtime) { |
| 1038 | mRealtime = 0; |
| 1039 | mUptime = 0; |
| 1040 | mPastUptime = 0; |
| 1041 | mPastRealtime = 0; |
| 1042 | mUptimeStart = uptime; |
| 1043 | mRealtimeStart = realtime; |
| 1044 | mUnpluggedUptime = getUptime(mUptimeStart); |
| 1045 | mUnpluggedRealtime = getRealtime(mRealtimeStart); |
| 1046 | } |
| 1047 | |
| 1048 | public void reset(long uptime, long realtime) { |
| 1049 | if (!mRunning) { |
| 1050 | mPastUptime = 0; |
| 1051 | mPastRealtime = 0; |
| 1052 | } else { |
| 1053 | mUptimeStart = uptime; |
| 1054 | mRealtimeStart = realtime; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1055 | // TODO: Since mUptimeStart was just reset and we are running, getUptime will |
| 1056 | // 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] | 1057 | mUnpluggedUptime = getUptime(uptime); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1058 | // TODO: likewise. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1059 | mUnpluggedRealtime = getRealtime(realtime); |
| 1060 | } |
| 1061 | } |
| 1062 | |
| 1063 | public long computeUptime(long curTime, int which) { |
| 1064 | switch (which) { |
| 1065 | case STATS_SINCE_CHARGED: |
| 1066 | return mUptime + getUptime(curTime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1067 | case STATS_CURRENT: |
| 1068 | return getUptime(curTime); |
| 1069 | case STATS_SINCE_UNPLUGGED: |
| 1070 | return getUptime(curTime) - mUnpluggedUptime; |
| 1071 | } |
| 1072 | return 0; |
| 1073 | } |
| 1074 | |
| 1075 | public long computeRealtime(long curTime, int which) { |
| 1076 | switch (which) { |
| 1077 | case STATS_SINCE_CHARGED: |
| 1078 | return mRealtime + getRealtime(curTime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1079 | case STATS_CURRENT: |
| 1080 | return getRealtime(curTime); |
| 1081 | case STATS_SINCE_UNPLUGGED: |
| 1082 | return getRealtime(curTime) - mUnpluggedRealtime; |
| 1083 | } |
| 1084 | return 0; |
| 1085 | } |
| 1086 | |
| 1087 | public long getUptime(long curTime) { |
| 1088 | long time = mPastUptime; |
| 1089 | if (mRunning) { |
| 1090 | time += curTime - mUptimeStart; |
| 1091 | } |
| 1092 | return time; |
| 1093 | } |
| 1094 | |
| 1095 | public long getRealtime(long curTime) { |
| 1096 | long time = mPastRealtime; |
| 1097 | if (mRunning) { |
| 1098 | time += curTime - mRealtimeStart; |
| 1099 | } |
| 1100 | return time; |
| 1101 | } |
| 1102 | |
| 1103 | public long getUptimeStart() { |
| 1104 | return mUptimeStart; |
| 1105 | } |
| 1106 | |
| 1107 | public long getRealtimeStart() { |
| 1108 | return mRealtimeStart; |
| 1109 | } |
| 1110 | |
| 1111 | public boolean isRunning() { |
| 1112 | return mRunning; |
| 1113 | } |
| 1114 | |
| 1115 | public boolean setRunning(boolean running, long uptime, long realtime) { |
| 1116 | if (mRunning != running) { |
| 1117 | mRunning = running; |
| 1118 | if (running) { |
| 1119 | mUptimeStart = uptime; |
| 1120 | mRealtimeStart = realtime; |
| 1121 | long batteryUptime = mUnpluggedUptime = getUptime(uptime); |
| 1122 | long batteryRealtime = mUnpluggedRealtime = getRealtime(realtime); |
| 1123 | |
| 1124 | for (int i = mObservers.size() - 1; i >= 0; i--) { |
| 1125 | mObservers.get(i).onTimeStarted(realtime, batteryUptime, batteryRealtime); |
| 1126 | } |
| 1127 | } else { |
| 1128 | mPastUptime += uptime - mUptimeStart; |
| 1129 | mPastRealtime += realtime - mRealtimeStart; |
| 1130 | |
| 1131 | long batteryUptime = getUptime(uptime); |
| 1132 | long batteryRealtime = getRealtime(realtime); |
| 1133 | |
| 1134 | for (int i = mObservers.size() - 1; i >= 0; i--) { |
| 1135 | mObservers.get(i).onTimeStopped(realtime, batteryUptime, batteryRealtime); |
| 1136 | } |
| 1137 | } |
| 1138 | return true; |
| 1139 | } |
| 1140 | return false; |
| 1141 | } |
| 1142 | |
| 1143 | public void readSummaryFromParcel(Parcel in) { |
| 1144 | mUptime = in.readLong(); |
| 1145 | mRealtime = in.readLong(); |
| 1146 | } |
| 1147 | |
| 1148 | public void writeSummaryToParcel(Parcel out, long uptime, long realtime) { |
| 1149 | out.writeLong(computeUptime(uptime, STATS_SINCE_CHARGED)); |
| 1150 | out.writeLong(computeRealtime(realtime, STATS_SINCE_CHARGED)); |
| 1151 | } |
| 1152 | |
| 1153 | public void readFromParcel(Parcel in) { |
| 1154 | mRunning = false; |
| 1155 | mUptime = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1156 | mPastUptime = in.readLong(); |
| 1157 | mUptimeStart = in.readLong(); |
Dianne Hackborn | ef640cd | 2014-03-25 14:41:05 -0700 | [diff] [blame] | 1158 | mRealtime = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1159 | mPastRealtime = in.readLong(); |
| 1160 | mRealtimeStart = in.readLong(); |
| 1161 | mUnpluggedUptime = in.readLong(); |
| 1162 | mUnpluggedRealtime = in.readLong(); |
| 1163 | } |
| 1164 | |
| 1165 | public void writeToParcel(Parcel out, long uptime, long realtime) { |
| 1166 | final long runningUptime = getUptime(uptime); |
| 1167 | final long runningRealtime = getRealtime(realtime); |
| 1168 | out.writeLong(mUptime); |
| 1169 | out.writeLong(runningUptime); |
| 1170 | out.writeLong(mUptimeStart); |
Dianne Hackborn | ef640cd | 2014-03-25 14:41:05 -0700 | [diff] [blame] | 1171 | out.writeLong(mRealtime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1172 | out.writeLong(runningRealtime); |
| 1173 | out.writeLong(mRealtimeStart); |
| 1174 | out.writeLong(mUnpluggedUptime); |
| 1175 | out.writeLong(mUnpluggedRealtime); |
| 1176 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1177 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1178 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1179 | /** |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1180 | * State for keeping track of counting information. |
| 1181 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1182 | public static class Counter extends BatteryStats.Counter implements TimeBaseObs { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 1183 | final AtomicInteger mCount = new AtomicInteger(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1184 | final TimeBase mTimeBase; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1185 | int mLoadedCount; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1186 | int mUnpluggedCount; |
| 1187 | int mPluggedCount; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1188 | |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 1189 | public Counter(TimeBase timeBase, Parcel in) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1190 | mTimeBase = timeBase; |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 1191 | mPluggedCount = in.readInt(); |
| 1192 | mCount.set(mPluggedCount); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1193 | mLoadedCount = in.readInt(); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1194 | mUnpluggedCount = in.readInt(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1195 | timeBase.add(this); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1196 | } |
| 1197 | |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 1198 | public Counter(TimeBase timeBase) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1199 | mTimeBase = timeBase; |
| 1200 | timeBase.add(this); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1201 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1202 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1203 | public void writeToParcel(Parcel out) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 1204 | out.writeInt(mCount.get()); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1205 | out.writeInt(mLoadedCount); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1206 | out.writeInt(mUnpluggedCount); |
| 1207 | } |
| 1208 | |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 1209 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1210 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 1211 | mUnpluggedCount = mPluggedCount; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1212 | } |
| 1213 | |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 1214 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1215 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 1216 | mPluggedCount = mCount.get(); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1217 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1218 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1219 | /** |
| 1220 | * Writes a possibly null Counter to a Parcel. |
| 1221 | * |
| 1222 | * @param out the Parcel to be written to. |
| 1223 | * @param counter a Counter, or null. |
| 1224 | */ |
Amith Yamasani | 977e11f | 2018-02-16 11:29:54 -0800 | [diff] [blame] | 1225 | public static void writeCounterToParcel(Parcel out, @Nullable Counter counter) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1226 | if (counter == null) { |
| 1227 | out.writeInt(0); // indicates null |
| 1228 | return; |
| 1229 | } |
| 1230 | out.writeInt(1); // indicates non-null |
| 1231 | |
| 1232 | counter.writeToParcel(out); |
| 1233 | } |
| 1234 | |
Amith Yamasani | 977e11f | 2018-02-16 11:29:54 -0800 | [diff] [blame] | 1235 | /** |
| 1236 | * Reads a Counter that was written using {@link #writeCounterToParcel(Parcel, Counter)}. |
| 1237 | * @param timeBase the timebase to assign to the Counter |
| 1238 | * @param in the parcel to read from |
| 1239 | * @return the Counter or null. |
| 1240 | */ |
| 1241 | public static @Nullable Counter readCounterFromParcel(TimeBase timeBase, Parcel in) { |
| 1242 | if (in.readInt() == 0) { |
| 1243 | return null; |
| 1244 | } |
| 1245 | return new Counter(timeBase, in); |
| 1246 | } |
| 1247 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1248 | @Override |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1249 | public int getCountLocked(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 1250 | int val = mCount.get(); |
| 1251 | if (which == STATS_SINCE_UNPLUGGED) { |
| 1252 | val -= mUnpluggedCount; |
| 1253 | } else if (which != STATS_SINCE_CHARGED) { |
| 1254 | val -= mLoadedCount; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1255 | } |
| 1256 | |
| 1257 | return val; |
| 1258 | } |
| 1259 | |
| 1260 | public void logState(Printer pw, String prefix) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 1261 | pw.println(prefix + "mCount=" + mCount.get() |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 1262 | + " mLoadedCount=" + mLoadedCount |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1263 | + " mUnpluggedCount=" + mUnpluggedCount |
| 1264 | + " mPluggedCount=" + mPluggedCount); |
| 1265 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1266 | |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 1267 | @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 1268 | public void stepAtomic() { |
| 1269 | if (mTimeBase.isRunning()) { |
| 1270 | mCount.incrementAndGet(); |
| 1271 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1272 | } |
| 1273 | |
Bookatz | 4ebc064 | 2017-05-11 12:21:19 -0700 | [diff] [blame] | 1274 | void addAtomic(int delta) { |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 1275 | if (mTimeBase.isRunning()) { |
| 1276 | mCount.addAndGet(delta); |
| 1277 | } |
Bookatz | 4ebc064 | 2017-05-11 12:21:19 -0700 | [diff] [blame] | 1278 | } |
| 1279 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1280 | /** |
| 1281 | * Clear state of this counter. |
| 1282 | */ |
| 1283 | void reset(boolean detachIfReset) { |
| 1284 | mCount.set(0); |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 1285 | mLoadedCount = mPluggedCount = mUnpluggedCount = 0; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1286 | if (detachIfReset) { |
| 1287 | detach(); |
| 1288 | } |
| 1289 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1290 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1291 | void detach() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1292 | mTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1293 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1294 | |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 1295 | @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 1296 | public void writeSummaryFromParcelLocked(Parcel out) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 1297 | int count = mCount.get(); |
| 1298 | out.writeInt(count); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1299 | } |
| 1300 | |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 1301 | @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 1302 | public void readSummaryFromParcelLocked(Parcel in) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 1303 | mLoadedCount = in.readInt(); |
| 1304 | mCount.set(mLoadedCount); |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 1305 | mUnpluggedCount = mPluggedCount = mLoadedCount; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1306 | } |
| 1307 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 1308 | |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 1309 | @VisibleForTesting |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1310 | public static class LongSamplingCounterArray extends LongCounterArray implements TimeBaseObs { |
| 1311 | final TimeBase mTimeBase; |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 1312 | public long[] mCounts; |
| 1313 | public long[] mLoadedCounts; |
| 1314 | public long[] mUnpluggedCounts; |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1315 | |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 1316 | private LongSamplingCounterArray(TimeBase timeBase, Parcel in) { |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1317 | mTimeBase = timeBase; |
Sudheer Shanka | e544d16 | 2017-12-28 17:06:20 -0800 | [diff] [blame] | 1318 | mCounts = in.createLongArray(); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1319 | mLoadedCounts = in.createLongArray(); |
| 1320 | mUnpluggedCounts = in.createLongArray(); |
| 1321 | timeBase.add(this); |
| 1322 | } |
| 1323 | |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 1324 | public LongSamplingCounterArray(TimeBase timeBase) { |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1325 | mTimeBase = timeBase; |
| 1326 | timeBase.add(this); |
| 1327 | } |
| 1328 | |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 1329 | private void writeToParcel(Parcel out) { |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1330 | out.writeLongArray(mCounts); |
| 1331 | out.writeLongArray(mLoadedCounts); |
| 1332 | out.writeLongArray(mUnpluggedCounts); |
| 1333 | } |
| 1334 | |
| 1335 | @Override |
| 1336 | public void onTimeStarted(long elapsedRealTime, long baseUptime, long baseRealtime) { |
Sudheer Shanka | e544d16 | 2017-12-28 17:06:20 -0800 | [diff] [blame] | 1337 | mUnpluggedCounts = copyArray(mCounts, mUnpluggedCounts); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1338 | } |
| 1339 | |
| 1340 | @Override |
| 1341 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1342 | } |
| 1343 | |
| 1344 | @Override |
| 1345 | public long[] getCountsLocked(int which) { |
Sudheer Shanka | e544d16 | 2017-12-28 17:06:20 -0800 | [diff] [blame] | 1346 | long[] val = copyArray(mCounts, null); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1347 | if (which == STATS_SINCE_UNPLUGGED) { |
| 1348 | subtract(val, mUnpluggedCounts); |
| 1349 | } else if (which != STATS_SINCE_CHARGED) { |
| 1350 | subtract(val, mLoadedCounts); |
| 1351 | } |
| 1352 | return val; |
| 1353 | } |
| 1354 | |
| 1355 | @Override |
| 1356 | public void logState(Printer pw, String prefix) { |
| 1357 | pw.println(prefix + "mCounts=" + Arrays.toString(mCounts) |
| 1358 | + " mLoadedCounts=" + Arrays.toString(mLoadedCounts) |
Sudheer Shanka | e544d16 | 2017-12-28 17:06:20 -0800 | [diff] [blame] | 1359 | + " mUnpluggedCounts=" + Arrays.toString(mUnpluggedCounts)); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1360 | } |
| 1361 | |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 1362 | public void addCountLocked(long[] counts) { |
Sudheer Shanka | e544d16 | 2017-12-28 17:06:20 -0800 | [diff] [blame] | 1363 | addCountLocked(counts, mTimeBase.isRunning()); |
| 1364 | } |
| 1365 | |
| 1366 | public void addCountLocked(long[] counts, boolean isRunning) { |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1367 | if (counts == null) { |
| 1368 | return; |
| 1369 | } |
Sudheer Shanka | e544d16 | 2017-12-28 17:06:20 -0800 | [diff] [blame] | 1370 | if (isRunning) { |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 1371 | if (mCounts == null) { |
| 1372 | mCounts = new long[counts.length]; |
| 1373 | } |
| 1374 | for (int i = 0; i < counts.length; ++i) { |
| 1375 | mCounts[i] += counts[i]; |
| 1376 | } |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1377 | } |
| 1378 | } |
| 1379 | |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 1380 | public int getSize() { |
| 1381 | return mCounts == null ? 0 : mCounts.length; |
| 1382 | } |
| 1383 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1384 | /** |
| 1385 | * Clear state of this counter. |
| 1386 | */ |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 1387 | public void reset(boolean detachIfReset) { |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1388 | fillArray(mCounts, 0); |
| 1389 | fillArray(mLoadedCounts, 0); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1390 | fillArray(mUnpluggedCounts, 0); |
| 1391 | if (detachIfReset) { |
| 1392 | detach(); |
| 1393 | } |
| 1394 | } |
| 1395 | |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 1396 | public void detach() { |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1397 | mTimeBase.remove(this); |
| 1398 | } |
| 1399 | |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 1400 | private void writeSummaryToParcelLocked(Parcel out) { |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1401 | out.writeLongArray(mCounts); |
| 1402 | } |
| 1403 | |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 1404 | private void readSummaryFromParcelLocked(Parcel in) { |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1405 | mCounts = in.createLongArray(); |
| 1406 | mLoadedCounts = copyArray(mCounts, mLoadedCounts); |
| 1407 | mUnpluggedCounts = copyArray(mCounts, mUnpluggedCounts); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1408 | } |
| 1409 | |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 1410 | public static void writeToParcel(Parcel out, LongSamplingCounterArray counterArray) { |
| 1411 | if (counterArray != null) { |
| 1412 | out.writeInt(1); |
| 1413 | counterArray.writeToParcel(out); |
| 1414 | } else { |
| 1415 | out.writeInt(0); |
| 1416 | } |
| 1417 | } |
| 1418 | |
| 1419 | public static LongSamplingCounterArray readFromParcel(Parcel in, TimeBase timeBase) { |
| 1420 | if (in.readInt() != 0) { |
| 1421 | return new LongSamplingCounterArray(timeBase, in); |
| 1422 | } else { |
| 1423 | return null; |
| 1424 | } |
| 1425 | } |
| 1426 | |
| 1427 | public static void writeSummaryToParcelLocked(Parcel out, |
| 1428 | LongSamplingCounterArray counterArray) { |
| 1429 | if (counterArray != null) { |
| 1430 | out.writeInt(1); |
| 1431 | counterArray.writeSummaryToParcelLocked(out); |
| 1432 | } else { |
| 1433 | out.writeInt(0); |
| 1434 | } |
| 1435 | } |
| 1436 | |
| 1437 | public static LongSamplingCounterArray readSummaryFromParcelLocked(Parcel in, |
| 1438 | TimeBase timeBase) { |
| 1439 | if (in.readInt() != 0) { |
| 1440 | final LongSamplingCounterArray counterArray |
| 1441 | = new LongSamplingCounterArray(timeBase); |
| 1442 | counterArray.readSummaryFromParcelLocked(in); |
| 1443 | return counterArray; |
| 1444 | } else { |
| 1445 | return null; |
| 1446 | } |
| 1447 | } |
| 1448 | |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 1449 | private static void fillArray(long[] a, long val) { |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1450 | if (a != null) { |
| 1451 | Arrays.fill(a, val); |
| 1452 | } |
| 1453 | } |
| 1454 | |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 1455 | private static void subtract(@NonNull long[] val, long[] toSubtract) { |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1456 | if (toSubtract == null) { |
| 1457 | return; |
| 1458 | } |
| 1459 | for (int i = 0; i < val.length; i++) { |
| 1460 | val[i] -= toSubtract[i]; |
| 1461 | } |
| 1462 | } |
| 1463 | |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 1464 | private static long[] copyArray(long[] src, long[] dest) { |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1465 | if (src == null) { |
| 1466 | return null; |
| 1467 | } else { |
| 1468 | if (dest == null) { |
| 1469 | dest = new long[src.length]; |
| 1470 | } |
| 1471 | System.arraycopy(src, 0, dest, 0, src.length); |
| 1472 | return dest; |
| 1473 | } |
| 1474 | } |
| 1475 | } |
| 1476 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1477 | public static class LongSamplingCounter extends LongCounter implements TimeBaseObs { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1478 | final TimeBase mTimeBase; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1479 | long mCount; |
| 1480 | long mLoadedCount; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1481 | long mUnpluggedCount; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1482 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1483 | LongSamplingCounter(TimeBase timeBase, Parcel in) { |
| 1484 | mTimeBase = timeBase; |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 1485 | mCount = in.readLong(); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1486 | mLoadedCount = in.readLong(); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1487 | mUnpluggedCount = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1488 | timeBase.add(this); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1489 | } |
| 1490 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1491 | LongSamplingCounter(TimeBase timeBase) { |
| 1492 | mTimeBase = timeBase; |
| 1493 | timeBase.add(this); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1494 | } |
| 1495 | |
| 1496 | public void writeToParcel(Parcel out) { |
| 1497 | out.writeLong(mCount); |
| 1498 | out.writeLong(mLoadedCount); |
| 1499 | out.writeLong(mUnpluggedCount); |
| 1500 | } |
| 1501 | |
| 1502 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1503 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 1504 | mUnpluggedCount = mCount; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1505 | } |
| 1506 | |
| 1507 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1508 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1509 | } |
| 1510 | |
| 1511 | public long getCountLocked(int which) { |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 1512 | long val = mCount; |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 1513 | if (which == STATS_SINCE_UNPLUGGED) { |
| 1514 | val -= mUnpluggedCount; |
| 1515 | } else if (which != STATS_SINCE_CHARGED) { |
| 1516 | val -= mLoadedCount; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1517 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1518 | return val; |
| 1519 | } |
| 1520 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1521 | @Override |
| 1522 | public void logState(Printer pw, String prefix) { |
| 1523 | pw.println(prefix + "mCount=" + mCount |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 1524 | + " mLoadedCount=" + mLoadedCount |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 1525 | + " mUnpluggedCount=" + mUnpluggedCount); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1526 | } |
| 1527 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1528 | void addCountLocked(long count) { |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 1529 | addCountLocked(count, mTimeBase.isRunning()); |
| 1530 | } |
| 1531 | |
| 1532 | void addCountLocked(long count, boolean isRunning) { |
| 1533 | if (isRunning) { |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 1534 | mCount += count; |
| 1535 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1536 | } |
| 1537 | |
| 1538 | /** |
| 1539 | * Clear state of this counter. |
| 1540 | */ |
| 1541 | void reset(boolean detachIfReset) { |
| 1542 | mCount = 0; |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 1543 | mLoadedCount = mUnpluggedCount = 0; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1544 | if (detachIfReset) { |
| 1545 | detach(); |
| 1546 | } |
| 1547 | } |
| 1548 | |
| 1549 | void detach() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1550 | mTimeBase.remove(this); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1551 | } |
| 1552 | |
| 1553 | void writeSummaryFromParcelLocked(Parcel out) { |
| 1554 | out.writeLong(mCount); |
| 1555 | } |
| 1556 | |
| 1557 | void readSummaryFromParcelLocked(Parcel in) { |
| 1558 | mLoadedCount = in.readLong(); |
| 1559 | mCount = mLoadedCount; |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 1560 | mUnpluggedCount = mLoadedCount; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1561 | } |
| 1562 | } |
| 1563 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1564 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1565 | * State for keeping track of timing information. |
| 1566 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1567 | public static abstract class Timer extends BatteryStats.Timer implements TimeBaseObs { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1568 | protected final Clocks mClocks; |
| 1569 | protected final int mType; |
| 1570 | protected final TimeBase mTimeBase; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1571 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1572 | protected int mCount; |
| 1573 | protected int mLoadedCount; |
| 1574 | protected int mLastCount; |
| 1575 | protected int mUnpluggedCount; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1576 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1577 | // Times are in microseconds for better accuracy when dividing by the |
| 1578 | // lock count, and are in "battery realtime" units. |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1579 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1580 | /** |
| 1581 | * The total time we have accumulated since the start of the original |
| 1582 | * boot, to the last time something interesting happened in the |
| 1583 | * current run. |
| 1584 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1585 | protected long mTotalTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1586 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1587 | /** |
| 1588 | * The total time we loaded for the previous runs. Subtract this from |
| 1589 | * mTotalTime to find the time for the current run of the system. |
| 1590 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1591 | protected long mLoadedTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1592 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1593 | /** |
| 1594 | * The run time of the last run of the system, as loaded from the |
| 1595 | * saved data. |
| 1596 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1597 | protected long mLastTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1598 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1599 | /** |
| 1600 | * The value of mTotalTime when unplug() was last called. Subtract |
| 1601 | * this from mTotalTime to find the time since the last unplug from |
| 1602 | * power. |
| 1603 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1604 | protected long mUnpluggedTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1605 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 1606 | /** |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1607 | * The total time this timer has been running until the latest mark has been set. |
| 1608 | * Subtract this from mTotalTime to get the time spent running since the mark was set. |
| 1609 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1610 | protected long mTimeBeforeMark; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1611 | |
| 1612 | /** |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 1613 | * Constructs from a parcel. |
| 1614 | * @param type |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1615 | * @param timeBase |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 1616 | * @param in |
| 1617 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1618 | public Timer(Clocks clocks, int type, TimeBase timeBase, Parcel in) { |
| 1619 | mClocks = clocks; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1620 | mType = type; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1621 | mTimeBase = timeBase; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1622 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1623 | mCount = in.readInt(); |
| 1624 | mLoadedCount = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1625 | mLastCount = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1626 | mUnpluggedCount = in.readInt(); |
| 1627 | mTotalTime = in.readLong(); |
| 1628 | mLoadedTime = in.readLong(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1629 | mLastTime = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1630 | mUnpluggedTime = in.readLong(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1631 | mTimeBeforeMark = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1632 | timeBase.add(this); |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 1633 | 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] | 1634 | } |
| 1635 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1636 | public Timer(Clocks clocks, int type, TimeBase timeBase) { |
| 1637 | mClocks = clocks; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1638 | mType = type; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1639 | mTimeBase = timeBase; |
| 1640 | timeBase.add(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1641 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1642 | |
| 1643 | protected abstract long computeRunTimeLocked(long curBatteryRealtime); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1644 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1645 | protected abstract int computeCurrentCountLocked(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1646 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1647 | /** |
| 1648 | * Clear state of this timer. Returns true if the timer is inactive |
| 1649 | * so can be completely dropped. |
| 1650 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1651 | public boolean reset(boolean detachIfReset) { |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1652 | mTotalTime = mLoadedTime = mLastTime = mTimeBeforeMark = 0; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1653 | mCount = mLoadedCount = mLastCount = 0; |
| 1654 | if (detachIfReset) { |
| 1655 | detach(); |
| 1656 | } |
| 1657 | return true; |
| 1658 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1659 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1660 | public void detach() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1661 | mTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1662 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1663 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1664 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 1665 | if (DEBUG) Log.i(TAG, "**** WRITING TIMER #" + mType + ": mTotalTime=" |
| 1666 | + computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs))); |
Adam Lesinski | 98f0d46 | 2016-04-19 16:46:20 -0700 | [diff] [blame] | 1667 | out.writeInt(computeCurrentCountLocked()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1668 | out.writeInt(mLoadedCount); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1669 | out.writeInt(mUnpluggedCount); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1670 | out.writeLong(computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs))); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1671 | out.writeLong(mLoadedTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1672 | out.writeLong(mUnpluggedTime); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1673 | out.writeLong(mTimeBeforeMark); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1674 | } |
| 1675 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1676 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1677 | public void onTimeStarted(long elapsedRealtime, long timeBaseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1678 | if (DEBUG && mType < 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1679 | Log.v(TAG, "unplug #" + mType + ": realtime=" + baseRealtime |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1680 | + " old mUnpluggedTime=" + mUnpluggedTime |
| 1681 | + " old mUnpluggedCount=" + mUnpluggedCount); |
| 1682 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1683 | mUnpluggedTime = computeRunTimeLocked(baseRealtime); |
Adam Lesinski | 98f0d46 | 2016-04-19 16:46:20 -0700 | [diff] [blame] | 1684 | mUnpluggedCount = computeCurrentCountLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1685 | if (DEBUG && mType < 0) { |
| 1686 | Log.v(TAG, "unplug #" + mType |
| 1687 | + ": new mUnpluggedTime=" + mUnpluggedTime |
| 1688 | + " new mUnpluggedCount=" + mUnpluggedCount); |
| 1689 | } |
| 1690 | } |
| 1691 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1692 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1693 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1694 | if (DEBUG && mType < 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1695 | Log.v(TAG, "plug #" + mType + ": realtime=" + baseRealtime |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1696 | + " old mTotalTime=" + mTotalTime); |
| 1697 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1698 | mTotalTime = computeRunTimeLocked(baseRealtime); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1699 | mCount = computeCurrentCountLocked(); |
| 1700 | if (DEBUG && mType < 0) { |
| 1701 | Log.v(TAG, "plug #" + mType |
| 1702 | + ": new mTotalTime=" + mTotalTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1703 | } |
| 1704 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1705 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1706 | /** |
| 1707 | * Writes a possibly null Timer to a Parcel. |
| 1708 | * |
| 1709 | * @param out the Parcel to be written to. |
| 1710 | * @param timer a Timer, or null. |
| 1711 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1712 | 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] | 1713 | if (timer == null) { |
| 1714 | out.writeInt(0); // indicates null |
| 1715 | return; |
| 1716 | } |
| 1717 | out.writeInt(1); // indicates non-null |
| 1718 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1719 | timer.writeToParcel(out, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1720 | } |
| 1721 | |
| 1722 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1723 | public long getTotalTimeLocked(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 1724 | long val = computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs)); |
| 1725 | if (which == STATS_SINCE_UNPLUGGED) { |
| 1726 | val -= mUnpluggedTime; |
| 1727 | } else if (which != STATS_SINCE_CHARGED) { |
| 1728 | val -= mLoadedTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1729 | } |
| 1730 | |
| 1731 | return val; |
| 1732 | } |
| 1733 | |
| 1734 | @Override |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1735 | public int getCountLocked(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 1736 | int val = computeCurrentCountLocked(); |
| 1737 | if (which == STATS_SINCE_UNPLUGGED) { |
| 1738 | val -= mUnpluggedCount; |
| 1739 | } else if (which != STATS_SINCE_CHARGED) { |
| 1740 | val -= mLoadedCount; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1741 | } |
| 1742 | |
| 1743 | return val; |
| 1744 | } |
| 1745 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1746 | @Override |
| 1747 | public long getTimeSinceMarkLocked(long elapsedRealtimeUs) { |
| 1748 | long val = computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs)); |
| 1749 | return val - mTimeBeforeMark; |
| 1750 | } |
| 1751 | |
| 1752 | @Override |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1753 | public void logState(Printer pw, String prefix) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 1754 | pw.println(prefix + "mCount=" + mCount |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1755 | + " mLoadedCount=" + mLoadedCount + " mLastCount=" + mLastCount |
| 1756 | + " mUnpluggedCount=" + mUnpluggedCount); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1757 | pw.println(prefix + "mTotalTime=" + mTotalTime |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1758 | + " mLoadedTime=" + mLoadedTime); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1759 | pw.println(prefix + "mLastTime=" + mLastTime |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1760 | + " mUnpluggedTime=" + mUnpluggedTime); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1761 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1762 | |
| 1763 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1764 | public void writeSummaryFromParcelLocked(Parcel out, long elapsedRealtimeUs) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1765 | long runTime = computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs)); |
| 1766 | out.writeLong(runTime); |
Adam Lesinski | 98f0d46 | 2016-04-19 16:46:20 -0700 | [diff] [blame] | 1767 | out.writeInt(computeCurrentCountLocked()); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1768 | } |
| 1769 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1770 | public void readSummaryFromParcelLocked(Parcel in) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1771 | // Multiply by 1000 for backwards compatibility |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1772 | mTotalTime = mLoadedTime = in.readLong(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1773 | mLastTime = 0; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1774 | mUnpluggedTime = mTotalTime; |
| 1775 | mCount = mLoadedCount = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1776 | mLastCount = 0; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1777 | mUnpluggedCount = mCount; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1778 | |
| 1779 | // When reading the summary, we set the mark to be the latest information. |
| 1780 | mTimeBeforeMark = mTotalTime; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1781 | } |
| 1782 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1783 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1784 | /** |
| 1785 | * A counter meant to accept monotonically increasing values to its {@link #update(long, int)} |
| 1786 | * method. The state of the timer according to its {@link TimeBase} will determine how much |
| 1787 | * of the value is recorded. |
| 1788 | * |
| 1789 | * If the value being recorded resets, {@link #endSample()} can be called in order to |
| 1790 | * account for the change. If the value passed in to {@link #update(long, int)} decreased |
| 1791 | * between calls, the {@link #endSample()} is automatically called and the new value is |
| 1792 | * expected to increase monotonically from that point on. |
| 1793 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1794 | public static class SamplingTimer extends Timer { |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1795 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1796 | /** |
| 1797 | * The most recent reported count from /proc/wakelocks. |
| 1798 | */ |
| 1799 | int mCurrentReportedCount; |
| 1800 | |
| 1801 | /** |
| 1802 | * The reported count from /proc/wakelocks when unplug() was last |
| 1803 | * called. |
| 1804 | */ |
| 1805 | int mUnpluggedReportedCount; |
| 1806 | |
| 1807 | /** |
| 1808 | * The most recent reported total_time from /proc/wakelocks. |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1809 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1810 | long mCurrentReportedTotalTime; |
| 1811 | |
| 1812 | |
| 1813 | /** |
| 1814 | * The reported total_time from /proc/wakelocks when unplug() was last |
| 1815 | * called. |
| 1816 | */ |
| 1817 | long mUnpluggedReportedTotalTime; |
| 1818 | |
| 1819 | /** |
| 1820 | * Whether we are currently in a discharge cycle. |
| 1821 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1822 | boolean mTimeBaseRunning; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1823 | |
| 1824 | /** |
| 1825 | * Whether we are currently recording reported values. |
| 1826 | */ |
| 1827 | boolean mTrackingReportedValues; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1828 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1829 | /* |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1830 | * A sequence counter, incremented once for each update of the stats. |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1831 | */ |
| 1832 | int mUpdateVersion; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1833 | |
Adam Lesinski | 98f0d46 | 2016-04-19 16:46:20 -0700 | [diff] [blame] | 1834 | @VisibleForTesting |
| 1835 | public SamplingTimer(Clocks clocks, TimeBase timeBase, Parcel in) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1836 | super(clocks, 0, timeBase, in); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1837 | mCurrentReportedCount = in.readInt(); |
| 1838 | mUnpluggedReportedCount = in.readInt(); |
| 1839 | mCurrentReportedTotalTime = in.readLong(); |
| 1840 | mUnpluggedReportedTotalTime = in.readLong(); |
| 1841 | mTrackingReportedValues = in.readInt() == 1; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1842 | mTimeBaseRunning = timeBase.isRunning(); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1843 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1844 | |
Adam Lesinski | 98f0d46 | 2016-04-19 16:46:20 -0700 | [diff] [blame] | 1845 | @VisibleForTesting |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1846 | public SamplingTimer(Clocks clocks, TimeBase timeBase) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1847 | super(clocks, 0, timeBase); |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1848 | mTrackingReportedValues = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1849 | mTimeBaseRunning = timeBase.isRunning(); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1850 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1851 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1852 | /** |
| 1853 | * Ends the current sample, allowing subsequent values to {@link #update(long, int)} to |
| 1854 | * be less than the values used for a previous invocation. |
| 1855 | */ |
| 1856 | public void endSample() { |
| 1857 | mTotalTime = computeRunTimeLocked(0 /* unused by us */); |
| 1858 | mCount = computeCurrentCountLocked(); |
| 1859 | mUnpluggedReportedTotalTime = mCurrentReportedTotalTime = 0; |
| 1860 | mUnpluggedReportedCount = mCurrentReportedCount = 0; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1861 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1862 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1863 | public void setUpdateVersion(int version) { |
| 1864 | mUpdateVersion = version; |
| 1865 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1866 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1867 | public int getUpdateVersion() { |
| 1868 | return mUpdateVersion; |
| 1869 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1870 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1871 | /** |
| 1872 | * Updates the current recorded values. These are meant to be monotonically increasing |
| 1873 | * and cumulative. If you are dealing with deltas, use {@link #add(long, int)}. |
| 1874 | * |
| 1875 | * If the values being recorded have been reset, the monotonically increasing requirement |
| 1876 | * will be broken. In this case, {@link #endSample()} is automatically called and |
| 1877 | * the total value of totalTime and count are recorded, starting a new monotonically |
| 1878 | * increasing sample. |
| 1879 | * |
| 1880 | * @param totalTime total time of sample in microseconds. |
| 1881 | * @param count total number of times the event being sampled occurred. |
| 1882 | */ |
| 1883 | public void update(long totalTime, int count) { |
| 1884 | if (mTimeBaseRunning && !mTrackingReportedValues) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1885 | // Updating the reported value for the first time. |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1886 | mUnpluggedReportedTotalTime = totalTime; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1887 | mUnpluggedReportedCount = count; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1888 | } |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1889 | |
| 1890 | mTrackingReportedValues = true; |
| 1891 | |
| 1892 | if (totalTime < mCurrentReportedTotalTime || count < mCurrentReportedCount) { |
| 1893 | endSample(); |
| 1894 | } |
| 1895 | |
| 1896 | mCurrentReportedTotalTime = totalTime; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1897 | mCurrentReportedCount = count; |
| 1898 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1899 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1900 | /** |
| 1901 | * Adds deltaTime and deltaCount to the current sample. |
| 1902 | * |
| 1903 | * @param deltaTime additional time recorded since the last sampled event, in microseconds. |
| 1904 | * @param deltaCount additional number of times the event being sampled occurred. |
| 1905 | */ |
| 1906 | public void add(long deltaTime, int deltaCount) { |
| 1907 | update(mCurrentReportedTotalTime + deltaTime, mCurrentReportedCount + deltaCount); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 1908 | } |
| 1909 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1910 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1911 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
| 1912 | super.onTimeStarted(elapsedRealtime, baseUptime, baseRealtime); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1913 | if (mTrackingReportedValues) { |
| 1914 | mUnpluggedReportedTotalTime = mCurrentReportedTotalTime; |
| 1915 | mUnpluggedReportedCount = mCurrentReportedCount; |
| 1916 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1917 | mTimeBaseRunning = true; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1918 | } |
| 1919 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1920 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1921 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
| 1922 | super.onTimeStopped(elapsedRealtime, baseUptime, baseRealtime); |
| 1923 | mTimeBaseRunning = false; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1924 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1925 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1926 | @Override |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1927 | public void logState(Printer pw, String prefix) { |
| 1928 | super.logState(pw, prefix); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1929 | pw.println(prefix + "mCurrentReportedCount=" + mCurrentReportedCount |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1930 | + " mUnpluggedReportedCount=" + mUnpluggedReportedCount |
| 1931 | + " mCurrentReportedTotalTime=" + mCurrentReportedTotalTime |
| 1932 | + " mUnpluggedReportedTotalTime=" + mUnpluggedReportedTotalTime); |
| 1933 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1934 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1935 | @Override |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1936 | protected long computeRunTimeLocked(long curBatteryRealtime) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1937 | return mTotalTime + (mTimeBaseRunning && mTrackingReportedValues |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1938 | ? mCurrentReportedTotalTime - mUnpluggedReportedTotalTime : 0); |
| 1939 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1940 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1941 | @Override |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1942 | protected int computeCurrentCountLocked() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1943 | return mCount + (mTimeBaseRunning && mTrackingReportedValues |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1944 | ? mCurrentReportedCount - mUnpluggedReportedCount : 0); |
| 1945 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1946 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1947 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1948 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
| 1949 | super.writeToParcel(out, elapsedRealtimeUs); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1950 | out.writeInt(mCurrentReportedCount); |
| 1951 | out.writeInt(mUnpluggedReportedCount); |
| 1952 | out.writeLong(mCurrentReportedTotalTime); |
| 1953 | out.writeLong(mUnpluggedReportedTotalTime); |
| 1954 | out.writeInt(mTrackingReportedValues ? 1 : 0); |
| 1955 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1956 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1957 | @Override |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1958 | public boolean reset(boolean detachIfReset) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1959 | super.reset(detachIfReset); |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1960 | mTrackingReportedValues = false; |
| 1961 | mUnpluggedReportedTotalTime = 0; |
| 1962 | mUnpluggedReportedCount = 0; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1963 | return true; |
| 1964 | } |
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 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1967 | /** |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1968 | * A timer that increments in batches. It does not run for durations, but just jumps |
| 1969 | * for a pre-determined amount. |
| 1970 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1971 | public static class BatchTimer extends Timer { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1972 | final Uid mUid; |
| 1973 | |
| 1974 | /** |
| 1975 | * The last time at which we updated the timer. This is in elapsed realtime microseconds. |
| 1976 | */ |
| 1977 | long mLastAddedTime; |
| 1978 | |
| 1979 | /** |
| 1980 | * The last duration that we added to the timer. This is in microseconds. |
| 1981 | */ |
| 1982 | long mLastAddedDuration; |
| 1983 | |
| 1984 | /** |
| 1985 | * Whether we are currently in a discharge cycle. |
| 1986 | */ |
| 1987 | boolean mInDischarge; |
| 1988 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1989 | BatchTimer(Clocks clocks, Uid uid, int type, TimeBase timeBase, Parcel in) { |
| 1990 | super(clocks, type, timeBase, in); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1991 | mUid = uid; |
| 1992 | mLastAddedTime = in.readLong(); |
| 1993 | mLastAddedDuration = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1994 | mInDischarge = timeBase.isRunning(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1995 | } |
| 1996 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1997 | BatchTimer(Clocks clocks, Uid uid, int type, TimeBase timeBase) { |
| 1998 | super(clocks, type, timeBase); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1999 | mUid = uid; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2000 | mInDischarge = timeBase.isRunning(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 2001 | } |
| 2002 | |
| 2003 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2004 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
| 2005 | super.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 2006 | out.writeLong(mLastAddedTime); |
| 2007 | out.writeLong(mLastAddedDuration); |
| 2008 | } |
| 2009 | |
| 2010 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2011 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2012 | recomputeLastDuration(mClocks.elapsedRealtime() * 1000, false); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 2013 | mInDischarge = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2014 | super.onTimeStopped(elapsedRealtime, baseUptime, baseRealtime); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 2015 | } |
| 2016 | |
| 2017 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2018 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 2019 | recomputeLastDuration(elapsedRealtime, false); |
| 2020 | mInDischarge = true; |
| 2021 | // If we are still within the last added duration, then re-added whatever remains. |
| 2022 | if (mLastAddedTime == elapsedRealtime) { |
| 2023 | mTotalTime += mLastAddedDuration; |
| 2024 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2025 | super.onTimeStarted(elapsedRealtime, baseUptime, baseRealtime); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 2026 | } |
| 2027 | |
| 2028 | @Override |
| 2029 | public void logState(Printer pw, String prefix) { |
| 2030 | super.logState(pw, prefix); |
| 2031 | pw.println(prefix + "mLastAddedTime=" + mLastAddedTime |
| 2032 | + " mLastAddedDuration=" + mLastAddedDuration); |
| 2033 | } |
| 2034 | |
| 2035 | private long computeOverage(long curTime) { |
| 2036 | if (mLastAddedTime > 0) { |
| 2037 | return mLastTime + mLastAddedDuration - curTime; |
| 2038 | } |
| 2039 | return 0; |
| 2040 | } |
| 2041 | |
| 2042 | private void recomputeLastDuration(long curTime, boolean abort) { |
| 2043 | final long overage = computeOverage(curTime); |
| 2044 | if (overage > 0) { |
| 2045 | // Aborting before the duration ran out -- roll back the remaining |
| 2046 | // duration. Only do this if currently discharging; otherwise we didn't |
| 2047 | // actually add the time. |
| 2048 | if (mInDischarge) { |
| 2049 | mTotalTime -= overage; |
| 2050 | } |
| 2051 | if (abort) { |
| 2052 | mLastAddedTime = 0; |
| 2053 | } else { |
| 2054 | mLastAddedTime = curTime; |
| 2055 | mLastAddedDuration -= overage; |
| 2056 | } |
| 2057 | } |
| 2058 | } |
| 2059 | |
| 2060 | public void addDuration(BatteryStatsImpl stats, long durationMillis) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2061 | final long now = mClocks.elapsedRealtime() * 1000; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 2062 | recomputeLastDuration(now, true); |
| 2063 | mLastAddedTime = now; |
| 2064 | mLastAddedDuration = durationMillis * 1000; |
| 2065 | if (mInDischarge) { |
| 2066 | mTotalTime += mLastAddedDuration; |
| 2067 | mCount++; |
| 2068 | } |
| 2069 | } |
| 2070 | |
| 2071 | public void abortLastDuration(BatteryStatsImpl stats) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2072 | final long now = mClocks.elapsedRealtime() * 1000; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 2073 | recomputeLastDuration(now, true); |
| 2074 | } |
| 2075 | |
| 2076 | @Override |
| 2077 | protected int computeCurrentCountLocked() { |
| 2078 | return mCount; |
| 2079 | } |
| 2080 | |
| 2081 | @Override |
| 2082 | protected long computeRunTimeLocked(long curBatteryRealtime) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2083 | final long overage = computeOverage(mClocks.elapsedRealtime() * 1000); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 2084 | if (overage > 0) { |
| 2085 | return mTotalTime = overage; |
| 2086 | } |
| 2087 | return mTotalTime; |
| 2088 | } |
| 2089 | |
| 2090 | @Override |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2091 | public boolean reset(boolean detachIfReset) { |
| 2092 | final long now = mClocks.elapsedRealtime() * 1000; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 2093 | recomputeLastDuration(now, true); |
| 2094 | boolean stillActive = mLastAddedTime == now; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2095 | super.reset(!stillActive && detachIfReset); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 2096 | return !stillActive; |
| 2097 | } |
| 2098 | } |
| 2099 | |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2100 | |
| 2101 | /** |
| 2102 | * A StopwatchTimer that also tracks the total and max individual |
| 2103 | * time spent active according to the given timebase. Whereas |
| 2104 | * StopwatchTimer apportions the time amongst all in the pool, |
| 2105 | * the total and max durations are not apportioned. |
| 2106 | */ |
| 2107 | public static class DurationTimer extends StopwatchTimer { |
| 2108 | /** |
| 2109 | * The time (in ms) that the timer was last acquired or the time base |
| 2110 | * last (re-)started. Increasing the nesting depth does not reset this time. |
| 2111 | * |
| 2112 | * -1 if the timer is currently not running or the time base is not running. |
| 2113 | * |
| 2114 | * If written to a parcel, the start time is reset, as is mNesting in the base class |
| 2115 | * StopwatchTimer. |
| 2116 | */ |
| 2117 | long mStartTimeMs = -1; |
| 2118 | |
| 2119 | /** |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2120 | * 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] | 2121 | */ |
| 2122 | long mMaxDurationMs; |
| 2123 | |
| 2124 | /** |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2125 | * The time (in ms) that that the timer has been active since most recent |
| 2126 | * stopRunningLocked() or reset(). Not pooled. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2127 | */ |
| 2128 | long mCurrentDurationMs; |
| 2129 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2130 | /** |
| 2131 | * The total time (in ms) that that the timer has been active since most recent reset() |
| 2132 | * prior to the current startRunningLocked. This is the sum of all past currentDurations |
| 2133 | * (but not including the present currentDuration) since reset. Not pooled. |
| 2134 | */ |
| 2135 | long mTotalDurationMs; |
| 2136 | |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2137 | public DurationTimer(Clocks clocks, Uid uid, int type, ArrayList<StopwatchTimer> timerPool, |
| 2138 | TimeBase timeBase, Parcel in) { |
| 2139 | super(clocks, uid, type, timerPool, timeBase, in); |
| 2140 | mMaxDurationMs = in.readLong(); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2141 | mTotalDurationMs = in.readLong(); |
jackqdyulei | 610a0a0 | 2017-08-09 14:02:01 -0700 | [diff] [blame] | 2142 | mCurrentDurationMs = in.readLong(); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2143 | } |
| 2144 | |
| 2145 | public DurationTimer(Clocks clocks, Uid uid, int type, ArrayList<StopwatchTimer> timerPool, |
| 2146 | TimeBase timeBase) { |
| 2147 | super(clocks, uid, type, timerPool, timeBase); |
| 2148 | } |
| 2149 | |
| 2150 | @Override |
| 2151 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
| 2152 | super.writeToParcel(out, elapsedRealtimeUs); |
Kweku Adams | 47db5a8 | 2016-12-09 19:04:50 -0800 | [diff] [blame] | 2153 | out.writeLong(getMaxDurationMsLocked(elapsedRealtimeUs / 1000)); |
jackqdyulei | 610a0a0 | 2017-08-09 14:02:01 -0700 | [diff] [blame] | 2154 | out.writeLong(mTotalDurationMs); |
| 2155 | out.writeLong(getCurrentDurationMsLocked(elapsedRealtimeUs / 1000)); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2156 | } |
| 2157 | |
| 2158 | /** |
| 2159 | * Write the summary to the parcel. |
| 2160 | * |
| 2161 | * Since the time base is probably meaningless after we come back, reading |
| 2162 | * 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] | 2163 | * is the max and total durations. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2164 | */ |
| 2165 | @Override |
| 2166 | public void writeSummaryFromParcelLocked(Parcel out, long elapsedRealtimeUs) { |
| 2167 | super.writeSummaryFromParcelLocked(out, elapsedRealtimeUs); |
Kweku Adams | 47db5a8 | 2016-12-09 19:04:50 -0800 | [diff] [blame] | 2168 | out.writeLong(getMaxDurationMsLocked(elapsedRealtimeUs / 1000)); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2169 | out.writeLong(getTotalDurationMsLocked(elapsedRealtimeUs / 1000)); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2170 | } |
| 2171 | |
| 2172 | /** |
| 2173 | * Read the summary parcel. |
| 2174 | * |
| 2175 | * Has the side effect of stopping the timer. |
| 2176 | */ |
| 2177 | @Override |
| 2178 | public void readSummaryFromParcelLocked(Parcel in) { |
| 2179 | super.readSummaryFromParcelLocked(in); |
| 2180 | mMaxDurationMs = in.readLong(); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2181 | mTotalDurationMs = in.readLong(); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2182 | mStartTimeMs = -1; |
| 2183 | mCurrentDurationMs = 0; |
| 2184 | } |
| 2185 | |
| 2186 | /** |
| 2187 | * The TimeBase time started (again). |
| 2188 | * |
| 2189 | * If the timer is also running, store the start time. |
| 2190 | */ |
| 2191 | public void onTimeStarted(long elapsedRealtimeUs, long baseUptime, long baseRealtime) { |
| 2192 | super.onTimeStarted(elapsedRealtimeUs, baseUptime, baseRealtime); |
| 2193 | if (mNesting > 0) { |
Kweku Adams | 47db5a8 | 2016-12-09 19:04:50 -0800 | [diff] [blame] | 2194 | mStartTimeMs = baseRealtime / 1000; |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2195 | } |
| 2196 | } |
| 2197 | |
| 2198 | /** |
| 2199 | * The TimeBase stopped running. |
| 2200 | * |
| 2201 | * If the timer is running, add the duration into mCurrentDurationMs. |
| 2202 | */ |
| 2203 | @Override |
Kweku Adams | 47db5a8 | 2016-12-09 19:04:50 -0800 | [diff] [blame] | 2204 | public void onTimeStopped(long elapsedRealtimeUs, long baseUptime, long baseRealtimeUs) { |
| 2205 | super.onTimeStopped(elapsedRealtimeUs, baseUptime, baseRealtimeUs); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2206 | if (mNesting > 0) { |
Kweku Adams | 47db5a8 | 2016-12-09 19:04:50 -0800 | [diff] [blame] | 2207 | // baseRealtimeUs has already been converted to the timebase's realtime. |
| 2208 | mCurrentDurationMs += (baseRealtimeUs / 1000) - mStartTimeMs; |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2209 | } |
| 2210 | mStartTimeMs = -1; |
| 2211 | } |
| 2212 | |
| 2213 | @Override |
| 2214 | public void logState(Printer pw, String prefix) { |
| 2215 | super.logState(pw, prefix); |
| 2216 | } |
| 2217 | |
| 2218 | @Override |
| 2219 | public void startRunningLocked(long elapsedRealtimeMs) { |
| 2220 | super.startRunningLocked(elapsedRealtimeMs); |
| 2221 | if (mNesting == 1 && mTimeBase.isRunning()) { |
| 2222 | // Just started |
Kweku Adams | 47db5a8 | 2016-12-09 19:04:50 -0800 | [diff] [blame] | 2223 | mStartTimeMs = mTimeBase.getRealtime(elapsedRealtimeMs * 1000) / 1000; |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2224 | } |
| 2225 | } |
| 2226 | |
| 2227 | /** |
| 2228 | * Decrements the mNesting ref-count on this timer. |
| 2229 | * |
| 2230 | * If it actually stopped (mNesting went to 0), then possibly update |
| 2231 | * mMaxDuration if the current duration was the longest ever. |
| 2232 | */ |
| 2233 | @Override |
| 2234 | public void stopRunningLocked(long elapsedRealtimeMs) { |
Kweku Adams | 47db5a8 | 2016-12-09 19:04:50 -0800 | [diff] [blame] | 2235 | if (mNesting == 1) { |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2236 | final long durationMs = getCurrentDurationMsLocked(elapsedRealtimeMs); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2237 | mTotalDurationMs += durationMs; |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2238 | if (durationMs > mMaxDurationMs) { |
| 2239 | mMaxDurationMs = durationMs; |
| 2240 | } |
| 2241 | mStartTimeMs = -1; |
| 2242 | mCurrentDurationMs = 0; |
| 2243 | } |
Kweku Adams | 47db5a8 | 2016-12-09 19:04:50 -0800 | [diff] [blame] | 2244 | // super method decrements mNesting, which getCurrentDurationMsLocked relies on, |
| 2245 | // so call super.stopRunningLocked after calling getCurrentDurationMsLocked. |
| 2246 | super.stopRunningLocked(elapsedRealtimeMs); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2247 | } |
| 2248 | |
| 2249 | @Override |
| 2250 | public boolean reset(boolean detachIfReset) { |
| 2251 | boolean result = super.reset(detachIfReset); |
| 2252 | mMaxDurationMs = 0; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2253 | mTotalDurationMs = 0; |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2254 | mCurrentDurationMs = 0; |
| 2255 | if (mNesting > 0) { |
| 2256 | mStartTimeMs = mTimeBase.getRealtime(mClocks.elapsedRealtime()*1000) / 1000; |
| 2257 | } else { |
| 2258 | mStartTimeMs = -1; |
| 2259 | } |
| 2260 | return result; |
| 2261 | } |
| 2262 | |
| 2263 | /** |
| 2264 | * Returns the max duration that this timer has ever seen. |
| 2265 | * |
| 2266 | * Note that this time is NOT split between the timers in the timer group that |
| 2267 | * this timer is attached to. It is the TOTAL time. |
| 2268 | */ |
| 2269 | @Override |
| 2270 | public long getMaxDurationMsLocked(long elapsedRealtimeMs) { |
| 2271 | if (mNesting > 0) { |
| 2272 | final long durationMs = getCurrentDurationMsLocked(elapsedRealtimeMs); |
| 2273 | if (durationMs > mMaxDurationMs) { |
| 2274 | return durationMs; |
| 2275 | } |
| 2276 | } |
| 2277 | return mMaxDurationMs; |
| 2278 | } |
| 2279 | |
| 2280 | /** |
| 2281 | * Returns the time since the timer was started. |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2282 | * Returns 0 if the timer is not currently running. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2283 | * |
| 2284 | * Note that this time is NOT split between the timers in the timer group that |
| 2285 | * this timer is attached to. It is the TOTAL time. |
jackqdyulei | 610a0a0 | 2017-08-09 14:02:01 -0700 | [diff] [blame] | 2286 | * |
| 2287 | * Note that if running timer is parceled and unparceled, this method will return |
| 2288 | * current duration value at the time of parceling even though timer may not be |
| 2289 | * currently running. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2290 | */ |
| 2291 | @Override |
| 2292 | public long getCurrentDurationMsLocked(long elapsedRealtimeMs) { |
| 2293 | long durationMs = mCurrentDurationMs; |
Kweku Adams | 47db5a8 | 2016-12-09 19:04:50 -0800 | [diff] [blame] | 2294 | if (mNesting > 0 && mTimeBase.isRunning()) { |
| 2295 | durationMs += (mTimeBase.getRealtime(elapsedRealtimeMs*1000)/1000) |
| 2296 | - mStartTimeMs; |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2297 | } |
| 2298 | return durationMs; |
| 2299 | } |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2300 | |
| 2301 | /** |
| 2302 | * Returns the total cumulative duration that this timer has been on since reset(). |
| 2303 | * If mTimerPool == null, this should be the same |
| 2304 | * as getTotalTimeLocked(elapsedRealtimeMs*1000, STATS_SINCE_CHARGED)/1000. |
| 2305 | * |
| 2306 | * Note that this time is NOT split between the timers in the timer group that |
| 2307 | * this timer is attached to. It is the TOTAL time. For this reason, if mTimerPool != null, |
| 2308 | * the result will not be equivalent to getTotalTimeLocked. |
| 2309 | */ |
| 2310 | @Override |
| 2311 | public long getTotalDurationMsLocked(long elapsedRealtimeMs) { |
| 2312 | return mTotalDurationMs + getCurrentDurationMsLocked(elapsedRealtimeMs); |
| 2313 | } |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2314 | } |
| 2315 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 2316 | /** |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2317 | * State for keeping track of timing information. |
| 2318 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2319 | public static class StopwatchTimer extends Timer { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 2320 | final Uid mUid; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2321 | final ArrayList<StopwatchTimer> mTimerPool; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 2322 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2323 | int mNesting; |
| 2324 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2325 | /** |
| 2326 | * The last time at which we updated the timer. If mNesting is > 0, |
| 2327 | * subtract this from the current battery time to find the amount of |
| 2328 | * time we have been running since we last computed an update. |
| 2329 | */ |
| 2330 | long mUpdateTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2331 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2332 | /** |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2333 | * The total time at which the timer was acquired, to determine if it |
Bookatz | ceebafe | 2017-04-06 11:59:13 -0700 | [diff] [blame] | 2334 | * was actually held for an interesting duration. If time base was not running when timer |
| 2335 | * was acquired, will be -1. |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2336 | */ |
Bookatz | ceebafe | 2017-04-06 11:59:13 -0700 | [diff] [blame] | 2337 | long mAcquireTime = -1; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2338 | |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 2339 | long mTimeout; |
| 2340 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 2341 | /** |
| 2342 | * For partial wake locks, keep track of whether we are in the list |
| 2343 | * to consume CPU cycles. |
| 2344 | */ |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 2345 | @VisibleForTesting |
| 2346 | public boolean mInList; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 2347 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2348 | public StopwatchTimer(Clocks clocks, Uid uid, int type, ArrayList<StopwatchTimer> timerPool, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2349 | TimeBase timeBase, Parcel in) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2350 | super(clocks, type, timeBase, in); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 2351 | mUid = uid; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2352 | mTimerPool = timerPool; |
| 2353 | mUpdateTime = in.readLong(); |
| 2354 | } |
| 2355 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2356 | public StopwatchTimer(Clocks clocks, Uid uid, int type, ArrayList<StopwatchTimer> timerPool, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2357 | TimeBase timeBase) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2358 | super(clocks, type, timeBase); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 2359 | mUid = uid; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2360 | mTimerPool = timerPool; |
| 2361 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2362 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2363 | public void setTimeout(long timeout) { |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 2364 | mTimeout = timeout; |
| 2365 | } |
| 2366 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2367 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
| 2368 | super.writeToParcel(out, elapsedRealtimeUs); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2369 | out.writeLong(mUpdateTime); |
| 2370 | } |
| 2371 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2372 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2373 | if (mNesting > 0) { |
| 2374 | if (DEBUG && mType < 0) { |
| 2375 | Log.v(TAG, "old mUpdateTime=" + mUpdateTime); |
| 2376 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2377 | super.onTimeStopped(elapsedRealtime, baseUptime, baseRealtime); |
| 2378 | mUpdateTime = baseRealtime; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2379 | if (DEBUG && mType < 0) { |
| 2380 | Log.v(TAG, "new mUpdateTime=" + mUpdateTime); |
| 2381 | } |
| 2382 | } |
| 2383 | } |
| 2384 | |
| 2385 | public void logState(Printer pw, String prefix) { |
| 2386 | super.logState(pw, prefix); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 2387 | pw.println(prefix + "mNesting=" + mNesting + " mUpdateTime=" + mUpdateTime |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2388 | + " mAcquireTime=" + mAcquireTime); |
| 2389 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2390 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2391 | public void startRunningLocked(long elapsedRealtimeMs) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2392 | if (mNesting++ == 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2393 | final long batteryRealtime = mTimeBase.getRealtime(elapsedRealtimeMs * 1000); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 2394 | mUpdateTime = batteryRealtime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2395 | if (mTimerPool != null) { |
| 2396 | // Accumulate time to all currently active timers before adding |
| 2397 | // this new one to the pool. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2398 | refreshTimersLocked(batteryRealtime, mTimerPool, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2399 | // Add this timer to the active pool |
| 2400 | mTimerPool.add(this); |
| 2401 | } |
Bookatz | ceebafe | 2017-04-06 11:59:13 -0700 | [diff] [blame] | 2402 | if (mTimeBase.isRunning()) { |
| 2403 | // Increment the count |
| 2404 | mCount++; |
| 2405 | mAcquireTime = mTotalTime; |
| 2406 | } else { |
| 2407 | mAcquireTime = -1; |
| 2408 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2409 | if (DEBUG && mType < 0) { |
| 2410 | Log.v(TAG, "start #" + mType + ": mUpdateTime=" + mUpdateTime |
| 2411 | + " mTotalTime=" + mTotalTime + " mCount=" + mCount |
| 2412 | + " mAcquireTime=" + mAcquireTime); |
| 2413 | } |
| 2414 | } |
| 2415 | } |
| 2416 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2417 | public boolean isRunningLocked() { |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 2418 | return mNesting > 0; |
| 2419 | } |
| 2420 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2421 | public void stopRunningLocked(long elapsedRealtimeMs) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2422 | // Ignore attempt to stop a timer that isn't running |
| 2423 | if (mNesting == 0) { |
| 2424 | return; |
| 2425 | } |
| 2426 | if (--mNesting == 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2427 | final long batteryRealtime = mTimeBase.getRealtime(elapsedRealtimeMs * 1000); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2428 | if (mTimerPool != null) { |
| 2429 | // Accumulate time to all active counters, scaled by the total |
| 2430 | // active in the pool, before taking this one out of the pool. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2431 | refreshTimersLocked(batteryRealtime, mTimerPool, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2432 | // Remove this timer from the active pool |
| 2433 | mTimerPool.remove(this); |
| 2434 | } else { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2435 | mNesting = 1; |
| 2436 | mTotalTime = computeRunTimeLocked(batteryRealtime); |
| 2437 | mNesting = 0; |
| 2438 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2439 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2440 | if (DEBUG && mType < 0) { |
| 2441 | Log.v(TAG, "stop #" + mType + ": mUpdateTime=" + mUpdateTime |
| 2442 | + " mTotalTime=" + mTotalTime + " mCount=" + mCount |
| 2443 | + " mAcquireTime=" + mAcquireTime); |
| 2444 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2445 | |
Bookatz | ceebafe | 2017-04-06 11:59:13 -0700 | [diff] [blame] | 2446 | if (mAcquireTime >= 0 && mTotalTime == mAcquireTime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2447 | // If there was no change in the time, then discard this |
| 2448 | // count. A somewhat cheezy strategy, but hey. |
| 2449 | mCount--; |
| 2450 | } |
| 2451 | } |
| 2452 | } |
| 2453 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2454 | public void stopAllRunningLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 2455 | if (mNesting > 0) { |
| 2456 | mNesting = 1; |
| 2457 | stopRunningLocked(elapsedRealtimeMs); |
| 2458 | } |
| 2459 | } |
| 2460 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2461 | // Update the total time for all other running Timers with the same type as this Timer |
| 2462 | // due to a change in timer count |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2463 | private static long refreshTimersLocked(long batteryRealtime, |
| 2464 | final ArrayList<StopwatchTimer> pool, StopwatchTimer self) { |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 2465 | long selfTime = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2466 | final int N = pool.size(); |
| 2467 | for (int i=N-1; i>= 0; i--) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2468 | final StopwatchTimer t = pool.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2469 | long heldTime = batteryRealtime - t.mUpdateTime; |
| 2470 | if (heldTime > 0) { |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 2471 | final long myTime = heldTime / N; |
| 2472 | if (t == self) { |
| 2473 | selfTime = myTime; |
| 2474 | } |
| 2475 | t.mTotalTime += myTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2476 | } |
| 2477 | t.mUpdateTime = batteryRealtime; |
| 2478 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 2479 | return selfTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2480 | } |
| 2481 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2482 | @Override |
| 2483 | protected long computeRunTimeLocked(long curBatteryRealtime) { |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 2484 | if (mTimeout > 0 && curBatteryRealtime > mUpdateTime + mTimeout) { |
| 2485 | curBatteryRealtime = mUpdateTime + mTimeout; |
| 2486 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2487 | return mTotalTime + (mNesting > 0 |
| 2488 | ? (curBatteryRealtime - mUpdateTime) |
| 2489 | / (mTimerPool != null ? mTimerPool.size() : 1) |
| 2490 | : 0); |
| 2491 | } |
| 2492 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2493 | @Override |
| 2494 | protected int computeCurrentCountLocked() { |
| 2495 | return mCount; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2496 | } |
| 2497 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 2498 | @Override |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2499 | public boolean reset(boolean detachIfReset) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2500 | boolean canDetach = mNesting <= 0; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2501 | super.reset(canDetach && detachIfReset); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2502 | if (mNesting > 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2503 | mUpdateTime = mTimeBase.getRealtime(mClocks.elapsedRealtime() * 1000); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2504 | } |
Bookatz | ceebafe | 2017-04-06 11:59:13 -0700 | [diff] [blame] | 2505 | 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] | 2506 | return canDetach; |
| 2507 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2508 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 2509 | @Override |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2510 | public void detach() { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2511 | super.detach(); |
| 2512 | if (mTimerPool != null) { |
| 2513 | mTimerPool.remove(this); |
| 2514 | } |
| 2515 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2516 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 2517 | @Override |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2518 | public void readSummaryFromParcelLocked(Parcel in) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2519 | super.readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2520 | mNesting = 0; |
| 2521 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 2522 | |
| 2523 | /** |
| 2524 | * Set the mark so that we can query later for the total time the timer has |
| 2525 | * accumulated since this point. The timer can be running or not. |
| 2526 | * |
| 2527 | * @param elapsedRealtimeMs the current elapsed realtime in milliseconds. |
| 2528 | */ |
| 2529 | public void setMark(long elapsedRealtimeMs) { |
| 2530 | final long batteryRealtime = mTimeBase.getRealtime(elapsedRealtimeMs * 1000); |
| 2531 | if (mNesting > 0) { |
| 2532 | // We are running. |
| 2533 | if (mTimerPool != null) { |
| 2534 | refreshTimersLocked(batteryRealtime, mTimerPool, this); |
| 2535 | } else { |
| 2536 | mTotalTime += batteryRealtime - mUpdateTime; |
| 2537 | mUpdateTime = batteryRealtime; |
| 2538 | } |
| 2539 | } |
| 2540 | mTimeBeforeMark = mTotalTime; |
| 2541 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2542 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2543 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2544 | /** |
| 2545 | * State for keeping track of two DurationTimers with different TimeBases, presumably where one |
| 2546 | * TimeBase is effectively a subset of the other. |
| 2547 | */ |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2548 | public static class DualTimer extends DurationTimer { |
| 2549 | // This class both is a DurationTimer and also holds a second DurationTimer. |
| 2550 | // The main timer (this) typically tracks the total time. It may be pooled (but since it's a |
| 2551 | // durationTimer, it also has the unpooled getTotalDurationMsLocked() for |
| 2552 | // STATS_SINCE_CHARGED). |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2553 | // mSubTimer typically tracks only part of the total time, such as background time, as |
| 2554 | // determined by a subTimeBase. It is NOT pooled. |
| 2555 | private final DurationTimer mSubTimer; |
| 2556 | |
| 2557 | /** |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2558 | * Creates a DualTimer to hold a main timer (this) and a mSubTimer. |
| 2559 | * The main timer (this) is based on the given timeBase and timerPool. |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2560 | * 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] | 2561 | * the main timer is. |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2562 | */ |
| 2563 | public DualTimer(Clocks clocks, Uid uid, int type, ArrayList<StopwatchTimer> timerPool, |
| 2564 | TimeBase timeBase, TimeBase subTimeBase, Parcel in) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2565 | super(clocks, uid, type, timerPool, timeBase, in); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2566 | mSubTimer = new DurationTimer(clocks, uid, type, null, subTimeBase, in); |
| 2567 | } |
| 2568 | |
| 2569 | /** |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2570 | * Creates a DualTimer to hold a main timer (this) and a mSubTimer. |
| 2571 | * The main timer (this) is based on the given timeBase and timerPool. |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2572 | * 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] | 2573 | * the main timer is. |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2574 | */ |
| 2575 | public DualTimer(Clocks clocks, Uid uid, int type, ArrayList<StopwatchTimer> timerPool, |
| 2576 | TimeBase timeBase, TimeBase subTimeBase) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2577 | super(clocks, uid, type, timerPool, timeBase); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2578 | mSubTimer = new DurationTimer(clocks, uid, type, null, subTimeBase); |
| 2579 | } |
| 2580 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2581 | /** Get the secondary timer. */ |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2582 | @Override |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2583 | public DurationTimer getSubTimer() { |
| 2584 | return mSubTimer; |
| 2585 | } |
| 2586 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2587 | @Override |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2588 | public void startRunningLocked(long elapsedRealtimeMs) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2589 | super.startRunningLocked(elapsedRealtimeMs); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2590 | mSubTimer.startRunningLocked(elapsedRealtimeMs); |
| 2591 | } |
| 2592 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2593 | @Override |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2594 | public void stopRunningLocked(long elapsedRealtimeMs) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2595 | super.stopRunningLocked(elapsedRealtimeMs); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2596 | mSubTimer.stopRunningLocked(elapsedRealtimeMs); |
| 2597 | } |
| 2598 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2599 | @Override |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2600 | public void stopAllRunningLocked(long elapsedRealtimeMs) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2601 | super.stopAllRunningLocked(elapsedRealtimeMs); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2602 | mSubTimer.stopAllRunningLocked(elapsedRealtimeMs); |
| 2603 | } |
| 2604 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2605 | @Override |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2606 | public boolean reset(boolean detachIfReset) { |
| 2607 | boolean active = false; |
Bookatz | 4a3eda9 | 2017-04-10 13:10:46 -0700 | [diff] [blame] | 2608 | // Do not detach the subTimer explicitly since that'll be done by DualTimer.detach(). |
| 2609 | active |= !mSubTimer.reset(false); |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2610 | active |= !super.reset(detachIfReset); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2611 | return !active; |
| 2612 | } |
| 2613 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2614 | @Override |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2615 | public void detach() { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2616 | mSubTimer.detach(); |
Bookatz | 4a3eda9 | 2017-04-10 13:10:46 -0700 | [diff] [blame] | 2617 | super.detach(); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2618 | } |
| 2619 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2620 | @Override |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2621 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2622 | super.writeToParcel(out, elapsedRealtimeUs); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2623 | mSubTimer.writeToParcel(out, elapsedRealtimeUs); |
| 2624 | } |
| 2625 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2626 | @Override |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2627 | public void writeSummaryFromParcelLocked(Parcel out, long elapsedRealtimeUs) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2628 | super.writeSummaryFromParcelLocked(out, elapsedRealtimeUs); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2629 | mSubTimer.writeSummaryFromParcelLocked(out, elapsedRealtimeUs); |
| 2630 | } |
| 2631 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2632 | @Override |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2633 | public void readSummaryFromParcelLocked(Parcel in) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2634 | super.readSummaryFromParcelLocked(in); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2635 | mSubTimer.readSummaryFromParcelLocked(in); |
| 2636 | } |
| 2637 | } |
| 2638 | |
| 2639 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2640 | public abstract class OverflowArrayMap<T> { |
| 2641 | private static final String OVERFLOW_NAME = "*overflow*"; |
| 2642 | |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame] | 2643 | final int mUid; |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2644 | final ArrayMap<String, T> mMap = new ArrayMap<>(); |
| 2645 | T mCurOverflow; |
| 2646 | ArrayMap<String, MutableInt> mActiveOverflow; |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame] | 2647 | long mLastOverflowTime; |
| 2648 | long mLastOverflowFinishTime; |
| 2649 | long mLastClearTime; |
| 2650 | long mLastCleanupTime; |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2651 | |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame] | 2652 | public OverflowArrayMap(int uid) { |
| 2653 | mUid = uid; |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2654 | } |
| 2655 | |
| 2656 | public ArrayMap<String, T> getMap() { |
| 2657 | return mMap; |
| 2658 | } |
| 2659 | |
| 2660 | public void clear() { |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame] | 2661 | mLastClearTime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2662 | mMap.clear(); |
| 2663 | mCurOverflow = null; |
| 2664 | mActiveOverflow = null; |
| 2665 | } |
| 2666 | |
| 2667 | public void add(String name, T obj) { |
Joe Onorato | 388fc33 | 2016-04-12 17:06:47 -0700 | [diff] [blame] | 2668 | if (name == null) { |
| 2669 | name = ""; |
| 2670 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2671 | mMap.put(name, obj); |
| 2672 | if (OVERFLOW_NAME.equals(name)) { |
| 2673 | mCurOverflow = obj; |
| 2674 | } |
| 2675 | } |
| 2676 | |
| 2677 | public void cleanup() { |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame] | 2678 | mLastCleanupTime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2679 | if (mActiveOverflow != null) { |
| 2680 | if (mActiveOverflow.size() == 0) { |
| 2681 | mActiveOverflow = null; |
| 2682 | } |
| 2683 | } |
| 2684 | if (mActiveOverflow == null) { |
| 2685 | // There is no currently active overflow, so we should no longer have |
| 2686 | // an overflow entry. |
| 2687 | if (mMap.containsKey(OVERFLOW_NAME)) { |
| 2688 | Slog.wtf(TAG, "Cleaning up with no active overflow, but have overflow entry " |
| 2689 | + mMap.get(OVERFLOW_NAME)); |
| 2690 | mMap.remove(OVERFLOW_NAME); |
| 2691 | } |
| 2692 | mCurOverflow = null; |
| 2693 | } else { |
| 2694 | // There is currently active overflow, so we should still have an overflow entry. |
| 2695 | if (mCurOverflow == null || !mMap.containsKey(OVERFLOW_NAME)) { |
| 2696 | Slog.wtf(TAG, "Cleaning up with active overflow, but no overflow entry: cur=" |
| 2697 | + mCurOverflow + " map=" + mMap.get(OVERFLOW_NAME)); |
| 2698 | } |
| 2699 | } |
| 2700 | } |
| 2701 | |
| 2702 | public T startObject(String name) { |
Joe Onorato | 388fc33 | 2016-04-12 17:06:47 -0700 | [diff] [blame] | 2703 | if (name == null) { |
| 2704 | name = ""; |
| 2705 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2706 | T obj = mMap.get(name); |
| 2707 | if (obj != null) { |
| 2708 | return obj; |
| 2709 | } |
| 2710 | |
| 2711 | // No object exists for the given name, but do we currently have it |
| 2712 | // running as part of the overflow? |
| 2713 | if (mActiveOverflow != null) { |
| 2714 | MutableInt over = mActiveOverflow.get(name); |
| 2715 | if (over != null) { |
| 2716 | // We are already actively counting this name in the overflow object. |
| 2717 | obj = mCurOverflow; |
| 2718 | if (obj == null) { |
| 2719 | // Shouldn't be here, but we'll try to recover. |
| 2720 | Slog.wtf(TAG, "Have active overflow " + name + " but null overflow"); |
| 2721 | obj = mCurOverflow = instantiateObject(); |
| 2722 | mMap.put(OVERFLOW_NAME, obj); |
| 2723 | } |
| 2724 | over.value++; |
| 2725 | return obj; |
| 2726 | } |
| 2727 | } |
| 2728 | |
| 2729 | // No object exists for given name nor in the overflow; we need to make |
| 2730 | // a new one. |
| 2731 | final int N = mMap.size(); |
| 2732 | if (N >= MAX_WAKELOCKS_PER_UID) { |
| 2733 | // Went over the limit on number of objects to track; this one goes |
| 2734 | // in to the overflow. |
| 2735 | obj = mCurOverflow; |
| 2736 | if (obj == null) { |
| 2737 | // Need to start overflow now... |
| 2738 | obj = mCurOverflow = instantiateObject(); |
| 2739 | mMap.put(OVERFLOW_NAME, obj); |
| 2740 | } |
| 2741 | if (mActiveOverflow == null) { |
| 2742 | mActiveOverflow = new ArrayMap<>(); |
| 2743 | } |
| 2744 | mActiveOverflow.put(name, new MutableInt(1)); |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame] | 2745 | mLastOverflowTime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2746 | return obj; |
| 2747 | } |
| 2748 | |
| 2749 | // Normal case where we just need to make a new object. |
| 2750 | obj = instantiateObject(); |
| 2751 | mMap.put(name, obj); |
| 2752 | return obj; |
| 2753 | } |
| 2754 | |
| 2755 | public T stopObject(String name) { |
Joe Onorato | 388fc33 | 2016-04-12 17:06:47 -0700 | [diff] [blame] | 2756 | if (name == null) { |
| 2757 | name = ""; |
| 2758 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2759 | T obj = mMap.get(name); |
| 2760 | if (obj != null) { |
| 2761 | return obj; |
| 2762 | } |
| 2763 | |
| 2764 | // No object exists for the given name, but do we currently have it |
| 2765 | // running as part of the overflow? |
| 2766 | if (mActiveOverflow != null) { |
| 2767 | MutableInt over = mActiveOverflow.get(name); |
| 2768 | if (over != null) { |
| 2769 | // We are already actively counting this name in the overflow object. |
| 2770 | obj = mCurOverflow; |
| 2771 | if (obj != null) { |
| 2772 | over.value--; |
| 2773 | if (over.value <= 0) { |
| 2774 | mActiveOverflow.remove(name); |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame] | 2775 | mLastOverflowFinishTime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2776 | } |
| 2777 | return obj; |
| 2778 | } |
| 2779 | } |
| 2780 | } |
| 2781 | |
| 2782 | // Huh, they are stopping an active operation but we can't find one! |
| 2783 | // That's not good. |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame] | 2784 | StringBuilder sb = new StringBuilder(); |
| 2785 | sb.append("Unable to find object for "); |
| 2786 | sb.append(name); |
| 2787 | sb.append(" in uid "); |
| 2788 | sb.append(mUid); |
| 2789 | sb.append(" mapsize="); |
| 2790 | sb.append(mMap.size()); |
| 2791 | sb.append(" activeoverflow="); |
| 2792 | sb.append(mActiveOverflow); |
| 2793 | sb.append(" curoverflow="); |
| 2794 | sb.append(mCurOverflow); |
| 2795 | long now = SystemClock.elapsedRealtime(); |
| 2796 | if (mLastOverflowTime != 0) { |
| 2797 | sb.append(" lastOverflowTime="); |
| 2798 | TimeUtils.formatDuration(mLastOverflowTime-now, sb); |
| 2799 | } |
| 2800 | if (mLastOverflowFinishTime != 0) { |
| 2801 | sb.append(" lastOverflowFinishTime="); |
| 2802 | TimeUtils.formatDuration(mLastOverflowFinishTime-now, sb); |
| 2803 | } |
| 2804 | if (mLastClearTime != 0) { |
| 2805 | sb.append(" lastClearTime="); |
| 2806 | TimeUtils.formatDuration(mLastClearTime-now, sb); |
| 2807 | } |
| 2808 | if (mLastCleanupTime != 0) { |
| 2809 | sb.append(" lastCleanupTime="); |
| 2810 | TimeUtils.formatDuration(mLastCleanupTime-now, sb); |
| 2811 | } |
| 2812 | Slog.wtf(TAG, sb.toString()); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2813 | return null; |
| 2814 | } |
| 2815 | |
| 2816 | public abstract T instantiateObject(); |
| 2817 | } |
| 2818 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2819 | public static class ControllerActivityCounterImpl extends ControllerActivityCounter |
| 2820 | implements Parcelable { |
| 2821 | private final LongSamplingCounter mIdleTimeMillis; |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 2822 | private final LongSamplingCounter mScanTimeMillis; |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2823 | private final LongSamplingCounter mRxTimeMillis; |
| 2824 | private final LongSamplingCounter[] mTxTimeMillis; |
| 2825 | private final LongSamplingCounter mPowerDrainMaMs; |
| 2826 | |
| 2827 | public ControllerActivityCounterImpl(TimeBase timeBase, int numTxStates) { |
| 2828 | mIdleTimeMillis = new LongSamplingCounter(timeBase); |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 2829 | mScanTimeMillis = new LongSamplingCounter(timeBase); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2830 | mRxTimeMillis = new LongSamplingCounter(timeBase); |
| 2831 | mTxTimeMillis = new LongSamplingCounter[numTxStates]; |
| 2832 | for (int i = 0; i < numTxStates; i++) { |
| 2833 | mTxTimeMillis[i] = new LongSamplingCounter(timeBase); |
| 2834 | } |
| 2835 | mPowerDrainMaMs = new LongSamplingCounter(timeBase); |
| 2836 | } |
| 2837 | |
| 2838 | public ControllerActivityCounterImpl(TimeBase timeBase, int numTxStates, Parcel in) { |
| 2839 | mIdleTimeMillis = new LongSamplingCounter(timeBase, in); |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 2840 | mScanTimeMillis = new LongSamplingCounter(timeBase, in); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2841 | mRxTimeMillis = new LongSamplingCounter(timeBase, in); |
| 2842 | final int recordedTxStates = in.readInt(); |
| 2843 | if (recordedTxStates != numTxStates) { |
| 2844 | throw new ParcelFormatException("inconsistent tx state lengths"); |
| 2845 | } |
| 2846 | |
| 2847 | mTxTimeMillis = new LongSamplingCounter[numTxStates]; |
| 2848 | for (int i = 0; i < numTxStates; i++) { |
| 2849 | mTxTimeMillis[i] = new LongSamplingCounter(timeBase, in); |
| 2850 | } |
| 2851 | mPowerDrainMaMs = new LongSamplingCounter(timeBase, in); |
| 2852 | } |
| 2853 | |
| 2854 | public void readSummaryFromParcel(Parcel in) { |
| 2855 | mIdleTimeMillis.readSummaryFromParcelLocked(in); |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 2856 | mScanTimeMillis.readSummaryFromParcelLocked(in); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2857 | mRxTimeMillis.readSummaryFromParcelLocked(in); |
| 2858 | final int recordedTxStates = in.readInt(); |
| 2859 | if (recordedTxStates != mTxTimeMillis.length) { |
| 2860 | throw new ParcelFormatException("inconsistent tx state lengths"); |
| 2861 | } |
| 2862 | for (LongSamplingCounter counter : mTxTimeMillis) { |
| 2863 | counter.readSummaryFromParcelLocked(in); |
| 2864 | } |
| 2865 | mPowerDrainMaMs.readSummaryFromParcelLocked(in); |
| 2866 | } |
| 2867 | |
| 2868 | @Override |
| 2869 | public int describeContents() { |
| 2870 | return 0; |
| 2871 | } |
| 2872 | |
| 2873 | public void writeSummaryToParcel(Parcel dest) { |
| 2874 | mIdleTimeMillis.writeSummaryFromParcelLocked(dest); |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 2875 | mScanTimeMillis.writeSummaryFromParcelLocked(dest); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2876 | mRxTimeMillis.writeSummaryFromParcelLocked(dest); |
| 2877 | dest.writeInt(mTxTimeMillis.length); |
| 2878 | for (LongSamplingCounter counter : mTxTimeMillis) { |
| 2879 | counter.writeSummaryFromParcelLocked(dest); |
| 2880 | } |
| 2881 | mPowerDrainMaMs.writeSummaryFromParcelLocked(dest); |
| 2882 | } |
| 2883 | |
| 2884 | @Override |
| 2885 | public void writeToParcel(Parcel dest, int flags) { |
| 2886 | mIdleTimeMillis.writeToParcel(dest); |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 2887 | mScanTimeMillis.writeToParcel(dest); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2888 | mRxTimeMillis.writeToParcel(dest); |
| 2889 | dest.writeInt(mTxTimeMillis.length); |
| 2890 | for (LongSamplingCounter counter : mTxTimeMillis) { |
| 2891 | counter.writeToParcel(dest); |
| 2892 | } |
| 2893 | mPowerDrainMaMs.writeToParcel(dest); |
| 2894 | } |
| 2895 | |
| 2896 | public void reset(boolean detachIfReset) { |
| 2897 | mIdleTimeMillis.reset(detachIfReset); |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 2898 | mScanTimeMillis.reset(detachIfReset); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2899 | mRxTimeMillis.reset(detachIfReset); |
| 2900 | for (LongSamplingCounter counter : mTxTimeMillis) { |
| 2901 | counter.reset(detachIfReset); |
| 2902 | } |
| 2903 | mPowerDrainMaMs.reset(detachIfReset); |
| 2904 | } |
| 2905 | |
| 2906 | public void detach() { |
| 2907 | mIdleTimeMillis.detach(); |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 2908 | mScanTimeMillis.detach(); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2909 | mRxTimeMillis.detach(); |
| 2910 | for (LongSamplingCounter counter : mTxTimeMillis) { |
| 2911 | counter.detach(); |
| 2912 | } |
| 2913 | mPowerDrainMaMs.detach(); |
| 2914 | } |
| 2915 | |
| 2916 | /** |
| 2917 | * @return a LongSamplingCounter, measuring time spent in the idle state in |
| 2918 | * milliseconds. |
| 2919 | */ |
| 2920 | @Override |
| 2921 | public LongSamplingCounter getIdleTimeCounter() { |
Roshan Pius | 8164330 | 2016-03-14 16:45:55 -0700 | [diff] [blame] | 2922 | return mIdleTimeMillis; |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2923 | } |
| 2924 | |
| 2925 | /** |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 2926 | * @return a LongSamplingCounter, measuring time spent in the scan state in |
| 2927 | * milliseconds. |
| 2928 | */ |
| 2929 | @Override |
| 2930 | public LongSamplingCounter getScanTimeCounter() { |
| 2931 | return mScanTimeMillis; |
| 2932 | } |
| 2933 | |
| 2934 | /** |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2935 | * @return a LongSamplingCounter, measuring time spent in the receive state in |
| 2936 | * milliseconds. |
| 2937 | */ |
| 2938 | @Override |
| 2939 | public LongSamplingCounter getRxTimeCounter() { |
| 2940 | return mRxTimeMillis; |
| 2941 | } |
| 2942 | |
| 2943 | /** |
| 2944 | * @return a LongSamplingCounter[], measuring time spent in various transmit states in |
| 2945 | * milliseconds. |
| 2946 | */ |
| 2947 | @Override |
| 2948 | public LongSamplingCounter[] getTxTimeCounters() { |
| 2949 | return mTxTimeMillis; |
| 2950 | } |
| 2951 | |
| 2952 | /** |
| 2953 | * @return a LongSamplingCounter, measuring power use in milli-ampere milliseconds (mAmS). |
| 2954 | */ |
| 2955 | @Override |
| 2956 | public LongSamplingCounter getPowerCounter() { |
| 2957 | return mPowerDrainMaMs; |
| 2958 | } |
| 2959 | } |
| 2960 | |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 2961 | /** Get Resource Power Manager stats. Create a new one if it doesn't already exist. */ |
| 2962 | public SamplingTimer getRpmTimerLocked(String name) { |
| 2963 | SamplingTimer rpmt = mRpmStats.get(name); |
| 2964 | if (rpmt == null) { |
| 2965 | rpmt = new SamplingTimer(mClocks, mOnBatteryTimeBase); |
| 2966 | mRpmStats.put(name, rpmt); |
| 2967 | } |
| 2968 | return rpmt; |
| 2969 | } |
| 2970 | |
| 2971 | /** Get Screen-off Resource Power Manager stats. Create new one if it doesn't already exist. */ |
| 2972 | public SamplingTimer getScreenOffRpmTimerLocked(String name) { |
| 2973 | SamplingTimer rpmt = mScreenOffRpmStats.get(name); |
| 2974 | if (rpmt == null) { |
| 2975 | rpmt = new SamplingTimer(mClocks, mOnBatteryScreenOffTimeBase); |
| 2976 | mScreenOffRpmStats.put(name, rpmt); |
| 2977 | } |
| 2978 | return rpmt; |
| 2979 | } |
| 2980 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2981 | /* |
| 2982 | * Get the wakeup reason counter, and create a new one if one |
| 2983 | * doesn't already exist. |
| 2984 | */ |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 2985 | public SamplingTimer getWakeupReasonTimerLocked(String name) { |
| 2986 | SamplingTimer timer = mWakeupReasonStats.get(name); |
| 2987 | if (timer == null) { |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 2988 | timer = new SamplingTimer(mClocks, mOnBatteryTimeBase); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 2989 | mWakeupReasonStats.put(name, timer); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2990 | } |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 2991 | return timer; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2992 | } |
| 2993 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2994 | /* |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2995 | * 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] | 2996 | * doesn't already exist. |
| 2997 | */ |
| 2998 | public SamplingTimer getKernelWakelockTimerLocked(String name) { |
| 2999 | SamplingTimer kwlt = mKernelWakelockStats.get(name); |
| 3000 | if (kwlt == null) { |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 3001 | kwlt = new SamplingTimer(mClocks, mOnBatteryScreenOffTimeBase); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 3002 | mKernelWakelockStats.put(name, kwlt); |
| 3003 | } |
| 3004 | return kwlt; |
| 3005 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 3006 | |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 3007 | public SamplingTimer getKernelMemoryTimerLocked(long bucket) { |
| 3008 | SamplingTimer kmt = mKernelMemoryStats.get(bucket); |
| 3009 | if (kmt == null) { |
| 3010 | kmt = new SamplingTimer(mClocks, mOnBatteryTimeBase); |
| 3011 | mKernelMemoryStats.put(bucket, kmt); |
| 3012 | } |
| 3013 | return kmt; |
| 3014 | } |
| 3015 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3016 | private int writeHistoryTag(HistoryTag tag) { |
| 3017 | Integer idxObj = mHistoryTagPool.get(tag); |
| 3018 | int idx; |
| 3019 | if (idxObj != null) { |
| 3020 | idx = idxObj; |
| 3021 | } else { |
| 3022 | idx = mNextHistoryTagIdx; |
| 3023 | HistoryTag key = new HistoryTag(); |
| 3024 | key.setTo(tag); |
| 3025 | tag.poolIdx = idx; |
| 3026 | mHistoryTagPool.put(key, idx); |
| 3027 | mNextHistoryTagIdx++; |
| 3028 | mNumHistoryTagChars += key.string.length() + 1; |
| 3029 | } |
| 3030 | return idx; |
| 3031 | } |
| 3032 | |
| 3033 | private void readHistoryTag(int index, HistoryTag tag) { |
| 3034 | tag.string = mReadHistoryStrings[index]; |
| 3035 | tag.uid = mReadHistoryUids[index]; |
| 3036 | tag.poolIdx = index; |
| 3037 | } |
| 3038 | |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 3039 | /* |
| 3040 | The history delta format uses flags to denote further data in subsequent ints in the parcel. |
| 3041 | |
| 3042 | There is always the first token, which may contain the delta time, or an indicator of |
| 3043 | the length of the time (int or long) following this token. |
| 3044 | |
| 3045 | First token: always present, |
| 3046 | 31 23 15 7 0 |
| 3047 | â–ˆ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â–ˆ |
| 3048 | |
| 3049 | T: the delta time if it is <= 0x7fffd. Otherwise 0x7fffe indicates an int immediately |
| 3050 | follows containing the time, and 0x7ffff indicates a long immediately follows with the |
| 3051 | delta time. |
| 3052 | A: battery level changed and an int follows with battery data. |
| 3053 | B: state changed and an int follows with state change data. |
| 3054 | C: state2 has changed and an int follows with state2 change data. |
| 3055 | D: wakelock/wakereason has changed and an wakelock/wakereason struct follows. |
| 3056 | E: event data has changed and an event struct follows. |
| 3057 | F: battery charge in coulombs has changed and an int with the charge follows. |
| 3058 | G: state flag denoting that the mobile radio was active. |
| 3059 | H: state flag denoting that the wifi radio was active. |
| 3060 | I: state flag denoting that a wifi scan occurred. |
| 3061 | J: state flag denoting that a wifi full lock was held. |
| 3062 | K: state flag denoting that the gps was on. |
| 3063 | L: state flag denoting that a wakelock was held. |
| 3064 | M: state flag denoting that the cpu was running. |
| 3065 | |
| 3066 | Time int/long: if T in the first token is 0x7ffff or 0x7fffe, then an int or long follows |
| 3067 | with the time delta. |
| 3068 | |
| 3069 | Battery level int: if A in the first token is set, |
| 3070 | 31 23 15 7 0 |
| 3071 | â–ˆ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â–ˆ |
| 3072 | |
| 3073 | D: indicates that extra history details follow. |
| 3074 | V: the battery voltage. |
| 3075 | T: the battery temperature. |
| 3076 | L: the battery level (out of 100). |
| 3077 | |
| 3078 | State change int: if B in the first token is set, |
| 3079 | 31 23 15 7 0 |
| 3080 | â–ˆS|S|S|H|H|H|P|Pâ–ˆF|E|D|C|B| | |Aâ–ˆ | | | | | | | â–ˆ | | | | | | | â–ˆ |
| 3081 | |
| 3082 | A: wifi multicast was on. |
| 3083 | B: battery was plugged in. |
| 3084 | C: screen was on. |
| 3085 | D: phone was scanning for signal. |
| 3086 | E: audio was on. |
| 3087 | F: a sensor was active. |
| 3088 | |
| 3089 | State2 change int: if C in the first token is set, |
| 3090 | 31 23 15 7 0 |
| 3091 | â–ˆM|L|K|J|I|H|H|Gâ–ˆF|E|D|C| | | | â–ˆ | | | | | | | â–ˆ |B|B|B|A|A|A|Aâ–ˆ |
| 3092 | |
| 3093 | A: 4 bits indicating the wifi supplicant state: {@link BatteryStats#WIFI_SUPPL_STATE_NAMES}. |
| 3094 | B: 3 bits indicating the wifi signal strength: 0, 1, 2, 3, 4. |
| 3095 | C: a bluetooth scan was active. |
| 3096 | D: the camera was active. |
| 3097 | E: bluetooth was on. |
| 3098 | F: a phone call was active. |
| 3099 | G: the device was charging. |
| 3100 | H: 2 bits indicating the device-idle (doze) state: off, light, full |
| 3101 | I: the flashlight was on. |
| 3102 | J: wifi was on. |
| 3103 | K: wifi was running. |
| 3104 | L: video was playing. |
| 3105 | M: power save mode was on. |
| 3106 | |
| 3107 | Wakelock/wakereason struct: if D in the first token is set, |
| 3108 | TODO(adamlesinski): describe wakelock/wakereason struct. |
| 3109 | |
| 3110 | Event struct: if E in the first token is set, |
| 3111 | TODO(adamlesinski): describe the event struct. |
| 3112 | |
| 3113 | History step details struct: if D in the battery level int is set, |
| 3114 | TODO(adamlesinski): describe the history step details struct. |
| 3115 | |
| 3116 | Battery charge int: if F in the first token is set, an int representing the battery charge |
| 3117 | in coulombs follows. |
| 3118 | */ |
| 3119 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3120 | // Part of initial delta int that specifies the time delta. |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 3121 | static final int DELTA_TIME_MASK = 0x7ffff; |
| 3122 | static final int DELTA_TIME_LONG = 0x7ffff; // The delta is a following long |
| 3123 | static final int DELTA_TIME_INT = 0x7fffe; // The delta is a following int |
| 3124 | 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] | 3125 | // Flag in delta int: a new battery level int follows. |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 3126 | static final int DELTA_BATTERY_LEVEL_FLAG = 0x00080000; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3127 | // 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] | 3128 | static final int DELTA_STATE_FLAG = 0x00100000; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 3129 | // Flag in delta int: a new full state2 int follows. |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 3130 | static final int DELTA_STATE2_FLAG = 0x00200000; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3131 | // Flag in delta int: contains a wakelock or wakeReason tag. |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 3132 | static final int DELTA_WAKELOCK_FLAG = 0x00400000; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3133 | // Flag in delta int: contains an event description. |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 3134 | static final int DELTA_EVENT_FLAG = 0x00800000; |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 3135 | // Flag in delta int: contains the battery charge count in uAh. |
| 3136 | static final int DELTA_BATTERY_CHARGE_FLAG = 0x01000000; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3137 | // These upper bits are the frequently changing state bits. |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 3138 | static final int DELTA_STATE_MASK = 0xfe000000; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 3139 | |
| 3140 | // These are the pieces of battery state that are packed in to the upper bits of |
| 3141 | // 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] | 3142 | // in STATE_BATTERY_MASK. |
| 3143 | static final int STATE_BATTERY_MASK = 0xff000000; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 3144 | static final int STATE_BATTERY_STATUS_MASK = 0x00000007; |
| 3145 | static final int STATE_BATTERY_STATUS_SHIFT = 29; |
| 3146 | static final int STATE_BATTERY_HEALTH_MASK = 0x00000007; |
| 3147 | static final int STATE_BATTERY_HEALTH_SHIFT = 26; |
| 3148 | static final int STATE_BATTERY_PLUG_MASK = 0x00000003; |
| 3149 | static final int STATE_BATTERY_PLUG_SHIFT = 24; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3150 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 3151 | // We use the low bit of the battery state int to indicate that we have full details |
| 3152 | // from a battery level change. |
| 3153 | static final int BATTERY_DELTA_LEVEL_FLAG = 0x00000001; |
| 3154 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3155 | public void writeHistoryDelta(Parcel dest, HistoryItem cur, HistoryItem last) { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3156 | if (last == null || cur.cmd != HistoryItem.CMD_UPDATE) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3157 | dest.writeInt(DELTA_TIME_ABS); |
| 3158 | cur.writeToParcel(dest, 0); |
| 3159 | return; |
| 3160 | } |
| 3161 | |
| 3162 | final long deltaTime = cur.time - last.time; |
| 3163 | final int lastBatteryLevelInt = buildBatteryLevelInt(last); |
| 3164 | final int lastStateInt = buildStateInt(last); |
| 3165 | |
| 3166 | int deltaTimeToken; |
| 3167 | if (deltaTime < 0 || deltaTime > Integer.MAX_VALUE) { |
| 3168 | deltaTimeToken = DELTA_TIME_LONG; |
| 3169 | } else if (deltaTime >= DELTA_TIME_ABS) { |
| 3170 | deltaTimeToken = DELTA_TIME_INT; |
| 3171 | } else { |
| 3172 | deltaTimeToken = (int)deltaTime; |
| 3173 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3174 | int firstToken = deltaTimeToken | (cur.states&DELTA_STATE_MASK); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 3175 | final int includeStepDetails = mLastHistoryStepLevel > cur.batteryLevel |
| 3176 | ? BATTERY_DELTA_LEVEL_FLAG : 0; |
| 3177 | final boolean computeStepDetails = includeStepDetails != 0 |
| 3178 | || mLastHistoryStepDetails == null; |
| 3179 | final int batteryLevelInt = buildBatteryLevelInt(cur) | includeStepDetails; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3180 | final boolean batteryLevelIntChanged = batteryLevelInt != lastBatteryLevelInt; |
| 3181 | if (batteryLevelIntChanged) { |
| 3182 | firstToken |= DELTA_BATTERY_LEVEL_FLAG; |
| 3183 | } |
| 3184 | final int stateInt = buildStateInt(cur); |
| 3185 | final boolean stateIntChanged = stateInt != lastStateInt; |
| 3186 | if (stateIntChanged) { |
| 3187 | firstToken |= DELTA_STATE_FLAG; |
| 3188 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3189 | final boolean state2IntChanged = cur.states2 != last.states2; |
| 3190 | if (state2IntChanged) { |
| 3191 | firstToken |= DELTA_STATE2_FLAG; |
| 3192 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3193 | if (cur.wakelockTag != null || cur.wakeReasonTag != null) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3194 | firstToken |= DELTA_WAKELOCK_FLAG; |
| 3195 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3196 | if (cur.eventCode != HistoryItem.EVENT_NONE) { |
| 3197 | firstToken |= DELTA_EVENT_FLAG; |
| 3198 | } |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 3199 | |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 3200 | final boolean batteryChargeChanged = cur.batteryChargeUAh != last.batteryChargeUAh; |
| 3201 | if (batteryChargeChanged) { |
| 3202 | firstToken |= DELTA_BATTERY_CHARGE_FLAG; |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 3203 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3204 | dest.writeInt(firstToken); |
| 3205 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: firstToken=0x" + Integer.toHexString(firstToken) |
| 3206 | + " deltaTime=" + deltaTime); |
| 3207 | |
| 3208 | if (deltaTimeToken >= DELTA_TIME_INT) { |
| 3209 | if (deltaTimeToken == DELTA_TIME_INT) { |
| 3210 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: int deltaTime=" + (int)deltaTime); |
| 3211 | dest.writeInt((int)deltaTime); |
| 3212 | } else { |
| 3213 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: long deltaTime=" + deltaTime); |
| 3214 | dest.writeLong(deltaTime); |
| 3215 | } |
| 3216 | } |
| 3217 | if (batteryLevelIntChanged) { |
| 3218 | dest.writeInt(batteryLevelInt); |
| 3219 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: batteryToken=0x" |
| 3220 | + Integer.toHexString(batteryLevelInt) |
| 3221 | + " batteryLevel=" + cur.batteryLevel |
| 3222 | + " batteryTemp=" + cur.batteryTemperature |
| 3223 | + " batteryVolt=" + (int)cur.batteryVoltage); |
| 3224 | } |
| 3225 | if (stateIntChanged) { |
| 3226 | dest.writeInt(stateInt); |
| 3227 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: stateToken=0x" |
| 3228 | + Integer.toHexString(stateInt) |
| 3229 | + " batteryStatus=" + cur.batteryStatus |
| 3230 | + " batteryHealth=" + cur.batteryHealth |
| 3231 | + " batteryPlugType=" + cur.batteryPlugType |
| 3232 | + " states=0x" + Integer.toHexString(cur.states)); |
| 3233 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3234 | if (state2IntChanged) { |
| 3235 | dest.writeInt(cur.states2); |
| 3236 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: states2=0x" |
| 3237 | + Integer.toHexString(cur.states2)); |
| 3238 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3239 | if (cur.wakelockTag != null || cur.wakeReasonTag != null) { |
| 3240 | int wakeLockIndex; |
| 3241 | int wakeReasonIndex; |
| 3242 | if (cur.wakelockTag != null) { |
| 3243 | wakeLockIndex = writeHistoryTag(cur.wakelockTag); |
| 3244 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: wakelockTag=#" + cur.wakelockTag.poolIdx |
| 3245 | + " " + cur.wakelockTag.uid + ":" + cur.wakelockTag.string); |
| 3246 | } else { |
| 3247 | wakeLockIndex = 0xffff; |
| 3248 | } |
| 3249 | if (cur.wakeReasonTag != null) { |
| 3250 | wakeReasonIndex = writeHistoryTag(cur.wakeReasonTag); |
| 3251 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: wakeReasonTag=#" + cur.wakeReasonTag.poolIdx |
| 3252 | + " " + cur.wakeReasonTag.uid + ":" + cur.wakeReasonTag.string); |
| 3253 | } else { |
| 3254 | wakeReasonIndex = 0xffff; |
| 3255 | } |
| 3256 | dest.writeInt((wakeReasonIndex<<16) | wakeLockIndex); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3257 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3258 | if (cur.eventCode != HistoryItem.EVENT_NONE) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3259 | int index = writeHistoryTag(cur.eventTag); |
| 3260 | int codeAndIndex = (cur.eventCode&0xffff) | (index<<16); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3261 | dest.writeInt(codeAndIndex); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3262 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: event=" + cur.eventCode + " tag=#" |
| 3263 | + cur.eventTag.poolIdx + " " + cur.eventTag.uid + ":" |
| 3264 | + cur.eventTag.string); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3265 | } |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 3266 | if (computeStepDetails) { |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 3267 | if (mPlatformIdleStateCallback != null) { |
| 3268 | mCurHistoryStepDetails.statPlatformIdleState = |
| 3269 | mPlatformIdleStateCallback.getPlatformLowPowerStats(); |
| 3270 | if (DEBUG) Slog.i(TAG, "WRITE PlatformIdleState:" + |
| 3271 | mCurHistoryStepDetails.statPlatformIdleState); |
Ahmed ElArabawy | d8b4411 | 2017-05-23 21:25:02 +0000 | [diff] [blame] | 3272 | |
| 3273 | mCurHistoryStepDetails.statSubsystemPowerState = |
| 3274 | mPlatformIdleStateCallback.getSubsystemLowPowerStats(); |
| 3275 | if (DEBUG) Slog.i(TAG, "WRITE SubsystemPowerState:" + |
| 3276 | mCurHistoryStepDetails.statSubsystemPowerState); |
| 3277 | |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 3278 | } |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 3279 | computeHistoryStepDetails(mCurHistoryStepDetails, mLastHistoryStepDetails); |
| 3280 | if (includeStepDetails != 0) { |
| 3281 | mCurHistoryStepDetails.writeToParcel(dest); |
| 3282 | } |
| 3283 | cur.stepDetails = mCurHistoryStepDetails; |
| 3284 | mLastHistoryStepDetails = mCurHistoryStepDetails; |
| 3285 | } else { |
| 3286 | cur.stepDetails = null; |
| 3287 | } |
| 3288 | if (mLastHistoryStepLevel < cur.batteryLevel) { |
| 3289 | mLastHistoryStepDetails = null; |
| 3290 | } |
| 3291 | mLastHistoryStepLevel = cur.batteryLevel; |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 3292 | |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 3293 | if (batteryChargeChanged) { |
| 3294 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: batteryChargeUAh=" + cur.batteryChargeUAh); |
| 3295 | dest.writeInt(cur.batteryChargeUAh); |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 3296 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3297 | } |
| 3298 | |
| 3299 | private int buildBatteryLevelInt(HistoryItem h) { |
| 3300 | return ((((int)h.batteryLevel)<<25)&0xfe000000) |
Adam Lesinski | 3944c81 | 2015-11-13 15:54:59 -0800 | [diff] [blame] | 3301 | | ((((int)h.batteryTemperature)<<15)&0x01ff8000) |
| 3302 | | ((((int)h.batteryVoltage)<<1)&0x00007ffe); |
| 3303 | } |
| 3304 | |
| 3305 | private void readBatteryLevelInt(int batteryLevelInt, HistoryItem out) { |
| 3306 | out.batteryLevel = (byte)((batteryLevelInt & 0xfe000000) >>> 25); |
| 3307 | out.batteryTemperature = (short)((batteryLevelInt & 0x01ff8000) >>> 15); |
| 3308 | out.batteryVoltage = (char)((batteryLevelInt & 0x00007ffe) >>> 1); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3309 | } |
| 3310 | |
| 3311 | private int buildStateInt(HistoryItem h) { |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 3312 | int plugType = 0; |
| 3313 | if ((h.batteryPlugType&BatteryManager.BATTERY_PLUGGED_AC) != 0) { |
| 3314 | plugType = 1; |
| 3315 | } else if ((h.batteryPlugType&BatteryManager.BATTERY_PLUGGED_USB) != 0) { |
| 3316 | plugType = 2; |
| 3317 | } else if ((h.batteryPlugType&BatteryManager.BATTERY_PLUGGED_WIRELESS) != 0) { |
| 3318 | plugType = 3; |
| 3319 | } |
| 3320 | return ((h.batteryStatus&STATE_BATTERY_STATUS_MASK)<<STATE_BATTERY_STATUS_SHIFT) |
| 3321 | | ((h.batteryHealth&STATE_BATTERY_HEALTH_MASK)<<STATE_BATTERY_HEALTH_SHIFT) |
| 3322 | | ((plugType&STATE_BATTERY_PLUG_MASK)<<STATE_BATTERY_PLUG_SHIFT) |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 3323 | | (h.states&(~STATE_BATTERY_MASK)); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3324 | } |
| 3325 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 3326 | private void computeHistoryStepDetails(final HistoryStepDetails out, |
| 3327 | final HistoryStepDetails last) { |
| 3328 | final HistoryStepDetails tmp = last != null ? mTmpHistoryStepDetails : out; |
| 3329 | |
| 3330 | // Perform a CPU update right after we do this collection, so we have started |
| 3331 | // collecting good data for the next step. |
| 3332 | requestImmediateCpuUpdate(); |
| 3333 | |
| 3334 | if (last == null) { |
| 3335 | // We are not generating a delta, so all we need to do is reset the stats |
| 3336 | // we will later be doing a delta from. |
| 3337 | final int NU = mUidStats.size(); |
| 3338 | for (int i=0; i<NU; i++) { |
| 3339 | final BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 3340 | uid.mLastStepUserTime = uid.mCurStepUserTime; |
| 3341 | uid.mLastStepSystemTime = uid.mCurStepSystemTime; |
| 3342 | } |
| 3343 | mLastStepCpuUserTime = mCurStepCpuUserTime; |
| 3344 | mLastStepCpuSystemTime = mCurStepCpuSystemTime; |
| 3345 | mLastStepStatUserTime = mCurStepStatUserTime; |
| 3346 | mLastStepStatSystemTime = mCurStepStatSystemTime; |
| 3347 | mLastStepStatIOWaitTime = mCurStepStatIOWaitTime; |
| 3348 | mLastStepStatIrqTime = mCurStepStatIrqTime; |
| 3349 | mLastStepStatSoftIrqTime = mCurStepStatSoftIrqTime; |
| 3350 | mLastStepStatIdleTime = mCurStepStatIdleTime; |
| 3351 | tmp.clear(); |
| 3352 | return; |
| 3353 | } |
| 3354 | if (DEBUG) { |
| 3355 | Slog.d(TAG, "Step stats last: user=" + mLastStepCpuUserTime + " sys=" |
| 3356 | + mLastStepStatSystemTime + " io=" + mLastStepStatIOWaitTime |
| 3357 | + " irq=" + mLastStepStatIrqTime + " sirq=" |
| 3358 | + mLastStepStatSoftIrqTime + " idle=" + mLastStepStatIdleTime); |
| 3359 | Slog.d(TAG, "Step stats cur: user=" + mCurStepCpuUserTime + " sys=" |
| 3360 | + mCurStepStatSystemTime + " io=" + mCurStepStatIOWaitTime |
| 3361 | + " irq=" + mCurStepStatIrqTime + " sirq=" |
| 3362 | + mCurStepStatSoftIrqTime + " idle=" + mCurStepStatIdleTime); |
| 3363 | } |
| 3364 | out.userTime = (int)(mCurStepCpuUserTime - mLastStepCpuUserTime); |
| 3365 | out.systemTime = (int)(mCurStepCpuSystemTime - mLastStepCpuSystemTime); |
| 3366 | out.statUserTime = (int)(mCurStepStatUserTime - mLastStepStatUserTime); |
| 3367 | out.statSystemTime = (int)(mCurStepStatSystemTime - mLastStepStatSystemTime); |
| 3368 | out.statIOWaitTime = (int)(mCurStepStatIOWaitTime - mLastStepStatIOWaitTime); |
| 3369 | out.statIrqTime = (int)(mCurStepStatIrqTime - mLastStepStatIrqTime); |
| 3370 | out.statSoftIrqTime = (int)(mCurStepStatSoftIrqTime - mLastStepStatSoftIrqTime); |
| 3371 | out.statIdlTime = (int)(mCurStepStatIdleTime - mLastStepStatIdleTime); |
| 3372 | out.appCpuUid1 = out.appCpuUid2 = out.appCpuUid3 = -1; |
| 3373 | out.appCpuUTime1 = out.appCpuUTime2 = out.appCpuUTime3 = 0; |
| 3374 | out.appCpuSTime1 = out.appCpuSTime2 = out.appCpuSTime3 = 0; |
| 3375 | final int NU = mUidStats.size(); |
| 3376 | for (int i=0; i<NU; i++) { |
| 3377 | final BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 3378 | final int totalUTime = (int)(uid.mCurStepUserTime - uid.mLastStepUserTime); |
| 3379 | final int totalSTime = (int)(uid.mCurStepSystemTime - uid.mLastStepSystemTime); |
| 3380 | final int totalTime = totalUTime + totalSTime; |
| 3381 | uid.mLastStepUserTime = uid.mCurStepUserTime; |
| 3382 | uid.mLastStepSystemTime = uid.mCurStepSystemTime; |
| 3383 | if (totalTime <= (out.appCpuUTime3+out.appCpuSTime3)) { |
| 3384 | continue; |
| 3385 | } |
| 3386 | if (totalTime <= (out.appCpuUTime2+out.appCpuSTime2)) { |
| 3387 | out.appCpuUid3 = uid.mUid; |
| 3388 | out.appCpuUTime3 = totalUTime; |
| 3389 | out.appCpuSTime3 = totalSTime; |
| 3390 | } else { |
| 3391 | out.appCpuUid3 = out.appCpuUid2; |
| 3392 | out.appCpuUTime3 = out.appCpuUTime2; |
| 3393 | out.appCpuSTime3 = out.appCpuSTime2; |
| 3394 | if (totalTime <= (out.appCpuUTime1+out.appCpuSTime1)) { |
| 3395 | out.appCpuUid2 = uid.mUid; |
| 3396 | out.appCpuUTime2 = totalUTime; |
| 3397 | out.appCpuSTime2 = totalSTime; |
| 3398 | } else { |
| 3399 | out.appCpuUid2 = out.appCpuUid1; |
| 3400 | out.appCpuUTime2 = out.appCpuUTime1; |
| 3401 | out.appCpuSTime2 = out.appCpuSTime1; |
| 3402 | out.appCpuUid1 = uid.mUid; |
| 3403 | out.appCpuUTime1 = totalUTime; |
| 3404 | out.appCpuSTime1 = totalSTime; |
| 3405 | } |
| 3406 | } |
| 3407 | } |
| 3408 | mLastStepCpuUserTime = mCurStepCpuUserTime; |
| 3409 | mLastStepCpuSystemTime = mCurStepCpuSystemTime; |
| 3410 | mLastStepStatUserTime = mCurStepStatUserTime; |
| 3411 | mLastStepStatSystemTime = mCurStepStatSystemTime; |
| 3412 | mLastStepStatIOWaitTime = mCurStepStatIOWaitTime; |
| 3413 | mLastStepStatIrqTime = mCurStepStatIrqTime; |
| 3414 | mLastStepStatSoftIrqTime = mCurStepStatSoftIrqTime; |
| 3415 | mLastStepStatIdleTime = mCurStepStatIdleTime; |
| 3416 | } |
| 3417 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3418 | public void readHistoryDelta(Parcel src, HistoryItem cur) { |
| 3419 | int firstToken = src.readInt(); |
| 3420 | int deltaTimeToken = firstToken&DELTA_TIME_MASK; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3421 | cur.cmd = HistoryItem.CMD_UPDATE; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3422 | cur.numReadInts = 1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3423 | if (DEBUG) Slog.i(TAG, "READ DELTA: firstToken=0x" + Integer.toHexString(firstToken) |
| 3424 | + " deltaTimeToken=" + deltaTimeToken); |
| 3425 | |
| 3426 | if (deltaTimeToken < DELTA_TIME_ABS) { |
| 3427 | cur.time += deltaTimeToken; |
| 3428 | } else if (deltaTimeToken == DELTA_TIME_ABS) { |
| 3429 | cur.time = src.readLong(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3430 | cur.numReadInts += 2; |
| 3431 | if (DEBUG) Slog.i(TAG, "READ DELTA: ABS time=" + cur.time); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3432 | cur.readFromParcel(src); |
| 3433 | return; |
| 3434 | } else if (deltaTimeToken == DELTA_TIME_INT) { |
| 3435 | int delta = src.readInt(); |
| 3436 | cur.time += delta; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3437 | cur.numReadInts += 1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3438 | if (DEBUG) Slog.i(TAG, "READ DELTA: time delta=" + delta + " new time=" + cur.time); |
| 3439 | } else { |
| 3440 | long delta = src.readLong(); |
| 3441 | if (DEBUG) Slog.i(TAG, "READ DELTA: time delta=" + delta + " new time=" + cur.time); |
| 3442 | cur.time += delta; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3443 | cur.numReadInts += 2; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3444 | } |
| 3445 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 3446 | final int batteryLevelInt; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3447 | if ((firstToken&DELTA_BATTERY_LEVEL_FLAG) != 0) { |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 3448 | batteryLevelInt = src.readInt(); |
Adam Lesinski | 3944c81 | 2015-11-13 15:54:59 -0800 | [diff] [blame] | 3449 | readBatteryLevelInt(batteryLevelInt, cur); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3450 | cur.numReadInts += 1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3451 | if (DEBUG) Slog.i(TAG, "READ DELTA: batteryToken=0x" |
| 3452 | + Integer.toHexString(batteryLevelInt) |
| 3453 | + " batteryLevel=" + cur.batteryLevel |
| 3454 | + " batteryTemp=" + cur.batteryTemperature |
| 3455 | + " batteryVolt=" + (int)cur.batteryVoltage); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 3456 | } else { |
| 3457 | batteryLevelInt = 0; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3458 | } |
| 3459 | |
| 3460 | if ((firstToken&DELTA_STATE_FLAG) != 0) { |
| 3461 | int stateInt = src.readInt(); |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 3462 | cur.states = (firstToken&DELTA_STATE_MASK) | (stateInt&(~STATE_BATTERY_MASK)); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 3463 | cur.batteryStatus = (byte)((stateInt>>STATE_BATTERY_STATUS_SHIFT) |
| 3464 | & STATE_BATTERY_STATUS_MASK); |
| 3465 | cur.batteryHealth = (byte)((stateInt>>STATE_BATTERY_HEALTH_SHIFT) |
| 3466 | & STATE_BATTERY_HEALTH_MASK); |
| 3467 | cur.batteryPlugType = (byte)((stateInt>>STATE_BATTERY_PLUG_SHIFT) |
| 3468 | & STATE_BATTERY_PLUG_MASK); |
| 3469 | switch (cur.batteryPlugType) { |
| 3470 | case 1: |
| 3471 | cur.batteryPlugType = BatteryManager.BATTERY_PLUGGED_AC; |
| 3472 | break; |
| 3473 | case 2: |
| 3474 | cur.batteryPlugType = BatteryManager.BATTERY_PLUGGED_USB; |
| 3475 | break; |
| 3476 | case 3: |
| 3477 | cur.batteryPlugType = BatteryManager.BATTERY_PLUGGED_WIRELESS; |
| 3478 | break; |
| 3479 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3480 | cur.numReadInts += 1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3481 | if (DEBUG) Slog.i(TAG, "READ DELTA: stateToken=0x" |
| 3482 | + Integer.toHexString(stateInt) |
| 3483 | + " batteryStatus=" + cur.batteryStatus |
| 3484 | + " batteryHealth=" + cur.batteryHealth |
| 3485 | + " batteryPlugType=" + cur.batteryPlugType |
| 3486 | + " states=0x" + Integer.toHexString(cur.states)); |
| 3487 | } else { |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 3488 | cur.states = (firstToken&DELTA_STATE_MASK) | (cur.states&(~STATE_BATTERY_MASK)); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3489 | } |
| 3490 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3491 | if ((firstToken&DELTA_STATE2_FLAG) != 0) { |
| 3492 | cur.states2 = src.readInt(); |
| 3493 | if (DEBUG) Slog.i(TAG, "READ DELTA: states2=0x" |
| 3494 | + Integer.toHexString(cur.states2)); |
| 3495 | } |
| 3496 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3497 | if ((firstToken&DELTA_WAKELOCK_FLAG) != 0) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3498 | int indexes = src.readInt(); |
| 3499 | int wakeLockIndex = indexes&0xffff; |
| 3500 | int wakeReasonIndex = (indexes>>16)&0xffff; |
| 3501 | if (wakeLockIndex != 0xffff) { |
| 3502 | cur.wakelockTag = cur.localWakelockTag; |
| 3503 | readHistoryTag(wakeLockIndex, cur.wakelockTag); |
| 3504 | if (DEBUG) Slog.i(TAG, "READ DELTA: wakelockTag=#" + cur.wakelockTag.poolIdx |
| 3505 | + " " + cur.wakelockTag.uid + ":" + cur.wakelockTag.string); |
| 3506 | } else { |
| 3507 | cur.wakelockTag = null; |
| 3508 | } |
| 3509 | if (wakeReasonIndex != 0xffff) { |
| 3510 | cur.wakeReasonTag = cur.localWakeReasonTag; |
| 3511 | readHistoryTag(wakeReasonIndex, cur.wakeReasonTag); |
| 3512 | if (DEBUG) Slog.i(TAG, "READ DELTA: wakeReasonTag=#" + cur.wakeReasonTag.poolIdx |
| 3513 | + " " + cur.wakeReasonTag.uid + ":" + cur.wakeReasonTag.string); |
| 3514 | } else { |
| 3515 | cur.wakeReasonTag = null; |
| 3516 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3517 | cur.numReadInts += 1; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3518 | } else { |
| 3519 | cur.wakelockTag = null; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3520 | cur.wakeReasonTag = null; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3521 | } |
| 3522 | |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3523 | if ((firstToken&DELTA_EVENT_FLAG) != 0) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3524 | cur.eventTag = cur.localEventTag; |
| 3525 | final int codeAndIndex = src.readInt(); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3526 | cur.eventCode = (codeAndIndex&0xffff); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3527 | final int index = ((codeAndIndex>>16)&0xffff); |
| 3528 | readHistoryTag(index, cur.eventTag); |
| 3529 | cur.numReadInts += 1; |
| 3530 | if (DEBUG) Slog.i(TAG, "READ DELTA: event=" + cur.eventCode + " tag=#" |
| 3531 | + cur.eventTag.poolIdx + " " + cur.eventTag.uid + ":" |
| 3532 | + cur.eventTag.string); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3533 | } else { |
| 3534 | cur.eventCode = HistoryItem.EVENT_NONE; |
| 3535 | } |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 3536 | |
| 3537 | if ((batteryLevelInt&BATTERY_DELTA_LEVEL_FLAG) != 0) { |
| 3538 | cur.stepDetails = mReadHistoryStepDetails; |
| 3539 | cur.stepDetails.readFromParcel(src); |
| 3540 | } else { |
| 3541 | cur.stepDetails = null; |
| 3542 | } |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 3543 | |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 3544 | if ((firstToken&DELTA_BATTERY_CHARGE_FLAG) != 0) { |
| 3545 | cur.batteryChargeUAh = src.readInt(); |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 3546 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3547 | } |
| 3548 | |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 3549 | @Override |
| 3550 | public void commitCurrentHistoryBatchLocked() { |
| 3551 | mHistoryLastWritten.cmd = HistoryItem.CMD_NULL; |
| 3552 | } |
| 3553 | |
Narayan Kamath | 5a5a7fe | 2018-02-05 17:30:06 +0000 | [diff] [blame] | 3554 | void addHistoryBufferLocked(long elapsedRealtimeMs, HistoryItem cur) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3555 | if (!mHaveBatteryLevel || !mRecordingHistory) { |
| 3556 | return; |
| 3557 | } |
| 3558 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3559 | final long timeDiff = (mHistoryBaseTime+elapsedRealtimeMs) - mHistoryLastWritten.time; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3560 | final int diffStates = mHistoryLastWritten.states^(cur.states&mActiveHistoryStates); |
| 3561 | final int diffStates2 = mHistoryLastWritten.states2^(cur.states2&mActiveHistoryStates2); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3562 | final int lastDiffStates = mHistoryLastWritten.states^mHistoryLastLastWritten.states; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3563 | final int lastDiffStates2 = mHistoryLastWritten.states2^mHistoryLastLastWritten.states2; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3564 | if (DEBUG) Slog.i(TAG, "ADD: tdelta=" + timeDiff + " diff=" |
| 3565 | + Integer.toHexString(diffStates) + " lastDiff=" |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3566 | + Integer.toHexString(lastDiffStates) + " diff2=" |
| 3567 | + Integer.toHexString(diffStates2) + " lastDiff2=" |
| 3568 | + Integer.toHexString(lastDiffStates2)); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3569 | if (mHistoryBufferLastPos >= 0 && mHistoryLastWritten.cmd == HistoryItem.CMD_UPDATE |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3570 | && timeDiff < 1000 && (diffStates&lastDiffStates) == 0 |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3571 | && (diffStates2&lastDiffStates2) == 0 |
| 3572 | && (mHistoryLastWritten.wakelockTag == null || cur.wakelockTag == null) |
| 3573 | && (mHistoryLastWritten.wakeReasonTag == null || cur.wakeReasonTag == null) |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 3574 | && mHistoryLastWritten.stepDetails == null |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3575 | && (mHistoryLastWritten.eventCode == HistoryItem.EVENT_NONE |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3576 | || cur.eventCode == HistoryItem.EVENT_NONE) |
| 3577 | && mHistoryLastWritten.batteryLevel == cur.batteryLevel |
| 3578 | && mHistoryLastWritten.batteryStatus == cur.batteryStatus |
| 3579 | && mHistoryLastWritten.batteryHealth == cur.batteryHealth |
| 3580 | && mHistoryLastWritten.batteryPlugType == cur.batteryPlugType |
| 3581 | && mHistoryLastWritten.batteryTemperature == cur.batteryTemperature |
| 3582 | && mHistoryLastWritten.batteryVoltage == cur.batteryVoltage) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3583 | // 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] | 3584 | // 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] | 3585 | // as long as no bit has changed both between now and the last entry, as |
| 3586 | // well as the last entry and the one before it (so we capture any toggles). |
| 3587 | if (DEBUG) Slog.i(TAG, "ADD: rewinding back to " + mHistoryBufferLastPos); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3588 | mHistoryBuffer.setDataSize(mHistoryBufferLastPos); |
| 3589 | mHistoryBuffer.setDataPosition(mHistoryBufferLastPos); |
| 3590 | mHistoryBufferLastPos = -1; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3591 | elapsedRealtimeMs = mHistoryLastWritten.time - mHistoryBaseTime; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3592 | // If the last written history had a wakelock tag, we need to retain it. |
| 3593 | // Note that the condition above made sure that we aren't in a case where |
| 3594 | // both it and the current history item have a wakelock tag. |
| 3595 | if (mHistoryLastWritten.wakelockTag != null) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3596 | cur.wakelockTag = cur.localWakelockTag; |
| 3597 | cur.wakelockTag.setTo(mHistoryLastWritten.wakelockTag); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3598 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3599 | // If the last written history had a wake reason tag, we need to retain it. |
| 3600 | // Note that the condition above made sure that we aren't in a case where |
| 3601 | // both it and the current history item have a wakelock tag. |
| 3602 | if (mHistoryLastWritten.wakeReasonTag != null) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3603 | cur.wakeReasonTag = cur.localWakeReasonTag; |
| 3604 | cur.wakeReasonTag.setTo(mHistoryLastWritten.wakeReasonTag); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3605 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3606 | // If the last written history had an event, we need to retain it. |
| 3607 | // Note that the condition above made sure that we aren't in a case where |
| 3608 | // both it and the current history item have an event. |
| 3609 | if (mHistoryLastWritten.eventCode != HistoryItem.EVENT_NONE) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3610 | cur.eventCode = mHistoryLastWritten.eventCode; |
| 3611 | cur.eventTag = cur.localEventTag; |
| 3612 | cur.eventTag.setTo(mHistoryLastWritten.eventTag); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3613 | } |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 3614 | mHistoryLastWritten.setTo(mHistoryLastLastWritten); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3615 | } |
| 3616 | |
Adam Lesinski | 4548978 | 2016-12-15 23:45:17 -0800 | [diff] [blame] | 3617 | boolean recordResetDueToOverflow = false; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3618 | final int dataSize = mHistoryBuffer.dataSize(); |
Adam Lesinski | 4548978 | 2016-12-15 23:45:17 -0800 | [diff] [blame] | 3619 | if (dataSize >= MAX_MAX_HISTORY_BUFFER*3) { |
| 3620 | // Clients can't deal with history buffers this large. This only |
| 3621 | // really happens when the device is on charger and interacted with |
| 3622 | // for long periods of time, like in retail mode. Since the device is |
| 3623 | // most likely charged, when unplugged, stats would have reset anyways. |
| 3624 | // Reset the stats and mark that we overflowed. |
| 3625 | // b/32540341 |
| 3626 | resetAllStatsLocked(); |
| 3627 | |
| 3628 | // Mark that we want to set *OVERFLOW* event and the RESET:START |
| 3629 | // events. |
| 3630 | recordResetDueToOverflow = true; |
| 3631 | |
| 3632 | } else if (dataSize >= MAX_HISTORY_BUFFER) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3633 | if (!mHistoryOverflow) { |
| 3634 | mHistoryOverflow = true; |
Narayan Kamath | 5a5a7fe | 2018-02-05 17:30:06 +0000 | [diff] [blame] | 3635 | addHistoryBufferLocked(elapsedRealtimeMs, HistoryItem.CMD_UPDATE, cur); |
| 3636 | addHistoryBufferLocked(elapsedRealtimeMs, HistoryItem.CMD_OVERFLOW, cur); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3637 | return; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3638 | } |
| 3639 | |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3640 | // After overflow, we allow various bit-wise states to settle to 0. |
| 3641 | boolean writeAnyway = false; |
| 3642 | final int curStates = cur.states & HistoryItem.SETTLE_TO_ZERO_STATES |
| 3643 | & mActiveHistoryStates; |
| 3644 | if (mHistoryLastWritten.states != curStates) { |
| 3645 | // mActiveHistoryStates keeps track of which bits in .states are now being |
| 3646 | // forced to 0. |
| 3647 | int old = mActiveHistoryStates; |
| 3648 | mActiveHistoryStates &= curStates | ~HistoryItem.SETTLE_TO_ZERO_STATES; |
| 3649 | writeAnyway |= old != mActiveHistoryStates; |
| 3650 | } |
| 3651 | final int curStates2 = cur.states2 & HistoryItem.SETTLE_TO_ZERO_STATES2 |
| 3652 | & mActiveHistoryStates2; |
| 3653 | if (mHistoryLastWritten.states2 != curStates2) { |
| 3654 | // mActiveHistoryStates2 keeps track of which bits in .states2 are now being |
| 3655 | // forced to 0. |
| 3656 | int old = mActiveHistoryStates2; |
| 3657 | mActiveHistoryStates2 &= curStates2 | ~HistoryItem.SETTLE_TO_ZERO_STATES2; |
| 3658 | writeAnyway |= old != mActiveHistoryStates2; |
| 3659 | } |
| 3660 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3661 | // Once we've reached the maximum number of items, we only |
| 3662 | // record changes to the battery level and the most interesting states. |
| 3663 | // Once we've reached the maximum maximum number of items, we only |
| 3664 | // record changes to the battery level. |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3665 | if (!writeAnyway && mHistoryLastWritten.batteryLevel == cur.batteryLevel && |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3666 | (dataSize >= MAX_MAX_HISTORY_BUFFER |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3667 | || ((mHistoryLastWritten.states^cur.states) |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3668 | & HistoryItem.MOST_INTERESTING_STATES) == 0 |
| 3669 | || ((mHistoryLastWritten.states2^cur.states2) |
| 3670 | & HistoryItem.MOST_INTERESTING_STATES2) == 0)) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3671 | return; |
| 3672 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3673 | |
Narayan Kamath | 5a5a7fe | 2018-02-05 17:30:06 +0000 | [diff] [blame] | 3674 | addHistoryBufferLocked(elapsedRealtimeMs, HistoryItem.CMD_UPDATE, cur); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3675 | return; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3676 | } |
| 3677 | |
Adam Lesinski | 4548978 | 2016-12-15 23:45:17 -0800 | [diff] [blame] | 3678 | if (dataSize == 0 || recordResetDueToOverflow) { |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 3679 | // The history is currently empty; we need it to start with a time stamp. |
| 3680 | cur.currentTime = System.currentTimeMillis(); |
Adam Lesinski | 4548978 | 2016-12-15 23:45:17 -0800 | [diff] [blame] | 3681 | if (recordResetDueToOverflow) { |
Narayan Kamath | 5a5a7fe | 2018-02-05 17:30:06 +0000 | [diff] [blame] | 3682 | addHistoryBufferLocked(elapsedRealtimeMs, HistoryItem.CMD_OVERFLOW, cur); |
Adam Lesinski | 4548978 | 2016-12-15 23:45:17 -0800 | [diff] [blame] | 3683 | } |
Narayan Kamath | 5a5a7fe | 2018-02-05 17:30:06 +0000 | [diff] [blame] | 3684 | addHistoryBufferLocked(elapsedRealtimeMs, HistoryItem.CMD_RESET, cur); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 3685 | } |
Narayan Kamath | 5a5a7fe | 2018-02-05 17:30:06 +0000 | [diff] [blame] | 3686 | addHistoryBufferLocked(elapsedRealtimeMs, HistoryItem.CMD_UPDATE, cur); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3687 | } |
| 3688 | |
Narayan Kamath | 5a5a7fe | 2018-02-05 17:30:06 +0000 | [diff] [blame] | 3689 | private void addHistoryBufferLocked(long elapsedRealtimeMs, byte cmd, HistoryItem cur) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3690 | if (mIteratingHistory) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3691 | throw new IllegalStateException("Can't do this while iterating history!"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3692 | } |
| 3693 | mHistoryBufferLastPos = mHistoryBuffer.dataPosition(); |
| 3694 | mHistoryLastLastWritten.setTo(mHistoryLastWritten); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3695 | mHistoryLastWritten.setTo(mHistoryBaseTime + elapsedRealtimeMs, cmd, cur); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3696 | mHistoryLastWritten.states &= mActiveHistoryStates; |
| 3697 | mHistoryLastWritten.states2 &= mActiveHistoryStates2; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3698 | writeHistoryDelta(mHistoryBuffer, mHistoryLastWritten, mHistoryLastLastWritten); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3699 | mLastHistoryElapsedRealtime = elapsedRealtimeMs; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3700 | cur.wakelockTag = null; |
| 3701 | cur.wakeReasonTag = null; |
| 3702 | cur.eventCode = HistoryItem.EVENT_NONE; |
| 3703 | cur.eventTag = null; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3704 | if (DEBUG_HISTORY) Slog.i(TAG, "Writing history buffer: was " + mHistoryBufferLastPos |
| 3705 | + " now " + mHistoryBuffer.dataPosition() |
| 3706 | + " size is now " + mHistoryBuffer.dataSize()); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3707 | } |
| 3708 | |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 3709 | int mChangedStates = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3710 | int mChangedStates2 = 0; |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 3711 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3712 | void addHistoryRecordLocked(long elapsedRealtimeMs, long uptimeMs) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3713 | if (mTrackRunningHistoryElapsedRealtime != 0) { |
| 3714 | final long diffElapsed = elapsedRealtimeMs - mTrackRunningHistoryElapsedRealtime; |
| 3715 | final long diffUptime = uptimeMs - mTrackRunningHistoryUptime; |
| 3716 | if (diffUptime < (diffElapsed-20)) { |
| 3717 | final long wakeElapsedTime = elapsedRealtimeMs - (diffElapsed - diffUptime); |
| 3718 | mHistoryAddTmp.setTo(mHistoryLastWritten); |
| 3719 | mHistoryAddTmp.wakelockTag = null; |
| 3720 | mHistoryAddTmp.wakeReasonTag = null; |
| 3721 | mHistoryAddTmp.eventCode = HistoryItem.EVENT_NONE; |
| 3722 | mHistoryAddTmp.states &= ~HistoryItem.STATE_CPU_RUNNING_FLAG; |
Narayan Kamath | 5a5a7fe | 2018-02-05 17:30:06 +0000 | [diff] [blame] | 3723 | addHistoryRecordInnerLocked(wakeElapsedTime, mHistoryAddTmp); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3724 | } |
| 3725 | } |
| 3726 | mHistoryCur.states |= HistoryItem.STATE_CPU_RUNNING_FLAG; |
| 3727 | mTrackRunningHistoryElapsedRealtime = elapsedRealtimeMs; |
| 3728 | mTrackRunningHistoryUptime = uptimeMs; |
Narayan Kamath | 5a5a7fe | 2018-02-05 17:30:06 +0000 | [diff] [blame] | 3729 | addHistoryRecordInnerLocked(elapsedRealtimeMs, mHistoryCur); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3730 | } |
| 3731 | |
Narayan Kamath | 5a5a7fe | 2018-02-05 17:30:06 +0000 | [diff] [blame] | 3732 | void addHistoryRecordInnerLocked(long elapsedRealtimeMs, HistoryItem cur) { |
| 3733 | addHistoryBufferLocked(elapsedRealtimeMs, cur); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3734 | |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 3735 | if (!USE_OLD_HISTORY) { |
| 3736 | return; |
| 3737 | } |
| 3738 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3739 | if (!mHaveBatteryLevel || !mRecordingHistory) { |
| 3740 | return; |
| 3741 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3742 | |
| 3743 | // If the current time is basically the same as the last time, |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 3744 | // and no states have since the last recorded entry changed and |
| 3745 | // are now resetting back to their original value, then just collapse |
| 3746 | // into one record. |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3747 | if (mHistoryEnd != null && mHistoryEnd.cmd == HistoryItem.CMD_UPDATE |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3748 | && (mHistoryBaseTime+elapsedRealtimeMs) < (mHistoryEnd.time+1000) |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3749 | && ((mHistoryEnd.states^cur.states)&mChangedStates&mActiveHistoryStates) == 0 |
| 3750 | && ((mHistoryEnd.states2^cur.states2)&mChangedStates2&mActiveHistoryStates2) == 0) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3751 | // If the current is the same as the one before, then we no |
| 3752 | // longer need the entry. |
| 3753 | if (mHistoryLastEnd != null && mHistoryLastEnd.cmd == HistoryItem.CMD_UPDATE |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3754 | && (mHistoryBaseTime+elapsedRealtimeMs) < (mHistoryEnd.time+500) |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3755 | && mHistoryLastEnd.sameNonEvent(cur)) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3756 | mHistoryLastEnd.next = null; |
| 3757 | mHistoryEnd.next = mHistoryCache; |
| 3758 | mHistoryCache = mHistoryEnd; |
| 3759 | mHistoryEnd = mHistoryLastEnd; |
| 3760 | mHistoryLastEnd = null; |
| 3761 | } else { |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3762 | mChangedStates |= mHistoryEnd.states^(cur.states&mActiveHistoryStates); |
| 3763 | mChangedStates2 |= mHistoryEnd.states^(cur.states2&mActiveHistoryStates2); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3764 | mHistoryEnd.setTo(mHistoryEnd.time, HistoryItem.CMD_UPDATE, cur); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3765 | } |
| 3766 | return; |
| 3767 | } |
| 3768 | |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 3769 | mChangedStates = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3770 | mChangedStates2 = 0; |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 3771 | |
| 3772 | if (mNumHistoryItems == MAX_HISTORY_ITEMS |
| 3773 | || mNumHistoryItems == MAX_MAX_HISTORY_ITEMS) { |
Narayan Kamath | 5a5a7fe | 2018-02-05 17:30:06 +0000 | [diff] [blame] | 3774 | addHistoryBufferLocked(elapsedRealtimeMs, HistoryItem.CMD_OVERFLOW, cur); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 3775 | } |
| 3776 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3777 | if (mNumHistoryItems >= MAX_HISTORY_ITEMS) { |
| 3778 | // Once we've reached the maximum number of items, we only |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 3779 | // record changes to the battery level and the most interesting states. |
| 3780 | // Once we've reached the maximum maximum number of items, we only |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3781 | // record changes to the battery level. |
| 3782 | if (mHistoryEnd != null && mHistoryEnd.batteryLevel |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3783 | == cur.batteryLevel && |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 3784 | (mNumHistoryItems >= MAX_MAX_HISTORY_ITEMS |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3785 | || ((mHistoryEnd.states^(cur.states&mActiveHistoryStates)) |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 3786 | & HistoryItem.MOST_INTERESTING_STATES) == 0)) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3787 | return; |
| 3788 | } |
| 3789 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3790 | |
Narayan Kamath | 5a5a7fe | 2018-02-05 17:30:06 +0000 | [diff] [blame] | 3791 | addHistoryBufferLocked(elapsedRealtimeMs, HistoryItem.CMD_UPDATE, cur); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3792 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3793 | |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3794 | public void addHistoryEventLocked(long elapsedRealtimeMs, long uptimeMs, int code, |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3795 | String name, int uid) { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3796 | mHistoryCur.eventCode = code; |
| 3797 | mHistoryCur.eventTag = mHistoryCur.localEventTag; |
| 3798 | mHistoryCur.eventTag.string = name; |
| 3799 | mHistoryCur.eventTag.uid = uid; |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 3800 | addHistoryRecordLocked(elapsedRealtimeMs, uptimeMs); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3801 | } |
| 3802 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3803 | void addHistoryRecordLocked(long elapsedRealtimeMs, long uptimeMs, byte cmd, HistoryItem cur) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3804 | HistoryItem rec = mHistoryCache; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3805 | if (rec != null) { |
| 3806 | mHistoryCache = rec.next; |
| 3807 | } else { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3808 | rec = new HistoryItem(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3809 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3810 | rec.setTo(mHistoryBaseTime + elapsedRealtimeMs, cmd, cur); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3811 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3812 | addHistoryRecordLocked(rec); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3813 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3814 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3815 | void addHistoryRecordLocked(HistoryItem rec) { |
| 3816 | mNumHistoryItems++; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3817 | rec.next = null; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3818 | mHistoryLastEnd = mHistoryEnd; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3819 | if (mHistoryEnd != null) { |
| 3820 | mHistoryEnd.next = rec; |
| 3821 | mHistoryEnd = rec; |
| 3822 | } else { |
| 3823 | mHistory = mHistoryEnd = rec; |
| 3824 | } |
| 3825 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3826 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3827 | void clearHistoryLocked() { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3828 | if (DEBUG_HISTORY) Slog.i(TAG, "********** CLEARING HISTORY!"); |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 3829 | if (USE_OLD_HISTORY) { |
| 3830 | if (mHistory != null) { |
| 3831 | mHistoryEnd.next = mHistoryCache; |
| 3832 | mHistoryCache = mHistory; |
| 3833 | mHistory = mHistoryLastEnd = mHistoryEnd = null; |
| 3834 | } |
| 3835 | mNumHistoryItems = 0; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3836 | } |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 3837 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3838 | mHistoryBaseTime = 0; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3839 | mLastHistoryElapsedRealtime = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3840 | mTrackRunningHistoryElapsedRealtime = 0; |
| 3841 | mTrackRunningHistoryUptime = 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3842 | |
| 3843 | mHistoryBuffer.setDataSize(0); |
| 3844 | mHistoryBuffer.setDataPosition(0); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3845 | mHistoryBuffer.setDataCapacity(MAX_HISTORY_BUFFER / 2); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3846 | mHistoryLastLastWritten.clear(); |
| 3847 | mHistoryLastWritten.clear(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3848 | mHistoryTagPool.clear(); |
| 3849 | mNextHistoryTagIdx = 0; |
| 3850 | mNumHistoryTagChars = 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3851 | mHistoryBufferLastPos = -1; |
| 3852 | mHistoryOverflow = false; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3853 | mActiveHistoryStates = 0xffffffff; |
| 3854 | mActiveHistoryStates2 = 0xffffffff; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3855 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3856 | |
Andreas Gampe | 3f24e69 | 2018-02-05 13:24:28 -0800 | [diff] [blame] | 3857 | @GuardedBy("this") |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 3858 | public void updateTimeBasesLocked(boolean unplugged, int screenState, long uptime, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3859 | long realtime) { |
Mike Ma | a772475 | 2017-10-10 15:29:25 -0700 | [diff] [blame] | 3860 | final boolean screenOff = !isScreenOn(screenState); |
Sudheer Shanka | 9d4ed7c | 2017-07-08 22:10:45 -0700 | [diff] [blame] | 3861 | final boolean updateOnBatteryTimeBase = unplugged != mOnBatteryTimeBase.isRunning(); |
| 3862 | final boolean updateOnBatteryScreenOffTimeBase = |
| 3863 | (unplugged && screenOff) != mOnBatteryScreenOffTimeBase.isRunning(); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3864 | |
Sudheer Shanka | 9d4ed7c | 2017-07-08 22:10:45 -0700 | [diff] [blame] | 3865 | if (updateOnBatteryScreenOffTimeBase || updateOnBatteryTimeBase) { |
| 3866 | if (updateOnBatteryScreenOffTimeBase) { |
| 3867 | updateKernelWakelocksLocked(); |
| 3868 | updateBatteryPropertiesLocked(); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3869 | } |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 3870 | // This if{} is only necessary due to SCREEN_OFF_RPM_STATS_ENABLED, which exists because |
| 3871 | // updateRpmStatsLocked is too slow to run each screen change. When the speed is |
| 3872 | // improved, remove the surrounding if{}. |
| 3873 | if (SCREEN_OFF_RPM_STATS_ENABLED || updateOnBatteryTimeBase) { |
| 3874 | updateRpmStatsLocked(); // if either OnBattery or OnBatteryScreenOff timebase changes. |
| 3875 | } |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 3876 | if (DEBUG_ENERGY_CPU) { |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 3877 | Slog.d(TAG, "Updating cpu time because screen is now " |
| 3878 | + Display.stateToString(screenState) |
Sudheer Shanka | 9d4ed7c | 2017-07-08 22:10:45 -0700 | [diff] [blame] | 3879 | + " and battery is " + (unplugged ? "on" : "off")); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3880 | } |
Sudheer Shanka | 9d4ed7c | 2017-07-08 22:10:45 -0700 | [diff] [blame] | 3881 | |
| 3882 | mOnBatteryTimeBase.setRunning(unplugged, uptime, realtime); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 3883 | if (updateOnBatteryTimeBase) { |
| 3884 | for (int i = mUidStats.size() - 1; i >= 0; --i) { |
| 3885 | mUidStats.valueAt(i).updateOnBatteryBgTimeBase(uptime, realtime); |
Sudheer Shanka | 9d4ed7c | 2017-07-08 22:10:45 -0700 | [diff] [blame] | 3886 | } |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 3887 | } |
| 3888 | if (updateOnBatteryScreenOffTimeBase) { |
| 3889 | mOnBatteryScreenOffTimeBase.setRunning(unplugged && screenOff, uptime, realtime); |
| 3890 | for (int i = mUidStats.size() - 1; i >= 0; --i) { |
| 3891 | mUidStats.valueAt(i).updateOnBatteryScreenOffBgTimeBase(uptime, realtime); |
Sudheer Shanka | 9d4ed7c | 2017-07-08 22:10:45 -0700 | [diff] [blame] | 3892 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3893 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3894 | } |
| 3895 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 3896 | |
Adam Lesinski | e1f480d | 2017-02-15 18:51:23 -0800 | [diff] [blame] | 3897 | private void updateBatteryPropertiesLocked() { |
| 3898 | try { |
| 3899 | IBatteryPropertiesRegistrar registrar = IBatteryPropertiesRegistrar.Stub.asInterface( |
| 3900 | ServiceManager.getService("batteryproperties")); |
| 3901 | registrar.scheduleUpdate(); |
| 3902 | } catch (RemoteException e) { |
| 3903 | // Ignore. |
| 3904 | } |
| 3905 | } |
| 3906 | |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3907 | public void addIsolatedUidLocked(int isolatedUid, int appUid) { |
| 3908 | mIsolatedUids.put(isolatedUid, appUid); |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 3909 | StatsLog.write(StatsLog.ISOLATED_UID_CHANGED, appUid, isolatedUid, |
| 3910 | StatsLog.ISOLATED_UID_CHANGED__EVENT__CREATED); |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 3911 | final Uid u = getUidStatsLocked(appUid); |
| 3912 | u.addIsolatedUid(isolatedUid); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3913 | } |
| 3914 | |
Adam Lesinski | 61db88f | 2015-07-01 15:05:07 -0700 | [diff] [blame] | 3915 | /** |
| 3916 | * Schedules a read of the latest cpu times before removing the isolated UID. |
| 3917 | * @see #removeIsolatedUidLocked(int) |
| 3918 | */ |
| 3919 | public void scheduleRemoveIsolatedUidLocked(int isolatedUid, int appUid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3920 | int curUid = mIsolatedUids.get(isolatedUid, -1); |
| 3921 | if (curUid == appUid) { |
Adam Lesinski | 61db88f | 2015-07-01 15:05:07 -0700 | [diff] [blame] | 3922 | if (mExternalSync != null) { |
| 3923 | mExternalSync.scheduleCpuSyncDueToRemovedUid(isolatedUid); |
| 3924 | } |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3925 | } |
| 3926 | } |
| 3927 | |
Adam Lesinski | 61db88f | 2015-07-01 15:05:07 -0700 | [diff] [blame] | 3928 | /** |
| 3929 | * This should only be called after the cpu times have been read. |
| 3930 | * @see #scheduleRemoveIsolatedUidLocked(int, int) |
| 3931 | */ |
Andreas Gampe | 3f24e69 | 2018-02-05 13:24:28 -0800 | [diff] [blame] | 3932 | @GuardedBy("this") |
Adam Lesinski | 61db88f | 2015-07-01 15:05:07 -0700 | [diff] [blame] | 3933 | public void removeIsolatedUidLocked(int isolatedUid) { |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 3934 | StatsLog.write( |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 3935 | StatsLog.ISOLATED_UID_CHANGED, mIsolatedUids.get(isolatedUid, -1), |
| 3936 | isolatedUid, StatsLog.ISOLATED_UID_CHANGED__EVENT__REMOVED); |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 3937 | final int idx = mIsolatedUids.indexOfKey(isolatedUid); |
| 3938 | if (idx >= 0) { |
| 3939 | final int ownerUid = mIsolatedUids.valueAt(idx); |
| 3940 | final Uid u = getUidStatsLocked(ownerUid); |
| 3941 | u.removeIsolatedUid(isolatedUid); |
| 3942 | mIsolatedUids.removeAt(idx); |
| 3943 | } |
| 3944 | mKernelUidCpuTimeReader.removeUid(isolatedUid); |
| 3945 | mKernelUidCpuFreqTimeReader.removeUid(isolatedUid); |
Mike Ma | fae87da | 2018-01-19 20:07:20 -0800 | [diff] [blame] | 3946 | if (mConstants.TRACK_CPU_ACTIVE_CLUSTER_TIME) { |
| 3947 | mKernelUidCpuActiveTimeReader.removeUid(isolatedUid); |
| 3948 | mKernelUidCpuClusterTimeReader.removeUid(isolatedUid); |
| 3949 | } |
Adam Lesinski | 61db88f | 2015-07-01 15:05:07 -0700 | [diff] [blame] | 3950 | } |
| 3951 | |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3952 | public int mapUid(int uid) { |
| 3953 | int isolated = mIsolatedUids.get(uid, -1); |
| 3954 | return isolated > 0 ? isolated : uid; |
| 3955 | } |
| 3956 | |
| 3957 | public void noteEventLocked(int code, String name, int uid) { |
| 3958 | uid = mapUid(uid); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 3959 | if (!mActiveEvents.updateState(code, name, uid, 0)) { |
| 3960 | return; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 3961 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3962 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3963 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3964 | addHistoryEventLocked(elapsedRealtime, uptime, code, name, uid); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3965 | } |
| 3966 | |
Dianne Hackborn | d48954f | 2015-07-22 17:20:33 -0700 | [diff] [blame] | 3967 | boolean ensureStartClockTime(final long currentTime) { |
| 3968 | final long ABOUT_ONE_YEAR = 365*24*60*60*1000L; |
| 3969 | if (currentTime > ABOUT_ONE_YEAR && mStartClockTime < (currentTime-ABOUT_ONE_YEAR)) { |
| 3970 | // If the start clock time has changed by more than a year, then presumably |
| 3971 | // the previous time was completely bogus. So we are going to figure out a |
| 3972 | // 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] | 3973 | mStartClockTime = currentTime - (mClocks.elapsedRealtime()-(mRealtimeStart/1000)); |
Dianne Hackborn | d48954f | 2015-07-22 17:20:33 -0700 | [diff] [blame] | 3974 | return true; |
| 3975 | } |
| 3976 | return false; |
| 3977 | } |
| 3978 | |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 3979 | public void noteCurrentTimeChangedLocked() { |
| 3980 | final long currentTime = System.currentTimeMillis(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3981 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3982 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 3983 | recordCurrentTimeChangeLocked(currentTime, elapsedRealtime, uptime); |
Dianne Hackborn | d48954f | 2015-07-22 17:20:33 -0700 | [diff] [blame] | 3984 | ensureStartClockTime(currentTime); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 3985 | } |
| 3986 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3987 | public void noteProcessStartLocked(String name, int uid) { |
| 3988 | uid = mapUid(uid); |
| 3989 | if (isOnBattery()) { |
| 3990 | Uid u = getUidStatsLocked(uid); |
| 3991 | u.getProcessStatsLocked(name).incStartsLocked(); |
| 3992 | } |
| 3993 | if (!mActiveEvents.updateState(HistoryItem.EVENT_PROC_START, name, uid, 0)) { |
| 3994 | return; |
| 3995 | } |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3996 | if (!mRecordAllHistory) { |
| 3997 | return; |
| 3998 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3999 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4000 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4001 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_PROC_START, name, uid); |
| 4002 | } |
| 4003 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 4004 | public void noteProcessCrashLocked(String name, int uid) { |
| 4005 | uid = mapUid(uid); |
| 4006 | if (isOnBattery()) { |
| 4007 | Uid u = getUidStatsLocked(uid); |
| 4008 | u.getProcessStatsLocked(name).incNumCrashesLocked(); |
| 4009 | } |
| 4010 | } |
| 4011 | |
| 4012 | public void noteProcessAnrLocked(String name, int uid) { |
| 4013 | uid = mapUid(uid); |
| 4014 | if (isOnBattery()) { |
| 4015 | Uid u = getUidStatsLocked(uid); |
| 4016 | u.getProcessStatsLocked(name).incNumAnrsLocked(); |
| 4017 | } |
| 4018 | } |
| 4019 | |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 4020 | public void noteUidProcessStateLocked(int uid, int state) { |
Amith Yamasani | fd3caf6 | 2017-07-26 11:48:35 -0700 | [diff] [blame] | 4021 | int parentUid = mapUid(uid); |
| 4022 | if (uid != parentUid) { |
| 4023 | // Isolated UIDs process state is already rolled up into parent, so no need to track |
| 4024 | // Otherwise the parent's process state will get downgraded incorrectly |
| 4025 | return; |
| 4026 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 4027 | getUidStatsLocked(uid).updateUidProcessStateLocked(state); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4028 | } |
| 4029 | |
| 4030 | public void noteProcessFinishLocked(String name, int uid) { |
| 4031 | uid = mapUid(uid); |
| 4032 | if (!mActiveEvents.updateState(HistoryItem.EVENT_PROC_FINISH, name, uid, 0)) { |
| 4033 | return; |
| 4034 | } |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 4035 | if (!mRecordAllHistory) { |
| 4036 | return; |
| 4037 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4038 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4039 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 4040 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_PROC_FINISH, name, uid); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4041 | } |
| 4042 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4043 | public void noteSyncStartLocked(String name, int uid) { |
| 4044 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4045 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4046 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4047 | getUidStatsLocked(uid).noteStartSyncLocked(name, elapsedRealtime); |
| 4048 | if (!mActiveEvents.updateState(HistoryItem.EVENT_SYNC_START, name, uid, 0)) { |
| 4049 | return; |
| 4050 | } |
| 4051 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_SYNC_START, name, uid); |
| 4052 | } |
| 4053 | |
| 4054 | public void noteSyncFinishLocked(String name, int uid) { |
| 4055 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4056 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4057 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4058 | getUidStatsLocked(uid).noteStopSyncLocked(name, elapsedRealtime); |
| 4059 | if (!mActiveEvents.updateState(HistoryItem.EVENT_SYNC_FINISH, name, uid, 0)) { |
| 4060 | return; |
| 4061 | } |
| 4062 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_SYNC_FINISH, name, uid); |
| 4063 | } |
| 4064 | |
| 4065 | public void noteJobStartLocked(String name, int uid) { |
| 4066 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4067 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4068 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4069 | getUidStatsLocked(uid).noteStartJobLocked(name, elapsedRealtime); |
| 4070 | if (!mActiveEvents.updateState(HistoryItem.EVENT_JOB_START, name, uid, 0)) { |
| 4071 | return; |
| 4072 | } |
| 4073 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_JOB_START, name, uid); |
| 4074 | } |
| 4075 | |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 4076 | public void noteJobFinishLocked(String name, int uid, int stopReason) { |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4077 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4078 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4079 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 4080 | getUidStatsLocked(uid).noteStopJobLocked(name, elapsedRealtime, stopReason); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4081 | if (!mActiveEvents.updateState(HistoryItem.EVENT_JOB_FINISH, name, uid, 0)) { |
| 4082 | return; |
| 4083 | } |
| 4084 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_JOB_FINISH, name, uid); |
| 4085 | } |
| 4086 | |
Amith Yamasani | 977e11f | 2018-02-16 11:29:54 -0800 | [diff] [blame] | 4087 | public void noteJobsDeferredLocked(int uid, int numDeferred, long sinceLast) { |
| 4088 | uid = mapUid(uid); |
| 4089 | getUidStatsLocked(uid).noteJobsDeferredLocked(numDeferred, sinceLast); |
| 4090 | } |
| 4091 | |
Narayan Kamath | 695cf72 | 2017-12-21 18:32:47 +0000 | [diff] [blame] | 4092 | public void noteAlarmStartLocked(String name, WorkSource workSource, int uid) { |
| 4093 | noteAlarmStartOrFinishLocked(HistoryItem.EVENT_ALARM_START, name, workSource, uid); |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 4094 | } |
| 4095 | |
Narayan Kamath | 695cf72 | 2017-12-21 18:32:47 +0000 | [diff] [blame] | 4096 | public void noteAlarmFinishLocked(String name, WorkSource workSource, int uid) { |
| 4097 | noteAlarmStartOrFinishLocked(HistoryItem.EVENT_ALARM_FINISH, name, workSource, uid); |
| 4098 | } |
| 4099 | |
| 4100 | private void noteAlarmStartOrFinishLocked(int historyItem, String name, WorkSource workSource, |
| 4101 | int uid) { |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 4102 | if (!mRecordAllHistory) { |
| 4103 | return; |
| 4104 | } |
Narayan Kamath | 695cf72 | 2017-12-21 18:32:47 +0000 | [diff] [blame] | 4105 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4106 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4107 | final long uptime = mClocks.uptimeMillis(); |
Narayan Kamath | 695cf72 | 2017-12-21 18:32:47 +0000 | [diff] [blame] | 4108 | |
| 4109 | if (workSource != null) { |
| 4110 | for (int i = 0; i < workSource.size(); ++i) { |
| 4111 | uid = mapUid(workSource.get(i)); |
| 4112 | if (mActiveEvents.updateState(historyItem, name, uid, 0)) { |
| 4113 | addHistoryEventLocked(elapsedRealtime, uptime, historyItem, name, uid); |
| 4114 | } |
| 4115 | } |
| 4116 | |
| 4117 | List<WorkChain> workChains = workSource.getWorkChains(); |
| 4118 | if (workChains != null) { |
| 4119 | for (int i = 0; i < workChains.size(); ++i) { |
| 4120 | uid = mapUid(workChains.get(i).getAttributionUid()); |
| 4121 | if (mActiveEvents.updateState(historyItem, name, uid, 0)) { |
| 4122 | addHistoryEventLocked(elapsedRealtime, uptime, historyItem, name, uid); |
| 4123 | } |
| 4124 | } |
| 4125 | } |
| 4126 | } else { |
| 4127 | uid = mapUid(uid); |
| 4128 | |
| 4129 | if (mActiveEvents.updateState(historyItem, name, uid, 0)) { |
| 4130 | addHistoryEventLocked(elapsedRealtime, uptime, historyItem, name, uid); |
| 4131 | } |
| 4132 | } |
| 4133 | } |
| 4134 | |
| 4135 | public void noteWakupAlarmLocked(String packageName, int uid, WorkSource workSource, |
| 4136 | String tag) { |
Narayan Kamath | 695cf72 | 2017-12-21 18:32:47 +0000 | [diff] [blame] | 4137 | if (workSource != null) { |
| 4138 | for (int i = 0; i < workSource.size(); ++i) { |
| 4139 | uid = workSource.get(i); |
| 4140 | final String workSourceName = workSource.getName(i); |
| 4141 | |
Tej Singh | 6f724c4 | 2018-01-03 20:02:03 -0800 | [diff] [blame] | 4142 | if (isOnBattery()) { |
| 4143 | BatteryStatsImpl.Uid.Pkg pkg = getPackageStatsLocked(uid, |
| 4144 | workSourceName != null ? workSourceName : packageName); |
| 4145 | pkg.noteWakeupAlarmLocked(tag); |
| 4146 | } |
Yangster-mac | 2f5daec | 2018-01-16 10:23:15 -0800 | [diff] [blame] | 4147 | StatsLog.write_non_chained(StatsLog.WAKEUP_ALARM_OCCURRED, workSource.get(i), |
| 4148 | workSource.getName(i), tag); |
Narayan Kamath | 695cf72 | 2017-12-21 18:32:47 +0000 | [diff] [blame] | 4149 | } |
| 4150 | |
| 4151 | ArrayList<WorkChain> workChains = workSource.getWorkChains(); |
| 4152 | if (workChains != null) { |
| 4153 | for (int i = 0; i < workChains.size(); ++i) { |
| 4154 | final WorkChain wc = workChains.get(i); |
| 4155 | uid = wc.getAttributionUid(); |
| 4156 | |
Tej Singh | 6f724c4 | 2018-01-03 20:02:03 -0800 | [diff] [blame] | 4157 | if (isOnBattery()) { |
| 4158 | BatteryStatsImpl.Uid.Pkg pkg = getPackageStatsLocked(uid, packageName); |
| 4159 | pkg.noteWakeupAlarmLocked(tag); |
| 4160 | } |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 4161 | StatsLog.write(StatsLog.WAKEUP_ALARM_OCCURRED, wc.getUids(), wc.getTags(), tag); |
Narayan Kamath | 695cf72 | 2017-12-21 18:32:47 +0000 | [diff] [blame] | 4162 | } |
| 4163 | } |
| 4164 | } else { |
Tej Singh | 6f724c4 | 2018-01-03 20:02:03 -0800 | [diff] [blame] | 4165 | if (isOnBattery()) { |
| 4166 | BatteryStatsImpl.Uid.Pkg pkg = getPackageStatsLocked(uid, packageName); |
| 4167 | pkg.noteWakeupAlarmLocked(tag); |
| 4168 | } |
Yangster-mac | 2f5daec | 2018-01-16 10:23:15 -0800 | [diff] [blame] | 4169 | StatsLog.write_non_chained(StatsLog.WAKEUP_ALARM_OCCURRED, uid, null, tag); |
Narayan Kamath | 695cf72 | 2017-12-21 18:32:47 +0000 | [diff] [blame] | 4170 | } |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 4171 | } |
| 4172 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4173 | private void requestWakelockCpuUpdate() { |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 4174 | mExternalSync.scheduleCpuSyncDueToWakelockChange(DELAY_UPDATE_WAKELOCKS); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4175 | } |
| 4176 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 4177 | private void requestImmediateCpuUpdate() { |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 4178 | mExternalSync.scheduleCpuSyncDueToWakelockChange(0 /* delayMillis */); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 4179 | } |
| 4180 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 4181 | public void setRecordAllHistoryLocked(boolean enabled) { |
| 4182 | mRecordAllHistory = enabled; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4183 | if (!enabled) { |
| 4184 | // Clear out any existing state. |
| 4185 | mActiveEvents.removeEvents(HistoryItem.EVENT_WAKE_LOCK); |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 4186 | mActiveEvents.removeEvents(HistoryItem.EVENT_ALARM); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 4187 | // Record the currently running processes as stopping, now that we are no |
| 4188 | // longer tracking them. |
| 4189 | HashMap<String, SparseIntArray> active = mActiveEvents.getStateForEvent( |
| 4190 | HistoryItem.EVENT_PROC); |
| 4191 | if (active != null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4192 | long mSecRealtime = mClocks.elapsedRealtime(); |
| 4193 | final long mSecUptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 4194 | for (HashMap.Entry<String, SparseIntArray> ent : active.entrySet()) { |
| 4195 | SparseIntArray uids = ent.getValue(); |
| 4196 | for (int j=0; j<uids.size(); j++) { |
| 4197 | addHistoryEventLocked(mSecRealtime, mSecUptime, |
| 4198 | HistoryItem.EVENT_PROC_FINISH, ent.getKey(), uids.keyAt(j)); |
| 4199 | } |
| 4200 | } |
| 4201 | } |
| 4202 | } else { |
| 4203 | // Record the currently running processes as starting, now that we are tracking them. |
| 4204 | HashMap<String, SparseIntArray> active = mActiveEvents.getStateForEvent( |
| 4205 | HistoryItem.EVENT_PROC); |
| 4206 | if (active != null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4207 | long mSecRealtime = mClocks.elapsedRealtime(); |
| 4208 | final long mSecUptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 4209 | for (HashMap.Entry<String, SparseIntArray> ent : active.entrySet()) { |
| 4210 | SparseIntArray uids = ent.getValue(); |
| 4211 | for (int j=0; j<uids.size(); j++) { |
| 4212 | addHistoryEventLocked(mSecRealtime, mSecUptime, |
| 4213 | HistoryItem.EVENT_PROC_START, ent.getKey(), uids.keyAt(j)); |
| 4214 | } |
| 4215 | } |
| 4216 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4217 | } |
| 4218 | } |
| 4219 | |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 4220 | public void setNoAutoReset(boolean enabled) { |
| 4221 | mNoAutoReset = enabled; |
| 4222 | } |
| 4223 | |
Amith Yamasani | 674c9bb | 2017-02-01 09:45:17 -0800 | [diff] [blame] | 4224 | public void setPretendScreenOff(boolean pretendScreenOff) { |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4225 | if (mPretendScreenOff != pretendScreenOff) { |
| 4226 | mPretendScreenOff = pretendScreenOff; |
| 4227 | noteScreenStateLocked(pretendScreenOff ? Display.STATE_OFF : Display.STATE_ON); |
| 4228 | } |
Amith Yamasani | 674c9bb | 2017-02-01 09:45:17 -0800 | [diff] [blame] | 4229 | } |
| 4230 | |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 4231 | private String mInitialAcquireWakeName; |
| 4232 | private int mInitialAcquireWakeUid = -1; |
| 4233 | |
Narayan Kamath | 8182202 | 2017-12-08 11:56:01 +0000 | [diff] [blame] | 4234 | public void noteStartWakeLocked(int uid, int pid, WorkChain wc, String name, String historyName, |
| 4235 | int type, boolean unimportantForLogging, long elapsedRealtime, long uptime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4236 | uid = mapUid(uid); |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 4237 | if (type == WAKE_TYPE_PARTIAL) { |
| 4238 | // Only care about partial wake locks, since full wake locks |
| 4239 | // will be canceled when the user puts the screen to sleep. |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4240 | aggregateLastWakeupUptimeLocked(uptime); |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 4241 | if (historyName == null) { |
| 4242 | historyName = name; |
| 4243 | } |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 4244 | if (mRecordAllHistory) { |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 4245 | if (mActiveEvents.updateState(HistoryItem.EVENT_WAKE_LOCK_START, historyName, |
| 4246 | uid, 0)) { |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 4247 | addHistoryEventLocked(elapsedRealtime, uptime, |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 4248 | HistoryItem.EVENT_WAKE_LOCK_START, historyName, uid); |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 4249 | } |
| 4250 | } |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 4251 | if (mWakeLockNesting == 0) { |
| 4252 | mHistoryCur.states |= HistoryItem.STATE_WAKE_LOCK_FLAG; |
| 4253 | if (DEBUG_HISTORY) Slog.v(TAG, "Start wake lock to: " |
| 4254 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4255 | mHistoryCur.wakelockTag = mHistoryCur.localWakelockTag; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4256 | mHistoryCur.wakelockTag.string = mInitialAcquireWakeName = historyName; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 4257 | mHistoryCur.wakelockTag.uid = mInitialAcquireWakeUid = uid; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 4258 | mWakeLockImportant = !unimportantForLogging; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4259 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 4260 | } else if (!mWakeLockImportant && !unimportantForLogging |
| 4261 | && mHistoryLastWritten.cmd == HistoryItem.CMD_UPDATE) { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 4262 | if (mHistoryLastWritten.wakelockTag != null) { |
| 4263 | // We'll try to update the last tag. |
| 4264 | mHistoryLastWritten.wakelockTag = null; |
| 4265 | mHistoryCur.wakelockTag = mHistoryCur.localWakelockTag; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4266 | mHistoryCur.wakelockTag.string = mInitialAcquireWakeName = historyName; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 4267 | mHistoryCur.wakelockTag.uid = mInitialAcquireWakeUid = uid; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4268 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 4269 | } |
| 4270 | mWakeLockImportant = true; |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 4271 | } |
| 4272 | mWakeLockNesting++; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4273 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4274 | if (uid >= 0) { |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 4275 | if (mOnBatteryScreenOffTimeBase.isRunning()) { |
| 4276 | // We only update the cpu time when a wake lock is acquired if the screen is off. |
| 4277 | // If the screen is on, we don't distribute the power amongst partial wakelocks. |
| 4278 | if (DEBUG_ENERGY_CPU) { |
| 4279 | Slog.d(TAG, "Updating cpu time because of +wake_lock"); |
| 4280 | } |
| 4281 | requestWakelockCpuUpdate(); |
| 4282 | } |
Narayan Kamath | 8182202 | 2017-12-08 11:56:01 +0000 | [diff] [blame] | 4283 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4284 | getUidStatsLocked(uid).noteStartWakeLocked(pid, name, type, elapsedRealtime); |
Narayan Kamath | 8182202 | 2017-12-08 11:56:01 +0000 | [diff] [blame] | 4285 | |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 4286 | if (wc != null) { |
Bookatz | 1a1b046 | 2018-01-12 11:47:03 -0800 | [diff] [blame] | 4287 | StatsLog.write(StatsLog.WAKELOCK_STATE_CHANGED, wc.getUids(), wc.getTags(), |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 4288 | getPowerManagerWakeLockLevel(type), name, |
| 4289 | StatsLog.WAKELOCK_STATE_CHANGED__STATE__ACQUIRE); |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 4290 | } else { |
Bookatz | 1a1b046 | 2018-01-12 11:47:03 -0800 | [diff] [blame] | 4291 | StatsLog.write_non_chained(StatsLog.WAKELOCK_STATE_CHANGED, uid, null, |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 4292 | getPowerManagerWakeLockLevel(type), name, |
| 4293 | StatsLog.WAKELOCK_STATE_CHANGED__STATE__ACQUIRE); |
Narayan Kamath | 8182202 | 2017-12-08 11:56:01 +0000 | [diff] [blame] | 4294 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4295 | } |
| 4296 | } |
| 4297 | |
Narayan Kamath | 8182202 | 2017-12-08 11:56:01 +0000 | [diff] [blame] | 4298 | public void noteStopWakeLocked(int uid, int pid, WorkChain wc, String name, String historyName, |
| 4299 | int type, long elapsedRealtime, long uptime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4300 | uid = mapUid(uid); |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 4301 | if (type == WAKE_TYPE_PARTIAL) { |
| 4302 | mWakeLockNesting--; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 4303 | if (mRecordAllHistory) { |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 4304 | if (historyName == null) { |
| 4305 | historyName = name; |
| 4306 | } |
| 4307 | if (mActiveEvents.updateState(HistoryItem.EVENT_WAKE_LOCK_FINISH, historyName, |
| 4308 | uid, 0)) { |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 4309 | addHistoryEventLocked(elapsedRealtime, uptime, |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 4310 | HistoryItem.EVENT_WAKE_LOCK_FINISH, historyName, uid); |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 4311 | } |
| 4312 | } |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 4313 | if (mWakeLockNesting == 0) { |
| 4314 | mHistoryCur.states &= ~HistoryItem.STATE_WAKE_LOCK_FLAG; |
| 4315 | if (DEBUG_HISTORY) Slog.v(TAG, "Stop wake lock to: " |
| 4316 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 4317 | mInitialAcquireWakeName = null; |
| 4318 | mInitialAcquireWakeUid = -1; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4319 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 4320 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4321 | } |
| 4322 | if (uid >= 0) { |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 4323 | if (mOnBatteryScreenOffTimeBase.isRunning()) { |
| 4324 | if (DEBUG_ENERGY_CPU) { |
| 4325 | Slog.d(TAG, "Updating cpu time because of -wake_lock"); |
| 4326 | } |
| 4327 | requestWakelockCpuUpdate(); |
| 4328 | } |
Narayan Kamath | 8182202 | 2017-12-08 11:56:01 +0000 | [diff] [blame] | 4329 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4330 | getUidStatsLocked(uid).noteStopWakeLocked(pid, name, type, elapsedRealtime); |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 4331 | if (wc != null) { |
Bookatz | 1a1b046 | 2018-01-12 11:47:03 -0800 | [diff] [blame] | 4332 | StatsLog.write(StatsLog.WAKELOCK_STATE_CHANGED, wc.getUids(), wc.getTags(), |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 4333 | getPowerManagerWakeLockLevel(type), name, |
| 4334 | StatsLog.WAKELOCK_STATE_CHANGED__STATE__RELEASE); |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 4335 | } else { |
Bookatz | 1a1b046 | 2018-01-12 11:47:03 -0800 | [diff] [blame] | 4336 | StatsLog.write_non_chained(StatsLog.WAKELOCK_STATE_CHANGED, uid, null, |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 4337 | getPowerManagerWakeLockLevel(type), name, |
| 4338 | StatsLog.WAKELOCK_STATE_CHANGED__STATE__RELEASE); |
Narayan Kamath | 8182202 | 2017-12-08 11:56:01 +0000 | [diff] [blame] | 4339 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4340 | } |
| 4341 | } |
| 4342 | |
Bookatz | 1a1b046 | 2018-01-12 11:47:03 -0800 | [diff] [blame] | 4343 | /** |
| 4344 | * Converts BatteryStats wakelock types back into PowerManager wakelock levels. |
| 4345 | * This is the inverse map of Notifier.getBatteryStatsWakeLockMonitorType(). |
| 4346 | * These are estimations, since batterystats loses some of the original data. |
| 4347 | * TODO: Delete this. Instead, StatsLog.write should be called from PowerManager's Notifier. |
| 4348 | */ |
| 4349 | private int getPowerManagerWakeLockLevel(int battertStatsWakelockType) { |
| 4350 | switch (battertStatsWakelockType) { |
| 4351 | // PowerManager.PARTIAL_WAKE_LOCK or PROXIMITY_SCREEN_OFF_WAKE_LOCK |
| 4352 | case BatteryStats.WAKE_TYPE_PARTIAL: |
| 4353 | return PowerManager.PARTIAL_WAKE_LOCK; |
| 4354 | |
| 4355 | // PowerManager.SCREEN_DIM_WAKE_LOCK or SCREEN_BRIGHT_WAKE_LOCK |
| 4356 | case BatteryStats.WAKE_TYPE_FULL: |
| 4357 | return PowerManager.FULL_WAKE_LOCK; |
| 4358 | |
| 4359 | case BatteryStats.WAKE_TYPE_DRAW: |
| 4360 | return PowerManager.DRAW_WAKE_LOCK; |
| 4361 | |
| 4362 | // It appears that nothing can ever make a Window and PowerManager lacks an equivalent. |
| 4363 | case BatteryStats.WAKE_TYPE_WINDOW: |
| 4364 | Slog.e(TAG, "Illegal window wakelock type observed in batterystats."); |
| 4365 | return -1; |
| 4366 | |
| 4367 | default: |
| 4368 | Slog.e(TAG, "Illegal wakelock type in batterystats: " + battertStatsWakelockType); |
| 4369 | return -1; |
| 4370 | } |
| 4371 | } |
| 4372 | |
Dianne Hackborn | a1f1a3c | 2014-02-24 18:12:28 -0800 | [diff] [blame] | 4373 | public void noteStartWakeFromSourceLocked(WorkSource ws, int pid, String name, |
| 4374 | String historyName, int type, boolean unimportantForLogging) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4375 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4376 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 4377 | final int N = ws.size(); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 4378 | for (int i=0; i<N; i++) { |
Narayan Kamath | 8182202 | 2017-12-08 11:56:01 +0000 | [diff] [blame] | 4379 | noteStartWakeLocked(ws.get(i), pid, null, name, historyName, type, |
| 4380 | unimportantForLogging, elapsedRealtime, uptime); |
| 4381 | } |
| 4382 | |
| 4383 | List<WorkChain> wcs = ws.getWorkChains(); |
| 4384 | if (wcs != null) { |
| 4385 | for (int i = 0; i < wcs.size(); ++i) { |
| 4386 | final WorkChain wc = wcs.get(i); |
| 4387 | noteStartWakeLocked(wc.getAttributionUid(), pid, wc, name, historyName, type, |
| 4388 | unimportantForLogging, elapsedRealtime, uptime); |
| 4389 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 4390 | } |
| 4391 | } |
| 4392 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4393 | public void noteChangeWakelockFromSourceLocked(WorkSource ws, int pid, String name, |
| 4394 | String historyName, int type, WorkSource newWs, int newPid, String newName, |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 4395 | String newHistoryName, int newType, boolean newUnimportantForLogging) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4396 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4397 | final long uptime = mClocks.uptimeMillis(); |
Narayan Kamath | 8182202 | 2017-12-08 11:56:01 +0000 | [diff] [blame] | 4398 | |
| 4399 | List<WorkChain>[] wcs = WorkSource.diffChains(ws, newWs); |
| 4400 | |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 4401 | // For correct semantics, we start the need worksources first, so that we won't |
| 4402 | // make inappropriate history items as if all wake locks went away and new ones |
| 4403 | // appeared. This is okay because tracking of wake locks allows nesting. |
Narayan Kamath | 8182202 | 2017-12-08 11:56:01 +0000 | [diff] [blame] | 4404 | // |
| 4405 | // First the starts : |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4406 | final int NN = newWs.size(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 4407 | for (int i=0; i<NN; i++) { |
Narayan Kamath | 8182202 | 2017-12-08 11:56:01 +0000 | [diff] [blame] | 4408 | noteStartWakeLocked(newWs.get(i), newPid, null, newName, newHistoryName, newType, |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4409 | newUnimportantForLogging, elapsedRealtime, uptime); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 4410 | } |
Narayan Kamath | 8182202 | 2017-12-08 11:56:01 +0000 | [diff] [blame] | 4411 | if (wcs != null) { |
| 4412 | List<WorkChain> newChains = wcs[0]; |
| 4413 | if (newChains != null) { |
| 4414 | for (int i = 0; i < newChains.size(); ++i) { |
| 4415 | final WorkChain newChain = newChains.get(i); |
| 4416 | noteStartWakeLocked(newChain.getAttributionUid(), newPid, newChain, newName, |
| 4417 | newHistoryName, newType, newUnimportantForLogging, elapsedRealtime, |
| 4418 | uptime); |
| 4419 | } |
| 4420 | } |
| 4421 | } |
| 4422 | |
| 4423 | // Then the stops : |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 4424 | final int NO = ws.size(); |
| 4425 | for (int i=0; i<NO; i++) { |
Narayan Kamath | 8182202 | 2017-12-08 11:56:01 +0000 | [diff] [blame] | 4426 | noteStopWakeLocked(ws.get(i), pid, null, name, historyName, type, elapsedRealtime, |
| 4427 | uptime); |
| 4428 | } |
| 4429 | if (wcs != null) { |
| 4430 | List<WorkChain> goneChains = wcs[1]; |
| 4431 | if (goneChains != null) { |
| 4432 | for (int i = 0; i < goneChains.size(); ++i) { |
| 4433 | final WorkChain goneChain = goneChains.get(i); |
| 4434 | noteStopWakeLocked(goneChain.getAttributionUid(), pid, goneChain, name, |
| 4435 | historyName, type, elapsedRealtime, uptime); |
| 4436 | } |
| 4437 | } |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 4438 | } |
| 4439 | } |
| 4440 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4441 | public void noteStopWakeFromSourceLocked(WorkSource ws, int pid, String name, |
| 4442 | String historyName, int type) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4443 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4444 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 4445 | final int N = ws.size(); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 4446 | for (int i=0; i<N; i++) { |
Narayan Kamath | 8182202 | 2017-12-08 11:56:01 +0000 | [diff] [blame] | 4447 | noteStopWakeLocked(ws.get(i), pid, null, name, historyName, type, elapsedRealtime, |
| 4448 | uptime); |
| 4449 | } |
| 4450 | |
| 4451 | List<WorkChain> wcs = ws.getWorkChains(); |
| 4452 | if (wcs != null) { |
| 4453 | for (int i = 0; i < wcs.size(); ++i) { |
| 4454 | final WorkChain wc = wcs.get(i); |
| 4455 | noteStopWakeLocked(wc.getAttributionUid(), pid, wc, name, historyName, type, |
| 4456 | elapsedRealtime, uptime); |
| 4457 | } |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 4458 | } |
| 4459 | } |
| 4460 | |
Dianne Hackborn | d0db6f0 | 2016-07-18 14:14:20 -0700 | [diff] [blame] | 4461 | public void noteLongPartialWakelockStart(String name, String historyName, int uid) { |
Yangster-mac | 2f5daec | 2018-01-16 10:23:15 -0800 | [diff] [blame] | 4462 | StatsLog.write_non_chained(StatsLog.LONG_PARTIAL_WAKELOCK_STATE_CHANGED, |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 4463 | uid, null, name, historyName, |
| 4464 | StatsLog.LONG_PARTIAL_WAKELOCK_STATE_CHANGED__STATE__ON); |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 4465 | |
Dianne Hackborn | d0db6f0 | 2016-07-18 14:14:20 -0700 | [diff] [blame] | 4466 | uid = mapUid(uid); |
Narayan Kamath | 96a9256 | 2018-01-02 18:57:17 +0000 | [diff] [blame] | 4467 | noteLongPartialWakeLockStartInternal(name, historyName, uid); |
Narayan Kamath | 96a9256 | 2018-01-02 18:57:17 +0000 | [diff] [blame] | 4468 | } |
| 4469 | |
| 4470 | public void noteLongPartialWakelockStartFromSource(String name, String historyName, |
| 4471 | WorkSource workSource) { |
| 4472 | final int N = workSource.size(); |
| 4473 | for (int i = 0; i < N; ++i) { |
| 4474 | final int uid = mapUid(workSource.get(i)); |
| 4475 | noteLongPartialWakeLockStartInternal(name, historyName, uid); |
Yangster-mac | 2f5daec | 2018-01-16 10:23:15 -0800 | [diff] [blame] | 4476 | StatsLog.write_non_chained(StatsLog.LONG_PARTIAL_WAKELOCK_STATE_CHANGED, |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 4477 | workSource.get(i), workSource.getName(i), name, historyName, |
| 4478 | StatsLog.LONG_PARTIAL_WAKELOCK_STATE_CHANGED__STATE__ON); |
Narayan Kamath | 96a9256 | 2018-01-02 18:57:17 +0000 | [diff] [blame] | 4479 | } |
| 4480 | |
| 4481 | final ArrayList<WorkChain> workChains = workSource.getWorkChains(); |
| 4482 | if (workChains != null) { |
| 4483 | for (int i = 0; i < workChains.size(); ++i) { |
| 4484 | final WorkChain workChain = workChains.get(i); |
| 4485 | final int uid = workChain.getAttributionUid(); |
| 4486 | noteLongPartialWakeLockStartInternal(name, historyName, uid); |
| 4487 | |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 4488 | StatsLog.write(StatsLog.LONG_PARTIAL_WAKELOCK_STATE_CHANGED, |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 4489 | workChain.getUids(), workChain.getTags(), name, historyName, |
| 4490 | StatsLog.LONG_PARTIAL_WAKELOCK_STATE_CHANGED__STATE__ON); |
Narayan Kamath | 96a9256 | 2018-01-02 18:57:17 +0000 | [diff] [blame] | 4491 | } |
| 4492 | } |
| 4493 | } |
| 4494 | |
| 4495 | private void noteLongPartialWakeLockStartInternal(String name, String historyName, int uid) { |
Dianne Hackborn | d0db6f0 | 2016-07-18 14:14:20 -0700 | [diff] [blame] | 4496 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4497 | final long uptime = mClocks.uptimeMillis(); |
| 4498 | if (historyName == null) { |
| 4499 | historyName = name; |
| 4500 | } |
| 4501 | if (!mActiveEvents.updateState(HistoryItem.EVENT_LONG_WAKE_LOCK_START, historyName, uid, |
| 4502 | 0)) { |
| 4503 | return; |
| 4504 | } |
| 4505 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_LONG_WAKE_LOCK_START, |
| 4506 | historyName, uid); |
| 4507 | } |
| 4508 | |
| 4509 | public void noteLongPartialWakelockFinish(String name, String historyName, int uid) { |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 4510 | StatsLog.write_non_chained(StatsLog.LONG_PARTIAL_WAKELOCK_STATE_CHANGED, uid, null, |
| 4511 | name, historyName, StatsLog.LONG_PARTIAL_WAKELOCK_STATE_CHANGED__STATE__OFF); |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 4512 | |
Dianne Hackborn | d0db6f0 | 2016-07-18 14:14:20 -0700 | [diff] [blame] | 4513 | uid = mapUid(uid); |
Narayan Kamath | 96a9256 | 2018-01-02 18:57:17 +0000 | [diff] [blame] | 4514 | noteLongPartialWakeLockFinishInternal(name, historyName, uid); |
Narayan Kamath | 96a9256 | 2018-01-02 18:57:17 +0000 | [diff] [blame] | 4515 | } |
| 4516 | |
| 4517 | public void noteLongPartialWakelockFinishFromSource(String name, String historyName, |
| 4518 | WorkSource workSource) { |
| 4519 | final int N = workSource.size(); |
| 4520 | for (int i = 0; i < N; ++i) { |
| 4521 | final int uid = mapUid(workSource.get(i)); |
| 4522 | noteLongPartialWakeLockFinishInternal(name, historyName, uid); |
Yangster-mac | 2f5daec | 2018-01-16 10:23:15 -0800 | [diff] [blame] | 4523 | StatsLog.write_non_chained(StatsLog.LONG_PARTIAL_WAKELOCK_STATE_CHANGED, |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 4524 | workSource.get(i), workSource.getName(i), name, historyName, |
| 4525 | StatsLog.LONG_PARTIAL_WAKELOCK_STATE_CHANGED__STATE__OFF); |
Narayan Kamath | 96a9256 | 2018-01-02 18:57:17 +0000 | [diff] [blame] | 4526 | } |
| 4527 | |
| 4528 | final ArrayList<WorkChain> workChains = workSource.getWorkChains(); |
| 4529 | if (workChains != null) { |
| 4530 | for (int i = 0; i < workChains.size(); ++i) { |
| 4531 | final WorkChain workChain = workChains.get(i); |
| 4532 | final int uid = workChain.getAttributionUid(); |
Narayan Kamath | 96a9256 | 2018-01-02 18:57:17 +0000 | [diff] [blame] | 4533 | noteLongPartialWakeLockFinishInternal(name, historyName, uid); |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 4534 | StatsLog.write(StatsLog.LONG_PARTIAL_WAKELOCK_STATE_CHANGED, |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 4535 | workChain.getUids(), workChain.getTags(), name, historyName, |
| 4536 | StatsLog.LONG_PARTIAL_WAKELOCK_STATE_CHANGED__STATE__OFF); |
Narayan Kamath | 96a9256 | 2018-01-02 18:57:17 +0000 | [diff] [blame] | 4537 | } |
| 4538 | } |
| 4539 | } |
| 4540 | |
| 4541 | private void noteLongPartialWakeLockFinishInternal(String name, String historyName, int uid) { |
Dianne Hackborn | d0db6f0 | 2016-07-18 14:14:20 -0700 | [diff] [blame] | 4542 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4543 | final long uptime = mClocks.uptimeMillis(); |
| 4544 | if (historyName == null) { |
| 4545 | historyName = name; |
| 4546 | } |
| 4547 | if (!mActiveEvents.updateState(HistoryItem.EVENT_LONG_WAKE_LOCK_FINISH, historyName, uid, |
| 4548 | 0)) { |
| 4549 | return; |
| 4550 | } |
| 4551 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_LONG_WAKE_LOCK_FINISH, |
| 4552 | historyName, uid); |
| 4553 | } |
| 4554 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4555 | void aggregateLastWakeupUptimeLocked(long uptimeMs) { |
| 4556 | if (mLastWakeupReason != null) { |
| 4557 | long deltaUptime = uptimeMs - mLastWakeupUptimeMs; |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 4558 | SamplingTimer timer = getWakeupReasonTimerLocked(mLastWakeupReason); |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 4559 | timer.add(deltaUptime * 1000, 1); // time in in microseconds |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 4560 | StatsLog.write(StatsLog.KERNEL_WAKEUP_REPORTED, mLastWakeupReason, |
| 4561 | /* duration_usec */ deltaUptime * 1000); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4562 | mLastWakeupReason = null; |
| 4563 | } |
| 4564 | } |
| 4565 | |
| 4566 | public void noteWakeupReasonLocked(String reason) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4567 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4568 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 4569 | if (DEBUG_HISTORY) Slog.v(TAG, "Wakeup reason \"" + reason +"\": " |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4570 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4571 | aggregateLastWakeupUptimeLocked(uptime); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4572 | mHistoryCur.wakeReasonTag = mHistoryCur.localWakeReasonTag; |
| 4573 | mHistoryCur.wakeReasonTag.string = reason; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4574 | mHistoryCur.wakeReasonTag.uid = 0; |
| 4575 | mLastWakeupReason = reason; |
| 4576 | mLastWakeupUptimeMs = uptime; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4577 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4578 | } |
| 4579 | |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 4580 | public boolean startAddingCpuLocked() { |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 4581 | mExternalSync.cancelCpuSyncDueToWakelockChange(); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 4582 | return mOnBatteryInternal; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 4583 | } |
| 4584 | |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 4585 | public void finishAddingCpuLocked(int totalUTime, int totalSTime, int statUserTime, |
| 4586 | int statSystemTime, int statIOWaitTime, int statIrqTime, |
| 4587 | int statSoftIrqTime, int statIdleTime) { |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 4588 | if (DEBUG) Slog.d(TAG, "Adding cpu: tuser=" + totalUTime + " tsys=" + totalSTime |
| 4589 | + " user=" + statUserTime + " sys=" + statSystemTime |
| 4590 | + " io=" + statIOWaitTime + " irq=" + statIrqTime |
| 4591 | + " sirq=" + statSoftIrqTime + " idle=" + statIdleTime); |
| 4592 | mCurStepCpuUserTime += totalUTime; |
| 4593 | mCurStepCpuSystemTime += totalSTime; |
| 4594 | mCurStepStatUserTime += statUserTime; |
| 4595 | mCurStepStatSystemTime += statSystemTime; |
| 4596 | mCurStepStatIOWaitTime += statIOWaitTime; |
| 4597 | mCurStepStatIrqTime += statIrqTime; |
| 4598 | mCurStepStatSoftIrqTime += statSoftIrqTime; |
| 4599 | mCurStepStatIdleTime += statIdleTime; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 4600 | } |
| 4601 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4602 | public void noteProcessDiedLocked(int uid, int pid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4603 | uid = mapUid(uid); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4604 | Uid u = mUidStats.get(uid); |
| 4605 | if (u != null) { |
| 4606 | u.mPids.remove(pid); |
| 4607 | } |
| 4608 | } |
| 4609 | |
| 4610 | public long getProcessWakeTime(int uid, int pid, long realtime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4611 | uid = mapUid(uid); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4612 | Uid u = mUidStats.get(uid); |
| 4613 | if (u != null) { |
| 4614 | Uid.Pid p = u.mPids.get(pid); |
| 4615 | if (p != null) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 4616 | return p.mWakeSumMs + (p.mWakeNesting > 0 ? (realtime - p.mWakeStartMs) : 0); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4617 | } |
| 4618 | } |
| 4619 | return 0; |
| 4620 | } |
| 4621 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 4622 | public void reportExcessiveCpuLocked(int uid, String proc, long overTime, long usedTime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4623 | uid = mapUid(uid); |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 4624 | Uid u = mUidStats.get(uid); |
| 4625 | if (u != null) { |
| 4626 | u.reportExcessiveCpuLocked(proc, overTime, usedTime); |
| 4627 | } |
| 4628 | } |
| 4629 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4630 | int mSensorNesting; |
| 4631 | |
| 4632 | public void noteStartSensorLocked(int uid, int sensor) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4633 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4634 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4635 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4636 | if (mSensorNesting == 0) { |
| 4637 | mHistoryCur.states |= HistoryItem.STATE_SENSOR_ON_FLAG; |
| 4638 | if (DEBUG_HISTORY) Slog.v(TAG, "Start sensor to: " |
| 4639 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4640 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4641 | } |
| 4642 | mSensorNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4643 | getUidStatsLocked(uid).noteStartSensor(sensor, elapsedRealtime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4644 | } |
| 4645 | |
| 4646 | public void noteStopSensorLocked(int uid, int sensor) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4647 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4648 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4649 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4650 | mSensorNesting--; |
| 4651 | if (mSensorNesting == 0) { |
| 4652 | mHistoryCur.states &= ~HistoryItem.STATE_SENSOR_ON_FLAG; |
| 4653 | if (DEBUG_HISTORY) Slog.v(TAG, "Stop sensor to: " |
| 4654 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4655 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4656 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4657 | getUidStatsLocked(uid).noteStopSensor(sensor, elapsedRealtime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4658 | } |
| 4659 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4660 | int mGpsNesting; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4661 | |
Narayan Kamath | 32684dd | 2018-01-08 17:32:51 +0000 | [diff] [blame] | 4662 | public void noteGpsChangedLocked(WorkSource oldWs, WorkSource newWs) { |
| 4663 | for (int i = 0; i < newWs.size(); ++i) { |
| 4664 | noteStartGpsLocked(newWs.get(i), null); |
| 4665 | } |
| 4666 | |
| 4667 | for (int i = 0; i < oldWs.size(); ++i) { |
| 4668 | noteStopGpsLocked((oldWs.get(i)), null); |
| 4669 | } |
| 4670 | |
| 4671 | List<WorkChain>[] wcs = WorkSource.diffChains(oldWs, newWs); |
| 4672 | if (wcs != null) { |
| 4673 | if (wcs[0] != null) { |
| 4674 | final List<WorkChain> newChains = wcs[0]; |
| 4675 | for (int i = 0; i < newChains.size(); ++i) { |
| 4676 | noteStartGpsLocked(-1, newChains.get(i)); |
| 4677 | } |
| 4678 | } |
| 4679 | |
| 4680 | if (wcs[1] != null) { |
| 4681 | final List<WorkChain> goneChains = wcs[1]; |
| 4682 | for (int i = 0; i < goneChains.size(); ++i) { |
| 4683 | noteStopGpsLocked(-1, goneChains.get(i)); |
| 4684 | } |
| 4685 | } |
| 4686 | } |
| 4687 | } |
| 4688 | |
| 4689 | private void noteStartGpsLocked(int uid, WorkChain workChain) { |
| 4690 | uid = getAttributionUid(uid, workChain); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4691 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4692 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4693 | if (mGpsNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4694 | mHistoryCur.states |= HistoryItem.STATE_GPS_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4695 | if (DEBUG_HISTORY) Slog.v(TAG, "Start GPS to: " |
| 4696 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4697 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4698 | } |
| 4699 | mGpsNesting++; |
Narayan Kamath | 32684dd | 2018-01-08 17:32:51 +0000 | [diff] [blame] | 4700 | |
| 4701 | if (workChain == null) { |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 4702 | StatsLog.write_non_chained(StatsLog.GPS_SCAN_STATE_CHANGED, uid, null, |
| 4703 | StatsLog.GPS_SCAN_STATE_CHANGED__STATE__ON); |
Narayan Kamath | 32684dd | 2018-01-08 17:32:51 +0000 | [diff] [blame] | 4704 | } else { |
| 4705 | StatsLog.write(StatsLog.GPS_SCAN_STATE_CHANGED, |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 4706 | workChain.getUids(), workChain.getTags(), |
| 4707 | StatsLog.GPS_SCAN_STATE_CHANGED__STATE__ON); |
Narayan Kamath | 32684dd | 2018-01-08 17:32:51 +0000 | [diff] [blame] | 4708 | } |
| 4709 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4710 | getUidStatsLocked(uid).noteStartGps(elapsedRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4711 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4712 | |
Narayan Kamath | 32684dd | 2018-01-08 17:32:51 +0000 | [diff] [blame] | 4713 | private void noteStopGpsLocked(int uid, WorkChain workChain) { |
| 4714 | uid = getAttributionUid(uid, workChain); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4715 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4716 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4717 | mGpsNesting--; |
| 4718 | if (mGpsNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4719 | mHistoryCur.states &= ~HistoryItem.STATE_GPS_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4720 | if (DEBUG_HISTORY) Slog.v(TAG, "Stop GPS to: " |
| 4721 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4722 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 4723 | stopAllGpsSignalQualityTimersLocked(-1); |
| 4724 | mGpsSignalQualityBin = -1; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4725 | } |
Narayan Kamath | 32684dd | 2018-01-08 17:32:51 +0000 | [diff] [blame] | 4726 | |
| 4727 | if (workChain == null) { |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 4728 | StatsLog.write_non_chained(StatsLog.GPS_SCAN_STATE_CHANGED, uid, null, |
| 4729 | StatsLog.GPS_SCAN_STATE_CHANGED__STATE__OFF); |
Narayan Kamath | 32684dd | 2018-01-08 17:32:51 +0000 | [diff] [blame] | 4730 | } else { |
| 4731 | StatsLog.write(StatsLog.GPS_SCAN_STATE_CHANGED, workChain.getUids(), |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 4732 | workChain.getTags(), StatsLog.GPS_SCAN_STATE_CHANGED__STATE__OFF); |
Narayan Kamath | 32684dd | 2018-01-08 17:32:51 +0000 | [diff] [blame] | 4733 | } |
| 4734 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4735 | getUidStatsLocked(uid).noteStopGps(elapsedRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4736 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 4737 | |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 4738 | public void noteGpsSignalQualityLocked(int signalLevel) { |
| 4739 | if (mGpsNesting == 0) { |
| 4740 | return; |
| 4741 | } |
| 4742 | if (signalLevel < 0 || signalLevel >= GnssMetrics.NUM_GPS_SIGNAL_QUALITY_LEVELS) { |
| 4743 | stopAllGpsSignalQualityTimersLocked(-1); |
| 4744 | return; |
| 4745 | } |
| 4746 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4747 | final long uptime = mClocks.uptimeMillis(); |
| 4748 | if (mGpsSignalQualityBin != signalLevel) { |
| 4749 | if (mGpsSignalQualityBin >= 0) { |
| 4750 | mGpsSignalQualityTimer[mGpsSignalQualityBin].stopRunningLocked(elapsedRealtime); |
| 4751 | } |
| 4752 | if(!mGpsSignalQualityTimer[signalLevel].isRunningLocked()) { |
| 4753 | mGpsSignalQualityTimer[signalLevel].startRunningLocked(elapsedRealtime); |
| 4754 | } |
| 4755 | mHistoryCur.states2 = (mHistoryCur.states2&~HistoryItem.STATE2_GPS_SIGNAL_QUALITY_MASK) |
| 4756 | | (signalLevel << HistoryItem.STATE2_GPS_SIGNAL_QUALITY_SHIFT); |
| 4757 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4758 | mGpsSignalQualityBin = signalLevel; |
| 4759 | } |
| 4760 | return; |
| 4761 | } |
| 4762 | |
Andreas Gampe | 3f24e69 | 2018-02-05 13:24:28 -0800 | [diff] [blame] | 4763 | @GuardedBy("this") |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4764 | public void noteScreenStateLocked(int state) { |
Amith Yamasani | 674c9bb | 2017-02-01 09:45:17 -0800 | [diff] [blame] | 4765 | state = mPretendScreenOff ? Display.STATE_OFF : state; |
Santos Cordon | e94f050 | 2017-02-24 12:31:20 -0800 | [diff] [blame] | 4766 | |
| 4767 | // Battery stats relies on there being 4 states. To accommodate this, new states beyond the |
| 4768 | // original 4 are mapped to one of the originals. |
| 4769 | if (state > MAX_TRACKED_SCREEN_STATE) { |
| 4770 | switch (state) { |
| 4771 | case Display.STATE_VR: |
| 4772 | state = Display.STATE_ON; |
| 4773 | break; |
| 4774 | default: |
| 4775 | Slog.wtf(TAG, "Unknown screen state (not mapped): " + state); |
| 4776 | break; |
| 4777 | } |
| 4778 | } |
| 4779 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4780 | if (mScreenState != state) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 4781 | recordDailyStatsIfNeededLocked(true); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4782 | final int oldState = mScreenState; |
| 4783 | mScreenState = state; |
| 4784 | if (DEBUG) Slog.v(TAG, "Screen state: oldState=" + Display.stateToString(oldState) |
| 4785 | + ", newState=" + Display.stateToString(state)); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4786 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 4787 | if (state != Display.STATE_UNKNOWN) { |
| 4788 | int stepState = state-1; |
Santos Cordon | e94f050 | 2017-02-24 12:31:20 -0800 | [diff] [blame] | 4789 | if ((stepState & STEP_LEVEL_MODE_SCREEN_STATE) == stepState) { |
| 4790 | mModStepMode |= (mCurStepMode & STEP_LEVEL_MODE_SCREEN_STATE) ^ stepState; |
| 4791 | mCurStepMode = (mCurStepMode & ~STEP_LEVEL_MODE_SCREEN_STATE) | stepState; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 4792 | } else { |
| 4793 | Slog.wtf(TAG, "Unexpected screen state: " + state); |
| 4794 | } |
| 4795 | } |
| 4796 | |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4797 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4798 | final long uptime = mClocks.uptimeMillis(); |
| 4799 | |
| 4800 | boolean updateHistory = false; |
| 4801 | if (isScreenDoze(state)) { |
| 4802 | mHistoryCur.states |= HistoryItem.STATE_SCREEN_DOZE_FLAG; |
| 4803 | mScreenDozeTimer.startRunningLocked(elapsedRealtime); |
| 4804 | updateHistory = true; |
| 4805 | } else if (isScreenDoze(oldState)) { |
| 4806 | mHistoryCur.states &= ~HistoryItem.STATE_SCREEN_DOZE_FLAG; |
| 4807 | mScreenDozeTimer.stopRunningLocked(elapsedRealtime); |
| 4808 | updateHistory = true; |
| 4809 | } |
| 4810 | if (isScreenOn(state)) { |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4811 | mHistoryCur.states |= HistoryItem.STATE_SCREEN_ON_FLAG; |
| 4812 | if (DEBUG_HISTORY) Slog.v(TAG, "Screen on to: " |
| 4813 | + Integer.toHexString(mHistoryCur.states)); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4814 | mScreenOnTimer.startRunningLocked(elapsedRealtime); |
| 4815 | if (mScreenBrightnessBin >= 0) { |
| 4816 | mScreenBrightnessTimer[mScreenBrightnessBin].startRunningLocked(elapsedRealtime); |
| 4817 | } |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4818 | updateHistory = true; |
| 4819 | } else if (isScreenOn(oldState)) { |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4820 | mHistoryCur.states &= ~HistoryItem.STATE_SCREEN_ON_FLAG; |
| 4821 | if (DEBUG_HISTORY) Slog.v(TAG, "Screen off to: " |
| 4822 | + Integer.toHexString(mHistoryCur.states)); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4823 | mScreenOnTimer.stopRunningLocked(elapsedRealtime); |
| 4824 | if (mScreenBrightnessBin >= 0) { |
| 4825 | mScreenBrightnessTimer[mScreenBrightnessBin].stopRunningLocked(elapsedRealtime); |
| 4826 | } |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4827 | updateHistory = true; |
| 4828 | } |
| 4829 | if (updateHistory) { |
| 4830 | if (DEBUG_HISTORY) Slog.v(TAG, "Screen state to: " |
| 4831 | + Display.stateToString(state)); |
| 4832 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4833 | } |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 4834 | mExternalSync.scheduleCpuSyncDueToScreenStateChange( |
| 4835 | mOnBatteryTimeBase.isRunning(), mOnBatteryScreenOffTimeBase.isRunning()); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4836 | if (isScreenOn(state)) { |
| 4837 | updateTimeBasesLocked(mOnBatteryTimeBase.isRunning(), state, |
| 4838 | mClocks.uptimeMillis() * 1000, elapsedRealtime * 1000); |
| 4839 | // 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] | 4840 | noteStartWakeLocked(-1, -1, null, "screen", null, WAKE_TYPE_PARTIAL, false, |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4841 | elapsedRealtime, uptime); |
| 4842 | } else if (isScreenOn(oldState)) { |
Narayan Kamath | 8182202 | 2017-12-08 11:56:01 +0000 | [diff] [blame] | 4843 | noteStopWakeLocked(-1, -1, null, "screen", "screen", WAKE_TYPE_PARTIAL, |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4844 | elapsedRealtime, uptime); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4845 | updateTimeBasesLocked(mOnBatteryTimeBase.isRunning(), state, |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4846 | mClocks.uptimeMillis() * 1000, elapsedRealtime * 1000); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4847 | } |
| 4848 | // Update discharge amounts. |
| 4849 | if (mOnBatteryInternal) { |
| 4850 | updateDischargeScreenLevelsLocked(oldState, state); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 4851 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4852 | } |
| 4853 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4854 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4855 | public void noteScreenBrightnessLocked(int brightness) { |
| 4856 | // Bin the brightness. |
| 4857 | int bin = brightness / (256/NUM_SCREEN_BRIGHTNESS_BINS); |
| 4858 | if (bin < 0) bin = 0; |
| 4859 | else if (bin >= NUM_SCREEN_BRIGHTNESS_BINS) bin = NUM_SCREEN_BRIGHTNESS_BINS-1; |
| 4860 | if (mScreenBrightnessBin != bin) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4861 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4862 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4863 | mHistoryCur.states = (mHistoryCur.states&~HistoryItem.STATE_BRIGHTNESS_MASK) |
| 4864 | | (bin << HistoryItem.STATE_BRIGHTNESS_SHIFT); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4865 | if (DEBUG_HISTORY) Slog.v(TAG, "Screen brightness " + bin + " to: " |
| 4866 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4867 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4868 | if (mScreenState == Display.STATE_ON) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4869 | if (mScreenBrightnessBin >= 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4870 | mScreenBrightnessTimer[mScreenBrightnessBin].stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4871 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4872 | mScreenBrightnessTimer[bin].startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4873 | } |
| 4874 | mScreenBrightnessBin = bin; |
| 4875 | } |
| 4876 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4877 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4878 | public void noteUserActivityLocked(int uid, int event) { |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4879 | if (mOnBatteryInternal) { |
| 4880 | uid = mapUid(uid); |
| 4881 | getUidStatsLocked(uid).noteUserActivityLocked(event); |
| 4882 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4883 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4884 | |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 4885 | public void noteWakeUpLocked(String reason, int reasonUid) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4886 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4887 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 4888 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_SCREEN_WAKE_UP, |
| 4889 | reason, reasonUid); |
| 4890 | } |
| 4891 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4892 | public void noteInteractiveLocked(boolean interactive) { |
| 4893 | if (mInteractive != interactive) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4894 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4895 | mInteractive = interactive; |
| 4896 | if (DEBUG) Slog.v(TAG, "Interactive: " + interactive); |
| 4897 | if (interactive) { |
| 4898 | mInteractiveTimer.startRunningLocked(elapsedRealtime); |
| 4899 | } else { |
| 4900 | mInteractiveTimer.stopRunningLocked(elapsedRealtime); |
| 4901 | } |
| 4902 | } |
| 4903 | } |
| 4904 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 4905 | public void noteConnectivityChangedLocked(int type, String extra) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4906 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4907 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 4908 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_CONNECTIVITY_CHANGED, |
| 4909 | extra, type); |
| 4910 | mNumConnectivityChange++; |
| 4911 | } |
| 4912 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 4913 | private void noteMobileRadioApWakeupLocked(final long elapsedRealtimeMillis, |
| 4914 | final long uptimeMillis, int uid) { |
| 4915 | uid = mapUid(uid); |
| 4916 | addHistoryEventLocked(elapsedRealtimeMillis, uptimeMillis, HistoryItem.EVENT_WAKEUP_AP, "", |
| 4917 | uid); |
| 4918 | getUidStatsLocked(uid).noteMobileRadioApWakeupLocked(); |
| 4919 | } |
| 4920 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 4921 | /** |
| 4922 | * Updates the radio power state and returns true if an external stats collection should occur. |
| 4923 | */ |
| 4924 | public boolean noteMobileRadioPowerStateLocked(int powerState, long timestampNs, int uid) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4925 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4926 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 4927 | if (mMobileRadioPowerState != powerState) { |
| 4928 | long realElapsedRealtimeMs; |
| 4929 | final boolean active = |
| 4930 | powerState == DataConnectionRealTimeInfo.DC_POWER_STATE_MEDIUM |
| 4931 | || powerState == DataConnectionRealTimeInfo.DC_POWER_STATE_HIGH; |
| 4932 | if (active) { |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 4933 | if (uid > 0) { |
| 4934 | noteMobileRadioApWakeupLocked(elapsedRealtime, uptime, uid); |
| 4935 | } |
| 4936 | |
Adam Lesinski | 9acfd81 | 2016-04-19 18:29:50 -0700 | [diff] [blame] | 4937 | mMobileRadioActiveStartTime = realElapsedRealtimeMs = timestampNs / (1000 * 1000); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 4938 | mHistoryCur.states |= HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG; |
| 4939 | } else { |
| 4940 | realElapsedRealtimeMs = timestampNs / (1000*1000); |
Dianne Hackborn | f7097a5 | 2014-05-13 09:56:14 -0700 | [diff] [blame] | 4941 | long lastUpdateTimeMs = mMobileRadioActiveStartTime; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 4942 | if (realElapsedRealtimeMs < lastUpdateTimeMs) { |
| 4943 | Slog.wtf(TAG, "Data connection inactive timestamp " + realElapsedRealtimeMs |
| 4944 | + " is before start time " + lastUpdateTimeMs); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4945 | realElapsedRealtimeMs = elapsedRealtime; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 4946 | } else if (realElapsedRealtimeMs < elapsedRealtime) { |
| 4947 | mMobileRadioActiveAdjustedTime.addCountLocked(elapsedRealtime |
| 4948 | - realElapsedRealtimeMs); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4949 | } |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 4950 | mHistoryCur.states &= ~HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG; |
| 4951 | } |
| 4952 | if (DEBUG_HISTORY) Slog.v(TAG, "Mobile network active " + active + " to: " |
| 4953 | + Integer.toHexString(mHistoryCur.states)); |
| 4954 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4955 | mMobileRadioPowerState = powerState; |
Bookatz | ddccf0a | 2017-11-28 16:48:14 -0800 | [diff] [blame] | 4956 | StatsLog.write(StatsLog.MOBILE_RADIO_POWER_STATE_CHANGED, uid, powerState); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 4957 | if (active) { |
| 4958 | mMobileRadioActiveTimer.startRunningLocked(elapsedRealtime); |
| 4959 | mMobileRadioActivePerAppTimer.startRunningLocked(elapsedRealtime); |
| 4960 | } else { |
| 4961 | mMobileRadioActiveTimer.stopRunningLocked(realElapsedRealtimeMs); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 4962 | mMobileRadioActivePerAppTimer.stopRunningLocked(realElapsedRealtimeMs); |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 4963 | // Tell the caller to collect radio network/power stats. |
| 4964 | return true; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 4965 | } |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 4966 | } |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 4967 | return false; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 4968 | } |
| 4969 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 4970 | public void notePowerSaveModeLocked(boolean enabled) { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4971 | if (mPowerSaveModeEnabled != enabled) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 4972 | int stepState = enabled ? STEP_LEVEL_MODE_POWER_SAVE : 0; |
| 4973 | mModStepMode |= (mCurStepMode&STEP_LEVEL_MODE_POWER_SAVE) ^ stepState; |
| 4974 | mCurStepMode = (mCurStepMode&~STEP_LEVEL_MODE_POWER_SAVE) | stepState; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4975 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4976 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4977 | mPowerSaveModeEnabled = enabled; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4978 | if (enabled) { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4979 | mHistoryCur.states2 |= HistoryItem.STATE2_POWER_SAVE_FLAG; |
| 4980 | if (DEBUG_HISTORY) Slog.v(TAG, "Power save mode enabled to: " |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4981 | + Integer.toHexString(mHistoryCur.states2)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4982 | mPowerSaveModeEnabledTimer.startRunningLocked(elapsedRealtime); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4983 | } else { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4984 | mHistoryCur.states2 &= ~HistoryItem.STATE2_POWER_SAVE_FLAG; |
| 4985 | if (DEBUG_HISTORY) Slog.v(TAG, "Power save mode disabled to: " |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4986 | + Integer.toHexString(mHistoryCur.states2)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4987 | mPowerSaveModeEnabledTimer.stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4988 | } |
| 4989 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 4990 | StatsLog.write(StatsLog.BATTERY_SAVER_MODE_STATE_CHANGED, enabled ? |
| 4991 | StatsLog.BATTERY_SAVER_MODE_STATE_CHANGED__STATE__ON : |
| 4992 | StatsLog.BATTERY_SAVER_MODE_STATE_CHANGED__STATE__OFF); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4993 | } |
| 4994 | } |
| 4995 | |
Bookatz | ddccf0a | 2017-11-28 16:48:14 -0800 | [diff] [blame] | 4996 | public void noteDeviceIdleModeLocked(final int mode, String activeReason, int activeUid) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4997 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4998 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4999 | boolean nowIdling = mode == DEVICE_IDLE_MODE_DEEP; |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 5000 | if (mDeviceIdling && !nowIdling && activeReason == null) { |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5001 | // We don't go out of general idling mode until explicitly taken out of |
| 5002 | // device idle through going active or significant motion. |
| 5003 | nowIdling = true; |
| 5004 | } |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 5005 | boolean nowLightIdling = mode == DEVICE_IDLE_MODE_LIGHT; |
| 5006 | if (mDeviceLightIdling && !nowLightIdling && !nowIdling && activeReason == null) { |
| 5007 | // We don't go out of general light idling mode until explicitly taken out of |
| 5008 | // device idle through going active or significant motion. |
| 5009 | nowLightIdling = true; |
| 5010 | } |
| 5011 | if (activeReason != null && (mDeviceIdling || mDeviceLightIdling)) { |
| 5012 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_ACTIVE, |
| 5013 | activeReason, activeUid); |
| 5014 | } |
Bookatz | ddccf0a | 2017-11-28 16:48:14 -0800 | [diff] [blame] | 5015 | if (mDeviceIdling != nowIdling || mDeviceLightIdling != nowLightIdling) { |
| 5016 | int statsmode; |
| 5017 | if (nowIdling) statsmode = DEVICE_IDLE_MODE_DEEP; |
| 5018 | else if (nowLightIdling) statsmode = DEVICE_IDLE_MODE_LIGHT; |
| 5019 | else statsmode = DEVICE_IDLE_MODE_OFF; |
| 5020 | StatsLog.write(StatsLog.DEVICE_IDLING_MODE_STATE_CHANGED, statsmode); |
| 5021 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5022 | if (mDeviceIdling != nowIdling) { |
| 5023 | mDeviceIdling = nowIdling; |
| 5024 | int stepState = nowIdling ? STEP_LEVEL_MODE_DEVICE_IDLE : 0; |
| 5025 | mModStepMode |= (mCurStepMode&STEP_LEVEL_MODE_DEVICE_IDLE) ^ stepState; |
| 5026 | mCurStepMode = (mCurStepMode&~STEP_LEVEL_MODE_DEVICE_IDLE) | stepState; |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 5027 | if (nowIdling) { |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5028 | mDeviceIdlingTimer.startRunningLocked(elapsedRealtime); |
| 5029 | } else { |
| 5030 | mDeviceIdlingTimer.stopRunningLocked(elapsedRealtime); |
| 5031 | } |
| 5032 | } |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 5033 | if (mDeviceLightIdling != nowLightIdling) { |
| 5034 | mDeviceLightIdling = nowLightIdling; |
| 5035 | if (nowLightIdling) { |
| 5036 | mDeviceLightIdlingTimer.startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 5037 | } else { |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 5038 | mDeviceLightIdlingTimer.stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 5039 | } |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 5040 | } |
| 5041 | if (mDeviceIdleMode != mode) { |
| 5042 | mHistoryCur.states2 = (mHistoryCur.states2 & ~HistoryItem.STATE2_DEVICE_IDLE_MASK) |
| 5043 | | (mode << HistoryItem.STATE2_DEVICE_IDLE_SHIFT); |
| 5044 | if (DEBUG_HISTORY) Slog.v(TAG, "Device idle mode changed to: " |
| 5045 | + Integer.toHexString(mHistoryCur.states2)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 5046 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 5047 | long lastDuration = elapsedRealtime - mLastIdleTimeStart; |
| 5048 | mLastIdleTimeStart = elapsedRealtime; |
| 5049 | if (mDeviceIdleMode == DEVICE_IDLE_MODE_LIGHT) { |
| 5050 | if (lastDuration > mLongestLightIdleTime) { |
| 5051 | mLongestLightIdleTime = lastDuration; |
| 5052 | } |
| 5053 | mDeviceIdleModeLightTimer.stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 5054 | } else if (mDeviceIdleMode == DEVICE_IDLE_MODE_DEEP) { |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 5055 | if (lastDuration > mLongestFullIdleTime) { |
| 5056 | mLongestFullIdleTime = lastDuration; |
| 5057 | } |
| 5058 | mDeviceIdleModeFullTimer.stopRunningLocked(elapsedRealtime); |
| 5059 | } |
| 5060 | if (mode == DEVICE_IDLE_MODE_LIGHT) { |
| 5061 | mDeviceIdleModeLightTimer.startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 5062 | } else if (mode == DEVICE_IDLE_MODE_DEEP) { |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 5063 | mDeviceIdleModeFullTimer.startRunningLocked(elapsedRealtime); |
| 5064 | } |
| 5065 | mDeviceIdleMode = mode; |
Bookatz | ddccf0a | 2017-11-28 16:48:14 -0800 | [diff] [blame] | 5066 | StatsLog.write(StatsLog.DEVICE_IDLE_MODE_STATE_CHANGED, mode); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 5067 | } |
| 5068 | } |
| 5069 | |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 5070 | public void notePackageInstalledLocked(String pkgName, long versionCode) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5071 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5072 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 5073 | // XXX need to figure out what to do with long version codes. |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 5074 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_PACKAGE_INSTALLED, |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 5075 | pkgName, (int)versionCode); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5076 | PackageChange pc = new PackageChange(); |
| 5077 | pc.mPackageName = pkgName; |
| 5078 | pc.mUpdate = true; |
| 5079 | pc.mVersionCode = versionCode; |
| 5080 | addPackageChange(pc); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 5081 | } |
| 5082 | |
| 5083 | public void notePackageUninstalledLocked(String pkgName) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5084 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5085 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 5086 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_PACKAGE_UNINSTALLED, |
| 5087 | pkgName, 0); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5088 | PackageChange pc = new PackageChange(); |
| 5089 | pc.mPackageName = pkgName; |
| 5090 | pc.mUpdate = true; |
| 5091 | addPackageChange(pc); |
| 5092 | } |
| 5093 | |
| 5094 | private void addPackageChange(PackageChange pc) { |
| 5095 | if (mDailyPackageChanges == null) { |
| 5096 | mDailyPackageChanges = new ArrayList<>(); |
| 5097 | } |
| 5098 | mDailyPackageChanges.add(pc); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 5099 | } |
| 5100 | |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 5101 | void stopAllGpsSignalQualityTimersLocked(int except) { |
| 5102 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5103 | for (int i = 0; i < GnssMetrics.NUM_GPS_SIGNAL_QUALITY_LEVELS; i++) { |
| 5104 | if (i == except) { |
| 5105 | continue; |
| 5106 | } |
| 5107 | while (mGpsSignalQualityTimer[i].isRunningLocked()) { |
| 5108 | mGpsSignalQualityTimer[i].stopRunningLocked(elapsedRealtime); |
| 5109 | } |
| 5110 | } |
| 5111 | } |
| 5112 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5113 | public void notePhoneOnLocked() { |
| 5114 | if (!mPhoneOn) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5115 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5116 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 5117 | mHistoryCur.states2 |= HistoryItem.STATE2_PHONE_IN_CALL_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5118 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone on to: " |
| 5119 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 5120 | addHistoryRecordLocked(elapsedRealtime, uptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5121 | mPhoneOn = true; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5122 | mPhoneOnTimer.startRunningLocked(elapsedRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5123 | } |
| 5124 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5125 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5126 | public void notePhoneOffLocked() { |
| 5127 | if (mPhoneOn) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5128 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5129 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 5130 | mHistoryCur.states2 &= ~HistoryItem.STATE2_PHONE_IN_CALL_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5131 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone off to: " |
| 5132 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 5133 | addHistoryRecordLocked(elapsedRealtime, uptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5134 | mPhoneOn = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5135 | mPhoneOnTimer.stopRunningLocked(elapsedRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5136 | } |
| 5137 | } |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 5138 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5139 | void stopAllPhoneSignalStrengthTimersLocked(int except) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5140 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 5141 | for (int i = 0; i < SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 5142 | if (i == except) { |
| 5143 | continue; |
| 5144 | } |
| 5145 | while (mPhoneSignalStrengthsTimer[i].isRunningLocked()) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5146 | mPhoneSignalStrengthsTimer[i].stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 5147 | } |
| 5148 | } |
| 5149 | } |
| 5150 | |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5151 | private int fixPhoneServiceState(int state, int signalBin) { |
| 5152 | if (mPhoneSimStateRaw == TelephonyManager.SIM_STATE_ABSENT) { |
| 5153 | // In this case we will always be STATE_OUT_OF_SERVICE, so need |
| 5154 | // to infer that we are scanning from other data. |
| 5155 | if (state == ServiceState.STATE_OUT_OF_SERVICE |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 5156 | && signalBin > SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5157 | state = ServiceState.STATE_IN_SERVICE; |
| 5158 | } |
| 5159 | } |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 5160 | |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5161 | return state; |
| 5162 | } |
| 5163 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5164 | private void updateAllPhoneStateLocked(int state, int simState, int strengthBin) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5165 | boolean scanning = false; |
| 5166 | boolean newHistory = false; |
| 5167 | |
| 5168 | mPhoneServiceStateRaw = state; |
| 5169 | mPhoneSimStateRaw = simState; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5170 | mPhoneSignalStrengthBinRaw = strengthBin; |
| 5171 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5172 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5173 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5174 | |
| 5175 | if (simState == TelephonyManager.SIM_STATE_ABSENT) { |
| 5176 | // In this case we will always be STATE_OUT_OF_SERVICE, so need |
| 5177 | // to infer that we are scanning from other data. |
| 5178 | if (state == ServiceState.STATE_OUT_OF_SERVICE |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5179 | && strengthBin > SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5180 | state = ServiceState.STATE_IN_SERVICE; |
| 5181 | } |
| 5182 | } |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 5183 | |
| 5184 | // If the phone is powered off, stop all timers. |
| 5185 | if (state == ServiceState.STATE_POWER_OFF) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5186 | strengthBin = -1; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 5187 | |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5188 | // If we are in service, make sure the correct signal string timer is running. |
| 5189 | } else if (state == ServiceState.STATE_IN_SERVICE) { |
| 5190 | // Bin will be changed below. |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 5191 | |
| 5192 | // If we're out of service, we are in the lowest signal strength |
| 5193 | // bin and have the scanning bit set. |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 5194 | } else if (state == ServiceState.STATE_OUT_OF_SERVICE) { |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 5195 | scanning = true; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5196 | strengthBin = SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 5197 | if (!mPhoneSignalScanningTimer.isRunningLocked()) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5198 | mHistoryCur.states |= HistoryItem.STATE_PHONE_SCANNING_FLAG; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5199 | newHistory = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5200 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone started scanning to: " |
| 5201 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5202 | mPhoneSignalScanningTimer.startRunningLocked(elapsedRealtime); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 5203 | } |
| 5204 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5205 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 5206 | if (!scanning) { |
| 5207 | // If we are no longer scanning, then stop the scanning timer. |
| 5208 | if (mPhoneSignalScanningTimer.isRunningLocked()) { |
| 5209 | mHistoryCur.states &= ~HistoryItem.STATE_PHONE_SCANNING_FLAG; |
| 5210 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone stopped scanning to: " |
| 5211 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5212 | newHistory = true; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5213 | mPhoneSignalScanningTimer.stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 5214 | } |
| 5215 | } |
| 5216 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5217 | if (mPhoneServiceState != state) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5218 | mHistoryCur.states = (mHistoryCur.states&~HistoryItem.STATE_PHONE_STATE_MASK) |
| 5219 | | (state << HistoryItem.STATE_PHONE_STATE_SHIFT); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5220 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone state " + state + " to: " |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5221 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5222 | newHistory = true; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5223 | mPhoneServiceState = state; |
| 5224 | } |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5225 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5226 | if (mPhoneSignalStrengthBin != strengthBin) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5227 | if (mPhoneSignalStrengthBin >= 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5228 | mPhoneSignalStrengthsTimer[mPhoneSignalStrengthBin].stopRunningLocked( |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5229 | elapsedRealtime); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5230 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5231 | if (strengthBin >= 0) { |
| 5232 | if (!mPhoneSignalStrengthsTimer[strengthBin].isRunningLocked()) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5233 | mPhoneSignalStrengthsTimer[strengthBin].startRunningLocked(elapsedRealtime); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5234 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5235 | mHistoryCur.states = (mHistoryCur.states&~HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_MASK) |
| 5236 | | (strengthBin << HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_SHIFT); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5237 | if (DEBUG_HISTORY) Slog.v(TAG, "Signal strength " + strengthBin + " to: " |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5238 | + Integer.toHexString(mHistoryCur.states)); |
| 5239 | newHistory = true; |
Bookatz | e588524 | 2017-10-24 20:10:31 -0700 | [diff] [blame] | 5240 | StatsLog.write(StatsLog.PHONE_SIGNAL_STRENGTH_CHANGED, strengthBin); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5241 | } else { |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5242 | stopAllPhoneSignalStrengthTimersLocked(-1); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5243 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5244 | mPhoneSignalStrengthBin = strengthBin; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5245 | } |
| 5246 | |
| 5247 | if (newHistory) { |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 5248 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5249 | } |
| 5250 | } |
| 5251 | |
| 5252 | /** |
| 5253 | * Telephony stack updates the phone state. |
| 5254 | * @param state phone state from ServiceState.getState() |
| 5255 | */ |
| 5256 | public void notePhoneStateLocked(int state, int simState) { |
| 5257 | updateAllPhoneStateLocked(state, simState, mPhoneSignalStrengthBinRaw); |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 5258 | } |
| 5259 | |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 5260 | public void notePhoneSignalStrengthLocked(SignalStrength signalStrength) { |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 5261 | // Bin the strength. |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 5262 | int bin = signalStrength.getLevel(); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5263 | updateAllPhoneStateLocked(mPhoneServiceStateRaw, mPhoneSimStateRaw, bin); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 5264 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5265 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 5266 | public void notePhoneDataConnectionStateLocked(int dataType, boolean hasData) { |
| 5267 | int bin = DATA_CONNECTION_NONE; |
| 5268 | if (hasData) { |
| 5269 | switch (dataType) { |
| 5270 | case TelephonyManager.NETWORK_TYPE_EDGE: |
| 5271 | bin = DATA_CONNECTION_EDGE; |
| 5272 | break; |
| 5273 | case TelephonyManager.NETWORK_TYPE_GPRS: |
| 5274 | bin = DATA_CONNECTION_GPRS; |
| 5275 | break; |
| 5276 | case TelephonyManager.NETWORK_TYPE_UMTS: |
| 5277 | bin = DATA_CONNECTION_UMTS; |
| 5278 | break; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5279 | case TelephonyManager.NETWORK_TYPE_CDMA: |
| 5280 | bin = DATA_CONNECTION_CDMA; |
| 5281 | break; |
| 5282 | case TelephonyManager.NETWORK_TYPE_EVDO_0: |
| 5283 | bin = DATA_CONNECTION_EVDO_0; |
| 5284 | break; |
| 5285 | case TelephonyManager.NETWORK_TYPE_EVDO_A: |
| 5286 | bin = DATA_CONNECTION_EVDO_A; |
| 5287 | break; |
| 5288 | case TelephonyManager.NETWORK_TYPE_1xRTT: |
| 5289 | bin = DATA_CONNECTION_1xRTT; |
| 5290 | break; |
| 5291 | case TelephonyManager.NETWORK_TYPE_HSDPA: |
| 5292 | bin = DATA_CONNECTION_HSDPA; |
| 5293 | break; |
| 5294 | case TelephonyManager.NETWORK_TYPE_HSUPA: |
| 5295 | bin = DATA_CONNECTION_HSUPA; |
| 5296 | break; |
| 5297 | case TelephonyManager.NETWORK_TYPE_HSPA: |
| 5298 | bin = DATA_CONNECTION_HSPA; |
| 5299 | break; |
| 5300 | case TelephonyManager.NETWORK_TYPE_IDEN: |
| 5301 | bin = DATA_CONNECTION_IDEN; |
| 5302 | break; |
| 5303 | case TelephonyManager.NETWORK_TYPE_EVDO_B: |
| 5304 | bin = DATA_CONNECTION_EVDO_B; |
| 5305 | break; |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 5306 | case TelephonyManager.NETWORK_TYPE_LTE: |
| 5307 | bin = DATA_CONNECTION_LTE; |
| 5308 | break; |
| 5309 | case TelephonyManager.NETWORK_TYPE_EHRPD: |
| 5310 | bin = DATA_CONNECTION_EHRPD; |
| 5311 | break; |
Patrick Tjin | b71703c | 2013-11-06 09:27:03 -0800 | [diff] [blame] | 5312 | case TelephonyManager.NETWORK_TYPE_HSPAP: |
| 5313 | bin = DATA_CONNECTION_HSPAP; |
| 5314 | break; |
Siddharth Ray | c72081d | 2018-02-13 11:31:54 -0800 | [diff] [blame] | 5315 | case TelephonyManager.NETWORK_TYPE_GSM: |
| 5316 | bin = DATA_CONNECTION_GSM; |
| 5317 | break; |
| 5318 | case TelephonyManager.NETWORK_TYPE_TD_SCDMA: |
| 5319 | bin = DATA_CONNECTION_TD_SCDMA; |
| 5320 | break; |
| 5321 | case TelephonyManager.NETWORK_TYPE_IWLAN: |
| 5322 | bin = DATA_CONNECTION_IWLAN; |
| 5323 | break; |
| 5324 | case TelephonyManager.NETWORK_TYPE_LTE_CA: |
| 5325 | bin = DATA_CONNECTION_LTE_CA; |
| 5326 | break; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 5327 | default: |
| 5328 | bin = DATA_CONNECTION_OTHER; |
| 5329 | break; |
| 5330 | } |
| 5331 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 5332 | if (DEBUG) Log.i(TAG, "Phone Data Connection -> " + dataType + " = " + hasData); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 5333 | if (mPhoneDataConnectionType != bin) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5334 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5335 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5336 | mHistoryCur.states = (mHistoryCur.states&~HistoryItem.STATE_DATA_CONNECTION_MASK) |
| 5337 | | (bin << HistoryItem.STATE_DATA_CONNECTION_SHIFT); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5338 | if (DEBUG_HISTORY) Slog.v(TAG, "Data connection " + bin + " to: " |
| 5339 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 5340 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 5341 | if (mPhoneDataConnectionType >= 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5342 | mPhoneDataConnectionsTimer[mPhoneDataConnectionType].stopRunningLocked( |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5343 | elapsedRealtime); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 5344 | } |
| 5345 | mPhoneDataConnectionType = bin; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5346 | mPhoneDataConnectionsTimer[bin].startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 5347 | } |
| 5348 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5349 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5350 | public void noteWifiOnLocked() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5351 | if (!mWifiOn) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5352 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5353 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5354 | mHistoryCur.states2 |= HistoryItem.STATE2_WIFI_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5355 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI on to: " |
| 5356 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 5357 | addHistoryRecordLocked(elapsedRealtime, uptime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5358 | mWifiOn = true; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5359 | mWifiOnTimer.startRunningLocked(elapsedRealtime); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5360 | scheduleSyncExternalStatsLocked("wifi-off", ExternalStatsSync.UPDATE_WIFI); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5361 | } |
| 5362 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5363 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5364 | public void noteWifiOffLocked() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5365 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5366 | final long uptime = mClocks.uptimeMillis(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5367 | if (mWifiOn) { |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5368 | mHistoryCur.states2 &= ~HistoryItem.STATE2_WIFI_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5369 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI off to: " |
| 5370 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 5371 | addHistoryRecordLocked(elapsedRealtime, uptime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5372 | mWifiOn = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5373 | mWifiOnTimer.stopRunningLocked(elapsedRealtime); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5374 | scheduleSyncExternalStatsLocked("wifi-on", ExternalStatsSync.UPDATE_WIFI); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5375 | } |
| 5376 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 5377 | |
| 5378 | public void noteAudioOnLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5379 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5380 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5381 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 5382 | if (mAudioOnNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5383 | mHistoryCur.states |= HistoryItem.STATE_AUDIO_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5384 | if (DEBUG_HISTORY) Slog.v(TAG, "Audio on to: " |
| 5385 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 5386 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5387 | mAudioOnTimer.startRunningLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 5388 | } |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 5389 | mAudioOnNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5390 | getUidStatsLocked(uid).noteAudioTurnedOnLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 5391 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5392 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 5393 | public void noteAudioOffLocked(int uid) { |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 5394 | if (mAudioOnNesting == 0) { |
| 5395 | return; |
| 5396 | } |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5397 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5398 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5399 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 5400 | if (--mAudioOnNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5401 | mHistoryCur.states &= ~HistoryItem.STATE_AUDIO_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5402 | if (DEBUG_HISTORY) Slog.v(TAG, "Audio off to: " |
| 5403 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 5404 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5405 | mAudioOnTimer.stopRunningLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 5406 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5407 | getUidStatsLocked(uid).noteAudioTurnedOffLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 5408 | } |
| 5409 | |
| 5410 | public void noteVideoOnLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5411 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5412 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5413 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 5414 | if (mVideoOnNesting == 0) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5415 | mHistoryCur.states2 |= HistoryItem.STATE2_VIDEO_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5416 | if (DEBUG_HISTORY) Slog.v(TAG, "Video on to: " |
| 5417 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 5418 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5419 | mVideoOnTimer.startRunningLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 5420 | } |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 5421 | mVideoOnNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5422 | getUidStatsLocked(uid).noteVideoTurnedOnLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 5423 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5424 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 5425 | public void noteVideoOffLocked(int uid) { |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 5426 | if (mVideoOnNesting == 0) { |
| 5427 | return; |
| 5428 | } |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5429 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5430 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5431 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 5432 | if (--mVideoOnNesting == 0) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5433 | mHistoryCur.states2 &= ~HistoryItem.STATE2_VIDEO_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5434 | if (DEBUG_HISTORY) Slog.v(TAG, "Video off to: " |
| 5435 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 5436 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5437 | mVideoOnTimer.stopRunningLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 5438 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5439 | getUidStatsLocked(uid).noteVideoTurnedOffLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 5440 | } |
| 5441 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 5442 | public void noteResetAudioLocked() { |
| 5443 | if (mAudioOnNesting > 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5444 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5445 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 5446 | mAudioOnNesting = 0; |
| 5447 | mHistoryCur.states &= ~HistoryItem.STATE_AUDIO_ON_FLAG; |
| 5448 | if (DEBUG_HISTORY) Slog.v(TAG, "Audio off to: " |
| 5449 | + Integer.toHexString(mHistoryCur.states)); |
| 5450 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 5451 | mAudioOnTimer.stopAllRunningLocked(elapsedRealtime); |
| 5452 | for (int i=0; i<mUidStats.size(); i++) { |
| 5453 | BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 5454 | uid.noteResetAudioLocked(elapsedRealtime); |
| 5455 | } |
| 5456 | } |
| 5457 | } |
| 5458 | |
| 5459 | public void noteResetVideoLocked() { |
| 5460 | if (mVideoOnNesting > 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5461 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5462 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 5463 | mAudioOnNesting = 0; |
| 5464 | mHistoryCur.states2 &= ~HistoryItem.STATE2_VIDEO_ON_FLAG; |
| 5465 | if (DEBUG_HISTORY) Slog.v(TAG, "Video off to: " |
| 5466 | + Integer.toHexString(mHistoryCur.states)); |
| 5467 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 5468 | mVideoOnTimer.stopAllRunningLocked(elapsedRealtime); |
| 5469 | for (int i=0; i<mUidStats.size(); i++) { |
| 5470 | BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 5471 | uid.noteResetVideoLocked(elapsedRealtime); |
| 5472 | } |
| 5473 | } |
| 5474 | } |
| 5475 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5476 | public void noteActivityResumedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5477 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5478 | getUidStatsLocked(uid).noteActivityResumedLocked(mClocks.elapsedRealtime()); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5479 | } |
| 5480 | |
| 5481 | public void noteActivityPausedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5482 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5483 | getUidStatsLocked(uid).noteActivityPausedLocked(mClocks.elapsedRealtime()); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5484 | } |
| 5485 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5486 | public void noteVibratorOnLocked(int uid, long durationMillis) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5487 | uid = mapUid(uid); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5488 | getUidStatsLocked(uid).noteVibratorOnLocked(durationMillis); |
| 5489 | } |
| 5490 | |
| 5491 | public void noteVibratorOffLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5492 | uid = mapUid(uid); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5493 | getUidStatsLocked(uid).noteVibratorOffLocked(); |
| 5494 | } |
| 5495 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5496 | public void noteFlashlightOnLocked(int uid) { |
| 5497 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5498 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5499 | final long uptime = mClocks.uptimeMillis(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5500 | if (mFlashlightOnNesting++ == 0) { |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 5501 | mHistoryCur.states2 |= HistoryItem.STATE2_FLASHLIGHT_FLAG; |
| 5502 | if (DEBUG_HISTORY) Slog.v(TAG, "Flashlight on to: " |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5503 | + Integer.toHexString(mHistoryCur.states2)); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 5504 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 5505 | mFlashlightOnTimer.startRunningLocked(elapsedRealtime); |
| 5506 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5507 | getUidStatsLocked(uid).noteFlashlightTurnedOnLocked(elapsedRealtime); |
| 5508 | } |
| 5509 | |
| 5510 | public void noteFlashlightOffLocked(int uid) { |
| 5511 | if (mFlashlightOnNesting == 0) { |
| 5512 | return; |
| 5513 | } |
| 5514 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5515 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5516 | final long uptime = mClocks.uptimeMillis(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5517 | if (--mFlashlightOnNesting == 0) { |
| 5518 | mHistoryCur.states2 &= ~HistoryItem.STATE2_FLASHLIGHT_FLAG; |
| 5519 | if (DEBUG_HISTORY) Slog.v(TAG, "Flashlight off to: " |
| 5520 | + Integer.toHexString(mHistoryCur.states2)); |
| 5521 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 5522 | mFlashlightOnTimer.stopRunningLocked(elapsedRealtime); |
| 5523 | } |
| 5524 | getUidStatsLocked(uid).noteFlashlightTurnedOffLocked(elapsedRealtime); |
| 5525 | } |
| 5526 | |
| 5527 | public void noteCameraOnLocked(int uid) { |
| 5528 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5529 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5530 | final long uptime = mClocks.uptimeMillis(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5531 | if (mCameraOnNesting++ == 0) { |
| 5532 | mHistoryCur.states2 |= HistoryItem.STATE2_CAMERA_FLAG; |
| 5533 | if (DEBUG_HISTORY) Slog.v(TAG, "Camera on to: " |
| 5534 | + Integer.toHexString(mHistoryCur.states2)); |
| 5535 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 5536 | mCameraOnTimer.startRunningLocked(elapsedRealtime); |
| 5537 | } |
| 5538 | getUidStatsLocked(uid).noteCameraTurnedOnLocked(elapsedRealtime); |
| 5539 | } |
| 5540 | |
| 5541 | public void noteCameraOffLocked(int uid) { |
| 5542 | if (mCameraOnNesting == 0) { |
| 5543 | return; |
| 5544 | } |
| 5545 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5546 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5547 | final long uptime = mClocks.uptimeMillis(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5548 | if (--mCameraOnNesting == 0) { |
| 5549 | mHistoryCur.states2 &= ~HistoryItem.STATE2_CAMERA_FLAG; |
| 5550 | if (DEBUG_HISTORY) Slog.v(TAG, "Camera off to: " |
| 5551 | + Integer.toHexString(mHistoryCur.states2)); |
| 5552 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 5553 | mCameraOnTimer.stopRunningLocked(elapsedRealtime); |
| 5554 | } |
| 5555 | getUidStatsLocked(uid).noteCameraTurnedOffLocked(elapsedRealtime); |
| 5556 | } |
| 5557 | |
| 5558 | public void noteResetCameraLocked() { |
| 5559 | if (mCameraOnNesting > 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5560 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5561 | final long uptime = mClocks.uptimeMillis(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5562 | mCameraOnNesting = 0; |
| 5563 | mHistoryCur.states2 &= ~HistoryItem.STATE2_CAMERA_FLAG; |
| 5564 | if (DEBUG_HISTORY) Slog.v(TAG, "Camera off to: " |
| 5565 | + Integer.toHexString(mHistoryCur.states2)); |
| 5566 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 5567 | mCameraOnTimer.stopAllRunningLocked(elapsedRealtime); |
| 5568 | for (int i=0; i<mUidStats.size(); i++) { |
| 5569 | BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 5570 | uid.noteResetCameraLocked(elapsedRealtime); |
| 5571 | } |
| 5572 | } |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 5573 | } |
| 5574 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5575 | public void noteResetFlashlightLocked() { |
| 5576 | if (mFlashlightOnNesting > 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5577 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5578 | final long uptime = mClocks.uptimeMillis(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5579 | mFlashlightOnNesting = 0; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 5580 | mHistoryCur.states2 &= ~HistoryItem.STATE2_FLASHLIGHT_FLAG; |
| 5581 | if (DEBUG_HISTORY) Slog.v(TAG, "Flashlight off to: " |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5582 | + Integer.toHexString(mHistoryCur.states2)); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 5583 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5584 | mFlashlightOnTimer.stopAllRunningLocked(elapsedRealtime); |
| 5585 | for (int i=0; i<mUidStats.size(); i++) { |
| 5586 | BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 5587 | uid.noteResetFlashlightLocked(elapsedRealtime); |
| 5588 | } |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 5589 | } |
| 5590 | } |
| 5591 | |
Narayan Kamath | 0ebc96c | 2017-12-29 13:32:38 +0000 | [diff] [blame] | 5592 | private void noteBluetoothScanStartedLocked(WorkChain workChain, int uid, |
| 5593 | boolean isUnoptimized) { |
| 5594 | uid = getAttributionUid(uid, workChain); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5595 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5596 | final long uptime = mClocks.uptimeMillis(); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5597 | if (mBluetoothScanNesting == 0) { |
| 5598 | mHistoryCur.states2 |= HistoryItem.STATE2_BLUETOOTH_SCAN_FLAG; |
| 5599 | if (DEBUG_HISTORY) Slog.v(TAG, "BLE scan started for: " |
| 5600 | + Integer.toHexString(mHistoryCur.states2)); |
| 5601 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Adam Lesinski | d9b99be | 2016-03-30 16:58:51 -0700 | [diff] [blame] | 5602 | mBluetoothScanTimer.startRunningLocked(elapsedRealtime); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5603 | } |
| 5604 | mBluetoothScanNesting++; |
Narayan Kamath | 0ebc96c | 2017-12-29 13:32:38 +0000 | [diff] [blame] | 5605 | |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 5606 | if (workChain != null) { |
| 5607 | StatsLog.write(StatsLog.BLE_SCAN_STATE_CHANGED, |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 5608 | workChain.getUids(), workChain.getTags(), |
| 5609 | StatsLog.BLE_SCAN_STATE_CHANGED__STATE__ON); |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 5610 | if (isUnoptimized) { |
| 5611 | StatsLog.write(StatsLog.BLE_UNOPTIMIZED_SCAN_STATE_CHANGED, |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 5612 | workChain.getUids(), workChain.getTags(), |
| 5613 | StatsLog.BLE_UNOPTIMIZED_SCAN_STATE_CHANGED__STATE__ON); |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 5614 | } |
| 5615 | } else { |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 5616 | StatsLog.write_non_chained(StatsLog.BLE_SCAN_STATE_CHANGED, uid, null, |
| 5617 | StatsLog.BLE_SCAN_STATE_CHANGED__STATE__ON); |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 5618 | if (isUnoptimized) { |
Yangster-mac | 2f5daec | 2018-01-16 10:23:15 -0800 | [diff] [blame] | 5619 | StatsLog.write_non_chained(StatsLog.BLE_UNOPTIMIZED_SCAN_STATE_CHANGED, uid, null, |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 5620 | StatsLog.BLE_UNOPTIMIZED_SCAN_STATE_CHANGED__STATE__ON); |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 5621 | } |
Narayan Kamath | 0ebc96c | 2017-12-29 13:32:38 +0000 | [diff] [blame] | 5622 | } |
| 5623 | |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5624 | getUidStatsLocked(uid).noteBluetoothScanStartedLocked(elapsedRealtime, isUnoptimized); |
Narayan Kamath | 0ebc96c | 2017-12-29 13:32:38 +0000 | [diff] [blame] | 5625 | if (workChain != null) { |
| 5626 | getUidStatsLocked(uid).addBluetoothWorkChain(workChain, isUnoptimized); |
| 5627 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5628 | } |
| 5629 | |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5630 | public void noteBluetoothScanStartedFromSourceLocked(WorkSource ws, boolean isUnoptimized) { |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5631 | final int N = ws.size(); |
| 5632 | for (int i = 0; i < N; i++) { |
Narayan Kamath | 0ebc96c | 2017-12-29 13:32:38 +0000 | [diff] [blame] | 5633 | noteBluetoothScanStartedLocked(null, ws.get(i), isUnoptimized); |
| 5634 | } |
| 5635 | |
| 5636 | final List<WorkChain> workChains = ws.getWorkChains(); |
| 5637 | if (workChains != null) { |
| 5638 | for (int i = 0; i < workChains.size(); ++i) { |
| 5639 | noteBluetoothScanStartedLocked(workChains.get(i), -1, isUnoptimized); |
| 5640 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5641 | } |
| 5642 | } |
| 5643 | |
Narayan Kamath | 0ebc96c | 2017-12-29 13:32:38 +0000 | [diff] [blame] | 5644 | private void noteBluetoothScanStoppedLocked(WorkChain workChain, int uid, |
| 5645 | boolean isUnoptimized) { |
| 5646 | uid = getAttributionUid(uid, workChain); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5647 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5648 | final long uptime = mClocks.uptimeMillis(); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5649 | mBluetoothScanNesting--; |
| 5650 | if (mBluetoothScanNesting == 0) { |
| 5651 | mHistoryCur.states2 &= ~HistoryItem.STATE2_BLUETOOTH_SCAN_FLAG; |
| 5652 | if (DEBUG_HISTORY) Slog.v(TAG, "BLE scan stopped for: " |
| 5653 | + Integer.toHexString(mHistoryCur.states2)); |
| 5654 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Adam Lesinski | d9b99be | 2016-03-30 16:58:51 -0700 | [diff] [blame] | 5655 | mBluetoothScanTimer.stopRunningLocked(elapsedRealtime); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5656 | } |
Narayan Kamath | 0ebc96c | 2017-12-29 13:32:38 +0000 | [diff] [blame] | 5657 | |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 5658 | if (workChain != null) { |
| 5659 | StatsLog.write( |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 5660 | StatsLog.BLE_SCAN_STATE_CHANGED, workChain.getUids(), workChain.getTags(), |
| 5661 | StatsLog.BLE_SCAN_STATE_CHANGED__STATE__OFF); |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 5662 | if (isUnoptimized) { |
| 5663 | StatsLog.write(StatsLog.BLE_UNOPTIMIZED_SCAN_STATE_CHANGED, |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 5664 | workChain.getUids(), workChain.getTags(), |
| 5665 | StatsLog.BLE_UNOPTIMIZED_SCAN_STATE_CHANGED__STATE__OFF); |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 5666 | } |
| 5667 | } else { |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 5668 | StatsLog.write_non_chained(StatsLog.BLE_SCAN_STATE_CHANGED, uid, null, |
| 5669 | StatsLog.BLE_SCAN_STATE_CHANGED__STATE__OFF); |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 5670 | if (isUnoptimized) { |
Yangster-mac | 2f5daec | 2018-01-16 10:23:15 -0800 | [diff] [blame] | 5671 | StatsLog.write_non_chained(StatsLog.BLE_UNOPTIMIZED_SCAN_STATE_CHANGED, uid, null, |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 5672 | StatsLog.BLE_UNOPTIMIZED_SCAN_STATE_CHANGED__STATE__OFF); |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 5673 | } |
Narayan Kamath | 0ebc96c | 2017-12-29 13:32:38 +0000 | [diff] [blame] | 5674 | } |
| 5675 | |
Bookatz | 94c5a31 | 2017-07-11 16:49:17 -0700 | [diff] [blame] | 5676 | getUidStatsLocked(uid).noteBluetoothScanStoppedLocked(elapsedRealtime, isUnoptimized); |
Narayan Kamath | 0ebc96c | 2017-12-29 13:32:38 +0000 | [diff] [blame] | 5677 | if (workChain != null) { |
| 5678 | getUidStatsLocked(uid).removeBluetoothWorkChain(workChain, isUnoptimized); |
| 5679 | } |
| 5680 | } |
| 5681 | |
| 5682 | private int getAttributionUid(int uid, WorkChain workChain) { |
| 5683 | if (workChain != null) { |
| 5684 | return mapUid(workChain.getAttributionUid()); |
| 5685 | } |
| 5686 | |
| 5687 | return mapUid(uid); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5688 | } |
| 5689 | |
Bookatz | 94c5a31 | 2017-07-11 16:49:17 -0700 | [diff] [blame] | 5690 | public void noteBluetoothScanStoppedFromSourceLocked(WorkSource ws, boolean isUnoptimized) { |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5691 | final int N = ws.size(); |
| 5692 | for (int i = 0; i < N; i++) { |
Narayan Kamath | 0ebc96c | 2017-12-29 13:32:38 +0000 | [diff] [blame] | 5693 | noteBluetoothScanStoppedLocked(null, ws.get(i), isUnoptimized); |
| 5694 | } |
| 5695 | |
| 5696 | final List<WorkChain> workChains = ws.getWorkChains(); |
| 5697 | if (workChains != null) { |
| 5698 | for (int i = 0; i < workChains.size(); ++i) { |
| 5699 | noteBluetoothScanStoppedLocked(workChains.get(i), -1, isUnoptimized); |
| 5700 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5701 | } |
| 5702 | } |
| 5703 | |
| 5704 | public void noteResetBluetoothScanLocked() { |
| 5705 | if (mBluetoothScanNesting > 0) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5706 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5707 | final long uptime = mClocks.uptimeMillis(); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5708 | mBluetoothScanNesting = 0; |
| 5709 | mHistoryCur.states2 &= ~HistoryItem.STATE2_BLUETOOTH_SCAN_FLAG; |
| 5710 | if (DEBUG_HISTORY) Slog.v(TAG, "BLE can stopped for: " |
| 5711 | + Integer.toHexString(mHistoryCur.states2)); |
| 5712 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 5713 | mBluetoothScanTimer.stopAllRunningLocked(elapsedRealtime); |
Narayan Kamath | 0ebc96c | 2017-12-29 13:32:38 +0000 | [diff] [blame] | 5714 | |
| 5715 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5716 | for (int i=0; i<mUidStats.size(); i++) { |
| 5717 | BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 5718 | uid.noteResetBluetoothScanLocked(elapsedRealtime); |
Narayan Kamath | 0ebc96c | 2017-12-29 13:32:38 +0000 | [diff] [blame] | 5719 | |
Narayan Kamath | 0ebc96c | 2017-12-29 13:32:38 +0000 | [diff] [blame] | 5720 | List<WorkChain> allWorkChains = uid.getAllBluetoothWorkChains(); |
| 5721 | if (allWorkChains != null) { |
| 5722 | for (int j = 0; j < allWorkChains.size(); ++j) { |
Narayan Kamath | 0ebc96c | 2017-12-29 13:32:38 +0000 | [diff] [blame] | 5723 | StatsLog.write(StatsLog.BLE_SCAN_STATE_CHANGED, |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 5724 | allWorkChains.get(j).getUids(), |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 5725 | allWorkChains.get(j).getTags(), |
| 5726 | StatsLog.BLE_SCAN_STATE_CHANGED__STATE__OFF); |
Narayan Kamath | 0ebc96c | 2017-12-29 13:32:38 +0000 | [diff] [blame] | 5727 | } |
Narayan Kamath | 0ebc96c | 2017-12-29 13:32:38 +0000 | [diff] [blame] | 5728 | allWorkChains.clear(); |
| 5729 | } |
| 5730 | |
| 5731 | List<WorkChain> unoptimizedWorkChains = uid.getUnoptimizedBluetoothWorkChains(); |
| 5732 | if (unoptimizedWorkChains != null) { |
| 5733 | for (int j = 0; j < unoptimizedWorkChains.size(); ++j) { |
Narayan Kamath | 0ebc96c | 2017-12-29 13:32:38 +0000 | [diff] [blame] | 5734 | StatsLog.write(StatsLog.BLE_UNOPTIMIZED_SCAN_STATE_CHANGED, |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 5735 | unoptimizedWorkChains.get(j).getUids(), |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 5736 | unoptimizedWorkChains.get(j).getTags(), |
| 5737 | StatsLog.BLE_UNOPTIMIZED_SCAN_STATE_CHANGED__STATE__OFF); |
Narayan Kamath | 0ebc96c | 2017-12-29 13:32:38 +0000 | [diff] [blame] | 5738 | } |
Narayan Kamath | 0ebc96c | 2017-12-29 13:32:38 +0000 | [diff] [blame] | 5739 | unoptimizedWorkChains.clear(); |
| 5740 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5741 | } |
| 5742 | } |
| 5743 | } |
| 5744 | |
Bookatz | 4ebc064 | 2017-05-11 12:21:19 -0700 | [diff] [blame] | 5745 | public void noteBluetoothScanResultsFromSourceLocked(WorkSource ws, int numNewResults) { |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 5746 | final int N = ws.size(); |
| 5747 | for (int i = 0; i < N; i++) { |
| 5748 | int uid = mapUid(ws.get(i)); |
Bookatz | 4ebc064 | 2017-05-11 12:21:19 -0700 | [diff] [blame] | 5749 | getUidStatsLocked(uid).noteBluetoothScanResultsLocked(numNewResults); |
Yangster-mac | 2f5daec | 2018-01-16 10:23:15 -0800 | [diff] [blame] | 5750 | StatsLog.write_non_chained(StatsLog.BLE_SCAN_RESULT_RECEIVED, ws.get(i), ws.getName(i), |
| 5751 | numNewResults); |
Narayan Kamath | 0ebc96c | 2017-12-29 13:32:38 +0000 | [diff] [blame] | 5752 | } |
| 5753 | |
| 5754 | final List<WorkChain> workChains = ws.getWorkChains(); |
| 5755 | if (workChains != null) { |
| 5756 | for (int i = 0; i < workChains.size(); ++i) { |
| 5757 | final WorkChain wc = workChains.get(i); |
| 5758 | int uid = mapUid(wc.getAttributionUid()); |
| 5759 | getUidStatsLocked(uid).noteBluetoothScanResultsLocked(numNewResults); |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 5760 | StatsLog.write(StatsLog.BLE_SCAN_RESULT_RECEIVED, |
| 5761 | wc.getUids(), wc.getTags(), numNewResults); |
Narayan Kamath | 0ebc96c | 2017-12-29 13:32:38 +0000 | [diff] [blame] | 5762 | } |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 5763 | } |
| 5764 | } |
| 5765 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 5766 | private void noteWifiRadioApWakeupLocked(final long elapsedRealtimeMillis, |
| 5767 | final long uptimeMillis, int uid) { |
| 5768 | uid = mapUid(uid); |
| 5769 | addHistoryEventLocked(elapsedRealtimeMillis, uptimeMillis, HistoryItem.EVENT_WAKEUP_AP, "", |
| 5770 | uid); |
| 5771 | getUidStatsLocked(uid).noteWifiRadioApWakeupLocked(); |
| 5772 | } |
| 5773 | |
| 5774 | public void noteWifiRadioPowerState(int powerState, long timestampNs, int uid) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5775 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5776 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 5777 | if (mWifiRadioPowerState != powerState) { |
| 5778 | final boolean active = |
| 5779 | powerState == DataConnectionRealTimeInfo.DC_POWER_STATE_MEDIUM |
| 5780 | || powerState == DataConnectionRealTimeInfo.DC_POWER_STATE_HIGH; |
| 5781 | if (active) { |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 5782 | if (uid > 0) { |
| 5783 | noteWifiRadioApWakeupLocked(elapsedRealtime, uptime, uid); |
| 5784 | } |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 5785 | mHistoryCur.states |= HistoryItem.STATE_WIFI_RADIO_ACTIVE_FLAG; |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 5786 | mWifiActiveTimer.startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 5787 | } else { |
| 5788 | mHistoryCur.states &= ~HistoryItem.STATE_WIFI_RADIO_ACTIVE_FLAG; |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 5789 | mWifiActiveTimer.stopRunningLocked( |
| 5790 | timestampNs / (1000 * 1000)); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 5791 | } |
| 5792 | if (DEBUG_HISTORY) Slog.v(TAG, "Wifi network active " + active + " to: " |
| 5793 | + Integer.toHexString(mHistoryCur.states)); |
| 5794 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 5795 | mWifiRadioPowerState = powerState; |
Bookatz | ddccf0a | 2017-11-28 16:48:14 -0800 | [diff] [blame] | 5796 | StatsLog.write(StatsLog.WIFI_RADIO_POWER_STATE_CHANGED, uid, powerState); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 5797 | } |
| 5798 | } |
| 5799 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5800 | public void noteWifiRunningLocked(WorkSource ws) { |
| 5801 | if (!mGlobalWifiRunning) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5802 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5803 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5804 | mHistoryCur.states2 |= HistoryItem.STATE2_WIFI_RUNNING_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5805 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI running to: " |
| 5806 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 5807 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5808 | mGlobalWifiRunning = true; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5809 | mGlobalWifiRunningTimer.startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5810 | int N = ws.size(); |
| 5811 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5812 | int uid = mapUid(ws.get(i)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5813 | getUidStatsLocked(uid).noteWifiRunningLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5814 | } |
Narayan Kamath | 728c8a0 | 2017-12-28 15:48:07 +0000 | [diff] [blame] | 5815 | |
| 5816 | List<WorkChain> workChains = ws.getWorkChains(); |
| 5817 | if (workChains != null) { |
| 5818 | for (int i = 0; i < workChains.size(); ++i) { |
| 5819 | int uid = mapUid(workChains.get(i).getAttributionUid()); |
| 5820 | getUidStatsLocked(uid).noteWifiRunningLocked(elapsedRealtime); |
| 5821 | } |
| 5822 | } |
| 5823 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5824 | scheduleSyncExternalStatsLocked("wifi-running", ExternalStatsSync.UPDATE_WIFI); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5825 | } else { |
| 5826 | Log.w(TAG, "noteWifiRunningLocked -- called while WIFI running"); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 5827 | } |
| 5828 | } |
| 5829 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5830 | public void noteWifiRunningChangedLocked(WorkSource oldWs, WorkSource newWs) { |
| 5831 | if (mGlobalWifiRunning) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5832 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5833 | int N = oldWs.size(); |
| 5834 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5835 | int uid = mapUid(oldWs.get(i)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5836 | getUidStatsLocked(uid).noteWifiStoppedLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5837 | } |
Narayan Kamath | 728c8a0 | 2017-12-28 15:48:07 +0000 | [diff] [blame] | 5838 | |
| 5839 | List<WorkChain> workChains = oldWs.getWorkChains(); |
| 5840 | if (workChains != null) { |
| 5841 | for (int i = 0; i < workChains.size(); ++i) { |
| 5842 | int uid = mapUid(workChains.get(i).getAttributionUid()); |
| 5843 | getUidStatsLocked(uid).noteWifiStoppedLocked(elapsedRealtime); |
| 5844 | } |
| 5845 | } |
| 5846 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5847 | N = newWs.size(); |
| 5848 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5849 | int uid = mapUid(newWs.get(i)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5850 | getUidStatsLocked(uid).noteWifiRunningLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5851 | } |
Narayan Kamath | 728c8a0 | 2017-12-28 15:48:07 +0000 | [diff] [blame] | 5852 | |
| 5853 | workChains = newWs.getWorkChains(); |
| 5854 | if (workChains != null) { |
| 5855 | for (int i = 0; i < workChains.size(); ++i) { |
| 5856 | int uid = mapUid(workChains.get(i).getAttributionUid()); |
| 5857 | getUidStatsLocked(uid).noteWifiRunningLocked(elapsedRealtime); |
| 5858 | } |
| 5859 | } |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5860 | } else { |
| 5861 | Log.w(TAG, "noteWifiRunningChangedLocked -- called while WIFI not running"); |
| 5862 | } |
| 5863 | } |
| 5864 | |
| 5865 | public void noteWifiStoppedLocked(WorkSource ws) { |
| 5866 | if (mGlobalWifiRunning) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5867 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5868 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5869 | mHistoryCur.states2 &= ~HistoryItem.STATE2_WIFI_RUNNING_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5870 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI stopped to: " |
| 5871 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 5872 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5873 | mGlobalWifiRunning = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5874 | mGlobalWifiRunningTimer.stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5875 | int N = ws.size(); |
| 5876 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5877 | int uid = mapUid(ws.get(i)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5878 | getUidStatsLocked(uid).noteWifiStoppedLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5879 | } |
Narayan Kamath | 728c8a0 | 2017-12-28 15:48:07 +0000 | [diff] [blame] | 5880 | |
| 5881 | List<WorkChain> workChains = ws.getWorkChains(); |
| 5882 | if (workChains != null) { |
| 5883 | for (int i = 0; i < workChains.size(); ++i) { |
| 5884 | int uid = mapUid(workChains.get(i).getAttributionUid()); |
| 5885 | getUidStatsLocked(uid).noteWifiStoppedLocked(elapsedRealtime); |
| 5886 | } |
| 5887 | } |
| 5888 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5889 | scheduleSyncExternalStatsLocked("wifi-stopped", ExternalStatsSync.UPDATE_WIFI); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5890 | } else { |
| 5891 | Log.w(TAG, "noteWifiStoppedLocked -- called while WIFI not running"); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 5892 | } |
| 5893 | } |
| 5894 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5895 | public void noteWifiStateLocked(int wifiState, String accessPoint) { |
| 5896 | if (DEBUG) Log.i(TAG, "WiFi state -> " + wifiState); |
| 5897 | if (mWifiState != wifiState) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5898 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5899 | if (mWifiState >= 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5900 | mWifiStateTimer[mWifiState].stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5901 | } |
| 5902 | mWifiState = wifiState; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5903 | mWifiStateTimer[wifiState].startRunningLocked(elapsedRealtime); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5904 | scheduleSyncExternalStatsLocked("wifi-state", ExternalStatsSync.UPDATE_WIFI); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5905 | } |
| 5906 | } |
| 5907 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5908 | public void noteWifiSupplicantStateChangedLocked(int supplState, boolean failedAuth) { |
| 5909 | if (DEBUG) Log.i(TAG, "WiFi suppl state -> " + supplState); |
| 5910 | if (mWifiSupplState != supplState) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5911 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5912 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5913 | if (mWifiSupplState >= 0) { |
| 5914 | mWifiSupplStateTimer[mWifiSupplState].stopRunningLocked(elapsedRealtime); |
| 5915 | } |
| 5916 | mWifiSupplState = supplState; |
| 5917 | mWifiSupplStateTimer[supplState].startRunningLocked(elapsedRealtime); |
| 5918 | mHistoryCur.states2 = |
| 5919 | (mHistoryCur.states2&~HistoryItem.STATE2_WIFI_SUPPL_STATE_MASK) |
| 5920 | | (supplState << HistoryItem.STATE2_WIFI_SUPPL_STATE_SHIFT); |
| 5921 | if (DEBUG_HISTORY) Slog.v(TAG, "Wifi suppl state " + supplState + " to: " |
| 5922 | + Integer.toHexString(mHistoryCur.states2)); |
| 5923 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 5924 | } |
| 5925 | } |
| 5926 | |
| 5927 | void stopAllWifiSignalStrengthTimersLocked(int except) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5928 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5929 | for (int i = 0; i < NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 5930 | if (i == except) { |
| 5931 | continue; |
| 5932 | } |
| 5933 | while (mWifiSignalStrengthsTimer[i].isRunningLocked()) { |
| 5934 | mWifiSignalStrengthsTimer[i].stopRunningLocked(elapsedRealtime); |
| 5935 | } |
| 5936 | } |
| 5937 | } |
| 5938 | |
| 5939 | public void noteWifiRssiChangedLocked(int newRssi) { |
| 5940 | int strengthBin = WifiManager.calculateSignalLevel(newRssi, NUM_WIFI_SIGNAL_STRENGTH_BINS); |
| 5941 | if (DEBUG) Log.i(TAG, "WiFi rssi -> " + newRssi + " bin=" + strengthBin); |
| 5942 | if (mWifiSignalStrengthBin != strengthBin) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5943 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5944 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5945 | if (mWifiSignalStrengthBin >= 0) { |
| 5946 | mWifiSignalStrengthsTimer[mWifiSignalStrengthBin].stopRunningLocked( |
| 5947 | elapsedRealtime); |
| 5948 | } |
| 5949 | if (strengthBin >= 0) { |
| 5950 | if (!mWifiSignalStrengthsTimer[strengthBin].isRunningLocked()) { |
| 5951 | mWifiSignalStrengthsTimer[strengthBin].startRunningLocked(elapsedRealtime); |
Bookatz | e588524 | 2017-10-24 20:10:31 -0700 | [diff] [blame] | 5952 | StatsLog.write(StatsLog.WIFI_SIGNAL_STRENGTH_CHANGED, strengthBin); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5953 | } |
| 5954 | mHistoryCur.states2 = |
| 5955 | (mHistoryCur.states2&~HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_MASK) |
| 5956 | | (strengthBin << HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_SHIFT); |
| 5957 | if (DEBUG_HISTORY) Slog.v(TAG, "Wifi signal strength " + strengthBin + " to: " |
| 5958 | + Integer.toHexString(mHistoryCur.states2)); |
| 5959 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 5960 | } else { |
| 5961 | stopAllWifiSignalStrengthTimersLocked(-1); |
| 5962 | } |
| 5963 | mWifiSignalStrengthBin = strengthBin; |
| 5964 | } |
| 5965 | } |
| 5966 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5967 | int mWifiFullLockNesting = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5968 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5969 | public void noteFullWifiLockAcquiredLocked(int uid) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5970 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5971 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5972 | if (mWifiFullLockNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5973 | mHistoryCur.states |= HistoryItem.STATE_WIFI_FULL_LOCK_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5974 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI full lock on to: " |
| 5975 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 5976 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5977 | } |
| 5978 | mWifiFullLockNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5979 | getUidStatsLocked(uid).noteFullWifiLockAcquiredLocked(elapsedRealtime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5980 | } |
| 5981 | |
| 5982 | public void noteFullWifiLockReleasedLocked(int uid) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5983 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5984 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5985 | mWifiFullLockNesting--; |
| 5986 | if (mWifiFullLockNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5987 | mHistoryCur.states &= ~HistoryItem.STATE_WIFI_FULL_LOCK_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5988 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI full lock off to: " |
| 5989 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 5990 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5991 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5992 | getUidStatsLocked(uid).noteFullWifiLockReleasedLocked(elapsedRealtime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5993 | } |
| 5994 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5995 | int mWifiScanNesting = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5996 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5997 | public void noteWifiScanStartedLocked(int uid) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5998 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5999 | final long uptime = mClocks.uptimeMillis(); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 6000 | if (mWifiScanNesting == 0) { |
| 6001 | mHistoryCur.states |= HistoryItem.STATE_WIFI_SCAN_FLAG; |
| 6002 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI scan started for: " |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 6003 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 6004 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 6005 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 6006 | mWifiScanNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 6007 | getUidStatsLocked(uid).noteWifiScanStartedLocked(elapsedRealtime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6008 | } |
| 6009 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 6010 | public void noteWifiScanStoppedLocked(int uid) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6011 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 6012 | final long uptime = mClocks.uptimeMillis(); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 6013 | mWifiScanNesting--; |
| 6014 | if (mWifiScanNesting == 0) { |
| 6015 | mHistoryCur.states &= ~HistoryItem.STATE_WIFI_SCAN_FLAG; |
| 6016 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI scan stopped for: " |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 6017 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 6018 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 6019 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 6020 | getUidStatsLocked(uid).noteWifiScanStoppedLocked(elapsedRealtime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6021 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 6022 | |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6023 | public void noteWifiBatchedScanStartedLocked(int uid, int csph) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6024 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6025 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 6026 | getUidStatsLocked(uid).noteWifiBatchedScanStartedLocked(csph, elapsedRealtime); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6027 | } |
| 6028 | |
| 6029 | public void noteWifiBatchedScanStoppedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6030 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6031 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 6032 | getUidStatsLocked(uid).noteWifiBatchedScanStoppedLocked(elapsedRealtime); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6033 | } |
| 6034 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 6035 | int mWifiMulticastNesting = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6036 | |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 6037 | public void noteWifiMulticastEnabledLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6038 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6039 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 6040 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 6041 | if (mWifiMulticastNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6042 | mHistoryCur.states |= HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 6043 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI multicast on to: " |
| 6044 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 6045 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 6046 | |
| 6047 | // Start Wifi Multicast overall timer |
| 6048 | if (!mWifiMulticastWakelockTimer.isRunningLocked()) { |
| 6049 | if (DEBUG_HISTORY) Slog.v(TAG, "WiFi Multicast Overall Timer Started"); |
| 6050 | mWifiMulticastWakelockTimer.startRunningLocked(elapsedRealtime); |
| 6051 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 6052 | } |
| 6053 | mWifiMulticastNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 6054 | getUidStatsLocked(uid).noteWifiMulticastEnabledLocked(elapsedRealtime); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 6055 | } |
| 6056 | |
| 6057 | public void noteWifiMulticastDisabledLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6058 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6059 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 6060 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 6061 | mWifiMulticastNesting--; |
| 6062 | if (mWifiMulticastNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6063 | mHistoryCur.states &= ~HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 6064 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI multicast off to: " |
| 6065 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 6066 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 6067 | |
| 6068 | // Stop Wifi Multicast overall timer |
| 6069 | if (mWifiMulticastWakelockTimer.isRunningLocked()) { |
| 6070 | if (DEBUG_HISTORY) Slog.v(TAG, "Multicast Overall Timer Stopped"); |
| 6071 | mWifiMulticastWakelockTimer.stopRunningLocked(elapsedRealtime); |
| 6072 | } |
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).noteWifiMulticastDisabledLocked(elapsedRealtime); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 6075 | } |
| 6076 | |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 6077 | public void noteFullWifiLockAcquiredFromSourceLocked(WorkSource ws) { |
| 6078 | int N = ws.size(); |
| 6079 | for (int i=0; i<N; i++) { |
Narayan Kamath | 728c8a0 | 2017-12-28 15:48:07 +0000 | [diff] [blame] | 6080 | final int uid = mapUid(ws.get(i)); |
| 6081 | noteFullWifiLockAcquiredLocked(uid); |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 6082 | StatsLog.write_non_chained(StatsLog.WIFI_LOCK_STATE_CHANGED, ws.get(i), ws.getName(i), |
| 6083 | StatsLog.WIFI_LOCK_STATE_CHANGED__STATE__ON); |
Narayan Kamath | 728c8a0 | 2017-12-28 15:48:07 +0000 | [diff] [blame] | 6084 | } |
| 6085 | |
| 6086 | final List<WorkChain> workChains = ws.getWorkChains(); |
| 6087 | if (workChains != null) { |
| 6088 | for (int i = 0; i < workChains.size(); ++i) { |
| 6089 | final WorkChain workChain = workChains.get(i); |
| 6090 | final int uid = mapUid(workChain.getAttributionUid()); |
| 6091 | noteFullWifiLockAcquiredLocked(uid); |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 6092 | StatsLog.write(StatsLog.WIFI_LOCK_STATE_CHANGED, |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 6093 | workChain.getUids(), workChain.getTags(), |
| 6094 | StatsLog.WIFI_LOCK_STATE_CHANGED__STATE__ON); |
Narayan Kamath | 728c8a0 | 2017-12-28 15:48:07 +0000 | [diff] [blame] | 6095 | } |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 6096 | } |
| 6097 | } |
| 6098 | |
| 6099 | public void noteFullWifiLockReleasedFromSourceLocked(WorkSource ws) { |
| 6100 | int N = ws.size(); |
| 6101 | for (int i=0; i<N; i++) { |
Narayan Kamath | 728c8a0 | 2017-12-28 15:48:07 +0000 | [diff] [blame] | 6102 | final int uid = mapUid(ws.get(i)); |
| 6103 | noteFullWifiLockReleasedLocked(uid); |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 6104 | StatsLog.write_non_chained(StatsLog.WIFI_LOCK_STATE_CHANGED, ws.get(i), ws.getName(i), |
| 6105 | StatsLog.WIFI_LOCK_STATE_CHANGED__STATE__OFF); |
Narayan Kamath | 728c8a0 | 2017-12-28 15:48:07 +0000 | [diff] [blame] | 6106 | } |
| 6107 | |
| 6108 | final List<WorkChain> workChains = ws.getWorkChains(); |
| 6109 | if (workChains != null) { |
| 6110 | for (int i = 0; i < workChains.size(); ++i) { |
| 6111 | final WorkChain workChain = workChains.get(i); |
| 6112 | final int uid = mapUid(workChain.getAttributionUid()); |
| 6113 | noteFullWifiLockReleasedLocked(uid); |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 6114 | StatsLog.write(StatsLog.WIFI_LOCK_STATE_CHANGED, |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 6115 | workChain.getUids(), workChain.getTags(), |
| 6116 | StatsLog.WIFI_LOCK_STATE_CHANGED__STATE__OFF); |
Narayan Kamath | 728c8a0 | 2017-12-28 15:48:07 +0000 | [diff] [blame] | 6117 | } |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 6118 | } |
| 6119 | } |
| 6120 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 6121 | public void noteWifiScanStartedFromSourceLocked(WorkSource ws) { |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 6122 | int N = ws.size(); |
| 6123 | for (int i=0; i<N; i++) { |
Narayan Kamath | 728c8a0 | 2017-12-28 15:48:07 +0000 | [diff] [blame] | 6124 | final int uid = mapUid(ws.get(i)); |
| 6125 | noteWifiScanStartedLocked(uid); |
Yangster-mac | 2f5daec | 2018-01-16 10:23:15 -0800 | [diff] [blame] | 6126 | 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] | 6127 | StatsLog.WIFI_SCAN_STATE_CHANGED__STATE__ON); |
Narayan Kamath | 728c8a0 | 2017-12-28 15:48:07 +0000 | [diff] [blame] | 6128 | } |
| 6129 | |
| 6130 | final List<WorkChain> workChains = ws.getWorkChains(); |
| 6131 | if (workChains != null) { |
| 6132 | for (int i = 0; i < workChains.size(); ++i) { |
| 6133 | final WorkChain workChain = workChains.get(i); |
| 6134 | final int uid = mapUid(workChain.getAttributionUid()); |
| 6135 | noteWifiScanStartedLocked(uid); |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 6136 | StatsLog.write(StatsLog.WIFI_SCAN_STATE_CHANGED, workChain.getUids(), |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 6137 | workChain.getTags(), StatsLog.WIFI_SCAN_STATE_CHANGED__STATE__ON); |
Narayan Kamath | 728c8a0 | 2017-12-28 15:48:07 +0000 | [diff] [blame] | 6138 | } |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 6139 | } |
| 6140 | } |
| 6141 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 6142 | public void noteWifiScanStoppedFromSourceLocked(WorkSource ws) { |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 6143 | int N = ws.size(); |
| 6144 | for (int i=0; i<N; i++) { |
Narayan Kamath | 728c8a0 | 2017-12-28 15:48:07 +0000 | [diff] [blame] | 6145 | final int uid = mapUid(ws.get(i)); |
| 6146 | noteWifiScanStoppedLocked(uid); |
Yangster-mac | 2f5daec | 2018-01-16 10:23:15 -0800 | [diff] [blame] | 6147 | 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] | 6148 | StatsLog.WIFI_SCAN_STATE_CHANGED__STATE__OFF); |
Narayan Kamath | 728c8a0 | 2017-12-28 15:48:07 +0000 | [diff] [blame] | 6149 | } |
| 6150 | |
| 6151 | final List<WorkChain> workChains = ws.getWorkChains(); |
| 6152 | if (workChains != null) { |
| 6153 | for (int i = 0; i < workChains.size(); ++i) { |
| 6154 | final WorkChain workChain = workChains.get(i); |
| 6155 | final int uid = mapUid(workChain.getAttributionUid()); |
| 6156 | noteWifiScanStoppedLocked(uid); |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 6157 | StatsLog.write(StatsLog.WIFI_SCAN_STATE_CHANGED, |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 6158 | workChain.getUids(), workChain.getTags(), |
| 6159 | StatsLog.WIFI_SCAN_STATE_CHANGED__STATE__OFF); |
Narayan Kamath | 728c8a0 | 2017-12-28 15:48:07 +0000 | [diff] [blame] | 6160 | } |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 6161 | } |
| 6162 | } |
| 6163 | |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6164 | public void noteWifiBatchedScanStartedFromSourceLocked(WorkSource ws, int csph) { |
| 6165 | int N = ws.size(); |
| 6166 | for (int i=0; i<N; i++) { |
| 6167 | noteWifiBatchedScanStartedLocked(ws.get(i), csph); |
| 6168 | } |
Narayan Kamath | 728c8a0 | 2017-12-28 15:48:07 +0000 | [diff] [blame] | 6169 | |
| 6170 | final List<WorkChain> workChains = ws.getWorkChains(); |
| 6171 | if (workChains != null) { |
| 6172 | for (int i = 0; i < workChains.size(); ++i) { |
| 6173 | noteWifiBatchedScanStartedLocked(workChains.get(i).getAttributionUid(), csph); |
| 6174 | } |
| 6175 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6176 | } |
| 6177 | |
| 6178 | public void noteWifiBatchedScanStoppedFromSourceLocked(WorkSource ws) { |
| 6179 | int N = ws.size(); |
| 6180 | for (int i=0; i<N; i++) { |
| 6181 | noteWifiBatchedScanStoppedLocked(ws.get(i)); |
| 6182 | } |
Narayan Kamath | 728c8a0 | 2017-12-28 15:48:07 +0000 | [diff] [blame] | 6183 | |
| 6184 | final List<WorkChain> workChains = ws.getWorkChains(); |
| 6185 | if (workChains != null) { |
| 6186 | for (int i = 0; i < workChains.size(); ++i) { |
| 6187 | noteWifiBatchedScanStoppedLocked(workChains.get(i).getAttributionUid()); |
| 6188 | } |
| 6189 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6190 | } |
| 6191 | |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 6192 | private static String[] includeInStringArray(String[] array, String str) { |
| 6193 | if (ArrayUtils.indexOf(array, str) >= 0) { |
| 6194 | return array; |
| 6195 | } |
| 6196 | String[] newArray = new String[array.length+1]; |
| 6197 | System.arraycopy(array, 0, newArray, 0, array.length); |
| 6198 | newArray[array.length] = str; |
| 6199 | return newArray; |
| 6200 | } |
| 6201 | |
| 6202 | private static String[] excludeFromStringArray(String[] array, String str) { |
| 6203 | int index = ArrayUtils.indexOf(array, str); |
| 6204 | if (index >= 0) { |
| 6205 | String[] newArray = new String[array.length-1]; |
| 6206 | if (index > 0) { |
| 6207 | System.arraycopy(array, 0, newArray, 0, index); |
| 6208 | } |
| 6209 | if (index < array.length-1) { |
| 6210 | System.arraycopy(array, index+1, newArray, index, array.length-index-1); |
| 6211 | } |
| 6212 | return newArray; |
| 6213 | } |
| 6214 | return array; |
| 6215 | } |
| 6216 | |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 6217 | public void noteNetworkInterfaceTypeLocked(String iface, int networkType) { |
Jeff Sharkey | 9da2f1e | 2014-08-14 12:55:00 -0700 | [diff] [blame] | 6218 | if (TextUtils.isEmpty(iface)) return; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6219 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 6220 | synchronized (mModemNetworkLock) { |
| 6221 | if (ConnectivityManager.isNetworkTypeMobile(networkType)) { |
| 6222 | mModemIfaces = includeInStringArray(mModemIfaces, iface); |
| 6223 | if (DEBUG) Slog.d(TAG, "Note mobile iface " + iface + ": " + mModemIfaces); |
| 6224 | } else { |
| 6225 | mModemIfaces = excludeFromStringArray(mModemIfaces, iface); |
| 6226 | if (DEBUG) Slog.d(TAG, "Note non-mobile iface " + iface + ": " + mModemIfaces); |
| 6227 | } |
| 6228 | } |
| 6229 | |
| 6230 | synchronized (mWifiNetworkLock) { |
| 6231 | if (ConnectivityManager.isNetworkTypeWifi(networkType)) { |
| 6232 | mWifiIfaces = includeInStringArray(mWifiIfaces, iface); |
| 6233 | if (DEBUG) Slog.d(TAG, "Note wifi iface " + iface + ": " + mWifiIfaces); |
| 6234 | } else { |
| 6235 | mWifiIfaces = excludeFromStringArray(mWifiIfaces, iface); |
| 6236 | if (DEBUG) Slog.d(TAG, "Note non-wifi iface " + iface + ": " + mWifiIfaces); |
| 6237 | } |
| 6238 | } |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 6239 | } |
| 6240 | |
David Chen | c8a4324 | 2017-10-17 16:23:28 -0700 | [diff] [blame] | 6241 | public String[] getWifiIfaces() { |
| 6242 | synchronized (mWifiNetworkLock) { |
| 6243 | return mWifiIfaces; |
| 6244 | } |
| 6245 | } |
| 6246 | |
| 6247 | public String[] getMobileIfaces() { |
| 6248 | synchronized (mModemNetworkLock) { |
| 6249 | return mModemIfaces; |
| 6250 | } |
| 6251 | } |
| 6252 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6253 | @Override public long getScreenOnTime(long elapsedRealtimeUs, int which) { |
| 6254 | return mScreenOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6255 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6256 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 6257 | @Override public int getScreenOnCount(int which) { |
| 6258 | return mScreenOnTimer.getCountLocked(which); |
| 6259 | } |
| 6260 | |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 6261 | @Override public long getScreenDozeTime(long elapsedRealtimeUs, int which) { |
| 6262 | return mScreenDozeTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 6263 | } |
| 6264 | |
| 6265 | @Override public int getScreenDozeCount(int which) { |
| 6266 | return mScreenDozeTimer.getCountLocked(which); |
| 6267 | } |
| 6268 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6269 | @Override public long getScreenBrightnessTime(int brightnessBin, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6270 | long elapsedRealtimeUs, int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6271 | return mScreenBrightnessTimer[brightnessBin].getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6272 | elapsedRealtimeUs, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6273 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 6274 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 6275 | @Override public Timer getScreenBrightnessTimer(int brightnessBin) { |
| 6276 | return mScreenBrightnessTimer[brightnessBin]; |
| 6277 | } |
| 6278 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 6279 | @Override public long getInteractiveTime(long elapsedRealtimeUs, int which) { |
| 6280 | return mInteractiveTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6281 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6282 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 6283 | @Override public long getPowerSaveModeEnabledTime(long elapsedRealtimeUs, int which) { |
| 6284 | return mPowerSaveModeEnabledTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 6285 | } |
| 6286 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 6287 | @Override public int getPowerSaveModeEnabledCount(int which) { |
| 6288 | return mPowerSaveModeEnabledTimer.getCountLocked(which); |
| 6289 | } |
| 6290 | |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 6291 | @Override public long getDeviceIdleModeTime(int mode, long elapsedRealtimeUs, |
| 6292 | int which) { |
| 6293 | switch (mode) { |
| 6294 | case DEVICE_IDLE_MODE_LIGHT: |
| 6295 | return mDeviceIdleModeLightTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 6296 | case DEVICE_IDLE_MODE_DEEP: |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 6297 | return mDeviceIdleModeFullTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 6298 | } |
| 6299 | return 0; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 6300 | } |
| 6301 | |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 6302 | @Override public int getDeviceIdleModeCount(int mode, int which) { |
| 6303 | switch (mode) { |
| 6304 | case DEVICE_IDLE_MODE_LIGHT: |
| 6305 | return mDeviceIdleModeLightTimer.getCountLocked(which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 6306 | case DEVICE_IDLE_MODE_DEEP: |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 6307 | return mDeviceIdleModeFullTimer.getCountLocked(which); |
| 6308 | } |
| 6309 | return 0; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 6310 | } |
| 6311 | |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 6312 | @Override public long getLongestDeviceIdleModeTime(int mode) { |
| 6313 | switch (mode) { |
| 6314 | case DEVICE_IDLE_MODE_LIGHT: |
| 6315 | return mLongestLightIdleTime; |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 6316 | case DEVICE_IDLE_MODE_DEEP: |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 6317 | return mLongestFullIdleTime; |
| 6318 | } |
| 6319 | return 0; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6320 | } |
| 6321 | |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 6322 | @Override public long getDeviceIdlingTime(int mode, long elapsedRealtimeUs, int which) { |
| 6323 | switch (mode) { |
| 6324 | case DEVICE_IDLE_MODE_LIGHT: |
| 6325 | return mDeviceLightIdlingTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 6326 | case DEVICE_IDLE_MODE_DEEP: |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 6327 | return mDeviceIdlingTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 6328 | } |
| 6329 | return 0; |
| 6330 | } |
| 6331 | |
| 6332 | @Override public int getDeviceIdlingCount(int mode, int which) { |
| 6333 | switch (mode) { |
| 6334 | case DEVICE_IDLE_MODE_LIGHT: |
| 6335 | return mDeviceLightIdlingTimer.getCountLocked(which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 6336 | case DEVICE_IDLE_MODE_DEEP: |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 6337 | return mDeviceIdlingTimer.getCountLocked(which); |
| 6338 | } |
| 6339 | return 0; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6340 | } |
| 6341 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6342 | @Override public int getNumConnectivityChange(int which) { |
| 6343 | int val = mNumConnectivityChange; |
| 6344 | if (which == STATS_CURRENT) { |
| 6345 | val -= mLoadedNumConnectivityChange; |
| 6346 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 6347 | val -= mUnpluggedNumConnectivityChange; |
| 6348 | } |
| 6349 | return val; |
| 6350 | } |
| 6351 | |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 6352 | @Override public long getGpsSignalQualityTime(int strengthBin, |
| 6353 | long elapsedRealtimeUs, int which) { |
| 6354 | if (strengthBin < 0 || strengthBin >= GnssMetrics.NUM_GPS_SIGNAL_QUALITY_LEVELS) { |
| 6355 | return 0; |
| 6356 | } |
| 6357 | return mGpsSignalQualityTimer[strengthBin].getTotalTimeLocked( |
| 6358 | elapsedRealtimeUs, which); |
| 6359 | } |
| 6360 | |
| 6361 | @Override public long getGpsBatteryDrainMaMs() { |
Siddharth Ray | 0ed2e95 | 2018-01-22 11:32:14 -0800 | [diff] [blame] | 6362 | final double opVolt = mPowerProfile.getAveragePower( |
| 6363 | PowerProfile.POWER_GPS_OPERATING_VOLTAGE) / 1000.0; |
| 6364 | if (opVolt == 0) { |
| 6365 | return 0; |
| 6366 | } |
| 6367 | double energyUsedMaMs = 0.0; |
| 6368 | final int which = STATS_SINCE_CHARGED; |
| 6369 | final long rawRealtime = SystemClock.elapsedRealtime() * 1000; |
| 6370 | for(int i=0; i < GnssMetrics.NUM_GPS_SIGNAL_QUALITY_LEVELS; i++) { |
| 6371 | energyUsedMaMs |
| 6372 | += mPowerProfile.getAveragePower(PowerProfile.POWER_GPS_SIGNAL_QUALITY_BASED, i) |
| 6373 | * (getGpsSignalQualityTime(i, rawRealtime, which) / 1000); |
| 6374 | } |
| 6375 | return (long) energyUsedMaMs; |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 6376 | } |
| 6377 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6378 | @Override public long getPhoneOnTime(long elapsedRealtimeUs, int which) { |
| 6379 | return mPhoneOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6380 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 6381 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 6382 | @Override public int getPhoneOnCount(int which) { |
| 6383 | return mPhoneOnTimer.getCountLocked(which); |
| 6384 | } |
| 6385 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 6386 | @Override public long getPhoneSignalStrengthTime(int strengthBin, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6387 | long elapsedRealtimeUs, int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6388 | return mPhoneSignalStrengthsTimer[strengthBin].getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6389 | elapsedRealtimeUs, which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 6390 | } |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 6391 | |
| 6392 | @Override public long getPhoneSignalScanningTime( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6393 | long elapsedRealtimeUs, int which) { |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 6394 | return mPhoneSignalScanningTimer.getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6395 | elapsedRealtimeUs, which); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 6396 | } |
| 6397 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 6398 | @Override public Timer getPhoneSignalScanningTimer() { |
| 6399 | return mPhoneSignalScanningTimer; |
| 6400 | } |
| 6401 | |
Catherine Liu | fb90081 | 2012-07-17 14:12:56 -0500 | [diff] [blame] | 6402 | @Override public int getPhoneSignalStrengthCount(int strengthBin, int which) { |
| 6403 | return mPhoneSignalStrengthsTimer[strengthBin].getCountLocked(which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6404 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6405 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 6406 | @Override public Timer getPhoneSignalStrengthTimer(int strengthBin) { |
| 6407 | return mPhoneSignalStrengthsTimer[strengthBin]; |
| 6408 | } |
| 6409 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 6410 | @Override public long getPhoneDataConnectionTime(int dataType, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6411 | long elapsedRealtimeUs, int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6412 | return mPhoneDataConnectionsTimer[dataType].getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6413 | elapsedRealtimeUs, which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 6414 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6415 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6416 | @Override public int getPhoneDataConnectionCount(int dataType, int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6417 | return mPhoneDataConnectionsTimer[dataType].getCountLocked(which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6418 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6419 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 6420 | @Override public Timer getPhoneDataConnectionTimer(int dataType) { |
| 6421 | return mPhoneDataConnectionsTimer[dataType]; |
| 6422 | } |
| 6423 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6424 | @Override public long getMobileRadioActiveTime(long elapsedRealtimeUs, int which) { |
| 6425 | return mMobileRadioActiveTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 6426 | } |
| 6427 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 6428 | @Override public int getMobileRadioActiveCount(int which) { |
| 6429 | return mMobileRadioActiveTimer.getCountLocked(which); |
| 6430 | } |
| 6431 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 6432 | @Override public long getMobileRadioActiveAdjustedTime(int which) { |
| 6433 | return mMobileRadioActiveAdjustedTime.getCountLocked(which); |
| 6434 | } |
| 6435 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 6436 | @Override public long getMobileRadioActiveUnknownTime(int which) { |
| 6437 | return mMobileRadioActiveUnknownTime.getCountLocked(which); |
| 6438 | } |
| 6439 | |
| 6440 | @Override public int getMobileRadioActiveUnknownCount(int which) { |
| 6441 | return (int)mMobileRadioActiveUnknownCount.getCountLocked(which); |
| 6442 | } |
| 6443 | |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 6444 | @Override public long getWifiMulticastWakelockTime( |
| 6445 | long elapsedRealtimeUs, int which) { |
| 6446 | return mWifiMulticastWakelockTimer.getTotalTimeLocked( |
| 6447 | elapsedRealtimeUs, which); |
| 6448 | } |
| 6449 | |
| 6450 | @Override public int getWifiMulticastWakelockCount(int which) { |
| 6451 | return mWifiMulticastWakelockTimer.getCountLocked(which); |
| 6452 | } |
| 6453 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6454 | @Override public long getWifiOnTime(long elapsedRealtimeUs, int which) { |
| 6455 | return mWifiOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6456 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6457 | |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 6458 | @Override public long getWifiActiveTime(long elapsedRealtimeUs, int which) { |
| 6459 | return mWifiActiveTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 6460 | } |
| 6461 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6462 | @Override public long getGlobalWifiRunningTime(long elapsedRealtimeUs, int which) { |
| 6463 | return mGlobalWifiRunningTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 6464 | } |
| 6465 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 6466 | @Override public long getWifiStateTime(int wifiState, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6467 | long elapsedRealtimeUs, int which) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 6468 | return mWifiStateTimer[wifiState].getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6469 | elapsedRealtimeUs, which); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 6470 | } |
| 6471 | |
| 6472 | @Override public int getWifiStateCount(int wifiState, int which) { |
| 6473 | return mWifiStateTimer[wifiState].getCountLocked(which); |
| 6474 | } |
| 6475 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 6476 | @Override public Timer getWifiStateTimer(int wifiState) { |
| 6477 | return mWifiStateTimer[wifiState]; |
| 6478 | } |
| 6479 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 6480 | @Override public long getWifiSupplStateTime(int state, |
| 6481 | long elapsedRealtimeUs, int which) { |
| 6482 | return mWifiSupplStateTimer[state].getTotalTimeLocked( |
| 6483 | elapsedRealtimeUs, which); |
| 6484 | } |
| 6485 | |
| 6486 | @Override public int getWifiSupplStateCount(int state, int which) { |
| 6487 | return mWifiSupplStateTimer[state].getCountLocked(which); |
| 6488 | } |
| 6489 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 6490 | @Override public Timer getWifiSupplStateTimer(int state) { |
| 6491 | return mWifiSupplStateTimer[state]; |
| 6492 | } |
| 6493 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 6494 | @Override public long getWifiSignalStrengthTime(int strengthBin, |
| 6495 | long elapsedRealtimeUs, int which) { |
| 6496 | return mWifiSignalStrengthsTimer[strengthBin].getTotalTimeLocked( |
| 6497 | elapsedRealtimeUs, which); |
| 6498 | } |
| 6499 | |
| 6500 | @Override public int getWifiSignalStrengthCount(int strengthBin, int which) { |
| 6501 | return mWifiSignalStrengthsTimer[strengthBin].getCountLocked(which); |
| 6502 | } |
| 6503 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 6504 | @Override public Timer getWifiSignalStrengthTimer(int strengthBin) { |
| 6505 | return mWifiSignalStrengthsTimer[strengthBin]; |
| 6506 | } |
| 6507 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6508 | @Override |
| 6509 | public ControllerActivityCounter getBluetoothControllerActivity() { |
| 6510 | return mBluetoothActivity; |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 6511 | } |
| 6512 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6513 | @Override |
| 6514 | public ControllerActivityCounter getWifiControllerActivity() { |
| 6515 | return mWifiActivity; |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 6516 | } |
| 6517 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6518 | @Override |
| 6519 | public ControllerActivityCounter getModemControllerActivity() { |
| 6520 | return mModemActivity; |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 6521 | } |
| 6522 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6523 | @Override |
| 6524 | public boolean hasBluetoothActivityReporting() { |
| 6525 | return mHasBluetoothReporting; |
| 6526 | } |
| 6527 | |
| 6528 | @Override |
| 6529 | public boolean hasWifiActivityReporting() { |
| 6530 | return mHasWifiReporting; |
| 6531 | } |
| 6532 | |
| 6533 | @Override |
| 6534 | public boolean hasModemActivityReporting() { |
| 6535 | return mHasModemReporting; |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 6536 | } |
| 6537 | |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 6538 | @Override |
| 6539 | public long getFlashlightOnTime(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 6540 | return mFlashlightOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 6541 | } |
| 6542 | |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 6543 | @Override |
| 6544 | public long getFlashlightOnCount(int which) { |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 6545 | return mFlashlightOnTimer.getCountLocked(which); |
| 6546 | } |
| 6547 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6548 | @Override |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 6549 | public long getCameraOnTime(long elapsedRealtimeUs, int which) { |
| 6550 | return mCameraOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 6551 | } |
| 6552 | |
| 6553 | @Override |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 6554 | public long getBluetoothScanTime(long elapsedRealtimeUs, int which) { |
| 6555 | return mBluetoothScanTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 6556 | } |
| 6557 | |
| 6558 | @Override |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6559 | public long getNetworkActivityBytes(int type, int which) { |
| 6560 | if (type >= 0 && type < mNetworkByteActivityCounters.length) { |
| 6561 | return mNetworkByteActivityCounters[type].getCountLocked(which); |
| 6562 | } else { |
| 6563 | return 0; |
| 6564 | } |
| 6565 | } |
| 6566 | |
| 6567 | @Override |
| 6568 | public long getNetworkActivityPackets(int type, int which) { |
| 6569 | if (type >= 0 && type < mNetworkPacketActivityCounters.length) { |
| 6570 | return mNetworkPacketActivityCounters[type].getCountLocked(which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6571 | } else { |
| 6572 | return 0; |
| 6573 | } |
| 6574 | } |
| 6575 | |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 6576 | @Override public long getStartClockTime() { |
Dianne Hackborn | d48954f | 2015-07-22 17:20:33 -0700 | [diff] [blame] | 6577 | final long currentTime = System.currentTimeMillis(); |
| 6578 | if (ensureStartClockTime(currentTime)) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6579 | recordCurrentTimeChangeLocked(currentTime, mClocks.elapsedRealtime(), |
| 6580 | mClocks.uptimeMillis()); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 6581 | } |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 6582 | return mStartClockTime; |
| 6583 | } |
| 6584 | |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 6585 | @Override public String getStartPlatformVersion() { |
| 6586 | return mStartPlatformVersion; |
| 6587 | } |
| 6588 | |
| 6589 | @Override public String getEndPlatformVersion() { |
| 6590 | return mEndPlatformVersion; |
| 6591 | } |
| 6592 | |
| 6593 | @Override public int getParcelVersion() { |
| 6594 | return VERSION; |
| 6595 | } |
| 6596 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6597 | @Override public boolean getIsOnBattery() { |
| 6598 | return mOnBattery; |
| 6599 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6600 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6601 | @Override public SparseArray<? extends BatteryStats.Uid> getUidStats() { |
| 6602 | return mUidStats; |
| 6603 | } |
| 6604 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 6605 | private static void detachTimerIfNotNull(BatteryStatsImpl.Timer timer) { |
| 6606 | if (timer != null) { |
| 6607 | timer.detach(); |
| 6608 | } |
| 6609 | } |
| 6610 | |
| 6611 | private static boolean resetTimerIfNotNull(BatteryStatsImpl.Timer timer, |
| 6612 | boolean detachIfReset) { |
| 6613 | if (timer != null) { |
| 6614 | return timer.reset(detachIfReset); |
| 6615 | } |
| 6616 | return true; |
| 6617 | } |
| 6618 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 6619 | private static boolean resetTimerIfNotNull(DualTimer timer, boolean detachIfReset) { |
| 6620 | if (timer != null) { |
| 6621 | return timer.reset(detachIfReset); |
| 6622 | } |
| 6623 | return true; |
| 6624 | } |
| 6625 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 6626 | private static void detachLongCounterIfNotNull(LongSamplingCounter counter) { |
| 6627 | if (counter != null) { |
| 6628 | counter.detach(); |
| 6629 | } |
| 6630 | } |
| 6631 | |
| 6632 | private static void resetLongCounterIfNotNull(LongSamplingCounter counter, |
| 6633 | boolean detachIfReset) { |
| 6634 | if (counter != null) { |
| 6635 | counter.reset(detachIfReset); |
| 6636 | } |
| 6637 | } |
| 6638 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6639 | /** |
| 6640 | * The statistics associated with a particular uid. |
| 6641 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6642 | public static class Uid extends BatteryStats.Uid { |
| 6643 | /** |
| 6644 | * BatteryStatsImpl that we are associated with. |
| 6645 | */ |
| 6646 | protected BatteryStatsImpl mBsi; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6647 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6648 | final int mUid; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6649 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 6650 | /** TimeBase for when uid is in background and device is on battery. */ |
| 6651 | @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 6652 | public final TimeBase mOnBatteryBackgroundTimeBase; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 6653 | @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 6654 | public final TimeBase mOnBatteryScreenOffBackgroundTimeBase; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 6655 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 6656 | boolean mWifiRunning; |
| 6657 | StopwatchTimer mWifiRunningTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6658 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6659 | boolean mFullWifiLockOut; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6660 | StopwatchTimer mFullWifiLockTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6661 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 6662 | boolean mWifiScanStarted; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 6663 | DualTimer mWifiScanTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6664 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 6665 | static final int NO_BATCHED_SCAN_STARTED = -1; |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6666 | int mWifiBatchedScanBinStarted = NO_BATCHED_SCAN_STARTED; |
| 6667 | StopwatchTimer[] mWifiBatchedScanTimer; |
| 6668 | |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 6669 | boolean mWifiMulticastEnabled; |
| 6670 | StopwatchTimer mWifiMulticastTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6671 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 6672 | StopwatchTimer mAudioTurnedOnTimer; |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 6673 | StopwatchTimer mVideoTurnedOnTimer; |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 6674 | StopwatchTimer mFlashlightTurnedOnTimer; |
| 6675 | StopwatchTimer mCameraTurnedOnTimer; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6676 | StopwatchTimer mForegroundActivityTimer; |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 6677 | StopwatchTimer mForegroundServiceTimer; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 6678 | /** Total time spent by the uid holding any partial wakelocks. */ |
| 6679 | DualTimer mAggregatedPartialWakelockTimer; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 6680 | DualTimer mBluetoothScanTimer; |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 6681 | DualTimer mBluetoothUnoptimizedScanTimer; |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 6682 | Counter mBluetoothScanResultCounter; |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 6683 | Counter mBluetoothScanResultBgCounter; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6684 | |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 6685 | int mProcessState = ActivityManager.PROCESS_STATE_NONEXISTENT; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 6686 | StopwatchTimer[] mProcessStateTimer; |
| 6687 | |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 6688 | boolean mInForegroundService = false; |
| 6689 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 6690 | BatchTimer mVibratorOnTimer; |
| 6691 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6692 | Counter[] mUserActivityCounters; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6693 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6694 | LongSamplingCounter[] mNetworkByteActivityCounters; |
| 6695 | LongSamplingCounter[] mNetworkPacketActivityCounters; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 6696 | LongSamplingCounter mMobileRadioActiveTime; |
| 6697 | LongSamplingCounter mMobileRadioActiveCount; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6698 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6699 | /** |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 6700 | * How many times this UID woke up the Application Processor due to a Mobile radio packet. |
| 6701 | */ |
| 6702 | private LongSamplingCounter mMobileRadioApWakeupCount; |
| 6703 | |
| 6704 | /** |
| 6705 | * How many times this UID woke up the Application Processor due to a Wifi packet. |
| 6706 | */ |
| 6707 | private LongSamplingCounter mWifiRadioApWakeupCount; |
| 6708 | |
| 6709 | /** |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6710 | * 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] | 6711 | * Can be null if the UID has had no such activity. |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6712 | */ |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6713 | private ControllerActivityCounterImpl mWifiControllerActivity; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6714 | |
| 6715 | /** |
| 6716 | * 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] | 6717 | * Can be null if the UID has had no such activity. |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6718 | */ |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6719 | private ControllerActivityCounterImpl mBluetoothControllerActivity; |
| 6720 | |
| 6721 | /** |
| 6722 | * The amount of time this uid has kept the Modem controller in idle, tx, and rx mode. |
| 6723 | * Can be null if the UID has had no such activity. |
| 6724 | */ |
| 6725 | private ControllerActivityCounterImpl mModemControllerActivity; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6726 | |
| 6727 | /** |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 6728 | * The CPU times we had at the last history details update. |
| 6729 | */ |
| 6730 | long mLastStepUserTime; |
| 6731 | long mLastStepSystemTime; |
| 6732 | long mCurStepUserTime; |
| 6733 | long mCurStepSystemTime; |
| 6734 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6735 | LongSamplingCounter mUserCpuTime; |
| 6736 | LongSamplingCounter mSystemCpuTime; |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 6737 | LongSamplingCounter[][] mCpuClusterSpeedTimesUs; |
Mike Ma | 3d422c3 | 2017-10-25 11:08:57 -0700 | [diff] [blame] | 6738 | LongSamplingCounter mCpuActiveTimeMs; |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 6739 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 6740 | LongSamplingCounterArray mCpuFreqTimeMs; |
| 6741 | LongSamplingCounterArray mScreenOffCpuFreqTimeMs; |
Mike Ma | 3d422c3 | 2017-10-25 11:08:57 -0700 | [diff] [blame] | 6742 | LongSamplingCounterArray mCpuClusterTimesMs; |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 6743 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 6744 | LongSamplingCounterArray[] mProcStateTimeMs; |
| 6745 | LongSamplingCounterArray[] mProcStateScreenOffTimeMs; |
| 6746 | |
| 6747 | IntArray mChildUids; |
| 6748 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 6749 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6750 | * The statistics we have collected for this uid's wake locks. |
| 6751 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6752 | final OverflowArrayMap<Wakelock> mWakelockStats; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6753 | |
| 6754 | /** |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6755 | * The statistics we have collected for this uid's syncs. |
| 6756 | */ |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 6757 | final OverflowArrayMap<DualTimer> mSyncStats; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6758 | |
| 6759 | /** |
| 6760 | * The statistics we have collected for this uid's jobs. |
| 6761 | */ |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 6762 | final OverflowArrayMap<DualTimer> mJobStats; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6763 | |
| 6764 | /** |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 6765 | * Count of the jobs that have completed and the reasons why they completed. |
| 6766 | */ |
| 6767 | final ArrayMap<String, SparseIntArray> mJobCompletions = new ArrayMap<>(); |
| 6768 | |
| 6769 | /** |
Amith Yamasani | 977e11f | 2018-02-16 11:29:54 -0800 | [diff] [blame] | 6770 | * Count of app launch events that had associated deferred job counts or info about |
| 6771 | * last time a job was run. |
| 6772 | */ |
| 6773 | Counter mJobsDeferredEventCount; |
| 6774 | |
| 6775 | /** |
| 6776 | * Count of deferred jobs that were pending when the app was launched or brought to |
| 6777 | * the foreground through a user interaction. |
| 6778 | */ |
| 6779 | Counter mJobsDeferredCount; |
| 6780 | |
| 6781 | /** |
| 6782 | * Sum of time since the last time a job was run for this app before it was launched. |
| 6783 | */ |
| 6784 | LongSamplingCounter mJobsFreshnessTimeMs; |
| 6785 | |
| 6786 | /** |
| 6787 | * Array of counts of instances where the time since the last job was run for the app |
| 6788 | * fell within one of the thresholds in {@link #JOB_FRESHNESS_BUCKETS}. |
| 6789 | */ |
| 6790 | final Counter[] mJobsFreshnessBuckets; |
| 6791 | |
| 6792 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6793 | * The statistics we have collected for this uid's sensor activations. |
| 6794 | */ |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6795 | final SparseArray<Sensor> mSensorStats = new SparseArray<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6796 | |
| 6797 | /** |
| 6798 | * The statistics we have collected for this uid's processes. |
| 6799 | */ |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6800 | final ArrayMap<String, Proc> mProcessStats = new ArrayMap<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6801 | |
| 6802 | /** |
| 6803 | * The statistics we have collected for this uid's processes. |
| 6804 | */ |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6805 | final ArrayMap<String, Pkg> mPackageStats = new ArrayMap<>(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6806 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6807 | /** |
| 6808 | * The transient wake stats we have collected for this uid's pids. |
| 6809 | */ |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6810 | final SparseArray<Pid> mPids = new SparseArray<>(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6811 | |
Narayan Kamath | 0ebc96c | 2017-12-29 13:32:38 +0000 | [diff] [blame] | 6812 | /** |
| 6813 | * The list of WorkChains associated with active bluetooth scans. |
| 6814 | * |
| 6815 | * NOTE: This is a hack and it only needs to exist because there's a "reset" API that is |
| 6816 | * supposed to stop and log all WorkChains that were currently active. |
| 6817 | */ |
| 6818 | ArrayList<WorkChain> mAllBluetoothChains = null; |
| 6819 | ArrayList<WorkChain> mUnoptimizedBluetoothChains = null; |
| 6820 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6821 | public Uid(BatteryStatsImpl bsi, int uid) { |
| 6822 | mBsi = bsi; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6823 | mUid = uid; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6824 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 6825 | mOnBatteryBackgroundTimeBase = new TimeBase(); |
| 6826 | mOnBatteryBackgroundTimeBase.init(mBsi.mClocks.uptimeMillis() * 1000, |
| 6827 | mBsi.mClocks.elapsedRealtime() * 1000); |
| 6828 | |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 6829 | mOnBatteryScreenOffBackgroundTimeBase = new TimeBase(); |
| 6830 | mOnBatteryScreenOffBackgroundTimeBase.init(mBsi.mClocks.uptimeMillis() * 1000, |
| 6831 | mBsi.mClocks.elapsedRealtime() * 1000); |
| 6832 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6833 | mUserCpuTime = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
| 6834 | mSystemCpuTime = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
Mike Ma | 3d422c3 | 2017-10-25 11:08:57 -0700 | [diff] [blame] | 6835 | mCpuActiveTimeMs = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
| 6836 | mCpuClusterTimesMs = new LongSamplingCounterArray(mBsi.mOnBatteryTimeBase); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6837 | |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame] | 6838 | mWakelockStats = mBsi.new OverflowArrayMap<Wakelock>(uid) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6839 | @Override public Wakelock instantiateObject() { |
| 6840 | return new Wakelock(mBsi, Uid.this); |
| 6841 | } |
| 6842 | }; |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 6843 | mSyncStats = mBsi.new OverflowArrayMap<DualTimer>(uid) { |
| 6844 | @Override public DualTimer instantiateObject() { |
| 6845 | return new DualTimer(mBsi.mClocks, Uid.this, SYNC, null, |
| 6846 | mBsi.mOnBatteryTimeBase, mOnBatteryBackgroundTimeBase); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6847 | } |
| 6848 | }; |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 6849 | mJobStats = mBsi.new OverflowArrayMap<DualTimer>(uid) { |
| 6850 | @Override public DualTimer instantiateObject() { |
| 6851 | return new DualTimer(mBsi.mClocks, Uid.this, JOB, null, |
| 6852 | mBsi.mOnBatteryTimeBase, mOnBatteryBackgroundTimeBase); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6853 | } |
| 6854 | }; |
| 6855 | |
| 6856 | mWifiRunningTimer = new StopwatchTimer(mBsi.mClocks, this, WIFI_RUNNING, |
| 6857 | mBsi.mWifiRunningTimers, mBsi.mOnBatteryTimeBase); |
| 6858 | mFullWifiLockTimer = new StopwatchTimer(mBsi.mClocks, this, FULL_WIFI_LOCK, |
| 6859 | mBsi.mFullWifiLockTimers, mBsi.mOnBatteryTimeBase); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 6860 | mWifiScanTimer = new DualTimer(mBsi.mClocks, this, WIFI_SCAN, |
| 6861 | mBsi.mWifiScanTimers, mBsi.mOnBatteryTimeBase, mOnBatteryBackgroundTimeBase); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6862 | mWifiBatchedScanTimer = new StopwatchTimer[NUM_WIFI_BATCHED_SCAN_BINS]; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6863 | mWifiMulticastTimer = new StopwatchTimer(mBsi.mClocks, this, WIFI_MULTICAST_ENABLED, |
| 6864 | mBsi.mWifiMulticastTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 6865 | mProcessStateTimer = new StopwatchTimer[NUM_PROCESS_STATE]; |
Amith Yamasani | 977e11f | 2018-02-16 11:29:54 -0800 | [diff] [blame] | 6866 | mJobsDeferredEventCount = new Counter(mBsi.mOnBatteryTimeBase); |
| 6867 | mJobsDeferredCount = new Counter(mBsi.mOnBatteryTimeBase); |
| 6868 | mJobsFreshnessTimeMs = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
| 6869 | mJobsFreshnessBuckets = new Counter[JOB_FRESHNESS_BUCKETS.length]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6870 | } |
| 6871 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 6872 | @VisibleForTesting |
| 6873 | public void setProcessStateForTest(int procState) { |
| 6874 | mProcessState = procState; |
| 6875 | } |
| 6876 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6877 | @Override |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 6878 | public long[] getCpuFreqTimes(int which) { |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 6879 | return nullIfAllZeros(mCpuFreqTimeMs, which); |
| 6880 | } |
| 6881 | |
| 6882 | @Override |
| 6883 | public long[] getScreenOffCpuFreqTimes(int which) { |
| 6884 | return nullIfAllZeros(mScreenOffCpuFreqTimeMs, which); |
| 6885 | } |
| 6886 | |
| 6887 | @Override |
Mike Ma | 3d422c3 | 2017-10-25 11:08:57 -0700 | [diff] [blame] | 6888 | public long getCpuActiveTime() { |
| 6889 | return mCpuActiveTimeMs.getCountLocked(STATS_SINCE_CHARGED); |
| 6890 | } |
| 6891 | |
| 6892 | @Override |
| 6893 | public long[] getCpuClusterTimes() { |
| 6894 | return nullIfAllZeros(mCpuClusterTimesMs, STATS_SINCE_CHARGED); |
| 6895 | } |
| 6896 | |
| 6897 | |
| 6898 | @Override |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 6899 | public long[] getCpuFreqTimes(int which, int procState) { |
| 6900 | if (which < 0 || which >= NUM_PROCESS_STATE) { |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 6901 | return null; |
| 6902 | } |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 6903 | if (mProcStateTimeMs == null) { |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 6904 | return null; |
| 6905 | } |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 6906 | if (!mBsi.mPerProcStateCpuTimesAvailable) { |
| 6907 | mProcStateTimeMs = null; |
| 6908 | return null; |
| 6909 | } |
| 6910 | return nullIfAllZeros(mProcStateTimeMs[procState], which); |
| 6911 | } |
| 6912 | |
| 6913 | @Override |
| 6914 | public long[] getScreenOffCpuFreqTimes(int which, int procState) { |
| 6915 | if (which < 0 || which >= NUM_PROCESS_STATE) { |
| 6916 | return null; |
| 6917 | } |
| 6918 | if (mProcStateScreenOffTimeMs == null) { |
| 6919 | return null; |
| 6920 | } |
| 6921 | if (!mBsi.mPerProcStateCpuTimesAvailable) { |
| 6922 | mProcStateScreenOffTimeMs = null; |
| 6923 | return null; |
| 6924 | } |
| 6925 | return nullIfAllZeros(mProcStateScreenOffTimeMs[procState], which); |
| 6926 | } |
| 6927 | |
| 6928 | public void addIsolatedUid(int isolatedUid) { |
| 6929 | if (mChildUids == null) { |
| 6930 | mChildUids = new IntArray(); |
| 6931 | } else if (mChildUids.indexOf(isolatedUid) >= 0) { |
| 6932 | return; |
| 6933 | } |
| 6934 | mChildUids.add(isolatedUid); |
| 6935 | } |
| 6936 | |
| 6937 | public void removeIsolatedUid(int isolatedUid) { |
| 6938 | final int idx = mChildUids == null ? -1 : mChildUids.indexOf(isolatedUid); |
| 6939 | if (idx < 0) { |
| 6940 | return; |
| 6941 | } |
| 6942 | mChildUids.remove(idx); |
| 6943 | } |
| 6944 | |
| 6945 | private long[] nullIfAllZeros(LongSamplingCounterArray cpuTimesMs, int which) { |
| 6946 | if (cpuTimesMs == null) { |
| 6947 | return null; |
| 6948 | } |
| 6949 | final long[] counts = cpuTimesMs.getCountsLocked(which); |
| 6950 | if (counts == null) { |
| 6951 | return null; |
| 6952 | } |
| 6953 | // Return counts only if at least one of the elements is non-zero. |
| 6954 | for (int i = counts.length - 1; i >= 0; --i) { |
| 6955 | if (counts[i] != 0) { |
| 6956 | return counts; |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 6957 | } |
| 6958 | } |
| 6959 | return null; |
| 6960 | } |
| 6961 | |
Sudheer Shanka | e544d16 | 2017-12-28 17:06:20 -0800 | [diff] [blame] | 6962 | private void addProcStateTimesMs(int procState, long[] cpuTimesMs, boolean onBattery) { |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 6963 | if (mProcStateTimeMs == null) { |
| 6964 | mProcStateTimeMs = new LongSamplingCounterArray[NUM_PROCESS_STATE]; |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 6965 | } |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 6966 | if (mProcStateTimeMs[procState] == null |
| 6967 | || mProcStateTimeMs[procState].getSize() != cpuTimesMs.length) { |
| 6968 | mProcStateTimeMs[procState] = new LongSamplingCounterArray( |
| 6969 | mBsi.mOnBatteryTimeBase); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 6970 | } |
Sudheer Shanka | e544d16 | 2017-12-28 17:06:20 -0800 | [diff] [blame] | 6971 | mProcStateTimeMs[procState].addCountLocked(cpuTimesMs, onBattery); |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 6972 | } |
| 6973 | |
Sudheer Shanka | e544d16 | 2017-12-28 17:06:20 -0800 | [diff] [blame] | 6974 | private void addProcStateScreenOffTimesMs(int procState, long[] cpuTimesMs, |
| 6975 | boolean onBatteryScreenOff) { |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 6976 | if (mProcStateScreenOffTimeMs == null) { |
| 6977 | mProcStateScreenOffTimeMs = new LongSamplingCounterArray[NUM_PROCESS_STATE]; |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 6978 | } |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 6979 | if (mProcStateScreenOffTimeMs[procState] == null |
| 6980 | || mProcStateScreenOffTimeMs[procState].getSize() != cpuTimesMs.length) { |
| 6981 | mProcStateScreenOffTimeMs[procState] = new LongSamplingCounterArray( |
| 6982 | mBsi.mOnBatteryScreenOffTimeBase); |
| 6983 | } |
Sudheer Shanka | e544d16 | 2017-12-28 17:06:20 -0800 | [diff] [blame] | 6984 | mProcStateScreenOffTimeMs[procState].addCountLocked(cpuTimesMs, onBatteryScreenOff); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 6985 | } |
| 6986 | |
| 6987 | @Override |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 6988 | public Timer getAggregatedPartialWakelockTimer() { |
| 6989 | return mAggregatedPartialWakelockTimer; |
| 6990 | } |
| 6991 | |
| 6992 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6993 | public ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> getWakelockStats() { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6994 | return mWakelockStats.getMap(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6995 | } |
| 6996 | |
| 6997 | @Override |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 6998 | public Timer getMulticastWakelockStats() { |
| 6999 | return mWifiMulticastTimer; |
| 7000 | } |
| 7001 | |
| 7002 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 7003 | public ArrayMap<String, ? extends BatteryStats.Timer> getSyncStats() { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7004 | return mSyncStats.getMap(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 7005 | } |
| 7006 | |
| 7007 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 7008 | public ArrayMap<String, ? extends BatteryStats.Timer> getJobStats() { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7009 | return mJobStats.getMap(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 7010 | } |
| 7011 | |
| 7012 | @Override |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 7013 | public ArrayMap<String, SparseIntArray> getJobCompletionStats() { |
| 7014 | return mJobCompletions; |
| 7015 | } |
| 7016 | |
| 7017 | @Override |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 7018 | public SparseArray<? extends BatteryStats.Uid.Sensor> getSensorStats() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7019 | return mSensorStats; |
| 7020 | } |
| 7021 | |
| 7022 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 7023 | public ArrayMap<String, ? extends BatteryStats.Uid.Proc> getProcessStats() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7024 | return mProcessStats; |
| 7025 | } |
| 7026 | |
| 7027 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 7028 | public ArrayMap<String, ? extends BatteryStats.Uid.Pkg> getPackageStats() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7029 | return mPackageStats; |
| 7030 | } |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 7031 | |
| 7032 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7033 | public int getUid() { |
| 7034 | return mUid; |
| 7035 | } |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 7036 | |
| 7037 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7038 | public void noteWifiRunningLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 7039 | if (!mWifiRunning) { |
| 7040 | mWifiRunning = true; |
| 7041 | if (mWifiRunningTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7042 | mWifiRunningTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, WIFI_RUNNING, |
| 7043 | mBsi.mWifiRunningTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7044 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7045 | mWifiRunningTimer.startRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 7046 | } |
| 7047 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7048 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 7049 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7050 | public void noteWifiStoppedLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 7051 | if (mWifiRunning) { |
| 7052 | mWifiRunning = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7053 | mWifiRunningTimer.stopRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 7054 | } |
| 7055 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7056 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 7057 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7058 | public void noteFullWifiLockAcquiredLocked(long elapsedRealtimeMs) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7059 | if (!mFullWifiLockOut) { |
| 7060 | mFullWifiLockOut = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7061 | if (mFullWifiLockTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7062 | mFullWifiLockTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, FULL_WIFI_LOCK, |
| 7063 | mBsi.mFullWifiLockTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7064 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7065 | mFullWifiLockTimer.startRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7066 | } |
| 7067 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7068 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7069 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7070 | public void noteFullWifiLockReleasedLocked(long elapsedRealtimeMs) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7071 | if (mFullWifiLockOut) { |
| 7072 | mFullWifiLockOut = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7073 | mFullWifiLockTimer.stopRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7074 | } |
| 7075 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7076 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7077 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7078 | public void noteWifiScanStartedLocked(long elapsedRealtimeMs) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 7079 | if (!mWifiScanStarted) { |
| 7080 | mWifiScanStarted = true; |
| 7081 | if (mWifiScanTimer == null) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 7082 | mWifiScanTimer = new DualTimer(mBsi.mClocks, Uid.this, WIFI_SCAN, |
| 7083 | mBsi.mWifiScanTimers, mBsi.mOnBatteryTimeBase, |
| 7084 | mOnBatteryBackgroundTimeBase); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7085 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7086 | mWifiScanTimer.startRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7087 | } |
| 7088 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7089 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7090 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7091 | public void noteWifiScanStoppedLocked(long elapsedRealtimeMs) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 7092 | if (mWifiScanStarted) { |
| 7093 | mWifiScanStarted = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7094 | mWifiScanTimer.stopRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7095 | } |
| 7096 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 7097 | |
| 7098 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7099 | public void noteWifiBatchedScanStartedLocked(int csph, long elapsedRealtimeMs) { |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 7100 | int bin = 0; |
Navtej Singh Mann | 3c0ce5c | 2015-06-11 16:53:11 -0700 | [diff] [blame] | 7101 | while (csph > 8 && bin < NUM_WIFI_BATCHED_SCAN_BINS-1) { |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 7102 | csph = csph >> 3; |
| 7103 | bin++; |
| 7104 | } |
| 7105 | |
| 7106 | if (mWifiBatchedScanBinStarted == bin) return; |
| 7107 | |
| 7108 | if (mWifiBatchedScanBinStarted != NO_BATCHED_SCAN_STARTED) { |
| 7109 | mWifiBatchedScanTimer[mWifiBatchedScanBinStarted]. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7110 | stopRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 7111 | } |
| 7112 | mWifiBatchedScanBinStarted = bin; |
| 7113 | if (mWifiBatchedScanTimer[bin] == null) { |
| 7114 | makeWifiBatchedScanBin(bin, null); |
| 7115 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7116 | mWifiBatchedScanTimer[bin].startRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 7117 | } |
| 7118 | |
| 7119 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7120 | public void noteWifiBatchedScanStoppedLocked(long elapsedRealtimeMs) { |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 7121 | if (mWifiBatchedScanBinStarted != NO_BATCHED_SCAN_STARTED) { |
| 7122 | mWifiBatchedScanTimer[mWifiBatchedScanBinStarted]. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7123 | stopRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 7124 | mWifiBatchedScanBinStarted = NO_BATCHED_SCAN_STARTED; |
| 7125 | } |
| 7126 | } |
| 7127 | |
| 7128 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7129 | public void noteWifiMulticastEnabledLocked(long elapsedRealtimeMs) { |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 7130 | if (!mWifiMulticastEnabled) { |
| 7131 | mWifiMulticastEnabled = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7132 | if (mWifiMulticastTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7133 | mWifiMulticastTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, |
| 7134 | WIFI_MULTICAST_ENABLED, mBsi.mWifiMulticastTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7135 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7136 | mWifiMulticastTimer.startRunningLocked(elapsedRealtimeMs); |
Tej Singh | 4503e10 | 2018-01-04 14:35:01 -0800 | [diff] [blame] | 7137 | StatsLog.write_non_chained( |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 7138 | StatsLog.WIFI_MULTICAST_LOCK_STATE_CHANGED, getUid(), null, |
| 7139 | StatsLog.WIFI_MULTICAST_LOCK_STATE_CHANGED__STATE__ON); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 7140 | } |
| 7141 | } |
| 7142 | |
| 7143 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7144 | public void noteWifiMulticastDisabledLocked(long elapsedRealtimeMs) { |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 7145 | if (mWifiMulticastEnabled) { |
| 7146 | mWifiMulticastEnabled = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7147 | mWifiMulticastTimer.stopRunningLocked(elapsedRealtimeMs); |
Tej Singh | 4503e10 | 2018-01-04 14:35:01 -0800 | [diff] [blame] | 7148 | StatsLog.write_non_chained( |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 7149 | StatsLog.WIFI_MULTICAST_LOCK_STATE_CHANGED, getUid(), null, |
| 7150 | StatsLog.WIFI_MULTICAST_LOCK_STATE_CHANGED__STATE__OFF); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 7151 | } |
| 7152 | } |
| 7153 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 7154 | @Override |
| 7155 | public ControllerActivityCounter getWifiControllerActivity() { |
| 7156 | return mWifiControllerActivity; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7157 | } |
| 7158 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 7159 | @Override |
| 7160 | public ControllerActivityCounter getBluetoothControllerActivity() { |
| 7161 | return mBluetoothControllerActivity; |
| 7162 | } |
| 7163 | |
| 7164 | @Override |
| 7165 | public ControllerActivityCounter getModemControllerActivity() { |
| 7166 | return mModemControllerActivity; |
| 7167 | } |
| 7168 | |
| 7169 | public ControllerActivityCounterImpl getOrCreateWifiControllerActivityLocked() { |
| 7170 | if (mWifiControllerActivity == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7171 | mWifiControllerActivity = new ControllerActivityCounterImpl(mBsi.mOnBatteryTimeBase, |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 7172 | NUM_BT_TX_LEVELS); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 7173 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 7174 | return mWifiControllerActivity; |
| 7175 | } |
| 7176 | |
| 7177 | public ControllerActivityCounterImpl getOrCreateBluetoothControllerActivityLocked() { |
| 7178 | if (mBluetoothControllerActivity == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7179 | mBluetoothControllerActivity = new ControllerActivityCounterImpl(mBsi.mOnBatteryTimeBase, |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 7180 | NUM_BT_TX_LEVELS); |
| 7181 | } |
| 7182 | return mBluetoothControllerActivity; |
| 7183 | } |
| 7184 | |
| 7185 | public ControllerActivityCounterImpl getOrCreateModemControllerActivityLocked() { |
| 7186 | if (mModemControllerActivity == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7187 | mModemControllerActivity = new ControllerActivityCounterImpl(mBsi.mOnBatteryTimeBase, |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 7188 | ModemActivityInfo.TX_POWER_LEVELS); |
| 7189 | } |
| 7190 | return mModemControllerActivity; |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 7191 | } |
| 7192 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 7193 | public StopwatchTimer createAudioTurnedOnTimerLocked() { |
| 7194 | if (mAudioTurnedOnTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7195 | mAudioTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, AUDIO_TURNED_ON, |
| 7196 | mBsi.mAudioTurnedOnTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 7197 | } |
| 7198 | return mAudioTurnedOnTimer; |
| 7199 | } |
| 7200 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7201 | public void noteAudioTurnedOnLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 7202 | createAudioTurnedOnTimerLocked().startRunningLocked(elapsedRealtimeMs); |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 7203 | StatsLog.write_non_chained(StatsLog.AUDIO_STATE_CHANGED, getUid(), null, |
| 7204 | StatsLog.AUDIO_STATE_CHANGED__STATE__ON); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 7205 | } |
| 7206 | |
| 7207 | public void noteAudioTurnedOffLocked(long elapsedRealtimeMs) { |
| 7208 | if (mAudioTurnedOnTimer != null) { |
| 7209 | mAudioTurnedOnTimer.stopRunningLocked(elapsedRealtimeMs); |
Bookatz | c1a050a | 2017-10-10 15:49:28 -0700 | [diff] [blame] | 7210 | if (!mAudioTurnedOnTimer.isRunningLocked()) { // only tell statsd if truly stopped |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 7211 | StatsLog.write_non_chained(StatsLog.AUDIO_STATE_CHANGED, getUid(), null, |
| 7212 | StatsLog.AUDIO_STATE_CHANGED__STATE__OFF); |
Bookatz | c1a050a | 2017-10-10 15:49:28 -0700 | [diff] [blame] | 7213 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7214 | } |
| 7215 | } |
| 7216 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 7217 | public void noteResetAudioLocked(long elapsedRealtimeMs) { |
| 7218 | if (mAudioTurnedOnTimer != null) { |
| 7219 | mAudioTurnedOnTimer.stopAllRunningLocked(elapsedRealtimeMs); |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 7220 | StatsLog.write_non_chained(StatsLog.AUDIO_STATE_CHANGED, getUid(), null, |
| 7221 | StatsLog.AUDIO_STATE_CHANGED__STATE__OFF); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7222 | } |
| 7223 | } |
| 7224 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 7225 | public StopwatchTimer createVideoTurnedOnTimerLocked() { |
| 7226 | if (mVideoTurnedOnTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7227 | mVideoTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, VIDEO_TURNED_ON, |
| 7228 | mBsi.mVideoTurnedOnTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 7229 | } |
| 7230 | return mVideoTurnedOnTimer; |
| 7231 | } |
| 7232 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7233 | public void noteVideoTurnedOnLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 7234 | createVideoTurnedOnTimerLocked().startRunningLocked(elapsedRealtimeMs); |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 7235 | StatsLog.write_non_chained(StatsLog.MEDIA_CODEC_ACTIVITY_CHANGED, getUid(), null, |
| 7236 | StatsLog.MEDIA_CODEC_ACTIVITY_CHANGED__STATE__ON); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 7237 | } |
| 7238 | |
| 7239 | public void noteVideoTurnedOffLocked(long elapsedRealtimeMs) { |
| 7240 | if (mVideoTurnedOnTimer != null) { |
| 7241 | mVideoTurnedOnTimer.stopRunningLocked(elapsedRealtimeMs); |
Bookatz | c1a050a | 2017-10-10 15:49:28 -0700 | [diff] [blame] | 7242 | if (!mVideoTurnedOnTimer.isRunningLocked()) { // only tell statsd if truly stopped |
Yangster-mac | 2f5daec | 2018-01-16 10:23:15 -0800 | [diff] [blame] | 7243 | StatsLog.write_non_chained(StatsLog.MEDIA_CODEC_ACTIVITY_CHANGED, getUid(), |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 7244 | null, StatsLog.MEDIA_CODEC_ACTIVITY_CHANGED__STATE__OFF); |
Bookatz | c1a050a | 2017-10-10 15:49:28 -0700 | [diff] [blame] | 7245 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7246 | } |
| 7247 | } |
| 7248 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 7249 | public void noteResetVideoLocked(long elapsedRealtimeMs) { |
| 7250 | if (mVideoTurnedOnTimer != null) { |
| 7251 | mVideoTurnedOnTimer.stopAllRunningLocked(elapsedRealtimeMs); |
Yangster-mac | 2f5daec | 2018-01-16 10:23:15 -0800 | [diff] [blame] | 7252 | StatsLog.write_non_chained(StatsLog.MEDIA_CODEC_ACTIVITY_CHANGED, getUid(), null, |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 7253 | StatsLog.MEDIA_CODEC_ACTIVITY_CHANGED__STATE__OFF); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 7254 | } |
| 7255 | } |
| 7256 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 7257 | public StopwatchTimer createFlashlightTurnedOnTimerLocked() { |
| 7258 | if (mFlashlightTurnedOnTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7259 | mFlashlightTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, |
| 7260 | FLASHLIGHT_TURNED_ON, mBsi.mFlashlightTurnedOnTimers, mBsi.mOnBatteryTimeBase); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 7261 | } |
| 7262 | return mFlashlightTurnedOnTimer; |
| 7263 | } |
| 7264 | |
| 7265 | public void noteFlashlightTurnedOnLocked(long elapsedRealtimeMs) { |
| 7266 | createFlashlightTurnedOnTimerLocked().startRunningLocked(elapsedRealtimeMs); |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 7267 | StatsLog.write_non_chained(StatsLog.FLASHLIGHT_STATE_CHANGED, getUid(), null, |
| 7268 | StatsLog.FLASHLIGHT_STATE_CHANGED__STATE__ON); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 7269 | } |
| 7270 | |
| 7271 | public void noteFlashlightTurnedOffLocked(long elapsedRealtimeMs) { |
| 7272 | if (mFlashlightTurnedOnTimer != null) { |
| 7273 | mFlashlightTurnedOnTimer.stopRunningLocked(elapsedRealtimeMs); |
Bookatz | c1a050a | 2017-10-10 15:49:28 -0700 | [diff] [blame] | 7274 | if (!mFlashlightTurnedOnTimer.isRunningLocked()) { |
Yangster-mac | 2f5daec | 2018-01-16 10:23:15 -0800 | [diff] [blame] | 7275 | StatsLog.write_non_chained(StatsLog.FLASHLIGHT_STATE_CHANGED, getUid(), null, |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 7276 | StatsLog.FLASHLIGHT_STATE_CHANGED__STATE__OFF); |
Bookatz | c1a050a | 2017-10-10 15:49:28 -0700 | [diff] [blame] | 7277 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 7278 | } |
| 7279 | } |
| 7280 | |
| 7281 | public void noteResetFlashlightLocked(long elapsedRealtimeMs) { |
| 7282 | if (mFlashlightTurnedOnTimer != null) { |
| 7283 | mFlashlightTurnedOnTimer.stopAllRunningLocked(elapsedRealtimeMs); |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 7284 | StatsLog.write_non_chained(StatsLog.FLASHLIGHT_STATE_CHANGED, getUid(), null, |
| 7285 | StatsLog.FLASHLIGHT_STATE_CHANGED__STATE__OFF); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 7286 | } |
| 7287 | } |
| 7288 | |
| 7289 | public StopwatchTimer createCameraTurnedOnTimerLocked() { |
| 7290 | if (mCameraTurnedOnTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7291 | mCameraTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, CAMERA_TURNED_ON, |
| 7292 | mBsi.mCameraTurnedOnTimers, mBsi.mOnBatteryTimeBase); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 7293 | } |
| 7294 | return mCameraTurnedOnTimer; |
| 7295 | } |
| 7296 | |
| 7297 | public void noteCameraTurnedOnLocked(long elapsedRealtimeMs) { |
| 7298 | createCameraTurnedOnTimerLocked().startRunningLocked(elapsedRealtimeMs); |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 7299 | StatsLog.write_non_chained(StatsLog.CAMERA_STATE_CHANGED, getUid(), null, |
| 7300 | StatsLog.CAMERA_STATE_CHANGED__STATE__ON); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 7301 | } |
| 7302 | |
| 7303 | public void noteCameraTurnedOffLocked(long elapsedRealtimeMs) { |
| 7304 | if (mCameraTurnedOnTimer != null) { |
| 7305 | mCameraTurnedOnTimer.stopRunningLocked(elapsedRealtimeMs); |
Bookatz | c1a050a | 2017-10-10 15:49:28 -0700 | [diff] [blame] | 7306 | if (!mCameraTurnedOnTimer.isRunningLocked()) { // only tell statsd if truly stopped |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 7307 | StatsLog.write_non_chained(StatsLog.CAMERA_STATE_CHANGED, getUid(), null, |
| 7308 | StatsLog.CAMERA_STATE_CHANGED__STATE__OFF); |
Bookatz | c1a050a | 2017-10-10 15:49:28 -0700 | [diff] [blame] | 7309 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 7310 | } |
| 7311 | } |
| 7312 | |
| 7313 | public void noteResetCameraLocked(long elapsedRealtimeMs) { |
| 7314 | if (mCameraTurnedOnTimer != null) { |
| 7315 | mCameraTurnedOnTimer.stopAllRunningLocked(elapsedRealtimeMs); |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 7316 | StatsLog.write_non_chained(StatsLog.CAMERA_STATE_CHANGED, getUid(), null, |
| 7317 | StatsLog.CAMERA_STATE_CHANGED__STATE__OFF); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 7318 | } |
| 7319 | } |
| 7320 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 7321 | public StopwatchTimer createForegroundActivityTimerLocked() { |
| 7322 | if (mForegroundActivityTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7323 | mForegroundActivityTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, |
| 7324 | FOREGROUND_ACTIVITY, null, mBsi.mOnBatteryTimeBase); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 7325 | } |
| 7326 | return mForegroundActivityTimer; |
| 7327 | } |
| 7328 | |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 7329 | public StopwatchTimer createForegroundServiceTimerLocked() { |
| 7330 | if (mForegroundServiceTimer == null) { |
| 7331 | mForegroundServiceTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, |
| 7332 | FOREGROUND_SERVICE, null, mBsi.mOnBatteryTimeBase); |
| 7333 | } |
| 7334 | return mForegroundServiceTimer; |
| 7335 | } |
| 7336 | |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 7337 | public DualTimer createAggregatedPartialWakelockTimerLocked() { |
| 7338 | if (mAggregatedPartialWakelockTimer == null) { |
| 7339 | mAggregatedPartialWakelockTimer = new DualTimer(mBsi.mClocks, this, |
| 7340 | AGGREGATED_WAKE_TYPE_PARTIAL, null, |
| 7341 | mBsi.mOnBatteryScreenOffTimeBase, mOnBatteryScreenOffBackgroundTimeBase); |
| 7342 | } |
| 7343 | return mAggregatedPartialWakelockTimer; |
| 7344 | } |
| 7345 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 7346 | public DualTimer createBluetoothScanTimerLocked() { |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 7347 | if (mBluetoothScanTimer == null) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 7348 | mBluetoothScanTimer = new DualTimer(mBsi.mClocks, Uid.this, BLUETOOTH_SCAN_ON, |
| 7349 | mBsi.mBluetoothScanOnTimers, mBsi.mOnBatteryTimeBase, |
| 7350 | mOnBatteryBackgroundTimeBase); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 7351 | } |
| 7352 | return mBluetoothScanTimer; |
| 7353 | } |
| 7354 | |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 7355 | public DualTimer createBluetoothUnoptimizedScanTimerLocked() { |
| 7356 | if (mBluetoothUnoptimizedScanTimer == null) { |
| 7357 | mBluetoothUnoptimizedScanTimer = new DualTimer(mBsi.mClocks, Uid.this, |
| 7358 | BLUETOOTH_UNOPTIMIZED_SCAN_ON, null, |
| 7359 | mBsi.mOnBatteryTimeBase, mOnBatteryBackgroundTimeBase); |
| 7360 | } |
| 7361 | return mBluetoothUnoptimizedScanTimer; |
| 7362 | } |
| 7363 | |
Narayan Kamath | 0ebc96c | 2017-12-29 13:32:38 +0000 | [diff] [blame] | 7364 | public void noteBluetoothScanStartedLocked(long elapsedRealtimeMs, |
| 7365 | boolean isUnoptimized) { |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 7366 | createBluetoothScanTimerLocked().startRunningLocked(elapsedRealtimeMs); |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 7367 | if (isUnoptimized) { |
| 7368 | createBluetoothUnoptimizedScanTimerLocked().startRunningLocked(elapsedRealtimeMs); |
| 7369 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 7370 | } |
| 7371 | |
Bookatz | 94c5a31 | 2017-07-11 16:49:17 -0700 | [diff] [blame] | 7372 | public void noteBluetoothScanStoppedLocked(long elapsedRealtimeMs, boolean isUnoptimized) { |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 7373 | if (mBluetoothScanTimer != null) { |
| 7374 | mBluetoothScanTimer.stopRunningLocked(elapsedRealtimeMs); |
| 7375 | } |
Bookatz | 94c5a31 | 2017-07-11 16:49:17 -0700 | [diff] [blame] | 7376 | if (isUnoptimized && mBluetoothUnoptimizedScanTimer != null) { |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 7377 | mBluetoothUnoptimizedScanTimer.stopRunningLocked(elapsedRealtimeMs); |
| 7378 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 7379 | } |
| 7380 | |
Narayan Kamath | 0ebc96c | 2017-12-29 13:32:38 +0000 | [diff] [blame] | 7381 | public void addBluetoothWorkChain(WorkChain workChain, boolean isUnoptimized) { |
| 7382 | if (mAllBluetoothChains == null) { |
| 7383 | mAllBluetoothChains = new ArrayList<WorkChain>(4); |
| 7384 | } |
| 7385 | |
| 7386 | if (isUnoptimized && mUnoptimizedBluetoothChains == null) { |
| 7387 | mUnoptimizedBluetoothChains = new ArrayList<WorkChain>(4); |
| 7388 | } |
| 7389 | |
| 7390 | mAllBluetoothChains.add(workChain); |
| 7391 | if (isUnoptimized) { |
| 7392 | mUnoptimizedBluetoothChains.add(workChain); |
| 7393 | } |
| 7394 | } |
| 7395 | |
| 7396 | public void removeBluetoothWorkChain(WorkChain workChain, boolean isUnoptimized) { |
| 7397 | if (mAllBluetoothChains != null) { |
| 7398 | mAllBluetoothChains.remove(workChain); |
| 7399 | } |
| 7400 | |
| 7401 | if (isUnoptimized && mUnoptimizedBluetoothChains != null) { |
| 7402 | mUnoptimizedBluetoothChains.remove(workChain); |
| 7403 | } |
| 7404 | } |
| 7405 | |
| 7406 | public List<WorkChain> getAllBluetoothWorkChains() { |
| 7407 | return mAllBluetoothChains; |
| 7408 | } |
| 7409 | |
| 7410 | public List<WorkChain> getUnoptimizedBluetoothWorkChains() { |
| 7411 | return mUnoptimizedBluetoothChains; |
| 7412 | } |
| 7413 | |
| 7414 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 7415 | public void noteResetBluetoothScanLocked(long elapsedRealtimeMs) { |
| 7416 | if (mBluetoothScanTimer != null) { |
| 7417 | mBluetoothScanTimer.stopAllRunningLocked(elapsedRealtimeMs); |
| 7418 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 7419 | if (mBluetoothUnoptimizedScanTimer != null) { |
| 7420 | mBluetoothUnoptimizedScanTimer.stopAllRunningLocked(elapsedRealtimeMs); |
| 7421 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 7422 | } |
| 7423 | |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 7424 | public Counter createBluetoothScanResultCounterLocked() { |
| 7425 | if (mBluetoothScanResultCounter == null) { |
| 7426 | mBluetoothScanResultCounter = new Counter(mBsi.mOnBatteryTimeBase); |
| 7427 | } |
| 7428 | return mBluetoothScanResultCounter; |
| 7429 | } |
| 7430 | |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 7431 | public Counter createBluetoothScanResultBgCounterLocked() { |
| 7432 | if (mBluetoothScanResultBgCounter == null) { |
| 7433 | mBluetoothScanResultBgCounter = new Counter(mOnBatteryBackgroundTimeBase); |
| 7434 | } |
| 7435 | return mBluetoothScanResultBgCounter; |
| 7436 | } |
| 7437 | |
Bookatz | 4ebc064 | 2017-05-11 12:21:19 -0700 | [diff] [blame] | 7438 | public void noteBluetoothScanResultsLocked(int numNewResults) { |
| 7439 | createBluetoothScanResultCounterLocked().addAtomic(numNewResults); |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 7440 | // Uses background timebase, so the count will only be incremented if uid in background. |
| 7441 | createBluetoothScanResultBgCounterLocked().addAtomic(numNewResults); |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 7442 | } |
| 7443 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 7444 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7445 | public void noteActivityResumedLocked(long elapsedRealtimeMs) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 7446 | // We always start, since we want multiple foreground PIDs to nest |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7447 | createForegroundActivityTimerLocked().startRunningLocked(elapsedRealtimeMs); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 7448 | } |
| 7449 | |
| 7450 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7451 | public void noteActivityPausedLocked(long elapsedRealtimeMs) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 7452 | if (mForegroundActivityTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7453 | mForegroundActivityTimer.stopRunningLocked(elapsedRealtimeMs); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 7454 | } |
| 7455 | } |
| 7456 | |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 7457 | public void noteForegroundServiceResumedLocked(long elapsedRealtimeMs) { |
| 7458 | createForegroundServiceTimerLocked().startRunningLocked(elapsedRealtimeMs); |
| 7459 | } |
| 7460 | |
| 7461 | public void noteForegroundServicePausedLocked(long elapsedRealtimeMs) { |
| 7462 | if (mForegroundServiceTimer != null) { |
| 7463 | mForegroundServiceTimer.stopRunningLocked(elapsedRealtimeMs); |
| 7464 | } |
| 7465 | } |
| 7466 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 7467 | public BatchTimer createVibratorOnTimerLocked() { |
| 7468 | if (mVibratorOnTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7469 | mVibratorOnTimer = new BatchTimer(mBsi.mClocks, Uid.this, VIBRATOR_ON, |
| 7470 | mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 7471 | } |
| 7472 | return mVibratorOnTimer; |
| 7473 | } |
| 7474 | |
| 7475 | public void noteVibratorOnLocked(long durationMillis) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7476 | createVibratorOnTimerLocked().addDuration(mBsi, durationMillis); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 7477 | } |
| 7478 | |
| 7479 | public void noteVibratorOffLocked() { |
| 7480 | if (mVibratorOnTimer != null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7481 | mVibratorOnTimer.abortLastDuration(mBsi); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7482 | } |
| 7483 | } |
| 7484 | |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7485 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7486 | public long getWifiRunningTime(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 7487 | if (mWifiRunningTimer == null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7488 | return 0; |
| 7489 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7490 | return mWifiRunningTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 7491 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 7492 | |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7493 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7494 | public long getFullWifiLockTime(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7495 | if (mFullWifiLockTimer == null) { |
| 7496 | return 0; |
| 7497 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7498 | return mFullWifiLockTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7499 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7500 | |
| 7501 | @Override |
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); |
| 7855 | final long averageLatency = deferredEventCount != 0 |
| 7856 | ? mJobsFreshnessTimeMs.getCountLocked(which) / deferredEventCount |
| 7857 | : 0L; |
| 7858 | sb.append(deferredEventCount); sb.append(','); |
| 7859 | sb.append(deferredCount); sb.append(','); |
| 7860 | sb.append(averageLatency); |
| 7861 | for (int i = 0; i < JOB_FRESHNESS_BUCKETS.length; i++) { |
| 7862 | if (mJobsFreshnessBuckets[i] == null) { |
| 7863 | sb.append(",0"); |
| 7864 | } else { |
| 7865 | sb.append(","); |
| 7866 | sb.append(mJobsFreshnessBuckets[i].getCountLocked(which)); |
| 7867 | } |
| 7868 | } |
| 7869 | } |
| 7870 | |
| 7871 | @Override |
| 7872 | public void getDeferredJobsLineLocked(StringBuilder sb, int which) { |
| 7873 | sb.setLength(0); |
| 7874 | final int deferredEventCount = mJobsDeferredEventCount.getCountLocked(which); |
| 7875 | if (deferredEventCount == 0) { |
| 7876 | return; |
| 7877 | } |
| 7878 | final int deferredCount = mJobsDeferredCount.getCountLocked(which); |
| 7879 | final long averageLatency = deferredEventCount != 0 |
| 7880 | ? mJobsFreshnessTimeMs.getCountLocked(which) / deferredEventCount |
| 7881 | : 0L; |
| 7882 | sb.append("times="); sb.append(deferredEventCount); sb.append(", "); |
| 7883 | sb.append("count="); sb.append(deferredCount); sb.append(", "); |
| 7884 | sb.append("avgLatency="); sb.append(averageLatency); sb.append(", "); |
| 7885 | for (int i = 0; i < JOB_FRESHNESS_BUCKETS.length; i++) { |
| 7886 | sb.append("<"); sb.append(JOB_FRESHNESS_BUCKETS[i]); sb.append("ms="); |
| 7887 | if (mJobsFreshnessBuckets[i] == null) { |
| 7888 | sb.append("0"); |
| 7889 | } else { |
| 7890 | sb.append(mJobsFreshnessBuckets[i].getCountLocked(which)); |
| 7891 | } |
| 7892 | sb.append(" "); |
| 7893 | } |
| 7894 | } |
| 7895 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7896 | void initNetworkActivityLocked() { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 7897 | mNetworkByteActivityCounters = new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
| 7898 | mNetworkPacketActivityCounters = new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7899 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7900 | mNetworkByteActivityCounters[i] = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
| 7901 | mNetworkPacketActivityCounters[i] = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7902 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7903 | mMobileRadioActiveTime = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
| 7904 | mMobileRadioActiveCount = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7905 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 7906 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7907 | /** |
| 7908 | * Clear all stats for this uid. Returns true if the uid is completely |
| 7909 | * inactive so can be dropped. |
| 7910 | */ |
Adam Lesinski | 5f212c8 | 2017-03-13 12:25:13 -0700 | [diff] [blame] | 7911 | @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
Bookatz | 993a0be | 2017-07-21 09:03:23 -0700 | [diff] [blame] | 7912 | public boolean reset(long uptime, long realtime) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7913 | boolean active = false; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7914 | |
Bookatz | 993a0be | 2017-07-21 09:03:23 -0700 | [diff] [blame] | 7915 | mOnBatteryBackgroundTimeBase.init(uptime, realtime); |
| 7916 | mOnBatteryScreenOffBackgroundTimeBase.init(uptime, realtime); |
| 7917 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 7918 | if (mWifiRunningTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7919 | active |= !mWifiRunningTimer.reset(false); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 7920 | active |= mWifiRunning; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7921 | } |
| 7922 | if (mFullWifiLockTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7923 | active |= !mFullWifiLockTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7924 | active |= mFullWifiLockOut; |
| 7925 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 7926 | if (mWifiScanTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7927 | active |= !mWifiScanTimer.reset(false); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 7928 | active |= mWifiScanStarted; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7929 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 7930 | if (mWifiBatchedScanTimer != null) { |
| 7931 | for (int i = 0; i < NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 7932 | if (mWifiBatchedScanTimer[i] != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7933 | active |= !mWifiBatchedScanTimer[i].reset(false); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 7934 | } |
| 7935 | } |
| 7936 | active |= (mWifiBatchedScanBinStarted != NO_BATCHED_SCAN_STARTED); |
| 7937 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7938 | if (mWifiMulticastTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7939 | active |= !mWifiMulticastTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7940 | active |= mWifiMulticastEnabled; |
| 7941 | } |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 7942 | |
| 7943 | active |= !resetTimerIfNotNull(mAudioTurnedOnTimer, false); |
| 7944 | active |= !resetTimerIfNotNull(mVideoTurnedOnTimer, false); |
| 7945 | active |= !resetTimerIfNotNull(mFlashlightTurnedOnTimer, false); |
| 7946 | active |= !resetTimerIfNotNull(mCameraTurnedOnTimer, false); |
| 7947 | active |= !resetTimerIfNotNull(mForegroundActivityTimer, false); |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 7948 | active |= !resetTimerIfNotNull(mForegroundServiceTimer, false); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 7949 | active |= !resetTimerIfNotNull(mAggregatedPartialWakelockTimer, false); |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 7950 | active |= !resetTimerIfNotNull(mBluetoothScanTimer, false); |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 7951 | active |= !resetTimerIfNotNull(mBluetoothUnoptimizedScanTimer, false); |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 7952 | if (mBluetoothScanResultCounter != null) { |
| 7953 | mBluetoothScanResultCounter.reset(false); |
| 7954 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 7955 | if (mBluetoothScanResultBgCounter != null) { |
| 7956 | mBluetoothScanResultBgCounter.reset(false); |
| 7957 | } |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 7958 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 7959 | if (mProcessStateTimer != null) { |
| 7960 | for (int i = 0; i < NUM_PROCESS_STATE; i++) { |
| 7961 | if (mProcessStateTimer[i] != null) { |
| 7962 | active |= !mProcessStateTimer[i].reset(false); |
| 7963 | } |
| 7964 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 7965 | active |= (mProcessState != ActivityManager.PROCESS_STATE_NONEXISTENT); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 7966 | } |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 7967 | if (mVibratorOnTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7968 | if (mVibratorOnTimer.reset(false)) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 7969 | mVibratorOnTimer.detach(); |
| 7970 | mVibratorOnTimer = null; |
| 7971 | } else { |
| 7972 | active = true; |
| 7973 | } |
| 7974 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7975 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7976 | if (mUserActivityCounters != null) { |
| 7977 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
| 7978 | mUserActivityCounters[i].reset(false); |
| 7979 | } |
| 7980 | } |
| 7981 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 7982 | if (mNetworkByteActivityCounters != null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7983 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 7984 | mNetworkByteActivityCounters[i].reset(false); |
| 7985 | mNetworkPacketActivityCounters[i].reset(false); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7986 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 7987 | mMobileRadioActiveTime.reset(false); |
| 7988 | mMobileRadioActiveCount.reset(false); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7989 | } |
| 7990 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 7991 | if (mWifiControllerActivity != null) { |
| 7992 | mWifiControllerActivity.reset(false); |
| 7993 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7994 | |
Adam Lesinski | 1a2b39e | 2016-04-29 17:56:58 -0700 | [diff] [blame] | 7995 | if (mBluetoothControllerActivity != null) { |
| 7996 | mBluetoothControllerActivity.reset(false); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 7997 | } |
| 7998 | |
Adam Lesinski | 1a2b39e | 2016-04-29 17:56:58 -0700 | [diff] [blame] | 7999 | if (mModemControllerActivity != null) { |
| 8000 | mModemControllerActivity.reset(false); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8001 | } |
| 8002 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 8003 | mUserCpuTime.reset(false); |
| 8004 | mSystemCpuTime.reset(false); |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 8005 | |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 8006 | if (mCpuClusterSpeedTimesUs != null) { |
| 8007 | for (LongSamplingCounter[] speeds : mCpuClusterSpeedTimesUs) { |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 8008 | if (speeds != null) { |
| 8009 | for (LongSamplingCounter speed : speeds) { |
| 8010 | if (speed != null) { |
| 8011 | speed.reset(false); |
| 8012 | } |
| 8013 | } |
| 8014 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 8015 | } |
| 8016 | } |
| 8017 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 8018 | if (mCpuFreqTimeMs != null) { |
| 8019 | mCpuFreqTimeMs.reset(false); |
| 8020 | } |
| 8021 | if (mScreenOffCpuFreqTimeMs != null) { |
| 8022 | mScreenOffCpuFreqTimeMs.reset(false); |
| 8023 | } |
| 8024 | |
Mike Ma | 3d422c3 | 2017-10-25 11:08:57 -0700 | [diff] [blame] | 8025 | mCpuActiveTimeMs.reset(false); |
| 8026 | mCpuClusterTimesMs.reset(false); |
| 8027 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 8028 | if (mProcStateTimeMs != null) { |
| 8029 | for (LongSamplingCounterArray counters : mProcStateTimeMs) { |
| 8030 | if (counters != null) { |
| 8031 | counters.reset(false); |
| 8032 | } |
| 8033 | } |
| 8034 | } |
| 8035 | if (mProcStateScreenOffTimeMs != null) { |
| 8036 | for (LongSamplingCounterArray counters : mProcStateScreenOffTimeMs) { |
| 8037 | if (counters != null) { |
| 8038 | counters.reset(false); |
| 8039 | } |
| 8040 | } |
| 8041 | } |
| 8042 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 8043 | resetLongCounterIfNotNull(mMobileRadioApWakeupCount, false); |
| 8044 | resetLongCounterIfNotNull(mWifiRadioApWakeupCount, false); |
| 8045 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8046 | final ArrayMap<String, Wakelock> wakeStats = mWakelockStats.getMap(); |
| 8047 | for (int iw=wakeStats.size()-1; iw>=0; iw--) { |
| 8048 | Wakelock wl = wakeStats.valueAt(iw); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 8049 | if (wl.reset()) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8050 | wakeStats.removeAt(iw); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 8051 | } else { |
| 8052 | active = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8053 | } |
| 8054 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8055 | mWakelockStats.cleanup(); |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 8056 | final ArrayMap<String, DualTimer> syncStats = mSyncStats.getMap(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8057 | for (int is=syncStats.size()-1; is>=0; is--) { |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 8058 | DualTimer timer = syncStats.valueAt(is); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 8059 | if (timer.reset(false)) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8060 | syncStats.removeAt(is); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 8061 | timer.detach(); |
| 8062 | } else { |
| 8063 | active = true; |
| 8064 | } |
| 8065 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8066 | mSyncStats.cleanup(); |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 8067 | final ArrayMap<String, DualTimer> jobStats = mJobStats.getMap(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8068 | for (int ij=jobStats.size()-1; ij>=0; ij--) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 8069 | DualTimer timer = jobStats.valueAt(ij); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 8070 | if (timer.reset(false)) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8071 | jobStats.removeAt(ij); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 8072 | timer.detach(); |
| 8073 | } else { |
| 8074 | active = true; |
| 8075 | } |
| 8076 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8077 | mJobStats.cleanup(); |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 8078 | mJobCompletions.clear(); |
Amith Yamasani | 977e11f | 2018-02-16 11:29:54 -0800 | [diff] [blame] | 8079 | |
| 8080 | mJobsDeferredEventCount.reset(false); |
| 8081 | mJobsDeferredCount.reset(false); |
| 8082 | mJobsFreshnessTimeMs.reset(false); |
| 8083 | for (int ij = 0; ij < JOB_FRESHNESS_BUCKETS.length; ij++) { |
| 8084 | if (mJobsFreshnessBuckets[ij] != null) { |
| 8085 | mJobsFreshnessBuckets[ij].reset(false); |
| 8086 | } |
| 8087 | } |
| 8088 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 8089 | for (int ise=mSensorStats.size()-1; ise>=0; ise--) { |
| 8090 | Sensor s = mSensorStats.valueAt(ise); |
| 8091 | if (s.reset()) { |
| 8092 | mSensorStats.removeAt(ise); |
| 8093 | } else { |
| 8094 | active = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8095 | } |
| 8096 | } |
Amith Yamasani | 977e11f | 2018-02-16 11:29:54 -0800 | [diff] [blame] | 8097 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 8098 | for (int ip=mProcessStats.size()-1; ip>=0; ip--) { |
| 8099 | Proc proc = mProcessStats.valueAt(ip); |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 8100 | proc.detach(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8101 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 8102 | mProcessStats.clear(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 8103 | if (mPids.size() > 0) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 8104 | for (int i=mPids.size()-1; i>=0; i--) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 8105 | Pid pid = mPids.valueAt(i); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 8106 | if (pid.mWakeNesting > 0) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 8107 | active = true; |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 8108 | } else { |
| 8109 | mPids.removeAt(i); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 8110 | } |
| 8111 | } |
| 8112 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8113 | if (mPackageStats.size() > 0) { |
| 8114 | Iterator<Map.Entry<String, Pkg>> it = mPackageStats.entrySet().iterator(); |
| 8115 | while (it.hasNext()) { |
| 8116 | Map.Entry<String, Pkg> pkgEntry = it.next(); |
| 8117 | Pkg p = pkgEntry.getValue(); |
| 8118 | p.detach(); |
| 8119 | if (p.mServiceStats.size() > 0) { |
| 8120 | Iterator<Map.Entry<String, Pkg.Serv>> it2 |
| 8121 | = p.mServiceStats.entrySet().iterator(); |
| 8122 | while (it2.hasNext()) { |
| 8123 | Map.Entry<String, Pkg.Serv> servEntry = it2.next(); |
| 8124 | servEntry.getValue().detach(); |
| 8125 | } |
| 8126 | } |
| 8127 | } |
| 8128 | mPackageStats.clear(); |
| 8129 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8130 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 8131 | mLastStepUserTime = mLastStepSystemTime = 0; |
| 8132 | mCurStepUserTime = mCurStepSystemTime = 0; |
| 8133 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8134 | if (!active) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 8135 | if (mWifiRunningTimer != null) { |
| 8136 | mWifiRunningTimer.detach(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8137 | } |
| 8138 | if (mFullWifiLockTimer != null) { |
| 8139 | mFullWifiLockTimer.detach(); |
| 8140 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 8141 | if (mWifiScanTimer != null) { |
| 8142 | mWifiScanTimer.detach(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8143 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 8144 | for (int i = 0; i < NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 8145 | if (mWifiBatchedScanTimer[i] != null) { |
| 8146 | mWifiBatchedScanTimer[i].detach(); |
| 8147 | } |
| 8148 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8149 | if (mWifiMulticastTimer != null) { |
| 8150 | mWifiMulticastTimer.detach(); |
| 8151 | } |
| 8152 | if (mAudioTurnedOnTimer != null) { |
| 8153 | mAudioTurnedOnTimer.detach(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 8154 | mAudioTurnedOnTimer = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8155 | } |
| 8156 | if (mVideoTurnedOnTimer != null) { |
| 8157 | mVideoTurnedOnTimer.detach(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 8158 | mVideoTurnedOnTimer = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8159 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 8160 | if (mFlashlightTurnedOnTimer != null) { |
| 8161 | mFlashlightTurnedOnTimer.detach(); |
| 8162 | mFlashlightTurnedOnTimer = null; |
| 8163 | } |
| 8164 | if (mCameraTurnedOnTimer != null) { |
| 8165 | mCameraTurnedOnTimer.detach(); |
| 8166 | mCameraTurnedOnTimer = null; |
| 8167 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 8168 | if (mForegroundActivityTimer != null) { |
| 8169 | mForegroundActivityTimer.detach(); |
| 8170 | mForegroundActivityTimer = null; |
| 8171 | } |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 8172 | if (mForegroundServiceTimer != null) { |
| 8173 | mForegroundServiceTimer.detach(); |
| 8174 | mForegroundServiceTimer = null; |
| 8175 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 8176 | if (mAggregatedPartialWakelockTimer != null) { |
| 8177 | mAggregatedPartialWakelockTimer.detach(); |
| 8178 | mAggregatedPartialWakelockTimer = null; |
| 8179 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 8180 | if (mBluetoothScanTimer != null) { |
| 8181 | mBluetoothScanTimer.detach(); |
| 8182 | mBluetoothScanTimer = null; |
| 8183 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 8184 | if (mBluetoothUnoptimizedScanTimer != null) { |
| 8185 | mBluetoothUnoptimizedScanTimer.detach(); |
| 8186 | mBluetoothUnoptimizedScanTimer = null; |
| 8187 | } |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 8188 | if (mBluetoothScanResultCounter != null) { |
| 8189 | mBluetoothScanResultCounter.detach(); |
| 8190 | mBluetoothScanResultCounter = null; |
| 8191 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 8192 | if (mBluetoothScanResultBgCounter != null) { |
| 8193 | mBluetoothScanResultBgCounter.detach(); |
| 8194 | mBluetoothScanResultBgCounter = null; |
| 8195 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8196 | if (mUserActivityCounters != null) { |
| 8197 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
| 8198 | mUserActivityCounters[i].detach(); |
| 8199 | } |
| 8200 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 8201 | if (mNetworkByteActivityCounters != null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 8202 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 8203 | mNetworkByteActivityCounters[i].detach(); |
| 8204 | mNetworkPacketActivityCounters[i].detach(); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 8205 | } |
| 8206 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8207 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8208 | if (mWifiControllerActivity != null) { |
| 8209 | mWifiControllerActivity.detach(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8210 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8211 | |
| 8212 | if (mBluetoothControllerActivity != null) { |
| 8213 | mBluetoothControllerActivity.detach(); |
| 8214 | } |
| 8215 | |
| 8216 | if (mModemControllerActivity != null) { |
| 8217 | mModemControllerActivity.detach(); |
| 8218 | } |
| 8219 | |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 8220 | mPids.clear(); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 8221 | |
| 8222 | mUserCpuTime.detach(); |
| 8223 | mSystemCpuTime.detach(); |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 8224 | |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 8225 | if (mCpuClusterSpeedTimesUs != null) { |
| 8226 | for (LongSamplingCounter[] cpuSpeeds : mCpuClusterSpeedTimesUs) { |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 8227 | if (cpuSpeeds != null) { |
| 8228 | for (LongSamplingCounter c : cpuSpeeds) { |
| 8229 | if (c != null) { |
| 8230 | c.detach(); |
| 8231 | } |
| 8232 | } |
| 8233 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 8234 | } |
| 8235 | } |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 8236 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 8237 | if (mCpuFreqTimeMs != null) { |
| 8238 | mCpuFreqTimeMs.detach(); |
| 8239 | } |
| 8240 | if (mScreenOffCpuFreqTimeMs != null) { |
| 8241 | mScreenOffCpuFreqTimeMs.detach(); |
| 8242 | } |
Mike Ma | 3d422c3 | 2017-10-25 11:08:57 -0700 | [diff] [blame] | 8243 | mCpuActiveTimeMs.detach(); |
| 8244 | mCpuClusterTimesMs.detach(); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 8245 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 8246 | if (mProcStateTimeMs != null) { |
| 8247 | for (LongSamplingCounterArray counters : mProcStateTimeMs) { |
| 8248 | if (counters != null) { |
| 8249 | counters.detach(); |
| 8250 | } |
| 8251 | } |
| 8252 | } |
| 8253 | if (mProcStateScreenOffTimeMs != null) { |
| 8254 | for (LongSamplingCounterArray counters : mProcStateScreenOffTimeMs) { |
| 8255 | if (counters != null) { |
| 8256 | counters.detach(); |
| 8257 | } |
| 8258 | } |
| 8259 | } |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 8260 | detachLongCounterIfNotNull(mMobileRadioApWakeupCount); |
| 8261 | detachLongCounterIfNotNull(mWifiRadioApWakeupCount); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8262 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8263 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8264 | return !active; |
| 8265 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8266 | |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 8267 | void writeJobCompletionsToParcelLocked(Parcel out) { |
| 8268 | int NJC = mJobCompletions.size(); |
| 8269 | out.writeInt(NJC); |
| 8270 | for (int ijc=0; ijc<NJC; ijc++) { |
| 8271 | out.writeString(mJobCompletions.keyAt(ijc)); |
| 8272 | SparseIntArray types = mJobCompletions.valueAt(ijc); |
| 8273 | int NT = types.size(); |
| 8274 | out.writeInt(NT); |
| 8275 | for (int it=0; it<NT; it++) { |
| 8276 | out.writeInt(types.keyAt(it)); |
| 8277 | out.writeInt(types.valueAt(it)); |
| 8278 | } |
| 8279 | } |
| 8280 | } |
| 8281 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 8282 | void writeToParcelLocked(Parcel out, long uptimeUs, long elapsedRealtimeUs) { |
| 8283 | mOnBatteryBackgroundTimeBase.writeToParcel(out, uptimeUs, elapsedRealtimeUs); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 8284 | mOnBatteryScreenOffBackgroundTimeBase.writeToParcel(out, uptimeUs, elapsedRealtimeUs); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 8285 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8286 | final ArrayMap<String, Wakelock> wakeStats = mWakelockStats.getMap(); |
| 8287 | int NW = wakeStats.size(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 8288 | out.writeInt(NW); |
| 8289 | for (int iw=0; iw<NW; iw++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8290 | out.writeString(wakeStats.keyAt(iw)); |
| 8291 | Uid.Wakelock wakelock = wakeStats.valueAt(iw); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8292 | wakelock.writeToParcelLocked(out, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8293 | } |
| 8294 | |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 8295 | final ArrayMap<String, DualTimer> syncStats = mSyncStats.getMap(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8296 | int NS = syncStats.size(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 8297 | out.writeInt(NS); |
| 8298 | for (int is=0; is<NS; is++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8299 | out.writeString(syncStats.keyAt(is)); |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 8300 | DualTimer timer = syncStats.valueAt(is); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 8301 | Timer.writeTimerToParcel(out, timer, elapsedRealtimeUs); |
| 8302 | } |
| 8303 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 8304 | final ArrayMap<String, DualTimer> jobStats = mJobStats.getMap(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8305 | int NJ = jobStats.size(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 8306 | out.writeInt(NJ); |
| 8307 | for (int ij=0; ij<NJ; ij++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8308 | out.writeString(jobStats.keyAt(ij)); |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 8309 | DualTimer timer = jobStats.valueAt(ij); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 8310 | Timer.writeTimerToParcel(out, timer, elapsedRealtimeUs); |
| 8311 | } |
| 8312 | |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 8313 | writeJobCompletionsToParcelLocked(out); |
| 8314 | |
Amith Yamasani | 977e11f | 2018-02-16 11:29:54 -0800 | [diff] [blame] | 8315 | mJobsDeferredEventCount.writeToParcel(out); |
| 8316 | mJobsDeferredCount.writeToParcel(out); |
| 8317 | mJobsFreshnessTimeMs.writeToParcel(out); |
| 8318 | for (int i = 0; i < JOB_FRESHNESS_BUCKETS.length; i++) { |
| 8319 | Counter.writeCounterToParcel(out, mJobsFreshnessBuckets[i]); |
| 8320 | } |
| 8321 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 8322 | int NSE = mSensorStats.size(); |
| 8323 | out.writeInt(NSE); |
| 8324 | for (int ise=0; ise<NSE; ise++) { |
| 8325 | out.writeInt(mSensorStats.keyAt(ise)); |
| 8326 | Uid.Sensor sensor = mSensorStats.valueAt(ise); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8327 | sensor.writeToParcelLocked(out, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8328 | } |
| 8329 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 8330 | int NP = mProcessStats.size(); |
| 8331 | out.writeInt(NP); |
| 8332 | for (int ip=0; ip<NP; ip++) { |
| 8333 | out.writeString(mProcessStats.keyAt(ip)); |
| 8334 | Uid.Proc proc = mProcessStats.valueAt(ip); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8335 | proc.writeToParcelLocked(out); |
| 8336 | } |
| 8337 | |
| 8338 | out.writeInt(mPackageStats.size()); |
| 8339 | for (Map.Entry<String, Uid.Pkg> pkgEntry : mPackageStats.entrySet()) { |
| 8340 | out.writeString(pkgEntry.getKey()); |
| 8341 | Uid.Pkg pkg = pkgEntry.getValue(); |
| 8342 | pkg.writeToParcelLocked(out); |
| 8343 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8344 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 8345 | if (mWifiRunningTimer != null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8346 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8347 | mWifiRunningTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 8348 | } else { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8349 | out.writeInt(0); |
| 8350 | } |
| 8351 | if (mFullWifiLockTimer != null) { |
| 8352 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8353 | mFullWifiLockTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8354 | } else { |
| 8355 | out.writeInt(0); |
| 8356 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 8357 | if (mWifiScanTimer != null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8358 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8359 | mWifiScanTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8360 | } else { |
| 8361 | out.writeInt(0); |
| 8362 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 8363 | for (int i = 0; i < NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 8364 | if (mWifiBatchedScanTimer[i] != null) { |
| 8365 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8366 | mWifiBatchedScanTimer[i].writeToParcel(out, elapsedRealtimeUs); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 8367 | } else { |
| 8368 | out.writeInt(0); |
| 8369 | } |
| 8370 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8371 | if (mWifiMulticastTimer != null) { |
| 8372 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8373 | mWifiMulticastTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8374 | } else { |
| 8375 | out.writeInt(0); |
| 8376 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8377 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8378 | if (mAudioTurnedOnTimer != null) { |
| 8379 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8380 | mAudioTurnedOnTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8381 | } else { |
| 8382 | out.writeInt(0); |
| 8383 | } |
| 8384 | if (mVideoTurnedOnTimer != null) { |
| 8385 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8386 | mVideoTurnedOnTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8387 | } else { |
| 8388 | out.writeInt(0); |
| 8389 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 8390 | if (mFlashlightTurnedOnTimer != null) { |
| 8391 | out.writeInt(1); |
| 8392 | mFlashlightTurnedOnTimer.writeToParcel(out, elapsedRealtimeUs); |
| 8393 | } else { |
| 8394 | out.writeInt(0); |
| 8395 | } |
| 8396 | if (mCameraTurnedOnTimer != null) { |
| 8397 | out.writeInt(1); |
| 8398 | mCameraTurnedOnTimer.writeToParcel(out, elapsedRealtimeUs); |
| 8399 | } else { |
| 8400 | out.writeInt(0); |
| 8401 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 8402 | if (mForegroundActivityTimer != null) { |
| 8403 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8404 | mForegroundActivityTimer.writeToParcel(out, elapsedRealtimeUs); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 8405 | } else { |
| 8406 | out.writeInt(0); |
| 8407 | } |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 8408 | if (mForegroundServiceTimer != null) { |
| 8409 | out.writeInt(1); |
| 8410 | mForegroundServiceTimer.writeToParcel(out, elapsedRealtimeUs); |
| 8411 | } else { |
| 8412 | out.writeInt(0); |
| 8413 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 8414 | if (mAggregatedPartialWakelockTimer != null) { |
| 8415 | out.writeInt(1); |
| 8416 | mAggregatedPartialWakelockTimer.writeToParcel(out, elapsedRealtimeUs); |
| 8417 | } else { |
| 8418 | out.writeInt(0); |
| 8419 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 8420 | if (mBluetoothScanTimer != null) { |
| 8421 | out.writeInt(1); |
| 8422 | mBluetoothScanTimer.writeToParcel(out, elapsedRealtimeUs); |
| 8423 | } else { |
| 8424 | out.writeInt(0); |
| 8425 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 8426 | if (mBluetoothUnoptimizedScanTimer != null) { |
| 8427 | out.writeInt(1); |
| 8428 | mBluetoothUnoptimizedScanTimer.writeToParcel(out, elapsedRealtimeUs); |
| 8429 | } else { |
| 8430 | out.writeInt(0); |
| 8431 | } |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 8432 | if (mBluetoothScanResultCounter != null) { |
| 8433 | out.writeInt(1); |
| 8434 | mBluetoothScanResultCounter.writeToParcel(out); |
| 8435 | } else { |
| 8436 | out.writeInt(0); |
| 8437 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 8438 | if (mBluetoothScanResultBgCounter != null) { |
| 8439 | out.writeInt(1); |
| 8440 | mBluetoothScanResultBgCounter.writeToParcel(out); |
| 8441 | } else { |
| 8442 | out.writeInt(0); |
| 8443 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 8444 | for (int i = 0; i < NUM_PROCESS_STATE; i++) { |
| 8445 | if (mProcessStateTimer[i] != null) { |
| 8446 | out.writeInt(1); |
| 8447 | mProcessStateTimer[i].writeToParcel(out, elapsedRealtimeUs); |
| 8448 | } else { |
| 8449 | out.writeInt(0); |
| 8450 | } |
| 8451 | } |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 8452 | if (mVibratorOnTimer != null) { |
| 8453 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8454 | mVibratorOnTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 8455 | } else { |
| 8456 | out.writeInt(0); |
| 8457 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8458 | if (mUserActivityCounters != null) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 8459 | out.writeInt(1); |
| 8460 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
| 8461 | mUserActivityCounters[i].writeToParcel(out); |
| 8462 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8463 | } else { |
| 8464 | out.writeInt(0); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 8465 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 8466 | if (mNetworkByteActivityCounters != null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 8467 | out.writeInt(1); |
| 8468 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 8469 | mNetworkByteActivityCounters[i].writeToParcel(out); |
| 8470 | mNetworkPacketActivityCounters[i].writeToParcel(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 8471 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 8472 | mMobileRadioActiveTime.writeToParcel(out); |
| 8473 | mMobileRadioActiveCount.writeToParcel(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 8474 | } else { |
| 8475 | out.writeInt(0); |
| 8476 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8477 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8478 | if (mWifiControllerActivity != null) { |
| 8479 | out.writeInt(1); |
| 8480 | mWifiControllerActivity.writeToParcel(out, 0); |
| 8481 | } else { |
| 8482 | out.writeInt(0); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8483 | } |
| 8484 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8485 | if (mBluetoothControllerActivity != null) { |
| 8486 | out.writeInt(1); |
| 8487 | mBluetoothControllerActivity.writeToParcel(out, 0); |
| 8488 | } else { |
| 8489 | out.writeInt(0); |
| 8490 | } |
| 8491 | |
| 8492 | if (mModemControllerActivity != null) { |
| 8493 | out.writeInt(1); |
| 8494 | mModemControllerActivity.writeToParcel(out, 0); |
| 8495 | } else { |
| 8496 | out.writeInt(0); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8497 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 8498 | |
| 8499 | mUserCpuTime.writeToParcel(out); |
| 8500 | mSystemCpuTime.writeToParcel(out); |
| 8501 | |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 8502 | if (mCpuClusterSpeedTimesUs != null) { |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 8503 | out.writeInt(1); |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 8504 | out.writeInt(mCpuClusterSpeedTimesUs.length); |
| 8505 | for (LongSamplingCounter[] cpuSpeeds : mCpuClusterSpeedTimesUs) { |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 8506 | if (cpuSpeeds != null) { |
| 8507 | out.writeInt(1); |
| 8508 | out.writeInt(cpuSpeeds.length); |
| 8509 | for (LongSamplingCounter c : cpuSpeeds) { |
| 8510 | if (c != null) { |
| 8511 | out.writeInt(1); |
| 8512 | c.writeToParcel(out); |
| 8513 | } else { |
| 8514 | out.writeInt(0); |
| 8515 | } |
| 8516 | } |
| 8517 | } else { |
| 8518 | out.writeInt(0); |
| 8519 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 8520 | } |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 8521 | } else { |
| 8522 | out.writeInt(0); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 8523 | } |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 8524 | |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 8525 | LongSamplingCounterArray.writeToParcel(out, mCpuFreqTimeMs); |
| 8526 | LongSamplingCounterArray.writeToParcel(out, mScreenOffCpuFreqTimeMs); |
Mike Ma | 3d422c3 | 2017-10-25 11:08:57 -0700 | [diff] [blame] | 8527 | |
| 8528 | mCpuActiveTimeMs.writeToParcel(out); |
| 8529 | mCpuClusterTimesMs.writeToParcel(out); |
| 8530 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 8531 | if (mProcStateTimeMs != null) { |
| 8532 | out.writeInt(mProcStateTimeMs.length); |
| 8533 | for (LongSamplingCounterArray counters : mProcStateTimeMs) { |
| 8534 | LongSamplingCounterArray.writeToParcel(out, counters); |
| 8535 | } |
| 8536 | } else { |
| 8537 | out.writeInt(0); |
| 8538 | } |
| 8539 | if (mProcStateScreenOffTimeMs != null) { |
| 8540 | out.writeInt(mProcStateScreenOffTimeMs.length); |
| 8541 | for (LongSamplingCounterArray counters : mProcStateScreenOffTimeMs) { |
| 8542 | LongSamplingCounterArray.writeToParcel(out, counters); |
| 8543 | } |
| 8544 | } else { |
| 8545 | out.writeInt(0); |
| 8546 | } |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 8547 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 8548 | if (mMobileRadioApWakeupCount != null) { |
| 8549 | out.writeInt(1); |
| 8550 | mMobileRadioApWakeupCount.writeToParcel(out); |
| 8551 | } else { |
| 8552 | out.writeInt(0); |
| 8553 | } |
| 8554 | |
| 8555 | if (mWifiRadioApWakeupCount != null) { |
| 8556 | out.writeInt(1); |
| 8557 | mWifiRadioApWakeupCount.writeToParcel(out); |
| 8558 | } else { |
| 8559 | out.writeInt(0); |
| 8560 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8561 | } |
| 8562 | |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 8563 | void readJobCompletionsFromParcelLocked(Parcel in) { |
| 8564 | int numJobCompletions = in.readInt(); |
| 8565 | mJobCompletions.clear(); |
| 8566 | for (int j = 0; j < numJobCompletions; j++) { |
| 8567 | String jobName = in.readString(); |
| 8568 | int numTypes = in.readInt(); |
| 8569 | if (numTypes > 0) { |
| 8570 | SparseIntArray types = new SparseIntArray(); |
| 8571 | for (int k = 0; k < numTypes; k++) { |
| 8572 | int type = in.readInt(); |
| 8573 | int count = in.readInt(); |
| 8574 | types.put(type, count); |
| 8575 | } |
| 8576 | mJobCompletions.put(jobName, types); |
| 8577 | } |
| 8578 | } |
| 8579 | } |
| 8580 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8581 | void readFromParcelLocked(TimeBase timeBase, TimeBase screenOffTimeBase, Parcel in) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 8582 | mOnBatteryBackgroundTimeBase.readFromParcel(in); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 8583 | mOnBatteryScreenOffBackgroundTimeBase.readFromParcel(in); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 8584 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8585 | int numWakelocks = in.readInt(); |
| 8586 | mWakelockStats.clear(); |
| 8587 | for (int j = 0; j < numWakelocks; j++) { |
| 8588 | String wakelockName = in.readString(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8589 | Uid.Wakelock wakelock = new Wakelock(mBsi, this); |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 8590 | wakelock.readFromParcelLocked( |
| 8591 | timeBase, screenOffTimeBase, mOnBatteryScreenOffBackgroundTimeBase, in); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8592 | mWakelockStats.add(wakelockName, wakelock); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8593 | } |
| 8594 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 8595 | int numSyncs = in.readInt(); |
| 8596 | mSyncStats.clear(); |
| 8597 | for (int j = 0; j < numSyncs; j++) { |
| 8598 | String syncName = in.readString(); |
| 8599 | if (in.readInt() != 0) { |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 8600 | mSyncStats.add(syncName, new DualTimer(mBsi.mClocks, Uid.this, SYNC, null, |
| 8601 | mBsi.mOnBatteryTimeBase, mOnBatteryBackgroundTimeBase, in)); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 8602 | } |
| 8603 | } |
| 8604 | |
| 8605 | int numJobs = in.readInt(); |
| 8606 | mJobStats.clear(); |
| 8607 | for (int j = 0; j < numJobs; j++) { |
| 8608 | String jobName = in.readString(); |
| 8609 | if (in.readInt() != 0) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 8610 | mJobStats.add(jobName, new DualTimer(mBsi.mClocks, Uid.this, JOB, null, |
| 8611 | mBsi.mOnBatteryTimeBase, mOnBatteryBackgroundTimeBase, in)); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 8612 | } |
| 8613 | } |
| 8614 | |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 8615 | readJobCompletionsFromParcelLocked(in); |
| 8616 | |
Amith Yamasani | 977e11f | 2018-02-16 11:29:54 -0800 | [diff] [blame] | 8617 | mJobsDeferredEventCount = new Counter(mBsi.mOnBatteryTimeBase, in); |
| 8618 | mJobsDeferredCount = new Counter(mBsi.mOnBatteryTimeBase, in); |
| 8619 | mJobsFreshnessTimeMs = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
| 8620 | for (int i = 0; i < JOB_FRESHNESS_BUCKETS.length; i++) { |
| 8621 | mJobsFreshnessBuckets[i] = Counter.readCounterFromParcel(mBsi.mOnBatteryTimeBase, |
| 8622 | in); |
| 8623 | } |
| 8624 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8625 | int numSensors = in.readInt(); |
| 8626 | mSensorStats.clear(); |
| 8627 | for (int k = 0; k < numSensors; k++) { |
| 8628 | int sensorNumber = in.readInt(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8629 | Uid.Sensor sensor = new Sensor(mBsi, this, sensorNumber); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 8630 | sensor.readFromParcelLocked(mBsi.mOnBatteryTimeBase, mOnBatteryBackgroundTimeBase, |
| 8631 | in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8632 | mSensorStats.put(sensorNumber, sensor); |
| 8633 | } |
| 8634 | |
| 8635 | int numProcs = in.readInt(); |
| 8636 | mProcessStats.clear(); |
| 8637 | for (int k = 0; k < numProcs; k++) { |
| 8638 | String processName = in.readString(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8639 | Uid.Proc proc = new Proc(mBsi, processName); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8640 | proc.readFromParcelLocked(in); |
| 8641 | mProcessStats.put(processName, proc); |
| 8642 | } |
| 8643 | |
| 8644 | int numPkgs = in.readInt(); |
| 8645 | mPackageStats.clear(); |
| 8646 | for (int l = 0; l < numPkgs; l++) { |
| 8647 | String packageName = in.readString(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8648 | Uid.Pkg pkg = new Pkg(mBsi); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8649 | pkg.readFromParcelLocked(in); |
| 8650 | mPackageStats.put(packageName, pkg); |
| 8651 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8652 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 8653 | mWifiRunning = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8654 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8655 | mWifiRunningTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, WIFI_RUNNING, |
| 8656 | mBsi.mWifiRunningTimers, mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 8657 | } else { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 8658 | mWifiRunningTimer = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8659 | } |
| 8660 | mFullWifiLockOut = false; |
| 8661 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8662 | mFullWifiLockTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, FULL_WIFI_LOCK, |
| 8663 | mBsi.mFullWifiLockTimers, mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8664 | } else { |
| 8665 | mFullWifiLockTimer = null; |
| 8666 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 8667 | mWifiScanStarted = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8668 | if (in.readInt() != 0) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 8669 | mWifiScanTimer = new DualTimer(mBsi.mClocks, Uid.this, WIFI_SCAN, |
| 8670 | mBsi.mWifiScanTimers, mBsi.mOnBatteryTimeBase, mOnBatteryBackgroundTimeBase, |
| 8671 | in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8672 | } else { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 8673 | mWifiScanTimer = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8674 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 8675 | mWifiBatchedScanBinStarted = NO_BATCHED_SCAN_STARTED; |
| 8676 | for (int i = 0; i < NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 8677 | if (in.readInt() != 0) { |
| 8678 | makeWifiBatchedScanBin(i, in); |
| 8679 | } else { |
| 8680 | mWifiBatchedScanTimer[i] = null; |
| 8681 | } |
| 8682 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8683 | mWifiMulticastEnabled = false; |
| 8684 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8685 | mWifiMulticastTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, WIFI_MULTICAST_ENABLED, |
| 8686 | mBsi.mWifiMulticastTimers, mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8687 | } else { |
| 8688 | mWifiMulticastTimer = null; |
| 8689 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8690 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8691 | mAudioTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, AUDIO_TURNED_ON, |
| 8692 | mBsi.mAudioTurnedOnTimers, mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8693 | } else { |
| 8694 | mAudioTurnedOnTimer = null; |
| 8695 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8696 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8697 | mVideoTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, VIDEO_TURNED_ON, |
| 8698 | mBsi.mVideoTurnedOnTimers, mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8699 | } else { |
| 8700 | mVideoTurnedOnTimer = null; |
| 8701 | } |
| 8702 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8703 | mFlashlightTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, |
| 8704 | FLASHLIGHT_TURNED_ON, mBsi.mFlashlightTurnedOnTimers, mBsi.mOnBatteryTimeBase, in); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 8705 | } else { |
| 8706 | mFlashlightTurnedOnTimer = null; |
| 8707 | } |
| 8708 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8709 | mCameraTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, CAMERA_TURNED_ON, |
| 8710 | mBsi.mCameraTurnedOnTimers, mBsi.mOnBatteryTimeBase, in); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 8711 | } else { |
| 8712 | mCameraTurnedOnTimer = null; |
| 8713 | } |
| 8714 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8715 | mForegroundActivityTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, |
| 8716 | FOREGROUND_ACTIVITY, null, mBsi.mOnBatteryTimeBase, in); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 8717 | } else { |
| 8718 | mForegroundActivityTimer = null; |
| 8719 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 8720 | if (in.readInt() != 0) { |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 8721 | mForegroundServiceTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, |
| 8722 | FOREGROUND_SERVICE, null, mBsi.mOnBatteryTimeBase, in); |
| 8723 | } else { |
| 8724 | mForegroundServiceTimer = null; |
| 8725 | } |
| 8726 | if (in.readInt() != 0) { |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 8727 | mAggregatedPartialWakelockTimer = new DualTimer(mBsi.mClocks, this, |
| 8728 | AGGREGATED_WAKE_TYPE_PARTIAL, null, |
| 8729 | mBsi.mOnBatteryScreenOffTimeBase, mOnBatteryScreenOffBackgroundTimeBase, |
| 8730 | in); |
| 8731 | } else { |
| 8732 | mAggregatedPartialWakelockTimer = null; |
| 8733 | } |
| 8734 | if (in.readInt() != 0) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 8735 | mBluetoothScanTimer = new DualTimer(mBsi.mClocks, Uid.this, BLUETOOTH_SCAN_ON, |
| 8736 | mBsi.mBluetoothScanOnTimers, mBsi.mOnBatteryTimeBase, |
| 8737 | mOnBatteryBackgroundTimeBase, in); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 8738 | } else { |
| 8739 | mBluetoothScanTimer = null; |
| 8740 | } |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 8741 | if (in.readInt() != 0) { |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 8742 | mBluetoothUnoptimizedScanTimer = new DualTimer(mBsi.mClocks, Uid.this, |
| 8743 | BLUETOOTH_UNOPTIMIZED_SCAN_ON, null, |
| 8744 | mBsi.mOnBatteryTimeBase, mOnBatteryBackgroundTimeBase, in); |
| 8745 | } else { |
| 8746 | mBluetoothUnoptimizedScanTimer = null; |
| 8747 | } |
| 8748 | if (in.readInt() != 0) { |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 8749 | mBluetoothScanResultCounter = new Counter(mBsi.mOnBatteryTimeBase, in); |
| 8750 | } else { |
| 8751 | mBluetoothScanResultCounter = null; |
| 8752 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 8753 | if (in.readInt() != 0) { |
| 8754 | mBluetoothScanResultBgCounter = new Counter(mOnBatteryBackgroundTimeBase, in); |
| 8755 | } else { |
| 8756 | mBluetoothScanResultBgCounter = null; |
| 8757 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 8758 | mProcessState = ActivityManager.PROCESS_STATE_NONEXISTENT; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 8759 | for (int i = 0; i < NUM_PROCESS_STATE; i++) { |
| 8760 | if (in.readInt() != 0) { |
| 8761 | makeProcessState(i, in); |
| 8762 | } else { |
| 8763 | mProcessStateTimer[i] = null; |
| 8764 | } |
| 8765 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 8766 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8767 | mVibratorOnTimer = new BatchTimer(mBsi.mClocks, Uid.this, VIBRATOR_ON, |
| 8768 | mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 8769 | } else { |
| 8770 | mVibratorOnTimer = null; |
| 8771 | } |
| 8772 | if (in.readInt() != 0) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 8773 | mUserActivityCounters = new Counter[NUM_USER_ACTIVITY_TYPES]; |
| 8774 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8775 | mUserActivityCounters[i] = new Counter(mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 8776 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8777 | } else { |
| 8778 | mUserActivityCounters = null; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 8779 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 8780 | if (in.readInt() != 0) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 8781 | mNetworkByteActivityCounters = new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
| 8782 | mNetworkPacketActivityCounters |
| 8783 | = new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 8784 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8785 | mNetworkByteActivityCounters[i] |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8786 | = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8787 | mNetworkPacketActivityCounters[i] |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8788 | = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 8789 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8790 | mMobileRadioActiveTime = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
| 8791 | mMobileRadioActiveCount = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 8792 | } else { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 8793 | mNetworkByteActivityCounters = null; |
| 8794 | mNetworkPacketActivityCounters = null; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 8795 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8796 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8797 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8798 | mWifiControllerActivity = new ControllerActivityCounterImpl(mBsi.mOnBatteryTimeBase, |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8799 | NUM_WIFI_TX_LEVELS, in); |
| 8800 | } else { |
| 8801 | mWifiControllerActivity = null; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8802 | } |
| 8803 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8804 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8805 | mBluetoothControllerActivity = new ControllerActivityCounterImpl(mBsi.mOnBatteryTimeBase, |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8806 | NUM_BT_TX_LEVELS, in); |
| 8807 | } else { |
| 8808 | mBluetoothControllerActivity = null; |
| 8809 | } |
| 8810 | |
| 8811 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8812 | mModemControllerActivity = new ControllerActivityCounterImpl(mBsi.mOnBatteryTimeBase, |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8813 | ModemActivityInfo.TX_POWER_LEVELS, in); |
| 8814 | } else { |
| 8815 | mModemControllerActivity = null; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8816 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 8817 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8818 | mUserCpuTime = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
| 8819 | mSystemCpuTime = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 8820 | |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 8821 | if (in.readInt() != 0) { |
| 8822 | int numCpuClusters = in.readInt(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8823 | if (mBsi.mPowerProfile != null && mBsi.mPowerProfile.getNumCpuClusters() != numCpuClusters) { |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 8824 | throw new ParcelFormatException("Incompatible number of cpu clusters"); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 8825 | } |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 8826 | |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 8827 | mCpuClusterSpeedTimesUs = new LongSamplingCounter[numCpuClusters][]; |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 8828 | for (int cluster = 0; cluster < numCpuClusters; cluster++) { |
| 8829 | if (in.readInt() != 0) { |
| 8830 | int numSpeeds = in.readInt(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8831 | if (mBsi.mPowerProfile != null && |
| 8832 | mBsi.mPowerProfile.getNumSpeedStepsInCpuCluster(cluster) != numSpeeds) { |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 8833 | throw new ParcelFormatException("Incompatible number of cpu speeds"); |
| 8834 | } |
| 8835 | |
| 8836 | final LongSamplingCounter[] cpuSpeeds = new LongSamplingCounter[numSpeeds]; |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 8837 | mCpuClusterSpeedTimesUs[cluster] = cpuSpeeds; |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 8838 | for (int speed = 0; speed < numSpeeds; speed++) { |
| 8839 | if (in.readInt() != 0) { |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 8840 | cpuSpeeds[speed] = new LongSamplingCounter( |
| 8841 | mBsi.mOnBatteryTimeBase, in); |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 8842 | } |
| 8843 | } |
Adam Lesinski | a57a540 | 2015-09-28 10:21:33 -0700 | [diff] [blame] | 8844 | } else { |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 8845 | mCpuClusterSpeedTimesUs[cluster] = null; |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 8846 | } |
| 8847 | } |
| 8848 | } else { |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 8849 | mCpuClusterSpeedTimesUs = null; |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 8850 | } |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 8851 | |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 8852 | mCpuFreqTimeMs = LongSamplingCounterArray.readFromParcel(in, mBsi.mOnBatteryTimeBase); |
| 8853 | mScreenOffCpuFreqTimeMs = LongSamplingCounterArray.readFromParcel( |
| 8854 | in, mBsi.mOnBatteryScreenOffTimeBase); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 8855 | |
Mike Ma | 3d422c3 | 2017-10-25 11:08:57 -0700 | [diff] [blame] | 8856 | mCpuActiveTimeMs = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
| 8857 | mCpuClusterTimesMs = new LongSamplingCounterArray(mBsi.mOnBatteryTimeBase, in); |
| 8858 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 8859 | int length = in.readInt(); |
| 8860 | if (length == NUM_PROCESS_STATE) { |
| 8861 | mProcStateTimeMs = new LongSamplingCounterArray[length]; |
| 8862 | for (int procState = 0; procState < length; ++procState) { |
| 8863 | mProcStateTimeMs[procState] = LongSamplingCounterArray.readFromParcel( |
| 8864 | in, mBsi.mOnBatteryTimeBase); |
| 8865 | } |
| 8866 | } else { |
| 8867 | mProcStateTimeMs = null; |
| 8868 | } |
| 8869 | length = in.readInt(); |
| 8870 | if (length == NUM_PROCESS_STATE) { |
| 8871 | mProcStateScreenOffTimeMs = new LongSamplingCounterArray[length]; |
| 8872 | for (int procState = 0; procState < length; ++procState) { |
| 8873 | mProcStateScreenOffTimeMs[procState] = LongSamplingCounterArray.readFromParcel( |
| 8874 | in, mBsi.mOnBatteryScreenOffTimeBase); |
| 8875 | } |
| 8876 | } else { |
| 8877 | mProcStateScreenOffTimeMs = null; |
| 8878 | } |
| 8879 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 8880 | if (in.readInt() != 0) { |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 8881 | mMobileRadioApWakeupCount = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
| 8882 | } else { |
| 8883 | mMobileRadioApWakeupCount = null; |
| 8884 | } |
| 8885 | |
| 8886 | if (in.readInt() != 0) { |
| 8887 | mWifiRadioApWakeupCount = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
| 8888 | } else { |
| 8889 | mWifiRadioApWakeupCount = null; |
| 8890 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8891 | } |
| 8892 | |
Amith Yamasani | 977e11f | 2018-02-16 11:29:54 -0800 | [diff] [blame] | 8893 | public void noteJobsDeferredLocked(int numDeferred, long sinceLast) { |
| 8894 | mJobsDeferredEventCount.addAtomic(1); |
| 8895 | mJobsDeferredCount.addAtomic(numDeferred); |
| 8896 | if (sinceLast != 0) { |
| 8897 | // Add the total time, which can be divided by the event count to get an average |
| 8898 | mJobsFreshnessTimeMs.addCountLocked(sinceLast); |
| 8899 | // Also keep track of how many times there were in these different buckets. |
| 8900 | for (int i = 0; i < JOB_FRESHNESS_BUCKETS.length; i++) { |
| 8901 | if (sinceLast < JOB_FRESHNESS_BUCKETS[i]) { |
| 8902 | if (mJobsFreshnessBuckets[i] == null) { |
| 8903 | mJobsFreshnessBuckets[i] = new Counter( |
| 8904 | mBsi.mOnBatteryTimeBase); |
| 8905 | } |
| 8906 | mJobsFreshnessBuckets[i].addAtomic(1); |
| 8907 | break; |
| 8908 | } |
| 8909 | } |
| 8910 | } |
| 8911 | } |
| 8912 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8913 | /** |
| 8914 | * The statistics associated with a particular wake lock. |
| 8915 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8916 | public static class Wakelock extends BatteryStats.Uid.Wakelock { |
| 8917 | /** |
| 8918 | * BatteryStatsImpl that we are associated with. |
| 8919 | */ |
| 8920 | protected BatteryStatsImpl mBsi; |
| 8921 | |
| 8922 | /** |
| 8923 | * BatteryStatsImpl that we are associated with. |
| 8924 | */ |
| 8925 | protected Uid mUid; |
| 8926 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8927 | /** |
| 8928 | * How long (in ms) this uid has been keeping the device partially awake. |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 8929 | * 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] | 8930 | */ |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 8931 | DualTimer mTimerPartial; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8932 | |
| 8933 | /** |
| 8934 | * How long (in ms) this uid has been keeping the device fully awake. |
| 8935 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 8936 | StopwatchTimer mTimerFull; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8937 | |
| 8938 | /** |
| 8939 | * How long (in ms) this uid has had a window keeping the device awake. |
| 8940 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 8941 | StopwatchTimer mTimerWindow; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8942 | |
| 8943 | /** |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 8944 | * How long (in ms) this uid has had a draw wake lock. |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 8945 | */ |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 8946 | StopwatchTimer mTimerDraw; |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 8947 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8948 | public Wakelock(BatteryStatsImpl bsi, Uid uid) { |
| 8949 | mBsi = bsi; |
| 8950 | mUid = uid; |
| 8951 | } |
| 8952 | |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 8953 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8954 | * Reads a possibly null Timer from a Parcel. The timer is associated with the |
| 8955 | * proper timer pool from the given BatteryStatsImpl object. |
| 8956 | * |
| 8957 | * @param in the Parcel to be read from. |
| 8958 | * return a new Timer, or null. |
| 8959 | */ |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 8960 | private StopwatchTimer readStopwatchTimerFromParcel(int type, |
| 8961 | ArrayList<StopwatchTimer> pool, TimeBase timeBase, Parcel in) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8962 | if (in.readInt() == 0) { |
| 8963 | return null; |
| 8964 | } |
| 8965 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8966 | 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] | 8967 | } |
| 8968 | |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 8969 | /** |
| 8970 | * Reads a possibly null Timer from a Parcel. The timer is associated with the |
| 8971 | * proper timer pool from the given BatteryStatsImpl object. |
| 8972 | * |
| 8973 | * @param in the Parcel to be read from. |
| 8974 | * return a new Timer, or null. |
| 8975 | */ |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 8976 | private DualTimer readDualTimerFromParcel(int type, ArrayList<StopwatchTimer> pool, |
| 8977 | TimeBase timeBase, TimeBase bgTimeBase, Parcel in) { |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 8978 | if (in.readInt() == 0) { |
| 8979 | return null; |
| 8980 | } |
| 8981 | |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 8982 | return new DualTimer(mBsi.mClocks, mUid, type, pool, timeBase, bgTimeBase, in); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 8983 | } |
| 8984 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8985 | boolean reset() { |
| 8986 | boolean wlactive = false; |
| 8987 | if (mTimerFull != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8988 | wlactive |= !mTimerFull.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8989 | } |
| 8990 | if (mTimerPartial != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8991 | wlactive |= !mTimerPartial.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8992 | } |
| 8993 | if (mTimerWindow != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8994 | wlactive |= !mTimerWindow.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8995 | } |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 8996 | if (mTimerDraw != null) { |
| 8997 | wlactive |= !mTimerDraw.reset(false); |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 8998 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8999 | if (!wlactive) { |
| 9000 | if (mTimerFull != null) { |
| 9001 | mTimerFull.detach(); |
| 9002 | mTimerFull = null; |
| 9003 | } |
| 9004 | if (mTimerPartial != null) { |
| 9005 | mTimerPartial.detach(); |
| 9006 | mTimerPartial = null; |
| 9007 | } |
| 9008 | if (mTimerWindow != null) { |
| 9009 | mTimerWindow.detach(); |
| 9010 | mTimerWindow = null; |
| 9011 | } |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 9012 | if (mTimerDraw != null) { |
| 9013 | mTimerDraw.detach(); |
| 9014 | mTimerDraw = null; |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 9015 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9016 | } |
| 9017 | return !wlactive; |
| 9018 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9019 | |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 9020 | void readFromParcelLocked(TimeBase timeBase, TimeBase screenOffTimeBase, |
| 9021 | TimeBase screenOffBgTimeBase, Parcel in) { |
| 9022 | mTimerPartial = readDualTimerFromParcel(WAKE_TYPE_PARTIAL, |
| 9023 | mBsi.mPartialTimers, screenOffTimeBase, screenOffBgTimeBase, in); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 9024 | mTimerFull = readStopwatchTimerFromParcel(WAKE_TYPE_FULL, |
| 9025 | mBsi.mFullTimers, timeBase, in); |
| 9026 | mTimerWindow = readStopwatchTimerFromParcel(WAKE_TYPE_WINDOW, |
| 9027 | mBsi.mWindowTimers, timeBase, in); |
| 9028 | mTimerDraw = readStopwatchTimerFromParcel(WAKE_TYPE_DRAW, |
| 9029 | mBsi.mDrawTimers, timeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9030 | } |
| 9031 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9032 | void writeToParcelLocked(Parcel out, long elapsedRealtimeUs) { |
| 9033 | Timer.writeTimerToParcel(out, mTimerPartial, elapsedRealtimeUs); |
| 9034 | Timer.writeTimerToParcel(out, mTimerFull, elapsedRealtimeUs); |
| 9035 | Timer.writeTimerToParcel(out, mTimerWindow, elapsedRealtimeUs); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 9036 | Timer.writeTimerToParcel(out, mTimerDraw, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9037 | } |
| 9038 | |
| 9039 | @Override |
| 9040 | public Timer getWakeTime(int type) { |
| 9041 | switch (type) { |
| 9042 | case WAKE_TYPE_FULL: return mTimerFull; |
| 9043 | case WAKE_TYPE_PARTIAL: return mTimerPartial; |
| 9044 | case WAKE_TYPE_WINDOW: return mTimerWindow; |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 9045 | case WAKE_TYPE_DRAW: return mTimerDraw; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9046 | default: throw new IllegalArgumentException("type = " + type); |
| 9047 | } |
| 9048 | } |
| 9049 | } |
| 9050 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9051 | public static class Sensor extends BatteryStats.Uid.Sensor { |
| 9052 | /** |
| 9053 | * BatteryStatsImpl that we are associated with. |
| 9054 | */ |
| 9055 | protected BatteryStatsImpl mBsi; |
| 9056 | |
| 9057 | /** |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 9058 | * Uid that we are associated with. |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9059 | */ |
| 9060 | protected Uid mUid; |
| 9061 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9062 | final int mHandle; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 9063 | DualTimer mTimer; |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 9064 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9065 | public Sensor(BatteryStatsImpl bsi, Uid uid, int handle) { |
| 9066 | mBsi = bsi; |
| 9067 | mUid = uid; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9068 | mHandle = handle; |
| 9069 | } |
| 9070 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 9071 | private DualTimer readTimersFromParcel( |
| 9072 | TimeBase timeBase, TimeBase bgTimeBase, Parcel in) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9073 | if (in.readInt() == 0) { |
| 9074 | return null; |
| 9075 | } |
| 9076 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9077 | ArrayList<StopwatchTimer> pool = mBsi.mSensorTimers.get(mHandle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9078 | if (pool == null) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 9079 | pool = new ArrayList<StopwatchTimer>(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9080 | mBsi.mSensorTimers.put(mHandle, pool); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9081 | } |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 9082 | return new DualTimer(mBsi.mClocks, mUid, 0, pool, timeBase, bgTimeBase, in); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 9083 | } |
| 9084 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9085 | boolean reset() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9086 | if (mTimer.reset(true)) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9087 | mTimer = null; |
| 9088 | return true; |
| 9089 | } |
| 9090 | return false; |
| 9091 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9092 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 9093 | void readFromParcelLocked(TimeBase timeBase, TimeBase bgTimeBase, Parcel in) { |
| 9094 | mTimer = readTimersFromParcel(timeBase, bgTimeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9095 | } |
| 9096 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9097 | void writeToParcelLocked(Parcel out, long elapsedRealtimeUs) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 9098 | Timer.writeTimerToParcel(out, mTimer, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9099 | } |
| 9100 | |
| 9101 | @Override |
| 9102 | public Timer getSensorTime() { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 9103 | return mTimer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9104 | } |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 9105 | |
| 9106 | @Override |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 9107 | public Timer getSensorBackgroundTime() { |
| 9108 | if (mTimer == null) { |
| 9109 | return null; |
| 9110 | } |
| 9111 | return mTimer.getSubTimer(); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 9112 | } |
| 9113 | |
| 9114 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9115 | public int getHandle() { |
| 9116 | return mHandle; |
| 9117 | } |
| 9118 | } |
| 9119 | |
| 9120 | /** |
| 9121 | * The statistics associated with a particular process. |
| 9122 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9123 | public static class Proc extends BatteryStats.Uid.Proc implements TimeBaseObs { |
| 9124 | /** |
| 9125 | * BatteryStatsImpl that we are associated with. |
| 9126 | */ |
| 9127 | protected BatteryStatsImpl mBsi; |
| 9128 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9129 | /** |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 9130 | * The name of this process. |
| 9131 | */ |
| 9132 | final String mName; |
| 9133 | |
| 9134 | /** |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 9135 | * Remains true until removed from the stats. |
| 9136 | */ |
| 9137 | boolean mActive = true; |
| 9138 | |
| 9139 | /** |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 9140 | * Total time (in ms) spent executing in user code. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9141 | */ |
| 9142 | long mUserTime; |
| 9143 | |
| 9144 | /** |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 9145 | * Total time (in ms) spent executing in kernel code. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9146 | */ |
| 9147 | long mSystemTime; |
| 9148 | |
| 9149 | /** |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 9150 | * Amount of time (in ms) the process was running in the foreground. |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 9151 | */ |
| 9152 | long mForegroundTime; |
| 9153 | |
| 9154 | /** |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 9155 | * Number of times the process has been started. |
| 9156 | */ |
| 9157 | int mStarts; |
| 9158 | |
| 9159 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9160 | * Number of times the process has crashed. |
| 9161 | */ |
| 9162 | int mNumCrashes; |
| 9163 | |
| 9164 | /** |
| 9165 | * Number of times the process has had an ANR. |
| 9166 | */ |
| 9167 | int mNumAnrs; |
| 9168 | |
| 9169 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9170 | * The amount of user time loaded from a previous save. |
| 9171 | */ |
| 9172 | long mLoadedUserTime; |
| 9173 | |
| 9174 | /** |
| 9175 | * The amount of system time loaded from a previous save. |
| 9176 | */ |
| 9177 | long mLoadedSystemTime; |
| 9178 | |
| 9179 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 9180 | * The amount of foreground time loaded from a previous save. |
| 9181 | */ |
| 9182 | long mLoadedForegroundTime; |
| 9183 | |
| 9184 | /** |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 9185 | * The number of times the process has started from a previous save. |
| 9186 | */ |
| 9187 | int mLoadedStarts; |
| 9188 | |
| 9189 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9190 | * 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] | 9191 | */ |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9192 | int mLoadedNumCrashes; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9193 | |
| 9194 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9195 | * 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] | 9196 | */ |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9197 | int mLoadedNumAnrs; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 9198 | |
| 9199 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9200 | * The amount of user time when last unplugged. |
| 9201 | */ |
| 9202 | long mUnpluggedUserTime; |
| 9203 | |
| 9204 | /** |
| 9205 | * The amount of system time when last unplugged. |
| 9206 | */ |
| 9207 | long mUnpluggedSystemTime; |
| 9208 | |
| 9209 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 9210 | * The amount of foreground time since unplugged. |
| 9211 | */ |
| 9212 | long mUnpluggedForegroundTime; |
| 9213 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 9214 | /** |
| 9215 | * The number of times the process has started before unplugged. |
| 9216 | */ |
| 9217 | int mUnpluggedStarts; |
| 9218 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 9219 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9220 | * Number of times the process has crashed before unplugged. |
| 9221 | */ |
| 9222 | int mUnpluggedNumCrashes; |
| 9223 | |
| 9224 | /** |
| 9225 | * Number of times the process has had an ANR before unplugged. |
| 9226 | */ |
| 9227 | int mUnpluggedNumAnrs; |
| 9228 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 9229 | ArrayList<ExcessivePower> mExcessivePower; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 9230 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9231 | public Proc(BatteryStatsImpl bsi, String name) { |
| 9232 | mBsi = bsi; |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 9233 | mName = name; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9234 | mBsi.mOnBatteryTimeBase.add(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9235 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 9236 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9237 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9238 | mUnpluggedUserTime = mUserTime; |
| 9239 | mUnpluggedSystemTime = mSystemTime; |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 9240 | mUnpluggedForegroundTime = mForegroundTime; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 9241 | mUnpluggedStarts = mStarts; |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9242 | mUnpluggedNumCrashes = mNumCrashes; |
| 9243 | mUnpluggedNumAnrs = mNumAnrs; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9244 | } |
| 9245 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9246 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9247 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9248 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9249 | void detach() { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 9250 | mActive = false; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9251 | mBsi.mOnBatteryTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9252 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9253 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 9254 | public int countExcessivePowers() { |
| 9255 | return mExcessivePower != null ? mExcessivePower.size() : 0; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 9256 | } |
| 9257 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 9258 | public ExcessivePower getExcessivePower(int i) { |
| 9259 | if (mExcessivePower != null) { |
| 9260 | return mExcessivePower.get(i); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 9261 | } |
| 9262 | return null; |
| 9263 | } |
| 9264 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 9265 | public void addExcessiveCpu(long overTime, long usedTime) { |
| 9266 | if (mExcessivePower == null) { |
| 9267 | mExcessivePower = new ArrayList<ExcessivePower>(); |
| 9268 | } |
| 9269 | ExcessivePower ew = new ExcessivePower(); |
| 9270 | ew.type = ExcessivePower.TYPE_CPU; |
| 9271 | ew.overTime = overTime; |
| 9272 | ew.usedTime = usedTime; |
| 9273 | mExcessivePower.add(ew); |
| 9274 | } |
| 9275 | |
| 9276 | void writeExcessivePowerToParcelLocked(Parcel out) { |
| 9277 | if (mExcessivePower == null) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 9278 | out.writeInt(0); |
| 9279 | return; |
| 9280 | } |
| 9281 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 9282 | final int N = mExcessivePower.size(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 9283 | out.writeInt(N); |
| 9284 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 9285 | ExcessivePower ew = mExcessivePower.get(i); |
| 9286 | out.writeInt(ew.type); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 9287 | out.writeLong(ew.overTime); |
| 9288 | out.writeLong(ew.usedTime); |
| 9289 | } |
| 9290 | } |
| 9291 | |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 9292 | void readExcessivePowerFromParcelLocked(Parcel in) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 9293 | final int N = in.readInt(); |
| 9294 | if (N == 0) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 9295 | mExcessivePower = null; |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 9296 | return; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 9297 | } |
| 9298 | |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 9299 | if (N > 10000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 9300 | throw new ParcelFormatException( |
| 9301 | "File corrupt: too many excessive power entries " + N); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 9302 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9303 | |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 9304 | mExcessivePower = new ArrayList<>(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 9305 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 9306 | ExcessivePower ew = new ExcessivePower(); |
| 9307 | ew.type = in.readInt(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 9308 | ew.overTime = in.readLong(); |
| 9309 | ew.usedTime = in.readLong(); |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 9310 | mExcessivePower.add(ew); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 9311 | } |
| 9312 | } |
| 9313 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9314 | void writeToParcelLocked(Parcel out) { |
| 9315 | out.writeLong(mUserTime); |
| 9316 | out.writeLong(mSystemTime); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 9317 | out.writeLong(mForegroundTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9318 | out.writeInt(mStarts); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9319 | out.writeInt(mNumCrashes); |
| 9320 | out.writeInt(mNumAnrs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9321 | out.writeLong(mLoadedUserTime); |
| 9322 | out.writeLong(mLoadedSystemTime); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 9323 | out.writeLong(mLoadedForegroundTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9324 | out.writeInt(mLoadedStarts); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9325 | out.writeInt(mLoadedNumCrashes); |
| 9326 | out.writeInt(mLoadedNumAnrs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9327 | out.writeLong(mUnpluggedUserTime); |
| 9328 | out.writeLong(mUnpluggedSystemTime); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 9329 | out.writeLong(mUnpluggedForegroundTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9330 | out.writeInt(mUnpluggedStarts); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9331 | out.writeInt(mUnpluggedNumCrashes); |
| 9332 | out.writeInt(mUnpluggedNumAnrs); |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 9333 | writeExcessivePowerToParcelLocked(out); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9334 | } |
| 9335 | |
| 9336 | void readFromParcelLocked(Parcel in) { |
| 9337 | mUserTime = in.readLong(); |
| 9338 | mSystemTime = in.readLong(); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 9339 | mForegroundTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9340 | mStarts = in.readInt(); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9341 | mNumCrashes = in.readInt(); |
| 9342 | mNumAnrs = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9343 | mLoadedUserTime = in.readLong(); |
| 9344 | mLoadedSystemTime = in.readLong(); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 9345 | mLoadedForegroundTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9346 | mLoadedStarts = in.readInt(); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9347 | mLoadedNumCrashes = in.readInt(); |
| 9348 | mLoadedNumAnrs = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9349 | mUnpluggedUserTime = in.readLong(); |
| 9350 | mUnpluggedSystemTime = in.readLong(); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 9351 | mUnpluggedForegroundTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9352 | mUnpluggedStarts = in.readInt(); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9353 | mUnpluggedNumCrashes = in.readInt(); |
| 9354 | mUnpluggedNumAnrs = in.readInt(); |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 9355 | readExcessivePowerFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9356 | } |
| 9357 | |
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 | |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 9369 | public void addForegroundTimeLocked(long ttime) { |
| 9370 | mForegroundTime += ttime; |
| 9371 | } |
| 9372 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9373 | public void incStartsLocked() { |
| 9374 | mStarts++; |
| 9375 | } |
| 9376 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9377 | public void incNumCrashesLocked() { |
| 9378 | mNumCrashes++; |
| 9379 | } |
| 9380 | |
| 9381 | public void incNumAnrsLocked() { |
| 9382 | mNumAnrs++; |
| 9383 | } |
| 9384 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9385 | @Override |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 9386 | public boolean isActive() { |
| 9387 | return mActive; |
| 9388 | } |
| 9389 | |
| 9390 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9391 | public long getUserTime(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 9392 | long val = mUserTime; |
| 9393 | if (which == STATS_CURRENT) { |
| 9394 | val -= mLoadedUserTime; |
| 9395 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 9396 | val -= mUnpluggedUserTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9397 | } |
| 9398 | return val; |
| 9399 | } |
| 9400 | |
| 9401 | @Override |
| 9402 | public long getSystemTime(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 9403 | long val = mSystemTime; |
| 9404 | if (which == STATS_CURRENT) { |
| 9405 | val -= mLoadedSystemTime; |
| 9406 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 9407 | val -= mUnpluggedSystemTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9408 | } |
| 9409 | return val; |
| 9410 | } |
| 9411 | |
| 9412 | @Override |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 9413 | public long getForegroundTime(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 9414 | long val = mForegroundTime; |
| 9415 | if (which == STATS_CURRENT) { |
| 9416 | val -= mLoadedForegroundTime; |
| 9417 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 9418 | val -= mUnpluggedForegroundTime; |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 9419 | } |
| 9420 | return val; |
| 9421 | } |
| 9422 | |
| 9423 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9424 | public int getStarts(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 9425 | int val = mStarts; |
| 9426 | if (which == STATS_CURRENT) { |
| 9427 | val -= mLoadedStarts; |
| 9428 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 9429 | val -= mUnpluggedStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9430 | } |
| 9431 | return val; |
| 9432 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 9433 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9434 | @Override |
| 9435 | public int getNumCrashes(int which) { |
| 9436 | int val = mNumCrashes; |
| 9437 | if (which == STATS_CURRENT) { |
| 9438 | val -= mLoadedNumCrashes; |
| 9439 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 9440 | val -= mUnpluggedNumCrashes; |
| 9441 | } |
| 9442 | return val; |
| 9443 | } |
| 9444 | |
| 9445 | @Override |
| 9446 | public int getNumAnrs(int which) { |
| 9447 | int val = mNumAnrs; |
| 9448 | if (which == STATS_CURRENT) { |
| 9449 | val -= mLoadedNumAnrs; |
| 9450 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 9451 | val -= mUnpluggedNumAnrs; |
| 9452 | } |
| 9453 | return val; |
| 9454 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9455 | } |
| 9456 | |
| 9457 | /** |
| 9458 | * The statistics associated with a particular package. |
| 9459 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9460 | public static class Pkg extends BatteryStats.Uid.Pkg implements TimeBaseObs { |
| 9461 | /** |
| 9462 | * BatteryStatsImpl that we are associated with. |
| 9463 | */ |
| 9464 | protected BatteryStatsImpl mBsi; |
| 9465 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9466 | /** |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 9467 | * Number of times wakeup alarms have occurred for this app. |
Bookatz | 98d4d5c | 2017-08-01 19:07:54 -0700 | [diff] [blame] | 9468 | * On screen-off timebase starting in report v25. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9469 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 9470 | ArrayMap<String, Counter> mWakeupAlarms = new ArrayMap<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9471 | |
| 9472 | /** |
| 9473 | * The statics we have collected for this package's services. |
| 9474 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 9475 | final ArrayMap<String, Serv> mServiceStats = new ArrayMap<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9476 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9477 | public Pkg(BatteryStatsImpl bsi) { |
| 9478 | mBsi = bsi; |
| 9479 | mBsi.mOnBatteryScreenOffTimeBase.add(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9480 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9481 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9482 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9483 | } |
| 9484 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9485 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
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 | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9488 | void detach() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9489 | mBsi.mOnBatteryScreenOffTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9490 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9491 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9492 | void readFromParcelLocked(Parcel in) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 9493 | int numWA = in.readInt(); |
| 9494 | mWakeupAlarms.clear(); |
| 9495 | for (int i=0; i<numWA; i++) { |
| 9496 | String tag = in.readString(); |
Bookatz | 98d4d5c | 2017-08-01 19:07:54 -0700 | [diff] [blame] | 9497 | mWakeupAlarms.put(tag, new Counter(mBsi.mOnBatteryScreenOffTimeBase, in)); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 9498 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9499 | |
| 9500 | int numServs = in.readInt(); |
| 9501 | mServiceStats.clear(); |
| 9502 | for (int m = 0; m < numServs; m++) { |
| 9503 | String serviceName = in.readString(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9504 | Uid.Pkg.Serv serv = new Serv(mBsi); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9505 | mServiceStats.put(serviceName, serv); |
| 9506 | |
| 9507 | serv.readFromParcelLocked(in); |
| 9508 | } |
| 9509 | } |
| 9510 | |
| 9511 | void writeToParcelLocked(Parcel out) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 9512 | int numWA = mWakeupAlarms.size(); |
| 9513 | out.writeInt(numWA); |
| 9514 | for (int i=0; i<numWA; i++) { |
| 9515 | out.writeString(mWakeupAlarms.keyAt(i)); |
| 9516 | mWakeupAlarms.valueAt(i).writeToParcel(out); |
| 9517 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9518 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 9519 | final int NS = mServiceStats.size(); |
| 9520 | out.writeInt(NS); |
| 9521 | for (int i=0; i<NS; i++) { |
| 9522 | out.writeString(mServiceStats.keyAt(i)); |
| 9523 | Uid.Pkg.Serv serv = mServiceStats.valueAt(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9524 | serv.writeToParcelLocked(out); |
| 9525 | } |
| 9526 | } |
| 9527 | |
| 9528 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 9529 | public ArrayMap<String, ? extends BatteryStats.Counter> getWakeupAlarmStats() { |
| 9530 | return mWakeupAlarms; |
| 9531 | } |
| 9532 | |
| 9533 | public void noteWakeupAlarmLocked(String tag) { |
| 9534 | Counter c = mWakeupAlarms.get(tag); |
| 9535 | if (c == null) { |
Bookatz | 98d4d5c | 2017-08-01 19:07:54 -0700 | [diff] [blame] | 9536 | c = new Counter(mBsi.mOnBatteryScreenOffTimeBase); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 9537 | mWakeupAlarms.put(tag, c); |
| 9538 | } |
| 9539 | c.stepAtomic(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9540 | } |
| 9541 | |
| 9542 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 9543 | public ArrayMap<String, ? extends BatteryStats.Uid.Pkg.Serv> getServiceStats() { |
| 9544 | return mServiceStats; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9545 | } |
| 9546 | |
| 9547 | /** |
| 9548 | * The statistics associated with a particular service. |
| 9549 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9550 | public static class Serv extends BatteryStats.Uid.Pkg.Serv implements TimeBaseObs { |
| 9551 | /** |
| 9552 | * BatteryStatsImpl that we are associated with. |
| 9553 | */ |
| 9554 | protected BatteryStatsImpl mBsi; |
| 9555 | |
| 9556 | /** |
| 9557 | * The android package in which this service resides. |
| 9558 | */ |
| 9559 | protected Pkg mPkg; |
| 9560 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9561 | /** |
| 9562 | * Total time (ms in battery uptime) the service has been left started. |
| 9563 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9564 | protected long mStartTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9565 | |
| 9566 | /** |
| 9567 | * If service has been started and not yet stopped, this is |
| 9568 | * when it was started. |
| 9569 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9570 | protected long mRunningSince; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9571 | |
| 9572 | /** |
| 9573 | * True if we are currently running. |
| 9574 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9575 | protected boolean mRunning; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9576 | |
| 9577 | /** |
| 9578 | * Total number of times startService() has been called. |
| 9579 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9580 | protected int mStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9581 | |
| 9582 | /** |
| 9583 | * Total time (ms in battery uptime) the service has been left launched. |
| 9584 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9585 | protected long mLaunchedTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9586 | |
| 9587 | /** |
| 9588 | * If service has been launched and not yet exited, this is |
| 9589 | * when it was launched (ms in battery uptime). |
| 9590 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9591 | protected long mLaunchedSince; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9592 | |
| 9593 | /** |
| 9594 | * True if we are currently launched. |
| 9595 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9596 | protected boolean mLaunched; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9597 | |
| 9598 | /** |
| 9599 | * Total number times the service has been launched. |
| 9600 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9601 | protected int mLaunches; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9602 | |
| 9603 | /** |
| 9604 | * The amount of time spent started loaded from a previous save |
| 9605 | * (ms in battery uptime). |
| 9606 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9607 | protected long mLoadedStartTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9608 | |
| 9609 | /** |
| 9610 | * The number of starts loaded from a previous save. |
| 9611 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9612 | protected int mLoadedStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9613 | |
| 9614 | /** |
| 9615 | * The number of launches loaded from a previous save. |
| 9616 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9617 | protected int mLoadedLaunches; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9618 | |
| 9619 | /** |
| 9620 | * The amount of time spent started as of the last run (ms |
| 9621 | * in battery uptime). |
| 9622 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9623 | protected long mLastStartTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9624 | |
| 9625 | /** |
| 9626 | * The number of starts as of the last run. |
| 9627 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9628 | protected int mLastStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9629 | |
| 9630 | /** |
| 9631 | * The number of launches as of the last run. |
| 9632 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9633 | protected int mLastLaunches; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9634 | |
| 9635 | /** |
| 9636 | * The amount of time spent started when last unplugged (ms |
| 9637 | * in battery uptime). |
| 9638 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9639 | protected long mUnpluggedStartTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9640 | |
| 9641 | /** |
| 9642 | * The number of starts when last unplugged. |
| 9643 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9644 | protected int mUnpluggedStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9645 | |
| 9646 | /** |
| 9647 | * The number of launches when last unplugged. |
| 9648 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9649 | protected int mUnpluggedLaunches; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9650 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9651 | /** |
| 9652 | * Construct a Serv. Also adds it to the on-battery time base as a listener. |
| 9653 | */ |
| 9654 | public Serv(BatteryStatsImpl bsi) { |
| 9655 | mBsi = bsi; |
| 9656 | mBsi.mOnBatteryTimeBase.add(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9657 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9658 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9659 | public void onTimeStarted(long elapsedRealtime, long baseUptime, |
| 9660 | long baseRealtime) { |
| 9661 | mUnpluggedStartTime = getStartTimeToNowLocked(baseUptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9662 | mUnpluggedStarts = mStarts; |
| 9663 | mUnpluggedLaunches = mLaunches; |
| 9664 | } |
| 9665 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9666 | public void onTimeStopped(long elapsedRealtime, long baseUptime, |
| 9667 | long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9668 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9669 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9670 | /** |
| 9671 | * Remove this Serv as a listener from the time base. |
| 9672 | */ |
| 9673 | public void detach() { |
| 9674 | mBsi.mOnBatteryTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9675 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9676 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9677 | public void readFromParcelLocked(Parcel in) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9678 | mStartTime = in.readLong(); |
| 9679 | mRunningSince = in.readLong(); |
| 9680 | mRunning = in.readInt() != 0; |
| 9681 | mStarts = in.readInt(); |
| 9682 | mLaunchedTime = in.readLong(); |
| 9683 | mLaunchedSince = in.readLong(); |
| 9684 | mLaunched = in.readInt() != 0; |
| 9685 | mLaunches = in.readInt(); |
| 9686 | mLoadedStartTime = in.readLong(); |
| 9687 | mLoadedStarts = in.readInt(); |
| 9688 | mLoadedLaunches = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 9689 | mLastStartTime = 0; |
| 9690 | mLastStarts = 0; |
| 9691 | mLastLaunches = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9692 | mUnpluggedStartTime = in.readLong(); |
| 9693 | mUnpluggedStarts = in.readInt(); |
| 9694 | mUnpluggedLaunches = in.readInt(); |
| 9695 | } |
| 9696 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9697 | public void writeToParcelLocked(Parcel out) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9698 | out.writeLong(mStartTime); |
| 9699 | out.writeLong(mRunningSince); |
| 9700 | out.writeInt(mRunning ? 1 : 0); |
| 9701 | out.writeInt(mStarts); |
| 9702 | out.writeLong(mLaunchedTime); |
| 9703 | out.writeLong(mLaunchedSince); |
| 9704 | out.writeInt(mLaunched ? 1 : 0); |
| 9705 | out.writeInt(mLaunches); |
| 9706 | out.writeLong(mLoadedStartTime); |
| 9707 | out.writeInt(mLoadedStarts); |
| 9708 | out.writeInt(mLoadedLaunches); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9709 | out.writeLong(mUnpluggedStartTime); |
| 9710 | out.writeInt(mUnpluggedStarts); |
| 9711 | out.writeInt(mUnpluggedLaunches); |
| 9712 | } |
| 9713 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9714 | public long getLaunchTimeToNowLocked(long batteryUptime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9715 | if (!mLaunched) return mLaunchedTime; |
| 9716 | return mLaunchedTime + batteryUptime - mLaunchedSince; |
| 9717 | } |
| 9718 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9719 | public long getStartTimeToNowLocked(long batteryUptime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9720 | if (!mRunning) return mStartTime; |
| 9721 | return mStartTime + batteryUptime - mRunningSince; |
| 9722 | } |
| 9723 | |
| 9724 | public void startLaunchedLocked() { |
| 9725 | if (!mLaunched) { |
| 9726 | mLaunches++; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9727 | mLaunchedSince = mBsi.getBatteryUptimeLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9728 | mLaunched = true; |
| 9729 | } |
| 9730 | } |
| 9731 | |
| 9732 | public void stopLaunchedLocked() { |
| 9733 | if (mLaunched) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9734 | long time = mBsi.getBatteryUptimeLocked() - mLaunchedSince; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9735 | if (time > 0) { |
| 9736 | mLaunchedTime += time; |
| 9737 | } else { |
| 9738 | mLaunches--; |
| 9739 | } |
| 9740 | mLaunched = false; |
| 9741 | } |
| 9742 | } |
| 9743 | |
| 9744 | public void startRunningLocked() { |
| 9745 | if (!mRunning) { |
| 9746 | mStarts++; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9747 | mRunningSince = mBsi.getBatteryUptimeLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9748 | mRunning = true; |
| 9749 | } |
| 9750 | } |
| 9751 | |
| 9752 | public void stopRunningLocked() { |
| 9753 | if (mRunning) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9754 | long time = mBsi.getBatteryUptimeLocked() - mRunningSince; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9755 | if (time > 0) { |
| 9756 | mStartTime += time; |
| 9757 | } else { |
| 9758 | mStarts--; |
| 9759 | } |
| 9760 | mRunning = false; |
| 9761 | } |
| 9762 | } |
| 9763 | |
| 9764 | public BatteryStatsImpl getBatteryStats() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9765 | return mBsi; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9766 | } |
| 9767 | |
| 9768 | @Override |
| 9769 | public int getLaunches(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 9770 | int val = mLaunches; |
| 9771 | if (which == STATS_CURRENT) { |
| 9772 | val -= mLoadedLaunches; |
| 9773 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 9774 | val -= mUnpluggedLaunches; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9775 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9776 | return val; |
| 9777 | } |
| 9778 | |
| 9779 | @Override |
| 9780 | public long getStartTime(long now, int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 9781 | long val = getStartTimeToNowLocked(now); |
| 9782 | if (which == STATS_CURRENT) { |
| 9783 | val -= mLoadedStartTime; |
| 9784 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 9785 | val -= mUnpluggedStartTime; |
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 int getStarts(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 9792 | int val = mStarts; |
| 9793 | if (which == STATS_CURRENT) { |
| 9794 | val -= mLoadedStarts; |
| 9795 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 9796 | val -= mUnpluggedStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9797 | } |
| 9798 | |
| 9799 | return val; |
| 9800 | } |
| 9801 | } |
| 9802 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9803 | final Serv newServiceStatsLocked() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9804 | return new Serv(mBsi); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9805 | } |
| 9806 | } |
| 9807 | |
| 9808 | /** |
| 9809 | * Retrieve the statistics object for a particular process, creating |
| 9810 | * if needed. |
| 9811 | */ |
| 9812 | public Proc getProcessStatsLocked(String name) { |
| 9813 | Proc ps = mProcessStats.get(name); |
| 9814 | if (ps == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9815 | ps = new Proc(mBsi, name); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9816 | mProcessStats.put(name, ps); |
| 9817 | } |
| 9818 | |
| 9819 | return ps; |
| 9820 | } |
| 9821 | |
Andreas Gampe | 3f24e69 | 2018-02-05 13:24:28 -0800 | [diff] [blame] | 9822 | @GuardedBy("mBsi") |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 9823 | public void updateUidProcessStateLocked(int procState) { |
| 9824 | int uidRunningState; |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 9825 | // Make special note of Foreground Services |
| 9826 | final boolean userAwareService = |
| 9827 | (procState == ActivityManager.PROCESS_STATE_FOREGROUND_SERVICE); |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 9828 | uidRunningState = BatteryStats.mapToInternalProcessState(procState); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 9829 | |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 9830 | if (mProcessState == uidRunningState && userAwareService == mInForegroundService) { |
| 9831 | return; |
| 9832 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 9833 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 9834 | final long elapsedRealtimeMs = mBsi.mClocks.elapsedRealtime(); |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 9835 | if (mProcessState != uidRunningState) { |
| 9836 | final long uptimeMs = mBsi.mClocks.uptimeMillis(); |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 9837 | |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 9838 | if (mProcessState != ActivityManager.PROCESS_STATE_NONEXISTENT) { |
| 9839 | mProcessStateTimer[mProcessState].stopRunningLocked(elapsedRealtimeMs); |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 9840 | |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 9841 | if (mBsi.trackPerProcStateCpuTimes()) { |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 9842 | if (mBsi.mPendingUids.size() == 0) { |
Sudheer Shanka | e544d16 | 2017-12-28 17:06:20 -0800 | [diff] [blame] | 9843 | mBsi.mExternalSync.scheduleReadProcStateCpuTimes( |
| 9844 | mBsi.mOnBatteryTimeBase.isRunning(), |
Sudheer Shanka | c20379e | 2018-02-15 00:06:21 -0800 | [diff] [blame] | 9845 | mBsi.mOnBatteryScreenOffTimeBase.isRunning(), |
| 9846 | mBsi.mConstants.PROC_STATE_CPU_TIMES_READ_DELAY_MS); |
| 9847 | mBsi.mNumCpuTimeReads++; |
| 9848 | } else { |
| 9849 | mBsi.mNumBatchedCpuTimeReads++; |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 9850 | } |
| 9851 | if (mBsi.mPendingUids.indexOfKey(mUid) < 0 |
| 9852 | || ArrayUtils.contains(CRITICAL_PROC_STATES, mProcessState)) { |
| 9853 | mBsi.mPendingUids.put(mUid, mProcessState); |
| 9854 | } |
| 9855 | } else { |
| 9856 | mBsi.mPendingUids.clear(); |
| 9857 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 9858 | } |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 9859 | mProcessState = uidRunningState; |
| 9860 | if (uidRunningState != ActivityManager.PROCESS_STATE_NONEXISTENT) { |
| 9861 | if (mProcessStateTimer[uidRunningState] == null) { |
| 9862 | makeProcessState(uidRunningState, null); |
| 9863 | } |
| 9864 | mProcessStateTimer[uidRunningState].startRunningLocked(elapsedRealtimeMs); |
| 9865 | } |
| 9866 | |
| 9867 | updateOnBatteryBgTimeBase(uptimeMs * 1000, elapsedRealtimeMs * 1000); |
| 9868 | updateOnBatteryScreenOffBgTimeBase(uptimeMs * 1000, elapsedRealtimeMs * 1000); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 9869 | } |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 9870 | |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 9871 | if (userAwareService != mInForegroundService) { |
| 9872 | if (userAwareService) { |
| 9873 | noteForegroundServiceResumedLocked(elapsedRealtimeMs); |
| 9874 | } else { |
| 9875 | noteForegroundServicePausedLocked(elapsedRealtimeMs); |
| 9876 | } |
| 9877 | mInForegroundService = userAwareService; |
| 9878 | } |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 9879 | } |
| 9880 | |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 9881 | /** Whether to consider Uid to be in the background for background timebase purposes. */ |
| 9882 | public boolean isInBackground() { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 9883 | // Note that PROCESS_STATE_CACHED and ActivityManager.PROCESS_STATE_NONEXISTENT is |
| 9884 | // also considered to be 'background' for our purposes, because it's not foreground. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 9885 | return mProcessState >= PROCESS_STATE_BACKGROUND; |
| 9886 | } |
| 9887 | |
| 9888 | public boolean updateOnBatteryBgTimeBase(long uptimeUs, long realtimeUs) { |
| 9889 | boolean on = mBsi.mOnBatteryTimeBase.isRunning() && isInBackground(); |
| 9890 | return mOnBatteryBackgroundTimeBase.setRunning(on, uptimeUs, realtimeUs); |
| 9891 | } |
| 9892 | |
| 9893 | public boolean updateOnBatteryScreenOffBgTimeBase(long uptimeUs, long realtimeUs) { |
| 9894 | boolean on = mBsi.mOnBatteryScreenOffTimeBase.isRunning() && isInBackground(); |
| 9895 | return mOnBatteryScreenOffBackgroundTimeBase.setRunning(on, uptimeUs, realtimeUs); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 9896 | } |
| 9897 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 9898 | public SparseArray<? extends Pid> getPidStats() { |
| 9899 | return mPids; |
| 9900 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9901 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 9902 | public Pid getPidStatsLocked(int pid) { |
| 9903 | Pid p = mPids.get(pid); |
| 9904 | if (p == null) { |
| 9905 | p = new Pid(); |
| 9906 | mPids.put(pid, p); |
| 9907 | } |
| 9908 | return p; |
| 9909 | } |
| 9910 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9911 | /** |
| 9912 | * Retrieve the statistics object for a particular service, creating |
| 9913 | * if needed. |
| 9914 | */ |
| 9915 | public Pkg getPackageStatsLocked(String name) { |
| 9916 | Pkg ps = mPackageStats.get(name); |
| 9917 | if (ps == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9918 | ps = new Pkg(mBsi); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9919 | mPackageStats.put(name, ps); |
| 9920 | } |
| 9921 | |
| 9922 | return ps; |
| 9923 | } |
| 9924 | |
| 9925 | /** |
| 9926 | * Retrieve the statistics object for a particular service, creating |
| 9927 | * if needed. |
| 9928 | */ |
| 9929 | public Pkg.Serv getServiceStatsLocked(String pkg, String serv) { |
| 9930 | Pkg ps = getPackageStatsLocked(pkg); |
| 9931 | Pkg.Serv ss = ps.mServiceStats.get(serv); |
| 9932 | if (ss == null) { |
| 9933 | ss = ps.newServiceStatsLocked(); |
| 9934 | ps.mServiceStats.put(serv, ss); |
| 9935 | } |
| 9936 | |
| 9937 | return ss; |
| 9938 | } |
| 9939 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 9940 | public void readSyncSummaryFromParcelLocked(String name, Parcel in) { |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 9941 | DualTimer timer = mSyncStats.instantiateObject(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 9942 | timer.readSummaryFromParcelLocked(in); |
| 9943 | mSyncStats.add(name, timer); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 9944 | } |
| 9945 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 9946 | public void readJobSummaryFromParcelLocked(String name, Parcel in) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 9947 | DualTimer timer = mJobStats.instantiateObject(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 9948 | timer.readSummaryFromParcelLocked(in); |
| 9949 | mJobStats.add(name, timer); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 9950 | } |
| 9951 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 9952 | public void readWakeSummaryFromParcelLocked(String wlName, Parcel in) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9953 | Wakelock wl = new Wakelock(mBsi, this); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 9954 | mWakelockStats.add(wlName, wl); |
| 9955 | if (in.readInt() != 0) { |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 9956 | getWakelockTimerLocked(wl, WAKE_TYPE_FULL).readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9957 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 9958 | if (in.readInt() != 0) { |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 9959 | getWakelockTimerLocked(wl, WAKE_TYPE_PARTIAL).readSummaryFromParcelLocked(in); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 9960 | } |
| 9961 | if (in.readInt() != 0) { |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 9962 | getWakelockTimerLocked(wl, WAKE_TYPE_WINDOW).readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9963 | } |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 9964 | if (in.readInt() != 0) { |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 9965 | getWakelockTimerLocked(wl, WAKE_TYPE_DRAW).readSummaryFromParcelLocked(in); |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 9966 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9967 | } |
| 9968 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 9969 | public DualTimer getSensorTimerLocked(int sensor, boolean create) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9970 | Sensor se = mSensorStats.get(sensor); |
| 9971 | if (se == null) { |
| 9972 | if (!create) { |
| 9973 | return null; |
| 9974 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9975 | se = new Sensor(mBsi, this, sensor); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9976 | mSensorStats.put(sensor, se); |
| 9977 | } |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 9978 | DualTimer t = se.mTimer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9979 | if (t != null) { |
| 9980 | return t; |
| 9981 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9982 | ArrayList<StopwatchTimer> timers = mBsi.mSensorTimers.get(sensor); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9983 | if (timers == null) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 9984 | timers = new ArrayList<StopwatchTimer>(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9985 | mBsi.mSensorTimers.put(sensor, timers); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9986 | } |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 9987 | t = new DualTimer(mBsi.mClocks, this, BatteryStats.SENSOR, timers, |
| 9988 | mBsi.mOnBatteryTimeBase, mOnBatteryBackgroundTimeBase); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9989 | se.mTimer = t; |
| 9990 | return t; |
| 9991 | } |
| 9992 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 9993 | public void noteStartSyncLocked(String name, long elapsedRealtimeMs) { |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 9994 | DualTimer t = mSyncStats.startObject(name); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 9995 | if (t != null) { |
| 9996 | t.startRunningLocked(elapsedRealtimeMs); |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 9997 | StatsLog.write_non_chained(StatsLog.SYNC_STATE_CHANGED, getUid(), null, name, |
| 9998 | StatsLog.SYNC_STATE_CHANGED__STATE__ON); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 9999 | } |
| 10000 | } |
| 10001 | |
| 10002 | public void noteStopSyncLocked(String name, long elapsedRealtimeMs) { |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 10003 | DualTimer t = mSyncStats.stopObject(name); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 10004 | if (t != null) { |
| 10005 | t.stopRunningLocked(elapsedRealtimeMs); |
Bookatz | c1a050a | 2017-10-10 15:49:28 -0700 | [diff] [blame] | 10006 | if (!t.isRunningLocked()) { // only tell statsd if truly stopped |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 10007 | StatsLog.write_non_chained(StatsLog.SYNC_STATE_CHANGED, getUid(), null, name, |
| 10008 | StatsLog.SYNC_STATE_CHANGED__STATE__OFF); |
Bookatz | c1a050a | 2017-10-10 15:49:28 -0700 | [diff] [blame] | 10009 | } |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 10010 | } |
| 10011 | } |
| 10012 | |
| 10013 | public void noteStartJobLocked(String name, long elapsedRealtimeMs) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 10014 | DualTimer t = mJobStats.startObject(name); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 10015 | if (t != null) { |
| 10016 | t.startRunningLocked(elapsedRealtimeMs); |
Yangster-mac | 2f5daec | 2018-01-16 10:23:15 -0800 | [diff] [blame] | 10017 | StatsLog.write_non_chained(StatsLog.SCHEDULED_JOB_STATE_CHANGED, getUid(), null, |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 10018 | name, StatsLog.SCHEDULED_JOB_STATE_CHANGED__STATE__STARTED); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 10019 | } |
| 10020 | } |
| 10021 | |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 10022 | public void noteStopJobLocked(String name, long elapsedRealtimeMs, int stopReason) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 10023 | DualTimer t = mJobStats.stopObject(name); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 10024 | if (t != null) { |
| 10025 | t.stopRunningLocked(elapsedRealtimeMs); |
Bookatz | c1a050a | 2017-10-10 15:49:28 -0700 | [diff] [blame] | 10026 | if (!t.isRunningLocked()) { // only tell statsd if truly stopped |
Yangster-mac | 2f5daec | 2018-01-16 10:23:15 -0800 | [diff] [blame] | 10027 | StatsLog.write_non_chained(StatsLog.SCHEDULED_JOB_STATE_CHANGED, getUid(), null, |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 10028 | name, StatsLog.SCHEDULED_JOB_STATE_CHANGED__STATE__FINISHED); |
Bookatz | c1a050a | 2017-10-10 15:49:28 -0700 | [diff] [blame] | 10029 | } |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 10030 | } |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 10031 | if (mBsi.mOnBatteryTimeBase.isRunning()) { |
| 10032 | SparseIntArray types = mJobCompletions.get(name); |
| 10033 | if (types == null) { |
| 10034 | types = new SparseIntArray(); |
| 10035 | mJobCompletions.put(name, types); |
| 10036 | } |
| 10037 | int last = types.get(stopReason, 0); |
| 10038 | types.put(stopReason, last + 1); |
| 10039 | } |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 10040 | } |
| 10041 | |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 10042 | public StopwatchTimer getWakelockTimerLocked(Wakelock wl, int type) { |
| 10043 | if (wl == null) { |
| 10044 | return null; |
| 10045 | } |
| 10046 | switch (type) { |
| 10047 | case WAKE_TYPE_PARTIAL: { |
| 10048 | DualTimer t = wl.mTimerPartial; |
| 10049 | if (t == null) { |
| 10050 | t = new DualTimer(mBsi.mClocks, this, WAKE_TYPE_PARTIAL, |
| 10051 | mBsi.mPartialTimers, mBsi.mOnBatteryScreenOffTimeBase, |
| 10052 | mOnBatteryScreenOffBackgroundTimeBase); |
| 10053 | wl.mTimerPartial = t; |
| 10054 | } |
| 10055 | return t; |
| 10056 | } |
| 10057 | case WAKE_TYPE_FULL: { |
| 10058 | StopwatchTimer t = wl.mTimerFull; |
| 10059 | if (t == null) { |
| 10060 | t = new StopwatchTimer(mBsi.mClocks, this, WAKE_TYPE_FULL, |
| 10061 | mBsi.mFullTimers, mBsi.mOnBatteryTimeBase); |
| 10062 | wl.mTimerFull = t; |
| 10063 | } |
| 10064 | return t; |
| 10065 | } |
| 10066 | case WAKE_TYPE_WINDOW: { |
| 10067 | StopwatchTimer t = wl.mTimerWindow; |
| 10068 | if (t == null) { |
| 10069 | t = new StopwatchTimer(mBsi.mClocks, this, WAKE_TYPE_WINDOW, |
| 10070 | mBsi.mWindowTimers, mBsi.mOnBatteryTimeBase); |
| 10071 | wl.mTimerWindow = t; |
| 10072 | } |
| 10073 | return t; |
| 10074 | } |
| 10075 | case WAKE_TYPE_DRAW: { |
| 10076 | StopwatchTimer t = wl.mTimerDraw; |
| 10077 | if (t == null) { |
| 10078 | t = new StopwatchTimer(mBsi.mClocks, this, WAKE_TYPE_DRAW, |
| 10079 | mBsi.mDrawTimers, mBsi.mOnBatteryTimeBase); |
| 10080 | wl.mTimerDraw = t; |
| 10081 | } |
| 10082 | return t; |
| 10083 | } |
| 10084 | default: |
| 10085 | throw new IllegalArgumentException("type=" + type); |
| 10086 | } |
| 10087 | } |
| 10088 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10089 | public void noteStartWakeLocked(int pid, String name, int type, long elapsedRealtimeMs) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 10090 | Wakelock wl = mWakelockStats.startObject(name); |
| 10091 | if (wl != null) { |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 10092 | getWakelockTimerLocked(wl, type).startRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10093 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 10094 | if (type == WAKE_TYPE_PARTIAL) { |
| 10095 | createAggregatedPartialWakelockTimerLocked().startRunningLocked(elapsedRealtimeMs); |
| 10096 | if (pid >= 0) { |
| 10097 | Pid p = getPidStatsLocked(pid); |
| 10098 | if (p.mWakeNesting++ == 0) { |
| 10099 | p.mWakeStartMs = elapsedRealtimeMs; |
| 10100 | } |
Dianne Hackborn | b8071d79 | 2010-09-09 16:45:15 -0700 | [diff] [blame] | 10101 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 10102 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10103 | } |
| 10104 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10105 | public void noteStopWakeLocked(int pid, String name, int type, long elapsedRealtimeMs) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 10106 | Wakelock wl = mWakelockStats.stopObject(name); |
| 10107 | if (wl != null) { |
Bookatz | d674624 | 2017-10-24 18:39:35 -0700 | [diff] [blame] | 10108 | StopwatchTimer wlt = getWakelockTimerLocked(wl, type); |
| 10109 | wlt.stopRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10110 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 10111 | if (type == WAKE_TYPE_PARTIAL) { |
| 10112 | if (mAggregatedPartialWakelockTimer != null) { |
| 10113 | mAggregatedPartialWakelockTimer.stopRunningLocked(elapsedRealtimeMs); |
| 10114 | } |
| 10115 | if (pid >= 0) { |
| 10116 | Pid p = mPids.get(pid); |
| 10117 | if (p != null && p.mWakeNesting > 0) { |
| 10118 | if (p.mWakeNesting-- == 1) { |
| 10119 | p.mWakeSumMs += elapsedRealtimeMs - p.mWakeStartMs; |
| 10120 | p.mWakeStartMs = 0; |
| 10121 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 10122 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 10123 | } |
| 10124 | } |
| 10125 | } |
| 10126 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 10127 | public void reportExcessiveCpuLocked(String proc, long overTime, long usedTime) { |
| 10128 | Proc p = getProcessStatsLocked(proc); |
| 10129 | if (p != null) { |
| 10130 | p.addExcessiveCpu(overTime, usedTime); |
| 10131 | } |
| 10132 | } |
| 10133 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10134 | public void noteStartSensor(int sensor, long elapsedRealtimeMs) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 10135 | DualTimer t = getSensorTimerLocked(sensor, /* create= */ true); |
Amith Yamasani | 154d124 | 2017-02-16 10:01:48 -0800 | [diff] [blame] | 10136 | t.startRunningLocked(elapsedRealtimeMs); |
Narayan Kamath | 32684dd | 2018-01-08 17:32:51 +0000 | [diff] [blame] | 10137 | if (sensor != Sensor.GPS) { |
Yangster-mac | 2f5daec | 2018-01-16 10:23:15 -0800 | [diff] [blame] | 10138 | StatsLog.write_non_chained(StatsLog.SENSOR_STATE_CHANGED, getUid(), null, sensor, |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 10139 | StatsLog.SENSOR_STATE_CHANGED__STATE__ON); |
Bookatz | c1a050a | 2017-10-10 15:49:28 -0700 | [diff] [blame] | 10140 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10141 | } |
| 10142 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10143 | public void noteStopSensor(int sensor, long elapsedRealtimeMs) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10144 | // Don't create a timer if one doesn't already exist |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 10145 | DualTimer t = getSensorTimerLocked(sensor, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10146 | if (t != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10147 | t.stopRunningLocked(elapsedRealtimeMs); |
Narayan Kamath | 32684dd | 2018-01-08 17:32:51 +0000 | [diff] [blame] | 10148 | if (sensor != Sensor.GPS) { |
| 10149 | StatsLog.write_non_chained(StatsLog.SENSOR_STATE_CHANGED, getUid(), null, |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 10150 | sensor, StatsLog.SENSOR_STATE_CHANGED__STATE__OFF); |
Bookatz | c1a050a | 2017-10-10 15:49:28 -0700 | [diff] [blame] | 10151 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10152 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10153 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10154 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10155 | public void noteStartGps(long elapsedRealtimeMs) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 10156 | noteStartSensor(Sensor.GPS, elapsedRealtimeMs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10157 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10158 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10159 | public void noteStopGps(long elapsedRealtimeMs) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 10160 | noteStopSensor(Sensor.GPS, elapsedRealtimeMs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10161 | } |
| 10162 | |
| 10163 | public BatteryStatsImpl getBatteryStats() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10164 | return mBsi; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10165 | } |
| 10166 | } |
| 10167 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 10168 | public long[] getCpuFreqs() { |
| 10169 | return mCpuFreqs; |
| 10170 | } |
| 10171 | |
Suprabh Shukla | e6e723d | 2017-06-14 16:14:43 -0700 | [diff] [blame] | 10172 | public BatteryStatsImpl(File systemDir, Handler handler, PlatformIdleStateCallback cb, |
| 10173 | UserInfoProvider userInfoProvider) { |
| 10174 | this(new SystemClocks(), systemDir, handler, cb, userInfoProvider); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 10175 | } |
| 10176 | |
Suprabh Shukla | e6e723d | 2017-06-14 16:14:43 -0700 | [diff] [blame] | 10177 | private BatteryStatsImpl(Clocks clocks, File systemDir, Handler handler, |
| 10178 | PlatformIdleStateCallback cb, |
| 10179 | UserInfoProvider userInfoProvider) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10180 | init(clocks); |
| 10181 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 10182 | if (systemDir != null) { |
| 10183 | mFile = new JournaledFile(new File(systemDir, "batterystats.bin"), |
| 10184 | new File(systemDir, "batterystats.bin.tmp")); |
| 10185 | } else { |
| 10186 | mFile = null; |
| 10187 | } |
| 10188 | mCheckinFile = new AtomicFile(new File(systemDir, "batterystats-checkin.bin")); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10189 | mDailyFile = new AtomicFile(new File(systemDir, "batterystats-daily.xml")); |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 10190 | mHandler = new MyHandler(handler.getLooper()); |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 10191 | mConstants = new Constants(mHandler); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10192 | mStartCount++; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10193 | mScreenOnTimer = new StopwatchTimer(mClocks, null, -1, null, mOnBatteryTimeBase); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 10194 | mScreenDozeTimer = new StopwatchTimer(mClocks, null, -1, null, mOnBatteryTimeBase); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 10195 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10196 | mScreenBrightnessTimer[i] = new StopwatchTimer(mClocks, null, -100-i, null, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10197 | mOnBatteryTimeBase); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 10198 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10199 | mInteractiveTimer = new StopwatchTimer(mClocks, null, -10, null, mOnBatteryTimeBase); |
| 10200 | mPowerSaveModeEnabledTimer = new StopwatchTimer(mClocks, null, -2, null, |
| 10201 | mOnBatteryTimeBase); |
| 10202 | mDeviceIdleModeLightTimer = new StopwatchTimer(mClocks, null, -11, null, |
| 10203 | mOnBatteryTimeBase); |
| 10204 | mDeviceIdleModeFullTimer = new StopwatchTimer(mClocks, null, -14, null, mOnBatteryTimeBase); |
| 10205 | mDeviceLightIdlingTimer = new StopwatchTimer(mClocks, null, -15, null, mOnBatteryTimeBase); |
| 10206 | mDeviceIdlingTimer = new StopwatchTimer(mClocks, null, -12, null, mOnBatteryTimeBase); |
| 10207 | mPhoneOnTimer = new StopwatchTimer(mClocks, null, -3, null, mOnBatteryTimeBase); |
| 10208 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
| 10209 | mPhoneSignalStrengthsTimer[i] = new StopwatchTimer(mClocks, null, -200-i, null, |
| 10210 | mOnBatteryTimeBase); |
| 10211 | } |
| 10212 | mPhoneSignalScanningTimer = new StopwatchTimer(mClocks, null, -200+1, null, |
| 10213 | mOnBatteryTimeBase); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 10214 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10215 | mPhoneDataConnectionsTimer[i] = new StopwatchTimer(mClocks, null, -300-i, null, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10216 | mOnBatteryTimeBase); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 10217 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 10218 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10219 | mNetworkByteActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase); |
| 10220 | mNetworkPacketActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 10221 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 10222 | mWifiActivity = new ControllerActivityCounterImpl(mOnBatteryTimeBase, NUM_WIFI_TX_LEVELS); |
| 10223 | mBluetoothActivity = new ControllerActivityCounterImpl(mOnBatteryTimeBase, |
| 10224 | NUM_BT_TX_LEVELS); |
| 10225 | mModemActivity = new ControllerActivityCounterImpl(mOnBatteryTimeBase, |
| 10226 | ModemActivityInfo.TX_POWER_LEVELS); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10227 | mMobileRadioActiveTimer = new StopwatchTimer(mClocks, null, -400, null, mOnBatteryTimeBase); |
| 10228 | mMobileRadioActivePerAppTimer = new StopwatchTimer(mClocks, null, -401, null, |
| 10229 | mOnBatteryTimeBase); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10230 | mMobileRadioActiveAdjustedTime = new LongSamplingCounter(mOnBatteryTimeBase); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10231 | mMobileRadioActiveUnknownTime = new LongSamplingCounter(mOnBatteryTimeBase); |
| 10232 | mMobileRadioActiveUnknownCount = new LongSamplingCounter(mOnBatteryTimeBase); |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 10233 | mWifiMulticastWakelockTimer = new StopwatchTimer(mClocks, null, |
| 10234 | WIFI_AGGREGATE_MULTICAST_ENABLED, null, mOnBatteryTimeBase); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10235 | mWifiOnTimer = new StopwatchTimer(mClocks, null, -4, null, mOnBatteryTimeBase); |
| 10236 | mGlobalWifiRunningTimer = new StopwatchTimer(mClocks, null, -5, null, mOnBatteryTimeBase); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 10237 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10238 | mWifiStateTimer[i] = new StopwatchTimer(mClocks, null, -600-i, null, |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 10239 | mOnBatteryTimeBase); |
| 10240 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10241 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 10242 | mWifiSupplStateTimer[i] = new StopwatchTimer(mClocks, null, -700-i, null, |
| 10243 | mOnBatteryTimeBase); |
| 10244 | } |
| 10245 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 10246 | mWifiSignalStrengthsTimer[i] = new StopwatchTimer(mClocks, null, -800-i, null, |
| 10247 | mOnBatteryTimeBase); |
| 10248 | } |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 10249 | mWifiActiveTimer = new StopwatchTimer(mClocks, null, -900, null, mOnBatteryTimeBase); |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 10250 | for (int i=0; i< GnssMetrics.NUM_GPS_SIGNAL_QUALITY_LEVELS; i++) { |
| 10251 | mGpsSignalQualityTimer[i] = new StopwatchTimer(mClocks, null, -1000-i, null, |
| 10252 | mOnBatteryTimeBase); |
| 10253 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10254 | mAudioOnTimer = new StopwatchTimer(mClocks, null, -7, null, mOnBatteryTimeBase); |
| 10255 | mVideoOnTimer = new StopwatchTimer(mClocks, null, -8, null, mOnBatteryTimeBase); |
| 10256 | mFlashlightOnTimer = new StopwatchTimer(mClocks, null, -9, null, mOnBatteryTimeBase); |
| 10257 | mCameraOnTimer = new StopwatchTimer(mClocks, null, -13, null, mOnBatteryTimeBase); |
| 10258 | mBluetoothScanTimer = new StopwatchTimer(mClocks, null, -14, null, mOnBatteryTimeBase); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 10259 | mDischargeScreenOffCounter = new LongSamplingCounter(mOnBatteryScreenOffTimeBase); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 10260 | mDischargeScreenDozeCounter = new LongSamplingCounter(mOnBatteryTimeBase); |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 10261 | mDischargeLightDozeCounter = new LongSamplingCounter(mOnBatteryTimeBase); |
| 10262 | mDischargeDeepDozeCounter = new LongSamplingCounter(mOnBatteryTimeBase); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 10263 | mDischargeCounter = new LongSamplingCounter(mOnBatteryTimeBase); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10264 | mOnBattery = mOnBatteryInternal = false; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10265 | long uptime = mClocks.uptimeMillis() * 1000; |
| 10266 | long realtime = mClocks.elapsedRealtime() * 1000; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10267 | initTimes(uptime, realtime); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 10268 | mStartPlatformVersion = mEndPlatformVersion = Build.ID; |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 10269 | mDischargeStartLevel = 0; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10270 | mDischargeUnplugLevel = 0; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 10271 | mDischargePlugLevel = -1; |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 10272 | mDischargeCurrentLevel = 0; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 10273 | mCurrentBatteryLevel = 0; |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 10274 | initDischarge(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10275 | clearHistoryLocked(); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10276 | updateDailyDeadlineLocked(); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 10277 | mPlatformIdleStateCallback = cb; |
Suprabh Shukla | e6e723d | 2017-06-14 16:14:43 -0700 | [diff] [blame] | 10278 | mUserInfoProvider = userInfoProvider; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10279 | } |
| 10280 | |
| 10281 | public BatteryStatsImpl(Parcel p) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10282 | this(new SystemClocks(), p); |
| 10283 | } |
| 10284 | |
| 10285 | public BatteryStatsImpl(Clocks clocks, Parcel p) { |
| 10286 | init(clocks); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10287 | mFile = null; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 10288 | mCheckinFile = null; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10289 | mDailyFile = null; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 10290 | mHandler = null; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 10291 | mExternalSync = null; |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 10292 | mConstants = new Constants(mHandler); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10293 | clearHistoryLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10294 | readFromParcel(p); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 10295 | mPlatformIdleStateCallback = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10296 | } |
| 10297 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 10298 | public void setPowerProfileLocked(PowerProfile profile) { |
| 10299 | mPowerProfile = profile; |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 10300 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 10301 | // We need to initialize the KernelCpuSpeedReaders to read from |
| 10302 | // the first cpu of each core. Once we have the PowerProfile, we have access to this |
| 10303 | // information. |
| 10304 | final int numClusters = mPowerProfile.getNumCpuClusters(); |
| 10305 | mKernelCpuSpeedReaders = new KernelCpuSpeedReader[numClusters]; |
| 10306 | int firstCpuOfCluster = 0; |
| 10307 | for (int i = 0; i < numClusters; i++) { |
| 10308 | final int numSpeedSteps = mPowerProfile.getNumSpeedStepsInCpuCluster(i); |
| 10309 | mKernelCpuSpeedReaders[i] = new KernelCpuSpeedReader(firstCpuOfCluster, |
| 10310 | numSpeedSteps); |
| 10311 | firstCpuOfCluster += mPowerProfile.getNumCoresInCpuCluster(i); |
| 10312 | } |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 10313 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 10314 | if (mEstimatedBatteryCapacity == -1) { |
| 10315 | // Initialize the estimated battery capacity to a known preset one. |
| 10316 | mEstimatedBatteryCapacity = (int) mPowerProfile.getBatteryCapacity(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 10317 | } |
| 10318 | } |
| 10319 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 10320 | public void setCallback(BatteryCallback cb) { |
| 10321 | mCallback = cb; |
| 10322 | } |
| 10323 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 10324 | public void setRadioScanningTimeoutLocked(long timeout) { |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 10325 | if (mPhoneSignalScanningTimer != null) { |
| 10326 | mPhoneSignalScanningTimer.setTimeout(timeout); |
| 10327 | } |
| 10328 | } |
| 10329 | |
Adam Lesinski | b3a1bad | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 10330 | public void setExternalStatsSyncLocked(ExternalStatsSync sync) { |
| 10331 | mExternalSync = sync; |
| 10332 | } |
| 10333 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10334 | public void updateDailyDeadlineLocked() { |
| 10335 | // Get the current time. |
| 10336 | long currentTime = mDailyStartTime = System.currentTimeMillis(); |
| 10337 | Calendar calDeadline = Calendar.getInstance(); |
| 10338 | calDeadline.setTimeInMillis(currentTime); |
| 10339 | |
| 10340 | // Move time up to the next day, ranging from 1am to 3pm. |
| 10341 | calDeadline.set(Calendar.DAY_OF_YEAR, calDeadline.get(Calendar.DAY_OF_YEAR) + 1); |
| 10342 | calDeadline.set(Calendar.MILLISECOND, 0); |
| 10343 | calDeadline.set(Calendar.SECOND, 0); |
| 10344 | calDeadline.set(Calendar.MINUTE, 0); |
| 10345 | calDeadline.set(Calendar.HOUR_OF_DAY, 1); |
| 10346 | mNextMinDailyDeadline = calDeadline.getTimeInMillis(); |
| 10347 | calDeadline.set(Calendar.HOUR_OF_DAY, 3); |
| 10348 | mNextMaxDailyDeadline = calDeadline.getTimeInMillis(); |
| 10349 | } |
| 10350 | |
| 10351 | public void recordDailyStatsIfNeededLocked(boolean settled) { |
| 10352 | long currentTime = System.currentTimeMillis(); |
| 10353 | if (currentTime >= mNextMaxDailyDeadline) { |
| 10354 | recordDailyStatsLocked(); |
| 10355 | } else if (settled && currentTime >= mNextMinDailyDeadline) { |
| 10356 | recordDailyStatsLocked(); |
| 10357 | } else if (currentTime < (mDailyStartTime-(1000*60*60*24))) { |
| 10358 | recordDailyStatsLocked(); |
| 10359 | } |
| 10360 | } |
| 10361 | |
| 10362 | public void recordDailyStatsLocked() { |
| 10363 | DailyItem item = new DailyItem(); |
| 10364 | item.mStartTime = mDailyStartTime; |
| 10365 | item.mEndTime = System.currentTimeMillis(); |
| 10366 | boolean hasData = false; |
| 10367 | if (mDailyDischargeStepTracker.mNumStepDurations > 0) { |
| 10368 | hasData = true; |
| 10369 | item.mDischargeSteps = new LevelStepTracker( |
| 10370 | mDailyDischargeStepTracker.mNumStepDurations, |
| 10371 | mDailyDischargeStepTracker.mStepDurations); |
| 10372 | } |
| 10373 | if (mDailyChargeStepTracker.mNumStepDurations > 0) { |
| 10374 | hasData = true; |
| 10375 | item.mChargeSteps = new LevelStepTracker( |
| 10376 | mDailyChargeStepTracker.mNumStepDurations, |
| 10377 | mDailyChargeStepTracker.mStepDurations); |
| 10378 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 10379 | if (mDailyPackageChanges != null) { |
| 10380 | hasData = true; |
| 10381 | item.mPackageChanges = mDailyPackageChanges; |
| 10382 | mDailyPackageChanges = null; |
| 10383 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10384 | mDailyDischargeStepTracker.init(); |
| 10385 | mDailyChargeStepTracker.init(); |
| 10386 | updateDailyDeadlineLocked(); |
| 10387 | |
| 10388 | if (hasData) { |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 10389 | final long startTime = SystemClock.uptimeMillis(); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10390 | mDailyItems.add(item); |
| 10391 | while (mDailyItems.size() > MAX_DAILY_ITEMS) { |
| 10392 | mDailyItems.remove(0); |
| 10393 | } |
| 10394 | final ByteArrayOutputStream memStream = new ByteArrayOutputStream(); |
| 10395 | try { |
| 10396 | XmlSerializer out = new FastXmlSerializer(); |
Wojciech Staszkiewicz | 9e9e2e7 | 2015-05-08 14:58:46 +0100 | [diff] [blame] | 10397 | out.setOutput(memStream, StandardCharsets.UTF_8.name()); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10398 | writeDailyItemsLocked(out); |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 10399 | final long initialTime = SystemClock.uptimeMillis() - startTime; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10400 | BackgroundThread.getHandler().post(new Runnable() { |
| 10401 | @Override |
| 10402 | public void run() { |
| 10403 | synchronized (mCheckinFile) { |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 10404 | final long startTime2 = SystemClock.uptimeMillis(); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10405 | FileOutputStream stream = null; |
| 10406 | try { |
| 10407 | stream = mDailyFile.startWrite(); |
| 10408 | memStream.writeTo(stream); |
| 10409 | stream.flush(); |
| 10410 | FileUtils.sync(stream); |
| 10411 | stream.close(); |
| 10412 | mDailyFile.finishWrite(stream); |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 10413 | com.android.internal.logging.EventLogTags.writeCommitSysConfigFile( |
| 10414 | "batterystats-daily", |
| 10415 | initialTime + SystemClock.uptimeMillis() - startTime2); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10416 | } catch (IOException e) { |
| 10417 | Slog.w("BatteryStats", |
| 10418 | "Error writing battery daily items", e); |
| 10419 | mDailyFile.failWrite(stream); |
| 10420 | } |
| 10421 | } |
| 10422 | } |
| 10423 | }); |
| 10424 | } catch (IOException e) { |
| 10425 | } |
| 10426 | } |
| 10427 | } |
| 10428 | |
| 10429 | private void writeDailyItemsLocked(XmlSerializer out) throws IOException { |
| 10430 | StringBuilder sb = new StringBuilder(64); |
| 10431 | out.startDocument(null, true); |
| 10432 | out.startTag(null, "daily-items"); |
| 10433 | for (int i=0; i<mDailyItems.size(); i++) { |
| 10434 | final DailyItem dit = mDailyItems.get(i); |
| 10435 | out.startTag(null, "item"); |
| 10436 | out.attribute(null, "start", Long.toString(dit.mStartTime)); |
| 10437 | out.attribute(null, "end", Long.toString(dit.mEndTime)); |
| 10438 | writeDailyLevelSteps(out, "dis", dit.mDischargeSteps, sb); |
| 10439 | writeDailyLevelSteps(out, "chg", dit.mChargeSteps, sb); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 10440 | if (dit.mPackageChanges != null) { |
| 10441 | for (int j=0; j<dit.mPackageChanges.size(); j++) { |
| 10442 | PackageChange pc = dit.mPackageChanges.get(j); |
| 10443 | if (pc.mUpdate) { |
| 10444 | out.startTag(null, "upd"); |
| 10445 | out.attribute(null, "pkg", pc.mPackageName); |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 10446 | out.attribute(null, "ver", Long.toString(pc.mVersionCode)); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 10447 | out.endTag(null, "upd"); |
| 10448 | } else { |
| 10449 | out.startTag(null, "rem"); |
| 10450 | out.attribute(null, "pkg", pc.mPackageName); |
| 10451 | out.endTag(null, "rem"); |
| 10452 | } |
| 10453 | } |
| 10454 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10455 | out.endTag(null, "item"); |
| 10456 | } |
| 10457 | out.endTag(null, "daily-items"); |
| 10458 | out.endDocument(); |
| 10459 | } |
| 10460 | |
| 10461 | private void writeDailyLevelSteps(XmlSerializer out, String tag, LevelStepTracker steps, |
| 10462 | StringBuilder tmpBuilder) throws IOException { |
| 10463 | if (steps != null) { |
| 10464 | out.startTag(null, tag); |
| 10465 | out.attribute(null, "n", Integer.toString(steps.mNumStepDurations)); |
| 10466 | for (int i=0; i<steps.mNumStepDurations; i++) { |
| 10467 | out.startTag(null, "s"); |
| 10468 | tmpBuilder.setLength(0); |
| 10469 | steps.encodeEntryAt(i, tmpBuilder); |
| 10470 | out.attribute(null, "v", tmpBuilder.toString()); |
| 10471 | out.endTag(null, "s"); |
| 10472 | } |
| 10473 | out.endTag(null, tag); |
| 10474 | } |
| 10475 | } |
| 10476 | |
| 10477 | public void readDailyStatsLocked() { |
| 10478 | Slog.d(TAG, "Reading daily items from " + mDailyFile.getBaseFile()); |
| 10479 | mDailyItems.clear(); |
| 10480 | FileInputStream stream; |
| 10481 | try { |
| 10482 | stream = mDailyFile.openRead(); |
| 10483 | } catch (FileNotFoundException e) { |
| 10484 | return; |
| 10485 | } |
| 10486 | try { |
| 10487 | XmlPullParser parser = Xml.newPullParser(); |
Wojciech Staszkiewicz | 9e9e2e7 | 2015-05-08 14:58:46 +0100 | [diff] [blame] | 10488 | parser.setInput(stream, StandardCharsets.UTF_8.name()); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10489 | readDailyItemsLocked(parser); |
| 10490 | } catch (XmlPullParserException e) { |
| 10491 | } finally { |
| 10492 | try { |
| 10493 | stream.close(); |
| 10494 | } catch (IOException e) { |
| 10495 | } |
| 10496 | } |
| 10497 | } |
| 10498 | |
| 10499 | private void readDailyItemsLocked(XmlPullParser parser) { |
| 10500 | try { |
| 10501 | int type; |
| 10502 | while ((type = parser.next()) != XmlPullParser.START_TAG |
| 10503 | && type != XmlPullParser.END_DOCUMENT) { |
| 10504 | ; |
| 10505 | } |
| 10506 | |
| 10507 | if (type != XmlPullParser.START_TAG) { |
| 10508 | throw new IllegalStateException("no start tag found"); |
| 10509 | } |
| 10510 | |
| 10511 | int outerDepth = parser.getDepth(); |
| 10512 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 10513 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 10514 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 10515 | continue; |
| 10516 | } |
| 10517 | |
| 10518 | String tagName = parser.getName(); |
| 10519 | if (tagName.equals("item")) { |
| 10520 | readDailyItemTagLocked(parser); |
| 10521 | } else { |
| 10522 | Slog.w(TAG, "Unknown element under <daily-items>: " |
| 10523 | + parser.getName()); |
| 10524 | XmlUtils.skipCurrentTag(parser); |
| 10525 | } |
| 10526 | } |
| 10527 | |
| 10528 | } catch (IllegalStateException e) { |
| 10529 | Slog.w(TAG, "Failed parsing daily " + e); |
| 10530 | } catch (NullPointerException e) { |
| 10531 | Slog.w(TAG, "Failed parsing daily " + e); |
| 10532 | } catch (NumberFormatException e) { |
| 10533 | Slog.w(TAG, "Failed parsing daily " + e); |
| 10534 | } catch (XmlPullParserException e) { |
| 10535 | Slog.w(TAG, "Failed parsing daily " + e); |
| 10536 | } catch (IOException e) { |
| 10537 | Slog.w(TAG, "Failed parsing daily " + e); |
| 10538 | } catch (IndexOutOfBoundsException e) { |
| 10539 | Slog.w(TAG, "Failed parsing daily " + e); |
| 10540 | } |
| 10541 | } |
| 10542 | |
| 10543 | void readDailyItemTagLocked(XmlPullParser parser) throws NumberFormatException, |
| 10544 | XmlPullParserException, IOException { |
| 10545 | DailyItem dit = new DailyItem(); |
| 10546 | String attr = parser.getAttributeValue(null, "start"); |
| 10547 | if (attr != null) { |
| 10548 | dit.mStartTime = Long.parseLong(attr); |
| 10549 | } |
| 10550 | attr = parser.getAttributeValue(null, "end"); |
| 10551 | if (attr != null) { |
| 10552 | dit.mEndTime = Long.parseLong(attr); |
| 10553 | } |
| 10554 | int outerDepth = parser.getDepth(); |
| 10555 | int type; |
| 10556 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 10557 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 10558 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 10559 | continue; |
| 10560 | } |
| 10561 | |
| 10562 | String tagName = parser.getName(); |
| 10563 | if (tagName.equals("dis")) { |
| 10564 | readDailyItemTagDetailsLocked(parser, dit, false, "dis"); |
| 10565 | } else if (tagName.equals("chg")) { |
| 10566 | readDailyItemTagDetailsLocked(parser, dit, true, "chg"); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 10567 | } else if (tagName.equals("upd")) { |
| 10568 | if (dit.mPackageChanges == null) { |
| 10569 | dit.mPackageChanges = new ArrayList<>(); |
| 10570 | } |
| 10571 | PackageChange pc = new PackageChange(); |
| 10572 | pc.mUpdate = true; |
| 10573 | pc.mPackageName = parser.getAttributeValue(null, "pkg"); |
| 10574 | String verStr = parser.getAttributeValue(null, "ver"); |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 10575 | pc.mVersionCode = verStr != null ? Long.parseLong(verStr) : 0; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 10576 | dit.mPackageChanges.add(pc); |
| 10577 | XmlUtils.skipCurrentTag(parser); |
| 10578 | } else if (tagName.equals("rem")) { |
| 10579 | if (dit.mPackageChanges == null) { |
| 10580 | dit.mPackageChanges = new ArrayList<>(); |
| 10581 | } |
| 10582 | PackageChange pc = new PackageChange(); |
| 10583 | pc.mUpdate = false; |
| 10584 | pc.mPackageName = parser.getAttributeValue(null, "pkg"); |
| 10585 | dit.mPackageChanges.add(pc); |
| 10586 | XmlUtils.skipCurrentTag(parser); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10587 | } else { |
| 10588 | Slog.w(TAG, "Unknown element under <item>: " |
| 10589 | + parser.getName()); |
| 10590 | XmlUtils.skipCurrentTag(parser); |
| 10591 | } |
| 10592 | } |
| 10593 | mDailyItems.add(dit); |
| 10594 | } |
| 10595 | |
| 10596 | void readDailyItemTagDetailsLocked(XmlPullParser parser, DailyItem dit, boolean isCharge, |
| 10597 | String tag) |
| 10598 | throws NumberFormatException, XmlPullParserException, IOException { |
| 10599 | final String numAttr = parser.getAttributeValue(null, "n"); |
| 10600 | if (numAttr == null) { |
| 10601 | Slog.w(TAG, "Missing 'n' attribute at " + parser.getPositionDescription()); |
| 10602 | XmlUtils.skipCurrentTag(parser); |
| 10603 | return; |
| 10604 | } |
| 10605 | final int num = Integer.parseInt(numAttr); |
| 10606 | LevelStepTracker steps = new LevelStepTracker(num); |
| 10607 | if (isCharge) { |
| 10608 | dit.mChargeSteps = steps; |
| 10609 | } else { |
| 10610 | dit.mDischargeSteps = steps; |
| 10611 | } |
| 10612 | int i = 0; |
| 10613 | int outerDepth = parser.getDepth(); |
| 10614 | int type; |
| 10615 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 10616 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 10617 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 10618 | continue; |
| 10619 | } |
| 10620 | |
| 10621 | String tagName = parser.getName(); |
| 10622 | if ("s".equals(tagName)) { |
| 10623 | if (i < num) { |
| 10624 | String valueAttr = parser.getAttributeValue(null, "v"); |
| 10625 | if (valueAttr != null) { |
| 10626 | steps.decodeEntryAt(i, valueAttr); |
| 10627 | i++; |
| 10628 | } |
| 10629 | } |
| 10630 | } else { |
| 10631 | Slog.w(TAG, "Unknown element under <" + tag + ">: " |
| 10632 | + parser.getName()); |
| 10633 | XmlUtils.skipCurrentTag(parser); |
| 10634 | } |
| 10635 | } |
| 10636 | steps.mNumStepDurations = i; |
| 10637 | } |
| 10638 | |
| 10639 | @Override |
| 10640 | public DailyItem getDailyItemLocked(int daysAgo) { |
| 10641 | int index = mDailyItems.size()-1-daysAgo; |
| 10642 | return index >= 0 ? mDailyItems.get(index) : null; |
| 10643 | } |
| 10644 | |
| 10645 | @Override |
| 10646 | public long getCurrentDailyStartTime() { |
| 10647 | return mDailyStartTime; |
| 10648 | } |
| 10649 | |
| 10650 | @Override |
| 10651 | public long getNextMinDailyDeadline() { |
| 10652 | return mNextMinDailyDeadline; |
| 10653 | } |
| 10654 | |
| 10655 | @Override |
| 10656 | public long getNextMaxDailyDeadline() { |
| 10657 | return mNextMaxDailyDeadline; |
| 10658 | } |
| 10659 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10660 | @Override |
| 10661 | public boolean startIteratingOldHistoryLocked() { |
| 10662 | if (DEBUG_HISTORY) Slog.i(TAG, "ITERATING: buff size=" + mHistoryBuffer.dataSize() |
| 10663 | + " pos=" + mHistoryBuffer.dataPosition()); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 10664 | if ((mHistoryIterator = mHistory) == null) { |
| 10665 | return false; |
| 10666 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10667 | mHistoryBuffer.setDataPosition(0); |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 10668 | mHistoryReadTmp.clear(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10669 | mReadOverflow = false; |
| 10670 | mIteratingHistory = true; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 10671 | return true; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 10672 | } |
| 10673 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10674 | @Override |
| 10675 | public boolean getNextOldHistoryLocked(HistoryItem out) { |
| 10676 | boolean end = mHistoryBuffer.dataPosition() >= mHistoryBuffer.dataSize(); |
| 10677 | if (!end) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 10678 | readHistoryDelta(mHistoryBuffer, mHistoryReadTmp); |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 10679 | mReadOverflow |= mHistoryReadTmp.cmd == HistoryItem.CMD_OVERFLOW; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10680 | } |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 10681 | HistoryItem cur = mHistoryIterator; |
| 10682 | if (cur == null) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10683 | if (!mReadOverflow && !end) { |
| 10684 | Slog.w(TAG, "Old history ends before new history!"); |
| 10685 | } |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 10686 | return false; |
| 10687 | } |
| 10688 | out.setTo(cur); |
| 10689 | mHistoryIterator = cur.next; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10690 | if (!mReadOverflow) { |
| 10691 | if (end) { |
| 10692 | Slog.w(TAG, "New history ends before old history!"); |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 10693 | } else if (!out.same(mHistoryReadTmp)) { |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 10694 | PrintWriter pw = new FastPrintWriter(new LogWriter(android.util.Log.WARN, TAG)); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10695 | pw.println("Histories differ!"); |
| 10696 | pw.println("Old history:"); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 10697 | (new HistoryPrinter()).printNextItem(pw, out, 0, false, true); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10698 | pw.println("New history:"); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 10699 | (new HistoryPrinter()).printNextItem(pw, mHistoryReadTmp, 0, false, |
| 10700 | true); |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 10701 | pw.flush(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10702 | } |
| 10703 | } |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 10704 | return true; |
| 10705 | } |
| 10706 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10707 | @Override |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10708 | public void finishIteratingOldHistoryLocked() { |
| 10709 | mIteratingHistory = false; |
| 10710 | mHistoryBuffer.setDataPosition(mHistoryBuffer.dataSize()); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 10711 | mHistoryIterator = null; |
| 10712 | } |
| 10713 | |
| 10714 | public int getHistoryTotalSize() { |
| 10715 | return MAX_HISTORY_BUFFER; |
| 10716 | } |
| 10717 | |
| 10718 | public int getHistoryUsedSize() { |
| 10719 | return mHistoryBuffer.dataSize(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10720 | } |
| 10721 | |
| 10722 | @Override |
| 10723 | public boolean startIteratingHistoryLocked() { |
| 10724 | if (DEBUG_HISTORY) Slog.i(TAG, "ITERATING: buff size=" + mHistoryBuffer.dataSize() |
| 10725 | + " pos=" + mHistoryBuffer.dataPosition()); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 10726 | if (mHistoryBuffer.dataSize() <= 0) { |
| 10727 | return false; |
| 10728 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10729 | mHistoryBuffer.setDataPosition(0); |
| 10730 | mReadOverflow = false; |
| 10731 | mIteratingHistory = true; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 10732 | mReadHistoryStrings = new String[mHistoryTagPool.size()]; |
| 10733 | mReadHistoryUids = new int[mHistoryTagPool.size()]; |
| 10734 | mReadHistoryChars = 0; |
| 10735 | for (HashMap.Entry<HistoryTag, Integer> ent : mHistoryTagPool.entrySet()) { |
| 10736 | final HistoryTag tag = ent.getKey(); |
| 10737 | final int idx = ent.getValue(); |
| 10738 | mReadHistoryStrings[idx] = tag.string; |
| 10739 | mReadHistoryUids[idx] = tag.uid; |
| 10740 | mReadHistoryChars += tag.string.length() + 1; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 10741 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 10742 | return true; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10743 | } |
| 10744 | |
| 10745 | @Override |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 10746 | public int getHistoryStringPoolSize() { |
| 10747 | return mReadHistoryStrings.length; |
| 10748 | } |
| 10749 | |
| 10750 | @Override |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 10751 | public int getHistoryStringPoolBytes() { |
| 10752 | // Each entry is a fixed 12 bytes: 4 for index, 4 for uid, 4 for string size |
| 10753 | // Each string character is 2 bytes. |
| 10754 | return (mReadHistoryStrings.length * 12) + (mReadHistoryChars * 2); |
| 10755 | } |
| 10756 | |
| 10757 | @Override |
| 10758 | public String getHistoryTagPoolString(int index) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 10759 | return mReadHistoryStrings[index]; |
| 10760 | } |
| 10761 | |
| 10762 | @Override |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 10763 | public int getHistoryTagPoolUid(int index) { |
| 10764 | return mReadHistoryUids[index]; |
| 10765 | } |
| 10766 | |
| 10767 | @Override |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10768 | public boolean getNextHistoryLocked(HistoryItem out) { |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 10769 | final int pos = mHistoryBuffer.dataPosition(); |
| 10770 | if (pos == 0) { |
| 10771 | out.clear(); |
| 10772 | } |
| 10773 | boolean end = pos >= mHistoryBuffer.dataSize(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10774 | if (end) { |
| 10775 | return false; |
| 10776 | } |
| 10777 | |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 10778 | final long lastRealtime = out.time; |
| 10779 | final long lastWalltime = out.currentTime; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 10780 | readHistoryDelta(mHistoryBuffer, out); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 10781 | if (out.cmd != HistoryItem.CMD_CURRENT_TIME |
| 10782 | && out.cmd != HistoryItem.CMD_RESET && lastWalltime != 0) { |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 10783 | out.currentTime = lastWalltime + (out.time - lastRealtime); |
| 10784 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10785 | return true; |
| 10786 | } |
| 10787 | |
| 10788 | @Override |
| 10789 | public void finishIteratingHistoryLocked() { |
| 10790 | mIteratingHistory = false; |
| 10791 | mHistoryBuffer.setDataPosition(mHistoryBuffer.dataSize()); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 10792 | mReadHistoryStrings = null; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 10793 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10794 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 10795 | @Override |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 10796 | public long getHistoryBaseTime() { |
| 10797 | return mHistoryBaseTime; |
| 10798 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10799 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 10800 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10801 | public int getStartCount() { |
| 10802 | return mStartCount; |
| 10803 | } |
| 10804 | |
| 10805 | public boolean isOnBattery() { |
| 10806 | return mOnBattery; |
| 10807 | } |
| 10808 | |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 10809 | public boolean isCharging() { |
| 10810 | return mCharging; |
| 10811 | } |
| 10812 | |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 10813 | public boolean isScreenOn(int state) { |
Chris Phoenix | 10a4a64 | 2017-09-25 13:21:00 -0700 | [diff] [blame] | 10814 | return state == Display.STATE_ON || state == Display.STATE_VR |
| 10815 | || state == Display.STATE_ON_SUSPEND; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 10816 | } |
| 10817 | |
| 10818 | public boolean isScreenOff(int state) { |
| 10819 | return state == Display.STATE_OFF; |
| 10820 | } |
| 10821 | |
| 10822 | public boolean isScreenDoze(int state) { |
| 10823 | return state == Display.STATE_DOZE || state == Display.STATE_DOZE_SUSPEND; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 10824 | } |
| 10825 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10826 | void initTimes(long uptime, long realtime) { |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 10827 | mStartClockTime = System.currentTimeMillis(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10828 | mOnBatteryTimeBase.init(uptime, realtime); |
| 10829 | mOnBatteryScreenOffTimeBase.init(uptime, realtime); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 10830 | mRealtime = 0; |
| 10831 | mUptime = 0; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10832 | mRealtimeStart = realtime; |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 10833 | mUptimeStart = uptime; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10834 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10835 | |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 10836 | void initDischarge() { |
| 10837 | mLowDischargeAmountSinceCharge = 0; |
| 10838 | mHighDischargeAmountSinceCharge = 0; |
| 10839 | mDischargeAmountScreenOn = 0; |
| 10840 | mDischargeAmountScreenOnSinceCharge = 0; |
| 10841 | mDischargeAmountScreenOff = 0; |
| 10842 | mDischargeAmountScreenOffSinceCharge = 0; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 10843 | mDischargeAmountScreenDoze = 0; |
| 10844 | mDischargeAmountScreenDozeSinceCharge = 0; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10845 | mDischargeStepTracker.init(); |
| 10846 | mChargeStepTracker.init(); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 10847 | mDischargeScreenOffCounter.reset(false); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 10848 | mDischargeScreenDozeCounter.reset(false); |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 10849 | mDischargeLightDozeCounter.reset(false); |
| 10850 | mDischargeDeepDozeCounter.reset(false); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 10851 | mDischargeCounter.reset(false); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 10852 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 10853 | |
| 10854 | public void resetAllStatsCmdLocked() { |
| 10855 | resetAllStatsLocked(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10856 | final long mSecUptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 10857 | long uptime = mSecUptime * 1000; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10858 | long mSecRealtime = mClocks.elapsedRealtime(); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 10859 | long realtime = mSecRealtime * 1000; |
| 10860 | mDischargeStartLevel = mHistoryCur.batteryLevel; |
| 10861 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 10862 | addHistoryRecordLocked(mSecRealtime, mSecUptime); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 10863 | mDischargeCurrentLevel = mDischargeUnplugLevel = mDischargePlugLevel |
| 10864 | = mCurrentBatteryLevel = mHistoryCur.batteryLevel; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10865 | mOnBatteryTimeBase.reset(uptime, realtime); |
| 10866 | mOnBatteryScreenOffTimeBase.reset(uptime, realtime); |
| 10867 | if ((mHistoryCur.states&HistoryItem.STATE_BATTERY_PLUGGED_FLAG) == 0) { |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 10868 | if (isScreenOn(mScreenState)) { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 10869 | mDischargeScreenOnUnplugLevel = mHistoryCur.batteryLevel; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 10870 | mDischargeScreenDozeUnplugLevel = 0; |
| 10871 | mDischargeScreenOffUnplugLevel = 0; |
| 10872 | } else if (isScreenDoze(mScreenState)) { |
| 10873 | mDischargeScreenOnUnplugLevel = 0; |
| 10874 | mDischargeScreenDozeUnplugLevel = mHistoryCur.batteryLevel; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 10875 | mDischargeScreenOffUnplugLevel = 0; |
| 10876 | } else { |
| 10877 | mDischargeScreenOnUnplugLevel = 0; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 10878 | mDischargeScreenDozeUnplugLevel = 0; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 10879 | mDischargeScreenOffUnplugLevel = mHistoryCur.batteryLevel; |
| 10880 | } |
| 10881 | mDischargeAmountScreenOn = 0; |
| 10882 | mDischargeAmountScreenOff = 0; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 10883 | mDischargeAmountScreenDoze = 0; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 10884 | } |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 10885 | initActiveHistoryEventsLocked(mSecRealtime, mSecUptime); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 10886 | } |
| 10887 | |
| 10888 | private void resetAllStatsLocked() { |
Adam Lesinski | 8ce3694 | 2016-05-26 16:05:35 -0700 | [diff] [blame] | 10889 | final long uptimeMillis = mClocks.uptimeMillis(); |
| 10890 | final long elapsedRealtimeMillis = mClocks.elapsedRealtime(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10891 | mStartCount = 0; |
Adam Lesinski | 8ce3694 | 2016-05-26 16:05:35 -0700 | [diff] [blame] | 10892 | initTimes(uptimeMillis * 1000, elapsedRealtimeMillis * 1000); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10893 | mScreenOnTimer.reset(false); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 10894 | mScreenDozeTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10895 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10896 | mScreenBrightnessTimer[i].reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10897 | } |
Adam Lesinski | 1a76a62 | 2016-06-22 10:28:47 -0700 | [diff] [blame] | 10898 | |
| 10899 | if (mPowerProfile != null) { |
| 10900 | mEstimatedBatteryCapacity = (int) mPowerProfile.getBatteryCapacity(); |
| 10901 | } else { |
| 10902 | mEstimatedBatteryCapacity = -1; |
| 10903 | } |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 10904 | mMinLearnedBatteryCapacity = -1; |
| 10905 | mMaxLearnedBatteryCapacity = -1; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 10906 | mInteractiveTimer.reset(false); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 10907 | mPowerSaveModeEnabledTimer.reset(false); |
Adam Lesinski | 8ce3694 | 2016-05-26 16:05:35 -0700 | [diff] [blame] | 10908 | mLastIdleTimeStart = elapsedRealtimeMillis; |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 10909 | mLongestLightIdleTime = 0; |
| 10910 | mLongestFullIdleTime = 0; |
| 10911 | mDeviceIdleModeLightTimer.reset(false); |
| 10912 | mDeviceIdleModeFullTimer.reset(false); |
| 10913 | mDeviceLightIdlingTimer.reset(false); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 10914 | mDeviceIdlingTimer.reset(false); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10915 | mPhoneOnTimer.reset(false); |
| 10916 | mAudioOnTimer.reset(false); |
| 10917 | mVideoOnTimer.reset(false); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 10918 | mFlashlightOnTimer.reset(false); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 10919 | mCameraOnTimer.reset(false); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 10920 | mBluetoothScanTimer.reset(false); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 10921 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10922 | mPhoneSignalStrengthsTimer[i].reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10923 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10924 | mPhoneSignalScanningTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10925 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10926 | mPhoneDataConnectionsTimer[i].reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10927 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 10928 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 10929 | mNetworkByteActivityCounters[i].reset(false); |
| 10930 | mNetworkPacketActivityCounters[i].reset(false); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 10931 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10932 | mMobileRadioActiveTimer.reset(false); |
| 10933 | mMobileRadioActivePerAppTimer.reset(false); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10934 | mMobileRadioActiveAdjustedTime.reset(false); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 10935 | mMobileRadioActiveUnknownTime.reset(false); |
| 10936 | mMobileRadioActiveUnknownCount.reset(false); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10937 | mWifiOnTimer.reset(false); |
| 10938 | mGlobalWifiRunningTimer.reset(false); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 10939 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10940 | mWifiStateTimer[i].reset(false); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 10941 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 10942 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 10943 | mWifiSupplStateTimer[i].reset(false); |
| 10944 | } |
| 10945 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 10946 | mWifiSignalStrengthsTimer[i].reset(false); |
| 10947 | } |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 10948 | mWifiMulticastWakelockTimer.reset(false); |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 10949 | mWifiActiveTimer.reset(false); |
| 10950 | mWifiActivity.reset(false); |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 10951 | for (int i=0; i< GnssMetrics.NUM_GPS_SIGNAL_QUALITY_LEVELS; i++) { |
| 10952 | mGpsSignalQualityTimer[i].reset(false); |
| 10953 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 10954 | mBluetoothActivity.reset(false); |
| 10955 | mModemActivity.reset(false); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 10956 | mNumConnectivityChange = mLoadedNumConnectivityChange = mUnpluggedNumConnectivityChange = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10957 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10958 | for (int i=0; i<mUidStats.size(); i++) { |
Bookatz | 993a0be | 2017-07-21 09:03:23 -0700 | [diff] [blame] | 10959 | if (mUidStats.valueAt(i).reset(uptimeMillis * 1000, elapsedRealtimeMillis * 1000)) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10960 | mUidStats.remove(mUidStats.keyAt(i)); |
| 10961 | i--; |
| 10962 | } |
| 10963 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10964 | |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 10965 | if (mRpmStats.size() > 0) { |
| 10966 | for (SamplingTimer timer : mRpmStats.values()) { |
| 10967 | mOnBatteryTimeBase.remove(timer); |
| 10968 | } |
| 10969 | mRpmStats.clear(); |
| 10970 | } |
| 10971 | if (mScreenOffRpmStats.size() > 0) { |
| 10972 | for (SamplingTimer timer : mScreenOffRpmStats.values()) { |
| 10973 | mOnBatteryScreenOffTimeBase.remove(timer); |
| 10974 | } |
| 10975 | mScreenOffRpmStats.clear(); |
| 10976 | } |
| 10977 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10978 | if (mKernelWakelockStats.size() > 0) { |
| 10979 | for (SamplingTimer timer : mKernelWakelockStats.values()) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10980 | mOnBatteryScreenOffTimeBase.remove(timer); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10981 | } |
| 10982 | mKernelWakelockStats.clear(); |
| 10983 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10984 | |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 10985 | if (mKernelMemoryStats.size() > 0) { |
| 10986 | for (int i = 0; i < mKernelMemoryStats.size(); i++) { |
| 10987 | mOnBatteryTimeBase.remove(mKernelMemoryStats.valueAt(i)); |
| 10988 | } |
| 10989 | mKernelMemoryStats.clear(); |
| 10990 | } |
| 10991 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10992 | if (mWakeupReasonStats.size() > 0) { |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 10993 | for (SamplingTimer timer : mWakeupReasonStats.values()) { |
| 10994 | mOnBatteryTimeBase.remove(timer); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10995 | } |
| 10996 | mWakeupReasonStats.clear(); |
| 10997 | } |
| 10998 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 10999 | mLastHistoryStepDetails = null; |
| 11000 | mLastStepCpuUserTime = mLastStepCpuSystemTime = 0; |
| 11001 | mCurStepCpuUserTime = mCurStepCpuSystemTime = 0; |
| 11002 | mLastStepCpuUserTime = mCurStepCpuUserTime = 0; |
| 11003 | mLastStepCpuSystemTime = mCurStepCpuSystemTime = 0; |
| 11004 | mLastStepStatUserTime = mCurStepStatUserTime = 0; |
| 11005 | mLastStepStatSystemTime = mCurStepStatSystemTime = 0; |
| 11006 | mLastStepStatIOWaitTime = mCurStepStatIOWaitTime = 0; |
| 11007 | mLastStepStatIrqTime = mCurStepStatIrqTime = 0; |
| 11008 | mLastStepStatSoftIrqTime = mCurStepStatSoftIrqTime = 0; |
| 11009 | mLastStepStatIdleTime = mCurStepStatIdleTime = 0; |
| 11010 | |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 11011 | initDischarge(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 11012 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 11013 | clearHistoryLocked(); |
| 11014 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 11015 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 11016 | private void initActiveHistoryEventsLocked(long elapsedRealtimeMs, long uptimeMs) { |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 11017 | for (int i=0; i<HistoryItem.EVENT_COUNT; i++) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 11018 | if (!mRecordAllHistory && i == HistoryItem.EVENT_PROC) { |
| 11019 | // Not recording process starts/stops. |
| 11020 | continue; |
| 11021 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 11022 | HashMap<String, SparseIntArray> active = mActiveEvents.getStateForEvent(i); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 11023 | if (active == null) { |
| 11024 | continue; |
| 11025 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 11026 | for (HashMap.Entry<String, SparseIntArray> ent : active.entrySet()) { |
| 11027 | SparseIntArray uids = ent.getValue(); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 11028 | for (int j=0; j<uids.size(); j++) { |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 11029 | addHistoryEventLocked(elapsedRealtimeMs, uptimeMs, i, ent.getKey(), |
| 11030 | uids.keyAt(j)); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 11031 | } |
| 11032 | } |
| 11033 | } |
| 11034 | } |
| 11035 | |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 11036 | void updateDischargeScreenLevelsLocked(int oldState, int newState) { |
| 11037 | updateOldDischargeScreenLevelLocked(oldState); |
| 11038 | updateNewDischargeScreenLevelLocked(newState); |
| 11039 | } |
| 11040 | |
| 11041 | private void updateOldDischargeScreenLevelLocked(int state) { |
| 11042 | if (isScreenOn(state)) { |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 11043 | int diff = mDischargeScreenOnUnplugLevel - mDischargeCurrentLevel; |
| 11044 | if (diff > 0) { |
| 11045 | mDischargeAmountScreenOn += diff; |
| 11046 | mDischargeAmountScreenOnSinceCharge += diff; |
| 11047 | } |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 11048 | } else if (isScreenDoze(state)) { |
| 11049 | int diff = mDischargeScreenDozeUnplugLevel - mDischargeCurrentLevel; |
| 11050 | if (diff > 0) { |
| 11051 | mDischargeAmountScreenDoze += diff; |
| 11052 | mDischargeAmountScreenDozeSinceCharge += diff; |
| 11053 | } |
| 11054 | } else if (isScreenOff(state)){ |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 11055 | int diff = mDischargeScreenOffUnplugLevel - mDischargeCurrentLevel; |
| 11056 | if (diff > 0) { |
| 11057 | mDischargeAmountScreenOff += diff; |
| 11058 | mDischargeAmountScreenOffSinceCharge += diff; |
| 11059 | } |
| 11060 | } |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 11061 | } |
| 11062 | |
| 11063 | private void updateNewDischargeScreenLevelLocked(int state) { |
| 11064 | if (isScreenOn(state)) { |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 11065 | mDischargeScreenOnUnplugLevel = mDischargeCurrentLevel; |
| 11066 | mDischargeScreenOffUnplugLevel = 0; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 11067 | mDischargeScreenDozeUnplugLevel = 0; |
| 11068 | } else if (isScreenDoze(state)){ |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 11069 | mDischargeScreenOnUnplugLevel = 0; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 11070 | mDischargeScreenDozeUnplugLevel = mDischargeCurrentLevel; |
| 11071 | mDischargeScreenOffUnplugLevel = 0; |
| 11072 | } else if (isScreenOff(state)) { |
| 11073 | mDischargeScreenOnUnplugLevel = 0; |
| 11074 | mDischargeScreenDozeUnplugLevel = 0; |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 11075 | mDischargeScreenOffUnplugLevel = mDischargeCurrentLevel; |
| 11076 | } |
| 11077 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11078 | |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 11079 | public void pullPendingStateUpdatesLocked() { |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 11080 | if (mOnBatteryInternal) { |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 11081 | updateDischargeScreenLevelsLocked(mScreenState, mScreenState); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 11082 | } |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 11083 | } |
| 11084 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11085 | private final NetworkStatsFactory mNetworkStatsFactory = new NetworkStatsFactory(); |
| 11086 | private final Pools.Pool<NetworkStats> mNetworkStatsPool = new Pools.SynchronizedPool<>(6); |
| 11087 | |
| 11088 | private final Object mWifiNetworkLock = new Object(); |
| 11089 | |
| 11090 | @GuardedBy("mWifiNetworkLock") |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11091 | private String[] mWifiIfaces = EmptyArray.STRING; |
| 11092 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11093 | @GuardedBy("mWifiNetworkLock") |
| 11094 | private NetworkStats mLastWifiNetworkStats = new NetworkStats(0, -1); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11095 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11096 | private final Object mModemNetworkLock = new Object(); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11097 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11098 | @GuardedBy("mModemNetworkLock") |
| 11099 | private String[] mModemIfaces = EmptyArray.STRING; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11100 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11101 | @GuardedBy("mModemNetworkLock") |
| 11102 | private NetworkStats mLastModemNetworkStats = new NetworkStats(0, -1); |
| 11103 | |
| 11104 | private NetworkStats readNetworkStatsLocked(String[] ifaces) { |
| 11105 | try { |
| 11106 | if (!ArrayUtils.isEmpty(ifaces)) { |
| 11107 | return mNetworkStatsFactory.readNetworkStatsDetail(NetworkStats.UID_ALL, ifaces, |
| 11108 | NetworkStats.TAG_NONE, mNetworkStatsPool.acquire()); |
| 11109 | } |
| 11110 | } catch (IOException e) { |
| 11111 | 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] | 11112 | } |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11113 | return null; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11114 | } |
| 11115 | |
Chenjie Yu | 8908339 | 2018-01-11 14:53:31 -0800 | [diff] [blame] | 11116 | /** |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11117 | * Distribute WiFi energy info and network traffic to apps. |
| 11118 | * @param info The energy information from the WiFi controller. |
| 11119 | */ |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11120 | public void updateWifiState(@Nullable final WifiActivityEnergyInfo info) { |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 11121 | if (DEBUG_ENERGY) { |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11122 | Slog.d(TAG, "Updating wifi stats: " + Arrays.toString(mWifiIfaces)); |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 11123 | } |
| 11124 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11125 | // 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] | 11126 | NetworkStats delta = null; |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11127 | synchronized (mWifiNetworkLock) { |
| 11128 | final NetworkStats latestStats = readNetworkStatsLocked(mWifiIfaces); |
| 11129 | if (latestStats != null) { |
| 11130 | delta = NetworkStats.subtract(latestStats, mLastWifiNetworkStats, null, null, |
| 11131 | mNetworkStatsPool.acquire()); |
| 11132 | mNetworkStatsPool.release(mLastWifiNetworkStats); |
| 11133 | mLastWifiNetworkStats = latestStats; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 11134 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11135 | } |
| 11136 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11137 | synchronized (this) { |
| 11138 | if (!mOnBatteryInternal) { |
| 11139 | if (delta != null) { |
| 11140 | mNetworkStatsPool.release(delta); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11141 | } |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11142 | return; |
| 11143 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11144 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11145 | final long elapsedRealtimeMs = mClocks.elapsedRealtime(); |
| 11146 | SparseLongArray rxPackets = new SparseLongArray(); |
| 11147 | SparseLongArray txPackets = new SparseLongArray(); |
| 11148 | long totalTxPackets = 0; |
| 11149 | long totalRxPackets = 0; |
| 11150 | if (delta != null) { |
| 11151 | NetworkStats.Entry entry = new NetworkStats.Entry(); |
| 11152 | final int size = delta.size(); |
| 11153 | for (int i = 0; i < size; i++) { |
| 11154 | entry = delta.getValues(i, entry); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11155 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11156 | if (DEBUG_ENERGY) { |
| 11157 | Slog.d(TAG, "Wifi uid " + entry.uid + ": delta rx=" + entry.rxBytes |
| 11158 | + " tx=" + entry.txBytes + " rxPackets=" + entry.rxPackets |
| 11159 | + " txPackets=" + entry.txPackets); |
| 11160 | } |
| 11161 | |
| 11162 | if (entry.rxBytes == 0 && entry.txBytes == 0) { |
| 11163 | // Skip the lookup below since there is no work to do. |
| 11164 | continue; |
| 11165 | } |
| 11166 | |
| 11167 | final Uid u = getUidStatsLocked(mapUid(entry.uid)); |
| 11168 | if (entry.rxBytes != 0) { |
| 11169 | u.noteNetworkActivityLocked(NETWORK_WIFI_RX_DATA, entry.rxBytes, |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 11170 | entry.rxPackets); |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11171 | if (entry.set == NetworkStats.SET_DEFAULT) { // Background transfers |
| 11172 | u.noteNetworkActivityLocked(NETWORK_WIFI_BG_RX_DATA, entry.rxBytes, |
| 11173 | entry.rxPackets); |
| 11174 | } |
| 11175 | mNetworkByteActivityCounters[NETWORK_WIFI_RX_DATA].addCountLocked( |
| 11176 | entry.rxBytes); |
| 11177 | mNetworkPacketActivityCounters[NETWORK_WIFI_RX_DATA].addCountLocked( |
| 11178 | entry.rxPackets); |
| 11179 | |
| 11180 | rxPackets.put(u.getUid(), entry.rxPackets); |
| 11181 | |
| 11182 | // Sum the total number of packets so that the Rx Power can |
| 11183 | // be evenly distributed amongst the apps. |
| 11184 | totalRxPackets += entry.rxPackets; |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 11185 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 11186 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11187 | if (entry.txBytes != 0) { |
| 11188 | u.noteNetworkActivityLocked(NETWORK_WIFI_TX_DATA, entry.txBytes, |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 11189 | entry.txPackets); |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11190 | if (entry.set == NetworkStats.SET_DEFAULT) { // Background transfers |
| 11191 | u.noteNetworkActivityLocked(NETWORK_WIFI_BG_TX_DATA, entry.txBytes, |
| 11192 | entry.txPackets); |
| 11193 | } |
| 11194 | mNetworkByteActivityCounters[NETWORK_WIFI_TX_DATA].addCountLocked( |
| 11195 | entry.txBytes); |
| 11196 | mNetworkPacketActivityCounters[NETWORK_WIFI_TX_DATA].addCountLocked( |
| 11197 | entry.txPackets); |
| 11198 | |
| 11199 | txPackets.put(u.getUid(), entry.txPackets); |
| 11200 | |
| 11201 | // Sum the total number of packets so that the Tx Power can |
| 11202 | // be evenly distributed amongst the apps. |
| 11203 | totalTxPackets += entry.txPackets; |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 11204 | } |
Adam Lesinski | ba88e68 | 2015-12-08 12:06:55 -0800 | [diff] [blame] | 11205 | } |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11206 | mNetworkStatsPool.release(delta); |
| 11207 | delta = null; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 11208 | } |
| 11209 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11210 | if (info != null) { |
| 11211 | mHasWifiReporting = true; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 11212 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11213 | // Measured in mAms |
| 11214 | final long txTimeMs = info.getControllerTxTimeMillis(); |
| 11215 | final long rxTimeMs = info.getControllerRxTimeMillis(); |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 11216 | final long scanTimeMs = info.getControllerScanTimeMillis(); |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11217 | final long idleTimeMs = info.getControllerIdleTimeMillis(); |
| 11218 | final long totalTimeMs = txTimeMs + rxTimeMs + idleTimeMs; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 11219 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11220 | long leftOverRxTimeMs = rxTimeMs; |
| 11221 | long leftOverTxTimeMs = txTimeMs; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 11222 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 11223 | if (DEBUG_ENERGY) { |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11224 | Slog.d(TAG, "------ BEGIN WiFi power blaming ------"); |
| 11225 | Slog.d(TAG, " Tx Time: " + txTimeMs + " ms"); |
| 11226 | Slog.d(TAG, " Rx Time: " + rxTimeMs + " ms"); |
| 11227 | Slog.d(TAG, " Idle Time: " + idleTimeMs + " ms"); |
| 11228 | Slog.d(TAG, " Total Time: " + totalTimeMs + " ms"); |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 11229 | Slog.d(TAG, " Scan Time: " + scanTimeMs + " ms"); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 11230 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 11231 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11232 | long totalWifiLockTimeMs = 0; |
| 11233 | long totalScanTimeMs = 0; |
| 11234 | |
| 11235 | // On the first pass, collect some totals so that we can normalize power |
| 11236 | // calculations if we need to. |
| 11237 | final int uidStatsSize = mUidStats.size(); |
| 11238 | for (int i = 0; i < uidStatsSize; i++) { |
| 11239 | final Uid uid = mUidStats.valueAt(i); |
| 11240 | |
| 11241 | // Sum the total scan power for all apps. |
| 11242 | totalScanTimeMs += uid.mWifiScanTimer.getTimeSinceMarkLocked( |
| 11243 | elapsedRealtimeMs * 1000) / 1000; |
| 11244 | |
| 11245 | // Sum the total time holding wifi lock for all apps. |
| 11246 | totalWifiLockTimeMs += uid.mFullWifiLockTimer.getTimeSinceMarkLocked( |
| 11247 | elapsedRealtimeMs * 1000) / 1000; |
| 11248 | } |
| 11249 | |
| 11250 | if (DEBUG_ENERGY && totalScanTimeMs > rxTimeMs) { |
| 11251 | Slog.d(TAG, |
| 11252 | " !Estimated scan time > Actual rx time (" + totalScanTimeMs + " ms > " |
| 11253 | + rxTimeMs + " ms). Normalizing scan time."); |
| 11254 | } |
| 11255 | if (DEBUG_ENERGY && totalScanTimeMs > txTimeMs) { |
| 11256 | Slog.d(TAG, |
| 11257 | " !Estimated scan time > Actual tx time (" + totalScanTimeMs + " ms > " |
| 11258 | + txTimeMs + " ms). Normalizing scan time."); |
| 11259 | } |
| 11260 | |
| 11261 | // Actually assign and distribute power usage to apps. |
| 11262 | for (int i = 0; i < uidStatsSize; i++) { |
| 11263 | final Uid uid = mUidStats.valueAt(i); |
| 11264 | |
| 11265 | long scanTimeSinceMarkMs = uid.mWifiScanTimer.getTimeSinceMarkLocked( |
| 11266 | elapsedRealtimeMs * 1000) / 1000; |
| 11267 | if (scanTimeSinceMarkMs > 0) { |
| 11268 | // Set the new mark so that next time we get new data since this point. |
| 11269 | uid.mWifiScanTimer.setMark(elapsedRealtimeMs); |
| 11270 | |
| 11271 | long scanRxTimeSinceMarkMs = scanTimeSinceMarkMs; |
| 11272 | long scanTxTimeSinceMarkMs = scanTimeSinceMarkMs; |
| 11273 | |
| 11274 | // Our total scan time is more than the reported Tx/Rx time. |
| 11275 | // This is possible because the cost of a scan is approximate. |
| 11276 | // Let's normalize the result so that we evenly blame each app |
| 11277 | // scanning. |
| 11278 | // |
| 11279 | // This means that we may have apps that transmitted/received packets not be |
| 11280 | // blamed for this, but this is fine as scans are relatively more expensive. |
| 11281 | if (totalScanTimeMs > rxTimeMs) { |
| 11282 | scanRxTimeSinceMarkMs = (rxTimeMs * scanRxTimeSinceMarkMs) / |
| 11283 | totalScanTimeMs; |
| 11284 | } |
| 11285 | if (totalScanTimeMs > txTimeMs) { |
| 11286 | scanTxTimeSinceMarkMs = (txTimeMs * scanTxTimeSinceMarkMs) / |
| 11287 | totalScanTimeMs; |
| 11288 | } |
| 11289 | |
| 11290 | if (DEBUG_ENERGY) { |
| 11291 | Slog.d(TAG, " ScanTime for UID " + uid.getUid() + ": Rx:" |
| 11292 | + scanRxTimeSinceMarkMs + " ms Tx:" |
| 11293 | + scanTxTimeSinceMarkMs + " ms)"); |
| 11294 | } |
| 11295 | |
| 11296 | ControllerActivityCounterImpl activityCounter = |
| 11297 | uid.getOrCreateWifiControllerActivityLocked(); |
| 11298 | activityCounter.getRxTimeCounter().addCountLocked(scanRxTimeSinceMarkMs); |
| 11299 | activityCounter.getTxTimeCounters()[0].addCountLocked( |
| 11300 | scanTxTimeSinceMarkMs); |
| 11301 | leftOverRxTimeMs -= scanRxTimeSinceMarkMs; |
| 11302 | leftOverTxTimeMs -= scanTxTimeSinceMarkMs; |
| 11303 | } |
| 11304 | |
| 11305 | // Distribute evenly the power consumed while Idle to each app holding a WiFi |
| 11306 | // lock. |
| 11307 | final long wifiLockTimeSinceMarkMs = |
| 11308 | uid.mFullWifiLockTimer.getTimeSinceMarkLocked( |
| 11309 | elapsedRealtimeMs * 1000) / 1000; |
| 11310 | if (wifiLockTimeSinceMarkMs > 0) { |
| 11311 | // Set the new mark so that next time we get new data since this point. |
| 11312 | uid.mFullWifiLockTimer.setMark(elapsedRealtimeMs); |
| 11313 | |
| 11314 | final long myIdleTimeMs = (wifiLockTimeSinceMarkMs * idleTimeMs) |
| 11315 | / totalWifiLockTimeMs; |
| 11316 | if (DEBUG_ENERGY) { |
| 11317 | Slog.d(TAG, " IdleTime for UID " + uid.getUid() + ": " |
| 11318 | + myIdleTimeMs + " ms"); |
| 11319 | } |
| 11320 | uid.getOrCreateWifiControllerActivityLocked().getIdleTimeCounter() |
| 11321 | .addCountLocked(myIdleTimeMs); |
| 11322 | } |
| 11323 | } |
| 11324 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 11325 | if (DEBUG_ENERGY) { |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11326 | Slog.d(TAG, " New RxPower: " + leftOverRxTimeMs + " ms"); |
| 11327 | Slog.d(TAG, " New TxPower: " + leftOverTxTimeMs + " ms"); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 11328 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 11329 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11330 | // Distribute the remaining Tx power appropriately between all apps that transmitted |
| 11331 | // packets. |
| 11332 | for (int i = 0; i < txPackets.size(); i++) { |
| 11333 | final Uid uid = getUidStatsLocked(txPackets.keyAt(i)); |
| 11334 | final long myTxTimeMs = (txPackets.valueAt(i) * leftOverTxTimeMs) |
| 11335 | / totalTxPackets; |
| 11336 | if (DEBUG_ENERGY) { |
| 11337 | Slog.d(TAG, " TxTime for UID " + uid.getUid() + ": " + myTxTimeMs + " ms"); |
| 11338 | } |
| 11339 | uid.getOrCreateWifiControllerActivityLocked().getTxTimeCounters()[0] |
| 11340 | .addCountLocked(myTxTimeMs); |
| 11341 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 11342 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11343 | // Distribute the remaining Rx power appropriately between all apps that received |
| 11344 | // packets. |
| 11345 | for (int i = 0; i < rxPackets.size(); i++) { |
| 11346 | final Uid uid = getUidStatsLocked(rxPackets.keyAt(i)); |
| 11347 | final long myRxTimeMs = (rxPackets.valueAt(i) * leftOverRxTimeMs) |
| 11348 | / totalRxPackets; |
| 11349 | if (DEBUG_ENERGY) { |
| 11350 | Slog.d(TAG, " RxTime for UID " + uid.getUid() + ": " + myRxTimeMs + " ms"); |
| 11351 | } |
| 11352 | uid.getOrCreateWifiControllerActivityLocked().getRxTimeCounter() |
| 11353 | .addCountLocked(myRxTimeMs); |
| 11354 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 11355 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11356 | // Any left over power use will be picked up by the WiFi category in BatteryStatsHelper. |
| 11357 | |
| 11358 | |
| 11359 | // Update WiFi controller stats. |
| 11360 | mWifiActivity.getRxTimeCounter().addCountLocked(info.getControllerRxTimeMillis()); |
| 11361 | mWifiActivity.getTxTimeCounters()[0].addCountLocked( |
| 11362 | info.getControllerTxTimeMillis()); |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 11363 | mWifiActivity.getScanTimeCounter().addCountLocked( |
| 11364 | info.getControllerScanTimeMillis()); |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11365 | mWifiActivity.getIdleTimeCounter().addCountLocked( |
| 11366 | info.getControllerIdleTimeMillis()); |
| 11367 | |
| 11368 | // POWER_WIFI_CONTROLLER_OPERATING_VOLTAGE is measured in mV, so convert to V. |
| 11369 | final double opVolt = mPowerProfile.getAveragePower( |
| 11370 | PowerProfile.POWER_WIFI_CONTROLLER_OPERATING_VOLTAGE) / 1000.0; |
| 11371 | if (opVolt != 0) { |
| 11372 | // We store the power drain as mAms. |
| 11373 | mWifiActivity.getPowerCounter().addCountLocked( |
| 11374 | (long) (info.getControllerEnergyUsed() / opVolt)); |
| 11375 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 11376 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11377 | } |
| 11378 | } |
| 11379 | |
Chenjie Yu | 8908339 | 2018-01-11 14:53:31 -0800 | [diff] [blame] | 11380 | private ModemActivityInfo mLastModemActivityInfo = |
| 11381 | new ModemActivityInfo(0, 0, 0, new int[0], 0, 0); |
| 11382 | |
Chenjie Yu | a54e54d | 2018-02-14 20:12:52 -0800 | [diff] [blame] | 11383 | private ModemActivityInfo getDeltaModemActivityInfo(ModemActivityInfo activityInfo) { |
| 11384 | if (activityInfo == null) { |
| 11385 | return null; |
| 11386 | } |
| 11387 | int[] txTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS]; |
| 11388 | for (int i = 0; i < ModemActivityInfo.TX_POWER_LEVELS; i++) { |
| 11389 | txTimeMs[i] = activityInfo.getTxTimeMillis()[i] |
| 11390 | - mLastModemActivityInfo.getTxTimeMillis()[i]; |
| 11391 | } |
| 11392 | ModemActivityInfo deltaInfo = new ModemActivityInfo(activityInfo.getTimestamp(), |
| 11393 | activityInfo.getSleepTimeMillis() - mLastModemActivityInfo.getSleepTimeMillis(), |
| 11394 | activityInfo.getIdleTimeMillis() - mLastModemActivityInfo.getIdleTimeMillis(), |
| 11395 | txTimeMs, |
| 11396 | activityInfo.getRxTimeMillis() - mLastModemActivityInfo.getRxTimeMillis(), |
| 11397 | activityInfo.getEnergyUsed() - mLastModemActivityInfo.getEnergyUsed()); |
| 11398 | mLastModemActivityInfo = activityInfo; |
| 11399 | return deltaInfo; |
| 11400 | } |
| 11401 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11402 | /** |
| 11403 | * Distribute Cell radio energy info and network traffic to apps. |
| 11404 | */ |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11405 | public void updateMobileRadioState(@Nullable final ModemActivityInfo activityInfo) { |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 11406 | if (DEBUG_ENERGY) { |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 11407 | Slog.d(TAG, "Updating mobile radio stats with " + activityInfo); |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 11408 | } |
Chenjie Yu | a54e54d | 2018-02-14 20:12:52 -0800 | [diff] [blame] | 11409 | ModemActivityInfo deltaInfo = getDeltaModemActivityInfo(activityInfo); |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 11410 | |
Siddharth Ray | f5e796a | 2018-01-22 18:18:17 -0800 | [diff] [blame] | 11411 | // Add modem tx power to history. |
Chenjie Yu | a54e54d | 2018-02-14 20:12:52 -0800 | [diff] [blame] | 11412 | addModemTxPowerToHistory(deltaInfo); |
Siddharth Ray | f5e796a | 2018-01-22 18:18:17 -0800 | [diff] [blame] | 11413 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11414 | // 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] | 11415 | NetworkStats delta = null; |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11416 | synchronized (mModemNetworkLock) { |
| 11417 | final NetworkStats latestStats = readNetworkStatsLocked(mModemIfaces); |
| 11418 | if (latestStats != null) { |
| 11419 | delta = NetworkStats.subtract(latestStats, mLastModemNetworkStats, null, null, |
| 11420 | mNetworkStatsPool.acquire()); |
| 11421 | mNetworkStatsPool.release(mLastModemNetworkStats); |
| 11422 | mLastModemNetworkStats = latestStats; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 11423 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11424 | } |
| 11425 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11426 | synchronized (this) { |
| 11427 | if (!mOnBatteryInternal) { |
| 11428 | if (delta != null) { |
| 11429 | mNetworkStatsPool.release(delta); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 11430 | } |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11431 | return; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 11432 | } |
| 11433 | |
Chenjie Yu | a54e54d | 2018-02-14 20:12:52 -0800 | [diff] [blame] | 11434 | if (deltaInfo != null) { |
Siddharth Ray | 2038af8 | 2018-01-17 17:40:26 -0800 | [diff] [blame] | 11435 | mHasModemReporting = true; |
| 11436 | mModemActivity.getIdleTimeCounter().addCountLocked( |
Chenjie Yu | a54e54d | 2018-02-14 20:12:52 -0800 | [diff] [blame] | 11437 | deltaInfo.getIdleTimeMillis()); |
| 11438 | mModemActivity.getRxTimeCounter().addCountLocked(deltaInfo.getRxTimeMillis()); |
Siddharth Ray | 2038af8 | 2018-01-17 17:40:26 -0800 | [diff] [blame] | 11439 | for (int lvl = 0; lvl < ModemActivityInfo.TX_POWER_LEVELS; lvl++) { |
| 11440 | mModemActivity.getTxTimeCounters()[lvl] |
Chenjie Yu | a54e54d | 2018-02-14 20:12:52 -0800 | [diff] [blame] | 11441 | .addCountLocked(deltaInfo.getTxTimeMillis()[lvl]); |
Siddharth Ray | 2038af8 | 2018-01-17 17:40:26 -0800 | [diff] [blame] | 11442 | } |
| 11443 | |
| 11444 | // POWER_MODEM_CONTROLLER_OPERATING_VOLTAGE is measured in mV, so convert to V. |
| 11445 | final double opVolt = mPowerProfile.getAveragePower( |
| 11446 | PowerProfile.POWER_MODEM_CONTROLLER_OPERATING_VOLTAGE) / 1000.0; |
| 11447 | if (opVolt != 0) { |
| 11448 | double energyUsed = |
Chenjie Yu | a54e54d | 2018-02-14 20:12:52 -0800 | [diff] [blame] | 11449 | deltaInfo.getSleepTimeMillis() * |
Siddharth Ray | 2038af8 | 2018-01-17 17:40:26 -0800 | [diff] [blame] | 11450 | mPowerProfile.getAveragePower(PowerProfile.POWER_MODEM_CONTROLLER_SLEEP) |
Chenjie Yu | a54e54d | 2018-02-14 20:12:52 -0800 | [diff] [blame] | 11451 | + deltaInfo.getIdleTimeMillis() * |
Siddharth Ray | 2038af8 | 2018-01-17 17:40:26 -0800 | [diff] [blame] | 11452 | mPowerProfile.getAveragePower(PowerProfile.POWER_MODEM_CONTROLLER_IDLE) |
Chenjie Yu | a54e54d | 2018-02-14 20:12:52 -0800 | [diff] [blame] | 11453 | + deltaInfo.getRxTimeMillis() * |
Siddharth Ray | 2038af8 | 2018-01-17 17:40:26 -0800 | [diff] [blame] | 11454 | mPowerProfile.getAveragePower(PowerProfile.POWER_MODEM_CONTROLLER_RX); |
Chenjie Yu | a54e54d | 2018-02-14 20:12:52 -0800 | [diff] [blame] | 11455 | int[] txTimeMs = deltaInfo.getTxTimeMillis(); |
Chenjie Yu | 8908339 | 2018-01-11 14:53:31 -0800 | [diff] [blame] | 11456 | for (int i = 0; i < Math.min(txTimeMs.length, |
Chenjie Yu | a54e54d | 2018-02-14 20:12:52 -0800 | [diff] [blame] | 11457 | SignalStrength.NUM_SIGNAL_STRENGTH_BINS); i++) { |
Chenjie Yu | 8908339 | 2018-01-11 14:53:31 -0800 | [diff] [blame] | 11458 | energyUsed += txTimeMs[i] * mPowerProfile.getAveragePower( |
Chenjie Yu | a54e54d | 2018-02-14 20:12:52 -0800 | [diff] [blame] | 11459 | PowerProfile.POWER_MODEM_CONTROLLER_TX, i); |
Siddharth Ray | 2038af8 | 2018-01-17 17:40:26 -0800 | [diff] [blame] | 11460 | } |
| 11461 | |
| 11462 | // We store the power drain as mAms. |
| 11463 | mModemActivity.getPowerCounter().addCountLocked((long) energyUsed); |
| 11464 | } |
| 11465 | } |
| 11466 | |
Adam Lesinski | b3a1bad | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11467 | final long elapsedRealtimeMs = mClocks.elapsedRealtime(); |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11468 | long radioTime = mMobileRadioActivePerAppTimer.getTimeSinceMarkLocked( |
| 11469 | elapsedRealtimeMs * 1000); |
| 11470 | mMobileRadioActivePerAppTimer.setMark(elapsedRealtimeMs); |
| 11471 | |
| 11472 | long totalRxPackets = 0; |
| 11473 | long totalTxPackets = 0; |
| 11474 | if (delta != null) { |
| 11475 | NetworkStats.Entry entry = new NetworkStats.Entry(); |
| 11476 | final int size = delta.size(); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 11477 | for (int i = 0; i < size; i++) { |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11478 | entry = delta.getValues(i, entry); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 11479 | if (entry.rxPackets == 0 && entry.txPackets == 0) { |
| 11480 | continue; |
| 11481 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11482 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11483 | if (DEBUG_ENERGY) { |
| 11484 | Slog.d(TAG, "Mobile uid " + entry.uid + ": delta rx=" + entry.rxBytes |
| 11485 | + " tx=" + entry.txBytes + " rxPackets=" + entry.rxPackets |
| 11486 | + " txPackets=" + entry.txPackets); |
| 11487 | } |
| 11488 | |
| 11489 | totalRxPackets += entry.rxPackets; |
| 11490 | totalTxPackets += entry.txPackets; |
| 11491 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 11492 | final Uid u = getUidStatsLocked(mapUid(entry.uid)); |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11493 | u.noteNetworkActivityLocked(NETWORK_MOBILE_RX_DATA, entry.rxBytes, |
| 11494 | entry.rxPackets); |
| 11495 | u.noteNetworkActivityLocked(NETWORK_MOBILE_TX_DATA, entry.txBytes, |
| 11496 | entry.txPackets); |
| 11497 | if (entry.set == NetworkStats.SET_DEFAULT) { // Background transfers |
| 11498 | u.noteNetworkActivityLocked(NETWORK_MOBILE_BG_RX_DATA, |
| 11499 | entry.rxBytes, entry.rxPackets); |
| 11500 | u.noteNetworkActivityLocked(NETWORK_MOBILE_BG_TX_DATA, |
| 11501 | entry.txBytes, entry.txPackets); |
| 11502 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 11503 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11504 | mNetworkByteActivityCounters[NETWORK_MOBILE_RX_DATA].addCountLocked( |
| 11505 | entry.rxBytes); |
| 11506 | mNetworkByteActivityCounters[NETWORK_MOBILE_TX_DATA].addCountLocked( |
| 11507 | entry.txBytes); |
| 11508 | mNetworkPacketActivityCounters[NETWORK_MOBILE_RX_DATA].addCountLocked( |
| 11509 | entry.rxPackets); |
| 11510 | mNetworkPacketActivityCounters[NETWORK_MOBILE_TX_DATA].addCountLocked( |
| 11511 | entry.txPackets); |
| 11512 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 11513 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11514 | // Now distribute proportional blame to the apps that did networking. |
| 11515 | long totalPackets = totalRxPackets + totalTxPackets; |
| 11516 | if (totalPackets > 0) { |
| 11517 | for (int i = 0; i < size; i++) { |
| 11518 | entry = delta.getValues(i, entry); |
| 11519 | if (entry.rxPackets == 0 && entry.txPackets == 0) { |
| 11520 | continue; |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 11521 | } |
| 11522 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11523 | final Uid u = getUidStatsLocked(mapUid(entry.uid)); |
| 11524 | |
| 11525 | // Distribute total radio active time in to this app. |
| 11526 | final long appPackets = entry.rxPackets + entry.txPackets; |
| 11527 | final long appRadioTime = (radioTime * appPackets) / totalPackets; |
| 11528 | u.noteMobileRadioActiveTimeLocked(appRadioTime); |
| 11529 | |
| 11530 | // Remove this app from the totals, so that we don't lose any time |
| 11531 | // due to rounding. |
| 11532 | radioTime -= appRadioTime; |
| 11533 | totalPackets -= appPackets; |
| 11534 | |
Chenjie Yu | a54e54d | 2018-02-14 20:12:52 -0800 | [diff] [blame] | 11535 | if (deltaInfo != null) { |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11536 | ControllerActivityCounterImpl activityCounter = |
| 11537 | u.getOrCreateModemControllerActivityLocked(); |
| 11538 | if (totalRxPackets > 0 && entry.rxPackets > 0) { |
Chenjie Yu | a54e54d | 2018-02-14 20:12:52 -0800 | [diff] [blame] | 11539 | final long rxMs = (entry.rxPackets * deltaInfo.getRxTimeMillis()) |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11540 | / totalRxPackets; |
| 11541 | activityCounter.getRxTimeCounter().addCountLocked(rxMs); |
| 11542 | } |
| 11543 | |
| 11544 | if (totalTxPackets > 0 && entry.txPackets > 0) { |
| 11545 | for (int lvl = 0; lvl < ModemActivityInfo.TX_POWER_LEVELS; lvl++) { |
| 11546 | long txMs = |
Chenjie Yu | a54e54d | 2018-02-14 20:12:52 -0800 | [diff] [blame] | 11547 | entry.txPackets * deltaInfo.getTxTimeMillis()[lvl]; |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11548 | txMs /= totalTxPackets; |
| 11549 | activityCounter.getTxTimeCounters()[lvl].addCountLocked(txMs); |
| 11550 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 11551 | } |
| 11552 | } |
| 11553 | } |
| 11554 | } |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11555 | |
| 11556 | if (radioTime > 0) { |
| 11557 | // Whoops, there is some radio time we can't blame on an app! |
| 11558 | mMobileRadioActiveUnknownTime.addCountLocked(radioTime); |
| 11559 | mMobileRadioActiveUnknownCount.addCountLocked(1); |
| 11560 | } |
| 11561 | |
| 11562 | mNetworkStatsPool.release(delta); |
| 11563 | delta = null; |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 11564 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11565 | } |
| 11566 | } |
| 11567 | |
Chenjie Yu | 8908339 | 2018-01-11 14:53:31 -0800 | [diff] [blame] | 11568 | // Cache last value for comparison. |
| 11569 | private BluetoothActivityEnergyInfo mLastBluetoothActivityEnergyInfo = |
| 11570 | new BluetoothActivityEnergyInfo(0, 0, 0, 0, 0, 0); |
| 11571 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11572 | /** |
Siddharth Ray | f5e796a | 2018-01-22 18:18:17 -0800 | [diff] [blame] | 11573 | * Add modem tx power to history |
| 11574 | * Device is said to be in high cellular transmit power when it has spent most of the transmit |
| 11575 | * time at the highest power level. |
| 11576 | * @param activityInfo |
| 11577 | */ |
| 11578 | private void addModemTxPowerToHistory(final ModemActivityInfo activityInfo) { |
| 11579 | if (activityInfo == null) { |
| 11580 | return; |
| 11581 | } |
| 11582 | int[] txTimeMs = activityInfo.getTxTimeMillis(); |
| 11583 | if (txTimeMs == null || txTimeMs.length != ModemActivityInfo.TX_POWER_LEVELS) { |
| 11584 | return; |
| 11585 | } |
| 11586 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 11587 | final long uptime = mClocks.uptimeMillis(); |
| 11588 | int levelMaxTimeSpent = 0; |
| 11589 | for (int i = 1; i < txTimeMs.length; i++) { |
| 11590 | if (txTimeMs[i] > txTimeMs[levelMaxTimeSpent]) { |
| 11591 | levelMaxTimeSpent = i; |
| 11592 | } |
| 11593 | } |
| 11594 | if (levelMaxTimeSpent == ModemActivityInfo.TX_POWER_LEVELS - 1) { |
| 11595 | if (!mIsCellularTxPowerHigh) { |
| 11596 | mHistoryCur.states2 |= HistoryItem.STATE2_CELLULAR_HIGH_TX_POWER_FLAG; |
| 11597 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 11598 | mIsCellularTxPowerHigh = true; |
| 11599 | } |
| 11600 | return; |
| 11601 | } |
| 11602 | if (mIsCellularTxPowerHigh) { |
| 11603 | mHistoryCur.states2 &= ~HistoryItem.STATE2_CELLULAR_HIGH_TX_POWER_FLAG; |
| 11604 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 11605 | mIsCellularTxPowerHigh = false; |
| 11606 | } |
| 11607 | return; |
| 11608 | } |
| 11609 | |
| 11610 | /** |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11611 | * Distribute Bluetooth energy info and network traffic to apps. |
| 11612 | * @param info The energy information from the bluetooth controller. |
| 11613 | */ |
| 11614 | public void updateBluetoothStateLocked(@Nullable final BluetoothActivityEnergyInfo info) { |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 11615 | if (DEBUG_ENERGY) { |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 11616 | Slog.d(TAG, "Updating bluetooth stats: " + info); |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 11617 | } |
| 11618 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 11619 | if (info == null || !mOnBatteryInternal) { |
| 11620 | return; |
| 11621 | } |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 11622 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 11623 | mHasBluetoothReporting = true; |
| 11624 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 11625 | final long elapsedRealtimeMs = mClocks.elapsedRealtime(); |
Chenjie Yu | 8908339 | 2018-01-11 14:53:31 -0800 | [diff] [blame] | 11626 | final long rxTimeMs = info.getControllerRxTimeMillis() - |
| 11627 | mLastBluetoothActivityEnergyInfo.getControllerRxTimeMillis(); |
| 11628 | final long txTimeMs = info.getControllerTxTimeMillis() - |
| 11629 | mLastBluetoothActivityEnergyInfo.getControllerTxTimeMillis(); |
| 11630 | final long idleTimeMs = info.getControllerIdleTimeMillis() - |
| 11631 | mLastBluetoothActivityEnergyInfo.getControllerIdleTimeMillis(); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 11632 | if (DEBUG_ENERGY) { |
| 11633 | Slog.d(TAG, "------ BEGIN BLE power blaming ------"); |
| 11634 | Slog.d(TAG, " Tx Time: " + txTimeMs + " ms"); |
| 11635 | Slog.d(TAG, " Rx Time: " + rxTimeMs + " ms"); |
Chenjie Yu | 8908339 | 2018-01-11 14:53:31 -0800 | [diff] [blame] | 11636 | Slog.d(TAG, " Idle Time: " + idleTimeMs + " ms"); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 11637 | } |
| 11638 | |
| 11639 | long totalScanTimeMs = 0; |
| 11640 | |
| 11641 | final int uidCount = mUidStats.size(); |
| 11642 | for (int i = 0; i < uidCount; i++) { |
| 11643 | final Uid u = mUidStats.valueAt(i); |
| 11644 | if (u.mBluetoothScanTimer == null) { |
| 11645 | continue; |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 11646 | } |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 11647 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 11648 | totalScanTimeMs += u.mBluetoothScanTimer.getTimeSinceMarkLocked( |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 11649 | elapsedRealtimeMs * 1000) / 1000; |
| 11650 | } |
| 11651 | |
| 11652 | final boolean normalizeScanRxTime = (totalScanTimeMs > rxTimeMs); |
| 11653 | final boolean normalizeScanTxTime = (totalScanTimeMs > txTimeMs); |
| 11654 | |
| 11655 | if (DEBUG_ENERGY) { |
| 11656 | Slog.d(TAG, "Normalizing scan power for RX=" + normalizeScanRxTime |
| 11657 | + " TX=" + normalizeScanTxTime); |
| 11658 | } |
| 11659 | |
| 11660 | long leftOverRxTimeMs = rxTimeMs; |
| 11661 | long leftOverTxTimeMs = txTimeMs; |
| 11662 | |
| 11663 | for (int i = 0; i < uidCount; i++) { |
| 11664 | final Uid u = mUidStats.valueAt(i); |
| 11665 | if (u.mBluetoothScanTimer == null) { |
| 11666 | continue; |
| 11667 | } |
| 11668 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 11669 | long scanTimeSinceMarkMs = u.mBluetoothScanTimer.getTimeSinceMarkLocked( |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 11670 | elapsedRealtimeMs * 1000) / 1000; |
| 11671 | if (scanTimeSinceMarkMs > 0) { |
| 11672 | // Set the new mark so that next time we get new data since this point. |
| 11673 | u.mBluetoothScanTimer.setMark(elapsedRealtimeMs); |
| 11674 | |
| 11675 | long scanTimeRxSinceMarkMs = scanTimeSinceMarkMs; |
| 11676 | long scanTimeTxSinceMarkMs = scanTimeSinceMarkMs; |
| 11677 | |
| 11678 | if (normalizeScanRxTime) { |
| 11679 | // Scan time is longer than the total rx time in the controller, |
| 11680 | // so distribute the scan time proportionately. This means regular traffic |
| 11681 | // will not blamed, but scans are more expensive anyways. |
| 11682 | scanTimeRxSinceMarkMs = (rxTimeMs * scanTimeRxSinceMarkMs) / totalScanTimeMs; |
| 11683 | } |
| 11684 | |
| 11685 | if (normalizeScanTxTime) { |
| 11686 | // Scan time is longer than the total tx time in the controller, |
| 11687 | // so distribute the scan time proportionately. This means regular traffic |
| 11688 | // will not blamed, but scans are more expensive anyways. |
| 11689 | scanTimeTxSinceMarkMs = (txTimeMs * scanTimeTxSinceMarkMs) / totalScanTimeMs; |
| 11690 | } |
| 11691 | |
| 11692 | final ControllerActivityCounterImpl counter = |
| 11693 | u.getOrCreateBluetoothControllerActivityLocked(); |
| 11694 | counter.getRxTimeCounter().addCountLocked(scanTimeRxSinceMarkMs); |
| 11695 | counter.getTxTimeCounters()[0].addCountLocked(scanTimeTxSinceMarkMs); |
| 11696 | |
| 11697 | leftOverRxTimeMs -= scanTimeRxSinceMarkMs; |
| 11698 | leftOverTxTimeMs -= scanTimeTxSinceMarkMs; |
| 11699 | } |
| 11700 | } |
| 11701 | |
| 11702 | if (DEBUG_ENERGY) { |
| 11703 | Slog.d(TAG, "Left over time for traffic RX=" + leftOverRxTimeMs |
| 11704 | + " TX=" + leftOverTxTimeMs); |
| 11705 | } |
| 11706 | |
| 11707 | // |
| 11708 | // Now distribute blame to apps that did bluetooth traffic. |
| 11709 | // |
| 11710 | |
| 11711 | long totalTxBytes = 0; |
| 11712 | long totalRxBytes = 0; |
| 11713 | |
| 11714 | final UidTraffic[] uidTraffic = info.getUidTraffic(); |
Chenjie Yu | 8908339 | 2018-01-11 14:53:31 -0800 | [diff] [blame] | 11715 | final UidTraffic[] lastUidTraffic = mLastBluetoothActivityEnergyInfo.getUidTraffic(); |
| 11716 | final ArrayList<UidTraffic> deltaTraffic = new ArrayList<>(); |
| 11717 | int m = 0, n = 0; |
| 11718 | for (; m < uidTraffic.length && n < lastUidTraffic.length; m++) { |
| 11719 | final UidTraffic traffic = uidTraffic[m]; |
| 11720 | final UidTraffic lastTraffic = lastUidTraffic[n]; |
| 11721 | if (traffic.getUid() == lastTraffic.getUid()) { |
| 11722 | deltaTraffic.add(new UidTraffic(traffic.getUid(), |
| 11723 | traffic.getRxBytes() - lastTraffic.getRxBytes(), |
| 11724 | traffic.getTxBytes() - lastTraffic.getTxBytes())); |
| 11725 | n++; |
| 11726 | } |
| 11727 | } |
| 11728 | for (; m < uidTraffic.length; m ++) { |
| 11729 | deltaTraffic.add(uidTraffic[m]); |
| 11730 | } |
| 11731 | |
| 11732 | for (int i = 0, j = 0; i < deltaTraffic.size(); i++) { |
| 11733 | final UidTraffic traffic = deltaTraffic.get(i); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 11734 | |
| 11735 | // Add to the global counters. |
| 11736 | mNetworkByteActivityCounters[NETWORK_BT_RX_DATA].addCountLocked( |
| 11737 | traffic.getRxBytes()); |
| 11738 | mNetworkByteActivityCounters[NETWORK_BT_TX_DATA].addCountLocked( |
| 11739 | traffic.getTxBytes()); |
| 11740 | |
| 11741 | // Add to the UID counters. |
| 11742 | final Uid u = getUidStatsLocked(mapUid(traffic.getUid())); |
| 11743 | u.noteNetworkActivityLocked(NETWORK_BT_RX_DATA, traffic.getRxBytes(), 0); |
| 11744 | u.noteNetworkActivityLocked(NETWORK_BT_TX_DATA, traffic.getTxBytes(), 0); |
| 11745 | |
| 11746 | // Calculate the total traffic. |
| 11747 | totalTxBytes += traffic.getTxBytes(); |
| 11748 | totalRxBytes += traffic.getRxBytes(); |
| 11749 | } |
| 11750 | |
| 11751 | if ((totalTxBytes != 0 || totalRxBytes != 0) && |
| 11752 | (leftOverRxTimeMs != 0 || leftOverTxTimeMs != 0)) { |
Chenjie Yu | 8908339 | 2018-01-11 14:53:31 -0800 | [diff] [blame] | 11753 | for (int i = 0; i < deltaTraffic.size(); i++) { |
| 11754 | final UidTraffic traffic = deltaTraffic.get(i); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 11755 | |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 11756 | final Uid u = getUidStatsLocked(mapUid(traffic.getUid())); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 11757 | final ControllerActivityCounterImpl counter = |
| 11758 | u.getOrCreateBluetoothControllerActivityLocked(); |
| 11759 | |
| 11760 | if (totalRxBytes > 0 && traffic.getRxBytes() > 0) { |
| 11761 | final long timeRxMs = (leftOverRxTimeMs * traffic.getRxBytes()) / totalRxBytes; |
| 11762 | |
| 11763 | if (DEBUG_ENERGY) { |
| 11764 | Slog.d(TAG, "UID=" + traffic.getUid() + " rx_bytes=" + traffic.getRxBytes() |
| 11765 | + " rx_time=" + timeRxMs); |
| 11766 | } |
| 11767 | counter.getRxTimeCounter().addCountLocked(timeRxMs); |
| 11768 | leftOverRxTimeMs -= timeRxMs; |
| 11769 | } |
| 11770 | |
| 11771 | if (totalTxBytes > 0 && traffic.getTxBytes() > 0) { |
| 11772 | final long timeTxMs = (leftOverTxTimeMs * traffic.getTxBytes()) / totalTxBytes; |
| 11773 | |
| 11774 | if (DEBUG_ENERGY) { |
| 11775 | Slog.d(TAG, "UID=" + traffic.getUid() + " tx_bytes=" + traffic.getTxBytes() |
| 11776 | + " tx_time=" + timeTxMs); |
| 11777 | } |
| 11778 | |
| 11779 | counter.getTxTimeCounters()[0].addCountLocked(timeTxMs); |
| 11780 | leftOverTxTimeMs -= timeTxMs; |
| 11781 | } |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 11782 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11783 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 11784 | |
Chenjie Yu | 8908339 | 2018-01-11 14:53:31 -0800 | [diff] [blame] | 11785 | mBluetoothActivity.getRxTimeCounter().addCountLocked(rxTimeMs); |
| 11786 | mBluetoothActivity.getTxTimeCounters()[0].addCountLocked(txTimeMs); |
| 11787 | mBluetoothActivity.getIdleTimeCounter().addCountLocked(idleTimeMs); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 11788 | |
| 11789 | // POWER_BLUETOOTH_CONTROLLER_OPERATING_VOLTAGE is measured in mV, so convert to V. |
| 11790 | final double opVolt = mPowerProfile.getAveragePower( |
| 11791 | PowerProfile.POWER_BLUETOOTH_CONTROLLER_OPERATING_VOLTAGE) / 1000.0; |
| 11792 | if (opVolt != 0) { |
| 11793 | // We store the power drain as mAms. |
| 11794 | mBluetoothActivity.getPowerCounter().addCountLocked( |
Chenjie Yu | 8908339 | 2018-01-11 14:53:31 -0800 | [diff] [blame] | 11795 | (long) ((info.getControllerEnergyUsed() - |
| 11796 | mLastBluetoothActivityEnergyInfo.getControllerEnergyUsed() )/ opVolt)); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 11797 | } |
Chenjie Yu | 8908339 | 2018-01-11 14:53:31 -0800 | [diff] [blame] | 11798 | mLastBluetoothActivityEnergyInfo = info; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11799 | } |
| 11800 | |
| 11801 | /** |
Bookatz | 0b8a050 | 2017-09-13 11:51:52 -0700 | [diff] [blame] | 11802 | * Read and record Resource Power Manager (RPM) state and voter times. |
| 11803 | * If RPM stats were fetched more recently than RPM_STATS_UPDATE_FREQ_MS ago, uses the old data |
| 11804 | * instead of fetching it anew. |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 11805 | */ |
| 11806 | public void updateRpmStatsLocked() { |
| 11807 | if (mPlatformIdleStateCallback == null) return; |
Bookatz | 0b8a050 | 2017-09-13 11:51:52 -0700 | [diff] [blame] | 11808 | long now = SystemClock.elapsedRealtime(); |
| 11809 | if (now - mLastRpmStatsUpdateTimeMs >= RPM_STATS_UPDATE_FREQ_MS) { |
| 11810 | mPlatformIdleStateCallback.fillLowPowerStats(mTmpRpmStats); |
| 11811 | mLastRpmStatsUpdateTimeMs = now; |
| 11812 | } |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 11813 | |
| 11814 | for (Map.Entry<String, RpmStats.PowerStatePlatformSleepState> pstate |
| 11815 | : mTmpRpmStats.mPlatformLowPowerStats.entrySet()) { |
| 11816 | |
| 11817 | // Update values for this platform state. |
| 11818 | final String pName = pstate.getKey(); |
| 11819 | final long pTimeUs = pstate.getValue().mTimeMs * 1000; |
| 11820 | final int pCount = pstate.getValue().mCount; |
| 11821 | getRpmTimerLocked(pName).update(pTimeUs, pCount); |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 11822 | if (SCREEN_OFF_RPM_STATS_ENABLED) { |
| 11823 | getScreenOffRpmTimerLocked(pName).update(pTimeUs, pCount); |
| 11824 | } |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 11825 | |
| 11826 | // Update values for each voter of this platform state. |
| 11827 | for (Map.Entry<String, RpmStats.PowerStateElement> voter |
| 11828 | : pstate.getValue().mVoters.entrySet()) { |
| 11829 | final String vName = pName + "." + voter.getKey(); |
| 11830 | final long vTimeUs = voter.getValue().mTimeMs * 1000; |
| 11831 | final int vCount = voter.getValue().mCount; |
| 11832 | getRpmTimerLocked(vName).update(vTimeUs, vCount); |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 11833 | if (SCREEN_OFF_RPM_STATS_ENABLED) { |
| 11834 | getScreenOffRpmTimerLocked(vName).update(vTimeUs, vCount); |
| 11835 | } |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 11836 | } |
| 11837 | } |
| 11838 | |
| 11839 | for (Map.Entry<String, RpmStats.PowerStateSubsystem> subsys |
| 11840 | : mTmpRpmStats.mSubsystemLowPowerStats.entrySet()) { |
| 11841 | |
| 11842 | final String subsysName = subsys.getKey(); |
| 11843 | for (Map.Entry<String, RpmStats.PowerStateElement> sstate |
| 11844 | : subsys.getValue().mStates.entrySet()) { |
| 11845 | final String name = subsysName + "." + sstate.getKey(); |
| 11846 | final long timeUs = sstate.getValue().mTimeMs * 1000; |
| 11847 | final int count = sstate.getValue().mCount; |
| 11848 | getRpmTimerLocked(name).update(timeUs, count); |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 11849 | if (SCREEN_OFF_RPM_STATS_ENABLED) { |
| 11850 | getScreenOffRpmTimerLocked(name).update(timeUs, count); |
| 11851 | } |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 11852 | } |
| 11853 | } |
| 11854 | } |
| 11855 | |
| 11856 | /** |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11857 | * Read and distribute kernel wake lock use across apps. |
| 11858 | */ |
| 11859 | public void updateKernelWakelocksLocked() { |
| 11860 | final KernelWakelockStats wakelockStats = mKernelWakelockReader.readKernelWakelockStats( |
| 11861 | mTmpWakelockStats); |
| 11862 | if (wakelockStats == null) { |
| 11863 | // Not crashing might make board bringup easier. |
| 11864 | Slog.w(TAG, "Couldn't get kernel wake lock stats"); |
| 11865 | return; |
| 11866 | } |
| 11867 | |
| 11868 | for (Map.Entry<String, KernelWakelockStats.Entry> ent : wakelockStats.entrySet()) { |
| 11869 | String name = ent.getKey(); |
| 11870 | KernelWakelockStats.Entry kws = ent.getValue(); |
| 11871 | |
| 11872 | SamplingTimer kwlt = mKernelWakelockStats.get(name); |
| 11873 | if (kwlt == null) { |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 11874 | kwlt = new SamplingTimer(mClocks, mOnBatteryScreenOffTimeBase); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11875 | mKernelWakelockStats.put(name, kwlt); |
| 11876 | } |
Adam Lesinski | d84ad30 | 2016-05-17 18:31:02 -0700 | [diff] [blame] | 11877 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 11878 | kwlt.update(kws.mTotalTime, kws.mCount); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11879 | kwlt.setUpdateVersion(kws.mVersion); |
| 11880 | } |
| 11881 | |
Adam Lesinski | fbabe7d | 2015-08-03 14:37:38 -0700 | [diff] [blame] | 11882 | int numWakelocksSetStale = 0; |
Adam Lesinski | d84ad30 | 2016-05-17 18:31:02 -0700 | [diff] [blame] | 11883 | // Set timers to stale if they didn't appear in /d/wakeup_sources (or /proc/wakelocks) |
| 11884 | // this time. |
| 11885 | for (Map.Entry<String, SamplingTimer> ent : mKernelWakelockStats.entrySet()) { |
| 11886 | SamplingTimer st = ent.getValue(); |
| 11887 | if (st.getUpdateVersion() != wakelockStats.kernelWakelockVersion) { |
| 11888 | st.endSample(); |
| 11889 | numWakelocksSetStale++; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11890 | } |
| 11891 | } |
Adam Lesinski | fbabe7d | 2015-08-03 14:37:38 -0700 | [diff] [blame] | 11892 | |
Adam Lesinski | d84ad30 | 2016-05-17 18:31:02 -0700 | [diff] [blame] | 11893 | // Record whether we've seen a non-zero time (for debugging b/22716723). |
| 11894 | if (wakelockStats.isEmpty()) { |
Adam Lesinski | fbabe7d | 2015-08-03 14:37:38 -0700 | [diff] [blame] | 11895 | Slog.wtf(TAG, "All kernel wakelocks had time of zero"); |
| 11896 | } |
| 11897 | |
| 11898 | if (numWakelocksSetStale == mKernelWakelockStats.size()) { |
| 11899 | Slog.wtf(TAG, "All kernel wakelocks were set stale. new version=" + |
| 11900 | wakelockStats.kernelWakelockVersion); |
| 11901 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11902 | } |
| 11903 | |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 11904 | // We use an anonymous class to access these variables, |
| 11905 | // so they can't live on the stack or they'd have to be |
| 11906 | // final MutableLong objects (more allocations). |
| 11907 | // Used in updateCpuTimeLocked(). |
| 11908 | long mTempTotalCpuUserTimeUs; |
| 11909 | long mTempTotalCpuSystemTimeUs; |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 11910 | long[][] mWakeLockAllocationsUs; |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 11911 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 11912 | /** |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 11913 | * Reads the newest memory stats from the kernel. |
| 11914 | */ |
| 11915 | public void updateKernelMemoryBandwidthLocked() { |
| 11916 | mKernelMemoryBandwidthStats.updateStats(); |
| 11917 | LongSparseLongArray bandwidthEntries = mKernelMemoryBandwidthStats.getBandwidthEntries(); |
| 11918 | final int bandwidthEntryCount = bandwidthEntries.size(); |
| 11919 | int index; |
| 11920 | for (int i = 0; i < bandwidthEntryCount; i++) { |
| 11921 | SamplingTimer timer; |
| 11922 | if ((index = mKernelMemoryStats.indexOfKey(bandwidthEntries.keyAt(i))) >= 0) { |
| 11923 | timer = mKernelMemoryStats.valueAt(index); |
| 11924 | } else { |
| 11925 | timer = new SamplingTimer(mClocks, mOnBatteryTimeBase); |
| 11926 | mKernelMemoryStats.put(bandwidthEntries.keyAt(i), timer); |
| 11927 | } |
| 11928 | timer.update(bandwidthEntries.valueAt(i), 1); |
| 11929 | if (DEBUG_MEMORY) { |
| 11930 | Slog.d(TAG, String.format("Added entry %d and updated timer to: " |
| 11931 | + "mUnpluggedReportedTotalTime %d size %d", bandwidthEntries.keyAt(i), |
| 11932 | mKernelMemoryStats.get( |
| 11933 | bandwidthEntries.keyAt(i)).mUnpluggedReportedTotalTime, |
| 11934 | mKernelMemoryStats.size())); |
| 11935 | } |
| 11936 | } |
| 11937 | } |
| 11938 | |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 11939 | public boolean isOnBatteryLocked() { |
| 11940 | return mOnBatteryTimeBase.isRunning(); |
| 11941 | } |
| 11942 | |
| 11943 | public boolean isOnBatteryScreenOffLocked() { |
| 11944 | return mOnBatteryScreenOffTimeBase.isRunning(); |
| 11945 | } |
| 11946 | |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 11947 | /** |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 11948 | * Read and distribute CPU usage across apps. If their are partial wakelocks being held |
| 11949 | * and we are on battery with screen off, we give more of the cpu time to those apps holding |
| 11950 | * 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] | 11951 | * It's possible this will be invoked after the internal battery/screen states are updated, so |
| 11952 | * passing the appropriate battery/screen states to try attribute the cpu times to correct |
| 11953 | * buckets. |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 11954 | */ |
Andreas Gampe | 3f24e69 | 2018-02-05 13:24:28 -0800 | [diff] [blame] | 11955 | @GuardedBy("this") |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 11956 | public void updateCpuTimeLocked(boolean onBattery, boolean onBatteryScreenOff) { |
Adam Lesinski | 52290c9c | 2015-09-21 16:54:52 -0700 | [diff] [blame] | 11957 | if (mPowerProfile == null) { |
| 11958 | return; |
| 11959 | } |
| 11960 | |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 11961 | if (DEBUG_ENERGY_CPU) { |
| 11962 | Slog.d(TAG, "!Cpu updating!"); |
| 11963 | } |
| 11964 | |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 11965 | if (mCpuFreqs == null) { |
| 11966 | mCpuFreqs = mKernelUidCpuFreqTimeReader.readFreqs(mPowerProfile); |
| 11967 | } |
| 11968 | |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 11969 | // Calculate the wakelocks we have to distribute amongst. The system is excluded as it is |
| 11970 | // usually holding the wakelock on behalf of an app. |
| 11971 | // And Only distribute cpu power to wakelocks if the screen is off and we're on battery. |
| 11972 | ArrayList<StopwatchTimer> partialTimersToConsider = null; |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 11973 | if (onBatteryScreenOff) { |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 11974 | partialTimersToConsider = new ArrayList<>(); |
| 11975 | for (int i = mPartialTimers.size() - 1; i >= 0; --i) { |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 11976 | final StopwatchTimer timer = mPartialTimers.get(i); |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 11977 | // Since the collection and blaming of wakelocks can be scheduled to run after |
| 11978 | // some delay, the mPartialTimers list may have new entries. We can't blame |
| 11979 | // the newly added timer for past cpu time, so we only consider timers that |
| 11980 | // were present for one round of collection. Once a timer has gone through |
| 11981 | // a round of collection, its mInList field is set to true. |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 11982 | if (timer.mInList && timer.mUid != null && timer.mUid.mUid != Process.SYSTEM_UID) { |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 11983 | partialTimersToConsider.add(timer); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 11984 | } |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 11985 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 11986 | } |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 11987 | markPartialTimersAsEligible(); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 11988 | |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 11989 | // When the battery is not on, we don't attribute the cpu times to any timers but we still |
| 11990 | // need to take the snapshots. |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 11991 | if (!onBattery) { |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 11992 | mKernelUidCpuTimeReader.readDelta(null); |
| 11993 | mKernelUidCpuFreqTimeReader.readDelta(null); |
Mike Ma | fae87da | 2018-01-19 20:07:20 -0800 | [diff] [blame] | 11994 | if (mConstants.TRACK_CPU_ACTIVE_CLUSTER_TIME) { |
| 11995 | mKernelUidCpuActiveTimeReader.readDelta(null); |
| 11996 | mKernelUidCpuClusterTimeReader.readDelta(null); |
| 11997 | } |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 11998 | for (int cluster = mKernelCpuSpeedReaders.length - 1; cluster >= 0; --cluster) { |
| 11999 | mKernelCpuSpeedReaders[cluster].readDelta(); |
| 12000 | } |
| 12001 | return; |
| 12002 | } |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 12003 | |
Suprabh Shukla | e6e723d | 2017-06-14 16:14:43 -0700 | [diff] [blame] | 12004 | mUserInfoProvider.refreshUserIds(); |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 12005 | final SparseLongArray updatedUids = mKernelUidCpuFreqTimeReader.perClusterTimesAvailable() |
| 12006 | ? null : new SparseLongArray(); |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 12007 | readKernelUidCpuTimesLocked(partialTimersToConsider, updatedUids, onBattery); |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 12008 | // updatedUids=null means /proc/uid_time_in_state provides snapshots of per-cluster cpu |
| 12009 | // freqs, so no need to approximate these values. |
| 12010 | if (updatedUids != null) { |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 12011 | updateClusterSpeedTimes(updatedUids, onBattery); |
Sudheer Shanka | 671985f | 2017-05-19 11:33:42 -0700 | [diff] [blame] | 12012 | } |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 12013 | readKernelUidCpuFreqTimesLocked(partialTimersToConsider, onBattery, onBatteryScreenOff); |
Mike Ma | fae87da | 2018-01-19 20:07:20 -0800 | [diff] [blame] | 12014 | if (mConstants.TRACK_CPU_ACTIVE_CLUSTER_TIME) { |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 12015 | readKernelUidCpuActiveTimesLocked(onBattery); |
| 12016 | readKernelUidCpuClusterTimesLocked(onBattery); |
Mike Ma | fae87da | 2018-01-19 20:07:20 -0800 | [diff] [blame] | 12017 | } |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 12018 | } |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 12019 | |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 12020 | /** |
| 12021 | * Mark the current partial timers as gone through a collection so that they will be |
| 12022 | * considered in the next cpu times distribution to wakelock holders. |
| 12023 | */ |
| 12024 | @VisibleForTesting |
| 12025 | public void markPartialTimersAsEligible() { |
| 12026 | if (ArrayUtils.referenceEquals(mPartialTimers, mLastPartialTimers)) { |
| 12027 | // No difference, so each timer is now considered for the next collection. |
| 12028 | for (int i = mPartialTimers.size() - 1; i >= 0; --i) { |
| 12029 | mPartialTimers.get(i).mInList = true; |
| 12030 | } |
| 12031 | } else { |
| 12032 | // The lists are different, meaning we added (or removed a timer) since the last |
| 12033 | // collection. |
| 12034 | for (int i = mLastPartialTimers.size() - 1; i >= 0; --i) { |
| 12035 | mLastPartialTimers.get(i).mInList = false; |
| 12036 | } |
| 12037 | mLastPartialTimers.clear(); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 12038 | |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 12039 | // Mark the current timers as gone through a collection. |
| 12040 | final int numPartialTimers = mPartialTimers.size(); |
| 12041 | for (int i = 0; i < numPartialTimers; ++i) { |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 12042 | final StopwatchTimer timer = mPartialTimers.get(i); |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 12043 | timer.mInList = true; |
| 12044 | mLastPartialTimers.add(timer); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 12045 | } |
| 12046 | } |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 12047 | } |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 12048 | |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 12049 | /** |
| 12050 | * Take snapshot of cpu times (aggregated over all uids) at different frequencies and |
| 12051 | * calculate cpu times spent by each uid at different frequencies. |
| 12052 | * |
| 12053 | * @param updatedUids The uids for which times spent at different frequencies are calculated. |
| 12054 | */ |
| 12055 | @VisibleForTesting |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 12056 | public void updateClusterSpeedTimes(@NonNull SparseLongArray updatedUids, boolean onBattery) { |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 12057 | long totalCpuClustersTimeMs = 0; |
Sudheer Shanka | 2fc52d4 | 2017-06-16 17:29:19 -0700 | [diff] [blame] | 12058 | // Read the time spent for each cluster at various cpu frequencies. |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 12059 | final long[][] clusterSpeedTimesMs = new long[mKernelCpuSpeedReaders.length][]; |
Sudheer Shanka | 2fc52d4 | 2017-06-16 17:29:19 -0700 | [diff] [blame] | 12060 | for (int cluster = 0; cluster < mKernelCpuSpeedReaders.length; cluster++) { |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 12061 | clusterSpeedTimesMs[cluster] = mKernelCpuSpeedReaders[cluster].readDelta(); |
| 12062 | if (clusterSpeedTimesMs[cluster] != null) { |
| 12063 | for (int speed = clusterSpeedTimesMs[cluster].length - 1; speed >= 0; --speed) { |
| 12064 | totalCpuClustersTimeMs += clusterSpeedTimesMs[cluster][speed]; |
Sudheer Shanka | 2fc52d4 | 2017-06-16 17:29:19 -0700 | [diff] [blame] | 12065 | } |
| 12066 | } |
| 12067 | } |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 12068 | if (totalCpuClustersTimeMs != 0) { |
Sudheer Shanka | 2fc52d4 | 2017-06-16 17:29:19 -0700 | [diff] [blame] | 12069 | // We have cpu times per freq aggregated over all uids but we need the times per uid. |
| 12070 | // So, we distribute total time spent by an uid to different cpu freqs based on the |
| 12071 | // amount of time cpu was running at that freq. |
| 12072 | final int updatedUidsCount = updatedUids.size(); |
| 12073 | for (int i = 0; i < updatedUidsCount; ++i) { |
| 12074 | final Uid u = getUidStatsLocked(updatedUids.keyAt(i)); |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 12075 | final long appCpuTimeUs = updatedUids.valueAt(i); |
Sudheer Shanka | 2fc52d4 | 2017-06-16 17:29:19 -0700 | [diff] [blame] | 12076 | // Add the cpu speeds to this UID. |
| 12077 | final int numClusters = mPowerProfile.getNumCpuClusters(); |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 12078 | if (u.mCpuClusterSpeedTimesUs == null || |
| 12079 | u.mCpuClusterSpeedTimesUs.length != numClusters) { |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 12080 | u.mCpuClusterSpeedTimesUs = new LongSamplingCounter[numClusters][]; |
Sudheer Shanka | 2fc52d4 | 2017-06-16 17:29:19 -0700 | [diff] [blame] | 12081 | } |
| 12082 | |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 12083 | for (int cluster = 0; cluster < clusterSpeedTimesMs.length; cluster++) { |
| 12084 | final int speedsInCluster = clusterSpeedTimesMs[cluster].length; |
| 12085 | if (u.mCpuClusterSpeedTimesUs[cluster] == null || speedsInCluster != |
| 12086 | u.mCpuClusterSpeedTimesUs[cluster].length) { |
| 12087 | u.mCpuClusterSpeedTimesUs[cluster] |
| 12088 | = new LongSamplingCounter[speedsInCluster]; |
Sudheer Shanka | 2fc52d4 | 2017-06-16 17:29:19 -0700 | [diff] [blame] | 12089 | } |
| 12090 | |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 12091 | final LongSamplingCounter[] cpuSpeeds = u.mCpuClusterSpeedTimesUs[cluster]; |
Sudheer Shanka | 2fc52d4 | 2017-06-16 17:29:19 -0700 | [diff] [blame] | 12092 | for (int speed = 0; speed < speedsInCluster; speed++) { |
| 12093 | if (cpuSpeeds[speed] == null) { |
| 12094 | cpuSpeeds[speed] = new LongSamplingCounter(mOnBatteryTimeBase); |
| 12095 | } |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 12096 | cpuSpeeds[speed].addCountLocked(appCpuTimeUs |
| 12097 | * clusterSpeedTimesMs[cluster][speed] |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 12098 | / totalCpuClustersTimeMs, onBattery); |
Sudheer Shanka | 2fc52d4 | 2017-06-16 17:29:19 -0700 | [diff] [blame] | 12099 | } |
| 12100 | } |
| 12101 | } |
| 12102 | } |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 12103 | } |
Sudheer Shanka | 2fc52d4 | 2017-06-16 17:29:19 -0700 | [diff] [blame] | 12104 | |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 12105 | /** |
| 12106 | * Take a snapshot of the cpu times spent by each uid and update the corresponding counters. |
| 12107 | * If {@param partialTimers} is not null and empty, then we assign a portion of cpu times to |
| 12108 | * wakelock holders. |
| 12109 | * |
| 12110 | * @param partialTimers The wakelock holders among which the cpu times will be distributed. |
| 12111 | * @param updatedUids If not null, then the uids found in the snapshot will be added to this. |
| 12112 | */ |
| 12113 | @VisibleForTesting |
| 12114 | public void readKernelUidCpuTimesLocked(@Nullable ArrayList<StopwatchTimer> partialTimers, |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 12115 | @Nullable SparseLongArray updatedUids, boolean onBattery) { |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 12116 | mTempTotalCpuUserTimeUs = mTempTotalCpuSystemTimeUs = 0; |
| 12117 | final int numWakelocks = partialTimers == null ? 0 : partialTimers.size(); |
| 12118 | final long startTimeMs = mClocks.uptimeMillis(); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 12119 | |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 12120 | mKernelUidCpuTimeReader.readDelta((uid, userTimeUs, systemTimeUs) -> { |
| 12121 | uid = mapUid(uid); |
| 12122 | if (Process.isIsolated(uid)) { |
| 12123 | // This could happen if the isolated uid mapping was removed before that process |
| 12124 | // was actually killed. |
| 12125 | mKernelUidCpuTimeReader.removeUid(uid); |
| 12126 | Slog.d(TAG, "Got readings for an isolated uid with no mapping: " + uid); |
| 12127 | return; |
| 12128 | } |
| 12129 | if (!mUserInfoProvider.exists(UserHandle.getUserId(uid))) { |
| 12130 | Slog.d(TAG, "Got readings for an invalid user's uid " + uid); |
| 12131 | mKernelUidCpuTimeReader.removeUid(uid); |
| 12132 | return; |
| 12133 | } |
| 12134 | final Uid u = getUidStatsLocked(uid); |
| 12135 | |
| 12136 | // Accumulate the total system and user time. |
| 12137 | mTempTotalCpuUserTimeUs += userTimeUs; |
| 12138 | mTempTotalCpuSystemTimeUs += systemTimeUs; |
| 12139 | |
| 12140 | StringBuilder sb = null; |
| 12141 | if (DEBUG_ENERGY_CPU) { |
| 12142 | sb = new StringBuilder(); |
| 12143 | sb.append(" got time for uid=").append(u.mUid).append(": u="); |
| 12144 | TimeUtils.formatDuration(userTimeUs / 1000, sb); |
| 12145 | sb.append(" s="); |
| 12146 | TimeUtils.formatDuration(systemTimeUs / 1000, sb); |
| 12147 | sb.append("\n"); |
| 12148 | } |
| 12149 | |
| 12150 | if (numWakelocks > 0) { |
| 12151 | // We have wakelocks being held, so only give a portion of the |
| 12152 | // time to the process. The rest will be distributed among wakelock |
| 12153 | // holders. |
| 12154 | userTimeUs = (userTimeUs * WAKE_LOCK_WEIGHT) / 100; |
| 12155 | systemTimeUs = (systemTimeUs * WAKE_LOCK_WEIGHT) / 100; |
| 12156 | } |
| 12157 | |
| 12158 | if (sb != null) { |
| 12159 | sb.append(" adding to uid=").append(u.mUid).append(": u="); |
| 12160 | TimeUtils.formatDuration(userTimeUs / 1000, sb); |
| 12161 | sb.append(" s="); |
| 12162 | TimeUtils.formatDuration(systemTimeUs / 1000, sb); |
| 12163 | Slog.d(TAG, sb.toString()); |
| 12164 | } |
| 12165 | |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 12166 | u.mUserCpuTime.addCountLocked(userTimeUs, onBattery); |
| 12167 | u.mSystemCpuTime.addCountLocked(systemTimeUs, onBattery); |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 12168 | if (updatedUids != null) { |
| 12169 | updatedUids.put(u.getUid(), userTimeUs + systemTimeUs); |
| 12170 | } |
| 12171 | }); |
| 12172 | |
| 12173 | final long elapsedTimeMs = mClocks.uptimeMillis() - startTimeMs; |
| 12174 | if (DEBUG_ENERGY_CPU || elapsedTimeMs >= 100) { |
| 12175 | Slog.d(TAG, "Reading cpu stats took " + elapsedTimeMs + "ms"); |
| 12176 | } |
| 12177 | |
| 12178 | if (numWakelocks > 0) { |
| 12179 | // Distribute a portion of the total cpu time to wakelock holders. |
| 12180 | mTempTotalCpuUserTimeUs = (mTempTotalCpuUserTimeUs * (100 - WAKE_LOCK_WEIGHT)) / 100; |
| 12181 | mTempTotalCpuSystemTimeUs = |
| 12182 | (mTempTotalCpuSystemTimeUs * (100 - WAKE_LOCK_WEIGHT)) / 100; |
| 12183 | |
| 12184 | for (int i = 0; i < numWakelocks; ++i) { |
| 12185 | final StopwatchTimer timer = partialTimers.get(i); |
| 12186 | final int userTimeUs = (int) (mTempTotalCpuUserTimeUs / (numWakelocks - i)); |
| 12187 | final int systemTimeUs = (int) (mTempTotalCpuSystemTimeUs / (numWakelocks - i)); |
| 12188 | |
| 12189 | if (DEBUG_ENERGY_CPU) { |
| 12190 | final StringBuilder sb = new StringBuilder(); |
| 12191 | sb.append(" Distributing wakelock uid=").append(timer.mUid.mUid) |
| 12192 | .append(": u="); |
| 12193 | TimeUtils.formatDuration(userTimeUs / 1000, sb); |
| 12194 | sb.append(" s="); |
| 12195 | TimeUtils.formatDuration(systemTimeUs / 1000, sb); |
| 12196 | Slog.d(TAG, sb.toString()); |
| 12197 | } |
| 12198 | |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 12199 | timer.mUid.mUserCpuTime.addCountLocked(userTimeUs, onBattery); |
| 12200 | timer.mUid.mSystemCpuTime.addCountLocked(systemTimeUs, onBattery); |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 12201 | if (updatedUids != null) { |
| 12202 | final int uid = timer.mUid.getUid(); |
| 12203 | updatedUids.put(uid, updatedUids.get(uid, 0) + userTimeUs + systemTimeUs); |
| 12204 | } |
| 12205 | |
| 12206 | final Uid.Proc proc = timer.mUid.getProcessStatsLocked("*wakelock*"); |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 12207 | proc.addCpuTimeLocked(userTimeUs / 1000, systemTimeUs / 1000, onBattery); |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 12208 | |
| 12209 | mTempTotalCpuUserTimeUs -= userTimeUs; |
| 12210 | mTempTotalCpuSystemTimeUs -= systemTimeUs; |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 12211 | } |
| 12212 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 12213 | } |
| 12214 | |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 12215 | /** |
| 12216 | * Take a snapshot of the cpu times spent by each uid in each freq and update the |
| 12217 | * corresponding counters. |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 12218 | * |
| 12219 | * @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] | 12220 | */ |
| 12221 | @VisibleForTesting |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 12222 | public void readKernelUidCpuFreqTimesLocked(@Nullable ArrayList<StopwatchTimer> partialTimers, |
| 12223 | boolean onBattery, boolean onBatteryScreenOff) { |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 12224 | final boolean perClusterTimesAvailable = |
| 12225 | mKernelUidCpuFreqTimeReader.perClusterTimesAvailable(); |
| 12226 | final int numWakelocks = partialTimers == null ? 0 : partialTimers.size(); |
| 12227 | final int numClusters = mPowerProfile.getNumCpuClusters(); |
| 12228 | mWakeLockAllocationsUs = null; |
Sudheer Shanka | ac5b88f | 2017-12-11 15:36:35 -0800 | [diff] [blame] | 12229 | final long startTimeMs = mClocks.uptimeMillis(); |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 12230 | mKernelUidCpuFreqTimeReader.readDelta((uid, cpuFreqTimeMs) -> { |
| 12231 | uid = mapUid(uid); |
| 12232 | if (Process.isIsolated(uid)) { |
| 12233 | mKernelUidCpuFreqTimeReader.removeUid(uid); |
| 12234 | Slog.d(TAG, "Got freq readings for an isolated uid with no mapping: " + uid); |
| 12235 | return; |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 12236 | } |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 12237 | if (!mUserInfoProvider.exists(UserHandle.getUserId(uid))) { |
| 12238 | Slog.d(TAG, "Got freq readings for an invalid user's uid " + uid); |
| 12239 | mKernelUidCpuFreqTimeReader.removeUid(uid); |
| 12240 | return; |
| 12241 | } |
| 12242 | final Uid u = getUidStatsLocked(uid); |
| 12243 | if (u.mCpuFreqTimeMs == null || u.mCpuFreqTimeMs.getSize() != cpuFreqTimeMs.length) { |
| 12244 | u.mCpuFreqTimeMs = new LongSamplingCounterArray(mOnBatteryTimeBase); |
| 12245 | } |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 12246 | u.mCpuFreqTimeMs.addCountLocked(cpuFreqTimeMs, onBattery); |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 12247 | if (u.mScreenOffCpuFreqTimeMs == null || |
| 12248 | u.mScreenOffCpuFreqTimeMs.getSize() != cpuFreqTimeMs.length) { |
| 12249 | u.mScreenOffCpuFreqTimeMs = new LongSamplingCounterArray( |
| 12250 | mOnBatteryScreenOffTimeBase); |
| 12251 | } |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 12252 | u.mScreenOffCpuFreqTimeMs.addCountLocked(cpuFreqTimeMs, onBatteryScreenOff); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 12253 | |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 12254 | if (perClusterTimesAvailable) { |
| 12255 | if (u.mCpuClusterSpeedTimesUs == null || |
| 12256 | u.mCpuClusterSpeedTimesUs.length != numClusters) { |
| 12257 | u.mCpuClusterSpeedTimesUs = new LongSamplingCounter[numClusters][]; |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 12258 | } |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 12259 | if (numWakelocks > 0 && mWakeLockAllocationsUs == null) { |
| 12260 | mWakeLockAllocationsUs = new long[numClusters][]; |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 12261 | } |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 12262 | |
| 12263 | int freqIndex = 0; |
| 12264 | for (int cluster = 0; cluster < numClusters; ++cluster) { |
| 12265 | final int speedsInCluster = mPowerProfile.getNumSpeedStepsInCpuCluster(cluster); |
| 12266 | if (u.mCpuClusterSpeedTimesUs[cluster] == null || |
| 12267 | u.mCpuClusterSpeedTimesUs[cluster].length != speedsInCluster) { |
| 12268 | u.mCpuClusterSpeedTimesUs[cluster] |
| 12269 | = new LongSamplingCounter[speedsInCluster]; |
| 12270 | } |
| 12271 | if (numWakelocks > 0 && mWakeLockAllocationsUs[cluster] == null) { |
| 12272 | mWakeLockAllocationsUs[cluster] = new long[speedsInCluster]; |
| 12273 | } |
| 12274 | final LongSamplingCounter[] cpuTimesUs = u.mCpuClusterSpeedTimesUs[cluster]; |
| 12275 | for (int speed = 0; speed < speedsInCluster; ++speed) { |
| 12276 | if (cpuTimesUs[speed] == null) { |
| 12277 | cpuTimesUs[speed] = new LongSamplingCounter(mOnBatteryTimeBase); |
| 12278 | } |
| 12279 | final long appAllocationUs; |
| 12280 | if (mWakeLockAllocationsUs != null) { |
| 12281 | appAllocationUs = |
| 12282 | (cpuFreqTimeMs[freqIndex] * 1000 * WAKE_LOCK_WEIGHT) / 100; |
| 12283 | mWakeLockAllocationsUs[cluster][speed] += |
| 12284 | (cpuFreqTimeMs[freqIndex] * 1000 - appAllocationUs); |
| 12285 | } else { |
| 12286 | appAllocationUs = cpuFreqTimeMs[freqIndex] * 1000; |
| 12287 | } |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 12288 | cpuTimesUs[speed].addCountLocked(appAllocationUs, onBattery); |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 12289 | freqIndex++; |
| 12290 | } |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 12291 | } |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 12292 | } |
| 12293 | }); |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 12294 | |
Sudheer Shanka | ac5b88f | 2017-12-11 15:36:35 -0800 | [diff] [blame] | 12295 | final long elapsedTimeMs = mClocks.uptimeMillis() - startTimeMs; |
| 12296 | if (DEBUG_ENERGY_CPU || elapsedTimeMs >= 100) { |
| 12297 | Slog.d(TAG, "Reading cpu freq times took " + elapsedTimeMs + "ms"); |
| 12298 | } |
| 12299 | |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 12300 | if (mWakeLockAllocationsUs != null) { |
| 12301 | for (int i = 0; i < numWakelocks; ++i) { |
| 12302 | final Uid u = partialTimers.get(i).mUid; |
| 12303 | if (u.mCpuClusterSpeedTimesUs == null || |
| 12304 | u.mCpuClusterSpeedTimesUs.length != numClusters) { |
| 12305 | u.mCpuClusterSpeedTimesUs = new LongSamplingCounter[numClusters][]; |
| 12306 | } |
| 12307 | |
| 12308 | for (int cluster = 0; cluster < numClusters; ++cluster) { |
| 12309 | final int speedsInCluster = mPowerProfile.getNumSpeedStepsInCpuCluster(cluster); |
| 12310 | if (u.mCpuClusterSpeedTimesUs[cluster] == null || |
| 12311 | u.mCpuClusterSpeedTimesUs[cluster].length != speedsInCluster) { |
| 12312 | u.mCpuClusterSpeedTimesUs[cluster] |
| 12313 | = new LongSamplingCounter[speedsInCluster]; |
| 12314 | } |
| 12315 | final LongSamplingCounter[] cpuTimeUs = u.mCpuClusterSpeedTimesUs[cluster]; |
| 12316 | for (int speed = 0; speed < speedsInCluster; ++speed) { |
| 12317 | if (cpuTimeUs[speed] == null) { |
| 12318 | cpuTimeUs[speed] = new LongSamplingCounter(mOnBatteryTimeBase); |
| 12319 | } |
| 12320 | final long allocationUs = |
| 12321 | mWakeLockAllocationsUs[cluster][speed] / (numWakelocks - i); |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 12322 | cpuTimeUs[speed].addCountLocked(allocationUs, onBattery); |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 12323 | mWakeLockAllocationsUs[cluster][speed] -= allocationUs; |
| 12324 | } |
| 12325 | } |
| 12326 | } |
| 12327 | } |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 12328 | } |
| 12329 | |
Mike Ma | 3d422c3 | 2017-10-25 11:08:57 -0700 | [diff] [blame] | 12330 | /** |
| 12331 | * Take a snapshot of the cpu active times spent by each uid and update the corresponding |
| 12332 | * counters. |
| 12333 | */ |
| 12334 | @VisibleForTesting |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 12335 | public void readKernelUidCpuActiveTimesLocked(boolean onBattery) { |
Mike Ma | 3d422c3 | 2017-10-25 11:08:57 -0700 | [diff] [blame] | 12336 | final long startTimeMs = mClocks.uptimeMillis(); |
| 12337 | mKernelUidCpuActiveTimeReader.readDelta((uid, cpuActiveTimesUs) -> { |
| 12338 | uid = mapUid(uid); |
| 12339 | if (Process.isIsolated(uid)) { |
| 12340 | mKernelUidCpuActiveTimeReader.removeUid(uid); |
| 12341 | Slog.w(TAG, "Got active times for an isolated uid with no mapping: " + uid); |
| 12342 | return; |
| 12343 | } |
| 12344 | if (!mUserInfoProvider.exists(UserHandle.getUserId(uid))) { |
| 12345 | Slog.w(TAG, "Got active times for an invalid user's uid " + uid); |
| 12346 | mKernelUidCpuActiveTimeReader.removeUid(uid); |
| 12347 | return; |
| 12348 | } |
| 12349 | final Uid u = getUidStatsLocked(uid); |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 12350 | u.mCpuActiveTimeMs.addCountLocked(cpuActiveTimesUs, onBattery); |
Mike Ma | 3d422c3 | 2017-10-25 11:08:57 -0700 | [diff] [blame] | 12351 | }); |
| 12352 | |
| 12353 | final long elapsedTimeMs = mClocks.uptimeMillis() - startTimeMs; |
| 12354 | if (DEBUG_ENERGY_CPU || elapsedTimeMs >= 100) { |
| 12355 | Slog.d(TAG, "Reading cpu active times took " + elapsedTimeMs + "ms"); |
| 12356 | } |
| 12357 | } |
| 12358 | |
| 12359 | /** |
| 12360 | * Take a snapshot of the cpu cluster times spent by each uid and update the corresponding |
| 12361 | * counters. |
| 12362 | */ |
| 12363 | @VisibleForTesting |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 12364 | public void readKernelUidCpuClusterTimesLocked(boolean onBattery) { |
Mike Ma | 3d422c3 | 2017-10-25 11:08:57 -0700 | [diff] [blame] | 12365 | final long startTimeMs = mClocks.uptimeMillis(); |
| 12366 | mKernelUidCpuClusterTimeReader.readDelta((uid, cpuClusterTimesUs) -> { |
| 12367 | uid = mapUid(uid); |
| 12368 | if (Process.isIsolated(uid)) { |
| 12369 | mKernelUidCpuClusterTimeReader.removeUid(uid); |
| 12370 | Slog.w(TAG, "Got cluster times for an isolated uid with no mapping: " + uid); |
| 12371 | return; |
| 12372 | } |
| 12373 | if (!mUserInfoProvider.exists(UserHandle.getUserId(uid))) { |
| 12374 | Slog.w(TAG, "Got cluster times for an invalid user's uid " + uid); |
| 12375 | mKernelUidCpuClusterTimeReader.removeUid(uid); |
| 12376 | return; |
| 12377 | } |
| 12378 | final Uid u = getUidStatsLocked(uid); |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 12379 | u.mCpuClusterTimesMs.addCountLocked(cpuClusterTimesUs, onBattery); |
Mike Ma | 3d422c3 | 2017-10-25 11:08:57 -0700 | [diff] [blame] | 12380 | }); |
| 12381 | |
| 12382 | final long elapsedTimeMs = mClocks.uptimeMillis() - startTimeMs; |
| 12383 | if (DEBUG_ENERGY_CPU || elapsedTimeMs >= 100) { |
| 12384 | Slog.d(TAG, "Reading cpu cluster times took " + elapsedTimeMs + "ms"); |
| 12385 | } |
| 12386 | } |
| 12387 | |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 12388 | boolean setChargingLocked(boolean charging) { |
| 12389 | if (mCharging != charging) { |
| 12390 | mCharging = charging; |
| 12391 | if (charging) { |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 12392 | mHistoryCur.states2 |= HistoryItem.STATE2_CHARGING_FLAG; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 12393 | } else { |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 12394 | mHistoryCur.states2 &= ~HistoryItem.STATE2_CHARGING_FLAG; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 12395 | } |
| 12396 | mHandler.sendEmptyMessage(MSG_REPORT_CHARGING); |
| 12397 | return true; |
| 12398 | } |
| 12399 | return false; |
| 12400 | } |
| 12401 | |
Andreas Gampe | 3f24e69 | 2018-02-05 13:24:28 -0800 | [diff] [blame] | 12402 | @GuardedBy("this") |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 12403 | protected void setOnBatteryLocked(final long mSecRealtime, final long mSecUptime, |
| 12404 | final boolean onBattery, final int oldStatus, final int level, final int chargeUAh) { |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 12405 | boolean doWrite = false; |
| 12406 | Message m = mHandler.obtainMessage(MSG_REPORT_POWER_CHANGE); |
| 12407 | m.arg1 = onBattery ? 1 : 0; |
| 12408 | mHandler.sendMessage(m); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 12409 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 12410 | final long uptime = mSecUptime * 1000; |
| 12411 | final long realtime = mSecRealtime * 1000; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 12412 | final int screenState = mScreenState; |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 12413 | if (onBattery) { |
| 12414 | // We will reset our status if we are unplugging after the |
| 12415 | // battery was last full, or the level is at 100, or |
| 12416 | // we have gone through a significant charge (from a very low |
| 12417 | // level to a now very high level). |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 12418 | boolean reset = false; |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 12419 | if (!mNoAutoReset && (oldStatus == BatteryManager.BATTERY_STATUS_FULL |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 12420 | || level >= 90 |
Dianne Hackborn | fb3809c | 2014-09-29 18:31:22 -0700 | [diff] [blame] | 12421 | || (mDischargeCurrentLevel < 20 && level >= 80) |
| 12422 | || (getHighDischargeAmountSinceCharge() >= 200 |
| 12423 | && mHistoryBuffer.dataSize() >= MAX_HISTORY_BUFFER))) { |
Dianne Hackborn | 73d6a82 | 2014-09-29 10:52:47 -0700 | [diff] [blame] | 12424 | Slog.i(TAG, "Resetting battery stats: level=" + level + " status=" + oldStatus |
Dianne Hackborn | fb3809c | 2014-09-29 18:31:22 -0700 | [diff] [blame] | 12425 | + " dischargeLevel=" + mDischargeCurrentLevel |
Dianne Hackborn | 73d6a82 | 2014-09-29 10:52:47 -0700 | [diff] [blame] | 12426 | + " lowAmount=" + getLowDischargeAmountSinceCharge() |
| 12427 | + " highAmount=" + getHighDischargeAmountSinceCharge()); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 12428 | // Before we write, collect a snapshot of the final aggregated |
| 12429 | // stats to be reported in the next checkin. Only do this if we have |
| 12430 | // a sufficient amount of data to make it interesting. |
| 12431 | if (getLowDischargeAmountSinceCharge() >= 20) { |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 12432 | final long startTime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 12433 | final Parcel parcel = Parcel.obtain(); |
| 12434 | writeSummaryToParcel(parcel, true); |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 12435 | final long initialTime = SystemClock.uptimeMillis() - startTime; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 12436 | BackgroundThread.getHandler().post(new Runnable() { |
| 12437 | @Override public void run() { |
| 12438 | synchronized (mCheckinFile) { |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 12439 | final long startTime2 = SystemClock.uptimeMillis(); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 12440 | FileOutputStream stream = null; |
| 12441 | try { |
| 12442 | stream = mCheckinFile.startWrite(); |
| 12443 | stream.write(parcel.marshall()); |
| 12444 | stream.flush(); |
| 12445 | FileUtils.sync(stream); |
| 12446 | stream.close(); |
| 12447 | mCheckinFile.finishWrite(stream); |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 12448 | com.android.internal.logging.EventLogTags.writeCommitSysConfigFile( |
| 12449 | "batterystats-checkin", |
| 12450 | initialTime + SystemClock.uptimeMillis() - startTime2); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 12451 | } catch (IOException e) { |
| 12452 | Slog.w("BatteryStats", |
| 12453 | "Error writing checkin battery statistics", e); |
| 12454 | mCheckinFile.failWrite(stream); |
| 12455 | } finally { |
| 12456 | parcel.recycle(); |
| 12457 | } |
| 12458 | } |
| 12459 | } |
| 12460 | }); |
| 12461 | } |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 12462 | doWrite = true; |
| 12463 | resetAllStatsLocked(); |
Ying Wai (Daniel) Fan | 442ab76 | 2017-01-31 22:00:10 -0800 | [diff] [blame] | 12464 | if (chargeUAh > 0 && level > 0) { |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 12465 | // 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] | 12466 | mEstimatedBatteryCapacity = (int) ((chargeUAh / 1000) / (level / 100.0)); |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 12467 | } |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 12468 | mDischargeStartLevel = level; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 12469 | reset = true; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 12470 | mDischargeStepTracker.init(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 12471 | } |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 12472 | if (mCharging) { |
| 12473 | setChargingLocked(false); |
| 12474 | } |
| 12475 | mLastChargingStateLevel = level; |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 12476 | mOnBattery = mOnBatteryInternal = true; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 12477 | mLastDischargeStepLevel = level; |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 12478 | mMinDischargeStepLevel = level; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 12479 | mDischargeStepTracker.clearTime(); |
| 12480 | mDailyDischargeStepTracker.clearTime(); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 12481 | mInitStepMode = mCurStepMode; |
| 12482 | mModStepMode = 0; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 12483 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 12484 | mHistoryCur.batteryLevel = (byte)level; |
| 12485 | mHistoryCur.states &= ~HistoryItem.STATE_BATTERY_PLUGGED_FLAG; |
| 12486 | if (DEBUG_HISTORY) Slog.v(TAG, "Battery unplugged to: " |
| 12487 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 12488 | if (reset) { |
| 12489 | mRecordingHistory = true; |
| 12490 | startRecordingHistory(mSecRealtime, mSecUptime, reset); |
| 12491 | } |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 12492 | addHistoryRecordLocked(mSecRealtime, mSecUptime); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 12493 | mDischargeCurrentLevel = mDischargeUnplugLevel = level; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 12494 | if (isScreenOn(screenState)) { |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 12495 | mDischargeScreenOnUnplugLevel = level; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 12496 | mDischargeScreenDozeUnplugLevel = 0; |
| 12497 | mDischargeScreenOffUnplugLevel = 0; |
| 12498 | } else if (isScreenDoze(screenState)) { |
| 12499 | mDischargeScreenOnUnplugLevel = 0; |
| 12500 | mDischargeScreenDozeUnplugLevel = level; |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 12501 | mDischargeScreenOffUnplugLevel = 0; |
| 12502 | } else { |
| 12503 | mDischargeScreenOnUnplugLevel = 0; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 12504 | mDischargeScreenDozeUnplugLevel = 0; |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 12505 | mDischargeScreenOffUnplugLevel = level; |
| 12506 | } |
| 12507 | mDischargeAmountScreenOn = 0; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 12508 | mDischargeAmountScreenDoze = 0; |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 12509 | mDischargeAmountScreenOff = 0; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 12510 | updateTimeBasesLocked(true, screenState, uptime, realtime); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 12511 | } else { |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 12512 | mLastChargingStateLevel = level; |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 12513 | mOnBattery = mOnBatteryInternal = false; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 12514 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 12515 | mHistoryCur.batteryLevel = (byte)level; |
| 12516 | mHistoryCur.states |= HistoryItem.STATE_BATTERY_PLUGGED_FLAG; |
| 12517 | if (DEBUG_HISTORY) Slog.v(TAG, "Battery plugged to: " |
| 12518 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 12519 | addHistoryRecordLocked(mSecRealtime, mSecUptime); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 12520 | mDischargeCurrentLevel = mDischargePlugLevel = level; |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 12521 | if (level < mDischargeUnplugLevel) { |
| 12522 | mLowDischargeAmountSinceCharge += mDischargeUnplugLevel-level-1; |
| 12523 | mHighDischargeAmountSinceCharge += mDischargeUnplugLevel-level; |
| 12524 | } |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 12525 | updateDischargeScreenLevelsLocked(screenState, screenState); |
| 12526 | updateTimeBasesLocked(false, screenState, uptime, realtime); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 12527 | mChargeStepTracker.init(); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 12528 | mLastChargeStepLevel = level; |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 12529 | mMaxChargeStepLevel = level; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 12530 | mInitStepMode = mCurStepMode; |
| 12531 | mModStepMode = 0; |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 12532 | } |
| 12533 | if (doWrite || (mLastWriteTime + (60 * 1000)) < mSecRealtime) { |
| 12534 | if (mFile != null) { |
| 12535 | writeAsyncLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12536 | } |
| 12537 | } |
| 12538 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 12539 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 12540 | private void startRecordingHistory(final long elapsedRealtimeMs, final long uptimeMs, |
| 12541 | boolean reset) { |
| 12542 | mRecordingHistory = true; |
| 12543 | mHistoryCur.currentTime = System.currentTimeMillis(); |
Narayan Kamath | 5a5a7fe | 2018-02-05 17:30:06 +0000 | [diff] [blame] | 12544 | addHistoryBufferLocked(elapsedRealtimeMs, |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 12545 | reset ? HistoryItem.CMD_RESET : HistoryItem.CMD_CURRENT_TIME, |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 12546 | mHistoryCur); |
| 12547 | mHistoryCur.currentTime = 0; |
| 12548 | if (reset) { |
| 12549 | initActiveHistoryEventsLocked(elapsedRealtimeMs, uptimeMs); |
| 12550 | } |
| 12551 | } |
| 12552 | |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 12553 | private void recordCurrentTimeChangeLocked(final long currentTime, final long elapsedRealtimeMs, |
| 12554 | final long uptimeMs) { |
| 12555 | if (mRecordingHistory) { |
| 12556 | mHistoryCur.currentTime = currentTime; |
Narayan Kamath | 5a5a7fe | 2018-02-05 17:30:06 +0000 | [diff] [blame] | 12557 | addHistoryBufferLocked(elapsedRealtimeMs, HistoryItem.CMD_CURRENT_TIME, mHistoryCur); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 12558 | mHistoryCur.currentTime = 0; |
| 12559 | } |
| 12560 | } |
| 12561 | |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 12562 | private void recordShutdownLocked(final long elapsedRealtimeMs, final long uptimeMs) { |
| 12563 | if (mRecordingHistory) { |
| 12564 | mHistoryCur.currentTime = System.currentTimeMillis(); |
Narayan Kamath | 5a5a7fe | 2018-02-05 17:30:06 +0000 | [diff] [blame] | 12565 | addHistoryBufferLocked(elapsedRealtimeMs, HistoryItem.CMD_SHUTDOWN, mHistoryCur); |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 12566 | mHistoryCur.currentTime = 0; |
| 12567 | } |
| 12568 | } |
| 12569 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 12570 | private void scheduleSyncExternalStatsLocked(String reason, int updateFlags) { |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 12571 | if (mExternalSync != null) { |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 12572 | mExternalSync.scheduleSync(reason, updateFlags); |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 12573 | } |
| 12574 | } |
| 12575 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 12576 | // This should probably be exposed in the API, though it's not critical |
Bookatz | 1a1b046 | 2018-01-12 11:47:03 -0800 | [diff] [blame] | 12577 | public static final int BATTERY_PLUGGED_NONE = OsProtoEnums.BATTERY_PLUGGED_NONE; // = 0 |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 12578 | |
Andreas Gampe | 3f24e69 | 2018-02-05 13:24:28 -0800 | [diff] [blame] | 12579 | @GuardedBy("this") |
Bookatz | 8c6571b | 2017-10-24 15:04:41 -0700 | [diff] [blame] | 12580 | public void setBatteryStateLocked(final int status, final int health, final int plugType, |
| 12581 | final int level, /* not final */ int temp, final int volt, final int chargeUAh, |
| 12582 | final int chargeFullUAh) { |
Adam Lesinski | 29ddfe5 | 2017-03-29 19:29:00 -0700 | [diff] [blame] | 12583 | // Temperature is encoded without the signed bit, so clamp any negative temperatures to 0. |
| 12584 | temp = Math.max(0, temp); |
| 12585 | |
Bookatz | 8c6571b | 2017-10-24 15:04:41 -0700 | [diff] [blame] | 12586 | reportChangesToStatsLog(mHaveBatteryLevel ? mHistoryCur : null, |
| 12587 | status, plugType, level, temp); |
| 12588 | |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 12589 | final boolean onBattery = isOnBattery(plugType, status); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 12590 | final long uptime = mClocks.uptimeMillis(); |
| 12591 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 12592 | if (!mHaveBatteryLevel) { |
| 12593 | mHaveBatteryLevel = true; |
| 12594 | // We start out assuming that the device is plugged in (not |
| 12595 | // on battery). If our first report is now that we are indeed |
| 12596 | // plugged in, then twiddle our state to correctly reflect that |
| 12597 | // since we won't be going through the full setOnBattery(). |
| 12598 | if (onBattery == mOnBattery) { |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 12599 | if (onBattery) { |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 12600 | mHistoryCur.states &= ~HistoryItem.STATE_BATTERY_PLUGGED_FLAG; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 12601 | } else { |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 12602 | mHistoryCur.states |= HistoryItem.STATE_BATTERY_PLUGGED_FLAG; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 12603 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 12604 | } |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 12605 | // Always start out assuming charging, that will be updated later. |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 12606 | mHistoryCur.states2 |= HistoryItem.STATE2_CHARGING_FLAG; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 12607 | mHistoryCur.batteryStatus = (byte)status; |
| 12608 | mHistoryCur.batteryLevel = (byte)level; |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 12609 | mHistoryCur.batteryChargeUAh = chargeUAh; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 12610 | mMaxChargeStepLevel = mMinDischargeStepLevel = |
| 12611 | mLastChargeStepLevel = mLastDischargeStepLevel = level; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 12612 | mLastChargingStateLevel = level; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 12613 | } else if (mCurrentBatteryLevel != level || mOnBattery != onBattery) { |
| 12614 | recordDailyStatsIfNeededLocked(level >= 100 && onBattery); |
| 12615 | } |
| 12616 | int oldStatus = mHistoryCur.batteryStatus; |
| 12617 | if (onBattery) { |
| 12618 | mDischargeCurrentLevel = level; |
| 12619 | if (!mRecordingHistory) { |
| 12620 | mRecordingHistory = true; |
| 12621 | startRecordingHistory(elapsedRealtime, uptime, true); |
| 12622 | } |
Todd Poynor | 1acf06a | 2017-12-07 19:19:35 -0800 | [diff] [blame] | 12623 | } else if (level < 96 && |
| 12624 | status != BatteryManager.BATTERY_STATUS_UNKNOWN) { |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 12625 | if (!mRecordingHistory) { |
| 12626 | mRecordingHistory = true; |
| 12627 | startRecordingHistory(elapsedRealtime, uptime, true); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 12628 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 12629 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 12630 | mCurrentBatteryLevel = level; |
| 12631 | if (mDischargePlugLevel < 0) { |
| 12632 | mDischargePlugLevel = level; |
Marco Nelissen | d859331 | 2009-04-30 14:45:06 -0700 | [diff] [blame] | 12633 | } |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 12634 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 12635 | if (onBattery != mOnBattery) { |
| 12636 | mHistoryCur.batteryLevel = (byte)level; |
| 12637 | mHistoryCur.batteryStatus = (byte)status; |
| 12638 | mHistoryCur.batteryHealth = (byte)health; |
| 12639 | mHistoryCur.batteryPlugType = (byte)plugType; |
| 12640 | mHistoryCur.batteryTemperature = (short)temp; |
| 12641 | mHistoryCur.batteryVoltage = (char)volt; |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 12642 | if (chargeUAh < mHistoryCur.batteryChargeUAh) { |
| 12643 | // Only record discharges |
| 12644 | final long chargeDiff = mHistoryCur.batteryChargeUAh - chargeUAh; |
| 12645 | mDischargeCounter.addCountLocked(chargeDiff); |
| 12646 | mDischargeScreenOffCounter.addCountLocked(chargeDiff); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 12647 | if (isScreenDoze(mScreenState)) { |
| 12648 | mDischargeScreenDozeCounter.addCountLocked(chargeDiff); |
| 12649 | } |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 12650 | if (mDeviceIdleMode == DEVICE_IDLE_MODE_LIGHT) { |
| 12651 | mDischargeLightDozeCounter.addCountLocked(chargeDiff); |
| 12652 | } else if (mDeviceIdleMode == DEVICE_IDLE_MODE_DEEP) { |
| 12653 | mDischargeDeepDozeCounter.addCountLocked(chargeDiff); |
| 12654 | } |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 12655 | } |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 12656 | mHistoryCur.batteryChargeUAh = chargeUAh; |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 12657 | setOnBatteryLocked(elapsedRealtime, uptime, onBattery, oldStatus, level, chargeUAh); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 12658 | } else { |
| 12659 | boolean changed = false; |
| 12660 | if (mHistoryCur.batteryLevel != level) { |
| 12661 | mHistoryCur.batteryLevel = (byte)level; |
| 12662 | changed = true; |
Marco Nelissen | d859331 | 2009-04-30 14:45:06 -0700 | [diff] [blame] | 12663 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 12664 | // TODO(adamlesinski): Schedule the creation of a HistoryStepDetails record |
| 12665 | // which will pull external stats. |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 12666 | scheduleSyncExternalStatsLocked("battery-level", ExternalStatsSync.UPDATE_ALL); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 12667 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 12668 | if (mHistoryCur.batteryStatus != status) { |
| 12669 | mHistoryCur.batteryStatus = (byte)status; |
| 12670 | changed = true; |
| 12671 | } |
| 12672 | if (mHistoryCur.batteryHealth != health) { |
| 12673 | mHistoryCur.batteryHealth = (byte)health; |
| 12674 | changed = true; |
| 12675 | } |
| 12676 | if (mHistoryCur.batteryPlugType != plugType) { |
| 12677 | mHistoryCur.batteryPlugType = (byte)plugType; |
| 12678 | changed = true; |
| 12679 | } |
| 12680 | if (temp >= (mHistoryCur.batteryTemperature+10) |
| 12681 | || temp <= (mHistoryCur.batteryTemperature-10)) { |
| 12682 | mHistoryCur.batteryTemperature = (short)temp; |
| 12683 | changed = true; |
| 12684 | } |
| 12685 | if (volt > (mHistoryCur.batteryVoltage+20) |
| 12686 | || volt < (mHistoryCur.batteryVoltage-20)) { |
| 12687 | mHistoryCur.batteryVoltage = (char)volt; |
| 12688 | changed = true; |
| 12689 | } |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 12690 | if (chargeUAh >= (mHistoryCur.batteryChargeUAh+10) |
| 12691 | || chargeUAh <= (mHistoryCur.batteryChargeUAh-10)) { |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 12692 | if (chargeUAh < mHistoryCur.batteryChargeUAh) { |
| 12693 | // Only record discharges |
| 12694 | final long chargeDiff = mHistoryCur.batteryChargeUAh - chargeUAh; |
| 12695 | mDischargeCounter.addCountLocked(chargeDiff); |
| 12696 | mDischargeScreenOffCounter.addCountLocked(chargeDiff); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 12697 | if (isScreenDoze(mScreenState)) { |
| 12698 | mDischargeScreenDozeCounter.addCountLocked(chargeDiff); |
| 12699 | } |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 12700 | if (mDeviceIdleMode == DEVICE_IDLE_MODE_LIGHT) { |
| 12701 | mDischargeLightDozeCounter.addCountLocked(chargeDiff); |
| 12702 | } else if (mDeviceIdleMode == DEVICE_IDLE_MODE_DEEP) { |
| 12703 | mDischargeDeepDozeCounter.addCountLocked(chargeDiff); |
| 12704 | } |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 12705 | } |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 12706 | mHistoryCur.batteryChargeUAh = chargeUAh; |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 12707 | changed = true; |
| 12708 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 12709 | long modeBits = (((long)mInitStepMode) << STEP_LEVEL_INITIAL_MODE_SHIFT) |
| 12710 | | (((long)mModStepMode) << STEP_LEVEL_MODIFIED_MODE_SHIFT) |
| 12711 | | (((long)(level&0xff)) << STEP_LEVEL_LEVEL_SHIFT); |
| 12712 | if (onBattery) { |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 12713 | changed |= setChargingLocked(false); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 12714 | if (mLastDischargeStepLevel != level && mMinDischargeStepLevel > level) { |
| 12715 | mDischargeStepTracker.addLevelSteps(mLastDischargeStepLevel - level, |
| 12716 | modeBits, elapsedRealtime); |
| 12717 | mDailyDischargeStepTracker.addLevelSteps(mLastDischargeStepLevel - level, |
| 12718 | modeBits, elapsedRealtime); |
| 12719 | mLastDischargeStepLevel = level; |
| 12720 | mMinDischargeStepLevel = level; |
| 12721 | mInitStepMode = mCurStepMode; |
| 12722 | mModStepMode = 0; |
| 12723 | } |
| 12724 | } else { |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 12725 | if (level >= 90) { |
| 12726 | // If the battery level is at least 90%, always consider the device to be |
| 12727 | // charging even if it happens to go down a level. |
| 12728 | changed |= setChargingLocked(true); |
| 12729 | mLastChargeStepLevel = level; |
| 12730 | } if (!mCharging) { |
| 12731 | if (mLastChargeStepLevel < level) { |
| 12732 | // We have not reporting that we are charging, but the level has now |
| 12733 | // gone up, so consider the state to be charging. |
| 12734 | changed |= setChargingLocked(true); |
| 12735 | mLastChargeStepLevel = level; |
| 12736 | } |
| 12737 | } else { |
| 12738 | if (mLastChargeStepLevel > level) { |
| 12739 | // We had reported that the device was charging, but here we are with |
| 12740 | // power connected and the level going down. Looks like the current |
| 12741 | // power supplied isn't enough, so consider the device to now be |
| 12742 | // discharging. |
| 12743 | changed |= setChargingLocked(false); |
| 12744 | mLastChargeStepLevel = level; |
| 12745 | } |
| 12746 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 12747 | if (mLastChargeStepLevel != level && mMaxChargeStepLevel < level) { |
| 12748 | mChargeStepTracker.addLevelSteps(level - mLastChargeStepLevel, |
| 12749 | modeBits, elapsedRealtime); |
| 12750 | mDailyChargeStepTracker.addLevelSteps(level - mLastChargeStepLevel, |
| 12751 | modeBits, elapsedRealtime); |
| 12752 | mLastChargeStepLevel = level; |
| 12753 | mMaxChargeStepLevel = level; |
| 12754 | mInitStepMode = mCurStepMode; |
| 12755 | mModStepMode = 0; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 12756 | } |
| 12757 | } |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 12758 | if (changed) { |
| 12759 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 12760 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 12761 | } |
Todd Poynor | 1acf06a | 2017-12-07 19:19:35 -0800 | [diff] [blame] | 12762 | if (!onBattery && |
| 12763 | (status == BatteryManager.BATTERY_STATUS_FULL || |
| 12764 | status == BatteryManager.BATTERY_STATUS_UNKNOWN)) { |
| 12765 | // We don't record history while we are plugged in and fully charged |
| 12766 | // (or when battery is not present). The next time we are |
| 12767 | // unplugged, history will be cleared. |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 12768 | mRecordingHistory = DEBUG; |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 12769 | } |
Adam Lesinski | 041d917 | 2016-12-12 12:03:56 -0800 | [diff] [blame] | 12770 | |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 12771 | if (mMinLearnedBatteryCapacity == -1) { |
| 12772 | mMinLearnedBatteryCapacity = chargeFullUAh; |
| 12773 | } else { |
| 12774 | Math.min(mMinLearnedBatteryCapacity, chargeFullUAh); |
Adam Lesinski | 041d917 | 2016-12-12 12:03:56 -0800 | [diff] [blame] | 12775 | } |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 12776 | mMaxLearnedBatteryCapacity = Math.max(mMaxLearnedBatteryCapacity, chargeFullUAh); |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 12777 | } |
| 12778 | |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 12779 | public static boolean isOnBattery(int plugType, int status) { |
| 12780 | return plugType == BATTERY_PLUGGED_NONE && status != BatteryManager.BATTERY_STATUS_UNKNOWN; |
| 12781 | } |
| 12782 | |
Bookatz | 8c6571b | 2017-10-24 15:04:41 -0700 | [diff] [blame] | 12783 | // Inform StatsLog of setBatteryState changes. |
| 12784 | // If this is the first reporting, pass in recentPast == null. |
| 12785 | private void reportChangesToStatsLog(HistoryItem recentPast, |
| 12786 | final int status, final int plugType, final int level, final int temp) { |
| 12787 | |
| 12788 | if (recentPast == null || recentPast.batteryStatus != status) { |
| 12789 | StatsLog.write(StatsLog.CHARGING_STATE_CHANGED, status); |
| 12790 | } |
| 12791 | if (recentPast == null || recentPast.batteryPlugType != plugType) { |
| 12792 | StatsLog.write(StatsLog.PLUGGED_STATE_CHANGED, plugType); |
| 12793 | } |
| 12794 | if (recentPast == null || recentPast.batteryLevel != level) { |
| 12795 | StatsLog.write(StatsLog.BATTERY_LEVEL_CHANGED, level); |
| 12796 | } |
| 12797 | // Let's just always print the temperature, regardless of whether it changed. |
| 12798 | StatsLog.write(StatsLog.DEVICE_TEMPERATURE_REPORTED, temp); |
| 12799 | } |
| 12800 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12801 | public long getAwakeTimeBattery() { |
| 12802 | return computeBatteryUptime(getBatteryUptimeLocked(), STATS_CURRENT); |
| 12803 | } |
| 12804 | |
| 12805 | public long getAwakeTimePlugged() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 12806 | return (mClocks.uptimeMillis() * 1000) - getAwakeTimeBattery(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12807 | } |
| 12808 | |
| 12809 | @Override |
| 12810 | public long computeUptime(long curTime, int which) { |
| 12811 | switch (which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 12812 | case STATS_SINCE_CHARGED: return mUptime + (curTime-mUptimeStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12813 | case STATS_CURRENT: return (curTime-mUptimeStart); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 12814 | case STATS_SINCE_UNPLUGGED: return (curTime-mOnBatteryTimeBase.getUptimeStart()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12815 | } |
| 12816 | return 0; |
| 12817 | } |
| 12818 | |
| 12819 | @Override |
| 12820 | public long computeRealtime(long curTime, int which) { |
| 12821 | switch (which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 12822 | case STATS_SINCE_CHARGED: return mRealtime + (curTime-mRealtimeStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12823 | case STATS_CURRENT: return (curTime-mRealtimeStart); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 12824 | case STATS_SINCE_UNPLUGGED: return (curTime-mOnBatteryTimeBase.getRealtimeStart()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12825 | } |
| 12826 | return 0; |
| 12827 | } |
| 12828 | |
| 12829 | @Override |
| 12830 | public long computeBatteryUptime(long curTime, int which) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 12831 | return mOnBatteryTimeBase.computeUptime(curTime, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12832 | } |
| 12833 | |
| 12834 | @Override |
| 12835 | public long computeBatteryRealtime(long curTime, int which) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 12836 | return mOnBatteryTimeBase.computeRealtime(curTime, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12837 | } |
| 12838 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 12839 | @Override |
| 12840 | public long computeBatteryScreenOffUptime(long curTime, int which) { |
| 12841 | return mOnBatteryScreenOffTimeBase.computeUptime(curTime, which); |
| 12842 | } |
| 12843 | |
| 12844 | @Override |
| 12845 | public long computeBatteryScreenOffRealtime(long curTime, int which) { |
| 12846 | return mOnBatteryScreenOffTimeBase.computeRealtime(curTime, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12847 | } |
| 12848 | |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 12849 | private long computeTimePerLevel(long[] steps, int numSteps) { |
| 12850 | // For now we'll do a simple average across all steps. |
| 12851 | if (numSteps <= 0) { |
| 12852 | return -1; |
| 12853 | } |
| 12854 | long total = 0; |
| 12855 | for (int i=0; i<numSteps; i++) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 12856 | total += steps[i] & STEP_LEVEL_TIME_MASK; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 12857 | } |
| 12858 | return total / numSteps; |
| 12859 | /* |
| 12860 | long[] buckets = new long[numSteps]; |
| 12861 | int numBuckets = 0; |
| 12862 | int numToAverage = 4; |
| 12863 | int i = 0; |
| 12864 | while (i < numSteps) { |
| 12865 | long totalTime = 0; |
| 12866 | int num = 0; |
| 12867 | for (int j=0; j<numToAverage && (i+j)<numSteps; j++) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 12868 | totalTime += steps[i+j] & STEP_LEVEL_TIME_MASK; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 12869 | num++; |
| 12870 | } |
| 12871 | buckets[numBuckets] = totalTime / num; |
| 12872 | numBuckets++; |
| 12873 | numToAverage *= 2; |
| 12874 | i += num; |
| 12875 | } |
| 12876 | if (numBuckets < 1) { |
| 12877 | return -1; |
| 12878 | } |
| 12879 | long averageTime = buckets[numBuckets-1]; |
| 12880 | for (i=numBuckets-2; i>=0; i--) { |
| 12881 | averageTime = (averageTime + buckets[i]) / 2; |
| 12882 | } |
| 12883 | return averageTime; |
| 12884 | */ |
| 12885 | } |
| 12886 | |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 12887 | @Override |
| 12888 | public long computeBatteryTimeRemaining(long curTime) { |
| 12889 | if (!mOnBattery) { |
| 12890 | return -1; |
| 12891 | } |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 12892 | /* Simple implementation just looks at the average discharge per level across the |
| 12893 | entire sample period. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 12894 | int discharge = (getLowDischargeAmountSinceCharge()+getHighDischargeAmountSinceCharge())/2; |
| 12895 | if (discharge < 2) { |
| 12896 | return -1; |
| 12897 | } |
| 12898 | long duration = computeBatteryRealtime(curTime, STATS_SINCE_CHARGED); |
| 12899 | if (duration < 1000*1000) { |
| 12900 | return -1; |
| 12901 | } |
| 12902 | long usPerLevel = duration/discharge; |
| 12903 | return usPerLevel * mCurrentBatteryLevel; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 12904 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 12905 | if (mDischargeStepTracker.mNumStepDurations < 1) { |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 12906 | return -1; |
| 12907 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 12908 | long msPerLevel = mDischargeStepTracker.computeTimePerLevel(); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 12909 | if (msPerLevel <= 0) { |
| 12910 | return -1; |
| 12911 | } |
| 12912 | return (msPerLevel * mCurrentBatteryLevel) * 1000; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 12913 | } |
| 12914 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 12915 | @Override |
| 12916 | public LevelStepTracker getDischargeLevelStepTracker() { |
| 12917 | return mDischargeStepTracker; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 12918 | } |
| 12919 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 12920 | @Override |
| 12921 | public LevelStepTracker getDailyDischargeLevelStepTracker() { |
| 12922 | return mDailyDischargeStepTracker; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 12923 | } |
| 12924 | |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 12925 | @Override |
| 12926 | public long computeChargeTimeRemaining(long curTime) { |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 12927 | if (mOnBattery) { |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 12928 | // Not yet working. |
| 12929 | return -1; |
| 12930 | } |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 12931 | /* Broken |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 12932 | int curLevel = mCurrentBatteryLevel; |
| 12933 | int plugLevel = mDischargePlugLevel; |
| 12934 | if (plugLevel < 0 || curLevel < (plugLevel+1)) { |
| 12935 | return -1; |
| 12936 | } |
| 12937 | long duration = computeBatteryRealtime(curTime, STATS_SINCE_UNPLUGGED); |
| 12938 | if (duration < 1000*1000) { |
| 12939 | return -1; |
| 12940 | } |
| 12941 | long usPerLevel = duration/(curLevel-plugLevel); |
| 12942 | return usPerLevel * (100-curLevel); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 12943 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 12944 | if (mChargeStepTracker.mNumStepDurations < 1) { |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 12945 | return -1; |
| 12946 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 12947 | long msPerLevel = mChargeStepTracker.computeTimePerLevel(); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 12948 | if (msPerLevel <= 0) { |
| 12949 | return -1; |
| 12950 | } |
| 12951 | return (msPerLevel * (100-mCurrentBatteryLevel)) * 1000; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 12952 | } |
| 12953 | |
Siddharth Ray | a1fd057 | 2017-11-13 14:20:47 -0800 | [diff] [blame] | 12954 | /*@hide */ |
| 12955 | public CellularBatteryStats getCellularBatteryStats() { |
| 12956 | CellularBatteryStats s = new CellularBatteryStats(); |
| 12957 | final int which = STATS_SINCE_CHARGED; |
| 12958 | final long rawRealTime = SystemClock.elapsedRealtime() * 1000; |
| 12959 | final ControllerActivityCounter counter = getModemControllerActivity(); |
| 12960 | final long idleTimeMs = counter.getIdleTimeCounter().getCountLocked(which); |
| 12961 | final long rxTimeMs = counter.getRxTimeCounter().getCountLocked(which); |
| 12962 | final long energyConsumedMaMs = counter.getPowerCounter().getCountLocked(which); |
| 12963 | long[] timeInRatMs = new long[BatteryStats.NUM_DATA_CONNECTION_TYPES]; |
| 12964 | for (int i = 0; i < timeInRatMs.length; i++) { |
| 12965 | timeInRatMs[i] = getPhoneDataConnectionTime(i, rawRealTime, which) / 1000; |
| 12966 | } |
| 12967 | long[] timeInRxSignalStrengthLevelMs = new long[SignalStrength.NUM_SIGNAL_STRENGTH_BINS]; |
| 12968 | for (int i = 0; i < timeInRxSignalStrengthLevelMs.length; i++) { |
| 12969 | timeInRxSignalStrengthLevelMs[i] |
| 12970 | = getPhoneSignalStrengthTime(i, rawRealTime, which) / 1000; |
| 12971 | } |
| 12972 | long[] txTimeMs = new long[Math.min(ModemActivityInfo.TX_POWER_LEVELS, |
| 12973 | counter.getTxTimeCounters().length)]; |
| 12974 | long totalTxTimeMs = 0; |
| 12975 | for (int i = 0; i < txTimeMs.length; i++) { |
| 12976 | txTimeMs[i] = counter.getTxTimeCounters()[i].getCountLocked(which); |
| 12977 | totalTxTimeMs += txTimeMs[i]; |
| 12978 | } |
| 12979 | final long totalControllerActivityTimeMs |
| 12980 | = computeBatteryRealtime(SystemClock.elapsedRealtime() * 1000, which) / 1000; |
| 12981 | final long sleepTimeMs |
| 12982 | = totalControllerActivityTimeMs - (idleTimeMs + rxTimeMs + totalTxTimeMs); |
| 12983 | s.setLoggingDurationMs(computeBatteryRealtime(rawRealTime, which) / 1000); |
| 12984 | s.setKernelActiveTimeMs(getMobileRadioActiveTime(rawRealTime, which) / 1000); |
| 12985 | s.setNumPacketsTx(getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which)); |
| 12986 | s.setNumBytesTx(getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which)); |
| 12987 | s.setNumPacketsRx(getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which)); |
| 12988 | s.setNumBytesRx(getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which)); |
| 12989 | s.setSleepTimeMs(sleepTimeMs); |
| 12990 | s.setIdleTimeMs(idleTimeMs); |
| 12991 | s.setRxTimeMs(rxTimeMs); |
| 12992 | s.setEnergyConsumedMaMs(energyConsumedMaMs); |
| 12993 | s.setTimeInRatMs(timeInRatMs); |
| 12994 | s.setTimeInRxSignalStrengthLevelMs(timeInRxSignalStrengthLevelMs); |
| 12995 | s.setTxTimeMs(txTimeMs); |
| 12996 | return s; |
| 12997 | } |
| 12998 | |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 12999 | /*@hide */ |
| 13000 | public WifiBatteryStats getWifiBatteryStats() { |
| 13001 | WifiBatteryStats s = new WifiBatteryStats(); |
| 13002 | final int which = STATS_SINCE_CHARGED; |
| 13003 | final long rawRealTime = SystemClock.elapsedRealtime() * 1000; |
| 13004 | final ControllerActivityCounter counter = getWifiControllerActivity(); |
| 13005 | final long idleTimeMs = counter.getIdleTimeCounter().getCountLocked(which); |
| 13006 | final long scanTimeMs = counter.getScanTimeCounter().getCountLocked(which); |
| 13007 | final long rxTimeMs = counter.getRxTimeCounter().getCountLocked(which); |
| 13008 | final long txTimeMs = counter.getTxTimeCounters()[0].getCountLocked(which); |
| 13009 | final long totalControllerActivityTimeMs |
| 13010 | = computeBatteryRealtime(SystemClock.elapsedRealtime() * 1000, which) / 1000; |
| 13011 | final long sleepTimeMs |
| 13012 | = totalControllerActivityTimeMs - (idleTimeMs + rxTimeMs + txTimeMs); |
| 13013 | final long energyConsumedMaMs = counter.getPowerCounter().getCountLocked(which); |
| 13014 | long numAppScanRequest = 0; |
| 13015 | for (int i = 0; i < mUidStats.size(); i++) { |
| 13016 | numAppScanRequest += mUidStats.valueAt(i).mWifiScanTimer.getCountLocked(which); |
| 13017 | } |
| 13018 | long[] timeInStateMs = new long[NUM_WIFI_STATES]; |
| 13019 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 13020 | timeInStateMs[i] = getWifiStateTime(i, rawRealTime, which) / 1000; |
| 13021 | } |
| 13022 | long[] timeInSupplStateMs = new long[NUM_WIFI_SUPPL_STATES]; |
| 13023 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 13024 | timeInSupplStateMs[i] = getWifiSupplStateTime(i, rawRealTime, which) / 1000; |
| 13025 | } |
| 13026 | long[] timeSignalStrengthTimeMs = new long[NUM_WIFI_SIGNAL_STRENGTH_BINS]; |
| 13027 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 13028 | timeSignalStrengthTimeMs[i] = getWifiSignalStrengthTime(i, rawRealTime, which) / 1000; |
| 13029 | } |
| 13030 | s.setLoggingDurationMs(computeBatteryRealtime(rawRealTime, which) / 1000); |
| 13031 | s.setKernelActiveTimeMs(getWifiActiveTime(rawRealTime, which) / 1000); |
| 13032 | s.setNumPacketsTx(getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which)); |
| 13033 | s.setNumBytesTx(getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which)); |
| 13034 | s.setNumPacketsRx(getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which)); |
| 13035 | s.setNumBytesRx(getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which)); |
| 13036 | s.setSleepTimeMs(sleepTimeMs); |
| 13037 | s.setIdleTimeMs(idleTimeMs); |
| 13038 | s.setRxTimeMs(rxTimeMs); |
| 13039 | s.setTxTimeMs(txTimeMs); |
| 13040 | s.setScanTimeMs(scanTimeMs); |
| 13041 | s.setEnergyConsumedMaMs(energyConsumedMaMs); |
| 13042 | s.setNumAppScanRequest(numAppScanRequest); |
| 13043 | s.setTimeInStateMs(timeInStateMs); |
| 13044 | s.setTimeInSupplicantStateMs(timeInSupplStateMs); |
| 13045 | s.setTimeInRxSignalStrengthLevelMs(timeSignalStrengthTimeMs); |
| 13046 | return s; |
| 13047 | } |
| 13048 | |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 13049 | /*@hide */ |
| 13050 | public GpsBatteryStats getGpsBatteryStats() { |
| 13051 | GpsBatteryStats s = new GpsBatteryStats(); |
| 13052 | final int which = STATS_SINCE_CHARGED; |
| 13053 | final long rawRealTime = SystemClock.elapsedRealtime() * 1000; |
| 13054 | s.setLoggingDurationMs(computeBatteryRealtime(rawRealTime, which) / 1000); |
| 13055 | s.setEnergyConsumedMaMs(getGpsBatteryDrainMaMs()); |
| 13056 | long[] time = new long[GnssMetrics.NUM_GPS_SIGNAL_QUALITY_LEVELS]; |
| 13057 | for (int i=0; i<time.length; i++) { |
| 13058 | time[i] = getGpsSignalQualityTime(i, rawRealTime, which) / 1000; |
| 13059 | } |
| 13060 | s.setTimeInGpsSignalQualityLevel(time); |
| 13061 | return s; |
| 13062 | } |
| 13063 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 13064 | @Override |
| 13065 | public LevelStepTracker getChargeLevelStepTracker() { |
| 13066 | return mChargeStepTracker; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 13067 | } |
| 13068 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 13069 | @Override |
| 13070 | public LevelStepTracker getDailyChargeLevelStepTracker() { |
| 13071 | return mDailyChargeStepTracker; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 13072 | } |
| 13073 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 13074 | @Override |
| 13075 | public ArrayList<PackageChange> getDailyPackageChanges() { |
| 13076 | return mDailyPackageChanges; |
| 13077 | } |
| 13078 | |
Joe Onorato | e1acd63 | 2016-02-23 13:25:10 -0800 | [diff] [blame] | 13079 | protected long getBatteryUptimeLocked() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 13080 | return mOnBatteryTimeBase.getUptime(mClocks.uptimeMillis() * 1000); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13081 | } |
| 13082 | |
| 13083 | @Override |
| 13084 | public long getBatteryUptime(long curTime) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 13085 | return mOnBatteryTimeBase.getUptime(curTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13086 | } |
| 13087 | |
| 13088 | @Override |
| 13089 | public long getBatteryRealtime(long curTime) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 13090 | return mOnBatteryTimeBase.getRealtime(curTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13091 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 13092 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 13093 | @Override |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 13094 | public int getDischargeStartLevel() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 13095 | synchronized(this) { |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 13096 | return getDischargeStartLevelLocked(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 13097 | } |
| 13098 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 13099 | |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 13100 | public int getDischargeStartLevelLocked() { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 13101 | return mDischargeUnplugLevel; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 13102 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 13103 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 13104 | @Override |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 13105 | public int getDischargeCurrentLevel() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 13106 | synchronized(this) { |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 13107 | return getDischargeCurrentLevelLocked(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 13108 | } |
| 13109 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 13110 | |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 13111 | public int getDischargeCurrentLevelLocked() { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 13112 | return mDischargeCurrentLevel; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 13113 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13114 | |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 13115 | @Override |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 13116 | public int getLowDischargeAmountSinceCharge() { |
| 13117 | synchronized(this) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 13118 | int val = mLowDischargeAmountSinceCharge; |
| 13119 | if (mOnBattery && mDischargeCurrentLevel < mDischargeUnplugLevel) { |
| 13120 | val += mDischargeUnplugLevel-mDischargeCurrentLevel-1; |
| 13121 | } |
| 13122 | return val; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 13123 | } |
| 13124 | } |
| 13125 | |
| 13126 | @Override |
| 13127 | public int getHighDischargeAmountSinceCharge() { |
| 13128 | synchronized(this) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 13129 | int val = mHighDischargeAmountSinceCharge; |
| 13130 | if (mOnBattery && mDischargeCurrentLevel < mDischargeUnplugLevel) { |
| 13131 | val += mDischargeUnplugLevel-mDischargeCurrentLevel; |
| 13132 | } |
| 13133 | return val; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 13134 | } |
| 13135 | } |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 13136 | |
| 13137 | @Override |
| 13138 | public int getDischargeAmount(int which) { |
| 13139 | int dischargeAmount = which == STATS_SINCE_CHARGED |
| 13140 | ? getHighDischargeAmountSinceCharge() |
| 13141 | : (getDischargeStartLevel() - getDischargeCurrentLevel()); |
| 13142 | if (dischargeAmount < 0) { |
| 13143 | dischargeAmount = 0; |
| 13144 | } |
| 13145 | return dischargeAmount; |
| 13146 | } |
| 13147 | |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 13148 | @Override |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 13149 | public int getDischargeAmountScreenOn() { |
| 13150 | synchronized(this) { |
| 13151 | int val = mDischargeAmountScreenOn; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 13152 | if (mOnBattery && isScreenOn(mScreenState) |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 13153 | && mDischargeCurrentLevel < mDischargeScreenOnUnplugLevel) { |
| 13154 | val += mDischargeScreenOnUnplugLevel-mDischargeCurrentLevel; |
| 13155 | } |
| 13156 | return val; |
| 13157 | } |
| 13158 | } |
| 13159 | |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 13160 | @Override |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 13161 | public int getDischargeAmountScreenOnSinceCharge() { |
| 13162 | synchronized(this) { |
| 13163 | int val = mDischargeAmountScreenOnSinceCharge; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 13164 | if (mOnBattery && isScreenOn(mScreenState) |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 13165 | && mDischargeCurrentLevel < mDischargeScreenOnUnplugLevel) { |
| 13166 | val += mDischargeScreenOnUnplugLevel-mDischargeCurrentLevel; |
| 13167 | } |
| 13168 | return val; |
| 13169 | } |
| 13170 | } |
| 13171 | |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 13172 | @Override |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 13173 | public int getDischargeAmountScreenOff() { |
| 13174 | synchronized(this) { |
| 13175 | int val = mDischargeAmountScreenOff; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 13176 | if (mOnBattery && isScreenOff(mScreenState) |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 13177 | && mDischargeCurrentLevel < mDischargeScreenOffUnplugLevel) { |
| 13178 | val += mDischargeScreenOffUnplugLevel-mDischargeCurrentLevel; |
| 13179 | } |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 13180 | // For backward compatibility, doze discharge is counted into screen off. |
| 13181 | return val + getDischargeAmountScreenDoze(); |
| 13182 | } |
| 13183 | } |
| 13184 | |
| 13185 | @Override |
| 13186 | public int getDischargeAmountScreenOffSinceCharge() { |
| 13187 | synchronized(this) { |
| 13188 | int val = mDischargeAmountScreenOffSinceCharge; |
| 13189 | if (mOnBattery && isScreenOff(mScreenState) |
| 13190 | && mDischargeCurrentLevel < mDischargeScreenOffUnplugLevel) { |
| 13191 | val += mDischargeScreenOffUnplugLevel-mDischargeCurrentLevel; |
| 13192 | } |
| 13193 | // For backward compatibility, doze discharge is counted into screen off. |
| 13194 | return val + getDischargeAmountScreenDozeSinceCharge(); |
| 13195 | } |
| 13196 | } |
| 13197 | |
| 13198 | @Override |
| 13199 | public int getDischargeAmountScreenDoze() { |
| 13200 | synchronized(this) { |
| 13201 | int val = mDischargeAmountScreenDoze; |
| 13202 | if (mOnBattery && isScreenDoze(mScreenState) |
| 13203 | && mDischargeCurrentLevel < mDischargeScreenDozeUnplugLevel) { |
| 13204 | val += mDischargeScreenDozeUnplugLevel-mDischargeCurrentLevel; |
| 13205 | } |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 13206 | return val; |
| 13207 | } |
| 13208 | } |
| 13209 | |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 13210 | @Override |
| 13211 | public int getDischargeAmountScreenDozeSinceCharge() { |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 13212 | synchronized(this) { |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 13213 | int val = mDischargeAmountScreenDozeSinceCharge; |
| 13214 | if (mOnBattery && isScreenDoze(mScreenState) |
| 13215 | && mDischargeCurrentLevel < mDischargeScreenDozeUnplugLevel) { |
| 13216 | val += mDischargeScreenDozeUnplugLevel-mDischargeCurrentLevel; |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 13217 | } |
| 13218 | return val; |
| 13219 | } |
| 13220 | } |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 13221 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13222 | /** |
| 13223 | * Retrieve the statistics object for a particular uid, creating if needed. |
| 13224 | */ |
| 13225 | public Uid getUidStatsLocked(int uid) { |
| 13226 | Uid u = mUidStats.get(uid); |
| 13227 | if (u == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 13228 | u = new Uid(this, uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13229 | mUidStats.put(uid, u); |
| 13230 | } |
| 13231 | return u; |
| 13232 | } |
| 13233 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 13234 | /** |
| 13235 | * Retrieve the statistics object for a particular uid. Returns null if the object is not |
| 13236 | * available. |
| 13237 | */ |
| 13238 | public Uid getAvailableUidStatsLocked(int uid) { |
| 13239 | Uid u = mUidStats.get(uid); |
| 13240 | return u; |
| 13241 | } |
| 13242 | |
Suprabh Shukla | e6e723d | 2017-06-14 16:14:43 -0700 | [diff] [blame] | 13243 | public void onCleanupUserLocked(int userId) { |
| 13244 | final int firstUidForUser = UserHandle.getUid(userId, 0); |
| 13245 | final int lastUidForUser = UserHandle.getUid(userId, UserHandle.PER_USER_RANGE - 1); |
| 13246 | mKernelUidCpuFreqTimeReader.removeUidsInRange(firstUidForUser, lastUidForUser); |
| 13247 | mKernelUidCpuTimeReader.removeUidsInRange(firstUidForUser, lastUidForUser); |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 13248 | if (mKernelSingleUidTimeReader != null) { |
| 13249 | mKernelSingleUidTimeReader.removeUidsInRange(firstUidForUser, lastUidForUser); |
| 13250 | } |
Suprabh Shukla | e6e723d | 2017-06-14 16:14:43 -0700 | [diff] [blame] | 13251 | } |
| 13252 | |
| 13253 | public void onUserRemovedLocked(int userId) { |
| 13254 | final int firstUidForUser = UserHandle.getUid(userId, 0); |
| 13255 | final int lastUidForUser = UserHandle.getUid(userId, UserHandle.PER_USER_RANGE - 1); |
| 13256 | mUidStats.put(firstUidForUser, null); |
| 13257 | mUidStats.put(lastUidForUser, null); |
| 13258 | final int firstIndex = mUidStats.indexOfKey(firstUidForUser); |
| 13259 | final int lastIndex = mUidStats.indexOfKey(lastUidForUser); |
| 13260 | mUidStats.removeAtRange(firstIndex, lastIndex - firstIndex + 1); |
| 13261 | } |
| 13262 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13263 | /** |
| 13264 | * Remove the statistics object for a particular uid. |
| 13265 | */ |
| 13266 | public void removeUidStatsLocked(int uid) { |
Adam Lesinski | b83ffee | 2015-05-12 14:43:47 -0700 | [diff] [blame] | 13267 | mKernelUidCpuTimeReader.removeUid(uid); |
Sudheer Shanka | 6d8dcec | 2017-06-01 12:09:03 -0700 | [diff] [blame] | 13268 | mKernelUidCpuFreqTimeReader.removeUid(uid); |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 13269 | if (mKernelSingleUidTimeReader != null) { |
| 13270 | mKernelSingleUidTimeReader.removeUid(uid); |
| 13271 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13272 | mUidStats.remove(uid); |
| 13273 | } |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 13274 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13275 | /** |
| 13276 | * Retrieve the statistics object for a particular process, creating |
| 13277 | * if needed. |
| 13278 | */ |
| 13279 | public Uid.Proc getProcessStatsLocked(int uid, String name) { |
Dianne Hackborn | bbb7472 | 2014-03-13 09:50:24 -0700 | [diff] [blame] | 13280 | uid = mapUid(uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13281 | Uid u = getUidStatsLocked(uid); |
| 13282 | return u.getProcessStatsLocked(name); |
| 13283 | } |
| 13284 | |
| 13285 | /** |
| 13286 | * Retrieve the statistics object for a particular process, creating |
| 13287 | * if needed. |
| 13288 | */ |
| 13289 | public Uid.Pkg getPackageStatsLocked(int uid, String pkg) { |
Dianne Hackborn | bbb7472 | 2014-03-13 09:50:24 -0700 | [diff] [blame] | 13290 | uid = mapUid(uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13291 | Uid u = getUidStatsLocked(uid); |
| 13292 | return u.getPackageStatsLocked(pkg); |
| 13293 | } |
| 13294 | |
| 13295 | /** |
| 13296 | * Retrieve the statistics object for a particular service, creating |
| 13297 | * if needed. |
| 13298 | */ |
| 13299 | public Uid.Pkg.Serv getServiceStatsLocked(int uid, String pkg, String name) { |
Dianne Hackborn | bbb7472 | 2014-03-13 09:50:24 -0700 | [diff] [blame] | 13300 | uid = mapUid(uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13301 | Uid u = getUidStatsLocked(uid); |
| 13302 | return u.getServiceStatsLocked(pkg, name); |
| 13303 | } |
| 13304 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 13305 | public void shutdownLocked() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 13306 | recordShutdownLocked(mClocks.elapsedRealtime(), mClocks.uptimeMillis()); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 13307 | writeSyncLocked(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 13308 | mShuttingDown = true; |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 13309 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 13310 | |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 13311 | public boolean trackPerProcStateCpuTimes() { |
| 13312 | return mConstants.TRACK_CPU_TIMES_BY_PROC_STATE && mPerProcStateCpuTimesAvailable; |
| 13313 | } |
| 13314 | |
| 13315 | public void systemServicesReady(Context context) { |
| 13316 | mConstants.startObserving(context.getContentResolver()); |
| 13317 | } |
| 13318 | |
| 13319 | @VisibleForTesting |
| 13320 | public final class Constants extends ContentObserver { |
| 13321 | public static final String KEY_TRACK_CPU_TIMES_BY_PROC_STATE |
| 13322 | = "track_cpu_times_by_proc_state"; |
Mike Ma | fae87da | 2018-01-19 20:07:20 -0800 | [diff] [blame] | 13323 | public static final String KEY_TRACK_CPU_ACTIVE_CLUSTER_TIME |
| 13324 | = "track_cpu_active_cluster_time"; |
| 13325 | public static final String KEY_READ_BINARY_CPU_TIME |
| 13326 | = "read_binary_cpu_time"; |
Sudheer Shanka | c20379e | 2018-02-15 00:06:21 -0800 | [diff] [blame] | 13327 | public static final String KEY_PROC_STATE_CPU_TIMES_READ_DELAY_MS |
| 13328 | = "proc_state_cpu_times_read_delay_ms"; |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 13329 | |
| 13330 | private static final boolean DEFAULT_TRACK_CPU_TIMES_BY_PROC_STATE = true; |
Mike Ma | fae87da | 2018-01-19 20:07:20 -0800 | [diff] [blame] | 13331 | private static final boolean DEFAULT_TRACK_CPU_ACTIVE_CLUSTER_TIME = true; |
| 13332 | private static final boolean DEFAULT_READ_BINARY_CPU_TIME = false; |
Sudheer Shanka | c20379e | 2018-02-15 00:06:21 -0800 | [diff] [blame] | 13333 | private static final long DEFAULT_PROC_STATE_CPU_TIMES_READ_DELAY_MS = 5_000; |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 13334 | |
| 13335 | 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] | 13336 | public boolean TRACK_CPU_ACTIVE_CLUSTER_TIME = DEFAULT_TRACK_CPU_ACTIVE_CLUSTER_TIME; |
| 13337 | // Not used right now. |
| 13338 | public boolean READ_BINARY_CPU_TIME = DEFAULT_READ_BINARY_CPU_TIME; |
Sudheer Shanka | c20379e | 2018-02-15 00:06:21 -0800 | [diff] [blame] | 13339 | public long PROC_STATE_CPU_TIMES_READ_DELAY_MS = DEFAULT_PROC_STATE_CPU_TIMES_READ_DELAY_MS; |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 13340 | |
| 13341 | private ContentResolver mResolver; |
| 13342 | private final KeyValueListParser mParser = new KeyValueListParser(','); |
| 13343 | |
| 13344 | public Constants(Handler handler) { |
| 13345 | super(handler); |
| 13346 | } |
| 13347 | |
| 13348 | public void startObserving(ContentResolver resolver) { |
| 13349 | mResolver = resolver; |
| 13350 | mResolver.registerContentObserver( |
| 13351 | Settings.Global.getUriFor(Settings.Global.BATTERY_STATS_CONSTANTS), |
| 13352 | false /* notifyForDescendants */, this); |
| 13353 | updateConstants(); |
| 13354 | } |
| 13355 | |
| 13356 | @Override |
| 13357 | public void onChange(boolean selfChange, Uri uri) { |
| 13358 | updateConstants(); |
| 13359 | } |
| 13360 | |
| 13361 | private void updateConstants() { |
| 13362 | synchronized (BatteryStatsImpl.this) { |
| 13363 | try { |
| 13364 | mParser.setString(Settings.Global.getString(mResolver, |
| 13365 | Settings.Global.BATTERY_STATS_CONSTANTS)); |
| 13366 | } catch (IllegalArgumentException e) { |
| 13367 | // Failed to parse the settings string, log this and move on |
| 13368 | // with defaults. |
| 13369 | Slog.e(TAG, "Bad batterystats settings", e); |
| 13370 | } |
| 13371 | |
| 13372 | updateTrackCpuTimesByProcStateLocked(TRACK_CPU_TIMES_BY_PROC_STATE, |
| 13373 | mParser.getBoolean(KEY_TRACK_CPU_TIMES_BY_PROC_STATE, |
| 13374 | DEFAULT_TRACK_CPU_TIMES_BY_PROC_STATE)); |
Mike Ma | fae87da | 2018-01-19 20:07:20 -0800 | [diff] [blame] | 13375 | TRACK_CPU_ACTIVE_CLUSTER_TIME = mParser.getBoolean( |
| 13376 | KEY_TRACK_CPU_ACTIVE_CLUSTER_TIME, DEFAULT_TRACK_CPU_ACTIVE_CLUSTER_TIME); |
| 13377 | READ_BINARY_CPU_TIME = mParser.getBoolean( |
| 13378 | KEY_READ_BINARY_CPU_TIME, DEFAULT_READ_BINARY_CPU_TIME); |
Sudheer Shanka | c20379e | 2018-02-15 00:06:21 -0800 | [diff] [blame] | 13379 | updateProcStateCpuTimesReadDelayMs(PROC_STATE_CPU_TIMES_READ_DELAY_MS, |
| 13380 | mParser.getLong(KEY_PROC_STATE_CPU_TIMES_READ_DELAY_MS, |
| 13381 | DEFAULT_PROC_STATE_CPU_TIMES_READ_DELAY_MS)); |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 13382 | } |
| 13383 | } |
| 13384 | |
| 13385 | private void updateTrackCpuTimesByProcStateLocked(boolean wasEnabled, boolean isEnabled) { |
| 13386 | TRACK_CPU_TIMES_BY_PROC_STATE = isEnabled; |
| 13387 | if (isEnabled && !wasEnabled) { |
| 13388 | mKernelSingleUidTimeReader.markDataAsStale(true); |
| 13389 | mExternalSync.scheduleCpuSyncDueToSettingChange(); |
Sudheer Shanka | c20379e | 2018-02-15 00:06:21 -0800 | [diff] [blame] | 13390 | |
| 13391 | mNumCpuTimeReads = 0; |
| 13392 | mNumBatchedCpuTimeReads = 0; |
| 13393 | mCpuTimeReadsTrackingStartTime = mClocks.uptimeMillis(); |
| 13394 | } |
| 13395 | } |
| 13396 | |
| 13397 | private void updateProcStateCpuTimesReadDelayMs(long oldDelayMillis, long newDelayMillis) { |
| 13398 | PROC_STATE_CPU_TIMES_READ_DELAY_MS = newDelayMillis; |
| 13399 | if (oldDelayMillis != newDelayMillis) { |
| 13400 | mNumCpuTimeReads = 0; |
| 13401 | mNumBatchedCpuTimeReads = 0; |
| 13402 | mCpuTimeReadsTrackingStartTime = mClocks.uptimeMillis(); |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 13403 | } |
| 13404 | } |
| 13405 | |
| 13406 | public void dumpLocked(PrintWriter pw) { |
| 13407 | pw.print(KEY_TRACK_CPU_TIMES_BY_PROC_STATE); pw.print("="); |
| 13408 | pw.println(TRACK_CPU_TIMES_BY_PROC_STATE); |
Mike Ma | fae87da | 2018-01-19 20:07:20 -0800 | [diff] [blame] | 13409 | pw.print(KEY_TRACK_CPU_ACTIVE_CLUSTER_TIME); pw.print("="); |
| 13410 | pw.println(TRACK_CPU_ACTIVE_CLUSTER_TIME); |
| 13411 | pw.print(KEY_READ_BINARY_CPU_TIME); pw.print("="); |
| 13412 | pw.println(READ_BINARY_CPU_TIME); |
Sudheer Shanka | c20379e | 2018-02-15 00:06:21 -0800 | [diff] [blame] | 13413 | pw.print(KEY_PROC_STATE_CPU_TIMES_READ_DELAY_MS); pw.print("="); |
| 13414 | pw.println(PROC_STATE_CPU_TIMES_READ_DELAY_MS); |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 13415 | } |
| 13416 | } |
| 13417 | |
Andreas Gampe | 3f24e69 | 2018-02-05 13:24:28 -0800 | [diff] [blame] | 13418 | @GuardedBy("this") |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 13419 | public void dumpConstantsLocked(PrintWriter pw) { |
| 13420 | mConstants.dumpLocked(pw); |
| 13421 | } |
| 13422 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 13423 | Parcel mPendingWrite = null; |
| 13424 | final ReentrantLock mWriteLock = new ReentrantLock(); |
| 13425 | |
| 13426 | public void writeAsyncLocked() { |
| 13427 | writeLocked(false); |
| 13428 | } |
| 13429 | |
| 13430 | public void writeSyncLocked() { |
| 13431 | writeLocked(true); |
| 13432 | } |
| 13433 | |
| 13434 | void writeLocked(boolean sync) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 13435 | if (mFile == null) { |
| 13436 | 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] | 13437 | return; |
| 13438 | } |
| 13439 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 13440 | if (mShuttingDown) { |
| 13441 | return; |
| 13442 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 13443 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 13444 | Parcel out = Parcel.obtain(); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 13445 | writeSummaryToParcel(out, true); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 13446 | mLastWriteTime = mClocks.elapsedRealtime(); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 13447 | |
| 13448 | if (mPendingWrite != null) { |
| 13449 | mPendingWrite.recycle(); |
| 13450 | } |
| 13451 | mPendingWrite = out; |
| 13452 | |
| 13453 | if (sync) { |
| 13454 | commitPendingDataToDisk(); |
| 13455 | } else { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 13456 | BackgroundThread.getHandler().post(new Runnable() { |
| 13457 | @Override public void run() { |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 13458 | commitPendingDataToDisk(); |
| 13459 | } |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 13460 | }); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 13461 | } |
| 13462 | } |
| 13463 | |
| 13464 | public void commitPendingDataToDisk() { |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 13465 | final Parcel next; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 13466 | synchronized (this) { |
| 13467 | next = mPendingWrite; |
| 13468 | mPendingWrite = null; |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 13469 | if (next == null) { |
| 13470 | return; |
| 13471 | } |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 13472 | } |
| 13473 | |
Amith Yamasani | d245086 | 2017-02-07 15:58:24 -0800 | [diff] [blame] | 13474 | mWriteLock.lock(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13475 | try { |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 13476 | final long startTime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 13477 | FileOutputStream stream = new FileOutputStream(mFile.chooseForWrite()); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 13478 | stream.write(next.marshall()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13479 | stream.flush(); |
Dianne Hackborn | 8bdf593 | 2010-10-15 12:54:40 -0700 | [diff] [blame] | 13480 | FileUtils.sync(stream); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13481 | stream.close(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 13482 | mFile.commit(); |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 13483 | com.android.internal.logging.EventLogTags.writeCommitSysConfigFile( |
| 13484 | "batterystats", SystemClock.uptimeMillis() - startTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13485 | } catch (IOException e) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 13486 | Slog.w("BatteryStats", "Error writing battery statistics", e); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 13487 | mFile.rollback(); |
| 13488 | } finally { |
| 13489 | next.recycle(); |
| 13490 | mWriteLock.unlock(); |
Suchi Amalapurapu | 8550f25 | 2009-09-29 15:20:32 -0700 | [diff] [blame] | 13491 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13492 | } |
| 13493 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13494 | public void readLocked() { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 13495 | if (mDailyFile != null) { |
| 13496 | readDailyStatsLocked(); |
| 13497 | } |
| 13498 | |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 13499 | if (mFile == null) { |
| 13500 | 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] | 13501 | return; |
| 13502 | } |
| 13503 | |
| 13504 | mUidStats.clear(); |
| 13505 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13506 | try { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 13507 | File file = mFile.chooseForRead(); |
| 13508 | if (!file.exists()) { |
| 13509 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13510 | } |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 13511 | FileInputStream stream = new FileInputStream(file); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13512 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 13513 | byte[] raw = BatteryStatsHelper.readFully(stream); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13514 | Parcel in = Parcel.obtain(); |
| 13515 | in.unmarshall(raw, 0, raw.length); |
| 13516 | in.setDataPosition(0); |
| 13517 | stream.close(); |
| 13518 | |
| 13519 | readSummaryFromParcel(in); |
Dianne Hackborn | 00e2521 | 2014-02-19 10:49:24 -0800 | [diff] [blame] | 13520 | } catch(Exception e) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 13521 | Slog.e("BatteryStats", "Error reading battery statistics", e); |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 13522 | resetAllStatsLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13523 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 13524 | |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 13525 | mEndPlatformVersion = Build.ID; |
| 13526 | |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 13527 | if (mHistoryBuffer.dataPosition() > 0) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 13528 | mRecordingHistory = true; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 13529 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 13530 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 13531 | if (USE_OLD_HISTORY) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 13532 | addHistoryRecordLocked(elapsedRealtime, uptime, HistoryItem.CMD_START, mHistoryCur); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 13533 | } |
Narayan Kamath | 5a5a7fe | 2018-02-05 17:30:06 +0000 | [diff] [blame] | 13534 | addHistoryBufferLocked(elapsedRealtime, HistoryItem.CMD_START, mHistoryCur); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 13535 | startRecordingHistory(elapsedRealtime, uptime, false); |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 13536 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 13537 | |
| 13538 | recordDailyStatsIfNeededLocked(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13539 | } |
| 13540 | |
| 13541 | public int describeContents() { |
| 13542 | return 0; |
| 13543 | } |
| 13544 | |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 13545 | void readHistory(Parcel in, boolean andOldHistory) throws ParcelFormatException { |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 13546 | final long historyBaseTime = in.readLong(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 13547 | |
| 13548 | mHistoryBuffer.setDataSize(0); |
| 13549 | mHistoryBuffer.setDataPosition(0); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 13550 | mHistoryTagPool.clear(); |
| 13551 | mNextHistoryTagIdx = 0; |
| 13552 | mNumHistoryTagChars = 0; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 13553 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 13554 | int numTags = in.readInt(); |
| 13555 | for (int i=0; i<numTags; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 13556 | int idx = in.readInt(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 13557 | String str = in.readString(); |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 13558 | if (str == null) { |
| 13559 | throw new ParcelFormatException("null history tag string"); |
| 13560 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 13561 | int uid = in.readInt(); |
| 13562 | HistoryTag tag = new HistoryTag(); |
| 13563 | tag.string = str; |
| 13564 | tag.uid = uid; |
| 13565 | tag.poolIdx = idx; |
| 13566 | mHistoryTagPool.put(tag, idx); |
| 13567 | if (idx >= mNextHistoryTagIdx) { |
| 13568 | mNextHistoryTagIdx = idx+1; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 13569 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 13570 | mNumHistoryTagChars += tag.string.length() + 1; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 13571 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 13572 | |
| 13573 | int bufSize = in.readInt(); |
| 13574 | int curPos = in.dataPosition(); |
| 13575 | if (bufSize >= (MAX_MAX_HISTORY_BUFFER*3)) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 13576 | throw new ParcelFormatException("File corrupt: history data buffer too large " + |
| 13577 | bufSize); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 13578 | } else if ((bufSize&~3) != bufSize) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 13579 | throw new ParcelFormatException("File corrupt: history data buffer not aligned " + |
| 13580 | bufSize); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 13581 | } else { |
| 13582 | if (DEBUG_HISTORY) Slog.i(TAG, "***************** READING NEW HISTORY: " + bufSize |
| 13583 | + " bytes at " + curPos); |
| 13584 | mHistoryBuffer.appendFrom(in, curPos, bufSize); |
| 13585 | in.setDataPosition(curPos + bufSize); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 13586 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 13587 | |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 13588 | if (andOldHistory) { |
| 13589 | readOldHistory(in); |
| 13590 | } |
| 13591 | |
| 13592 | if (DEBUG_HISTORY) { |
| 13593 | StringBuilder sb = new StringBuilder(128); |
| 13594 | sb.append("****************** OLD mHistoryBaseTime: "); |
| 13595 | TimeUtils.formatDuration(mHistoryBaseTime, sb); |
| 13596 | Slog.i(TAG, sb.toString()); |
| 13597 | } |
| 13598 | mHistoryBaseTime = historyBaseTime; |
| 13599 | if (DEBUG_HISTORY) { |
| 13600 | StringBuilder sb = new StringBuilder(128); |
| 13601 | sb.append("****************** NEW mHistoryBaseTime: "); |
| 13602 | TimeUtils.formatDuration(mHistoryBaseTime, sb); |
| 13603 | Slog.i(TAG, sb.toString()); |
| 13604 | } |
| 13605 | |
| 13606 | // We are just arbitrarily going to insert 1 minute from the sample of |
| 13607 | // the last run until samples in this run. |
| 13608 | if (mHistoryBaseTime > 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 13609 | long oldnow = mClocks.elapsedRealtime(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 13610 | mHistoryBaseTime = mHistoryBaseTime - oldnow + 1; |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 13611 | if (DEBUG_HISTORY) { |
| 13612 | StringBuilder sb = new StringBuilder(128); |
| 13613 | sb.append("****************** ADJUSTED mHistoryBaseTime: "); |
| 13614 | TimeUtils.formatDuration(mHistoryBaseTime, sb); |
| 13615 | Slog.i(TAG, sb.toString()); |
| 13616 | } |
Dianne Hackborn | 1e4b9f3 | 2010-06-23 14:10:57 -0700 | [diff] [blame] | 13617 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 13618 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 13619 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 13620 | void readOldHistory(Parcel in) { |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 13621 | if (!USE_OLD_HISTORY) { |
| 13622 | return; |
| 13623 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 13624 | mHistory = mHistoryEnd = mHistoryCache = null; |
| 13625 | long time; |
Conley Owens | 5e3357f | 2011-05-02 09:59:30 -0700 | [diff] [blame] | 13626 | while (in.dataAvail() > 0 && (time=in.readLong()) >= 0) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 13627 | HistoryItem rec = new HistoryItem(time, in); |
| 13628 | addHistoryRecordLocked(rec); |
| 13629 | } |
| 13630 | } |
| 13631 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 13632 | void writeHistory(Parcel out, boolean inclData, boolean andOldHistory) { |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 13633 | if (DEBUG_HISTORY) { |
| 13634 | StringBuilder sb = new StringBuilder(128); |
| 13635 | sb.append("****************** WRITING mHistoryBaseTime: "); |
| 13636 | TimeUtils.formatDuration(mHistoryBaseTime, sb); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 13637 | sb.append(" mLastHistoryElapsedRealtime: "); |
| 13638 | TimeUtils.formatDuration(mLastHistoryElapsedRealtime, sb); |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 13639 | Slog.i(TAG, sb.toString()); |
| 13640 | } |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 13641 | out.writeLong(mHistoryBaseTime + mLastHistoryElapsedRealtime); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 13642 | if (!inclData) { |
| 13643 | out.writeInt(0); |
| 13644 | out.writeInt(0); |
| 13645 | return; |
| 13646 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 13647 | out.writeInt(mHistoryTagPool.size()); |
| 13648 | for (HashMap.Entry<HistoryTag, Integer> ent : mHistoryTagPool.entrySet()) { |
| 13649 | HistoryTag tag = ent.getKey(); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 13650 | out.writeInt(ent.getValue()); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 13651 | out.writeString(tag.string); |
| 13652 | out.writeInt(tag.uid); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 13653 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 13654 | out.writeInt(mHistoryBuffer.dataSize()); |
| 13655 | if (DEBUG_HISTORY) Slog.i(TAG, "***************** WRITING HISTORY: " |
| 13656 | + mHistoryBuffer.dataSize() + " bytes at " + out.dataPosition()); |
| 13657 | out.appendFrom(mHistoryBuffer, 0, mHistoryBuffer.dataSize()); |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 13658 | |
| 13659 | if (andOldHistory) { |
| 13660 | writeOldHistory(out); |
| 13661 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 13662 | } |
| 13663 | |
| 13664 | void writeOldHistory(Parcel out) { |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 13665 | if (!USE_OLD_HISTORY) { |
| 13666 | return; |
| 13667 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 13668 | HistoryItem rec = mHistory; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 13669 | while (rec != null) { |
| 13670 | if (rec.time >= 0) rec.writeToParcel(out, 0); |
| 13671 | rec = rec.next; |
| 13672 | } |
| 13673 | out.writeLong(-1); |
| 13674 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 13675 | |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 13676 | public void readSummaryFromParcel(Parcel in) throws ParcelFormatException { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13677 | final int version = in.readInt(); |
| 13678 | if (version != VERSION) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 13679 | Slog.w("BatteryStats", "readFromParcel: version got " + version |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13680 | + ", expected " + VERSION + "; erasing old stats"); |
| 13681 | return; |
| 13682 | } |
| 13683 | |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 13684 | readHistory(in, true); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 13685 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13686 | mStartCount = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13687 | mUptime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13688 | mRealtime = in.readLong(); |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 13689 | mStartClockTime = in.readLong(); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 13690 | mStartPlatformVersion = in.readString(); |
| 13691 | mEndPlatformVersion = in.readString(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 13692 | mOnBatteryTimeBase.readSummaryFromParcel(in); |
| 13693 | mOnBatteryScreenOffTimeBase.readSummaryFromParcel(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 13694 | mDischargeUnplugLevel = in.readInt(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 13695 | mDischargePlugLevel = in.readInt(); |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 13696 | mDischargeCurrentLevel = in.readInt(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 13697 | mCurrentBatteryLevel = in.readInt(); |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 13698 | mEstimatedBatteryCapacity = in.readInt(); |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 13699 | mMinLearnedBatteryCapacity = in.readInt(); |
| 13700 | mMaxLearnedBatteryCapacity = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 13701 | mLowDischargeAmountSinceCharge = in.readInt(); |
| 13702 | mHighDischargeAmountSinceCharge = in.readInt(); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 13703 | mDischargeAmountScreenOnSinceCharge = in.readInt(); |
| 13704 | mDischargeAmountScreenOffSinceCharge = in.readInt(); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 13705 | mDischargeAmountScreenDozeSinceCharge = in.readInt(); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 13706 | mDischargeStepTracker.readFromParcel(in); |
| 13707 | mChargeStepTracker.readFromParcel(in); |
| 13708 | mDailyDischargeStepTracker.readFromParcel(in); |
| 13709 | mDailyChargeStepTracker.readFromParcel(in); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 13710 | mDischargeCounter.readSummaryFromParcelLocked(in); |
| 13711 | mDischargeScreenOffCounter.readSummaryFromParcelLocked(in); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 13712 | mDischargeScreenDozeCounter.readSummaryFromParcelLocked(in); |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 13713 | mDischargeLightDozeCounter.readSummaryFromParcelLocked(in); |
| 13714 | mDischargeDeepDozeCounter.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 13715 | int NPKG = in.readInt(); |
| 13716 | if (NPKG > 0) { |
| 13717 | mDailyPackageChanges = new ArrayList<>(NPKG); |
| 13718 | while (NPKG > 0) { |
| 13719 | NPKG--; |
| 13720 | PackageChange pc = new PackageChange(); |
| 13721 | pc.mPackageName = in.readString(); |
| 13722 | pc.mUpdate = in.readInt() != 0; |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 13723 | pc.mVersionCode = in.readLong(); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 13724 | mDailyPackageChanges.add(pc); |
| 13725 | } |
| 13726 | } else { |
| 13727 | mDailyPackageChanges = null; |
| 13728 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 13729 | mDailyStartTime = in.readLong(); |
| 13730 | mNextMinDailyDeadline = in.readLong(); |
| 13731 | mNextMaxDailyDeadline = in.readLong(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 13732 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13733 | mStartCount++; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 13734 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 13735 | mScreenState = Display.STATE_UNKNOWN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13736 | mScreenOnTimer.readSummaryFromParcelLocked(in); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 13737 | mScreenDozeTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 13738 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
| 13739 | mScreenBrightnessTimer[i].readSummaryFromParcelLocked(in); |
| 13740 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 13741 | mInteractive = false; |
| 13742 | mInteractiveTimer.readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13743 | mPhoneOn = false; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 13744 | mPowerSaveModeEnabledTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 13745 | mLongestLightIdleTime = in.readLong(); |
| 13746 | mLongestFullIdleTime = in.readLong(); |
| 13747 | mDeviceIdleModeLightTimer.readSummaryFromParcelLocked(in); |
| 13748 | mDeviceIdleModeFullTimer.readSummaryFromParcelLocked(in); |
| 13749 | mDeviceLightIdlingTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 13750 | mDeviceIdlingTimer.readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13751 | mPhoneOnTimer.readSummaryFromParcelLocked(in); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 13752 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 13753 | mPhoneSignalStrengthsTimer[i].readSummaryFromParcelLocked(in); |
| 13754 | } |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 13755 | mPhoneSignalScanningTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 13756 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
| 13757 | mPhoneDataConnectionsTimer[i].readSummaryFromParcelLocked(in); |
| 13758 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 13759 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 13760 | mNetworkByteActivityCounters[i].readSummaryFromParcelLocked(in); |
| 13761 | mNetworkPacketActivityCounters[i].readSummaryFromParcelLocked(in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 13762 | } |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 13763 | mMobileRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 13764 | mMobileRadioActiveTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 13765 | mMobileRadioActivePerAppTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 13766 | mMobileRadioActiveAdjustedTime.readSummaryFromParcelLocked(in); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 13767 | mMobileRadioActiveUnknownTime.readSummaryFromParcelLocked(in); |
| 13768 | mMobileRadioActiveUnknownCount.readSummaryFromParcelLocked(in); |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 13769 | mWifiMulticastWakelockTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 13770 | mWifiRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 13771 | mWifiOn = false; |
| 13772 | mWifiOnTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 13773 | mGlobalWifiRunning = false; |
| 13774 | mGlobalWifiRunningTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 13775 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 13776 | mWifiStateTimer[i].readSummaryFromParcelLocked(in); |
| 13777 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 13778 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 13779 | mWifiSupplStateTimer[i].readSummaryFromParcelLocked(in); |
| 13780 | } |
| 13781 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 13782 | mWifiSignalStrengthsTimer[i].readSummaryFromParcelLocked(in); |
| 13783 | } |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 13784 | mWifiActiveTimer.readSummaryFromParcelLocked(in); |
| 13785 | mWifiActivity.readSummaryFromParcel(in); |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 13786 | for (int i=0; i<GnssMetrics.NUM_GPS_SIGNAL_QUALITY_LEVELS; i++) { |
| 13787 | mGpsSignalQualityTimer[i].readSummaryFromParcelLocked(in); |
| 13788 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 13789 | mBluetoothActivity.readSummaryFromParcel(in); |
| 13790 | mModemActivity.readSummaryFromParcel(in); |
| 13791 | mHasWifiReporting = in.readInt() != 0; |
| 13792 | mHasBluetoothReporting = in.readInt() != 0; |
| 13793 | mHasModemReporting = in.readInt() != 0; |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 13794 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 13795 | mNumConnectivityChange = mLoadedNumConnectivityChange = in.readInt(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 13796 | mFlashlightOnNesting = 0; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 13797 | mFlashlightOnTimer.readSummaryFromParcelLocked(in); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 13798 | mCameraOnNesting = 0; |
| 13799 | mCameraOnTimer.readSummaryFromParcelLocked(in); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 13800 | mBluetoothScanNesting = 0; |
| 13801 | mBluetoothScanTimer.readSummaryFromParcelLocked(in); |
Siddharth Ray | f5e796a | 2018-01-22 18:18:17 -0800 | [diff] [blame] | 13802 | mIsCellularTxPowerHigh = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13803 | |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 13804 | int NRPMS = in.readInt(); |
| 13805 | if (NRPMS > 10000) { |
| 13806 | throw new ParcelFormatException("File corrupt: too many rpm stats " + NRPMS); |
| 13807 | } |
| 13808 | for (int irpm = 0; irpm < NRPMS; irpm++) { |
| 13809 | if (in.readInt() != 0) { |
| 13810 | String rpmName = in.readString(); |
| 13811 | getRpmTimerLocked(rpmName).readSummaryFromParcelLocked(in); |
| 13812 | } |
| 13813 | } |
| 13814 | int NSORPMS = in.readInt(); |
| 13815 | if (NSORPMS > 10000) { |
| 13816 | throw new ParcelFormatException("File corrupt: too many screen-off rpm stats " + NSORPMS); |
| 13817 | } |
| 13818 | for (int irpm = 0; irpm < NSORPMS; irpm++) { |
| 13819 | if (in.readInt() != 0) { |
| 13820 | String rpmName = in.readString(); |
| 13821 | getScreenOffRpmTimerLocked(rpmName).readSummaryFromParcelLocked(in); |
| 13822 | } |
| 13823 | } |
| 13824 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 13825 | int NKW = in.readInt(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 13826 | if (NKW > 10000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 13827 | throw new ParcelFormatException("File corrupt: too many kernel wake locks " + NKW); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 13828 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 13829 | for (int ikw = 0; ikw < NKW; ikw++) { |
| 13830 | if (in.readInt() != 0) { |
| 13831 | String kwltName = in.readString(); |
| 13832 | getKernelWakelockTimerLocked(kwltName).readSummaryFromParcelLocked(in); |
| 13833 | } |
| 13834 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 13835 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 13836 | int NWR = in.readInt(); |
| 13837 | if (NWR > 10000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 13838 | throw new ParcelFormatException("File corrupt: too many wakeup reasons " + NWR); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 13839 | } |
| 13840 | for (int iwr = 0; iwr < NWR; iwr++) { |
| 13841 | if (in.readInt() != 0) { |
| 13842 | String reasonName = in.readString(); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 13843 | getWakeupReasonTimerLocked(reasonName).readSummaryFromParcelLocked(in); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 13844 | } |
| 13845 | } |
| 13846 | |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 13847 | int NMS = in.readInt(); |
| 13848 | for (int ims = 0; ims < NMS; ims++) { |
| 13849 | if (in.readInt() != 0) { |
| 13850 | long kmstName = in.readLong(); |
| 13851 | getKernelMemoryTimerLocked(kmstName).readSummaryFromParcelLocked(in); |
| 13852 | } |
| 13853 | } |
| 13854 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13855 | final int NU = in.readInt(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 13856 | if (NU > 10000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 13857 | throw new ParcelFormatException("File corrupt: too many uids " + NU); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 13858 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13859 | for (int iu = 0; iu < NU; iu++) { |
| 13860 | int uid = in.readInt(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 13861 | Uid u = new Uid(this, uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13862 | mUidStats.put(uid, u); |
| 13863 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 13864 | u.mOnBatteryBackgroundTimeBase.readSummaryFromParcel(in); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 13865 | u.mOnBatteryScreenOffBackgroundTimeBase.readSummaryFromParcel(in); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 13866 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 13867 | u.mWifiRunning = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 13868 | if (in.readInt() != 0) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 13869 | u.mWifiRunningTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 13870 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 13871 | u.mFullWifiLockOut = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 13872 | if (in.readInt() != 0) { |
| 13873 | u.mFullWifiLockTimer.readSummaryFromParcelLocked(in); |
| 13874 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 13875 | u.mWifiScanStarted = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 13876 | if (in.readInt() != 0) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 13877 | u.mWifiScanTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 13878 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 13879 | u.mWifiBatchedScanBinStarted = Uid.NO_BATCHED_SCAN_STARTED; |
| 13880 | for (int i = 0; i < Uid.NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 13881 | if (in.readInt() != 0) { |
| 13882 | u.makeWifiBatchedScanBin(i, null); |
| 13883 | u.mWifiBatchedScanTimer[i].readSummaryFromParcelLocked(in); |
| 13884 | } |
| 13885 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 13886 | u.mWifiMulticastEnabled = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 13887 | if (in.readInt() != 0) { |
| 13888 | u.mWifiMulticastTimer.readSummaryFromParcelLocked(in); |
| 13889 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 13890 | if (in.readInt() != 0) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 13891 | u.createAudioTurnedOnTimerLocked().readSummaryFromParcelLocked(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 13892 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 13893 | if (in.readInt() != 0) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 13894 | u.createVideoTurnedOnTimerLocked().readSummaryFromParcelLocked(in); |
| 13895 | } |
| 13896 | if (in.readInt() != 0) { |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 13897 | u.createFlashlightTurnedOnTimerLocked().readSummaryFromParcelLocked(in); |
| 13898 | } |
| 13899 | if (in.readInt() != 0) { |
| 13900 | u.createCameraTurnedOnTimerLocked().readSummaryFromParcelLocked(in); |
| 13901 | } |
| 13902 | if (in.readInt() != 0) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 13903 | u.createForegroundActivityTimerLocked().readSummaryFromParcelLocked(in); |
| 13904 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 13905 | if (in.readInt() != 0) { |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 13906 | u.createForegroundServiceTimerLocked().readSummaryFromParcelLocked(in); |
| 13907 | } |
| 13908 | if (in.readInt() != 0) { |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 13909 | u.createAggregatedPartialWakelockTimerLocked().readSummaryFromParcelLocked(in); |
| 13910 | } |
| 13911 | if (in.readInt() != 0) { |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 13912 | u.createBluetoothScanTimerLocked().readSummaryFromParcelLocked(in); |
| 13913 | } |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 13914 | if (in.readInt() != 0) { |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 13915 | u.createBluetoothUnoptimizedScanTimerLocked().readSummaryFromParcelLocked(in); |
| 13916 | } |
| 13917 | if (in.readInt() != 0) { |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 13918 | u.createBluetoothScanResultCounterLocked().readSummaryFromParcelLocked(in); |
| 13919 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 13920 | if (in.readInt() != 0) { |
| 13921 | u.createBluetoothScanResultBgCounterLocked().readSummaryFromParcelLocked(in); |
| 13922 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 13923 | u.mProcessState = ActivityManager.PROCESS_STATE_NONEXISTENT; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 13924 | for (int i = 0; i < Uid.NUM_PROCESS_STATE; i++) { |
| 13925 | if (in.readInt() != 0) { |
| 13926 | u.makeProcessState(i, null); |
| 13927 | u.mProcessStateTimer[i].readSummaryFromParcelLocked(in); |
| 13928 | } |
| 13929 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 13930 | if (in.readInt() != 0) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 13931 | u.createVibratorOnTimerLocked().readSummaryFromParcelLocked(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 13932 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 13933 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 13934 | if (in.readInt() != 0) { |
| 13935 | if (u.mUserActivityCounters == null) { |
| 13936 | u.initUserActivityLocked(); |
| 13937 | } |
| 13938 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
| 13939 | u.mUserActivityCounters[i].readSummaryFromParcelLocked(in); |
| 13940 | } |
| 13941 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 13942 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 13943 | if (in.readInt() != 0) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 13944 | if (u.mNetworkByteActivityCounters == null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 13945 | u.initNetworkActivityLocked(); |
| 13946 | } |
| 13947 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 13948 | u.mNetworkByteActivityCounters[i].readSummaryFromParcelLocked(in); |
| 13949 | u.mNetworkPacketActivityCounters[i].readSummaryFromParcelLocked(in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 13950 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 13951 | u.mMobileRadioActiveTime.readSummaryFromParcelLocked(in); |
| 13952 | u.mMobileRadioActiveCount.readSummaryFromParcelLocked(in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 13953 | } |
| 13954 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 13955 | u.mUserCpuTime.readSummaryFromParcelLocked(in); |
| 13956 | u.mSystemCpuTime.readSummaryFromParcelLocked(in); |
| 13957 | |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 13958 | if (in.readInt() != 0) { |
| 13959 | final int numClusters = in.readInt(); |
| 13960 | if (mPowerProfile != null && mPowerProfile.getNumCpuClusters() != numClusters) { |
| 13961 | throw new ParcelFormatException("Incompatible cpu cluster arrangement"); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 13962 | } |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 13963 | |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 13964 | u.mCpuClusterSpeedTimesUs = new LongSamplingCounter[numClusters][]; |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 13965 | for (int cluster = 0; cluster < numClusters; cluster++) { |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 13966 | if (in.readInt() != 0) { |
Adam Lesinski | a57a540 | 2015-09-28 10:21:33 -0700 | [diff] [blame] | 13967 | final int NSB = in.readInt(); |
| 13968 | if (mPowerProfile != null && |
| 13969 | mPowerProfile.getNumSpeedStepsInCpuCluster(cluster) != NSB) { |
| 13970 | throw new ParcelFormatException("File corrupt: too many speed bins " + |
| 13971 | NSB); |
| 13972 | } |
| 13973 | |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 13974 | u.mCpuClusterSpeedTimesUs[cluster] = new LongSamplingCounter[NSB]; |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 13975 | for (int speed = 0; speed < NSB; speed++) { |
| 13976 | if (in.readInt() != 0) { |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 13977 | u.mCpuClusterSpeedTimesUs[cluster][speed] = new LongSamplingCounter( |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 13978 | mOnBatteryTimeBase); |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 13979 | u.mCpuClusterSpeedTimesUs[cluster][speed].readSummaryFromParcelLocked(in); |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 13980 | } |
| 13981 | } |
Adam Lesinski | a57a540 | 2015-09-28 10:21:33 -0700 | [diff] [blame] | 13982 | } else { |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 13983 | u.mCpuClusterSpeedTimesUs[cluster] = null; |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 13984 | } |
| 13985 | } |
| 13986 | } else { |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 13987 | u.mCpuClusterSpeedTimesUs = null; |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 13988 | } |
| 13989 | |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 13990 | u.mCpuFreqTimeMs = LongSamplingCounterArray.readSummaryFromParcelLocked( |
| 13991 | in, mOnBatteryTimeBase); |
| 13992 | u.mScreenOffCpuFreqTimeMs = LongSamplingCounterArray.readSummaryFromParcelLocked( |
| 13993 | in, mOnBatteryScreenOffTimeBase); |
Mike Ma | 3d422c3 | 2017-10-25 11:08:57 -0700 | [diff] [blame] | 13994 | |
| 13995 | u.mCpuActiveTimeMs.readSummaryFromParcelLocked(in); |
| 13996 | u.mCpuClusterTimesMs.readSummaryFromParcelLocked(in); |
| 13997 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 13998 | int length = in.readInt(); |
| 13999 | if (length == Uid.NUM_PROCESS_STATE) { |
| 14000 | u.mProcStateTimeMs = new LongSamplingCounterArray[length]; |
| 14001 | for (int procState = 0; procState < length; ++procState) { |
| 14002 | u.mProcStateTimeMs[procState] |
| 14003 | = LongSamplingCounterArray.readSummaryFromParcelLocked( |
| 14004 | in, mOnBatteryTimeBase); |
| 14005 | } |
| 14006 | } else { |
| 14007 | u.mProcStateTimeMs = null; |
| 14008 | } |
| 14009 | length = in.readInt(); |
| 14010 | if (length == Uid.NUM_PROCESS_STATE) { |
| 14011 | u.mProcStateScreenOffTimeMs = new LongSamplingCounterArray[length]; |
| 14012 | for (int procState = 0; procState < length; ++procState) { |
| 14013 | u.mProcStateScreenOffTimeMs[procState] |
| 14014 | = LongSamplingCounterArray.readSummaryFromParcelLocked( |
| 14015 | in, mOnBatteryScreenOffTimeBase); |
| 14016 | } |
| 14017 | } else { |
| 14018 | u.mProcStateScreenOffTimeMs = null; |
| 14019 | } |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 14020 | |
| 14021 | if (in.readInt() != 0) { |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 14022 | u.mMobileRadioApWakeupCount = new LongSamplingCounter(mOnBatteryTimeBase); |
| 14023 | u.mMobileRadioApWakeupCount.readSummaryFromParcelLocked(in); |
| 14024 | } else { |
| 14025 | u.mMobileRadioApWakeupCount = null; |
| 14026 | } |
| 14027 | |
| 14028 | if (in.readInt() != 0) { |
| 14029 | u.mWifiRadioApWakeupCount = new LongSamplingCounter(mOnBatteryTimeBase); |
| 14030 | u.mWifiRadioApWakeupCount.readSummaryFromParcelLocked(in); |
| 14031 | } else { |
| 14032 | u.mWifiRadioApWakeupCount = null; |
| 14033 | } |
| 14034 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14035 | int NW = in.readInt(); |
Dianne Hackborn | cb99a72 | 2016-10-03 17:00:02 -0700 | [diff] [blame] | 14036 | if (NW > (MAX_WAKELOCKS_PER_UID+1)) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 14037 | throw new ParcelFormatException("File corrupt: too many wake locks " + NW); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 14038 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14039 | for (int iw = 0; iw < NW; iw++) { |
| 14040 | String wlName = in.readString(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 14041 | u.readWakeSummaryFromParcelLocked(wlName, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14042 | } |
| 14043 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 14044 | int NS = in.readInt(); |
Dianne Hackborn | cb99a72 | 2016-10-03 17:00:02 -0700 | [diff] [blame] | 14045 | if (NS > (MAX_WAKELOCKS_PER_UID+1)) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 14046 | throw new ParcelFormatException("File corrupt: too many syncs " + NS); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 14047 | } |
| 14048 | for (int is = 0; is < NS; is++) { |
| 14049 | String name = in.readString(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 14050 | u.readSyncSummaryFromParcelLocked(name, in); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 14051 | } |
| 14052 | |
| 14053 | int NJ = in.readInt(); |
Dianne Hackborn | cb99a72 | 2016-10-03 17:00:02 -0700 | [diff] [blame] | 14054 | if (NJ > (MAX_WAKELOCKS_PER_UID+1)) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 14055 | throw new ParcelFormatException("File corrupt: too many job timers " + NJ); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 14056 | } |
| 14057 | for (int ij = 0; ij < NJ; ij++) { |
| 14058 | String name = in.readString(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 14059 | u.readJobSummaryFromParcelLocked(name, in); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 14060 | } |
| 14061 | |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 14062 | u.readJobCompletionsFromParcelLocked(in); |
| 14063 | |
Amith Yamasani | 977e11f | 2018-02-16 11:29:54 -0800 | [diff] [blame] | 14064 | u.mJobsDeferredEventCount.readSummaryFromParcelLocked(in); |
| 14065 | u.mJobsDeferredCount.readSummaryFromParcelLocked(in); |
| 14066 | u.mJobsFreshnessTimeMs.readSummaryFromParcelLocked(in); |
| 14067 | for (int i = 0; i < JOB_FRESHNESS_BUCKETS.length; i++) { |
| 14068 | if (in.readInt() != 0) { |
| 14069 | u.mJobsFreshnessBuckets[i] = new Counter(u.mBsi.mOnBatteryTimeBase); |
| 14070 | u.mJobsFreshnessBuckets[i].readSummaryFromParcelLocked(in); |
| 14071 | } |
| 14072 | } |
| 14073 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14074 | int NP = in.readInt(); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 14075 | if (NP > 1000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 14076 | throw new ParcelFormatException("File corrupt: too many sensors " + NP); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 14077 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14078 | for (int is = 0; is < NP; is++) { |
| 14079 | int seNumber = in.readInt(); |
| 14080 | if (in.readInt() != 0) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 14081 | u.getSensorTimerLocked(seNumber, true).readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14082 | } |
| 14083 | } |
| 14084 | |
| 14085 | NP = in.readInt(); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 14086 | if (NP > 1000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 14087 | throw new ParcelFormatException("File corrupt: too many processes " + NP); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 14088 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14089 | for (int ip = 0; ip < NP; ip++) { |
| 14090 | String procName = in.readString(); |
| 14091 | Uid.Proc p = u.getProcessStatsLocked(procName); |
| 14092 | p.mUserTime = p.mLoadedUserTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14093 | p.mSystemTime = p.mLoadedSystemTime = in.readLong(); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 14094 | p.mForegroundTime = p.mLoadedForegroundTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14095 | p.mStarts = p.mLoadedStarts = in.readInt(); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 14096 | p.mNumCrashes = p.mLoadedNumCrashes = in.readInt(); |
| 14097 | p.mNumAnrs = p.mLoadedNumAnrs = in.readInt(); |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 14098 | p.readExcessivePowerFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14099 | } |
| 14100 | |
| 14101 | NP = in.readInt(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 14102 | if (NP > 10000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 14103 | throw new ParcelFormatException("File corrupt: too many packages " + NP); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 14104 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14105 | for (int ip = 0; ip < NP; ip++) { |
| 14106 | String pkgName = in.readString(); |
| 14107 | Uid.Pkg p = u.getPackageStatsLocked(pkgName); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 14108 | final int NWA = in.readInt(); |
| 14109 | if (NWA > 1000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 14110 | throw new ParcelFormatException("File corrupt: too many wakeup alarms " + NWA); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 14111 | } |
| 14112 | p.mWakeupAlarms.clear(); |
| 14113 | for (int iwa=0; iwa<NWA; iwa++) { |
| 14114 | String tag = in.readString(); |
Bookatz | 98d4d5c | 2017-08-01 19:07:54 -0700 | [diff] [blame] | 14115 | Counter c = new Counter(mOnBatteryScreenOffTimeBase); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 14116 | c.readSummaryFromParcelLocked(in); |
| 14117 | p.mWakeupAlarms.put(tag, c); |
| 14118 | } |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 14119 | NS = in.readInt(); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 14120 | if (NS > 1000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 14121 | throw new ParcelFormatException("File corrupt: too many services " + NS); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 14122 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14123 | for (int is = 0; is < NS; is++) { |
| 14124 | String servName = in.readString(); |
| 14125 | Uid.Pkg.Serv s = u.getServiceStatsLocked(pkgName, servName); |
| 14126 | s.mStartTime = s.mLoadedStartTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14127 | s.mStarts = s.mLoadedStarts = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14128 | s.mLaunches = s.mLoadedLaunches = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14129 | } |
| 14130 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14131 | } |
| 14132 | } |
| 14133 | |
| 14134 | /** |
| 14135 | * Writes a summary of the statistics to a Parcel, in a format suitable to be written to |
| 14136 | * disk. This format does not allow a lossless round-trip. |
| 14137 | * |
| 14138 | * @param out the Parcel to be written to. |
| 14139 | */ |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 14140 | public void writeSummaryToParcel(Parcel out, boolean inclHistory) { |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 14141 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 14142 | |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 14143 | // Pull the clock time. This may update the time and make a new history entry |
| 14144 | // if we had originally pulled a time before the RTC was set. |
| 14145 | long startClockTime = getStartClockTime(); |
| 14146 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14147 | final long NOW_SYS = mClocks.uptimeMillis() * 1000; |
| 14148 | final long NOWREAL_SYS = mClocks.elapsedRealtime() * 1000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14149 | |
| 14150 | out.writeInt(VERSION); |
| 14151 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 14152 | writeHistory(out, inclHistory, true); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 14153 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14154 | out.writeInt(mStartCount); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 14155 | out.writeLong(computeUptime(NOW_SYS, STATS_SINCE_CHARGED)); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 14156 | out.writeLong(computeRealtime(NOWREAL_SYS, STATS_SINCE_CHARGED)); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 14157 | out.writeLong(startClockTime); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 14158 | out.writeString(mStartPlatformVersion); |
| 14159 | out.writeString(mEndPlatformVersion); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14160 | mOnBatteryTimeBase.writeSummaryToParcel(out, NOW_SYS, NOWREAL_SYS); |
| 14161 | mOnBatteryScreenOffTimeBase.writeSummaryToParcel(out, NOW_SYS, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 14162 | out.writeInt(mDischargeUnplugLevel); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 14163 | out.writeInt(mDischargePlugLevel); |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 14164 | out.writeInt(mDischargeCurrentLevel); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 14165 | out.writeInt(mCurrentBatteryLevel); |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 14166 | out.writeInt(mEstimatedBatteryCapacity); |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 14167 | out.writeInt(mMinLearnedBatteryCapacity); |
| 14168 | out.writeInt(mMaxLearnedBatteryCapacity); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 14169 | out.writeInt(getLowDischargeAmountSinceCharge()); |
| 14170 | out.writeInt(getHighDischargeAmountSinceCharge()); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 14171 | out.writeInt(getDischargeAmountScreenOnSinceCharge()); |
| 14172 | out.writeInt(getDischargeAmountScreenOffSinceCharge()); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 14173 | out.writeInt(getDischargeAmountScreenDozeSinceCharge()); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 14174 | mDischargeStepTracker.writeToParcel(out); |
| 14175 | mChargeStepTracker.writeToParcel(out); |
| 14176 | mDailyDischargeStepTracker.writeToParcel(out); |
| 14177 | mDailyChargeStepTracker.writeToParcel(out); |
Adam Lesinski | 67c134f | 2016-06-10 15:15:08 -0700 | [diff] [blame] | 14178 | mDischargeCounter.writeSummaryFromParcelLocked(out); |
| 14179 | mDischargeScreenOffCounter.writeSummaryFromParcelLocked(out); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 14180 | mDischargeScreenDozeCounter.writeSummaryFromParcelLocked(out); |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 14181 | mDischargeLightDozeCounter.writeSummaryFromParcelLocked(out); |
| 14182 | mDischargeDeepDozeCounter.writeSummaryFromParcelLocked(out); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 14183 | if (mDailyPackageChanges != null) { |
| 14184 | final int NPKG = mDailyPackageChanges.size(); |
| 14185 | out.writeInt(NPKG); |
| 14186 | for (int i=0; i<NPKG; i++) { |
| 14187 | PackageChange pc = mDailyPackageChanges.get(i); |
| 14188 | out.writeString(pc.mPackageName); |
| 14189 | out.writeInt(pc.mUpdate ? 1 : 0); |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 14190 | out.writeLong(pc.mVersionCode); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 14191 | } |
| 14192 | } else { |
| 14193 | out.writeInt(0); |
| 14194 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 14195 | out.writeLong(mDailyStartTime); |
| 14196 | out.writeLong(mNextMinDailyDeadline); |
| 14197 | out.writeLong(mNextMaxDailyDeadline); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14198 | |
| 14199 | mScreenOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 14200 | mScreenDozeTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 14201 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14202 | mScreenBrightnessTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 14203 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 14204 | mInteractiveTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 14205 | mPowerSaveModeEnabledTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 14206 | out.writeLong(mLongestLightIdleTime); |
| 14207 | out.writeLong(mLongestFullIdleTime); |
| 14208 | mDeviceIdleModeLightTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14209 | mDeviceIdleModeFullTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14210 | mDeviceLightIdlingTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 14211 | mDeviceIdlingTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14212 | mPhoneOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 14213 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14214 | mPhoneSignalStrengthsTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 14215 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14216 | mPhoneSignalScanningTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 14217 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14218 | mPhoneDataConnectionsTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 14219 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 14220 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 14221 | mNetworkByteActivityCounters[i].writeSummaryFromParcelLocked(out); |
| 14222 | mNetworkPacketActivityCounters[i].writeSummaryFromParcelLocked(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 14223 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14224 | mMobileRadioActiveTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14225 | mMobileRadioActivePerAppTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 14226 | mMobileRadioActiveAdjustedTime.writeSummaryFromParcelLocked(out); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 14227 | mMobileRadioActiveUnknownTime.writeSummaryFromParcelLocked(out); |
| 14228 | mMobileRadioActiveUnknownCount.writeSummaryFromParcelLocked(out); |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 14229 | mWifiMulticastWakelockTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14230 | mWifiOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14231 | mGlobalWifiRunningTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 14232 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14233 | mWifiStateTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 14234 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 14235 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 14236 | mWifiSupplStateTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14237 | } |
| 14238 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 14239 | mWifiSignalStrengthsTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14240 | } |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 14241 | mWifiActiveTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14242 | mWifiActivity.writeSummaryToParcel(out); |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 14243 | for (int i=0; i< GnssMetrics.NUM_GPS_SIGNAL_QUALITY_LEVELS; i++) { |
| 14244 | mGpsSignalQualityTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14245 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 14246 | mBluetoothActivity.writeSummaryToParcel(out); |
| 14247 | mModemActivity.writeSummaryToParcel(out); |
| 14248 | out.writeInt(mHasWifiReporting ? 1 : 0); |
| 14249 | out.writeInt(mHasBluetoothReporting ? 1 : 0); |
| 14250 | out.writeInt(mHasModemReporting ? 1 : 0); |
| 14251 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 14252 | out.writeInt(mNumConnectivityChange); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 14253 | mFlashlightOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 14254 | mCameraOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 14255 | mBluetoothScanTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14256 | |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 14257 | out.writeInt(mRpmStats.size()); |
| 14258 | for (Map.Entry<String, SamplingTimer> ent : mRpmStats.entrySet()) { |
| 14259 | Timer rpmt = ent.getValue(); |
| 14260 | if (rpmt != null) { |
| 14261 | out.writeInt(1); |
| 14262 | out.writeString(ent.getKey()); |
| 14263 | rpmt.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14264 | } else { |
| 14265 | out.writeInt(0); |
| 14266 | } |
| 14267 | } |
| 14268 | out.writeInt(mScreenOffRpmStats.size()); |
| 14269 | for (Map.Entry<String, SamplingTimer> ent : mScreenOffRpmStats.entrySet()) { |
| 14270 | Timer rpmt = ent.getValue(); |
| 14271 | if (rpmt != null) { |
| 14272 | out.writeInt(1); |
| 14273 | out.writeString(ent.getKey()); |
| 14274 | rpmt.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14275 | } else { |
| 14276 | out.writeInt(0); |
| 14277 | } |
| 14278 | } |
| 14279 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 14280 | out.writeInt(mKernelWakelockStats.size()); |
| 14281 | for (Map.Entry<String, SamplingTimer> ent : mKernelWakelockStats.entrySet()) { |
| 14282 | Timer kwlt = ent.getValue(); |
| 14283 | if (kwlt != null) { |
| 14284 | out.writeInt(1); |
| 14285 | out.writeString(ent.getKey()); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 14286 | kwlt.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14287 | } else { |
| 14288 | out.writeInt(0); |
| 14289 | } |
| 14290 | } |
| 14291 | |
| 14292 | out.writeInt(mWakeupReasonStats.size()); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 14293 | for (Map.Entry<String, SamplingTimer> ent : mWakeupReasonStats.entrySet()) { |
| 14294 | SamplingTimer timer = ent.getValue(); |
| 14295 | if (timer != null) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 14296 | out.writeInt(1); |
| 14297 | out.writeString(ent.getKey()); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 14298 | timer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 14299 | } else { |
| 14300 | out.writeInt(0); |
| 14301 | } |
| 14302 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 14303 | |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 14304 | out.writeInt(mKernelMemoryStats.size()); |
| 14305 | for (int i = 0; i < mKernelMemoryStats.size(); i++) { |
| 14306 | Timer kmt = mKernelMemoryStats.valueAt(i); |
| 14307 | if (kmt != null) { |
| 14308 | out.writeInt(1); |
| 14309 | out.writeLong(mKernelMemoryStats.keyAt(i)); |
| 14310 | kmt.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14311 | } else { |
| 14312 | out.writeInt(0); |
| 14313 | } |
| 14314 | } |
| 14315 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14316 | final int NU = mUidStats.size(); |
| 14317 | out.writeInt(NU); |
| 14318 | for (int iu = 0; iu < NU; iu++) { |
| 14319 | out.writeInt(mUidStats.keyAt(iu)); |
| 14320 | Uid u = mUidStats.valueAt(iu); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 14321 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 14322 | u.mOnBatteryBackgroundTimeBase.writeSummaryToParcel(out, NOW_SYS, NOWREAL_SYS); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 14323 | u.mOnBatteryScreenOffBackgroundTimeBase.writeSummaryToParcel(out, NOW_SYS, NOWREAL_SYS); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 14324 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 14325 | if (u.mWifiRunningTimer != null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 14326 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14327 | u.mWifiRunningTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 14328 | } else { |
| 14329 | out.writeInt(0); |
| 14330 | } |
| 14331 | if (u.mFullWifiLockTimer != null) { |
| 14332 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14333 | u.mFullWifiLockTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 14334 | } else { |
| 14335 | out.writeInt(0); |
| 14336 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 14337 | if (u.mWifiScanTimer != null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 14338 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14339 | u.mWifiScanTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 14340 | } else { |
| 14341 | out.writeInt(0); |
| 14342 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 14343 | for (int i = 0; i < Uid.NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 14344 | if (u.mWifiBatchedScanTimer[i] != null) { |
| 14345 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14346 | u.mWifiBatchedScanTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 14347 | } else { |
| 14348 | out.writeInt(0); |
| 14349 | } |
| 14350 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 14351 | if (u.mWifiMulticastTimer != null) { |
| 14352 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14353 | u.mWifiMulticastTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 14354 | } else { |
| 14355 | out.writeInt(0); |
| 14356 | } |
| 14357 | if (u.mAudioTurnedOnTimer != null) { |
| 14358 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14359 | u.mAudioTurnedOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 14360 | } else { |
| 14361 | out.writeInt(0); |
| 14362 | } |
| 14363 | if (u.mVideoTurnedOnTimer != null) { |
| 14364 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14365 | u.mVideoTurnedOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 14366 | } else { |
| 14367 | out.writeInt(0); |
| 14368 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 14369 | if (u.mFlashlightTurnedOnTimer != null) { |
| 14370 | out.writeInt(1); |
| 14371 | u.mFlashlightTurnedOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14372 | } else { |
| 14373 | out.writeInt(0); |
| 14374 | } |
| 14375 | if (u.mCameraTurnedOnTimer != null) { |
| 14376 | out.writeInt(1); |
| 14377 | u.mCameraTurnedOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14378 | } else { |
| 14379 | out.writeInt(0); |
| 14380 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 14381 | if (u.mForegroundActivityTimer != null) { |
| 14382 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14383 | u.mForegroundActivityTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 14384 | } else { |
| 14385 | out.writeInt(0); |
| 14386 | } |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 14387 | if (u.mForegroundServiceTimer != null) { |
| 14388 | out.writeInt(1); |
| 14389 | u.mForegroundServiceTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14390 | } else { |
| 14391 | out.writeInt(0); |
| 14392 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 14393 | if (u.mAggregatedPartialWakelockTimer != null) { |
| 14394 | out.writeInt(1); |
| 14395 | u.mAggregatedPartialWakelockTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14396 | } else { |
| 14397 | out.writeInt(0); |
| 14398 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 14399 | if (u.mBluetoothScanTimer != null) { |
| 14400 | out.writeInt(1); |
| 14401 | u.mBluetoothScanTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14402 | } else { |
| 14403 | out.writeInt(0); |
| 14404 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 14405 | if (u.mBluetoothUnoptimizedScanTimer != null) { |
| 14406 | out.writeInt(1); |
| 14407 | u.mBluetoothUnoptimizedScanTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14408 | } else { |
| 14409 | out.writeInt(0); |
| 14410 | } |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 14411 | if (u.mBluetoothScanResultCounter != null) { |
| 14412 | out.writeInt(1); |
| 14413 | u.mBluetoothScanResultCounter.writeSummaryFromParcelLocked(out); |
| 14414 | } else { |
| 14415 | out.writeInt(0); |
| 14416 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 14417 | if (u.mBluetoothScanResultBgCounter != null) { |
| 14418 | out.writeInt(1); |
| 14419 | u.mBluetoothScanResultBgCounter.writeSummaryFromParcelLocked(out); |
| 14420 | } else { |
| 14421 | out.writeInt(0); |
| 14422 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 14423 | for (int i = 0; i < Uid.NUM_PROCESS_STATE; i++) { |
| 14424 | if (u.mProcessStateTimer[i] != null) { |
| 14425 | out.writeInt(1); |
| 14426 | u.mProcessStateTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14427 | } else { |
| 14428 | out.writeInt(0); |
| 14429 | } |
| 14430 | } |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 14431 | if (u.mVibratorOnTimer != null) { |
| 14432 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14433 | u.mVibratorOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 14434 | } else { |
| 14435 | out.writeInt(0); |
| 14436 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14437 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 14438 | if (u.mUserActivityCounters == null) { |
| 14439 | out.writeInt(0); |
| 14440 | } else { |
| 14441 | out.writeInt(1); |
| 14442 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
| 14443 | u.mUserActivityCounters[i].writeSummaryFromParcelLocked(out); |
| 14444 | } |
| 14445 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 14446 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 14447 | if (u.mNetworkByteActivityCounters == null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 14448 | out.writeInt(0); |
| 14449 | } else { |
| 14450 | out.writeInt(1); |
| 14451 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 14452 | u.mNetworkByteActivityCounters[i].writeSummaryFromParcelLocked(out); |
| 14453 | u.mNetworkPacketActivityCounters[i].writeSummaryFromParcelLocked(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 14454 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 14455 | u.mMobileRadioActiveTime.writeSummaryFromParcelLocked(out); |
| 14456 | u.mMobileRadioActiveCount.writeSummaryFromParcelLocked(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 14457 | } |
| 14458 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 14459 | u.mUserCpuTime.writeSummaryFromParcelLocked(out); |
| 14460 | u.mSystemCpuTime.writeSummaryFromParcelLocked(out); |
| 14461 | |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 14462 | if (u.mCpuClusterSpeedTimesUs != null) { |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 14463 | out.writeInt(1); |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 14464 | out.writeInt(u.mCpuClusterSpeedTimesUs.length); |
| 14465 | for (LongSamplingCounter[] cpuSpeeds : u.mCpuClusterSpeedTimesUs) { |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 14466 | if (cpuSpeeds != null) { |
| 14467 | out.writeInt(1); |
| 14468 | out.writeInt(cpuSpeeds.length); |
| 14469 | for (LongSamplingCounter c : cpuSpeeds) { |
| 14470 | if (c != null) { |
| 14471 | out.writeInt(1); |
| 14472 | c.writeSummaryFromParcelLocked(out); |
| 14473 | } else { |
| 14474 | out.writeInt(0); |
| 14475 | } |
| 14476 | } |
| 14477 | } else { |
| 14478 | out.writeInt(0); |
| 14479 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 14480 | } |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 14481 | } else { |
| 14482 | out.writeInt(0); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 14483 | } |
| 14484 | |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 14485 | LongSamplingCounterArray.writeSummaryToParcelLocked(out, u.mCpuFreqTimeMs); |
| 14486 | LongSamplingCounterArray.writeSummaryToParcelLocked(out, u.mScreenOffCpuFreqTimeMs); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 14487 | |
Mike Ma | 3d422c3 | 2017-10-25 11:08:57 -0700 | [diff] [blame] | 14488 | u.mCpuActiveTimeMs.writeSummaryFromParcelLocked(out); |
| 14489 | u.mCpuClusterTimesMs.writeSummaryToParcelLocked(out); |
| 14490 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 14491 | if (u.mProcStateTimeMs != null) { |
| 14492 | out.writeInt(u.mProcStateTimeMs.length); |
| 14493 | for (LongSamplingCounterArray counters : u.mProcStateTimeMs) { |
| 14494 | LongSamplingCounterArray.writeSummaryToParcelLocked(out, counters); |
| 14495 | } |
| 14496 | } else { |
| 14497 | out.writeInt(0); |
| 14498 | } |
| 14499 | if (u.mProcStateScreenOffTimeMs != null) { |
| 14500 | out.writeInt(u.mProcStateScreenOffTimeMs.length); |
| 14501 | for (LongSamplingCounterArray counters : u.mProcStateScreenOffTimeMs) { |
| 14502 | LongSamplingCounterArray.writeSummaryToParcelLocked(out, counters); |
| 14503 | } |
| 14504 | } else { |
| 14505 | out.writeInt(0); |
| 14506 | } |
| 14507 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 14508 | if (u.mMobileRadioApWakeupCount != null) { |
| 14509 | out.writeInt(1); |
| 14510 | u.mMobileRadioApWakeupCount.writeSummaryFromParcelLocked(out); |
| 14511 | } else { |
| 14512 | out.writeInt(0); |
| 14513 | } |
| 14514 | |
| 14515 | if (u.mWifiRadioApWakeupCount != null) { |
| 14516 | out.writeInt(1); |
| 14517 | u.mWifiRadioApWakeupCount.writeSummaryFromParcelLocked(out); |
| 14518 | } else { |
| 14519 | out.writeInt(0); |
| 14520 | } |
| 14521 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 14522 | final ArrayMap<String, Uid.Wakelock> wakeStats = u.mWakelockStats.getMap(); |
| 14523 | int NW = wakeStats.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14524 | out.writeInt(NW); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 14525 | for (int iw=0; iw<NW; iw++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 14526 | out.writeString(wakeStats.keyAt(iw)); |
| 14527 | Uid.Wakelock wl = wakeStats.valueAt(iw); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 14528 | if (wl.mTimerFull != null) { |
| 14529 | out.writeInt(1); |
| 14530 | wl.mTimerFull.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14531 | } else { |
| 14532 | out.writeInt(0); |
| 14533 | } |
| 14534 | if (wl.mTimerPartial != null) { |
| 14535 | out.writeInt(1); |
| 14536 | wl.mTimerPartial.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14537 | } else { |
| 14538 | out.writeInt(0); |
| 14539 | } |
| 14540 | if (wl.mTimerWindow != null) { |
| 14541 | out.writeInt(1); |
| 14542 | wl.mTimerWindow.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14543 | } else { |
| 14544 | out.writeInt(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14545 | } |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 14546 | if (wl.mTimerDraw != null) { |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 14547 | out.writeInt(1); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 14548 | wl.mTimerDraw.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 14549 | } else { |
| 14550 | out.writeInt(0); |
| 14551 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14552 | } |
| 14553 | |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 14554 | final ArrayMap<String, DualTimer> syncStats = u.mSyncStats.getMap(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 14555 | int NS = syncStats.size(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 14556 | out.writeInt(NS); |
| 14557 | for (int is=0; is<NS; is++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 14558 | out.writeString(syncStats.keyAt(is)); |
| 14559 | syncStats.valueAt(is).writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 14560 | } |
| 14561 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 14562 | final ArrayMap<String, DualTimer> jobStats = u.mJobStats.getMap(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 14563 | int NJ = jobStats.size(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 14564 | out.writeInt(NJ); |
| 14565 | for (int ij=0; ij<NJ; ij++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 14566 | out.writeString(jobStats.keyAt(ij)); |
| 14567 | jobStats.valueAt(ij).writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 14568 | } |
| 14569 | |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 14570 | u.writeJobCompletionsToParcelLocked(out); |
| 14571 | |
Amith Yamasani | 977e11f | 2018-02-16 11:29:54 -0800 | [diff] [blame] | 14572 | u.mJobsDeferredEventCount.writeSummaryFromParcelLocked(out); |
| 14573 | u.mJobsDeferredCount.writeSummaryFromParcelLocked(out); |
| 14574 | u.mJobsFreshnessTimeMs.writeSummaryFromParcelLocked(out); |
| 14575 | for (int i = 0; i < JOB_FRESHNESS_BUCKETS.length; i++) { |
| 14576 | if (u.mJobsFreshnessBuckets[i] != null) { |
| 14577 | u.mJobsFreshnessBuckets[i].writeSummaryFromParcelLocked(out); |
| 14578 | } else { |
| 14579 | out.writeInt(0); |
| 14580 | } |
| 14581 | } |
| 14582 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14583 | int NSE = u.mSensorStats.size(); |
| 14584 | out.writeInt(NSE); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 14585 | for (int ise=0; ise<NSE; ise++) { |
| 14586 | out.writeInt(u.mSensorStats.keyAt(ise)); |
| 14587 | Uid.Sensor se = u.mSensorStats.valueAt(ise); |
| 14588 | if (se.mTimer != null) { |
| 14589 | out.writeInt(1); |
| 14590 | se.mTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14591 | } else { |
| 14592 | out.writeInt(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14593 | } |
| 14594 | } |
| 14595 | |
| 14596 | int NP = u.mProcessStats.size(); |
| 14597 | out.writeInt(NP); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 14598 | for (int ip=0; ip<NP; ip++) { |
| 14599 | out.writeString(u.mProcessStats.keyAt(ip)); |
| 14600 | Uid.Proc ps = u.mProcessStats.valueAt(ip); |
| 14601 | out.writeLong(ps.mUserTime); |
| 14602 | out.writeLong(ps.mSystemTime); |
| 14603 | out.writeLong(ps.mForegroundTime); |
| 14604 | out.writeInt(ps.mStarts); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 14605 | out.writeInt(ps.mNumCrashes); |
| 14606 | out.writeInt(ps.mNumAnrs); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 14607 | ps.writeExcessivePowerToParcelLocked(out); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14608 | } |
| 14609 | |
| 14610 | NP = u.mPackageStats.size(); |
| 14611 | out.writeInt(NP); |
| 14612 | if (NP > 0) { |
| 14613 | for (Map.Entry<String, BatteryStatsImpl.Uid.Pkg> ent |
| 14614 | : u.mPackageStats.entrySet()) { |
| 14615 | out.writeString(ent.getKey()); |
| 14616 | Uid.Pkg ps = ent.getValue(); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 14617 | final int NWA = ps.mWakeupAlarms.size(); |
| 14618 | out.writeInt(NWA); |
| 14619 | for (int iwa=0; iwa<NWA; iwa++) { |
| 14620 | out.writeString(ps.mWakeupAlarms.keyAt(iwa)); |
| 14621 | ps.mWakeupAlarms.valueAt(iwa).writeSummaryFromParcelLocked(out); |
| 14622 | } |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 14623 | NS = ps.mServiceStats.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14624 | out.writeInt(NS); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 14625 | for (int is=0; is<NS; is++) { |
| 14626 | out.writeString(ps.mServiceStats.keyAt(is)); |
| 14627 | BatteryStatsImpl.Uid.Pkg.Serv ss = ps.mServiceStats.valueAt(is); |
| 14628 | long time = ss.getStartTimeToNowLocked( |
| 14629 | mOnBatteryTimeBase.getUptime(NOW_SYS)); |
| 14630 | out.writeLong(time); |
| 14631 | out.writeInt(ss.mStarts); |
| 14632 | out.writeInt(ss.mLaunches); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14633 | } |
| 14634 | } |
| 14635 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14636 | } |
| 14637 | } |
| 14638 | |
| 14639 | public void readFromParcel(Parcel in) { |
| 14640 | readFromParcelLocked(in); |
| 14641 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 14642 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14643 | void readFromParcelLocked(Parcel in) { |
| 14644 | int magic = in.readInt(); |
| 14645 | if (magic != MAGIC) { |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 14646 | throw new ParcelFormatException("Bad magic number: #" + Integer.toHexString(magic)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14647 | } |
| 14648 | |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 14649 | readHistory(in, false); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 14650 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14651 | mStartCount = in.readInt(); |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 14652 | mStartClockTime = in.readLong(); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 14653 | mStartPlatformVersion = in.readString(); |
| 14654 | mEndPlatformVersion = in.readString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14655 | mUptime = in.readLong(); |
| 14656 | mUptimeStart = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14657 | mRealtime = in.readLong(); |
| 14658 | mRealtimeStart = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14659 | mOnBattery = in.readInt() != 0; |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 14660 | mEstimatedBatteryCapacity = in.readInt(); |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 14661 | mMinLearnedBatteryCapacity = in.readInt(); |
| 14662 | mMaxLearnedBatteryCapacity = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14663 | mOnBatteryInternal = false; // we are no longer really running. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14664 | mOnBatteryTimeBase.readFromParcel(in); |
| 14665 | mOnBatteryScreenOffTimeBase.readFromParcel(in); |
| 14666 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 14667 | mScreenState = Display.STATE_UNKNOWN; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14668 | mScreenOnTimer = new StopwatchTimer(mClocks, null, -1, null, mOnBatteryTimeBase, in); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 14669 | mScreenDozeTimer = new StopwatchTimer(mClocks, null, -1, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14670 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14671 | mScreenBrightnessTimer[i] = new StopwatchTimer(mClocks, null, -100-i, null, |
| 14672 | mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14673 | } |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 14674 | mInteractive = false; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14675 | mInteractiveTimer = new StopwatchTimer(mClocks, null, -10, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14676 | mPhoneOn = false; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14677 | mPowerSaveModeEnabledTimer = new StopwatchTimer(mClocks, null, -2, null, |
| 14678 | mOnBatteryTimeBase, in); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 14679 | mLongestLightIdleTime = in.readLong(); |
| 14680 | mLongestFullIdleTime = in.readLong(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14681 | mDeviceIdleModeLightTimer = new StopwatchTimer(mClocks, null, -14, null, |
| 14682 | mOnBatteryTimeBase, in); |
| 14683 | mDeviceIdleModeFullTimer = new StopwatchTimer(mClocks, null, -11, null, |
| 14684 | mOnBatteryTimeBase, in); |
| 14685 | mDeviceLightIdlingTimer = new StopwatchTimer(mClocks, null, -15, null, |
| 14686 | mOnBatteryTimeBase, in); |
| 14687 | mDeviceIdlingTimer = new StopwatchTimer(mClocks, null, -12, null, mOnBatteryTimeBase, in); |
| 14688 | mPhoneOnTimer = new StopwatchTimer(mClocks, null, -3, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14689 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14690 | mPhoneSignalStrengthsTimer[i] = new StopwatchTimer(mClocks, null, -200-i, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14691 | null, mOnBatteryTimeBase, in); |
| 14692 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14693 | mPhoneSignalScanningTimer = new StopwatchTimer(mClocks, null, -200+1, null, |
| 14694 | mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14695 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14696 | mPhoneDataConnectionsTimer[i] = new StopwatchTimer(mClocks, null, -300-i, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14697 | null, mOnBatteryTimeBase, in); |
| 14698 | } |
| 14699 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
| 14700 | mNetworkByteActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 14701 | mNetworkPacketActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 14702 | } |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 14703 | mMobileRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14704 | mMobileRadioActiveTimer = new StopwatchTimer(mClocks, null, -400, null, |
| 14705 | mOnBatteryTimeBase, in); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 14706 | mMobileRadioActivePerAppTimer = new StopwatchTimer(mClocks, null, -401, null, |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14707 | mOnBatteryTimeBase, in); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 14708 | mMobileRadioActiveAdjustedTime = new LongSamplingCounter(mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14709 | mMobileRadioActiveUnknownTime = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 14710 | mMobileRadioActiveUnknownCount = new LongSamplingCounter(mOnBatteryTimeBase, in); |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 14711 | mWifiMulticastWakelockTimer = new StopwatchTimer(mClocks, null, -4, null, |
| 14712 | mOnBatteryTimeBase, in); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 14713 | mWifiRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14714 | mWifiOn = false; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14715 | mWifiOnTimer = new StopwatchTimer(mClocks, null, -4, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14716 | mGlobalWifiRunning = false; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14717 | mGlobalWifiRunningTimer = new StopwatchTimer(mClocks, null, -5, null, |
| 14718 | mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14719 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14720 | mWifiStateTimer[i] = new StopwatchTimer(mClocks, null, -600-i, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14721 | null, mOnBatteryTimeBase, in); |
| 14722 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 14723 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14724 | mWifiSupplStateTimer[i] = new StopwatchTimer(mClocks, null, -700-i, |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 14725 | null, mOnBatteryTimeBase, in); |
| 14726 | } |
| 14727 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14728 | mWifiSignalStrengthsTimer[i] = new StopwatchTimer(mClocks, null, -800-i, |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 14729 | null, mOnBatteryTimeBase, in); |
| 14730 | } |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 14731 | mWifiActiveTimer = new StopwatchTimer(mClocks, null, -900, null, |
| 14732 | mOnBatteryTimeBase, in); |
| 14733 | mWifiActivity = new ControllerActivityCounterImpl(mOnBatteryTimeBase, |
| 14734 | NUM_WIFI_TX_LEVELS, in); |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 14735 | for (int i=0; i<GnssMetrics.NUM_GPS_SIGNAL_QUALITY_LEVELS; i++) { |
| 14736 | mGpsSignalQualityTimer[i] = new StopwatchTimer(mClocks, null, -1000-i, |
| 14737 | null, mOnBatteryTimeBase, in); |
| 14738 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 14739 | mBluetoothActivity = new ControllerActivityCounterImpl(mOnBatteryTimeBase, |
| 14740 | NUM_BT_TX_LEVELS, in); |
| 14741 | mModemActivity = new ControllerActivityCounterImpl(mOnBatteryTimeBase, |
| 14742 | ModemActivityInfo.TX_POWER_LEVELS, in); |
| 14743 | mHasWifiReporting = in.readInt() != 0; |
| 14744 | mHasBluetoothReporting = in.readInt() != 0; |
| 14745 | mHasModemReporting = in.readInt() != 0; |
| 14746 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 14747 | mNumConnectivityChange = in.readInt(); |
| 14748 | mLoadedNumConnectivityChange = in.readInt(); |
| 14749 | mUnpluggedNumConnectivityChange = in.readInt(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 14750 | mAudioOnNesting = 0; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14751 | mAudioOnTimer = new StopwatchTimer(mClocks, null, -7, null, mOnBatteryTimeBase); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 14752 | mVideoOnNesting = 0; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14753 | mVideoOnTimer = new StopwatchTimer(mClocks, null, -8, null, mOnBatteryTimeBase); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 14754 | mFlashlightOnNesting = 0; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14755 | mFlashlightOnTimer = new StopwatchTimer(mClocks, null, -9, null, mOnBatteryTimeBase, in); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 14756 | mCameraOnNesting = 0; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14757 | mCameraOnTimer = new StopwatchTimer(mClocks, null, -13, null, mOnBatteryTimeBase, in); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 14758 | mBluetoothScanNesting = 0; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14759 | mBluetoothScanTimer = new StopwatchTimer(mClocks, null, -14, null, mOnBatteryTimeBase, in); |
Siddharth Ray | f5e796a | 2018-01-22 18:18:17 -0800 | [diff] [blame] | 14760 | mIsCellularTxPowerHigh = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 14761 | mDischargeUnplugLevel = in.readInt(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 14762 | mDischargePlugLevel = in.readInt(); |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 14763 | mDischargeCurrentLevel = in.readInt(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 14764 | mCurrentBatteryLevel = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 14765 | mLowDischargeAmountSinceCharge = in.readInt(); |
| 14766 | mHighDischargeAmountSinceCharge = in.readInt(); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 14767 | mDischargeAmountScreenOn = in.readInt(); |
| 14768 | mDischargeAmountScreenOnSinceCharge = in.readInt(); |
| 14769 | mDischargeAmountScreenOff = in.readInt(); |
| 14770 | mDischargeAmountScreenOffSinceCharge = in.readInt(); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 14771 | mDischargeAmountScreenDoze = in.readInt(); |
| 14772 | mDischargeAmountScreenDozeSinceCharge = in.readInt(); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 14773 | mDischargeStepTracker.readFromParcel(in); |
| 14774 | mChargeStepTracker.readFromParcel(in); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 14775 | mDischargeCounter = new LongSamplingCounter(mOnBatteryTimeBase, in); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 14776 | mDischargeScreenOffCounter = new LongSamplingCounter(mOnBatteryScreenOffTimeBase, in); |
| 14777 | mDischargeScreenDozeCounter = new LongSamplingCounter(mOnBatteryTimeBase, in); |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 14778 | mDischargeLightDozeCounter = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 14779 | mDischargeDeepDozeCounter = new LongSamplingCounter(mOnBatteryTimeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14780 | mLastWriteTime = in.readLong(); |
| 14781 | |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 14782 | mRpmStats.clear(); |
| 14783 | int NRPMS = in.readInt(); |
| 14784 | for (int irpm = 0; irpm < NRPMS; irpm++) { |
| 14785 | if (in.readInt() != 0) { |
| 14786 | String rpmName = in.readString(); |
| 14787 | SamplingTimer rpmt = new SamplingTimer(mClocks, mOnBatteryTimeBase, in); |
| 14788 | mRpmStats.put(rpmName, rpmt); |
| 14789 | } |
| 14790 | } |
| 14791 | mScreenOffRpmStats.clear(); |
| 14792 | int NSORPMS = in.readInt(); |
| 14793 | for (int irpm = 0; irpm < NSORPMS; irpm++) { |
| 14794 | if (in.readInt() != 0) { |
| 14795 | String rpmName = in.readString(); |
| 14796 | SamplingTimer rpmt = new SamplingTimer(mClocks, mOnBatteryScreenOffTimeBase, in); |
| 14797 | mScreenOffRpmStats.put(rpmName, rpmt); |
| 14798 | } |
| 14799 | } |
| 14800 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 14801 | mKernelWakelockStats.clear(); |
| 14802 | int NKW = in.readInt(); |
| 14803 | for (int ikw = 0; ikw < NKW; ikw++) { |
| 14804 | if (in.readInt() != 0) { |
| 14805 | String wakelockName = in.readString(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14806 | SamplingTimer kwlt = new SamplingTimer(mClocks, mOnBatteryScreenOffTimeBase, in); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 14807 | mKernelWakelockStats.put(wakelockName, kwlt); |
| 14808 | } |
| 14809 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 14810 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 14811 | mWakeupReasonStats.clear(); |
| 14812 | int NWR = in.readInt(); |
| 14813 | for (int iwr = 0; iwr < NWR; iwr++) { |
| 14814 | if (in.readInt() != 0) { |
| 14815 | String reasonName = in.readString(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14816 | SamplingTimer timer = new SamplingTimer(mClocks, mOnBatteryTimeBase, in); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 14817 | mWakeupReasonStats.put(reasonName, timer); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 14818 | } |
| 14819 | } |
| 14820 | |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 14821 | mKernelMemoryStats.clear(); |
| 14822 | int nmt = in.readInt(); |
| 14823 | for (int imt = 0; imt < nmt; imt++) { |
| 14824 | if (in.readInt() != 0) { |
| 14825 | Long bucket = in.readLong(); |
| 14826 | SamplingTimer kmt = new SamplingTimer(mClocks, mOnBatteryTimeBase, in); |
| 14827 | mKernelMemoryStats.put(bucket, kmt); |
| 14828 | } |
| 14829 | } |
| 14830 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14831 | mPartialTimers.clear(); |
| 14832 | mFullTimers.clear(); |
| 14833 | mWindowTimers.clear(); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 14834 | mWifiRunningTimers.clear(); |
| 14835 | mFullWifiLockTimers.clear(); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 14836 | mWifiScanTimers.clear(); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 14837 | mWifiBatchedScanTimers.clear(); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 14838 | mWifiMulticastTimers.clear(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 14839 | mAudioTurnedOnTimers.clear(); |
| 14840 | mVideoTurnedOnTimers.clear(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 14841 | mFlashlightTurnedOnTimers.clear(); |
| 14842 | mCameraTurnedOnTimers.clear(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14843 | |
| 14844 | int numUids = in.readInt(); |
| 14845 | mUidStats.clear(); |
| 14846 | for (int i = 0; i < numUids; i++) { |
| 14847 | int uid = in.readInt(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14848 | Uid u = new Uid(this, uid); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14849 | u.readFromParcelLocked(mOnBatteryTimeBase, mOnBatteryScreenOffTimeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14850 | mUidStats.append(uid, u); |
| 14851 | } |
| 14852 | } |
| 14853 | |
| 14854 | public void writeToParcel(Parcel out, int flags) { |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 14855 | writeToParcelLocked(out, true, flags); |
| 14856 | } |
| 14857 | |
| 14858 | public void writeToParcelWithoutUids(Parcel out, int flags) { |
| 14859 | writeToParcelLocked(out, false, flags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14860 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 14861 | |
| 14862 | @SuppressWarnings("unused") |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 14863 | void writeToParcelLocked(Parcel out, boolean inclUids, int flags) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 14864 | // Need to update with current kernel wake lock counts. |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 14865 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 14866 | |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 14867 | // Pull the clock time. This may update the time and make a new history entry |
| 14868 | // if we had originally pulled a time before the RTC was set. |
| 14869 | long startClockTime = getStartClockTime(); |
| 14870 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14871 | final long uSecUptime = mClocks.uptimeMillis() * 1000; |
| 14872 | final long uSecRealtime = mClocks.elapsedRealtime() * 1000; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14873 | final long batteryRealtime = mOnBatteryTimeBase.getRealtime(uSecRealtime); |
| 14874 | final long batteryScreenOffRealtime = mOnBatteryScreenOffTimeBase.getRealtime(uSecRealtime); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 14875 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14876 | out.writeInt(MAGIC); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 14877 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 14878 | writeHistory(out, true, false); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 14879 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14880 | out.writeInt(mStartCount); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 14881 | out.writeLong(startClockTime); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 14882 | out.writeString(mStartPlatformVersion); |
| 14883 | out.writeString(mEndPlatformVersion); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14884 | out.writeLong(mUptime); |
| 14885 | out.writeLong(mUptimeStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14886 | out.writeLong(mRealtime); |
| 14887 | out.writeLong(mRealtimeStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14888 | out.writeInt(mOnBattery ? 1 : 0); |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 14889 | out.writeInt(mEstimatedBatteryCapacity); |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 14890 | out.writeInt(mMinLearnedBatteryCapacity); |
| 14891 | out.writeInt(mMaxLearnedBatteryCapacity); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14892 | mOnBatteryTimeBase.writeToParcel(out, uSecUptime, uSecRealtime); |
| 14893 | mOnBatteryScreenOffTimeBase.writeToParcel(out, uSecUptime, uSecRealtime); |
| 14894 | |
| 14895 | mScreenOnTimer.writeToParcel(out, uSecRealtime); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 14896 | mScreenDozeTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14897 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
| 14898 | mScreenBrightnessTimer[i].writeToParcel(out, uSecRealtime); |
| 14899 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 14900 | mInteractiveTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 14901 | mPowerSaveModeEnabledTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 14902 | out.writeLong(mLongestLightIdleTime); |
| 14903 | out.writeLong(mLongestFullIdleTime); |
| 14904 | mDeviceIdleModeLightTimer.writeToParcel(out, uSecRealtime); |
| 14905 | mDeviceIdleModeFullTimer.writeToParcel(out, uSecRealtime); |
| 14906 | mDeviceLightIdlingTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 14907 | mDeviceIdlingTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14908 | mPhoneOnTimer.writeToParcel(out, uSecRealtime); |
| 14909 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
| 14910 | mPhoneSignalStrengthsTimer[i].writeToParcel(out, uSecRealtime); |
| 14911 | } |
| 14912 | mPhoneSignalScanningTimer.writeToParcel(out, uSecRealtime); |
| 14913 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
| 14914 | mPhoneDataConnectionsTimer[i].writeToParcel(out, uSecRealtime); |
| 14915 | } |
| 14916 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
| 14917 | mNetworkByteActivityCounters[i].writeToParcel(out); |
| 14918 | mNetworkPacketActivityCounters[i].writeToParcel(out); |
| 14919 | } |
| 14920 | mMobileRadioActiveTimer.writeToParcel(out, uSecRealtime); |
| 14921 | mMobileRadioActivePerAppTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 14922 | mMobileRadioActiveAdjustedTime.writeToParcel(out); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14923 | mMobileRadioActiveUnknownTime.writeToParcel(out); |
| 14924 | mMobileRadioActiveUnknownCount.writeToParcel(out); |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 14925 | mWifiMulticastWakelockTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14926 | mWifiOnTimer.writeToParcel(out, uSecRealtime); |
| 14927 | mGlobalWifiRunningTimer.writeToParcel(out, uSecRealtime); |
| 14928 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 14929 | mWifiStateTimer[i].writeToParcel(out, uSecRealtime); |
| 14930 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 14931 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 14932 | mWifiSupplStateTimer[i].writeToParcel(out, uSecRealtime); |
| 14933 | } |
| 14934 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 14935 | mWifiSignalStrengthsTimer[i].writeToParcel(out, uSecRealtime); |
| 14936 | } |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 14937 | mWifiActiveTimer.writeToParcel(out, uSecRealtime); |
| 14938 | mWifiActivity.writeToParcel(out, 0); |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 14939 | for (int i=0; i< GnssMetrics.NUM_GPS_SIGNAL_QUALITY_LEVELS; i++) { |
| 14940 | mGpsSignalQualityTimer[i].writeToParcel(out, uSecRealtime); |
| 14941 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 14942 | mBluetoothActivity.writeToParcel(out, 0); |
| 14943 | mModemActivity.writeToParcel(out, 0); |
| 14944 | out.writeInt(mHasWifiReporting ? 1 : 0); |
| 14945 | out.writeInt(mHasBluetoothReporting ? 1 : 0); |
| 14946 | out.writeInt(mHasModemReporting ? 1 : 0); |
| 14947 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 14948 | out.writeInt(mNumConnectivityChange); |
| 14949 | out.writeInt(mLoadedNumConnectivityChange); |
| 14950 | out.writeInt(mUnpluggedNumConnectivityChange); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 14951 | mFlashlightOnTimer.writeToParcel(out, uSecRealtime); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 14952 | mCameraOnTimer.writeToParcel(out, uSecRealtime); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 14953 | mBluetoothScanTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 14954 | out.writeInt(mDischargeUnplugLevel); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 14955 | out.writeInt(mDischargePlugLevel); |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 14956 | out.writeInt(mDischargeCurrentLevel); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 14957 | out.writeInt(mCurrentBatteryLevel); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 14958 | out.writeInt(mLowDischargeAmountSinceCharge); |
| 14959 | out.writeInt(mHighDischargeAmountSinceCharge); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 14960 | out.writeInt(mDischargeAmountScreenOn); |
| 14961 | out.writeInt(mDischargeAmountScreenOnSinceCharge); |
| 14962 | out.writeInt(mDischargeAmountScreenOff); |
| 14963 | out.writeInt(mDischargeAmountScreenOffSinceCharge); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 14964 | out.writeInt(mDischargeAmountScreenDoze); |
| 14965 | out.writeInt(mDischargeAmountScreenDozeSinceCharge); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 14966 | mDischargeStepTracker.writeToParcel(out); |
| 14967 | mChargeStepTracker.writeToParcel(out); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 14968 | mDischargeCounter.writeToParcel(out); |
| 14969 | mDischargeScreenOffCounter.writeToParcel(out); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 14970 | mDischargeScreenDozeCounter.writeToParcel(out); |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 14971 | mDischargeLightDozeCounter.writeToParcel(out); |
| 14972 | mDischargeDeepDozeCounter.writeToParcel(out); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14973 | out.writeLong(mLastWriteTime); |
| 14974 | |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 14975 | out.writeInt(mRpmStats.size()); |
| 14976 | for (Map.Entry<String, SamplingTimer> ent : mRpmStats.entrySet()) { |
| 14977 | SamplingTimer rpmt = ent.getValue(); |
| 14978 | if (rpmt != null) { |
| 14979 | out.writeInt(1); |
| 14980 | out.writeString(ent.getKey()); |
| 14981 | rpmt.writeToParcel(out, uSecRealtime); |
| 14982 | } else { |
| 14983 | out.writeInt(0); |
| 14984 | } |
| 14985 | } |
| 14986 | out.writeInt(mScreenOffRpmStats.size()); |
| 14987 | for (Map.Entry<String, SamplingTimer> ent : mScreenOffRpmStats.entrySet()) { |
| 14988 | SamplingTimer rpmt = ent.getValue(); |
| 14989 | if (rpmt != null) { |
| 14990 | out.writeInt(1); |
| 14991 | out.writeString(ent.getKey()); |
| 14992 | rpmt.writeToParcel(out, uSecRealtime); |
| 14993 | } else { |
| 14994 | out.writeInt(0); |
| 14995 | } |
| 14996 | } |
| 14997 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 14998 | if (inclUids) { |
| 14999 | out.writeInt(mKernelWakelockStats.size()); |
| 15000 | for (Map.Entry<String, SamplingTimer> ent : mKernelWakelockStats.entrySet()) { |
| 15001 | SamplingTimer kwlt = ent.getValue(); |
| 15002 | if (kwlt != null) { |
| 15003 | out.writeInt(1); |
| 15004 | out.writeString(ent.getKey()); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 15005 | kwlt.writeToParcel(out, uSecRealtime); |
| 15006 | } else { |
| 15007 | out.writeInt(0); |
| 15008 | } |
| 15009 | } |
| 15010 | out.writeInt(mWakeupReasonStats.size()); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 15011 | for (Map.Entry<String, SamplingTimer> ent : mWakeupReasonStats.entrySet()) { |
| 15012 | SamplingTimer timer = ent.getValue(); |
| 15013 | if (timer != null) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 15014 | out.writeInt(1); |
| 15015 | out.writeString(ent.getKey()); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 15016 | timer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 15017 | } else { |
| 15018 | out.writeInt(0); |
| 15019 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 15020 | } |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 15021 | } else { |
Bookatz | ba78b2b | 2017-10-10 11:06:33 -0700 | [diff] [blame] | 15022 | out.writeInt(0); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 15023 | out.writeInt(0); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 15024 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 15025 | |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 15026 | out.writeInt(mKernelMemoryStats.size()); |
| 15027 | for (int i = 0; i < mKernelMemoryStats.size(); i++) { |
| 15028 | SamplingTimer kmt = mKernelMemoryStats.valueAt(i); |
| 15029 | if (kmt != null) { |
| 15030 | out.writeInt(1); |
| 15031 | out.writeLong(mKernelMemoryStats.keyAt(i)); |
| 15032 | kmt.writeToParcel(out, uSecRealtime); |
| 15033 | } else { |
| 15034 | out.writeInt(0); |
| 15035 | } |
| 15036 | } |
| 15037 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 15038 | if (inclUids) { |
| 15039 | int size = mUidStats.size(); |
| 15040 | out.writeInt(size); |
| 15041 | for (int i = 0; i < size; i++) { |
| 15042 | out.writeInt(mUidStats.keyAt(i)); |
| 15043 | Uid uid = mUidStats.valueAt(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15044 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 15045 | uid.writeToParcelLocked(out, uSecUptime, uSecRealtime); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 15046 | } |
| 15047 | } else { |
| 15048 | out.writeInt(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15049 | } |
| 15050 | } |
| 15051 | |
| 15052 | public static final Parcelable.Creator<BatteryStatsImpl> CREATOR = |
| 15053 | new Parcelable.Creator<BatteryStatsImpl>() { |
| 15054 | public BatteryStatsImpl createFromParcel(Parcel in) { |
| 15055 | return new BatteryStatsImpl(in); |
| 15056 | } |
| 15057 | |
| 15058 | public BatteryStatsImpl[] newArray(int size) { |
| 15059 | return new BatteryStatsImpl[size]; |
| 15060 | } |
| 15061 | }; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 15062 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 15063 | public void prepareForDumpLocked() { |
| 15064 | // Need to retrieve current kernel wake lock stats before printing. |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 15065 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 15066 | |
| 15067 | // Pull the clock time. This may update the time and make a new history entry |
| 15068 | // if we had originally pulled a time before the RTC was set. |
| 15069 | getStartClockTime(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 15070 | } |
| 15071 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 15072 | 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] | 15073 | if (DEBUG) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 15074 | pw.println("mOnBatteryTimeBase:"); |
| 15075 | mOnBatteryTimeBase.dump(pw, " "); |
| 15076 | pw.println("mOnBatteryScreenOffTimeBase:"); |
| 15077 | mOnBatteryScreenOffTimeBase.dump(pw, " "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 15078 | Printer pr = new PrintWriterPrinter(pw); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 15079 | pr.println("*** Screen on timer:"); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 15080 | mScreenOnTimer.logState(pr, " "); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 15081 | pr.println("*** Screen doze timer:"); |
| 15082 | mScreenDozeTimer.logState(pr, " "); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 15083 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 15084 | pr.println("*** Screen brightness #" + i + ":"); |
| 15085 | mScreenBrightnessTimer[i].logState(pr, " "); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 15086 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 15087 | pr.println("*** Interactive timer:"); |
| 15088 | mInteractiveTimer.logState(pr, " "); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 15089 | pr.println("*** Power save mode timer:"); |
| 15090 | mPowerSaveModeEnabledTimer.logState(pr, " "); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 15091 | pr.println("*** Device idle mode light timer:"); |
| 15092 | mDeviceIdleModeLightTimer.logState(pr, " "); |
| 15093 | pr.println("*** Device idle mode full timer:"); |
| 15094 | mDeviceIdleModeFullTimer.logState(pr, " "); |
| 15095 | pr.println("*** Device light idling timer:"); |
| 15096 | mDeviceLightIdlingTimer.logState(pr, " "); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 15097 | pr.println("*** Device idling timer:"); |
| 15098 | mDeviceIdlingTimer.logState(pr, " "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 15099 | pr.println("*** Phone timer:"); |
| 15100 | mPhoneOnTimer.logState(pr, " "); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 15101 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 15102 | pr.println("*** Phone signal strength #" + i + ":"); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 15103 | mPhoneSignalStrengthsTimer[i].logState(pr, " "); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 15104 | } |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 15105 | pr.println("*** Signal scanning :"); |
| 15106 | mPhoneSignalScanningTimer.logState(pr, " "); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 15107 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 15108 | pr.println("*** Data connection type #" + i + ":"); |
| 15109 | mPhoneDataConnectionsTimer[i].logState(pr, " "); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 15110 | } |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 15111 | pr.println("*** mMobileRadioPowerState=" + mMobileRadioPowerState); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 15112 | pr.println("*** Mobile network active timer:"); |
| 15113 | mMobileRadioActiveTimer.logState(pr, " "); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 15114 | pr.println("*** Mobile network active adjusted timer:"); |
| 15115 | mMobileRadioActiveAdjustedTime.logState(pr, " "); |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 15116 | pr.println("*** Wifi Multicast WakeLock Timer:"); |
| 15117 | mWifiMulticastWakelockTimer.logState(pr, " "); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 15118 | pr.println("*** mWifiRadioPowerState=" + mWifiRadioPowerState); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 15119 | pr.println("*** Wifi timer:"); |
| 15120 | mWifiOnTimer.logState(pr, " "); |
| 15121 | pr.println("*** WifiRunning timer:"); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 15122 | mGlobalWifiRunningTimer.logState(pr, " "); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 15123 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 15124 | pr.println("*** Wifi state #" + i + ":"); |
| 15125 | mWifiStateTimer[i].logState(pr, " "); |
| 15126 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 15127 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 15128 | pr.println("*** Wifi suppl state #" + i + ":"); |
| 15129 | mWifiSupplStateTimer[i].logState(pr, " "); |
| 15130 | } |
| 15131 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 15132 | pr.println("*** Wifi signal strength #" + i + ":"); |
| 15133 | mWifiSignalStrengthsTimer[i].logState(pr, " "); |
| 15134 | } |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 15135 | for (int i=0; i<GnssMetrics.NUM_GPS_SIGNAL_QUALITY_LEVELS; i++) { |
| 15136 | pr.println("*** GPS signal quality #" + i + ":"); |
| 15137 | mGpsSignalQualityTimer[i].logState(pr, " "); |
| 15138 | } |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 15139 | pr.println("*** Flashlight timer:"); |
| 15140 | mFlashlightOnTimer.logState(pr, " "); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 15141 | pr.println("*** Camera timer:"); |
| 15142 | mCameraOnTimer.logState(pr, " "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15143 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 15144 | super.dumpLocked(context, pw, flags, reqUid, histStart); |
Sudheer Shanka | c20379e | 2018-02-15 00:06:21 -0800 | [diff] [blame] | 15145 | pw.print("Total cpu time reads: "); |
| 15146 | pw.println(mNumCpuTimeReads); |
| 15147 | pw.print("Batched cpu time reads: "); |
| 15148 | pw.println(mNumBatchedCpuTimeReads); |
| 15149 | pw.print("Batching Duration (min): "); |
| 15150 | pw.println((mClocks.uptimeMillis() - mCpuTimeReadsTrackingStartTime) / (60 * 1000)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15151 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15152 | } |