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; |
Mike Ma | 2ab0144 | 2018-02-13 14:22:47 -0800 | [diff] [blame] | 113 | import java.util.concurrent.ExecutorService; |
| 114 | import java.util.concurrent.Executors; |
Adam Lesinski | b3a1bad | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 115 | import java.util.concurrent.Future; |
Mike Ma | 2ab0144 | 2018-02-13 14:22:47 -0800 | [diff] [blame] | 116 | import java.util.concurrent.ThreadFactory; |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 117 | import java.util.concurrent.atomic.AtomicInteger; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 118 | import java.util.concurrent.locks.ReentrantLock; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 119 | |
| 120 | /** |
| 121 | * All information we are collecting about things that can happen that impact |
| 122 | * battery life. All times are represented in microseconds except where indicated |
| 123 | * otherwise. |
| 124 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 125 | public class BatteryStatsImpl extends BatteryStats { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 126 | private static final String TAG = "BatteryStatsImpl"; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 127 | private static final boolean DEBUG = false; |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 128 | public static final boolean DEBUG_ENERGY = false; |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 129 | private static final boolean DEBUG_ENERGY_CPU = DEBUG_ENERGY; |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 130 | private static final boolean DEBUG_MEMORY = false; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 131 | private static final boolean DEBUG_HISTORY = false; |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 132 | private static final boolean USE_OLD_HISTORY = false; // for debugging. |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 133 | |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 134 | // TODO: remove "tcp" from network methods, since we measure total stats. |
| 135 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 136 | // 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] | 137 | private static final int MAGIC = 0xBA757475; // 'BATSTATS' |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 138 | |
| 139 | // Current on-disk Parcel version |
Amith Yamasani | 977e11f | 2018-02-16 11:29:54 -0800 | [diff] [blame] | 140 | private static final int VERSION = 175 + (USE_OLD_HISTORY ? 1000 : 0); |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 141 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 142 | // 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_HISTORY_ITEMS; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 144 | |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 145 | // 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] | 146 | private static final int MAX_MAX_HISTORY_ITEMS; |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 147 | |
Dianne Hackborn | 9e0f5d9 | 2010-02-22 15:05:42 -0800 | [diff] [blame] | 148 | // The maximum number of names wakelocks we will keep track of |
| 149 | // per uid; once the limit is reached, we batch the remaining wakelocks |
| 150 | // in to one common name. |
Narayan Kamath | b59b7c3 | 2017-06-12 14:11:03 +0100 | [diff] [blame] | 151 | private static final int MAX_WAKELOCKS_PER_UID; |
| 152 | |
| 153 | static final int MAX_HISTORY_BUFFER; // 256KB |
| 154 | static final int MAX_MAX_HISTORY_BUFFER; // 320KB |
| 155 | |
| 156 | static { |
| 157 | if (ActivityManager.isLowRamDeviceStatic()) { |
| 158 | MAX_HISTORY_ITEMS = 800; |
| 159 | MAX_MAX_HISTORY_ITEMS = 1200; |
| 160 | MAX_WAKELOCKS_PER_UID = 40; |
| 161 | MAX_HISTORY_BUFFER = 96*1024; // 96KB |
| 162 | MAX_MAX_HISTORY_BUFFER = 128*1024; // 128KB |
| 163 | } else { |
Makoto Onuki | 44d6460 | 2018-01-18 08:44:28 -0800 | [diff] [blame] | 164 | MAX_HISTORY_ITEMS = 4000; |
| 165 | MAX_MAX_HISTORY_ITEMS = 6000; |
| 166 | MAX_WAKELOCKS_PER_UID = 200; |
| 167 | MAX_HISTORY_BUFFER = 512*1024; // 512KB |
| 168 | MAX_MAX_HISTORY_BUFFER = 640*1024; // 640KB |
Narayan Kamath | b59b7c3 | 2017-06-12 14:11:03 +0100 | [diff] [blame] | 169 | } |
| 170 | } |
Dianne Hackborn | c24ab86 | 2011-10-18 15:55:03 -0700 | [diff] [blame] | 171 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 172 | // Number of transmit power states the Wifi controller can be in. |
| 173 | private static final int NUM_WIFI_TX_LEVELS = 1; |
| 174 | |
| 175 | // Number of transmit power states the Bluetooth controller can be in. |
| 176 | private static final int NUM_BT_TX_LEVELS = 1; |
| 177 | |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 178 | /** |
| 179 | * Holding a wakelock costs more than just using the cpu. |
| 180 | * Currently, we assign only half the cpu time to an app that is running but |
| 181 | * not holding a wakelock. The apps holding wakelocks get the rest of the blame. |
| 182 | * If no app is holding a wakelock, then the distribution is normal. |
| 183 | */ |
| 184 | @VisibleForTesting |
| 185 | public static final int WAKE_LOCK_WEIGHT = 50; |
| 186 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 187 | protected Clocks mClocks; |
| 188 | |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 189 | private final JournaledFile mFile; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 190 | public final AtomicFile mCheckinFile; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 191 | public final AtomicFile mDailyFile; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 192 | |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 193 | static final int MSG_REPORT_CPU_UPDATE_NEEDED = 1; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 194 | static final int MSG_REPORT_POWER_CHANGE = 2; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 195 | static final int MSG_REPORT_CHARGING = 3; |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 196 | static final long DELAY_UPDATE_WAKELOCKS = 5*1000; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 197 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 198 | private final KernelWakelockReader mKernelWakelockReader = new KernelWakelockReader(); |
| 199 | private final KernelWakelockStats mTmpWakelockStats = new KernelWakelockStats(); |
| 200 | |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 201 | @VisibleForTesting |
| 202 | protected KernelUidCpuTimeReader mKernelUidCpuTimeReader = new KernelUidCpuTimeReader(); |
| 203 | @VisibleForTesting |
| 204 | protected KernelCpuSpeedReader[] mKernelCpuSpeedReaders; |
| 205 | @VisibleForTesting |
| 206 | protected KernelUidCpuFreqTimeReader mKernelUidCpuFreqTimeReader = |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 207 | new KernelUidCpuFreqTimeReader(); |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 208 | @VisibleForTesting |
Mike Ma | 3d422c3 | 2017-10-25 11:08:57 -0700 | [diff] [blame] | 209 | protected KernelUidCpuActiveTimeReader mKernelUidCpuActiveTimeReader = |
| 210 | new KernelUidCpuActiveTimeReader(); |
| 211 | @VisibleForTesting |
| 212 | protected KernelUidCpuClusterTimeReader mKernelUidCpuClusterTimeReader = |
| 213 | new KernelUidCpuClusterTimeReader(); |
| 214 | @VisibleForTesting |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 215 | protected KernelSingleUidTimeReader mKernelSingleUidTimeReader; |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 216 | |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 217 | private final KernelMemoryBandwidthStats mKernelMemoryBandwidthStats |
| 218 | = new KernelMemoryBandwidthStats(); |
| 219 | private final LongSparseArray<SamplingTimer> mKernelMemoryStats = new LongSparseArray<>(); |
| 220 | public LongSparseArray<SamplingTimer> getKernelMemoryStats() { |
| 221 | return mKernelMemoryStats; |
| 222 | } |
| 223 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 224 | @GuardedBy("this") |
| 225 | public boolean mPerProcStateCpuTimesAvailable = true; |
| 226 | |
| 227 | /** |
| 228 | * Uids for which per-procstate cpu times need to be updated. |
| 229 | * |
| 230 | * Contains uid -> procState mappings. |
| 231 | */ |
| 232 | @GuardedBy("this") |
| 233 | @VisibleForTesting |
| 234 | protected final SparseIntArray mPendingUids = new SparseIntArray(); |
| 235 | |
Sudheer Shanka | c20379e | 2018-02-15 00:06:21 -0800 | [diff] [blame] | 236 | @GuardedBy("this") |
| 237 | private long mNumCpuTimeReads; |
| 238 | @GuardedBy("this") |
| 239 | private long mNumBatchedCpuTimeReads; |
| 240 | @GuardedBy("this") |
| 241 | private long mCpuTimeReadsTrackingStartTime = SystemClock.uptimeMillis(); |
| 242 | |
Bookatz | 0b8a050 | 2017-09-13 11:51:52 -0700 | [diff] [blame] | 243 | /** Container for Resource Power Manager stats. Updated by updateRpmStatsLocked. */ |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 244 | private final RpmStats mTmpRpmStats = new RpmStats(); |
Bookatz | 0b8a050 | 2017-09-13 11:51:52 -0700 | [diff] [blame] | 245 | /** The soonest the RPM stats can be updated after it was last updated. */ |
| 246 | private static final long RPM_STATS_UPDATE_FREQ_MS = 1000; |
| 247 | /** Last time that RPM stats were updated by updateRpmStatsLocked. */ |
| 248 | private long mLastRpmStatsUpdateTimeMs = -RPM_STATS_UPDATE_FREQ_MS; |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 249 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 250 | public interface BatteryCallback { |
| 251 | public void batteryNeedsCpuUpdate(); |
| 252 | public void batteryPowerChanged(boolean onBattery); |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 253 | public void batterySendBroadcast(Intent intent); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 254 | } |
| 255 | |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 256 | public interface PlatformIdleStateCallback { |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 257 | public void fillLowPowerStats(RpmStats rpmStats); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 258 | public String getPlatformLowPowerStats(); |
Ahmed ElArabawy | d8b4411 | 2017-05-23 21:25:02 +0000 | [diff] [blame] | 259 | public String getSubsystemLowPowerStats(); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 260 | } |
| 261 | |
Suprabh Shukla | e6e723d | 2017-06-14 16:14:43 -0700 | [diff] [blame] | 262 | public static abstract class UserInfoProvider { |
| 263 | private int[] userIds; |
| 264 | protected abstract @Nullable int[] getUserIds(); |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 265 | @VisibleForTesting |
| 266 | public final void refreshUserIds() { |
Suprabh Shukla | e6e723d | 2017-06-14 16:14:43 -0700 | [diff] [blame] | 267 | userIds = getUserIds(); |
| 268 | } |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 269 | @VisibleForTesting |
| 270 | public boolean exists(int userId) { |
Suprabh Shukla | e6e723d | 2017-06-14 16:14:43 -0700 | [diff] [blame] | 271 | return userIds != null ? ArrayUtils.contains(userIds, userId) : true; |
| 272 | } |
| 273 | } |
| 274 | |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 275 | private final PlatformIdleStateCallback mPlatformIdleStateCallback; |
| 276 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 277 | final class MyHandler extends Handler { |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 278 | public MyHandler(Looper looper) { |
| 279 | super(looper, null, true); |
| 280 | } |
| 281 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 282 | @Override |
| 283 | public void handleMessage(Message msg) { |
| 284 | BatteryCallback cb = mCallback; |
| 285 | switch (msg.what) { |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 286 | case MSG_REPORT_CPU_UPDATE_NEEDED: |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 287 | if (cb != null) { |
| 288 | cb.batteryNeedsCpuUpdate(); |
| 289 | } |
| 290 | break; |
| 291 | case MSG_REPORT_POWER_CHANGE: |
| 292 | if (cb != null) { |
| 293 | cb.batteryPowerChanged(msg.arg1 != 0); |
| 294 | } |
| 295 | break; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 296 | case MSG_REPORT_CHARGING: |
| 297 | if (cb != null) { |
| 298 | final String action; |
| 299 | synchronized (BatteryStatsImpl.this) { |
| 300 | action = mCharging ? BatteryManager.ACTION_CHARGING |
| 301 | : BatteryManager.ACTION_DISCHARGING; |
| 302 | } |
| 303 | Intent intent = new Intent(action); |
| 304 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); |
| 305 | cb.batterySendBroadcast(intent); |
| 306 | } |
| 307 | break; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 308 | } |
| 309 | } |
| 310 | } |
| 311 | |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 312 | public void postBatteryNeedsCpuUpdateMsg() { |
| 313 | mHandler.sendEmptyMessage(MSG_REPORT_CPU_UPDATE_NEEDED); |
| 314 | } |
| 315 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 316 | /** |
| 317 | * Update per-freq cpu times for all the uids in {@link #mPendingUids}. |
| 318 | */ |
Sudheer Shanka | e544d16 | 2017-12-28 17:06:20 -0800 | [diff] [blame] | 319 | public void updateProcStateCpuTimes(boolean onBattery, boolean onBatteryScreenOff) { |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 320 | final SparseIntArray uidStates; |
| 321 | synchronized (BatteryStatsImpl.this) { |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 322 | if (!mConstants.TRACK_CPU_TIMES_BY_PROC_STATE) { |
| 323 | return; |
| 324 | } |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 325 | if(!initKernelSingleUidTimeReaderLocked()) { |
| 326 | return; |
| 327 | } |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 328 | // If the KernelSingleUidTimeReader has stale cpu times, then we shouldn't try to |
| 329 | // compute deltas since it might result in mis-attributing cpu times to wrong states. |
| 330 | if (mKernelSingleUidTimeReader.hasStaleData()) { |
| 331 | mPendingUids.clear(); |
| 332 | return; |
| 333 | } |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 334 | |
| 335 | if (mPendingUids.size() == 0) { |
| 336 | return; |
| 337 | } |
| 338 | uidStates = mPendingUids.clone(); |
| 339 | mPendingUids.clear(); |
| 340 | } |
| 341 | for (int i = uidStates.size() - 1; i >= 0; --i) { |
| 342 | final int uid = uidStates.keyAt(i); |
| 343 | final int procState = uidStates.valueAt(i); |
| 344 | final int[] isolatedUids; |
| 345 | final Uid u; |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 346 | synchronized (BatteryStatsImpl.this) { |
| 347 | // It's possible that uid no longer exists and any internal references have |
| 348 | // already been deleted, so using {@link #getAvailableUidStatsLocked} to avoid |
| 349 | // creating an UidStats object if it doesn't already exist. |
| 350 | u = getAvailableUidStatsLocked(uid); |
| 351 | if (u == null) { |
| 352 | continue; |
| 353 | } |
| 354 | if (u.mChildUids == null) { |
| 355 | isolatedUids = null; |
| 356 | } else { |
| 357 | isolatedUids = u.mChildUids.toArray(); |
| 358 | for (int j = isolatedUids.length - 1; j >= 0; --j) { |
| 359 | isolatedUids[j] = u.mChildUids.get(j); |
| 360 | } |
| 361 | } |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 362 | } |
| 363 | long[] cpuTimesMs = mKernelSingleUidTimeReader.readDeltaMs(uid); |
| 364 | if (isolatedUids != null) { |
| 365 | for (int j = isolatedUids.length - 1; j >= 0; --j) { |
| 366 | cpuTimesMs = addCpuTimes(cpuTimesMs, |
| 367 | mKernelSingleUidTimeReader.readDeltaMs(isolatedUids[j])); |
| 368 | } |
| 369 | } |
| 370 | if (onBattery && cpuTimesMs != null) { |
| 371 | synchronized (BatteryStatsImpl.this) { |
Sudheer Shanka | e544d16 | 2017-12-28 17:06:20 -0800 | [diff] [blame] | 372 | u.addProcStateTimesMs(procState, cpuTimesMs, onBattery); |
| 373 | u.addProcStateScreenOffTimesMs(procState, cpuTimesMs, onBatteryScreenOff); |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 374 | } |
| 375 | } |
| 376 | } |
| 377 | } |
| 378 | |
Sudheer Shanka | e544d16 | 2017-12-28 17:06:20 -0800 | [diff] [blame] | 379 | public void copyFromAllUidsCpuTimes() { |
| 380 | synchronized (BatteryStatsImpl.this) { |
| 381 | copyFromAllUidsCpuTimes( |
| 382 | mOnBatteryTimeBase.isRunning(), mOnBatteryScreenOffTimeBase.isRunning()); |
| 383 | } |
| 384 | } |
| 385 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 386 | /** |
| 387 | * When the battery/screen state changes, we don't attribute the cpu times to any process |
| 388 | * but we still need to snapshots of all uids to get correct deltas later on. Since we |
| 389 | * already read this data for updating per-freq cpu times, we can use the same data for |
| 390 | * per-procstate cpu times. |
| 391 | */ |
Sudheer Shanka | e544d16 | 2017-12-28 17:06:20 -0800 | [diff] [blame] | 392 | public void copyFromAllUidsCpuTimes(boolean onBattery, boolean onBatteryScreenOff) { |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 393 | synchronized (BatteryStatsImpl.this) { |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 394 | if (!mConstants.TRACK_CPU_TIMES_BY_PROC_STATE) { |
| 395 | return; |
| 396 | } |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 397 | if(!initKernelSingleUidTimeReaderLocked()) { |
| 398 | return; |
| 399 | } |
| 400 | |
| 401 | final SparseArray<long[]> allUidCpuFreqTimesMs = |
| 402 | mKernelUidCpuFreqTimeReader.getAllUidCpuFreqTimeMs(); |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 403 | // If the KernelSingleUidTimeReader has stale cpu times, then we shouldn't try to |
| 404 | // compute deltas since it might result in mis-attributing cpu times to wrong states. |
| 405 | if (mKernelSingleUidTimeReader.hasStaleData()) { |
| 406 | mKernelSingleUidTimeReader.setAllUidsCpuTimesMs(allUidCpuFreqTimesMs); |
| 407 | mKernelSingleUidTimeReader.markDataAsStale(false); |
| 408 | mPendingUids.clear(); |
| 409 | return; |
| 410 | } |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 411 | for (int i = allUidCpuFreqTimesMs.size() - 1; i >= 0; --i) { |
| 412 | final int uid = allUidCpuFreqTimesMs.keyAt(i); |
| 413 | final Uid u = getAvailableUidStatsLocked(mapUid(uid)); |
| 414 | if (u == null) { |
| 415 | continue; |
| 416 | } |
| 417 | final long[] cpuTimesMs = allUidCpuFreqTimesMs.valueAt(i); |
| 418 | if (cpuTimesMs == null) { |
| 419 | continue; |
| 420 | } |
| 421 | final long[] deltaTimesMs = mKernelSingleUidTimeReader.computeDelta( |
| 422 | uid, cpuTimesMs.clone()); |
Sudheer Shanka | e544d16 | 2017-12-28 17:06:20 -0800 | [diff] [blame] | 423 | if (onBattery && deltaTimesMs != null) { |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 424 | final int procState; |
| 425 | final int idx = mPendingUids.indexOfKey(uid); |
| 426 | if (idx >= 0) { |
| 427 | procState = mPendingUids.valueAt(idx); |
| 428 | mPendingUids.removeAt(idx); |
| 429 | } else { |
| 430 | procState = u.mProcessState; |
| 431 | } |
| 432 | if (procState >= 0 && procState < Uid.NUM_PROCESS_STATE) { |
Sudheer Shanka | e544d16 | 2017-12-28 17:06:20 -0800 | [diff] [blame] | 433 | u.addProcStateTimesMs(procState, deltaTimesMs, onBattery); |
| 434 | u.addProcStateScreenOffTimesMs(procState, deltaTimesMs, onBatteryScreenOff); |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 435 | } |
| 436 | } |
| 437 | } |
| 438 | } |
| 439 | } |
| 440 | |
| 441 | @VisibleForTesting |
| 442 | public long[] addCpuTimes(long[] timesA, long[] timesB) { |
| 443 | if (timesA != null && timesB != null) { |
| 444 | for (int i = timesA.length - 1; i >= 0; --i) { |
| 445 | timesA[i] += timesB[i]; |
| 446 | } |
| 447 | return timesA; |
| 448 | } |
| 449 | return timesA == null ? (timesB == null ? null : timesB) : timesA; |
| 450 | } |
| 451 | |
| 452 | @GuardedBy("this") |
| 453 | private boolean initKernelSingleUidTimeReaderLocked() { |
| 454 | if (mKernelSingleUidTimeReader == null) { |
| 455 | if (mPowerProfile == null) { |
| 456 | return false; |
| 457 | } |
| 458 | if (mCpuFreqs == null) { |
| 459 | mCpuFreqs = mKernelUidCpuFreqTimeReader.readFreqs(mPowerProfile); |
| 460 | } |
| 461 | if (mCpuFreqs != null) { |
| 462 | mKernelSingleUidTimeReader = new KernelSingleUidTimeReader(mCpuFreqs.length); |
| 463 | } else { |
| 464 | mPerProcStateCpuTimesAvailable = mKernelUidCpuFreqTimeReader.allUidTimesAvailable(); |
| 465 | return false; |
| 466 | } |
| 467 | } |
| 468 | mPerProcStateCpuTimesAvailable = mKernelUidCpuFreqTimeReader.allUidTimesAvailable() |
| 469 | && mKernelSingleUidTimeReader.singleUidCpuTimesAvailable(); |
| 470 | return true; |
| 471 | } |
| 472 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 473 | public interface Clocks { |
| 474 | public long elapsedRealtime(); |
| 475 | public long uptimeMillis(); |
| 476 | } |
| 477 | |
| 478 | public static class SystemClocks implements Clocks { |
| 479 | public long elapsedRealtime() { |
| 480 | return SystemClock.elapsedRealtime(); |
| 481 | } |
| 482 | |
| 483 | public long uptimeMillis() { |
| 484 | return SystemClock.uptimeMillis(); |
| 485 | } |
| 486 | } |
| 487 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 488 | public interface ExternalStatsSync { |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 489 | int UPDATE_CPU = 0x01; |
| 490 | int UPDATE_WIFI = 0x02; |
| 491 | int UPDATE_RADIO = 0x04; |
| 492 | int UPDATE_BT = 0x08; |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 493 | int UPDATE_RPM = 0x10; // 16 |
| 494 | 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] | 495 | |
Adam Lesinski | b3a1bad | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 496 | Future<?> scheduleSync(String reason, int flags); |
| 497 | Future<?> scheduleCpuSyncDueToRemovedUid(int uid); |
Sudheer Shanka | c20379e | 2018-02-15 00:06:21 -0800 | [diff] [blame] | 498 | Future<?> scheduleReadProcStateCpuTimes(boolean onBattery, boolean onBatteryScreenOff, |
| 499 | long delayMillis); |
Sudheer Shanka | e544d16 | 2017-12-28 17:06:20 -0800 | [diff] [blame] | 500 | Future<?> scheduleCopyFromAllUidsCpuTimes(boolean onBattery, boolean onBatteryScreenOff); |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 501 | Future<?> scheduleCpuSyncDueToSettingChange(); |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 502 | Future<?> scheduleCpuSyncDueToScreenStateChange(boolean onBattery, |
| 503 | boolean onBatteryScreenOff); |
| 504 | Future<?> scheduleCpuSyncDueToWakelockChange(long delayMillis); |
| 505 | void cancelCpuSyncDueToWakelockChange(); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 506 | } |
| 507 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 508 | public Handler mHandler; |
Adam Lesinski | b3a1bad | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 509 | private ExternalStatsSync mExternalSync = null; |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 510 | @VisibleForTesting |
| 511 | protected UserInfoProvider mUserInfoProvider = null; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 512 | |
| 513 | private BatteryCallback mCallback; |
| 514 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 515 | /** |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 516 | * Mapping isolated uids to the actual owning app uid. |
| 517 | */ |
| 518 | final SparseIntArray mIsolatedUids = new SparseIntArray(); |
| 519 | |
| 520 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 521 | * The statistics we have collected organized by uids. |
| 522 | */ |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 523 | final SparseArray<BatteryStatsImpl.Uid> mUidStats = new SparseArray<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 524 | |
| 525 | // A set of pools of currently active timers. When a timer is queried, we will divide the |
| 526 | // elapsed time by the number of active timers to arrive at that timer's share of the time. |
| 527 | // In order to do this, we must refresh each timer whenever the number of active timers |
| 528 | // changes. |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 529 | @VisibleForTesting |
| 530 | protected ArrayList<StopwatchTimer> mPartialTimers = new ArrayList<>(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 531 | final ArrayList<StopwatchTimer> mFullTimers = new ArrayList<>(); |
| 532 | final ArrayList<StopwatchTimer> mWindowTimers = new ArrayList<>(); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 533 | final ArrayList<StopwatchTimer> mDrawTimers = new ArrayList<>(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 534 | final SparseArray<ArrayList<StopwatchTimer>> mSensorTimers = new SparseArray<>(); |
| 535 | final ArrayList<StopwatchTimer> mWifiRunningTimers = new ArrayList<>(); |
| 536 | final ArrayList<StopwatchTimer> mFullWifiLockTimers = new ArrayList<>(); |
| 537 | final ArrayList<StopwatchTimer> mWifiMulticastTimers = new ArrayList<>(); |
| 538 | final ArrayList<StopwatchTimer> mWifiScanTimers = new ArrayList<>(); |
| 539 | final SparseArray<ArrayList<StopwatchTimer>> mWifiBatchedScanTimers = new SparseArray<>(); |
| 540 | final ArrayList<StopwatchTimer> mAudioTurnedOnTimers = new ArrayList<>(); |
| 541 | final ArrayList<StopwatchTimer> mVideoTurnedOnTimers = new ArrayList<>(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 542 | final ArrayList<StopwatchTimer> mFlashlightTurnedOnTimers = new ArrayList<>(); |
| 543 | final ArrayList<StopwatchTimer> mCameraTurnedOnTimers = new ArrayList<>(); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 544 | final ArrayList<StopwatchTimer> mBluetoothScanOnTimers = new ArrayList<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 545 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 546 | // Last partial timers we use for distributing CPU usage. |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 547 | @VisibleForTesting |
| 548 | protected ArrayList<StopwatchTimer> mLastPartialTimers = new ArrayList<>(); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 549 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 550 | // These are the objects that will want to do something when the device |
| 551 | // is unplugged from power. |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 552 | protected final TimeBase mOnBatteryTimeBase = new TimeBase(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 553 | |
| 554 | // 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] | 555 | // is unplugged from power *and* the screen is off or doze. |
| 556 | protected final TimeBase mOnBatteryScreenOffTimeBase = new TimeBase(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 557 | |
| 558 | // Set to true when we want to distribute CPU across wakelocks for the next |
| 559 | // CPU update, even if we aren't currently running wake locks. |
| 560 | boolean mDistributeWakelockCpu; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 561 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 562 | boolean mShuttingDown; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 563 | |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 564 | final HistoryEventTracker mActiveEvents = new HistoryEventTracker(); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 565 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 566 | long mHistoryBaseTime; |
Narayan Kamath | 695cf72 | 2017-12-21 18:32:47 +0000 | [diff] [blame] | 567 | protected boolean mHaveBatteryLevel = false; |
| 568 | protected boolean mRecordingHistory = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 569 | int mNumHistoryItems; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 570 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 571 | final Parcel mHistoryBuffer = Parcel.obtain(); |
| 572 | final HistoryItem mHistoryLastWritten = new HistoryItem(); |
| 573 | final HistoryItem mHistoryLastLastWritten = new HistoryItem(); |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 574 | final HistoryItem mHistoryReadTmp = new HistoryItem(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 575 | final HistoryItem mHistoryAddTmp = new HistoryItem(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 576 | final HashMap<HistoryTag, Integer> mHistoryTagPool = new HashMap<>(); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 577 | String[] mReadHistoryStrings; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 578 | int[] mReadHistoryUids; |
| 579 | int mReadHistoryChars; |
| 580 | int mNextHistoryTagIdx = 0; |
| 581 | int mNumHistoryTagChars = 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 582 | int mHistoryBufferLastPos = -1; |
| 583 | boolean mHistoryOverflow = false; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 584 | int mActiveHistoryStates = 0xffffffff; |
| 585 | int mActiveHistoryStates2 = 0xffffffff; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 586 | long mLastHistoryElapsedRealtime = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 587 | long mTrackRunningHistoryElapsedRealtime = 0; |
| 588 | long mTrackRunningHistoryUptime = 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 589 | |
| 590 | final HistoryItem mHistoryCur = new HistoryItem(); |
| 591 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 592 | HistoryItem mHistory; |
| 593 | HistoryItem mHistoryEnd; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 594 | HistoryItem mHistoryLastEnd; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 595 | HistoryItem mHistoryCache; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 596 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 597 | // Used by computeHistoryStepDetails |
| 598 | HistoryStepDetails mLastHistoryStepDetails = null; |
| 599 | byte mLastHistoryStepLevel = 0; |
| 600 | final HistoryStepDetails mCurHistoryStepDetails = new HistoryStepDetails(); |
| 601 | final HistoryStepDetails mReadHistoryStepDetails = new HistoryStepDetails(); |
| 602 | final HistoryStepDetails mTmpHistoryStepDetails = new HistoryStepDetails(); |
Adam Lesinski | 7b83b0c | 2015-06-05 12:59:36 -0700 | [diff] [blame] | 603 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 604 | /** |
Adam Lesinski | 7b83b0c | 2015-06-05 12:59:36 -0700 | [diff] [blame] | 605 | * Total time (in milliseconds) spent executing in user code. |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 606 | */ |
| 607 | long mLastStepCpuUserTime; |
| 608 | long mCurStepCpuUserTime; |
| 609 | /** |
Adam Lesinski | 7b83b0c | 2015-06-05 12:59:36 -0700 | [diff] [blame] | 610 | * Total time (in milliseconds) spent executing in kernel code. |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 611 | */ |
| 612 | long mLastStepCpuSystemTime; |
| 613 | long mCurStepCpuSystemTime; |
| 614 | /** |
Adam Lesinski | 7b83b0c | 2015-06-05 12:59:36 -0700 | [diff] [blame] | 615 | * Times from /proc/stat (but measured in milliseconds). |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 616 | */ |
| 617 | long mLastStepStatUserTime; |
| 618 | long mLastStepStatSystemTime; |
| 619 | long mLastStepStatIOWaitTime; |
| 620 | long mLastStepStatIrqTime; |
| 621 | long mLastStepStatSoftIrqTime; |
| 622 | long mLastStepStatIdleTime; |
| 623 | long mCurStepStatUserTime; |
| 624 | long mCurStepStatSystemTime; |
| 625 | long mCurStepStatIOWaitTime; |
| 626 | long mCurStepStatIrqTime; |
| 627 | long mCurStepStatSoftIrqTime; |
| 628 | long mCurStepStatIdleTime; |
| 629 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 630 | private HistoryItem mHistoryIterator; |
| 631 | private boolean mReadOverflow; |
| 632 | private boolean mIteratingHistory; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 633 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 634 | int mStartCount; |
| 635 | |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 636 | long mStartClockTime; |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 637 | String mStartPlatformVersion; |
| 638 | String mEndPlatformVersion; |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 639 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 640 | long mUptime; |
| 641 | long mUptimeStart; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 642 | long mRealtime; |
| 643 | long mRealtimeStart; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 644 | |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 645 | int mWakeLockNesting; |
| 646 | boolean mWakeLockImportant; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 647 | public boolean mRecordAllHistory; |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 648 | boolean mNoAutoReset; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 649 | |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 650 | @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 651 | protected int mScreenState = Display.STATE_UNKNOWN; |
| 652 | @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 653 | protected StopwatchTimer mScreenOnTimer; |
| 654 | @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 655 | protected StopwatchTimer mScreenDozeTimer; |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 656 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 657 | int mScreenBrightnessBin = -1; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 658 | final StopwatchTimer[] mScreenBrightnessTimer = new StopwatchTimer[NUM_SCREEN_BRIGHTNESS_BINS]; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 659 | |
Amith Yamasani | 674c9bb | 2017-02-01 09:45:17 -0800 | [diff] [blame] | 660 | boolean mPretendScreenOff; |
| 661 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 662 | boolean mInteractive; |
| 663 | StopwatchTimer mInteractiveTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 664 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 665 | boolean mPowerSaveModeEnabled; |
| 666 | StopwatchTimer mPowerSaveModeEnabledTimer; |
| 667 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 668 | boolean mDeviceIdling; |
| 669 | StopwatchTimer mDeviceIdlingTimer; |
| 670 | |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 671 | boolean mDeviceLightIdling; |
| 672 | StopwatchTimer mDeviceLightIdlingTimer; |
| 673 | |
| 674 | int mDeviceIdleMode; |
| 675 | long mLastIdleTimeStart; |
| 676 | long mLongestLightIdleTime; |
| 677 | long mLongestFullIdleTime; |
| 678 | StopwatchTimer mDeviceIdleModeLightTimer; |
| 679 | StopwatchTimer mDeviceIdleModeFullTimer; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 680 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 681 | boolean mPhoneOn; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 682 | StopwatchTimer mPhoneOnTimer; |
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 mAudioOnNesting; |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 685 | StopwatchTimer mAudioOnTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 686 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 687 | int mVideoOnNesting; |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 688 | StopwatchTimer mVideoOnTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 689 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 690 | int mFlashlightOnNesting; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 691 | StopwatchTimer mFlashlightOnTimer; |
| 692 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 693 | int mCameraOnNesting; |
| 694 | StopwatchTimer mCameraOnTimer; |
| 695 | |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 696 | int mGpsSignalQualityBin = -1; |
Narayan Kamath | efa0fe6 | 2018-02-05 16:04:43 +0000 | [diff] [blame] | 697 | @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 698 | protected final StopwatchTimer[] mGpsSignalQualityTimer = |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 699 | new StopwatchTimer[GnssMetrics.NUM_GPS_SIGNAL_QUALITY_LEVELS]; |
| 700 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 701 | int mPhoneSignalStrengthBin = -1; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 702 | int mPhoneSignalStrengthBinRaw = -1; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 703 | final StopwatchTimer[] mPhoneSignalStrengthsTimer = |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 704 | new StopwatchTimer[SignalStrength.NUM_SIGNAL_STRENGTH_BINS]; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 705 | |
| 706 | StopwatchTimer mPhoneSignalScanningTimer; |
| 707 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 708 | int mPhoneDataConnectionType = -1; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 709 | final StopwatchTimer[] mPhoneDataConnectionsTimer = |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 710 | new StopwatchTimer[NUM_DATA_CONNECTION_TYPES]; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 711 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 712 | final LongSamplingCounter[] mNetworkByteActivityCounters = |
| 713 | new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
| 714 | final LongSamplingCounter[] mNetworkPacketActivityCounters = |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 715 | new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
| 716 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 717 | /** |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 718 | * The WiFi Overall wakelock timer |
| 719 | * This timer tracks the actual aggregate time for which MC wakelocks are enabled |
| 720 | * since addition of per UID timers would not result in an accurate value due to overlapp of |
| 721 | * per uid wakelock timers |
| 722 | */ |
| 723 | StopwatchTimer mWifiMulticastWakelockTimer; |
| 724 | |
| 725 | /** |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 726 | * The WiFi controller activity (time in tx, rx, idle, and power consumed) for the device. |
| 727 | */ |
| 728 | ControllerActivityCounterImpl mWifiActivity; |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 729 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 730 | /** |
| 731 | * The Bluetooth controller activity (time in tx, rx, idle, and power consumed) for the device. |
| 732 | */ |
| 733 | ControllerActivityCounterImpl mBluetoothActivity; |
| 734 | |
| 735 | /** |
| 736 | * The Modem controller activity (time in tx, rx, idle, and power consumed) for the device. |
| 737 | */ |
| 738 | ControllerActivityCounterImpl mModemActivity; |
| 739 | |
| 740 | /** |
| 741 | * Whether the device supports WiFi controller energy reporting. This is set to true on |
| 742 | * the first WiFi energy report. See {@link #mWifiActivity}. |
| 743 | */ |
| 744 | boolean mHasWifiReporting = false; |
| 745 | |
| 746 | /** |
| 747 | * Whether the device supports Bluetooth controller energy reporting. This is set to true on |
| 748 | * the first Bluetooth energy report. See {@link #mBluetoothActivity}. |
| 749 | */ |
| 750 | boolean mHasBluetoothReporting = false; |
| 751 | |
| 752 | /** |
| 753 | * Whether the device supports Modem controller energy reporting. This is set to true on |
| 754 | * the first Modem energy report. See {@link #mModemActivity}. |
| 755 | */ |
| 756 | boolean mHasModemReporting = false; |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 757 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 758 | boolean mWifiOn; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 759 | StopwatchTimer mWifiOnTimer; |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 760 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 761 | boolean mGlobalWifiRunning; |
| 762 | StopwatchTimer mGlobalWifiRunningTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 763 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 764 | int mWifiState = -1; |
| 765 | final StopwatchTimer[] mWifiStateTimer = new StopwatchTimer[NUM_WIFI_STATES]; |
| 766 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 767 | int mWifiSupplState = -1; |
| 768 | final StopwatchTimer[] mWifiSupplStateTimer = new StopwatchTimer[NUM_WIFI_SUPPL_STATES]; |
| 769 | |
| 770 | int mWifiSignalStrengthBin = -1; |
| 771 | final StopwatchTimer[] mWifiSignalStrengthsTimer = |
| 772 | new StopwatchTimer[NUM_WIFI_SIGNAL_STRENGTH_BINS]; |
| 773 | |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 774 | StopwatchTimer mWifiActiveTimer; |
| 775 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 776 | int mBluetoothScanNesting; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 777 | @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 778 | protected StopwatchTimer mBluetoothScanTimer; |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 779 | |
Siddharth Ray | f5e796a | 2018-01-22 18:18:17 -0800 | [diff] [blame] | 780 | boolean mIsCellularTxPowerHigh = false; |
| 781 | |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 782 | int mMobileRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
Dianne Hackborn | f7097a5 | 2014-05-13 09:56:14 -0700 | [diff] [blame] | 783 | long mMobileRadioActiveStartTime; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 784 | StopwatchTimer mMobileRadioActiveTimer; |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 785 | StopwatchTimer mMobileRadioActivePerAppTimer; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 786 | LongSamplingCounter mMobileRadioActiveAdjustedTime; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 787 | LongSamplingCounter mMobileRadioActiveUnknownTime; |
| 788 | LongSamplingCounter mMobileRadioActiveUnknownCount; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 789 | |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 790 | int mWifiRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
| 791 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 792 | /** |
| 793 | * These provide time bases that discount the time the device is plugged |
| 794 | * in to power. |
| 795 | */ |
| 796 | boolean mOnBattery; |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 797 | @VisibleForTesting |
| 798 | protected boolean mOnBatteryInternal; |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 799 | |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 800 | /** |
| 801 | * External reporting of whether the device is actually charging. |
| 802 | */ |
| 803 | boolean mCharging = true; |
| 804 | int mLastChargingStateLevel; |
| 805 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 806 | /* |
| 807 | * These keep track of battery levels (1-100) at the last plug event and the last unplug event. |
| 808 | */ |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 809 | int mDischargeStartLevel; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 810 | int mDischargeUnplugLevel; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 811 | int mDischargePlugLevel; |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 812 | int mDischargeCurrentLevel; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 813 | int mCurrentBatteryLevel; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 814 | int mLowDischargeAmountSinceCharge; |
| 815 | int mHighDischargeAmountSinceCharge; |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 816 | int mDischargeScreenOnUnplugLevel; |
| 817 | int mDischargeScreenOffUnplugLevel; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 818 | int mDischargeScreenDozeUnplugLevel; |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 819 | int mDischargeAmountScreenOn; |
| 820 | int mDischargeAmountScreenOnSinceCharge; |
| 821 | int mDischargeAmountScreenOff; |
| 822 | int mDischargeAmountScreenOffSinceCharge; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 823 | int mDischargeAmountScreenDoze; |
| 824 | int mDischargeAmountScreenDozeSinceCharge; |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 825 | |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 826 | private LongSamplingCounter mDischargeScreenOffCounter; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 827 | private LongSamplingCounter mDischargeScreenDozeCounter; |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 828 | private LongSamplingCounter mDischargeCounter; |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 829 | private LongSamplingCounter mDischargeLightDozeCounter; |
| 830 | private LongSamplingCounter mDischargeDeepDozeCounter; |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 831 | |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 832 | static final int MAX_LEVEL_STEPS = 200; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 833 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 834 | int mInitStepMode = 0; |
| 835 | int mCurStepMode = 0; |
| 836 | int mModStepMode = 0; |
| 837 | |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 838 | int mLastDischargeStepLevel; |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 839 | int mMinDischargeStepLevel; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 840 | final LevelStepTracker mDischargeStepTracker = new LevelStepTracker(MAX_LEVEL_STEPS); |
| 841 | final LevelStepTracker mDailyDischargeStepTracker = new LevelStepTracker(MAX_LEVEL_STEPS*2); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 842 | ArrayList<PackageChange> mDailyPackageChanges; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 843 | |
| 844 | int mLastChargeStepLevel; |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 845 | int mMaxChargeStepLevel; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 846 | final LevelStepTracker mChargeStepTracker = new LevelStepTracker(MAX_LEVEL_STEPS); |
| 847 | final LevelStepTracker mDailyChargeStepTracker = new LevelStepTracker(MAX_LEVEL_STEPS*2); |
| 848 | |
| 849 | static final int MAX_DAILY_ITEMS = 10; |
| 850 | |
| 851 | long mDailyStartTime = 0; |
| 852 | long mNextMinDailyDeadline = 0; |
| 853 | long mNextMaxDailyDeadline = 0; |
| 854 | |
| 855 | final ArrayList<DailyItem> mDailyItems = new ArrayList<>(); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 856 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 857 | long mLastWriteTime = 0; // Milliseconds |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 858 | |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 859 | private int mPhoneServiceState = -1; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 860 | private int mPhoneServiceStateRaw = -1; |
| 861 | private int mPhoneSimStateRaw = -1; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 862 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 863 | private int mNumConnectivityChange; |
| 864 | private int mLoadedNumConnectivityChange; |
| 865 | private int mUnpluggedNumConnectivityChange; |
| 866 | |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 867 | private int mEstimatedBatteryCapacity = -1; |
| 868 | |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 869 | private int mMinLearnedBatteryCapacity = -1; |
| 870 | private int mMaxLearnedBatteryCapacity = -1; |
Adam Lesinski | 041d917 | 2016-12-12 12:03:56 -0800 | [diff] [blame] | 871 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 872 | private long[] mCpuFreqs; |
| 873 | |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 874 | @VisibleForTesting |
| 875 | protected PowerProfile mPowerProfile; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 876 | |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 877 | @GuardedBy("this") |
| 878 | private final Constants mConstants; |
| 879 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 880 | /* |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 881 | * Holds a SamplingTimer associated with each Resource Power Manager state and voter, |
| 882 | * recording their times when on-battery (regardless of screen state). |
| 883 | */ |
| 884 | private final HashMap<String, SamplingTimer> mRpmStats = new HashMap<>(); |
| 885 | /** Times for each Resource Power Manager state and voter when screen-off and on-battery. */ |
| 886 | private final HashMap<String, SamplingTimer> mScreenOffRpmStats = new HashMap<>(); |
| 887 | |
| 888 | @Override |
| 889 | public Map<String, ? extends Timer> getRpmStats() { |
| 890 | return mRpmStats; |
| 891 | } |
| 892 | |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 893 | // TODO: Note: screenOffRpmStats has been disabled via SCREEN_OFF_RPM_STATS_ENABLED. |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 894 | @Override |
| 895 | public Map<String, ? extends Timer> getScreenOffRpmStats() { |
| 896 | return mScreenOffRpmStats; |
| 897 | } |
| 898 | |
| 899 | /* |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 900 | * Holds a SamplingTimer associated with each kernel wakelock name being tracked. |
| 901 | */ |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 902 | private final HashMap<String, SamplingTimer> mKernelWakelockStats = new HashMap<>(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 903 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 904 | public Map<String, ? extends Timer> getKernelWakelockStats() { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 905 | return mKernelWakelockStats; |
| 906 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 907 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 908 | String mLastWakeupReason = null; |
| 909 | long mLastWakeupUptimeMs = 0; |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 910 | private final HashMap<String, SamplingTimer> mWakeupReasonStats = new HashMap<>(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 911 | |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 912 | public Map<String, ? extends Timer> getWakeupReasonStats() { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 913 | return mWakeupReasonStats; |
| 914 | } |
| 915 | |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 916 | @Override |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 917 | public long getUahDischarge(int which) { |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 918 | return mDischargeCounter.getCountLocked(which); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 919 | } |
| 920 | |
| 921 | @Override |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 922 | public long getUahDischargeScreenOff(int which) { |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 923 | return mDischargeScreenOffCounter.getCountLocked(which); |
| 924 | } |
| 925 | |
| 926 | @Override |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 927 | public long getUahDischargeScreenDoze(int which) { |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 928 | return mDischargeScreenDozeCounter.getCountLocked(which); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 929 | } |
| 930 | |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 931 | @Override |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 932 | public long getUahDischargeLightDoze(int which) { |
| 933 | return mDischargeLightDozeCounter.getCountLocked(which); |
| 934 | } |
| 935 | |
| 936 | @Override |
| 937 | public long getUahDischargeDeepDoze(int which) { |
| 938 | return mDischargeDeepDozeCounter.getCountLocked(which); |
| 939 | } |
| 940 | |
| 941 | @Override |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 942 | public int getEstimatedBatteryCapacity() { |
| 943 | return mEstimatedBatteryCapacity; |
| 944 | } |
| 945 | |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 946 | @Override |
| 947 | public int getMinLearnedBatteryCapacity() { |
| 948 | return mMinLearnedBatteryCapacity; |
| 949 | } |
| 950 | |
| 951 | @Override |
| 952 | public int getMaxLearnedBatteryCapacity() { |
| 953 | return mMaxLearnedBatteryCapacity; |
| 954 | } |
| 955 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 956 | public BatteryStatsImpl() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 957 | this(new SystemClocks()); |
| 958 | } |
| 959 | |
| 960 | public BatteryStatsImpl(Clocks clocks) { |
| 961 | init(clocks); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 962 | mFile = null; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 963 | mCheckinFile = null; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 964 | mDailyFile = null; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 965 | mHandler = null; |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 966 | mPlatformIdleStateCallback = null; |
Suprabh Shukla | e6e723d | 2017-06-14 16:14:43 -0700 | [diff] [blame] | 967 | mUserInfoProvider = null; |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 968 | mConstants = new Constants(mHandler); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 969 | clearHistoryLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 970 | } |
| 971 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 972 | private void init(Clocks clocks) { |
| 973 | mClocks = clocks; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 974 | } |
| 975 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 976 | public interface TimeBaseObs { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 977 | void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime); |
| 978 | void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime); |
| 979 | } |
| 980 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 981 | // methods are protected not private to be VisibleForTesting |
| 982 | public static class TimeBase { |
| 983 | protected final ArrayList<TimeBaseObs> mObservers = new ArrayList<>(); |
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 long mUptime; |
| 986 | protected long mRealtime; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 987 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 988 | protected boolean mRunning; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 989 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 990 | protected long mPastUptime; |
| 991 | protected long mUptimeStart; |
| 992 | protected long mPastRealtime; |
| 993 | protected long mRealtimeStart; |
| 994 | protected long mUnpluggedUptime; |
| 995 | protected long mUnpluggedRealtime; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 996 | |
| 997 | public void dump(PrintWriter pw, String prefix) { |
| 998 | StringBuilder sb = new StringBuilder(128); |
| 999 | pw.print(prefix); pw.print("mRunning="); pw.println(mRunning); |
| 1000 | sb.setLength(0); |
| 1001 | sb.append(prefix); |
| 1002 | sb.append("mUptime="); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 1003 | formatTimeMs(sb, mUptime / 1000); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1004 | pw.println(sb.toString()); |
| 1005 | sb.setLength(0); |
| 1006 | sb.append(prefix); |
| 1007 | sb.append("mRealtime="); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 1008 | formatTimeMs(sb, mRealtime / 1000); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1009 | pw.println(sb.toString()); |
| 1010 | sb.setLength(0); |
| 1011 | sb.append(prefix); |
| 1012 | sb.append("mPastUptime="); |
| 1013 | formatTimeMs(sb, mPastUptime / 1000); sb.append("mUptimeStart="); |
| 1014 | formatTimeMs(sb, mUptimeStart / 1000); |
| 1015 | sb.append("mUnpluggedUptime="); formatTimeMs(sb, mUnpluggedUptime / 1000); |
| 1016 | pw.println(sb.toString()); |
| 1017 | sb.setLength(0); |
| 1018 | sb.append(prefix); |
| 1019 | sb.append("mPastRealtime="); |
| 1020 | formatTimeMs(sb, mPastRealtime / 1000); sb.append("mRealtimeStart="); |
| 1021 | formatTimeMs(sb, mRealtimeStart / 1000); |
| 1022 | sb.append("mUnpluggedRealtime="); formatTimeMs(sb, mUnpluggedRealtime / 1000); |
| 1023 | pw.println(sb.toString()); |
| 1024 | } |
| 1025 | |
| 1026 | public void add(TimeBaseObs observer) { |
| 1027 | mObservers.add(observer); |
| 1028 | } |
| 1029 | |
| 1030 | public void remove(TimeBaseObs observer) { |
| 1031 | if (!mObservers.remove(observer)) { |
| 1032 | Slog.wtf(TAG, "Removed unknown observer: " + observer); |
| 1033 | } |
| 1034 | } |
| 1035 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1036 | public boolean hasObserver(TimeBaseObs observer) { |
| 1037 | return mObservers.contains(observer); |
| 1038 | } |
| 1039 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1040 | public void init(long uptime, long realtime) { |
| 1041 | mRealtime = 0; |
| 1042 | mUptime = 0; |
| 1043 | mPastUptime = 0; |
| 1044 | mPastRealtime = 0; |
| 1045 | mUptimeStart = uptime; |
| 1046 | mRealtimeStart = realtime; |
| 1047 | mUnpluggedUptime = getUptime(mUptimeStart); |
| 1048 | mUnpluggedRealtime = getRealtime(mRealtimeStart); |
| 1049 | } |
| 1050 | |
| 1051 | public void reset(long uptime, long realtime) { |
| 1052 | if (!mRunning) { |
| 1053 | mPastUptime = 0; |
| 1054 | mPastRealtime = 0; |
| 1055 | } else { |
| 1056 | mUptimeStart = uptime; |
| 1057 | mRealtimeStart = realtime; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1058 | // TODO: Since mUptimeStart was just reset and we are running, getUptime will |
| 1059 | // 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] | 1060 | mUnpluggedUptime = getUptime(uptime); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1061 | // TODO: likewise. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1062 | mUnpluggedRealtime = getRealtime(realtime); |
| 1063 | } |
| 1064 | } |
| 1065 | |
| 1066 | public long computeUptime(long curTime, int which) { |
| 1067 | switch (which) { |
| 1068 | case STATS_SINCE_CHARGED: |
| 1069 | return mUptime + getUptime(curTime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1070 | case STATS_CURRENT: |
| 1071 | return getUptime(curTime); |
| 1072 | case STATS_SINCE_UNPLUGGED: |
| 1073 | return getUptime(curTime) - mUnpluggedUptime; |
| 1074 | } |
| 1075 | return 0; |
| 1076 | } |
| 1077 | |
| 1078 | public long computeRealtime(long curTime, int which) { |
| 1079 | switch (which) { |
| 1080 | case STATS_SINCE_CHARGED: |
| 1081 | return mRealtime + getRealtime(curTime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1082 | case STATS_CURRENT: |
| 1083 | return getRealtime(curTime); |
| 1084 | case STATS_SINCE_UNPLUGGED: |
| 1085 | return getRealtime(curTime) - mUnpluggedRealtime; |
| 1086 | } |
| 1087 | return 0; |
| 1088 | } |
| 1089 | |
| 1090 | public long getUptime(long curTime) { |
| 1091 | long time = mPastUptime; |
| 1092 | if (mRunning) { |
| 1093 | time += curTime - mUptimeStart; |
| 1094 | } |
| 1095 | return time; |
| 1096 | } |
| 1097 | |
| 1098 | public long getRealtime(long curTime) { |
| 1099 | long time = mPastRealtime; |
| 1100 | if (mRunning) { |
| 1101 | time += curTime - mRealtimeStart; |
| 1102 | } |
| 1103 | return time; |
| 1104 | } |
| 1105 | |
| 1106 | public long getUptimeStart() { |
| 1107 | return mUptimeStart; |
| 1108 | } |
| 1109 | |
| 1110 | public long getRealtimeStart() { |
| 1111 | return mRealtimeStart; |
| 1112 | } |
| 1113 | |
| 1114 | public boolean isRunning() { |
| 1115 | return mRunning; |
| 1116 | } |
| 1117 | |
| 1118 | public boolean setRunning(boolean running, long uptime, long realtime) { |
| 1119 | if (mRunning != running) { |
| 1120 | mRunning = running; |
| 1121 | if (running) { |
| 1122 | mUptimeStart = uptime; |
| 1123 | mRealtimeStart = realtime; |
| 1124 | long batteryUptime = mUnpluggedUptime = getUptime(uptime); |
| 1125 | long batteryRealtime = mUnpluggedRealtime = getRealtime(realtime); |
| 1126 | |
| 1127 | for (int i = mObservers.size() - 1; i >= 0; i--) { |
| 1128 | mObservers.get(i).onTimeStarted(realtime, batteryUptime, batteryRealtime); |
| 1129 | } |
| 1130 | } else { |
| 1131 | mPastUptime += uptime - mUptimeStart; |
| 1132 | mPastRealtime += realtime - mRealtimeStart; |
| 1133 | |
| 1134 | long batteryUptime = getUptime(uptime); |
| 1135 | long batteryRealtime = getRealtime(realtime); |
| 1136 | |
| 1137 | for (int i = mObservers.size() - 1; i >= 0; i--) { |
| 1138 | mObservers.get(i).onTimeStopped(realtime, batteryUptime, batteryRealtime); |
| 1139 | } |
| 1140 | } |
| 1141 | return true; |
| 1142 | } |
| 1143 | return false; |
| 1144 | } |
| 1145 | |
| 1146 | public void readSummaryFromParcel(Parcel in) { |
| 1147 | mUptime = in.readLong(); |
| 1148 | mRealtime = in.readLong(); |
| 1149 | } |
| 1150 | |
| 1151 | public void writeSummaryToParcel(Parcel out, long uptime, long realtime) { |
| 1152 | out.writeLong(computeUptime(uptime, STATS_SINCE_CHARGED)); |
| 1153 | out.writeLong(computeRealtime(realtime, STATS_SINCE_CHARGED)); |
| 1154 | } |
| 1155 | |
| 1156 | public void readFromParcel(Parcel in) { |
| 1157 | mRunning = false; |
| 1158 | mUptime = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1159 | mPastUptime = in.readLong(); |
| 1160 | mUptimeStart = in.readLong(); |
Dianne Hackborn | ef640cd | 2014-03-25 14:41:05 -0700 | [diff] [blame] | 1161 | mRealtime = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1162 | mPastRealtime = in.readLong(); |
| 1163 | mRealtimeStart = in.readLong(); |
| 1164 | mUnpluggedUptime = in.readLong(); |
| 1165 | mUnpluggedRealtime = in.readLong(); |
| 1166 | } |
| 1167 | |
| 1168 | public void writeToParcel(Parcel out, long uptime, long realtime) { |
| 1169 | final long runningUptime = getUptime(uptime); |
| 1170 | final long runningRealtime = getRealtime(realtime); |
| 1171 | out.writeLong(mUptime); |
| 1172 | out.writeLong(runningUptime); |
| 1173 | out.writeLong(mUptimeStart); |
Dianne Hackborn | ef640cd | 2014-03-25 14:41:05 -0700 | [diff] [blame] | 1174 | out.writeLong(mRealtime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1175 | out.writeLong(runningRealtime); |
| 1176 | out.writeLong(mRealtimeStart); |
| 1177 | out.writeLong(mUnpluggedUptime); |
| 1178 | out.writeLong(mUnpluggedRealtime); |
| 1179 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1180 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1181 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1182 | /** |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1183 | * State for keeping track of counting information. |
| 1184 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1185 | public static class Counter extends BatteryStats.Counter implements TimeBaseObs { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 1186 | final AtomicInteger mCount = new AtomicInteger(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1187 | final TimeBase mTimeBase; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1188 | int mLoadedCount; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1189 | int mUnpluggedCount; |
| 1190 | int mPluggedCount; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1191 | |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 1192 | public Counter(TimeBase timeBase, Parcel in) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1193 | mTimeBase = timeBase; |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 1194 | mPluggedCount = in.readInt(); |
| 1195 | mCount.set(mPluggedCount); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1196 | mLoadedCount = in.readInt(); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1197 | mUnpluggedCount = in.readInt(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1198 | timeBase.add(this); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1199 | } |
| 1200 | |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 1201 | public Counter(TimeBase timeBase) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1202 | mTimeBase = timeBase; |
| 1203 | timeBase.add(this); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1204 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1205 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1206 | public void writeToParcel(Parcel out) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 1207 | out.writeInt(mCount.get()); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1208 | out.writeInt(mLoadedCount); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1209 | out.writeInt(mUnpluggedCount); |
| 1210 | } |
| 1211 | |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 1212 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1213 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 1214 | mUnpluggedCount = mPluggedCount; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1215 | } |
| 1216 | |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 1217 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1218 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 1219 | mPluggedCount = mCount.get(); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1220 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1221 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1222 | /** |
| 1223 | * Writes a possibly null Counter to a Parcel. |
| 1224 | * |
| 1225 | * @param out the Parcel to be written to. |
| 1226 | * @param counter a Counter, or null. |
| 1227 | */ |
Amith Yamasani | 977e11f | 2018-02-16 11:29:54 -0800 | [diff] [blame] | 1228 | public static void writeCounterToParcel(Parcel out, @Nullable Counter counter) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1229 | if (counter == null) { |
| 1230 | out.writeInt(0); // indicates null |
| 1231 | return; |
| 1232 | } |
| 1233 | out.writeInt(1); // indicates non-null |
| 1234 | |
| 1235 | counter.writeToParcel(out); |
| 1236 | } |
| 1237 | |
Amith Yamasani | 977e11f | 2018-02-16 11:29:54 -0800 | [diff] [blame] | 1238 | /** |
| 1239 | * Reads a Counter that was written using {@link #writeCounterToParcel(Parcel, Counter)}. |
| 1240 | * @param timeBase the timebase to assign to the Counter |
| 1241 | * @param in the parcel to read from |
| 1242 | * @return the Counter or null. |
| 1243 | */ |
| 1244 | public static @Nullable Counter readCounterFromParcel(TimeBase timeBase, Parcel in) { |
| 1245 | if (in.readInt() == 0) { |
| 1246 | return null; |
| 1247 | } |
| 1248 | return new Counter(timeBase, in); |
| 1249 | } |
| 1250 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1251 | @Override |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1252 | public int getCountLocked(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 1253 | int val = mCount.get(); |
| 1254 | if (which == STATS_SINCE_UNPLUGGED) { |
| 1255 | val -= mUnpluggedCount; |
| 1256 | } else if (which != STATS_SINCE_CHARGED) { |
| 1257 | val -= mLoadedCount; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1258 | } |
| 1259 | |
| 1260 | return val; |
| 1261 | } |
| 1262 | |
| 1263 | public void logState(Printer pw, String prefix) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 1264 | pw.println(prefix + "mCount=" + mCount.get() |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 1265 | + " mLoadedCount=" + mLoadedCount |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1266 | + " mUnpluggedCount=" + mUnpluggedCount |
| 1267 | + " mPluggedCount=" + mPluggedCount); |
| 1268 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1269 | |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 1270 | @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 1271 | public void stepAtomic() { |
| 1272 | if (mTimeBase.isRunning()) { |
| 1273 | mCount.incrementAndGet(); |
| 1274 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1275 | } |
| 1276 | |
Bookatz | 4ebc064 | 2017-05-11 12:21:19 -0700 | [diff] [blame] | 1277 | void addAtomic(int delta) { |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 1278 | if (mTimeBase.isRunning()) { |
| 1279 | mCount.addAndGet(delta); |
| 1280 | } |
Bookatz | 4ebc064 | 2017-05-11 12:21:19 -0700 | [diff] [blame] | 1281 | } |
| 1282 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1283 | /** |
| 1284 | * Clear state of this counter. |
| 1285 | */ |
| 1286 | void reset(boolean detachIfReset) { |
| 1287 | mCount.set(0); |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 1288 | mLoadedCount = mPluggedCount = mUnpluggedCount = 0; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1289 | if (detachIfReset) { |
| 1290 | detach(); |
| 1291 | } |
| 1292 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1293 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1294 | void detach() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1295 | mTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1296 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1297 | |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 1298 | @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 1299 | public void writeSummaryFromParcelLocked(Parcel out) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 1300 | int count = mCount.get(); |
| 1301 | out.writeInt(count); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1302 | } |
| 1303 | |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 1304 | @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 1305 | public void readSummaryFromParcelLocked(Parcel in) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 1306 | mLoadedCount = in.readInt(); |
| 1307 | mCount.set(mLoadedCount); |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 1308 | mUnpluggedCount = mPluggedCount = mLoadedCount; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1309 | } |
| 1310 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 1311 | |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 1312 | @VisibleForTesting |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1313 | public static class LongSamplingCounterArray extends LongCounterArray implements TimeBaseObs { |
| 1314 | final TimeBase mTimeBase; |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 1315 | public long[] mCounts; |
| 1316 | public long[] mLoadedCounts; |
| 1317 | public long[] mUnpluggedCounts; |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1318 | |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 1319 | private LongSamplingCounterArray(TimeBase timeBase, Parcel in) { |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1320 | mTimeBase = timeBase; |
Sudheer Shanka | e544d16 | 2017-12-28 17:06:20 -0800 | [diff] [blame] | 1321 | mCounts = in.createLongArray(); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1322 | mLoadedCounts = in.createLongArray(); |
| 1323 | mUnpluggedCounts = in.createLongArray(); |
| 1324 | timeBase.add(this); |
| 1325 | } |
| 1326 | |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 1327 | public LongSamplingCounterArray(TimeBase timeBase) { |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1328 | mTimeBase = timeBase; |
| 1329 | timeBase.add(this); |
| 1330 | } |
| 1331 | |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 1332 | private void writeToParcel(Parcel out) { |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1333 | out.writeLongArray(mCounts); |
| 1334 | out.writeLongArray(mLoadedCounts); |
| 1335 | out.writeLongArray(mUnpluggedCounts); |
| 1336 | } |
| 1337 | |
| 1338 | @Override |
| 1339 | public void onTimeStarted(long elapsedRealTime, long baseUptime, long baseRealtime) { |
Sudheer Shanka | e544d16 | 2017-12-28 17:06:20 -0800 | [diff] [blame] | 1340 | mUnpluggedCounts = copyArray(mCounts, mUnpluggedCounts); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1341 | } |
| 1342 | |
| 1343 | @Override |
| 1344 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1345 | } |
| 1346 | |
| 1347 | @Override |
| 1348 | public long[] getCountsLocked(int which) { |
Sudheer Shanka | e544d16 | 2017-12-28 17:06:20 -0800 | [diff] [blame] | 1349 | long[] val = copyArray(mCounts, null); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1350 | if (which == STATS_SINCE_UNPLUGGED) { |
| 1351 | subtract(val, mUnpluggedCounts); |
| 1352 | } else if (which != STATS_SINCE_CHARGED) { |
| 1353 | subtract(val, mLoadedCounts); |
| 1354 | } |
| 1355 | return val; |
| 1356 | } |
| 1357 | |
| 1358 | @Override |
| 1359 | public void logState(Printer pw, String prefix) { |
| 1360 | pw.println(prefix + "mCounts=" + Arrays.toString(mCounts) |
| 1361 | + " mLoadedCounts=" + Arrays.toString(mLoadedCounts) |
Sudheer Shanka | e544d16 | 2017-12-28 17:06:20 -0800 | [diff] [blame] | 1362 | + " mUnpluggedCounts=" + Arrays.toString(mUnpluggedCounts)); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1363 | } |
| 1364 | |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 1365 | public void addCountLocked(long[] counts) { |
Sudheer Shanka | e544d16 | 2017-12-28 17:06:20 -0800 | [diff] [blame] | 1366 | addCountLocked(counts, mTimeBase.isRunning()); |
| 1367 | } |
| 1368 | |
| 1369 | public void addCountLocked(long[] counts, boolean isRunning) { |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1370 | if (counts == null) { |
| 1371 | return; |
| 1372 | } |
Sudheer Shanka | e544d16 | 2017-12-28 17:06:20 -0800 | [diff] [blame] | 1373 | if (isRunning) { |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 1374 | if (mCounts == null) { |
| 1375 | mCounts = new long[counts.length]; |
| 1376 | } |
| 1377 | for (int i = 0; i < counts.length; ++i) { |
| 1378 | mCounts[i] += counts[i]; |
| 1379 | } |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1380 | } |
| 1381 | } |
| 1382 | |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 1383 | public int getSize() { |
| 1384 | return mCounts == null ? 0 : mCounts.length; |
| 1385 | } |
| 1386 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1387 | /** |
| 1388 | * Clear state of this counter. |
| 1389 | */ |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 1390 | public void reset(boolean detachIfReset) { |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1391 | fillArray(mCounts, 0); |
| 1392 | fillArray(mLoadedCounts, 0); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1393 | fillArray(mUnpluggedCounts, 0); |
| 1394 | if (detachIfReset) { |
| 1395 | detach(); |
| 1396 | } |
| 1397 | } |
| 1398 | |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 1399 | public void detach() { |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1400 | mTimeBase.remove(this); |
| 1401 | } |
| 1402 | |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 1403 | private void writeSummaryToParcelLocked(Parcel out) { |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1404 | out.writeLongArray(mCounts); |
| 1405 | } |
| 1406 | |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 1407 | private void readSummaryFromParcelLocked(Parcel in) { |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1408 | mCounts = in.createLongArray(); |
| 1409 | mLoadedCounts = copyArray(mCounts, mLoadedCounts); |
| 1410 | mUnpluggedCounts = copyArray(mCounts, mUnpluggedCounts); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1411 | } |
| 1412 | |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 1413 | public static void writeToParcel(Parcel out, LongSamplingCounterArray counterArray) { |
| 1414 | if (counterArray != null) { |
| 1415 | out.writeInt(1); |
| 1416 | counterArray.writeToParcel(out); |
| 1417 | } else { |
| 1418 | out.writeInt(0); |
| 1419 | } |
| 1420 | } |
| 1421 | |
| 1422 | public static LongSamplingCounterArray readFromParcel(Parcel in, TimeBase timeBase) { |
| 1423 | if (in.readInt() != 0) { |
| 1424 | return new LongSamplingCounterArray(timeBase, in); |
| 1425 | } else { |
| 1426 | return null; |
| 1427 | } |
| 1428 | } |
| 1429 | |
| 1430 | public static void writeSummaryToParcelLocked(Parcel out, |
| 1431 | LongSamplingCounterArray counterArray) { |
| 1432 | if (counterArray != null) { |
| 1433 | out.writeInt(1); |
| 1434 | counterArray.writeSummaryToParcelLocked(out); |
| 1435 | } else { |
| 1436 | out.writeInt(0); |
| 1437 | } |
| 1438 | } |
| 1439 | |
| 1440 | public static LongSamplingCounterArray readSummaryFromParcelLocked(Parcel in, |
| 1441 | TimeBase timeBase) { |
| 1442 | if (in.readInt() != 0) { |
| 1443 | final LongSamplingCounterArray counterArray |
| 1444 | = new LongSamplingCounterArray(timeBase); |
| 1445 | counterArray.readSummaryFromParcelLocked(in); |
| 1446 | return counterArray; |
| 1447 | } else { |
| 1448 | return null; |
| 1449 | } |
| 1450 | } |
| 1451 | |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 1452 | private static void fillArray(long[] a, long val) { |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1453 | if (a != null) { |
| 1454 | Arrays.fill(a, val); |
| 1455 | } |
| 1456 | } |
| 1457 | |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 1458 | private static void subtract(@NonNull long[] val, long[] toSubtract) { |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1459 | if (toSubtract == null) { |
| 1460 | return; |
| 1461 | } |
| 1462 | for (int i = 0; i < val.length; i++) { |
| 1463 | val[i] -= toSubtract[i]; |
| 1464 | } |
| 1465 | } |
| 1466 | |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 1467 | private static long[] copyArray(long[] src, long[] dest) { |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1468 | if (src == null) { |
| 1469 | return null; |
| 1470 | } else { |
| 1471 | if (dest == null) { |
| 1472 | dest = new long[src.length]; |
| 1473 | } |
| 1474 | System.arraycopy(src, 0, dest, 0, src.length); |
| 1475 | return dest; |
| 1476 | } |
| 1477 | } |
| 1478 | } |
| 1479 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1480 | public static class LongSamplingCounter extends LongCounter implements TimeBaseObs { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1481 | final TimeBase mTimeBase; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1482 | long mCount; |
| 1483 | long mLoadedCount; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1484 | long mUnpluggedCount; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1485 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1486 | LongSamplingCounter(TimeBase timeBase, Parcel in) { |
| 1487 | mTimeBase = timeBase; |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 1488 | mCount = in.readLong(); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1489 | mLoadedCount = in.readLong(); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1490 | mUnpluggedCount = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1491 | timeBase.add(this); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1492 | } |
| 1493 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1494 | LongSamplingCounter(TimeBase timeBase) { |
| 1495 | mTimeBase = timeBase; |
| 1496 | timeBase.add(this); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1497 | } |
| 1498 | |
| 1499 | public void writeToParcel(Parcel out) { |
| 1500 | out.writeLong(mCount); |
| 1501 | out.writeLong(mLoadedCount); |
| 1502 | out.writeLong(mUnpluggedCount); |
| 1503 | } |
| 1504 | |
| 1505 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1506 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 1507 | mUnpluggedCount = mCount; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1508 | } |
| 1509 | |
| 1510 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1511 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1512 | } |
| 1513 | |
| 1514 | public long getCountLocked(int which) { |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 1515 | long val = mCount; |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 1516 | if (which == STATS_SINCE_UNPLUGGED) { |
| 1517 | val -= mUnpluggedCount; |
| 1518 | } else if (which != STATS_SINCE_CHARGED) { |
| 1519 | val -= mLoadedCount; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1520 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1521 | return val; |
| 1522 | } |
| 1523 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1524 | @Override |
| 1525 | public void logState(Printer pw, String prefix) { |
| 1526 | pw.println(prefix + "mCount=" + mCount |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 1527 | + " mLoadedCount=" + mLoadedCount |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 1528 | + " mUnpluggedCount=" + mUnpluggedCount); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1529 | } |
| 1530 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1531 | void addCountLocked(long count) { |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 1532 | addCountLocked(count, mTimeBase.isRunning()); |
| 1533 | } |
| 1534 | |
| 1535 | void addCountLocked(long count, boolean isRunning) { |
| 1536 | if (isRunning) { |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 1537 | mCount += count; |
| 1538 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1539 | } |
| 1540 | |
| 1541 | /** |
| 1542 | * Clear state of this counter. |
| 1543 | */ |
| 1544 | void reset(boolean detachIfReset) { |
| 1545 | mCount = 0; |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 1546 | mLoadedCount = mUnpluggedCount = 0; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1547 | if (detachIfReset) { |
| 1548 | detach(); |
| 1549 | } |
| 1550 | } |
| 1551 | |
| 1552 | void detach() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1553 | mTimeBase.remove(this); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1554 | } |
| 1555 | |
| 1556 | void writeSummaryFromParcelLocked(Parcel out) { |
| 1557 | out.writeLong(mCount); |
| 1558 | } |
| 1559 | |
| 1560 | void readSummaryFromParcelLocked(Parcel in) { |
| 1561 | mLoadedCount = in.readLong(); |
| 1562 | mCount = mLoadedCount; |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 1563 | mUnpluggedCount = mLoadedCount; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1564 | } |
| 1565 | } |
| 1566 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1567 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1568 | * State for keeping track of timing information. |
| 1569 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1570 | public static abstract class Timer extends BatteryStats.Timer implements TimeBaseObs { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1571 | protected final Clocks mClocks; |
| 1572 | protected final int mType; |
| 1573 | protected final TimeBase mTimeBase; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1574 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1575 | protected int mCount; |
| 1576 | protected int mLoadedCount; |
| 1577 | protected int mLastCount; |
| 1578 | protected int mUnpluggedCount; |
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 | // Times are in microseconds for better accuracy when dividing by the |
| 1581 | // lock count, and are in "battery realtime" units. |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1582 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1583 | /** |
| 1584 | * The total time we have accumulated since the start of the original |
| 1585 | * boot, to the last time something interesting happened in the |
| 1586 | * current run. |
| 1587 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1588 | protected long mTotalTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1589 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1590 | /** |
| 1591 | * The total time we loaded for the previous runs. Subtract this from |
| 1592 | * mTotalTime to find the time for the current run of the system. |
| 1593 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1594 | protected long mLoadedTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1595 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1596 | /** |
| 1597 | * The run time of the last run of the system, as loaded from the |
| 1598 | * saved data. |
| 1599 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1600 | protected long mLastTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1601 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1602 | /** |
| 1603 | * The value of mTotalTime when unplug() was last called. Subtract |
| 1604 | * this from mTotalTime to find the time since the last unplug from |
| 1605 | * power. |
| 1606 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1607 | protected long mUnpluggedTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1608 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 1609 | /** |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1610 | * The total time this timer has been running until the latest mark has been set. |
| 1611 | * Subtract this from mTotalTime to get the time spent running since the mark was set. |
| 1612 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1613 | protected long mTimeBeforeMark; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1614 | |
| 1615 | /** |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 1616 | * Constructs from a parcel. |
| 1617 | * @param type |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1618 | * @param timeBase |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 1619 | * @param in |
| 1620 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1621 | public Timer(Clocks clocks, int type, TimeBase timeBase, Parcel in) { |
| 1622 | mClocks = clocks; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1623 | mType = type; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1624 | mTimeBase = timeBase; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1625 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1626 | mCount = in.readInt(); |
| 1627 | mLoadedCount = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1628 | mLastCount = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1629 | mUnpluggedCount = in.readInt(); |
| 1630 | mTotalTime = in.readLong(); |
| 1631 | mLoadedTime = in.readLong(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1632 | mLastTime = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1633 | mUnpluggedTime = in.readLong(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1634 | mTimeBeforeMark = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1635 | timeBase.add(this); |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 1636 | 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] | 1637 | } |
| 1638 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1639 | public Timer(Clocks clocks, int type, TimeBase timeBase) { |
| 1640 | mClocks = clocks; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1641 | mType = type; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1642 | mTimeBase = timeBase; |
| 1643 | timeBase.add(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1644 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1645 | |
| 1646 | protected abstract long computeRunTimeLocked(long curBatteryRealtime); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1647 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1648 | protected abstract int computeCurrentCountLocked(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1649 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1650 | /** |
| 1651 | * Clear state of this timer. Returns true if the timer is inactive |
| 1652 | * so can be completely dropped. |
| 1653 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1654 | public boolean reset(boolean detachIfReset) { |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1655 | mTotalTime = mLoadedTime = mLastTime = mTimeBeforeMark = 0; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1656 | mCount = mLoadedCount = mLastCount = 0; |
| 1657 | if (detachIfReset) { |
| 1658 | detach(); |
| 1659 | } |
| 1660 | return true; |
| 1661 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1662 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1663 | public void detach() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1664 | mTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1665 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1666 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1667 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 1668 | if (DEBUG) Log.i(TAG, "**** WRITING TIMER #" + mType + ": mTotalTime=" |
| 1669 | + computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs))); |
Adam Lesinski | 98f0d46 | 2016-04-19 16:46:20 -0700 | [diff] [blame] | 1670 | out.writeInt(computeCurrentCountLocked()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1671 | out.writeInt(mLoadedCount); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1672 | out.writeInt(mUnpluggedCount); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1673 | out.writeLong(computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs))); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1674 | out.writeLong(mLoadedTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1675 | out.writeLong(mUnpluggedTime); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1676 | out.writeLong(mTimeBeforeMark); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1677 | } |
| 1678 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1679 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1680 | public void onTimeStarted(long elapsedRealtime, long timeBaseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1681 | if (DEBUG && mType < 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1682 | Log.v(TAG, "unplug #" + mType + ": realtime=" + baseRealtime |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1683 | + " old mUnpluggedTime=" + mUnpluggedTime |
| 1684 | + " old mUnpluggedCount=" + mUnpluggedCount); |
| 1685 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1686 | mUnpluggedTime = computeRunTimeLocked(baseRealtime); |
Adam Lesinski | 98f0d46 | 2016-04-19 16:46:20 -0700 | [diff] [blame] | 1687 | mUnpluggedCount = computeCurrentCountLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1688 | if (DEBUG && mType < 0) { |
| 1689 | Log.v(TAG, "unplug #" + mType |
| 1690 | + ": new mUnpluggedTime=" + mUnpluggedTime |
| 1691 | + " new mUnpluggedCount=" + mUnpluggedCount); |
| 1692 | } |
| 1693 | } |
| 1694 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1695 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1696 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1697 | if (DEBUG && mType < 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1698 | Log.v(TAG, "plug #" + mType + ": realtime=" + baseRealtime |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1699 | + " old mTotalTime=" + mTotalTime); |
| 1700 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1701 | mTotalTime = computeRunTimeLocked(baseRealtime); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1702 | mCount = computeCurrentCountLocked(); |
| 1703 | if (DEBUG && mType < 0) { |
| 1704 | Log.v(TAG, "plug #" + mType |
| 1705 | + ": new mTotalTime=" + mTotalTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1706 | } |
| 1707 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1708 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1709 | /** |
| 1710 | * Writes a possibly null Timer to a Parcel. |
| 1711 | * |
| 1712 | * @param out the Parcel to be written to. |
| 1713 | * @param timer a Timer, or null. |
| 1714 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1715 | 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] | 1716 | if (timer == null) { |
| 1717 | out.writeInt(0); // indicates null |
| 1718 | return; |
| 1719 | } |
| 1720 | out.writeInt(1); // indicates non-null |
| 1721 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1722 | timer.writeToParcel(out, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1723 | } |
| 1724 | |
| 1725 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1726 | public long getTotalTimeLocked(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 1727 | long val = computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs)); |
| 1728 | if (which == STATS_SINCE_UNPLUGGED) { |
| 1729 | val -= mUnpluggedTime; |
| 1730 | } else if (which != STATS_SINCE_CHARGED) { |
| 1731 | val -= mLoadedTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1732 | } |
| 1733 | |
| 1734 | return val; |
| 1735 | } |
| 1736 | |
| 1737 | @Override |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1738 | public int getCountLocked(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 1739 | int val = computeCurrentCountLocked(); |
| 1740 | if (which == STATS_SINCE_UNPLUGGED) { |
| 1741 | val -= mUnpluggedCount; |
| 1742 | } else if (which != STATS_SINCE_CHARGED) { |
| 1743 | val -= mLoadedCount; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1744 | } |
| 1745 | |
| 1746 | return val; |
| 1747 | } |
| 1748 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1749 | @Override |
| 1750 | public long getTimeSinceMarkLocked(long elapsedRealtimeUs) { |
| 1751 | long val = computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs)); |
| 1752 | return val - mTimeBeforeMark; |
| 1753 | } |
| 1754 | |
| 1755 | @Override |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1756 | public void logState(Printer pw, String prefix) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 1757 | pw.println(prefix + "mCount=" + mCount |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1758 | + " mLoadedCount=" + mLoadedCount + " mLastCount=" + mLastCount |
| 1759 | + " mUnpluggedCount=" + mUnpluggedCount); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1760 | pw.println(prefix + "mTotalTime=" + mTotalTime |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1761 | + " mLoadedTime=" + mLoadedTime); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1762 | pw.println(prefix + "mLastTime=" + mLastTime |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1763 | + " mUnpluggedTime=" + mUnpluggedTime); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1764 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1765 | |
| 1766 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1767 | public void writeSummaryFromParcelLocked(Parcel out, long elapsedRealtimeUs) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1768 | long runTime = computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs)); |
| 1769 | out.writeLong(runTime); |
Adam Lesinski | 98f0d46 | 2016-04-19 16:46:20 -0700 | [diff] [blame] | 1770 | out.writeInt(computeCurrentCountLocked()); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1771 | } |
| 1772 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1773 | public void readSummaryFromParcelLocked(Parcel in) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1774 | // Multiply by 1000 for backwards compatibility |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1775 | mTotalTime = mLoadedTime = in.readLong(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1776 | mLastTime = 0; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1777 | mUnpluggedTime = mTotalTime; |
| 1778 | mCount = mLoadedCount = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1779 | mLastCount = 0; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1780 | mUnpluggedCount = mCount; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1781 | |
| 1782 | // When reading the summary, we set the mark to be the latest information. |
| 1783 | mTimeBeforeMark = mTotalTime; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1784 | } |
| 1785 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1786 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1787 | /** |
| 1788 | * A counter meant to accept monotonically increasing values to its {@link #update(long, int)} |
| 1789 | * method. The state of the timer according to its {@link TimeBase} will determine how much |
| 1790 | * of the value is recorded. |
| 1791 | * |
| 1792 | * If the value being recorded resets, {@link #endSample()} can be called in order to |
| 1793 | * account for the change. If the value passed in to {@link #update(long, int)} decreased |
| 1794 | * between calls, the {@link #endSample()} is automatically called and the new value is |
| 1795 | * expected to increase monotonically from that point on. |
| 1796 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1797 | public static class SamplingTimer extends Timer { |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1798 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1799 | /** |
| 1800 | * The most recent reported count from /proc/wakelocks. |
| 1801 | */ |
| 1802 | int mCurrentReportedCount; |
| 1803 | |
| 1804 | /** |
| 1805 | * The reported count from /proc/wakelocks when unplug() was last |
| 1806 | * called. |
| 1807 | */ |
| 1808 | int mUnpluggedReportedCount; |
| 1809 | |
| 1810 | /** |
| 1811 | * The most recent reported total_time from /proc/wakelocks. |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1812 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1813 | long mCurrentReportedTotalTime; |
| 1814 | |
| 1815 | |
| 1816 | /** |
| 1817 | * The reported total_time from /proc/wakelocks when unplug() was last |
| 1818 | * called. |
| 1819 | */ |
| 1820 | long mUnpluggedReportedTotalTime; |
| 1821 | |
| 1822 | /** |
| 1823 | * Whether we are currently in a discharge cycle. |
| 1824 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1825 | boolean mTimeBaseRunning; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1826 | |
| 1827 | /** |
| 1828 | * Whether we are currently recording reported values. |
| 1829 | */ |
| 1830 | boolean mTrackingReportedValues; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1831 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1832 | /* |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1833 | * A sequence counter, incremented once for each update of the stats. |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1834 | */ |
| 1835 | int mUpdateVersion; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1836 | |
Adam Lesinski | 98f0d46 | 2016-04-19 16:46:20 -0700 | [diff] [blame] | 1837 | @VisibleForTesting |
| 1838 | public SamplingTimer(Clocks clocks, TimeBase timeBase, Parcel in) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1839 | super(clocks, 0, timeBase, in); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1840 | mCurrentReportedCount = in.readInt(); |
| 1841 | mUnpluggedReportedCount = in.readInt(); |
| 1842 | mCurrentReportedTotalTime = in.readLong(); |
| 1843 | mUnpluggedReportedTotalTime = in.readLong(); |
| 1844 | mTrackingReportedValues = in.readInt() == 1; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1845 | mTimeBaseRunning = timeBase.isRunning(); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1846 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1847 | |
Adam Lesinski | 98f0d46 | 2016-04-19 16:46:20 -0700 | [diff] [blame] | 1848 | @VisibleForTesting |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1849 | public SamplingTimer(Clocks clocks, TimeBase timeBase) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1850 | super(clocks, 0, timeBase); |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1851 | mTrackingReportedValues = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1852 | mTimeBaseRunning = timeBase.isRunning(); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1853 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1854 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1855 | /** |
| 1856 | * Ends the current sample, allowing subsequent values to {@link #update(long, int)} to |
| 1857 | * be less than the values used for a previous invocation. |
| 1858 | */ |
| 1859 | public void endSample() { |
| 1860 | mTotalTime = computeRunTimeLocked(0 /* unused by us */); |
| 1861 | mCount = computeCurrentCountLocked(); |
| 1862 | mUnpluggedReportedTotalTime = mCurrentReportedTotalTime = 0; |
| 1863 | mUnpluggedReportedCount = mCurrentReportedCount = 0; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1864 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1865 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1866 | public void setUpdateVersion(int version) { |
| 1867 | mUpdateVersion = version; |
| 1868 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1869 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1870 | public int getUpdateVersion() { |
| 1871 | return mUpdateVersion; |
| 1872 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1873 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1874 | /** |
| 1875 | * Updates the current recorded values. These are meant to be monotonically increasing |
| 1876 | * and cumulative. If you are dealing with deltas, use {@link #add(long, int)}. |
| 1877 | * |
| 1878 | * If the values being recorded have been reset, the monotonically increasing requirement |
| 1879 | * will be broken. In this case, {@link #endSample()} is automatically called and |
| 1880 | * the total value of totalTime and count are recorded, starting a new monotonically |
| 1881 | * increasing sample. |
| 1882 | * |
| 1883 | * @param totalTime total time of sample in microseconds. |
| 1884 | * @param count total number of times the event being sampled occurred. |
| 1885 | */ |
| 1886 | public void update(long totalTime, int count) { |
| 1887 | if (mTimeBaseRunning && !mTrackingReportedValues) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1888 | // Updating the reported value for the first time. |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1889 | mUnpluggedReportedTotalTime = totalTime; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1890 | mUnpluggedReportedCount = count; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1891 | } |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1892 | |
| 1893 | mTrackingReportedValues = true; |
| 1894 | |
| 1895 | if (totalTime < mCurrentReportedTotalTime || count < mCurrentReportedCount) { |
| 1896 | endSample(); |
| 1897 | } |
| 1898 | |
| 1899 | mCurrentReportedTotalTime = totalTime; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1900 | mCurrentReportedCount = count; |
| 1901 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1902 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1903 | /** |
| 1904 | * Adds deltaTime and deltaCount to the current sample. |
| 1905 | * |
| 1906 | * @param deltaTime additional time recorded since the last sampled event, in microseconds. |
| 1907 | * @param deltaCount additional number of times the event being sampled occurred. |
| 1908 | */ |
| 1909 | public void add(long deltaTime, int deltaCount) { |
| 1910 | update(mCurrentReportedTotalTime + deltaTime, mCurrentReportedCount + deltaCount); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 1911 | } |
| 1912 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1913 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1914 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
| 1915 | super.onTimeStarted(elapsedRealtime, baseUptime, baseRealtime); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1916 | if (mTrackingReportedValues) { |
| 1917 | mUnpluggedReportedTotalTime = mCurrentReportedTotalTime; |
| 1918 | mUnpluggedReportedCount = mCurrentReportedCount; |
| 1919 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1920 | mTimeBaseRunning = true; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1921 | } |
| 1922 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1923 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1924 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
| 1925 | super.onTimeStopped(elapsedRealtime, baseUptime, baseRealtime); |
| 1926 | mTimeBaseRunning = false; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1927 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1928 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1929 | @Override |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1930 | public void logState(Printer pw, String prefix) { |
| 1931 | super.logState(pw, prefix); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1932 | pw.println(prefix + "mCurrentReportedCount=" + mCurrentReportedCount |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1933 | + " mUnpluggedReportedCount=" + mUnpluggedReportedCount |
| 1934 | + " mCurrentReportedTotalTime=" + mCurrentReportedTotalTime |
| 1935 | + " mUnpluggedReportedTotalTime=" + mUnpluggedReportedTotalTime); |
| 1936 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1937 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1938 | @Override |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1939 | protected long computeRunTimeLocked(long curBatteryRealtime) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1940 | return mTotalTime + (mTimeBaseRunning && mTrackingReportedValues |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1941 | ? mCurrentReportedTotalTime - mUnpluggedReportedTotalTime : 0); |
| 1942 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1943 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1944 | @Override |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1945 | protected int computeCurrentCountLocked() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1946 | return mCount + (mTimeBaseRunning && mTrackingReportedValues |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1947 | ? mCurrentReportedCount - mUnpluggedReportedCount : 0); |
| 1948 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1949 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1950 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1951 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
| 1952 | super.writeToParcel(out, elapsedRealtimeUs); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1953 | out.writeInt(mCurrentReportedCount); |
| 1954 | out.writeInt(mUnpluggedReportedCount); |
| 1955 | out.writeLong(mCurrentReportedTotalTime); |
| 1956 | out.writeLong(mUnpluggedReportedTotalTime); |
| 1957 | out.writeInt(mTrackingReportedValues ? 1 : 0); |
| 1958 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1959 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1960 | @Override |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1961 | public boolean reset(boolean detachIfReset) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1962 | super.reset(detachIfReset); |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1963 | mTrackingReportedValues = false; |
| 1964 | mUnpluggedReportedTotalTime = 0; |
| 1965 | mUnpluggedReportedCount = 0; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1966 | return true; |
| 1967 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1968 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1969 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1970 | /** |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1971 | * A timer that increments in batches. It does not run for durations, but just jumps |
| 1972 | * for a pre-determined amount. |
| 1973 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1974 | public static class BatchTimer extends Timer { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1975 | final Uid mUid; |
| 1976 | |
| 1977 | /** |
| 1978 | * The last time at which we updated the timer. This is in elapsed realtime microseconds. |
| 1979 | */ |
| 1980 | long mLastAddedTime; |
| 1981 | |
| 1982 | /** |
| 1983 | * The last duration that we added to the timer. This is in microseconds. |
| 1984 | */ |
| 1985 | long mLastAddedDuration; |
| 1986 | |
| 1987 | /** |
| 1988 | * Whether we are currently in a discharge cycle. |
| 1989 | */ |
| 1990 | boolean mInDischarge; |
| 1991 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1992 | BatchTimer(Clocks clocks, Uid uid, int type, TimeBase timeBase, Parcel in) { |
| 1993 | super(clocks, type, timeBase, in); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1994 | mUid = uid; |
| 1995 | mLastAddedTime = in.readLong(); |
| 1996 | mLastAddedDuration = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1997 | mInDischarge = timeBase.isRunning(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1998 | } |
| 1999 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2000 | BatchTimer(Clocks clocks, Uid uid, int type, TimeBase timeBase) { |
| 2001 | super(clocks, type, timeBase); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 2002 | mUid = uid; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2003 | mInDischarge = timeBase.isRunning(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 2004 | } |
| 2005 | |
| 2006 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2007 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
| 2008 | super.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 2009 | out.writeLong(mLastAddedTime); |
| 2010 | out.writeLong(mLastAddedDuration); |
| 2011 | } |
| 2012 | |
| 2013 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2014 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2015 | recomputeLastDuration(mClocks.elapsedRealtime() * 1000, false); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 2016 | mInDischarge = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2017 | super.onTimeStopped(elapsedRealtime, baseUptime, baseRealtime); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 2018 | } |
| 2019 | |
| 2020 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2021 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 2022 | recomputeLastDuration(elapsedRealtime, false); |
| 2023 | mInDischarge = true; |
| 2024 | // If we are still within the last added duration, then re-added whatever remains. |
| 2025 | if (mLastAddedTime == elapsedRealtime) { |
| 2026 | mTotalTime += mLastAddedDuration; |
| 2027 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2028 | super.onTimeStarted(elapsedRealtime, baseUptime, baseRealtime); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 2029 | } |
| 2030 | |
| 2031 | @Override |
| 2032 | public void logState(Printer pw, String prefix) { |
| 2033 | super.logState(pw, prefix); |
| 2034 | pw.println(prefix + "mLastAddedTime=" + mLastAddedTime |
| 2035 | + " mLastAddedDuration=" + mLastAddedDuration); |
| 2036 | } |
| 2037 | |
| 2038 | private long computeOverage(long curTime) { |
| 2039 | if (mLastAddedTime > 0) { |
| 2040 | return mLastTime + mLastAddedDuration - curTime; |
| 2041 | } |
| 2042 | return 0; |
| 2043 | } |
| 2044 | |
| 2045 | private void recomputeLastDuration(long curTime, boolean abort) { |
| 2046 | final long overage = computeOverage(curTime); |
| 2047 | if (overage > 0) { |
| 2048 | // Aborting before the duration ran out -- roll back the remaining |
| 2049 | // duration. Only do this if currently discharging; otherwise we didn't |
| 2050 | // actually add the time. |
| 2051 | if (mInDischarge) { |
| 2052 | mTotalTime -= overage; |
| 2053 | } |
| 2054 | if (abort) { |
| 2055 | mLastAddedTime = 0; |
| 2056 | } else { |
| 2057 | mLastAddedTime = curTime; |
| 2058 | mLastAddedDuration -= overage; |
| 2059 | } |
| 2060 | } |
| 2061 | } |
| 2062 | |
| 2063 | public void addDuration(BatteryStatsImpl stats, long durationMillis) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2064 | final long now = mClocks.elapsedRealtime() * 1000; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 2065 | recomputeLastDuration(now, true); |
| 2066 | mLastAddedTime = now; |
| 2067 | mLastAddedDuration = durationMillis * 1000; |
| 2068 | if (mInDischarge) { |
| 2069 | mTotalTime += mLastAddedDuration; |
| 2070 | mCount++; |
| 2071 | } |
| 2072 | } |
| 2073 | |
| 2074 | public void abortLastDuration(BatteryStatsImpl stats) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2075 | final long now = mClocks.elapsedRealtime() * 1000; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 2076 | recomputeLastDuration(now, true); |
| 2077 | } |
| 2078 | |
| 2079 | @Override |
| 2080 | protected int computeCurrentCountLocked() { |
| 2081 | return mCount; |
| 2082 | } |
| 2083 | |
| 2084 | @Override |
| 2085 | protected long computeRunTimeLocked(long curBatteryRealtime) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2086 | final long overage = computeOverage(mClocks.elapsedRealtime() * 1000); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 2087 | if (overage > 0) { |
| 2088 | return mTotalTime = overage; |
| 2089 | } |
| 2090 | return mTotalTime; |
| 2091 | } |
| 2092 | |
| 2093 | @Override |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2094 | public boolean reset(boolean detachIfReset) { |
| 2095 | final long now = mClocks.elapsedRealtime() * 1000; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 2096 | recomputeLastDuration(now, true); |
| 2097 | boolean stillActive = mLastAddedTime == now; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2098 | super.reset(!stillActive && detachIfReset); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 2099 | return !stillActive; |
| 2100 | } |
| 2101 | } |
| 2102 | |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2103 | |
| 2104 | /** |
| 2105 | * A StopwatchTimer that also tracks the total and max individual |
| 2106 | * time spent active according to the given timebase. Whereas |
| 2107 | * StopwatchTimer apportions the time amongst all in the pool, |
| 2108 | * the total and max durations are not apportioned. |
| 2109 | */ |
| 2110 | public static class DurationTimer extends StopwatchTimer { |
| 2111 | /** |
| 2112 | * The time (in ms) that the timer was last acquired or the time base |
| 2113 | * last (re-)started. Increasing the nesting depth does not reset this time. |
| 2114 | * |
| 2115 | * -1 if the timer is currently not running or the time base is not running. |
| 2116 | * |
| 2117 | * If written to a parcel, the start time is reset, as is mNesting in the base class |
| 2118 | * StopwatchTimer. |
| 2119 | */ |
| 2120 | long mStartTimeMs = -1; |
| 2121 | |
| 2122 | /** |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2123 | * 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] | 2124 | */ |
| 2125 | long mMaxDurationMs; |
| 2126 | |
| 2127 | /** |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2128 | * The time (in ms) that that the timer has been active since most recent |
| 2129 | * stopRunningLocked() or reset(). Not pooled. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2130 | */ |
| 2131 | long mCurrentDurationMs; |
| 2132 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2133 | /** |
| 2134 | * The total time (in ms) that that the timer has been active since most recent reset() |
| 2135 | * prior to the current startRunningLocked. This is the sum of all past currentDurations |
| 2136 | * (but not including the present currentDuration) since reset. Not pooled. |
| 2137 | */ |
| 2138 | long mTotalDurationMs; |
| 2139 | |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2140 | public DurationTimer(Clocks clocks, Uid uid, int type, ArrayList<StopwatchTimer> timerPool, |
| 2141 | TimeBase timeBase, Parcel in) { |
| 2142 | super(clocks, uid, type, timerPool, timeBase, in); |
| 2143 | mMaxDurationMs = in.readLong(); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2144 | mTotalDurationMs = in.readLong(); |
jackqdyulei | 610a0a0 | 2017-08-09 14:02:01 -0700 | [diff] [blame] | 2145 | mCurrentDurationMs = in.readLong(); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2146 | } |
| 2147 | |
| 2148 | public DurationTimer(Clocks clocks, Uid uid, int type, ArrayList<StopwatchTimer> timerPool, |
| 2149 | TimeBase timeBase) { |
| 2150 | super(clocks, uid, type, timerPool, timeBase); |
| 2151 | } |
| 2152 | |
| 2153 | @Override |
| 2154 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
| 2155 | super.writeToParcel(out, elapsedRealtimeUs); |
Kweku Adams | 47db5a8 | 2016-12-09 19:04:50 -0800 | [diff] [blame] | 2156 | out.writeLong(getMaxDurationMsLocked(elapsedRealtimeUs / 1000)); |
jackqdyulei | 610a0a0 | 2017-08-09 14:02:01 -0700 | [diff] [blame] | 2157 | out.writeLong(mTotalDurationMs); |
| 2158 | out.writeLong(getCurrentDurationMsLocked(elapsedRealtimeUs / 1000)); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2159 | } |
| 2160 | |
| 2161 | /** |
| 2162 | * Write the summary to the parcel. |
| 2163 | * |
| 2164 | * Since the time base is probably meaningless after we come back, reading |
| 2165 | * 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] | 2166 | * is the max and total durations. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2167 | */ |
| 2168 | @Override |
| 2169 | public void writeSummaryFromParcelLocked(Parcel out, long elapsedRealtimeUs) { |
| 2170 | super.writeSummaryFromParcelLocked(out, elapsedRealtimeUs); |
Kweku Adams | 47db5a8 | 2016-12-09 19:04:50 -0800 | [diff] [blame] | 2171 | out.writeLong(getMaxDurationMsLocked(elapsedRealtimeUs / 1000)); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2172 | out.writeLong(getTotalDurationMsLocked(elapsedRealtimeUs / 1000)); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2173 | } |
| 2174 | |
| 2175 | /** |
| 2176 | * Read the summary parcel. |
| 2177 | * |
| 2178 | * Has the side effect of stopping the timer. |
| 2179 | */ |
| 2180 | @Override |
| 2181 | public void readSummaryFromParcelLocked(Parcel in) { |
| 2182 | super.readSummaryFromParcelLocked(in); |
| 2183 | mMaxDurationMs = in.readLong(); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2184 | mTotalDurationMs = in.readLong(); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2185 | mStartTimeMs = -1; |
| 2186 | mCurrentDurationMs = 0; |
| 2187 | } |
| 2188 | |
| 2189 | /** |
| 2190 | * The TimeBase time started (again). |
| 2191 | * |
| 2192 | * If the timer is also running, store the start time. |
| 2193 | */ |
| 2194 | public void onTimeStarted(long elapsedRealtimeUs, long baseUptime, long baseRealtime) { |
| 2195 | super.onTimeStarted(elapsedRealtimeUs, baseUptime, baseRealtime); |
| 2196 | if (mNesting > 0) { |
Kweku Adams | 47db5a8 | 2016-12-09 19:04:50 -0800 | [diff] [blame] | 2197 | mStartTimeMs = baseRealtime / 1000; |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2198 | } |
| 2199 | } |
| 2200 | |
| 2201 | /** |
| 2202 | * The TimeBase stopped running. |
| 2203 | * |
| 2204 | * If the timer is running, add the duration into mCurrentDurationMs. |
| 2205 | */ |
| 2206 | @Override |
Kweku Adams | 47db5a8 | 2016-12-09 19:04:50 -0800 | [diff] [blame] | 2207 | public void onTimeStopped(long elapsedRealtimeUs, long baseUptime, long baseRealtimeUs) { |
| 2208 | super.onTimeStopped(elapsedRealtimeUs, baseUptime, baseRealtimeUs); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2209 | if (mNesting > 0) { |
Kweku Adams | 47db5a8 | 2016-12-09 19:04:50 -0800 | [diff] [blame] | 2210 | // baseRealtimeUs has already been converted to the timebase's realtime. |
| 2211 | mCurrentDurationMs += (baseRealtimeUs / 1000) - mStartTimeMs; |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2212 | } |
| 2213 | mStartTimeMs = -1; |
| 2214 | } |
| 2215 | |
| 2216 | @Override |
| 2217 | public void logState(Printer pw, String prefix) { |
| 2218 | super.logState(pw, prefix); |
| 2219 | } |
| 2220 | |
| 2221 | @Override |
| 2222 | public void startRunningLocked(long elapsedRealtimeMs) { |
| 2223 | super.startRunningLocked(elapsedRealtimeMs); |
| 2224 | if (mNesting == 1 && mTimeBase.isRunning()) { |
| 2225 | // Just started |
Kweku Adams | 47db5a8 | 2016-12-09 19:04:50 -0800 | [diff] [blame] | 2226 | mStartTimeMs = mTimeBase.getRealtime(elapsedRealtimeMs * 1000) / 1000; |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2227 | } |
| 2228 | } |
| 2229 | |
| 2230 | /** |
| 2231 | * Decrements the mNesting ref-count on this timer. |
| 2232 | * |
| 2233 | * If it actually stopped (mNesting went to 0), then possibly update |
| 2234 | * mMaxDuration if the current duration was the longest ever. |
| 2235 | */ |
| 2236 | @Override |
| 2237 | public void stopRunningLocked(long elapsedRealtimeMs) { |
Kweku Adams | 47db5a8 | 2016-12-09 19:04:50 -0800 | [diff] [blame] | 2238 | if (mNesting == 1) { |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2239 | final long durationMs = getCurrentDurationMsLocked(elapsedRealtimeMs); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2240 | mTotalDurationMs += durationMs; |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2241 | if (durationMs > mMaxDurationMs) { |
| 2242 | mMaxDurationMs = durationMs; |
| 2243 | } |
| 2244 | mStartTimeMs = -1; |
| 2245 | mCurrentDurationMs = 0; |
| 2246 | } |
Kweku Adams | 47db5a8 | 2016-12-09 19:04:50 -0800 | [diff] [blame] | 2247 | // super method decrements mNesting, which getCurrentDurationMsLocked relies on, |
| 2248 | // so call super.stopRunningLocked after calling getCurrentDurationMsLocked. |
| 2249 | super.stopRunningLocked(elapsedRealtimeMs); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2250 | } |
| 2251 | |
| 2252 | @Override |
| 2253 | public boolean reset(boolean detachIfReset) { |
| 2254 | boolean result = super.reset(detachIfReset); |
| 2255 | mMaxDurationMs = 0; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2256 | mTotalDurationMs = 0; |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2257 | mCurrentDurationMs = 0; |
| 2258 | if (mNesting > 0) { |
| 2259 | mStartTimeMs = mTimeBase.getRealtime(mClocks.elapsedRealtime()*1000) / 1000; |
| 2260 | } else { |
| 2261 | mStartTimeMs = -1; |
| 2262 | } |
| 2263 | return result; |
| 2264 | } |
| 2265 | |
| 2266 | /** |
| 2267 | * Returns the max duration that this timer has ever seen. |
| 2268 | * |
| 2269 | * Note that this time is NOT split between the timers in the timer group that |
| 2270 | * this timer is attached to. It is the TOTAL time. |
| 2271 | */ |
| 2272 | @Override |
| 2273 | public long getMaxDurationMsLocked(long elapsedRealtimeMs) { |
| 2274 | if (mNesting > 0) { |
| 2275 | final long durationMs = getCurrentDurationMsLocked(elapsedRealtimeMs); |
| 2276 | if (durationMs > mMaxDurationMs) { |
| 2277 | return durationMs; |
| 2278 | } |
| 2279 | } |
| 2280 | return mMaxDurationMs; |
| 2281 | } |
| 2282 | |
| 2283 | /** |
| 2284 | * Returns the time since the timer was started. |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2285 | * Returns 0 if the timer is not currently running. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2286 | * |
| 2287 | * Note that this time is NOT split between the timers in the timer group that |
| 2288 | * this timer is attached to. It is the TOTAL time. |
jackqdyulei | 610a0a0 | 2017-08-09 14:02:01 -0700 | [diff] [blame] | 2289 | * |
| 2290 | * Note that if running timer is parceled and unparceled, this method will return |
| 2291 | * current duration value at the time of parceling even though timer may not be |
| 2292 | * currently running. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2293 | */ |
| 2294 | @Override |
| 2295 | public long getCurrentDurationMsLocked(long elapsedRealtimeMs) { |
| 2296 | long durationMs = mCurrentDurationMs; |
Kweku Adams | 47db5a8 | 2016-12-09 19:04:50 -0800 | [diff] [blame] | 2297 | if (mNesting > 0 && mTimeBase.isRunning()) { |
| 2298 | durationMs += (mTimeBase.getRealtime(elapsedRealtimeMs*1000)/1000) |
| 2299 | - mStartTimeMs; |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2300 | } |
| 2301 | return durationMs; |
| 2302 | } |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2303 | |
| 2304 | /** |
| 2305 | * Returns the total cumulative duration that this timer has been on since reset(). |
| 2306 | * If mTimerPool == null, this should be the same |
| 2307 | * as getTotalTimeLocked(elapsedRealtimeMs*1000, STATS_SINCE_CHARGED)/1000. |
| 2308 | * |
| 2309 | * Note that this time is NOT split between the timers in the timer group that |
| 2310 | * this timer is attached to. It is the TOTAL time. For this reason, if mTimerPool != null, |
| 2311 | * the result will not be equivalent to getTotalTimeLocked. |
| 2312 | */ |
| 2313 | @Override |
| 2314 | public long getTotalDurationMsLocked(long elapsedRealtimeMs) { |
| 2315 | return mTotalDurationMs + getCurrentDurationMsLocked(elapsedRealtimeMs); |
| 2316 | } |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2317 | } |
| 2318 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 2319 | /** |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2320 | * State for keeping track of timing information. |
| 2321 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2322 | public static class StopwatchTimer extends Timer { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 2323 | final Uid mUid; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2324 | final ArrayList<StopwatchTimer> mTimerPool; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 2325 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2326 | int mNesting; |
| 2327 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2328 | /** |
| 2329 | * The last time at which we updated the timer. If mNesting is > 0, |
| 2330 | * subtract this from the current battery time to find the amount of |
| 2331 | * time we have been running since we last computed an update. |
| 2332 | */ |
| 2333 | long mUpdateTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2334 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2335 | /** |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2336 | * The total time at which the timer was acquired, to determine if it |
Bookatz | ceebafe | 2017-04-06 11:59:13 -0700 | [diff] [blame] | 2337 | * was actually held for an interesting duration. If time base was not running when timer |
| 2338 | * was acquired, will be -1. |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2339 | */ |
Bookatz | ceebafe | 2017-04-06 11:59:13 -0700 | [diff] [blame] | 2340 | long mAcquireTime = -1; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2341 | |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 2342 | long mTimeout; |
| 2343 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 2344 | /** |
| 2345 | * For partial wake locks, keep track of whether we are in the list |
| 2346 | * to consume CPU cycles. |
| 2347 | */ |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 2348 | @VisibleForTesting |
| 2349 | public boolean mInList; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 2350 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2351 | public StopwatchTimer(Clocks clocks, Uid uid, int type, ArrayList<StopwatchTimer> timerPool, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2352 | TimeBase timeBase, Parcel in) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2353 | super(clocks, type, timeBase, in); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 2354 | mUid = uid; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2355 | mTimerPool = timerPool; |
| 2356 | mUpdateTime = in.readLong(); |
| 2357 | } |
| 2358 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2359 | public StopwatchTimer(Clocks clocks, Uid uid, int type, ArrayList<StopwatchTimer> timerPool, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2360 | TimeBase timeBase) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2361 | super(clocks, type, timeBase); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 2362 | mUid = uid; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2363 | mTimerPool = timerPool; |
| 2364 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2365 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2366 | public void setTimeout(long timeout) { |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 2367 | mTimeout = timeout; |
| 2368 | } |
| 2369 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2370 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
| 2371 | super.writeToParcel(out, elapsedRealtimeUs); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2372 | out.writeLong(mUpdateTime); |
| 2373 | } |
| 2374 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2375 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2376 | if (mNesting > 0) { |
| 2377 | if (DEBUG && mType < 0) { |
| 2378 | Log.v(TAG, "old mUpdateTime=" + mUpdateTime); |
| 2379 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2380 | super.onTimeStopped(elapsedRealtime, baseUptime, baseRealtime); |
| 2381 | mUpdateTime = baseRealtime; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2382 | if (DEBUG && mType < 0) { |
| 2383 | Log.v(TAG, "new mUpdateTime=" + mUpdateTime); |
| 2384 | } |
| 2385 | } |
| 2386 | } |
| 2387 | |
| 2388 | public void logState(Printer pw, String prefix) { |
| 2389 | super.logState(pw, prefix); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 2390 | pw.println(prefix + "mNesting=" + mNesting + " mUpdateTime=" + mUpdateTime |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2391 | + " mAcquireTime=" + mAcquireTime); |
| 2392 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2393 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2394 | public void startRunningLocked(long elapsedRealtimeMs) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2395 | if (mNesting++ == 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2396 | final long batteryRealtime = mTimeBase.getRealtime(elapsedRealtimeMs * 1000); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 2397 | mUpdateTime = batteryRealtime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2398 | if (mTimerPool != null) { |
| 2399 | // Accumulate time to all currently active timers before adding |
| 2400 | // this new one to the pool. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2401 | refreshTimersLocked(batteryRealtime, mTimerPool, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2402 | // Add this timer to the active pool |
| 2403 | mTimerPool.add(this); |
| 2404 | } |
Bookatz | ceebafe | 2017-04-06 11:59:13 -0700 | [diff] [blame] | 2405 | if (mTimeBase.isRunning()) { |
| 2406 | // Increment the count |
| 2407 | mCount++; |
| 2408 | mAcquireTime = mTotalTime; |
| 2409 | } else { |
| 2410 | mAcquireTime = -1; |
| 2411 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2412 | if (DEBUG && mType < 0) { |
| 2413 | Log.v(TAG, "start #" + mType + ": mUpdateTime=" + mUpdateTime |
| 2414 | + " mTotalTime=" + mTotalTime + " mCount=" + mCount |
| 2415 | + " mAcquireTime=" + mAcquireTime); |
| 2416 | } |
| 2417 | } |
| 2418 | } |
| 2419 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2420 | public boolean isRunningLocked() { |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 2421 | return mNesting > 0; |
| 2422 | } |
| 2423 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2424 | public void stopRunningLocked(long elapsedRealtimeMs) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2425 | // Ignore attempt to stop a timer that isn't running |
| 2426 | if (mNesting == 0) { |
| 2427 | return; |
| 2428 | } |
| 2429 | if (--mNesting == 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2430 | final long batteryRealtime = mTimeBase.getRealtime(elapsedRealtimeMs * 1000); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2431 | if (mTimerPool != null) { |
| 2432 | // Accumulate time to all active counters, scaled by the total |
| 2433 | // active in the pool, before taking this one out of the pool. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2434 | refreshTimersLocked(batteryRealtime, mTimerPool, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2435 | // Remove this timer from the active pool |
| 2436 | mTimerPool.remove(this); |
| 2437 | } else { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2438 | mNesting = 1; |
| 2439 | mTotalTime = computeRunTimeLocked(batteryRealtime); |
| 2440 | mNesting = 0; |
| 2441 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2442 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2443 | if (DEBUG && mType < 0) { |
| 2444 | Log.v(TAG, "stop #" + mType + ": mUpdateTime=" + mUpdateTime |
| 2445 | + " mTotalTime=" + mTotalTime + " mCount=" + mCount |
| 2446 | + " mAcquireTime=" + mAcquireTime); |
| 2447 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2448 | |
Bookatz | ceebafe | 2017-04-06 11:59:13 -0700 | [diff] [blame] | 2449 | if (mAcquireTime >= 0 && mTotalTime == mAcquireTime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2450 | // If there was no change in the time, then discard this |
| 2451 | // count. A somewhat cheezy strategy, but hey. |
| 2452 | mCount--; |
| 2453 | } |
| 2454 | } |
| 2455 | } |
| 2456 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2457 | public void stopAllRunningLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 2458 | if (mNesting > 0) { |
| 2459 | mNesting = 1; |
| 2460 | stopRunningLocked(elapsedRealtimeMs); |
| 2461 | } |
| 2462 | } |
| 2463 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2464 | // Update the total time for all other running Timers with the same type as this Timer |
| 2465 | // due to a change in timer count |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2466 | private static long refreshTimersLocked(long batteryRealtime, |
| 2467 | final ArrayList<StopwatchTimer> pool, StopwatchTimer self) { |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 2468 | long selfTime = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2469 | final int N = pool.size(); |
| 2470 | for (int i=N-1; i>= 0; i--) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2471 | final StopwatchTimer t = pool.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2472 | long heldTime = batteryRealtime - t.mUpdateTime; |
| 2473 | if (heldTime > 0) { |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 2474 | final long myTime = heldTime / N; |
| 2475 | if (t == self) { |
| 2476 | selfTime = myTime; |
| 2477 | } |
| 2478 | t.mTotalTime += myTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2479 | } |
| 2480 | t.mUpdateTime = batteryRealtime; |
| 2481 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 2482 | return selfTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2483 | } |
| 2484 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2485 | @Override |
| 2486 | protected long computeRunTimeLocked(long curBatteryRealtime) { |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 2487 | if (mTimeout > 0 && curBatteryRealtime > mUpdateTime + mTimeout) { |
| 2488 | curBatteryRealtime = mUpdateTime + mTimeout; |
| 2489 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2490 | return mTotalTime + (mNesting > 0 |
| 2491 | ? (curBatteryRealtime - mUpdateTime) |
| 2492 | / (mTimerPool != null ? mTimerPool.size() : 1) |
| 2493 | : 0); |
| 2494 | } |
| 2495 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2496 | @Override |
| 2497 | protected int computeCurrentCountLocked() { |
| 2498 | return mCount; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2499 | } |
| 2500 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 2501 | @Override |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2502 | public boolean reset(boolean detachIfReset) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2503 | boolean canDetach = mNesting <= 0; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2504 | super.reset(canDetach && detachIfReset); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2505 | if (mNesting > 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2506 | mUpdateTime = mTimeBase.getRealtime(mClocks.elapsedRealtime() * 1000); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2507 | } |
Bookatz | ceebafe | 2017-04-06 11:59:13 -0700 | [diff] [blame] | 2508 | 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] | 2509 | return canDetach; |
| 2510 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2511 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 2512 | @Override |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2513 | public void detach() { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2514 | super.detach(); |
| 2515 | if (mTimerPool != null) { |
| 2516 | mTimerPool.remove(this); |
| 2517 | } |
| 2518 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2519 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 2520 | @Override |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2521 | public void readSummaryFromParcelLocked(Parcel in) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2522 | super.readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2523 | mNesting = 0; |
| 2524 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 2525 | |
| 2526 | /** |
| 2527 | * Set the mark so that we can query later for the total time the timer has |
| 2528 | * accumulated since this point. The timer can be running or not. |
| 2529 | * |
| 2530 | * @param elapsedRealtimeMs the current elapsed realtime in milliseconds. |
| 2531 | */ |
| 2532 | public void setMark(long elapsedRealtimeMs) { |
| 2533 | final long batteryRealtime = mTimeBase.getRealtime(elapsedRealtimeMs * 1000); |
| 2534 | if (mNesting > 0) { |
| 2535 | // We are running. |
| 2536 | if (mTimerPool != null) { |
| 2537 | refreshTimersLocked(batteryRealtime, mTimerPool, this); |
| 2538 | } else { |
| 2539 | mTotalTime += batteryRealtime - mUpdateTime; |
| 2540 | mUpdateTime = batteryRealtime; |
| 2541 | } |
| 2542 | } |
| 2543 | mTimeBeforeMark = mTotalTime; |
| 2544 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2545 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2546 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2547 | /** |
| 2548 | * State for keeping track of two DurationTimers with different TimeBases, presumably where one |
| 2549 | * TimeBase is effectively a subset of the other. |
| 2550 | */ |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2551 | public static class DualTimer extends DurationTimer { |
| 2552 | // This class both is a DurationTimer and also holds a second DurationTimer. |
| 2553 | // The main timer (this) typically tracks the total time. It may be pooled (but since it's a |
| 2554 | // durationTimer, it also has the unpooled getTotalDurationMsLocked() for |
| 2555 | // STATS_SINCE_CHARGED). |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2556 | // mSubTimer typically tracks only part of the total time, such as background time, as |
| 2557 | // determined by a subTimeBase. It is NOT pooled. |
| 2558 | private final DurationTimer mSubTimer; |
| 2559 | |
| 2560 | /** |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2561 | * Creates a DualTimer to hold a main timer (this) and a mSubTimer. |
| 2562 | * The main timer (this) is based on the given timeBase and timerPool. |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2563 | * 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] | 2564 | * the main timer is. |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2565 | */ |
| 2566 | public DualTimer(Clocks clocks, Uid uid, int type, ArrayList<StopwatchTimer> timerPool, |
| 2567 | TimeBase timeBase, TimeBase subTimeBase, Parcel in) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2568 | super(clocks, uid, type, timerPool, timeBase, in); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2569 | mSubTimer = new DurationTimer(clocks, uid, type, null, subTimeBase, in); |
| 2570 | } |
| 2571 | |
| 2572 | /** |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2573 | * Creates a DualTimer to hold a main timer (this) and a mSubTimer. |
| 2574 | * The main timer (this) is based on the given timeBase and timerPool. |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2575 | * 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] | 2576 | * the main timer is. |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2577 | */ |
| 2578 | public DualTimer(Clocks clocks, Uid uid, int type, ArrayList<StopwatchTimer> timerPool, |
| 2579 | TimeBase timeBase, TimeBase subTimeBase) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2580 | super(clocks, uid, type, timerPool, timeBase); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2581 | mSubTimer = new DurationTimer(clocks, uid, type, null, subTimeBase); |
| 2582 | } |
| 2583 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2584 | /** Get the secondary timer. */ |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2585 | @Override |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2586 | public DurationTimer getSubTimer() { |
| 2587 | return mSubTimer; |
| 2588 | } |
| 2589 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2590 | @Override |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2591 | public void startRunningLocked(long elapsedRealtimeMs) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2592 | super.startRunningLocked(elapsedRealtimeMs); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2593 | mSubTimer.startRunningLocked(elapsedRealtimeMs); |
| 2594 | } |
| 2595 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2596 | @Override |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2597 | public void stopRunningLocked(long elapsedRealtimeMs) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2598 | super.stopRunningLocked(elapsedRealtimeMs); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2599 | mSubTimer.stopRunningLocked(elapsedRealtimeMs); |
| 2600 | } |
| 2601 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2602 | @Override |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2603 | public void stopAllRunningLocked(long elapsedRealtimeMs) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2604 | super.stopAllRunningLocked(elapsedRealtimeMs); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2605 | mSubTimer.stopAllRunningLocked(elapsedRealtimeMs); |
| 2606 | } |
| 2607 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2608 | @Override |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2609 | public boolean reset(boolean detachIfReset) { |
| 2610 | boolean active = false; |
Bookatz | 4a3eda9 | 2017-04-10 13:10:46 -0700 | [diff] [blame] | 2611 | // Do not detach the subTimer explicitly since that'll be done by DualTimer.detach(). |
| 2612 | active |= !mSubTimer.reset(false); |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2613 | active |= !super.reset(detachIfReset); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2614 | return !active; |
| 2615 | } |
| 2616 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2617 | @Override |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2618 | public void detach() { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2619 | mSubTimer.detach(); |
Bookatz | 4a3eda9 | 2017-04-10 13:10:46 -0700 | [diff] [blame] | 2620 | super.detach(); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2621 | } |
| 2622 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2623 | @Override |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2624 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2625 | super.writeToParcel(out, elapsedRealtimeUs); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2626 | mSubTimer.writeToParcel(out, elapsedRealtimeUs); |
| 2627 | } |
| 2628 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2629 | @Override |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2630 | public void writeSummaryFromParcelLocked(Parcel out, long elapsedRealtimeUs) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2631 | super.writeSummaryFromParcelLocked(out, elapsedRealtimeUs); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2632 | mSubTimer.writeSummaryFromParcelLocked(out, elapsedRealtimeUs); |
| 2633 | } |
| 2634 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2635 | @Override |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2636 | public void readSummaryFromParcelLocked(Parcel in) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2637 | super.readSummaryFromParcelLocked(in); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2638 | mSubTimer.readSummaryFromParcelLocked(in); |
| 2639 | } |
| 2640 | } |
| 2641 | |
| 2642 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2643 | public abstract class OverflowArrayMap<T> { |
| 2644 | private static final String OVERFLOW_NAME = "*overflow*"; |
| 2645 | |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame] | 2646 | final int mUid; |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2647 | final ArrayMap<String, T> mMap = new ArrayMap<>(); |
| 2648 | T mCurOverflow; |
| 2649 | ArrayMap<String, MutableInt> mActiveOverflow; |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame] | 2650 | long mLastOverflowTime; |
| 2651 | long mLastOverflowFinishTime; |
| 2652 | long mLastClearTime; |
| 2653 | long mLastCleanupTime; |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2654 | |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame] | 2655 | public OverflowArrayMap(int uid) { |
| 2656 | mUid = uid; |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2657 | } |
| 2658 | |
| 2659 | public ArrayMap<String, T> getMap() { |
| 2660 | return mMap; |
| 2661 | } |
| 2662 | |
| 2663 | public void clear() { |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame] | 2664 | mLastClearTime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2665 | mMap.clear(); |
| 2666 | mCurOverflow = null; |
| 2667 | mActiveOverflow = null; |
| 2668 | } |
| 2669 | |
| 2670 | public void add(String name, T obj) { |
Joe Onorato | 388fc33 | 2016-04-12 17:06:47 -0700 | [diff] [blame] | 2671 | if (name == null) { |
| 2672 | name = ""; |
| 2673 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2674 | mMap.put(name, obj); |
| 2675 | if (OVERFLOW_NAME.equals(name)) { |
| 2676 | mCurOverflow = obj; |
| 2677 | } |
| 2678 | } |
| 2679 | |
| 2680 | public void cleanup() { |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame] | 2681 | mLastCleanupTime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2682 | if (mActiveOverflow != null) { |
| 2683 | if (mActiveOverflow.size() == 0) { |
| 2684 | mActiveOverflow = null; |
| 2685 | } |
| 2686 | } |
| 2687 | if (mActiveOverflow == null) { |
| 2688 | // There is no currently active overflow, so we should no longer have |
| 2689 | // an overflow entry. |
| 2690 | if (mMap.containsKey(OVERFLOW_NAME)) { |
| 2691 | Slog.wtf(TAG, "Cleaning up with no active overflow, but have overflow entry " |
| 2692 | + mMap.get(OVERFLOW_NAME)); |
| 2693 | mMap.remove(OVERFLOW_NAME); |
| 2694 | } |
| 2695 | mCurOverflow = null; |
| 2696 | } else { |
| 2697 | // There is currently active overflow, so we should still have an overflow entry. |
| 2698 | if (mCurOverflow == null || !mMap.containsKey(OVERFLOW_NAME)) { |
| 2699 | Slog.wtf(TAG, "Cleaning up with active overflow, but no overflow entry: cur=" |
| 2700 | + mCurOverflow + " map=" + mMap.get(OVERFLOW_NAME)); |
| 2701 | } |
| 2702 | } |
| 2703 | } |
| 2704 | |
| 2705 | public T startObject(String name) { |
Joe Onorato | 388fc33 | 2016-04-12 17:06:47 -0700 | [diff] [blame] | 2706 | if (name == null) { |
| 2707 | name = ""; |
| 2708 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2709 | T obj = mMap.get(name); |
| 2710 | if (obj != null) { |
| 2711 | return obj; |
| 2712 | } |
| 2713 | |
| 2714 | // No object exists for the given name, but do we currently have it |
| 2715 | // running as part of the overflow? |
| 2716 | if (mActiveOverflow != null) { |
| 2717 | MutableInt over = mActiveOverflow.get(name); |
| 2718 | if (over != null) { |
| 2719 | // We are already actively counting this name in the overflow object. |
| 2720 | obj = mCurOverflow; |
| 2721 | if (obj == null) { |
| 2722 | // Shouldn't be here, but we'll try to recover. |
| 2723 | Slog.wtf(TAG, "Have active overflow " + name + " but null overflow"); |
| 2724 | obj = mCurOverflow = instantiateObject(); |
| 2725 | mMap.put(OVERFLOW_NAME, obj); |
| 2726 | } |
| 2727 | over.value++; |
| 2728 | return obj; |
| 2729 | } |
| 2730 | } |
| 2731 | |
| 2732 | // No object exists for given name nor in the overflow; we need to make |
| 2733 | // a new one. |
| 2734 | final int N = mMap.size(); |
| 2735 | if (N >= MAX_WAKELOCKS_PER_UID) { |
| 2736 | // Went over the limit on number of objects to track; this one goes |
| 2737 | // in to the overflow. |
| 2738 | obj = mCurOverflow; |
| 2739 | if (obj == null) { |
| 2740 | // Need to start overflow now... |
| 2741 | obj = mCurOverflow = instantiateObject(); |
| 2742 | mMap.put(OVERFLOW_NAME, obj); |
| 2743 | } |
| 2744 | if (mActiveOverflow == null) { |
| 2745 | mActiveOverflow = new ArrayMap<>(); |
| 2746 | } |
| 2747 | mActiveOverflow.put(name, new MutableInt(1)); |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame] | 2748 | mLastOverflowTime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2749 | return obj; |
| 2750 | } |
| 2751 | |
| 2752 | // Normal case where we just need to make a new object. |
| 2753 | obj = instantiateObject(); |
| 2754 | mMap.put(name, obj); |
| 2755 | return obj; |
| 2756 | } |
| 2757 | |
| 2758 | public T stopObject(String name) { |
Joe Onorato | 388fc33 | 2016-04-12 17:06:47 -0700 | [diff] [blame] | 2759 | if (name == null) { |
| 2760 | name = ""; |
| 2761 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2762 | T obj = mMap.get(name); |
| 2763 | if (obj != null) { |
| 2764 | return obj; |
| 2765 | } |
| 2766 | |
| 2767 | // No object exists for the given name, but do we currently have it |
| 2768 | // running as part of the overflow? |
| 2769 | if (mActiveOverflow != null) { |
| 2770 | MutableInt over = mActiveOverflow.get(name); |
| 2771 | if (over != null) { |
| 2772 | // We are already actively counting this name in the overflow object. |
| 2773 | obj = mCurOverflow; |
| 2774 | if (obj != null) { |
| 2775 | over.value--; |
| 2776 | if (over.value <= 0) { |
| 2777 | mActiveOverflow.remove(name); |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame] | 2778 | mLastOverflowFinishTime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2779 | } |
| 2780 | return obj; |
| 2781 | } |
| 2782 | } |
| 2783 | } |
| 2784 | |
| 2785 | // Huh, they are stopping an active operation but we can't find one! |
| 2786 | // That's not good. |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame] | 2787 | StringBuilder sb = new StringBuilder(); |
| 2788 | sb.append("Unable to find object for "); |
| 2789 | sb.append(name); |
| 2790 | sb.append(" in uid "); |
| 2791 | sb.append(mUid); |
| 2792 | sb.append(" mapsize="); |
| 2793 | sb.append(mMap.size()); |
| 2794 | sb.append(" activeoverflow="); |
| 2795 | sb.append(mActiveOverflow); |
| 2796 | sb.append(" curoverflow="); |
| 2797 | sb.append(mCurOverflow); |
| 2798 | long now = SystemClock.elapsedRealtime(); |
| 2799 | if (mLastOverflowTime != 0) { |
| 2800 | sb.append(" lastOverflowTime="); |
| 2801 | TimeUtils.formatDuration(mLastOverflowTime-now, sb); |
| 2802 | } |
| 2803 | if (mLastOverflowFinishTime != 0) { |
| 2804 | sb.append(" lastOverflowFinishTime="); |
| 2805 | TimeUtils.formatDuration(mLastOverflowFinishTime-now, sb); |
| 2806 | } |
| 2807 | if (mLastClearTime != 0) { |
| 2808 | sb.append(" lastClearTime="); |
| 2809 | TimeUtils.formatDuration(mLastClearTime-now, sb); |
| 2810 | } |
| 2811 | if (mLastCleanupTime != 0) { |
| 2812 | sb.append(" lastCleanupTime="); |
| 2813 | TimeUtils.formatDuration(mLastCleanupTime-now, sb); |
| 2814 | } |
| 2815 | Slog.wtf(TAG, sb.toString()); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2816 | return null; |
| 2817 | } |
| 2818 | |
| 2819 | public abstract T instantiateObject(); |
| 2820 | } |
| 2821 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2822 | public static class ControllerActivityCounterImpl extends ControllerActivityCounter |
| 2823 | implements Parcelable { |
| 2824 | private final LongSamplingCounter mIdleTimeMillis; |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 2825 | private final LongSamplingCounter mScanTimeMillis; |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2826 | private final LongSamplingCounter mRxTimeMillis; |
| 2827 | private final LongSamplingCounter[] mTxTimeMillis; |
| 2828 | private final LongSamplingCounter mPowerDrainMaMs; |
| 2829 | |
| 2830 | public ControllerActivityCounterImpl(TimeBase timeBase, int numTxStates) { |
| 2831 | mIdleTimeMillis = new LongSamplingCounter(timeBase); |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 2832 | mScanTimeMillis = new LongSamplingCounter(timeBase); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2833 | mRxTimeMillis = new LongSamplingCounter(timeBase); |
| 2834 | mTxTimeMillis = new LongSamplingCounter[numTxStates]; |
| 2835 | for (int i = 0; i < numTxStates; i++) { |
| 2836 | mTxTimeMillis[i] = new LongSamplingCounter(timeBase); |
| 2837 | } |
| 2838 | mPowerDrainMaMs = new LongSamplingCounter(timeBase); |
| 2839 | } |
| 2840 | |
| 2841 | public ControllerActivityCounterImpl(TimeBase timeBase, int numTxStates, Parcel in) { |
| 2842 | mIdleTimeMillis = new LongSamplingCounter(timeBase, in); |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 2843 | mScanTimeMillis = new LongSamplingCounter(timeBase, in); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2844 | mRxTimeMillis = new LongSamplingCounter(timeBase, in); |
| 2845 | final int recordedTxStates = in.readInt(); |
| 2846 | if (recordedTxStates != numTxStates) { |
| 2847 | throw new ParcelFormatException("inconsistent tx state lengths"); |
| 2848 | } |
| 2849 | |
| 2850 | mTxTimeMillis = new LongSamplingCounter[numTxStates]; |
| 2851 | for (int i = 0; i < numTxStates; i++) { |
| 2852 | mTxTimeMillis[i] = new LongSamplingCounter(timeBase, in); |
| 2853 | } |
| 2854 | mPowerDrainMaMs = new LongSamplingCounter(timeBase, in); |
| 2855 | } |
| 2856 | |
| 2857 | public void readSummaryFromParcel(Parcel in) { |
| 2858 | mIdleTimeMillis.readSummaryFromParcelLocked(in); |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 2859 | mScanTimeMillis.readSummaryFromParcelLocked(in); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2860 | mRxTimeMillis.readSummaryFromParcelLocked(in); |
| 2861 | final int recordedTxStates = in.readInt(); |
| 2862 | if (recordedTxStates != mTxTimeMillis.length) { |
| 2863 | throw new ParcelFormatException("inconsistent tx state lengths"); |
| 2864 | } |
| 2865 | for (LongSamplingCounter counter : mTxTimeMillis) { |
| 2866 | counter.readSummaryFromParcelLocked(in); |
| 2867 | } |
| 2868 | mPowerDrainMaMs.readSummaryFromParcelLocked(in); |
| 2869 | } |
| 2870 | |
| 2871 | @Override |
| 2872 | public int describeContents() { |
| 2873 | return 0; |
| 2874 | } |
| 2875 | |
| 2876 | public void writeSummaryToParcel(Parcel dest) { |
| 2877 | mIdleTimeMillis.writeSummaryFromParcelLocked(dest); |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 2878 | mScanTimeMillis.writeSummaryFromParcelLocked(dest); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2879 | mRxTimeMillis.writeSummaryFromParcelLocked(dest); |
| 2880 | dest.writeInt(mTxTimeMillis.length); |
| 2881 | for (LongSamplingCounter counter : mTxTimeMillis) { |
| 2882 | counter.writeSummaryFromParcelLocked(dest); |
| 2883 | } |
| 2884 | mPowerDrainMaMs.writeSummaryFromParcelLocked(dest); |
| 2885 | } |
| 2886 | |
| 2887 | @Override |
| 2888 | public void writeToParcel(Parcel dest, int flags) { |
| 2889 | mIdleTimeMillis.writeToParcel(dest); |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 2890 | mScanTimeMillis.writeToParcel(dest); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2891 | mRxTimeMillis.writeToParcel(dest); |
| 2892 | dest.writeInt(mTxTimeMillis.length); |
| 2893 | for (LongSamplingCounter counter : mTxTimeMillis) { |
| 2894 | counter.writeToParcel(dest); |
| 2895 | } |
| 2896 | mPowerDrainMaMs.writeToParcel(dest); |
| 2897 | } |
| 2898 | |
| 2899 | public void reset(boolean detachIfReset) { |
| 2900 | mIdleTimeMillis.reset(detachIfReset); |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 2901 | mScanTimeMillis.reset(detachIfReset); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2902 | mRxTimeMillis.reset(detachIfReset); |
| 2903 | for (LongSamplingCounter counter : mTxTimeMillis) { |
| 2904 | counter.reset(detachIfReset); |
| 2905 | } |
| 2906 | mPowerDrainMaMs.reset(detachIfReset); |
| 2907 | } |
| 2908 | |
| 2909 | public void detach() { |
| 2910 | mIdleTimeMillis.detach(); |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 2911 | mScanTimeMillis.detach(); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2912 | mRxTimeMillis.detach(); |
| 2913 | for (LongSamplingCounter counter : mTxTimeMillis) { |
| 2914 | counter.detach(); |
| 2915 | } |
| 2916 | mPowerDrainMaMs.detach(); |
| 2917 | } |
| 2918 | |
| 2919 | /** |
| 2920 | * @return a LongSamplingCounter, measuring time spent in the idle state in |
| 2921 | * milliseconds. |
| 2922 | */ |
| 2923 | @Override |
| 2924 | public LongSamplingCounter getIdleTimeCounter() { |
Roshan Pius | 8164330 | 2016-03-14 16:45:55 -0700 | [diff] [blame] | 2925 | return mIdleTimeMillis; |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2926 | } |
| 2927 | |
| 2928 | /** |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 2929 | * @return a LongSamplingCounter, measuring time spent in the scan state in |
| 2930 | * milliseconds. |
| 2931 | */ |
| 2932 | @Override |
| 2933 | public LongSamplingCounter getScanTimeCounter() { |
| 2934 | return mScanTimeMillis; |
| 2935 | } |
| 2936 | |
| 2937 | /** |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2938 | * @return a LongSamplingCounter, measuring time spent in the receive state in |
| 2939 | * milliseconds. |
| 2940 | */ |
| 2941 | @Override |
| 2942 | public LongSamplingCounter getRxTimeCounter() { |
| 2943 | return mRxTimeMillis; |
| 2944 | } |
| 2945 | |
| 2946 | /** |
| 2947 | * @return a LongSamplingCounter[], measuring time spent in various transmit states in |
| 2948 | * milliseconds. |
| 2949 | */ |
| 2950 | @Override |
| 2951 | public LongSamplingCounter[] getTxTimeCounters() { |
| 2952 | return mTxTimeMillis; |
| 2953 | } |
| 2954 | |
| 2955 | /** |
| 2956 | * @return a LongSamplingCounter, measuring power use in milli-ampere milliseconds (mAmS). |
| 2957 | */ |
| 2958 | @Override |
| 2959 | public LongSamplingCounter getPowerCounter() { |
| 2960 | return mPowerDrainMaMs; |
| 2961 | } |
| 2962 | } |
| 2963 | |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 2964 | /** Get Resource Power Manager stats. Create a new one if it doesn't already exist. */ |
| 2965 | public SamplingTimer getRpmTimerLocked(String name) { |
| 2966 | SamplingTimer rpmt = mRpmStats.get(name); |
| 2967 | if (rpmt == null) { |
| 2968 | rpmt = new SamplingTimer(mClocks, mOnBatteryTimeBase); |
| 2969 | mRpmStats.put(name, rpmt); |
| 2970 | } |
| 2971 | return rpmt; |
| 2972 | } |
| 2973 | |
| 2974 | /** Get Screen-off Resource Power Manager stats. Create new one if it doesn't already exist. */ |
| 2975 | public SamplingTimer getScreenOffRpmTimerLocked(String name) { |
| 2976 | SamplingTimer rpmt = mScreenOffRpmStats.get(name); |
| 2977 | if (rpmt == null) { |
| 2978 | rpmt = new SamplingTimer(mClocks, mOnBatteryScreenOffTimeBase); |
| 2979 | mScreenOffRpmStats.put(name, rpmt); |
| 2980 | } |
| 2981 | return rpmt; |
| 2982 | } |
| 2983 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2984 | /* |
| 2985 | * Get the wakeup reason counter, and create a new one if one |
| 2986 | * doesn't already exist. |
| 2987 | */ |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 2988 | public SamplingTimer getWakeupReasonTimerLocked(String name) { |
| 2989 | SamplingTimer timer = mWakeupReasonStats.get(name); |
| 2990 | if (timer == null) { |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 2991 | timer = new SamplingTimer(mClocks, mOnBatteryTimeBase); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 2992 | mWakeupReasonStats.put(name, timer); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2993 | } |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 2994 | return timer; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2995 | } |
| 2996 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2997 | /* |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2998 | * 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] | 2999 | * doesn't already exist. |
| 3000 | */ |
| 3001 | public SamplingTimer getKernelWakelockTimerLocked(String name) { |
| 3002 | SamplingTimer kwlt = mKernelWakelockStats.get(name); |
| 3003 | if (kwlt == null) { |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 3004 | kwlt = new SamplingTimer(mClocks, mOnBatteryScreenOffTimeBase); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 3005 | mKernelWakelockStats.put(name, kwlt); |
| 3006 | } |
| 3007 | return kwlt; |
| 3008 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 3009 | |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 3010 | public SamplingTimer getKernelMemoryTimerLocked(long bucket) { |
| 3011 | SamplingTimer kmt = mKernelMemoryStats.get(bucket); |
| 3012 | if (kmt == null) { |
| 3013 | kmt = new SamplingTimer(mClocks, mOnBatteryTimeBase); |
| 3014 | mKernelMemoryStats.put(bucket, kmt); |
| 3015 | } |
| 3016 | return kmt; |
| 3017 | } |
| 3018 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3019 | private int writeHistoryTag(HistoryTag tag) { |
| 3020 | Integer idxObj = mHistoryTagPool.get(tag); |
| 3021 | int idx; |
| 3022 | if (idxObj != null) { |
| 3023 | idx = idxObj; |
| 3024 | } else { |
| 3025 | idx = mNextHistoryTagIdx; |
| 3026 | HistoryTag key = new HistoryTag(); |
| 3027 | key.setTo(tag); |
| 3028 | tag.poolIdx = idx; |
| 3029 | mHistoryTagPool.put(key, idx); |
| 3030 | mNextHistoryTagIdx++; |
| 3031 | mNumHistoryTagChars += key.string.length() + 1; |
| 3032 | } |
| 3033 | return idx; |
| 3034 | } |
| 3035 | |
| 3036 | private void readHistoryTag(int index, HistoryTag tag) { |
| 3037 | tag.string = mReadHistoryStrings[index]; |
| 3038 | tag.uid = mReadHistoryUids[index]; |
| 3039 | tag.poolIdx = index; |
| 3040 | } |
| 3041 | |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 3042 | /* |
| 3043 | The history delta format uses flags to denote further data in subsequent ints in the parcel. |
| 3044 | |
| 3045 | There is always the first token, which may contain the delta time, or an indicator of |
| 3046 | the length of the time (int or long) following this token. |
| 3047 | |
| 3048 | First token: always present, |
| 3049 | 31 23 15 7 0 |
| 3050 | â–ˆ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â–ˆ |
| 3051 | |
| 3052 | T: the delta time if it is <= 0x7fffd. Otherwise 0x7fffe indicates an int immediately |
| 3053 | follows containing the time, and 0x7ffff indicates a long immediately follows with the |
| 3054 | delta time. |
| 3055 | A: battery level changed and an int follows with battery data. |
| 3056 | B: state changed and an int follows with state change data. |
| 3057 | C: state2 has changed and an int follows with state2 change data. |
| 3058 | D: wakelock/wakereason has changed and an wakelock/wakereason struct follows. |
| 3059 | E: event data has changed and an event struct follows. |
| 3060 | F: battery charge in coulombs has changed and an int with the charge follows. |
| 3061 | G: state flag denoting that the mobile radio was active. |
| 3062 | H: state flag denoting that the wifi radio was active. |
| 3063 | I: state flag denoting that a wifi scan occurred. |
| 3064 | J: state flag denoting that a wifi full lock was held. |
| 3065 | K: state flag denoting that the gps was on. |
| 3066 | L: state flag denoting that a wakelock was held. |
| 3067 | M: state flag denoting that the cpu was running. |
| 3068 | |
| 3069 | Time int/long: if T in the first token is 0x7ffff or 0x7fffe, then an int or long follows |
| 3070 | with the time delta. |
| 3071 | |
| 3072 | Battery level int: if A in the first token is set, |
| 3073 | 31 23 15 7 0 |
| 3074 | â–ˆ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â–ˆ |
| 3075 | |
| 3076 | D: indicates that extra history details follow. |
| 3077 | V: the battery voltage. |
| 3078 | T: the battery temperature. |
| 3079 | L: the battery level (out of 100). |
| 3080 | |
| 3081 | State change int: if B in the first token is set, |
| 3082 | 31 23 15 7 0 |
| 3083 | â–ˆS|S|S|H|H|H|P|Pâ–ˆF|E|D|C|B| | |Aâ–ˆ | | | | | | | â–ˆ | | | | | | | â–ˆ |
| 3084 | |
| 3085 | A: wifi multicast was on. |
| 3086 | B: battery was plugged in. |
| 3087 | C: screen was on. |
| 3088 | D: phone was scanning for signal. |
| 3089 | E: audio was on. |
| 3090 | F: a sensor was active. |
| 3091 | |
| 3092 | State2 change int: if C in the first token is set, |
| 3093 | 31 23 15 7 0 |
| 3094 | â–ˆM|L|K|J|I|H|H|Gâ–ˆF|E|D|C| | | | â–ˆ | | | | | | | â–ˆ |B|B|B|A|A|A|Aâ–ˆ |
| 3095 | |
| 3096 | A: 4 bits indicating the wifi supplicant state: {@link BatteryStats#WIFI_SUPPL_STATE_NAMES}. |
| 3097 | B: 3 bits indicating the wifi signal strength: 0, 1, 2, 3, 4. |
| 3098 | C: a bluetooth scan was active. |
| 3099 | D: the camera was active. |
| 3100 | E: bluetooth was on. |
| 3101 | F: a phone call was active. |
| 3102 | G: the device was charging. |
| 3103 | H: 2 bits indicating the device-idle (doze) state: off, light, full |
| 3104 | I: the flashlight was on. |
| 3105 | J: wifi was on. |
| 3106 | K: wifi was running. |
| 3107 | L: video was playing. |
| 3108 | M: power save mode was on. |
| 3109 | |
| 3110 | Wakelock/wakereason struct: if D in the first token is set, |
| 3111 | TODO(adamlesinski): describe wakelock/wakereason struct. |
| 3112 | |
| 3113 | Event struct: if E in the first token is set, |
| 3114 | TODO(adamlesinski): describe the event struct. |
| 3115 | |
| 3116 | History step details struct: if D in the battery level int is set, |
| 3117 | TODO(adamlesinski): describe the history step details struct. |
| 3118 | |
| 3119 | Battery charge int: if F in the first token is set, an int representing the battery charge |
| 3120 | in coulombs follows. |
| 3121 | */ |
| 3122 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3123 | // Part of initial delta int that specifies the time delta. |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 3124 | static final int DELTA_TIME_MASK = 0x7ffff; |
| 3125 | static final int DELTA_TIME_LONG = 0x7ffff; // The delta is a following long |
| 3126 | static final int DELTA_TIME_INT = 0x7fffe; // The delta is a following int |
| 3127 | 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] | 3128 | // Flag in delta int: a new battery level int follows. |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 3129 | static final int DELTA_BATTERY_LEVEL_FLAG = 0x00080000; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3130 | // 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] | 3131 | static final int DELTA_STATE_FLAG = 0x00100000; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 3132 | // Flag in delta int: a new full state2 int follows. |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 3133 | static final int DELTA_STATE2_FLAG = 0x00200000; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3134 | // Flag in delta int: contains a wakelock or wakeReason tag. |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 3135 | static final int DELTA_WAKELOCK_FLAG = 0x00400000; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3136 | // Flag in delta int: contains an event description. |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 3137 | static final int DELTA_EVENT_FLAG = 0x00800000; |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 3138 | // Flag in delta int: contains the battery charge count in uAh. |
| 3139 | static final int DELTA_BATTERY_CHARGE_FLAG = 0x01000000; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3140 | // These upper bits are the frequently changing state bits. |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 3141 | static final int DELTA_STATE_MASK = 0xfe000000; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 3142 | |
| 3143 | // These are the pieces of battery state that are packed in to the upper bits of |
| 3144 | // 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] | 3145 | // in STATE_BATTERY_MASK. |
| 3146 | static final int STATE_BATTERY_MASK = 0xff000000; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 3147 | static final int STATE_BATTERY_STATUS_MASK = 0x00000007; |
| 3148 | static final int STATE_BATTERY_STATUS_SHIFT = 29; |
| 3149 | static final int STATE_BATTERY_HEALTH_MASK = 0x00000007; |
| 3150 | static final int STATE_BATTERY_HEALTH_SHIFT = 26; |
| 3151 | static final int STATE_BATTERY_PLUG_MASK = 0x00000003; |
| 3152 | static final int STATE_BATTERY_PLUG_SHIFT = 24; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3153 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 3154 | // We use the low bit of the battery state int to indicate that we have full details |
| 3155 | // from a battery level change. |
| 3156 | static final int BATTERY_DELTA_LEVEL_FLAG = 0x00000001; |
| 3157 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3158 | public void writeHistoryDelta(Parcel dest, HistoryItem cur, HistoryItem last) { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3159 | if (last == null || cur.cmd != HistoryItem.CMD_UPDATE) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3160 | dest.writeInt(DELTA_TIME_ABS); |
| 3161 | cur.writeToParcel(dest, 0); |
| 3162 | return; |
| 3163 | } |
| 3164 | |
| 3165 | final long deltaTime = cur.time - last.time; |
| 3166 | final int lastBatteryLevelInt = buildBatteryLevelInt(last); |
| 3167 | final int lastStateInt = buildStateInt(last); |
| 3168 | |
| 3169 | int deltaTimeToken; |
| 3170 | if (deltaTime < 0 || deltaTime > Integer.MAX_VALUE) { |
| 3171 | deltaTimeToken = DELTA_TIME_LONG; |
| 3172 | } else if (deltaTime >= DELTA_TIME_ABS) { |
| 3173 | deltaTimeToken = DELTA_TIME_INT; |
| 3174 | } else { |
| 3175 | deltaTimeToken = (int)deltaTime; |
| 3176 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3177 | int firstToken = deltaTimeToken | (cur.states&DELTA_STATE_MASK); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 3178 | final int includeStepDetails = mLastHistoryStepLevel > cur.batteryLevel |
| 3179 | ? BATTERY_DELTA_LEVEL_FLAG : 0; |
| 3180 | final boolean computeStepDetails = includeStepDetails != 0 |
| 3181 | || mLastHistoryStepDetails == null; |
| 3182 | final int batteryLevelInt = buildBatteryLevelInt(cur) | includeStepDetails; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3183 | final boolean batteryLevelIntChanged = batteryLevelInt != lastBatteryLevelInt; |
| 3184 | if (batteryLevelIntChanged) { |
| 3185 | firstToken |= DELTA_BATTERY_LEVEL_FLAG; |
| 3186 | } |
| 3187 | final int stateInt = buildStateInt(cur); |
| 3188 | final boolean stateIntChanged = stateInt != lastStateInt; |
| 3189 | if (stateIntChanged) { |
| 3190 | firstToken |= DELTA_STATE_FLAG; |
| 3191 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3192 | final boolean state2IntChanged = cur.states2 != last.states2; |
| 3193 | if (state2IntChanged) { |
| 3194 | firstToken |= DELTA_STATE2_FLAG; |
| 3195 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3196 | if (cur.wakelockTag != null || cur.wakeReasonTag != null) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3197 | firstToken |= DELTA_WAKELOCK_FLAG; |
| 3198 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3199 | if (cur.eventCode != HistoryItem.EVENT_NONE) { |
| 3200 | firstToken |= DELTA_EVENT_FLAG; |
| 3201 | } |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 3202 | |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 3203 | final boolean batteryChargeChanged = cur.batteryChargeUAh != last.batteryChargeUAh; |
| 3204 | if (batteryChargeChanged) { |
| 3205 | firstToken |= DELTA_BATTERY_CHARGE_FLAG; |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 3206 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3207 | dest.writeInt(firstToken); |
| 3208 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: firstToken=0x" + Integer.toHexString(firstToken) |
| 3209 | + " deltaTime=" + deltaTime); |
| 3210 | |
| 3211 | if (deltaTimeToken >= DELTA_TIME_INT) { |
| 3212 | if (deltaTimeToken == DELTA_TIME_INT) { |
| 3213 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: int deltaTime=" + (int)deltaTime); |
| 3214 | dest.writeInt((int)deltaTime); |
| 3215 | } else { |
| 3216 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: long deltaTime=" + deltaTime); |
| 3217 | dest.writeLong(deltaTime); |
| 3218 | } |
| 3219 | } |
| 3220 | if (batteryLevelIntChanged) { |
| 3221 | dest.writeInt(batteryLevelInt); |
| 3222 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: batteryToken=0x" |
| 3223 | + Integer.toHexString(batteryLevelInt) |
| 3224 | + " batteryLevel=" + cur.batteryLevel |
| 3225 | + " batteryTemp=" + cur.batteryTemperature |
| 3226 | + " batteryVolt=" + (int)cur.batteryVoltage); |
| 3227 | } |
| 3228 | if (stateIntChanged) { |
| 3229 | dest.writeInt(stateInt); |
| 3230 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: stateToken=0x" |
| 3231 | + Integer.toHexString(stateInt) |
| 3232 | + " batteryStatus=" + cur.batteryStatus |
| 3233 | + " batteryHealth=" + cur.batteryHealth |
| 3234 | + " batteryPlugType=" + cur.batteryPlugType |
| 3235 | + " states=0x" + Integer.toHexString(cur.states)); |
| 3236 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3237 | if (state2IntChanged) { |
| 3238 | dest.writeInt(cur.states2); |
| 3239 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: states2=0x" |
| 3240 | + Integer.toHexString(cur.states2)); |
| 3241 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3242 | if (cur.wakelockTag != null || cur.wakeReasonTag != null) { |
| 3243 | int wakeLockIndex; |
| 3244 | int wakeReasonIndex; |
| 3245 | if (cur.wakelockTag != null) { |
| 3246 | wakeLockIndex = writeHistoryTag(cur.wakelockTag); |
| 3247 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: wakelockTag=#" + cur.wakelockTag.poolIdx |
| 3248 | + " " + cur.wakelockTag.uid + ":" + cur.wakelockTag.string); |
| 3249 | } else { |
| 3250 | wakeLockIndex = 0xffff; |
| 3251 | } |
| 3252 | if (cur.wakeReasonTag != null) { |
| 3253 | wakeReasonIndex = writeHistoryTag(cur.wakeReasonTag); |
| 3254 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: wakeReasonTag=#" + cur.wakeReasonTag.poolIdx |
| 3255 | + " " + cur.wakeReasonTag.uid + ":" + cur.wakeReasonTag.string); |
| 3256 | } else { |
| 3257 | wakeReasonIndex = 0xffff; |
| 3258 | } |
| 3259 | dest.writeInt((wakeReasonIndex<<16) | wakeLockIndex); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3260 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3261 | if (cur.eventCode != HistoryItem.EVENT_NONE) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3262 | int index = writeHistoryTag(cur.eventTag); |
| 3263 | int codeAndIndex = (cur.eventCode&0xffff) | (index<<16); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3264 | dest.writeInt(codeAndIndex); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3265 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: event=" + cur.eventCode + " tag=#" |
| 3266 | + cur.eventTag.poolIdx + " " + cur.eventTag.uid + ":" |
| 3267 | + cur.eventTag.string); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3268 | } |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 3269 | if (computeStepDetails) { |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 3270 | if (mPlatformIdleStateCallback != null) { |
| 3271 | mCurHistoryStepDetails.statPlatformIdleState = |
| 3272 | mPlatformIdleStateCallback.getPlatformLowPowerStats(); |
| 3273 | if (DEBUG) Slog.i(TAG, "WRITE PlatformIdleState:" + |
| 3274 | mCurHistoryStepDetails.statPlatformIdleState); |
Ahmed ElArabawy | d8b4411 | 2017-05-23 21:25:02 +0000 | [diff] [blame] | 3275 | |
| 3276 | mCurHistoryStepDetails.statSubsystemPowerState = |
| 3277 | mPlatformIdleStateCallback.getSubsystemLowPowerStats(); |
| 3278 | if (DEBUG) Slog.i(TAG, "WRITE SubsystemPowerState:" + |
| 3279 | mCurHistoryStepDetails.statSubsystemPowerState); |
| 3280 | |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 3281 | } |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 3282 | computeHistoryStepDetails(mCurHistoryStepDetails, mLastHistoryStepDetails); |
| 3283 | if (includeStepDetails != 0) { |
| 3284 | mCurHistoryStepDetails.writeToParcel(dest); |
| 3285 | } |
| 3286 | cur.stepDetails = mCurHistoryStepDetails; |
| 3287 | mLastHistoryStepDetails = mCurHistoryStepDetails; |
| 3288 | } else { |
| 3289 | cur.stepDetails = null; |
| 3290 | } |
| 3291 | if (mLastHistoryStepLevel < cur.batteryLevel) { |
| 3292 | mLastHistoryStepDetails = null; |
| 3293 | } |
| 3294 | mLastHistoryStepLevel = cur.batteryLevel; |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 3295 | |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 3296 | if (batteryChargeChanged) { |
| 3297 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: batteryChargeUAh=" + cur.batteryChargeUAh); |
| 3298 | dest.writeInt(cur.batteryChargeUAh); |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 3299 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3300 | } |
| 3301 | |
| 3302 | private int buildBatteryLevelInt(HistoryItem h) { |
| 3303 | return ((((int)h.batteryLevel)<<25)&0xfe000000) |
Adam Lesinski | 3944c81 | 2015-11-13 15:54:59 -0800 | [diff] [blame] | 3304 | | ((((int)h.batteryTemperature)<<15)&0x01ff8000) |
| 3305 | | ((((int)h.batteryVoltage)<<1)&0x00007ffe); |
| 3306 | } |
| 3307 | |
| 3308 | private void readBatteryLevelInt(int batteryLevelInt, HistoryItem out) { |
| 3309 | out.batteryLevel = (byte)((batteryLevelInt & 0xfe000000) >>> 25); |
| 3310 | out.batteryTemperature = (short)((batteryLevelInt & 0x01ff8000) >>> 15); |
| 3311 | out.batteryVoltage = (char)((batteryLevelInt & 0x00007ffe) >>> 1); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3312 | } |
| 3313 | |
| 3314 | private int buildStateInt(HistoryItem h) { |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 3315 | int plugType = 0; |
| 3316 | if ((h.batteryPlugType&BatteryManager.BATTERY_PLUGGED_AC) != 0) { |
| 3317 | plugType = 1; |
| 3318 | } else if ((h.batteryPlugType&BatteryManager.BATTERY_PLUGGED_USB) != 0) { |
| 3319 | plugType = 2; |
| 3320 | } else if ((h.batteryPlugType&BatteryManager.BATTERY_PLUGGED_WIRELESS) != 0) { |
| 3321 | plugType = 3; |
| 3322 | } |
| 3323 | return ((h.batteryStatus&STATE_BATTERY_STATUS_MASK)<<STATE_BATTERY_STATUS_SHIFT) |
| 3324 | | ((h.batteryHealth&STATE_BATTERY_HEALTH_MASK)<<STATE_BATTERY_HEALTH_SHIFT) |
| 3325 | | ((plugType&STATE_BATTERY_PLUG_MASK)<<STATE_BATTERY_PLUG_SHIFT) |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 3326 | | (h.states&(~STATE_BATTERY_MASK)); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3327 | } |
| 3328 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 3329 | private void computeHistoryStepDetails(final HistoryStepDetails out, |
| 3330 | final HistoryStepDetails last) { |
| 3331 | final HistoryStepDetails tmp = last != null ? mTmpHistoryStepDetails : out; |
| 3332 | |
| 3333 | // Perform a CPU update right after we do this collection, so we have started |
| 3334 | // collecting good data for the next step. |
| 3335 | requestImmediateCpuUpdate(); |
| 3336 | |
| 3337 | if (last == null) { |
| 3338 | // We are not generating a delta, so all we need to do is reset the stats |
| 3339 | // we will later be doing a delta from. |
| 3340 | final int NU = mUidStats.size(); |
| 3341 | for (int i=0; i<NU; i++) { |
| 3342 | final BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 3343 | uid.mLastStepUserTime = uid.mCurStepUserTime; |
| 3344 | uid.mLastStepSystemTime = uid.mCurStepSystemTime; |
| 3345 | } |
| 3346 | mLastStepCpuUserTime = mCurStepCpuUserTime; |
| 3347 | mLastStepCpuSystemTime = mCurStepCpuSystemTime; |
| 3348 | mLastStepStatUserTime = mCurStepStatUserTime; |
| 3349 | mLastStepStatSystemTime = mCurStepStatSystemTime; |
| 3350 | mLastStepStatIOWaitTime = mCurStepStatIOWaitTime; |
| 3351 | mLastStepStatIrqTime = mCurStepStatIrqTime; |
| 3352 | mLastStepStatSoftIrqTime = mCurStepStatSoftIrqTime; |
| 3353 | mLastStepStatIdleTime = mCurStepStatIdleTime; |
| 3354 | tmp.clear(); |
| 3355 | return; |
| 3356 | } |
| 3357 | if (DEBUG) { |
| 3358 | Slog.d(TAG, "Step stats last: user=" + mLastStepCpuUserTime + " sys=" |
| 3359 | + mLastStepStatSystemTime + " io=" + mLastStepStatIOWaitTime |
| 3360 | + " irq=" + mLastStepStatIrqTime + " sirq=" |
| 3361 | + mLastStepStatSoftIrqTime + " idle=" + mLastStepStatIdleTime); |
| 3362 | Slog.d(TAG, "Step stats cur: user=" + mCurStepCpuUserTime + " sys=" |
| 3363 | + mCurStepStatSystemTime + " io=" + mCurStepStatIOWaitTime |
| 3364 | + " irq=" + mCurStepStatIrqTime + " sirq=" |
| 3365 | + mCurStepStatSoftIrqTime + " idle=" + mCurStepStatIdleTime); |
| 3366 | } |
| 3367 | out.userTime = (int)(mCurStepCpuUserTime - mLastStepCpuUserTime); |
| 3368 | out.systemTime = (int)(mCurStepCpuSystemTime - mLastStepCpuSystemTime); |
| 3369 | out.statUserTime = (int)(mCurStepStatUserTime - mLastStepStatUserTime); |
| 3370 | out.statSystemTime = (int)(mCurStepStatSystemTime - mLastStepStatSystemTime); |
| 3371 | out.statIOWaitTime = (int)(mCurStepStatIOWaitTime - mLastStepStatIOWaitTime); |
| 3372 | out.statIrqTime = (int)(mCurStepStatIrqTime - mLastStepStatIrqTime); |
| 3373 | out.statSoftIrqTime = (int)(mCurStepStatSoftIrqTime - mLastStepStatSoftIrqTime); |
| 3374 | out.statIdlTime = (int)(mCurStepStatIdleTime - mLastStepStatIdleTime); |
| 3375 | out.appCpuUid1 = out.appCpuUid2 = out.appCpuUid3 = -1; |
| 3376 | out.appCpuUTime1 = out.appCpuUTime2 = out.appCpuUTime3 = 0; |
| 3377 | out.appCpuSTime1 = out.appCpuSTime2 = out.appCpuSTime3 = 0; |
| 3378 | final int NU = mUidStats.size(); |
| 3379 | for (int i=0; i<NU; i++) { |
| 3380 | final BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 3381 | final int totalUTime = (int)(uid.mCurStepUserTime - uid.mLastStepUserTime); |
| 3382 | final int totalSTime = (int)(uid.mCurStepSystemTime - uid.mLastStepSystemTime); |
| 3383 | final int totalTime = totalUTime + totalSTime; |
| 3384 | uid.mLastStepUserTime = uid.mCurStepUserTime; |
| 3385 | uid.mLastStepSystemTime = uid.mCurStepSystemTime; |
| 3386 | if (totalTime <= (out.appCpuUTime3+out.appCpuSTime3)) { |
| 3387 | continue; |
| 3388 | } |
| 3389 | if (totalTime <= (out.appCpuUTime2+out.appCpuSTime2)) { |
| 3390 | out.appCpuUid3 = uid.mUid; |
| 3391 | out.appCpuUTime3 = totalUTime; |
| 3392 | out.appCpuSTime3 = totalSTime; |
| 3393 | } else { |
| 3394 | out.appCpuUid3 = out.appCpuUid2; |
| 3395 | out.appCpuUTime3 = out.appCpuUTime2; |
| 3396 | out.appCpuSTime3 = out.appCpuSTime2; |
| 3397 | if (totalTime <= (out.appCpuUTime1+out.appCpuSTime1)) { |
| 3398 | out.appCpuUid2 = uid.mUid; |
| 3399 | out.appCpuUTime2 = totalUTime; |
| 3400 | out.appCpuSTime2 = totalSTime; |
| 3401 | } else { |
| 3402 | out.appCpuUid2 = out.appCpuUid1; |
| 3403 | out.appCpuUTime2 = out.appCpuUTime1; |
| 3404 | out.appCpuSTime2 = out.appCpuSTime1; |
| 3405 | out.appCpuUid1 = uid.mUid; |
| 3406 | out.appCpuUTime1 = totalUTime; |
| 3407 | out.appCpuSTime1 = totalSTime; |
| 3408 | } |
| 3409 | } |
| 3410 | } |
| 3411 | mLastStepCpuUserTime = mCurStepCpuUserTime; |
| 3412 | mLastStepCpuSystemTime = mCurStepCpuSystemTime; |
| 3413 | mLastStepStatUserTime = mCurStepStatUserTime; |
| 3414 | mLastStepStatSystemTime = mCurStepStatSystemTime; |
| 3415 | mLastStepStatIOWaitTime = mCurStepStatIOWaitTime; |
| 3416 | mLastStepStatIrqTime = mCurStepStatIrqTime; |
| 3417 | mLastStepStatSoftIrqTime = mCurStepStatSoftIrqTime; |
| 3418 | mLastStepStatIdleTime = mCurStepStatIdleTime; |
| 3419 | } |
| 3420 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3421 | public void readHistoryDelta(Parcel src, HistoryItem cur) { |
| 3422 | int firstToken = src.readInt(); |
| 3423 | int deltaTimeToken = firstToken&DELTA_TIME_MASK; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3424 | cur.cmd = HistoryItem.CMD_UPDATE; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3425 | cur.numReadInts = 1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3426 | if (DEBUG) Slog.i(TAG, "READ DELTA: firstToken=0x" + Integer.toHexString(firstToken) |
| 3427 | + " deltaTimeToken=" + deltaTimeToken); |
| 3428 | |
| 3429 | if (deltaTimeToken < DELTA_TIME_ABS) { |
| 3430 | cur.time += deltaTimeToken; |
| 3431 | } else if (deltaTimeToken == DELTA_TIME_ABS) { |
| 3432 | cur.time = src.readLong(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3433 | cur.numReadInts += 2; |
| 3434 | if (DEBUG) Slog.i(TAG, "READ DELTA: ABS time=" + cur.time); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3435 | cur.readFromParcel(src); |
| 3436 | return; |
| 3437 | } else if (deltaTimeToken == DELTA_TIME_INT) { |
| 3438 | int delta = src.readInt(); |
| 3439 | cur.time += delta; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3440 | cur.numReadInts += 1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3441 | if (DEBUG) Slog.i(TAG, "READ DELTA: time delta=" + delta + " new time=" + cur.time); |
| 3442 | } else { |
| 3443 | long delta = src.readLong(); |
| 3444 | if (DEBUG) Slog.i(TAG, "READ DELTA: time delta=" + delta + " new time=" + cur.time); |
| 3445 | cur.time += delta; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3446 | cur.numReadInts += 2; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3447 | } |
| 3448 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 3449 | final int batteryLevelInt; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3450 | if ((firstToken&DELTA_BATTERY_LEVEL_FLAG) != 0) { |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 3451 | batteryLevelInt = src.readInt(); |
Adam Lesinski | 3944c81 | 2015-11-13 15:54:59 -0800 | [diff] [blame] | 3452 | readBatteryLevelInt(batteryLevelInt, cur); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3453 | cur.numReadInts += 1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3454 | if (DEBUG) Slog.i(TAG, "READ DELTA: batteryToken=0x" |
| 3455 | + Integer.toHexString(batteryLevelInt) |
| 3456 | + " batteryLevel=" + cur.batteryLevel |
| 3457 | + " batteryTemp=" + cur.batteryTemperature |
| 3458 | + " batteryVolt=" + (int)cur.batteryVoltage); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 3459 | } else { |
| 3460 | batteryLevelInt = 0; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3461 | } |
| 3462 | |
| 3463 | if ((firstToken&DELTA_STATE_FLAG) != 0) { |
| 3464 | int stateInt = src.readInt(); |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 3465 | cur.states = (firstToken&DELTA_STATE_MASK) | (stateInt&(~STATE_BATTERY_MASK)); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 3466 | cur.batteryStatus = (byte)((stateInt>>STATE_BATTERY_STATUS_SHIFT) |
| 3467 | & STATE_BATTERY_STATUS_MASK); |
| 3468 | cur.batteryHealth = (byte)((stateInt>>STATE_BATTERY_HEALTH_SHIFT) |
| 3469 | & STATE_BATTERY_HEALTH_MASK); |
| 3470 | cur.batteryPlugType = (byte)((stateInt>>STATE_BATTERY_PLUG_SHIFT) |
| 3471 | & STATE_BATTERY_PLUG_MASK); |
| 3472 | switch (cur.batteryPlugType) { |
| 3473 | case 1: |
| 3474 | cur.batteryPlugType = BatteryManager.BATTERY_PLUGGED_AC; |
| 3475 | break; |
| 3476 | case 2: |
| 3477 | cur.batteryPlugType = BatteryManager.BATTERY_PLUGGED_USB; |
| 3478 | break; |
| 3479 | case 3: |
| 3480 | cur.batteryPlugType = BatteryManager.BATTERY_PLUGGED_WIRELESS; |
| 3481 | break; |
| 3482 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3483 | cur.numReadInts += 1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3484 | if (DEBUG) Slog.i(TAG, "READ DELTA: stateToken=0x" |
| 3485 | + Integer.toHexString(stateInt) |
| 3486 | + " batteryStatus=" + cur.batteryStatus |
| 3487 | + " batteryHealth=" + cur.batteryHealth |
| 3488 | + " batteryPlugType=" + cur.batteryPlugType |
| 3489 | + " states=0x" + Integer.toHexString(cur.states)); |
| 3490 | } else { |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 3491 | cur.states = (firstToken&DELTA_STATE_MASK) | (cur.states&(~STATE_BATTERY_MASK)); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3492 | } |
| 3493 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3494 | if ((firstToken&DELTA_STATE2_FLAG) != 0) { |
| 3495 | cur.states2 = src.readInt(); |
| 3496 | if (DEBUG) Slog.i(TAG, "READ DELTA: states2=0x" |
| 3497 | + Integer.toHexString(cur.states2)); |
| 3498 | } |
| 3499 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3500 | if ((firstToken&DELTA_WAKELOCK_FLAG) != 0) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3501 | int indexes = src.readInt(); |
| 3502 | int wakeLockIndex = indexes&0xffff; |
| 3503 | int wakeReasonIndex = (indexes>>16)&0xffff; |
| 3504 | if (wakeLockIndex != 0xffff) { |
| 3505 | cur.wakelockTag = cur.localWakelockTag; |
| 3506 | readHistoryTag(wakeLockIndex, cur.wakelockTag); |
| 3507 | if (DEBUG) Slog.i(TAG, "READ DELTA: wakelockTag=#" + cur.wakelockTag.poolIdx |
| 3508 | + " " + cur.wakelockTag.uid + ":" + cur.wakelockTag.string); |
| 3509 | } else { |
| 3510 | cur.wakelockTag = null; |
| 3511 | } |
| 3512 | if (wakeReasonIndex != 0xffff) { |
| 3513 | cur.wakeReasonTag = cur.localWakeReasonTag; |
| 3514 | readHistoryTag(wakeReasonIndex, cur.wakeReasonTag); |
| 3515 | if (DEBUG) Slog.i(TAG, "READ DELTA: wakeReasonTag=#" + cur.wakeReasonTag.poolIdx |
| 3516 | + " " + cur.wakeReasonTag.uid + ":" + cur.wakeReasonTag.string); |
| 3517 | } else { |
| 3518 | cur.wakeReasonTag = null; |
| 3519 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3520 | cur.numReadInts += 1; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3521 | } else { |
| 3522 | cur.wakelockTag = null; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3523 | cur.wakeReasonTag = null; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3524 | } |
| 3525 | |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3526 | if ((firstToken&DELTA_EVENT_FLAG) != 0) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3527 | cur.eventTag = cur.localEventTag; |
| 3528 | final int codeAndIndex = src.readInt(); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3529 | cur.eventCode = (codeAndIndex&0xffff); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3530 | final int index = ((codeAndIndex>>16)&0xffff); |
| 3531 | readHistoryTag(index, cur.eventTag); |
| 3532 | cur.numReadInts += 1; |
| 3533 | if (DEBUG) Slog.i(TAG, "READ DELTA: event=" + cur.eventCode + " tag=#" |
| 3534 | + cur.eventTag.poolIdx + " " + cur.eventTag.uid + ":" |
| 3535 | + cur.eventTag.string); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3536 | } else { |
| 3537 | cur.eventCode = HistoryItem.EVENT_NONE; |
| 3538 | } |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 3539 | |
| 3540 | if ((batteryLevelInt&BATTERY_DELTA_LEVEL_FLAG) != 0) { |
| 3541 | cur.stepDetails = mReadHistoryStepDetails; |
| 3542 | cur.stepDetails.readFromParcel(src); |
| 3543 | } else { |
| 3544 | cur.stepDetails = null; |
| 3545 | } |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 3546 | |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 3547 | if ((firstToken&DELTA_BATTERY_CHARGE_FLAG) != 0) { |
| 3548 | cur.batteryChargeUAh = src.readInt(); |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 3549 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3550 | } |
| 3551 | |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 3552 | @Override |
| 3553 | public void commitCurrentHistoryBatchLocked() { |
| 3554 | mHistoryLastWritten.cmd = HistoryItem.CMD_NULL; |
| 3555 | } |
| 3556 | |
Narayan Kamath | 5a5a7fe | 2018-02-05 17:30:06 +0000 | [diff] [blame] | 3557 | void addHistoryBufferLocked(long elapsedRealtimeMs, HistoryItem cur) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3558 | if (!mHaveBatteryLevel || !mRecordingHistory) { |
| 3559 | return; |
| 3560 | } |
| 3561 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3562 | final long timeDiff = (mHistoryBaseTime+elapsedRealtimeMs) - mHistoryLastWritten.time; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3563 | final int diffStates = mHistoryLastWritten.states^(cur.states&mActiveHistoryStates); |
| 3564 | final int diffStates2 = mHistoryLastWritten.states2^(cur.states2&mActiveHistoryStates2); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3565 | final int lastDiffStates = mHistoryLastWritten.states^mHistoryLastLastWritten.states; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3566 | final int lastDiffStates2 = mHistoryLastWritten.states2^mHistoryLastLastWritten.states2; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3567 | if (DEBUG) Slog.i(TAG, "ADD: tdelta=" + timeDiff + " diff=" |
| 3568 | + Integer.toHexString(diffStates) + " lastDiff=" |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3569 | + Integer.toHexString(lastDiffStates) + " diff2=" |
| 3570 | + Integer.toHexString(diffStates2) + " lastDiff2=" |
| 3571 | + Integer.toHexString(lastDiffStates2)); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3572 | if (mHistoryBufferLastPos >= 0 && mHistoryLastWritten.cmd == HistoryItem.CMD_UPDATE |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3573 | && timeDiff < 1000 && (diffStates&lastDiffStates) == 0 |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3574 | && (diffStates2&lastDiffStates2) == 0 |
| 3575 | && (mHistoryLastWritten.wakelockTag == null || cur.wakelockTag == null) |
| 3576 | && (mHistoryLastWritten.wakeReasonTag == null || cur.wakeReasonTag == null) |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 3577 | && mHistoryLastWritten.stepDetails == null |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3578 | && (mHistoryLastWritten.eventCode == HistoryItem.EVENT_NONE |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3579 | || cur.eventCode == HistoryItem.EVENT_NONE) |
| 3580 | && mHistoryLastWritten.batteryLevel == cur.batteryLevel |
| 3581 | && mHistoryLastWritten.batteryStatus == cur.batteryStatus |
| 3582 | && mHistoryLastWritten.batteryHealth == cur.batteryHealth |
| 3583 | && mHistoryLastWritten.batteryPlugType == cur.batteryPlugType |
| 3584 | && mHistoryLastWritten.batteryTemperature == cur.batteryTemperature |
| 3585 | && mHistoryLastWritten.batteryVoltage == cur.batteryVoltage) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3586 | // 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] | 3587 | // 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] | 3588 | // as long as no bit has changed both between now and the last entry, as |
| 3589 | // well as the last entry and the one before it (so we capture any toggles). |
| 3590 | if (DEBUG) Slog.i(TAG, "ADD: rewinding back to " + mHistoryBufferLastPos); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3591 | mHistoryBuffer.setDataSize(mHistoryBufferLastPos); |
| 3592 | mHistoryBuffer.setDataPosition(mHistoryBufferLastPos); |
| 3593 | mHistoryBufferLastPos = -1; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3594 | elapsedRealtimeMs = mHistoryLastWritten.time - mHistoryBaseTime; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3595 | // If the last written history had a wakelock tag, we need to retain it. |
| 3596 | // Note that the condition above made sure that we aren't in a case where |
| 3597 | // both it and the current history item have a wakelock tag. |
| 3598 | if (mHistoryLastWritten.wakelockTag != null) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3599 | cur.wakelockTag = cur.localWakelockTag; |
| 3600 | cur.wakelockTag.setTo(mHistoryLastWritten.wakelockTag); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3601 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3602 | // If the last written history had a wake reason tag, we need to retain it. |
| 3603 | // Note that the condition above made sure that we aren't in a case where |
| 3604 | // both it and the current history item have a wakelock tag. |
| 3605 | if (mHistoryLastWritten.wakeReasonTag != null) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3606 | cur.wakeReasonTag = cur.localWakeReasonTag; |
| 3607 | cur.wakeReasonTag.setTo(mHistoryLastWritten.wakeReasonTag); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3608 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3609 | // If the last written history had an event, we need to retain it. |
| 3610 | // Note that the condition above made sure that we aren't in a case where |
| 3611 | // both it and the current history item have an event. |
| 3612 | if (mHistoryLastWritten.eventCode != HistoryItem.EVENT_NONE) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3613 | cur.eventCode = mHistoryLastWritten.eventCode; |
| 3614 | cur.eventTag = cur.localEventTag; |
| 3615 | cur.eventTag.setTo(mHistoryLastWritten.eventTag); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3616 | } |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 3617 | mHistoryLastWritten.setTo(mHistoryLastLastWritten); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3618 | } |
| 3619 | |
Adam Lesinski | 4548978 | 2016-12-15 23:45:17 -0800 | [diff] [blame] | 3620 | boolean recordResetDueToOverflow = false; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3621 | final int dataSize = mHistoryBuffer.dataSize(); |
Adam Lesinski | 4548978 | 2016-12-15 23:45:17 -0800 | [diff] [blame] | 3622 | if (dataSize >= MAX_MAX_HISTORY_BUFFER*3) { |
| 3623 | // Clients can't deal with history buffers this large. This only |
| 3624 | // really happens when the device is on charger and interacted with |
| 3625 | // for long periods of time, like in retail mode. Since the device is |
| 3626 | // most likely charged, when unplugged, stats would have reset anyways. |
| 3627 | // Reset the stats and mark that we overflowed. |
| 3628 | // b/32540341 |
| 3629 | resetAllStatsLocked(); |
| 3630 | |
| 3631 | // Mark that we want to set *OVERFLOW* event and the RESET:START |
| 3632 | // events. |
| 3633 | recordResetDueToOverflow = true; |
| 3634 | |
| 3635 | } else if (dataSize >= MAX_HISTORY_BUFFER) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3636 | if (!mHistoryOverflow) { |
| 3637 | mHistoryOverflow = true; |
Narayan Kamath | 5a5a7fe | 2018-02-05 17:30:06 +0000 | [diff] [blame] | 3638 | addHistoryBufferLocked(elapsedRealtimeMs, HistoryItem.CMD_UPDATE, cur); |
| 3639 | addHistoryBufferLocked(elapsedRealtimeMs, HistoryItem.CMD_OVERFLOW, cur); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3640 | return; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3641 | } |
| 3642 | |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3643 | // After overflow, we allow various bit-wise states to settle to 0. |
| 3644 | boolean writeAnyway = false; |
| 3645 | final int curStates = cur.states & HistoryItem.SETTLE_TO_ZERO_STATES |
| 3646 | & mActiveHistoryStates; |
| 3647 | if (mHistoryLastWritten.states != curStates) { |
| 3648 | // mActiveHistoryStates keeps track of which bits in .states are now being |
| 3649 | // forced to 0. |
| 3650 | int old = mActiveHistoryStates; |
| 3651 | mActiveHistoryStates &= curStates | ~HistoryItem.SETTLE_TO_ZERO_STATES; |
| 3652 | writeAnyway |= old != mActiveHistoryStates; |
| 3653 | } |
| 3654 | final int curStates2 = cur.states2 & HistoryItem.SETTLE_TO_ZERO_STATES2 |
| 3655 | & mActiveHistoryStates2; |
| 3656 | if (mHistoryLastWritten.states2 != curStates2) { |
| 3657 | // mActiveHistoryStates2 keeps track of which bits in .states2 are now being |
| 3658 | // forced to 0. |
| 3659 | int old = mActiveHistoryStates2; |
| 3660 | mActiveHistoryStates2 &= curStates2 | ~HistoryItem.SETTLE_TO_ZERO_STATES2; |
| 3661 | writeAnyway |= old != mActiveHistoryStates2; |
| 3662 | } |
| 3663 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3664 | // Once we've reached the maximum number of items, we only |
| 3665 | // record changes to the battery level and the most interesting states. |
| 3666 | // Once we've reached the maximum maximum number of items, we only |
| 3667 | // record changes to the battery level. |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3668 | if (!writeAnyway && mHistoryLastWritten.batteryLevel == cur.batteryLevel && |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3669 | (dataSize >= MAX_MAX_HISTORY_BUFFER |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3670 | || ((mHistoryLastWritten.states^cur.states) |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3671 | & HistoryItem.MOST_INTERESTING_STATES) == 0 |
| 3672 | || ((mHistoryLastWritten.states2^cur.states2) |
| 3673 | & HistoryItem.MOST_INTERESTING_STATES2) == 0)) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3674 | return; |
| 3675 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3676 | |
Narayan Kamath | 5a5a7fe | 2018-02-05 17:30:06 +0000 | [diff] [blame] | 3677 | addHistoryBufferLocked(elapsedRealtimeMs, HistoryItem.CMD_UPDATE, cur); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3678 | return; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3679 | } |
| 3680 | |
Adam Lesinski | 4548978 | 2016-12-15 23:45:17 -0800 | [diff] [blame] | 3681 | if (dataSize == 0 || recordResetDueToOverflow) { |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 3682 | // The history is currently empty; we need it to start with a time stamp. |
| 3683 | cur.currentTime = System.currentTimeMillis(); |
Adam Lesinski | 4548978 | 2016-12-15 23:45:17 -0800 | [diff] [blame] | 3684 | if (recordResetDueToOverflow) { |
Narayan Kamath | 5a5a7fe | 2018-02-05 17:30:06 +0000 | [diff] [blame] | 3685 | addHistoryBufferLocked(elapsedRealtimeMs, HistoryItem.CMD_OVERFLOW, cur); |
Adam Lesinski | 4548978 | 2016-12-15 23:45:17 -0800 | [diff] [blame] | 3686 | } |
Narayan Kamath | 5a5a7fe | 2018-02-05 17:30:06 +0000 | [diff] [blame] | 3687 | addHistoryBufferLocked(elapsedRealtimeMs, HistoryItem.CMD_RESET, cur); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 3688 | } |
Narayan Kamath | 5a5a7fe | 2018-02-05 17:30:06 +0000 | [diff] [blame] | 3689 | addHistoryBufferLocked(elapsedRealtimeMs, HistoryItem.CMD_UPDATE, cur); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3690 | } |
| 3691 | |
Narayan Kamath | 5a5a7fe | 2018-02-05 17:30:06 +0000 | [diff] [blame] | 3692 | private void addHistoryBufferLocked(long elapsedRealtimeMs, byte cmd, HistoryItem cur) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3693 | if (mIteratingHistory) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3694 | throw new IllegalStateException("Can't do this while iterating history!"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3695 | } |
| 3696 | mHistoryBufferLastPos = mHistoryBuffer.dataPosition(); |
| 3697 | mHistoryLastLastWritten.setTo(mHistoryLastWritten); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3698 | mHistoryLastWritten.setTo(mHistoryBaseTime + elapsedRealtimeMs, cmd, cur); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3699 | mHistoryLastWritten.states &= mActiveHistoryStates; |
| 3700 | mHistoryLastWritten.states2 &= mActiveHistoryStates2; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3701 | writeHistoryDelta(mHistoryBuffer, mHistoryLastWritten, mHistoryLastLastWritten); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3702 | mLastHistoryElapsedRealtime = elapsedRealtimeMs; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3703 | cur.wakelockTag = null; |
| 3704 | cur.wakeReasonTag = null; |
| 3705 | cur.eventCode = HistoryItem.EVENT_NONE; |
| 3706 | cur.eventTag = null; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3707 | if (DEBUG_HISTORY) Slog.i(TAG, "Writing history buffer: was " + mHistoryBufferLastPos |
| 3708 | + " now " + mHistoryBuffer.dataPosition() |
| 3709 | + " size is now " + mHistoryBuffer.dataSize()); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3710 | } |
| 3711 | |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 3712 | int mChangedStates = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3713 | int mChangedStates2 = 0; |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 3714 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3715 | void addHistoryRecordLocked(long elapsedRealtimeMs, long uptimeMs) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3716 | if (mTrackRunningHistoryElapsedRealtime != 0) { |
| 3717 | final long diffElapsed = elapsedRealtimeMs - mTrackRunningHistoryElapsedRealtime; |
| 3718 | final long diffUptime = uptimeMs - mTrackRunningHistoryUptime; |
| 3719 | if (diffUptime < (diffElapsed-20)) { |
| 3720 | final long wakeElapsedTime = elapsedRealtimeMs - (diffElapsed - diffUptime); |
| 3721 | mHistoryAddTmp.setTo(mHistoryLastWritten); |
| 3722 | mHistoryAddTmp.wakelockTag = null; |
| 3723 | mHistoryAddTmp.wakeReasonTag = null; |
| 3724 | mHistoryAddTmp.eventCode = HistoryItem.EVENT_NONE; |
| 3725 | mHistoryAddTmp.states &= ~HistoryItem.STATE_CPU_RUNNING_FLAG; |
Narayan Kamath | 5a5a7fe | 2018-02-05 17:30:06 +0000 | [diff] [blame] | 3726 | addHistoryRecordInnerLocked(wakeElapsedTime, mHistoryAddTmp); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3727 | } |
| 3728 | } |
| 3729 | mHistoryCur.states |= HistoryItem.STATE_CPU_RUNNING_FLAG; |
| 3730 | mTrackRunningHistoryElapsedRealtime = elapsedRealtimeMs; |
| 3731 | mTrackRunningHistoryUptime = uptimeMs; |
Narayan Kamath | 5a5a7fe | 2018-02-05 17:30:06 +0000 | [diff] [blame] | 3732 | addHistoryRecordInnerLocked(elapsedRealtimeMs, mHistoryCur); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3733 | } |
| 3734 | |
Narayan Kamath | 5a5a7fe | 2018-02-05 17:30:06 +0000 | [diff] [blame] | 3735 | void addHistoryRecordInnerLocked(long elapsedRealtimeMs, HistoryItem cur) { |
| 3736 | addHistoryBufferLocked(elapsedRealtimeMs, cur); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3737 | |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 3738 | if (!USE_OLD_HISTORY) { |
| 3739 | return; |
| 3740 | } |
| 3741 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3742 | if (!mHaveBatteryLevel || !mRecordingHistory) { |
| 3743 | return; |
| 3744 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3745 | |
| 3746 | // If the current time is basically the same as the last time, |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 3747 | // and no states have since the last recorded entry changed and |
| 3748 | // are now resetting back to their original value, then just collapse |
| 3749 | // into one record. |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3750 | if (mHistoryEnd != null && mHistoryEnd.cmd == HistoryItem.CMD_UPDATE |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3751 | && (mHistoryBaseTime+elapsedRealtimeMs) < (mHistoryEnd.time+1000) |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3752 | && ((mHistoryEnd.states^cur.states)&mChangedStates&mActiveHistoryStates) == 0 |
| 3753 | && ((mHistoryEnd.states2^cur.states2)&mChangedStates2&mActiveHistoryStates2) == 0) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3754 | // If the current is the same as the one before, then we no |
| 3755 | // longer need the entry. |
| 3756 | if (mHistoryLastEnd != null && mHistoryLastEnd.cmd == HistoryItem.CMD_UPDATE |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3757 | && (mHistoryBaseTime+elapsedRealtimeMs) < (mHistoryEnd.time+500) |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3758 | && mHistoryLastEnd.sameNonEvent(cur)) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3759 | mHistoryLastEnd.next = null; |
| 3760 | mHistoryEnd.next = mHistoryCache; |
| 3761 | mHistoryCache = mHistoryEnd; |
| 3762 | mHistoryEnd = mHistoryLastEnd; |
| 3763 | mHistoryLastEnd = null; |
| 3764 | } else { |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3765 | mChangedStates |= mHistoryEnd.states^(cur.states&mActiveHistoryStates); |
| 3766 | mChangedStates2 |= mHistoryEnd.states^(cur.states2&mActiveHistoryStates2); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3767 | mHistoryEnd.setTo(mHistoryEnd.time, HistoryItem.CMD_UPDATE, cur); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3768 | } |
| 3769 | return; |
| 3770 | } |
| 3771 | |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 3772 | mChangedStates = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3773 | mChangedStates2 = 0; |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 3774 | |
| 3775 | if (mNumHistoryItems == MAX_HISTORY_ITEMS |
| 3776 | || mNumHistoryItems == MAX_MAX_HISTORY_ITEMS) { |
Narayan Kamath | 5a5a7fe | 2018-02-05 17:30:06 +0000 | [diff] [blame] | 3777 | addHistoryBufferLocked(elapsedRealtimeMs, HistoryItem.CMD_OVERFLOW, cur); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 3778 | } |
| 3779 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3780 | if (mNumHistoryItems >= MAX_HISTORY_ITEMS) { |
| 3781 | // Once we've reached the maximum number of items, we only |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 3782 | // record changes to the battery level and the most interesting states. |
| 3783 | // Once we've reached the maximum maximum number of items, we only |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3784 | // record changes to the battery level. |
| 3785 | if (mHistoryEnd != null && mHistoryEnd.batteryLevel |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3786 | == cur.batteryLevel && |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 3787 | (mNumHistoryItems >= MAX_MAX_HISTORY_ITEMS |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3788 | || ((mHistoryEnd.states^(cur.states&mActiveHistoryStates)) |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 3789 | & HistoryItem.MOST_INTERESTING_STATES) == 0)) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3790 | return; |
| 3791 | } |
| 3792 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3793 | |
Narayan Kamath | 5a5a7fe | 2018-02-05 17:30:06 +0000 | [diff] [blame] | 3794 | addHistoryBufferLocked(elapsedRealtimeMs, HistoryItem.CMD_UPDATE, cur); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3795 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3796 | |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3797 | public void addHistoryEventLocked(long elapsedRealtimeMs, long uptimeMs, int code, |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3798 | String name, int uid) { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3799 | mHistoryCur.eventCode = code; |
| 3800 | mHistoryCur.eventTag = mHistoryCur.localEventTag; |
| 3801 | mHistoryCur.eventTag.string = name; |
| 3802 | mHistoryCur.eventTag.uid = uid; |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 3803 | addHistoryRecordLocked(elapsedRealtimeMs, uptimeMs); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3804 | } |
| 3805 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3806 | void addHistoryRecordLocked(long elapsedRealtimeMs, long uptimeMs, byte cmd, HistoryItem cur) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3807 | HistoryItem rec = mHistoryCache; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3808 | if (rec != null) { |
| 3809 | mHistoryCache = rec.next; |
| 3810 | } else { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3811 | rec = new HistoryItem(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3812 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3813 | rec.setTo(mHistoryBaseTime + elapsedRealtimeMs, cmd, cur); |
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 | addHistoryRecordLocked(rec); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3816 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3817 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3818 | void addHistoryRecordLocked(HistoryItem rec) { |
| 3819 | mNumHistoryItems++; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3820 | rec.next = null; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3821 | mHistoryLastEnd = mHistoryEnd; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3822 | if (mHistoryEnd != null) { |
| 3823 | mHistoryEnd.next = rec; |
| 3824 | mHistoryEnd = rec; |
| 3825 | } else { |
| 3826 | mHistory = mHistoryEnd = rec; |
| 3827 | } |
| 3828 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3829 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3830 | void clearHistoryLocked() { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3831 | if (DEBUG_HISTORY) Slog.i(TAG, "********** CLEARING HISTORY!"); |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 3832 | if (USE_OLD_HISTORY) { |
| 3833 | if (mHistory != null) { |
| 3834 | mHistoryEnd.next = mHistoryCache; |
| 3835 | mHistoryCache = mHistory; |
| 3836 | mHistory = mHistoryLastEnd = mHistoryEnd = null; |
| 3837 | } |
| 3838 | mNumHistoryItems = 0; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3839 | } |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 3840 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3841 | mHistoryBaseTime = 0; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3842 | mLastHistoryElapsedRealtime = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3843 | mTrackRunningHistoryElapsedRealtime = 0; |
| 3844 | mTrackRunningHistoryUptime = 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3845 | |
| 3846 | mHistoryBuffer.setDataSize(0); |
| 3847 | mHistoryBuffer.setDataPosition(0); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3848 | mHistoryBuffer.setDataCapacity(MAX_HISTORY_BUFFER / 2); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3849 | mHistoryLastLastWritten.clear(); |
| 3850 | mHistoryLastWritten.clear(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3851 | mHistoryTagPool.clear(); |
| 3852 | mNextHistoryTagIdx = 0; |
| 3853 | mNumHistoryTagChars = 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3854 | mHistoryBufferLastPos = -1; |
| 3855 | mHistoryOverflow = false; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3856 | mActiveHistoryStates = 0xffffffff; |
| 3857 | mActiveHistoryStates2 = 0xffffffff; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3858 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3859 | |
Andreas Gampe | 3f24e69 | 2018-02-05 13:24:28 -0800 | [diff] [blame] | 3860 | @GuardedBy("this") |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 3861 | public void updateTimeBasesLocked(boolean unplugged, int screenState, long uptime, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3862 | long realtime) { |
Mike Ma | a772475 | 2017-10-10 15:29:25 -0700 | [diff] [blame] | 3863 | final boolean screenOff = !isScreenOn(screenState); |
Sudheer Shanka | 9d4ed7c | 2017-07-08 22:10:45 -0700 | [diff] [blame] | 3864 | final boolean updateOnBatteryTimeBase = unplugged != mOnBatteryTimeBase.isRunning(); |
| 3865 | final boolean updateOnBatteryScreenOffTimeBase = |
| 3866 | (unplugged && screenOff) != mOnBatteryScreenOffTimeBase.isRunning(); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3867 | |
Sudheer Shanka | 9d4ed7c | 2017-07-08 22:10:45 -0700 | [diff] [blame] | 3868 | if (updateOnBatteryScreenOffTimeBase || updateOnBatteryTimeBase) { |
| 3869 | if (updateOnBatteryScreenOffTimeBase) { |
| 3870 | updateKernelWakelocksLocked(); |
| 3871 | updateBatteryPropertiesLocked(); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3872 | } |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 3873 | // This if{} is only necessary due to SCREEN_OFF_RPM_STATS_ENABLED, which exists because |
| 3874 | // updateRpmStatsLocked is too slow to run each screen change. When the speed is |
| 3875 | // improved, remove the surrounding if{}. |
| 3876 | if (SCREEN_OFF_RPM_STATS_ENABLED || updateOnBatteryTimeBase) { |
| 3877 | updateRpmStatsLocked(); // if either OnBattery or OnBatteryScreenOff timebase changes. |
| 3878 | } |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 3879 | if (DEBUG_ENERGY_CPU) { |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 3880 | Slog.d(TAG, "Updating cpu time because screen is now " |
| 3881 | + Display.stateToString(screenState) |
Sudheer Shanka | 9d4ed7c | 2017-07-08 22:10:45 -0700 | [diff] [blame] | 3882 | + " and battery is " + (unplugged ? "on" : "off")); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3883 | } |
Sudheer Shanka | 9d4ed7c | 2017-07-08 22:10:45 -0700 | [diff] [blame] | 3884 | |
| 3885 | mOnBatteryTimeBase.setRunning(unplugged, uptime, realtime); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 3886 | if (updateOnBatteryTimeBase) { |
| 3887 | for (int i = mUidStats.size() - 1; i >= 0; --i) { |
| 3888 | mUidStats.valueAt(i).updateOnBatteryBgTimeBase(uptime, realtime); |
Sudheer Shanka | 9d4ed7c | 2017-07-08 22:10:45 -0700 | [diff] [blame] | 3889 | } |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 3890 | } |
| 3891 | if (updateOnBatteryScreenOffTimeBase) { |
| 3892 | mOnBatteryScreenOffTimeBase.setRunning(unplugged && screenOff, uptime, realtime); |
| 3893 | for (int i = mUidStats.size() - 1; i >= 0; --i) { |
| 3894 | mUidStats.valueAt(i).updateOnBatteryScreenOffBgTimeBase(uptime, realtime); |
Sudheer Shanka | 9d4ed7c | 2017-07-08 22:10:45 -0700 | [diff] [blame] | 3895 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3896 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3897 | } |
| 3898 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 3899 | |
Adam Lesinski | e1f480d | 2017-02-15 18:51:23 -0800 | [diff] [blame] | 3900 | private void updateBatteryPropertiesLocked() { |
| 3901 | try { |
| 3902 | IBatteryPropertiesRegistrar registrar = IBatteryPropertiesRegistrar.Stub.asInterface( |
| 3903 | ServiceManager.getService("batteryproperties")); |
| 3904 | registrar.scheduleUpdate(); |
| 3905 | } catch (RemoteException e) { |
| 3906 | // Ignore. |
| 3907 | } |
| 3908 | } |
| 3909 | |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3910 | public void addIsolatedUidLocked(int isolatedUid, int appUid) { |
| 3911 | mIsolatedUids.put(isolatedUid, appUid); |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 3912 | StatsLog.write(StatsLog.ISOLATED_UID_CHANGED, appUid, isolatedUid, |
| 3913 | StatsLog.ISOLATED_UID_CHANGED__EVENT__CREATED); |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 3914 | final Uid u = getUidStatsLocked(appUid); |
| 3915 | u.addIsolatedUid(isolatedUid); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3916 | } |
| 3917 | |
Adam Lesinski | 61db88f | 2015-07-01 15:05:07 -0700 | [diff] [blame] | 3918 | /** |
| 3919 | * Schedules a read of the latest cpu times before removing the isolated UID. |
| 3920 | * @see #removeIsolatedUidLocked(int) |
| 3921 | */ |
| 3922 | public void scheduleRemoveIsolatedUidLocked(int isolatedUid, int appUid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3923 | int curUid = mIsolatedUids.get(isolatedUid, -1); |
| 3924 | if (curUid == appUid) { |
Adam Lesinski | 61db88f | 2015-07-01 15:05:07 -0700 | [diff] [blame] | 3925 | if (mExternalSync != null) { |
| 3926 | mExternalSync.scheduleCpuSyncDueToRemovedUid(isolatedUid); |
| 3927 | } |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3928 | } |
| 3929 | } |
| 3930 | |
Adam Lesinski | 61db88f | 2015-07-01 15:05:07 -0700 | [diff] [blame] | 3931 | /** |
| 3932 | * This should only be called after the cpu times have been read. |
| 3933 | * @see #scheduleRemoveIsolatedUidLocked(int, int) |
| 3934 | */ |
Andreas Gampe | 3f24e69 | 2018-02-05 13:24:28 -0800 | [diff] [blame] | 3935 | @GuardedBy("this") |
Adam Lesinski | 61db88f | 2015-07-01 15:05:07 -0700 | [diff] [blame] | 3936 | public void removeIsolatedUidLocked(int isolatedUid) { |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 3937 | StatsLog.write( |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 3938 | StatsLog.ISOLATED_UID_CHANGED, mIsolatedUids.get(isolatedUid, -1), |
| 3939 | isolatedUid, StatsLog.ISOLATED_UID_CHANGED__EVENT__REMOVED); |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 3940 | final int idx = mIsolatedUids.indexOfKey(isolatedUid); |
| 3941 | if (idx >= 0) { |
| 3942 | final int ownerUid = mIsolatedUids.valueAt(idx); |
| 3943 | final Uid u = getUidStatsLocked(ownerUid); |
| 3944 | u.removeIsolatedUid(isolatedUid); |
| 3945 | mIsolatedUids.removeAt(idx); |
| 3946 | } |
| 3947 | mKernelUidCpuTimeReader.removeUid(isolatedUid); |
| 3948 | mKernelUidCpuFreqTimeReader.removeUid(isolatedUid); |
Mike Ma | fae87da | 2018-01-19 20:07:20 -0800 | [diff] [blame] | 3949 | if (mConstants.TRACK_CPU_ACTIVE_CLUSTER_TIME) { |
| 3950 | mKernelUidCpuActiveTimeReader.removeUid(isolatedUid); |
| 3951 | mKernelUidCpuClusterTimeReader.removeUid(isolatedUid); |
| 3952 | } |
Adam Lesinski | 61db88f | 2015-07-01 15:05:07 -0700 | [diff] [blame] | 3953 | } |
| 3954 | |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3955 | public int mapUid(int uid) { |
| 3956 | int isolated = mIsolatedUids.get(uid, -1); |
| 3957 | return isolated > 0 ? isolated : uid; |
| 3958 | } |
| 3959 | |
| 3960 | public void noteEventLocked(int code, String name, int uid) { |
| 3961 | uid = mapUid(uid); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 3962 | if (!mActiveEvents.updateState(code, name, uid, 0)) { |
| 3963 | return; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 3964 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3965 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3966 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3967 | addHistoryEventLocked(elapsedRealtime, uptime, code, name, uid); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3968 | } |
| 3969 | |
Dianne Hackborn | d48954f | 2015-07-22 17:20:33 -0700 | [diff] [blame] | 3970 | boolean ensureStartClockTime(final long currentTime) { |
| 3971 | final long ABOUT_ONE_YEAR = 365*24*60*60*1000L; |
| 3972 | if (currentTime > ABOUT_ONE_YEAR && mStartClockTime < (currentTime-ABOUT_ONE_YEAR)) { |
| 3973 | // If the start clock time has changed by more than a year, then presumably |
| 3974 | // the previous time was completely bogus. So we are going to figure out a |
| 3975 | // 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] | 3976 | mStartClockTime = currentTime - (mClocks.elapsedRealtime()-(mRealtimeStart/1000)); |
Dianne Hackborn | d48954f | 2015-07-22 17:20:33 -0700 | [diff] [blame] | 3977 | return true; |
| 3978 | } |
| 3979 | return false; |
| 3980 | } |
| 3981 | |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 3982 | public void noteCurrentTimeChangedLocked() { |
| 3983 | final long currentTime = System.currentTimeMillis(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3984 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3985 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 3986 | recordCurrentTimeChangeLocked(currentTime, elapsedRealtime, uptime); |
Dianne Hackborn | d48954f | 2015-07-22 17:20:33 -0700 | [diff] [blame] | 3987 | ensureStartClockTime(currentTime); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 3988 | } |
| 3989 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3990 | public void noteProcessStartLocked(String name, int uid) { |
| 3991 | uid = mapUid(uid); |
| 3992 | if (isOnBattery()) { |
| 3993 | Uid u = getUidStatsLocked(uid); |
| 3994 | u.getProcessStatsLocked(name).incStartsLocked(); |
| 3995 | } |
| 3996 | if (!mActiveEvents.updateState(HistoryItem.EVENT_PROC_START, name, uid, 0)) { |
| 3997 | return; |
| 3998 | } |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3999 | if (!mRecordAllHistory) { |
| 4000 | return; |
| 4001 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4002 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4003 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4004 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_PROC_START, name, uid); |
| 4005 | } |
| 4006 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 4007 | public void noteProcessCrashLocked(String name, int uid) { |
| 4008 | uid = mapUid(uid); |
| 4009 | if (isOnBattery()) { |
| 4010 | Uid u = getUidStatsLocked(uid); |
| 4011 | u.getProcessStatsLocked(name).incNumCrashesLocked(); |
| 4012 | } |
| 4013 | } |
| 4014 | |
| 4015 | public void noteProcessAnrLocked(String name, int uid) { |
| 4016 | uid = mapUid(uid); |
| 4017 | if (isOnBattery()) { |
| 4018 | Uid u = getUidStatsLocked(uid); |
| 4019 | u.getProcessStatsLocked(name).incNumAnrsLocked(); |
| 4020 | } |
| 4021 | } |
| 4022 | |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 4023 | public void noteUidProcessStateLocked(int uid, int state) { |
Amith Yamasani | fd3caf6 | 2017-07-26 11:48:35 -0700 | [diff] [blame] | 4024 | int parentUid = mapUid(uid); |
| 4025 | if (uid != parentUid) { |
| 4026 | // Isolated UIDs process state is already rolled up into parent, so no need to track |
| 4027 | // Otherwise the parent's process state will get downgraded incorrectly |
| 4028 | return; |
| 4029 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 4030 | getUidStatsLocked(uid).updateUidProcessStateLocked(state); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4031 | } |
| 4032 | |
| 4033 | public void noteProcessFinishLocked(String name, int uid) { |
| 4034 | uid = mapUid(uid); |
| 4035 | if (!mActiveEvents.updateState(HistoryItem.EVENT_PROC_FINISH, name, uid, 0)) { |
| 4036 | return; |
| 4037 | } |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 4038 | if (!mRecordAllHistory) { |
| 4039 | return; |
| 4040 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4041 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4042 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 4043 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_PROC_FINISH, name, uid); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4044 | } |
| 4045 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4046 | public void noteSyncStartLocked(String name, int uid) { |
| 4047 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4048 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4049 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4050 | getUidStatsLocked(uid).noteStartSyncLocked(name, elapsedRealtime); |
| 4051 | if (!mActiveEvents.updateState(HistoryItem.EVENT_SYNC_START, name, uid, 0)) { |
| 4052 | return; |
| 4053 | } |
| 4054 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_SYNC_START, name, uid); |
| 4055 | } |
| 4056 | |
| 4057 | public void noteSyncFinishLocked(String name, int uid) { |
| 4058 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4059 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4060 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4061 | getUidStatsLocked(uid).noteStopSyncLocked(name, elapsedRealtime); |
| 4062 | if (!mActiveEvents.updateState(HistoryItem.EVENT_SYNC_FINISH, name, uid, 0)) { |
| 4063 | return; |
| 4064 | } |
| 4065 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_SYNC_FINISH, name, uid); |
| 4066 | } |
| 4067 | |
| 4068 | public void noteJobStartLocked(String name, int uid) { |
| 4069 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4070 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4071 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4072 | getUidStatsLocked(uid).noteStartJobLocked(name, elapsedRealtime); |
| 4073 | if (!mActiveEvents.updateState(HistoryItem.EVENT_JOB_START, name, uid, 0)) { |
| 4074 | return; |
| 4075 | } |
| 4076 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_JOB_START, name, uid); |
| 4077 | } |
| 4078 | |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 4079 | public void noteJobFinishLocked(String name, int uid, int stopReason) { |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4080 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4081 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4082 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 4083 | getUidStatsLocked(uid).noteStopJobLocked(name, elapsedRealtime, stopReason); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4084 | if (!mActiveEvents.updateState(HistoryItem.EVENT_JOB_FINISH, name, uid, 0)) { |
| 4085 | return; |
| 4086 | } |
| 4087 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_JOB_FINISH, name, uid); |
| 4088 | } |
| 4089 | |
Amith Yamasani | 977e11f | 2018-02-16 11:29:54 -0800 | [diff] [blame] | 4090 | public void noteJobsDeferredLocked(int uid, int numDeferred, long sinceLast) { |
| 4091 | uid = mapUid(uid); |
| 4092 | getUidStatsLocked(uid).noteJobsDeferredLocked(numDeferred, sinceLast); |
| 4093 | } |
| 4094 | |
Narayan Kamath | 695cf72 | 2017-12-21 18:32:47 +0000 | [diff] [blame] | 4095 | public void noteAlarmStartLocked(String name, WorkSource workSource, int uid) { |
| 4096 | noteAlarmStartOrFinishLocked(HistoryItem.EVENT_ALARM_START, name, workSource, uid); |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 4097 | } |
| 4098 | |
Narayan Kamath | 695cf72 | 2017-12-21 18:32:47 +0000 | [diff] [blame] | 4099 | public void noteAlarmFinishLocked(String name, WorkSource workSource, int uid) { |
| 4100 | noteAlarmStartOrFinishLocked(HistoryItem.EVENT_ALARM_FINISH, name, workSource, uid); |
| 4101 | } |
| 4102 | |
| 4103 | private void noteAlarmStartOrFinishLocked(int historyItem, String name, WorkSource workSource, |
| 4104 | int uid) { |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 4105 | if (!mRecordAllHistory) { |
| 4106 | return; |
| 4107 | } |
Narayan Kamath | 695cf72 | 2017-12-21 18:32:47 +0000 | [diff] [blame] | 4108 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4109 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4110 | final long uptime = mClocks.uptimeMillis(); |
Narayan Kamath | 695cf72 | 2017-12-21 18:32:47 +0000 | [diff] [blame] | 4111 | |
| 4112 | if (workSource != null) { |
| 4113 | for (int i = 0; i < workSource.size(); ++i) { |
| 4114 | uid = mapUid(workSource.get(i)); |
| 4115 | if (mActiveEvents.updateState(historyItem, name, uid, 0)) { |
| 4116 | addHistoryEventLocked(elapsedRealtime, uptime, historyItem, name, uid); |
| 4117 | } |
| 4118 | } |
| 4119 | |
| 4120 | List<WorkChain> workChains = workSource.getWorkChains(); |
| 4121 | if (workChains != null) { |
| 4122 | for (int i = 0; i < workChains.size(); ++i) { |
| 4123 | uid = mapUid(workChains.get(i).getAttributionUid()); |
| 4124 | if (mActiveEvents.updateState(historyItem, name, uid, 0)) { |
| 4125 | addHistoryEventLocked(elapsedRealtime, uptime, historyItem, name, uid); |
| 4126 | } |
| 4127 | } |
| 4128 | } |
| 4129 | } else { |
| 4130 | uid = mapUid(uid); |
| 4131 | |
| 4132 | if (mActiveEvents.updateState(historyItem, name, uid, 0)) { |
| 4133 | addHistoryEventLocked(elapsedRealtime, uptime, historyItem, name, uid); |
| 4134 | } |
| 4135 | } |
| 4136 | } |
| 4137 | |
| 4138 | public void noteWakupAlarmLocked(String packageName, int uid, WorkSource workSource, |
| 4139 | String tag) { |
Narayan Kamath | 695cf72 | 2017-12-21 18:32:47 +0000 | [diff] [blame] | 4140 | if (workSource != null) { |
| 4141 | for (int i = 0; i < workSource.size(); ++i) { |
| 4142 | uid = workSource.get(i); |
| 4143 | final String workSourceName = workSource.getName(i); |
| 4144 | |
Tej Singh | 6f724c4 | 2018-01-03 20:02:03 -0800 | [diff] [blame] | 4145 | if (isOnBattery()) { |
| 4146 | BatteryStatsImpl.Uid.Pkg pkg = getPackageStatsLocked(uid, |
| 4147 | workSourceName != null ? workSourceName : packageName); |
| 4148 | pkg.noteWakeupAlarmLocked(tag); |
| 4149 | } |
Yangster-mac | 2f5daec | 2018-01-16 10:23:15 -0800 | [diff] [blame] | 4150 | StatsLog.write_non_chained(StatsLog.WAKEUP_ALARM_OCCURRED, workSource.get(i), |
| 4151 | workSource.getName(i), tag); |
Narayan Kamath | 695cf72 | 2017-12-21 18:32:47 +0000 | [diff] [blame] | 4152 | } |
| 4153 | |
| 4154 | ArrayList<WorkChain> workChains = workSource.getWorkChains(); |
| 4155 | if (workChains != null) { |
| 4156 | for (int i = 0; i < workChains.size(); ++i) { |
| 4157 | final WorkChain wc = workChains.get(i); |
| 4158 | uid = wc.getAttributionUid(); |
| 4159 | |
Tej Singh | 6f724c4 | 2018-01-03 20:02:03 -0800 | [diff] [blame] | 4160 | if (isOnBattery()) { |
| 4161 | BatteryStatsImpl.Uid.Pkg pkg = getPackageStatsLocked(uid, packageName); |
| 4162 | pkg.noteWakeupAlarmLocked(tag); |
| 4163 | } |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 4164 | StatsLog.write(StatsLog.WAKEUP_ALARM_OCCURRED, wc.getUids(), wc.getTags(), tag); |
Narayan Kamath | 695cf72 | 2017-12-21 18:32:47 +0000 | [diff] [blame] | 4165 | } |
| 4166 | } |
| 4167 | } else { |
Tej Singh | 6f724c4 | 2018-01-03 20:02:03 -0800 | [diff] [blame] | 4168 | if (isOnBattery()) { |
| 4169 | BatteryStatsImpl.Uid.Pkg pkg = getPackageStatsLocked(uid, packageName); |
| 4170 | pkg.noteWakeupAlarmLocked(tag); |
| 4171 | } |
Yangster-mac | 2f5daec | 2018-01-16 10:23:15 -0800 | [diff] [blame] | 4172 | StatsLog.write_non_chained(StatsLog.WAKEUP_ALARM_OCCURRED, uid, null, tag); |
Narayan Kamath | 695cf72 | 2017-12-21 18:32:47 +0000 | [diff] [blame] | 4173 | } |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 4174 | } |
| 4175 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4176 | private void requestWakelockCpuUpdate() { |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 4177 | mExternalSync.scheduleCpuSyncDueToWakelockChange(DELAY_UPDATE_WAKELOCKS); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4178 | } |
| 4179 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 4180 | private void requestImmediateCpuUpdate() { |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 4181 | mExternalSync.scheduleCpuSyncDueToWakelockChange(0 /* delayMillis */); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 4182 | } |
| 4183 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 4184 | public void setRecordAllHistoryLocked(boolean enabled) { |
| 4185 | mRecordAllHistory = enabled; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4186 | if (!enabled) { |
| 4187 | // Clear out any existing state. |
| 4188 | mActiveEvents.removeEvents(HistoryItem.EVENT_WAKE_LOCK); |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 4189 | mActiveEvents.removeEvents(HistoryItem.EVENT_ALARM); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 4190 | // Record the currently running processes as stopping, now that we are no |
| 4191 | // longer tracking them. |
| 4192 | HashMap<String, SparseIntArray> active = mActiveEvents.getStateForEvent( |
| 4193 | HistoryItem.EVENT_PROC); |
| 4194 | if (active != null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4195 | long mSecRealtime = mClocks.elapsedRealtime(); |
| 4196 | final long mSecUptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 4197 | for (HashMap.Entry<String, SparseIntArray> ent : active.entrySet()) { |
| 4198 | SparseIntArray uids = ent.getValue(); |
| 4199 | for (int j=0; j<uids.size(); j++) { |
| 4200 | addHistoryEventLocked(mSecRealtime, mSecUptime, |
| 4201 | HistoryItem.EVENT_PROC_FINISH, ent.getKey(), uids.keyAt(j)); |
| 4202 | } |
| 4203 | } |
| 4204 | } |
| 4205 | } else { |
| 4206 | // Record the currently running processes as starting, now that we are tracking them. |
| 4207 | HashMap<String, SparseIntArray> active = mActiveEvents.getStateForEvent( |
| 4208 | HistoryItem.EVENT_PROC); |
| 4209 | if (active != null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4210 | long mSecRealtime = mClocks.elapsedRealtime(); |
| 4211 | final long mSecUptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 4212 | for (HashMap.Entry<String, SparseIntArray> ent : active.entrySet()) { |
| 4213 | SparseIntArray uids = ent.getValue(); |
| 4214 | for (int j=0; j<uids.size(); j++) { |
| 4215 | addHistoryEventLocked(mSecRealtime, mSecUptime, |
| 4216 | HistoryItem.EVENT_PROC_START, ent.getKey(), uids.keyAt(j)); |
| 4217 | } |
| 4218 | } |
| 4219 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4220 | } |
| 4221 | } |
| 4222 | |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 4223 | public void setNoAutoReset(boolean enabled) { |
| 4224 | mNoAutoReset = enabled; |
| 4225 | } |
| 4226 | |
Amith Yamasani | 674c9bb | 2017-02-01 09:45:17 -0800 | [diff] [blame] | 4227 | public void setPretendScreenOff(boolean pretendScreenOff) { |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4228 | if (mPretendScreenOff != pretendScreenOff) { |
| 4229 | mPretendScreenOff = pretendScreenOff; |
| 4230 | noteScreenStateLocked(pretendScreenOff ? Display.STATE_OFF : Display.STATE_ON); |
| 4231 | } |
Amith Yamasani | 674c9bb | 2017-02-01 09:45:17 -0800 | [diff] [blame] | 4232 | } |
| 4233 | |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 4234 | private String mInitialAcquireWakeName; |
| 4235 | private int mInitialAcquireWakeUid = -1; |
| 4236 | |
Narayan Kamath | 8182202 | 2017-12-08 11:56:01 +0000 | [diff] [blame] | 4237 | public void noteStartWakeLocked(int uid, int pid, WorkChain wc, String name, String historyName, |
| 4238 | int type, boolean unimportantForLogging, long elapsedRealtime, long uptime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4239 | uid = mapUid(uid); |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 4240 | if (type == WAKE_TYPE_PARTIAL) { |
| 4241 | // Only care about partial wake locks, since full wake locks |
| 4242 | // will be canceled when the user puts the screen to sleep. |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4243 | aggregateLastWakeupUptimeLocked(uptime); |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 4244 | if (historyName == null) { |
| 4245 | historyName = name; |
| 4246 | } |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 4247 | if (mRecordAllHistory) { |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 4248 | if (mActiveEvents.updateState(HistoryItem.EVENT_WAKE_LOCK_START, historyName, |
| 4249 | uid, 0)) { |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 4250 | addHistoryEventLocked(elapsedRealtime, uptime, |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 4251 | HistoryItem.EVENT_WAKE_LOCK_START, historyName, uid); |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 4252 | } |
| 4253 | } |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 4254 | if (mWakeLockNesting == 0) { |
| 4255 | mHistoryCur.states |= HistoryItem.STATE_WAKE_LOCK_FLAG; |
| 4256 | if (DEBUG_HISTORY) Slog.v(TAG, "Start wake lock to: " |
| 4257 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4258 | mHistoryCur.wakelockTag = mHistoryCur.localWakelockTag; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4259 | mHistoryCur.wakelockTag.string = mInitialAcquireWakeName = historyName; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 4260 | mHistoryCur.wakelockTag.uid = mInitialAcquireWakeUid = uid; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 4261 | mWakeLockImportant = !unimportantForLogging; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4262 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 4263 | } else if (!mWakeLockImportant && !unimportantForLogging |
| 4264 | && mHistoryLastWritten.cmd == HistoryItem.CMD_UPDATE) { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 4265 | if (mHistoryLastWritten.wakelockTag != null) { |
| 4266 | // We'll try to update the last tag. |
| 4267 | mHistoryLastWritten.wakelockTag = null; |
| 4268 | mHistoryCur.wakelockTag = mHistoryCur.localWakelockTag; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4269 | mHistoryCur.wakelockTag.string = mInitialAcquireWakeName = historyName; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 4270 | mHistoryCur.wakelockTag.uid = mInitialAcquireWakeUid = uid; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4271 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 4272 | } |
| 4273 | mWakeLockImportant = true; |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 4274 | } |
| 4275 | mWakeLockNesting++; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4276 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4277 | if (uid >= 0) { |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 4278 | if (mOnBatteryScreenOffTimeBase.isRunning()) { |
| 4279 | // We only update the cpu time when a wake lock is acquired if the screen is off. |
| 4280 | // If the screen is on, we don't distribute the power amongst partial wakelocks. |
| 4281 | if (DEBUG_ENERGY_CPU) { |
| 4282 | Slog.d(TAG, "Updating cpu time because of +wake_lock"); |
| 4283 | } |
| 4284 | requestWakelockCpuUpdate(); |
| 4285 | } |
Narayan Kamath | 8182202 | 2017-12-08 11:56:01 +0000 | [diff] [blame] | 4286 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4287 | getUidStatsLocked(uid).noteStartWakeLocked(pid, name, type, elapsedRealtime); |
Narayan Kamath | 8182202 | 2017-12-08 11:56:01 +0000 | [diff] [blame] | 4288 | |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 4289 | if (wc != null) { |
Bookatz | 1a1b046 | 2018-01-12 11:47:03 -0800 | [diff] [blame] | 4290 | StatsLog.write(StatsLog.WAKELOCK_STATE_CHANGED, wc.getUids(), wc.getTags(), |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 4291 | getPowerManagerWakeLockLevel(type), name, |
| 4292 | StatsLog.WAKELOCK_STATE_CHANGED__STATE__ACQUIRE); |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 4293 | } else { |
Bookatz | 1a1b046 | 2018-01-12 11:47:03 -0800 | [diff] [blame] | 4294 | StatsLog.write_non_chained(StatsLog.WAKELOCK_STATE_CHANGED, uid, null, |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 4295 | getPowerManagerWakeLockLevel(type), name, |
| 4296 | StatsLog.WAKELOCK_STATE_CHANGED__STATE__ACQUIRE); |
Narayan Kamath | 8182202 | 2017-12-08 11:56:01 +0000 | [diff] [blame] | 4297 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4298 | } |
| 4299 | } |
| 4300 | |
Narayan Kamath | 8182202 | 2017-12-08 11:56:01 +0000 | [diff] [blame] | 4301 | public void noteStopWakeLocked(int uid, int pid, WorkChain wc, String name, String historyName, |
| 4302 | int type, long elapsedRealtime, long uptime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4303 | uid = mapUid(uid); |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 4304 | if (type == WAKE_TYPE_PARTIAL) { |
| 4305 | mWakeLockNesting--; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 4306 | if (mRecordAllHistory) { |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 4307 | if (historyName == null) { |
| 4308 | historyName = name; |
| 4309 | } |
| 4310 | if (mActiveEvents.updateState(HistoryItem.EVENT_WAKE_LOCK_FINISH, historyName, |
| 4311 | uid, 0)) { |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 4312 | addHistoryEventLocked(elapsedRealtime, uptime, |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 4313 | HistoryItem.EVENT_WAKE_LOCK_FINISH, historyName, uid); |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 4314 | } |
| 4315 | } |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 4316 | if (mWakeLockNesting == 0) { |
| 4317 | mHistoryCur.states &= ~HistoryItem.STATE_WAKE_LOCK_FLAG; |
| 4318 | if (DEBUG_HISTORY) Slog.v(TAG, "Stop wake lock to: " |
| 4319 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 4320 | mInitialAcquireWakeName = null; |
| 4321 | mInitialAcquireWakeUid = -1; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4322 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 4323 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4324 | } |
| 4325 | if (uid >= 0) { |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 4326 | if (mOnBatteryScreenOffTimeBase.isRunning()) { |
| 4327 | if (DEBUG_ENERGY_CPU) { |
| 4328 | Slog.d(TAG, "Updating cpu time because of -wake_lock"); |
| 4329 | } |
| 4330 | requestWakelockCpuUpdate(); |
| 4331 | } |
Narayan Kamath | 8182202 | 2017-12-08 11:56:01 +0000 | [diff] [blame] | 4332 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4333 | getUidStatsLocked(uid).noteStopWakeLocked(pid, name, type, elapsedRealtime); |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 4334 | if (wc != null) { |
Bookatz | 1a1b046 | 2018-01-12 11:47:03 -0800 | [diff] [blame] | 4335 | StatsLog.write(StatsLog.WAKELOCK_STATE_CHANGED, wc.getUids(), wc.getTags(), |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 4336 | getPowerManagerWakeLockLevel(type), name, |
| 4337 | StatsLog.WAKELOCK_STATE_CHANGED__STATE__RELEASE); |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 4338 | } else { |
Bookatz | 1a1b046 | 2018-01-12 11:47:03 -0800 | [diff] [blame] | 4339 | StatsLog.write_non_chained(StatsLog.WAKELOCK_STATE_CHANGED, uid, null, |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 4340 | getPowerManagerWakeLockLevel(type), name, |
| 4341 | StatsLog.WAKELOCK_STATE_CHANGED__STATE__RELEASE); |
Narayan Kamath | 8182202 | 2017-12-08 11:56:01 +0000 | [diff] [blame] | 4342 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4343 | } |
| 4344 | } |
| 4345 | |
Bookatz | 1a1b046 | 2018-01-12 11:47:03 -0800 | [diff] [blame] | 4346 | /** |
| 4347 | * Converts BatteryStats wakelock types back into PowerManager wakelock levels. |
| 4348 | * This is the inverse map of Notifier.getBatteryStatsWakeLockMonitorType(). |
| 4349 | * These are estimations, since batterystats loses some of the original data. |
| 4350 | * TODO: Delete this. Instead, StatsLog.write should be called from PowerManager's Notifier. |
| 4351 | */ |
| 4352 | private int getPowerManagerWakeLockLevel(int battertStatsWakelockType) { |
| 4353 | switch (battertStatsWakelockType) { |
| 4354 | // PowerManager.PARTIAL_WAKE_LOCK or PROXIMITY_SCREEN_OFF_WAKE_LOCK |
| 4355 | case BatteryStats.WAKE_TYPE_PARTIAL: |
| 4356 | return PowerManager.PARTIAL_WAKE_LOCK; |
| 4357 | |
| 4358 | // PowerManager.SCREEN_DIM_WAKE_LOCK or SCREEN_BRIGHT_WAKE_LOCK |
| 4359 | case BatteryStats.WAKE_TYPE_FULL: |
| 4360 | return PowerManager.FULL_WAKE_LOCK; |
| 4361 | |
| 4362 | case BatteryStats.WAKE_TYPE_DRAW: |
| 4363 | return PowerManager.DRAW_WAKE_LOCK; |
| 4364 | |
| 4365 | // It appears that nothing can ever make a Window and PowerManager lacks an equivalent. |
| 4366 | case BatteryStats.WAKE_TYPE_WINDOW: |
| 4367 | Slog.e(TAG, "Illegal window wakelock type observed in batterystats."); |
| 4368 | return -1; |
| 4369 | |
| 4370 | default: |
| 4371 | Slog.e(TAG, "Illegal wakelock type in batterystats: " + battertStatsWakelockType); |
| 4372 | return -1; |
| 4373 | } |
| 4374 | } |
| 4375 | |
Dianne Hackborn | a1f1a3c | 2014-02-24 18:12:28 -0800 | [diff] [blame] | 4376 | public void noteStartWakeFromSourceLocked(WorkSource ws, int pid, String name, |
| 4377 | String historyName, int type, boolean unimportantForLogging) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4378 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4379 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 4380 | final int N = ws.size(); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 4381 | for (int i=0; i<N; i++) { |
Narayan Kamath | 8182202 | 2017-12-08 11:56:01 +0000 | [diff] [blame] | 4382 | noteStartWakeLocked(ws.get(i), pid, null, name, historyName, type, |
| 4383 | unimportantForLogging, elapsedRealtime, uptime); |
| 4384 | } |
| 4385 | |
| 4386 | List<WorkChain> wcs = ws.getWorkChains(); |
| 4387 | if (wcs != null) { |
| 4388 | for (int i = 0; i < wcs.size(); ++i) { |
| 4389 | final WorkChain wc = wcs.get(i); |
| 4390 | noteStartWakeLocked(wc.getAttributionUid(), pid, wc, name, historyName, type, |
| 4391 | unimportantForLogging, elapsedRealtime, uptime); |
| 4392 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 4393 | } |
| 4394 | } |
| 4395 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4396 | public void noteChangeWakelockFromSourceLocked(WorkSource ws, int pid, String name, |
| 4397 | String historyName, int type, WorkSource newWs, int newPid, String newName, |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 4398 | String newHistoryName, int newType, boolean newUnimportantForLogging) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4399 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4400 | final long uptime = mClocks.uptimeMillis(); |
Narayan Kamath | 8182202 | 2017-12-08 11:56:01 +0000 | [diff] [blame] | 4401 | |
| 4402 | List<WorkChain>[] wcs = WorkSource.diffChains(ws, newWs); |
| 4403 | |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 4404 | // For correct semantics, we start the need worksources first, so that we won't |
| 4405 | // make inappropriate history items as if all wake locks went away and new ones |
| 4406 | // appeared. This is okay because tracking of wake locks allows nesting. |
Narayan Kamath | 8182202 | 2017-12-08 11:56:01 +0000 | [diff] [blame] | 4407 | // |
| 4408 | // First the starts : |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4409 | final int NN = newWs.size(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 4410 | for (int i=0; i<NN; i++) { |
Narayan Kamath | 8182202 | 2017-12-08 11:56:01 +0000 | [diff] [blame] | 4411 | noteStartWakeLocked(newWs.get(i), newPid, null, newName, newHistoryName, newType, |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4412 | newUnimportantForLogging, elapsedRealtime, uptime); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 4413 | } |
Narayan Kamath | 8182202 | 2017-12-08 11:56:01 +0000 | [diff] [blame] | 4414 | if (wcs != null) { |
| 4415 | List<WorkChain> newChains = wcs[0]; |
| 4416 | if (newChains != null) { |
| 4417 | for (int i = 0; i < newChains.size(); ++i) { |
| 4418 | final WorkChain newChain = newChains.get(i); |
| 4419 | noteStartWakeLocked(newChain.getAttributionUid(), newPid, newChain, newName, |
| 4420 | newHistoryName, newType, newUnimportantForLogging, elapsedRealtime, |
| 4421 | uptime); |
| 4422 | } |
| 4423 | } |
| 4424 | } |
| 4425 | |
| 4426 | // Then the stops : |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 4427 | final int NO = ws.size(); |
| 4428 | for (int i=0; i<NO; i++) { |
Narayan Kamath | 8182202 | 2017-12-08 11:56:01 +0000 | [diff] [blame] | 4429 | noteStopWakeLocked(ws.get(i), pid, null, name, historyName, type, elapsedRealtime, |
| 4430 | uptime); |
| 4431 | } |
| 4432 | if (wcs != null) { |
| 4433 | List<WorkChain> goneChains = wcs[1]; |
| 4434 | if (goneChains != null) { |
| 4435 | for (int i = 0; i < goneChains.size(); ++i) { |
| 4436 | final WorkChain goneChain = goneChains.get(i); |
| 4437 | noteStopWakeLocked(goneChain.getAttributionUid(), pid, goneChain, name, |
| 4438 | historyName, type, elapsedRealtime, uptime); |
| 4439 | } |
| 4440 | } |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 4441 | } |
| 4442 | } |
| 4443 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4444 | public void noteStopWakeFromSourceLocked(WorkSource ws, int pid, String name, |
| 4445 | String historyName, int type) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4446 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4447 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 4448 | final int N = ws.size(); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 4449 | for (int i=0; i<N; i++) { |
Narayan Kamath | 8182202 | 2017-12-08 11:56:01 +0000 | [diff] [blame] | 4450 | noteStopWakeLocked(ws.get(i), pid, null, name, historyName, type, elapsedRealtime, |
| 4451 | uptime); |
| 4452 | } |
| 4453 | |
| 4454 | List<WorkChain> wcs = ws.getWorkChains(); |
| 4455 | if (wcs != null) { |
| 4456 | for (int i = 0; i < wcs.size(); ++i) { |
| 4457 | final WorkChain wc = wcs.get(i); |
| 4458 | noteStopWakeLocked(wc.getAttributionUid(), pid, wc, name, historyName, type, |
| 4459 | elapsedRealtime, uptime); |
| 4460 | } |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 4461 | } |
| 4462 | } |
| 4463 | |
Dianne Hackborn | d0db6f0 | 2016-07-18 14:14:20 -0700 | [diff] [blame] | 4464 | public void noteLongPartialWakelockStart(String name, String historyName, int uid) { |
Yangster-mac | 2f5daec | 2018-01-16 10:23:15 -0800 | [diff] [blame] | 4465 | StatsLog.write_non_chained(StatsLog.LONG_PARTIAL_WAKELOCK_STATE_CHANGED, |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 4466 | uid, null, name, historyName, |
| 4467 | StatsLog.LONG_PARTIAL_WAKELOCK_STATE_CHANGED__STATE__ON); |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 4468 | |
Dianne Hackborn | d0db6f0 | 2016-07-18 14:14:20 -0700 | [diff] [blame] | 4469 | uid = mapUid(uid); |
Narayan Kamath | 96a9256 | 2018-01-02 18:57:17 +0000 | [diff] [blame] | 4470 | noteLongPartialWakeLockStartInternal(name, historyName, uid); |
Narayan Kamath | 96a9256 | 2018-01-02 18:57:17 +0000 | [diff] [blame] | 4471 | } |
| 4472 | |
| 4473 | public void noteLongPartialWakelockStartFromSource(String name, String historyName, |
| 4474 | WorkSource workSource) { |
| 4475 | final int N = workSource.size(); |
| 4476 | for (int i = 0; i < N; ++i) { |
| 4477 | final int uid = mapUid(workSource.get(i)); |
| 4478 | noteLongPartialWakeLockStartInternal(name, historyName, uid); |
Yangster-mac | 2f5daec | 2018-01-16 10:23:15 -0800 | [diff] [blame] | 4479 | StatsLog.write_non_chained(StatsLog.LONG_PARTIAL_WAKELOCK_STATE_CHANGED, |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 4480 | workSource.get(i), workSource.getName(i), name, historyName, |
| 4481 | StatsLog.LONG_PARTIAL_WAKELOCK_STATE_CHANGED__STATE__ON); |
Narayan Kamath | 96a9256 | 2018-01-02 18:57:17 +0000 | [diff] [blame] | 4482 | } |
| 4483 | |
| 4484 | final ArrayList<WorkChain> workChains = workSource.getWorkChains(); |
| 4485 | if (workChains != null) { |
| 4486 | for (int i = 0; i < workChains.size(); ++i) { |
| 4487 | final WorkChain workChain = workChains.get(i); |
| 4488 | final int uid = workChain.getAttributionUid(); |
| 4489 | noteLongPartialWakeLockStartInternal(name, historyName, uid); |
| 4490 | |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 4491 | StatsLog.write(StatsLog.LONG_PARTIAL_WAKELOCK_STATE_CHANGED, |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 4492 | workChain.getUids(), workChain.getTags(), name, historyName, |
| 4493 | StatsLog.LONG_PARTIAL_WAKELOCK_STATE_CHANGED__STATE__ON); |
Narayan Kamath | 96a9256 | 2018-01-02 18:57:17 +0000 | [diff] [blame] | 4494 | } |
| 4495 | } |
| 4496 | } |
| 4497 | |
| 4498 | private void noteLongPartialWakeLockStartInternal(String name, String historyName, int uid) { |
Dianne Hackborn | d0db6f0 | 2016-07-18 14:14:20 -0700 | [diff] [blame] | 4499 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4500 | final long uptime = mClocks.uptimeMillis(); |
| 4501 | if (historyName == null) { |
| 4502 | historyName = name; |
| 4503 | } |
| 4504 | if (!mActiveEvents.updateState(HistoryItem.EVENT_LONG_WAKE_LOCK_START, historyName, uid, |
| 4505 | 0)) { |
| 4506 | return; |
| 4507 | } |
| 4508 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_LONG_WAKE_LOCK_START, |
| 4509 | historyName, uid); |
| 4510 | } |
| 4511 | |
| 4512 | public void noteLongPartialWakelockFinish(String name, String historyName, int uid) { |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 4513 | StatsLog.write_non_chained(StatsLog.LONG_PARTIAL_WAKELOCK_STATE_CHANGED, uid, null, |
| 4514 | name, historyName, StatsLog.LONG_PARTIAL_WAKELOCK_STATE_CHANGED__STATE__OFF); |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 4515 | |
Dianne Hackborn | d0db6f0 | 2016-07-18 14:14:20 -0700 | [diff] [blame] | 4516 | uid = mapUid(uid); |
Narayan Kamath | 96a9256 | 2018-01-02 18:57:17 +0000 | [diff] [blame] | 4517 | noteLongPartialWakeLockFinishInternal(name, historyName, uid); |
Narayan Kamath | 96a9256 | 2018-01-02 18:57:17 +0000 | [diff] [blame] | 4518 | } |
| 4519 | |
| 4520 | public void noteLongPartialWakelockFinishFromSource(String name, String historyName, |
| 4521 | WorkSource workSource) { |
| 4522 | final int N = workSource.size(); |
| 4523 | for (int i = 0; i < N; ++i) { |
| 4524 | final int uid = mapUid(workSource.get(i)); |
| 4525 | noteLongPartialWakeLockFinishInternal(name, historyName, uid); |
Yangster-mac | 2f5daec | 2018-01-16 10:23:15 -0800 | [diff] [blame] | 4526 | StatsLog.write_non_chained(StatsLog.LONG_PARTIAL_WAKELOCK_STATE_CHANGED, |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 4527 | workSource.get(i), workSource.getName(i), name, historyName, |
| 4528 | StatsLog.LONG_PARTIAL_WAKELOCK_STATE_CHANGED__STATE__OFF); |
Narayan Kamath | 96a9256 | 2018-01-02 18:57:17 +0000 | [diff] [blame] | 4529 | } |
| 4530 | |
| 4531 | final ArrayList<WorkChain> workChains = workSource.getWorkChains(); |
| 4532 | if (workChains != null) { |
| 4533 | for (int i = 0; i < workChains.size(); ++i) { |
| 4534 | final WorkChain workChain = workChains.get(i); |
| 4535 | final int uid = workChain.getAttributionUid(); |
Narayan Kamath | 96a9256 | 2018-01-02 18:57:17 +0000 | [diff] [blame] | 4536 | noteLongPartialWakeLockFinishInternal(name, historyName, uid); |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 4537 | StatsLog.write(StatsLog.LONG_PARTIAL_WAKELOCK_STATE_CHANGED, |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 4538 | workChain.getUids(), workChain.getTags(), name, historyName, |
| 4539 | StatsLog.LONG_PARTIAL_WAKELOCK_STATE_CHANGED__STATE__OFF); |
Narayan Kamath | 96a9256 | 2018-01-02 18:57:17 +0000 | [diff] [blame] | 4540 | } |
| 4541 | } |
| 4542 | } |
| 4543 | |
| 4544 | private void noteLongPartialWakeLockFinishInternal(String name, String historyName, int uid) { |
Dianne Hackborn | d0db6f0 | 2016-07-18 14:14:20 -0700 | [diff] [blame] | 4545 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4546 | final long uptime = mClocks.uptimeMillis(); |
| 4547 | if (historyName == null) { |
| 4548 | historyName = name; |
| 4549 | } |
| 4550 | if (!mActiveEvents.updateState(HistoryItem.EVENT_LONG_WAKE_LOCK_FINISH, historyName, uid, |
| 4551 | 0)) { |
| 4552 | return; |
| 4553 | } |
| 4554 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_LONG_WAKE_LOCK_FINISH, |
| 4555 | historyName, uid); |
| 4556 | } |
| 4557 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4558 | void aggregateLastWakeupUptimeLocked(long uptimeMs) { |
| 4559 | if (mLastWakeupReason != null) { |
| 4560 | long deltaUptime = uptimeMs - mLastWakeupUptimeMs; |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 4561 | SamplingTimer timer = getWakeupReasonTimerLocked(mLastWakeupReason); |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 4562 | timer.add(deltaUptime * 1000, 1); // time in in microseconds |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 4563 | StatsLog.write(StatsLog.KERNEL_WAKEUP_REPORTED, mLastWakeupReason, |
| 4564 | /* duration_usec */ deltaUptime * 1000); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4565 | mLastWakeupReason = null; |
| 4566 | } |
| 4567 | } |
| 4568 | |
| 4569 | public void noteWakeupReasonLocked(String reason) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4570 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4571 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 4572 | if (DEBUG_HISTORY) Slog.v(TAG, "Wakeup reason \"" + reason +"\": " |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4573 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4574 | aggregateLastWakeupUptimeLocked(uptime); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4575 | mHistoryCur.wakeReasonTag = mHistoryCur.localWakeReasonTag; |
| 4576 | mHistoryCur.wakeReasonTag.string = reason; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4577 | mHistoryCur.wakeReasonTag.uid = 0; |
| 4578 | mLastWakeupReason = reason; |
| 4579 | mLastWakeupUptimeMs = uptime; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4580 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4581 | } |
| 4582 | |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 4583 | public boolean startAddingCpuLocked() { |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 4584 | mExternalSync.cancelCpuSyncDueToWakelockChange(); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 4585 | return mOnBatteryInternal; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 4586 | } |
| 4587 | |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 4588 | public void finishAddingCpuLocked(int totalUTime, int totalSTime, int statUserTime, |
| 4589 | int statSystemTime, int statIOWaitTime, int statIrqTime, |
| 4590 | int statSoftIrqTime, int statIdleTime) { |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 4591 | if (DEBUG) Slog.d(TAG, "Adding cpu: tuser=" + totalUTime + " tsys=" + totalSTime |
| 4592 | + " user=" + statUserTime + " sys=" + statSystemTime |
| 4593 | + " io=" + statIOWaitTime + " irq=" + statIrqTime |
| 4594 | + " sirq=" + statSoftIrqTime + " idle=" + statIdleTime); |
| 4595 | mCurStepCpuUserTime += totalUTime; |
| 4596 | mCurStepCpuSystemTime += totalSTime; |
| 4597 | mCurStepStatUserTime += statUserTime; |
| 4598 | mCurStepStatSystemTime += statSystemTime; |
| 4599 | mCurStepStatIOWaitTime += statIOWaitTime; |
| 4600 | mCurStepStatIrqTime += statIrqTime; |
| 4601 | mCurStepStatSoftIrqTime += statSoftIrqTime; |
| 4602 | mCurStepStatIdleTime += statIdleTime; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 4603 | } |
| 4604 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4605 | public void noteProcessDiedLocked(int uid, int pid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4606 | uid = mapUid(uid); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4607 | Uid u = mUidStats.get(uid); |
| 4608 | if (u != null) { |
| 4609 | u.mPids.remove(pid); |
| 4610 | } |
| 4611 | } |
| 4612 | |
| 4613 | public long getProcessWakeTime(int uid, int pid, long realtime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4614 | uid = mapUid(uid); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4615 | Uid u = mUidStats.get(uid); |
| 4616 | if (u != null) { |
| 4617 | Uid.Pid p = u.mPids.get(pid); |
| 4618 | if (p != null) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 4619 | return p.mWakeSumMs + (p.mWakeNesting > 0 ? (realtime - p.mWakeStartMs) : 0); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4620 | } |
| 4621 | } |
| 4622 | return 0; |
| 4623 | } |
| 4624 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 4625 | public void reportExcessiveCpuLocked(int uid, String proc, long overTime, long usedTime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4626 | uid = mapUid(uid); |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 4627 | Uid u = mUidStats.get(uid); |
| 4628 | if (u != null) { |
| 4629 | u.reportExcessiveCpuLocked(proc, overTime, usedTime); |
| 4630 | } |
| 4631 | } |
| 4632 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4633 | int mSensorNesting; |
| 4634 | |
| 4635 | public void noteStartSensorLocked(int uid, int sensor) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4636 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4637 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4638 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4639 | if (mSensorNesting == 0) { |
| 4640 | mHistoryCur.states |= HistoryItem.STATE_SENSOR_ON_FLAG; |
| 4641 | if (DEBUG_HISTORY) Slog.v(TAG, "Start sensor to: " |
| 4642 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4643 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4644 | } |
| 4645 | mSensorNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4646 | getUidStatsLocked(uid).noteStartSensor(sensor, elapsedRealtime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4647 | } |
| 4648 | |
| 4649 | public void noteStopSensorLocked(int uid, int sensor) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4650 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4651 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4652 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4653 | mSensorNesting--; |
| 4654 | if (mSensorNesting == 0) { |
| 4655 | mHistoryCur.states &= ~HistoryItem.STATE_SENSOR_ON_FLAG; |
| 4656 | if (DEBUG_HISTORY) Slog.v(TAG, "Stop sensor to: " |
| 4657 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4658 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4659 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4660 | getUidStatsLocked(uid).noteStopSensor(sensor, elapsedRealtime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4661 | } |
| 4662 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4663 | int mGpsNesting; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4664 | |
Narayan Kamath | 32684dd | 2018-01-08 17:32:51 +0000 | [diff] [blame] | 4665 | public void noteGpsChangedLocked(WorkSource oldWs, WorkSource newWs) { |
| 4666 | for (int i = 0; i < newWs.size(); ++i) { |
| 4667 | noteStartGpsLocked(newWs.get(i), null); |
| 4668 | } |
| 4669 | |
| 4670 | for (int i = 0; i < oldWs.size(); ++i) { |
| 4671 | noteStopGpsLocked((oldWs.get(i)), null); |
| 4672 | } |
| 4673 | |
| 4674 | List<WorkChain>[] wcs = WorkSource.diffChains(oldWs, newWs); |
| 4675 | if (wcs != null) { |
| 4676 | if (wcs[0] != null) { |
| 4677 | final List<WorkChain> newChains = wcs[0]; |
| 4678 | for (int i = 0; i < newChains.size(); ++i) { |
| 4679 | noteStartGpsLocked(-1, newChains.get(i)); |
| 4680 | } |
| 4681 | } |
| 4682 | |
| 4683 | if (wcs[1] != null) { |
| 4684 | final List<WorkChain> goneChains = wcs[1]; |
| 4685 | for (int i = 0; i < goneChains.size(); ++i) { |
| 4686 | noteStopGpsLocked(-1, goneChains.get(i)); |
| 4687 | } |
| 4688 | } |
| 4689 | } |
| 4690 | } |
| 4691 | |
| 4692 | private void noteStartGpsLocked(int uid, WorkChain workChain) { |
| 4693 | uid = getAttributionUid(uid, workChain); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4694 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4695 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4696 | if (mGpsNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4697 | mHistoryCur.states |= HistoryItem.STATE_GPS_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4698 | if (DEBUG_HISTORY) Slog.v(TAG, "Start GPS to: " |
| 4699 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4700 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4701 | } |
| 4702 | mGpsNesting++; |
Narayan Kamath | 32684dd | 2018-01-08 17:32:51 +0000 | [diff] [blame] | 4703 | |
| 4704 | if (workChain == null) { |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 4705 | StatsLog.write_non_chained(StatsLog.GPS_SCAN_STATE_CHANGED, uid, null, |
| 4706 | StatsLog.GPS_SCAN_STATE_CHANGED__STATE__ON); |
Narayan Kamath | 32684dd | 2018-01-08 17:32:51 +0000 | [diff] [blame] | 4707 | } else { |
| 4708 | StatsLog.write(StatsLog.GPS_SCAN_STATE_CHANGED, |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 4709 | workChain.getUids(), workChain.getTags(), |
| 4710 | StatsLog.GPS_SCAN_STATE_CHANGED__STATE__ON); |
Narayan Kamath | 32684dd | 2018-01-08 17:32:51 +0000 | [diff] [blame] | 4711 | } |
| 4712 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4713 | getUidStatsLocked(uid).noteStartGps(elapsedRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4714 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4715 | |
Narayan Kamath | 32684dd | 2018-01-08 17:32:51 +0000 | [diff] [blame] | 4716 | private void noteStopGpsLocked(int uid, WorkChain workChain) { |
| 4717 | uid = getAttributionUid(uid, workChain); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4718 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4719 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4720 | mGpsNesting--; |
| 4721 | if (mGpsNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4722 | mHistoryCur.states &= ~HistoryItem.STATE_GPS_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4723 | if (DEBUG_HISTORY) Slog.v(TAG, "Stop GPS to: " |
| 4724 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4725 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 4726 | stopAllGpsSignalQualityTimersLocked(-1); |
| 4727 | mGpsSignalQualityBin = -1; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4728 | } |
Narayan Kamath | 32684dd | 2018-01-08 17:32:51 +0000 | [diff] [blame] | 4729 | |
| 4730 | if (workChain == null) { |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 4731 | StatsLog.write_non_chained(StatsLog.GPS_SCAN_STATE_CHANGED, uid, null, |
| 4732 | StatsLog.GPS_SCAN_STATE_CHANGED__STATE__OFF); |
Narayan Kamath | 32684dd | 2018-01-08 17:32:51 +0000 | [diff] [blame] | 4733 | } else { |
| 4734 | StatsLog.write(StatsLog.GPS_SCAN_STATE_CHANGED, workChain.getUids(), |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 4735 | workChain.getTags(), StatsLog.GPS_SCAN_STATE_CHANGED__STATE__OFF); |
Narayan Kamath | 32684dd | 2018-01-08 17:32:51 +0000 | [diff] [blame] | 4736 | } |
| 4737 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4738 | getUidStatsLocked(uid).noteStopGps(elapsedRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4739 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 4740 | |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 4741 | public void noteGpsSignalQualityLocked(int signalLevel) { |
| 4742 | if (mGpsNesting == 0) { |
| 4743 | return; |
| 4744 | } |
| 4745 | if (signalLevel < 0 || signalLevel >= GnssMetrics.NUM_GPS_SIGNAL_QUALITY_LEVELS) { |
| 4746 | stopAllGpsSignalQualityTimersLocked(-1); |
| 4747 | return; |
| 4748 | } |
| 4749 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4750 | final long uptime = mClocks.uptimeMillis(); |
| 4751 | if (mGpsSignalQualityBin != signalLevel) { |
| 4752 | if (mGpsSignalQualityBin >= 0) { |
| 4753 | mGpsSignalQualityTimer[mGpsSignalQualityBin].stopRunningLocked(elapsedRealtime); |
| 4754 | } |
| 4755 | if(!mGpsSignalQualityTimer[signalLevel].isRunningLocked()) { |
| 4756 | mGpsSignalQualityTimer[signalLevel].startRunningLocked(elapsedRealtime); |
| 4757 | } |
| 4758 | mHistoryCur.states2 = (mHistoryCur.states2&~HistoryItem.STATE2_GPS_SIGNAL_QUALITY_MASK) |
| 4759 | | (signalLevel << HistoryItem.STATE2_GPS_SIGNAL_QUALITY_SHIFT); |
| 4760 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4761 | mGpsSignalQualityBin = signalLevel; |
| 4762 | } |
| 4763 | return; |
| 4764 | } |
| 4765 | |
Andreas Gampe | 3f24e69 | 2018-02-05 13:24:28 -0800 | [diff] [blame] | 4766 | @GuardedBy("this") |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4767 | public void noteScreenStateLocked(int state) { |
Amith Yamasani | 674c9bb | 2017-02-01 09:45:17 -0800 | [diff] [blame] | 4768 | state = mPretendScreenOff ? Display.STATE_OFF : state; |
Santos Cordon | e94f050 | 2017-02-24 12:31:20 -0800 | [diff] [blame] | 4769 | |
| 4770 | // Battery stats relies on there being 4 states. To accommodate this, new states beyond the |
| 4771 | // original 4 are mapped to one of the originals. |
| 4772 | if (state > MAX_TRACKED_SCREEN_STATE) { |
| 4773 | switch (state) { |
| 4774 | case Display.STATE_VR: |
| 4775 | state = Display.STATE_ON; |
| 4776 | break; |
| 4777 | default: |
| 4778 | Slog.wtf(TAG, "Unknown screen state (not mapped): " + state); |
| 4779 | break; |
| 4780 | } |
| 4781 | } |
| 4782 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4783 | if (mScreenState != state) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 4784 | recordDailyStatsIfNeededLocked(true); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4785 | final int oldState = mScreenState; |
| 4786 | mScreenState = state; |
| 4787 | if (DEBUG) Slog.v(TAG, "Screen state: oldState=" + Display.stateToString(oldState) |
| 4788 | + ", newState=" + Display.stateToString(state)); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4789 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 4790 | if (state != Display.STATE_UNKNOWN) { |
| 4791 | int stepState = state-1; |
Santos Cordon | e94f050 | 2017-02-24 12:31:20 -0800 | [diff] [blame] | 4792 | if ((stepState & STEP_LEVEL_MODE_SCREEN_STATE) == stepState) { |
| 4793 | mModStepMode |= (mCurStepMode & STEP_LEVEL_MODE_SCREEN_STATE) ^ stepState; |
| 4794 | mCurStepMode = (mCurStepMode & ~STEP_LEVEL_MODE_SCREEN_STATE) | stepState; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 4795 | } else { |
| 4796 | Slog.wtf(TAG, "Unexpected screen state: " + state); |
| 4797 | } |
| 4798 | } |
| 4799 | |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4800 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4801 | final long uptime = mClocks.uptimeMillis(); |
| 4802 | |
| 4803 | boolean updateHistory = false; |
| 4804 | if (isScreenDoze(state)) { |
| 4805 | mHistoryCur.states |= HistoryItem.STATE_SCREEN_DOZE_FLAG; |
| 4806 | mScreenDozeTimer.startRunningLocked(elapsedRealtime); |
| 4807 | updateHistory = true; |
| 4808 | } else if (isScreenDoze(oldState)) { |
| 4809 | mHistoryCur.states &= ~HistoryItem.STATE_SCREEN_DOZE_FLAG; |
| 4810 | mScreenDozeTimer.stopRunningLocked(elapsedRealtime); |
| 4811 | updateHistory = true; |
| 4812 | } |
| 4813 | if (isScreenOn(state)) { |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4814 | mHistoryCur.states |= HistoryItem.STATE_SCREEN_ON_FLAG; |
| 4815 | if (DEBUG_HISTORY) Slog.v(TAG, "Screen on to: " |
| 4816 | + Integer.toHexString(mHistoryCur.states)); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4817 | mScreenOnTimer.startRunningLocked(elapsedRealtime); |
| 4818 | if (mScreenBrightnessBin >= 0) { |
| 4819 | mScreenBrightnessTimer[mScreenBrightnessBin].startRunningLocked(elapsedRealtime); |
| 4820 | } |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4821 | updateHistory = true; |
| 4822 | } else if (isScreenOn(oldState)) { |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4823 | mHistoryCur.states &= ~HistoryItem.STATE_SCREEN_ON_FLAG; |
| 4824 | if (DEBUG_HISTORY) Slog.v(TAG, "Screen off to: " |
| 4825 | + Integer.toHexString(mHistoryCur.states)); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4826 | mScreenOnTimer.stopRunningLocked(elapsedRealtime); |
| 4827 | if (mScreenBrightnessBin >= 0) { |
| 4828 | mScreenBrightnessTimer[mScreenBrightnessBin].stopRunningLocked(elapsedRealtime); |
| 4829 | } |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4830 | updateHistory = true; |
| 4831 | } |
| 4832 | if (updateHistory) { |
| 4833 | if (DEBUG_HISTORY) Slog.v(TAG, "Screen state to: " |
| 4834 | + Display.stateToString(state)); |
| 4835 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4836 | } |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 4837 | mExternalSync.scheduleCpuSyncDueToScreenStateChange( |
| 4838 | mOnBatteryTimeBase.isRunning(), mOnBatteryScreenOffTimeBase.isRunning()); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4839 | if (isScreenOn(state)) { |
| 4840 | updateTimeBasesLocked(mOnBatteryTimeBase.isRunning(), state, |
| 4841 | mClocks.uptimeMillis() * 1000, elapsedRealtime * 1000); |
| 4842 | // 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] | 4843 | noteStartWakeLocked(-1, -1, null, "screen", null, WAKE_TYPE_PARTIAL, false, |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4844 | elapsedRealtime, uptime); |
| 4845 | } else if (isScreenOn(oldState)) { |
Narayan Kamath | 8182202 | 2017-12-08 11:56:01 +0000 | [diff] [blame] | 4846 | noteStopWakeLocked(-1, -1, null, "screen", "screen", WAKE_TYPE_PARTIAL, |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4847 | elapsedRealtime, uptime); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4848 | updateTimeBasesLocked(mOnBatteryTimeBase.isRunning(), state, |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4849 | mClocks.uptimeMillis() * 1000, elapsedRealtime * 1000); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4850 | } |
| 4851 | // Update discharge amounts. |
| 4852 | if (mOnBatteryInternal) { |
| 4853 | updateDischargeScreenLevelsLocked(oldState, state); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 4854 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4855 | } |
| 4856 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4857 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4858 | public void noteScreenBrightnessLocked(int brightness) { |
| 4859 | // Bin the brightness. |
| 4860 | int bin = brightness / (256/NUM_SCREEN_BRIGHTNESS_BINS); |
| 4861 | if (bin < 0) bin = 0; |
| 4862 | else if (bin >= NUM_SCREEN_BRIGHTNESS_BINS) bin = NUM_SCREEN_BRIGHTNESS_BINS-1; |
| 4863 | if (mScreenBrightnessBin != bin) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4864 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4865 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4866 | mHistoryCur.states = (mHistoryCur.states&~HistoryItem.STATE_BRIGHTNESS_MASK) |
| 4867 | | (bin << HistoryItem.STATE_BRIGHTNESS_SHIFT); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4868 | if (DEBUG_HISTORY) Slog.v(TAG, "Screen brightness " + bin + " to: " |
| 4869 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4870 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4871 | if (mScreenState == Display.STATE_ON) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4872 | if (mScreenBrightnessBin >= 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4873 | mScreenBrightnessTimer[mScreenBrightnessBin].stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4874 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4875 | mScreenBrightnessTimer[bin].startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4876 | } |
| 4877 | mScreenBrightnessBin = bin; |
| 4878 | } |
| 4879 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4880 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4881 | public void noteUserActivityLocked(int uid, int event) { |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4882 | if (mOnBatteryInternal) { |
| 4883 | uid = mapUid(uid); |
| 4884 | getUidStatsLocked(uid).noteUserActivityLocked(event); |
| 4885 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4886 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4887 | |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 4888 | public void noteWakeUpLocked(String reason, int reasonUid) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4889 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4890 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 4891 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_SCREEN_WAKE_UP, |
| 4892 | reason, reasonUid); |
| 4893 | } |
| 4894 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4895 | public void noteInteractiveLocked(boolean interactive) { |
| 4896 | if (mInteractive != interactive) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4897 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4898 | mInteractive = interactive; |
| 4899 | if (DEBUG) Slog.v(TAG, "Interactive: " + interactive); |
| 4900 | if (interactive) { |
| 4901 | mInteractiveTimer.startRunningLocked(elapsedRealtime); |
| 4902 | } else { |
| 4903 | mInteractiveTimer.stopRunningLocked(elapsedRealtime); |
| 4904 | } |
| 4905 | } |
| 4906 | } |
| 4907 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 4908 | public void noteConnectivityChangedLocked(int type, String extra) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4909 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4910 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 4911 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_CONNECTIVITY_CHANGED, |
| 4912 | extra, type); |
| 4913 | mNumConnectivityChange++; |
| 4914 | } |
| 4915 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 4916 | private void noteMobileRadioApWakeupLocked(final long elapsedRealtimeMillis, |
| 4917 | final long uptimeMillis, int uid) { |
| 4918 | uid = mapUid(uid); |
| 4919 | addHistoryEventLocked(elapsedRealtimeMillis, uptimeMillis, HistoryItem.EVENT_WAKEUP_AP, "", |
| 4920 | uid); |
| 4921 | getUidStatsLocked(uid).noteMobileRadioApWakeupLocked(); |
| 4922 | } |
| 4923 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 4924 | /** |
| 4925 | * Updates the radio power state and returns true if an external stats collection should occur. |
| 4926 | */ |
| 4927 | public boolean noteMobileRadioPowerStateLocked(int powerState, long timestampNs, int uid) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4928 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4929 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 4930 | if (mMobileRadioPowerState != powerState) { |
| 4931 | long realElapsedRealtimeMs; |
| 4932 | final boolean active = |
| 4933 | powerState == DataConnectionRealTimeInfo.DC_POWER_STATE_MEDIUM |
| 4934 | || powerState == DataConnectionRealTimeInfo.DC_POWER_STATE_HIGH; |
| 4935 | if (active) { |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 4936 | if (uid > 0) { |
| 4937 | noteMobileRadioApWakeupLocked(elapsedRealtime, uptime, uid); |
| 4938 | } |
| 4939 | |
Adam Lesinski | 9acfd81 | 2016-04-19 18:29:50 -0700 | [diff] [blame] | 4940 | mMobileRadioActiveStartTime = realElapsedRealtimeMs = timestampNs / (1000 * 1000); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 4941 | mHistoryCur.states |= HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG; |
| 4942 | } else { |
| 4943 | realElapsedRealtimeMs = timestampNs / (1000*1000); |
Dianne Hackborn | f7097a5 | 2014-05-13 09:56:14 -0700 | [diff] [blame] | 4944 | long lastUpdateTimeMs = mMobileRadioActiveStartTime; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 4945 | if (realElapsedRealtimeMs < lastUpdateTimeMs) { |
| 4946 | Slog.wtf(TAG, "Data connection inactive timestamp " + realElapsedRealtimeMs |
| 4947 | + " is before start time " + lastUpdateTimeMs); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4948 | realElapsedRealtimeMs = elapsedRealtime; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 4949 | } else if (realElapsedRealtimeMs < elapsedRealtime) { |
| 4950 | mMobileRadioActiveAdjustedTime.addCountLocked(elapsedRealtime |
| 4951 | - realElapsedRealtimeMs); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4952 | } |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 4953 | mHistoryCur.states &= ~HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG; |
| 4954 | } |
| 4955 | if (DEBUG_HISTORY) Slog.v(TAG, "Mobile network active " + active + " to: " |
| 4956 | + Integer.toHexString(mHistoryCur.states)); |
| 4957 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4958 | mMobileRadioPowerState = powerState; |
Bookatz | ddccf0a | 2017-11-28 16:48:14 -0800 | [diff] [blame] | 4959 | StatsLog.write(StatsLog.MOBILE_RADIO_POWER_STATE_CHANGED, uid, powerState); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 4960 | if (active) { |
| 4961 | mMobileRadioActiveTimer.startRunningLocked(elapsedRealtime); |
| 4962 | mMobileRadioActivePerAppTimer.startRunningLocked(elapsedRealtime); |
| 4963 | } else { |
| 4964 | mMobileRadioActiveTimer.stopRunningLocked(realElapsedRealtimeMs); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 4965 | mMobileRadioActivePerAppTimer.stopRunningLocked(realElapsedRealtimeMs); |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 4966 | // Tell the caller to collect radio network/power stats. |
| 4967 | return true; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 4968 | } |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 4969 | } |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 4970 | return false; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 4971 | } |
| 4972 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 4973 | public void notePowerSaveModeLocked(boolean enabled) { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4974 | if (mPowerSaveModeEnabled != enabled) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 4975 | int stepState = enabled ? STEP_LEVEL_MODE_POWER_SAVE : 0; |
| 4976 | mModStepMode |= (mCurStepMode&STEP_LEVEL_MODE_POWER_SAVE) ^ stepState; |
| 4977 | mCurStepMode = (mCurStepMode&~STEP_LEVEL_MODE_POWER_SAVE) | stepState; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4978 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4979 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4980 | mPowerSaveModeEnabled = enabled; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4981 | if (enabled) { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4982 | mHistoryCur.states2 |= HistoryItem.STATE2_POWER_SAVE_FLAG; |
| 4983 | if (DEBUG_HISTORY) Slog.v(TAG, "Power save mode enabled to: " |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4984 | + Integer.toHexString(mHistoryCur.states2)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4985 | mPowerSaveModeEnabledTimer.startRunningLocked(elapsedRealtime); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4986 | } else { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4987 | mHistoryCur.states2 &= ~HistoryItem.STATE2_POWER_SAVE_FLAG; |
| 4988 | if (DEBUG_HISTORY) Slog.v(TAG, "Power save mode disabled to: " |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4989 | + Integer.toHexString(mHistoryCur.states2)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4990 | mPowerSaveModeEnabledTimer.stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4991 | } |
| 4992 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 4993 | StatsLog.write(StatsLog.BATTERY_SAVER_MODE_STATE_CHANGED, enabled ? |
| 4994 | StatsLog.BATTERY_SAVER_MODE_STATE_CHANGED__STATE__ON : |
| 4995 | StatsLog.BATTERY_SAVER_MODE_STATE_CHANGED__STATE__OFF); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4996 | } |
| 4997 | } |
| 4998 | |
Bookatz | ddccf0a | 2017-11-28 16:48:14 -0800 | [diff] [blame] | 4999 | public void noteDeviceIdleModeLocked(final int mode, String activeReason, int activeUid) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5000 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5001 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 5002 | boolean nowIdling = mode == DEVICE_IDLE_MODE_DEEP; |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 5003 | if (mDeviceIdling && !nowIdling && activeReason == null) { |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5004 | // We don't go out of general idling mode until explicitly taken out of |
| 5005 | // device idle through going active or significant motion. |
| 5006 | nowIdling = true; |
| 5007 | } |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 5008 | boolean nowLightIdling = mode == DEVICE_IDLE_MODE_LIGHT; |
| 5009 | if (mDeviceLightIdling && !nowLightIdling && !nowIdling && activeReason == null) { |
| 5010 | // We don't go out of general light idling mode until explicitly taken out of |
| 5011 | // device idle through going active or significant motion. |
| 5012 | nowLightIdling = true; |
| 5013 | } |
| 5014 | if (activeReason != null && (mDeviceIdling || mDeviceLightIdling)) { |
| 5015 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_ACTIVE, |
| 5016 | activeReason, activeUid); |
| 5017 | } |
Bookatz | ddccf0a | 2017-11-28 16:48:14 -0800 | [diff] [blame] | 5018 | if (mDeviceIdling != nowIdling || mDeviceLightIdling != nowLightIdling) { |
| 5019 | int statsmode; |
| 5020 | if (nowIdling) statsmode = DEVICE_IDLE_MODE_DEEP; |
| 5021 | else if (nowLightIdling) statsmode = DEVICE_IDLE_MODE_LIGHT; |
| 5022 | else statsmode = DEVICE_IDLE_MODE_OFF; |
| 5023 | StatsLog.write(StatsLog.DEVICE_IDLING_MODE_STATE_CHANGED, statsmode); |
| 5024 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5025 | if (mDeviceIdling != nowIdling) { |
| 5026 | mDeviceIdling = nowIdling; |
| 5027 | int stepState = nowIdling ? STEP_LEVEL_MODE_DEVICE_IDLE : 0; |
| 5028 | mModStepMode |= (mCurStepMode&STEP_LEVEL_MODE_DEVICE_IDLE) ^ stepState; |
| 5029 | mCurStepMode = (mCurStepMode&~STEP_LEVEL_MODE_DEVICE_IDLE) | stepState; |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 5030 | if (nowIdling) { |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5031 | mDeviceIdlingTimer.startRunningLocked(elapsedRealtime); |
| 5032 | } else { |
| 5033 | mDeviceIdlingTimer.stopRunningLocked(elapsedRealtime); |
| 5034 | } |
| 5035 | } |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 5036 | if (mDeviceLightIdling != nowLightIdling) { |
| 5037 | mDeviceLightIdling = nowLightIdling; |
| 5038 | if (nowLightIdling) { |
| 5039 | mDeviceLightIdlingTimer.startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 5040 | } else { |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 5041 | mDeviceLightIdlingTimer.stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 5042 | } |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 5043 | } |
| 5044 | if (mDeviceIdleMode != mode) { |
| 5045 | mHistoryCur.states2 = (mHistoryCur.states2 & ~HistoryItem.STATE2_DEVICE_IDLE_MASK) |
| 5046 | | (mode << HistoryItem.STATE2_DEVICE_IDLE_SHIFT); |
| 5047 | if (DEBUG_HISTORY) Slog.v(TAG, "Device idle mode changed to: " |
| 5048 | + Integer.toHexString(mHistoryCur.states2)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 5049 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 5050 | long lastDuration = elapsedRealtime - mLastIdleTimeStart; |
| 5051 | mLastIdleTimeStart = elapsedRealtime; |
| 5052 | if (mDeviceIdleMode == DEVICE_IDLE_MODE_LIGHT) { |
| 5053 | if (lastDuration > mLongestLightIdleTime) { |
| 5054 | mLongestLightIdleTime = lastDuration; |
| 5055 | } |
| 5056 | mDeviceIdleModeLightTimer.stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 5057 | } else if (mDeviceIdleMode == DEVICE_IDLE_MODE_DEEP) { |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 5058 | if (lastDuration > mLongestFullIdleTime) { |
| 5059 | mLongestFullIdleTime = lastDuration; |
| 5060 | } |
| 5061 | mDeviceIdleModeFullTimer.stopRunningLocked(elapsedRealtime); |
| 5062 | } |
| 5063 | if (mode == DEVICE_IDLE_MODE_LIGHT) { |
| 5064 | mDeviceIdleModeLightTimer.startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 5065 | } else if (mode == DEVICE_IDLE_MODE_DEEP) { |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 5066 | mDeviceIdleModeFullTimer.startRunningLocked(elapsedRealtime); |
| 5067 | } |
| 5068 | mDeviceIdleMode = mode; |
Bookatz | ddccf0a | 2017-11-28 16:48:14 -0800 | [diff] [blame] | 5069 | StatsLog.write(StatsLog.DEVICE_IDLE_MODE_STATE_CHANGED, mode); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 5070 | } |
| 5071 | } |
| 5072 | |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 5073 | public void notePackageInstalledLocked(String pkgName, long versionCode) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5074 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5075 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 5076 | // XXX need to figure out what to do with long version codes. |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 5077 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_PACKAGE_INSTALLED, |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 5078 | pkgName, (int)versionCode); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5079 | PackageChange pc = new PackageChange(); |
| 5080 | pc.mPackageName = pkgName; |
| 5081 | pc.mUpdate = true; |
| 5082 | pc.mVersionCode = versionCode; |
| 5083 | addPackageChange(pc); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 5084 | } |
| 5085 | |
| 5086 | public void notePackageUninstalledLocked(String pkgName) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5087 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5088 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 5089 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_PACKAGE_UNINSTALLED, |
| 5090 | pkgName, 0); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5091 | PackageChange pc = new PackageChange(); |
| 5092 | pc.mPackageName = pkgName; |
| 5093 | pc.mUpdate = true; |
| 5094 | addPackageChange(pc); |
| 5095 | } |
| 5096 | |
| 5097 | private void addPackageChange(PackageChange pc) { |
| 5098 | if (mDailyPackageChanges == null) { |
| 5099 | mDailyPackageChanges = new ArrayList<>(); |
| 5100 | } |
| 5101 | mDailyPackageChanges.add(pc); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 5102 | } |
| 5103 | |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 5104 | void stopAllGpsSignalQualityTimersLocked(int except) { |
| 5105 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5106 | for (int i = 0; i < GnssMetrics.NUM_GPS_SIGNAL_QUALITY_LEVELS; i++) { |
| 5107 | if (i == except) { |
| 5108 | continue; |
| 5109 | } |
| 5110 | while (mGpsSignalQualityTimer[i].isRunningLocked()) { |
| 5111 | mGpsSignalQualityTimer[i].stopRunningLocked(elapsedRealtime); |
| 5112 | } |
| 5113 | } |
| 5114 | } |
| 5115 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5116 | public void notePhoneOnLocked() { |
| 5117 | if (!mPhoneOn) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5118 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5119 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 5120 | mHistoryCur.states2 |= HistoryItem.STATE2_PHONE_IN_CALL_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5121 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone on to: " |
| 5122 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 5123 | addHistoryRecordLocked(elapsedRealtime, uptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5124 | mPhoneOn = true; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5125 | mPhoneOnTimer.startRunningLocked(elapsedRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5126 | } |
| 5127 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5128 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5129 | public void notePhoneOffLocked() { |
| 5130 | if (mPhoneOn) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5131 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5132 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 5133 | mHistoryCur.states2 &= ~HistoryItem.STATE2_PHONE_IN_CALL_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5134 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone off to: " |
| 5135 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 5136 | addHistoryRecordLocked(elapsedRealtime, uptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5137 | mPhoneOn = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5138 | mPhoneOnTimer.stopRunningLocked(elapsedRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5139 | } |
| 5140 | } |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 5141 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5142 | void stopAllPhoneSignalStrengthTimersLocked(int except) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5143 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 5144 | for (int i = 0; i < SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 5145 | if (i == except) { |
| 5146 | continue; |
| 5147 | } |
| 5148 | while (mPhoneSignalStrengthsTimer[i].isRunningLocked()) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5149 | mPhoneSignalStrengthsTimer[i].stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 5150 | } |
| 5151 | } |
| 5152 | } |
| 5153 | |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5154 | private int fixPhoneServiceState(int state, int signalBin) { |
| 5155 | if (mPhoneSimStateRaw == TelephonyManager.SIM_STATE_ABSENT) { |
| 5156 | // In this case we will always be STATE_OUT_OF_SERVICE, so need |
| 5157 | // to infer that we are scanning from other data. |
| 5158 | if (state == ServiceState.STATE_OUT_OF_SERVICE |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 5159 | && signalBin > SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5160 | state = ServiceState.STATE_IN_SERVICE; |
| 5161 | } |
| 5162 | } |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 5163 | |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5164 | return state; |
| 5165 | } |
| 5166 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5167 | private void updateAllPhoneStateLocked(int state, int simState, int strengthBin) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5168 | boolean scanning = false; |
| 5169 | boolean newHistory = false; |
| 5170 | |
| 5171 | mPhoneServiceStateRaw = state; |
| 5172 | mPhoneSimStateRaw = simState; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5173 | mPhoneSignalStrengthBinRaw = strengthBin; |
| 5174 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5175 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5176 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5177 | |
| 5178 | if (simState == TelephonyManager.SIM_STATE_ABSENT) { |
| 5179 | // In this case we will always be STATE_OUT_OF_SERVICE, so need |
| 5180 | // to infer that we are scanning from other data. |
| 5181 | if (state == ServiceState.STATE_OUT_OF_SERVICE |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5182 | && strengthBin > SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5183 | state = ServiceState.STATE_IN_SERVICE; |
| 5184 | } |
| 5185 | } |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 5186 | |
| 5187 | // If the phone is powered off, stop all timers. |
| 5188 | if (state == ServiceState.STATE_POWER_OFF) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5189 | strengthBin = -1; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 5190 | |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5191 | // If we are in service, make sure the correct signal string timer is running. |
| 5192 | } else if (state == ServiceState.STATE_IN_SERVICE) { |
| 5193 | // Bin will be changed below. |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 5194 | |
| 5195 | // If we're out of service, we are in the lowest signal strength |
| 5196 | // bin and have the scanning bit set. |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 5197 | } else if (state == ServiceState.STATE_OUT_OF_SERVICE) { |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 5198 | scanning = true; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5199 | strengthBin = SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 5200 | if (!mPhoneSignalScanningTimer.isRunningLocked()) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5201 | mHistoryCur.states |= HistoryItem.STATE_PHONE_SCANNING_FLAG; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5202 | newHistory = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5203 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone started scanning to: " |
| 5204 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5205 | mPhoneSignalScanningTimer.startRunningLocked(elapsedRealtime); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 5206 | } |
| 5207 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5208 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 5209 | if (!scanning) { |
| 5210 | // If we are no longer scanning, then stop the scanning timer. |
| 5211 | if (mPhoneSignalScanningTimer.isRunningLocked()) { |
| 5212 | mHistoryCur.states &= ~HistoryItem.STATE_PHONE_SCANNING_FLAG; |
| 5213 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone stopped scanning to: " |
| 5214 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5215 | newHistory = true; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5216 | mPhoneSignalScanningTimer.stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 5217 | } |
| 5218 | } |
| 5219 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5220 | if (mPhoneServiceState != state) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5221 | mHistoryCur.states = (mHistoryCur.states&~HistoryItem.STATE_PHONE_STATE_MASK) |
| 5222 | | (state << HistoryItem.STATE_PHONE_STATE_SHIFT); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5223 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone state " + state + " to: " |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5224 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5225 | newHistory = true; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5226 | mPhoneServiceState = state; |
| 5227 | } |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5228 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5229 | if (mPhoneSignalStrengthBin != strengthBin) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5230 | if (mPhoneSignalStrengthBin >= 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5231 | mPhoneSignalStrengthsTimer[mPhoneSignalStrengthBin].stopRunningLocked( |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5232 | elapsedRealtime); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5233 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5234 | if (strengthBin >= 0) { |
| 5235 | if (!mPhoneSignalStrengthsTimer[strengthBin].isRunningLocked()) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5236 | mPhoneSignalStrengthsTimer[strengthBin].startRunningLocked(elapsedRealtime); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5237 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5238 | mHistoryCur.states = (mHistoryCur.states&~HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_MASK) |
| 5239 | | (strengthBin << HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_SHIFT); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5240 | if (DEBUG_HISTORY) Slog.v(TAG, "Signal strength " + strengthBin + " to: " |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5241 | + Integer.toHexString(mHistoryCur.states)); |
| 5242 | newHistory = true; |
Bookatz | e588524 | 2017-10-24 20:10:31 -0700 | [diff] [blame] | 5243 | StatsLog.write(StatsLog.PHONE_SIGNAL_STRENGTH_CHANGED, strengthBin); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5244 | } else { |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5245 | stopAllPhoneSignalStrengthTimersLocked(-1); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5246 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5247 | mPhoneSignalStrengthBin = strengthBin; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5248 | } |
| 5249 | |
| 5250 | if (newHistory) { |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 5251 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5252 | } |
| 5253 | } |
| 5254 | |
| 5255 | /** |
| 5256 | * Telephony stack updates the phone state. |
| 5257 | * @param state phone state from ServiceState.getState() |
| 5258 | */ |
| 5259 | public void notePhoneStateLocked(int state, int simState) { |
| 5260 | updateAllPhoneStateLocked(state, simState, mPhoneSignalStrengthBinRaw); |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 5261 | } |
| 5262 | |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 5263 | public void notePhoneSignalStrengthLocked(SignalStrength signalStrength) { |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 5264 | // Bin the strength. |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 5265 | int bin = signalStrength.getLevel(); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5266 | updateAllPhoneStateLocked(mPhoneServiceStateRaw, mPhoneSimStateRaw, bin); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 5267 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5268 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 5269 | public void notePhoneDataConnectionStateLocked(int dataType, boolean hasData) { |
| 5270 | int bin = DATA_CONNECTION_NONE; |
| 5271 | if (hasData) { |
| 5272 | switch (dataType) { |
| 5273 | case TelephonyManager.NETWORK_TYPE_EDGE: |
| 5274 | bin = DATA_CONNECTION_EDGE; |
| 5275 | break; |
| 5276 | case TelephonyManager.NETWORK_TYPE_GPRS: |
| 5277 | bin = DATA_CONNECTION_GPRS; |
| 5278 | break; |
| 5279 | case TelephonyManager.NETWORK_TYPE_UMTS: |
| 5280 | bin = DATA_CONNECTION_UMTS; |
| 5281 | break; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5282 | case TelephonyManager.NETWORK_TYPE_CDMA: |
| 5283 | bin = DATA_CONNECTION_CDMA; |
| 5284 | break; |
| 5285 | case TelephonyManager.NETWORK_TYPE_EVDO_0: |
| 5286 | bin = DATA_CONNECTION_EVDO_0; |
| 5287 | break; |
| 5288 | case TelephonyManager.NETWORK_TYPE_EVDO_A: |
| 5289 | bin = DATA_CONNECTION_EVDO_A; |
| 5290 | break; |
| 5291 | case TelephonyManager.NETWORK_TYPE_1xRTT: |
| 5292 | bin = DATA_CONNECTION_1xRTT; |
| 5293 | break; |
| 5294 | case TelephonyManager.NETWORK_TYPE_HSDPA: |
| 5295 | bin = DATA_CONNECTION_HSDPA; |
| 5296 | break; |
| 5297 | case TelephonyManager.NETWORK_TYPE_HSUPA: |
| 5298 | bin = DATA_CONNECTION_HSUPA; |
| 5299 | break; |
| 5300 | case TelephonyManager.NETWORK_TYPE_HSPA: |
| 5301 | bin = DATA_CONNECTION_HSPA; |
| 5302 | break; |
| 5303 | case TelephonyManager.NETWORK_TYPE_IDEN: |
| 5304 | bin = DATA_CONNECTION_IDEN; |
| 5305 | break; |
| 5306 | case TelephonyManager.NETWORK_TYPE_EVDO_B: |
| 5307 | bin = DATA_CONNECTION_EVDO_B; |
| 5308 | break; |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 5309 | case TelephonyManager.NETWORK_TYPE_LTE: |
| 5310 | bin = DATA_CONNECTION_LTE; |
| 5311 | break; |
| 5312 | case TelephonyManager.NETWORK_TYPE_EHRPD: |
| 5313 | bin = DATA_CONNECTION_EHRPD; |
| 5314 | break; |
Patrick Tjin | b71703c | 2013-11-06 09:27:03 -0800 | [diff] [blame] | 5315 | case TelephonyManager.NETWORK_TYPE_HSPAP: |
| 5316 | bin = DATA_CONNECTION_HSPAP; |
| 5317 | break; |
Siddharth Ray | c72081d | 2018-02-13 11:31:54 -0800 | [diff] [blame] | 5318 | case TelephonyManager.NETWORK_TYPE_GSM: |
| 5319 | bin = DATA_CONNECTION_GSM; |
| 5320 | break; |
| 5321 | case TelephonyManager.NETWORK_TYPE_TD_SCDMA: |
| 5322 | bin = DATA_CONNECTION_TD_SCDMA; |
| 5323 | break; |
| 5324 | case TelephonyManager.NETWORK_TYPE_IWLAN: |
| 5325 | bin = DATA_CONNECTION_IWLAN; |
| 5326 | break; |
| 5327 | case TelephonyManager.NETWORK_TYPE_LTE_CA: |
| 5328 | bin = DATA_CONNECTION_LTE_CA; |
| 5329 | break; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 5330 | default: |
| 5331 | bin = DATA_CONNECTION_OTHER; |
| 5332 | break; |
| 5333 | } |
| 5334 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 5335 | if (DEBUG) Log.i(TAG, "Phone Data Connection -> " + dataType + " = " + hasData); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 5336 | if (mPhoneDataConnectionType != bin) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5337 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5338 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5339 | mHistoryCur.states = (mHistoryCur.states&~HistoryItem.STATE_DATA_CONNECTION_MASK) |
| 5340 | | (bin << HistoryItem.STATE_DATA_CONNECTION_SHIFT); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5341 | if (DEBUG_HISTORY) Slog.v(TAG, "Data connection " + bin + " to: " |
| 5342 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 5343 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 5344 | if (mPhoneDataConnectionType >= 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5345 | mPhoneDataConnectionsTimer[mPhoneDataConnectionType].stopRunningLocked( |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5346 | elapsedRealtime); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 5347 | } |
| 5348 | mPhoneDataConnectionType = bin; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5349 | mPhoneDataConnectionsTimer[bin].startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 5350 | } |
| 5351 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5352 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5353 | public void noteWifiOnLocked() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5354 | if (!mWifiOn) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5355 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5356 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5357 | mHistoryCur.states2 |= HistoryItem.STATE2_WIFI_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5358 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI on to: " |
| 5359 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 5360 | addHistoryRecordLocked(elapsedRealtime, uptime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5361 | mWifiOn = true; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5362 | mWifiOnTimer.startRunningLocked(elapsedRealtime); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5363 | scheduleSyncExternalStatsLocked("wifi-off", ExternalStatsSync.UPDATE_WIFI); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5364 | } |
| 5365 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5366 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5367 | public void noteWifiOffLocked() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5368 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5369 | final long uptime = mClocks.uptimeMillis(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5370 | if (mWifiOn) { |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5371 | mHistoryCur.states2 &= ~HistoryItem.STATE2_WIFI_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5372 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI off to: " |
| 5373 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 5374 | addHistoryRecordLocked(elapsedRealtime, uptime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5375 | mWifiOn = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5376 | mWifiOnTimer.stopRunningLocked(elapsedRealtime); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5377 | scheduleSyncExternalStatsLocked("wifi-on", ExternalStatsSync.UPDATE_WIFI); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5378 | } |
| 5379 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 5380 | |
| 5381 | public void noteAudioOnLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5382 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5383 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5384 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 5385 | if (mAudioOnNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5386 | mHistoryCur.states |= HistoryItem.STATE_AUDIO_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5387 | if (DEBUG_HISTORY) Slog.v(TAG, "Audio on to: " |
| 5388 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 5389 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5390 | mAudioOnTimer.startRunningLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 5391 | } |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 5392 | mAudioOnNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5393 | getUidStatsLocked(uid).noteAudioTurnedOnLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 5394 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5395 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 5396 | public void noteAudioOffLocked(int uid) { |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 5397 | if (mAudioOnNesting == 0) { |
| 5398 | return; |
| 5399 | } |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5400 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5401 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5402 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 5403 | if (--mAudioOnNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5404 | mHistoryCur.states &= ~HistoryItem.STATE_AUDIO_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5405 | if (DEBUG_HISTORY) Slog.v(TAG, "Audio off to: " |
| 5406 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 5407 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5408 | mAudioOnTimer.stopRunningLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 5409 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5410 | getUidStatsLocked(uid).noteAudioTurnedOffLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 5411 | } |
| 5412 | |
| 5413 | public void noteVideoOnLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5414 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5415 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5416 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 5417 | if (mVideoOnNesting == 0) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5418 | mHistoryCur.states2 |= HistoryItem.STATE2_VIDEO_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5419 | if (DEBUG_HISTORY) Slog.v(TAG, "Video on to: " |
| 5420 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 5421 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5422 | mVideoOnTimer.startRunningLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 5423 | } |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 5424 | mVideoOnNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5425 | getUidStatsLocked(uid).noteVideoTurnedOnLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 5426 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5427 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 5428 | public void noteVideoOffLocked(int uid) { |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 5429 | if (mVideoOnNesting == 0) { |
| 5430 | return; |
| 5431 | } |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5432 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5433 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5434 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 5435 | if (--mVideoOnNesting == 0) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5436 | mHistoryCur.states2 &= ~HistoryItem.STATE2_VIDEO_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5437 | if (DEBUG_HISTORY) Slog.v(TAG, "Video off to: " |
| 5438 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 5439 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5440 | mVideoOnTimer.stopRunningLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 5441 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5442 | getUidStatsLocked(uid).noteVideoTurnedOffLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 5443 | } |
| 5444 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 5445 | public void noteResetAudioLocked() { |
| 5446 | if (mAudioOnNesting > 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5447 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5448 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 5449 | mAudioOnNesting = 0; |
| 5450 | mHistoryCur.states &= ~HistoryItem.STATE_AUDIO_ON_FLAG; |
| 5451 | if (DEBUG_HISTORY) Slog.v(TAG, "Audio off to: " |
| 5452 | + Integer.toHexString(mHistoryCur.states)); |
| 5453 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 5454 | mAudioOnTimer.stopAllRunningLocked(elapsedRealtime); |
| 5455 | for (int i=0; i<mUidStats.size(); i++) { |
| 5456 | BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 5457 | uid.noteResetAudioLocked(elapsedRealtime); |
| 5458 | } |
| 5459 | } |
| 5460 | } |
| 5461 | |
| 5462 | public void noteResetVideoLocked() { |
| 5463 | if (mVideoOnNesting > 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5464 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5465 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 5466 | mAudioOnNesting = 0; |
| 5467 | mHistoryCur.states2 &= ~HistoryItem.STATE2_VIDEO_ON_FLAG; |
| 5468 | if (DEBUG_HISTORY) Slog.v(TAG, "Video off to: " |
| 5469 | + Integer.toHexString(mHistoryCur.states)); |
| 5470 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 5471 | mVideoOnTimer.stopAllRunningLocked(elapsedRealtime); |
| 5472 | for (int i=0; i<mUidStats.size(); i++) { |
| 5473 | BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 5474 | uid.noteResetVideoLocked(elapsedRealtime); |
| 5475 | } |
| 5476 | } |
| 5477 | } |
| 5478 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5479 | public void noteActivityResumedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5480 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5481 | getUidStatsLocked(uid).noteActivityResumedLocked(mClocks.elapsedRealtime()); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5482 | } |
| 5483 | |
| 5484 | public void noteActivityPausedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5485 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5486 | getUidStatsLocked(uid).noteActivityPausedLocked(mClocks.elapsedRealtime()); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5487 | } |
| 5488 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5489 | public void noteVibratorOnLocked(int uid, long durationMillis) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5490 | uid = mapUid(uid); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5491 | getUidStatsLocked(uid).noteVibratorOnLocked(durationMillis); |
| 5492 | } |
| 5493 | |
| 5494 | public void noteVibratorOffLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5495 | uid = mapUid(uid); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5496 | getUidStatsLocked(uid).noteVibratorOffLocked(); |
| 5497 | } |
| 5498 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5499 | public void noteFlashlightOnLocked(int uid) { |
| 5500 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5501 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5502 | final long uptime = mClocks.uptimeMillis(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5503 | if (mFlashlightOnNesting++ == 0) { |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 5504 | mHistoryCur.states2 |= HistoryItem.STATE2_FLASHLIGHT_FLAG; |
| 5505 | if (DEBUG_HISTORY) Slog.v(TAG, "Flashlight on to: " |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5506 | + Integer.toHexString(mHistoryCur.states2)); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 5507 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 5508 | mFlashlightOnTimer.startRunningLocked(elapsedRealtime); |
| 5509 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5510 | getUidStatsLocked(uid).noteFlashlightTurnedOnLocked(elapsedRealtime); |
| 5511 | } |
| 5512 | |
| 5513 | public void noteFlashlightOffLocked(int uid) { |
| 5514 | if (mFlashlightOnNesting == 0) { |
| 5515 | return; |
| 5516 | } |
| 5517 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5518 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5519 | final long uptime = mClocks.uptimeMillis(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5520 | if (--mFlashlightOnNesting == 0) { |
| 5521 | mHistoryCur.states2 &= ~HistoryItem.STATE2_FLASHLIGHT_FLAG; |
| 5522 | if (DEBUG_HISTORY) Slog.v(TAG, "Flashlight off to: " |
| 5523 | + Integer.toHexString(mHistoryCur.states2)); |
| 5524 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 5525 | mFlashlightOnTimer.stopRunningLocked(elapsedRealtime); |
| 5526 | } |
| 5527 | getUidStatsLocked(uid).noteFlashlightTurnedOffLocked(elapsedRealtime); |
| 5528 | } |
| 5529 | |
| 5530 | public void noteCameraOnLocked(int uid) { |
| 5531 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5532 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5533 | final long uptime = mClocks.uptimeMillis(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5534 | if (mCameraOnNesting++ == 0) { |
| 5535 | mHistoryCur.states2 |= HistoryItem.STATE2_CAMERA_FLAG; |
| 5536 | if (DEBUG_HISTORY) Slog.v(TAG, "Camera on to: " |
| 5537 | + Integer.toHexString(mHistoryCur.states2)); |
| 5538 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 5539 | mCameraOnTimer.startRunningLocked(elapsedRealtime); |
| 5540 | } |
| 5541 | getUidStatsLocked(uid).noteCameraTurnedOnLocked(elapsedRealtime); |
| 5542 | } |
| 5543 | |
| 5544 | public void noteCameraOffLocked(int uid) { |
| 5545 | if (mCameraOnNesting == 0) { |
| 5546 | return; |
| 5547 | } |
| 5548 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5549 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5550 | final long uptime = mClocks.uptimeMillis(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5551 | if (--mCameraOnNesting == 0) { |
| 5552 | mHistoryCur.states2 &= ~HistoryItem.STATE2_CAMERA_FLAG; |
| 5553 | if (DEBUG_HISTORY) Slog.v(TAG, "Camera off to: " |
| 5554 | + Integer.toHexString(mHistoryCur.states2)); |
| 5555 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 5556 | mCameraOnTimer.stopRunningLocked(elapsedRealtime); |
| 5557 | } |
| 5558 | getUidStatsLocked(uid).noteCameraTurnedOffLocked(elapsedRealtime); |
| 5559 | } |
| 5560 | |
| 5561 | public void noteResetCameraLocked() { |
| 5562 | if (mCameraOnNesting > 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5563 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5564 | final long uptime = mClocks.uptimeMillis(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5565 | mCameraOnNesting = 0; |
| 5566 | mHistoryCur.states2 &= ~HistoryItem.STATE2_CAMERA_FLAG; |
| 5567 | if (DEBUG_HISTORY) Slog.v(TAG, "Camera off to: " |
| 5568 | + Integer.toHexString(mHistoryCur.states2)); |
| 5569 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 5570 | mCameraOnTimer.stopAllRunningLocked(elapsedRealtime); |
| 5571 | for (int i=0; i<mUidStats.size(); i++) { |
| 5572 | BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 5573 | uid.noteResetCameraLocked(elapsedRealtime); |
| 5574 | } |
| 5575 | } |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 5576 | } |
| 5577 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5578 | public void noteResetFlashlightLocked() { |
| 5579 | if (mFlashlightOnNesting > 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5580 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5581 | final long uptime = mClocks.uptimeMillis(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5582 | mFlashlightOnNesting = 0; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 5583 | mHistoryCur.states2 &= ~HistoryItem.STATE2_FLASHLIGHT_FLAG; |
| 5584 | if (DEBUG_HISTORY) Slog.v(TAG, "Flashlight off to: " |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5585 | + Integer.toHexString(mHistoryCur.states2)); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 5586 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5587 | mFlashlightOnTimer.stopAllRunningLocked(elapsedRealtime); |
| 5588 | for (int i=0; i<mUidStats.size(); i++) { |
| 5589 | BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 5590 | uid.noteResetFlashlightLocked(elapsedRealtime); |
| 5591 | } |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 5592 | } |
| 5593 | } |
| 5594 | |
Narayan Kamath | 0ebc96c | 2017-12-29 13:32:38 +0000 | [diff] [blame] | 5595 | private void noteBluetoothScanStartedLocked(WorkChain workChain, int uid, |
| 5596 | boolean isUnoptimized) { |
| 5597 | uid = getAttributionUid(uid, workChain); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5598 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5599 | final long uptime = mClocks.uptimeMillis(); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5600 | if (mBluetoothScanNesting == 0) { |
| 5601 | mHistoryCur.states2 |= HistoryItem.STATE2_BLUETOOTH_SCAN_FLAG; |
| 5602 | if (DEBUG_HISTORY) Slog.v(TAG, "BLE scan started for: " |
| 5603 | + Integer.toHexString(mHistoryCur.states2)); |
| 5604 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Adam Lesinski | d9b99be | 2016-03-30 16:58:51 -0700 | [diff] [blame] | 5605 | mBluetoothScanTimer.startRunningLocked(elapsedRealtime); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5606 | } |
| 5607 | mBluetoothScanNesting++; |
Narayan Kamath | 0ebc96c | 2017-12-29 13:32:38 +0000 | [diff] [blame] | 5608 | |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 5609 | if (workChain != null) { |
| 5610 | StatsLog.write(StatsLog.BLE_SCAN_STATE_CHANGED, |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 5611 | workChain.getUids(), workChain.getTags(), |
| 5612 | StatsLog.BLE_SCAN_STATE_CHANGED__STATE__ON); |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 5613 | if (isUnoptimized) { |
| 5614 | StatsLog.write(StatsLog.BLE_UNOPTIMIZED_SCAN_STATE_CHANGED, |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 5615 | workChain.getUids(), workChain.getTags(), |
| 5616 | StatsLog.BLE_UNOPTIMIZED_SCAN_STATE_CHANGED__STATE__ON); |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 5617 | } |
| 5618 | } else { |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 5619 | StatsLog.write_non_chained(StatsLog.BLE_SCAN_STATE_CHANGED, uid, null, |
| 5620 | StatsLog.BLE_SCAN_STATE_CHANGED__STATE__ON); |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 5621 | if (isUnoptimized) { |
Yangster-mac | 2f5daec | 2018-01-16 10:23:15 -0800 | [diff] [blame] | 5622 | StatsLog.write_non_chained(StatsLog.BLE_UNOPTIMIZED_SCAN_STATE_CHANGED, uid, null, |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 5623 | StatsLog.BLE_UNOPTIMIZED_SCAN_STATE_CHANGED__STATE__ON); |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 5624 | } |
Narayan Kamath | 0ebc96c | 2017-12-29 13:32:38 +0000 | [diff] [blame] | 5625 | } |
| 5626 | |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5627 | getUidStatsLocked(uid).noteBluetoothScanStartedLocked(elapsedRealtime, isUnoptimized); |
Narayan Kamath | 0ebc96c | 2017-12-29 13:32:38 +0000 | [diff] [blame] | 5628 | if (workChain != null) { |
| 5629 | getUidStatsLocked(uid).addBluetoothWorkChain(workChain, isUnoptimized); |
| 5630 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5631 | } |
| 5632 | |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5633 | public void noteBluetoothScanStartedFromSourceLocked(WorkSource ws, boolean isUnoptimized) { |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5634 | final int N = ws.size(); |
| 5635 | for (int i = 0; i < N; i++) { |
Narayan Kamath | 0ebc96c | 2017-12-29 13:32:38 +0000 | [diff] [blame] | 5636 | noteBluetoothScanStartedLocked(null, ws.get(i), isUnoptimized); |
| 5637 | } |
| 5638 | |
| 5639 | final List<WorkChain> workChains = ws.getWorkChains(); |
| 5640 | if (workChains != null) { |
| 5641 | for (int i = 0; i < workChains.size(); ++i) { |
| 5642 | noteBluetoothScanStartedLocked(workChains.get(i), -1, isUnoptimized); |
| 5643 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5644 | } |
| 5645 | } |
| 5646 | |
Narayan Kamath | 0ebc96c | 2017-12-29 13:32:38 +0000 | [diff] [blame] | 5647 | private void noteBluetoothScanStoppedLocked(WorkChain workChain, int uid, |
| 5648 | boolean isUnoptimized) { |
| 5649 | uid = getAttributionUid(uid, workChain); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5650 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5651 | final long uptime = mClocks.uptimeMillis(); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5652 | mBluetoothScanNesting--; |
| 5653 | if (mBluetoothScanNesting == 0) { |
| 5654 | mHistoryCur.states2 &= ~HistoryItem.STATE2_BLUETOOTH_SCAN_FLAG; |
| 5655 | if (DEBUG_HISTORY) Slog.v(TAG, "BLE scan stopped for: " |
| 5656 | + Integer.toHexString(mHistoryCur.states2)); |
| 5657 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Adam Lesinski | d9b99be | 2016-03-30 16:58:51 -0700 | [diff] [blame] | 5658 | mBluetoothScanTimer.stopRunningLocked(elapsedRealtime); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5659 | } |
Narayan Kamath | 0ebc96c | 2017-12-29 13:32:38 +0000 | [diff] [blame] | 5660 | |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 5661 | if (workChain != null) { |
| 5662 | StatsLog.write( |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 5663 | StatsLog.BLE_SCAN_STATE_CHANGED, workChain.getUids(), workChain.getTags(), |
| 5664 | StatsLog.BLE_SCAN_STATE_CHANGED__STATE__OFF); |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 5665 | if (isUnoptimized) { |
| 5666 | StatsLog.write(StatsLog.BLE_UNOPTIMIZED_SCAN_STATE_CHANGED, |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 5667 | workChain.getUids(), workChain.getTags(), |
| 5668 | StatsLog.BLE_UNOPTIMIZED_SCAN_STATE_CHANGED__STATE__OFF); |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 5669 | } |
| 5670 | } else { |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 5671 | StatsLog.write_non_chained(StatsLog.BLE_SCAN_STATE_CHANGED, uid, null, |
| 5672 | StatsLog.BLE_SCAN_STATE_CHANGED__STATE__OFF); |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 5673 | if (isUnoptimized) { |
Yangster-mac | 2f5daec | 2018-01-16 10:23:15 -0800 | [diff] [blame] | 5674 | StatsLog.write_non_chained(StatsLog.BLE_UNOPTIMIZED_SCAN_STATE_CHANGED, uid, null, |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 5675 | StatsLog.BLE_UNOPTIMIZED_SCAN_STATE_CHANGED__STATE__OFF); |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 5676 | } |
Narayan Kamath | 0ebc96c | 2017-12-29 13:32:38 +0000 | [diff] [blame] | 5677 | } |
| 5678 | |
Bookatz | 94c5a31 | 2017-07-11 16:49:17 -0700 | [diff] [blame] | 5679 | getUidStatsLocked(uid).noteBluetoothScanStoppedLocked(elapsedRealtime, isUnoptimized); |
Narayan Kamath | 0ebc96c | 2017-12-29 13:32:38 +0000 | [diff] [blame] | 5680 | if (workChain != null) { |
| 5681 | getUidStatsLocked(uid).removeBluetoothWorkChain(workChain, isUnoptimized); |
| 5682 | } |
| 5683 | } |
| 5684 | |
| 5685 | private int getAttributionUid(int uid, WorkChain workChain) { |
| 5686 | if (workChain != null) { |
| 5687 | return mapUid(workChain.getAttributionUid()); |
| 5688 | } |
| 5689 | |
| 5690 | return mapUid(uid); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5691 | } |
| 5692 | |
Bookatz | 94c5a31 | 2017-07-11 16:49:17 -0700 | [diff] [blame] | 5693 | public void noteBluetoothScanStoppedFromSourceLocked(WorkSource ws, boolean isUnoptimized) { |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5694 | final int N = ws.size(); |
| 5695 | for (int i = 0; i < N; i++) { |
Narayan Kamath | 0ebc96c | 2017-12-29 13:32:38 +0000 | [diff] [blame] | 5696 | noteBluetoothScanStoppedLocked(null, ws.get(i), isUnoptimized); |
| 5697 | } |
| 5698 | |
| 5699 | final List<WorkChain> workChains = ws.getWorkChains(); |
| 5700 | if (workChains != null) { |
| 5701 | for (int i = 0; i < workChains.size(); ++i) { |
| 5702 | noteBluetoothScanStoppedLocked(workChains.get(i), -1, isUnoptimized); |
| 5703 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5704 | } |
| 5705 | } |
| 5706 | |
| 5707 | public void noteResetBluetoothScanLocked() { |
| 5708 | if (mBluetoothScanNesting > 0) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5709 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5710 | final long uptime = mClocks.uptimeMillis(); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5711 | mBluetoothScanNesting = 0; |
| 5712 | mHistoryCur.states2 &= ~HistoryItem.STATE2_BLUETOOTH_SCAN_FLAG; |
| 5713 | if (DEBUG_HISTORY) Slog.v(TAG, "BLE can stopped for: " |
| 5714 | + Integer.toHexString(mHistoryCur.states2)); |
| 5715 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 5716 | mBluetoothScanTimer.stopAllRunningLocked(elapsedRealtime); |
Narayan Kamath | 0ebc96c | 2017-12-29 13:32:38 +0000 | [diff] [blame] | 5717 | |
| 5718 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5719 | for (int i=0; i<mUidStats.size(); i++) { |
| 5720 | BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 5721 | uid.noteResetBluetoothScanLocked(elapsedRealtime); |
Narayan Kamath | 0ebc96c | 2017-12-29 13:32:38 +0000 | [diff] [blame] | 5722 | |
Narayan Kamath | 0ebc96c | 2017-12-29 13:32:38 +0000 | [diff] [blame] | 5723 | List<WorkChain> allWorkChains = uid.getAllBluetoothWorkChains(); |
| 5724 | if (allWorkChains != null) { |
| 5725 | for (int j = 0; j < allWorkChains.size(); ++j) { |
Narayan Kamath | 0ebc96c | 2017-12-29 13:32:38 +0000 | [diff] [blame] | 5726 | StatsLog.write(StatsLog.BLE_SCAN_STATE_CHANGED, |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 5727 | allWorkChains.get(j).getUids(), |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 5728 | allWorkChains.get(j).getTags(), |
| 5729 | StatsLog.BLE_SCAN_STATE_CHANGED__STATE__OFF); |
Narayan Kamath | 0ebc96c | 2017-12-29 13:32:38 +0000 | [diff] [blame] | 5730 | } |
Narayan Kamath | 0ebc96c | 2017-12-29 13:32:38 +0000 | [diff] [blame] | 5731 | allWorkChains.clear(); |
| 5732 | } |
| 5733 | |
| 5734 | List<WorkChain> unoptimizedWorkChains = uid.getUnoptimizedBluetoothWorkChains(); |
| 5735 | if (unoptimizedWorkChains != null) { |
| 5736 | for (int j = 0; j < unoptimizedWorkChains.size(); ++j) { |
Narayan Kamath | 0ebc96c | 2017-12-29 13:32:38 +0000 | [diff] [blame] | 5737 | StatsLog.write(StatsLog.BLE_UNOPTIMIZED_SCAN_STATE_CHANGED, |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 5738 | unoptimizedWorkChains.get(j).getUids(), |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 5739 | unoptimizedWorkChains.get(j).getTags(), |
| 5740 | StatsLog.BLE_UNOPTIMIZED_SCAN_STATE_CHANGED__STATE__OFF); |
Narayan Kamath | 0ebc96c | 2017-12-29 13:32:38 +0000 | [diff] [blame] | 5741 | } |
Narayan Kamath | 0ebc96c | 2017-12-29 13:32:38 +0000 | [diff] [blame] | 5742 | unoptimizedWorkChains.clear(); |
| 5743 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5744 | } |
| 5745 | } |
| 5746 | } |
| 5747 | |
Bookatz | 4ebc064 | 2017-05-11 12:21:19 -0700 | [diff] [blame] | 5748 | public void noteBluetoothScanResultsFromSourceLocked(WorkSource ws, int numNewResults) { |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 5749 | final int N = ws.size(); |
| 5750 | for (int i = 0; i < N; i++) { |
| 5751 | int uid = mapUid(ws.get(i)); |
Bookatz | 4ebc064 | 2017-05-11 12:21:19 -0700 | [diff] [blame] | 5752 | getUidStatsLocked(uid).noteBluetoothScanResultsLocked(numNewResults); |
Yangster-mac | 2f5daec | 2018-01-16 10:23:15 -0800 | [diff] [blame] | 5753 | StatsLog.write_non_chained(StatsLog.BLE_SCAN_RESULT_RECEIVED, ws.get(i), ws.getName(i), |
| 5754 | numNewResults); |
Narayan Kamath | 0ebc96c | 2017-12-29 13:32:38 +0000 | [diff] [blame] | 5755 | } |
| 5756 | |
| 5757 | final List<WorkChain> workChains = ws.getWorkChains(); |
| 5758 | if (workChains != null) { |
| 5759 | for (int i = 0; i < workChains.size(); ++i) { |
| 5760 | final WorkChain wc = workChains.get(i); |
| 5761 | int uid = mapUid(wc.getAttributionUid()); |
| 5762 | getUidStatsLocked(uid).noteBluetoothScanResultsLocked(numNewResults); |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 5763 | StatsLog.write(StatsLog.BLE_SCAN_RESULT_RECEIVED, |
| 5764 | wc.getUids(), wc.getTags(), numNewResults); |
Narayan Kamath | 0ebc96c | 2017-12-29 13:32:38 +0000 | [diff] [blame] | 5765 | } |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 5766 | } |
| 5767 | } |
| 5768 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 5769 | private void noteWifiRadioApWakeupLocked(final long elapsedRealtimeMillis, |
| 5770 | final long uptimeMillis, int uid) { |
| 5771 | uid = mapUid(uid); |
| 5772 | addHistoryEventLocked(elapsedRealtimeMillis, uptimeMillis, HistoryItem.EVENT_WAKEUP_AP, "", |
| 5773 | uid); |
| 5774 | getUidStatsLocked(uid).noteWifiRadioApWakeupLocked(); |
| 5775 | } |
| 5776 | |
| 5777 | public void noteWifiRadioPowerState(int powerState, long timestampNs, int uid) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5778 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5779 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 5780 | if (mWifiRadioPowerState != powerState) { |
| 5781 | final boolean active = |
| 5782 | powerState == DataConnectionRealTimeInfo.DC_POWER_STATE_MEDIUM |
| 5783 | || powerState == DataConnectionRealTimeInfo.DC_POWER_STATE_HIGH; |
| 5784 | if (active) { |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 5785 | if (uid > 0) { |
| 5786 | noteWifiRadioApWakeupLocked(elapsedRealtime, uptime, uid); |
| 5787 | } |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 5788 | mHistoryCur.states |= HistoryItem.STATE_WIFI_RADIO_ACTIVE_FLAG; |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 5789 | mWifiActiveTimer.startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 5790 | } else { |
| 5791 | mHistoryCur.states &= ~HistoryItem.STATE_WIFI_RADIO_ACTIVE_FLAG; |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 5792 | mWifiActiveTimer.stopRunningLocked( |
| 5793 | timestampNs / (1000 * 1000)); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 5794 | } |
| 5795 | if (DEBUG_HISTORY) Slog.v(TAG, "Wifi network active " + active + " to: " |
| 5796 | + Integer.toHexString(mHistoryCur.states)); |
| 5797 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 5798 | mWifiRadioPowerState = powerState; |
Bookatz | ddccf0a | 2017-11-28 16:48:14 -0800 | [diff] [blame] | 5799 | StatsLog.write(StatsLog.WIFI_RADIO_POWER_STATE_CHANGED, uid, powerState); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 5800 | } |
| 5801 | } |
| 5802 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5803 | public void noteWifiRunningLocked(WorkSource ws) { |
| 5804 | if (!mGlobalWifiRunning) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5805 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5806 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5807 | mHistoryCur.states2 |= HistoryItem.STATE2_WIFI_RUNNING_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5808 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI running to: " |
| 5809 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 5810 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5811 | mGlobalWifiRunning = true; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5812 | mGlobalWifiRunningTimer.startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5813 | int N = ws.size(); |
| 5814 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5815 | int uid = mapUid(ws.get(i)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5816 | getUidStatsLocked(uid).noteWifiRunningLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5817 | } |
Narayan Kamath | 728c8a0 | 2017-12-28 15:48:07 +0000 | [diff] [blame] | 5818 | |
| 5819 | List<WorkChain> workChains = ws.getWorkChains(); |
| 5820 | if (workChains != null) { |
| 5821 | for (int i = 0; i < workChains.size(); ++i) { |
| 5822 | int uid = mapUid(workChains.get(i).getAttributionUid()); |
| 5823 | getUidStatsLocked(uid).noteWifiRunningLocked(elapsedRealtime); |
| 5824 | } |
| 5825 | } |
| 5826 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5827 | scheduleSyncExternalStatsLocked("wifi-running", ExternalStatsSync.UPDATE_WIFI); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5828 | } else { |
| 5829 | Log.w(TAG, "noteWifiRunningLocked -- called while WIFI running"); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 5830 | } |
| 5831 | } |
| 5832 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5833 | public void noteWifiRunningChangedLocked(WorkSource oldWs, WorkSource newWs) { |
| 5834 | if (mGlobalWifiRunning) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5835 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5836 | int N = oldWs.size(); |
| 5837 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5838 | int uid = mapUid(oldWs.get(i)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5839 | getUidStatsLocked(uid).noteWifiStoppedLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5840 | } |
Narayan Kamath | 728c8a0 | 2017-12-28 15:48:07 +0000 | [diff] [blame] | 5841 | |
| 5842 | List<WorkChain> workChains = oldWs.getWorkChains(); |
| 5843 | if (workChains != null) { |
| 5844 | for (int i = 0; i < workChains.size(); ++i) { |
| 5845 | int uid = mapUid(workChains.get(i).getAttributionUid()); |
| 5846 | getUidStatsLocked(uid).noteWifiStoppedLocked(elapsedRealtime); |
| 5847 | } |
| 5848 | } |
| 5849 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5850 | N = newWs.size(); |
| 5851 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5852 | int uid = mapUid(newWs.get(i)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5853 | getUidStatsLocked(uid).noteWifiRunningLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5854 | } |
Narayan Kamath | 728c8a0 | 2017-12-28 15:48:07 +0000 | [diff] [blame] | 5855 | |
| 5856 | workChains = newWs.getWorkChains(); |
| 5857 | if (workChains != null) { |
| 5858 | for (int i = 0; i < workChains.size(); ++i) { |
| 5859 | int uid = mapUid(workChains.get(i).getAttributionUid()); |
| 5860 | getUidStatsLocked(uid).noteWifiRunningLocked(elapsedRealtime); |
| 5861 | } |
| 5862 | } |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5863 | } else { |
| 5864 | Log.w(TAG, "noteWifiRunningChangedLocked -- called while WIFI not running"); |
| 5865 | } |
| 5866 | } |
| 5867 | |
| 5868 | public void noteWifiStoppedLocked(WorkSource ws) { |
| 5869 | if (mGlobalWifiRunning) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5870 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5871 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5872 | mHistoryCur.states2 &= ~HistoryItem.STATE2_WIFI_RUNNING_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5873 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI stopped to: " |
| 5874 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 5875 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5876 | mGlobalWifiRunning = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5877 | mGlobalWifiRunningTimer.stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5878 | int N = ws.size(); |
| 5879 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5880 | int uid = mapUid(ws.get(i)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5881 | getUidStatsLocked(uid).noteWifiStoppedLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5882 | } |
Narayan Kamath | 728c8a0 | 2017-12-28 15:48:07 +0000 | [diff] [blame] | 5883 | |
| 5884 | List<WorkChain> workChains = ws.getWorkChains(); |
| 5885 | if (workChains != null) { |
| 5886 | for (int i = 0; i < workChains.size(); ++i) { |
| 5887 | int uid = mapUid(workChains.get(i).getAttributionUid()); |
| 5888 | getUidStatsLocked(uid).noteWifiStoppedLocked(elapsedRealtime); |
| 5889 | } |
| 5890 | } |
| 5891 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5892 | scheduleSyncExternalStatsLocked("wifi-stopped", ExternalStatsSync.UPDATE_WIFI); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5893 | } else { |
| 5894 | Log.w(TAG, "noteWifiStoppedLocked -- called while WIFI not running"); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 5895 | } |
| 5896 | } |
| 5897 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5898 | public void noteWifiStateLocked(int wifiState, String accessPoint) { |
| 5899 | if (DEBUG) Log.i(TAG, "WiFi state -> " + wifiState); |
| 5900 | if (mWifiState != wifiState) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5901 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5902 | if (mWifiState >= 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5903 | mWifiStateTimer[mWifiState].stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5904 | } |
| 5905 | mWifiState = wifiState; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5906 | mWifiStateTimer[wifiState].startRunningLocked(elapsedRealtime); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5907 | scheduleSyncExternalStatsLocked("wifi-state", ExternalStatsSync.UPDATE_WIFI); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5908 | } |
| 5909 | } |
| 5910 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5911 | public void noteWifiSupplicantStateChangedLocked(int supplState, boolean failedAuth) { |
| 5912 | if (DEBUG) Log.i(TAG, "WiFi suppl state -> " + supplState); |
| 5913 | if (mWifiSupplState != supplState) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5914 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5915 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5916 | if (mWifiSupplState >= 0) { |
| 5917 | mWifiSupplStateTimer[mWifiSupplState].stopRunningLocked(elapsedRealtime); |
| 5918 | } |
| 5919 | mWifiSupplState = supplState; |
| 5920 | mWifiSupplStateTimer[supplState].startRunningLocked(elapsedRealtime); |
| 5921 | mHistoryCur.states2 = |
| 5922 | (mHistoryCur.states2&~HistoryItem.STATE2_WIFI_SUPPL_STATE_MASK) |
| 5923 | | (supplState << HistoryItem.STATE2_WIFI_SUPPL_STATE_SHIFT); |
| 5924 | if (DEBUG_HISTORY) Slog.v(TAG, "Wifi suppl state " + supplState + " to: " |
| 5925 | + Integer.toHexString(mHistoryCur.states2)); |
| 5926 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 5927 | } |
| 5928 | } |
| 5929 | |
| 5930 | void stopAllWifiSignalStrengthTimersLocked(int except) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5931 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5932 | for (int i = 0; i < NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 5933 | if (i == except) { |
| 5934 | continue; |
| 5935 | } |
| 5936 | while (mWifiSignalStrengthsTimer[i].isRunningLocked()) { |
| 5937 | mWifiSignalStrengthsTimer[i].stopRunningLocked(elapsedRealtime); |
| 5938 | } |
| 5939 | } |
| 5940 | } |
| 5941 | |
| 5942 | public void noteWifiRssiChangedLocked(int newRssi) { |
| 5943 | int strengthBin = WifiManager.calculateSignalLevel(newRssi, NUM_WIFI_SIGNAL_STRENGTH_BINS); |
| 5944 | if (DEBUG) Log.i(TAG, "WiFi rssi -> " + newRssi + " bin=" + strengthBin); |
| 5945 | if (mWifiSignalStrengthBin != strengthBin) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5946 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5947 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5948 | if (mWifiSignalStrengthBin >= 0) { |
| 5949 | mWifiSignalStrengthsTimer[mWifiSignalStrengthBin].stopRunningLocked( |
| 5950 | elapsedRealtime); |
| 5951 | } |
| 5952 | if (strengthBin >= 0) { |
| 5953 | if (!mWifiSignalStrengthsTimer[strengthBin].isRunningLocked()) { |
| 5954 | mWifiSignalStrengthsTimer[strengthBin].startRunningLocked(elapsedRealtime); |
Bookatz | e588524 | 2017-10-24 20:10:31 -0700 | [diff] [blame] | 5955 | StatsLog.write(StatsLog.WIFI_SIGNAL_STRENGTH_CHANGED, strengthBin); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5956 | } |
| 5957 | mHistoryCur.states2 = |
| 5958 | (mHistoryCur.states2&~HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_MASK) |
| 5959 | | (strengthBin << HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_SHIFT); |
| 5960 | if (DEBUG_HISTORY) Slog.v(TAG, "Wifi signal strength " + strengthBin + " to: " |
| 5961 | + Integer.toHexString(mHistoryCur.states2)); |
| 5962 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 5963 | } else { |
| 5964 | stopAllWifiSignalStrengthTimersLocked(-1); |
| 5965 | } |
| 5966 | mWifiSignalStrengthBin = strengthBin; |
| 5967 | } |
| 5968 | } |
| 5969 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5970 | int mWifiFullLockNesting = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5971 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5972 | public void noteFullWifiLockAcquiredLocked(int uid) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5973 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5974 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5975 | if (mWifiFullLockNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5976 | mHistoryCur.states |= HistoryItem.STATE_WIFI_FULL_LOCK_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5977 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI full lock on to: " |
| 5978 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 5979 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5980 | } |
| 5981 | mWifiFullLockNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5982 | getUidStatsLocked(uid).noteFullWifiLockAcquiredLocked(elapsedRealtime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5983 | } |
| 5984 | |
| 5985 | public void noteFullWifiLockReleasedLocked(int uid) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5986 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5987 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5988 | mWifiFullLockNesting--; |
| 5989 | if (mWifiFullLockNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5990 | mHistoryCur.states &= ~HistoryItem.STATE_WIFI_FULL_LOCK_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5991 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI full lock off to: " |
| 5992 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 5993 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5994 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5995 | getUidStatsLocked(uid).noteFullWifiLockReleasedLocked(elapsedRealtime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5996 | } |
| 5997 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5998 | int mWifiScanNesting = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5999 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 6000 | public void noteWifiScanStartedLocked(int uid) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6001 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 6002 | final long uptime = mClocks.uptimeMillis(); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 6003 | if (mWifiScanNesting == 0) { |
| 6004 | mHistoryCur.states |= HistoryItem.STATE_WIFI_SCAN_FLAG; |
| 6005 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI scan started for: " |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 6006 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 6007 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 6008 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 6009 | mWifiScanNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 6010 | getUidStatsLocked(uid).noteWifiScanStartedLocked(elapsedRealtime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6011 | } |
| 6012 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 6013 | public void noteWifiScanStoppedLocked(int uid) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6014 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 6015 | final long uptime = mClocks.uptimeMillis(); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 6016 | mWifiScanNesting--; |
| 6017 | if (mWifiScanNesting == 0) { |
| 6018 | mHistoryCur.states &= ~HistoryItem.STATE_WIFI_SCAN_FLAG; |
| 6019 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI scan stopped for: " |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 6020 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 6021 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 6022 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 6023 | getUidStatsLocked(uid).noteWifiScanStoppedLocked(elapsedRealtime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6024 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 6025 | |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6026 | public void noteWifiBatchedScanStartedLocked(int uid, int csph) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6027 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6028 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 6029 | getUidStatsLocked(uid).noteWifiBatchedScanStartedLocked(csph, elapsedRealtime); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6030 | } |
| 6031 | |
| 6032 | public void noteWifiBatchedScanStoppedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6033 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6034 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 6035 | getUidStatsLocked(uid).noteWifiBatchedScanStoppedLocked(elapsedRealtime); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6036 | } |
| 6037 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 6038 | int mWifiMulticastNesting = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6039 | |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 6040 | public void noteWifiMulticastEnabledLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6041 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6042 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 6043 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 6044 | if (mWifiMulticastNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6045 | mHistoryCur.states |= HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 6046 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI multicast on to: " |
| 6047 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 6048 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 6049 | |
| 6050 | // Start Wifi Multicast overall timer |
| 6051 | if (!mWifiMulticastWakelockTimer.isRunningLocked()) { |
| 6052 | if (DEBUG_HISTORY) Slog.v(TAG, "WiFi Multicast Overall Timer Started"); |
| 6053 | mWifiMulticastWakelockTimer.startRunningLocked(elapsedRealtime); |
| 6054 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 6055 | } |
| 6056 | mWifiMulticastNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 6057 | getUidStatsLocked(uid).noteWifiMulticastEnabledLocked(elapsedRealtime); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 6058 | } |
| 6059 | |
| 6060 | public void noteWifiMulticastDisabledLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6061 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6062 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 6063 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 6064 | mWifiMulticastNesting--; |
| 6065 | if (mWifiMulticastNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6066 | mHistoryCur.states &= ~HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 6067 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI multicast off to: " |
| 6068 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 6069 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 6070 | |
| 6071 | // Stop Wifi Multicast overall timer |
| 6072 | if (mWifiMulticastWakelockTimer.isRunningLocked()) { |
| 6073 | if (DEBUG_HISTORY) Slog.v(TAG, "Multicast Overall Timer Stopped"); |
| 6074 | mWifiMulticastWakelockTimer.stopRunningLocked(elapsedRealtime); |
| 6075 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 6076 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 6077 | getUidStatsLocked(uid).noteWifiMulticastDisabledLocked(elapsedRealtime); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 6078 | } |
| 6079 | |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 6080 | public void noteFullWifiLockAcquiredFromSourceLocked(WorkSource ws) { |
| 6081 | int N = ws.size(); |
| 6082 | for (int i=0; i<N; i++) { |
Narayan Kamath | 728c8a0 | 2017-12-28 15:48:07 +0000 | [diff] [blame] | 6083 | final int uid = mapUid(ws.get(i)); |
| 6084 | noteFullWifiLockAcquiredLocked(uid); |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 6085 | StatsLog.write_non_chained(StatsLog.WIFI_LOCK_STATE_CHANGED, ws.get(i), ws.getName(i), |
| 6086 | StatsLog.WIFI_LOCK_STATE_CHANGED__STATE__ON); |
Narayan Kamath | 728c8a0 | 2017-12-28 15:48:07 +0000 | [diff] [blame] | 6087 | } |
| 6088 | |
| 6089 | final List<WorkChain> workChains = ws.getWorkChains(); |
| 6090 | if (workChains != null) { |
| 6091 | for (int i = 0; i < workChains.size(); ++i) { |
| 6092 | final WorkChain workChain = workChains.get(i); |
| 6093 | final int uid = mapUid(workChain.getAttributionUid()); |
| 6094 | noteFullWifiLockAcquiredLocked(uid); |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 6095 | StatsLog.write(StatsLog.WIFI_LOCK_STATE_CHANGED, |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 6096 | workChain.getUids(), workChain.getTags(), |
| 6097 | StatsLog.WIFI_LOCK_STATE_CHANGED__STATE__ON); |
Narayan Kamath | 728c8a0 | 2017-12-28 15:48:07 +0000 | [diff] [blame] | 6098 | } |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 6099 | } |
| 6100 | } |
| 6101 | |
| 6102 | public void noteFullWifiLockReleasedFromSourceLocked(WorkSource ws) { |
| 6103 | int N = ws.size(); |
| 6104 | for (int i=0; i<N; i++) { |
Narayan Kamath | 728c8a0 | 2017-12-28 15:48:07 +0000 | [diff] [blame] | 6105 | final int uid = mapUid(ws.get(i)); |
| 6106 | noteFullWifiLockReleasedLocked(uid); |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 6107 | StatsLog.write_non_chained(StatsLog.WIFI_LOCK_STATE_CHANGED, ws.get(i), ws.getName(i), |
| 6108 | StatsLog.WIFI_LOCK_STATE_CHANGED__STATE__OFF); |
Narayan Kamath | 728c8a0 | 2017-12-28 15:48:07 +0000 | [diff] [blame] | 6109 | } |
| 6110 | |
| 6111 | final List<WorkChain> workChains = ws.getWorkChains(); |
| 6112 | if (workChains != null) { |
| 6113 | for (int i = 0; i < workChains.size(); ++i) { |
| 6114 | final WorkChain workChain = workChains.get(i); |
| 6115 | final int uid = mapUid(workChain.getAttributionUid()); |
| 6116 | noteFullWifiLockReleasedLocked(uid); |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 6117 | StatsLog.write(StatsLog.WIFI_LOCK_STATE_CHANGED, |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 6118 | workChain.getUids(), workChain.getTags(), |
| 6119 | StatsLog.WIFI_LOCK_STATE_CHANGED__STATE__OFF); |
Narayan Kamath | 728c8a0 | 2017-12-28 15:48:07 +0000 | [diff] [blame] | 6120 | } |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 6121 | } |
| 6122 | } |
| 6123 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 6124 | public void noteWifiScanStartedFromSourceLocked(WorkSource ws) { |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 6125 | int N = ws.size(); |
| 6126 | for (int i=0; i<N; i++) { |
Narayan Kamath | 728c8a0 | 2017-12-28 15:48:07 +0000 | [diff] [blame] | 6127 | final int uid = mapUid(ws.get(i)); |
| 6128 | noteWifiScanStartedLocked(uid); |
Yangster-mac | 2f5daec | 2018-01-16 10:23:15 -0800 | [diff] [blame] | 6129 | 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] | 6130 | StatsLog.WIFI_SCAN_STATE_CHANGED__STATE__ON); |
Narayan Kamath | 728c8a0 | 2017-12-28 15:48:07 +0000 | [diff] [blame] | 6131 | } |
| 6132 | |
| 6133 | final List<WorkChain> workChains = ws.getWorkChains(); |
| 6134 | if (workChains != null) { |
| 6135 | for (int i = 0; i < workChains.size(); ++i) { |
| 6136 | final WorkChain workChain = workChains.get(i); |
| 6137 | final int uid = mapUid(workChain.getAttributionUid()); |
| 6138 | noteWifiScanStartedLocked(uid); |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 6139 | StatsLog.write(StatsLog.WIFI_SCAN_STATE_CHANGED, workChain.getUids(), |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 6140 | workChain.getTags(), StatsLog.WIFI_SCAN_STATE_CHANGED__STATE__ON); |
Narayan Kamath | 728c8a0 | 2017-12-28 15:48:07 +0000 | [diff] [blame] | 6141 | } |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 6142 | } |
| 6143 | } |
| 6144 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 6145 | public void noteWifiScanStoppedFromSourceLocked(WorkSource ws) { |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 6146 | int N = ws.size(); |
| 6147 | for (int i=0; i<N; i++) { |
Narayan Kamath | 728c8a0 | 2017-12-28 15:48:07 +0000 | [diff] [blame] | 6148 | final int uid = mapUid(ws.get(i)); |
| 6149 | noteWifiScanStoppedLocked(uid); |
Yangster-mac | 2f5daec | 2018-01-16 10:23:15 -0800 | [diff] [blame] | 6150 | 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] | 6151 | StatsLog.WIFI_SCAN_STATE_CHANGED__STATE__OFF); |
Narayan Kamath | 728c8a0 | 2017-12-28 15:48:07 +0000 | [diff] [blame] | 6152 | } |
| 6153 | |
| 6154 | final List<WorkChain> workChains = ws.getWorkChains(); |
| 6155 | if (workChains != null) { |
| 6156 | for (int i = 0; i < workChains.size(); ++i) { |
| 6157 | final WorkChain workChain = workChains.get(i); |
| 6158 | final int uid = mapUid(workChain.getAttributionUid()); |
| 6159 | noteWifiScanStoppedLocked(uid); |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 6160 | StatsLog.write(StatsLog.WIFI_SCAN_STATE_CHANGED, |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 6161 | workChain.getUids(), workChain.getTags(), |
| 6162 | StatsLog.WIFI_SCAN_STATE_CHANGED__STATE__OFF); |
Narayan Kamath | 728c8a0 | 2017-12-28 15:48:07 +0000 | [diff] [blame] | 6163 | } |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 6164 | } |
| 6165 | } |
| 6166 | |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6167 | public void noteWifiBatchedScanStartedFromSourceLocked(WorkSource ws, int csph) { |
| 6168 | int N = ws.size(); |
| 6169 | for (int i=0; i<N; i++) { |
| 6170 | noteWifiBatchedScanStartedLocked(ws.get(i), csph); |
| 6171 | } |
Narayan Kamath | 728c8a0 | 2017-12-28 15:48:07 +0000 | [diff] [blame] | 6172 | |
| 6173 | final List<WorkChain> workChains = ws.getWorkChains(); |
| 6174 | if (workChains != null) { |
| 6175 | for (int i = 0; i < workChains.size(); ++i) { |
| 6176 | noteWifiBatchedScanStartedLocked(workChains.get(i).getAttributionUid(), csph); |
| 6177 | } |
| 6178 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6179 | } |
| 6180 | |
| 6181 | public void noteWifiBatchedScanStoppedFromSourceLocked(WorkSource ws) { |
| 6182 | int N = ws.size(); |
| 6183 | for (int i=0; i<N; i++) { |
| 6184 | noteWifiBatchedScanStoppedLocked(ws.get(i)); |
| 6185 | } |
Narayan Kamath | 728c8a0 | 2017-12-28 15:48:07 +0000 | [diff] [blame] | 6186 | |
| 6187 | final List<WorkChain> workChains = ws.getWorkChains(); |
| 6188 | if (workChains != null) { |
| 6189 | for (int i = 0; i < workChains.size(); ++i) { |
| 6190 | noteWifiBatchedScanStoppedLocked(workChains.get(i).getAttributionUid()); |
| 6191 | } |
| 6192 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6193 | } |
| 6194 | |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 6195 | private static String[] includeInStringArray(String[] array, String str) { |
| 6196 | if (ArrayUtils.indexOf(array, str) >= 0) { |
| 6197 | return array; |
| 6198 | } |
| 6199 | String[] newArray = new String[array.length+1]; |
| 6200 | System.arraycopy(array, 0, newArray, 0, array.length); |
| 6201 | newArray[array.length] = str; |
| 6202 | return newArray; |
| 6203 | } |
| 6204 | |
| 6205 | private static String[] excludeFromStringArray(String[] array, String str) { |
| 6206 | int index = ArrayUtils.indexOf(array, str); |
| 6207 | if (index >= 0) { |
| 6208 | String[] newArray = new String[array.length-1]; |
| 6209 | if (index > 0) { |
| 6210 | System.arraycopy(array, 0, newArray, 0, index); |
| 6211 | } |
| 6212 | if (index < array.length-1) { |
| 6213 | System.arraycopy(array, index+1, newArray, index, array.length-index-1); |
| 6214 | } |
| 6215 | return newArray; |
| 6216 | } |
| 6217 | return array; |
| 6218 | } |
| 6219 | |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 6220 | public void noteNetworkInterfaceTypeLocked(String iface, int networkType) { |
Jeff Sharkey | 9da2f1e | 2014-08-14 12:55:00 -0700 | [diff] [blame] | 6221 | if (TextUtils.isEmpty(iface)) return; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6222 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 6223 | synchronized (mModemNetworkLock) { |
| 6224 | if (ConnectivityManager.isNetworkTypeMobile(networkType)) { |
| 6225 | mModemIfaces = includeInStringArray(mModemIfaces, iface); |
| 6226 | if (DEBUG) Slog.d(TAG, "Note mobile iface " + iface + ": " + mModemIfaces); |
| 6227 | } else { |
| 6228 | mModemIfaces = excludeFromStringArray(mModemIfaces, iface); |
| 6229 | if (DEBUG) Slog.d(TAG, "Note non-mobile iface " + iface + ": " + mModemIfaces); |
| 6230 | } |
| 6231 | } |
| 6232 | |
| 6233 | synchronized (mWifiNetworkLock) { |
| 6234 | if (ConnectivityManager.isNetworkTypeWifi(networkType)) { |
| 6235 | mWifiIfaces = includeInStringArray(mWifiIfaces, iface); |
| 6236 | if (DEBUG) Slog.d(TAG, "Note wifi iface " + iface + ": " + mWifiIfaces); |
| 6237 | } else { |
| 6238 | mWifiIfaces = excludeFromStringArray(mWifiIfaces, iface); |
| 6239 | if (DEBUG) Slog.d(TAG, "Note non-wifi iface " + iface + ": " + mWifiIfaces); |
| 6240 | } |
| 6241 | } |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 6242 | } |
| 6243 | |
David Chen | c8a4324 | 2017-10-17 16:23:28 -0700 | [diff] [blame] | 6244 | public String[] getWifiIfaces() { |
| 6245 | synchronized (mWifiNetworkLock) { |
| 6246 | return mWifiIfaces; |
| 6247 | } |
| 6248 | } |
| 6249 | |
| 6250 | public String[] getMobileIfaces() { |
| 6251 | synchronized (mModemNetworkLock) { |
| 6252 | return mModemIfaces; |
| 6253 | } |
| 6254 | } |
| 6255 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6256 | @Override public long getScreenOnTime(long elapsedRealtimeUs, int which) { |
| 6257 | return mScreenOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6258 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6259 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 6260 | @Override public int getScreenOnCount(int which) { |
| 6261 | return mScreenOnTimer.getCountLocked(which); |
| 6262 | } |
| 6263 | |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 6264 | @Override public long getScreenDozeTime(long elapsedRealtimeUs, int which) { |
| 6265 | return mScreenDozeTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 6266 | } |
| 6267 | |
| 6268 | @Override public int getScreenDozeCount(int which) { |
| 6269 | return mScreenDozeTimer.getCountLocked(which); |
| 6270 | } |
| 6271 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6272 | @Override public long getScreenBrightnessTime(int brightnessBin, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6273 | long elapsedRealtimeUs, int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6274 | return mScreenBrightnessTimer[brightnessBin].getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6275 | elapsedRealtimeUs, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6276 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 6277 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 6278 | @Override public Timer getScreenBrightnessTimer(int brightnessBin) { |
| 6279 | return mScreenBrightnessTimer[brightnessBin]; |
| 6280 | } |
| 6281 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 6282 | @Override public long getInteractiveTime(long elapsedRealtimeUs, int which) { |
| 6283 | return mInteractiveTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6284 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6285 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 6286 | @Override public long getPowerSaveModeEnabledTime(long elapsedRealtimeUs, int which) { |
| 6287 | return mPowerSaveModeEnabledTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 6288 | } |
| 6289 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 6290 | @Override public int getPowerSaveModeEnabledCount(int which) { |
| 6291 | return mPowerSaveModeEnabledTimer.getCountLocked(which); |
| 6292 | } |
| 6293 | |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 6294 | @Override public long getDeviceIdleModeTime(int mode, long elapsedRealtimeUs, |
| 6295 | int which) { |
| 6296 | switch (mode) { |
| 6297 | case DEVICE_IDLE_MODE_LIGHT: |
| 6298 | return mDeviceIdleModeLightTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 6299 | case DEVICE_IDLE_MODE_DEEP: |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 6300 | return mDeviceIdleModeFullTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 6301 | } |
| 6302 | return 0; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 6303 | } |
| 6304 | |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 6305 | @Override public int getDeviceIdleModeCount(int mode, int which) { |
| 6306 | switch (mode) { |
| 6307 | case DEVICE_IDLE_MODE_LIGHT: |
| 6308 | return mDeviceIdleModeLightTimer.getCountLocked(which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 6309 | case DEVICE_IDLE_MODE_DEEP: |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 6310 | return mDeviceIdleModeFullTimer.getCountLocked(which); |
| 6311 | } |
| 6312 | return 0; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 6313 | } |
| 6314 | |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 6315 | @Override public long getLongestDeviceIdleModeTime(int mode) { |
| 6316 | switch (mode) { |
| 6317 | case DEVICE_IDLE_MODE_LIGHT: |
| 6318 | return mLongestLightIdleTime; |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 6319 | case DEVICE_IDLE_MODE_DEEP: |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 6320 | return mLongestFullIdleTime; |
| 6321 | } |
| 6322 | return 0; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6323 | } |
| 6324 | |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 6325 | @Override public long getDeviceIdlingTime(int mode, long elapsedRealtimeUs, int which) { |
| 6326 | switch (mode) { |
| 6327 | case DEVICE_IDLE_MODE_LIGHT: |
| 6328 | return mDeviceLightIdlingTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 6329 | case DEVICE_IDLE_MODE_DEEP: |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 6330 | return mDeviceIdlingTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 6331 | } |
| 6332 | return 0; |
| 6333 | } |
| 6334 | |
| 6335 | @Override public int getDeviceIdlingCount(int mode, int which) { |
| 6336 | switch (mode) { |
| 6337 | case DEVICE_IDLE_MODE_LIGHT: |
| 6338 | return mDeviceLightIdlingTimer.getCountLocked(which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 6339 | case DEVICE_IDLE_MODE_DEEP: |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 6340 | return mDeviceIdlingTimer.getCountLocked(which); |
| 6341 | } |
| 6342 | return 0; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6343 | } |
| 6344 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6345 | @Override public int getNumConnectivityChange(int which) { |
| 6346 | int val = mNumConnectivityChange; |
| 6347 | if (which == STATS_CURRENT) { |
| 6348 | val -= mLoadedNumConnectivityChange; |
| 6349 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 6350 | val -= mUnpluggedNumConnectivityChange; |
| 6351 | } |
| 6352 | return val; |
| 6353 | } |
| 6354 | |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 6355 | @Override public long getGpsSignalQualityTime(int strengthBin, |
| 6356 | long elapsedRealtimeUs, int which) { |
| 6357 | if (strengthBin < 0 || strengthBin >= GnssMetrics.NUM_GPS_SIGNAL_QUALITY_LEVELS) { |
| 6358 | return 0; |
| 6359 | } |
| 6360 | return mGpsSignalQualityTimer[strengthBin].getTotalTimeLocked( |
| 6361 | elapsedRealtimeUs, which); |
| 6362 | } |
| 6363 | |
| 6364 | @Override public long getGpsBatteryDrainMaMs() { |
Siddharth Ray | 0ed2e95 | 2018-01-22 11:32:14 -0800 | [diff] [blame] | 6365 | final double opVolt = mPowerProfile.getAveragePower( |
| 6366 | PowerProfile.POWER_GPS_OPERATING_VOLTAGE) / 1000.0; |
| 6367 | if (opVolt == 0) { |
| 6368 | return 0; |
| 6369 | } |
| 6370 | double energyUsedMaMs = 0.0; |
| 6371 | final int which = STATS_SINCE_CHARGED; |
| 6372 | final long rawRealtime = SystemClock.elapsedRealtime() * 1000; |
| 6373 | for(int i=0; i < GnssMetrics.NUM_GPS_SIGNAL_QUALITY_LEVELS; i++) { |
| 6374 | energyUsedMaMs |
| 6375 | += mPowerProfile.getAveragePower(PowerProfile.POWER_GPS_SIGNAL_QUALITY_BASED, i) |
| 6376 | * (getGpsSignalQualityTime(i, rawRealtime, which) / 1000); |
| 6377 | } |
| 6378 | return (long) energyUsedMaMs; |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 6379 | } |
| 6380 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6381 | @Override public long getPhoneOnTime(long elapsedRealtimeUs, int which) { |
| 6382 | return mPhoneOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6383 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 6384 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 6385 | @Override public int getPhoneOnCount(int which) { |
| 6386 | return mPhoneOnTimer.getCountLocked(which); |
| 6387 | } |
| 6388 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 6389 | @Override public long getPhoneSignalStrengthTime(int strengthBin, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6390 | long elapsedRealtimeUs, int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6391 | return mPhoneSignalStrengthsTimer[strengthBin].getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6392 | elapsedRealtimeUs, which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 6393 | } |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 6394 | |
| 6395 | @Override public long getPhoneSignalScanningTime( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6396 | long elapsedRealtimeUs, int which) { |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 6397 | return mPhoneSignalScanningTimer.getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6398 | elapsedRealtimeUs, which); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 6399 | } |
| 6400 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 6401 | @Override public Timer getPhoneSignalScanningTimer() { |
| 6402 | return mPhoneSignalScanningTimer; |
| 6403 | } |
| 6404 | |
Catherine Liu | fb90081 | 2012-07-17 14:12:56 -0500 | [diff] [blame] | 6405 | @Override public int getPhoneSignalStrengthCount(int strengthBin, int which) { |
| 6406 | return mPhoneSignalStrengthsTimer[strengthBin].getCountLocked(which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6407 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6408 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 6409 | @Override public Timer getPhoneSignalStrengthTimer(int strengthBin) { |
| 6410 | return mPhoneSignalStrengthsTimer[strengthBin]; |
| 6411 | } |
| 6412 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 6413 | @Override public long getPhoneDataConnectionTime(int dataType, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6414 | long elapsedRealtimeUs, int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6415 | return mPhoneDataConnectionsTimer[dataType].getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6416 | elapsedRealtimeUs, which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 6417 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6418 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6419 | @Override public int getPhoneDataConnectionCount(int dataType, int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6420 | return mPhoneDataConnectionsTimer[dataType].getCountLocked(which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6421 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6422 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 6423 | @Override public Timer getPhoneDataConnectionTimer(int dataType) { |
| 6424 | return mPhoneDataConnectionsTimer[dataType]; |
| 6425 | } |
| 6426 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6427 | @Override public long getMobileRadioActiveTime(long elapsedRealtimeUs, int which) { |
| 6428 | return mMobileRadioActiveTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 6429 | } |
| 6430 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 6431 | @Override public int getMobileRadioActiveCount(int which) { |
| 6432 | return mMobileRadioActiveTimer.getCountLocked(which); |
| 6433 | } |
| 6434 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 6435 | @Override public long getMobileRadioActiveAdjustedTime(int which) { |
| 6436 | return mMobileRadioActiveAdjustedTime.getCountLocked(which); |
| 6437 | } |
| 6438 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 6439 | @Override public long getMobileRadioActiveUnknownTime(int which) { |
| 6440 | return mMobileRadioActiveUnknownTime.getCountLocked(which); |
| 6441 | } |
| 6442 | |
| 6443 | @Override public int getMobileRadioActiveUnknownCount(int which) { |
| 6444 | return (int)mMobileRadioActiveUnknownCount.getCountLocked(which); |
| 6445 | } |
| 6446 | |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 6447 | @Override public long getWifiMulticastWakelockTime( |
| 6448 | long elapsedRealtimeUs, int which) { |
| 6449 | return mWifiMulticastWakelockTimer.getTotalTimeLocked( |
| 6450 | elapsedRealtimeUs, which); |
| 6451 | } |
| 6452 | |
| 6453 | @Override public int getWifiMulticastWakelockCount(int which) { |
| 6454 | return mWifiMulticastWakelockTimer.getCountLocked(which); |
| 6455 | } |
| 6456 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6457 | @Override public long getWifiOnTime(long elapsedRealtimeUs, int which) { |
| 6458 | return mWifiOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6459 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6460 | |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 6461 | @Override public long getWifiActiveTime(long elapsedRealtimeUs, int which) { |
| 6462 | return mWifiActiveTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 6463 | } |
| 6464 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6465 | @Override public long getGlobalWifiRunningTime(long elapsedRealtimeUs, int which) { |
| 6466 | return mGlobalWifiRunningTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 6467 | } |
| 6468 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 6469 | @Override public long getWifiStateTime(int wifiState, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6470 | long elapsedRealtimeUs, int which) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 6471 | return mWifiStateTimer[wifiState].getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6472 | elapsedRealtimeUs, which); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 6473 | } |
| 6474 | |
| 6475 | @Override public int getWifiStateCount(int wifiState, int which) { |
| 6476 | return mWifiStateTimer[wifiState].getCountLocked(which); |
| 6477 | } |
| 6478 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 6479 | @Override public Timer getWifiStateTimer(int wifiState) { |
| 6480 | return mWifiStateTimer[wifiState]; |
| 6481 | } |
| 6482 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 6483 | @Override public long getWifiSupplStateTime(int state, |
| 6484 | long elapsedRealtimeUs, int which) { |
| 6485 | return mWifiSupplStateTimer[state].getTotalTimeLocked( |
| 6486 | elapsedRealtimeUs, which); |
| 6487 | } |
| 6488 | |
| 6489 | @Override public int getWifiSupplStateCount(int state, int which) { |
| 6490 | return mWifiSupplStateTimer[state].getCountLocked(which); |
| 6491 | } |
| 6492 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 6493 | @Override public Timer getWifiSupplStateTimer(int state) { |
| 6494 | return mWifiSupplStateTimer[state]; |
| 6495 | } |
| 6496 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 6497 | @Override public long getWifiSignalStrengthTime(int strengthBin, |
| 6498 | long elapsedRealtimeUs, int which) { |
| 6499 | return mWifiSignalStrengthsTimer[strengthBin].getTotalTimeLocked( |
| 6500 | elapsedRealtimeUs, which); |
| 6501 | } |
| 6502 | |
| 6503 | @Override public int getWifiSignalStrengthCount(int strengthBin, int which) { |
| 6504 | return mWifiSignalStrengthsTimer[strengthBin].getCountLocked(which); |
| 6505 | } |
| 6506 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 6507 | @Override public Timer getWifiSignalStrengthTimer(int strengthBin) { |
| 6508 | return mWifiSignalStrengthsTimer[strengthBin]; |
| 6509 | } |
| 6510 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6511 | @Override |
| 6512 | public ControllerActivityCounter getBluetoothControllerActivity() { |
| 6513 | return mBluetoothActivity; |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 6514 | } |
| 6515 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6516 | @Override |
| 6517 | public ControllerActivityCounter getWifiControllerActivity() { |
| 6518 | return mWifiActivity; |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 6519 | } |
| 6520 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6521 | @Override |
| 6522 | public ControllerActivityCounter getModemControllerActivity() { |
| 6523 | return mModemActivity; |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 6524 | } |
| 6525 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6526 | @Override |
| 6527 | public boolean hasBluetoothActivityReporting() { |
| 6528 | return mHasBluetoothReporting; |
| 6529 | } |
| 6530 | |
| 6531 | @Override |
| 6532 | public boolean hasWifiActivityReporting() { |
| 6533 | return mHasWifiReporting; |
| 6534 | } |
| 6535 | |
| 6536 | @Override |
| 6537 | public boolean hasModemActivityReporting() { |
| 6538 | return mHasModemReporting; |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 6539 | } |
| 6540 | |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 6541 | @Override |
| 6542 | public long getFlashlightOnTime(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 6543 | return mFlashlightOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 6544 | } |
| 6545 | |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 6546 | @Override |
| 6547 | public long getFlashlightOnCount(int which) { |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 6548 | return mFlashlightOnTimer.getCountLocked(which); |
| 6549 | } |
| 6550 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6551 | @Override |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 6552 | public long getCameraOnTime(long elapsedRealtimeUs, int which) { |
| 6553 | return mCameraOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 6554 | } |
| 6555 | |
| 6556 | @Override |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 6557 | public long getBluetoothScanTime(long elapsedRealtimeUs, int which) { |
| 6558 | return mBluetoothScanTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 6559 | } |
| 6560 | |
| 6561 | @Override |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6562 | public long getNetworkActivityBytes(int type, int which) { |
| 6563 | if (type >= 0 && type < mNetworkByteActivityCounters.length) { |
| 6564 | return mNetworkByteActivityCounters[type].getCountLocked(which); |
| 6565 | } else { |
| 6566 | return 0; |
| 6567 | } |
| 6568 | } |
| 6569 | |
| 6570 | @Override |
| 6571 | public long getNetworkActivityPackets(int type, int which) { |
| 6572 | if (type >= 0 && type < mNetworkPacketActivityCounters.length) { |
| 6573 | return mNetworkPacketActivityCounters[type].getCountLocked(which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6574 | } else { |
| 6575 | return 0; |
| 6576 | } |
| 6577 | } |
| 6578 | |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 6579 | @Override public long getStartClockTime() { |
Dianne Hackborn | d48954f | 2015-07-22 17:20:33 -0700 | [diff] [blame] | 6580 | final long currentTime = System.currentTimeMillis(); |
| 6581 | if (ensureStartClockTime(currentTime)) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6582 | recordCurrentTimeChangeLocked(currentTime, mClocks.elapsedRealtime(), |
| 6583 | mClocks.uptimeMillis()); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 6584 | } |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 6585 | return mStartClockTime; |
| 6586 | } |
| 6587 | |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 6588 | @Override public String getStartPlatformVersion() { |
| 6589 | return mStartPlatformVersion; |
| 6590 | } |
| 6591 | |
| 6592 | @Override public String getEndPlatformVersion() { |
| 6593 | return mEndPlatformVersion; |
| 6594 | } |
| 6595 | |
| 6596 | @Override public int getParcelVersion() { |
| 6597 | return VERSION; |
| 6598 | } |
| 6599 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6600 | @Override public boolean getIsOnBattery() { |
| 6601 | return mOnBattery; |
| 6602 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6603 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6604 | @Override public SparseArray<? extends BatteryStats.Uid> getUidStats() { |
| 6605 | return mUidStats; |
| 6606 | } |
| 6607 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 6608 | private static void detachTimerIfNotNull(BatteryStatsImpl.Timer timer) { |
| 6609 | if (timer != null) { |
| 6610 | timer.detach(); |
| 6611 | } |
| 6612 | } |
| 6613 | |
| 6614 | private static boolean resetTimerIfNotNull(BatteryStatsImpl.Timer timer, |
| 6615 | boolean detachIfReset) { |
| 6616 | if (timer != null) { |
| 6617 | return timer.reset(detachIfReset); |
| 6618 | } |
| 6619 | return true; |
| 6620 | } |
| 6621 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 6622 | private static boolean resetTimerIfNotNull(DualTimer timer, boolean detachIfReset) { |
| 6623 | if (timer != null) { |
| 6624 | return timer.reset(detachIfReset); |
| 6625 | } |
| 6626 | return true; |
| 6627 | } |
| 6628 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 6629 | private static void detachLongCounterIfNotNull(LongSamplingCounter counter) { |
| 6630 | if (counter != null) { |
| 6631 | counter.detach(); |
| 6632 | } |
| 6633 | } |
| 6634 | |
| 6635 | private static void resetLongCounterIfNotNull(LongSamplingCounter counter, |
| 6636 | boolean detachIfReset) { |
| 6637 | if (counter != null) { |
| 6638 | counter.reset(detachIfReset); |
| 6639 | } |
| 6640 | } |
| 6641 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6642 | /** |
| 6643 | * The statistics associated with a particular uid. |
| 6644 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6645 | public static class Uid extends BatteryStats.Uid { |
| 6646 | /** |
| 6647 | * BatteryStatsImpl that we are associated with. |
| 6648 | */ |
| 6649 | protected BatteryStatsImpl mBsi; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6650 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6651 | final int mUid; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6652 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 6653 | /** TimeBase for when uid is in background and device is on battery. */ |
| 6654 | @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 6655 | public final TimeBase mOnBatteryBackgroundTimeBase; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 6656 | @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 6657 | public final TimeBase mOnBatteryScreenOffBackgroundTimeBase; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 6658 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 6659 | boolean mWifiRunning; |
| 6660 | StopwatchTimer mWifiRunningTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6661 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6662 | boolean mFullWifiLockOut; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6663 | StopwatchTimer mFullWifiLockTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6664 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 6665 | boolean mWifiScanStarted; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 6666 | DualTimer mWifiScanTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6667 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 6668 | static final int NO_BATCHED_SCAN_STARTED = -1; |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6669 | int mWifiBatchedScanBinStarted = NO_BATCHED_SCAN_STARTED; |
| 6670 | StopwatchTimer[] mWifiBatchedScanTimer; |
| 6671 | |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 6672 | boolean mWifiMulticastEnabled; |
| 6673 | StopwatchTimer mWifiMulticastTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6674 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 6675 | StopwatchTimer mAudioTurnedOnTimer; |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 6676 | StopwatchTimer mVideoTurnedOnTimer; |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 6677 | StopwatchTimer mFlashlightTurnedOnTimer; |
| 6678 | StopwatchTimer mCameraTurnedOnTimer; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6679 | StopwatchTimer mForegroundActivityTimer; |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 6680 | StopwatchTimer mForegroundServiceTimer; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 6681 | /** Total time spent by the uid holding any partial wakelocks. */ |
| 6682 | DualTimer mAggregatedPartialWakelockTimer; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 6683 | DualTimer mBluetoothScanTimer; |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 6684 | DualTimer mBluetoothUnoptimizedScanTimer; |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 6685 | Counter mBluetoothScanResultCounter; |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 6686 | Counter mBluetoothScanResultBgCounter; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6687 | |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 6688 | int mProcessState = ActivityManager.PROCESS_STATE_NONEXISTENT; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 6689 | StopwatchTimer[] mProcessStateTimer; |
| 6690 | |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 6691 | boolean mInForegroundService = false; |
| 6692 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 6693 | BatchTimer mVibratorOnTimer; |
| 6694 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6695 | Counter[] mUserActivityCounters; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6696 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6697 | LongSamplingCounter[] mNetworkByteActivityCounters; |
| 6698 | LongSamplingCounter[] mNetworkPacketActivityCounters; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 6699 | LongSamplingCounter mMobileRadioActiveTime; |
| 6700 | LongSamplingCounter mMobileRadioActiveCount; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6701 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6702 | /** |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 6703 | * How many times this UID woke up the Application Processor due to a Mobile radio packet. |
| 6704 | */ |
| 6705 | private LongSamplingCounter mMobileRadioApWakeupCount; |
| 6706 | |
| 6707 | /** |
| 6708 | * How many times this UID woke up the Application Processor due to a Wifi packet. |
| 6709 | */ |
| 6710 | private LongSamplingCounter mWifiRadioApWakeupCount; |
| 6711 | |
| 6712 | /** |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6713 | * 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] | 6714 | * Can be null if the UID has had no such activity. |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6715 | */ |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6716 | private ControllerActivityCounterImpl mWifiControllerActivity; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6717 | |
| 6718 | /** |
| 6719 | * 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] | 6720 | * Can be null if the UID has had no such activity. |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6721 | */ |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6722 | private ControllerActivityCounterImpl mBluetoothControllerActivity; |
| 6723 | |
| 6724 | /** |
| 6725 | * The amount of time this uid has kept the Modem controller in idle, tx, and rx mode. |
| 6726 | * Can be null if the UID has had no such activity. |
| 6727 | */ |
| 6728 | private ControllerActivityCounterImpl mModemControllerActivity; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6729 | |
| 6730 | /** |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 6731 | * The CPU times we had at the last history details update. |
| 6732 | */ |
| 6733 | long mLastStepUserTime; |
| 6734 | long mLastStepSystemTime; |
| 6735 | long mCurStepUserTime; |
| 6736 | long mCurStepSystemTime; |
| 6737 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6738 | LongSamplingCounter mUserCpuTime; |
| 6739 | LongSamplingCounter mSystemCpuTime; |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 6740 | LongSamplingCounter[][] mCpuClusterSpeedTimesUs; |
Mike Ma | 3d422c3 | 2017-10-25 11:08:57 -0700 | [diff] [blame] | 6741 | LongSamplingCounter mCpuActiveTimeMs; |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 6742 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 6743 | LongSamplingCounterArray mCpuFreqTimeMs; |
| 6744 | LongSamplingCounterArray mScreenOffCpuFreqTimeMs; |
Mike Ma | 3d422c3 | 2017-10-25 11:08:57 -0700 | [diff] [blame] | 6745 | LongSamplingCounterArray mCpuClusterTimesMs; |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 6746 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 6747 | LongSamplingCounterArray[] mProcStateTimeMs; |
| 6748 | LongSamplingCounterArray[] mProcStateScreenOffTimeMs; |
| 6749 | |
| 6750 | IntArray mChildUids; |
| 6751 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 6752 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6753 | * The statistics we have collected for this uid's wake locks. |
| 6754 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6755 | final OverflowArrayMap<Wakelock> mWakelockStats; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6756 | |
| 6757 | /** |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6758 | * The statistics we have collected for this uid's syncs. |
| 6759 | */ |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 6760 | final OverflowArrayMap<DualTimer> mSyncStats; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6761 | |
| 6762 | /** |
| 6763 | * The statistics we have collected for this uid's jobs. |
| 6764 | */ |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 6765 | final OverflowArrayMap<DualTimer> mJobStats; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6766 | |
| 6767 | /** |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 6768 | * Count of the jobs that have completed and the reasons why they completed. |
| 6769 | */ |
| 6770 | final ArrayMap<String, SparseIntArray> mJobCompletions = new ArrayMap<>(); |
| 6771 | |
| 6772 | /** |
Amith Yamasani | 977e11f | 2018-02-16 11:29:54 -0800 | [diff] [blame] | 6773 | * Count of app launch events that had associated deferred job counts or info about |
| 6774 | * last time a job was run. |
| 6775 | */ |
| 6776 | Counter mJobsDeferredEventCount; |
| 6777 | |
| 6778 | /** |
| 6779 | * Count of deferred jobs that were pending when the app was launched or brought to |
| 6780 | * the foreground through a user interaction. |
| 6781 | */ |
| 6782 | Counter mJobsDeferredCount; |
| 6783 | |
| 6784 | /** |
| 6785 | * Sum of time since the last time a job was run for this app before it was launched. |
| 6786 | */ |
| 6787 | LongSamplingCounter mJobsFreshnessTimeMs; |
| 6788 | |
| 6789 | /** |
| 6790 | * Array of counts of instances where the time since the last job was run for the app |
| 6791 | * fell within one of the thresholds in {@link #JOB_FRESHNESS_BUCKETS}. |
| 6792 | */ |
| 6793 | final Counter[] mJobsFreshnessBuckets; |
| 6794 | |
| 6795 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6796 | * The statistics we have collected for this uid's sensor activations. |
| 6797 | */ |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6798 | final SparseArray<Sensor> mSensorStats = new SparseArray<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6799 | |
| 6800 | /** |
| 6801 | * The statistics we have collected for this uid's processes. |
| 6802 | */ |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6803 | final ArrayMap<String, Proc> mProcessStats = new ArrayMap<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6804 | |
| 6805 | /** |
| 6806 | * The statistics we have collected for this uid's processes. |
| 6807 | */ |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6808 | final ArrayMap<String, Pkg> mPackageStats = new ArrayMap<>(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6809 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6810 | /** |
| 6811 | * The transient wake stats we have collected for this uid's pids. |
| 6812 | */ |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6813 | final SparseArray<Pid> mPids = new SparseArray<>(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6814 | |
Narayan Kamath | 0ebc96c | 2017-12-29 13:32:38 +0000 | [diff] [blame] | 6815 | /** |
| 6816 | * The list of WorkChains associated with active bluetooth scans. |
| 6817 | * |
| 6818 | * NOTE: This is a hack and it only needs to exist because there's a "reset" API that is |
| 6819 | * supposed to stop and log all WorkChains that were currently active. |
| 6820 | */ |
| 6821 | ArrayList<WorkChain> mAllBluetoothChains = null; |
| 6822 | ArrayList<WorkChain> mUnoptimizedBluetoothChains = null; |
| 6823 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6824 | public Uid(BatteryStatsImpl bsi, int uid) { |
| 6825 | mBsi = bsi; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6826 | mUid = uid; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6827 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 6828 | mOnBatteryBackgroundTimeBase = new TimeBase(); |
| 6829 | mOnBatteryBackgroundTimeBase.init(mBsi.mClocks.uptimeMillis() * 1000, |
| 6830 | mBsi.mClocks.elapsedRealtime() * 1000); |
| 6831 | |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 6832 | mOnBatteryScreenOffBackgroundTimeBase = new TimeBase(); |
| 6833 | mOnBatteryScreenOffBackgroundTimeBase.init(mBsi.mClocks.uptimeMillis() * 1000, |
| 6834 | mBsi.mClocks.elapsedRealtime() * 1000); |
| 6835 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6836 | mUserCpuTime = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
| 6837 | mSystemCpuTime = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
Mike Ma | 3d422c3 | 2017-10-25 11:08:57 -0700 | [diff] [blame] | 6838 | mCpuActiveTimeMs = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
| 6839 | mCpuClusterTimesMs = new LongSamplingCounterArray(mBsi.mOnBatteryTimeBase); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6840 | |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame] | 6841 | mWakelockStats = mBsi.new OverflowArrayMap<Wakelock>(uid) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6842 | @Override public Wakelock instantiateObject() { |
| 6843 | return new Wakelock(mBsi, Uid.this); |
| 6844 | } |
| 6845 | }; |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 6846 | mSyncStats = mBsi.new OverflowArrayMap<DualTimer>(uid) { |
| 6847 | @Override public DualTimer instantiateObject() { |
| 6848 | return new DualTimer(mBsi.mClocks, Uid.this, SYNC, null, |
| 6849 | mBsi.mOnBatteryTimeBase, mOnBatteryBackgroundTimeBase); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6850 | } |
| 6851 | }; |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 6852 | mJobStats = mBsi.new OverflowArrayMap<DualTimer>(uid) { |
| 6853 | @Override public DualTimer instantiateObject() { |
| 6854 | return new DualTimer(mBsi.mClocks, Uid.this, JOB, null, |
| 6855 | mBsi.mOnBatteryTimeBase, mOnBatteryBackgroundTimeBase); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6856 | } |
| 6857 | }; |
| 6858 | |
| 6859 | mWifiRunningTimer = new StopwatchTimer(mBsi.mClocks, this, WIFI_RUNNING, |
| 6860 | mBsi.mWifiRunningTimers, mBsi.mOnBatteryTimeBase); |
| 6861 | mFullWifiLockTimer = new StopwatchTimer(mBsi.mClocks, this, FULL_WIFI_LOCK, |
| 6862 | mBsi.mFullWifiLockTimers, mBsi.mOnBatteryTimeBase); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 6863 | mWifiScanTimer = new DualTimer(mBsi.mClocks, this, WIFI_SCAN, |
| 6864 | mBsi.mWifiScanTimers, mBsi.mOnBatteryTimeBase, mOnBatteryBackgroundTimeBase); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6865 | mWifiBatchedScanTimer = new StopwatchTimer[NUM_WIFI_BATCHED_SCAN_BINS]; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6866 | mWifiMulticastTimer = new StopwatchTimer(mBsi.mClocks, this, WIFI_MULTICAST_ENABLED, |
| 6867 | mBsi.mWifiMulticastTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 6868 | mProcessStateTimer = new StopwatchTimer[NUM_PROCESS_STATE]; |
Amith Yamasani | 977e11f | 2018-02-16 11:29:54 -0800 | [diff] [blame] | 6869 | mJobsDeferredEventCount = new Counter(mBsi.mOnBatteryTimeBase); |
| 6870 | mJobsDeferredCount = new Counter(mBsi.mOnBatteryTimeBase); |
| 6871 | mJobsFreshnessTimeMs = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
| 6872 | mJobsFreshnessBuckets = new Counter[JOB_FRESHNESS_BUCKETS.length]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6873 | } |
| 6874 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 6875 | @VisibleForTesting |
| 6876 | public void setProcessStateForTest(int procState) { |
| 6877 | mProcessState = procState; |
| 6878 | } |
| 6879 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6880 | @Override |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 6881 | public long[] getCpuFreqTimes(int which) { |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 6882 | return nullIfAllZeros(mCpuFreqTimeMs, which); |
| 6883 | } |
| 6884 | |
| 6885 | @Override |
| 6886 | public long[] getScreenOffCpuFreqTimes(int which) { |
| 6887 | return nullIfAllZeros(mScreenOffCpuFreqTimeMs, which); |
| 6888 | } |
| 6889 | |
| 6890 | @Override |
Mike Ma | 3d422c3 | 2017-10-25 11:08:57 -0700 | [diff] [blame] | 6891 | public long getCpuActiveTime() { |
| 6892 | return mCpuActiveTimeMs.getCountLocked(STATS_SINCE_CHARGED); |
| 6893 | } |
| 6894 | |
| 6895 | @Override |
| 6896 | public long[] getCpuClusterTimes() { |
| 6897 | return nullIfAllZeros(mCpuClusterTimesMs, STATS_SINCE_CHARGED); |
| 6898 | } |
| 6899 | |
| 6900 | |
| 6901 | @Override |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 6902 | public long[] getCpuFreqTimes(int which, int procState) { |
| 6903 | if (which < 0 || which >= NUM_PROCESS_STATE) { |
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 (mProcStateTimeMs == null) { |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 6907 | return null; |
| 6908 | } |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 6909 | if (!mBsi.mPerProcStateCpuTimesAvailable) { |
| 6910 | mProcStateTimeMs = null; |
| 6911 | return null; |
| 6912 | } |
| 6913 | return nullIfAllZeros(mProcStateTimeMs[procState], which); |
| 6914 | } |
| 6915 | |
| 6916 | @Override |
| 6917 | public long[] getScreenOffCpuFreqTimes(int which, int procState) { |
| 6918 | if (which < 0 || which >= NUM_PROCESS_STATE) { |
| 6919 | return null; |
| 6920 | } |
| 6921 | if (mProcStateScreenOffTimeMs == null) { |
| 6922 | return null; |
| 6923 | } |
| 6924 | if (!mBsi.mPerProcStateCpuTimesAvailable) { |
| 6925 | mProcStateScreenOffTimeMs = null; |
| 6926 | return null; |
| 6927 | } |
| 6928 | return nullIfAllZeros(mProcStateScreenOffTimeMs[procState], which); |
| 6929 | } |
| 6930 | |
| 6931 | public void addIsolatedUid(int isolatedUid) { |
| 6932 | if (mChildUids == null) { |
| 6933 | mChildUids = new IntArray(); |
| 6934 | } else if (mChildUids.indexOf(isolatedUid) >= 0) { |
| 6935 | return; |
| 6936 | } |
| 6937 | mChildUids.add(isolatedUid); |
| 6938 | } |
| 6939 | |
| 6940 | public void removeIsolatedUid(int isolatedUid) { |
| 6941 | final int idx = mChildUids == null ? -1 : mChildUids.indexOf(isolatedUid); |
| 6942 | if (idx < 0) { |
| 6943 | return; |
| 6944 | } |
| 6945 | mChildUids.remove(idx); |
| 6946 | } |
| 6947 | |
| 6948 | private long[] nullIfAllZeros(LongSamplingCounterArray cpuTimesMs, int which) { |
| 6949 | if (cpuTimesMs == null) { |
| 6950 | return null; |
| 6951 | } |
| 6952 | final long[] counts = cpuTimesMs.getCountsLocked(which); |
| 6953 | if (counts == null) { |
| 6954 | return null; |
| 6955 | } |
| 6956 | // Return counts only if at least one of the elements is non-zero. |
| 6957 | for (int i = counts.length - 1; i >= 0; --i) { |
| 6958 | if (counts[i] != 0) { |
| 6959 | return counts; |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 6960 | } |
| 6961 | } |
| 6962 | return null; |
| 6963 | } |
| 6964 | |
Sudheer Shanka | e544d16 | 2017-12-28 17:06:20 -0800 | [diff] [blame] | 6965 | private void addProcStateTimesMs(int procState, long[] cpuTimesMs, boolean onBattery) { |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 6966 | if (mProcStateTimeMs == null) { |
| 6967 | mProcStateTimeMs = new LongSamplingCounterArray[NUM_PROCESS_STATE]; |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 6968 | } |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 6969 | if (mProcStateTimeMs[procState] == null |
| 6970 | || mProcStateTimeMs[procState].getSize() != cpuTimesMs.length) { |
| 6971 | mProcStateTimeMs[procState] = new LongSamplingCounterArray( |
| 6972 | mBsi.mOnBatteryTimeBase); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 6973 | } |
Sudheer Shanka | e544d16 | 2017-12-28 17:06:20 -0800 | [diff] [blame] | 6974 | mProcStateTimeMs[procState].addCountLocked(cpuTimesMs, onBattery); |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 6975 | } |
| 6976 | |
Sudheer Shanka | e544d16 | 2017-12-28 17:06:20 -0800 | [diff] [blame] | 6977 | private void addProcStateScreenOffTimesMs(int procState, long[] cpuTimesMs, |
| 6978 | boolean onBatteryScreenOff) { |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 6979 | if (mProcStateScreenOffTimeMs == null) { |
| 6980 | mProcStateScreenOffTimeMs = new LongSamplingCounterArray[NUM_PROCESS_STATE]; |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 6981 | } |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 6982 | if (mProcStateScreenOffTimeMs[procState] == null |
| 6983 | || mProcStateScreenOffTimeMs[procState].getSize() != cpuTimesMs.length) { |
| 6984 | mProcStateScreenOffTimeMs[procState] = new LongSamplingCounterArray( |
| 6985 | mBsi.mOnBatteryScreenOffTimeBase); |
| 6986 | } |
Sudheer Shanka | e544d16 | 2017-12-28 17:06:20 -0800 | [diff] [blame] | 6987 | mProcStateScreenOffTimeMs[procState].addCountLocked(cpuTimesMs, onBatteryScreenOff); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 6988 | } |
| 6989 | |
| 6990 | @Override |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 6991 | public Timer getAggregatedPartialWakelockTimer() { |
| 6992 | return mAggregatedPartialWakelockTimer; |
| 6993 | } |
| 6994 | |
| 6995 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6996 | public ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> getWakelockStats() { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6997 | return mWakelockStats.getMap(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6998 | } |
| 6999 | |
| 7000 | @Override |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 7001 | public Timer getMulticastWakelockStats() { |
| 7002 | return mWifiMulticastTimer; |
| 7003 | } |
| 7004 | |
| 7005 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 7006 | public ArrayMap<String, ? extends BatteryStats.Timer> getSyncStats() { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7007 | return mSyncStats.getMap(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 7008 | } |
| 7009 | |
| 7010 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 7011 | public ArrayMap<String, ? extends BatteryStats.Timer> getJobStats() { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7012 | return mJobStats.getMap(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 7013 | } |
| 7014 | |
| 7015 | @Override |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 7016 | public ArrayMap<String, SparseIntArray> getJobCompletionStats() { |
| 7017 | return mJobCompletions; |
| 7018 | } |
| 7019 | |
| 7020 | @Override |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 7021 | public SparseArray<? extends BatteryStats.Uid.Sensor> getSensorStats() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7022 | return mSensorStats; |
| 7023 | } |
| 7024 | |
| 7025 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 7026 | public ArrayMap<String, ? extends BatteryStats.Uid.Proc> getProcessStats() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7027 | return mProcessStats; |
| 7028 | } |
| 7029 | |
| 7030 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 7031 | public ArrayMap<String, ? extends BatteryStats.Uid.Pkg> getPackageStats() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7032 | return mPackageStats; |
| 7033 | } |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 7034 | |
| 7035 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7036 | public int getUid() { |
| 7037 | return mUid; |
| 7038 | } |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 7039 | |
| 7040 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7041 | public void noteWifiRunningLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 7042 | if (!mWifiRunning) { |
| 7043 | mWifiRunning = true; |
| 7044 | if (mWifiRunningTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7045 | mWifiRunningTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, WIFI_RUNNING, |
| 7046 | mBsi.mWifiRunningTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7047 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7048 | mWifiRunningTimer.startRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 7049 | } |
| 7050 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7051 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 7052 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7053 | public void noteWifiStoppedLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 7054 | if (mWifiRunning) { |
| 7055 | mWifiRunning = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7056 | mWifiRunningTimer.stopRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 7057 | } |
| 7058 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7059 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 7060 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7061 | public void noteFullWifiLockAcquiredLocked(long elapsedRealtimeMs) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7062 | if (!mFullWifiLockOut) { |
| 7063 | mFullWifiLockOut = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7064 | if (mFullWifiLockTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7065 | mFullWifiLockTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, FULL_WIFI_LOCK, |
| 7066 | mBsi.mFullWifiLockTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7067 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7068 | mFullWifiLockTimer.startRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7069 | } |
| 7070 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7071 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7072 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7073 | public void noteFullWifiLockReleasedLocked(long elapsedRealtimeMs) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7074 | if (mFullWifiLockOut) { |
| 7075 | mFullWifiLockOut = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7076 | mFullWifiLockTimer.stopRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7077 | } |
| 7078 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7079 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7080 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7081 | public void noteWifiScanStartedLocked(long elapsedRealtimeMs) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 7082 | if (!mWifiScanStarted) { |
| 7083 | mWifiScanStarted = true; |
| 7084 | if (mWifiScanTimer == null) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 7085 | mWifiScanTimer = new DualTimer(mBsi.mClocks, Uid.this, WIFI_SCAN, |
| 7086 | mBsi.mWifiScanTimers, mBsi.mOnBatteryTimeBase, |
| 7087 | mOnBatteryBackgroundTimeBase); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7088 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7089 | mWifiScanTimer.startRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7090 | } |
| 7091 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7092 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7093 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7094 | public void noteWifiScanStoppedLocked(long elapsedRealtimeMs) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 7095 | if (mWifiScanStarted) { |
| 7096 | mWifiScanStarted = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7097 | mWifiScanTimer.stopRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7098 | } |
| 7099 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 7100 | |
| 7101 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7102 | public void noteWifiBatchedScanStartedLocked(int csph, long elapsedRealtimeMs) { |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 7103 | int bin = 0; |
Navtej Singh Mann | 3c0ce5c | 2015-06-11 16:53:11 -0700 | [diff] [blame] | 7104 | while (csph > 8 && bin < NUM_WIFI_BATCHED_SCAN_BINS-1) { |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 7105 | csph = csph >> 3; |
| 7106 | bin++; |
| 7107 | } |
| 7108 | |
| 7109 | if (mWifiBatchedScanBinStarted == bin) return; |
| 7110 | |
| 7111 | if (mWifiBatchedScanBinStarted != NO_BATCHED_SCAN_STARTED) { |
| 7112 | mWifiBatchedScanTimer[mWifiBatchedScanBinStarted]. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7113 | stopRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 7114 | } |
| 7115 | mWifiBatchedScanBinStarted = bin; |
| 7116 | if (mWifiBatchedScanTimer[bin] == null) { |
| 7117 | makeWifiBatchedScanBin(bin, null); |
| 7118 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7119 | mWifiBatchedScanTimer[bin].startRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 7120 | } |
| 7121 | |
| 7122 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7123 | public void noteWifiBatchedScanStoppedLocked(long elapsedRealtimeMs) { |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 7124 | if (mWifiBatchedScanBinStarted != NO_BATCHED_SCAN_STARTED) { |
| 7125 | mWifiBatchedScanTimer[mWifiBatchedScanBinStarted]. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7126 | stopRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 7127 | mWifiBatchedScanBinStarted = NO_BATCHED_SCAN_STARTED; |
| 7128 | } |
| 7129 | } |
| 7130 | |
| 7131 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7132 | public void noteWifiMulticastEnabledLocked(long elapsedRealtimeMs) { |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 7133 | if (!mWifiMulticastEnabled) { |
| 7134 | mWifiMulticastEnabled = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7135 | if (mWifiMulticastTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7136 | mWifiMulticastTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, |
| 7137 | WIFI_MULTICAST_ENABLED, mBsi.mWifiMulticastTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7138 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7139 | mWifiMulticastTimer.startRunningLocked(elapsedRealtimeMs); |
Tej Singh | 4503e10 | 2018-01-04 14:35:01 -0800 | [diff] [blame] | 7140 | StatsLog.write_non_chained( |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 7141 | StatsLog.WIFI_MULTICAST_LOCK_STATE_CHANGED, getUid(), null, |
| 7142 | StatsLog.WIFI_MULTICAST_LOCK_STATE_CHANGED__STATE__ON); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 7143 | } |
| 7144 | } |
| 7145 | |
| 7146 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7147 | public void noteWifiMulticastDisabledLocked(long elapsedRealtimeMs) { |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 7148 | if (mWifiMulticastEnabled) { |
| 7149 | mWifiMulticastEnabled = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7150 | mWifiMulticastTimer.stopRunningLocked(elapsedRealtimeMs); |
Tej Singh | 4503e10 | 2018-01-04 14:35:01 -0800 | [diff] [blame] | 7151 | StatsLog.write_non_chained( |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 7152 | StatsLog.WIFI_MULTICAST_LOCK_STATE_CHANGED, getUid(), null, |
| 7153 | StatsLog.WIFI_MULTICAST_LOCK_STATE_CHANGED__STATE__OFF); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 7154 | } |
| 7155 | } |
| 7156 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 7157 | @Override |
| 7158 | public ControllerActivityCounter getWifiControllerActivity() { |
| 7159 | return mWifiControllerActivity; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7160 | } |
| 7161 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 7162 | @Override |
| 7163 | public ControllerActivityCounter getBluetoothControllerActivity() { |
| 7164 | return mBluetoothControllerActivity; |
| 7165 | } |
| 7166 | |
| 7167 | @Override |
| 7168 | public ControllerActivityCounter getModemControllerActivity() { |
| 7169 | return mModemControllerActivity; |
| 7170 | } |
| 7171 | |
| 7172 | public ControllerActivityCounterImpl getOrCreateWifiControllerActivityLocked() { |
| 7173 | if (mWifiControllerActivity == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7174 | mWifiControllerActivity = new ControllerActivityCounterImpl(mBsi.mOnBatteryTimeBase, |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 7175 | NUM_BT_TX_LEVELS); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 7176 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 7177 | return mWifiControllerActivity; |
| 7178 | } |
| 7179 | |
| 7180 | public ControllerActivityCounterImpl getOrCreateBluetoothControllerActivityLocked() { |
| 7181 | if (mBluetoothControllerActivity == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7182 | mBluetoothControllerActivity = new ControllerActivityCounterImpl(mBsi.mOnBatteryTimeBase, |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 7183 | NUM_BT_TX_LEVELS); |
| 7184 | } |
| 7185 | return mBluetoothControllerActivity; |
| 7186 | } |
| 7187 | |
| 7188 | public ControllerActivityCounterImpl getOrCreateModemControllerActivityLocked() { |
| 7189 | if (mModemControllerActivity == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7190 | mModemControllerActivity = new ControllerActivityCounterImpl(mBsi.mOnBatteryTimeBase, |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 7191 | ModemActivityInfo.TX_POWER_LEVELS); |
| 7192 | } |
| 7193 | return mModemControllerActivity; |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 7194 | } |
| 7195 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 7196 | public StopwatchTimer createAudioTurnedOnTimerLocked() { |
| 7197 | if (mAudioTurnedOnTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7198 | mAudioTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, AUDIO_TURNED_ON, |
| 7199 | mBsi.mAudioTurnedOnTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 7200 | } |
| 7201 | return mAudioTurnedOnTimer; |
| 7202 | } |
| 7203 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7204 | public void noteAudioTurnedOnLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 7205 | createAudioTurnedOnTimerLocked().startRunningLocked(elapsedRealtimeMs); |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 7206 | StatsLog.write_non_chained(StatsLog.AUDIO_STATE_CHANGED, getUid(), null, |
| 7207 | StatsLog.AUDIO_STATE_CHANGED__STATE__ON); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 7208 | } |
| 7209 | |
| 7210 | public void noteAudioTurnedOffLocked(long elapsedRealtimeMs) { |
| 7211 | if (mAudioTurnedOnTimer != null) { |
| 7212 | mAudioTurnedOnTimer.stopRunningLocked(elapsedRealtimeMs); |
Bookatz | c1a050a | 2017-10-10 15:49:28 -0700 | [diff] [blame] | 7213 | if (!mAudioTurnedOnTimer.isRunningLocked()) { // only tell statsd if truly stopped |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 7214 | StatsLog.write_non_chained(StatsLog.AUDIO_STATE_CHANGED, getUid(), null, |
| 7215 | StatsLog.AUDIO_STATE_CHANGED__STATE__OFF); |
Bookatz | c1a050a | 2017-10-10 15:49:28 -0700 | [diff] [blame] | 7216 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7217 | } |
| 7218 | } |
| 7219 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 7220 | public void noteResetAudioLocked(long elapsedRealtimeMs) { |
| 7221 | if (mAudioTurnedOnTimer != null) { |
| 7222 | mAudioTurnedOnTimer.stopAllRunningLocked(elapsedRealtimeMs); |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 7223 | StatsLog.write_non_chained(StatsLog.AUDIO_STATE_CHANGED, getUid(), null, |
| 7224 | StatsLog.AUDIO_STATE_CHANGED__STATE__OFF); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7225 | } |
| 7226 | } |
| 7227 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 7228 | public StopwatchTimer createVideoTurnedOnTimerLocked() { |
| 7229 | if (mVideoTurnedOnTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7230 | mVideoTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, VIDEO_TURNED_ON, |
| 7231 | mBsi.mVideoTurnedOnTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 7232 | } |
| 7233 | return mVideoTurnedOnTimer; |
| 7234 | } |
| 7235 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7236 | public void noteVideoTurnedOnLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 7237 | createVideoTurnedOnTimerLocked().startRunningLocked(elapsedRealtimeMs); |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 7238 | StatsLog.write_non_chained(StatsLog.MEDIA_CODEC_ACTIVITY_CHANGED, getUid(), null, |
| 7239 | StatsLog.MEDIA_CODEC_ACTIVITY_CHANGED__STATE__ON); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 7240 | } |
| 7241 | |
| 7242 | public void noteVideoTurnedOffLocked(long elapsedRealtimeMs) { |
| 7243 | if (mVideoTurnedOnTimer != null) { |
| 7244 | mVideoTurnedOnTimer.stopRunningLocked(elapsedRealtimeMs); |
Bookatz | c1a050a | 2017-10-10 15:49:28 -0700 | [diff] [blame] | 7245 | if (!mVideoTurnedOnTimer.isRunningLocked()) { // only tell statsd if truly stopped |
Yangster-mac | 2f5daec | 2018-01-16 10:23:15 -0800 | [diff] [blame] | 7246 | StatsLog.write_non_chained(StatsLog.MEDIA_CODEC_ACTIVITY_CHANGED, getUid(), |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 7247 | null, StatsLog.MEDIA_CODEC_ACTIVITY_CHANGED__STATE__OFF); |
Bookatz | c1a050a | 2017-10-10 15:49:28 -0700 | [diff] [blame] | 7248 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7249 | } |
| 7250 | } |
| 7251 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 7252 | public void noteResetVideoLocked(long elapsedRealtimeMs) { |
| 7253 | if (mVideoTurnedOnTimer != null) { |
| 7254 | mVideoTurnedOnTimer.stopAllRunningLocked(elapsedRealtimeMs); |
Yangster-mac | 2f5daec | 2018-01-16 10:23:15 -0800 | [diff] [blame] | 7255 | StatsLog.write_non_chained(StatsLog.MEDIA_CODEC_ACTIVITY_CHANGED, getUid(), null, |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 7256 | StatsLog.MEDIA_CODEC_ACTIVITY_CHANGED__STATE__OFF); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 7257 | } |
| 7258 | } |
| 7259 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 7260 | public StopwatchTimer createFlashlightTurnedOnTimerLocked() { |
| 7261 | if (mFlashlightTurnedOnTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7262 | mFlashlightTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, |
| 7263 | FLASHLIGHT_TURNED_ON, mBsi.mFlashlightTurnedOnTimers, mBsi.mOnBatteryTimeBase); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 7264 | } |
| 7265 | return mFlashlightTurnedOnTimer; |
| 7266 | } |
| 7267 | |
| 7268 | public void noteFlashlightTurnedOnLocked(long elapsedRealtimeMs) { |
| 7269 | createFlashlightTurnedOnTimerLocked().startRunningLocked(elapsedRealtimeMs); |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 7270 | StatsLog.write_non_chained(StatsLog.FLASHLIGHT_STATE_CHANGED, getUid(), null, |
| 7271 | StatsLog.FLASHLIGHT_STATE_CHANGED__STATE__ON); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 7272 | } |
| 7273 | |
| 7274 | public void noteFlashlightTurnedOffLocked(long elapsedRealtimeMs) { |
| 7275 | if (mFlashlightTurnedOnTimer != null) { |
| 7276 | mFlashlightTurnedOnTimer.stopRunningLocked(elapsedRealtimeMs); |
Bookatz | c1a050a | 2017-10-10 15:49:28 -0700 | [diff] [blame] | 7277 | if (!mFlashlightTurnedOnTimer.isRunningLocked()) { |
Yangster-mac | 2f5daec | 2018-01-16 10:23:15 -0800 | [diff] [blame] | 7278 | StatsLog.write_non_chained(StatsLog.FLASHLIGHT_STATE_CHANGED, getUid(), null, |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 7279 | StatsLog.FLASHLIGHT_STATE_CHANGED__STATE__OFF); |
Bookatz | c1a050a | 2017-10-10 15:49:28 -0700 | [diff] [blame] | 7280 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 7281 | } |
| 7282 | } |
| 7283 | |
| 7284 | public void noteResetFlashlightLocked(long elapsedRealtimeMs) { |
| 7285 | if (mFlashlightTurnedOnTimer != null) { |
| 7286 | mFlashlightTurnedOnTimer.stopAllRunningLocked(elapsedRealtimeMs); |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 7287 | StatsLog.write_non_chained(StatsLog.FLASHLIGHT_STATE_CHANGED, getUid(), null, |
| 7288 | StatsLog.FLASHLIGHT_STATE_CHANGED__STATE__OFF); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 7289 | } |
| 7290 | } |
| 7291 | |
| 7292 | public StopwatchTimer createCameraTurnedOnTimerLocked() { |
| 7293 | if (mCameraTurnedOnTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7294 | mCameraTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, CAMERA_TURNED_ON, |
| 7295 | mBsi.mCameraTurnedOnTimers, mBsi.mOnBatteryTimeBase); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 7296 | } |
| 7297 | return mCameraTurnedOnTimer; |
| 7298 | } |
| 7299 | |
| 7300 | public void noteCameraTurnedOnLocked(long elapsedRealtimeMs) { |
| 7301 | createCameraTurnedOnTimerLocked().startRunningLocked(elapsedRealtimeMs); |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 7302 | StatsLog.write_non_chained(StatsLog.CAMERA_STATE_CHANGED, getUid(), null, |
| 7303 | StatsLog.CAMERA_STATE_CHANGED__STATE__ON); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 7304 | } |
| 7305 | |
| 7306 | public void noteCameraTurnedOffLocked(long elapsedRealtimeMs) { |
| 7307 | if (mCameraTurnedOnTimer != null) { |
| 7308 | mCameraTurnedOnTimer.stopRunningLocked(elapsedRealtimeMs); |
Bookatz | c1a050a | 2017-10-10 15:49:28 -0700 | [diff] [blame] | 7309 | if (!mCameraTurnedOnTimer.isRunningLocked()) { // only tell statsd if truly stopped |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 7310 | StatsLog.write_non_chained(StatsLog.CAMERA_STATE_CHANGED, getUid(), null, |
| 7311 | StatsLog.CAMERA_STATE_CHANGED__STATE__OFF); |
Bookatz | c1a050a | 2017-10-10 15:49:28 -0700 | [diff] [blame] | 7312 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 7313 | } |
| 7314 | } |
| 7315 | |
| 7316 | public void noteResetCameraLocked(long elapsedRealtimeMs) { |
| 7317 | if (mCameraTurnedOnTimer != null) { |
| 7318 | mCameraTurnedOnTimer.stopAllRunningLocked(elapsedRealtimeMs); |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 7319 | StatsLog.write_non_chained(StatsLog.CAMERA_STATE_CHANGED, getUid(), null, |
| 7320 | StatsLog.CAMERA_STATE_CHANGED__STATE__OFF); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 7321 | } |
| 7322 | } |
| 7323 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 7324 | public StopwatchTimer createForegroundActivityTimerLocked() { |
| 7325 | if (mForegroundActivityTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7326 | mForegroundActivityTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, |
| 7327 | FOREGROUND_ACTIVITY, null, mBsi.mOnBatteryTimeBase); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 7328 | } |
| 7329 | return mForegroundActivityTimer; |
| 7330 | } |
| 7331 | |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 7332 | public StopwatchTimer createForegroundServiceTimerLocked() { |
| 7333 | if (mForegroundServiceTimer == null) { |
| 7334 | mForegroundServiceTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, |
| 7335 | FOREGROUND_SERVICE, null, mBsi.mOnBatteryTimeBase); |
| 7336 | } |
| 7337 | return mForegroundServiceTimer; |
| 7338 | } |
| 7339 | |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 7340 | public DualTimer createAggregatedPartialWakelockTimerLocked() { |
| 7341 | if (mAggregatedPartialWakelockTimer == null) { |
| 7342 | mAggregatedPartialWakelockTimer = new DualTimer(mBsi.mClocks, this, |
| 7343 | AGGREGATED_WAKE_TYPE_PARTIAL, null, |
| 7344 | mBsi.mOnBatteryScreenOffTimeBase, mOnBatteryScreenOffBackgroundTimeBase); |
| 7345 | } |
| 7346 | return mAggregatedPartialWakelockTimer; |
| 7347 | } |
| 7348 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 7349 | public DualTimer createBluetoothScanTimerLocked() { |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 7350 | if (mBluetoothScanTimer == null) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 7351 | mBluetoothScanTimer = new DualTimer(mBsi.mClocks, Uid.this, BLUETOOTH_SCAN_ON, |
| 7352 | mBsi.mBluetoothScanOnTimers, mBsi.mOnBatteryTimeBase, |
| 7353 | mOnBatteryBackgroundTimeBase); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 7354 | } |
| 7355 | return mBluetoothScanTimer; |
| 7356 | } |
| 7357 | |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 7358 | public DualTimer createBluetoothUnoptimizedScanTimerLocked() { |
| 7359 | if (mBluetoothUnoptimizedScanTimer == null) { |
| 7360 | mBluetoothUnoptimizedScanTimer = new DualTimer(mBsi.mClocks, Uid.this, |
| 7361 | BLUETOOTH_UNOPTIMIZED_SCAN_ON, null, |
| 7362 | mBsi.mOnBatteryTimeBase, mOnBatteryBackgroundTimeBase); |
| 7363 | } |
| 7364 | return mBluetoothUnoptimizedScanTimer; |
| 7365 | } |
| 7366 | |
Narayan Kamath | 0ebc96c | 2017-12-29 13:32:38 +0000 | [diff] [blame] | 7367 | public void noteBluetoothScanStartedLocked(long elapsedRealtimeMs, |
| 7368 | boolean isUnoptimized) { |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 7369 | createBluetoothScanTimerLocked().startRunningLocked(elapsedRealtimeMs); |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 7370 | if (isUnoptimized) { |
| 7371 | createBluetoothUnoptimizedScanTimerLocked().startRunningLocked(elapsedRealtimeMs); |
| 7372 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 7373 | } |
| 7374 | |
Bookatz | 94c5a31 | 2017-07-11 16:49:17 -0700 | [diff] [blame] | 7375 | public void noteBluetoothScanStoppedLocked(long elapsedRealtimeMs, boolean isUnoptimized) { |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 7376 | if (mBluetoothScanTimer != null) { |
| 7377 | mBluetoothScanTimer.stopRunningLocked(elapsedRealtimeMs); |
| 7378 | } |
Bookatz | 94c5a31 | 2017-07-11 16:49:17 -0700 | [diff] [blame] | 7379 | if (isUnoptimized && mBluetoothUnoptimizedScanTimer != null) { |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 7380 | mBluetoothUnoptimizedScanTimer.stopRunningLocked(elapsedRealtimeMs); |
| 7381 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 7382 | } |
| 7383 | |
Narayan Kamath | 0ebc96c | 2017-12-29 13:32:38 +0000 | [diff] [blame] | 7384 | public void addBluetoothWorkChain(WorkChain workChain, boolean isUnoptimized) { |
| 7385 | if (mAllBluetoothChains == null) { |
| 7386 | mAllBluetoothChains = new ArrayList<WorkChain>(4); |
| 7387 | } |
| 7388 | |
| 7389 | if (isUnoptimized && mUnoptimizedBluetoothChains == null) { |
| 7390 | mUnoptimizedBluetoothChains = new ArrayList<WorkChain>(4); |
| 7391 | } |
| 7392 | |
| 7393 | mAllBluetoothChains.add(workChain); |
| 7394 | if (isUnoptimized) { |
| 7395 | mUnoptimizedBluetoothChains.add(workChain); |
| 7396 | } |
| 7397 | } |
| 7398 | |
| 7399 | public void removeBluetoothWorkChain(WorkChain workChain, boolean isUnoptimized) { |
| 7400 | if (mAllBluetoothChains != null) { |
| 7401 | mAllBluetoothChains.remove(workChain); |
| 7402 | } |
| 7403 | |
| 7404 | if (isUnoptimized && mUnoptimizedBluetoothChains != null) { |
| 7405 | mUnoptimizedBluetoothChains.remove(workChain); |
| 7406 | } |
| 7407 | } |
| 7408 | |
| 7409 | public List<WorkChain> getAllBluetoothWorkChains() { |
| 7410 | return mAllBluetoothChains; |
| 7411 | } |
| 7412 | |
| 7413 | public List<WorkChain> getUnoptimizedBluetoothWorkChains() { |
| 7414 | return mUnoptimizedBluetoothChains; |
| 7415 | } |
| 7416 | |
| 7417 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 7418 | public void noteResetBluetoothScanLocked(long elapsedRealtimeMs) { |
| 7419 | if (mBluetoothScanTimer != null) { |
| 7420 | mBluetoothScanTimer.stopAllRunningLocked(elapsedRealtimeMs); |
| 7421 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 7422 | if (mBluetoothUnoptimizedScanTimer != null) { |
| 7423 | mBluetoothUnoptimizedScanTimer.stopAllRunningLocked(elapsedRealtimeMs); |
| 7424 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 7425 | } |
| 7426 | |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 7427 | public Counter createBluetoothScanResultCounterLocked() { |
| 7428 | if (mBluetoothScanResultCounter == null) { |
| 7429 | mBluetoothScanResultCounter = new Counter(mBsi.mOnBatteryTimeBase); |
| 7430 | } |
| 7431 | return mBluetoothScanResultCounter; |
| 7432 | } |
| 7433 | |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 7434 | public Counter createBluetoothScanResultBgCounterLocked() { |
| 7435 | if (mBluetoothScanResultBgCounter == null) { |
| 7436 | mBluetoothScanResultBgCounter = new Counter(mOnBatteryBackgroundTimeBase); |
| 7437 | } |
| 7438 | return mBluetoothScanResultBgCounter; |
| 7439 | } |
| 7440 | |
Bookatz | 4ebc064 | 2017-05-11 12:21:19 -0700 | [diff] [blame] | 7441 | public void noteBluetoothScanResultsLocked(int numNewResults) { |
| 7442 | createBluetoothScanResultCounterLocked().addAtomic(numNewResults); |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 7443 | // Uses background timebase, so the count will only be incremented if uid in background. |
| 7444 | createBluetoothScanResultBgCounterLocked().addAtomic(numNewResults); |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 7445 | } |
| 7446 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 7447 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7448 | public void noteActivityResumedLocked(long elapsedRealtimeMs) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 7449 | // We always start, since we want multiple foreground PIDs to nest |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7450 | createForegroundActivityTimerLocked().startRunningLocked(elapsedRealtimeMs); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 7451 | } |
| 7452 | |
| 7453 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7454 | public void noteActivityPausedLocked(long elapsedRealtimeMs) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 7455 | if (mForegroundActivityTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7456 | mForegroundActivityTimer.stopRunningLocked(elapsedRealtimeMs); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 7457 | } |
| 7458 | } |
| 7459 | |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 7460 | public void noteForegroundServiceResumedLocked(long elapsedRealtimeMs) { |
| 7461 | createForegroundServiceTimerLocked().startRunningLocked(elapsedRealtimeMs); |
| 7462 | } |
| 7463 | |
| 7464 | public void noteForegroundServicePausedLocked(long elapsedRealtimeMs) { |
| 7465 | if (mForegroundServiceTimer != null) { |
| 7466 | mForegroundServiceTimer.stopRunningLocked(elapsedRealtimeMs); |
| 7467 | } |
| 7468 | } |
| 7469 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 7470 | public BatchTimer createVibratorOnTimerLocked() { |
| 7471 | if (mVibratorOnTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7472 | mVibratorOnTimer = new BatchTimer(mBsi.mClocks, Uid.this, VIBRATOR_ON, |
| 7473 | mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 7474 | } |
| 7475 | return mVibratorOnTimer; |
| 7476 | } |
| 7477 | |
| 7478 | public void noteVibratorOnLocked(long durationMillis) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7479 | createVibratorOnTimerLocked().addDuration(mBsi, durationMillis); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 7480 | } |
| 7481 | |
| 7482 | public void noteVibratorOffLocked() { |
| 7483 | if (mVibratorOnTimer != null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7484 | mVibratorOnTimer.abortLastDuration(mBsi); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7485 | } |
| 7486 | } |
| 7487 | |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7488 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7489 | public long getWifiRunningTime(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 7490 | if (mWifiRunningTimer == null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7491 | return 0; |
| 7492 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7493 | return mWifiRunningTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 7494 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 7495 | |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7496 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7497 | public long getFullWifiLockTime(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7498 | if (mFullWifiLockTimer == null) { |
| 7499 | return 0; |
| 7500 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7501 | return mFullWifiLockTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7502 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7503 | |
| 7504 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7505 | public long getWifiScanTime(long elapsedRealtimeUs, int which) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 7506 | if (mWifiScanTimer == null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7507 | return 0; |
| 7508 | } |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 7509 | return mWifiScanTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7510 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 7511 | |
| 7512 | @Override |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 7513 | public int getWifiScanCount(int which) { |
| 7514 | if (mWifiScanTimer == null) { |
| 7515 | return 0; |
| 7516 | } |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 7517 | return mWifiScanTimer.getCountLocked(which); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 7518 | } |
| 7519 | |
| 7520 | @Override |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7521 | public Timer getWifiScanTimer() { |
| 7522 | return mWifiScanTimer; |
| 7523 | } |
| 7524 | |
| 7525 | @Override |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 7526 | public int getWifiScanBackgroundCount(int which) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 7527 | if (mWifiScanTimer == null || mWifiScanTimer.getSubTimer() == null) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 7528 | return 0; |
| 7529 | } |
| 7530 | return mWifiScanTimer.getSubTimer().getCountLocked(which); |
| 7531 | } |
| 7532 | |
| 7533 | @Override |
| 7534 | public long getWifiScanActualTime(final long elapsedRealtimeUs) { |
| 7535 | if (mWifiScanTimer == null) { |
| 7536 | return 0; |
| 7537 | } |
| 7538 | final long elapsedRealtimeMs = (elapsedRealtimeUs + 500) / 1000; |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 7539 | return mWifiScanTimer.getTotalDurationMsLocked(elapsedRealtimeMs) * 1000; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 7540 | } |
| 7541 | |
| 7542 | @Override |
| 7543 | public long getWifiScanBackgroundTime(final long elapsedRealtimeUs) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 7544 | if (mWifiScanTimer == null || mWifiScanTimer.getSubTimer() == null) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 7545 | return 0; |
| 7546 | } |
| 7547 | final long elapsedRealtimeMs = (elapsedRealtimeUs + 500) / 1000; |
| 7548 | return mWifiScanTimer.getSubTimer().getTotalDurationMsLocked(elapsedRealtimeMs) * 1000; |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 7549 | } |
| 7550 | |
| 7551 | @Override |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7552 | public Timer getWifiScanBackgroundTimer() { |
| 7553 | if (mWifiScanTimer == null) { |
| 7554 | return null; |
| 7555 | } |
| 7556 | return mWifiScanTimer.getSubTimer(); |
| 7557 | } |
| 7558 | |
| 7559 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7560 | public long getWifiBatchedScanTime(int csphBin, long elapsedRealtimeUs, int which) { |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 7561 | if (csphBin < 0 || csphBin >= NUM_WIFI_BATCHED_SCAN_BINS) return 0; |
| 7562 | if (mWifiBatchedScanTimer[csphBin] == null) { |
| 7563 | return 0; |
| 7564 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7565 | return mWifiBatchedScanTimer[csphBin].getTotalTimeLocked(elapsedRealtimeUs, which); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 7566 | } |
| 7567 | |
| 7568 | @Override |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 7569 | public int getWifiBatchedScanCount(int csphBin, int which) { |
| 7570 | if (csphBin < 0 || csphBin >= NUM_WIFI_BATCHED_SCAN_BINS) return 0; |
| 7571 | if (mWifiBatchedScanTimer[csphBin] == null) { |
| 7572 | return 0; |
| 7573 | } |
| 7574 | return mWifiBatchedScanTimer[csphBin].getCountLocked(which); |
| 7575 | } |
| 7576 | |
| 7577 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7578 | public long getWifiMulticastTime(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7579 | if (mWifiMulticastTimer == null) { |
| 7580 | return 0; |
| 7581 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7582 | return mWifiMulticastTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 7583 | } |
| 7584 | |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7585 | @Override |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 7586 | public Timer getAudioTurnedOnTimer() { |
| 7587 | return mAudioTurnedOnTimer; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7588 | } |
| 7589 | |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7590 | @Override |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 7591 | public Timer getVideoTurnedOnTimer() { |
| 7592 | return mVideoTurnedOnTimer; |
| 7593 | } |
| 7594 | |
| 7595 | @Override |
| 7596 | public Timer getFlashlightTurnedOnTimer() { |
| 7597 | return mFlashlightTurnedOnTimer; |
| 7598 | } |
| 7599 | |
| 7600 | @Override |
| 7601 | public Timer getCameraTurnedOnTimer() { |
| 7602 | return mCameraTurnedOnTimer; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7603 | } |
| 7604 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 7605 | @Override |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 7606 | public Timer getForegroundActivityTimer() { |
| 7607 | return mForegroundActivityTimer; |
| 7608 | } |
| 7609 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 7610 | @Override |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 7611 | public Timer getForegroundServiceTimer() { |
| 7612 | return mForegroundServiceTimer; |
| 7613 | } |
| 7614 | |
| 7615 | @Override |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 7616 | public Timer getBluetoothScanTimer() { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 7617 | return mBluetoothScanTimer; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 7618 | } |
| 7619 | |
| 7620 | @Override |
| 7621 | public Timer getBluetoothScanBackgroundTimer() { |
| 7622 | if (mBluetoothScanTimer == null) { |
| 7623 | return null; |
| 7624 | } |
| 7625 | return mBluetoothScanTimer.getSubTimer(); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 7626 | } |
| 7627 | |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 7628 | @Override |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 7629 | public Timer getBluetoothUnoptimizedScanTimer() { |
| 7630 | return mBluetoothUnoptimizedScanTimer; |
| 7631 | } |
| 7632 | |
| 7633 | @Override |
| 7634 | public Timer getBluetoothUnoptimizedScanBackgroundTimer() { |
| 7635 | if (mBluetoothUnoptimizedScanTimer == null) { |
| 7636 | return null; |
| 7637 | } |
| 7638 | return mBluetoothUnoptimizedScanTimer.getSubTimer(); |
| 7639 | } |
| 7640 | |
| 7641 | @Override |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 7642 | public Counter getBluetoothScanResultCounter() { |
| 7643 | return mBluetoothScanResultCounter; |
| 7644 | } |
| 7645 | |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 7646 | @Override |
| 7647 | public Counter getBluetoothScanResultBgCounter() { |
| 7648 | return mBluetoothScanResultBgCounter; |
| 7649 | } |
| 7650 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 7651 | void makeProcessState(int i, Parcel in) { |
| 7652 | if (i < 0 || i >= NUM_PROCESS_STATE) return; |
| 7653 | |
| 7654 | if (in == null) { |
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); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 7657 | } else { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7658 | mProcessStateTimer[i] = new StopwatchTimer(mBsi.mClocks, this, PROCESS_STATE, null, |
| 7659 | mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 7660 | } |
| 7661 | } |
| 7662 | |
| 7663 | @Override |
| 7664 | public long getProcessStateTime(int state, long elapsedRealtimeUs, int which) { |
| 7665 | if (state < 0 || state >= NUM_PROCESS_STATE) return 0; |
| 7666 | if (mProcessStateTimer[state] == null) { |
| 7667 | return 0; |
| 7668 | } |
| 7669 | return mProcessStateTimer[state].getTotalTimeLocked(elapsedRealtimeUs, which); |
| 7670 | } |
| 7671 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 7672 | @Override |
Joe Onorato | 713fec8 | 2016-03-04 10:34:02 -0800 | [diff] [blame] | 7673 | public Timer getProcessStateTimer(int state) { |
| 7674 | if (state < 0 || state >= NUM_PROCESS_STATE) return null; |
| 7675 | return mProcessStateTimer[state]; |
| 7676 | } |
| 7677 | |
| 7678 | @Override |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 7679 | public Timer getVibratorOnTimer() { |
| 7680 | return mVibratorOnTimer; |
| 7681 | } |
| 7682 | |
| 7683 | @Override |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 7684 | public void noteUserActivityLocked(int type) { |
| 7685 | if (mUserActivityCounters == null) { |
| 7686 | initUserActivityLocked(); |
| 7687 | } |
Jeff Brown | df693de | 2012-07-27 12:03:38 -0700 | [diff] [blame] | 7688 | if (type >= 0 && type < NUM_USER_ACTIVITY_TYPES) { |
| 7689 | mUserActivityCounters[type].stepAtomic(); |
| 7690 | } else { |
| 7691 | Slog.w(TAG, "Unknown user activity type " + type + " was specified.", |
| 7692 | new Throwable()); |
| 7693 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 7694 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7695 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 7696 | @Override |
| 7697 | public boolean hasUserActivity() { |
| 7698 | return mUserActivityCounters != null; |
| 7699 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7700 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 7701 | @Override |
| 7702 | public int getUserActivityCount(int type, int which) { |
| 7703 | if (mUserActivityCounters == null) { |
| 7704 | return 0; |
| 7705 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 7706 | return mUserActivityCounters[type].getCountLocked(which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 7707 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7708 | |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 7709 | void makeWifiBatchedScanBin(int i, Parcel in) { |
| 7710 | if (i < 0 || i >= NUM_WIFI_BATCHED_SCAN_BINS) return; |
| 7711 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7712 | ArrayList<StopwatchTimer> collected = mBsi.mWifiBatchedScanTimers.get(i); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 7713 | if (collected == null) { |
| 7714 | collected = new ArrayList<StopwatchTimer>(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7715 | mBsi.mWifiBatchedScanTimers.put(i, collected); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 7716 | } |
| 7717 | if (in == null) { |
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); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 7720 | } else { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7721 | mWifiBatchedScanTimer[i] = new StopwatchTimer(mBsi.mClocks, this, WIFI_BATCHED_SCAN, |
| 7722 | collected, mBsi.mOnBatteryTimeBase, in); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 7723 | } |
| 7724 | } |
| 7725 | |
| 7726 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 7727 | void initUserActivityLocked() { |
| 7728 | mUserActivityCounters = new Counter[NUM_USER_ACTIVITY_TYPES]; |
| 7729 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7730 | mUserActivityCounters[i] = new Counter(mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 7731 | } |
| 7732 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7733 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 7734 | void noteNetworkActivityLocked(int type, long deltaBytes, long deltaPackets) { |
| 7735 | if (mNetworkByteActivityCounters == null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7736 | initNetworkActivityLocked(); |
| 7737 | } |
| 7738 | if (type >= 0 && type < NUM_NETWORK_ACTIVITY_TYPES) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 7739 | mNetworkByteActivityCounters[type].addCountLocked(deltaBytes); |
| 7740 | mNetworkPacketActivityCounters[type].addCountLocked(deltaPackets); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7741 | } else { |
| 7742 | Slog.w(TAG, "Unknown network activity type " + type + " was specified.", |
| 7743 | new Throwable()); |
| 7744 | } |
| 7745 | } |
| 7746 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 7747 | void noteMobileRadioActiveTimeLocked(long batteryUptime) { |
| 7748 | if (mNetworkByteActivityCounters == null) { |
| 7749 | initNetworkActivityLocked(); |
| 7750 | } |
| 7751 | mMobileRadioActiveTime.addCountLocked(batteryUptime); |
| 7752 | mMobileRadioActiveCount.addCountLocked(1); |
| 7753 | } |
| 7754 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7755 | @Override |
| 7756 | public boolean hasNetworkActivity() { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 7757 | return mNetworkByteActivityCounters != null; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7758 | } |
| 7759 | |
| 7760 | @Override |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 7761 | public long getNetworkActivityBytes(int type, int which) { |
| 7762 | if (mNetworkByteActivityCounters != null && type >= 0 |
| 7763 | && type < mNetworkByteActivityCounters.length) { |
| 7764 | return mNetworkByteActivityCounters[type].getCountLocked(which); |
| 7765 | } else { |
| 7766 | return 0; |
| 7767 | } |
| 7768 | } |
| 7769 | |
| 7770 | @Override |
| 7771 | public long getNetworkActivityPackets(int type, int which) { |
| 7772 | if (mNetworkPacketActivityCounters != null && type >= 0 |
| 7773 | && type < mNetworkPacketActivityCounters.length) { |
| 7774 | return mNetworkPacketActivityCounters[type].getCountLocked(which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7775 | } else { |
| 7776 | return 0; |
| 7777 | } |
| 7778 | } |
| 7779 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 7780 | @Override |
| 7781 | public long getMobileRadioActiveTime(int which) { |
| 7782 | return mMobileRadioActiveTime != null |
| 7783 | ? mMobileRadioActiveTime.getCountLocked(which) : 0; |
| 7784 | } |
| 7785 | |
| 7786 | @Override |
| 7787 | public int getMobileRadioActiveCount(int which) { |
| 7788 | return mMobileRadioActiveCount != null |
| 7789 | ? (int)mMobileRadioActiveCount.getCountLocked(which) : 0; |
| 7790 | } |
| 7791 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7792 | @Override |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 7793 | public long getUserCpuTimeUs(int which) { |
| 7794 | return mUserCpuTime.getCountLocked(which); |
| 7795 | } |
| 7796 | |
| 7797 | @Override |
| 7798 | public long getSystemCpuTimeUs(int which) { |
| 7799 | return mSystemCpuTime.getCountLocked(which); |
| 7800 | } |
| 7801 | |
| 7802 | @Override |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 7803 | public long getTimeAtCpuSpeed(int cluster, int step, int which) { |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 7804 | if (mCpuClusterSpeedTimesUs != null) { |
| 7805 | if (cluster >= 0 && cluster < mCpuClusterSpeedTimesUs.length) { |
| 7806 | final LongSamplingCounter[] cpuSpeedTimesUs = mCpuClusterSpeedTimesUs[cluster]; |
| 7807 | if (cpuSpeedTimesUs != null) { |
| 7808 | if (step >= 0 && step < cpuSpeedTimesUs.length) { |
| 7809 | final LongSamplingCounter c = cpuSpeedTimesUs[step]; |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 7810 | if (c != null) { |
| 7811 | return c.getCountLocked(which); |
| 7812 | } |
| 7813 | } |
| 7814 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 7815 | } |
| 7816 | } |
| 7817 | return 0; |
| 7818 | } |
| 7819 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 7820 | public void noteMobileRadioApWakeupLocked() { |
| 7821 | if (mMobileRadioApWakeupCount == null) { |
| 7822 | mMobileRadioApWakeupCount = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
| 7823 | } |
| 7824 | mMobileRadioApWakeupCount.addCountLocked(1); |
| 7825 | } |
| 7826 | |
| 7827 | @Override |
| 7828 | public long getMobileRadioApWakeupCount(int which) { |
| 7829 | if (mMobileRadioApWakeupCount != null) { |
| 7830 | return mMobileRadioApWakeupCount.getCountLocked(which); |
| 7831 | } |
| 7832 | return 0; |
| 7833 | } |
| 7834 | |
| 7835 | public void noteWifiRadioApWakeupLocked() { |
| 7836 | if (mWifiRadioApWakeupCount == null) { |
| 7837 | mWifiRadioApWakeupCount = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
| 7838 | } |
| 7839 | mWifiRadioApWakeupCount.addCountLocked(1); |
| 7840 | } |
| 7841 | |
| 7842 | @Override |
| 7843 | public long getWifiRadioApWakeupCount(int which) { |
| 7844 | if (mWifiRadioApWakeupCount != null) { |
| 7845 | return mWifiRadioApWakeupCount.getCountLocked(which); |
| 7846 | } |
| 7847 | return 0; |
| 7848 | } |
| 7849 | |
Amith Yamasani | 977e11f | 2018-02-16 11:29:54 -0800 | [diff] [blame] | 7850 | @Override |
| 7851 | public void getDeferredJobsCheckinLineLocked(StringBuilder sb, int which) { |
| 7852 | sb.setLength(0); |
| 7853 | final int deferredEventCount = mJobsDeferredEventCount.getCountLocked(which); |
| 7854 | if (deferredEventCount == 0) { |
| 7855 | return; |
| 7856 | } |
| 7857 | final int deferredCount = mJobsDeferredCount.getCountLocked(which); |
| 7858 | final long averageLatency = deferredEventCount != 0 |
| 7859 | ? mJobsFreshnessTimeMs.getCountLocked(which) / deferredEventCount |
| 7860 | : 0L; |
| 7861 | sb.append(deferredEventCount); sb.append(','); |
| 7862 | sb.append(deferredCount); sb.append(','); |
| 7863 | sb.append(averageLatency); |
| 7864 | for (int i = 0; i < JOB_FRESHNESS_BUCKETS.length; i++) { |
| 7865 | if (mJobsFreshnessBuckets[i] == null) { |
| 7866 | sb.append(",0"); |
| 7867 | } else { |
| 7868 | sb.append(","); |
| 7869 | sb.append(mJobsFreshnessBuckets[i].getCountLocked(which)); |
| 7870 | } |
| 7871 | } |
| 7872 | } |
| 7873 | |
| 7874 | @Override |
| 7875 | public void getDeferredJobsLineLocked(StringBuilder sb, int which) { |
| 7876 | sb.setLength(0); |
| 7877 | final int deferredEventCount = mJobsDeferredEventCount.getCountLocked(which); |
| 7878 | if (deferredEventCount == 0) { |
| 7879 | return; |
| 7880 | } |
| 7881 | final int deferredCount = mJobsDeferredCount.getCountLocked(which); |
| 7882 | final long averageLatency = deferredEventCount != 0 |
| 7883 | ? mJobsFreshnessTimeMs.getCountLocked(which) / deferredEventCount |
| 7884 | : 0L; |
| 7885 | sb.append("times="); sb.append(deferredEventCount); sb.append(", "); |
| 7886 | sb.append("count="); sb.append(deferredCount); sb.append(", "); |
| 7887 | sb.append("avgLatency="); sb.append(averageLatency); sb.append(", "); |
| 7888 | for (int i = 0; i < JOB_FRESHNESS_BUCKETS.length; i++) { |
| 7889 | sb.append("<"); sb.append(JOB_FRESHNESS_BUCKETS[i]); sb.append("ms="); |
| 7890 | if (mJobsFreshnessBuckets[i] == null) { |
| 7891 | sb.append("0"); |
| 7892 | } else { |
| 7893 | sb.append(mJobsFreshnessBuckets[i].getCountLocked(which)); |
| 7894 | } |
| 7895 | sb.append(" "); |
| 7896 | } |
| 7897 | } |
| 7898 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7899 | void initNetworkActivityLocked() { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 7900 | mNetworkByteActivityCounters = new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
| 7901 | mNetworkPacketActivityCounters = new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7902 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7903 | mNetworkByteActivityCounters[i] = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
| 7904 | mNetworkPacketActivityCounters[i] = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7905 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7906 | mMobileRadioActiveTime = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
| 7907 | mMobileRadioActiveCount = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7908 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 7909 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7910 | /** |
| 7911 | * Clear all stats for this uid. Returns true if the uid is completely |
| 7912 | * inactive so can be dropped. |
| 7913 | */ |
Adam Lesinski | 5f212c8 | 2017-03-13 12:25:13 -0700 | [diff] [blame] | 7914 | @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
Bookatz | 993a0be | 2017-07-21 09:03:23 -0700 | [diff] [blame] | 7915 | public boolean reset(long uptime, long realtime) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7916 | boolean active = false; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7917 | |
Bookatz | 993a0be | 2017-07-21 09:03:23 -0700 | [diff] [blame] | 7918 | mOnBatteryBackgroundTimeBase.init(uptime, realtime); |
| 7919 | mOnBatteryScreenOffBackgroundTimeBase.init(uptime, realtime); |
| 7920 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 7921 | if (mWifiRunningTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7922 | active |= !mWifiRunningTimer.reset(false); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 7923 | active |= mWifiRunning; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7924 | } |
| 7925 | if (mFullWifiLockTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7926 | active |= !mFullWifiLockTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7927 | active |= mFullWifiLockOut; |
| 7928 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 7929 | if (mWifiScanTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7930 | active |= !mWifiScanTimer.reset(false); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 7931 | active |= mWifiScanStarted; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7932 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 7933 | if (mWifiBatchedScanTimer != null) { |
| 7934 | for (int i = 0; i < NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 7935 | if (mWifiBatchedScanTimer[i] != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7936 | active |= !mWifiBatchedScanTimer[i].reset(false); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 7937 | } |
| 7938 | } |
| 7939 | active |= (mWifiBatchedScanBinStarted != NO_BATCHED_SCAN_STARTED); |
| 7940 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7941 | if (mWifiMulticastTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7942 | active |= !mWifiMulticastTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7943 | active |= mWifiMulticastEnabled; |
| 7944 | } |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 7945 | |
| 7946 | active |= !resetTimerIfNotNull(mAudioTurnedOnTimer, false); |
| 7947 | active |= !resetTimerIfNotNull(mVideoTurnedOnTimer, false); |
| 7948 | active |= !resetTimerIfNotNull(mFlashlightTurnedOnTimer, false); |
| 7949 | active |= !resetTimerIfNotNull(mCameraTurnedOnTimer, false); |
| 7950 | active |= !resetTimerIfNotNull(mForegroundActivityTimer, false); |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 7951 | active |= !resetTimerIfNotNull(mForegroundServiceTimer, false); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 7952 | active |= !resetTimerIfNotNull(mAggregatedPartialWakelockTimer, false); |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 7953 | active |= !resetTimerIfNotNull(mBluetoothScanTimer, false); |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 7954 | active |= !resetTimerIfNotNull(mBluetoothUnoptimizedScanTimer, false); |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 7955 | if (mBluetoothScanResultCounter != null) { |
| 7956 | mBluetoothScanResultCounter.reset(false); |
| 7957 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 7958 | if (mBluetoothScanResultBgCounter != null) { |
| 7959 | mBluetoothScanResultBgCounter.reset(false); |
| 7960 | } |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 7961 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 7962 | if (mProcessStateTimer != null) { |
| 7963 | for (int i = 0; i < NUM_PROCESS_STATE; i++) { |
| 7964 | if (mProcessStateTimer[i] != null) { |
| 7965 | active |= !mProcessStateTimer[i].reset(false); |
| 7966 | } |
| 7967 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 7968 | active |= (mProcessState != ActivityManager.PROCESS_STATE_NONEXISTENT); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 7969 | } |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 7970 | if (mVibratorOnTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7971 | if (mVibratorOnTimer.reset(false)) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 7972 | mVibratorOnTimer.detach(); |
| 7973 | mVibratorOnTimer = null; |
| 7974 | } else { |
| 7975 | active = true; |
| 7976 | } |
| 7977 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7978 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7979 | if (mUserActivityCounters != null) { |
| 7980 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
| 7981 | mUserActivityCounters[i].reset(false); |
| 7982 | } |
| 7983 | } |
| 7984 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 7985 | if (mNetworkByteActivityCounters != null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7986 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 7987 | mNetworkByteActivityCounters[i].reset(false); |
| 7988 | mNetworkPacketActivityCounters[i].reset(false); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7989 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 7990 | mMobileRadioActiveTime.reset(false); |
| 7991 | mMobileRadioActiveCount.reset(false); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7992 | } |
| 7993 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 7994 | if (mWifiControllerActivity != null) { |
| 7995 | mWifiControllerActivity.reset(false); |
| 7996 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7997 | |
Adam Lesinski | 1a2b39e | 2016-04-29 17:56:58 -0700 | [diff] [blame] | 7998 | if (mBluetoothControllerActivity != null) { |
| 7999 | mBluetoothControllerActivity.reset(false); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8000 | } |
| 8001 | |
Adam Lesinski | 1a2b39e | 2016-04-29 17:56:58 -0700 | [diff] [blame] | 8002 | if (mModemControllerActivity != null) { |
| 8003 | mModemControllerActivity.reset(false); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8004 | } |
| 8005 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 8006 | mUserCpuTime.reset(false); |
| 8007 | mSystemCpuTime.reset(false); |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 8008 | |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 8009 | if (mCpuClusterSpeedTimesUs != null) { |
| 8010 | for (LongSamplingCounter[] speeds : mCpuClusterSpeedTimesUs) { |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 8011 | if (speeds != null) { |
| 8012 | for (LongSamplingCounter speed : speeds) { |
| 8013 | if (speed != null) { |
| 8014 | speed.reset(false); |
| 8015 | } |
| 8016 | } |
| 8017 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 8018 | } |
| 8019 | } |
| 8020 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 8021 | if (mCpuFreqTimeMs != null) { |
| 8022 | mCpuFreqTimeMs.reset(false); |
| 8023 | } |
| 8024 | if (mScreenOffCpuFreqTimeMs != null) { |
| 8025 | mScreenOffCpuFreqTimeMs.reset(false); |
| 8026 | } |
| 8027 | |
Mike Ma | 3d422c3 | 2017-10-25 11:08:57 -0700 | [diff] [blame] | 8028 | mCpuActiveTimeMs.reset(false); |
| 8029 | mCpuClusterTimesMs.reset(false); |
| 8030 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 8031 | if (mProcStateTimeMs != null) { |
| 8032 | for (LongSamplingCounterArray counters : mProcStateTimeMs) { |
| 8033 | if (counters != null) { |
| 8034 | counters.reset(false); |
| 8035 | } |
| 8036 | } |
| 8037 | } |
| 8038 | if (mProcStateScreenOffTimeMs != null) { |
| 8039 | for (LongSamplingCounterArray counters : mProcStateScreenOffTimeMs) { |
| 8040 | if (counters != null) { |
| 8041 | counters.reset(false); |
| 8042 | } |
| 8043 | } |
| 8044 | } |
| 8045 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 8046 | resetLongCounterIfNotNull(mMobileRadioApWakeupCount, false); |
| 8047 | resetLongCounterIfNotNull(mWifiRadioApWakeupCount, false); |
| 8048 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8049 | final ArrayMap<String, Wakelock> wakeStats = mWakelockStats.getMap(); |
| 8050 | for (int iw=wakeStats.size()-1; iw>=0; iw--) { |
| 8051 | Wakelock wl = wakeStats.valueAt(iw); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 8052 | if (wl.reset()) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8053 | wakeStats.removeAt(iw); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 8054 | } else { |
| 8055 | active = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8056 | } |
| 8057 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8058 | mWakelockStats.cleanup(); |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 8059 | final ArrayMap<String, DualTimer> syncStats = mSyncStats.getMap(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8060 | for (int is=syncStats.size()-1; is>=0; is--) { |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 8061 | DualTimer timer = syncStats.valueAt(is); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 8062 | if (timer.reset(false)) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8063 | syncStats.removeAt(is); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 8064 | timer.detach(); |
| 8065 | } else { |
| 8066 | active = true; |
| 8067 | } |
| 8068 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8069 | mSyncStats.cleanup(); |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 8070 | final ArrayMap<String, DualTimer> jobStats = mJobStats.getMap(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8071 | for (int ij=jobStats.size()-1; ij>=0; ij--) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 8072 | DualTimer timer = jobStats.valueAt(ij); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 8073 | if (timer.reset(false)) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8074 | jobStats.removeAt(ij); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 8075 | timer.detach(); |
| 8076 | } else { |
| 8077 | active = true; |
| 8078 | } |
| 8079 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8080 | mJobStats.cleanup(); |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 8081 | mJobCompletions.clear(); |
Amith Yamasani | 977e11f | 2018-02-16 11:29:54 -0800 | [diff] [blame] | 8082 | |
| 8083 | mJobsDeferredEventCount.reset(false); |
| 8084 | mJobsDeferredCount.reset(false); |
| 8085 | mJobsFreshnessTimeMs.reset(false); |
| 8086 | for (int ij = 0; ij < JOB_FRESHNESS_BUCKETS.length; ij++) { |
| 8087 | if (mJobsFreshnessBuckets[ij] != null) { |
| 8088 | mJobsFreshnessBuckets[ij].reset(false); |
| 8089 | } |
| 8090 | } |
| 8091 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 8092 | for (int ise=mSensorStats.size()-1; ise>=0; ise--) { |
| 8093 | Sensor s = mSensorStats.valueAt(ise); |
| 8094 | if (s.reset()) { |
| 8095 | mSensorStats.removeAt(ise); |
| 8096 | } else { |
| 8097 | active = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8098 | } |
| 8099 | } |
Amith Yamasani | 977e11f | 2018-02-16 11:29:54 -0800 | [diff] [blame] | 8100 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 8101 | for (int ip=mProcessStats.size()-1; ip>=0; ip--) { |
| 8102 | Proc proc = mProcessStats.valueAt(ip); |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 8103 | proc.detach(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8104 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 8105 | mProcessStats.clear(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 8106 | if (mPids.size() > 0) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 8107 | for (int i=mPids.size()-1; i>=0; i--) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 8108 | Pid pid = mPids.valueAt(i); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 8109 | if (pid.mWakeNesting > 0) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 8110 | active = true; |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 8111 | } else { |
| 8112 | mPids.removeAt(i); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 8113 | } |
| 8114 | } |
| 8115 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8116 | if (mPackageStats.size() > 0) { |
| 8117 | Iterator<Map.Entry<String, Pkg>> it = mPackageStats.entrySet().iterator(); |
| 8118 | while (it.hasNext()) { |
| 8119 | Map.Entry<String, Pkg> pkgEntry = it.next(); |
| 8120 | Pkg p = pkgEntry.getValue(); |
| 8121 | p.detach(); |
| 8122 | if (p.mServiceStats.size() > 0) { |
| 8123 | Iterator<Map.Entry<String, Pkg.Serv>> it2 |
| 8124 | = p.mServiceStats.entrySet().iterator(); |
| 8125 | while (it2.hasNext()) { |
| 8126 | Map.Entry<String, Pkg.Serv> servEntry = it2.next(); |
| 8127 | servEntry.getValue().detach(); |
| 8128 | } |
| 8129 | } |
| 8130 | } |
| 8131 | mPackageStats.clear(); |
| 8132 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8133 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 8134 | mLastStepUserTime = mLastStepSystemTime = 0; |
| 8135 | mCurStepUserTime = mCurStepSystemTime = 0; |
| 8136 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8137 | if (!active) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 8138 | if (mWifiRunningTimer != null) { |
| 8139 | mWifiRunningTimer.detach(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8140 | } |
| 8141 | if (mFullWifiLockTimer != null) { |
| 8142 | mFullWifiLockTimer.detach(); |
| 8143 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 8144 | if (mWifiScanTimer != null) { |
| 8145 | mWifiScanTimer.detach(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8146 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 8147 | for (int i = 0; i < NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 8148 | if (mWifiBatchedScanTimer[i] != null) { |
| 8149 | mWifiBatchedScanTimer[i].detach(); |
| 8150 | } |
| 8151 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8152 | if (mWifiMulticastTimer != null) { |
| 8153 | mWifiMulticastTimer.detach(); |
| 8154 | } |
| 8155 | if (mAudioTurnedOnTimer != null) { |
| 8156 | mAudioTurnedOnTimer.detach(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 8157 | mAudioTurnedOnTimer = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8158 | } |
| 8159 | if (mVideoTurnedOnTimer != null) { |
| 8160 | mVideoTurnedOnTimer.detach(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 8161 | mVideoTurnedOnTimer = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8162 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 8163 | if (mFlashlightTurnedOnTimer != null) { |
| 8164 | mFlashlightTurnedOnTimer.detach(); |
| 8165 | mFlashlightTurnedOnTimer = null; |
| 8166 | } |
| 8167 | if (mCameraTurnedOnTimer != null) { |
| 8168 | mCameraTurnedOnTimer.detach(); |
| 8169 | mCameraTurnedOnTimer = null; |
| 8170 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 8171 | if (mForegroundActivityTimer != null) { |
| 8172 | mForegroundActivityTimer.detach(); |
| 8173 | mForegroundActivityTimer = null; |
| 8174 | } |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 8175 | if (mForegroundServiceTimer != null) { |
| 8176 | mForegroundServiceTimer.detach(); |
| 8177 | mForegroundServiceTimer = null; |
| 8178 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 8179 | if (mAggregatedPartialWakelockTimer != null) { |
| 8180 | mAggregatedPartialWakelockTimer.detach(); |
| 8181 | mAggregatedPartialWakelockTimer = null; |
| 8182 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 8183 | if (mBluetoothScanTimer != null) { |
| 8184 | mBluetoothScanTimer.detach(); |
| 8185 | mBluetoothScanTimer = null; |
| 8186 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 8187 | if (mBluetoothUnoptimizedScanTimer != null) { |
| 8188 | mBluetoothUnoptimizedScanTimer.detach(); |
| 8189 | mBluetoothUnoptimizedScanTimer = null; |
| 8190 | } |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 8191 | if (mBluetoothScanResultCounter != null) { |
| 8192 | mBluetoothScanResultCounter.detach(); |
| 8193 | mBluetoothScanResultCounter = null; |
| 8194 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 8195 | if (mBluetoothScanResultBgCounter != null) { |
| 8196 | mBluetoothScanResultBgCounter.detach(); |
| 8197 | mBluetoothScanResultBgCounter = null; |
| 8198 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8199 | if (mUserActivityCounters != null) { |
| 8200 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
| 8201 | mUserActivityCounters[i].detach(); |
| 8202 | } |
| 8203 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 8204 | if (mNetworkByteActivityCounters != null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 8205 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 8206 | mNetworkByteActivityCounters[i].detach(); |
| 8207 | mNetworkPacketActivityCounters[i].detach(); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 8208 | } |
| 8209 | } |
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 | if (mWifiControllerActivity != null) { |
| 8212 | mWifiControllerActivity.detach(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8213 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8214 | |
| 8215 | if (mBluetoothControllerActivity != null) { |
| 8216 | mBluetoothControllerActivity.detach(); |
| 8217 | } |
| 8218 | |
| 8219 | if (mModemControllerActivity != null) { |
| 8220 | mModemControllerActivity.detach(); |
| 8221 | } |
| 8222 | |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 8223 | mPids.clear(); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 8224 | |
| 8225 | mUserCpuTime.detach(); |
| 8226 | mSystemCpuTime.detach(); |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 8227 | |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 8228 | if (mCpuClusterSpeedTimesUs != null) { |
| 8229 | for (LongSamplingCounter[] cpuSpeeds : mCpuClusterSpeedTimesUs) { |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 8230 | if (cpuSpeeds != null) { |
| 8231 | for (LongSamplingCounter c : cpuSpeeds) { |
| 8232 | if (c != null) { |
| 8233 | c.detach(); |
| 8234 | } |
| 8235 | } |
| 8236 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 8237 | } |
| 8238 | } |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 8239 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 8240 | if (mCpuFreqTimeMs != null) { |
| 8241 | mCpuFreqTimeMs.detach(); |
| 8242 | } |
| 8243 | if (mScreenOffCpuFreqTimeMs != null) { |
| 8244 | mScreenOffCpuFreqTimeMs.detach(); |
| 8245 | } |
Mike Ma | 3d422c3 | 2017-10-25 11:08:57 -0700 | [diff] [blame] | 8246 | mCpuActiveTimeMs.detach(); |
| 8247 | mCpuClusterTimesMs.detach(); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 8248 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 8249 | if (mProcStateTimeMs != null) { |
| 8250 | for (LongSamplingCounterArray counters : mProcStateTimeMs) { |
| 8251 | if (counters != null) { |
| 8252 | counters.detach(); |
| 8253 | } |
| 8254 | } |
| 8255 | } |
| 8256 | if (mProcStateScreenOffTimeMs != null) { |
| 8257 | for (LongSamplingCounterArray counters : mProcStateScreenOffTimeMs) { |
| 8258 | if (counters != null) { |
| 8259 | counters.detach(); |
| 8260 | } |
| 8261 | } |
| 8262 | } |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 8263 | detachLongCounterIfNotNull(mMobileRadioApWakeupCount); |
| 8264 | detachLongCounterIfNotNull(mWifiRadioApWakeupCount); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8265 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8266 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8267 | return !active; |
| 8268 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8269 | |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 8270 | void writeJobCompletionsToParcelLocked(Parcel out) { |
| 8271 | int NJC = mJobCompletions.size(); |
| 8272 | out.writeInt(NJC); |
| 8273 | for (int ijc=0; ijc<NJC; ijc++) { |
| 8274 | out.writeString(mJobCompletions.keyAt(ijc)); |
| 8275 | SparseIntArray types = mJobCompletions.valueAt(ijc); |
| 8276 | int NT = types.size(); |
| 8277 | out.writeInt(NT); |
| 8278 | for (int it=0; it<NT; it++) { |
| 8279 | out.writeInt(types.keyAt(it)); |
| 8280 | out.writeInt(types.valueAt(it)); |
| 8281 | } |
| 8282 | } |
| 8283 | } |
| 8284 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 8285 | void writeToParcelLocked(Parcel out, long uptimeUs, long elapsedRealtimeUs) { |
| 8286 | mOnBatteryBackgroundTimeBase.writeToParcel(out, uptimeUs, elapsedRealtimeUs); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 8287 | mOnBatteryScreenOffBackgroundTimeBase.writeToParcel(out, uptimeUs, elapsedRealtimeUs); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 8288 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8289 | final ArrayMap<String, Wakelock> wakeStats = mWakelockStats.getMap(); |
| 8290 | int NW = wakeStats.size(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 8291 | out.writeInt(NW); |
| 8292 | for (int iw=0; iw<NW; iw++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8293 | out.writeString(wakeStats.keyAt(iw)); |
| 8294 | Uid.Wakelock wakelock = wakeStats.valueAt(iw); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8295 | wakelock.writeToParcelLocked(out, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8296 | } |
| 8297 | |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 8298 | final ArrayMap<String, DualTimer> syncStats = mSyncStats.getMap(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8299 | int NS = syncStats.size(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 8300 | out.writeInt(NS); |
| 8301 | for (int is=0; is<NS; is++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8302 | out.writeString(syncStats.keyAt(is)); |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 8303 | DualTimer timer = syncStats.valueAt(is); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 8304 | Timer.writeTimerToParcel(out, timer, elapsedRealtimeUs); |
| 8305 | } |
| 8306 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 8307 | final ArrayMap<String, DualTimer> jobStats = mJobStats.getMap(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8308 | int NJ = jobStats.size(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 8309 | out.writeInt(NJ); |
| 8310 | for (int ij=0; ij<NJ; ij++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8311 | out.writeString(jobStats.keyAt(ij)); |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 8312 | DualTimer timer = jobStats.valueAt(ij); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 8313 | Timer.writeTimerToParcel(out, timer, elapsedRealtimeUs); |
| 8314 | } |
| 8315 | |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 8316 | writeJobCompletionsToParcelLocked(out); |
| 8317 | |
Amith Yamasani | 977e11f | 2018-02-16 11:29:54 -0800 | [diff] [blame] | 8318 | mJobsDeferredEventCount.writeToParcel(out); |
| 8319 | mJobsDeferredCount.writeToParcel(out); |
| 8320 | mJobsFreshnessTimeMs.writeToParcel(out); |
| 8321 | for (int i = 0; i < JOB_FRESHNESS_BUCKETS.length; i++) { |
| 8322 | Counter.writeCounterToParcel(out, mJobsFreshnessBuckets[i]); |
| 8323 | } |
| 8324 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 8325 | int NSE = mSensorStats.size(); |
| 8326 | out.writeInt(NSE); |
| 8327 | for (int ise=0; ise<NSE; ise++) { |
| 8328 | out.writeInt(mSensorStats.keyAt(ise)); |
| 8329 | Uid.Sensor sensor = mSensorStats.valueAt(ise); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8330 | sensor.writeToParcelLocked(out, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8331 | } |
| 8332 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 8333 | int NP = mProcessStats.size(); |
| 8334 | out.writeInt(NP); |
| 8335 | for (int ip=0; ip<NP; ip++) { |
| 8336 | out.writeString(mProcessStats.keyAt(ip)); |
| 8337 | Uid.Proc proc = mProcessStats.valueAt(ip); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8338 | proc.writeToParcelLocked(out); |
| 8339 | } |
| 8340 | |
| 8341 | out.writeInt(mPackageStats.size()); |
| 8342 | for (Map.Entry<String, Uid.Pkg> pkgEntry : mPackageStats.entrySet()) { |
| 8343 | out.writeString(pkgEntry.getKey()); |
| 8344 | Uid.Pkg pkg = pkgEntry.getValue(); |
| 8345 | pkg.writeToParcelLocked(out); |
| 8346 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8347 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 8348 | if (mWifiRunningTimer != null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8349 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8350 | mWifiRunningTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 8351 | } else { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8352 | out.writeInt(0); |
| 8353 | } |
| 8354 | if (mFullWifiLockTimer != null) { |
| 8355 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8356 | mFullWifiLockTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8357 | } else { |
| 8358 | out.writeInt(0); |
| 8359 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 8360 | if (mWifiScanTimer != null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8361 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8362 | mWifiScanTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8363 | } else { |
| 8364 | out.writeInt(0); |
| 8365 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 8366 | for (int i = 0; i < NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 8367 | if (mWifiBatchedScanTimer[i] != null) { |
| 8368 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8369 | mWifiBatchedScanTimer[i].writeToParcel(out, elapsedRealtimeUs); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 8370 | } else { |
| 8371 | out.writeInt(0); |
| 8372 | } |
| 8373 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8374 | if (mWifiMulticastTimer != null) { |
| 8375 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8376 | mWifiMulticastTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8377 | } else { |
| 8378 | out.writeInt(0); |
| 8379 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8380 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8381 | if (mAudioTurnedOnTimer != null) { |
| 8382 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8383 | mAudioTurnedOnTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8384 | } else { |
| 8385 | out.writeInt(0); |
| 8386 | } |
| 8387 | if (mVideoTurnedOnTimer != null) { |
| 8388 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8389 | mVideoTurnedOnTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8390 | } else { |
| 8391 | out.writeInt(0); |
| 8392 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 8393 | if (mFlashlightTurnedOnTimer != null) { |
| 8394 | out.writeInt(1); |
| 8395 | mFlashlightTurnedOnTimer.writeToParcel(out, elapsedRealtimeUs); |
| 8396 | } else { |
| 8397 | out.writeInt(0); |
| 8398 | } |
| 8399 | if (mCameraTurnedOnTimer != null) { |
| 8400 | out.writeInt(1); |
| 8401 | mCameraTurnedOnTimer.writeToParcel(out, elapsedRealtimeUs); |
| 8402 | } else { |
| 8403 | out.writeInt(0); |
| 8404 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 8405 | if (mForegroundActivityTimer != null) { |
| 8406 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8407 | mForegroundActivityTimer.writeToParcel(out, elapsedRealtimeUs); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 8408 | } else { |
| 8409 | out.writeInt(0); |
| 8410 | } |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 8411 | if (mForegroundServiceTimer != null) { |
| 8412 | out.writeInt(1); |
| 8413 | mForegroundServiceTimer.writeToParcel(out, elapsedRealtimeUs); |
| 8414 | } else { |
| 8415 | out.writeInt(0); |
| 8416 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 8417 | if (mAggregatedPartialWakelockTimer != null) { |
| 8418 | out.writeInt(1); |
| 8419 | mAggregatedPartialWakelockTimer.writeToParcel(out, elapsedRealtimeUs); |
| 8420 | } else { |
| 8421 | out.writeInt(0); |
| 8422 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 8423 | if (mBluetoothScanTimer != null) { |
| 8424 | out.writeInt(1); |
| 8425 | mBluetoothScanTimer.writeToParcel(out, elapsedRealtimeUs); |
| 8426 | } else { |
| 8427 | out.writeInt(0); |
| 8428 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 8429 | if (mBluetoothUnoptimizedScanTimer != null) { |
| 8430 | out.writeInt(1); |
| 8431 | mBluetoothUnoptimizedScanTimer.writeToParcel(out, elapsedRealtimeUs); |
| 8432 | } else { |
| 8433 | out.writeInt(0); |
| 8434 | } |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 8435 | if (mBluetoothScanResultCounter != null) { |
| 8436 | out.writeInt(1); |
| 8437 | mBluetoothScanResultCounter.writeToParcel(out); |
| 8438 | } else { |
| 8439 | out.writeInt(0); |
| 8440 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 8441 | if (mBluetoothScanResultBgCounter != null) { |
| 8442 | out.writeInt(1); |
| 8443 | mBluetoothScanResultBgCounter.writeToParcel(out); |
| 8444 | } else { |
| 8445 | out.writeInt(0); |
| 8446 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 8447 | for (int i = 0; i < NUM_PROCESS_STATE; i++) { |
| 8448 | if (mProcessStateTimer[i] != null) { |
| 8449 | out.writeInt(1); |
| 8450 | mProcessStateTimer[i].writeToParcel(out, elapsedRealtimeUs); |
| 8451 | } else { |
| 8452 | out.writeInt(0); |
| 8453 | } |
| 8454 | } |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 8455 | if (mVibratorOnTimer != null) { |
| 8456 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8457 | mVibratorOnTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 8458 | } else { |
| 8459 | out.writeInt(0); |
| 8460 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8461 | if (mUserActivityCounters != null) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 8462 | out.writeInt(1); |
| 8463 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
| 8464 | mUserActivityCounters[i].writeToParcel(out); |
| 8465 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8466 | } else { |
| 8467 | out.writeInt(0); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 8468 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 8469 | if (mNetworkByteActivityCounters != null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 8470 | out.writeInt(1); |
| 8471 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 8472 | mNetworkByteActivityCounters[i].writeToParcel(out); |
| 8473 | mNetworkPacketActivityCounters[i].writeToParcel(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 8474 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 8475 | mMobileRadioActiveTime.writeToParcel(out); |
| 8476 | mMobileRadioActiveCount.writeToParcel(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 8477 | } else { |
| 8478 | out.writeInt(0); |
| 8479 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8480 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8481 | if (mWifiControllerActivity != null) { |
| 8482 | out.writeInt(1); |
| 8483 | mWifiControllerActivity.writeToParcel(out, 0); |
| 8484 | } else { |
| 8485 | out.writeInt(0); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8486 | } |
| 8487 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8488 | if (mBluetoothControllerActivity != null) { |
| 8489 | out.writeInt(1); |
| 8490 | mBluetoothControllerActivity.writeToParcel(out, 0); |
| 8491 | } else { |
| 8492 | out.writeInt(0); |
| 8493 | } |
| 8494 | |
| 8495 | if (mModemControllerActivity != null) { |
| 8496 | out.writeInt(1); |
| 8497 | mModemControllerActivity.writeToParcel(out, 0); |
| 8498 | } else { |
| 8499 | out.writeInt(0); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8500 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 8501 | |
| 8502 | mUserCpuTime.writeToParcel(out); |
| 8503 | mSystemCpuTime.writeToParcel(out); |
| 8504 | |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 8505 | if (mCpuClusterSpeedTimesUs != null) { |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 8506 | out.writeInt(1); |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 8507 | out.writeInt(mCpuClusterSpeedTimesUs.length); |
| 8508 | for (LongSamplingCounter[] cpuSpeeds : mCpuClusterSpeedTimesUs) { |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 8509 | if (cpuSpeeds != null) { |
| 8510 | out.writeInt(1); |
| 8511 | out.writeInt(cpuSpeeds.length); |
| 8512 | for (LongSamplingCounter c : cpuSpeeds) { |
| 8513 | if (c != null) { |
| 8514 | out.writeInt(1); |
| 8515 | c.writeToParcel(out); |
| 8516 | } else { |
| 8517 | out.writeInt(0); |
| 8518 | } |
| 8519 | } |
| 8520 | } else { |
| 8521 | out.writeInt(0); |
| 8522 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 8523 | } |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 8524 | } else { |
| 8525 | out.writeInt(0); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 8526 | } |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 8527 | |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 8528 | LongSamplingCounterArray.writeToParcel(out, mCpuFreqTimeMs); |
| 8529 | LongSamplingCounterArray.writeToParcel(out, mScreenOffCpuFreqTimeMs); |
Mike Ma | 3d422c3 | 2017-10-25 11:08:57 -0700 | [diff] [blame] | 8530 | |
| 8531 | mCpuActiveTimeMs.writeToParcel(out); |
| 8532 | mCpuClusterTimesMs.writeToParcel(out); |
| 8533 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 8534 | if (mProcStateTimeMs != null) { |
| 8535 | out.writeInt(mProcStateTimeMs.length); |
| 8536 | for (LongSamplingCounterArray counters : mProcStateTimeMs) { |
| 8537 | LongSamplingCounterArray.writeToParcel(out, counters); |
| 8538 | } |
| 8539 | } else { |
| 8540 | out.writeInt(0); |
| 8541 | } |
| 8542 | if (mProcStateScreenOffTimeMs != null) { |
| 8543 | out.writeInt(mProcStateScreenOffTimeMs.length); |
| 8544 | for (LongSamplingCounterArray counters : mProcStateScreenOffTimeMs) { |
| 8545 | LongSamplingCounterArray.writeToParcel(out, counters); |
| 8546 | } |
| 8547 | } else { |
| 8548 | out.writeInt(0); |
| 8549 | } |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 8550 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 8551 | if (mMobileRadioApWakeupCount != null) { |
| 8552 | out.writeInt(1); |
| 8553 | mMobileRadioApWakeupCount.writeToParcel(out); |
| 8554 | } else { |
| 8555 | out.writeInt(0); |
| 8556 | } |
| 8557 | |
| 8558 | if (mWifiRadioApWakeupCount != null) { |
| 8559 | out.writeInt(1); |
| 8560 | mWifiRadioApWakeupCount.writeToParcel(out); |
| 8561 | } else { |
| 8562 | out.writeInt(0); |
| 8563 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8564 | } |
| 8565 | |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 8566 | void readJobCompletionsFromParcelLocked(Parcel in) { |
| 8567 | int numJobCompletions = in.readInt(); |
| 8568 | mJobCompletions.clear(); |
| 8569 | for (int j = 0; j < numJobCompletions; j++) { |
| 8570 | String jobName = in.readString(); |
| 8571 | int numTypes = in.readInt(); |
| 8572 | if (numTypes > 0) { |
| 8573 | SparseIntArray types = new SparseIntArray(); |
| 8574 | for (int k = 0; k < numTypes; k++) { |
| 8575 | int type = in.readInt(); |
| 8576 | int count = in.readInt(); |
| 8577 | types.put(type, count); |
| 8578 | } |
| 8579 | mJobCompletions.put(jobName, types); |
| 8580 | } |
| 8581 | } |
| 8582 | } |
| 8583 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8584 | void readFromParcelLocked(TimeBase timeBase, TimeBase screenOffTimeBase, Parcel in) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 8585 | mOnBatteryBackgroundTimeBase.readFromParcel(in); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 8586 | mOnBatteryScreenOffBackgroundTimeBase.readFromParcel(in); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 8587 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8588 | int numWakelocks = in.readInt(); |
| 8589 | mWakelockStats.clear(); |
| 8590 | for (int j = 0; j < numWakelocks; j++) { |
| 8591 | String wakelockName = in.readString(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8592 | Uid.Wakelock wakelock = new Wakelock(mBsi, this); |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 8593 | wakelock.readFromParcelLocked( |
| 8594 | timeBase, screenOffTimeBase, mOnBatteryScreenOffBackgroundTimeBase, in); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8595 | mWakelockStats.add(wakelockName, wakelock); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8596 | } |
| 8597 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 8598 | int numSyncs = in.readInt(); |
| 8599 | mSyncStats.clear(); |
| 8600 | for (int j = 0; j < numSyncs; j++) { |
| 8601 | String syncName = in.readString(); |
| 8602 | if (in.readInt() != 0) { |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 8603 | mSyncStats.add(syncName, new DualTimer(mBsi.mClocks, Uid.this, SYNC, null, |
| 8604 | mBsi.mOnBatteryTimeBase, mOnBatteryBackgroundTimeBase, in)); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 8605 | } |
| 8606 | } |
| 8607 | |
| 8608 | int numJobs = in.readInt(); |
| 8609 | mJobStats.clear(); |
| 8610 | for (int j = 0; j < numJobs; j++) { |
| 8611 | String jobName = in.readString(); |
| 8612 | if (in.readInt() != 0) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 8613 | mJobStats.add(jobName, new DualTimer(mBsi.mClocks, Uid.this, JOB, null, |
| 8614 | mBsi.mOnBatteryTimeBase, mOnBatteryBackgroundTimeBase, in)); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 8615 | } |
| 8616 | } |
| 8617 | |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 8618 | readJobCompletionsFromParcelLocked(in); |
| 8619 | |
Amith Yamasani | 977e11f | 2018-02-16 11:29:54 -0800 | [diff] [blame] | 8620 | mJobsDeferredEventCount = new Counter(mBsi.mOnBatteryTimeBase, in); |
| 8621 | mJobsDeferredCount = new Counter(mBsi.mOnBatteryTimeBase, in); |
| 8622 | mJobsFreshnessTimeMs = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
| 8623 | for (int i = 0; i < JOB_FRESHNESS_BUCKETS.length; i++) { |
| 8624 | mJobsFreshnessBuckets[i] = Counter.readCounterFromParcel(mBsi.mOnBatteryTimeBase, |
| 8625 | in); |
| 8626 | } |
| 8627 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8628 | int numSensors = in.readInt(); |
| 8629 | mSensorStats.clear(); |
| 8630 | for (int k = 0; k < numSensors; k++) { |
| 8631 | int sensorNumber = in.readInt(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8632 | Uid.Sensor sensor = new Sensor(mBsi, this, sensorNumber); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 8633 | sensor.readFromParcelLocked(mBsi.mOnBatteryTimeBase, mOnBatteryBackgroundTimeBase, |
| 8634 | in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8635 | mSensorStats.put(sensorNumber, sensor); |
| 8636 | } |
| 8637 | |
| 8638 | int numProcs = in.readInt(); |
| 8639 | mProcessStats.clear(); |
| 8640 | for (int k = 0; k < numProcs; k++) { |
| 8641 | String processName = in.readString(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8642 | Uid.Proc proc = new Proc(mBsi, processName); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8643 | proc.readFromParcelLocked(in); |
| 8644 | mProcessStats.put(processName, proc); |
| 8645 | } |
| 8646 | |
| 8647 | int numPkgs = in.readInt(); |
| 8648 | mPackageStats.clear(); |
| 8649 | for (int l = 0; l < numPkgs; l++) { |
| 8650 | String packageName = in.readString(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8651 | Uid.Pkg pkg = new Pkg(mBsi); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8652 | pkg.readFromParcelLocked(in); |
| 8653 | mPackageStats.put(packageName, pkg); |
| 8654 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8655 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 8656 | mWifiRunning = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8657 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8658 | mWifiRunningTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, WIFI_RUNNING, |
| 8659 | mBsi.mWifiRunningTimers, mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 8660 | } else { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 8661 | mWifiRunningTimer = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8662 | } |
| 8663 | mFullWifiLockOut = false; |
| 8664 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8665 | mFullWifiLockTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, FULL_WIFI_LOCK, |
| 8666 | mBsi.mFullWifiLockTimers, mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8667 | } else { |
| 8668 | mFullWifiLockTimer = null; |
| 8669 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 8670 | mWifiScanStarted = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8671 | if (in.readInt() != 0) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 8672 | mWifiScanTimer = new DualTimer(mBsi.mClocks, Uid.this, WIFI_SCAN, |
| 8673 | mBsi.mWifiScanTimers, mBsi.mOnBatteryTimeBase, mOnBatteryBackgroundTimeBase, |
| 8674 | in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8675 | } else { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 8676 | mWifiScanTimer = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8677 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 8678 | mWifiBatchedScanBinStarted = NO_BATCHED_SCAN_STARTED; |
| 8679 | for (int i = 0; i < NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 8680 | if (in.readInt() != 0) { |
| 8681 | makeWifiBatchedScanBin(i, in); |
| 8682 | } else { |
| 8683 | mWifiBatchedScanTimer[i] = null; |
| 8684 | } |
| 8685 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8686 | mWifiMulticastEnabled = false; |
| 8687 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8688 | mWifiMulticastTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, WIFI_MULTICAST_ENABLED, |
| 8689 | mBsi.mWifiMulticastTimers, mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8690 | } else { |
| 8691 | mWifiMulticastTimer = null; |
| 8692 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8693 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8694 | mAudioTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, AUDIO_TURNED_ON, |
| 8695 | mBsi.mAudioTurnedOnTimers, mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8696 | } else { |
| 8697 | mAudioTurnedOnTimer = null; |
| 8698 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8699 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8700 | mVideoTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, VIDEO_TURNED_ON, |
| 8701 | mBsi.mVideoTurnedOnTimers, mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8702 | } else { |
| 8703 | mVideoTurnedOnTimer = null; |
| 8704 | } |
| 8705 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8706 | mFlashlightTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, |
| 8707 | FLASHLIGHT_TURNED_ON, mBsi.mFlashlightTurnedOnTimers, mBsi.mOnBatteryTimeBase, in); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 8708 | } else { |
| 8709 | mFlashlightTurnedOnTimer = null; |
| 8710 | } |
| 8711 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8712 | mCameraTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, CAMERA_TURNED_ON, |
| 8713 | mBsi.mCameraTurnedOnTimers, mBsi.mOnBatteryTimeBase, in); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 8714 | } else { |
| 8715 | mCameraTurnedOnTimer = null; |
| 8716 | } |
| 8717 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8718 | mForegroundActivityTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, |
| 8719 | FOREGROUND_ACTIVITY, null, mBsi.mOnBatteryTimeBase, in); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 8720 | } else { |
| 8721 | mForegroundActivityTimer = null; |
| 8722 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 8723 | if (in.readInt() != 0) { |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 8724 | mForegroundServiceTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, |
| 8725 | FOREGROUND_SERVICE, null, mBsi.mOnBatteryTimeBase, in); |
| 8726 | } else { |
| 8727 | mForegroundServiceTimer = null; |
| 8728 | } |
| 8729 | if (in.readInt() != 0) { |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 8730 | mAggregatedPartialWakelockTimer = new DualTimer(mBsi.mClocks, this, |
| 8731 | AGGREGATED_WAKE_TYPE_PARTIAL, null, |
| 8732 | mBsi.mOnBatteryScreenOffTimeBase, mOnBatteryScreenOffBackgroundTimeBase, |
| 8733 | in); |
| 8734 | } else { |
| 8735 | mAggregatedPartialWakelockTimer = null; |
| 8736 | } |
| 8737 | if (in.readInt() != 0) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 8738 | mBluetoothScanTimer = new DualTimer(mBsi.mClocks, Uid.this, BLUETOOTH_SCAN_ON, |
| 8739 | mBsi.mBluetoothScanOnTimers, mBsi.mOnBatteryTimeBase, |
| 8740 | mOnBatteryBackgroundTimeBase, in); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 8741 | } else { |
| 8742 | mBluetoothScanTimer = null; |
| 8743 | } |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 8744 | if (in.readInt() != 0) { |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 8745 | mBluetoothUnoptimizedScanTimer = new DualTimer(mBsi.mClocks, Uid.this, |
| 8746 | BLUETOOTH_UNOPTIMIZED_SCAN_ON, null, |
| 8747 | mBsi.mOnBatteryTimeBase, mOnBatteryBackgroundTimeBase, in); |
| 8748 | } else { |
| 8749 | mBluetoothUnoptimizedScanTimer = null; |
| 8750 | } |
| 8751 | if (in.readInt() != 0) { |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 8752 | mBluetoothScanResultCounter = new Counter(mBsi.mOnBatteryTimeBase, in); |
| 8753 | } else { |
| 8754 | mBluetoothScanResultCounter = null; |
| 8755 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 8756 | if (in.readInt() != 0) { |
| 8757 | mBluetoothScanResultBgCounter = new Counter(mOnBatteryBackgroundTimeBase, in); |
| 8758 | } else { |
| 8759 | mBluetoothScanResultBgCounter = null; |
| 8760 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 8761 | mProcessState = ActivityManager.PROCESS_STATE_NONEXISTENT; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 8762 | for (int i = 0; i < NUM_PROCESS_STATE; i++) { |
| 8763 | if (in.readInt() != 0) { |
| 8764 | makeProcessState(i, in); |
| 8765 | } else { |
| 8766 | mProcessStateTimer[i] = null; |
| 8767 | } |
| 8768 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 8769 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8770 | mVibratorOnTimer = new BatchTimer(mBsi.mClocks, Uid.this, VIBRATOR_ON, |
| 8771 | mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 8772 | } else { |
| 8773 | mVibratorOnTimer = null; |
| 8774 | } |
| 8775 | if (in.readInt() != 0) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 8776 | mUserActivityCounters = new Counter[NUM_USER_ACTIVITY_TYPES]; |
| 8777 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8778 | mUserActivityCounters[i] = new Counter(mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 8779 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8780 | } else { |
| 8781 | mUserActivityCounters = null; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 8782 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 8783 | if (in.readInt() != 0) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 8784 | mNetworkByteActivityCounters = new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
| 8785 | mNetworkPacketActivityCounters |
| 8786 | = new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 8787 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8788 | mNetworkByteActivityCounters[i] |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8789 | = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8790 | mNetworkPacketActivityCounters[i] |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8791 | = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 8792 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8793 | mMobileRadioActiveTime = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
| 8794 | mMobileRadioActiveCount = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 8795 | } else { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 8796 | mNetworkByteActivityCounters = null; |
| 8797 | mNetworkPacketActivityCounters = null; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 8798 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8799 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8800 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8801 | mWifiControllerActivity = new ControllerActivityCounterImpl(mBsi.mOnBatteryTimeBase, |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8802 | NUM_WIFI_TX_LEVELS, in); |
| 8803 | } else { |
| 8804 | mWifiControllerActivity = null; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8805 | } |
| 8806 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8807 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8808 | mBluetoothControllerActivity = new ControllerActivityCounterImpl(mBsi.mOnBatteryTimeBase, |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8809 | NUM_BT_TX_LEVELS, in); |
| 8810 | } else { |
| 8811 | mBluetoothControllerActivity = null; |
| 8812 | } |
| 8813 | |
| 8814 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8815 | mModemControllerActivity = new ControllerActivityCounterImpl(mBsi.mOnBatteryTimeBase, |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8816 | ModemActivityInfo.TX_POWER_LEVELS, in); |
| 8817 | } else { |
| 8818 | mModemControllerActivity = null; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8819 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 8820 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8821 | mUserCpuTime = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
| 8822 | mSystemCpuTime = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 8823 | |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 8824 | if (in.readInt() != 0) { |
| 8825 | int numCpuClusters = in.readInt(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8826 | if (mBsi.mPowerProfile != null && mBsi.mPowerProfile.getNumCpuClusters() != numCpuClusters) { |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 8827 | throw new ParcelFormatException("Incompatible number of cpu clusters"); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 8828 | } |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 8829 | |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 8830 | mCpuClusterSpeedTimesUs = new LongSamplingCounter[numCpuClusters][]; |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 8831 | for (int cluster = 0; cluster < numCpuClusters; cluster++) { |
| 8832 | if (in.readInt() != 0) { |
| 8833 | int numSpeeds = in.readInt(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8834 | if (mBsi.mPowerProfile != null && |
| 8835 | mBsi.mPowerProfile.getNumSpeedStepsInCpuCluster(cluster) != numSpeeds) { |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 8836 | throw new ParcelFormatException("Incompatible number of cpu speeds"); |
| 8837 | } |
| 8838 | |
| 8839 | final LongSamplingCounter[] cpuSpeeds = new LongSamplingCounter[numSpeeds]; |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 8840 | mCpuClusterSpeedTimesUs[cluster] = cpuSpeeds; |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 8841 | for (int speed = 0; speed < numSpeeds; speed++) { |
| 8842 | if (in.readInt() != 0) { |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 8843 | cpuSpeeds[speed] = new LongSamplingCounter( |
| 8844 | mBsi.mOnBatteryTimeBase, in); |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 8845 | } |
| 8846 | } |
Adam Lesinski | a57a540 | 2015-09-28 10:21:33 -0700 | [diff] [blame] | 8847 | } else { |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 8848 | mCpuClusterSpeedTimesUs[cluster] = null; |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 8849 | } |
| 8850 | } |
| 8851 | } else { |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 8852 | mCpuClusterSpeedTimesUs = null; |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 8853 | } |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 8854 | |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 8855 | mCpuFreqTimeMs = LongSamplingCounterArray.readFromParcel(in, mBsi.mOnBatteryTimeBase); |
| 8856 | mScreenOffCpuFreqTimeMs = LongSamplingCounterArray.readFromParcel( |
| 8857 | in, mBsi.mOnBatteryScreenOffTimeBase); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 8858 | |
Mike Ma | 3d422c3 | 2017-10-25 11:08:57 -0700 | [diff] [blame] | 8859 | mCpuActiveTimeMs = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
| 8860 | mCpuClusterTimesMs = new LongSamplingCounterArray(mBsi.mOnBatteryTimeBase, in); |
| 8861 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 8862 | int length = in.readInt(); |
| 8863 | if (length == NUM_PROCESS_STATE) { |
| 8864 | mProcStateTimeMs = new LongSamplingCounterArray[length]; |
| 8865 | for (int procState = 0; procState < length; ++procState) { |
| 8866 | mProcStateTimeMs[procState] = LongSamplingCounterArray.readFromParcel( |
| 8867 | in, mBsi.mOnBatteryTimeBase); |
| 8868 | } |
| 8869 | } else { |
| 8870 | mProcStateTimeMs = null; |
| 8871 | } |
| 8872 | length = in.readInt(); |
| 8873 | if (length == NUM_PROCESS_STATE) { |
| 8874 | mProcStateScreenOffTimeMs = new LongSamplingCounterArray[length]; |
| 8875 | for (int procState = 0; procState < length; ++procState) { |
| 8876 | mProcStateScreenOffTimeMs[procState] = LongSamplingCounterArray.readFromParcel( |
| 8877 | in, mBsi.mOnBatteryScreenOffTimeBase); |
| 8878 | } |
| 8879 | } else { |
| 8880 | mProcStateScreenOffTimeMs = null; |
| 8881 | } |
| 8882 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 8883 | if (in.readInt() != 0) { |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 8884 | mMobileRadioApWakeupCount = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
| 8885 | } else { |
| 8886 | mMobileRadioApWakeupCount = null; |
| 8887 | } |
| 8888 | |
| 8889 | if (in.readInt() != 0) { |
| 8890 | mWifiRadioApWakeupCount = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
| 8891 | } else { |
| 8892 | mWifiRadioApWakeupCount = null; |
| 8893 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8894 | } |
| 8895 | |
Amith Yamasani | 977e11f | 2018-02-16 11:29:54 -0800 | [diff] [blame] | 8896 | public void noteJobsDeferredLocked(int numDeferred, long sinceLast) { |
| 8897 | mJobsDeferredEventCount.addAtomic(1); |
| 8898 | mJobsDeferredCount.addAtomic(numDeferred); |
| 8899 | if (sinceLast != 0) { |
| 8900 | // Add the total time, which can be divided by the event count to get an average |
| 8901 | mJobsFreshnessTimeMs.addCountLocked(sinceLast); |
| 8902 | // Also keep track of how many times there were in these different buckets. |
| 8903 | for (int i = 0; i < JOB_FRESHNESS_BUCKETS.length; i++) { |
| 8904 | if (sinceLast < JOB_FRESHNESS_BUCKETS[i]) { |
| 8905 | if (mJobsFreshnessBuckets[i] == null) { |
| 8906 | mJobsFreshnessBuckets[i] = new Counter( |
| 8907 | mBsi.mOnBatteryTimeBase); |
| 8908 | } |
| 8909 | mJobsFreshnessBuckets[i].addAtomic(1); |
| 8910 | break; |
| 8911 | } |
| 8912 | } |
| 8913 | } |
| 8914 | } |
| 8915 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8916 | /** |
| 8917 | * The statistics associated with a particular wake lock. |
| 8918 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8919 | public static class Wakelock extends BatteryStats.Uid.Wakelock { |
| 8920 | /** |
| 8921 | * BatteryStatsImpl that we are associated with. |
| 8922 | */ |
| 8923 | protected BatteryStatsImpl mBsi; |
| 8924 | |
| 8925 | /** |
| 8926 | * BatteryStatsImpl that we are associated with. |
| 8927 | */ |
| 8928 | protected Uid mUid; |
| 8929 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8930 | /** |
| 8931 | * How long (in ms) this uid has been keeping the device partially awake. |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 8932 | * 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] | 8933 | */ |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 8934 | DualTimer mTimerPartial; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8935 | |
| 8936 | /** |
| 8937 | * How long (in ms) this uid has been keeping the device fully awake. |
| 8938 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 8939 | StopwatchTimer mTimerFull; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8940 | |
| 8941 | /** |
| 8942 | * How long (in ms) this uid has had a window keeping the device awake. |
| 8943 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 8944 | StopwatchTimer mTimerWindow; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8945 | |
| 8946 | /** |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 8947 | * How long (in ms) this uid has had a draw wake lock. |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 8948 | */ |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 8949 | StopwatchTimer mTimerDraw; |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 8950 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8951 | public Wakelock(BatteryStatsImpl bsi, Uid uid) { |
| 8952 | mBsi = bsi; |
| 8953 | mUid = uid; |
| 8954 | } |
| 8955 | |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 8956 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8957 | * Reads a possibly null Timer from a Parcel. The timer is associated with the |
| 8958 | * proper timer pool from the given BatteryStatsImpl object. |
| 8959 | * |
| 8960 | * @param in the Parcel to be read from. |
| 8961 | * return a new Timer, or null. |
| 8962 | */ |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 8963 | private StopwatchTimer readStopwatchTimerFromParcel(int type, |
| 8964 | ArrayList<StopwatchTimer> pool, TimeBase timeBase, Parcel in) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8965 | if (in.readInt() == 0) { |
| 8966 | return null; |
| 8967 | } |
| 8968 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8969 | 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] | 8970 | } |
| 8971 | |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 8972 | /** |
| 8973 | * Reads a possibly null Timer from a Parcel. The timer is associated with the |
| 8974 | * proper timer pool from the given BatteryStatsImpl object. |
| 8975 | * |
| 8976 | * @param in the Parcel to be read from. |
| 8977 | * return a new Timer, or null. |
| 8978 | */ |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 8979 | private DualTimer readDualTimerFromParcel(int type, ArrayList<StopwatchTimer> pool, |
| 8980 | TimeBase timeBase, TimeBase bgTimeBase, Parcel in) { |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 8981 | if (in.readInt() == 0) { |
| 8982 | return null; |
| 8983 | } |
| 8984 | |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 8985 | return new DualTimer(mBsi.mClocks, mUid, type, pool, timeBase, bgTimeBase, in); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 8986 | } |
| 8987 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8988 | boolean reset() { |
| 8989 | boolean wlactive = false; |
| 8990 | if (mTimerFull != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8991 | wlactive |= !mTimerFull.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8992 | } |
| 8993 | if (mTimerPartial != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8994 | wlactive |= !mTimerPartial.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8995 | } |
| 8996 | if (mTimerWindow != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8997 | wlactive |= !mTimerWindow.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8998 | } |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 8999 | if (mTimerDraw != null) { |
| 9000 | wlactive |= !mTimerDraw.reset(false); |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 9001 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9002 | if (!wlactive) { |
| 9003 | if (mTimerFull != null) { |
| 9004 | mTimerFull.detach(); |
| 9005 | mTimerFull = null; |
| 9006 | } |
| 9007 | if (mTimerPartial != null) { |
| 9008 | mTimerPartial.detach(); |
| 9009 | mTimerPartial = null; |
| 9010 | } |
| 9011 | if (mTimerWindow != null) { |
| 9012 | mTimerWindow.detach(); |
| 9013 | mTimerWindow = null; |
| 9014 | } |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 9015 | if (mTimerDraw != null) { |
| 9016 | mTimerDraw.detach(); |
| 9017 | mTimerDraw = null; |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 9018 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9019 | } |
| 9020 | return !wlactive; |
| 9021 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9022 | |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 9023 | void readFromParcelLocked(TimeBase timeBase, TimeBase screenOffTimeBase, |
| 9024 | TimeBase screenOffBgTimeBase, Parcel in) { |
| 9025 | mTimerPartial = readDualTimerFromParcel(WAKE_TYPE_PARTIAL, |
| 9026 | mBsi.mPartialTimers, screenOffTimeBase, screenOffBgTimeBase, in); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 9027 | mTimerFull = readStopwatchTimerFromParcel(WAKE_TYPE_FULL, |
| 9028 | mBsi.mFullTimers, timeBase, in); |
| 9029 | mTimerWindow = readStopwatchTimerFromParcel(WAKE_TYPE_WINDOW, |
| 9030 | mBsi.mWindowTimers, timeBase, in); |
| 9031 | mTimerDraw = readStopwatchTimerFromParcel(WAKE_TYPE_DRAW, |
| 9032 | mBsi.mDrawTimers, timeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9033 | } |
| 9034 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9035 | void writeToParcelLocked(Parcel out, long elapsedRealtimeUs) { |
| 9036 | Timer.writeTimerToParcel(out, mTimerPartial, elapsedRealtimeUs); |
| 9037 | Timer.writeTimerToParcel(out, mTimerFull, elapsedRealtimeUs); |
| 9038 | Timer.writeTimerToParcel(out, mTimerWindow, elapsedRealtimeUs); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 9039 | Timer.writeTimerToParcel(out, mTimerDraw, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9040 | } |
| 9041 | |
| 9042 | @Override |
| 9043 | public Timer getWakeTime(int type) { |
| 9044 | switch (type) { |
| 9045 | case WAKE_TYPE_FULL: return mTimerFull; |
| 9046 | case WAKE_TYPE_PARTIAL: return mTimerPartial; |
| 9047 | case WAKE_TYPE_WINDOW: return mTimerWindow; |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 9048 | case WAKE_TYPE_DRAW: return mTimerDraw; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9049 | default: throw new IllegalArgumentException("type = " + type); |
| 9050 | } |
| 9051 | } |
| 9052 | } |
| 9053 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9054 | public static class Sensor extends BatteryStats.Uid.Sensor { |
| 9055 | /** |
| 9056 | * BatteryStatsImpl that we are associated with. |
| 9057 | */ |
| 9058 | protected BatteryStatsImpl mBsi; |
| 9059 | |
| 9060 | /** |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 9061 | * Uid that we are associated with. |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9062 | */ |
| 9063 | protected Uid mUid; |
| 9064 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9065 | final int mHandle; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 9066 | DualTimer mTimer; |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 9067 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9068 | public Sensor(BatteryStatsImpl bsi, Uid uid, int handle) { |
| 9069 | mBsi = bsi; |
| 9070 | mUid = uid; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9071 | mHandle = handle; |
| 9072 | } |
| 9073 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 9074 | private DualTimer readTimersFromParcel( |
| 9075 | TimeBase timeBase, TimeBase bgTimeBase, Parcel in) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9076 | if (in.readInt() == 0) { |
| 9077 | return null; |
| 9078 | } |
| 9079 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9080 | ArrayList<StopwatchTimer> pool = mBsi.mSensorTimers.get(mHandle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9081 | if (pool == null) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 9082 | pool = new ArrayList<StopwatchTimer>(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9083 | mBsi.mSensorTimers.put(mHandle, pool); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9084 | } |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 9085 | return new DualTimer(mBsi.mClocks, mUid, 0, pool, timeBase, bgTimeBase, in); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 9086 | } |
| 9087 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9088 | boolean reset() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9089 | if (mTimer.reset(true)) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9090 | mTimer = null; |
| 9091 | return true; |
| 9092 | } |
| 9093 | return false; |
| 9094 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9095 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 9096 | void readFromParcelLocked(TimeBase timeBase, TimeBase bgTimeBase, Parcel in) { |
| 9097 | mTimer = readTimersFromParcel(timeBase, bgTimeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9098 | } |
| 9099 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9100 | void writeToParcelLocked(Parcel out, long elapsedRealtimeUs) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 9101 | Timer.writeTimerToParcel(out, mTimer, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9102 | } |
| 9103 | |
| 9104 | @Override |
| 9105 | public Timer getSensorTime() { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 9106 | return mTimer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9107 | } |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 9108 | |
| 9109 | @Override |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 9110 | public Timer getSensorBackgroundTime() { |
| 9111 | if (mTimer == null) { |
| 9112 | return null; |
| 9113 | } |
| 9114 | return mTimer.getSubTimer(); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 9115 | } |
| 9116 | |
| 9117 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9118 | public int getHandle() { |
| 9119 | return mHandle; |
| 9120 | } |
| 9121 | } |
| 9122 | |
| 9123 | /** |
| 9124 | * The statistics associated with a particular process. |
| 9125 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9126 | public static class Proc extends BatteryStats.Uid.Proc implements TimeBaseObs { |
| 9127 | /** |
| 9128 | * BatteryStatsImpl that we are associated with. |
| 9129 | */ |
| 9130 | protected BatteryStatsImpl mBsi; |
| 9131 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9132 | /** |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 9133 | * The name of this process. |
| 9134 | */ |
| 9135 | final String mName; |
| 9136 | |
| 9137 | /** |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 9138 | * Remains true until removed from the stats. |
| 9139 | */ |
| 9140 | boolean mActive = true; |
| 9141 | |
| 9142 | /** |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 9143 | * Total time (in ms) spent executing in user code. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9144 | */ |
| 9145 | long mUserTime; |
| 9146 | |
| 9147 | /** |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 9148 | * Total time (in ms) spent executing in kernel code. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9149 | */ |
| 9150 | long mSystemTime; |
| 9151 | |
| 9152 | /** |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 9153 | * Amount of time (in ms) the process was running in the foreground. |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 9154 | */ |
| 9155 | long mForegroundTime; |
| 9156 | |
| 9157 | /** |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 9158 | * Number of times the process has been started. |
| 9159 | */ |
| 9160 | int mStarts; |
| 9161 | |
| 9162 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9163 | * Number of times the process has crashed. |
| 9164 | */ |
| 9165 | int mNumCrashes; |
| 9166 | |
| 9167 | /** |
| 9168 | * Number of times the process has had an ANR. |
| 9169 | */ |
| 9170 | int mNumAnrs; |
| 9171 | |
| 9172 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9173 | * The amount of user time loaded from a previous save. |
| 9174 | */ |
| 9175 | long mLoadedUserTime; |
| 9176 | |
| 9177 | /** |
| 9178 | * The amount of system time loaded from a previous save. |
| 9179 | */ |
| 9180 | long mLoadedSystemTime; |
| 9181 | |
| 9182 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 9183 | * The amount of foreground time loaded from a previous save. |
| 9184 | */ |
| 9185 | long mLoadedForegroundTime; |
| 9186 | |
| 9187 | /** |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 9188 | * The number of times the process has started from a previous save. |
| 9189 | */ |
| 9190 | int mLoadedStarts; |
| 9191 | |
| 9192 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9193 | * 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] | 9194 | */ |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9195 | int mLoadedNumCrashes; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9196 | |
| 9197 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9198 | * 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] | 9199 | */ |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9200 | int mLoadedNumAnrs; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 9201 | |
| 9202 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9203 | * The amount of user time when last unplugged. |
| 9204 | */ |
| 9205 | long mUnpluggedUserTime; |
| 9206 | |
| 9207 | /** |
| 9208 | * The amount of system time when last unplugged. |
| 9209 | */ |
| 9210 | long mUnpluggedSystemTime; |
| 9211 | |
| 9212 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 9213 | * The amount of foreground time since unplugged. |
| 9214 | */ |
| 9215 | long mUnpluggedForegroundTime; |
| 9216 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 9217 | /** |
| 9218 | * The number of times the process has started before unplugged. |
| 9219 | */ |
| 9220 | int mUnpluggedStarts; |
| 9221 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 9222 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9223 | * Number of times the process has crashed before unplugged. |
| 9224 | */ |
| 9225 | int mUnpluggedNumCrashes; |
| 9226 | |
| 9227 | /** |
| 9228 | * Number of times the process has had an ANR before unplugged. |
| 9229 | */ |
| 9230 | int mUnpluggedNumAnrs; |
| 9231 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 9232 | ArrayList<ExcessivePower> mExcessivePower; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 9233 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9234 | public Proc(BatteryStatsImpl bsi, String name) { |
| 9235 | mBsi = bsi; |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 9236 | mName = name; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9237 | mBsi.mOnBatteryTimeBase.add(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9238 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 9239 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9240 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9241 | mUnpluggedUserTime = mUserTime; |
| 9242 | mUnpluggedSystemTime = mSystemTime; |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 9243 | mUnpluggedForegroundTime = mForegroundTime; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 9244 | mUnpluggedStarts = mStarts; |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9245 | mUnpluggedNumCrashes = mNumCrashes; |
| 9246 | mUnpluggedNumAnrs = mNumAnrs; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9247 | } |
| 9248 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9249 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9250 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9251 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9252 | void detach() { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 9253 | mActive = false; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9254 | mBsi.mOnBatteryTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9255 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9256 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 9257 | public int countExcessivePowers() { |
| 9258 | return mExcessivePower != null ? mExcessivePower.size() : 0; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 9259 | } |
| 9260 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 9261 | public ExcessivePower getExcessivePower(int i) { |
| 9262 | if (mExcessivePower != null) { |
| 9263 | return mExcessivePower.get(i); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 9264 | } |
| 9265 | return null; |
| 9266 | } |
| 9267 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 9268 | public void addExcessiveCpu(long overTime, long usedTime) { |
| 9269 | if (mExcessivePower == null) { |
| 9270 | mExcessivePower = new ArrayList<ExcessivePower>(); |
| 9271 | } |
| 9272 | ExcessivePower ew = new ExcessivePower(); |
| 9273 | ew.type = ExcessivePower.TYPE_CPU; |
| 9274 | ew.overTime = overTime; |
| 9275 | ew.usedTime = usedTime; |
| 9276 | mExcessivePower.add(ew); |
| 9277 | } |
| 9278 | |
| 9279 | void writeExcessivePowerToParcelLocked(Parcel out) { |
| 9280 | if (mExcessivePower == null) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 9281 | out.writeInt(0); |
| 9282 | return; |
| 9283 | } |
| 9284 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 9285 | final int N = mExcessivePower.size(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 9286 | out.writeInt(N); |
| 9287 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 9288 | ExcessivePower ew = mExcessivePower.get(i); |
| 9289 | out.writeInt(ew.type); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 9290 | out.writeLong(ew.overTime); |
| 9291 | out.writeLong(ew.usedTime); |
| 9292 | } |
| 9293 | } |
| 9294 | |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 9295 | void readExcessivePowerFromParcelLocked(Parcel in) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 9296 | final int N = in.readInt(); |
| 9297 | if (N == 0) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 9298 | mExcessivePower = null; |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 9299 | return; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 9300 | } |
| 9301 | |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 9302 | if (N > 10000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 9303 | throw new ParcelFormatException( |
| 9304 | "File corrupt: too many excessive power entries " + N); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 9305 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9306 | |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 9307 | mExcessivePower = new ArrayList<>(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 9308 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 9309 | ExcessivePower ew = new ExcessivePower(); |
| 9310 | ew.type = in.readInt(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 9311 | ew.overTime = in.readLong(); |
| 9312 | ew.usedTime = in.readLong(); |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 9313 | mExcessivePower.add(ew); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 9314 | } |
| 9315 | } |
| 9316 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9317 | void writeToParcelLocked(Parcel out) { |
| 9318 | out.writeLong(mUserTime); |
| 9319 | out.writeLong(mSystemTime); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 9320 | out.writeLong(mForegroundTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9321 | out.writeInt(mStarts); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9322 | out.writeInt(mNumCrashes); |
| 9323 | out.writeInt(mNumAnrs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9324 | out.writeLong(mLoadedUserTime); |
| 9325 | out.writeLong(mLoadedSystemTime); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 9326 | out.writeLong(mLoadedForegroundTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9327 | out.writeInt(mLoadedStarts); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9328 | out.writeInt(mLoadedNumCrashes); |
| 9329 | out.writeInt(mLoadedNumAnrs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9330 | out.writeLong(mUnpluggedUserTime); |
| 9331 | out.writeLong(mUnpluggedSystemTime); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 9332 | out.writeLong(mUnpluggedForegroundTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9333 | out.writeInt(mUnpluggedStarts); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9334 | out.writeInt(mUnpluggedNumCrashes); |
| 9335 | out.writeInt(mUnpluggedNumAnrs); |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 9336 | writeExcessivePowerToParcelLocked(out); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9337 | } |
| 9338 | |
| 9339 | void readFromParcelLocked(Parcel in) { |
| 9340 | mUserTime = in.readLong(); |
| 9341 | mSystemTime = in.readLong(); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 9342 | mForegroundTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9343 | mStarts = in.readInt(); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9344 | mNumCrashes = in.readInt(); |
| 9345 | mNumAnrs = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9346 | mLoadedUserTime = in.readLong(); |
| 9347 | mLoadedSystemTime = in.readLong(); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 9348 | mLoadedForegroundTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9349 | mLoadedStarts = in.readInt(); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9350 | mLoadedNumCrashes = in.readInt(); |
| 9351 | mLoadedNumAnrs = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9352 | mUnpluggedUserTime = in.readLong(); |
| 9353 | mUnpluggedSystemTime = in.readLong(); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 9354 | mUnpluggedForegroundTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9355 | mUnpluggedStarts = in.readInt(); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9356 | mUnpluggedNumCrashes = in.readInt(); |
| 9357 | mUnpluggedNumAnrs = in.readInt(); |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 9358 | readExcessivePowerFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9359 | } |
| 9360 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 9361 | public void addCpuTimeLocked(int utime, int stime) { |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 9362 | addCpuTimeLocked(utime, stime, mBsi.mOnBatteryTimeBase.isRunning()); |
| 9363 | } |
| 9364 | |
| 9365 | public void addCpuTimeLocked(int utime, int stime, boolean isRunning) { |
| 9366 | if (isRunning) { |
| 9367 | mUserTime += utime; |
| 9368 | mSystemTime += stime; |
| 9369 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9370 | } |
| 9371 | |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 9372 | public void addForegroundTimeLocked(long ttime) { |
| 9373 | mForegroundTime += ttime; |
| 9374 | } |
| 9375 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9376 | public void incStartsLocked() { |
| 9377 | mStarts++; |
| 9378 | } |
| 9379 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9380 | public void incNumCrashesLocked() { |
| 9381 | mNumCrashes++; |
| 9382 | } |
| 9383 | |
| 9384 | public void incNumAnrsLocked() { |
| 9385 | mNumAnrs++; |
| 9386 | } |
| 9387 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9388 | @Override |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 9389 | public boolean isActive() { |
| 9390 | return mActive; |
| 9391 | } |
| 9392 | |
| 9393 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9394 | public long getUserTime(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 9395 | long val = mUserTime; |
| 9396 | if (which == STATS_CURRENT) { |
| 9397 | val -= mLoadedUserTime; |
| 9398 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 9399 | val -= mUnpluggedUserTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9400 | } |
| 9401 | return val; |
| 9402 | } |
| 9403 | |
| 9404 | @Override |
| 9405 | public long getSystemTime(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 9406 | long val = mSystemTime; |
| 9407 | if (which == STATS_CURRENT) { |
| 9408 | val -= mLoadedSystemTime; |
| 9409 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 9410 | val -= mUnpluggedSystemTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9411 | } |
| 9412 | return val; |
| 9413 | } |
| 9414 | |
| 9415 | @Override |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 9416 | public long getForegroundTime(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 9417 | long val = mForegroundTime; |
| 9418 | if (which == STATS_CURRENT) { |
| 9419 | val -= mLoadedForegroundTime; |
| 9420 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 9421 | val -= mUnpluggedForegroundTime; |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 9422 | } |
| 9423 | return val; |
| 9424 | } |
| 9425 | |
| 9426 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9427 | public int getStarts(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 9428 | int val = mStarts; |
| 9429 | if (which == STATS_CURRENT) { |
| 9430 | val -= mLoadedStarts; |
| 9431 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 9432 | val -= mUnpluggedStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9433 | } |
| 9434 | return val; |
| 9435 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 9436 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9437 | @Override |
| 9438 | public int getNumCrashes(int which) { |
| 9439 | int val = mNumCrashes; |
| 9440 | if (which == STATS_CURRENT) { |
| 9441 | val -= mLoadedNumCrashes; |
| 9442 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 9443 | val -= mUnpluggedNumCrashes; |
| 9444 | } |
| 9445 | return val; |
| 9446 | } |
| 9447 | |
| 9448 | @Override |
| 9449 | public int getNumAnrs(int which) { |
| 9450 | int val = mNumAnrs; |
| 9451 | if (which == STATS_CURRENT) { |
| 9452 | val -= mLoadedNumAnrs; |
| 9453 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 9454 | val -= mUnpluggedNumAnrs; |
| 9455 | } |
| 9456 | return val; |
| 9457 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9458 | } |
| 9459 | |
| 9460 | /** |
| 9461 | * The statistics associated with a particular package. |
| 9462 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9463 | public static class Pkg extends BatteryStats.Uid.Pkg implements TimeBaseObs { |
| 9464 | /** |
| 9465 | * BatteryStatsImpl that we are associated with. |
| 9466 | */ |
| 9467 | protected BatteryStatsImpl mBsi; |
| 9468 | |
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 | * Number of times wakeup alarms have occurred for this app. |
Bookatz | 98d4d5c | 2017-08-01 19:07:54 -0700 | [diff] [blame] | 9471 | * On screen-off timebase starting in report v25. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9472 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 9473 | ArrayMap<String, Counter> mWakeupAlarms = new ArrayMap<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9474 | |
| 9475 | /** |
| 9476 | * The statics we have collected for this package's services. |
| 9477 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 9478 | final ArrayMap<String, Serv> mServiceStats = new ArrayMap<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9479 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9480 | public Pkg(BatteryStatsImpl bsi) { |
| 9481 | mBsi = bsi; |
| 9482 | mBsi.mOnBatteryScreenOffTimeBase.add(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9483 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9484 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9485 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9486 | } |
| 9487 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9488 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9489 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9490 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9491 | void detach() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9492 | mBsi.mOnBatteryScreenOffTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9493 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9494 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9495 | void readFromParcelLocked(Parcel in) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 9496 | int numWA = in.readInt(); |
| 9497 | mWakeupAlarms.clear(); |
| 9498 | for (int i=0; i<numWA; i++) { |
| 9499 | String tag = in.readString(); |
Bookatz | 98d4d5c | 2017-08-01 19:07:54 -0700 | [diff] [blame] | 9500 | mWakeupAlarms.put(tag, new Counter(mBsi.mOnBatteryScreenOffTimeBase, in)); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 9501 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9502 | |
| 9503 | int numServs = in.readInt(); |
| 9504 | mServiceStats.clear(); |
| 9505 | for (int m = 0; m < numServs; m++) { |
| 9506 | String serviceName = in.readString(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9507 | Uid.Pkg.Serv serv = new Serv(mBsi); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9508 | mServiceStats.put(serviceName, serv); |
| 9509 | |
| 9510 | serv.readFromParcelLocked(in); |
| 9511 | } |
| 9512 | } |
| 9513 | |
| 9514 | void writeToParcelLocked(Parcel out) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 9515 | int numWA = mWakeupAlarms.size(); |
| 9516 | out.writeInt(numWA); |
| 9517 | for (int i=0; i<numWA; i++) { |
| 9518 | out.writeString(mWakeupAlarms.keyAt(i)); |
| 9519 | mWakeupAlarms.valueAt(i).writeToParcel(out); |
| 9520 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9521 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 9522 | final int NS = mServiceStats.size(); |
| 9523 | out.writeInt(NS); |
| 9524 | for (int i=0; i<NS; i++) { |
| 9525 | out.writeString(mServiceStats.keyAt(i)); |
| 9526 | Uid.Pkg.Serv serv = mServiceStats.valueAt(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9527 | serv.writeToParcelLocked(out); |
| 9528 | } |
| 9529 | } |
| 9530 | |
| 9531 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 9532 | public ArrayMap<String, ? extends BatteryStats.Counter> getWakeupAlarmStats() { |
| 9533 | return mWakeupAlarms; |
| 9534 | } |
| 9535 | |
| 9536 | public void noteWakeupAlarmLocked(String tag) { |
| 9537 | Counter c = mWakeupAlarms.get(tag); |
| 9538 | if (c == null) { |
Bookatz | 98d4d5c | 2017-08-01 19:07:54 -0700 | [diff] [blame] | 9539 | c = new Counter(mBsi.mOnBatteryScreenOffTimeBase); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 9540 | mWakeupAlarms.put(tag, c); |
| 9541 | } |
| 9542 | c.stepAtomic(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9543 | } |
| 9544 | |
| 9545 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 9546 | public ArrayMap<String, ? extends BatteryStats.Uid.Pkg.Serv> getServiceStats() { |
| 9547 | return mServiceStats; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9548 | } |
| 9549 | |
| 9550 | /** |
| 9551 | * The statistics associated with a particular service. |
| 9552 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9553 | public static class Serv extends BatteryStats.Uid.Pkg.Serv implements TimeBaseObs { |
| 9554 | /** |
| 9555 | * BatteryStatsImpl that we are associated with. |
| 9556 | */ |
| 9557 | protected BatteryStatsImpl mBsi; |
| 9558 | |
| 9559 | /** |
| 9560 | * The android package in which this service resides. |
| 9561 | */ |
| 9562 | protected Pkg mPkg; |
| 9563 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9564 | /** |
| 9565 | * Total time (ms in battery uptime) the service has been left started. |
| 9566 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9567 | protected long mStartTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9568 | |
| 9569 | /** |
| 9570 | * If service has been started and not yet stopped, this is |
| 9571 | * when it was started. |
| 9572 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9573 | protected long mRunningSince; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9574 | |
| 9575 | /** |
| 9576 | * True if we are currently running. |
| 9577 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9578 | protected boolean mRunning; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9579 | |
| 9580 | /** |
| 9581 | * Total number of times startService() has been called. |
| 9582 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9583 | protected int mStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9584 | |
| 9585 | /** |
| 9586 | * Total time (ms in battery uptime) the service has been left launched. |
| 9587 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9588 | protected long mLaunchedTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9589 | |
| 9590 | /** |
| 9591 | * If service has been launched and not yet exited, this is |
| 9592 | * when it was launched (ms in battery uptime). |
| 9593 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9594 | protected long mLaunchedSince; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9595 | |
| 9596 | /** |
| 9597 | * True if we are currently launched. |
| 9598 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9599 | protected boolean mLaunched; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9600 | |
| 9601 | /** |
| 9602 | * Total number times the service has been launched. |
| 9603 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9604 | protected int mLaunches; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9605 | |
| 9606 | /** |
| 9607 | * The amount of time spent started loaded from a previous save |
| 9608 | * (ms in battery uptime). |
| 9609 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9610 | protected long mLoadedStartTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9611 | |
| 9612 | /** |
| 9613 | * The number of starts loaded from a previous save. |
| 9614 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9615 | protected int mLoadedStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9616 | |
| 9617 | /** |
| 9618 | * The number of launches loaded from a previous save. |
| 9619 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9620 | protected int mLoadedLaunches; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9621 | |
| 9622 | /** |
| 9623 | * The amount of time spent started as of the last run (ms |
| 9624 | * in battery uptime). |
| 9625 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9626 | protected long mLastStartTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9627 | |
| 9628 | /** |
| 9629 | * The number of starts as of the last run. |
| 9630 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9631 | protected int mLastStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9632 | |
| 9633 | /** |
| 9634 | * The number of launches as of the last run. |
| 9635 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9636 | protected int mLastLaunches; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9637 | |
| 9638 | /** |
| 9639 | * The amount of time spent started when last unplugged (ms |
| 9640 | * in battery uptime). |
| 9641 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9642 | protected long mUnpluggedStartTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9643 | |
| 9644 | /** |
| 9645 | * The number of starts when last unplugged. |
| 9646 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9647 | protected int mUnpluggedStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9648 | |
| 9649 | /** |
| 9650 | * The number of launches when last unplugged. |
| 9651 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9652 | protected int mUnpluggedLaunches; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9653 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9654 | /** |
| 9655 | * Construct a Serv. Also adds it to the on-battery time base as a listener. |
| 9656 | */ |
| 9657 | public Serv(BatteryStatsImpl bsi) { |
| 9658 | mBsi = bsi; |
| 9659 | mBsi.mOnBatteryTimeBase.add(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9660 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9661 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9662 | public void onTimeStarted(long elapsedRealtime, long baseUptime, |
| 9663 | long baseRealtime) { |
| 9664 | mUnpluggedStartTime = getStartTimeToNowLocked(baseUptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9665 | mUnpluggedStarts = mStarts; |
| 9666 | mUnpluggedLaunches = mLaunches; |
| 9667 | } |
| 9668 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9669 | public void onTimeStopped(long elapsedRealtime, long baseUptime, |
| 9670 | long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9671 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9672 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9673 | /** |
| 9674 | * Remove this Serv as a listener from the time base. |
| 9675 | */ |
| 9676 | public void detach() { |
| 9677 | mBsi.mOnBatteryTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9678 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9679 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9680 | public void readFromParcelLocked(Parcel in) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9681 | mStartTime = in.readLong(); |
| 9682 | mRunningSince = in.readLong(); |
| 9683 | mRunning = in.readInt() != 0; |
| 9684 | mStarts = in.readInt(); |
| 9685 | mLaunchedTime = in.readLong(); |
| 9686 | mLaunchedSince = in.readLong(); |
| 9687 | mLaunched = in.readInt() != 0; |
| 9688 | mLaunches = in.readInt(); |
| 9689 | mLoadedStartTime = in.readLong(); |
| 9690 | mLoadedStarts = in.readInt(); |
| 9691 | mLoadedLaunches = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 9692 | mLastStartTime = 0; |
| 9693 | mLastStarts = 0; |
| 9694 | mLastLaunches = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9695 | mUnpluggedStartTime = in.readLong(); |
| 9696 | mUnpluggedStarts = in.readInt(); |
| 9697 | mUnpluggedLaunches = in.readInt(); |
| 9698 | } |
| 9699 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9700 | public void writeToParcelLocked(Parcel out) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9701 | out.writeLong(mStartTime); |
| 9702 | out.writeLong(mRunningSince); |
| 9703 | out.writeInt(mRunning ? 1 : 0); |
| 9704 | out.writeInt(mStarts); |
| 9705 | out.writeLong(mLaunchedTime); |
| 9706 | out.writeLong(mLaunchedSince); |
| 9707 | out.writeInt(mLaunched ? 1 : 0); |
| 9708 | out.writeInt(mLaunches); |
| 9709 | out.writeLong(mLoadedStartTime); |
| 9710 | out.writeInt(mLoadedStarts); |
| 9711 | out.writeInt(mLoadedLaunches); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9712 | out.writeLong(mUnpluggedStartTime); |
| 9713 | out.writeInt(mUnpluggedStarts); |
| 9714 | out.writeInt(mUnpluggedLaunches); |
| 9715 | } |
| 9716 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9717 | public long getLaunchTimeToNowLocked(long batteryUptime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9718 | if (!mLaunched) return mLaunchedTime; |
| 9719 | return mLaunchedTime + batteryUptime - mLaunchedSince; |
| 9720 | } |
| 9721 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9722 | public long getStartTimeToNowLocked(long batteryUptime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9723 | if (!mRunning) return mStartTime; |
| 9724 | return mStartTime + batteryUptime - mRunningSince; |
| 9725 | } |
| 9726 | |
| 9727 | public void startLaunchedLocked() { |
| 9728 | if (!mLaunched) { |
| 9729 | mLaunches++; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9730 | mLaunchedSince = mBsi.getBatteryUptimeLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9731 | mLaunched = true; |
| 9732 | } |
| 9733 | } |
| 9734 | |
| 9735 | public void stopLaunchedLocked() { |
| 9736 | if (mLaunched) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9737 | long time = mBsi.getBatteryUptimeLocked() - mLaunchedSince; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9738 | if (time > 0) { |
| 9739 | mLaunchedTime += time; |
| 9740 | } else { |
| 9741 | mLaunches--; |
| 9742 | } |
| 9743 | mLaunched = false; |
| 9744 | } |
| 9745 | } |
| 9746 | |
| 9747 | public void startRunningLocked() { |
| 9748 | if (!mRunning) { |
| 9749 | mStarts++; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9750 | mRunningSince = mBsi.getBatteryUptimeLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9751 | mRunning = true; |
| 9752 | } |
| 9753 | } |
| 9754 | |
| 9755 | public void stopRunningLocked() { |
| 9756 | if (mRunning) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9757 | long time = mBsi.getBatteryUptimeLocked() - mRunningSince; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9758 | if (time > 0) { |
| 9759 | mStartTime += time; |
| 9760 | } else { |
| 9761 | mStarts--; |
| 9762 | } |
| 9763 | mRunning = false; |
| 9764 | } |
| 9765 | } |
| 9766 | |
| 9767 | public BatteryStatsImpl getBatteryStats() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9768 | return mBsi; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9769 | } |
| 9770 | |
| 9771 | @Override |
| 9772 | public int getLaunches(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 9773 | int val = mLaunches; |
| 9774 | if (which == STATS_CURRENT) { |
| 9775 | val -= mLoadedLaunches; |
| 9776 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 9777 | val -= mUnpluggedLaunches; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9778 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9779 | return val; |
| 9780 | } |
| 9781 | |
| 9782 | @Override |
| 9783 | public long getStartTime(long now, int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 9784 | long val = getStartTimeToNowLocked(now); |
| 9785 | if (which == STATS_CURRENT) { |
| 9786 | val -= mLoadedStartTime; |
| 9787 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 9788 | val -= mUnpluggedStartTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9789 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9790 | return val; |
| 9791 | } |
| 9792 | |
| 9793 | @Override |
| 9794 | public int getStarts(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 9795 | int val = mStarts; |
| 9796 | if (which == STATS_CURRENT) { |
| 9797 | val -= mLoadedStarts; |
| 9798 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 9799 | val -= mUnpluggedStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9800 | } |
| 9801 | |
| 9802 | return val; |
| 9803 | } |
| 9804 | } |
| 9805 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9806 | final Serv newServiceStatsLocked() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9807 | return new Serv(mBsi); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9808 | } |
| 9809 | } |
| 9810 | |
| 9811 | /** |
| 9812 | * Retrieve the statistics object for a particular process, creating |
| 9813 | * if needed. |
| 9814 | */ |
| 9815 | public Proc getProcessStatsLocked(String name) { |
| 9816 | Proc ps = mProcessStats.get(name); |
| 9817 | if (ps == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9818 | ps = new Proc(mBsi, name); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9819 | mProcessStats.put(name, ps); |
| 9820 | } |
| 9821 | |
| 9822 | return ps; |
| 9823 | } |
| 9824 | |
Andreas Gampe | 3f24e69 | 2018-02-05 13:24:28 -0800 | [diff] [blame] | 9825 | @GuardedBy("mBsi") |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 9826 | public void updateUidProcessStateLocked(int procState) { |
| 9827 | int uidRunningState; |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 9828 | // Make special note of Foreground Services |
| 9829 | final boolean userAwareService = |
| 9830 | (procState == ActivityManager.PROCESS_STATE_FOREGROUND_SERVICE); |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 9831 | uidRunningState = BatteryStats.mapToInternalProcessState(procState); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 9832 | |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 9833 | if (mProcessState == uidRunningState && userAwareService == mInForegroundService) { |
| 9834 | return; |
| 9835 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 9836 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 9837 | final long elapsedRealtimeMs = mBsi.mClocks.elapsedRealtime(); |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 9838 | if (mProcessState != uidRunningState) { |
| 9839 | final long uptimeMs = mBsi.mClocks.uptimeMillis(); |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 9840 | |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 9841 | if (mProcessState != ActivityManager.PROCESS_STATE_NONEXISTENT) { |
| 9842 | mProcessStateTimer[mProcessState].stopRunningLocked(elapsedRealtimeMs); |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 9843 | |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 9844 | if (mBsi.trackPerProcStateCpuTimes()) { |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 9845 | if (mBsi.mPendingUids.size() == 0) { |
Sudheer Shanka | e544d16 | 2017-12-28 17:06:20 -0800 | [diff] [blame] | 9846 | mBsi.mExternalSync.scheduleReadProcStateCpuTimes( |
| 9847 | mBsi.mOnBatteryTimeBase.isRunning(), |
Sudheer Shanka | c20379e | 2018-02-15 00:06:21 -0800 | [diff] [blame] | 9848 | mBsi.mOnBatteryScreenOffTimeBase.isRunning(), |
| 9849 | mBsi.mConstants.PROC_STATE_CPU_TIMES_READ_DELAY_MS); |
| 9850 | mBsi.mNumCpuTimeReads++; |
| 9851 | } else { |
| 9852 | mBsi.mNumBatchedCpuTimeReads++; |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 9853 | } |
| 9854 | if (mBsi.mPendingUids.indexOfKey(mUid) < 0 |
| 9855 | || ArrayUtils.contains(CRITICAL_PROC_STATES, mProcessState)) { |
| 9856 | mBsi.mPendingUids.put(mUid, mProcessState); |
| 9857 | } |
| 9858 | } else { |
| 9859 | mBsi.mPendingUids.clear(); |
| 9860 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 9861 | } |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 9862 | mProcessState = uidRunningState; |
| 9863 | if (uidRunningState != ActivityManager.PROCESS_STATE_NONEXISTENT) { |
| 9864 | if (mProcessStateTimer[uidRunningState] == null) { |
| 9865 | makeProcessState(uidRunningState, null); |
| 9866 | } |
| 9867 | mProcessStateTimer[uidRunningState].startRunningLocked(elapsedRealtimeMs); |
| 9868 | } |
| 9869 | |
| 9870 | updateOnBatteryBgTimeBase(uptimeMs * 1000, elapsedRealtimeMs * 1000); |
| 9871 | updateOnBatteryScreenOffBgTimeBase(uptimeMs * 1000, elapsedRealtimeMs * 1000); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 9872 | } |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 9873 | |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 9874 | if (userAwareService != mInForegroundService) { |
| 9875 | if (userAwareService) { |
| 9876 | noteForegroundServiceResumedLocked(elapsedRealtimeMs); |
| 9877 | } else { |
| 9878 | noteForegroundServicePausedLocked(elapsedRealtimeMs); |
| 9879 | } |
| 9880 | mInForegroundService = userAwareService; |
| 9881 | } |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 9882 | } |
| 9883 | |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 9884 | /** Whether to consider Uid to be in the background for background timebase purposes. */ |
| 9885 | public boolean isInBackground() { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 9886 | // Note that PROCESS_STATE_CACHED and ActivityManager.PROCESS_STATE_NONEXISTENT is |
| 9887 | // also considered to be 'background' for our purposes, because it's not foreground. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 9888 | return mProcessState >= PROCESS_STATE_BACKGROUND; |
| 9889 | } |
| 9890 | |
| 9891 | public boolean updateOnBatteryBgTimeBase(long uptimeUs, long realtimeUs) { |
| 9892 | boolean on = mBsi.mOnBatteryTimeBase.isRunning() && isInBackground(); |
| 9893 | return mOnBatteryBackgroundTimeBase.setRunning(on, uptimeUs, realtimeUs); |
| 9894 | } |
| 9895 | |
| 9896 | public boolean updateOnBatteryScreenOffBgTimeBase(long uptimeUs, long realtimeUs) { |
| 9897 | boolean on = mBsi.mOnBatteryScreenOffTimeBase.isRunning() && isInBackground(); |
| 9898 | return mOnBatteryScreenOffBackgroundTimeBase.setRunning(on, uptimeUs, realtimeUs); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 9899 | } |
| 9900 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 9901 | public SparseArray<? extends Pid> getPidStats() { |
| 9902 | return mPids; |
| 9903 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9904 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 9905 | public Pid getPidStatsLocked(int pid) { |
| 9906 | Pid p = mPids.get(pid); |
| 9907 | if (p == null) { |
| 9908 | p = new Pid(); |
| 9909 | mPids.put(pid, p); |
| 9910 | } |
| 9911 | return p; |
| 9912 | } |
| 9913 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9914 | /** |
| 9915 | * Retrieve the statistics object for a particular service, creating |
| 9916 | * if needed. |
| 9917 | */ |
| 9918 | public Pkg getPackageStatsLocked(String name) { |
| 9919 | Pkg ps = mPackageStats.get(name); |
| 9920 | if (ps == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9921 | ps = new Pkg(mBsi); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9922 | mPackageStats.put(name, ps); |
| 9923 | } |
| 9924 | |
| 9925 | return ps; |
| 9926 | } |
| 9927 | |
| 9928 | /** |
| 9929 | * Retrieve the statistics object for a particular service, creating |
| 9930 | * if needed. |
| 9931 | */ |
| 9932 | public Pkg.Serv getServiceStatsLocked(String pkg, String serv) { |
| 9933 | Pkg ps = getPackageStatsLocked(pkg); |
| 9934 | Pkg.Serv ss = ps.mServiceStats.get(serv); |
| 9935 | if (ss == null) { |
| 9936 | ss = ps.newServiceStatsLocked(); |
| 9937 | ps.mServiceStats.put(serv, ss); |
| 9938 | } |
| 9939 | |
| 9940 | return ss; |
| 9941 | } |
| 9942 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 9943 | public void readSyncSummaryFromParcelLocked(String name, Parcel in) { |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 9944 | DualTimer timer = mSyncStats.instantiateObject(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 9945 | timer.readSummaryFromParcelLocked(in); |
| 9946 | mSyncStats.add(name, timer); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 9947 | } |
| 9948 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 9949 | public void readJobSummaryFromParcelLocked(String name, Parcel in) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 9950 | DualTimer timer = mJobStats.instantiateObject(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 9951 | timer.readSummaryFromParcelLocked(in); |
| 9952 | mJobStats.add(name, timer); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 9953 | } |
| 9954 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 9955 | public void readWakeSummaryFromParcelLocked(String wlName, Parcel in) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9956 | Wakelock wl = new Wakelock(mBsi, this); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 9957 | mWakelockStats.add(wlName, wl); |
| 9958 | if (in.readInt() != 0) { |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 9959 | getWakelockTimerLocked(wl, WAKE_TYPE_FULL).readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9960 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 9961 | if (in.readInt() != 0) { |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 9962 | getWakelockTimerLocked(wl, WAKE_TYPE_PARTIAL).readSummaryFromParcelLocked(in); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 9963 | } |
| 9964 | if (in.readInt() != 0) { |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 9965 | getWakelockTimerLocked(wl, WAKE_TYPE_WINDOW).readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9966 | } |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 9967 | if (in.readInt() != 0) { |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 9968 | getWakelockTimerLocked(wl, WAKE_TYPE_DRAW).readSummaryFromParcelLocked(in); |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 9969 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9970 | } |
| 9971 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 9972 | public DualTimer getSensorTimerLocked(int sensor, boolean create) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9973 | Sensor se = mSensorStats.get(sensor); |
| 9974 | if (se == null) { |
| 9975 | if (!create) { |
| 9976 | return null; |
| 9977 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9978 | se = new Sensor(mBsi, this, sensor); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9979 | mSensorStats.put(sensor, se); |
| 9980 | } |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 9981 | DualTimer t = se.mTimer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9982 | if (t != null) { |
| 9983 | return t; |
| 9984 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9985 | ArrayList<StopwatchTimer> timers = mBsi.mSensorTimers.get(sensor); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9986 | if (timers == null) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 9987 | timers = new ArrayList<StopwatchTimer>(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9988 | mBsi.mSensorTimers.put(sensor, timers); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9989 | } |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 9990 | t = new DualTimer(mBsi.mClocks, this, BatteryStats.SENSOR, timers, |
| 9991 | mBsi.mOnBatteryTimeBase, mOnBatteryBackgroundTimeBase); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9992 | se.mTimer = t; |
| 9993 | return t; |
| 9994 | } |
| 9995 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 9996 | public void noteStartSyncLocked(String name, long elapsedRealtimeMs) { |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 9997 | DualTimer t = mSyncStats.startObject(name); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 9998 | if (t != null) { |
| 9999 | t.startRunningLocked(elapsedRealtimeMs); |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 10000 | StatsLog.write_non_chained(StatsLog.SYNC_STATE_CHANGED, getUid(), null, name, |
| 10001 | StatsLog.SYNC_STATE_CHANGED__STATE__ON); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 10002 | } |
| 10003 | } |
| 10004 | |
| 10005 | public void noteStopSyncLocked(String name, long elapsedRealtimeMs) { |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 10006 | DualTimer t = mSyncStats.stopObject(name); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 10007 | if (t != null) { |
| 10008 | t.stopRunningLocked(elapsedRealtimeMs); |
Bookatz | c1a050a | 2017-10-10 15:49:28 -0700 | [diff] [blame] | 10009 | if (!t.isRunningLocked()) { // only tell statsd if truly stopped |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 10010 | StatsLog.write_non_chained(StatsLog.SYNC_STATE_CHANGED, getUid(), null, name, |
| 10011 | StatsLog.SYNC_STATE_CHANGED__STATE__OFF); |
Bookatz | c1a050a | 2017-10-10 15:49:28 -0700 | [diff] [blame] | 10012 | } |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 10013 | } |
| 10014 | } |
| 10015 | |
| 10016 | public void noteStartJobLocked(String name, long elapsedRealtimeMs) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 10017 | DualTimer t = mJobStats.startObject(name); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 10018 | if (t != null) { |
| 10019 | t.startRunningLocked(elapsedRealtimeMs); |
Yangster-mac | 2f5daec | 2018-01-16 10:23:15 -0800 | [diff] [blame] | 10020 | StatsLog.write_non_chained(StatsLog.SCHEDULED_JOB_STATE_CHANGED, getUid(), null, |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 10021 | name, StatsLog.SCHEDULED_JOB_STATE_CHANGED__STATE__STARTED); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 10022 | } |
| 10023 | } |
| 10024 | |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 10025 | public void noteStopJobLocked(String name, long elapsedRealtimeMs, int stopReason) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 10026 | DualTimer t = mJobStats.stopObject(name); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 10027 | if (t != null) { |
| 10028 | t.stopRunningLocked(elapsedRealtimeMs); |
Bookatz | c1a050a | 2017-10-10 15:49:28 -0700 | [diff] [blame] | 10029 | if (!t.isRunningLocked()) { // only tell statsd if truly stopped |
Yangster-mac | 2f5daec | 2018-01-16 10:23:15 -0800 | [diff] [blame] | 10030 | StatsLog.write_non_chained(StatsLog.SCHEDULED_JOB_STATE_CHANGED, getUid(), null, |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 10031 | name, StatsLog.SCHEDULED_JOB_STATE_CHANGED__STATE__FINISHED); |
Bookatz | c1a050a | 2017-10-10 15:49:28 -0700 | [diff] [blame] | 10032 | } |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 10033 | } |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 10034 | if (mBsi.mOnBatteryTimeBase.isRunning()) { |
| 10035 | SparseIntArray types = mJobCompletions.get(name); |
| 10036 | if (types == null) { |
| 10037 | types = new SparseIntArray(); |
| 10038 | mJobCompletions.put(name, types); |
| 10039 | } |
| 10040 | int last = types.get(stopReason, 0); |
| 10041 | types.put(stopReason, last + 1); |
| 10042 | } |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 10043 | } |
| 10044 | |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 10045 | public StopwatchTimer getWakelockTimerLocked(Wakelock wl, int type) { |
| 10046 | if (wl == null) { |
| 10047 | return null; |
| 10048 | } |
| 10049 | switch (type) { |
| 10050 | case WAKE_TYPE_PARTIAL: { |
| 10051 | DualTimer t = wl.mTimerPartial; |
| 10052 | if (t == null) { |
| 10053 | t = new DualTimer(mBsi.mClocks, this, WAKE_TYPE_PARTIAL, |
| 10054 | mBsi.mPartialTimers, mBsi.mOnBatteryScreenOffTimeBase, |
| 10055 | mOnBatteryScreenOffBackgroundTimeBase); |
| 10056 | wl.mTimerPartial = t; |
| 10057 | } |
| 10058 | return t; |
| 10059 | } |
| 10060 | case WAKE_TYPE_FULL: { |
| 10061 | StopwatchTimer t = wl.mTimerFull; |
| 10062 | if (t == null) { |
| 10063 | t = new StopwatchTimer(mBsi.mClocks, this, WAKE_TYPE_FULL, |
| 10064 | mBsi.mFullTimers, mBsi.mOnBatteryTimeBase); |
| 10065 | wl.mTimerFull = t; |
| 10066 | } |
| 10067 | return t; |
| 10068 | } |
| 10069 | case WAKE_TYPE_WINDOW: { |
| 10070 | StopwatchTimer t = wl.mTimerWindow; |
| 10071 | if (t == null) { |
| 10072 | t = new StopwatchTimer(mBsi.mClocks, this, WAKE_TYPE_WINDOW, |
| 10073 | mBsi.mWindowTimers, mBsi.mOnBatteryTimeBase); |
| 10074 | wl.mTimerWindow = t; |
| 10075 | } |
| 10076 | return t; |
| 10077 | } |
| 10078 | case WAKE_TYPE_DRAW: { |
| 10079 | StopwatchTimer t = wl.mTimerDraw; |
| 10080 | if (t == null) { |
| 10081 | t = new StopwatchTimer(mBsi.mClocks, this, WAKE_TYPE_DRAW, |
| 10082 | mBsi.mDrawTimers, mBsi.mOnBatteryTimeBase); |
| 10083 | wl.mTimerDraw = t; |
| 10084 | } |
| 10085 | return t; |
| 10086 | } |
| 10087 | default: |
| 10088 | throw new IllegalArgumentException("type=" + type); |
| 10089 | } |
| 10090 | } |
| 10091 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10092 | public void noteStartWakeLocked(int pid, String name, int type, long elapsedRealtimeMs) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 10093 | Wakelock wl = mWakelockStats.startObject(name); |
| 10094 | if (wl != null) { |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 10095 | getWakelockTimerLocked(wl, type).startRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10096 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 10097 | if (type == WAKE_TYPE_PARTIAL) { |
| 10098 | createAggregatedPartialWakelockTimerLocked().startRunningLocked(elapsedRealtimeMs); |
| 10099 | if (pid >= 0) { |
| 10100 | Pid p = getPidStatsLocked(pid); |
| 10101 | if (p.mWakeNesting++ == 0) { |
| 10102 | p.mWakeStartMs = elapsedRealtimeMs; |
| 10103 | } |
Dianne Hackborn | b8071d79 | 2010-09-09 16:45:15 -0700 | [diff] [blame] | 10104 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 10105 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10106 | } |
| 10107 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10108 | public void noteStopWakeLocked(int pid, String name, int type, long elapsedRealtimeMs) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 10109 | Wakelock wl = mWakelockStats.stopObject(name); |
| 10110 | if (wl != null) { |
Bookatz | d674624 | 2017-10-24 18:39:35 -0700 | [diff] [blame] | 10111 | StopwatchTimer wlt = getWakelockTimerLocked(wl, type); |
| 10112 | wlt.stopRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10113 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 10114 | if (type == WAKE_TYPE_PARTIAL) { |
| 10115 | if (mAggregatedPartialWakelockTimer != null) { |
| 10116 | mAggregatedPartialWakelockTimer.stopRunningLocked(elapsedRealtimeMs); |
| 10117 | } |
| 10118 | if (pid >= 0) { |
| 10119 | Pid p = mPids.get(pid); |
| 10120 | if (p != null && p.mWakeNesting > 0) { |
| 10121 | if (p.mWakeNesting-- == 1) { |
| 10122 | p.mWakeSumMs += elapsedRealtimeMs - p.mWakeStartMs; |
| 10123 | p.mWakeStartMs = 0; |
| 10124 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 10125 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 10126 | } |
| 10127 | } |
| 10128 | } |
| 10129 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 10130 | public void reportExcessiveCpuLocked(String proc, long overTime, long usedTime) { |
| 10131 | Proc p = getProcessStatsLocked(proc); |
| 10132 | if (p != null) { |
| 10133 | p.addExcessiveCpu(overTime, usedTime); |
| 10134 | } |
| 10135 | } |
| 10136 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10137 | public void noteStartSensor(int sensor, long elapsedRealtimeMs) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 10138 | DualTimer t = getSensorTimerLocked(sensor, /* create= */ true); |
Amith Yamasani | 154d124 | 2017-02-16 10:01:48 -0800 | [diff] [blame] | 10139 | t.startRunningLocked(elapsedRealtimeMs); |
Narayan Kamath | 32684dd | 2018-01-08 17:32:51 +0000 | [diff] [blame] | 10140 | if (sensor != Sensor.GPS) { |
Yangster-mac | 2f5daec | 2018-01-16 10:23:15 -0800 | [diff] [blame] | 10141 | StatsLog.write_non_chained(StatsLog.SENSOR_STATE_CHANGED, getUid(), null, sensor, |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 10142 | StatsLog.SENSOR_STATE_CHANGED__STATE__ON); |
Bookatz | c1a050a | 2017-10-10 15:49:28 -0700 | [diff] [blame] | 10143 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10144 | } |
| 10145 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10146 | public void noteStopSensor(int sensor, long elapsedRealtimeMs) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10147 | // Don't create a timer if one doesn't already exist |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 10148 | DualTimer t = getSensorTimerLocked(sensor, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10149 | if (t != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10150 | t.stopRunningLocked(elapsedRealtimeMs); |
Narayan Kamath | 32684dd | 2018-01-08 17:32:51 +0000 | [diff] [blame] | 10151 | if (sensor != Sensor.GPS) { |
| 10152 | StatsLog.write_non_chained(StatsLog.SENSOR_STATE_CHANGED, getUid(), null, |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 10153 | sensor, StatsLog.SENSOR_STATE_CHANGED__STATE__OFF); |
Bookatz | c1a050a | 2017-10-10 15:49:28 -0700 | [diff] [blame] | 10154 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10155 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10156 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10157 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10158 | public void noteStartGps(long elapsedRealtimeMs) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 10159 | noteStartSensor(Sensor.GPS, elapsedRealtimeMs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10160 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10161 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10162 | public void noteStopGps(long elapsedRealtimeMs) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 10163 | noteStopSensor(Sensor.GPS, elapsedRealtimeMs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10164 | } |
| 10165 | |
| 10166 | public BatteryStatsImpl getBatteryStats() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10167 | return mBsi; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10168 | } |
| 10169 | } |
| 10170 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 10171 | public long[] getCpuFreqs() { |
| 10172 | return mCpuFreqs; |
| 10173 | } |
| 10174 | |
Suprabh Shukla | e6e723d | 2017-06-14 16:14:43 -0700 | [diff] [blame] | 10175 | public BatteryStatsImpl(File systemDir, Handler handler, PlatformIdleStateCallback cb, |
| 10176 | UserInfoProvider userInfoProvider) { |
| 10177 | this(new SystemClocks(), systemDir, handler, cb, userInfoProvider); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 10178 | } |
| 10179 | |
Suprabh Shukla | e6e723d | 2017-06-14 16:14:43 -0700 | [diff] [blame] | 10180 | private BatteryStatsImpl(Clocks clocks, File systemDir, Handler handler, |
| 10181 | PlatformIdleStateCallback cb, |
| 10182 | UserInfoProvider userInfoProvider) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10183 | init(clocks); |
| 10184 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 10185 | if (systemDir != null) { |
| 10186 | mFile = new JournaledFile(new File(systemDir, "batterystats.bin"), |
| 10187 | new File(systemDir, "batterystats.bin.tmp")); |
| 10188 | } else { |
| 10189 | mFile = null; |
| 10190 | } |
| 10191 | mCheckinFile = new AtomicFile(new File(systemDir, "batterystats-checkin.bin")); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10192 | mDailyFile = new AtomicFile(new File(systemDir, "batterystats-daily.xml")); |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 10193 | mHandler = new MyHandler(handler.getLooper()); |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 10194 | mConstants = new Constants(mHandler); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10195 | mStartCount++; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10196 | mScreenOnTimer = new StopwatchTimer(mClocks, null, -1, null, mOnBatteryTimeBase); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 10197 | mScreenDozeTimer = new StopwatchTimer(mClocks, null, -1, null, mOnBatteryTimeBase); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 10198 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10199 | mScreenBrightnessTimer[i] = new StopwatchTimer(mClocks, null, -100-i, null, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10200 | mOnBatteryTimeBase); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 10201 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10202 | mInteractiveTimer = new StopwatchTimer(mClocks, null, -10, null, mOnBatteryTimeBase); |
| 10203 | mPowerSaveModeEnabledTimer = new StopwatchTimer(mClocks, null, -2, null, |
| 10204 | mOnBatteryTimeBase); |
| 10205 | mDeviceIdleModeLightTimer = new StopwatchTimer(mClocks, null, -11, null, |
| 10206 | mOnBatteryTimeBase); |
| 10207 | mDeviceIdleModeFullTimer = new StopwatchTimer(mClocks, null, -14, null, mOnBatteryTimeBase); |
| 10208 | mDeviceLightIdlingTimer = new StopwatchTimer(mClocks, null, -15, null, mOnBatteryTimeBase); |
| 10209 | mDeviceIdlingTimer = new StopwatchTimer(mClocks, null, -12, null, mOnBatteryTimeBase); |
| 10210 | mPhoneOnTimer = new StopwatchTimer(mClocks, null, -3, null, mOnBatteryTimeBase); |
| 10211 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
| 10212 | mPhoneSignalStrengthsTimer[i] = new StopwatchTimer(mClocks, null, -200-i, null, |
| 10213 | mOnBatteryTimeBase); |
| 10214 | } |
| 10215 | mPhoneSignalScanningTimer = new StopwatchTimer(mClocks, null, -200+1, null, |
| 10216 | mOnBatteryTimeBase); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 10217 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10218 | mPhoneDataConnectionsTimer[i] = new StopwatchTimer(mClocks, null, -300-i, null, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10219 | mOnBatteryTimeBase); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 10220 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 10221 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10222 | mNetworkByteActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase); |
| 10223 | mNetworkPacketActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 10224 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 10225 | mWifiActivity = new ControllerActivityCounterImpl(mOnBatteryTimeBase, NUM_WIFI_TX_LEVELS); |
| 10226 | mBluetoothActivity = new ControllerActivityCounterImpl(mOnBatteryTimeBase, |
| 10227 | NUM_BT_TX_LEVELS); |
| 10228 | mModemActivity = new ControllerActivityCounterImpl(mOnBatteryTimeBase, |
| 10229 | ModemActivityInfo.TX_POWER_LEVELS); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10230 | mMobileRadioActiveTimer = new StopwatchTimer(mClocks, null, -400, null, mOnBatteryTimeBase); |
| 10231 | mMobileRadioActivePerAppTimer = new StopwatchTimer(mClocks, null, -401, null, |
| 10232 | mOnBatteryTimeBase); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10233 | mMobileRadioActiveAdjustedTime = new LongSamplingCounter(mOnBatteryTimeBase); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10234 | mMobileRadioActiveUnknownTime = new LongSamplingCounter(mOnBatteryTimeBase); |
| 10235 | mMobileRadioActiveUnknownCount = new LongSamplingCounter(mOnBatteryTimeBase); |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 10236 | mWifiMulticastWakelockTimer = new StopwatchTimer(mClocks, null, |
| 10237 | WIFI_AGGREGATE_MULTICAST_ENABLED, null, mOnBatteryTimeBase); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10238 | mWifiOnTimer = new StopwatchTimer(mClocks, null, -4, null, mOnBatteryTimeBase); |
| 10239 | mGlobalWifiRunningTimer = new StopwatchTimer(mClocks, null, -5, null, mOnBatteryTimeBase); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 10240 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10241 | mWifiStateTimer[i] = new StopwatchTimer(mClocks, null, -600-i, null, |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 10242 | mOnBatteryTimeBase); |
| 10243 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10244 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 10245 | mWifiSupplStateTimer[i] = new StopwatchTimer(mClocks, null, -700-i, null, |
| 10246 | mOnBatteryTimeBase); |
| 10247 | } |
| 10248 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 10249 | mWifiSignalStrengthsTimer[i] = new StopwatchTimer(mClocks, null, -800-i, null, |
| 10250 | mOnBatteryTimeBase); |
| 10251 | } |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 10252 | mWifiActiveTimer = new StopwatchTimer(mClocks, null, -900, null, mOnBatteryTimeBase); |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 10253 | for (int i=0; i< GnssMetrics.NUM_GPS_SIGNAL_QUALITY_LEVELS; i++) { |
| 10254 | mGpsSignalQualityTimer[i] = new StopwatchTimer(mClocks, null, -1000-i, null, |
| 10255 | mOnBatteryTimeBase); |
| 10256 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10257 | mAudioOnTimer = new StopwatchTimer(mClocks, null, -7, null, mOnBatteryTimeBase); |
| 10258 | mVideoOnTimer = new StopwatchTimer(mClocks, null, -8, null, mOnBatteryTimeBase); |
| 10259 | mFlashlightOnTimer = new StopwatchTimer(mClocks, null, -9, null, mOnBatteryTimeBase); |
| 10260 | mCameraOnTimer = new StopwatchTimer(mClocks, null, -13, null, mOnBatteryTimeBase); |
| 10261 | mBluetoothScanTimer = new StopwatchTimer(mClocks, null, -14, null, mOnBatteryTimeBase); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 10262 | mDischargeScreenOffCounter = new LongSamplingCounter(mOnBatteryScreenOffTimeBase); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 10263 | mDischargeScreenDozeCounter = new LongSamplingCounter(mOnBatteryTimeBase); |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 10264 | mDischargeLightDozeCounter = new LongSamplingCounter(mOnBatteryTimeBase); |
| 10265 | mDischargeDeepDozeCounter = new LongSamplingCounter(mOnBatteryTimeBase); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 10266 | mDischargeCounter = new LongSamplingCounter(mOnBatteryTimeBase); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10267 | mOnBattery = mOnBatteryInternal = false; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10268 | long uptime = mClocks.uptimeMillis() * 1000; |
| 10269 | long realtime = mClocks.elapsedRealtime() * 1000; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10270 | initTimes(uptime, realtime); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 10271 | mStartPlatformVersion = mEndPlatformVersion = Build.ID; |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 10272 | mDischargeStartLevel = 0; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10273 | mDischargeUnplugLevel = 0; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 10274 | mDischargePlugLevel = -1; |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 10275 | mDischargeCurrentLevel = 0; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 10276 | mCurrentBatteryLevel = 0; |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 10277 | initDischarge(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10278 | clearHistoryLocked(); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10279 | updateDailyDeadlineLocked(); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 10280 | mPlatformIdleStateCallback = cb; |
Suprabh Shukla | e6e723d | 2017-06-14 16:14:43 -0700 | [diff] [blame] | 10281 | mUserInfoProvider = userInfoProvider; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10282 | } |
| 10283 | |
| 10284 | public BatteryStatsImpl(Parcel p) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10285 | this(new SystemClocks(), p); |
| 10286 | } |
| 10287 | |
| 10288 | public BatteryStatsImpl(Clocks clocks, Parcel p) { |
| 10289 | init(clocks); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10290 | mFile = null; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 10291 | mCheckinFile = null; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10292 | mDailyFile = null; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 10293 | mHandler = null; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 10294 | mExternalSync = null; |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 10295 | mConstants = new Constants(mHandler); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10296 | clearHistoryLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10297 | readFromParcel(p); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 10298 | mPlatformIdleStateCallback = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10299 | } |
| 10300 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 10301 | public void setPowerProfileLocked(PowerProfile profile) { |
| 10302 | mPowerProfile = profile; |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 10303 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 10304 | // We need to initialize the KernelCpuSpeedReaders to read from |
| 10305 | // the first cpu of each core. Once we have the PowerProfile, we have access to this |
| 10306 | // information. |
| 10307 | final int numClusters = mPowerProfile.getNumCpuClusters(); |
| 10308 | mKernelCpuSpeedReaders = new KernelCpuSpeedReader[numClusters]; |
| 10309 | int firstCpuOfCluster = 0; |
| 10310 | for (int i = 0; i < numClusters; i++) { |
| 10311 | final int numSpeedSteps = mPowerProfile.getNumSpeedStepsInCpuCluster(i); |
| 10312 | mKernelCpuSpeedReaders[i] = new KernelCpuSpeedReader(firstCpuOfCluster, |
| 10313 | numSpeedSteps); |
| 10314 | firstCpuOfCluster += mPowerProfile.getNumCoresInCpuCluster(i); |
| 10315 | } |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 10316 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 10317 | if (mEstimatedBatteryCapacity == -1) { |
| 10318 | // Initialize the estimated battery capacity to a known preset one. |
| 10319 | mEstimatedBatteryCapacity = (int) mPowerProfile.getBatteryCapacity(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 10320 | } |
| 10321 | } |
| 10322 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 10323 | public void setCallback(BatteryCallback cb) { |
| 10324 | mCallback = cb; |
| 10325 | } |
| 10326 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 10327 | public void setRadioScanningTimeoutLocked(long timeout) { |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 10328 | if (mPhoneSignalScanningTimer != null) { |
| 10329 | mPhoneSignalScanningTimer.setTimeout(timeout); |
| 10330 | } |
| 10331 | } |
| 10332 | |
Adam Lesinski | b3a1bad | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 10333 | public void setExternalStatsSyncLocked(ExternalStatsSync sync) { |
| 10334 | mExternalSync = sync; |
| 10335 | } |
| 10336 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10337 | public void updateDailyDeadlineLocked() { |
| 10338 | // Get the current time. |
| 10339 | long currentTime = mDailyStartTime = System.currentTimeMillis(); |
| 10340 | Calendar calDeadline = Calendar.getInstance(); |
| 10341 | calDeadline.setTimeInMillis(currentTime); |
| 10342 | |
| 10343 | // Move time up to the next day, ranging from 1am to 3pm. |
| 10344 | calDeadline.set(Calendar.DAY_OF_YEAR, calDeadline.get(Calendar.DAY_OF_YEAR) + 1); |
| 10345 | calDeadline.set(Calendar.MILLISECOND, 0); |
| 10346 | calDeadline.set(Calendar.SECOND, 0); |
| 10347 | calDeadline.set(Calendar.MINUTE, 0); |
| 10348 | calDeadline.set(Calendar.HOUR_OF_DAY, 1); |
| 10349 | mNextMinDailyDeadline = calDeadline.getTimeInMillis(); |
| 10350 | calDeadline.set(Calendar.HOUR_OF_DAY, 3); |
| 10351 | mNextMaxDailyDeadline = calDeadline.getTimeInMillis(); |
| 10352 | } |
| 10353 | |
| 10354 | public void recordDailyStatsIfNeededLocked(boolean settled) { |
| 10355 | long currentTime = System.currentTimeMillis(); |
| 10356 | if (currentTime >= mNextMaxDailyDeadline) { |
| 10357 | recordDailyStatsLocked(); |
| 10358 | } else if (settled && currentTime >= mNextMinDailyDeadline) { |
| 10359 | recordDailyStatsLocked(); |
| 10360 | } else if (currentTime < (mDailyStartTime-(1000*60*60*24))) { |
| 10361 | recordDailyStatsLocked(); |
| 10362 | } |
| 10363 | } |
| 10364 | |
| 10365 | public void recordDailyStatsLocked() { |
| 10366 | DailyItem item = new DailyItem(); |
| 10367 | item.mStartTime = mDailyStartTime; |
| 10368 | item.mEndTime = System.currentTimeMillis(); |
| 10369 | boolean hasData = false; |
| 10370 | if (mDailyDischargeStepTracker.mNumStepDurations > 0) { |
| 10371 | hasData = true; |
| 10372 | item.mDischargeSteps = new LevelStepTracker( |
| 10373 | mDailyDischargeStepTracker.mNumStepDurations, |
| 10374 | mDailyDischargeStepTracker.mStepDurations); |
| 10375 | } |
| 10376 | if (mDailyChargeStepTracker.mNumStepDurations > 0) { |
| 10377 | hasData = true; |
| 10378 | item.mChargeSteps = new LevelStepTracker( |
| 10379 | mDailyChargeStepTracker.mNumStepDurations, |
| 10380 | mDailyChargeStepTracker.mStepDurations); |
| 10381 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 10382 | if (mDailyPackageChanges != null) { |
| 10383 | hasData = true; |
| 10384 | item.mPackageChanges = mDailyPackageChanges; |
| 10385 | mDailyPackageChanges = null; |
| 10386 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10387 | mDailyDischargeStepTracker.init(); |
| 10388 | mDailyChargeStepTracker.init(); |
| 10389 | updateDailyDeadlineLocked(); |
| 10390 | |
| 10391 | if (hasData) { |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 10392 | final long startTime = SystemClock.uptimeMillis(); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10393 | mDailyItems.add(item); |
| 10394 | while (mDailyItems.size() > MAX_DAILY_ITEMS) { |
| 10395 | mDailyItems.remove(0); |
| 10396 | } |
| 10397 | final ByteArrayOutputStream memStream = new ByteArrayOutputStream(); |
| 10398 | try { |
| 10399 | XmlSerializer out = new FastXmlSerializer(); |
Wojciech Staszkiewicz | 9e9e2e7 | 2015-05-08 14:58:46 +0100 | [diff] [blame] | 10400 | out.setOutput(memStream, StandardCharsets.UTF_8.name()); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10401 | writeDailyItemsLocked(out); |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 10402 | final long initialTime = SystemClock.uptimeMillis() - startTime; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10403 | BackgroundThread.getHandler().post(new Runnable() { |
| 10404 | @Override |
| 10405 | public void run() { |
| 10406 | synchronized (mCheckinFile) { |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 10407 | final long startTime2 = SystemClock.uptimeMillis(); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10408 | FileOutputStream stream = null; |
| 10409 | try { |
| 10410 | stream = mDailyFile.startWrite(); |
| 10411 | memStream.writeTo(stream); |
| 10412 | stream.flush(); |
| 10413 | FileUtils.sync(stream); |
| 10414 | stream.close(); |
| 10415 | mDailyFile.finishWrite(stream); |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 10416 | com.android.internal.logging.EventLogTags.writeCommitSysConfigFile( |
| 10417 | "batterystats-daily", |
| 10418 | initialTime + SystemClock.uptimeMillis() - startTime2); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10419 | } catch (IOException e) { |
| 10420 | Slog.w("BatteryStats", |
| 10421 | "Error writing battery daily items", e); |
| 10422 | mDailyFile.failWrite(stream); |
| 10423 | } |
| 10424 | } |
| 10425 | } |
| 10426 | }); |
| 10427 | } catch (IOException e) { |
| 10428 | } |
| 10429 | } |
| 10430 | } |
| 10431 | |
| 10432 | private void writeDailyItemsLocked(XmlSerializer out) throws IOException { |
| 10433 | StringBuilder sb = new StringBuilder(64); |
| 10434 | out.startDocument(null, true); |
| 10435 | out.startTag(null, "daily-items"); |
| 10436 | for (int i=0; i<mDailyItems.size(); i++) { |
| 10437 | final DailyItem dit = mDailyItems.get(i); |
| 10438 | out.startTag(null, "item"); |
| 10439 | out.attribute(null, "start", Long.toString(dit.mStartTime)); |
| 10440 | out.attribute(null, "end", Long.toString(dit.mEndTime)); |
| 10441 | writeDailyLevelSteps(out, "dis", dit.mDischargeSteps, sb); |
| 10442 | writeDailyLevelSteps(out, "chg", dit.mChargeSteps, sb); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 10443 | if (dit.mPackageChanges != null) { |
| 10444 | for (int j=0; j<dit.mPackageChanges.size(); j++) { |
| 10445 | PackageChange pc = dit.mPackageChanges.get(j); |
| 10446 | if (pc.mUpdate) { |
| 10447 | out.startTag(null, "upd"); |
| 10448 | out.attribute(null, "pkg", pc.mPackageName); |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 10449 | out.attribute(null, "ver", Long.toString(pc.mVersionCode)); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 10450 | out.endTag(null, "upd"); |
| 10451 | } else { |
| 10452 | out.startTag(null, "rem"); |
| 10453 | out.attribute(null, "pkg", pc.mPackageName); |
| 10454 | out.endTag(null, "rem"); |
| 10455 | } |
| 10456 | } |
| 10457 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10458 | out.endTag(null, "item"); |
| 10459 | } |
| 10460 | out.endTag(null, "daily-items"); |
| 10461 | out.endDocument(); |
| 10462 | } |
| 10463 | |
| 10464 | private void writeDailyLevelSteps(XmlSerializer out, String tag, LevelStepTracker steps, |
| 10465 | StringBuilder tmpBuilder) throws IOException { |
| 10466 | if (steps != null) { |
| 10467 | out.startTag(null, tag); |
| 10468 | out.attribute(null, "n", Integer.toString(steps.mNumStepDurations)); |
| 10469 | for (int i=0; i<steps.mNumStepDurations; i++) { |
| 10470 | out.startTag(null, "s"); |
| 10471 | tmpBuilder.setLength(0); |
| 10472 | steps.encodeEntryAt(i, tmpBuilder); |
| 10473 | out.attribute(null, "v", tmpBuilder.toString()); |
| 10474 | out.endTag(null, "s"); |
| 10475 | } |
| 10476 | out.endTag(null, tag); |
| 10477 | } |
| 10478 | } |
| 10479 | |
| 10480 | public void readDailyStatsLocked() { |
| 10481 | Slog.d(TAG, "Reading daily items from " + mDailyFile.getBaseFile()); |
| 10482 | mDailyItems.clear(); |
| 10483 | FileInputStream stream; |
| 10484 | try { |
| 10485 | stream = mDailyFile.openRead(); |
| 10486 | } catch (FileNotFoundException e) { |
| 10487 | return; |
| 10488 | } |
| 10489 | try { |
| 10490 | XmlPullParser parser = Xml.newPullParser(); |
Wojciech Staszkiewicz | 9e9e2e7 | 2015-05-08 14:58:46 +0100 | [diff] [blame] | 10491 | parser.setInput(stream, StandardCharsets.UTF_8.name()); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10492 | readDailyItemsLocked(parser); |
| 10493 | } catch (XmlPullParserException e) { |
| 10494 | } finally { |
| 10495 | try { |
| 10496 | stream.close(); |
| 10497 | } catch (IOException e) { |
| 10498 | } |
| 10499 | } |
| 10500 | } |
| 10501 | |
| 10502 | private void readDailyItemsLocked(XmlPullParser parser) { |
| 10503 | try { |
| 10504 | int type; |
| 10505 | while ((type = parser.next()) != XmlPullParser.START_TAG |
| 10506 | && type != XmlPullParser.END_DOCUMENT) { |
| 10507 | ; |
| 10508 | } |
| 10509 | |
| 10510 | if (type != XmlPullParser.START_TAG) { |
| 10511 | throw new IllegalStateException("no start tag found"); |
| 10512 | } |
| 10513 | |
| 10514 | int outerDepth = parser.getDepth(); |
| 10515 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 10516 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 10517 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 10518 | continue; |
| 10519 | } |
| 10520 | |
| 10521 | String tagName = parser.getName(); |
| 10522 | if (tagName.equals("item")) { |
| 10523 | readDailyItemTagLocked(parser); |
| 10524 | } else { |
| 10525 | Slog.w(TAG, "Unknown element under <daily-items>: " |
| 10526 | + parser.getName()); |
| 10527 | XmlUtils.skipCurrentTag(parser); |
| 10528 | } |
| 10529 | } |
| 10530 | |
| 10531 | } catch (IllegalStateException e) { |
| 10532 | Slog.w(TAG, "Failed parsing daily " + e); |
| 10533 | } catch (NullPointerException e) { |
| 10534 | Slog.w(TAG, "Failed parsing daily " + e); |
| 10535 | } catch (NumberFormatException e) { |
| 10536 | Slog.w(TAG, "Failed parsing daily " + e); |
| 10537 | } catch (XmlPullParserException e) { |
| 10538 | Slog.w(TAG, "Failed parsing daily " + e); |
| 10539 | } catch (IOException e) { |
| 10540 | Slog.w(TAG, "Failed parsing daily " + e); |
| 10541 | } catch (IndexOutOfBoundsException e) { |
| 10542 | Slog.w(TAG, "Failed parsing daily " + e); |
| 10543 | } |
| 10544 | } |
| 10545 | |
| 10546 | void readDailyItemTagLocked(XmlPullParser parser) throws NumberFormatException, |
| 10547 | XmlPullParserException, IOException { |
| 10548 | DailyItem dit = new DailyItem(); |
| 10549 | String attr = parser.getAttributeValue(null, "start"); |
| 10550 | if (attr != null) { |
| 10551 | dit.mStartTime = Long.parseLong(attr); |
| 10552 | } |
| 10553 | attr = parser.getAttributeValue(null, "end"); |
| 10554 | if (attr != null) { |
| 10555 | dit.mEndTime = Long.parseLong(attr); |
| 10556 | } |
| 10557 | int outerDepth = parser.getDepth(); |
| 10558 | int type; |
| 10559 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 10560 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 10561 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 10562 | continue; |
| 10563 | } |
| 10564 | |
| 10565 | String tagName = parser.getName(); |
| 10566 | if (tagName.equals("dis")) { |
| 10567 | readDailyItemTagDetailsLocked(parser, dit, false, "dis"); |
| 10568 | } else if (tagName.equals("chg")) { |
| 10569 | readDailyItemTagDetailsLocked(parser, dit, true, "chg"); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 10570 | } else if (tagName.equals("upd")) { |
| 10571 | if (dit.mPackageChanges == null) { |
| 10572 | dit.mPackageChanges = new ArrayList<>(); |
| 10573 | } |
| 10574 | PackageChange pc = new PackageChange(); |
| 10575 | pc.mUpdate = true; |
| 10576 | pc.mPackageName = parser.getAttributeValue(null, "pkg"); |
| 10577 | String verStr = parser.getAttributeValue(null, "ver"); |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 10578 | pc.mVersionCode = verStr != null ? Long.parseLong(verStr) : 0; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 10579 | dit.mPackageChanges.add(pc); |
| 10580 | XmlUtils.skipCurrentTag(parser); |
| 10581 | } else if (tagName.equals("rem")) { |
| 10582 | if (dit.mPackageChanges == null) { |
| 10583 | dit.mPackageChanges = new ArrayList<>(); |
| 10584 | } |
| 10585 | PackageChange pc = new PackageChange(); |
| 10586 | pc.mUpdate = false; |
| 10587 | pc.mPackageName = parser.getAttributeValue(null, "pkg"); |
| 10588 | dit.mPackageChanges.add(pc); |
| 10589 | XmlUtils.skipCurrentTag(parser); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10590 | } else { |
| 10591 | Slog.w(TAG, "Unknown element under <item>: " |
| 10592 | + parser.getName()); |
| 10593 | XmlUtils.skipCurrentTag(parser); |
| 10594 | } |
| 10595 | } |
| 10596 | mDailyItems.add(dit); |
| 10597 | } |
| 10598 | |
| 10599 | void readDailyItemTagDetailsLocked(XmlPullParser parser, DailyItem dit, boolean isCharge, |
| 10600 | String tag) |
| 10601 | throws NumberFormatException, XmlPullParserException, IOException { |
| 10602 | final String numAttr = parser.getAttributeValue(null, "n"); |
| 10603 | if (numAttr == null) { |
| 10604 | Slog.w(TAG, "Missing 'n' attribute at " + parser.getPositionDescription()); |
| 10605 | XmlUtils.skipCurrentTag(parser); |
| 10606 | return; |
| 10607 | } |
| 10608 | final int num = Integer.parseInt(numAttr); |
| 10609 | LevelStepTracker steps = new LevelStepTracker(num); |
| 10610 | if (isCharge) { |
| 10611 | dit.mChargeSteps = steps; |
| 10612 | } else { |
| 10613 | dit.mDischargeSteps = steps; |
| 10614 | } |
| 10615 | int i = 0; |
| 10616 | int outerDepth = parser.getDepth(); |
| 10617 | int type; |
| 10618 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 10619 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 10620 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 10621 | continue; |
| 10622 | } |
| 10623 | |
| 10624 | String tagName = parser.getName(); |
| 10625 | if ("s".equals(tagName)) { |
| 10626 | if (i < num) { |
| 10627 | String valueAttr = parser.getAttributeValue(null, "v"); |
| 10628 | if (valueAttr != null) { |
| 10629 | steps.decodeEntryAt(i, valueAttr); |
| 10630 | i++; |
| 10631 | } |
| 10632 | } |
| 10633 | } else { |
| 10634 | Slog.w(TAG, "Unknown element under <" + tag + ">: " |
| 10635 | + parser.getName()); |
| 10636 | XmlUtils.skipCurrentTag(parser); |
| 10637 | } |
| 10638 | } |
| 10639 | steps.mNumStepDurations = i; |
| 10640 | } |
| 10641 | |
| 10642 | @Override |
| 10643 | public DailyItem getDailyItemLocked(int daysAgo) { |
| 10644 | int index = mDailyItems.size()-1-daysAgo; |
| 10645 | return index >= 0 ? mDailyItems.get(index) : null; |
| 10646 | } |
| 10647 | |
| 10648 | @Override |
| 10649 | public long getCurrentDailyStartTime() { |
| 10650 | return mDailyStartTime; |
| 10651 | } |
| 10652 | |
| 10653 | @Override |
| 10654 | public long getNextMinDailyDeadline() { |
| 10655 | return mNextMinDailyDeadline; |
| 10656 | } |
| 10657 | |
| 10658 | @Override |
| 10659 | public long getNextMaxDailyDeadline() { |
| 10660 | return mNextMaxDailyDeadline; |
| 10661 | } |
| 10662 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10663 | @Override |
| 10664 | public boolean startIteratingOldHistoryLocked() { |
| 10665 | if (DEBUG_HISTORY) Slog.i(TAG, "ITERATING: buff size=" + mHistoryBuffer.dataSize() |
| 10666 | + " pos=" + mHistoryBuffer.dataPosition()); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 10667 | if ((mHistoryIterator = mHistory) == null) { |
| 10668 | return false; |
| 10669 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10670 | mHistoryBuffer.setDataPosition(0); |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 10671 | mHistoryReadTmp.clear(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10672 | mReadOverflow = false; |
| 10673 | mIteratingHistory = true; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 10674 | return true; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 10675 | } |
| 10676 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10677 | @Override |
| 10678 | public boolean getNextOldHistoryLocked(HistoryItem out) { |
| 10679 | boolean end = mHistoryBuffer.dataPosition() >= mHistoryBuffer.dataSize(); |
| 10680 | if (!end) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 10681 | readHistoryDelta(mHistoryBuffer, mHistoryReadTmp); |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 10682 | mReadOverflow |= mHistoryReadTmp.cmd == HistoryItem.CMD_OVERFLOW; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10683 | } |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 10684 | HistoryItem cur = mHistoryIterator; |
| 10685 | if (cur == null) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10686 | if (!mReadOverflow && !end) { |
| 10687 | Slog.w(TAG, "Old history ends before new history!"); |
| 10688 | } |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 10689 | return false; |
| 10690 | } |
| 10691 | out.setTo(cur); |
| 10692 | mHistoryIterator = cur.next; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10693 | if (!mReadOverflow) { |
| 10694 | if (end) { |
| 10695 | Slog.w(TAG, "New history ends before old history!"); |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 10696 | } else if (!out.same(mHistoryReadTmp)) { |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 10697 | PrintWriter pw = new FastPrintWriter(new LogWriter(android.util.Log.WARN, TAG)); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10698 | pw.println("Histories differ!"); |
| 10699 | pw.println("Old history:"); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 10700 | (new HistoryPrinter()).printNextItem(pw, out, 0, false, true); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10701 | pw.println("New history:"); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 10702 | (new HistoryPrinter()).printNextItem(pw, mHistoryReadTmp, 0, false, |
| 10703 | true); |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 10704 | pw.flush(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10705 | } |
| 10706 | } |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 10707 | return true; |
| 10708 | } |
| 10709 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10710 | @Override |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10711 | public void finishIteratingOldHistoryLocked() { |
| 10712 | mIteratingHistory = false; |
| 10713 | mHistoryBuffer.setDataPosition(mHistoryBuffer.dataSize()); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 10714 | mHistoryIterator = null; |
| 10715 | } |
| 10716 | |
| 10717 | public int getHistoryTotalSize() { |
| 10718 | return MAX_HISTORY_BUFFER; |
| 10719 | } |
| 10720 | |
| 10721 | public int getHistoryUsedSize() { |
| 10722 | return mHistoryBuffer.dataSize(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10723 | } |
| 10724 | |
| 10725 | @Override |
| 10726 | public boolean startIteratingHistoryLocked() { |
| 10727 | if (DEBUG_HISTORY) Slog.i(TAG, "ITERATING: buff size=" + mHistoryBuffer.dataSize() |
| 10728 | + " pos=" + mHistoryBuffer.dataPosition()); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 10729 | if (mHistoryBuffer.dataSize() <= 0) { |
| 10730 | return false; |
| 10731 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10732 | mHistoryBuffer.setDataPosition(0); |
| 10733 | mReadOverflow = false; |
| 10734 | mIteratingHistory = true; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 10735 | mReadHistoryStrings = new String[mHistoryTagPool.size()]; |
| 10736 | mReadHistoryUids = new int[mHistoryTagPool.size()]; |
| 10737 | mReadHistoryChars = 0; |
| 10738 | for (HashMap.Entry<HistoryTag, Integer> ent : mHistoryTagPool.entrySet()) { |
| 10739 | final HistoryTag tag = ent.getKey(); |
| 10740 | final int idx = ent.getValue(); |
| 10741 | mReadHistoryStrings[idx] = tag.string; |
| 10742 | mReadHistoryUids[idx] = tag.uid; |
| 10743 | mReadHistoryChars += tag.string.length() + 1; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 10744 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 10745 | return true; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10746 | } |
| 10747 | |
| 10748 | @Override |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 10749 | public int getHistoryStringPoolSize() { |
| 10750 | return mReadHistoryStrings.length; |
| 10751 | } |
| 10752 | |
| 10753 | @Override |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 10754 | public int getHistoryStringPoolBytes() { |
| 10755 | // Each entry is a fixed 12 bytes: 4 for index, 4 for uid, 4 for string size |
| 10756 | // Each string character is 2 bytes. |
| 10757 | return (mReadHistoryStrings.length * 12) + (mReadHistoryChars * 2); |
| 10758 | } |
| 10759 | |
| 10760 | @Override |
| 10761 | public String getHistoryTagPoolString(int index) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 10762 | return mReadHistoryStrings[index]; |
| 10763 | } |
| 10764 | |
| 10765 | @Override |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 10766 | public int getHistoryTagPoolUid(int index) { |
| 10767 | return mReadHistoryUids[index]; |
| 10768 | } |
| 10769 | |
| 10770 | @Override |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10771 | public boolean getNextHistoryLocked(HistoryItem out) { |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 10772 | final int pos = mHistoryBuffer.dataPosition(); |
| 10773 | if (pos == 0) { |
| 10774 | out.clear(); |
| 10775 | } |
| 10776 | boolean end = pos >= mHistoryBuffer.dataSize(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10777 | if (end) { |
| 10778 | return false; |
| 10779 | } |
| 10780 | |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 10781 | final long lastRealtime = out.time; |
| 10782 | final long lastWalltime = out.currentTime; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 10783 | readHistoryDelta(mHistoryBuffer, out); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 10784 | if (out.cmd != HistoryItem.CMD_CURRENT_TIME |
| 10785 | && out.cmd != HistoryItem.CMD_RESET && lastWalltime != 0) { |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 10786 | out.currentTime = lastWalltime + (out.time - lastRealtime); |
| 10787 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10788 | return true; |
| 10789 | } |
| 10790 | |
| 10791 | @Override |
| 10792 | public void finishIteratingHistoryLocked() { |
| 10793 | mIteratingHistory = false; |
| 10794 | mHistoryBuffer.setDataPosition(mHistoryBuffer.dataSize()); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 10795 | mReadHistoryStrings = null; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 10796 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10797 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 10798 | @Override |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 10799 | public long getHistoryBaseTime() { |
| 10800 | return mHistoryBaseTime; |
| 10801 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10802 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 10803 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10804 | public int getStartCount() { |
| 10805 | return mStartCount; |
| 10806 | } |
| 10807 | |
| 10808 | public boolean isOnBattery() { |
| 10809 | return mOnBattery; |
| 10810 | } |
| 10811 | |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 10812 | public boolean isCharging() { |
| 10813 | return mCharging; |
| 10814 | } |
| 10815 | |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 10816 | public boolean isScreenOn(int state) { |
Chris Phoenix | 10a4a64 | 2017-09-25 13:21:00 -0700 | [diff] [blame] | 10817 | return state == Display.STATE_ON || state == Display.STATE_VR |
| 10818 | || state == Display.STATE_ON_SUSPEND; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 10819 | } |
| 10820 | |
| 10821 | public boolean isScreenOff(int state) { |
| 10822 | return state == Display.STATE_OFF; |
| 10823 | } |
| 10824 | |
| 10825 | public boolean isScreenDoze(int state) { |
| 10826 | return state == Display.STATE_DOZE || state == Display.STATE_DOZE_SUSPEND; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 10827 | } |
| 10828 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10829 | void initTimes(long uptime, long realtime) { |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 10830 | mStartClockTime = System.currentTimeMillis(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10831 | mOnBatteryTimeBase.init(uptime, realtime); |
| 10832 | mOnBatteryScreenOffTimeBase.init(uptime, realtime); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 10833 | mRealtime = 0; |
| 10834 | mUptime = 0; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10835 | mRealtimeStart = realtime; |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 10836 | mUptimeStart = uptime; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10837 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10838 | |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 10839 | void initDischarge() { |
| 10840 | mLowDischargeAmountSinceCharge = 0; |
| 10841 | mHighDischargeAmountSinceCharge = 0; |
| 10842 | mDischargeAmountScreenOn = 0; |
| 10843 | mDischargeAmountScreenOnSinceCharge = 0; |
| 10844 | mDischargeAmountScreenOff = 0; |
| 10845 | mDischargeAmountScreenOffSinceCharge = 0; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 10846 | mDischargeAmountScreenDoze = 0; |
| 10847 | mDischargeAmountScreenDozeSinceCharge = 0; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10848 | mDischargeStepTracker.init(); |
| 10849 | mChargeStepTracker.init(); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 10850 | mDischargeScreenOffCounter.reset(false); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 10851 | mDischargeScreenDozeCounter.reset(false); |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 10852 | mDischargeLightDozeCounter.reset(false); |
| 10853 | mDischargeDeepDozeCounter.reset(false); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 10854 | mDischargeCounter.reset(false); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 10855 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 10856 | |
| 10857 | public void resetAllStatsCmdLocked() { |
| 10858 | resetAllStatsLocked(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10859 | final long mSecUptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 10860 | long uptime = mSecUptime * 1000; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10861 | long mSecRealtime = mClocks.elapsedRealtime(); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 10862 | long realtime = mSecRealtime * 1000; |
| 10863 | mDischargeStartLevel = mHistoryCur.batteryLevel; |
| 10864 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 10865 | addHistoryRecordLocked(mSecRealtime, mSecUptime); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 10866 | mDischargeCurrentLevel = mDischargeUnplugLevel = mDischargePlugLevel |
| 10867 | = mCurrentBatteryLevel = mHistoryCur.batteryLevel; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10868 | mOnBatteryTimeBase.reset(uptime, realtime); |
| 10869 | mOnBatteryScreenOffTimeBase.reset(uptime, realtime); |
| 10870 | if ((mHistoryCur.states&HistoryItem.STATE_BATTERY_PLUGGED_FLAG) == 0) { |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 10871 | if (isScreenOn(mScreenState)) { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 10872 | mDischargeScreenOnUnplugLevel = mHistoryCur.batteryLevel; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 10873 | mDischargeScreenDozeUnplugLevel = 0; |
| 10874 | mDischargeScreenOffUnplugLevel = 0; |
| 10875 | } else if (isScreenDoze(mScreenState)) { |
| 10876 | mDischargeScreenOnUnplugLevel = 0; |
| 10877 | mDischargeScreenDozeUnplugLevel = mHistoryCur.batteryLevel; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 10878 | mDischargeScreenOffUnplugLevel = 0; |
| 10879 | } else { |
| 10880 | mDischargeScreenOnUnplugLevel = 0; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 10881 | mDischargeScreenDozeUnplugLevel = 0; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 10882 | mDischargeScreenOffUnplugLevel = mHistoryCur.batteryLevel; |
| 10883 | } |
| 10884 | mDischargeAmountScreenOn = 0; |
| 10885 | mDischargeAmountScreenOff = 0; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 10886 | mDischargeAmountScreenDoze = 0; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 10887 | } |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 10888 | initActiveHistoryEventsLocked(mSecRealtime, mSecUptime); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 10889 | } |
| 10890 | |
| 10891 | private void resetAllStatsLocked() { |
Adam Lesinski | 8ce3694 | 2016-05-26 16:05:35 -0700 | [diff] [blame] | 10892 | final long uptimeMillis = mClocks.uptimeMillis(); |
| 10893 | final long elapsedRealtimeMillis = mClocks.elapsedRealtime(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10894 | mStartCount = 0; |
Adam Lesinski | 8ce3694 | 2016-05-26 16:05:35 -0700 | [diff] [blame] | 10895 | initTimes(uptimeMillis * 1000, elapsedRealtimeMillis * 1000); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10896 | mScreenOnTimer.reset(false); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 10897 | mScreenDozeTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10898 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10899 | mScreenBrightnessTimer[i].reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10900 | } |
Adam Lesinski | 1a76a62 | 2016-06-22 10:28:47 -0700 | [diff] [blame] | 10901 | |
| 10902 | if (mPowerProfile != null) { |
| 10903 | mEstimatedBatteryCapacity = (int) mPowerProfile.getBatteryCapacity(); |
| 10904 | } else { |
| 10905 | mEstimatedBatteryCapacity = -1; |
| 10906 | } |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 10907 | mMinLearnedBatteryCapacity = -1; |
| 10908 | mMaxLearnedBatteryCapacity = -1; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 10909 | mInteractiveTimer.reset(false); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 10910 | mPowerSaveModeEnabledTimer.reset(false); |
Adam Lesinski | 8ce3694 | 2016-05-26 16:05:35 -0700 | [diff] [blame] | 10911 | mLastIdleTimeStart = elapsedRealtimeMillis; |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 10912 | mLongestLightIdleTime = 0; |
| 10913 | mLongestFullIdleTime = 0; |
| 10914 | mDeviceIdleModeLightTimer.reset(false); |
| 10915 | mDeviceIdleModeFullTimer.reset(false); |
| 10916 | mDeviceLightIdlingTimer.reset(false); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 10917 | mDeviceIdlingTimer.reset(false); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10918 | mPhoneOnTimer.reset(false); |
| 10919 | mAudioOnTimer.reset(false); |
| 10920 | mVideoOnTimer.reset(false); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 10921 | mFlashlightOnTimer.reset(false); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 10922 | mCameraOnTimer.reset(false); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 10923 | mBluetoothScanTimer.reset(false); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 10924 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10925 | mPhoneSignalStrengthsTimer[i].reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10926 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10927 | mPhoneSignalScanningTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10928 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10929 | mPhoneDataConnectionsTimer[i].reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10930 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 10931 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 10932 | mNetworkByteActivityCounters[i].reset(false); |
| 10933 | mNetworkPacketActivityCounters[i].reset(false); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 10934 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10935 | mMobileRadioActiveTimer.reset(false); |
| 10936 | mMobileRadioActivePerAppTimer.reset(false); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10937 | mMobileRadioActiveAdjustedTime.reset(false); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 10938 | mMobileRadioActiveUnknownTime.reset(false); |
| 10939 | mMobileRadioActiveUnknownCount.reset(false); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10940 | mWifiOnTimer.reset(false); |
| 10941 | mGlobalWifiRunningTimer.reset(false); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 10942 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10943 | mWifiStateTimer[i].reset(false); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 10944 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 10945 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 10946 | mWifiSupplStateTimer[i].reset(false); |
| 10947 | } |
| 10948 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 10949 | mWifiSignalStrengthsTimer[i].reset(false); |
| 10950 | } |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 10951 | mWifiMulticastWakelockTimer.reset(false); |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 10952 | mWifiActiveTimer.reset(false); |
| 10953 | mWifiActivity.reset(false); |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 10954 | for (int i=0; i< GnssMetrics.NUM_GPS_SIGNAL_QUALITY_LEVELS; i++) { |
| 10955 | mGpsSignalQualityTimer[i].reset(false); |
| 10956 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 10957 | mBluetoothActivity.reset(false); |
| 10958 | mModemActivity.reset(false); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 10959 | mNumConnectivityChange = mLoadedNumConnectivityChange = mUnpluggedNumConnectivityChange = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10960 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10961 | for (int i=0; i<mUidStats.size(); i++) { |
Bookatz | 993a0be | 2017-07-21 09:03:23 -0700 | [diff] [blame] | 10962 | if (mUidStats.valueAt(i).reset(uptimeMillis * 1000, elapsedRealtimeMillis * 1000)) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10963 | mUidStats.remove(mUidStats.keyAt(i)); |
| 10964 | i--; |
| 10965 | } |
| 10966 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10967 | |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 10968 | if (mRpmStats.size() > 0) { |
| 10969 | for (SamplingTimer timer : mRpmStats.values()) { |
| 10970 | mOnBatteryTimeBase.remove(timer); |
| 10971 | } |
| 10972 | mRpmStats.clear(); |
| 10973 | } |
| 10974 | if (mScreenOffRpmStats.size() > 0) { |
| 10975 | for (SamplingTimer timer : mScreenOffRpmStats.values()) { |
| 10976 | mOnBatteryScreenOffTimeBase.remove(timer); |
| 10977 | } |
| 10978 | mScreenOffRpmStats.clear(); |
| 10979 | } |
| 10980 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10981 | if (mKernelWakelockStats.size() > 0) { |
| 10982 | for (SamplingTimer timer : mKernelWakelockStats.values()) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10983 | mOnBatteryScreenOffTimeBase.remove(timer); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10984 | } |
| 10985 | mKernelWakelockStats.clear(); |
| 10986 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10987 | |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 10988 | if (mKernelMemoryStats.size() > 0) { |
| 10989 | for (int i = 0; i < mKernelMemoryStats.size(); i++) { |
| 10990 | mOnBatteryTimeBase.remove(mKernelMemoryStats.valueAt(i)); |
| 10991 | } |
| 10992 | mKernelMemoryStats.clear(); |
| 10993 | } |
| 10994 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10995 | if (mWakeupReasonStats.size() > 0) { |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 10996 | for (SamplingTimer timer : mWakeupReasonStats.values()) { |
| 10997 | mOnBatteryTimeBase.remove(timer); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10998 | } |
| 10999 | mWakeupReasonStats.clear(); |
| 11000 | } |
| 11001 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 11002 | mLastHistoryStepDetails = null; |
| 11003 | mLastStepCpuUserTime = mLastStepCpuSystemTime = 0; |
| 11004 | mCurStepCpuUserTime = mCurStepCpuSystemTime = 0; |
| 11005 | mLastStepCpuUserTime = mCurStepCpuUserTime = 0; |
| 11006 | mLastStepCpuSystemTime = mCurStepCpuSystemTime = 0; |
| 11007 | mLastStepStatUserTime = mCurStepStatUserTime = 0; |
| 11008 | mLastStepStatSystemTime = mCurStepStatSystemTime = 0; |
| 11009 | mLastStepStatIOWaitTime = mCurStepStatIOWaitTime = 0; |
| 11010 | mLastStepStatIrqTime = mCurStepStatIrqTime = 0; |
| 11011 | mLastStepStatSoftIrqTime = mCurStepStatSoftIrqTime = 0; |
| 11012 | mLastStepStatIdleTime = mCurStepStatIdleTime = 0; |
| 11013 | |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 11014 | initDischarge(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 11015 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 11016 | clearHistoryLocked(); |
| 11017 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 11018 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 11019 | private void initActiveHistoryEventsLocked(long elapsedRealtimeMs, long uptimeMs) { |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 11020 | for (int i=0; i<HistoryItem.EVENT_COUNT; i++) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 11021 | if (!mRecordAllHistory && i == HistoryItem.EVENT_PROC) { |
| 11022 | // Not recording process starts/stops. |
| 11023 | continue; |
| 11024 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 11025 | HashMap<String, SparseIntArray> active = mActiveEvents.getStateForEvent(i); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 11026 | if (active == null) { |
| 11027 | continue; |
| 11028 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 11029 | for (HashMap.Entry<String, SparseIntArray> ent : active.entrySet()) { |
| 11030 | SparseIntArray uids = ent.getValue(); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 11031 | for (int j=0; j<uids.size(); j++) { |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 11032 | addHistoryEventLocked(elapsedRealtimeMs, uptimeMs, i, ent.getKey(), |
| 11033 | uids.keyAt(j)); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 11034 | } |
| 11035 | } |
| 11036 | } |
| 11037 | } |
| 11038 | |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 11039 | void updateDischargeScreenLevelsLocked(int oldState, int newState) { |
| 11040 | updateOldDischargeScreenLevelLocked(oldState); |
| 11041 | updateNewDischargeScreenLevelLocked(newState); |
| 11042 | } |
| 11043 | |
| 11044 | private void updateOldDischargeScreenLevelLocked(int state) { |
| 11045 | if (isScreenOn(state)) { |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 11046 | int diff = mDischargeScreenOnUnplugLevel - mDischargeCurrentLevel; |
| 11047 | if (diff > 0) { |
| 11048 | mDischargeAmountScreenOn += diff; |
| 11049 | mDischargeAmountScreenOnSinceCharge += diff; |
| 11050 | } |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 11051 | } else if (isScreenDoze(state)) { |
| 11052 | int diff = mDischargeScreenDozeUnplugLevel - mDischargeCurrentLevel; |
| 11053 | if (diff > 0) { |
| 11054 | mDischargeAmountScreenDoze += diff; |
| 11055 | mDischargeAmountScreenDozeSinceCharge += diff; |
| 11056 | } |
| 11057 | } else if (isScreenOff(state)){ |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 11058 | int diff = mDischargeScreenOffUnplugLevel - mDischargeCurrentLevel; |
| 11059 | if (diff > 0) { |
| 11060 | mDischargeAmountScreenOff += diff; |
| 11061 | mDischargeAmountScreenOffSinceCharge += diff; |
| 11062 | } |
| 11063 | } |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 11064 | } |
| 11065 | |
| 11066 | private void updateNewDischargeScreenLevelLocked(int state) { |
| 11067 | if (isScreenOn(state)) { |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 11068 | mDischargeScreenOnUnplugLevel = mDischargeCurrentLevel; |
| 11069 | mDischargeScreenOffUnplugLevel = 0; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 11070 | mDischargeScreenDozeUnplugLevel = 0; |
| 11071 | } else if (isScreenDoze(state)){ |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 11072 | mDischargeScreenOnUnplugLevel = 0; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 11073 | mDischargeScreenDozeUnplugLevel = mDischargeCurrentLevel; |
| 11074 | mDischargeScreenOffUnplugLevel = 0; |
| 11075 | } else if (isScreenOff(state)) { |
| 11076 | mDischargeScreenOnUnplugLevel = 0; |
| 11077 | mDischargeScreenDozeUnplugLevel = 0; |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 11078 | mDischargeScreenOffUnplugLevel = mDischargeCurrentLevel; |
| 11079 | } |
| 11080 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11081 | |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 11082 | public void pullPendingStateUpdatesLocked() { |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 11083 | if (mOnBatteryInternal) { |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 11084 | updateDischargeScreenLevelsLocked(mScreenState, mScreenState); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 11085 | } |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 11086 | } |
| 11087 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11088 | private final NetworkStatsFactory mNetworkStatsFactory = new NetworkStatsFactory(); |
| 11089 | private final Pools.Pool<NetworkStats> mNetworkStatsPool = new Pools.SynchronizedPool<>(6); |
| 11090 | |
| 11091 | private final Object mWifiNetworkLock = new Object(); |
| 11092 | |
| 11093 | @GuardedBy("mWifiNetworkLock") |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11094 | private String[] mWifiIfaces = EmptyArray.STRING; |
| 11095 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11096 | @GuardedBy("mWifiNetworkLock") |
| 11097 | private NetworkStats mLastWifiNetworkStats = new NetworkStats(0, -1); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11098 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11099 | private final Object mModemNetworkLock = new Object(); |
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 String[] mModemIfaces = EmptyArray.STRING; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11103 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11104 | @GuardedBy("mModemNetworkLock") |
| 11105 | private NetworkStats mLastModemNetworkStats = new NetworkStats(0, -1); |
| 11106 | |
| 11107 | private NetworkStats readNetworkStatsLocked(String[] ifaces) { |
| 11108 | try { |
| 11109 | if (!ArrayUtils.isEmpty(ifaces)) { |
| 11110 | return mNetworkStatsFactory.readNetworkStatsDetail(NetworkStats.UID_ALL, ifaces, |
| 11111 | NetworkStats.TAG_NONE, mNetworkStatsPool.acquire()); |
| 11112 | } |
| 11113 | } catch (IOException e) { |
| 11114 | 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] | 11115 | } |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11116 | return null; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11117 | } |
| 11118 | |
Chenjie Yu | 8908339 | 2018-01-11 14:53:31 -0800 | [diff] [blame] | 11119 | /** |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11120 | * Distribute WiFi energy info and network traffic to apps. |
| 11121 | * @param info The energy information from the WiFi controller. |
| 11122 | */ |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11123 | public void updateWifiState(@Nullable final WifiActivityEnergyInfo info) { |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 11124 | if (DEBUG_ENERGY) { |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11125 | Slog.d(TAG, "Updating wifi stats: " + Arrays.toString(mWifiIfaces)); |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 11126 | } |
| 11127 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11128 | // 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] | 11129 | NetworkStats delta = null; |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11130 | synchronized (mWifiNetworkLock) { |
| 11131 | final NetworkStats latestStats = readNetworkStatsLocked(mWifiIfaces); |
| 11132 | if (latestStats != null) { |
| 11133 | delta = NetworkStats.subtract(latestStats, mLastWifiNetworkStats, null, null, |
| 11134 | mNetworkStatsPool.acquire()); |
| 11135 | mNetworkStatsPool.release(mLastWifiNetworkStats); |
| 11136 | mLastWifiNetworkStats = latestStats; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 11137 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11138 | } |
| 11139 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11140 | synchronized (this) { |
| 11141 | if (!mOnBatteryInternal) { |
| 11142 | if (delta != null) { |
| 11143 | mNetworkStatsPool.release(delta); |
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 | return; |
| 11146 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11147 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11148 | final long elapsedRealtimeMs = mClocks.elapsedRealtime(); |
| 11149 | SparseLongArray rxPackets = new SparseLongArray(); |
| 11150 | SparseLongArray txPackets = new SparseLongArray(); |
| 11151 | long totalTxPackets = 0; |
| 11152 | long totalRxPackets = 0; |
| 11153 | if (delta != null) { |
| 11154 | NetworkStats.Entry entry = new NetworkStats.Entry(); |
| 11155 | final int size = delta.size(); |
| 11156 | for (int i = 0; i < size; i++) { |
| 11157 | entry = delta.getValues(i, entry); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11158 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11159 | if (DEBUG_ENERGY) { |
| 11160 | Slog.d(TAG, "Wifi uid " + entry.uid + ": delta rx=" + entry.rxBytes |
| 11161 | + " tx=" + entry.txBytes + " rxPackets=" + entry.rxPackets |
| 11162 | + " txPackets=" + entry.txPackets); |
| 11163 | } |
| 11164 | |
| 11165 | if (entry.rxBytes == 0 && entry.txBytes == 0) { |
| 11166 | // Skip the lookup below since there is no work to do. |
| 11167 | continue; |
| 11168 | } |
| 11169 | |
| 11170 | final Uid u = getUidStatsLocked(mapUid(entry.uid)); |
| 11171 | if (entry.rxBytes != 0) { |
| 11172 | u.noteNetworkActivityLocked(NETWORK_WIFI_RX_DATA, entry.rxBytes, |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 11173 | entry.rxPackets); |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11174 | if (entry.set == NetworkStats.SET_DEFAULT) { // Background transfers |
| 11175 | u.noteNetworkActivityLocked(NETWORK_WIFI_BG_RX_DATA, entry.rxBytes, |
| 11176 | entry.rxPackets); |
| 11177 | } |
| 11178 | mNetworkByteActivityCounters[NETWORK_WIFI_RX_DATA].addCountLocked( |
| 11179 | entry.rxBytes); |
| 11180 | mNetworkPacketActivityCounters[NETWORK_WIFI_RX_DATA].addCountLocked( |
| 11181 | entry.rxPackets); |
| 11182 | |
| 11183 | rxPackets.put(u.getUid(), entry.rxPackets); |
| 11184 | |
| 11185 | // Sum the total number of packets so that the Rx Power can |
| 11186 | // be evenly distributed amongst the apps. |
| 11187 | totalRxPackets += entry.rxPackets; |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 11188 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 11189 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11190 | if (entry.txBytes != 0) { |
| 11191 | u.noteNetworkActivityLocked(NETWORK_WIFI_TX_DATA, entry.txBytes, |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 11192 | entry.txPackets); |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11193 | if (entry.set == NetworkStats.SET_DEFAULT) { // Background transfers |
| 11194 | u.noteNetworkActivityLocked(NETWORK_WIFI_BG_TX_DATA, entry.txBytes, |
| 11195 | entry.txPackets); |
| 11196 | } |
| 11197 | mNetworkByteActivityCounters[NETWORK_WIFI_TX_DATA].addCountLocked( |
| 11198 | entry.txBytes); |
| 11199 | mNetworkPacketActivityCounters[NETWORK_WIFI_TX_DATA].addCountLocked( |
| 11200 | entry.txPackets); |
| 11201 | |
| 11202 | txPackets.put(u.getUid(), entry.txPackets); |
| 11203 | |
| 11204 | // Sum the total number of packets so that the Tx Power can |
| 11205 | // be evenly distributed amongst the apps. |
| 11206 | totalTxPackets += entry.txPackets; |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 11207 | } |
Adam Lesinski | ba88e68 | 2015-12-08 12:06:55 -0800 | [diff] [blame] | 11208 | } |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11209 | mNetworkStatsPool.release(delta); |
| 11210 | delta = null; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 11211 | } |
| 11212 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11213 | if (info != null) { |
| 11214 | mHasWifiReporting = true; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 11215 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11216 | // Measured in mAms |
| 11217 | final long txTimeMs = info.getControllerTxTimeMillis(); |
| 11218 | final long rxTimeMs = info.getControllerRxTimeMillis(); |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 11219 | final long scanTimeMs = info.getControllerScanTimeMillis(); |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11220 | final long idleTimeMs = info.getControllerIdleTimeMillis(); |
| 11221 | final long totalTimeMs = txTimeMs + rxTimeMs + idleTimeMs; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 11222 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11223 | long leftOverRxTimeMs = rxTimeMs; |
| 11224 | long leftOverTxTimeMs = txTimeMs; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 11225 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 11226 | if (DEBUG_ENERGY) { |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11227 | Slog.d(TAG, "------ BEGIN WiFi power blaming ------"); |
| 11228 | Slog.d(TAG, " Tx Time: " + txTimeMs + " ms"); |
| 11229 | Slog.d(TAG, " Rx Time: " + rxTimeMs + " ms"); |
| 11230 | Slog.d(TAG, " Idle Time: " + idleTimeMs + " ms"); |
| 11231 | Slog.d(TAG, " Total Time: " + totalTimeMs + " ms"); |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 11232 | Slog.d(TAG, " Scan Time: " + scanTimeMs + " ms"); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 11233 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 11234 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11235 | long totalWifiLockTimeMs = 0; |
| 11236 | long totalScanTimeMs = 0; |
| 11237 | |
| 11238 | // On the first pass, collect some totals so that we can normalize power |
| 11239 | // calculations if we need to. |
| 11240 | final int uidStatsSize = mUidStats.size(); |
| 11241 | for (int i = 0; i < uidStatsSize; i++) { |
| 11242 | final Uid uid = mUidStats.valueAt(i); |
| 11243 | |
| 11244 | // Sum the total scan power for all apps. |
| 11245 | totalScanTimeMs += uid.mWifiScanTimer.getTimeSinceMarkLocked( |
| 11246 | elapsedRealtimeMs * 1000) / 1000; |
| 11247 | |
| 11248 | // Sum the total time holding wifi lock for all apps. |
| 11249 | totalWifiLockTimeMs += uid.mFullWifiLockTimer.getTimeSinceMarkLocked( |
| 11250 | elapsedRealtimeMs * 1000) / 1000; |
| 11251 | } |
| 11252 | |
| 11253 | if (DEBUG_ENERGY && totalScanTimeMs > rxTimeMs) { |
| 11254 | Slog.d(TAG, |
| 11255 | " !Estimated scan time > Actual rx time (" + totalScanTimeMs + " ms > " |
| 11256 | + rxTimeMs + " ms). Normalizing scan time."); |
| 11257 | } |
| 11258 | if (DEBUG_ENERGY && totalScanTimeMs > txTimeMs) { |
| 11259 | Slog.d(TAG, |
| 11260 | " !Estimated scan time > Actual tx time (" + totalScanTimeMs + " ms > " |
| 11261 | + txTimeMs + " ms). Normalizing scan time."); |
| 11262 | } |
| 11263 | |
| 11264 | // Actually assign and distribute power usage to apps. |
| 11265 | for (int i = 0; i < uidStatsSize; i++) { |
| 11266 | final Uid uid = mUidStats.valueAt(i); |
| 11267 | |
| 11268 | long scanTimeSinceMarkMs = uid.mWifiScanTimer.getTimeSinceMarkLocked( |
| 11269 | elapsedRealtimeMs * 1000) / 1000; |
| 11270 | if (scanTimeSinceMarkMs > 0) { |
| 11271 | // Set the new mark so that next time we get new data since this point. |
| 11272 | uid.mWifiScanTimer.setMark(elapsedRealtimeMs); |
| 11273 | |
| 11274 | long scanRxTimeSinceMarkMs = scanTimeSinceMarkMs; |
| 11275 | long scanTxTimeSinceMarkMs = scanTimeSinceMarkMs; |
| 11276 | |
| 11277 | // Our total scan time is more than the reported Tx/Rx time. |
| 11278 | // This is possible because the cost of a scan is approximate. |
| 11279 | // Let's normalize the result so that we evenly blame each app |
| 11280 | // scanning. |
| 11281 | // |
| 11282 | // This means that we may have apps that transmitted/received packets not be |
| 11283 | // blamed for this, but this is fine as scans are relatively more expensive. |
| 11284 | if (totalScanTimeMs > rxTimeMs) { |
| 11285 | scanRxTimeSinceMarkMs = (rxTimeMs * scanRxTimeSinceMarkMs) / |
| 11286 | totalScanTimeMs; |
| 11287 | } |
| 11288 | if (totalScanTimeMs > txTimeMs) { |
| 11289 | scanTxTimeSinceMarkMs = (txTimeMs * scanTxTimeSinceMarkMs) / |
| 11290 | totalScanTimeMs; |
| 11291 | } |
| 11292 | |
| 11293 | if (DEBUG_ENERGY) { |
| 11294 | Slog.d(TAG, " ScanTime for UID " + uid.getUid() + ": Rx:" |
| 11295 | + scanRxTimeSinceMarkMs + " ms Tx:" |
| 11296 | + scanTxTimeSinceMarkMs + " ms)"); |
| 11297 | } |
| 11298 | |
| 11299 | ControllerActivityCounterImpl activityCounter = |
| 11300 | uid.getOrCreateWifiControllerActivityLocked(); |
| 11301 | activityCounter.getRxTimeCounter().addCountLocked(scanRxTimeSinceMarkMs); |
| 11302 | activityCounter.getTxTimeCounters()[0].addCountLocked( |
| 11303 | scanTxTimeSinceMarkMs); |
| 11304 | leftOverRxTimeMs -= scanRxTimeSinceMarkMs; |
| 11305 | leftOverTxTimeMs -= scanTxTimeSinceMarkMs; |
| 11306 | } |
| 11307 | |
| 11308 | // Distribute evenly the power consumed while Idle to each app holding a WiFi |
| 11309 | // lock. |
| 11310 | final long wifiLockTimeSinceMarkMs = |
| 11311 | uid.mFullWifiLockTimer.getTimeSinceMarkLocked( |
| 11312 | elapsedRealtimeMs * 1000) / 1000; |
| 11313 | if (wifiLockTimeSinceMarkMs > 0) { |
| 11314 | // Set the new mark so that next time we get new data since this point. |
| 11315 | uid.mFullWifiLockTimer.setMark(elapsedRealtimeMs); |
| 11316 | |
| 11317 | final long myIdleTimeMs = (wifiLockTimeSinceMarkMs * idleTimeMs) |
| 11318 | / totalWifiLockTimeMs; |
| 11319 | if (DEBUG_ENERGY) { |
| 11320 | Slog.d(TAG, " IdleTime for UID " + uid.getUid() + ": " |
| 11321 | + myIdleTimeMs + " ms"); |
| 11322 | } |
| 11323 | uid.getOrCreateWifiControllerActivityLocked().getIdleTimeCounter() |
| 11324 | .addCountLocked(myIdleTimeMs); |
| 11325 | } |
| 11326 | } |
| 11327 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 11328 | if (DEBUG_ENERGY) { |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11329 | Slog.d(TAG, " New RxPower: " + leftOverRxTimeMs + " ms"); |
| 11330 | Slog.d(TAG, " New TxPower: " + leftOverTxTimeMs + " ms"); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 11331 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 11332 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11333 | // Distribute the remaining Tx power appropriately between all apps that transmitted |
| 11334 | // packets. |
| 11335 | for (int i = 0; i < txPackets.size(); i++) { |
| 11336 | final Uid uid = getUidStatsLocked(txPackets.keyAt(i)); |
| 11337 | final long myTxTimeMs = (txPackets.valueAt(i) * leftOverTxTimeMs) |
| 11338 | / totalTxPackets; |
| 11339 | if (DEBUG_ENERGY) { |
| 11340 | Slog.d(TAG, " TxTime for UID " + uid.getUid() + ": " + myTxTimeMs + " ms"); |
| 11341 | } |
| 11342 | uid.getOrCreateWifiControllerActivityLocked().getTxTimeCounters()[0] |
| 11343 | .addCountLocked(myTxTimeMs); |
| 11344 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 11345 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11346 | // Distribute the remaining Rx power appropriately between all apps that received |
| 11347 | // packets. |
| 11348 | for (int i = 0; i < rxPackets.size(); i++) { |
| 11349 | final Uid uid = getUidStatsLocked(rxPackets.keyAt(i)); |
| 11350 | final long myRxTimeMs = (rxPackets.valueAt(i) * leftOverRxTimeMs) |
| 11351 | / totalRxPackets; |
| 11352 | if (DEBUG_ENERGY) { |
| 11353 | Slog.d(TAG, " RxTime for UID " + uid.getUid() + ": " + myRxTimeMs + " ms"); |
| 11354 | } |
| 11355 | uid.getOrCreateWifiControllerActivityLocked().getRxTimeCounter() |
| 11356 | .addCountLocked(myRxTimeMs); |
| 11357 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 11358 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11359 | // Any left over power use will be picked up by the WiFi category in BatteryStatsHelper. |
| 11360 | |
| 11361 | |
| 11362 | // Update WiFi controller stats. |
| 11363 | mWifiActivity.getRxTimeCounter().addCountLocked(info.getControllerRxTimeMillis()); |
| 11364 | mWifiActivity.getTxTimeCounters()[0].addCountLocked( |
| 11365 | info.getControllerTxTimeMillis()); |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 11366 | mWifiActivity.getScanTimeCounter().addCountLocked( |
| 11367 | info.getControllerScanTimeMillis()); |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11368 | mWifiActivity.getIdleTimeCounter().addCountLocked( |
| 11369 | info.getControllerIdleTimeMillis()); |
| 11370 | |
| 11371 | // POWER_WIFI_CONTROLLER_OPERATING_VOLTAGE is measured in mV, so convert to V. |
| 11372 | final double opVolt = mPowerProfile.getAveragePower( |
| 11373 | PowerProfile.POWER_WIFI_CONTROLLER_OPERATING_VOLTAGE) / 1000.0; |
| 11374 | if (opVolt != 0) { |
| 11375 | // We store the power drain as mAms. |
| 11376 | mWifiActivity.getPowerCounter().addCountLocked( |
| 11377 | (long) (info.getControllerEnergyUsed() / opVolt)); |
| 11378 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 11379 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11380 | } |
| 11381 | } |
| 11382 | |
Chenjie Yu | 8908339 | 2018-01-11 14:53:31 -0800 | [diff] [blame] | 11383 | private ModemActivityInfo mLastModemActivityInfo = |
| 11384 | new ModemActivityInfo(0, 0, 0, new int[0], 0, 0); |
| 11385 | |
Chenjie Yu | a54e54d | 2018-02-14 20:12:52 -0800 | [diff] [blame] | 11386 | private ModemActivityInfo getDeltaModemActivityInfo(ModemActivityInfo activityInfo) { |
| 11387 | if (activityInfo == null) { |
| 11388 | return null; |
| 11389 | } |
| 11390 | int[] txTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS]; |
| 11391 | for (int i = 0; i < ModemActivityInfo.TX_POWER_LEVELS; i++) { |
| 11392 | txTimeMs[i] = activityInfo.getTxTimeMillis()[i] |
| 11393 | - mLastModemActivityInfo.getTxTimeMillis()[i]; |
| 11394 | } |
| 11395 | ModemActivityInfo deltaInfo = new ModemActivityInfo(activityInfo.getTimestamp(), |
| 11396 | activityInfo.getSleepTimeMillis() - mLastModemActivityInfo.getSleepTimeMillis(), |
| 11397 | activityInfo.getIdleTimeMillis() - mLastModemActivityInfo.getIdleTimeMillis(), |
| 11398 | txTimeMs, |
| 11399 | activityInfo.getRxTimeMillis() - mLastModemActivityInfo.getRxTimeMillis(), |
| 11400 | activityInfo.getEnergyUsed() - mLastModemActivityInfo.getEnergyUsed()); |
| 11401 | mLastModemActivityInfo = activityInfo; |
| 11402 | return deltaInfo; |
| 11403 | } |
| 11404 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11405 | /** |
| 11406 | * Distribute Cell radio energy info and network traffic to apps. |
| 11407 | */ |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11408 | public void updateMobileRadioState(@Nullable final ModemActivityInfo activityInfo) { |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 11409 | if (DEBUG_ENERGY) { |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 11410 | Slog.d(TAG, "Updating mobile radio stats with " + activityInfo); |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 11411 | } |
Chenjie Yu | a54e54d | 2018-02-14 20:12:52 -0800 | [diff] [blame] | 11412 | ModemActivityInfo deltaInfo = getDeltaModemActivityInfo(activityInfo); |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 11413 | |
Siddharth Ray | f5e796a | 2018-01-22 18:18:17 -0800 | [diff] [blame] | 11414 | // Add modem tx power to history. |
Chenjie Yu | a54e54d | 2018-02-14 20:12:52 -0800 | [diff] [blame] | 11415 | addModemTxPowerToHistory(deltaInfo); |
Siddharth Ray | f5e796a | 2018-01-22 18:18:17 -0800 | [diff] [blame] | 11416 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11417 | // 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] | 11418 | NetworkStats delta = null; |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11419 | synchronized (mModemNetworkLock) { |
| 11420 | final NetworkStats latestStats = readNetworkStatsLocked(mModemIfaces); |
| 11421 | if (latestStats != null) { |
| 11422 | delta = NetworkStats.subtract(latestStats, mLastModemNetworkStats, null, null, |
| 11423 | mNetworkStatsPool.acquire()); |
| 11424 | mNetworkStatsPool.release(mLastModemNetworkStats); |
| 11425 | mLastModemNetworkStats = latestStats; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 11426 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11427 | } |
| 11428 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11429 | synchronized (this) { |
| 11430 | if (!mOnBatteryInternal) { |
| 11431 | if (delta != null) { |
| 11432 | mNetworkStatsPool.release(delta); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 11433 | } |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11434 | return; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 11435 | } |
| 11436 | |
Chenjie Yu | a54e54d | 2018-02-14 20:12:52 -0800 | [diff] [blame] | 11437 | if (deltaInfo != null) { |
Siddharth Ray | 2038af8 | 2018-01-17 17:40:26 -0800 | [diff] [blame] | 11438 | mHasModemReporting = true; |
| 11439 | mModemActivity.getIdleTimeCounter().addCountLocked( |
Chenjie Yu | a54e54d | 2018-02-14 20:12:52 -0800 | [diff] [blame] | 11440 | deltaInfo.getIdleTimeMillis()); |
| 11441 | mModemActivity.getRxTimeCounter().addCountLocked(deltaInfo.getRxTimeMillis()); |
Siddharth Ray | 2038af8 | 2018-01-17 17:40:26 -0800 | [diff] [blame] | 11442 | for (int lvl = 0; lvl < ModemActivityInfo.TX_POWER_LEVELS; lvl++) { |
| 11443 | mModemActivity.getTxTimeCounters()[lvl] |
Chenjie Yu | a54e54d | 2018-02-14 20:12:52 -0800 | [diff] [blame] | 11444 | .addCountLocked(deltaInfo.getTxTimeMillis()[lvl]); |
Siddharth Ray | 2038af8 | 2018-01-17 17:40:26 -0800 | [diff] [blame] | 11445 | } |
| 11446 | |
| 11447 | // POWER_MODEM_CONTROLLER_OPERATING_VOLTAGE is measured in mV, so convert to V. |
| 11448 | final double opVolt = mPowerProfile.getAveragePower( |
| 11449 | PowerProfile.POWER_MODEM_CONTROLLER_OPERATING_VOLTAGE) / 1000.0; |
| 11450 | if (opVolt != 0) { |
| 11451 | double energyUsed = |
Chenjie Yu | a54e54d | 2018-02-14 20:12:52 -0800 | [diff] [blame] | 11452 | deltaInfo.getSleepTimeMillis() * |
Siddharth Ray | 2038af8 | 2018-01-17 17:40:26 -0800 | [diff] [blame] | 11453 | mPowerProfile.getAveragePower(PowerProfile.POWER_MODEM_CONTROLLER_SLEEP) |
Chenjie Yu | a54e54d | 2018-02-14 20:12:52 -0800 | [diff] [blame] | 11454 | + deltaInfo.getIdleTimeMillis() * |
Siddharth Ray | 2038af8 | 2018-01-17 17:40:26 -0800 | [diff] [blame] | 11455 | mPowerProfile.getAveragePower(PowerProfile.POWER_MODEM_CONTROLLER_IDLE) |
Chenjie Yu | a54e54d | 2018-02-14 20:12:52 -0800 | [diff] [blame] | 11456 | + deltaInfo.getRxTimeMillis() * |
Siddharth Ray | 2038af8 | 2018-01-17 17:40:26 -0800 | [diff] [blame] | 11457 | mPowerProfile.getAveragePower(PowerProfile.POWER_MODEM_CONTROLLER_RX); |
Chenjie Yu | a54e54d | 2018-02-14 20:12:52 -0800 | [diff] [blame] | 11458 | int[] txTimeMs = deltaInfo.getTxTimeMillis(); |
Chenjie Yu | 8908339 | 2018-01-11 14:53:31 -0800 | [diff] [blame] | 11459 | for (int i = 0; i < Math.min(txTimeMs.length, |
Chenjie Yu | a54e54d | 2018-02-14 20:12:52 -0800 | [diff] [blame] | 11460 | SignalStrength.NUM_SIGNAL_STRENGTH_BINS); i++) { |
Chenjie Yu | 8908339 | 2018-01-11 14:53:31 -0800 | [diff] [blame] | 11461 | energyUsed += txTimeMs[i] * mPowerProfile.getAveragePower( |
Chenjie Yu | a54e54d | 2018-02-14 20:12:52 -0800 | [diff] [blame] | 11462 | PowerProfile.POWER_MODEM_CONTROLLER_TX, i); |
Siddharth Ray | 2038af8 | 2018-01-17 17:40:26 -0800 | [diff] [blame] | 11463 | } |
| 11464 | |
| 11465 | // We store the power drain as mAms. |
| 11466 | mModemActivity.getPowerCounter().addCountLocked((long) energyUsed); |
| 11467 | } |
| 11468 | } |
| 11469 | |
Adam Lesinski | b3a1bad | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11470 | final long elapsedRealtimeMs = mClocks.elapsedRealtime(); |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11471 | long radioTime = mMobileRadioActivePerAppTimer.getTimeSinceMarkLocked( |
| 11472 | elapsedRealtimeMs * 1000); |
| 11473 | mMobileRadioActivePerAppTimer.setMark(elapsedRealtimeMs); |
| 11474 | |
| 11475 | long totalRxPackets = 0; |
| 11476 | long totalTxPackets = 0; |
| 11477 | if (delta != null) { |
| 11478 | NetworkStats.Entry entry = new NetworkStats.Entry(); |
| 11479 | final int size = delta.size(); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 11480 | for (int i = 0; i < size; i++) { |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11481 | entry = delta.getValues(i, entry); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 11482 | if (entry.rxPackets == 0 && entry.txPackets == 0) { |
| 11483 | continue; |
| 11484 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11485 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11486 | if (DEBUG_ENERGY) { |
| 11487 | Slog.d(TAG, "Mobile uid " + entry.uid + ": delta rx=" + entry.rxBytes |
| 11488 | + " tx=" + entry.txBytes + " rxPackets=" + entry.rxPackets |
| 11489 | + " txPackets=" + entry.txPackets); |
| 11490 | } |
| 11491 | |
| 11492 | totalRxPackets += entry.rxPackets; |
| 11493 | totalTxPackets += entry.txPackets; |
| 11494 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 11495 | final Uid u = getUidStatsLocked(mapUid(entry.uid)); |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11496 | u.noteNetworkActivityLocked(NETWORK_MOBILE_RX_DATA, entry.rxBytes, |
| 11497 | entry.rxPackets); |
| 11498 | u.noteNetworkActivityLocked(NETWORK_MOBILE_TX_DATA, entry.txBytes, |
| 11499 | entry.txPackets); |
| 11500 | if (entry.set == NetworkStats.SET_DEFAULT) { // Background transfers |
| 11501 | u.noteNetworkActivityLocked(NETWORK_MOBILE_BG_RX_DATA, |
| 11502 | entry.rxBytes, entry.rxPackets); |
| 11503 | u.noteNetworkActivityLocked(NETWORK_MOBILE_BG_TX_DATA, |
| 11504 | entry.txBytes, entry.txPackets); |
| 11505 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 11506 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11507 | mNetworkByteActivityCounters[NETWORK_MOBILE_RX_DATA].addCountLocked( |
| 11508 | entry.rxBytes); |
| 11509 | mNetworkByteActivityCounters[NETWORK_MOBILE_TX_DATA].addCountLocked( |
| 11510 | entry.txBytes); |
| 11511 | mNetworkPacketActivityCounters[NETWORK_MOBILE_RX_DATA].addCountLocked( |
| 11512 | entry.rxPackets); |
| 11513 | mNetworkPacketActivityCounters[NETWORK_MOBILE_TX_DATA].addCountLocked( |
| 11514 | entry.txPackets); |
| 11515 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 11516 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11517 | // Now distribute proportional blame to the apps that did networking. |
| 11518 | long totalPackets = totalRxPackets + totalTxPackets; |
| 11519 | if (totalPackets > 0) { |
| 11520 | for (int i = 0; i < size; i++) { |
| 11521 | entry = delta.getValues(i, entry); |
| 11522 | if (entry.rxPackets == 0 && entry.txPackets == 0) { |
| 11523 | continue; |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 11524 | } |
| 11525 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11526 | final Uid u = getUidStatsLocked(mapUid(entry.uid)); |
| 11527 | |
| 11528 | // Distribute total radio active time in to this app. |
| 11529 | final long appPackets = entry.rxPackets + entry.txPackets; |
| 11530 | final long appRadioTime = (radioTime * appPackets) / totalPackets; |
| 11531 | u.noteMobileRadioActiveTimeLocked(appRadioTime); |
| 11532 | |
| 11533 | // Remove this app from the totals, so that we don't lose any time |
| 11534 | // due to rounding. |
| 11535 | radioTime -= appRadioTime; |
| 11536 | totalPackets -= appPackets; |
| 11537 | |
Chenjie Yu | a54e54d | 2018-02-14 20:12:52 -0800 | [diff] [blame] | 11538 | if (deltaInfo != null) { |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11539 | ControllerActivityCounterImpl activityCounter = |
| 11540 | u.getOrCreateModemControllerActivityLocked(); |
| 11541 | if (totalRxPackets > 0 && entry.rxPackets > 0) { |
Chenjie Yu | a54e54d | 2018-02-14 20:12:52 -0800 | [diff] [blame] | 11542 | final long rxMs = (entry.rxPackets * deltaInfo.getRxTimeMillis()) |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11543 | / totalRxPackets; |
| 11544 | activityCounter.getRxTimeCounter().addCountLocked(rxMs); |
| 11545 | } |
| 11546 | |
| 11547 | if (totalTxPackets > 0 && entry.txPackets > 0) { |
| 11548 | for (int lvl = 0; lvl < ModemActivityInfo.TX_POWER_LEVELS; lvl++) { |
| 11549 | long txMs = |
Chenjie Yu | a54e54d | 2018-02-14 20:12:52 -0800 | [diff] [blame] | 11550 | entry.txPackets * deltaInfo.getTxTimeMillis()[lvl]; |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11551 | txMs /= totalTxPackets; |
| 11552 | activityCounter.getTxTimeCounters()[lvl].addCountLocked(txMs); |
| 11553 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 11554 | } |
| 11555 | } |
| 11556 | } |
| 11557 | } |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11558 | |
| 11559 | if (radioTime > 0) { |
| 11560 | // Whoops, there is some radio time we can't blame on an app! |
| 11561 | mMobileRadioActiveUnknownTime.addCountLocked(radioTime); |
| 11562 | mMobileRadioActiveUnknownCount.addCountLocked(1); |
| 11563 | } |
| 11564 | |
| 11565 | mNetworkStatsPool.release(delta); |
| 11566 | delta = null; |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 11567 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11568 | } |
| 11569 | } |
| 11570 | |
Chenjie Yu | 8908339 | 2018-01-11 14:53:31 -0800 | [diff] [blame] | 11571 | // Cache last value for comparison. |
| 11572 | private BluetoothActivityEnergyInfo mLastBluetoothActivityEnergyInfo = |
| 11573 | new BluetoothActivityEnergyInfo(0, 0, 0, 0, 0, 0); |
| 11574 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11575 | /** |
Siddharth Ray | f5e796a | 2018-01-22 18:18:17 -0800 | [diff] [blame] | 11576 | * Add modem tx power to history |
| 11577 | * Device is said to be in high cellular transmit power when it has spent most of the transmit |
| 11578 | * time at the highest power level. |
| 11579 | * @param activityInfo |
| 11580 | */ |
| 11581 | private void addModemTxPowerToHistory(final ModemActivityInfo activityInfo) { |
| 11582 | if (activityInfo == null) { |
| 11583 | return; |
| 11584 | } |
| 11585 | int[] txTimeMs = activityInfo.getTxTimeMillis(); |
| 11586 | if (txTimeMs == null || txTimeMs.length != ModemActivityInfo.TX_POWER_LEVELS) { |
| 11587 | return; |
| 11588 | } |
| 11589 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 11590 | final long uptime = mClocks.uptimeMillis(); |
| 11591 | int levelMaxTimeSpent = 0; |
| 11592 | for (int i = 1; i < txTimeMs.length; i++) { |
| 11593 | if (txTimeMs[i] > txTimeMs[levelMaxTimeSpent]) { |
| 11594 | levelMaxTimeSpent = i; |
| 11595 | } |
| 11596 | } |
| 11597 | if (levelMaxTimeSpent == ModemActivityInfo.TX_POWER_LEVELS - 1) { |
| 11598 | if (!mIsCellularTxPowerHigh) { |
| 11599 | mHistoryCur.states2 |= HistoryItem.STATE2_CELLULAR_HIGH_TX_POWER_FLAG; |
| 11600 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 11601 | mIsCellularTxPowerHigh = true; |
| 11602 | } |
| 11603 | return; |
| 11604 | } |
| 11605 | if (mIsCellularTxPowerHigh) { |
| 11606 | mHistoryCur.states2 &= ~HistoryItem.STATE2_CELLULAR_HIGH_TX_POWER_FLAG; |
| 11607 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 11608 | mIsCellularTxPowerHigh = false; |
| 11609 | } |
| 11610 | return; |
| 11611 | } |
| 11612 | |
| 11613 | /** |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11614 | * Distribute Bluetooth energy info and network traffic to apps. |
| 11615 | * @param info The energy information from the bluetooth controller. |
| 11616 | */ |
| 11617 | public void updateBluetoothStateLocked(@Nullable final BluetoothActivityEnergyInfo info) { |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 11618 | if (DEBUG_ENERGY) { |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 11619 | Slog.d(TAG, "Updating bluetooth stats: " + info); |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 11620 | } |
| 11621 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 11622 | if (info == null || !mOnBatteryInternal) { |
| 11623 | return; |
| 11624 | } |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 11625 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 11626 | mHasBluetoothReporting = true; |
| 11627 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 11628 | final long elapsedRealtimeMs = mClocks.elapsedRealtime(); |
Chenjie Yu | 8908339 | 2018-01-11 14:53:31 -0800 | [diff] [blame] | 11629 | final long rxTimeMs = info.getControllerRxTimeMillis() - |
| 11630 | mLastBluetoothActivityEnergyInfo.getControllerRxTimeMillis(); |
| 11631 | final long txTimeMs = info.getControllerTxTimeMillis() - |
| 11632 | mLastBluetoothActivityEnergyInfo.getControllerTxTimeMillis(); |
| 11633 | final long idleTimeMs = info.getControllerIdleTimeMillis() - |
| 11634 | mLastBluetoothActivityEnergyInfo.getControllerIdleTimeMillis(); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 11635 | if (DEBUG_ENERGY) { |
| 11636 | Slog.d(TAG, "------ BEGIN BLE power blaming ------"); |
| 11637 | Slog.d(TAG, " Tx Time: " + txTimeMs + " ms"); |
| 11638 | Slog.d(TAG, " Rx Time: " + rxTimeMs + " ms"); |
Chenjie Yu | 8908339 | 2018-01-11 14:53:31 -0800 | [diff] [blame] | 11639 | Slog.d(TAG, " Idle Time: " + idleTimeMs + " ms"); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 11640 | } |
| 11641 | |
| 11642 | long totalScanTimeMs = 0; |
| 11643 | |
| 11644 | final int uidCount = mUidStats.size(); |
| 11645 | for (int i = 0; i < uidCount; i++) { |
| 11646 | final Uid u = mUidStats.valueAt(i); |
| 11647 | if (u.mBluetoothScanTimer == null) { |
| 11648 | continue; |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 11649 | } |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 11650 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 11651 | totalScanTimeMs += u.mBluetoothScanTimer.getTimeSinceMarkLocked( |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 11652 | elapsedRealtimeMs * 1000) / 1000; |
| 11653 | } |
| 11654 | |
| 11655 | final boolean normalizeScanRxTime = (totalScanTimeMs > rxTimeMs); |
| 11656 | final boolean normalizeScanTxTime = (totalScanTimeMs > txTimeMs); |
| 11657 | |
| 11658 | if (DEBUG_ENERGY) { |
| 11659 | Slog.d(TAG, "Normalizing scan power for RX=" + normalizeScanRxTime |
| 11660 | + " TX=" + normalizeScanTxTime); |
| 11661 | } |
| 11662 | |
| 11663 | long leftOverRxTimeMs = rxTimeMs; |
| 11664 | long leftOverTxTimeMs = txTimeMs; |
| 11665 | |
| 11666 | for (int i = 0; i < uidCount; i++) { |
| 11667 | final Uid u = mUidStats.valueAt(i); |
| 11668 | if (u.mBluetoothScanTimer == null) { |
| 11669 | continue; |
| 11670 | } |
| 11671 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 11672 | long scanTimeSinceMarkMs = u.mBluetoothScanTimer.getTimeSinceMarkLocked( |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 11673 | elapsedRealtimeMs * 1000) / 1000; |
| 11674 | if (scanTimeSinceMarkMs > 0) { |
| 11675 | // Set the new mark so that next time we get new data since this point. |
| 11676 | u.mBluetoothScanTimer.setMark(elapsedRealtimeMs); |
| 11677 | |
| 11678 | long scanTimeRxSinceMarkMs = scanTimeSinceMarkMs; |
| 11679 | long scanTimeTxSinceMarkMs = scanTimeSinceMarkMs; |
| 11680 | |
| 11681 | if (normalizeScanRxTime) { |
| 11682 | // Scan time is longer than the total rx time in the controller, |
| 11683 | // so distribute the scan time proportionately. This means regular traffic |
| 11684 | // will not blamed, but scans are more expensive anyways. |
| 11685 | scanTimeRxSinceMarkMs = (rxTimeMs * scanTimeRxSinceMarkMs) / totalScanTimeMs; |
| 11686 | } |
| 11687 | |
| 11688 | if (normalizeScanTxTime) { |
| 11689 | // Scan time is longer than the total tx time in the controller, |
| 11690 | // so distribute the scan time proportionately. This means regular traffic |
| 11691 | // will not blamed, but scans are more expensive anyways. |
| 11692 | scanTimeTxSinceMarkMs = (txTimeMs * scanTimeTxSinceMarkMs) / totalScanTimeMs; |
| 11693 | } |
| 11694 | |
| 11695 | final ControllerActivityCounterImpl counter = |
| 11696 | u.getOrCreateBluetoothControllerActivityLocked(); |
| 11697 | counter.getRxTimeCounter().addCountLocked(scanTimeRxSinceMarkMs); |
| 11698 | counter.getTxTimeCounters()[0].addCountLocked(scanTimeTxSinceMarkMs); |
| 11699 | |
| 11700 | leftOverRxTimeMs -= scanTimeRxSinceMarkMs; |
| 11701 | leftOverTxTimeMs -= scanTimeTxSinceMarkMs; |
| 11702 | } |
| 11703 | } |
| 11704 | |
| 11705 | if (DEBUG_ENERGY) { |
| 11706 | Slog.d(TAG, "Left over time for traffic RX=" + leftOverRxTimeMs |
| 11707 | + " TX=" + leftOverTxTimeMs); |
| 11708 | } |
| 11709 | |
| 11710 | // |
| 11711 | // Now distribute blame to apps that did bluetooth traffic. |
| 11712 | // |
| 11713 | |
| 11714 | long totalTxBytes = 0; |
| 11715 | long totalRxBytes = 0; |
| 11716 | |
| 11717 | final UidTraffic[] uidTraffic = info.getUidTraffic(); |
Chenjie Yu | 8908339 | 2018-01-11 14:53:31 -0800 | [diff] [blame] | 11718 | final UidTraffic[] lastUidTraffic = mLastBluetoothActivityEnergyInfo.getUidTraffic(); |
| 11719 | final ArrayList<UidTraffic> deltaTraffic = new ArrayList<>(); |
| 11720 | int m = 0, n = 0; |
| 11721 | for (; m < uidTraffic.length && n < lastUidTraffic.length; m++) { |
| 11722 | final UidTraffic traffic = uidTraffic[m]; |
| 11723 | final UidTraffic lastTraffic = lastUidTraffic[n]; |
| 11724 | if (traffic.getUid() == lastTraffic.getUid()) { |
| 11725 | deltaTraffic.add(new UidTraffic(traffic.getUid(), |
| 11726 | traffic.getRxBytes() - lastTraffic.getRxBytes(), |
| 11727 | traffic.getTxBytes() - lastTraffic.getTxBytes())); |
| 11728 | n++; |
| 11729 | } |
| 11730 | } |
| 11731 | for (; m < uidTraffic.length; m ++) { |
| 11732 | deltaTraffic.add(uidTraffic[m]); |
| 11733 | } |
| 11734 | |
| 11735 | for (int i = 0, j = 0; i < deltaTraffic.size(); i++) { |
| 11736 | final UidTraffic traffic = deltaTraffic.get(i); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 11737 | |
| 11738 | // Add to the global counters. |
| 11739 | mNetworkByteActivityCounters[NETWORK_BT_RX_DATA].addCountLocked( |
| 11740 | traffic.getRxBytes()); |
| 11741 | mNetworkByteActivityCounters[NETWORK_BT_TX_DATA].addCountLocked( |
| 11742 | traffic.getTxBytes()); |
| 11743 | |
| 11744 | // Add to the UID counters. |
| 11745 | final Uid u = getUidStatsLocked(mapUid(traffic.getUid())); |
| 11746 | u.noteNetworkActivityLocked(NETWORK_BT_RX_DATA, traffic.getRxBytes(), 0); |
| 11747 | u.noteNetworkActivityLocked(NETWORK_BT_TX_DATA, traffic.getTxBytes(), 0); |
| 11748 | |
| 11749 | // Calculate the total traffic. |
| 11750 | totalTxBytes += traffic.getTxBytes(); |
| 11751 | totalRxBytes += traffic.getRxBytes(); |
| 11752 | } |
| 11753 | |
| 11754 | if ((totalTxBytes != 0 || totalRxBytes != 0) && |
| 11755 | (leftOverRxTimeMs != 0 || leftOverTxTimeMs != 0)) { |
Chenjie Yu | 8908339 | 2018-01-11 14:53:31 -0800 | [diff] [blame] | 11756 | for (int i = 0; i < deltaTraffic.size(); i++) { |
| 11757 | final UidTraffic traffic = deltaTraffic.get(i); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 11758 | |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 11759 | final Uid u = getUidStatsLocked(mapUid(traffic.getUid())); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 11760 | final ControllerActivityCounterImpl counter = |
| 11761 | u.getOrCreateBluetoothControllerActivityLocked(); |
| 11762 | |
| 11763 | if (totalRxBytes > 0 && traffic.getRxBytes() > 0) { |
| 11764 | final long timeRxMs = (leftOverRxTimeMs * traffic.getRxBytes()) / totalRxBytes; |
| 11765 | |
| 11766 | if (DEBUG_ENERGY) { |
| 11767 | Slog.d(TAG, "UID=" + traffic.getUid() + " rx_bytes=" + traffic.getRxBytes() |
| 11768 | + " rx_time=" + timeRxMs); |
| 11769 | } |
| 11770 | counter.getRxTimeCounter().addCountLocked(timeRxMs); |
| 11771 | leftOverRxTimeMs -= timeRxMs; |
| 11772 | } |
| 11773 | |
| 11774 | if (totalTxBytes > 0 && traffic.getTxBytes() > 0) { |
| 11775 | final long timeTxMs = (leftOverTxTimeMs * traffic.getTxBytes()) / totalTxBytes; |
| 11776 | |
| 11777 | if (DEBUG_ENERGY) { |
| 11778 | Slog.d(TAG, "UID=" + traffic.getUid() + " tx_bytes=" + traffic.getTxBytes() |
| 11779 | + " tx_time=" + timeTxMs); |
| 11780 | } |
| 11781 | |
| 11782 | counter.getTxTimeCounters()[0].addCountLocked(timeTxMs); |
| 11783 | leftOverTxTimeMs -= timeTxMs; |
| 11784 | } |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 11785 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11786 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 11787 | |
Chenjie Yu | 8908339 | 2018-01-11 14:53:31 -0800 | [diff] [blame] | 11788 | mBluetoothActivity.getRxTimeCounter().addCountLocked(rxTimeMs); |
| 11789 | mBluetoothActivity.getTxTimeCounters()[0].addCountLocked(txTimeMs); |
| 11790 | mBluetoothActivity.getIdleTimeCounter().addCountLocked(idleTimeMs); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 11791 | |
| 11792 | // POWER_BLUETOOTH_CONTROLLER_OPERATING_VOLTAGE is measured in mV, so convert to V. |
| 11793 | final double opVolt = mPowerProfile.getAveragePower( |
| 11794 | PowerProfile.POWER_BLUETOOTH_CONTROLLER_OPERATING_VOLTAGE) / 1000.0; |
| 11795 | if (opVolt != 0) { |
| 11796 | // We store the power drain as mAms. |
| 11797 | mBluetoothActivity.getPowerCounter().addCountLocked( |
Chenjie Yu | 8908339 | 2018-01-11 14:53:31 -0800 | [diff] [blame] | 11798 | (long) ((info.getControllerEnergyUsed() - |
| 11799 | mLastBluetoothActivityEnergyInfo.getControllerEnergyUsed() )/ opVolt)); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 11800 | } |
Chenjie Yu | 8908339 | 2018-01-11 14:53:31 -0800 | [diff] [blame] | 11801 | mLastBluetoothActivityEnergyInfo = info; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11802 | } |
| 11803 | |
| 11804 | /** |
Bookatz | 0b8a050 | 2017-09-13 11:51:52 -0700 | [diff] [blame] | 11805 | * Read and record Resource Power Manager (RPM) state and voter times. |
| 11806 | * If RPM stats were fetched more recently than RPM_STATS_UPDATE_FREQ_MS ago, uses the old data |
| 11807 | * instead of fetching it anew. |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 11808 | */ |
| 11809 | public void updateRpmStatsLocked() { |
| 11810 | if (mPlatformIdleStateCallback == null) return; |
Bookatz | 0b8a050 | 2017-09-13 11:51:52 -0700 | [diff] [blame] | 11811 | long now = SystemClock.elapsedRealtime(); |
| 11812 | if (now - mLastRpmStatsUpdateTimeMs >= RPM_STATS_UPDATE_FREQ_MS) { |
| 11813 | mPlatformIdleStateCallback.fillLowPowerStats(mTmpRpmStats); |
| 11814 | mLastRpmStatsUpdateTimeMs = now; |
| 11815 | } |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 11816 | |
| 11817 | for (Map.Entry<String, RpmStats.PowerStatePlatformSleepState> pstate |
| 11818 | : mTmpRpmStats.mPlatformLowPowerStats.entrySet()) { |
| 11819 | |
| 11820 | // Update values for this platform state. |
| 11821 | final String pName = pstate.getKey(); |
| 11822 | final long pTimeUs = pstate.getValue().mTimeMs * 1000; |
| 11823 | final int pCount = pstate.getValue().mCount; |
| 11824 | getRpmTimerLocked(pName).update(pTimeUs, pCount); |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 11825 | if (SCREEN_OFF_RPM_STATS_ENABLED) { |
| 11826 | getScreenOffRpmTimerLocked(pName).update(pTimeUs, pCount); |
| 11827 | } |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 11828 | |
| 11829 | // Update values for each voter of this platform state. |
| 11830 | for (Map.Entry<String, RpmStats.PowerStateElement> voter |
| 11831 | : pstate.getValue().mVoters.entrySet()) { |
| 11832 | final String vName = pName + "." + voter.getKey(); |
| 11833 | final long vTimeUs = voter.getValue().mTimeMs * 1000; |
| 11834 | final int vCount = voter.getValue().mCount; |
| 11835 | getRpmTimerLocked(vName).update(vTimeUs, vCount); |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 11836 | if (SCREEN_OFF_RPM_STATS_ENABLED) { |
| 11837 | getScreenOffRpmTimerLocked(vName).update(vTimeUs, vCount); |
| 11838 | } |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 11839 | } |
| 11840 | } |
| 11841 | |
| 11842 | for (Map.Entry<String, RpmStats.PowerStateSubsystem> subsys |
| 11843 | : mTmpRpmStats.mSubsystemLowPowerStats.entrySet()) { |
| 11844 | |
| 11845 | final String subsysName = subsys.getKey(); |
| 11846 | for (Map.Entry<String, RpmStats.PowerStateElement> sstate |
| 11847 | : subsys.getValue().mStates.entrySet()) { |
| 11848 | final String name = subsysName + "." + sstate.getKey(); |
| 11849 | final long timeUs = sstate.getValue().mTimeMs * 1000; |
| 11850 | final int count = sstate.getValue().mCount; |
| 11851 | getRpmTimerLocked(name).update(timeUs, count); |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 11852 | if (SCREEN_OFF_RPM_STATS_ENABLED) { |
| 11853 | getScreenOffRpmTimerLocked(name).update(timeUs, count); |
| 11854 | } |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 11855 | } |
| 11856 | } |
| 11857 | } |
| 11858 | |
| 11859 | /** |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11860 | * Read and distribute kernel wake lock use across apps. |
| 11861 | */ |
| 11862 | public void updateKernelWakelocksLocked() { |
| 11863 | final KernelWakelockStats wakelockStats = mKernelWakelockReader.readKernelWakelockStats( |
| 11864 | mTmpWakelockStats); |
| 11865 | if (wakelockStats == null) { |
| 11866 | // Not crashing might make board bringup easier. |
| 11867 | Slog.w(TAG, "Couldn't get kernel wake lock stats"); |
| 11868 | return; |
| 11869 | } |
| 11870 | |
| 11871 | for (Map.Entry<String, KernelWakelockStats.Entry> ent : wakelockStats.entrySet()) { |
| 11872 | String name = ent.getKey(); |
| 11873 | KernelWakelockStats.Entry kws = ent.getValue(); |
| 11874 | |
| 11875 | SamplingTimer kwlt = mKernelWakelockStats.get(name); |
| 11876 | if (kwlt == null) { |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 11877 | kwlt = new SamplingTimer(mClocks, mOnBatteryScreenOffTimeBase); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11878 | mKernelWakelockStats.put(name, kwlt); |
| 11879 | } |
Adam Lesinski | d84ad30 | 2016-05-17 18:31:02 -0700 | [diff] [blame] | 11880 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 11881 | kwlt.update(kws.mTotalTime, kws.mCount); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11882 | kwlt.setUpdateVersion(kws.mVersion); |
| 11883 | } |
| 11884 | |
Adam Lesinski | fbabe7d | 2015-08-03 14:37:38 -0700 | [diff] [blame] | 11885 | int numWakelocksSetStale = 0; |
Adam Lesinski | d84ad30 | 2016-05-17 18:31:02 -0700 | [diff] [blame] | 11886 | // Set timers to stale if they didn't appear in /d/wakeup_sources (or /proc/wakelocks) |
| 11887 | // this time. |
| 11888 | for (Map.Entry<String, SamplingTimer> ent : mKernelWakelockStats.entrySet()) { |
| 11889 | SamplingTimer st = ent.getValue(); |
| 11890 | if (st.getUpdateVersion() != wakelockStats.kernelWakelockVersion) { |
| 11891 | st.endSample(); |
| 11892 | numWakelocksSetStale++; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11893 | } |
| 11894 | } |
Adam Lesinski | fbabe7d | 2015-08-03 14:37:38 -0700 | [diff] [blame] | 11895 | |
Adam Lesinski | d84ad30 | 2016-05-17 18:31:02 -0700 | [diff] [blame] | 11896 | // Record whether we've seen a non-zero time (for debugging b/22716723). |
| 11897 | if (wakelockStats.isEmpty()) { |
Adam Lesinski | fbabe7d | 2015-08-03 14:37:38 -0700 | [diff] [blame] | 11898 | Slog.wtf(TAG, "All kernel wakelocks had time of zero"); |
| 11899 | } |
| 11900 | |
| 11901 | if (numWakelocksSetStale == mKernelWakelockStats.size()) { |
| 11902 | Slog.wtf(TAG, "All kernel wakelocks were set stale. new version=" + |
| 11903 | wakelockStats.kernelWakelockVersion); |
| 11904 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11905 | } |
| 11906 | |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 11907 | // We use an anonymous class to access these variables, |
| 11908 | // so they can't live on the stack or they'd have to be |
| 11909 | // final MutableLong objects (more allocations). |
| 11910 | // Used in updateCpuTimeLocked(). |
| 11911 | long mTempTotalCpuUserTimeUs; |
| 11912 | long mTempTotalCpuSystemTimeUs; |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 11913 | long[][] mWakeLockAllocationsUs; |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 11914 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 11915 | /** |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 11916 | * Reads the newest memory stats from the kernel. |
| 11917 | */ |
| 11918 | public void updateKernelMemoryBandwidthLocked() { |
| 11919 | mKernelMemoryBandwidthStats.updateStats(); |
| 11920 | LongSparseLongArray bandwidthEntries = mKernelMemoryBandwidthStats.getBandwidthEntries(); |
| 11921 | final int bandwidthEntryCount = bandwidthEntries.size(); |
| 11922 | int index; |
| 11923 | for (int i = 0; i < bandwidthEntryCount; i++) { |
| 11924 | SamplingTimer timer; |
| 11925 | if ((index = mKernelMemoryStats.indexOfKey(bandwidthEntries.keyAt(i))) >= 0) { |
| 11926 | timer = mKernelMemoryStats.valueAt(index); |
| 11927 | } else { |
| 11928 | timer = new SamplingTimer(mClocks, mOnBatteryTimeBase); |
| 11929 | mKernelMemoryStats.put(bandwidthEntries.keyAt(i), timer); |
| 11930 | } |
| 11931 | timer.update(bandwidthEntries.valueAt(i), 1); |
| 11932 | if (DEBUG_MEMORY) { |
| 11933 | Slog.d(TAG, String.format("Added entry %d and updated timer to: " |
| 11934 | + "mUnpluggedReportedTotalTime %d size %d", bandwidthEntries.keyAt(i), |
| 11935 | mKernelMemoryStats.get( |
| 11936 | bandwidthEntries.keyAt(i)).mUnpluggedReportedTotalTime, |
| 11937 | mKernelMemoryStats.size())); |
| 11938 | } |
| 11939 | } |
| 11940 | } |
| 11941 | |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 11942 | public boolean isOnBatteryLocked() { |
| 11943 | return mOnBatteryTimeBase.isRunning(); |
| 11944 | } |
| 11945 | |
| 11946 | public boolean isOnBatteryScreenOffLocked() { |
| 11947 | return mOnBatteryScreenOffTimeBase.isRunning(); |
| 11948 | } |
| 11949 | |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 11950 | /** |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 11951 | * Read and distribute CPU usage across apps. If their are partial wakelocks being held |
| 11952 | * and we are on battery with screen off, we give more of the cpu time to those apps holding |
| 11953 | * 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] | 11954 | * It's possible this will be invoked after the internal battery/screen states are updated, so |
| 11955 | * passing the appropriate battery/screen states to try attribute the cpu times to correct |
| 11956 | * buckets. |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 11957 | */ |
Andreas Gampe | 3f24e69 | 2018-02-05 13:24:28 -0800 | [diff] [blame] | 11958 | @GuardedBy("this") |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 11959 | public void updateCpuTimeLocked(boolean onBattery, boolean onBatteryScreenOff) { |
Adam Lesinski | 52290c9c | 2015-09-21 16:54:52 -0700 | [diff] [blame] | 11960 | if (mPowerProfile == null) { |
| 11961 | return; |
| 11962 | } |
| 11963 | |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 11964 | if (DEBUG_ENERGY_CPU) { |
| 11965 | Slog.d(TAG, "!Cpu updating!"); |
| 11966 | } |
| 11967 | |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 11968 | if (mCpuFreqs == null) { |
| 11969 | mCpuFreqs = mKernelUidCpuFreqTimeReader.readFreqs(mPowerProfile); |
| 11970 | } |
| 11971 | |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 11972 | // Calculate the wakelocks we have to distribute amongst. The system is excluded as it is |
| 11973 | // usually holding the wakelock on behalf of an app. |
| 11974 | // And Only distribute cpu power to wakelocks if the screen is off and we're on battery. |
| 11975 | ArrayList<StopwatchTimer> partialTimersToConsider = null; |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 11976 | if (onBatteryScreenOff) { |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 11977 | partialTimersToConsider = new ArrayList<>(); |
| 11978 | for (int i = mPartialTimers.size() - 1; i >= 0; --i) { |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 11979 | final StopwatchTimer timer = mPartialTimers.get(i); |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 11980 | // Since the collection and blaming of wakelocks can be scheduled to run after |
| 11981 | // some delay, the mPartialTimers list may have new entries. We can't blame |
| 11982 | // the newly added timer for past cpu time, so we only consider timers that |
| 11983 | // were present for one round of collection. Once a timer has gone through |
| 11984 | // a round of collection, its mInList field is set to true. |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 11985 | if (timer.mInList && timer.mUid != null && timer.mUid.mUid != Process.SYSTEM_UID) { |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 11986 | partialTimersToConsider.add(timer); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 11987 | } |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 11988 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 11989 | } |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 11990 | markPartialTimersAsEligible(); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 11991 | |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 11992 | // When the battery is not on, we don't attribute the cpu times to any timers but we still |
| 11993 | // need to take the snapshots. |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 11994 | if (!onBattery) { |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 11995 | mKernelUidCpuTimeReader.readDelta(null); |
| 11996 | mKernelUidCpuFreqTimeReader.readDelta(null); |
Mike Ma | fae87da | 2018-01-19 20:07:20 -0800 | [diff] [blame] | 11997 | if (mConstants.TRACK_CPU_ACTIVE_CLUSTER_TIME) { |
| 11998 | mKernelUidCpuActiveTimeReader.readDelta(null); |
| 11999 | mKernelUidCpuClusterTimeReader.readDelta(null); |
| 12000 | } |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 12001 | for (int cluster = mKernelCpuSpeedReaders.length - 1; cluster >= 0; --cluster) { |
| 12002 | mKernelCpuSpeedReaders[cluster].readDelta(); |
| 12003 | } |
| 12004 | return; |
| 12005 | } |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 12006 | |
Suprabh Shukla | e6e723d | 2017-06-14 16:14:43 -0700 | [diff] [blame] | 12007 | mUserInfoProvider.refreshUserIds(); |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 12008 | final SparseLongArray updatedUids = mKernelUidCpuFreqTimeReader.perClusterTimesAvailable() |
| 12009 | ? null : new SparseLongArray(); |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 12010 | readKernelUidCpuTimesLocked(partialTimersToConsider, updatedUids, onBattery); |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 12011 | // updatedUids=null means /proc/uid_time_in_state provides snapshots of per-cluster cpu |
| 12012 | // freqs, so no need to approximate these values. |
| 12013 | if (updatedUids != null) { |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 12014 | updateClusterSpeedTimes(updatedUids, onBattery); |
Sudheer Shanka | 671985f | 2017-05-19 11:33:42 -0700 | [diff] [blame] | 12015 | } |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 12016 | readKernelUidCpuFreqTimesLocked(partialTimersToConsider, onBattery, onBatteryScreenOff); |
Mike Ma | fae87da | 2018-01-19 20:07:20 -0800 | [diff] [blame] | 12017 | if (mConstants.TRACK_CPU_ACTIVE_CLUSTER_TIME) { |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 12018 | readKernelUidCpuActiveTimesLocked(onBattery); |
| 12019 | readKernelUidCpuClusterTimesLocked(onBattery); |
Mike Ma | fae87da | 2018-01-19 20:07:20 -0800 | [diff] [blame] | 12020 | } |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 12021 | } |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 12022 | |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 12023 | /** |
| 12024 | * Mark the current partial timers as gone through a collection so that they will be |
| 12025 | * considered in the next cpu times distribution to wakelock holders. |
| 12026 | */ |
| 12027 | @VisibleForTesting |
| 12028 | public void markPartialTimersAsEligible() { |
| 12029 | if (ArrayUtils.referenceEquals(mPartialTimers, mLastPartialTimers)) { |
| 12030 | // No difference, so each timer is now considered for the next collection. |
| 12031 | for (int i = mPartialTimers.size() - 1; i >= 0; --i) { |
| 12032 | mPartialTimers.get(i).mInList = true; |
| 12033 | } |
| 12034 | } else { |
| 12035 | // The lists are different, meaning we added (or removed a timer) since the last |
| 12036 | // collection. |
| 12037 | for (int i = mLastPartialTimers.size() - 1; i >= 0; --i) { |
| 12038 | mLastPartialTimers.get(i).mInList = false; |
| 12039 | } |
| 12040 | mLastPartialTimers.clear(); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 12041 | |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 12042 | // Mark the current timers as gone through a collection. |
| 12043 | final int numPartialTimers = mPartialTimers.size(); |
| 12044 | for (int i = 0; i < numPartialTimers; ++i) { |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 12045 | final StopwatchTimer timer = mPartialTimers.get(i); |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 12046 | timer.mInList = true; |
| 12047 | mLastPartialTimers.add(timer); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 12048 | } |
| 12049 | } |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 12050 | } |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 12051 | |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 12052 | /** |
| 12053 | * Take snapshot of cpu times (aggregated over all uids) at different frequencies and |
| 12054 | * calculate cpu times spent by each uid at different frequencies. |
| 12055 | * |
| 12056 | * @param updatedUids The uids for which times spent at different frequencies are calculated. |
| 12057 | */ |
| 12058 | @VisibleForTesting |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 12059 | public void updateClusterSpeedTimes(@NonNull SparseLongArray updatedUids, boolean onBattery) { |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 12060 | long totalCpuClustersTimeMs = 0; |
Sudheer Shanka | 2fc52d4 | 2017-06-16 17:29:19 -0700 | [diff] [blame] | 12061 | // Read the time spent for each cluster at various cpu frequencies. |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 12062 | final long[][] clusterSpeedTimesMs = new long[mKernelCpuSpeedReaders.length][]; |
Sudheer Shanka | 2fc52d4 | 2017-06-16 17:29:19 -0700 | [diff] [blame] | 12063 | for (int cluster = 0; cluster < mKernelCpuSpeedReaders.length; cluster++) { |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 12064 | clusterSpeedTimesMs[cluster] = mKernelCpuSpeedReaders[cluster].readDelta(); |
| 12065 | if (clusterSpeedTimesMs[cluster] != null) { |
| 12066 | for (int speed = clusterSpeedTimesMs[cluster].length - 1; speed >= 0; --speed) { |
| 12067 | totalCpuClustersTimeMs += clusterSpeedTimesMs[cluster][speed]; |
Sudheer Shanka | 2fc52d4 | 2017-06-16 17:29:19 -0700 | [diff] [blame] | 12068 | } |
| 12069 | } |
| 12070 | } |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 12071 | if (totalCpuClustersTimeMs != 0) { |
Sudheer Shanka | 2fc52d4 | 2017-06-16 17:29:19 -0700 | [diff] [blame] | 12072 | // We have cpu times per freq aggregated over all uids but we need the times per uid. |
| 12073 | // So, we distribute total time spent by an uid to different cpu freqs based on the |
| 12074 | // amount of time cpu was running at that freq. |
| 12075 | final int updatedUidsCount = updatedUids.size(); |
| 12076 | for (int i = 0; i < updatedUidsCount; ++i) { |
| 12077 | final Uid u = getUidStatsLocked(updatedUids.keyAt(i)); |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 12078 | final long appCpuTimeUs = updatedUids.valueAt(i); |
Sudheer Shanka | 2fc52d4 | 2017-06-16 17:29:19 -0700 | [diff] [blame] | 12079 | // Add the cpu speeds to this UID. |
| 12080 | final int numClusters = mPowerProfile.getNumCpuClusters(); |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 12081 | if (u.mCpuClusterSpeedTimesUs == null || |
| 12082 | u.mCpuClusterSpeedTimesUs.length != numClusters) { |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 12083 | u.mCpuClusterSpeedTimesUs = new LongSamplingCounter[numClusters][]; |
Sudheer Shanka | 2fc52d4 | 2017-06-16 17:29:19 -0700 | [diff] [blame] | 12084 | } |
| 12085 | |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 12086 | for (int cluster = 0; cluster < clusterSpeedTimesMs.length; cluster++) { |
| 12087 | final int speedsInCluster = clusterSpeedTimesMs[cluster].length; |
| 12088 | if (u.mCpuClusterSpeedTimesUs[cluster] == null || speedsInCluster != |
| 12089 | u.mCpuClusterSpeedTimesUs[cluster].length) { |
| 12090 | u.mCpuClusterSpeedTimesUs[cluster] |
| 12091 | = new LongSamplingCounter[speedsInCluster]; |
Sudheer Shanka | 2fc52d4 | 2017-06-16 17:29:19 -0700 | [diff] [blame] | 12092 | } |
| 12093 | |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 12094 | final LongSamplingCounter[] cpuSpeeds = u.mCpuClusterSpeedTimesUs[cluster]; |
Sudheer Shanka | 2fc52d4 | 2017-06-16 17:29:19 -0700 | [diff] [blame] | 12095 | for (int speed = 0; speed < speedsInCluster; speed++) { |
| 12096 | if (cpuSpeeds[speed] == null) { |
| 12097 | cpuSpeeds[speed] = new LongSamplingCounter(mOnBatteryTimeBase); |
| 12098 | } |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 12099 | cpuSpeeds[speed].addCountLocked(appCpuTimeUs |
| 12100 | * clusterSpeedTimesMs[cluster][speed] |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 12101 | / totalCpuClustersTimeMs, onBattery); |
Sudheer Shanka | 2fc52d4 | 2017-06-16 17:29:19 -0700 | [diff] [blame] | 12102 | } |
| 12103 | } |
| 12104 | } |
| 12105 | } |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 12106 | } |
Sudheer Shanka | 2fc52d4 | 2017-06-16 17:29:19 -0700 | [diff] [blame] | 12107 | |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 12108 | /** |
| 12109 | * Take a snapshot of the cpu times spent by each uid and update the corresponding counters. |
| 12110 | * If {@param partialTimers} is not null and empty, then we assign a portion of cpu times to |
| 12111 | * wakelock holders. |
| 12112 | * |
| 12113 | * @param partialTimers The wakelock holders among which the cpu times will be distributed. |
| 12114 | * @param updatedUids If not null, then the uids found in the snapshot will be added to this. |
| 12115 | */ |
| 12116 | @VisibleForTesting |
| 12117 | public void readKernelUidCpuTimesLocked(@Nullable ArrayList<StopwatchTimer> partialTimers, |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 12118 | @Nullable SparseLongArray updatedUids, boolean onBattery) { |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 12119 | mTempTotalCpuUserTimeUs = mTempTotalCpuSystemTimeUs = 0; |
| 12120 | final int numWakelocks = partialTimers == null ? 0 : partialTimers.size(); |
| 12121 | final long startTimeMs = mClocks.uptimeMillis(); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 12122 | |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 12123 | mKernelUidCpuTimeReader.readDelta((uid, userTimeUs, systemTimeUs) -> { |
| 12124 | uid = mapUid(uid); |
| 12125 | if (Process.isIsolated(uid)) { |
| 12126 | // This could happen if the isolated uid mapping was removed before that process |
| 12127 | // was actually killed. |
| 12128 | mKernelUidCpuTimeReader.removeUid(uid); |
| 12129 | Slog.d(TAG, "Got readings for an isolated uid with no mapping: " + uid); |
| 12130 | return; |
| 12131 | } |
| 12132 | if (!mUserInfoProvider.exists(UserHandle.getUserId(uid))) { |
| 12133 | Slog.d(TAG, "Got readings for an invalid user's uid " + uid); |
| 12134 | mKernelUidCpuTimeReader.removeUid(uid); |
| 12135 | return; |
| 12136 | } |
| 12137 | final Uid u = getUidStatsLocked(uid); |
| 12138 | |
| 12139 | // Accumulate the total system and user time. |
| 12140 | mTempTotalCpuUserTimeUs += userTimeUs; |
| 12141 | mTempTotalCpuSystemTimeUs += systemTimeUs; |
| 12142 | |
| 12143 | StringBuilder sb = null; |
| 12144 | if (DEBUG_ENERGY_CPU) { |
| 12145 | sb = new StringBuilder(); |
| 12146 | sb.append(" got time for uid=").append(u.mUid).append(": u="); |
| 12147 | TimeUtils.formatDuration(userTimeUs / 1000, sb); |
| 12148 | sb.append(" s="); |
| 12149 | TimeUtils.formatDuration(systemTimeUs / 1000, sb); |
| 12150 | sb.append("\n"); |
| 12151 | } |
| 12152 | |
| 12153 | if (numWakelocks > 0) { |
| 12154 | // We have wakelocks being held, so only give a portion of the |
| 12155 | // time to the process. The rest will be distributed among wakelock |
| 12156 | // holders. |
| 12157 | userTimeUs = (userTimeUs * WAKE_LOCK_WEIGHT) / 100; |
| 12158 | systemTimeUs = (systemTimeUs * WAKE_LOCK_WEIGHT) / 100; |
| 12159 | } |
| 12160 | |
| 12161 | if (sb != null) { |
| 12162 | sb.append(" adding to uid=").append(u.mUid).append(": u="); |
| 12163 | TimeUtils.formatDuration(userTimeUs / 1000, sb); |
| 12164 | sb.append(" s="); |
| 12165 | TimeUtils.formatDuration(systemTimeUs / 1000, sb); |
| 12166 | Slog.d(TAG, sb.toString()); |
| 12167 | } |
| 12168 | |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 12169 | u.mUserCpuTime.addCountLocked(userTimeUs, onBattery); |
| 12170 | u.mSystemCpuTime.addCountLocked(systemTimeUs, onBattery); |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 12171 | if (updatedUids != null) { |
| 12172 | updatedUids.put(u.getUid(), userTimeUs + systemTimeUs); |
| 12173 | } |
| 12174 | }); |
| 12175 | |
| 12176 | final long elapsedTimeMs = mClocks.uptimeMillis() - startTimeMs; |
| 12177 | if (DEBUG_ENERGY_CPU || elapsedTimeMs >= 100) { |
| 12178 | Slog.d(TAG, "Reading cpu stats took " + elapsedTimeMs + "ms"); |
| 12179 | } |
| 12180 | |
| 12181 | if (numWakelocks > 0) { |
| 12182 | // Distribute a portion of the total cpu time to wakelock holders. |
| 12183 | mTempTotalCpuUserTimeUs = (mTempTotalCpuUserTimeUs * (100 - WAKE_LOCK_WEIGHT)) / 100; |
| 12184 | mTempTotalCpuSystemTimeUs = |
| 12185 | (mTempTotalCpuSystemTimeUs * (100 - WAKE_LOCK_WEIGHT)) / 100; |
| 12186 | |
| 12187 | for (int i = 0; i < numWakelocks; ++i) { |
| 12188 | final StopwatchTimer timer = partialTimers.get(i); |
| 12189 | final int userTimeUs = (int) (mTempTotalCpuUserTimeUs / (numWakelocks - i)); |
| 12190 | final int systemTimeUs = (int) (mTempTotalCpuSystemTimeUs / (numWakelocks - i)); |
| 12191 | |
| 12192 | if (DEBUG_ENERGY_CPU) { |
| 12193 | final StringBuilder sb = new StringBuilder(); |
| 12194 | sb.append(" Distributing wakelock uid=").append(timer.mUid.mUid) |
| 12195 | .append(": u="); |
| 12196 | TimeUtils.formatDuration(userTimeUs / 1000, sb); |
| 12197 | sb.append(" s="); |
| 12198 | TimeUtils.formatDuration(systemTimeUs / 1000, sb); |
| 12199 | Slog.d(TAG, sb.toString()); |
| 12200 | } |
| 12201 | |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 12202 | timer.mUid.mUserCpuTime.addCountLocked(userTimeUs, onBattery); |
| 12203 | timer.mUid.mSystemCpuTime.addCountLocked(systemTimeUs, onBattery); |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 12204 | if (updatedUids != null) { |
| 12205 | final int uid = timer.mUid.getUid(); |
| 12206 | updatedUids.put(uid, updatedUids.get(uid, 0) + userTimeUs + systemTimeUs); |
| 12207 | } |
| 12208 | |
| 12209 | final Uid.Proc proc = timer.mUid.getProcessStatsLocked("*wakelock*"); |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 12210 | proc.addCpuTimeLocked(userTimeUs / 1000, systemTimeUs / 1000, onBattery); |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 12211 | |
| 12212 | mTempTotalCpuUserTimeUs -= userTimeUs; |
| 12213 | mTempTotalCpuSystemTimeUs -= systemTimeUs; |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 12214 | } |
| 12215 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 12216 | } |
| 12217 | |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 12218 | /** |
| 12219 | * Take a snapshot of the cpu times spent by each uid in each freq and update the |
| 12220 | * corresponding counters. |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 12221 | * |
| 12222 | * @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] | 12223 | */ |
| 12224 | @VisibleForTesting |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 12225 | public void readKernelUidCpuFreqTimesLocked(@Nullable ArrayList<StopwatchTimer> partialTimers, |
| 12226 | boolean onBattery, boolean onBatteryScreenOff) { |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 12227 | final boolean perClusterTimesAvailable = |
| 12228 | mKernelUidCpuFreqTimeReader.perClusterTimesAvailable(); |
| 12229 | final int numWakelocks = partialTimers == null ? 0 : partialTimers.size(); |
| 12230 | final int numClusters = mPowerProfile.getNumCpuClusters(); |
| 12231 | mWakeLockAllocationsUs = null; |
Sudheer Shanka | ac5b88f | 2017-12-11 15:36:35 -0800 | [diff] [blame] | 12232 | final long startTimeMs = mClocks.uptimeMillis(); |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 12233 | mKernelUidCpuFreqTimeReader.readDelta((uid, cpuFreqTimeMs) -> { |
| 12234 | uid = mapUid(uid); |
| 12235 | if (Process.isIsolated(uid)) { |
| 12236 | mKernelUidCpuFreqTimeReader.removeUid(uid); |
| 12237 | Slog.d(TAG, "Got freq readings for an isolated uid with no mapping: " + uid); |
| 12238 | return; |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 12239 | } |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 12240 | if (!mUserInfoProvider.exists(UserHandle.getUserId(uid))) { |
| 12241 | Slog.d(TAG, "Got freq readings for an invalid user's uid " + uid); |
| 12242 | mKernelUidCpuFreqTimeReader.removeUid(uid); |
| 12243 | return; |
| 12244 | } |
| 12245 | final Uid u = getUidStatsLocked(uid); |
| 12246 | if (u.mCpuFreqTimeMs == null || u.mCpuFreqTimeMs.getSize() != cpuFreqTimeMs.length) { |
| 12247 | u.mCpuFreqTimeMs = new LongSamplingCounterArray(mOnBatteryTimeBase); |
| 12248 | } |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 12249 | u.mCpuFreqTimeMs.addCountLocked(cpuFreqTimeMs, onBattery); |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 12250 | if (u.mScreenOffCpuFreqTimeMs == null || |
| 12251 | u.mScreenOffCpuFreqTimeMs.getSize() != cpuFreqTimeMs.length) { |
| 12252 | u.mScreenOffCpuFreqTimeMs = new LongSamplingCounterArray( |
| 12253 | mOnBatteryScreenOffTimeBase); |
| 12254 | } |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 12255 | u.mScreenOffCpuFreqTimeMs.addCountLocked(cpuFreqTimeMs, onBatteryScreenOff); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 12256 | |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 12257 | if (perClusterTimesAvailable) { |
| 12258 | if (u.mCpuClusterSpeedTimesUs == null || |
| 12259 | u.mCpuClusterSpeedTimesUs.length != numClusters) { |
| 12260 | u.mCpuClusterSpeedTimesUs = new LongSamplingCounter[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 | if (numWakelocks > 0 && mWakeLockAllocationsUs == null) { |
| 12263 | mWakeLockAllocationsUs = new long[numClusters][]; |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 12264 | } |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 12265 | |
| 12266 | int freqIndex = 0; |
| 12267 | for (int cluster = 0; cluster < numClusters; ++cluster) { |
| 12268 | final int speedsInCluster = mPowerProfile.getNumSpeedStepsInCpuCluster(cluster); |
| 12269 | if (u.mCpuClusterSpeedTimesUs[cluster] == null || |
| 12270 | u.mCpuClusterSpeedTimesUs[cluster].length != speedsInCluster) { |
| 12271 | u.mCpuClusterSpeedTimesUs[cluster] |
| 12272 | = new LongSamplingCounter[speedsInCluster]; |
| 12273 | } |
| 12274 | if (numWakelocks > 0 && mWakeLockAllocationsUs[cluster] == null) { |
| 12275 | mWakeLockAllocationsUs[cluster] = new long[speedsInCluster]; |
| 12276 | } |
| 12277 | final LongSamplingCounter[] cpuTimesUs = u.mCpuClusterSpeedTimesUs[cluster]; |
| 12278 | for (int speed = 0; speed < speedsInCluster; ++speed) { |
| 12279 | if (cpuTimesUs[speed] == null) { |
| 12280 | cpuTimesUs[speed] = new LongSamplingCounter(mOnBatteryTimeBase); |
| 12281 | } |
| 12282 | final long appAllocationUs; |
| 12283 | if (mWakeLockAllocationsUs != null) { |
| 12284 | appAllocationUs = |
| 12285 | (cpuFreqTimeMs[freqIndex] * 1000 * WAKE_LOCK_WEIGHT) / 100; |
| 12286 | mWakeLockAllocationsUs[cluster][speed] += |
| 12287 | (cpuFreqTimeMs[freqIndex] * 1000 - appAllocationUs); |
| 12288 | } else { |
| 12289 | appAllocationUs = cpuFreqTimeMs[freqIndex] * 1000; |
| 12290 | } |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 12291 | cpuTimesUs[speed].addCountLocked(appAllocationUs, onBattery); |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 12292 | freqIndex++; |
| 12293 | } |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 12294 | } |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 12295 | } |
| 12296 | }); |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 12297 | |
Sudheer Shanka | ac5b88f | 2017-12-11 15:36:35 -0800 | [diff] [blame] | 12298 | final long elapsedTimeMs = mClocks.uptimeMillis() - startTimeMs; |
| 12299 | if (DEBUG_ENERGY_CPU || elapsedTimeMs >= 100) { |
| 12300 | Slog.d(TAG, "Reading cpu freq times took " + elapsedTimeMs + "ms"); |
| 12301 | } |
| 12302 | |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 12303 | if (mWakeLockAllocationsUs != null) { |
| 12304 | for (int i = 0; i < numWakelocks; ++i) { |
| 12305 | final Uid u = partialTimers.get(i).mUid; |
| 12306 | if (u.mCpuClusterSpeedTimesUs == null || |
| 12307 | u.mCpuClusterSpeedTimesUs.length != numClusters) { |
| 12308 | u.mCpuClusterSpeedTimesUs = new LongSamplingCounter[numClusters][]; |
| 12309 | } |
| 12310 | |
| 12311 | for (int cluster = 0; cluster < numClusters; ++cluster) { |
| 12312 | final int speedsInCluster = mPowerProfile.getNumSpeedStepsInCpuCluster(cluster); |
| 12313 | if (u.mCpuClusterSpeedTimesUs[cluster] == null || |
| 12314 | u.mCpuClusterSpeedTimesUs[cluster].length != speedsInCluster) { |
| 12315 | u.mCpuClusterSpeedTimesUs[cluster] |
| 12316 | = new LongSamplingCounter[speedsInCluster]; |
| 12317 | } |
| 12318 | final LongSamplingCounter[] cpuTimeUs = u.mCpuClusterSpeedTimesUs[cluster]; |
| 12319 | for (int speed = 0; speed < speedsInCluster; ++speed) { |
| 12320 | if (cpuTimeUs[speed] == null) { |
| 12321 | cpuTimeUs[speed] = new LongSamplingCounter(mOnBatteryTimeBase); |
| 12322 | } |
| 12323 | final long allocationUs = |
| 12324 | mWakeLockAllocationsUs[cluster][speed] / (numWakelocks - i); |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 12325 | cpuTimeUs[speed].addCountLocked(allocationUs, onBattery); |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 12326 | mWakeLockAllocationsUs[cluster][speed] -= allocationUs; |
| 12327 | } |
| 12328 | } |
| 12329 | } |
| 12330 | } |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 12331 | } |
| 12332 | |
Mike Ma | 3d422c3 | 2017-10-25 11:08:57 -0700 | [diff] [blame] | 12333 | /** |
| 12334 | * Take a snapshot of the cpu active times spent by each uid and update the corresponding |
| 12335 | * counters. |
| 12336 | */ |
| 12337 | @VisibleForTesting |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 12338 | public void readKernelUidCpuActiveTimesLocked(boolean onBattery) { |
Mike Ma | 3d422c3 | 2017-10-25 11:08:57 -0700 | [diff] [blame] | 12339 | final long startTimeMs = mClocks.uptimeMillis(); |
Mike Ma | 2ab0144 | 2018-02-13 14:22:47 -0800 | [diff] [blame] | 12340 | mKernelUidCpuActiveTimeReader.readDelta((uid, cpuActiveTimesMs) -> { |
Mike Ma | 3d422c3 | 2017-10-25 11:08:57 -0700 | [diff] [blame] | 12341 | uid = mapUid(uid); |
| 12342 | if (Process.isIsolated(uid)) { |
| 12343 | mKernelUidCpuActiveTimeReader.removeUid(uid); |
| 12344 | Slog.w(TAG, "Got active times for an isolated uid with no mapping: " + uid); |
| 12345 | return; |
| 12346 | } |
| 12347 | if (!mUserInfoProvider.exists(UserHandle.getUserId(uid))) { |
| 12348 | Slog.w(TAG, "Got active times for an invalid user's uid " + uid); |
| 12349 | mKernelUidCpuActiveTimeReader.removeUid(uid); |
| 12350 | return; |
| 12351 | } |
| 12352 | final Uid u = getUidStatsLocked(uid); |
Mike Ma | 2ab0144 | 2018-02-13 14:22:47 -0800 | [diff] [blame] | 12353 | u.mCpuActiveTimeMs.addCountLocked(cpuActiveTimesMs, onBattery); |
Mike Ma | 3d422c3 | 2017-10-25 11:08:57 -0700 | [diff] [blame] | 12354 | }); |
| 12355 | |
| 12356 | final long elapsedTimeMs = mClocks.uptimeMillis() - startTimeMs; |
| 12357 | if (DEBUG_ENERGY_CPU || elapsedTimeMs >= 100) { |
| 12358 | Slog.d(TAG, "Reading cpu active times took " + elapsedTimeMs + "ms"); |
| 12359 | } |
| 12360 | } |
| 12361 | |
| 12362 | /** |
| 12363 | * Take a snapshot of the cpu cluster times spent by each uid and update the corresponding |
| 12364 | * counters. |
| 12365 | */ |
| 12366 | @VisibleForTesting |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 12367 | public void readKernelUidCpuClusterTimesLocked(boolean onBattery) { |
Mike Ma | 3d422c3 | 2017-10-25 11:08:57 -0700 | [diff] [blame] | 12368 | final long startTimeMs = mClocks.uptimeMillis(); |
Mike Ma | 2ab0144 | 2018-02-13 14:22:47 -0800 | [diff] [blame] | 12369 | mKernelUidCpuClusterTimeReader.readDelta((uid, cpuClusterTimesMs) -> { |
Mike Ma | 3d422c3 | 2017-10-25 11:08:57 -0700 | [diff] [blame] | 12370 | uid = mapUid(uid); |
| 12371 | if (Process.isIsolated(uid)) { |
| 12372 | mKernelUidCpuClusterTimeReader.removeUid(uid); |
| 12373 | Slog.w(TAG, "Got cluster times for an isolated uid with no mapping: " + uid); |
| 12374 | return; |
| 12375 | } |
| 12376 | if (!mUserInfoProvider.exists(UserHandle.getUserId(uid))) { |
| 12377 | Slog.w(TAG, "Got cluster times for an invalid user's uid " + uid); |
| 12378 | mKernelUidCpuClusterTimeReader.removeUid(uid); |
| 12379 | return; |
| 12380 | } |
| 12381 | final Uid u = getUidStatsLocked(uid); |
Mike Ma | 2ab0144 | 2018-02-13 14:22:47 -0800 | [diff] [blame] | 12382 | u.mCpuClusterTimesMs.addCountLocked(cpuClusterTimesMs, onBattery); |
Mike Ma | 3d422c3 | 2017-10-25 11:08:57 -0700 | [diff] [blame] | 12383 | }); |
| 12384 | |
| 12385 | final long elapsedTimeMs = mClocks.uptimeMillis() - startTimeMs; |
| 12386 | if (DEBUG_ENERGY_CPU || elapsedTimeMs >= 100) { |
| 12387 | Slog.d(TAG, "Reading cpu cluster times took " + elapsedTimeMs + "ms"); |
| 12388 | } |
| 12389 | } |
| 12390 | |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 12391 | boolean setChargingLocked(boolean charging) { |
| 12392 | if (mCharging != charging) { |
| 12393 | mCharging = charging; |
| 12394 | if (charging) { |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 12395 | mHistoryCur.states2 |= HistoryItem.STATE2_CHARGING_FLAG; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 12396 | } else { |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 12397 | mHistoryCur.states2 &= ~HistoryItem.STATE2_CHARGING_FLAG; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 12398 | } |
| 12399 | mHandler.sendEmptyMessage(MSG_REPORT_CHARGING); |
| 12400 | return true; |
| 12401 | } |
| 12402 | return false; |
| 12403 | } |
| 12404 | |
Andreas Gampe | 3f24e69 | 2018-02-05 13:24:28 -0800 | [diff] [blame] | 12405 | @GuardedBy("this") |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 12406 | protected void setOnBatteryLocked(final long mSecRealtime, final long mSecUptime, |
| 12407 | final boolean onBattery, final int oldStatus, final int level, final int chargeUAh) { |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 12408 | boolean doWrite = false; |
| 12409 | Message m = mHandler.obtainMessage(MSG_REPORT_POWER_CHANGE); |
| 12410 | m.arg1 = onBattery ? 1 : 0; |
| 12411 | mHandler.sendMessage(m); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 12412 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 12413 | final long uptime = mSecUptime * 1000; |
| 12414 | final long realtime = mSecRealtime * 1000; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 12415 | final int screenState = mScreenState; |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 12416 | if (onBattery) { |
| 12417 | // We will reset our status if we are unplugging after the |
| 12418 | // battery was last full, or the level is at 100, or |
| 12419 | // we have gone through a significant charge (from a very low |
| 12420 | // level to a now very high level). |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 12421 | boolean reset = false; |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 12422 | if (!mNoAutoReset && (oldStatus == BatteryManager.BATTERY_STATUS_FULL |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 12423 | || level >= 90 |
Dianne Hackborn | fb3809c | 2014-09-29 18:31:22 -0700 | [diff] [blame] | 12424 | || (mDischargeCurrentLevel < 20 && level >= 80) |
| 12425 | || (getHighDischargeAmountSinceCharge() >= 200 |
| 12426 | && mHistoryBuffer.dataSize() >= MAX_HISTORY_BUFFER))) { |
Dianne Hackborn | 73d6a82 | 2014-09-29 10:52:47 -0700 | [diff] [blame] | 12427 | Slog.i(TAG, "Resetting battery stats: level=" + level + " status=" + oldStatus |
Dianne Hackborn | fb3809c | 2014-09-29 18:31:22 -0700 | [diff] [blame] | 12428 | + " dischargeLevel=" + mDischargeCurrentLevel |
Dianne Hackborn | 73d6a82 | 2014-09-29 10:52:47 -0700 | [diff] [blame] | 12429 | + " lowAmount=" + getLowDischargeAmountSinceCharge() |
| 12430 | + " highAmount=" + getHighDischargeAmountSinceCharge()); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 12431 | // Before we write, collect a snapshot of the final aggregated |
| 12432 | // stats to be reported in the next checkin. Only do this if we have |
| 12433 | // a sufficient amount of data to make it interesting. |
| 12434 | if (getLowDischargeAmountSinceCharge() >= 20) { |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 12435 | final long startTime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 12436 | final Parcel parcel = Parcel.obtain(); |
| 12437 | writeSummaryToParcel(parcel, true); |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 12438 | final long initialTime = SystemClock.uptimeMillis() - startTime; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 12439 | BackgroundThread.getHandler().post(new Runnable() { |
| 12440 | @Override public void run() { |
| 12441 | synchronized (mCheckinFile) { |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 12442 | final long startTime2 = SystemClock.uptimeMillis(); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 12443 | FileOutputStream stream = null; |
| 12444 | try { |
| 12445 | stream = mCheckinFile.startWrite(); |
| 12446 | stream.write(parcel.marshall()); |
| 12447 | stream.flush(); |
| 12448 | FileUtils.sync(stream); |
| 12449 | stream.close(); |
| 12450 | mCheckinFile.finishWrite(stream); |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 12451 | com.android.internal.logging.EventLogTags.writeCommitSysConfigFile( |
| 12452 | "batterystats-checkin", |
| 12453 | initialTime + SystemClock.uptimeMillis() - startTime2); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 12454 | } catch (IOException e) { |
| 12455 | Slog.w("BatteryStats", |
| 12456 | "Error writing checkin battery statistics", e); |
| 12457 | mCheckinFile.failWrite(stream); |
| 12458 | } finally { |
| 12459 | parcel.recycle(); |
| 12460 | } |
| 12461 | } |
| 12462 | } |
| 12463 | }); |
| 12464 | } |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 12465 | doWrite = true; |
| 12466 | resetAllStatsLocked(); |
Ying Wai (Daniel) Fan | 442ab76 | 2017-01-31 22:00:10 -0800 | [diff] [blame] | 12467 | if (chargeUAh > 0 && level > 0) { |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 12468 | // 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] | 12469 | mEstimatedBatteryCapacity = (int) ((chargeUAh / 1000) / (level / 100.0)); |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 12470 | } |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 12471 | mDischargeStartLevel = level; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 12472 | reset = true; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 12473 | mDischargeStepTracker.init(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 12474 | } |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 12475 | if (mCharging) { |
| 12476 | setChargingLocked(false); |
| 12477 | } |
| 12478 | mLastChargingStateLevel = level; |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 12479 | mOnBattery = mOnBatteryInternal = true; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 12480 | mLastDischargeStepLevel = level; |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 12481 | mMinDischargeStepLevel = level; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 12482 | mDischargeStepTracker.clearTime(); |
| 12483 | mDailyDischargeStepTracker.clearTime(); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 12484 | mInitStepMode = mCurStepMode; |
| 12485 | mModStepMode = 0; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 12486 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 12487 | mHistoryCur.batteryLevel = (byte)level; |
| 12488 | mHistoryCur.states &= ~HistoryItem.STATE_BATTERY_PLUGGED_FLAG; |
| 12489 | if (DEBUG_HISTORY) Slog.v(TAG, "Battery unplugged to: " |
| 12490 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 12491 | if (reset) { |
| 12492 | mRecordingHistory = true; |
| 12493 | startRecordingHistory(mSecRealtime, mSecUptime, reset); |
| 12494 | } |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 12495 | addHistoryRecordLocked(mSecRealtime, mSecUptime); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 12496 | mDischargeCurrentLevel = mDischargeUnplugLevel = level; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 12497 | if (isScreenOn(screenState)) { |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 12498 | mDischargeScreenOnUnplugLevel = level; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 12499 | mDischargeScreenDozeUnplugLevel = 0; |
| 12500 | mDischargeScreenOffUnplugLevel = 0; |
| 12501 | } else if (isScreenDoze(screenState)) { |
| 12502 | mDischargeScreenOnUnplugLevel = 0; |
| 12503 | mDischargeScreenDozeUnplugLevel = level; |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 12504 | mDischargeScreenOffUnplugLevel = 0; |
| 12505 | } else { |
| 12506 | mDischargeScreenOnUnplugLevel = 0; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 12507 | mDischargeScreenDozeUnplugLevel = 0; |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 12508 | mDischargeScreenOffUnplugLevel = level; |
| 12509 | } |
| 12510 | mDischargeAmountScreenOn = 0; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 12511 | mDischargeAmountScreenDoze = 0; |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 12512 | mDischargeAmountScreenOff = 0; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 12513 | updateTimeBasesLocked(true, screenState, uptime, realtime); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 12514 | } else { |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 12515 | mLastChargingStateLevel = level; |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 12516 | mOnBattery = mOnBatteryInternal = false; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 12517 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 12518 | mHistoryCur.batteryLevel = (byte)level; |
| 12519 | mHistoryCur.states |= HistoryItem.STATE_BATTERY_PLUGGED_FLAG; |
| 12520 | if (DEBUG_HISTORY) Slog.v(TAG, "Battery plugged to: " |
| 12521 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 12522 | addHistoryRecordLocked(mSecRealtime, mSecUptime); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 12523 | mDischargeCurrentLevel = mDischargePlugLevel = level; |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 12524 | if (level < mDischargeUnplugLevel) { |
| 12525 | mLowDischargeAmountSinceCharge += mDischargeUnplugLevel-level-1; |
| 12526 | mHighDischargeAmountSinceCharge += mDischargeUnplugLevel-level; |
| 12527 | } |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 12528 | updateDischargeScreenLevelsLocked(screenState, screenState); |
| 12529 | updateTimeBasesLocked(false, screenState, uptime, realtime); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 12530 | mChargeStepTracker.init(); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 12531 | mLastChargeStepLevel = level; |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 12532 | mMaxChargeStepLevel = level; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 12533 | mInitStepMode = mCurStepMode; |
| 12534 | mModStepMode = 0; |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 12535 | } |
| 12536 | if (doWrite || (mLastWriteTime + (60 * 1000)) < mSecRealtime) { |
| 12537 | if (mFile != null) { |
| 12538 | writeAsyncLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12539 | } |
| 12540 | } |
| 12541 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 12542 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 12543 | private void startRecordingHistory(final long elapsedRealtimeMs, final long uptimeMs, |
| 12544 | boolean reset) { |
| 12545 | mRecordingHistory = true; |
| 12546 | mHistoryCur.currentTime = System.currentTimeMillis(); |
Narayan Kamath | 5a5a7fe | 2018-02-05 17:30:06 +0000 | [diff] [blame] | 12547 | addHistoryBufferLocked(elapsedRealtimeMs, |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 12548 | reset ? HistoryItem.CMD_RESET : HistoryItem.CMD_CURRENT_TIME, |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 12549 | mHistoryCur); |
| 12550 | mHistoryCur.currentTime = 0; |
| 12551 | if (reset) { |
| 12552 | initActiveHistoryEventsLocked(elapsedRealtimeMs, uptimeMs); |
| 12553 | } |
| 12554 | } |
| 12555 | |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 12556 | private void recordCurrentTimeChangeLocked(final long currentTime, final long elapsedRealtimeMs, |
| 12557 | final long uptimeMs) { |
| 12558 | if (mRecordingHistory) { |
| 12559 | mHistoryCur.currentTime = currentTime; |
Narayan Kamath | 5a5a7fe | 2018-02-05 17:30:06 +0000 | [diff] [blame] | 12560 | addHistoryBufferLocked(elapsedRealtimeMs, HistoryItem.CMD_CURRENT_TIME, mHistoryCur); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 12561 | mHistoryCur.currentTime = 0; |
| 12562 | } |
| 12563 | } |
| 12564 | |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 12565 | private void recordShutdownLocked(final long elapsedRealtimeMs, final long uptimeMs) { |
| 12566 | if (mRecordingHistory) { |
| 12567 | mHistoryCur.currentTime = System.currentTimeMillis(); |
Narayan Kamath | 5a5a7fe | 2018-02-05 17:30:06 +0000 | [diff] [blame] | 12568 | addHistoryBufferLocked(elapsedRealtimeMs, HistoryItem.CMD_SHUTDOWN, mHistoryCur); |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 12569 | mHistoryCur.currentTime = 0; |
| 12570 | } |
| 12571 | } |
| 12572 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 12573 | private void scheduleSyncExternalStatsLocked(String reason, int updateFlags) { |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 12574 | if (mExternalSync != null) { |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 12575 | mExternalSync.scheduleSync(reason, updateFlags); |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 12576 | } |
| 12577 | } |
| 12578 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 12579 | // This should probably be exposed in the API, though it's not critical |
Bookatz | 1a1b046 | 2018-01-12 11:47:03 -0800 | [diff] [blame] | 12580 | public static final int BATTERY_PLUGGED_NONE = OsProtoEnums.BATTERY_PLUGGED_NONE; // = 0 |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 12581 | |
Andreas Gampe | 3f24e69 | 2018-02-05 13:24:28 -0800 | [diff] [blame] | 12582 | @GuardedBy("this") |
Bookatz | 8c6571b | 2017-10-24 15:04:41 -0700 | [diff] [blame] | 12583 | public void setBatteryStateLocked(final int status, final int health, final int plugType, |
| 12584 | final int level, /* not final */ int temp, final int volt, final int chargeUAh, |
| 12585 | final int chargeFullUAh) { |
Adam Lesinski | 29ddfe5 | 2017-03-29 19:29:00 -0700 | [diff] [blame] | 12586 | // Temperature is encoded without the signed bit, so clamp any negative temperatures to 0. |
| 12587 | temp = Math.max(0, temp); |
| 12588 | |
Bookatz | 8c6571b | 2017-10-24 15:04:41 -0700 | [diff] [blame] | 12589 | reportChangesToStatsLog(mHaveBatteryLevel ? mHistoryCur : null, |
Tej Singh | 4029831 | 2018-02-16 00:15:09 -0800 | [diff] [blame^] | 12590 | status, plugType, level); |
Bookatz | 8c6571b | 2017-10-24 15:04:41 -0700 | [diff] [blame] | 12591 | |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 12592 | final boolean onBattery = isOnBattery(plugType, status); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 12593 | final long uptime = mClocks.uptimeMillis(); |
| 12594 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 12595 | if (!mHaveBatteryLevel) { |
| 12596 | mHaveBatteryLevel = true; |
| 12597 | // We start out assuming that the device is plugged in (not |
| 12598 | // on battery). If our first report is now that we are indeed |
| 12599 | // plugged in, then twiddle our state to correctly reflect that |
| 12600 | // since we won't be going through the full setOnBattery(). |
| 12601 | if (onBattery == mOnBattery) { |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 12602 | if (onBattery) { |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 12603 | mHistoryCur.states &= ~HistoryItem.STATE_BATTERY_PLUGGED_FLAG; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 12604 | } else { |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 12605 | mHistoryCur.states |= HistoryItem.STATE_BATTERY_PLUGGED_FLAG; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 12606 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 12607 | } |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 12608 | // Always start out assuming charging, that will be updated later. |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 12609 | mHistoryCur.states2 |= HistoryItem.STATE2_CHARGING_FLAG; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 12610 | mHistoryCur.batteryStatus = (byte)status; |
| 12611 | mHistoryCur.batteryLevel = (byte)level; |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 12612 | mHistoryCur.batteryChargeUAh = chargeUAh; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 12613 | mMaxChargeStepLevel = mMinDischargeStepLevel = |
| 12614 | mLastChargeStepLevel = mLastDischargeStepLevel = level; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 12615 | mLastChargingStateLevel = level; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 12616 | } else if (mCurrentBatteryLevel != level || mOnBattery != onBattery) { |
| 12617 | recordDailyStatsIfNeededLocked(level >= 100 && onBattery); |
| 12618 | } |
| 12619 | int oldStatus = mHistoryCur.batteryStatus; |
| 12620 | if (onBattery) { |
| 12621 | mDischargeCurrentLevel = level; |
| 12622 | if (!mRecordingHistory) { |
| 12623 | mRecordingHistory = true; |
| 12624 | startRecordingHistory(elapsedRealtime, uptime, true); |
| 12625 | } |
Todd Poynor | 1acf06a | 2017-12-07 19:19:35 -0800 | [diff] [blame] | 12626 | } else if (level < 96 && |
| 12627 | status != BatteryManager.BATTERY_STATUS_UNKNOWN) { |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 12628 | if (!mRecordingHistory) { |
| 12629 | mRecordingHistory = true; |
| 12630 | startRecordingHistory(elapsedRealtime, uptime, true); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 12631 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 12632 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 12633 | mCurrentBatteryLevel = level; |
| 12634 | if (mDischargePlugLevel < 0) { |
| 12635 | mDischargePlugLevel = level; |
Marco Nelissen | d859331 | 2009-04-30 14:45:06 -0700 | [diff] [blame] | 12636 | } |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 12637 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 12638 | if (onBattery != mOnBattery) { |
| 12639 | mHistoryCur.batteryLevel = (byte)level; |
| 12640 | mHistoryCur.batteryStatus = (byte)status; |
| 12641 | mHistoryCur.batteryHealth = (byte)health; |
| 12642 | mHistoryCur.batteryPlugType = (byte)plugType; |
| 12643 | mHistoryCur.batteryTemperature = (short)temp; |
| 12644 | mHistoryCur.batteryVoltage = (char)volt; |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 12645 | if (chargeUAh < mHistoryCur.batteryChargeUAh) { |
| 12646 | // Only record discharges |
| 12647 | final long chargeDiff = mHistoryCur.batteryChargeUAh - chargeUAh; |
| 12648 | mDischargeCounter.addCountLocked(chargeDiff); |
| 12649 | mDischargeScreenOffCounter.addCountLocked(chargeDiff); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 12650 | if (isScreenDoze(mScreenState)) { |
| 12651 | mDischargeScreenDozeCounter.addCountLocked(chargeDiff); |
| 12652 | } |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 12653 | if (mDeviceIdleMode == DEVICE_IDLE_MODE_LIGHT) { |
| 12654 | mDischargeLightDozeCounter.addCountLocked(chargeDiff); |
| 12655 | } else if (mDeviceIdleMode == DEVICE_IDLE_MODE_DEEP) { |
| 12656 | mDischargeDeepDozeCounter.addCountLocked(chargeDiff); |
| 12657 | } |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 12658 | } |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 12659 | mHistoryCur.batteryChargeUAh = chargeUAh; |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 12660 | setOnBatteryLocked(elapsedRealtime, uptime, onBattery, oldStatus, level, chargeUAh); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 12661 | } else { |
| 12662 | boolean changed = false; |
| 12663 | if (mHistoryCur.batteryLevel != level) { |
| 12664 | mHistoryCur.batteryLevel = (byte)level; |
| 12665 | changed = true; |
Marco Nelissen | d859331 | 2009-04-30 14:45:06 -0700 | [diff] [blame] | 12666 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 12667 | // TODO(adamlesinski): Schedule the creation of a HistoryStepDetails record |
| 12668 | // which will pull external stats. |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 12669 | scheduleSyncExternalStatsLocked("battery-level", ExternalStatsSync.UPDATE_ALL); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 12670 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 12671 | if (mHistoryCur.batteryStatus != status) { |
| 12672 | mHistoryCur.batteryStatus = (byte)status; |
| 12673 | changed = true; |
| 12674 | } |
| 12675 | if (mHistoryCur.batteryHealth != health) { |
| 12676 | mHistoryCur.batteryHealth = (byte)health; |
| 12677 | changed = true; |
| 12678 | } |
| 12679 | if (mHistoryCur.batteryPlugType != plugType) { |
| 12680 | mHistoryCur.batteryPlugType = (byte)plugType; |
| 12681 | changed = true; |
| 12682 | } |
| 12683 | if (temp >= (mHistoryCur.batteryTemperature+10) |
| 12684 | || temp <= (mHistoryCur.batteryTemperature-10)) { |
| 12685 | mHistoryCur.batteryTemperature = (short)temp; |
| 12686 | changed = true; |
| 12687 | } |
| 12688 | if (volt > (mHistoryCur.batteryVoltage+20) |
| 12689 | || volt < (mHistoryCur.batteryVoltage-20)) { |
| 12690 | mHistoryCur.batteryVoltage = (char)volt; |
| 12691 | changed = true; |
| 12692 | } |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 12693 | if (chargeUAh >= (mHistoryCur.batteryChargeUAh+10) |
| 12694 | || chargeUAh <= (mHistoryCur.batteryChargeUAh-10)) { |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 12695 | if (chargeUAh < mHistoryCur.batteryChargeUAh) { |
| 12696 | // Only record discharges |
| 12697 | final long chargeDiff = mHistoryCur.batteryChargeUAh - chargeUAh; |
| 12698 | mDischargeCounter.addCountLocked(chargeDiff); |
| 12699 | mDischargeScreenOffCounter.addCountLocked(chargeDiff); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 12700 | if (isScreenDoze(mScreenState)) { |
| 12701 | mDischargeScreenDozeCounter.addCountLocked(chargeDiff); |
| 12702 | } |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 12703 | if (mDeviceIdleMode == DEVICE_IDLE_MODE_LIGHT) { |
| 12704 | mDischargeLightDozeCounter.addCountLocked(chargeDiff); |
| 12705 | } else if (mDeviceIdleMode == DEVICE_IDLE_MODE_DEEP) { |
| 12706 | mDischargeDeepDozeCounter.addCountLocked(chargeDiff); |
| 12707 | } |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 12708 | } |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 12709 | mHistoryCur.batteryChargeUAh = chargeUAh; |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 12710 | changed = true; |
| 12711 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 12712 | long modeBits = (((long)mInitStepMode) << STEP_LEVEL_INITIAL_MODE_SHIFT) |
| 12713 | | (((long)mModStepMode) << STEP_LEVEL_MODIFIED_MODE_SHIFT) |
| 12714 | | (((long)(level&0xff)) << STEP_LEVEL_LEVEL_SHIFT); |
| 12715 | if (onBattery) { |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 12716 | changed |= setChargingLocked(false); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 12717 | if (mLastDischargeStepLevel != level && mMinDischargeStepLevel > level) { |
| 12718 | mDischargeStepTracker.addLevelSteps(mLastDischargeStepLevel - level, |
| 12719 | modeBits, elapsedRealtime); |
| 12720 | mDailyDischargeStepTracker.addLevelSteps(mLastDischargeStepLevel - level, |
| 12721 | modeBits, elapsedRealtime); |
| 12722 | mLastDischargeStepLevel = level; |
| 12723 | mMinDischargeStepLevel = level; |
| 12724 | mInitStepMode = mCurStepMode; |
| 12725 | mModStepMode = 0; |
| 12726 | } |
| 12727 | } else { |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 12728 | if (level >= 90) { |
| 12729 | // If the battery level is at least 90%, always consider the device to be |
| 12730 | // charging even if it happens to go down a level. |
| 12731 | changed |= setChargingLocked(true); |
| 12732 | mLastChargeStepLevel = level; |
| 12733 | } if (!mCharging) { |
| 12734 | if (mLastChargeStepLevel < level) { |
| 12735 | // We have not reporting that we are charging, but the level has now |
| 12736 | // gone up, so consider the state to be charging. |
| 12737 | changed |= setChargingLocked(true); |
| 12738 | mLastChargeStepLevel = level; |
| 12739 | } |
| 12740 | } else { |
| 12741 | if (mLastChargeStepLevel > level) { |
| 12742 | // We had reported that the device was charging, but here we are with |
| 12743 | // power connected and the level going down. Looks like the current |
| 12744 | // power supplied isn't enough, so consider the device to now be |
| 12745 | // discharging. |
| 12746 | changed |= setChargingLocked(false); |
| 12747 | mLastChargeStepLevel = level; |
| 12748 | } |
| 12749 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 12750 | if (mLastChargeStepLevel != level && mMaxChargeStepLevel < level) { |
| 12751 | mChargeStepTracker.addLevelSteps(level - mLastChargeStepLevel, |
| 12752 | modeBits, elapsedRealtime); |
| 12753 | mDailyChargeStepTracker.addLevelSteps(level - mLastChargeStepLevel, |
| 12754 | modeBits, elapsedRealtime); |
| 12755 | mLastChargeStepLevel = level; |
| 12756 | mMaxChargeStepLevel = level; |
| 12757 | mInitStepMode = mCurStepMode; |
| 12758 | mModStepMode = 0; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 12759 | } |
| 12760 | } |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 12761 | if (changed) { |
| 12762 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 12763 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 12764 | } |
Todd Poynor | 1acf06a | 2017-12-07 19:19:35 -0800 | [diff] [blame] | 12765 | if (!onBattery && |
| 12766 | (status == BatteryManager.BATTERY_STATUS_FULL || |
| 12767 | status == BatteryManager.BATTERY_STATUS_UNKNOWN)) { |
| 12768 | // We don't record history while we are plugged in and fully charged |
| 12769 | // (or when battery is not present). The next time we are |
| 12770 | // unplugged, history will be cleared. |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 12771 | mRecordingHistory = DEBUG; |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 12772 | } |
Adam Lesinski | 041d917 | 2016-12-12 12:03:56 -0800 | [diff] [blame] | 12773 | |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 12774 | if (mMinLearnedBatteryCapacity == -1) { |
| 12775 | mMinLearnedBatteryCapacity = chargeFullUAh; |
| 12776 | } else { |
| 12777 | Math.min(mMinLearnedBatteryCapacity, chargeFullUAh); |
Adam Lesinski | 041d917 | 2016-12-12 12:03:56 -0800 | [diff] [blame] | 12778 | } |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 12779 | mMaxLearnedBatteryCapacity = Math.max(mMaxLearnedBatteryCapacity, chargeFullUAh); |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 12780 | } |
| 12781 | |
Sudheer Shanka | c57729a | 2018-02-09 15:44:42 -0800 | [diff] [blame] | 12782 | public static boolean isOnBattery(int plugType, int status) { |
| 12783 | return plugType == BATTERY_PLUGGED_NONE && status != BatteryManager.BATTERY_STATUS_UNKNOWN; |
| 12784 | } |
| 12785 | |
Bookatz | 8c6571b | 2017-10-24 15:04:41 -0700 | [diff] [blame] | 12786 | // Inform StatsLog of setBatteryState changes. |
| 12787 | // If this is the first reporting, pass in recentPast == null. |
| 12788 | private void reportChangesToStatsLog(HistoryItem recentPast, |
Tej Singh | 4029831 | 2018-02-16 00:15:09 -0800 | [diff] [blame^] | 12789 | final int status, final int plugType, final int level) { |
Bookatz | 8c6571b | 2017-10-24 15:04:41 -0700 | [diff] [blame] | 12790 | |
| 12791 | if (recentPast == null || recentPast.batteryStatus != status) { |
| 12792 | StatsLog.write(StatsLog.CHARGING_STATE_CHANGED, status); |
| 12793 | } |
| 12794 | if (recentPast == null || recentPast.batteryPlugType != plugType) { |
| 12795 | StatsLog.write(StatsLog.PLUGGED_STATE_CHANGED, plugType); |
| 12796 | } |
| 12797 | if (recentPast == null || recentPast.batteryLevel != level) { |
| 12798 | StatsLog.write(StatsLog.BATTERY_LEVEL_CHANGED, level); |
| 12799 | } |
Bookatz | 8c6571b | 2017-10-24 15:04:41 -0700 | [diff] [blame] | 12800 | } |
| 12801 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12802 | public long getAwakeTimeBattery() { |
| 12803 | return computeBatteryUptime(getBatteryUptimeLocked(), STATS_CURRENT); |
| 12804 | } |
| 12805 | |
| 12806 | public long getAwakeTimePlugged() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 12807 | return (mClocks.uptimeMillis() * 1000) - getAwakeTimeBattery(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12808 | } |
| 12809 | |
| 12810 | @Override |
| 12811 | public long computeUptime(long curTime, int which) { |
| 12812 | switch (which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 12813 | case STATS_SINCE_CHARGED: return mUptime + (curTime-mUptimeStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12814 | case STATS_CURRENT: return (curTime-mUptimeStart); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 12815 | case STATS_SINCE_UNPLUGGED: return (curTime-mOnBatteryTimeBase.getUptimeStart()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12816 | } |
| 12817 | return 0; |
| 12818 | } |
| 12819 | |
| 12820 | @Override |
| 12821 | public long computeRealtime(long curTime, int which) { |
| 12822 | switch (which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 12823 | case STATS_SINCE_CHARGED: return mRealtime + (curTime-mRealtimeStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12824 | case STATS_CURRENT: return (curTime-mRealtimeStart); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 12825 | case STATS_SINCE_UNPLUGGED: return (curTime-mOnBatteryTimeBase.getRealtimeStart()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12826 | } |
| 12827 | return 0; |
| 12828 | } |
| 12829 | |
| 12830 | @Override |
| 12831 | public long computeBatteryUptime(long curTime, int which) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 12832 | return mOnBatteryTimeBase.computeUptime(curTime, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12833 | } |
| 12834 | |
| 12835 | @Override |
| 12836 | public long computeBatteryRealtime(long curTime, int which) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 12837 | return mOnBatteryTimeBase.computeRealtime(curTime, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12838 | } |
| 12839 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 12840 | @Override |
| 12841 | public long computeBatteryScreenOffUptime(long curTime, int which) { |
| 12842 | return mOnBatteryScreenOffTimeBase.computeUptime(curTime, which); |
| 12843 | } |
| 12844 | |
| 12845 | @Override |
| 12846 | public long computeBatteryScreenOffRealtime(long curTime, int which) { |
| 12847 | return mOnBatteryScreenOffTimeBase.computeRealtime(curTime, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12848 | } |
| 12849 | |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 12850 | private long computeTimePerLevel(long[] steps, int numSteps) { |
| 12851 | // For now we'll do a simple average across all steps. |
| 12852 | if (numSteps <= 0) { |
| 12853 | return -1; |
| 12854 | } |
| 12855 | long total = 0; |
| 12856 | for (int i=0; i<numSteps; i++) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 12857 | total += steps[i] & STEP_LEVEL_TIME_MASK; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 12858 | } |
| 12859 | return total / numSteps; |
| 12860 | /* |
| 12861 | long[] buckets = new long[numSteps]; |
| 12862 | int numBuckets = 0; |
| 12863 | int numToAverage = 4; |
| 12864 | int i = 0; |
| 12865 | while (i < numSteps) { |
| 12866 | long totalTime = 0; |
| 12867 | int num = 0; |
| 12868 | for (int j=0; j<numToAverage && (i+j)<numSteps; j++) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 12869 | totalTime += steps[i+j] & STEP_LEVEL_TIME_MASK; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 12870 | num++; |
| 12871 | } |
| 12872 | buckets[numBuckets] = totalTime / num; |
| 12873 | numBuckets++; |
| 12874 | numToAverage *= 2; |
| 12875 | i += num; |
| 12876 | } |
| 12877 | if (numBuckets < 1) { |
| 12878 | return -1; |
| 12879 | } |
| 12880 | long averageTime = buckets[numBuckets-1]; |
| 12881 | for (i=numBuckets-2; i>=0; i--) { |
| 12882 | averageTime = (averageTime + buckets[i]) / 2; |
| 12883 | } |
| 12884 | return averageTime; |
| 12885 | */ |
| 12886 | } |
| 12887 | |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 12888 | @Override |
| 12889 | public long computeBatteryTimeRemaining(long curTime) { |
| 12890 | if (!mOnBattery) { |
| 12891 | return -1; |
| 12892 | } |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 12893 | /* Simple implementation just looks at the average discharge per level across the |
| 12894 | entire sample period. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 12895 | int discharge = (getLowDischargeAmountSinceCharge()+getHighDischargeAmountSinceCharge())/2; |
| 12896 | if (discharge < 2) { |
| 12897 | return -1; |
| 12898 | } |
| 12899 | long duration = computeBatteryRealtime(curTime, STATS_SINCE_CHARGED); |
| 12900 | if (duration < 1000*1000) { |
| 12901 | return -1; |
| 12902 | } |
| 12903 | long usPerLevel = duration/discharge; |
| 12904 | return usPerLevel * mCurrentBatteryLevel; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 12905 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 12906 | if (mDischargeStepTracker.mNumStepDurations < 1) { |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 12907 | return -1; |
| 12908 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 12909 | long msPerLevel = mDischargeStepTracker.computeTimePerLevel(); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 12910 | if (msPerLevel <= 0) { |
| 12911 | return -1; |
| 12912 | } |
| 12913 | return (msPerLevel * mCurrentBatteryLevel) * 1000; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 12914 | } |
| 12915 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 12916 | @Override |
| 12917 | public LevelStepTracker getDischargeLevelStepTracker() { |
| 12918 | return mDischargeStepTracker; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 12919 | } |
| 12920 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 12921 | @Override |
| 12922 | public LevelStepTracker getDailyDischargeLevelStepTracker() { |
| 12923 | return mDailyDischargeStepTracker; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 12924 | } |
| 12925 | |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 12926 | @Override |
| 12927 | public long computeChargeTimeRemaining(long curTime) { |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 12928 | if (mOnBattery) { |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 12929 | // Not yet working. |
| 12930 | return -1; |
| 12931 | } |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 12932 | /* Broken |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 12933 | int curLevel = mCurrentBatteryLevel; |
| 12934 | int plugLevel = mDischargePlugLevel; |
| 12935 | if (plugLevel < 0 || curLevel < (plugLevel+1)) { |
| 12936 | return -1; |
| 12937 | } |
| 12938 | long duration = computeBatteryRealtime(curTime, STATS_SINCE_UNPLUGGED); |
| 12939 | if (duration < 1000*1000) { |
| 12940 | return -1; |
| 12941 | } |
| 12942 | long usPerLevel = duration/(curLevel-plugLevel); |
| 12943 | return usPerLevel * (100-curLevel); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 12944 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 12945 | if (mChargeStepTracker.mNumStepDurations < 1) { |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 12946 | return -1; |
| 12947 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 12948 | long msPerLevel = mChargeStepTracker.computeTimePerLevel(); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 12949 | if (msPerLevel <= 0) { |
| 12950 | return -1; |
| 12951 | } |
| 12952 | return (msPerLevel * (100-mCurrentBatteryLevel)) * 1000; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 12953 | } |
| 12954 | |
Siddharth Ray | a1fd057 | 2017-11-13 14:20:47 -0800 | [diff] [blame] | 12955 | /*@hide */ |
| 12956 | public CellularBatteryStats getCellularBatteryStats() { |
| 12957 | CellularBatteryStats s = new CellularBatteryStats(); |
| 12958 | final int which = STATS_SINCE_CHARGED; |
| 12959 | final long rawRealTime = SystemClock.elapsedRealtime() * 1000; |
| 12960 | final ControllerActivityCounter counter = getModemControllerActivity(); |
| 12961 | final long idleTimeMs = counter.getIdleTimeCounter().getCountLocked(which); |
| 12962 | final long rxTimeMs = counter.getRxTimeCounter().getCountLocked(which); |
| 12963 | final long energyConsumedMaMs = counter.getPowerCounter().getCountLocked(which); |
| 12964 | long[] timeInRatMs = new long[BatteryStats.NUM_DATA_CONNECTION_TYPES]; |
| 12965 | for (int i = 0; i < timeInRatMs.length; i++) { |
| 12966 | timeInRatMs[i] = getPhoneDataConnectionTime(i, rawRealTime, which) / 1000; |
| 12967 | } |
| 12968 | long[] timeInRxSignalStrengthLevelMs = new long[SignalStrength.NUM_SIGNAL_STRENGTH_BINS]; |
| 12969 | for (int i = 0; i < timeInRxSignalStrengthLevelMs.length; i++) { |
| 12970 | timeInRxSignalStrengthLevelMs[i] |
| 12971 | = getPhoneSignalStrengthTime(i, rawRealTime, which) / 1000; |
| 12972 | } |
| 12973 | long[] txTimeMs = new long[Math.min(ModemActivityInfo.TX_POWER_LEVELS, |
| 12974 | counter.getTxTimeCounters().length)]; |
| 12975 | long totalTxTimeMs = 0; |
| 12976 | for (int i = 0; i < txTimeMs.length; i++) { |
| 12977 | txTimeMs[i] = counter.getTxTimeCounters()[i].getCountLocked(which); |
| 12978 | totalTxTimeMs += txTimeMs[i]; |
| 12979 | } |
| 12980 | final long totalControllerActivityTimeMs |
| 12981 | = computeBatteryRealtime(SystemClock.elapsedRealtime() * 1000, which) / 1000; |
| 12982 | final long sleepTimeMs |
| 12983 | = totalControllerActivityTimeMs - (idleTimeMs + rxTimeMs + totalTxTimeMs); |
| 12984 | s.setLoggingDurationMs(computeBatteryRealtime(rawRealTime, which) / 1000); |
| 12985 | s.setKernelActiveTimeMs(getMobileRadioActiveTime(rawRealTime, which) / 1000); |
| 12986 | s.setNumPacketsTx(getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which)); |
| 12987 | s.setNumBytesTx(getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which)); |
| 12988 | s.setNumPacketsRx(getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which)); |
| 12989 | s.setNumBytesRx(getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which)); |
| 12990 | s.setSleepTimeMs(sleepTimeMs); |
| 12991 | s.setIdleTimeMs(idleTimeMs); |
| 12992 | s.setRxTimeMs(rxTimeMs); |
| 12993 | s.setEnergyConsumedMaMs(energyConsumedMaMs); |
| 12994 | s.setTimeInRatMs(timeInRatMs); |
| 12995 | s.setTimeInRxSignalStrengthLevelMs(timeInRxSignalStrengthLevelMs); |
| 12996 | s.setTxTimeMs(txTimeMs); |
| 12997 | return s; |
| 12998 | } |
| 12999 | |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 13000 | /*@hide */ |
| 13001 | public WifiBatteryStats getWifiBatteryStats() { |
| 13002 | WifiBatteryStats s = new WifiBatteryStats(); |
| 13003 | final int which = STATS_SINCE_CHARGED; |
| 13004 | final long rawRealTime = SystemClock.elapsedRealtime() * 1000; |
| 13005 | final ControllerActivityCounter counter = getWifiControllerActivity(); |
| 13006 | final long idleTimeMs = counter.getIdleTimeCounter().getCountLocked(which); |
| 13007 | final long scanTimeMs = counter.getScanTimeCounter().getCountLocked(which); |
| 13008 | final long rxTimeMs = counter.getRxTimeCounter().getCountLocked(which); |
| 13009 | final long txTimeMs = counter.getTxTimeCounters()[0].getCountLocked(which); |
| 13010 | final long totalControllerActivityTimeMs |
| 13011 | = computeBatteryRealtime(SystemClock.elapsedRealtime() * 1000, which) / 1000; |
| 13012 | final long sleepTimeMs |
| 13013 | = totalControllerActivityTimeMs - (idleTimeMs + rxTimeMs + txTimeMs); |
| 13014 | final long energyConsumedMaMs = counter.getPowerCounter().getCountLocked(which); |
| 13015 | long numAppScanRequest = 0; |
| 13016 | for (int i = 0; i < mUidStats.size(); i++) { |
| 13017 | numAppScanRequest += mUidStats.valueAt(i).mWifiScanTimer.getCountLocked(which); |
| 13018 | } |
| 13019 | long[] timeInStateMs = new long[NUM_WIFI_STATES]; |
| 13020 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 13021 | timeInStateMs[i] = getWifiStateTime(i, rawRealTime, which) / 1000; |
| 13022 | } |
| 13023 | long[] timeInSupplStateMs = new long[NUM_WIFI_SUPPL_STATES]; |
| 13024 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 13025 | timeInSupplStateMs[i] = getWifiSupplStateTime(i, rawRealTime, which) / 1000; |
| 13026 | } |
| 13027 | long[] timeSignalStrengthTimeMs = new long[NUM_WIFI_SIGNAL_STRENGTH_BINS]; |
| 13028 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 13029 | timeSignalStrengthTimeMs[i] = getWifiSignalStrengthTime(i, rawRealTime, which) / 1000; |
| 13030 | } |
| 13031 | s.setLoggingDurationMs(computeBatteryRealtime(rawRealTime, which) / 1000); |
| 13032 | s.setKernelActiveTimeMs(getWifiActiveTime(rawRealTime, which) / 1000); |
| 13033 | s.setNumPacketsTx(getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which)); |
| 13034 | s.setNumBytesTx(getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which)); |
| 13035 | s.setNumPacketsRx(getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which)); |
| 13036 | s.setNumBytesRx(getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which)); |
| 13037 | s.setSleepTimeMs(sleepTimeMs); |
| 13038 | s.setIdleTimeMs(idleTimeMs); |
| 13039 | s.setRxTimeMs(rxTimeMs); |
| 13040 | s.setTxTimeMs(txTimeMs); |
| 13041 | s.setScanTimeMs(scanTimeMs); |
| 13042 | s.setEnergyConsumedMaMs(energyConsumedMaMs); |
| 13043 | s.setNumAppScanRequest(numAppScanRequest); |
| 13044 | s.setTimeInStateMs(timeInStateMs); |
| 13045 | s.setTimeInSupplicantStateMs(timeInSupplStateMs); |
| 13046 | s.setTimeInRxSignalStrengthLevelMs(timeSignalStrengthTimeMs); |
| 13047 | return s; |
| 13048 | } |
| 13049 | |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 13050 | /*@hide */ |
| 13051 | public GpsBatteryStats getGpsBatteryStats() { |
| 13052 | GpsBatteryStats s = new GpsBatteryStats(); |
| 13053 | final int which = STATS_SINCE_CHARGED; |
| 13054 | final long rawRealTime = SystemClock.elapsedRealtime() * 1000; |
| 13055 | s.setLoggingDurationMs(computeBatteryRealtime(rawRealTime, which) / 1000); |
| 13056 | s.setEnergyConsumedMaMs(getGpsBatteryDrainMaMs()); |
| 13057 | long[] time = new long[GnssMetrics.NUM_GPS_SIGNAL_QUALITY_LEVELS]; |
| 13058 | for (int i=0; i<time.length; i++) { |
| 13059 | time[i] = getGpsSignalQualityTime(i, rawRealTime, which) / 1000; |
| 13060 | } |
| 13061 | s.setTimeInGpsSignalQualityLevel(time); |
| 13062 | return s; |
| 13063 | } |
| 13064 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 13065 | @Override |
| 13066 | public LevelStepTracker getChargeLevelStepTracker() { |
| 13067 | return mChargeStepTracker; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 13068 | } |
| 13069 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 13070 | @Override |
| 13071 | public LevelStepTracker getDailyChargeLevelStepTracker() { |
| 13072 | return mDailyChargeStepTracker; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 13073 | } |
| 13074 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 13075 | @Override |
| 13076 | public ArrayList<PackageChange> getDailyPackageChanges() { |
| 13077 | return mDailyPackageChanges; |
| 13078 | } |
| 13079 | |
Joe Onorato | e1acd63 | 2016-02-23 13:25:10 -0800 | [diff] [blame] | 13080 | protected long getBatteryUptimeLocked() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 13081 | return mOnBatteryTimeBase.getUptime(mClocks.uptimeMillis() * 1000); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13082 | } |
| 13083 | |
| 13084 | @Override |
| 13085 | public long getBatteryUptime(long curTime) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 13086 | return mOnBatteryTimeBase.getUptime(curTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13087 | } |
| 13088 | |
| 13089 | @Override |
| 13090 | public long getBatteryRealtime(long curTime) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 13091 | return mOnBatteryTimeBase.getRealtime(curTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13092 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 13093 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 13094 | @Override |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 13095 | public int getDischargeStartLevel() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 13096 | synchronized(this) { |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 13097 | return getDischargeStartLevelLocked(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 13098 | } |
| 13099 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 13100 | |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 13101 | public int getDischargeStartLevelLocked() { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 13102 | return mDischargeUnplugLevel; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 13103 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 13104 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 13105 | @Override |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 13106 | public int getDischargeCurrentLevel() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 13107 | synchronized(this) { |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 13108 | return getDischargeCurrentLevelLocked(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 13109 | } |
| 13110 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 13111 | |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 13112 | public int getDischargeCurrentLevelLocked() { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 13113 | return mDischargeCurrentLevel; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 13114 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13115 | |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 13116 | @Override |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 13117 | public int getLowDischargeAmountSinceCharge() { |
| 13118 | synchronized(this) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 13119 | int val = mLowDischargeAmountSinceCharge; |
| 13120 | if (mOnBattery && mDischargeCurrentLevel < mDischargeUnplugLevel) { |
| 13121 | val += mDischargeUnplugLevel-mDischargeCurrentLevel-1; |
| 13122 | } |
| 13123 | return val; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 13124 | } |
| 13125 | } |
| 13126 | |
| 13127 | @Override |
| 13128 | public int getHighDischargeAmountSinceCharge() { |
| 13129 | synchronized(this) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 13130 | int val = mHighDischargeAmountSinceCharge; |
| 13131 | if (mOnBattery && mDischargeCurrentLevel < mDischargeUnplugLevel) { |
| 13132 | val += mDischargeUnplugLevel-mDischargeCurrentLevel; |
| 13133 | } |
| 13134 | return val; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 13135 | } |
| 13136 | } |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 13137 | |
| 13138 | @Override |
| 13139 | public int getDischargeAmount(int which) { |
| 13140 | int dischargeAmount = which == STATS_SINCE_CHARGED |
| 13141 | ? getHighDischargeAmountSinceCharge() |
| 13142 | : (getDischargeStartLevel() - getDischargeCurrentLevel()); |
| 13143 | if (dischargeAmount < 0) { |
| 13144 | dischargeAmount = 0; |
| 13145 | } |
| 13146 | return dischargeAmount; |
| 13147 | } |
| 13148 | |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 13149 | @Override |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 13150 | public int getDischargeAmountScreenOn() { |
| 13151 | synchronized(this) { |
| 13152 | int val = mDischargeAmountScreenOn; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 13153 | if (mOnBattery && isScreenOn(mScreenState) |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 13154 | && mDischargeCurrentLevel < mDischargeScreenOnUnplugLevel) { |
| 13155 | val += mDischargeScreenOnUnplugLevel-mDischargeCurrentLevel; |
| 13156 | } |
| 13157 | return val; |
| 13158 | } |
| 13159 | } |
| 13160 | |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 13161 | @Override |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 13162 | public int getDischargeAmountScreenOnSinceCharge() { |
| 13163 | synchronized(this) { |
| 13164 | int val = mDischargeAmountScreenOnSinceCharge; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 13165 | if (mOnBattery && isScreenOn(mScreenState) |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 13166 | && mDischargeCurrentLevel < mDischargeScreenOnUnplugLevel) { |
| 13167 | val += mDischargeScreenOnUnplugLevel-mDischargeCurrentLevel; |
| 13168 | } |
| 13169 | return val; |
| 13170 | } |
| 13171 | } |
| 13172 | |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 13173 | @Override |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 13174 | public int getDischargeAmountScreenOff() { |
| 13175 | synchronized(this) { |
| 13176 | int val = mDischargeAmountScreenOff; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 13177 | if (mOnBattery && isScreenOff(mScreenState) |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 13178 | && mDischargeCurrentLevel < mDischargeScreenOffUnplugLevel) { |
| 13179 | val += mDischargeScreenOffUnplugLevel-mDischargeCurrentLevel; |
| 13180 | } |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 13181 | // For backward compatibility, doze discharge is counted into screen off. |
| 13182 | return val + getDischargeAmountScreenDoze(); |
| 13183 | } |
| 13184 | } |
| 13185 | |
| 13186 | @Override |
| 13187 | public int getDischargeAmountScreenOffSinceCharge() { |
| 13188 | synchronized(this) { |
| 13189 | int val = mDischargeAmountScreenOffSinceCharge; |
| 13190 | if (mOnBattery && isScreenOff(mScreenState) |
| 13191 | && mDischargeCurrentLevel < mDischargeScreenOffUnplugLevel) { |
| 13192 | val += mDischargeScreenOffUnplugLevel-mDischargeCurrentLevel; |
| 13193 | } |
| 13194 | // For backward compatibility, doze discharge is counted into screen off. |
| 13195 | return val + getDischargeAmountScreenDozeSinceCharge(); |
| 13196 | } |
| 13197 | } |
| 13198 | |
| 13199 | @Override |
| 13200 | public int getDischargeAmountScreenDoze() { |
| 13201 | synchronized(this) { |
| 13202 | int val = mDischargeAmountScreenDoze; |
| 13203 | if (mOnBattery && isScreenDoze(mScreenState) |
| 13204 | && mDischargeCurrentLevel < mDischargeScreenDozeUnplugLevel) { |
| 13205 | val += mDischargeScreenDozeUnplugLevel-mDischargeCurrentLevel; |
| 13206 | } |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 13207 | return val; |
| 13208 | } |
| 13209 | } |
| 13210 | |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 13211 | @Override |
| 13212 | public int getDischargeAmountScreenDozeSinceCharge() { |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 13213 | synchronized(this) { |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 13214 | int val = mDischargeAmountScreenDozeSinceCharge; |
| 13215 | if (mOnBattery && isScreenDoze(mScreenState) |
| 13216 | && mDischargeCurrentLevel < mDischargeScreenDozeUnplugLevel) { |
| 13217 | val += mDischargeScreenDozeUnplugLevel-mDischargeCurrentLevel; |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 13218 | } |
| 13219 | return val; |
| 13220 | } |
| 13221 | } |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 13222 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13223 | /** |
| 13224 | * Retrieve the statistics object for a particular uid, creating if needed. |
| 13225 | */ |
| 13226 | public Uid getUidStatsLocked(int uid) { |
| 13227 | Uid u = mUidStats.get(uid); |
| 13228 | if (u == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 13229 | u = new Uid(this, uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13230 | mUidStats.put(uid, u); |
| 13231 | } |
| 13232 | return u; |
| 13233 | } |
| 13234 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 13235 | /** |
| 13236 | * Retrieve the statistics object for a particular uid. Returns null if the object is not |
| 13237 | * available. |
| 13238 | */ |
| 13239 | public Uid getAvailableUidStatsLocked(int uid) { |
| 13240 | Uid u = mUidStats.get(uid); |
| 13241 | return u; |
| 13242 | } |
| 13243 | |
Suprabh Shukla | e6e723d | 2017-06-14 16:14:43 -0700 | [diff] [blame] | 13244 | public void onCleanupUserLocked(int userId) { |
| 13245 | final int firstUidForUser = UserHandle.getUid(userId, 0); |
| 13246 | final int lastUidForUser = UserHandle.getUid(userId, UserHandle.PER_USER_RANGE - 1); |
| 13247 | mKernelUidCpuFreqTimeReader.removeUidsInRange(firstUidForUser, lastUidForUser); |
| 13248 | mKernelUidCpuTimeReader.removeUidsInRange(firstUidForUser, lastUidForUser); |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 13249 | if (mKernelSingleUidTimeReader != null) { |
| 13250 | mKernelSingleUidTimeReader.removeUidsInRange(firstUidForUser, lastUidForUser); |
| 13251 | } |
Suprabh Shukla | e6e723d | 2017-06-14 16:14:43 -0700 | [diff] [blame] | 13252 | } |
| 13253 | |
| 13254 | public void onUserRemovedLocked(int userId) { |
| 13255 | final int firstUidForUser = UserHandle.getUid(userId, 0); |
| 13256 | final int lastUidForUser = UserHandle.getUid(userId, UserHandle.PER_USER_RANGE - 1); |
| 13257 | mUidStats.put(firstUidForUser, null); |
| 13258 | mUidStats.put(lastUidForUser, null); |
| 13259 | final int firstIndex = mUidStats.indexOfKey(firstUidForUser); |
| 13260 | final int lastIndex = mUidStats.indexOfKey(lastUidForUser); |
| 13261 | mUidStats.removeAtRange(firstIndex, lastIndex - firstIndex + 1); |
| 13262 | } |
| 13263 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13264 | /** |
| 13265 | * Remove the statistics object for a particular uid. |
| 13266 | */ |
| 13267 | public void removeUidStatsLocked(int uid) { |
Adam Lesinski | b83ffee | 2015-05-12 14:43:47 -0700 | [diff] [blame] | 13268 | mKernelUidCpuTimeReader.removeUid(uid); |
Sudheer Shanka | 6d8dcec | 2017-06-01 12:09:03 -0700 | [diff] [blame] | 13269 | mKernelUidCpuFreqTimeReader.removeUid(uid); |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 13270 | if (mKernelSingleUidTimeReader != null) { |
| 13271 | mKernelSingleUidTimeReader.removeUid(uid); |
| 13272 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13273 | mUidStats.remove(uid); |
| 13274 | } |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 13275 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13276 | /** |
| 13277 | * Retrieve the statistics object for a particular process, creating |
| 13278 | * if needed. |
| 13279 | */ |
| 13280 | public Uid.Proc getProcessStatsLocked(int uid, String name) { |
Dianne Hackborn | bbb7472 | 2014-03-13 09:50:24 -0700 | [diff] [blame] | 13281 | uid = mapUid(uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13282 | Uid u = getUidStatsLocked(uid); |
| 13283 | return u.getProcessStatsLocked(name); |
| 13284 | } |
| 13285 | |
| 13286 | /** |
| 13287 | * Retrieve the statistics object for a particular process, creating |
| 13288 | * if needed. |
| 13289 | */ |
| 13290 | public Uid.Pkg getPackageStatsLocked(int uid, String pkg) { |
Dianne Hackborn | bbb7472 | 2014-03-13 09:50:24 -0700 | [diff] [blame] | 13291 | uid = mapUid(uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13292 | Uid u = getUidStatsLocked(uid); |
| 13293 | return u.getPackageStatsLocked(pkg); |
| 13294 | } |
| 13295 | |
| 13296 | /** |
| 13297 | * Retrieve the statistics object for a particular service, creating |
| 13298 | * if needed. |
| 13299 | */ |
| 13300 | public Uid.Pkg.Serv getServiceStatsLocked(int uid, String pkg, String name) { |
Dianne Hackborn | bbb7472 | 2014-03-13 09:50:24 -0700 | [diff] [blame] | 13301 | uid = mapUid(uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13302 | Uid u = getUidStatsLocked(uid); |
| 13303 | return u.getServiceStatsLocked(pkg, name); |
| 13304 | } |
| 13305 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 13306 | public void shutdownLocked() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 13307 | recordShutdownLocked(mClocks.elapsedRealtime(), mClocks.uptimeMillis()); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 13308 | writeSyncLocked(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 13309 | mShuttingDown = true; |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 13310 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 13311 | |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 13312 | public boolean trackPerProcStateCpuTimes() { |
| 13313 | return mConstants.TRACK_CPU_TIMES_BY_PROC_STATE && mPerProcStateCpuTimesAvailable; |
| 13314 | } |
| 13315 | |
| 13316 | public void systemServicesReady(Context context) { |
| 13317 | mConstants.startObserving(context.getContentResolver()); |
| 13318 | } |
| 13319 | |
| 13320 | @VisibleForTesting |
| 13321 | public final class Constants extends ContentObserver { |
| 13322 | public static final String KEY_TRACK_CPU_TIMES_BY_PROC_STATE |
| 13323 | = "track_cpu_times_by_proc_state"; |
Mike Ma | fae87da | 2018-01-19 20:07:20 -0800 | [diff] [blame] | 13324 | public static final String KEY_TRACK_CPU_ACTIVE_CLUSTER_TIME |
| 13325 | = "track_cpu_active_cluster_time"; |
| 13326 | public static final String KEY_READ_BINARY_CPU_TIME |
| 13327 | = "read_binary_cpu_time"; |
Sudheer Shanka | c20379e | 2018-02-15 00:06:21 -0800 | [diff] [blame] | 13328 | public static final String KEY_PROC_STATE_CPU_TIMES_READ_DELAY_MS |
| 13329 | = "proc_state_cpu_times_read_delay_ms"; |
Mike Ma | 2ab0144 | 2018-02-13 14:22:47 -0800 | [diff] [blame] | 13330 | public static final String KEY_KERNEL_UID_READERS_THROTTLE_TIME |
| 13331 | = "kernel_uid_readers_throttle_time"; |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 13332 | |
| 13333 | private static final boolean DEFAULT_TRACK_CPU_TIMES_BY_PROC_STATE = true; |
Mike Ma | fae87da | 2018-01-19 20:07:20 -0800 | [diff] [blame] | 13334 | private static final boolean DEFAULT_TRACK_CPU_ACTIVE_CLUSTER_TIME = true; |
| 13335 | private static final boolean DEFAULT_READ_BINARY_CPU_TIME = false; |
Sudheer Shanka | c20379e | 2018-02-15 00:06:21 -0800 | [diff] [blame] | 13336 | private static final long DEFAULT_PROC_STATE_CPU_TIMES_READ_DELAY_MS = 5_000; |
Mike Ma | 2ab0144 | 2018-02-13 14:22:47 -0800 | [diff] [blame] | 13337 | private static final long DEFAULT_KERNEL_UID_READERS_THROTTLE_TIME = 10_000; |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 13338 | |
| 13339 | 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] | 13340 | public boolean TRACK_CPU_ACTIVE_CLUSTER_TIME = DEFAULT_TRACK_CPU_ACTIVE_CLUSTER_TIME; |
Mike Ma | fae87da | 2018-01-19 20:07:20 -0800 | [diff] [blame] | 13341 | public boolean READ_BINARY_CPU_TIME = DEFAULT_READ_BINARY_CPU_TIME; |
Sudheer Shanka | c20379e | 2018-02-15 00:06:21 -0800 | [diff] [blame] | 13342 | public long PROC_STATE_CPU_TIMES_READ_DELAY_MS = DEFAULT_PROC_STATE_CPU_TIMES_READ_DELAY_MS; |
Mike Ma | 2ab0144 | 2018-02-13 14:22:47 -0800 | [diff] [blame] | 13343 | public long KERNEL_UID_READERS_THROTTLE_TIME = DEFAULT_KERNEL_UID_READERS_THROTTLE_TIME; |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 13344 | |
| 13345 | private ContentResolver mResolver; |
| 13346 | private final KeyValueListParser mParser = new KeyValueListParser(','); |
| 13347 | |
| 13348 | public Constants(Handler handler) { |
| 13349 | super(handler); |
| 13350 | } |
| 13351 | |
| 13352 | public void startObserving(ContentResolver resolver) { |
| 13353 | mResolver = resolver; |
| 13354 | mResolver.registerContentObserver( |
| 13355 | Settings.Global.getUriFor(Settings.Global.BATTERY_STATS_CONSTANTS), |
| 13356 | false /* notifyForDescendants */, this); |
| 13357 | updateConstants(); |
| 13358 | } |
| 13359 | |
| 13360 | @Override |
| 13361 | public void onChange(boolean selfChange, Uri uri) { |
| 13362 | updateConstants(); |
| 13363 | } |
| 13364 | |
| 13365 | private void updateConstants() { |
| 13366 | synchronized (BatteryStatsImpl.this) { |
| 13367 | try { |
| 13368 | mParser.setString(Settings.Global.getString(mResolver, |
| 13369 | Settings.Global.BATTERY_STATS_CONSTANTS)); |
| 13370 | } catch (IllegalArgumentException e) { |
| 13371 | // Failed to parse the settings string, log this and move on |
| 13372 | // with defaults. |
| 13373 | Slog.e(TAG, "Bad batterystats settings", e); |
| 13374 | } |
| 13375 | |
| 13376 | updateTrackCpuTimesByProcStateLocked(TRACK_CPU_TIMES_BY_PROC_STATE, |
| 13377 | mParser.getBoolean(KEY_TRACK_CPU_TIMES_BY_PROC_STATE, |
| 13378 | DEFAULT_TRACK_CPU_TIMES_BY_PROC_STATE)); |
Mike Ma | fae87da | 2018-01-19 20:07:20 -0800 | [diff] [blame] | 13379 | TRACK_CPU_ACTIVE_CLUSTER_TIME = mParser.getBoolean( |
| 13380 | KEY_TRACK_CPU_ACTIVE_CLUSTER_TIME, DEFAULT_TRACK_CPU_ACTIVE_CLUSTER_TIME); |
Mike Ma | 2ab0144 | 2018-02-13 14:22:47 -0800 | [diff] [blame] | 13381 | updateReadBinaryCpuTime(READ_BINARY_CPU_TIME, |
| 13382 | mParser.getBoolean(KEY_READ_BINARY_CPU_TIME, DEFAULT_READ_BINARY_CPU_TIME)); |
Sudheer Shanka | c20379e | 2018-02-15 00:06:21 -0800 | [diff] [blame] | 13383 | updateProcStateCpuTimesReadDelayMs(PROC_STATE_CPU_TIMES_READ_DELAY_MS, |
| 13384 | mParser.getLong(KEY_PROC_STATE_CPU_TIMES_READ_DELAY_MS, |
Mike Ma | 2ab0144 | 2018-02-13 14:22:47 -0800 | [diff] [blame] | 13385 | DEFAULT_PROC_STATE_CPU_TIMES_READ_DELAY_MS)); |
| 13386 | updateKernelUidReadersThrottleTime(KERNEL_UID_READERS_THROTTLE_TIME, |
| 13387 | mParser.getLong(KEY_KERNEL_UID_READERS_THROTTLE_TIME, |
| 13388 | DEFAULT_KERNEL_UID_READERS_THROTTLE_TIME)); |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 13389 | } |
| 13390 | } |
| 13391 | |
| 13392 | private void updateTrackCpuTimesByProcStateLocked(boolean wasEnabled, boolean isEnabled) { |
| 13393 | TRACK_CPU_TIMES_BY_PROC_STATE = isEnabled; |
| 13394 | if (isEnabled && !wasEnabled) { |
| 13395 | mKernelSingleUidTimeReader.markDataAsStale(true); |
| 13396 | mExternalSync.scheduleCpuSyncDueToSettingChange(); |
Sudheer Shanka | c20379e | 2018-02-15 00:06:21 -0800 | [diff] [blame] | 13397 | |
| 13398 | mNumCpuTimeReads = 0; |
| 13399 | mNumBatchedCpuTimeReads = 0; |
| 13400 | mCpuTimeReadsTrackingStartTime = mClocks.uptimeMillis(); |
| 13401 | } |
| 13402 | } |
| 13403 | |
Mike Ma | 2ab0144 | 2018-02-13 14:22:47 -0800 | [diff] [blame] | 13404 | private void updateReadBinaryCpuTime(boolean oldEnabled, boolean isEnabled) { |
| 13405 | READ_BINARY_CPU_TIME = isEnabled; |
| 13406 | if (oldEnabled != isEnabled) { |
| 13407 | mKernelUidCpuFreqTimeReader.setReadBinary(isEnabled); |
| 13408 | } |
| 13409 | } |
| 13410 | |
Sudheer Shanka | c20379e | 2018-02-15 00:06:21 -0800 | [diff] [blame] | 13411 | private void updateProcStateCpuTimesReadDelayMs(long oldDelayMillis, long newDelayMillis) { |
| 13412 | PROC_STATE_CPU_TIMES_READ_DELAY_MS = newDelayMillis; |
| 13413 | if (oldDelayMillis != newDelayMillis) { |
| 13414 | mNumCpuTimeReads = 0; |
| 13415 | mNumBatchedCpuTimeReads = 0; |
| 13416 | mCpuTimeReadsTrackingStartTime = mClocks.uptimeMillis(); |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 13417 | } |
| 13418 | } |
| 13419 | |
Mike Ma | 2ab0144 | 2018-02-13 14:22:47 -0800 | [diff] [blame] | 13420 | private void updateKernelUidReadersThrottleTime(long oldTimeMs, long newTimeMs) { |
| 13421 | KERNEL_UID_READERS_THROTTLE_TIME = newTimeMs; |
| 13422 | if (oldTimeMs != newTimeMs) { |
| 13423 | mKernelUidCpuFreqTimeReader.setThrottleInterval(KERNEL_UID_READERS_THROTTLE_TIME); |
| 13424 | mKernelUidCpuActiveTimeReader.setThrottleInterval(KERNEL_UID_READERS_THROTTLE_TIME); |
| 13425 | mKernelUidCpuClusterTimeReader |
| 13426 | .setThrottleInterval(KERNEL_UID_READERS_THROTTLE_TIME); |
| 13427 | } |
| 13428 | } |
| 13429 | |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 13430 | public void dumpLocked(PrintWriter pw) { |
| 13431 | pw.print(KEY_TRACK_CPU_TIMES_BY_PROC_STATE); pw.print("="); |
| 13432 | pw.println(TRACK_CPU_TIMES_BY_PROC_STATE); |
Mike Ma | fae87da | 2018-01-19 20:07:20 -0800 | [diff] [blame] | 13433 | pw.print(KEY_TRACK_CPU_ACTIVE_CLUSTER_TIME); pw.print("="); |
| 13434 | pw.println(TRACK_CPU_ACTIVE_CLUSTER_TIME); |
| 13435 | pw.print(KEY_READ_BINARY_CPU_TIME); pw.print("="); |
| 13436 | pw.println(READ_BINARY_CPU_TIME); |
Sudheer Shanka | c20379e | 2018-02-15 00:06:21 -0800 | [diff] [blame] | 13437 | pw.print(KEY_PROC_STATE_CPU_TIMES_READ_DELAY_MS); pw.print("="); |
| 13438 | pw.println(PROC_STATE_CPU_TIMES_READ_DELAY_MS); |
Mike Ma | 2ab0144 | 2018-02-13 14:22:47 -0800 | [diff] [blame] | 13439 | pw.print(KEY_KERNEL_UID_READERS_THROTTLE_TIME); pw.print("="); |
| 13440 | pw.println(KERNEL_UID_READERS_THROTTLE_TIME); |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 13441 | } |
| 13442 | } |
| 13443 | |
Andreas Gampe | 3f24e69 | 2018-02-05 13:24:28 -0800 | [diff] [blame] | 13444 | @GuardedBy("this") |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 13445 | public void dumpConstantsLocked(PrintWriter pw) { |
| 13446 | mConstants.dumpLocked(pw); |
| 13447 | } |
| 13448 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 13449 | Parcel mPendingWrite = null; |
| 13450 | final ReentrantLock mWriteLock = new ReentrantLock(); |
| 13451 | |
| 13452 | public void writeAsyncLocked() { |
| 13453 | writeLocked(false); |
| 13454 | } |
| 13455 | |
| 13456 | public void writeSyncLocked() { |
| 13457 | writeLocked(true); |
| 13458 | } |
| 13459 | |
| 13460 | void writeLocked(boolean sync) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 13461 | if (mFile == null) { |
| 13462 | 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] | 13463 | return; |
| 13464 | } |
| 13465 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 13466 | if (mShuttingDown) { |
| 13467 | return; |
| 13468 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 13469 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 13470 | Parcel out = Parcel.obtain(); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 13471 | writeSummaryToParcel(out, true); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 13472 | mLastWriteTime = mClocks.elapsedRealtime(); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 13473 | |
| 13474 | if (mPendingWrite != null) { |
| 13475 | mPendingWrite.recycle(); |
| 13476 | } |
| 13477 | mPendingWrite = out; |
| 13478 | |
| 13479 | if (sync) { |
| 13480 | commitPendingDataToDisk(); |
| 13481 | } else { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 13482 | BackgroundThread.getHandler().post(new Runnable() { |
| 13483 | @Override public void run() { |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 13484 | commitPendingDataToDisk(); |
| 13485 | } |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 13486 | }); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 13487 | } |
| 13488 | } |
| 13489 | |
| 13490 | public void commitPendingDataToDisk() { |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 13491 | final Parcel next; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 13492 | synchronized (this) { |
| 13493 | next = mPendingWrite; |
| 13494 | mPendingWrite = null; |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 13495 | if (next == null) { |
| 13496 | return; |
| 13497 | } |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 13498 | } |
| 13499 | |
Amith Yamasani | d245086 | 2017-02-07 15:58:24 -0800 | [diff] [blame] | 13500 | mWriteLock.lock(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13501 | try { |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 13502 | final long startTime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 13503 | FileOutputStream stream = new FileOutputStream(mFile.chooseForWrite()); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 13504 | stream.write(next.marshall()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13505 | stream.flush(); |
Dianne Hackborn | 8bdf593 | 2010-10-15 12:54:40 -0700 | [diff] [blame] | 13506 | FileUtils.sync(stream); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13507 | stream.close(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 13508 | mFile.commit(); |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 13509 | com.android.internal.logging.EventLogTags.writeCommitSysConfigFile( |
| 13510 | "batterystats", SystemClock.uptimeMillis() - startTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13511 | } catch (IOException e) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 13512 | Slog.w("BatteryStats", "Error writing battery statistics", e); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 13513 | mFile.rollback(); |
| 13514 | } finally { |
| 13515 | next.recycle(); |
| 13516 | mWriteLock.unlock(); |
Suchi Amalapurapu | 8550f25 | 2009-09-29 15:20:32 -0700 | [diff] [blame] | 13517 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13518 | } |
| 13519 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13520 | public void readLocked() { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 13521 | if (mDailyFile != null) { |
| 13522 | readDailyStatsLocked(); |
| 13523 | } |
| 13524 | |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 13525 | if (mFile == null) { |
| 13526 | 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] | 13527 | return; |
| 13528 | } |
| 13529 | |
| 13530 | mUidStats.clear(); |
| 13531 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13532 | try { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 13533 | File file = mFile.chooseForRead(); |
| 13534 | if (!file.exists()) { |
| 13535 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13536 | } |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 13537 | FileInputStream stream = new FileInputStream(file); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13538 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 13539 | byte[] raw = BatteryStatsHelper.readFully(stream); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13540 | Parcel in = Parcel.obtain(); |
| 13541 | in.unmarshall(raw, 0, raw.length); |
| 13542 | in.setDataPosition(0); |
| 13543 | stream.close(); |
| 13544 | |
| 13545 | readSummaryFromParcel(in); |
Dianne Hackborn | 00e2521 | 2014-02-19 10:49:24 -0800 | [diff] [blame] | 13546 | } catch(Exception e) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 13547 | Slog.e("BatteryStats", "Error reading battery statistics", e); |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 13548 | resetAllStatsLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13549 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 13550 | |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 13551 | mEndPlatformVersion = Build.ID; |
| 13552 | |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 13553 | if (mHistoryBuffer.dataPosition() > 0) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 13554 | mRecordingHistory = true; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 13555 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 13556 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 13557 | if (USE_OLD_HISTORY) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 13558 | addHistoryRecordLocked(elapsedRealtime, uptime, HistoryItem.CMD_START, mHistoryCur); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 13559 | } |
Narayan Kamath | 5a5a7fe | 2018-02-05 17:30:06 +0000 | [diff] [blame] | 13560 | addHistoryBufferLocked(elapsedRealtime, HistoryItem.CMD_START, mHistoryCur); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 13561 | startRecordingHistory(elapsedRealtime, uptime, false); |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 13562 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 13563 | |
| 13564 | recordDailyStatsIfNeededLocked(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13565 | } |
| 13566 | |
| 13567 | public int describeContents() { |
| 13568 | return 0; |
| 13569 | } |
| 13570 | |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 13571 | void readHistory(Parcel in, boolean andOldHistory) throws ParcelFormatException { |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 13572 | final long historyBaseTime = in.readLong(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 13573 | |
| 13574 | mHistoryBuffer.setDataSize(0); |
| 13575 | mHistoryBuffer.setDataPosition(0); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 13576 | mHistoryTagPool.clear(); |
| 13577 | mNextHistoryTagIdx = 0; |
| 13578 | mNumHistoryTagChars = 0; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 13579 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 13580 | int numTags = in.readInt(); |
| 13581 | for (int i=0; i<numTags; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 13582 | int idx = in.readInt(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 13583 | String str = in.readString(); |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 13584 | if (str == null) { |
| 13585 | throw new ParcelFormatException("null history tag string"); |
| 13586 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 13587 | int uid = in.readInt(); |
| 13588 | HistoryTag tag = new HistoryTag(); |
| 13589 | tag.string = str; |
| 13590 | tag.uid = uid; |
| 13591 | tag.poolIdx = idx; |
| 13592 | mHistoryTagPool.put(tag, idx); |
| 13593 | if (idx >= mNextHistoryTagIdx) { |
| 13594 | mNextHistoryTagIdx = idx+1; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 13595 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 13596 | mNumHistoryTagChars += tag.string.length() + 1; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 13597 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 13598 | |
| 13599 | int bufSize = in.readInt(); |
| 13600 | int curPos = in.dataPosition(); |
| 13601 | if (bufSize >= (MAX_MAX_HISTORY_BUFFER*3)) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 13602 | throw new ParcelFormatException("File corrupt: history data buffer too large " + |
| 13603 | bufSize); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 13604 | } else if ((bufSize&~3) != bufSize) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 13605 | throw new ParcelFormatException("File corrupt: history data buffer not aligned " + |
| 13606 | bufSize); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 13607 | } else { |
| 13608 | if (DEBUG_HISTORY) Slog.i(TAG, "***************** READING NEW HISTORY: " + bufSize |
| 13609 | + " bytes at " + curPos); |
| 13610 | mHistoryBuffer.appendFrom(in, curPos, bufSize); |
| 13611 | in.setDataPosition(curPos + bufSize); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 13612 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 13613 | |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 13614 | if (andOldHistory) { |
| 13615 | readOldHistory(in); |
| 13616 | } |
| 13617 | |
| 13618 | if (DEBUG_HISTORY) { |
| 13619 | StringBuilder sb = new StringBuilder(128); |
| 13620 | sb.append("****************** OLD mHistoryBaseTime: "); |
| 13621 | TimeUtils.formatDuration(mHistoryBaseTime, sb); |
| 13622 | Slog.i(TAG, sb.toString()); |
| 13623 | } |
| 13624 | mHistoryBaseTime = historyBaseTime; |
| 13625 | if (DEBUG_HISTORY) { |
| 13626 | StringBuilder sb = new StringBuilder(128); |
| 13627 | sb.append("****************** NEW mHistoryBaseTime: "); |
| 13628 | TimeUtils.formatDuration(mHistoryBaseTime, sb); |
| 13629 | Slog.i(TAG, sb.toString()); |
| 13630 | } |
| 13631 | |
| 13632 | // We are just arbitrarily going to insert 1 minute from the sample of |
| 13633 | // the last run until samples in this run. |
| 13634 | if (mHistoryBaseTime > 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 13635 | long oldnow = mClocks.elapsedRealtime(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 13636 | mHistoryBaseTime = mHistoryBaseTime - oldnow + 1; |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 13637 | if (DEBUG_HISTORY) { |
| 13638 | StringBuilder sb = new StringBuilder(128); |
| 13639 | sb.append("****************** ADJUSTED mHistoryBaseTime: "); |
| 13640 | TimeUtils.formatDuration(mHistoryBaseTime, sb); |
| 13641 | Slog.i(TAG, sb.toString()); |
| 13642 | } |
Dianne Hackborn | 1e4b9f3 | 2010-06-23 14:10:57 -0700 | [diff] [blame] | 13643 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 13644 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 13645 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 13646 | void readOldHistory(Parcel in) { |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 13647 | if (!USE_OLD_HISTORY) { |
| 13648 | return; |
| 13649 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 13650 | mHistory = mHistoryEnd = mHistoryCache = null; |
| 13651 | long time; |
Conley Owens | 5e3357f | 2011-05-02 09:59:30 -0700 | [diff] [blame] | 13652 | while (in.dataAvail() > 0 && (time=in.readLong()) >= 0) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 13653 | HistoryItem rec = new HistoryItem(time, in); |
| 13654 | addHistoryRecordLocked(rec); |
| 13655 | } |
| 13656 | } |
| 13657 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 13658 | void writeHistory(Parcel out, boolean inclData, boolean andOldHistory) { |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 13659 | if (DEBUG_HISTORY) { |
| 13660 | StringBuilder sb = new StringBuilder(128); |
| 13661 | sb.append("****************** WRITING mHistoryBaseTime: "); |
| 13662 | TimeUtils.formatDuration(mHistoryBaseTime, sb); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 13663 | sb.append(" mLastHistoryElapsedRealtime: "); |
| 13664 | TimeUtils.formatDuration(mLastHistoryElapsedRealtime, sb); |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 13665 | Slog.i(TAG, sb.toString()); |
| 13666 | } |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 13667 | out.writeLong(mHistoryBaseTime + mLastHistoryElapsedRealtime); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 13668 | if (!inclData) { |
| 13669 | out.writeInt(0); |
| 13670 | out.writeInt(0); |
| 13671 | return; |
| 13672 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 13673 | out.writeInt(mHistoryTagPool.size()); |
| 13674 | for (HashMap.Entry<HistoryTag, Integer> ent : mHistoryTagPool.entrySet()) { |
| 13675 | HistoryTag tag = ent.getKey(); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 13676 | out.writeInt(ent.getValue()); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 13677 | out.writeString(tag.string); |
| 13678 | out.writeInt(tag.uid); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 13679 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 13680 | out.writeInt(mHistoryBuffer.dataSize()); |
| 13681 | if (DEBUG_HISTORY) Slog.i(TAG, "***************** WRITING HISTORY: " |
| 13682 | + mHistoryBuffer.dataSize() + " bytes at " + out.dataPosition()); |
| 13683 | out.appendFrom(mHistoryBuffer, 0, mHistoryBuffer.dataSize()); |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 13684 | |
| 13685 | if (andOldHistory) { |
| 13686 | writeOldHistory(out); |
| 13687 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 13688 | } |
| 13689 | |
| 13690 | void writeOldHistory(Parcel out) { |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 13691 | if (!USE_OLD_HISTORY) { |
| 13692 | return; |
| 13693 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 13694 | HistoryItem rec = mHistory; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 13695 | while (rec != null) { |
| 13696 | if (rec.time >= 0) rec.writeToParcel(out, 0); |
| 13697 | rec = rec.next; |
| 13698 | } |
| 13699 | out.writeLong(-1); |
| 13700 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 13701 | |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 13702 | public void readSummaryFromParcel(Parcel in) throws ParcelFormatException { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13703 | final int version = in.readInt(); |
| 13704 | if (version != VERSION) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 13705 | Slog.w("BatteryStats", "readFromParcel: version got " + version |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13706 | + ", expected " + VERSION + "; erasing old stats"); |
| 13707 | return; |
| 13708 | } |
| 13709 | |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 13710 | readHistory(in, true); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 13711 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13712 | mStartCount = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13713 | mUptime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13714 | mRealtime = in.readLong(); |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 13715 | mStartClockTime = in.readLong(); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 13716 | mStartPlatformVersion = in.readString(); |
| 13717 | mEndPlatformVersion = in.readString(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 13718 | mOnBatteryTimeBase.readSummaryFromParcel(in); |
| 13719 | mOnBatteryScreenOffTimeBase.readSummaryFromParcel(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 13720 | mDischargeUnplugLevel = in.readInt(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 13721 | mDischargePlugLevel = in.readInt(); |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 13722 | mDischargeCurrentLevel = in.readInt(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 13723 | mCurrentBatteryLevel = in.readInt(); |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 13724 | mEstimatedBatteryCapacity = in.readInt(); |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 13725 | mMinLearnedBatteryCapacity = in.readInt(); |
| 13726 | mMaxLearnedBatteryCapacity = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 13727 | mLowDischargeAmountSinceCharge = in.readInt(); |
| 13728 | mHighDischargeAmountSinceCharge = in.readInt(); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 13729 | mDischargeAmountScreenOnSinceCharge = in.readInt(); |
| 13730 | mDischargeAmountScreenOffSinceCharge = in.readInt(); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 13731 | mDischargeAmountScreenDozeSinceCharge = in.readInt(); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 13732 | mDischargeStepTracker.readFromParcel(in); |
| 13733 | mChargeStepTracker.readFromParcel(in); |
| 13734 | mDailyDischargeStepTracker.readFromParcel(in); |
| 13735 | mDailyChargeStepTracker.readFromParcel(in); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 13736 | mDischargeCounter.readSummaryFromParcelLocked(in); |
| 13737 | mDischargeScreenOffCounter.readSummaryFromParcelLocked(in); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 13738 | mDischargeScreenDozeCounter.readSummaryFromParcelLocked(in); |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 13739 | mDischargeLightDozeCounter.readSummaryFromParcelLocked(in); |
| 13740 | mDischargeDeepDozeCounter.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 13741 | int NPKG = in.readInt(); |
| 13742 | if (NPKG > 0) { |
| 13743 | mDailyPackageChanges = new ArrayList<>(NPKG); |
| 13744 | while (NPKG > 0) { |
| 13745 | NPKG--; |
| 13746 | PackageChange pc = new PackageChange(); |
| 13747 | pc.mPackageName = in.readString(); |
| 13748 | pc.mUpdate = in.readInt() != 0; |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 13749 | pc.mVersionCode = in.readLong(); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 13750 | mDailyPackageChanges.add(pc); |
| 13751 | } |
| 13752 | } else { |
| 13753 | mDailyPackageChanges = null; |
| 13754 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 13755 | mDailyStartTime = in.readLong(); |
| 13756 | mNextMinDailyDeadline = in.readLong(); |
| 13757 | mNextMaxDailyDeadline = in.readLong(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 13758 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13759 | mStartCount++; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 13760 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 13761 | mScreenState = Display.STATE_UNKNOWN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13762 | mScreenOnTimer.readSummaryFromParcelLocked(in); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 13763 | mScreenDozeTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 13764 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
| 13765 | mScreenBrightnessTimer[i].readSummaryFromParcelLocked(in); |
| 13766 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 13767 | mInteractive = false; |
| 13768 | mInteractiveTimer.readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13769 | mPhoneOn = false; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 13770 | mPowerSaveModeEnabledTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 13771 | mLongestLightIdleTime = in.readLong(); |
| 13772 | mLongestFullIdleTime = in.readLong(); |
| 13773 | mDeviceIdleModeLightTimer.readSummaryFromParcelLocked(in); |
| 13774 | mDeviceIdleModeFullTimer.readSummaryFromParcelLocked(in); |
| 13775 | mDeviceLightIdlingTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 13776 | mDeviceIdlingTimer.readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13777 | mPhoneOnTimer.readSummaryFromParcelLocked(in); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 13778 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 13779 | mPhoneSignalStrengthsTimer[i].readSummaryFromParcelLocked(in); |
| 13780 | } |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 13781 | mPhoneSignalScanningTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 13782 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
| 13783 | mPhoneDataConnectionsTimer[i].readSummaryFromParcelLocked(in); |
| 13784 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 13785 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 13786 | mNetworkByteActivityCounters[i].readSummaryFromParcelLocked(in); |
| 13787 | mNetworkPacketActivityCounters[i].readSummaryFromParcelLocked(in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 13788 | } |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 13789 | mMobileRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 13790 | mMobileRadioActiveTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 13791 | mMobileRadioActivePerAppTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 13792 | mMobileRadioActiveAdjustedTime.readSummaryFromParcelLocked(in); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 13793 | mMobileRadioActiveUnknownTime.readSummaryFromParcelLocked(in); |
| 13794 | mMobileRadioActiveUnknownCount.readSummaryFromParcelLocked(in); |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 13795 | mWifiMulticastWakelockTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 13796 | mWifiRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 13797 | mWifiOn = false; |
| 13798 | mWifiOnTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 13799 | mGlobalWifiRunning = false; |
| 13800 | mGlobalWifiRunningTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 13801 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 13802 | mWifiStateTimer[i].readSummaryFromParcelLocked(in); |
| 13803 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 13804 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 13805 | mWifiSupplStateTimer[i].readSummaryFromParcelLocked(in); |
| 13806 | } |
| 13807 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 13808 | mWifiSignalStrengthsTimer[i].readSummaryFromParcelLocked(in); |
| 13809 | } |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 13810 | mWifiActiveTimer.readSummaryFromParcelLocked(in); |
| 13811 | mWifiActivity.readSummaryFromParcel(in); |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 13812 | for (int i=0; i<GnssMetrics.NUM_GPS_SIGNAL_QUALITY_LEVELS; i++) { |
| 13813 | mGpsSignalQualityTimer[i].readSummaryFromParcelLocked(in); |
| 13814 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 13815 | mBluetoothActivity.readSummaryFromParcel(in); |
| 13816 | mModemActivity.readSummaryFromParcel(in); |
| 13817 | mHasWifiReporting = in.readInt() != 0; |
| 13818 | mHasBluetoothReporting = in.readInt() != 0; |
| 13819 | mHasModemReporting = in.readInt() != 0; |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 13820 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 13821 | mNumConnectivityChange = mLoadedNumConnectivityChange = in.readInt(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 13822 | mFlashlightOnNesting = 0; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 13823 | mFlashlightOnTimer.readSummaryFromParcelLocked(in); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 13824 | mCameraOnNesting = 0; |
| 13825 | mCameraOnTimer.readSummaryFromParcelLocked(in); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 13826 | mBluetoothScanNesting = 0; |
| 13827 | mBluetoothScanTimer.readSummaryFromParcelLocked(in); |
Siddharth Ray | f5e796a | 2018-01-22 18:18:17 -0800 | [diff] [blame] | 13828 | mIsCellularTxPowerHigh = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13829 | |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 13830 | int NRPMS = in.readInt(); |
| 13831 | if (NRPMS > 10000) { |
| 13832 | throw new ParcelFormatException("File corrupt: too many rpm stats " + NRPMS); |
| 13833 | } |
| 13834 | for (int irpm = 0; irpm < NRPMS; irpm++) { |
| 13835 | if (in.readInt() != 0) { |
| 13836 | String rpmName = in.readString(); |
| 13837 | getRpmTimerLocked(rpmName).readSummaryFromParcelLocked(in); |
| 13838 | } |
| 13839 | } |
| 13840 | int NSORPMS = in.readInt(); |
| 13841 | if (NSORPMS > 10000) { |
| 13842 | throw new ParcelFormatException("File corrupt: too many screen-off rpm stats " + NSORPMS); |
| 13843 | } |
| 13844 | for (int irpm = 0; irpm < NSORPMS; irpm++) { |
| 13845 | if (in.readInt() != 0) { |
| 13846 | String rpmName = in.readString(); |
| 13847 | getScreenOffRpmTimerLocked(rpmName).readSummaryFromParcelLocked(in); |
| 13848 | } |
| 13849 | } |
| 13850 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 13851 | int NKW = in.readInt(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 13852 | if (NKW > 10000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 13853 | throw new ParcelFormatException("File corrupt: too many kernel wake locks " + NKW); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 13854 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 13855 | for (int ikw = 0; ikw < NKW; ikw++) { |
| 13856 | if (in.readInt() != 0) { |
| 13857 | String kwltName = in.readString(); |
| 13858 | getKernelWakelockTimerLocked(kwltName).readSummaryFromParcelLocked(in); |
| 13859 | } |
| 13860 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 13861 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 13862 | int NWR = in.readInt(); |
| 13863 | if (NWR > 10000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 13864 | throw new ParcelFormatException("File corrupt: too many wakeup reasons " + NWR); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 13865 | } |
| 13866 | for (int iwr = 0; iwr < NWR; iwr++) { |
| 13867 | if (in.readInt() != 0) { |
| 13868 | String reasonName = in.readString(); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 13869 | getWakeupReasonTimerLocked(reasonName).readSummaryFromParcelLocked(in); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 13870 | } |
| 13871 | } |
| 13872 | |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 13873 | int NMS = in.readInt(); |
| 13874 | for (int ims = 0; ims < NMS; ims++) { |
| 13875 | if (in.readInt() != 0) { |
| 13876 | long kmstName = in.readLong(); |
| 13877 | getKernelMemoryTimerLocked(kmstName).readSummaryFromParcelLocked(in); |
| 13878 | } |
| 13879 | } |
| 13880 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13881 | final int NU = in.readInt(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 13882 | if (NU > 10000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 13883 | throw new ParcelFormatException("File corrupt: too many uids " + NU); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 13884 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13885 | for (int iu = 0; iu < NU; iu++) { |
| 13886 | int uid = in.readInt(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 13887 | Uid u = new Uid(this, uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13888 | mUidStats.put(uid, u); |
| 13889 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 13890 | u.mOnBatteryBackgroundTimeBase.readSummaryFromParcel(in); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 13891 | u.mOnBatteryScreenOffBackgroundTimeBase.readSummaryFromParcel(in); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 13892 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 13893 | u.mWifiRunning = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 13894 | if (in.readInt() != 0) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 13895 | u.mWifiRunningTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 13896 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 13897 | u.mFullWifiLockOut = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 13898 | if (in.readInt() != 0) { |
| 13899 | u.mFullWifiLockTimer.readSummaryFromParcelLocked(in); |
| 13900 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 13901 | u.mWifiScanStarted = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 13902 | if (in.readInt() != 0) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 13903 | u.mWifiScanTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 13904 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 13905 | u.mWifiBatchedScanBinStarted = Uid.NO_BATCHED_SCAN_STARTED; |
| 13906 | for (int i = 0; i < Uid.NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 13907 | if (in.readInt() != 0) { |
| 13908 | u.makeWifiBatchedScanBin(i, null); |
| 13909 | u.mWifiBatchedScanTimer[i].readSummaryFromParcelLocked(in); |
| 13910 | } |
| 13911 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 13912 | u.mWifiMulticastEnabled = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 13913 | if (in.readInt() != 0) { |
| 13914 | u.mWifiMulticastTimer.readSummaryFromParcelLocked(in); |
| 13915 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 13916 | if (in.readInt() != 0) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 13917 | u.createAudioTurnedOnTimerLocked().readSummaryFromParcelLocked(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 13918 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 13919 | if (in.readInt() != 0) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 13920 | u.createVideoTurnedOnTimerLocked().readSummaryFromParcelLocked(in); |
| 13921 | } |
| 13922 | if (in.readInt() != 0) { |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 13923 | u.createFlashlightTurnedOnTimerLocked().readSummaryFromParcelLocked(in); |
| 13924 | } |
| 13925 | if (in.readInt() != 0) { |
| 13926 | u.createCameraTurnedOnTimerLocked().readSummaryFromParcelLocked(in); |
| 13927 | } |
| 13928 | if (in.readInt() != 0) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 13929 | u.createForegroundActivityTimerLocked().readSummaryFromParcelLocked(in); |
| 13930 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 13931 | if (in.readInt() != 0) { |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 13932 | u.createForegroundServiceTimerLocked().readSummaryFromParcelLocked(in); |
| 13933 | } |
| 13934 | if (in.readInt() != 0) { |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 13935 | u.createAggregatedPartialWakelockTimerLocked().readSummaryFromParcelLocked(in); |
| 13936 | } |
| 13937 | if (in.readInt() != 0) { |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 13938 | u.createBluetoothScanTimerLocked().readSummaryFromParcelLocked(in); |
| 13939 | } |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 13940 | if (in.readInt() != 0) { |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 13941 | u.createBluetoothUnoptimizedScanTimerLocked().readSummaryFromParcelLocked(in); |
| 13942 | } |
| 13943 | if (in.readInt() != 0) { |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 13944 | u.createBluetoothScanResultCounterLocked().readSummaryFromParcelLocked(in); |
| 13945 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 13946 | if (in.readInt() != 0) { |
| 13947 | u.createBluetoothScanResultBgCounterLocked().readSummaryFromParcelLocked(in); |
| 13948 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 13949 | u.mProcessState = ActivityManager.PROCESS_STATE_NONEXISTENT; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 13950 | for (int i = 0; i < Uid.NUM_PROCESS_STATE; i++) { |
| 13951 | if (in.readInt() != 0) { |
| 13952 | u.makeProcessState(i, null); |
| 13953 | u.mProcessStateTimer[i].readSummaryFromParcelLocked(in); |
| 13954 | } |
| 13955 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 13956 | if (in.readInt() != 0) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 13957 | u.createVibratorOnTimerLocked().readSummaryFromParcelLocked(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 13958 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 13959 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 13960 | if (in.readInt() != 0) { |
| 13961 | if (u.mUserActivityCounters == null) { |
| 13962 | u.initUserActivityLocked(); |
| 13963 | } |
| 13964 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
| 13965 | u.mUserActivityCounters[i].readSummaryFromParcelLocked(in); |
| 13966 | } |
| 13967 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 13968 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 13969 | if (in.readInt() != 0) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 13970 | if (u.mNetworkByteActivityCounters == null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 13971 | u.initNetworkActivityLocked(); |
| 13972 | } |
| 13973 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 13974 | u.mNetworkByteActivityCounters[i].readSummaryFromParcelLocked(in); |
| 13975 | u.mNetworkPacketActivityCounters[i].readSummaryFromParcelLocked(in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 13976 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 13977 | u.mMobileRadioActiveTime.readSummaryFromParcelLocked(in); |
| 13978 | u.mMobileRadioActiveCount.readSummaryFromParcelLocked(in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 13979 | } |
| 13980 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 13981 | u.mUserCpuTime.readSummaryFromParcelLocked(in); |
| 13982 | u.mSystemCpuTime.readSummaryFromParcelLocked(in); |
| 13983 | |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 13984 | if (in.readInt() != 0) { |
| 13985 | final int numClusters = in.readInt(); |
| 13986 | if (mPowerProfile != null && mPowerProfile.getNumCpuClusters() != numClusters) { |
| 13987 | throw new ParcelFormatException("Incompatible cpu cluster arrangement"); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 13988 | } |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 13989 | |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 13990 | u.mCpuClusterSpeedTimesUs = new LongSamplingCounter[numClusters][]; |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 13991 | for (int cluster = 0; cluster < numClusters; cluster++) { |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 13992 | if (in.readInt() != 0) { |
Adam Lesinski | a57a540 | 2015-09-28 10:21:33 -0700 | [diff] [blame] | 13993 | final int NSB = in.readInt(); |
| 13994 | if (mPowerProfile != null && |
| 13995 | mPowerProfile.getNumSpeedStepsInCpuCluster(cluster) != NSB) { |
| 13996 | throw new ParcelFormatException("File corrupt: too many speed bins " + |
| 13997 | NSB); |
| 13998 | } |
| 13999 | |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 14000 | u.mCpuClusterSpeedTimesUs[cluster] = new LongSamplingCounter[NSB]; |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 14001 | for (int speed = 0; speed < NSB; speed++) { |
| 14002 | if (in.readInt() != 0) { |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 14003 | u.mCpuClusterSpeedTimesUs[cluster][speed] = new LongSamplingCounter( |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 14004 | mOnBatteryTimeBase); |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 14005 | u.mCpuClusterSpeedTimesUs[cluster][speed].readSummaryFromParcelLocked(in); |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 14006 | } |
| 14007 | } |
Adam Lesinski | a57a540 | 2015-09-28 10:21:33 -0700 | [diff] [blame] | 14008 | } else { |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 14009 | u.mCpuClusterSpeedTimesUs[cluster] = null; |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 14010 | } |
| 14011 | } |
| 14012 | } else { |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 14013 | u.mCpuClusterSpeedTimesUs = null; |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 14014 | } |
| 14015 | |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 14016 | u.mCpuFreqTimeMs = LongSamplingCounterArray.readSummaryFromParcelLocked( |
| 14017 | in, mOnBatteryTimeBase); |
| 14018 | u.mScreenOffCpuFreqTimeMs = LongSamplingCounterArray.readSummaryFromParcelLocked( |
| 14019 | in, mOnBatteryScreenOffTimeBase); |
Mike Ma | 3d422c3 | 2017-10-25 11:08:57 -0700 | [diff] [blame] | 14020 | |
| 14021 | u.mCpuActiveTimeMs.readSummaryFromParcelLocked(in); |
| 14022 | u.mCpuClusterTimesMs.readSummaryFromParcelLocked(in); |
| 14023 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 14024 | int length = in.readInt(); |
| 14025 | if (length == Uid.NUM_PROCESS_STATE) { |
| 14026 | u.mProcStateTimeMs = new LongSamplingCounterArray[length]; |
| 14027 | for (int procState = 0; procState < length; ++procState) { |
| 14028 | u.mProcStateTimeMs[procState] |
| 14029 | = LongSamplingCounterArray.readSummaryFromParcelLocked( |
| 14030 | in, mOnBatteryTimeBase); |
| 14031 | } |
| 14032 | } else { |
| 14033 | u.mProcStateTimeMs = null; |
| 14034 | } |
| 14035 | length = in.readInt(); |
| 14036 | if (length == Uid.NUM_PROCESS_STATE) { |
| 14037 | u.mProcStateScreenOffTimeMs = new LongSamplingCounterArray[length]; |
| 14038 | for (int procState = 0; procState < length; ++procState) { |
| 14039 | u.mProcStateScreenOffTimeMs[procState] |
| 14040 | = LongSamplingCounterArray.readSummaryFromParcelLocked( |
| 14041 | in, mOnBatteryScreenOffTimeBase); |
| 14042 | } |
| 14043 | } else { |
| 14044 | u.mProcStateScreenOffTimeMs = null; |
| 14045 | } |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 14046 | |
| 14047 | if (in.readInt() != 0) { |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 14048 | u.mMobileRadioApWakeupCount = new LongSamplingCounter(mOnBatteryTimeBase); |
| 14049 | u.mMobileRadioApWakeupCount.readSummaryFromParcelLocked(in); |
| 14050 | } else { |
| 14051 | u.mMobileRadioApWakeupCount = null; |
| 14052 | } |
| 14053 | |
| 14054 | if (in.readInt() != 0) { |
| 14055 | u.mWifiRadioApWakeupCount = new LongSamplingCounter(mOnBatteryTimeBase); |
| 14056 | u.mWifiRadioApWakeupCount.readSummaryFromParcelLocked(in); |
| 14057 | } else { |
| 14058 | u.mWifiRadioApWakeupCount = null; |
| 14059 | } |
| 14060 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14061 | int NW = in.readInt(); |
Dianne Hackborn | cb99a72 | 2016-10-03 17:00:02 -0700 | [diff] [blame] | 14062 | if (NW > (MAX_WAKELOCKS_PER_UID+1)) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 14063 | throw new ParcelFormatException("File corrupt: too many wake locks " + NW); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 14064 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14065 | for (int iw = 0; iw < NW; iw++) { |
| 14066 | String wlName = in.readString(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 14067 | u.readWakeSummaryFromParcelLocked(wlName, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14068 | } |
| 14069 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 14070 | int NS = in.readInt(); |
Dianne Hackborn | cb99a72 | 2016-10-03 17:00:02 -0700 | [diff] [blame] | 14071 | if (NS > (MAX_WAKELOCKS_PER_UID+1)) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 14072 | throw new ParcelFormatException("File corrupt: too many syncs " + NS); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 14073 | } |
| 14074 | for (int is = 0; is < NS; is++) { |
| 14075 | String name = in.readString(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 14076 | u.readSyncSummaryFromParcelLocked(name, in); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 14077 | } |
| 14078 | |
| 14079 | int NJ = in.readInt(); |
Dianne Hackborn | cb99a72 | 2016-10-03 17:00:02 -0700 | [diff] [blame] | 14080 | if (NJ > (MAX_WAKELOCKS_PER_UID+1)) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 14081 | throw new ParcelFormatException("File corrupt: too many job timers " + NJ); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 14082 | } |
| 14083 | for (int ij = 0; ij < NJ; ij++) { |
| 14084 | String name = in.readString(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 14085 | u.readJobSummaryFromParcelLocked(name, in); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 14086 | } |
| 14087 | |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 14088 | u.readJobCompletionsFromParcelLocked(in); |
| 14089 | |
Amith Yamasani | 977e11f | 2018-02-16 11:29:54 -0800 | [diff] [blame] | 14090 | u.mJobsDeferredEventCount.readSummaryFromParcelLocked(in); |
| 14091 | u.mJobsDeferredCount.readSummaryFromParcelLocked(in); |
| 14092 | u.mJobsFreshnessTimeMs.readSummaryFromParcelLocked(in); |
| 14093 | for (int i = 0; i < JOB_FRESHNESS_BUCKETS.length; i++) { |
| 14094 | if (in.readInt() != 0) { |
| 14095 | u.mJobsFreshnessBuckets[i] = new Counter(u.mBsi.mOnBatteryTimeBase); |
| 14096 | u.mJobsFreshnessBuckets[i].readSummaryFromParcelLocked(in); |
| 14097 | } |
| 14098 | } |
| 14099 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14100 | int NP = in.readInt(); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 14101 | if (NP > 1000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 14102 | throw new ParcelFormatException("File corrupt: too many sensors " + NP); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 14103 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14104 | for (int is = 0; is < NP; is++) { |
| 14105 | int seNumber = in.readInt(); |
| 14106 | if (in.readInt() != 0) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 14107 | u.getSensorTimerLocked(seNumber, true).readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14108 | } |
| 14109 | } |
| 14110 | |
| 14111 | NP = in.readInt(); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 14112 | if (NP > 1000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 14113 | throw new ParcelFormatException("File corrupt: too many processes " + NP); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 14114 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14115 | for (int ip = 0; ip < NP; ip++) { |
| 14116 | String procName = in.readString(); |
| 14117 | Uid.Proc p = u.getProcessStatsLocked(procName); |
| 14118 | p.mUserTime = p.mLoadedUserTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14119 | p.mSystemTime = p.mLoadedSystemTime = in.readLong(); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 14120 | p.mForegroundTime = p.mLoadedForegroundTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14121 | p.mStarts = p.mLoadedStarts = in.readInt(); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 14122 | p.mNumCrashes = p.mLoadedNumCrashes = in.readInt(); |
| 14123 | p.mNumAnrs = p.mLoadedNumAnrs = in.readInt(); |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 14124 | p.readExcessivePowerFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14125 | } |
| 14126 | |
| 14127 | NP = in.readInt(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 14128 | if (NP > 10000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 14129 | throw new ParcelFormatException("File corrupt: too many packages " + NP); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 14130 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14131 | for (int ip = 0; ip < NP; ip++) { |
| 14132 | String pkgName = in.readString(); |
| 14133 | Uid.Pkg p = u.getPackageStatsLocked(pkgName); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 14134 | final int NWA = in.readInt(); |
| 14135 | if (NWA > 1000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 14136 | throw new ParcelFormatException("File corrupt: too many wakeup alarms " + NWA); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 14137 | } |
| 14138 | p.mWakeupAlarms.clear(); |
| 14139 | for (int iwa=0; iwa<NWA; iwa++) { |
| 14140 | String tag = in.readString(); |
Bookatz | 98d4d5c | 2017-08-01 19:07:54 -0700 | [diff] [blame] | 14141 | Counter c = new Counter(mOnBatteryScreenOffTimeBase); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 14142 | c.readSummaryFromParcelLocked(in); |
| 14143 | p.mWakeupAlarms.put(tag, c); |
| 14144 | } |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 14145 | NS = in.readInt(); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 14146 | if (NS > 1000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 14147 | throw new ParcelFormatException("File corrupt: too many services " + NS); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 14148 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14149 | for (int is = 0; is < NS; is++) { |
| 14150 | String servName = in.readString(); |
| 14151 | Uid.Pkg.Serv s = u.getServiceStatsLocked(pkgName, servName); |
| 14152 | s.mStartTime = s.mLoadedStartTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14153 | s.mStarts = s.mLoadedStarts = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14154 | s.mLaunches = s.mLoadedLaunches = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14155 | } |
| 14156 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14157 | } |
| 14158 | } |
| 14159 | |
| 14160 | /** |
| 14161 | * Writes a summary of the statistics to a Parcel, in a format suitable to be written to |
| 14162 | * disk. This format does not allow a lossless round-trip. |
| 14163 | * |
| 14164 | * @param out the Parcel to be written to. |
| 14165 | */ |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 14166 | public void writeSummaryToParcel(Parcel out, boolean inclHistory) { |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 14167 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 14168 | |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 14169 | // Pull the clock time. This may update the time and make a new history entry |
| 14170 | // if we had originally pulled a time before the RTC was set. |
| 14171 | long startClockTime = getStartClockTime(); |
| 14172 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14173 | final long NOW_SYS = mClocks.uptimeMillis() * 1000; |
| 14174 | final long NOWREAL_SYS = mClocks.elapsedRealtime() * 1000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14175 | |
| 14176 | out.writeInt(VERSION); |
| 14177 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 14178 | writeHistory(out, inclHistory, true); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 14179 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14180 | out.writeInt(mStartCount); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 14181 | out.writeLong(computeUptime(NOW_SYS, STATS_SINCE_CHARGED)); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 14182 | out.writeLong(computeRealtime(NOWREAL_SYS, STATS_SINCE_CHARGED)); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 14183 | out.writeLong(startClockTime); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 14184 | out.writeString(mStartPlatformVersion); |
| 14185 | out.writeString(mEndPlatformVersion); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14186 | mOnBatteryTimeBase.writeSummaryToParcel(out, NOW_SYS, NOWREAL_SYS); |
| 14187 | mOnBatteryScreenOffTimeBase.writeSummaryToParcel(out, NOW_SYS, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 14188 | out.writeInt(mDischargeUnplugLevel); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 14189 | out.writeInt(mDischargePlugLevel); |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 14190 | out.writeInt(mDischargeCurrentLevel); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 14191 | out.writeInt(mCurrentBatteryLevel); |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 14192 | out.writeInt(mEstimatedBatteryCapacity); |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 14193 | out.writeInt(mMinLearnedBatteryCapacity); |
| 14194 | out.writeInt(mMaxLearnedBatteryCapacity); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 14195 | out.writeInt(getLowDischargeAmountSinceCharge()); |
| 14196 | out.writeInt(getHighDischargeAmountSinceCharge()); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 14197 | out.writeInt(getDischargeAmountScreenOnSinceCharge()); |
| 14198 | out.writeInt(getDischargeAmountScreenOffSinceCharge()); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 14199 | out.writeInt(getDischargeAmountScreenDozeSinceCharge()); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 14200 | mDischargeStepTracker.writeToParcel(out); |
| 14201 | mChargeStepTracker.writeToParcel(out); |
| 14202 | mDailyDischargeStepTracker.writeToParcel(out); |
| 14203 | mDailyChargeStepTracker.writeToParcel(out); |
Adam Lesinski | 67c134f | 2016-06-10 15:15:08 -0700 | [diff] [blame] | 14204 | mDischargeCounter.writeSummaryFromParcelLocked(out); |
| 14205 | mDischargeScreenOffCounter.writeSummaryFromParcelLocked(out); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 14206 | mDischargeScreenDozeCounter.writeSummaryFromParcelLocked(out); |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 14207 | mDischargeLightDozeCounter.writeSummaryFromParcelLocked(out); |
| 14208 | mDischargeDeepDozeCounter.writeSummaryFromParcelLocked(out); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 14209 | if (mDailyPackageChanges != null) { |
| 14210 | final int NPKG = mDailyPackageChanges.size(); |
| 14211 | out.writeInt(NPKG); |
| 14212 | for (int i=0; i<NPKG; i++) { |
| 14213 | PackageChange pc = mDailyPackageChanges.get(i); |
| 14214 | out.writeString(pc.mPackageName); |
| 14215 | out.writeInt(pc.mUpdate ? 1 : 0); |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 14216 | out.writeLong(pc.mVersionCode); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 14217 | } |
| 14218 | } else { |
| 14219 | out.writeInt(0); |
| 14220 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 14221 | out.writeLong(mDailyStartTime); |
| 14222 | out.writeLong(mNextMinDailyDeadline); |
| 14223 | out.writeLong(mNextMaxDailyDeadline); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14224 | |
| 14225 | mScreenOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 14226 | mScreenDozeTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 14227 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14228 | mScreenBrightnessTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 14229 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 14230 | mInteractiveTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 14231 | mPowerSaveModeEnabledTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 14232 | out.writeLong(mLongestLightIdleTime); |
| 14233 | out.writeLong(mLongestFullIdleTime); |
| 14234 | mDeviceIdleModeLightTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14235 | mDeviceIdleModeFullTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14236 | mDeviceLightIdlingTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 14237 | mDeviceIdlingTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14238 | mPhoneOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 14239 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14240 | mPhoneSignalStrengthsTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 14241 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14242 | mPhoneSignalScanningTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 14243 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14244 | mPhoneDataConnectionsTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 14245 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 14246 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 14247 | mNetworkByteActivityCounters[i].writeSummaryFromParcelLocked(out); |
| 14248 | mNetworkPacketActivityCounters[i].writeSummaryFromParcelLocked(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 14249 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14250 | mMobileRadioActiveTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14251 | mMobileRadioActivePerAppTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 14252 | mMobileRadioActiveAdjustedTime.writeSummaryFromParcelLocked(out); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 14253 | mMobileRadioActiveUnknownTime.writeSummaryFromParcelLocked(out); |
| 14254 | mMobileRadioActiveUnknownCount.writeSummaryFromParcelLocked(out); |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 14255 | mWifiMulticastWakelockTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14256 | mWifiOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14257 | mGlobalWifiRunningTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 14258 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14259 | mWifiStateTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 14260 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 14261 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 14262 | mWifiSupplStateTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14263 | } |
| 14264 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 14265 | mWifiSignalStrengthsTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14266 | } |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 14267 | mWifiActiveTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14268 | mWifiActivity.writeSummaryToParcel(out); |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 14269 | for (int i=0; i< GnssMetrics.NUM_GPS_SIGNAL_QUALITY_LEVELS; i++) { |
| 14270 | mGpsSignalQualityTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14271 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 14272 | mBluetoothActivity.writeSummaryToParcel(out); |
| 14273 | mModemActivity.writeSummaryToParcel(out); |
| 14274 | out.writeInt(mHasWifiReporting ? 1 : 0); |
| 14275 | out.writeInt(mHasBluetoothReporting ? 1 : 0); |
| 14276 | out.writeInt(mHasModemReporting ? 1 : 0); |
| 14277 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 14278 | out.writeInt(mNumConnectivityChange); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 14279 | mFlashlightOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 14280 | mCameraOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 14281 | mBluetoothScanTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14282 | |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 14283 | out.writeInt(mRpmStats.size()); |
| 14284 | for (Map.Entry<String, SamplingTimer> ent : mRpmStats.entrySet()) { |
| 14285 | Timer rpmt = ent.getValue(); |
| 14286 | if (rpmt != null) { |
| 14287 | out.writeInt(1); |
| 14288 | out.writeString(ent.getKey()); |
| 14289 | rpmt.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14290 | } else { |
| 14291 | out.writeInt(0); |
| 14292 | } |
| 14293 | } |
| 14294 | out.writeInt(mScreenOffRpmStats.size()); |
| 14295 | for (Map.Entry<String, SamplingTimer> ent : mScreenOffRpmStats.entrySet()) { |
| 14296 | Timer rpmt = ent.getValue(); |
| 14297 | if (rpmt != null) { |
| 14298 | out.writeInt(1); |
| 14299 | out.writeString(ent.getKey()); |
| 14300 | rpmt.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14301 | } else { |
| 14302 | out.writeInt(0); |
| 14303 | } |
| 14304 | } |
| 14305 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 14306 | out.writeInt(mKernelWakelockStats.size()); |
| 14307 | for (Map.Entry<String, SamplingTimer> ent : mKernelWakelockStats.entrySet()) { |
| 14308 | Timer kwlt = ent.getValue(); |
| 14309 | if (kwlt != null) { |
| 14310 | out.writeInt(1); |
| 14311 | out.writeString(ent.getKey()); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 14312 | kwlt.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14313 | } else { |
| 14314 | out.writeInt(0); |
| 14315 | } |
| 14316 | } |
| 14317 | |
| 14318 | out.writeInt(mWakeupReasonStats.size()); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 14319 | for (Map.Entry<String, SamplingTimer> ent : mWakeupReasonStats.entrySet()) { |
| 14320 | SamplingTimer timer = ent.getValue(); |
| 14321 | if (timer != null) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 14322 | out.writeInt(1); |
| 14323 | out.writeString(ent.getKey()); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 14324 | timer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 14325 | } else { |
| 14326 | out.writeInt(0); |
| 14327 | } |
| 14328 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 14329 | |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 14330 | out.writeInt(mKernelMemoryStats.size()); |
| 14331 | for (int i = 0; i < mKernelMemoryStats.size(); i++) { |
| 14332 | Timer kmt = mKernelMemoryStats.valueAt(i); |
| 14333 | if (kmt != null) { |
| 14334 | out.writeInt(1); |
| 14335 | out.writeLong(mKernelMemoryStats.keyAt(i)); |
| 14336 | kmt.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14337 | } else { |
| 14338 | out.writeInt(0); |
| 14339 | } |
| 14340 | } |
| 14341 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14342 | final int NU = mUidStats.size(); |
| 14343 | out.writeInt(NU); |
| 14344 | for (int iu = 0; iu < NU; iu++) { |
| 14345 | out.writeInt(mUidStats.keyAt(iu)); |
| 14346 | Uid u = mUidStats.valueAt(iu); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 14347 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 14348 | u.mOnBatteryBackgroundTimeBase.writeSummaryToParcel(out, NOW_SYS, NOWREAL_SYS); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 14349 | u.mOnBatteryScreenOffBackgroundTimeBase.writeSummaryToParcel(out, NOW_SYS, NOWREAL_SYS); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 14350 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 14351 | if (u.mWifiRunningTimer != null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 14352 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14353 | u.mWifiRunningTimer.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.mFullWifiLockTimer != null) { |
| 14358 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14359 | u.mFullWifiLockTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 14360 | } else { |
| 14361 | out.writeInt(0); |
| 14362 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 14363 | if (u.mWifiScanTimer != null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 14364 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14365 | u.mWifiScanTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 14366 | } else { |
| 14367 | out.writeInt(0); |
| 14368 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 14369 | for (int i = 0; i < Uid.NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 14370 | if (u.mWifiBatchedScanTimer[i] != null) { |
| 14371 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14372 | u.mWifiBatchedScanTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 14373 | } else { |
| 14374 | out.writeInt(0); |
| 14375 | } |
| 14376 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 14377 | if (u.mWifiMulticastTimer != null) { |
| 14378 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14379 | u.mWifiMulticastTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 14380 | } else { |
| 14381 | out.writeInt(0); |
| 14382 | } |
| 14383 | if (u.mAudioTurnedOnTimer != null) { |
| 14384 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14385 | u.mAudioTurnedOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 14386 | } else { |
| 14387 | out.writeInt(0); |
| 14388 | } |
| 14389 | if (u.mVideoTurnedOnTimer != null) { |
| 14390 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14391 | u.mVideoTurnedOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 14392 | } else { |
| 14393 | out.writeInt(0); |
| 14394 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 14395 | if (u.mFlashlightTurnedOnTimer != null) { |
| 14396 | out.writeInt(1); |
| 14397 | u.mFlashlightTurnedOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14398 | } else { |
| 14399 | out.writeInt(0); |
| 14400 | } |
| 14401 | if (u.mCameraTurnedOnTimer != null) { |
| 14402 | out.writeInt(1); |
| 14403 | u.mCameraTurnedOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14404 | } else { |
| 14405 | out.writeInt(0); |
| 14406 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 14407 | if (u.mForegroundActivityTimer != null) { |
| 14408 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14409 | u.mForegroundActivityTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 14410 | } else { |
| 14411 | out.writeInt(0); |
| 14412 | } |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 14413 | if (u.mForegroundServiceTimer != null) { |
| 14414 | out.writeInt(1); |
| 14415 | u.mForegroundServiceTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14416 | } else { |
| 14417 | out.writeInt(0); |
| 14418 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 14419 | if (u.mAggregatedPartialWakelockTimer != null) { |
| 14420 | out.writeInt(1); |
| 14421 | u.mAggregatedPartialWakelockTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14422 | } else { |
| 14423 | out.writeInt(0); |
| 14424 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 14425 | if (u.mBluetoothScanTimer != null) { |
| 14426 | out.writeInt(1); |
| 14427 | u.mBluetoothScanTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14428 | } else { |
| 14429 | out.writeInt(0); |
| 14430 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 14431 | if (u.mBluetoothUnoptimizedScanTimer != null) { |
| 14432 | out.writeInt(1); |
| 14433 | u.mBluetoothUnoptimizedScanTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14434 | } else { |
| 14435 | out.writeInt(0); |
| 14436 | } |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 14437 | if (u.mBluetoothScanResultCounter != null) { |
| 14438 | out.writeInt(1); |
| 14439 | u.mBluetoothScanResultCounter.writeSummaryFromParcelLocked(out); |
| 14440 | } else { |
| 14441 | out.writeInt(0); |
| 14442 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 14443 | if (u.mBluetoothScanResultBgCounter != null) { |
| 14444 | out.writeInt(1); |
| 14445 | u.mBluetoothScanResultBgCounter.writeSummaryFromParcelLocked(out); |
| 14446 | } else { |
| 14447 | out.writeInt(0); |
| 14448 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 14449 | for (int i = 0; i < Uid.NUM_PROCESS_STATE; i++) { |
| 14450 | if (u.mProcessStateTimer[i] != null) { |
| 14451 | out.writeInt(1); |
| 14452 | u.mProcessStateTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14453 | } else { |
| 14454 | out.writeInt(0); |
| 14455 | } |
| 14456 | } |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 14457 | if (u.mVibratorOnTimer != null) { |
| 14458 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14459 | u.mVibratorOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 14460 | } else { |
| 14461 | out.writeInt(0); |
| 14462 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14463 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 14464 | if (u.mUserActivityCounters == null) { |
| 14465 | out.writeInt(0); |
| 14466 | } else { |
| 14467 | out.writeInt(1); |
| 14468 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
| 14469 | u.mUserActivityCounters[i].writeSummaryFromParcelLocked(out); |
| 14470 | } |
| 14471 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 14472 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 14473 | if (u.mNetworkByteActivityCounters == null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 14474 | out.writeInt(0); |
| 14475 | } else { |
| 14476 | out.writeInt(1); |
| 14477 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 14478 | u.mNetworkByteActivityCounters[i].writeSummaryFromParcelLocked(out); |
| 14479 | u.mNetworkPacketActivityCounters[i].writeSummaryFromParcelLocked(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 14480 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 14481 | u.mMobileRadioActiveTime.writeSummaryFromParcelLocked(out); |
| 14482 | u.mMobileRadioActiveCount.writeSummaryFromParcelLocked(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 14483 | } |
| 14484 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 14485 | u.mUserCpuTime.writeSummaryFromParcelLocked(out); |
| 14486 | u.mSystemCpuTime.writeSummaryFromParcelLocked(out); |
| 14487 | |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 14488 | if (u.mCpuClusterSpeedTimesUs != null) { |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 14489 | out.writeInt(1); |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 14490 | out.writeInt(u.mCpuClusterSpeedTimesUs.length); |
| 14491 | for (LongSamplingCounter[] cpuSpeeds : u.mCpuClusterSpeedTimesUs) { |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 14492 | if (cpuSpeeds != null) { |
| 14493 | out.writeInt(1); |
| 14494 | out.writeInt(cpuSpeeds.length); |
| 14495 | for (LongSamplingCounter c : cpuSpeeds) { |
| 14496 | if (c != null) { |
| 14497 | out.writeInt(1); |
| 14498 | c.writeSummaryFromParcelLocked(out); |
| 14499 | } else { |
| 14500 | out.writeInt(0); |
| 14501 | } |
| 14502 | } |
| 14503 | } else { |
| 14504 | out.writeInt(0); |
| 14505 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 14506 | } |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 14507 | } else { |
| 14508 | out.writeInt(0); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 14509 | } |
| 14510 | |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 14511 | LongSamplingCounterArray.writeSummaryToParcelLocked(out, u.mCpuFreqTimeMs); |
| 14512 | LongSamplingCounterArray.writeSummaryToParcelLocked(out, u.mScreenOffCpuFreqTimeMs); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 14513 | |
Mike Ma | 3d422c3 | 2017-10-25 11:08:57 -0700 | [diff] [blame] | 14514 | u.mCpuActiveTimeMs.writeSummaryFromParcelLocked(out); |
| 14515 | u.mCpuClusterTimesMs.writeSummaryToParcelLocked(out); |
| 14516 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 14517 | if (u.mProcStateTimeMs != null) { |
| 14518 | out.writeInt(u.mProcStateTimeMs.length); |
| 14519 | for (LongSamplingCounterArray counters : u.mProcStateTimeMs) { |
| 14520 | LongSamplingCounterArray.writeSummaryToParcelLocked(out, counters); |
| 14521 | } |
| 14522 | } else { |
| 14523 | out.writeInt(0); |
| 14524 | } |
| 14525 | if (u.mProcStateScreenOffTimeMs != null) { |
| 14526 | out.writeInt(u.mProcStateScreenOffTimeMs.length); |
| 14527 | for (LongSamplingCounterArray counters : u.mProcStateScreenOffTimeMs) { |
| 14528 | LongSamplingCounterArray.writeSummaryToParcelLocked(out, counters); |
| 14529 | } |
| 14530 | } else { |
| 14531 | out.writeInt(0); |
| 14532 | } |
| 14533 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 14534 | if (u.mMobileRadioApWakeupCount != null) { |
| 14535 | out.writeInt(1); |
| 14536 | u.mMobileRadioApWakeupCount.writeSummaryFromParcelLocked(out); |
| 14537 | } else { |
| 14538 | out.writeInt(0); |
| 14539 | } |
| 14540 | |
| 14541 | if (u.mWifiRadioApWakeupCount != null) { |
| 14542 | out.writeInt(1); |
| 14543 | u.mWifiRadioApWakeupCount.writeSummaryFromParcelLocked(out); |
| 14544 | } else { |
| 14545 | out.writeInt(0); |
| 14546 | } |
| 14547 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 14548 | final ArrayMap<String, Uid.Wakelock> wakeStats = u.mWakelockStats.getMap(); |
| 14549 | int NW = wakeStats.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14550 | out.writeInt(NW); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 14551 | for (int iw=0; iw<NW; iw++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 14552 | out.writeString(wakeStats.keyAt(iw)); |
| 14553 | Uid.Wakelock wl = wakeStats.valueAt(iw); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 14554 | if (wl.mTimerFull != null) { |
| 14555 | out.writeInt(1); |
| 14556 | wl.mTimerFull.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14557 | } else { |
| 14558 | out.writeInt(0); |
| 14559 | } |
| 14560 | if (wl.mTimerPartial != null) { |
| 14561 | out.writeInt(1); |
| 14562 | wl.mTimerPartial.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14563 | } else { |
| 14564 | out.writeInt(0); |
| 14565 | } |
| 14566 | if (wl.mTimerWindow != null) { |
| 14567 | out.writeInt(1); |
| 14568 | wl.mTimerWindow.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14569 | } else { |
| 14570 | out.writeInt(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14571 | } |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 14572 | if (wl.mTimerDraw != null) { |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 14573 | out.writeInt(1); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 14574 | wl.mTimerDraw.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 14575 | } else { |
| 14576 | out.writeInt(0); |
| 14577 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14578 | } |
| 14579 | |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 14580 | final ArrayMap<String, DualTimer> syncStats = u.mSyncStats.getMap(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 14581 | int NS = syncStats.size(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 14582 | out.writeInt(NS); |
| 14583 | for (int is=0; is<NS; is++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 14584 | out.writeString(syncStats.keyAt(is)); |
| 14585 | syncStats.valueAt(is).writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 14586 | } |
| 14587 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 14588 | final ArrayMap<String, DualTimer> jobStats = u.mJobStats.getMap(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 14589 | int NJ = jobStats.size(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 14590 | out.writeInt(NJ); |
| 14591 | for (int ij=0; ij<NJ; ij++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 14592 | out.writeString(jobStats.keyAt(ij)); |
| 14593 | jobStats.valueAt(ij).writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 14594 | } |
| 14595 | |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 14596 | u.writeJobCompletionsToParcelLocked(out); |
| 14597 | |
Amith Yamasani | 977e11f | 2018-02-16 11:29:54 -0800 | [diff] [blame] | 14598 | u.mJobsDeferredEventCount.writeSummaryFromParcelLocked(out); |
| 14599 | u.mJobsDeferredCount.writeSummaryFromParcelLocked(out); |
| 14600 | u.mJobsFreshnessTimeMs.writeSummaryFromParcelLocked(out); |
| 14601 | for (int i = 0; i < JOB_FRESHNESS_BUCKETS.length; i++) { |
| 14602 | if (u.mJobsFreshnessBuckets[i] != null) { |
| 14603 | u.mJobsFreshnessBuckets[i].writeSummaryFromParcelLocked(out); |
| 14604 | } else { |
| 14605 | out.writeInt(0); |
| 14606 | } |
| 14607 | } |
| 14608 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14609 | int NSE = u.mSensorStats.size(); |
| 14610 | out.writeInt(NSE); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 14611 | for (int ise=0; ise<NSE; ise++) { |
| 14612 | out.writeInt(u.mSensorStats.keyAt(ise)); |
| 14613 | Uid.Sensor se = u.mSensorStats.valueAt(ise); |
| 14614 | if (se.mTimer != null) { |
| 14615 | out.writeInt(1); |
| 14616 | se.mTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14617 | } else { |
| 14618 | out.writeInt(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14619 | } |
| 14620 | } |
| 14621 | |
| 14622 | int NP = u.mProcessStats.size(); |
| 14623 | out.writeInt(NP); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 14624 | for (int ip=0; ip<NP; ip++) { |
| 14625 | out.writeString(u.mProcessStats.keyAt(ip)); |
| 14626 | Uid.Proc ps = u.mProcessStats.valueAt(ip); |
| 14627 | out.writeLong(ps.mUserTime); |
| 14628 | out.writeLong(ps.mSystemTime); |
| 14629 | out.writeLong(ps.mForegroundTime); |
| 14630 | out.writeInt(ps.mStarts); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 14631 | out.writeInt(ps.mNumCrashes); |
| 14632 | out.writeInt(ps.mNumAnrs); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 14633 | ps.writeExcessivePowerToParcelLocked(out); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14634 | } |
| 14635 | |
| 14636 | NP = u.mPackageStats.size(); |
| 14637 | out.writeInt(NP); |
| 14638 | if (NP > 0) { |
| 14639 | for (Map.Entry<String, BatteryStatsImpl.Uid.Pkg> ent |
| 14640 | : u.mPackageStats.entrySet()) { |
| 14641 | out.writeString(ent.getKey()); |
| 14642 | Uid.Pkg ps = ent.getValue(); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 14643 | final int NWA = ps.mWakeupAlarms.size(); |
| 14644 | out.writeInt(NWA); |
| 14645 | for (int iwa=0; iwa<NWA; iwa++) { |
| 14646 | out.writeString(ps.mWakeupAlarms.keyAt(iwa)); |
| 14647 | ps.mWakeupAlarms.valueAt(iwa).writeSummaryFromParcelLocked(out); |
| 14648 | } |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 14649 | NS = ps.mServiceStats.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14650 | out.writeInt(NS); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 14651 | for (int is=0; is<NS; is++) { |
| 14652 | out.writeString(ps.mServiceStats.keyAt(is)); |
| 14653 | BatteryStatsImpl.Uid.Pkg.Serv ss = ps.mServiceStats.valueAt(is); |
| 14654 | long time = ss.getStartTimeToNowLocked( |
| 14655 | mOnBatteryTimeBase.getUptime(NOW_SYS)); |
| 14656 | out.writeLong(time); |
| 14657 | out.writeInt(ss.mStarts); |
| 14658 | out.writeInt(ss.mLaunches); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14659 | } |
| 14660 | } |
| 14661 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14662 | } |
| 14663 | } |
| 14664 | |
| 14665 | public void readFromParcel(Parcel in) { |
| 14666 | readFromParcelLocked(in); |
| 14667 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 14668 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14669 | void readFromParcelLocked(Parcel in) { |
| 14670 | int magic = in.readInt(); |
| 14671 | if (magic != MAGIC) { |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 14672 | throw new ParcelFormatException("Bad magic number: #" + Integer.toHexString(magic)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14673 | } |
| 14674 | |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 14675 | readHistory(in, false); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 14676 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14677 | mStartCount = in.readInt(); |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 14678 | mStartClockTime = in.readLong(); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 14679 | mStartPlatformVersion = in.readString(); |
| 14680 | mEndPlatformVersion = in.readString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14681 | mUptime = in.readLong(); |
| 14682 | mUptimeStart = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14683 | mRealtime = in.readLong(); |
| 14684 | mRealtimeStart = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14685 | mOnBattery = in.readInt() != 0; |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 14686 | mEstimatedBatteryCapacity = in.readInt(); |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 14687 | mMinLearnedBatteryCapacity = in.readInt(); |
| 14688 | mMaxLearnedBatteryCapacity = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14689 | mOnBatteryInternal = false; // we are no longer really running. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14690 | mOnBatteryTimeBase.readFromParcel(in); |
| 14691 | mOnBatteryScreenOffTimeBase.readFromParcel(in); |
| 14692 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 14693 | mScreenState = Display.STATE_UNKNOWN; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14694 | mScreenOnTimer = new StopwatchTimer(mClocks, null, -1, null, mOnBatteryTimeBase, in); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 14695 | mScreenDozeTimer = new StopwatchTimer(mClocks, null, -1, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14696 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14697 | mScreenBrightnessTimer[i] = new StopwatchTimer(mClocks, null, -100-i, null, |
| 14698 | mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14699 | } |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 14700 | mInteractive = false; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14701 | mInteractiveTimer = new StopwatchTimer(mClocks, null, -10, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14702 | mPhoneOn = false; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14703 | mPowerSaveModeEnabledTimer = new StopwatchTimer(mClocks, null, -2, null, |
| 14704 | mOnBatteryTimeBase, in); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 14705 | mLongestLightIdleTime = in.readLong(); |
| 14706 | mLongestFullIdleTime = in.readLong(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14707 | mDeviceIdleModeLightTimer = new StopwatchTimer(mClocks, null, -14, null, |
| 14708 | mOnBatteryTimeBase, in); |
| 14709 | mDeviceIdleModeFullTimer = new StopwatchTimer(mClocks, null, -11, null, |
| 14710 | mOnBatteryTimeBase, in); |
| 14711 | mDeviceLightIdlingTimer = new StopwatchTimer(mClocks, null, -15, null, |
| 14712 | mOnBatteryTimeBase, in); |
| 14713 | mDeviceIdlingTimer = new StopwatchTimer(mClocks, null, -12, null, mOnBatteryTimeBase, in); |
| 14714 | mPhoneOnTimer = new StopwatchTimer(mClocks, null, -3, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14715 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14716 | mPhoneSignalStrengthsTimer[i] = new StopwatchTimer(mClocks, null, -200-i, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14717 | null, mOnBatteryTimeBase, in); |
| 14718 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14719 | mPhoneSignalScanningTimer = new StopwatchTimer(mClocks, null, -200+1, null, |
| 14720 | mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14721 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14722 | mPhoneDataConnectionsTimer[i] = new StopwatchTimer(mClocks, null, -300-i, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14723 | null, mOnBatteryTimeBase, in); |
| 14724 | } |
| 14725 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
| 14726 | mNetworkByteActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 14727 | mNetworkPacketActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 14728 | } |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 14729 | mMobileRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14730 | mMobileRadioActiveTimer = new StopwatchTimer(mClocks, null, -400, null, |
| 14731 | mOnBatteryTimeBase, in); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 14732 | mMobileRadioActivePerAppTimer = new StopwatchTimer(mClocks, null, -401, null, |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14733 | mOnBatteryTimeBase, in); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 14734 | mMobileRadioActiveAdjustedTime = new LongSamplingCounter(mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14735 | mMobileRadioActiveUnknownTime = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 14736 | mMobileRadioActiveUnknownCount = new LongSamplingCounter(mOnBatteryTimeBase, in); |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 14737 | mWifiMulticastWakelockTimer = new StopwatchTimer(mClocks, null, -4, null, |
| 14738 | mOnBatteryTimeBase, in); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 14739 | mWifiRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14740 | mWifiOn = false; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14741 | mWifiOnTimer = new StopwatchTimer(mClocks, null, -4, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14742 | mGlobalWifiRunning = false; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14743 | mGlobalWifiRunningTimer = new StopwatchTimer(mClocks, null, -5, null, |
| 14744 | mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14745 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14746 | mWifiStateTimer[i] = new StopwatchTimer(mClocks, null, -600-i, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14747 | null, mOnBatteryTimeBase, in); |
| 14748 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 14749 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14750 | mWifiSupplStateTimer[i] = new StopwatchTimer(mClocks, null, -700-i, |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 14751 | null, mOnBatteryTimeBase, in); |
| 14752 | } |
| 14753 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14754 | mWifiSignalStrengthsTimer[i] = new StopwatchTimer(mClocks, null, -800-i, |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 14755 | null, mOnBatteryTimeBase, in); |
| 14756 | } |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 14757 | mWifiActiveTimer = new StopwatchTimer(mClocks, null, -900, null, |
| 14758 | mOnBatteryTimeBase, in); |
| 14759 | mWifiActivity = new ControllerActivityCounterImpl(mOnBatteryTimeBase, |
| 14760 | NUM_WIFI_TX_LEVELS, in); |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 14761 | for (int i=0; i<GnssMetrics.NUM_GPS_SIGNAL_QUALITY_LEVELS; i++) { |
| 14762 | mGpsSignalQualityTimer[i] = new StopwatchTimer(mClocks, null, -1000-i, |
| 14763 | null, mOnBatteryTimeBase, in); |
| 14764 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 14765 | mBluetoothActivity = new ControllerActivityCounterImpl(mOnBatteryTimeBase, |
| 14766 | NUM_BT_TX_LEVELS, in); |
| 14767 | mModemActivity = new ControllerActivityCounterImpl(mOnBatteryTimeBase, |
| 14768 | ModemActivityInfo.TX_POWER_LEVELS, in); |
| 14769 | mHasWifiReporting = in.readInt() != 0; |
| 14770 | mHasBluetoothReporting = in.readInt() != 0; |
| 14771 | mHasModemReporting = in.readInt() != 0; |
| 14772 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 14773 | mNumConnectivityChange = in.readInt(); |
| 14774 | mLoadedNumConnectivityChange = in.readInt(); |
| 14775 | mUnpluggedNumConnectivityChange = in.readInt(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 14776 | mAudioOnNesting = 0; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14777 | mAudioOnTimer = new StopwatchTimer(mClocks, null, -7, null, mOnBatteryTimeBase); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 14778 | mVideoOnNesting = 0; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14779 | mVideoOnTimer = new StopwatchTimer(mClocks, null, -8, null, mOnBatteryTimeBase); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 14780 | mFlashlightOnNesting = 0; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14781 | mFlashlightOnTimer = new StopwatchTimer(mClocks, null, -9, null, mOnBatteryTimeBase, in); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 14782 | mCameraOnNesting = 0; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14783 | mCameraOnTimer = new StopwatchTimer(mClocks, null, -13, null, mOnBatteryTimeBase, in); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 14784 | mBluetoothScanNesting = 0; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14785 | mBluetoothScanTimer = new StopwatchTimer(mClocks, null, -14, null, mOnBatteryTimeBase, in); |
Siddharth Ray | f5e796a | 2018-01-22 18:18:17 -0800 | [diff] [blame] | 14786 | mIsCellularTxPowerHigh = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 14787 | mDischargeUnplugLevel = in.readInt(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 14788 | mDischargePlugLevel = in.readInt(); |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 14789 | mDischargeCurrentLevel = in.readInt(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 14790 | mCurrentBatteryLevel = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 14791 | mLowDischargeAmountSinceCharge = in.readInt(); |
| 14792 | mHighDischargeAmountSinceCharge = in.readInt(); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 14793 | mDischargeAmountScreenOn = in.readInt(); |
| 14794 | mDischargeAmountScreenOnSinceCharge = in.readInt(); |
| 14795 | mDischargeAmountScreenOff = in.readInt(); |
| 14796 | mDischargeAmountScreenOffSinceCharge = in.readInt(); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 14797 | mDischargeAmountScreenDoze = in.readInt(); |
| 14798 | mDischargeAmountScreenDozeSinceCharge = in.readInt(); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 14799 | mDischargeStepTracker.readFromParcel(in); |
| 14800 | mChargeStepTracker.readFromParcel(in); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 14801 | mDischargeCounter = new LongSamplingCounter(mOnBatteryTimeBase, in); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 14802 | mDischargeScreenOffCounter = new LongSamplingCounter(mOnBatteryScreenOffTimeBase, in); |
| 14803 | mDischargeScreenDozeCounter = new LongSamplingCounter(mOnBatteryTimeBase, in); |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 14804 | mDischargeLightDozeCounter = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 14805 | mDischargeDeepDozeCounter = new LongSamplingCounter(mOnBatteryTimeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14806 | mLastWriteTime = in.readLong(); |
| 14807 | |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 14808 | mRpmStats.clear(); |
| 14809 | int NRPMS = in.readInt(); |
| 14810 | for (int irpm = 0; irpm < NRPMS; irpm++) { |
| 14811 | if (in.readInt() != 0) { |
| 14812 | String rpmName = in.readString(); |
| 14813 | SamplingTimer rpmt = new SamplingTimer(mClocks, mOnBatteryTimeBase, in); |
| 14814 | mRpmStats.put(rpmName, rpmt); |
| 14815 | } |
| 14816 | } |
| 14817 | mScreenOffRpmStats.clear(); |
| 14818 | int NSORPMS = in.readInt(); |
| 14819 | for (int irpm = 0; irpm < NSORPMS; irpm++) { |
| 14820 | if (in.readInt() != 0) { |
| 14821 | String rpmName = in.readString(); |
| 14822 | SamplingTimer rpmt = new SamplingTimer(mClocks, mOnBatteryScreenOffTimeBase, in); |
| 14823 | mScreenOffRpmStats.put(rpmName, rpmt); |
| 14824 | } |
| 14825 | } |
| 14826 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 14827 | mKernelWakelockStats.clear(); |
| 14828 | int NKW = in.readInt(); |
| 14829 | for (int ikw = 0; ikw < NKW; ikw++) { |
| 14830 | if (in.readInt() != 0) { |
| 14831 | String wakelockName = in.readString(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14832 | SamplingTimer kwlt = new SamplingTimer(mClocks, mOnBatteryScreenOffTimeBase, in); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 14833 | mKernelWakelockStats.put(wakelockName, kwlt); |
| 14834 | } |
| 14835 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 14836 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 14837 | mWakeupReasonStats.clear(); |
| 14838 | int NWR = in.readInt(); |
| 14839 | for (int iwr = 0; iwr < NWR; iwr++) { |
| 14840 | if (in.readInt() != 0) { |
| 14841 | String reasonName = in.readString(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14842 | SamplingTimer timer = new SamplingTimer(mClocks, mOnBatteryTimeBase, in); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 14843 | mWakeupReasonStats.put(reasonName, timer); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 14844 | } |
| 14845 | } |
| 14846 | |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 14847 | mKernelMemoryStats.clear(); |
| 14848 | int nmt = in.readInt(); |
| 14849 | for (int imt = 0; imt < nmt; imt++) { |
| 14850 | if (in.readInt() != 0) { |
| 14851 | Long bucket = in.readLong(); |
| 14852 | SamplingTimer kmt = new SamplingTimer(mClocks, mOnBatteryTimeBase, in); |
| 14853 | mKernelMemoryStats.put(bucket, kmt); |
| 14854 | } |
| 14855 | } |
| 14856 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14857 | mPartialTimers.clear(); |
| 14858 | mFullTimers.clear(); |
| 14859 | mWindowTimers.clear(); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 14860 | mWifiRunningTimers.clear(); |
| 14861 | mFullWifiLockTimers.clear(); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 14862 | mWifiScanTimers.clear(); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 14863 | mWifiBatchedScanTimers.clear(); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 14864 | mWifiMulticastTimers.clear(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 14865 | mAudioTurnedOnTimers.clear(); |
| 14866 | mVideoTurnedOnTimers.clear(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 14867 | mFlashlightTurnedOnTimers.clear(); |
| 14868 | mCameraTurnedOnTimers.clear(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14869 | |
| 14870 | int numUids = in.readInt(); |
| 14871 | mUidStats.clear(); |
| 14872 | for (int i = 0; i < numUids; i++) { |
| 14873 | int uid = in.readInt(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14874 | Uid u = new Uid(this, uid); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14875 | u.readFromParcelLocked(mOnBatteryTimeBase, mOnBatteryScreenOffTimeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14876 | mUidStats.append(uid, u); |
| 14877 | } |
| 14878 | } |
| 14879 | |
| 14880 | public void writeToParcel(Parcel out, int flags) { |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 14881 | writeToParcelLocked(out, true, flags); |
| 14882 | } |
| 14883 | |
| 14884 | public void writeToParcelWithoutUids(Parcel out, int flags) { |
| 14885 | writeToParcelLocked(out, false, flags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14886 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 14887 | |
| 14888 | @SuppressWarnings("unused") |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 14889 | void writeToParcelLocked(Parcel out, boolean inclUids, int flags) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 14890 | // Need to update with current kernel wake lock counts. |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 14891 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 14892 | |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 14893 | // Pull the clock time. This may update the time and make a new history entry |
| 14894 | // if we had originally pulled a time before the RTC was set. |
| 14895 | long startClockTime = getStartClockTime(); |
| 14896 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14897 | final long uSecUptime = mClocks.uptimeMillis() * 1000; |
| 14898 | final long uSecRealtime = mClocks.elapsedRealtime() * 1000; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14899 | final long batteryRealtime = mOnBatteryTimeBase.getRealtime(uSecRealtime); |
| 14900 | final long batteryScreenOffRealtime = mOnBatteryScreenOffTimeBase.getRealtime(uSecRealtime); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 14901 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14902 | out.writeInt(MAGIC); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 14903 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 14904 | writeHistory(out, true, false); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 14905 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14906 | out.writeInt(mStartCount); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 14907 | out.writeLong(startClockTime); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 14908 | out.writeString(mStartPlatformVersion); |
| 14909 | out.writeString(mEndPlatformVersion); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14910 | out.writeLong(mUptime); |
| 14911 | out.writeLong(mUptimeStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14912 | out.writeLong(mRealtime); |
| 14913 | out.writeLong(mRealtimeStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14914 | out.writeInt(mOnBattery ? 1 : 0); |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 14915 | out.writeInt(mEstimatedBatteryCapacity); |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 14916 | out.writeInt(mMinLearnedBatteryCapacity); |
| 14917 | out.writeInt(mMaxLearnedBatteryCapacity); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14918 | mOnBatteryTimeBase.writeToParcel(out, uSecUptime, uSecRealtime); |
| 14919 | mOnBatteryScreenOffTimeBase.writeToParcel(out, uSecUptime, uSecRealtime); |
| 14920 | |
| 14921 | mScreenOnTimer.writeToParcel(out, uSecRealtime); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 14922 | mScreenDozeTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14923 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
| 14924 | mScreenBrightnessTimer[i].writeToParcel(out, uSecRealtime); |
| 14925 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 14926 | mInteractiveTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 14927 | mPowerSaveModeEnabledTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 14928 | out.writeLong(mLongestLightIdleTime); |
| 14929 | out.writeLong(mLongestFullIdleTime); |
| 14930 | mDeviceIdleModeLightTimer.writeToParcel(out, uSecRealtime); |
| 14931 | mDeviceIdleModeFullTimer.writeToParcel(out, uSecRealtime); |
| 14932 | mDeviceLightIdlingTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 14933 | mDeviceIdlingTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14934 | mPhoneOnTimer.writeToParcel(out, uSecRealtime); |
| 14935 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
| 14936 | mPhoneSignalStrengthsTimer[i].writeToParcel(out, uSecRealtime); |
| 14937 | } |
| 14938 | mPhoneSignalScanningTimer.writeToParcel(out, uSecRealtime); |
| 14939 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
| 14940 | mPhoneDataConnectionsTimer[i].writeToParcel(out, uSecRealtime); |
| 14941 | } |
| 14942 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
| 14943 | mNetworkByteActivityCounters[i].writeToParcel(out); |
| 14944 | mNetworkPacketActivityCounters[i].writeToParcel(out); |
| 14945 | } |
| 14946 | mMobileRadioActiveTimer.writeToParcel(out, uSecRealtime); |
| 14947 | mMobileRadioActivePerAppTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 14948 | mMobileRadioActiveAdjustedTime.writeToParcel(out); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14949 | mMobileRadioActiveUnknownTime.writeToParcel(out); |
| 14950 | mMobileRadioActiveUnknownCount.writeToParcel(out); |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 14951 | mWifiMulticastWakelockTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14952 | mWifiOnTimer.writeToParcel(out, uSecRealtime); |
| 14953 | mGlobalWifiRunningTimer.writeToParcel(out, uSecRealtime); |
| 14954 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 14955 | mWifiStateTimer[i].writeToParcel(out, uSecRealtime); |
| 14956 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 14957 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 14958 | mWifiSupplStateTimer[i].writeToParcel(out, uSecRealtime); |
| 14959 | } |
| 14960 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 14961 | mWifiSignalStrengthsTimer[i].writeToParcel(out, uSecRealtime); |
| 14962 | } |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 14963 | mWifiActiveTimer.writeToParcel(out, uSecRealtime); |
| 14964 | mWifiActivity.writeToParcel(out, 0); |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 14965 | for (int i=0; i< GnssMetrics.NUM_GPS_SIGNAL_QUALITY_LEVELS; i++) { |
| 14966 | mGpsSignalQualityTimer[i].writeToParcel(out, uSecRealtime); |
| 14967 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 14968 | mBluetoothActivity.writeToParcel(out, 0); |
| 14969 | mModemActivity.writeToParcel(out, 0); |
| 14970 | out.writeInt(mHasWifiReporting ? 1 : 0); |
| 14971 | out.writeInt(mHasBluetoothReporting ? 1 : 0); |
| 14972 | out.writeInt(mHasModemReporting ? 1 : 0); |
| 14973 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 14974 | out.writeInt(mNumConnectivityChange); |
| 14975 | out.writeInt(mLoadedNumConnectivityChange); |
| 14976 | out.writeInt(mUnpluggedNumConnectivityChange); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 14977 | mFlashlightOnTimer.writeToParcel(out, uSecRealtime); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 14978 | mCameraOnTimer.writeToParcel(out, uSecRealtime); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 14979 | mBluetoothScanTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 14980 | out.writeInt(mDischargeUnplugLevel); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 14981 | out.writeInt(mDischargePlugLevel); |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 14982 | out.writeInt(mDischargeCurrentLevel); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 14983 | out.writeInt(mCurrentBatteryLevel); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 14984 | out.writeInt(mLowDischargeAmountSinceCharge); |
| 14985 | out.writeInt(mHighDischargeAmountSinceCharge); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 14986 | out.writeInt(mDischargeAmountScreenOn); |
| 14987 | out.writeInt(mDischargeAmountScreenOnSinceCharge); |
| 14988 | out.writeInt(mDischargeAmountScreenOff); |
| 14989 | out.writeInt(mDischargeAmountScreenOffSinceCharge); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 14990 | out.writeInt(mDischargeAmountScreenDoze); |
| 14991 | out.writeInt(mDischargeAmountScreenDozeSinceCharge); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 14992 | mDischargeStepTracker.writeToParcel(out); |
| 14993 | mChargeStepTracker.writeToParcel(out); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 14994 | mDischargeCounter.writeToParcel(out); |
| 14995 | mDischargeScreenOffCounter.writeToParcel(out); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 14996 | mDischargeScreenDozeCounter.writeToParcel(out); |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 14997 | mDischargeLightDozeCounter.writeToParcel(out); |
| 14998 | mDischargeDeepDozeCounter.writeToParcel(out); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14999 | out.writeLong(mLastWriteTime); |
| 15000 | |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 15001 | out.writeInt(mRpmStats.size()); |
| 15002 | for (Map.Entry<String, SamplingTimer> ent : mRpmStats.entrySet()) { |
| 15003 | SamplingTimer rpmt = ent.getValue(); |
| 15004 | if (rpmt != null) { |
| 15005 | out.writeInt(1); |
| 15006 | out.writeString(ent.getKey()); |
| 15007 | rpmt.writeToParcel(out, uSecRealtime); |
| 15008 | } else { |
| 15009 | out.writeInt(0); |
| 15010 | } |
| 15011 | } |
| 15012 | out.writeInt(mScreenOffRpmStats.size()); |
| 15013 | for (Map.Entry<String, SamplingTimer> ent : mScreenOffRpmStats.entrySet()) { |
| 15014 | SamplingTimer rpmt = ent.getValue(); |
| 15015 | if (rpmt != null) { |
| 15016 | out.writeInt(1); |
| 15017 | out.writeString(ent.getKey()); |
| 15018 | rpmt.writeToParcel(out, uSecRealtime); |
| 15019 | } else { |
| 15020 | out.writeInt(0); |
| 15021 | } |
| 15022 | } |
| 15023 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 15024 | if (inclUids) { |
| 15025 | out.writeInt(mKernelWakelockStats.size()); |
| 15026 | for (Map.Entry<String, SamplingTimer> ent : mKernelWakelockStats.entrySet()) { |
| 15027 | SamplingTimer kwlt = ent.getValue(); |
| 15028 | if (kwlt != null) { |
| 15029 | out.writeInt(1); |
| 15030 | out.writeString(ent.getKey()); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 15031 | kwlt.writeToParcel(out, uSecRealtime); |
| 15032 | } else { |
| 15033 | out.writeInt(0); |
| 15034 | } |
| 15035 | } |
| 15036 | out.writeInt(mWakeupReasonStats.size()); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 15037 | for (Map.Entry<String, SamplingTimer> ent : mWakeupReasonStats.entrySet()) { |
| 15038 | SamplingTimer timer = ent.getValue(); |
| 15039 | if (timer != null) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 15040 | out.writeInt(1); |
| 15041 | out.writeString(ent.getKey()); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 15042 | timer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 15043 | } else { |
| 15044 | out.writeInt(0); |
| 15045 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 15046 | } |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 15047 | } else { |
Bookatz | ba78b2b | 2017-10-10 11:06:33 -0700 | [diff] [blame] | 15048 | out.writeInt(0); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 15049 | out.writeInt(0); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 15050 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 15051 | |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 15052 | out.writeInt(mKernelMemoryStats.size()); |
| 15053 | for (int i = 0; i < mKernelMemoryStats.size(); i++) { |
| 15054 | SamplingTimer kmt = mKernelMemoryStats.valueAt(i); |
| 15055 | if (kmt != null) { |
| 15056 | out.writeInt(1); |
| 15057 | out.writeLong(mKernelMemoryStats.keyAt(i)); |
| 15058 | kmt.writeToParcel(out, uSecRealtime); |
| 15059 | } else { |
| 15060 | out.writeInt(0); |
| 15061 | } |
| 15062 | } |
| 15063 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 15064 | if (inclUids) { |
| 15065 | int size = mUidStats.size(); |
| 15066 | out.writeInt(size); |
| 15067 | for (int i = 0; i < size; i++) { |
| 15068 | out.writeInt(mUidStats.keyAt(i)); |
| 15069 | Uid uid = mUidStats.valueAt(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15070 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 15071 | uid.writeToParcelLocked(out, uSecUptime, uSecRealtime); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 15072 | } |
| 15073 | } else { |
| 15074 | out.writeInt(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15075 | } |
| 15076 | } |
| 15077 | |
| 15078 | public static final Parcelable.Creator<BatteryStatsImpl> CREATOR = |
| 15079 | new Parcelable.Creator<BatteryStatsImpl>() { |
| 15080 | public BatteryStatsImpl createFromParcel(Parcel in) { |
| 15081 | return new BatteryStatsImpl(in); |
| 15082 | } |
| 15083 | |
| 15084 | public BatteryStatsImpl[] newArray(int size) { |
| 15085 | return new BatteryStatsImpl[size]; |
| 15086 | } |
| 15087 | }; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 15088 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 15089 | public void prepareForDumpLocked() { |
| 15090 | // Need to retrieve current kernel wake lock stats before printing. |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 15091 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 15092 | |
| 15093 | // Pull the clock time. This may update the time and make a new history entry |
| 15094 | // if we had originally pulled a time before the RTC was set. |
| 15095 | getStartClockTime(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 15096 | } |
| 15097 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 15098 | 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] | 15099 | if (DEBUG) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 15100 | pw.println("mOnBatteryTimeBase:"); |
| 15101 | mOnBatteryTimeBase.dump(pw, " "); |
| 15102 | pw.println("mOnBatteryScreenOffTimeBase:"); |
| 15103 | mOnBatteryScreenOffTimeBase.dump(pw, " "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 15104 | Printer pr = new PrintWriterPrinter(pw); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 15105 | pr.println("*** Screen on timer:"); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 15106 | mScreenOnTimer.logState(pr, " "); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 15107 | pr.println("*** Screen doze timer:"); |
| 15108 | mScreenDozeTimer.logState(pr, " "); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 15109 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 15110 | pr.println("*** Screen brightness #" + i + ":"); |
| 15111 | mScreenBrightnessTimer[i].logState(pr, " "); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 15112 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 15113 | pr.println("*** Interactive timer:"); |
| 15114 | mInteractiveTimer.logState(pr, " "); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 15115 | pr.println("*** Power save mode timer:"); |
| 15116 | mPowerSaveModeEnabledTimer.logState(pr, " "); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 15117 | pr.println("*** Device idle mode light timer:"); |
| 15118 | mDeviceIdleModeLightTimer.logState(pr, " "); |
| 15119 | pr.println("*** Device idle mode full timer:"); |
| 15120 | mDeviceIdleModeFullTimer.logState(pr, " "); |
| 15121 | pr.println("*** Device light idling timer:"); |
| 15122 | mDeviceLightIdlingTimer.logState(pr, " "); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 15123 | pr.println("*** Device idling timer:"); |
| 15124 | mDeviceIdlingTimer.logState(pr, " "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 15125 | pr.println("*** Phone timer:"); |
| 15126 | mPhoneOnTimer.logState(pr, " "); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 15127 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 15128 | pr.println("*** Phone signal strength #" + i + ":"); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 15129 | mPhoneSignalStrengthsTimer[i].logState(pr, " "); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 15130 | } |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 15131 | pr.println("*** Signal scanning :"); |
| 15132 | mPhoneSignalScanningTimer.logState(pr, " "); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 15133 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 15134 | pr.println("*** Data connection type #" + i + ":"); |
| 15135 | mPhoneDataConnectionsTimer[i].logState(pr, " "); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 15136 | } |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 15137 | pr.println("*** mMobileRadioPowerState=" + mMobileRadioPowerState); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 15138 | pr.println("*** Mobile network active timer:"); |
| 15139 | mMobileRadioActiveTimer.logState(pr, " "); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 15140 | pr.println("*** Mobile network active adjusted timer:"); |
| 15141 | mMobileRadioActiveAdjustedTime.logState(pr, " "); |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 15142 | pr.println("*** Wifi Multicast WakeLock Timer:"); |
| 15143 | mWifiMulticastWakelockTimer.logState(pr, " "); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 15144 | pr.println("*** mWifiRadioPowerState=" + mWifiRadioPowerState); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 15145 | pr.println("*** Wifi timer:"); |
| 15146 | mWifiOnTimer.logState(pr, " "); |
| 15147 | pr.println("*** WifiRunning timer:"); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 15148 | mGlobalWifiRunningTimer.logState(pr, " "); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 15149 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 15150 | pr.println("*** Wifi state #" + i + ":"); |
| 15151 | mWifiStateTimer[i].logState(pr, " "); |
| 15152 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 15153 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 15154 | pr.println("*** Wifi suppl state #" + i + ":"); |
| 15155 | mWifiSupplStateTimer[i].logState(pr, " "); |
| 15156 | } |
| 15157 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 15158 | pr.println("*** Wifi signal strength #" + i + ":"); |
| 15159 | mWifiSignalStrengthsTimer[i].logState(pr, " "); |
| 15160 | } |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 15161 | for (int i=0; i<GnssMetrics.NUM_GPS_SIGNAL_QUALITY_LEVELS; i++) { |
| 15162 | pr.println("*** GPS signal quality #" + i + ":"); |
| 15163 | mGpsSignalQualityTimer[i].logState(pr, " "); |
| 15164 | } |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 15165 | pr.println("*** Flashlight timer:"); |
| 15166 | mFlashlightOnTimer.logState(pr, " "); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 15167 | pr.println("*** Camera timer:"); |
| 15168 | mCameraOnTimer.logState(pr, " "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15169 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 15170 | super.dumpLocked(context, pw, flags, reqUid, histStart); |
Sudheer Shanka | c20379e | 2018-02-15 00:06:21 -0800 | [diff] [blame] | 15171 | pw.print("Total cpu time reads: "); |
| 15172 | pw.println(mNumCpuTimeReads); |
| 15173 | pw.print("Batched cpu time reads: "); |
| 15174 | pw.println(mNumBatchedCpuTimeReads); |
| 15175 | pw.print("Batching Duration (min): "); |
| 15176 | pw.println((mClocks.uptimeMillis() - mCpuTimeReadsTrackingStartTime) / (60 * 1000)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15177 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15178 | } |