The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006-2007 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.internal.os; |
| 18 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 19 | import android.annotation.NonNull; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 20 | import android.annotation.Nullable; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 21 | import android.app.ActivityManager; |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 22 | import android.bluetooth.BluetoothActivityEnergyInfo; |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 23 | import android.bluetooth.UidTraffic; |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 24 | import android.content.ContentResolver; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 25 | import android.content.Context; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 26 | import android.content.Intent; |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 27 | import android.database.ContentObserver; |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 28 | import android.net.ConnectivityManager; |
| 29 | import android.net.NetworkStats; |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 30 | import android.net.Uri; |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 31 | import android.net.wifi.WifiActivityEnergyInfo; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 32 | import android.net.wifi.WifiManager; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 33 | import android.os.BatteryManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 34 | import android.os.BatteryStats; |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 35 | import android.os.Build; |
Siddharth Ray | a1fd057 | 2017-11-13 14:20:47 -0800 | [diff] [blame] | 36 | import android.os.connectivity.CellularBatteryStats; |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 37 | import android.os.connectivity.WifiBatteryStats; |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 38 | import android.os.connectivity.GpsBatteryStats; |
Dianne Hackborn | 8bdf593 | 2010-10-15 12:54:40 -0700 | [diff] [blame] | 39 | import android.os.FileUtils; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 40 | import android.os.Handler; |
Adam Lesinski | e1f480d | 2017-02-15 18:51:23 -0800 | [diff] [blame] | 41 | import android.os.IBatteryPropertiesRegistrar; |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 42 | import android.os.Looper; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 43 | import android.os.Message; |
Bookatz | 1a1b046 | 2018-01-12 11:47:03 -0800 | [diff] [blame] | 44 | import android.os.OsProtoEnums; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 45 | import android.os.Parcel; |
| 46 | import android.os.ParcelFormatException; |
| 47 | import android.os.Parcelable; |
Bookatz | 1a1b046 | 2018-01-12 11:47:03 -0800 | [diff] [blame] | 48 | import android.os.PowerManager; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 49 | import android.os.Process; |
Adam Lesinski | e1f480d | 2017-02-15 18:51:23 -0800 | [diff] [blame] | 50 | import android.os.RemoteException; |
| 51 | import android.os.ServiceManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 52 | import android.os.SystemClock; |
Suprabh Shukla | e6e723d | 2017-06-14 16:14:43 -0700 | [diff] [blame] | 53 | import android.os.UserHandle; |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 54 | import android.os.WorkSource; |
Narayan Kamath | 8182202 | 2017-12-08 11:56:01 +0000 | [diff] [blame] | 55 | import android.os.WorkSource.WorkChain; |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 56 | import android.provider.Settings; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 57 | import android.telephony.DataConnectionRealTimeInfo; |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 58 | import android.telephony.ModemActivityInfo; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 59 | import android.telephony.ServiceState; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 60 | import android.telephony.SignalStrength; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 61 | import android.telephony.TelephonyManager; |
Jeff Sharkey | 9da2f1e | 2014-08-14 12:55:00 -0700 | [diff] [blame] | 62 | import android.text.TextUtils; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 63 | import android.util.ArrayMap; |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 64 | import android.util.IntArray; |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 65 | import android.util.KeyValueListParser; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 66 | import android.util.Log; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 67 | import android.util.LogWriter; |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 68 | import android.util.LongSparseArray; |
| 69 | import android.util.LongSparseLongArray; |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 70 | import android.util.MutableInt; |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 71 | import android.util.Pools; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 72 | import android.util.PrintWriterPrinter; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 73 | import android.util.Printer; |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 74 | import android.util.Slog; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 75 | import android.util.SparseArray; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 76 | import android.util.SparseIntArray; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 77 | import android.util.SparseLongArray; |
Bookatz | c1a050a | 2017-10-10 15:49:28 -0700 | [diff] [blame] | 78 | import android.util.StatsLog; |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 79 | import android.util.TimeUtils; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 80 | import android.util.Xml; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 81 | import android.view.Display; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 82 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 83 | import com.android.internal.annotations.GuardedBy; |
Adam Lesinski | 98f0d46 | 2016-04-19 16:46:20 -0700 | [diff] [blame] | 84 | import com.android.internal.annotations.VisibleForTesting; |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 85 | import com.android.internal.location.gnssmetrics.GnssMetrics; |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 86 | import com.android.internal.net.NetworkStatsFactory; |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 87 | import com.android.internal.util.ArrayUtils; |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 88 | import com.android.internal.util.FastPrintWriter; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 89 | import com.android.internal.util.FastXmlSerializer; |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 90 | import com.android.internal.util.JournaledFile; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 91 | import com.android.internal.util.XmlUtils; |
Suprabh Shukla | e6e723d | 2017-06-14 16:14:43 -0700 | [diff] [blame] | 92 | |
Narayan Kamath | 8182202 | 2017-12-08 11:56:01 +0000 | [diff] [blame] | 93 | import java.util.List; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 94 | import libcore.util.EmptyArray; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 95 | import org.xmlpull.v1.XmlPullParser; |
| 96 | import org.xmlpull.v1.XmlPullParserException; |
| 97 | import org.xmlpull.v1.XmlSerializer; |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 98 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 99 | import java.io.ByteArrayOutputStream; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 100 | import java.io.File; |
| 101 | import java.io.FileInputStream; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 102 | import java.io.FileNotFoundException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 103 | import java.io.FileOutputStream; |
| 104 | import java.io.IOException; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 105 | import java.io.PrintWriter; |
Wojciech Staszkiewicz | 9e9e2e7 | 2015-05-08 14:58:46 +0100 | [diff] [blame] | 106 | import java.nio.charset.StandardCharsets; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 107 | import java.util.ArrayList; |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 108 | import java.util.Arrays; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 109 | import java.util.Calendar; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 110 | import java.util.HashMap; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 111 | import java.util.Iterator; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 112 | import java.util.Map; |
Adam Lesinski | b3a1bad | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 113 | import java.util.concurrent.Future; |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 114 | import java.util.concurrent.atomic.AtomicInteger; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 115 | import java.util.concurrent.locks.ReentrantLock; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 116 | |
| 117 | /** |
| 118 | * All information we are collecting about things that can happen that impact |
| 119 | * battery life. All times are represented in microseconds except where indicated |
| 120 | * otherwise. |
| 121 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 122 | public class BatteryStatsImpl extends BatteryStats { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 123 | private static final String TAG = "BatteryStatsImpl"; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 124 | private static final boolean DEBUG = false; |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 125 | public static final boolean DEBUG_ENERGY = false; |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 126 | private static final boolean DEBUG_ENERGY_CPU = DEBUG_ENERGY; |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 127 | private static final boolean DEBUG_MEMORY = false; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 128 | private static final boolean DEBUG_HISTORY = false; |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 129 | private static final boolean USE_OLD_HISTORY = false; // for debugging. |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 130 | |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 131 | // TODO: remove "tcp" from network methods, since we measure total stats. |
| 132 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 133 | // In-memory Parcel magic number, used to detect attempts to unmarshall bad data |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 134 | private static final int MAGIC = 0xBA757475; // 'BATSTATS' |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 135 | |
| 136 | // Current on-disk Parcel version |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 137 | private static final int VERSION = 174 + (USE_OLD_HISTORY ? 1000 : 0); |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 138 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 139 | // Maximum number of items we will record in the history. |
Narayan Kamath | b59b7c3 | 2017-06-12 14:11:03 +0100 | [diff] [blame] | 140 | private static final int MAX_HISTORY_ITEMS; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 141 | |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 142 | // No, really, THIS is the maximum number of items we will record in the history. |
Narayan Kamath | b59b7c3 | 2017-06-12 14:11:03 +0100 | [diff] [blame] | 143 | private static final int MAX_MAX_HISTORY_ITEMS; |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 144 | |
Dianne Hackborn | 9e0f5d9 | 2010-02-22 15:05:42 -0800 | [diff] [blame] | 145 | // The maximum number of names wakelocks we will keep track of |
| 146 | // per uid; once the limit is reached, we batch the remaining wakelocks |
| 147 | // in to one common name. |
Narayan Kamath | b59b7c3 | 2017-06-12 14:11:03 +0100 | [diff] [blame] | 148 | private static final int MAX_WAKELOCKS_PER_UID; |
| 149 | |
| 150 | static final int MAX_HISTORY_BUFFER; // 256KB |
| 151 | static final int MAX_MAX_HISTORY_BUFFER; // 320KB |
| 152 | |
| 153 | static { |
| 154 | if (ActivityManager.isLowRamDeviceStatic()) { |
| 155 | MAX_HISTORY_ITEMS = 800; |
| 156 | MAX_MAX_HISTORY_ITEMS = 1200; |
| 157 | MAX_WAKELOCKS_PER_UID = 40; |
| 158 | MAX_HISTORY_BUFFER = 96*1024; // 96KB |
| 159 | MAX_MAX_HISTORY_BUFFER = 128*1024; // 128KB |
| 160 | } else { |
Makoto Onuki | 44d6460 | 2018-01-18 08:44:28 -0800 | [diff] [blame] | 161 | MAX_HISTORY_ITEMS = 4000; |
| 162 | MAX_MAX_HISTORY_ITEMS = 6000; |
| 163 | MAX_WAKELOCKS_PER_UID = 200; |
| 164 | MAX_HISTORY_BUFFER = 512*1024; // 512KB |
| 165 | MAX_MAX_HISTORY_BUFFER = 640*1024; // 640KB |
Narayan Kamath | b59b7c3 | 2017-06-12 14:11:03 +0100 | [diff] [blame] | 166 | } |
| 167 | } |
Dianne Hackborn | c24ab86 | 2011-10-18 15:55:03 -0700 | [diff] [blame] | 168 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 169 | // Number of transmit power states the Wifi controller can be in. |
| 170 | private static final int NUM_WIFI_TX_LEVELS = 1; |
| 171 | |
| 172 | // Number of transmit power states the Bluetooth controller can be in. |
| 173 | private static final int NUM_BT_TX_LEVELS = 1; |
| 174 | |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 175 | /** |
| 176 | * Holding a wakelock costs more than just using the cpu. |
| 177 | * Currently, we assign only half the cpu time to an app that is running but |
| 178 | * not holding a wakelock. The apps holding wakelocks get the rest of the blame. |
| 179 | * If no app is holding a wakelock, then the distribution is normal. |
| 180 | */ |
| 181 | @VisibleForTesting |
| 182 | public static final int WAKE_LOCK_WEIGHT = 50; |
| 183 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 184 | protected Clocks mClocks; |
| 185 | |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 186 | private final JournaledFile mFile; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 187 | public final AtomicFile mCheckinFile; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 188 | public final AtomicFile mDailyFile; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 189 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 190 | static final int MSG_UPDATE_WAKELOCKS = 1; |
| 191 | static final int MSG_REPORT_POWER_CHANGE = 2; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 192 | static final int MSG_REPORT_CHARGING = 3; |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 193 | static final long DELAY_UPDATE_WAKELOCKS = 5*1000; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 194 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 195 | private final KernelWakelockReader mKernelWakelockReader = new KernelWakelockReader(); |
| 196 | private final KernelWakelockStats mTmpWakelockStats = new KernelWakelockStats(); |
| 197 | |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 198 | @VisibleForTesting |
| 199 | protected KernelUidCpuTimeReader mKernelUidCpuTimeReader = new KernelUidCpuTimeReader(); |
| 200 | @VisibleForTesting |
| 201 | protected KernelCpuSpeedReader[] mKernelCpuSpeedReaders; |
| 202 | @VisibleForTesting |
| 203 | protected KernelUidCpuFreqTimeReader mKernelUidCpuFreqTimeReader = |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 204 | new KernelUidCpuFreqTimeReader(); |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 205 | @VisibleForTesting |
Mike Ma | 3d422c3 | 2017-10-25 11:08:57 -0700 | [diff] [blame] | 206 | protected KernelUidCpuActiveTimeReader mKernelUidCpuActiveTimeReader = |
| 207 | new KernelUidCpuActiveTimeReader(); |
| 208 | @VisibleForTesting |
| 209 | protected KernelUidCpuClusterTimeReader mKernelUidCpuClusterTimeReader = |
| 210 | new KernelUidCpuClusterTimeReader(); |
| 211 | @VisibleForTesting |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 212 | protected KernelSingleUidTimeReader mKernelSingleUidTimeReader; |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 213 | |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 214 | private final KernelMemoryBandwidthStats mKernelMemoryBandwidthStats |
| 215 | = new KernelMemoryBandwidthStats(); |
| 216 | private final LongSparseArray<SamplingTimer> mKernelMemoryStats = new LongSparseArray<>(); |
| 217 | public LongSparseArray<SamplingTimer> getKernelMemoryStats() { |
| 218 | return mKernelMemoryStats; |
| 219 | } |
| 220 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 221 | @GuardedBy("this") |
| 222 | public boolean mPerProcStateCpuTimesAvailable = true; |
| 223 | |
| 224 | /** |
| 225 | * Uids for which per-procstate cpu times need to be updated. |
| 226 | * |
| 227 | * Contains uid -> procState mappings. |
| 228 | */ |
| 229 | @GuardedBy("this") |
| 230 | @VisibleForTesting |
| 231 | protected final SparseIntArray mPendingUids = new SparseIntArray(); |
| 232 | |
Bookatz | 0b8a050 | 2017-09-13 11:51:52 -0700 | [diff] [blame] | 233 | /** Container for Resource Power Manager stats. Updated by updateRpmStatsLocked. */ |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 234 | private final RpmStats mTmpRpmStats = new RpmStats(); |
Bookatz | 0b8a050 | 2017-09-13 11:51:52 -0700 | [diff] [blame] | 235 | /** The soonest the RPM stats can be updated after it was last updated. */ |
| 236 | private static final long RPM_STATS_UPDATE_FREQ_MS = 1000; |
| 237 | /** Last time that RPM stats were updated by updateRpmStatsLocked. */ |
| 238 | private long mLastRpmStatsUpdateTimeMs = -RPM_STATS_UPDATE_FREQ_MS; |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 239 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 240 | public interface BatteryCallback { |
| 241 | public void batteryNeedsCpuUpdate(); |
| 242 | public void batteryPowerChanged(boolean onBattery); |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 243 | public void batterySendBroadcast(Intent intent); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 244 | } |
| 245 | |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 246 | public interface PlatformIdleStateCallback { |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 247 | public void fillLowPowerStats(RpmStats rpmStats); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 248 | public String getPlatformLowPowerStats(); |
Ahmed ElArabawy | d8b4411 | 2017-05-23 21:25:02 +0000 | [diff] [blame] | 249 | public String getSubsystemLowPowerStats(); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 250 | } |
| 251 | |
Suprabh Shukla | e6e723d | 2017-06-14 16:14:43 -0700 | [diff] [blame] | 252 | public static abstract class UserInfoProvider { |
| 253 | private int[] userIds; |
| 254 | protected abstract @Nullable int[] getUserIds(); |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 255 | @VisibleForTesting |
| 256 | public final void refreshUserIds() { |
Suprabh Shukla | e6e723d | 2017-06-14 16:14:43 -0700 | [diff] [blame] | 257 | userIds = getUserIds(); |
| 258 | } |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 259 | @VisibleForTesting |
| 260 | public boolean exists(int userId) { |
Suprabh Shukla | e6e723d | 2017-06-14 16:14:43 -0700 | [diff] [blame] | 261 | return userIds != null ? ArrayUtils.contains(userIds, userId) : true; |
| 262 | } |
| 263 | } |
| 264 | |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 265 | private final PlatformIdleStateCallback mPlatformIdleStateCallback; |
| 266 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 267 | final class MyHandler extends Handler { |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 268 | public MyHandler(Looper looper) { |
| 269 | super(looper, null, true); |
| 270 | } |
| 271 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 272 | @Override |
| 273 | public void handleMessage(Message msg) { |
| 274 | BatteryCallback cb = mCallback; |
| 275 | switch (msg.what) { |
| 276 | case MSG_UPDATE_WAKELOCKS: |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 277 | synchronized (BatteryStatsImpl.this) { |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 278 | updateCpuTimeLocked(); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 279 | } |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 280 | if (cb != null) { |
| 281 | cb.batteryNeedsCpuUpdate(); |
| 282 | } |
| 283 | break; |
| 284 | case MSG_REPORT_POWER_CHANGE: |
| 285 | if (cb != null) { |
| 286 | cb.batteryPowerChanged(msg.arg1 != 0); |
| 287 | } |
| 288 | break; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 289 | case MSG_REPORT_CHARGING: |
| 290 | if (cb != null) { |
| 291 | final String action; |
| 292 | synchronized (BatteryStatsImpl.this) { |
| 293 | action = mCharging ? BatteryManager.ACTION_CHARGING |
| 294 | : BatteryManager.ACTION_DISCHARGING; |
| 295 | } |
| 296 | Intent intent = new Intent(action); |
| 297 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); |
| 298 | cb.batterySendBroadcast(intent); |
| 299 | } |
| 300 | break; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 301 | } |
| 302 | } |
| 303 | } |
| 304 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 305 | /** |
| 306 | * Update per-freq cpu times for all the uids in {@link #mPendingUids}. |
| 307 | */ |
Sudheer Shanka | e544d16 | 2017-12-28 17:06:20 -0800 | [diff] [blame] | 308 | public void updateProcStateCpuTimes(boolean onBattery, boolean onBatteryScreenOff) { |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 309 | final SparseIntArray uidStates; |
| 310 | synchronized (BatteryStatsImpl.this) { |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 311 | if (!mConstants.TRACK_CPU_TIMES_BY_PROC_STATE) { |
| 312 | return; |
| 313 | } |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 314 | if(!initKernelSingleUidTimeReaderLocked()) { |
| 315 | return; |
| 316 | } |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 317 | // If the KernelSingleUidTimeReader has stale cpu times, then we shouldn't try to |
| 318 | // compute deltas since it might result in mis-attributing cpu times to wrong states. |
| 319 | if (mKernelSingleUidTimeReader.hasStaleData()) { |
| 320 | mPendingUids.clear(); |
| 321 | return; |
| 322 | } |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 323 | |
| 324 | if (mPendingUids.size() == 0) { |
| 325 | return; |
| 326 | } |
| 327 | uidStates = mPendingUids.clone(); |
| 328 | mPendingUids.clear(); |
| 329 | } |
| 330 | for (int i = uidStates.size() - 1; i >= 0; --i) { |
| 331 | final int uid = uidStates.keyAt(i); |
| 332 | final int procState = uidStates.valueAt(i); |
| 333 | final int[] isolatedUids; |
| 334 | final Uid u; |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 335 | synchronized (BatteryStatsImpl.this) { |
| 336 | // It's possible that uid no longer exists and any internal references have |
| 337 | // already been deleted, so using {@link #getAvailableUidStatsLocked} to avoid |
| 338 | // creating an UidStats object if it doesn't already exist. |
| 339 | u = getAvailableUidStatsLocked(uid); |
| 340 | if (u == null) { |
| 341 | continue; |
| 342 | } |
| 343 | if (u.mChildUids == null) { |
| 344 | isolatedUids = null; |
| 345 | } else { |
| 346 | isolatedUids = u.mChildUids.toArray(); |
| 347 | for (int j = isolatedUids.length - 1; j >= 0; --j) { |
| 348 | isolatedUids[j] = u.mChildUids.get(j); |
| 349 | } |
| 350 | } |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 351 | } |
| 352 | long[] cpuTimesMs = mKernelSingleUidTimeReader.readDeltaMs(uid); |
| 353 | if (isolatedUids != null) { |
| 354 | for (int j = isolatedUids.length - 1; j >= 0; --j) { |
| 355 | cpuTimesMs = addCpuTimes(cpuTimesMs, |
| 356 | mKernelSingleUidTimeReader.readDeltaMs(isolatedUids[j])); |
| 357 | } |
| 358 | } |
| 359 | if (onBattery && cpuTimesMs != null) { |
| 360 | synchronized (BatteryStatsImpl.this) { |
Sudheer Shanka | e544d16 | 2017-12-28 17:06:20 -0800 | [diff] [blame] | 361 | u.addProcStateTimesMs(procState, cpuTimesMs, onBattery); |
| 362 | u.addProcStateScreenOffTimesMs(procState, cpuTimesMs, onBatteryScreenOff); |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 363 | } |
| 364 | } |
| 365 | } |
| 366 | } |
| 367 | |
Sudheer Shanka | e544d16 | 2017-12-28 17:06:20 -0800 | [diff] [blame] | 368 | public void copyFromAllUidsCpuTimes() { |
| 369 | synchronized (BatteryStatsImpl.this) { |
| 370 | copyFromAllUidsCpuTimes( |
| 371 | mOnBatteryTimeBase.isRunning(), mOnBatteryScreenOffTimeBase.isRunning()); |
| 372 | } |
| 373 | } |
| 374 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 375 | /** |
| 376 | * When the battery/screen state changes, we don't attribute the cpu times to any process |
| 377 | * but we still need to snapshots of all uids to get correct deltas later on. Since we |
| 378 | * already read this data for updating per-freq cpu times, we can use the same data for |
| 379 | * per-procstate cpu times. |
| 380 | */ |
Sudheer Shanka | e544d16 | 2017-12-28 17:06:20 -0800 | [diff] [blame] | 381 | public void copyFromAllUidsCpuTimes(boolean onBattery, boolean onBatteryScreenOff) { |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 382 | synchronized (BatteryStatsImpl.this) { |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 383 | if (!mConstants.TRACK_CPU_TIMES_BY_PROC_STATE) { |
| 384 | return; |
| 385 | } |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 386 | if(!initKernelSingleUidTimeReaderLocked()) { |
| 387 | return; |
| 388 | } |
| 389 | |
| 390 | final SparseArray<long[]> allUidCpuFreqTimesMs = |
| 391 | mKernelUidCpuFreqTimeReader.getAllUidCpuFreqTimeMs(); |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 392 | // If the KernelSingleUidTimeReader has stale cpu times, then we shouldn't try to |
| 393 | // compute deltas since it might result in mis-attributing cpu times to wrong states. |
| 394 | if (mKernelSingleUidTimeReader.hasStaleData()) { |
| 395 | mKernelSingleUidTimeReader.setAllUidsCpuTimesMs(allUidCpuFreqTimesMs); |
| 396 | mKernelSingleUidTimeReader.markDataAsStale(false); |
| 397 | mPendingUids.clear(); |
| 398 | return; |
| 399 | } |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 400 | for (int i = allUidCpuFreqTimesMs.size() - 1; i >= 0; --i) { |
| 401 | final int uid = allUidCpuFreqTimesMs.keyAt(i); |
| 402 | final Uid u = getAvailableUidStatsLocked(mapUid(uid)); |
| 403 | if (u == null) { |
| 404 | continue; |
| 405 | } |
| 406 | final long[] cpuTimesMs = allUidCpuFreqTimesMs.valueAt(i); |
| 407 | if (cpuTimesMs == null) { |
| 408 | continue; |
| 409 | } |
| 410 | final long[] deltaTimesMs = mKernelSingleUidTimeReader.computeDelta( |
| 411 | uid, cpuTimesMs.clone()); |
Sudheer Shanka | e544d16 | 2017-12-28 17:06:20 -0800 | [diff] [blame] | 412 | if (onBattery && deltaTimesMs != null) { |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 413 | final int procState; |
| 414 | final int idx = mPendingUids.indexOfKey(uid); |
| 415 | if (idx >= 0) { |
| 416 | procState = mPendingUids.valueAt(idx); |
| 417 | mPendingUids.removeAt(idx); |
| 418 | } else { |
| 419 | procState = u.mProcessState; |
| 420 | } |
| 421 | if (procState >= 0 && procState < Uid.NUM_PROCESS_STATE) { |
Sudheer Shanka | e544d16 | 2017-12-28 17:06:20 -0800 | [diff] [blame] | 422 | u.addProcStateTimesMs(procState, deltaTimesMs, onBattery); |
| 423 | u.addProcStateScreenOffTimesMs(procState, deltaTimesMs, onBatteryScreenOff); |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 424 | } |
| 425 | } |
| 426 | } |
| 427 | } |
| 428 | } |
| 429 | |
| 430 | @VisibleForTesting |
| 431 | public long[] addCpuTimes(long[] timesA, long[] timesB) { |
| 432 | if (timesA != null && timesB != null) { |
| 433 | for (int i = timesA.length - 1; i >= 0; --i) { |
| 434 | timesA[i] += timesB[i]; |
| 435 | } |
| 436 | return timesA; |
| 437 | } |
| 438 | return timesA == null ? (timesB == null ? null : timesB) : timesA; |
| 439 | } |
| 440 | |
| 441 | @GuardedBy("this") |
| 442 | private boolean initKernelSingleUidTimeReaderLocked() { |
| 443 | if (mKernelSingleUidTimeReader == null) { |
| 444 | if (mPowerProfile == null) { |
| 445 | return false; |
| 446 | } |
| 447 | if (mCpuFreqs == null) { |
| 448 | mCpuFreqs = mKernelUidCpuFreqTimeReader.readFreqs(mPowerProfile); |
| 449 | } |
| 450 | if (mCpuFreqs != null) { |
| 451 | mKernelSingleUidTimeReader = new KernelSingleUidTimeReader(mCpuFreqs.length); |
| 452 | } else { |
| 453 | mPerProcStateCpuTimesAvailable = mKernelUidCpuFreqTimeReader.allUidTimesAvailable(); |
| 454 | return false; |
| 455 | } |
| 456 | } |
| 457 | mPerProcStateCpuTimesAvailable = mKernelUidCpuFreqTimeReader.allUidTimesAvailable() |
| 458 | && mKernelSingleUidTimeReader.singleUidCpuTimesAvailable(); |
| 459 | return true; |
| 460 | } |
| 461 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 462 | public interface Clocks { |
| 463 | public long elapsedRealtime(); |
| 464 | public long uptimeMillis(); |
| 465 | } |
| 466 | |
| 467 | public static class SystemClocks implements Clocks { |
| 468 | public long elapsedRealtime() { |
| 469 | return SystemClock.elapsedRealtime(); |
| 470 | } |
| 471 | |
| 472 | public long uptimeMillis() { |
| 473 | return SystemClock.uptimeMillis(); |
| 474 | } |
| 475 | } |
| 476 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 477 | public interface ExternalStatsSync { |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 478 | int UPDATE_CPU = 0x01; |
| 479 | int UPDATE_WIFI = 0x02; |
| 480 | int UPDATE_RADIO = 0x04; |
| 481 | int UPDATE_BT = 0x08; |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 482 | int UPDATE_RPM = 0x10; // 16 |
| 483 | 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] | 484 | |
Adam Lesinski | b3a1bad | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 485 | Future<?> scheduleSync(String reason, int flags); |
| 486 | Future<?> scheduleCpuSyncDueToRemovedUid(int uid); |
Sudheer Shanka | e544d16 | 2017-12-28 17:06:20 -0800 | [diff] [blame] | 487 | Future<?> scheduleReadProcStateCpuTimes(boolean onBattery, boolean onBatteryScreenOff); |
| 488 | Future<?> scheduleCopyFromAllUidsCpuTimes(boolean onBattery, boolean onBatteryScreenOff); |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 489 | Future<?> scheduleCpuSyncDueToSettingChange(); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 490 | } |
| 491 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 492 | public Handler mHandler; |
Adam Lesinski | b3a1bad | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 493 | private ExternalStatsSync mExternalSync = null; |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 494 | @VisibleForTesting |
| 495 | protected UserInfoProvider mUserInfoProvider = null; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 496 | |
| 497 | private BatteryCallback mCallback; |
| 498 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 499 | /** |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 500 | * Mapping isolated uids to the actual owning app uid. |
| 501 | */ |
| 502 | final SparseIntArray mIsolatedUids = new SparseIntArray(); |
| 503 | |
| 504 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 505 | * The statistics we have collected organized by uids. |
| 506 | */ |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 507 | final SparseArray<BatteryStatsImpl.Uid> mUidStats = new SparseArray<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 508 | |
| 509 | // A set of pools of currently active timers. When a timer is queried, we will divide the |
| 510 | // elapsed time by the number of active timers to arrive at that timer's share of the time. |
| 511 | // In order to do this, we must refresh each timer whenever the number of active timers |
| 512 | // changes. |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 513 | @VisibleForTesting |
| 514 | protected ArrayList<StopwatchTimer> mPartialTimers = new ArrayList<>(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 515 | final ArrayList<StopwatchTimer> mFullTimers = new ArrayList<>(); |
| 516 | final ArrayList<StopwatchTimer> mWindowTimers = new ArrayList<>(); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 517 | final ArrayList<StopwatchTimer> mDrawTimers = new ArrayList<>(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 518 | final SparseArray<ArrayList<StopwatchTimer>> mSensorTimers = new SparseArray<>(); |
| 519 | final ArrayList<StopwatchTimer> mWifiRunningTimers = new ArrayList<>(); |
| 520 | final ArrayList<StopwatchTimer> mFullWifiLockTimers = new ArrayList<>(); |
| 521 | final ArrayList<StopwatchTimer> mWifiMulticastTimers = new ArrayList<>(); |
| 522 | final ArrayList<StopwatchTimer> mWifiScanTimers = new ArrayList<>(); |
| 523 | final SparseArray<ArrayList<StopwatchTimer>> mWifiBatchedScanTimers = new SparseArray<>(); |
| 524 | final ArrayList<StopwatchTimer> mAudioTurnedOnTimers = new ArrayList<>(); |
| 525 | final ArrayList<StopwatchTimer> mVideoTurnedOnTimers = new ArrayList<>(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 526 | final ArrayList<StopwatchTimer> mFlashlightTurnedOnTimers = new ArrayList<>(); |
| 527 | final ArrayList<StopwatchTimer> mCameraTurnedOnTimers = new ArrayList<>(); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 528 | final ArrayList<StopwatchTimer> mBluetoothScanOnTimers = new ArrayList<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 529 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 530 | // Last partial timers we use for distributing CPU usage. |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 531 | @VisibleForTesting |
| 532 | protected ArrayList<StopwatchTimer> mLastPartialTimers = new ArrayList<>(); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 533 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 534 | // These are the objects that will want to do something when the device |
| 535 | // is unplugged from power. |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 536 | protected final TimeBase mOnBatteryTimeBase = new TimeBase(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 537 | |
| 538 | // 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] | 539 | // is unplugged from power *and* the screen is off or doze. |
| 540 | protected final TimeBase mOnBatteryScreenOffTimeBase = new TimeBase(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 541 | |
| 542 | // Set to true when we want to distribute CPU across wakelocks for the next |
| 543 | // CPU update, even if we aren't currently running wake locks. |
| 544 | boolean mDistributeWakelockCpu; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 545 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 546 | boolean mShuttingDown; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 547 | |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 548 | final HistoryEventTracker mActiveEvents = new HistoryEventTracker(); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 549 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 550 | long mHistoryBaseTime; |
Narayan Kamath | 695cf72 | 2017-12-21 18:32:47 +0000 | [diff] [blame] | 551 | protected boolean mHaveBatteryLevel = false; |
| 552 | protected boolean mRecordingHistory = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 553 | int mNumHistoryItems; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 554 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 555 | final Parcel mHistoryBuffer = Parcel.obtain(); |
| 556 | final HistoryItem mHistoryLastWritten = new HistoryItem(); |
| 557 | final HistoryItem mHistoryLastLastWritten = new HistoryItem(); |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 558 | final HistoryItem mHistoryReadTmp = new HistoryItem(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 559 | final HistoryItem mHistoryAddTmp = new HistoryItem(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 560 | final HashMap<HistoryTag, Integer> mHistoryTagPool = new HashMap<>(); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 561 | String[] mReadHistoryStrings; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 562 | int[] mReadHistoryUids; |
| 563 | int mReadHistoryChars; |
| 564 | int mNextHistoryTagIdx = 0; |
| 565 | int mNumHistoryTagChars = 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 566 | int mHistoryBufferLastPos = -1; |
| 567 | boolean mHistoryOverflow = false; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 568 | int mActiveHistoryStates = 0xffffffff; |
| 569 | int mActiveHistoryStates2 = 0xffffffff; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 570 | long mLastHistoryElapsedRealtime = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 571 | long mTrackRunningHistoryElapsedRealtime = 0; |
| 572 | long mTrackRunningHistoryUptime = 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 573 | |
| 574 | final HistoryItem mHistoryCur = new HistoryItem(); |
| 575 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 576 | HistoryItem mHistory; |
| 577 | HistoryItem mHistoryEnd; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 578 | HistoryItem mHistoryLastEnd; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 579 | HistoryItem mHistoryCache; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 580 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 581 | // Used by computeHistoryStepDetails |
| 582 | HistoryStepDetails mLastHistoryStepDetails = null; |
| 583 | byte mLastHistoryStepLevel = 0; |
| 584 | final HistoryStepDetails mCurHistoryStepDetails = new HistoryStepDetails(); |
| 585 | final HistoryStepDetails mReadHistoryStepDetails = new HistoryStepDetails(); |
| 586 | final HistoryStepDetails mTmpHistoryStepDetails = new HistoryStepDetails(); |
Adam Lesinski | 7b83b0c | 2015-06-05 12:59:36 -0700 | [diff] [blame] | 587 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 588 | /** |
Adam Lesinski | 7b83b0c | 2015-06-05 12:59:36 -0700 | [diff] [blame] | 589 | * Total time (in milliseconds) spent executing in user code. |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 590 | */ |
| 591 | long mLastStepCpuUserTime; |
| 592 | long mCurStepCpuUserTime; |
| 593 | /** |
Adam Lesinski | 7b83b0c | 2015-06-05 12:59:36 -0700 | [diff] [blame] | 594 | * Total time (in milliseconds) spent executing in kernel code. |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 595 | */ |
| 596 | long mLastStepCpuSystemTime; |
| 597 | long mCurStepCpuSystemTime; |
| 598 | /** |
Adam Lesinski | 7b83b0c | 2015-06-05 12:59:36 -0700 | [diff] [blame] | 599 | * Times from /proc/stat (but measured in milliseconds). |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 600 | */ |
| 601 | long mLastStepStatUserTime; |
| 602 | long mLastStepStatSystemTime; |
| 603 | long mLastStepStatIOWaitTime; |
| 604 | long mLastStepStatIrqTime; |
| 605 | long mLastStepStatSoftIrqTime; |
| 606 | long mLastStepStatIdleTime; |
| 607 | long mCurStepStatUserTime; |
| 608 | long mCurStepStatSystemTime; |
| 609 | long mCurStepStatIOWaitTime; |
| 610 | long mCurStepStatIrqTime; |
| 611 | long mCurStepStatSoftIrqTime; |
| 612 | long mCurStepStatIdleTime; |
| 613 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 614 | private HistoryItem mHistoryIterator; |
| 615 | private boolean mReadOverflow; |
| 616 | private boolean mIteratingHistory; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 617 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 618 | int mStartCount; |
| 619 | |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 620 | long mStartClockTime; |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 621 | String mStartPlatformVersion; |
| 622 | String mEndPlatformVersion; |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 623 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 624 | long mUptime; |
| 625 | long mUptimeStart; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 626 | long mRealtime; |
| 627 | long mRealtimeStart; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 628 | |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 629 | int mWakeLockNesting; |
| 630 | boolean mWakeLockImportant; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 631 | public boolean mRecordAllHistory; |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 632 | boolean mNoAutoReset; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 633 | |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 634 | @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 635 | protected int mScreenState = Display.STATE_UNKNOWN; |
| 636 | @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 637 | protected StopwatchTimer mScreenOnTimer; |
| 638 | @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 639 | protected StopwatchTimer mScreenDozeTimer; |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 640 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 641 | int mScreenBrightnessBin = -1; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 642 | final StopwatchTimer[] mScreenBrightnessTimer = new StopwatchTimer[NUM_SCREEN_BRIGHTNESS_BINS]; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 643 | |
Amith Yamasani | 674c9bb | 2017-02-01 09:45:17 -0800 | [diff] [blame] | 644 | boolean mPretendScreenOff; |
| 645 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 646 | boolean mInteractive; |
| 647 | StopwatchTimer mInteractiveTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 648 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 649 | boolean mPowerSaveModeEnabled; |
| 650 | StopwatchTimer mPowerSaveModeEnabledTimer; |
| 651 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 652 | boolean mDeviceIdling; |
| 653 | StopwatchTimer mDeviceIdlingTimer; |
| 654 | |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 655 | boolean mDeviceLightIdling; |
| 656 | StopwatchTimer mDeviceLightIdlingTimer; |
| 657 | |
| 658 | int mDeviceIdleMode; |
| 659 | long mLastIdleTimeStart; |
| 660 | long mLongestLightIdleTime; |
| 661 | long mLongestFullIdleTime; |
| 662 | StopwatchTimer mDeviceIdleModeLightTimer; |
| 663 | StopwatchTimer mDeviceIdleModeFullTimer; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 664 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 665 | boolean mPhoneOn; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 666 | StopwatchTimer mPhoneOnTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 667 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 668 | int mAudioOnNesting; |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 669 | StopwatchTimer mAudioOnTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 670 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 671 | int mVideoOnNesting; |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 672 | StopwatchTimer mVideoOnTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 673 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 674 | int mFlashlightOnNesting; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 675 | StopwatchTimer mFlashlightOnTimer; |
| 676 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 677 | int mCameraOnNesting; |
| 678 | StopwatchTimer mCameraOnTimer; |
| 679 | |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 680 | int mGpsSignalQualityBin = -1; |
| 681 | final StopwatchTimer[] mGpsSignalQualityTimer = |
| 682 | new StopwatchTimer[GnssMetrics.NUM_GPS_SIGNAL_QUALITY_LEVELS]; |
| 683 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 684 | int mPhoneSignalStrengthBin = -1; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 685 | int mPhoneSignalStrengthBinRaw = -1; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 686 | final StopwatchTimer[] mPhoneSignalStrengthsTimer = |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 687 | new StopwatchTimer[SignalStrength.NUM_SIGNAL_STRENGTH_BINS]; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 688 | |
| 689 | StopwatchTimer mPhoneSignalScanningTimer; |
| 690 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 691 | int mPhoneDataConnectionType = -1; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 692 | final StopwatchTimer[] mPhoneDataConnectionsTimer = |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 693 | new StopwatchTimer[NUM_DATA_CONNECTION_TYPES]; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 694 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 695 | final LongSamplingCounter[] mNetworkByteActivityCounters = |
| 696 | new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
| 697 | final LongSamplingCounter[] mNetworkPacketActivityCounters = |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 698 | new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
| 699 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 700 | /** |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 701 | * The WiFi Overall wakelock timer |
| 702 | * This timer tracks the actual aggregate time for which MC wakelocks are enabled |
| 703 | * since addition of per UID timers would not result in an accurate value due to overlapp of |
| 704 | * per uid wakelock timers |
| 705 | */ |
| 706 | StopwatchTimer mWifiMulticastWakelockTimer; |
| 707 | |
| 708 | /** |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 709 | * The WiFi controller activity (time in tx, rx, idle, and power consumed) for the device. |
| 710 | */ |
| 711 | ControllerActivityCounterImpl mWifiActivity; |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 712 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 713 | /** |
| 714 | * The Bluetooth controller activity (time in tx, rx, idle, and power consumed) for the device. |
| 715 | */ |
| 716 | ControllerActivityCounterImpl mBluetoothActivity; |
| 717 | |
| 718 | /** |
| 719 | * The Modem controller activity (time in tx, rx, idle, and power consumed) for the device. |
| 720 | */ |
| 721 | ControllerActivityCounterImpl mModemActivity; |
| 722 | |
| 723 | /** |
| 724 | * Whether the device supports WiFi controller energy reporting. This is set to true on |
| 725 | * the first WiFi energy report. See {@link #mWifiActivity}. |
| 726 | */ |
| 727 | boolean mHasWifiReporting = false; |
| 728 | |
| 729 | /** |
| 730 | * Whether the device supports Bluetooth controller energy reporting. This is set to true on |
| 731 | * the first Bluetooth energy report. See {@link #mBluetoothActivity}. |
| 732 | */ |
| 733 | boolean mHasBluetoothReporting = false; |
| 734 | |
| 735 | /** |
| 736 | * Whether the device supports Modem controller energy reporting. This is set to true on |
| 737 | * the first Modem energy report. See {@link #mModemActivity}. |
| 738 | */ |
| 739 | boolean mHasModemReporting = false; |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 740 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 741 | boolean mWifiOn; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 742 | StopwatchTimer mWifiOnTimer; |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 743 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 744 | boolean mGlobalWifiRunning; |
| 745 | StopwatchTimer mGlobalWifiRunningTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 746 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 747 | int mWifiState = -1; |
| 748 | final StopwatchTimer[] mWifiStateTimer = new StopwatchTimer[NUM_WIFI_STATES]; |
| 749 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 750 | int mWifiSupplState = -1; |
| 751 | final StopwatchTimer[] mWifiSupplStateTimer = new StopwatchTimer[NUM_WIFI_SUPPL_STATES]; |
| 752 | |
| 753 | int mWifiSignalStrengthBin = -1; |
| 754 | final StopwatchTimer[] mWifiSignalStrengthsTimer = |
| 755 | new StopwatchTimer[NUM_WIFI_SIGNAL_STRENGTH_BINS]; |
| 756 | |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 757 | StopwatchTimer mWifiActiveTimer; |
| 758 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 759 | int mBluetoothScanNesting; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 760 | @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 761 | protected StopwatchTimer mBluetoothScanTimer; |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 762 | |
Siddharth Ray | f5e796a | 2018-01-22 18:18:17 -0800 | [diff] [blame] | 763 | boolean mIsCellularTxPowerHigh = false; |
| 764 | |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 765 | int mMobileRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
Dianne Hackborn | f7097a5 | 2014-05-13 09:56:14 -0700 | [diff] [blame] | 766 | long mMobileRadioActiveStartTime; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 767 | StopwatchTimer mMobileRadioActiveTimer; |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 768 | StopwatchTimer mMobileRadioActivePerAppTimer; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 769 | LongSamplingCounter mMobileRadioActiveAdjustedTime; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 770 | LongSamplingCounter mMobileRadioActiveUnknownTime; |
| 771 | LongSamplingCounter mMobileRadioActiveUnknownCount; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 772 | |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 773 | int mWifiRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
| 774 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 775 | /** |
| 776 | * These provide time bases that discount the time the device is plugged |
| 777 | * in to power. |
| 778 | */ |
| 779 | boolean mOnBattery; |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 780 | @VisibleForTesting |
| 781 | protected boolean mOnBatteryInternal; |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 782 | |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 783 | /** |
| 784 | * External reporting of whether the device is actually charging. |
| 785 | */ |
| 786 | boolean mCharging = true; |
| 787 | int mLastChargingStateLevel; |
| 788 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 789 | /* |
| 790 | * These keep track of battery levels (1-100) at the last plug event and the last unplug event. |
| 791 | */ |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 792 | int mDischargeStartLevel; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 793 | int mDischargeUnplugLevel; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 794 | int mDischargePlugLevel; |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 795 | int mDischargeCurrentLevel; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 796 | int mCurrentBatteryLevel; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 797 | int mLowDischargeAmountSinceCharge; |
| 798 | int mHighDischargeAmountSinceCharge; |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 799 | int mDischargeScreenOnUnplugLevel; |
| 800 | int mDischargeScreenOffUnplugLevel; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 801 | int mDischargeScreenDozeUnplugLevel; |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 802 | int mDischargeAmountScreenOn; |
| 803 | int mDischargeAmountScreenOnSinceCharge; |
| 804 | int mDischargeAmountScreenOff; |
| 805 | int mDischargeAmountScreenOffSinceCharge; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 806 | int mDischargeAmountScreenDoze; |
| 807 | int mDischargeAmountScreenDozeSinceCharge; |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 808 | |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 809 | private LongSamplingCounter mDischargeScreenOffCounter; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 810 | private LongSamplingCounter mDischargeScreenDozeCounter; |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 811 | private LongSamplingCounter mDischargeCounter; |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 812 | private LongSamplingCounter mDischargeLightDozeCounter; |
| 813 | private LongSamplingCounter mDischargeDeepDozeCounter; |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 814 | |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 815 | static final int MAX_LEVEL_STEPS = 200; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 816 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 817 | int mInitStepMode = 0; |
| 818 | int mCurStepMode = 0; |
| 819 | int mModStepMode = 0; |
| 820 | |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 821 | int mLastDischargeStepLevel; |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 822 | int mMinDischargeStepLevel; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 823 | final LevelStepTracker mDischargeStepTracker = new LevelStepTracker(MAX_LEVEL_STEPS); |
| 824 | final LevelStepTracker mDailyDischargeStepTracker = new LevelStepTracker(MAX_LEVEL_STEPS*2); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 825 | ArrayList<PackageChange> mDailyPackageChanges; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 826 | |
| 827 | int mLastChargeStepLevel; |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 828 | int mMaxChargeStepLevel; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 829 | final LevelStepTracker mChargeStepTracker = new LevelStepTracker(MAX_LEVEL_STEPS); |
| 830 | final LevelStepTracker mDailyChargeStepTracker = new LevelStepTracker(MAX_LEVEL_STEPS*2); |
| 831 | |
| 832 | static final int MAX_DAILY_ITEMS = 10; |
| 833 | |
| 834 | long mDailyStartTime = 0; |
| 835 | long mNextMinDailyDeadline = 0; |
| 836 | long mNextMaxDailyDeadline = 0; |
| 837 | |
| 838 | final ArrayList<DailyItem> mDailyItems = new ArrayList<>(); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 839 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 840 | long mLastWriteTime = 0; // Milliseconds |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 841 | |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 842 | private int mPhoneServiceState = -1; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 843 | private int mPhoneServiceStateRaw = -1; |
| 844 | private int mPhoneSimStateRaw = -1; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 845 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 846 | private int mNumConnectivityChange; |
| 847 | private int mLoadedNumConnectivityChange; |
| 848 | private int mUnpluggedNumConnectivityChange; |
| 849 | |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 850 | private int mEstimatedBatteryCapacity = -1; |
| 851 | |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 852 | private int mMinLearnedBatteryCapacity = -1; |
| 853 | private int mMaxLearnedBatteryCapacity = -1; |
Adam Lesinski | 041d917 | 2016-12-12 12:03:56 -0800 | [diff] [blame] | 854 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 855 | private long[] mCpuFreqs; |
| 856 | |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 857 | @VisibleForTesting |
| 858 | protected PowerProfile mPowerProfile; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 859 | |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 860 | @GuardedBy("this") |
| 861 | private final Constants mConstants; |
| 862 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 863 | /* |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 864 | * Holds a SamplingTimer associated with each Resource Power Manager state and voter, |
| 865 | * recording their times when on-battery (regardless of screen state). |
| 866 | */ |
| 867 | private final HashMap<String, SamplingTimer> mRpmStats = new HashMap<>(); |
| 868 | /** Times for each Resource Power Manager state and voter when screen-off and on-battery. */ |
| 869 | private final HashMap<String, SamplingTimer> mScreenOffRpmStats = new HashMap<>(); |
| 870 | |
| 871 | @Override |
| 872 | public Map<String, ? extends Timer> getRpmStats() { |
| 873 | return mRpmStats; |
| 874 | } |
| 875 | |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 876 | // TODO: Note: screenOffRpmStats has been disabled via SCREEN_OFF_RPM_STATS_ENABLED. |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 877 | @Override |
| 878 | public Map<String, ? extends Timer> getScreenOffRpmStats() { |
| 879 | return mScreenOffRpmStats; |
| 880 | } |
| 881 | |
| 882 | /* |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 883 | * Holds a SamplingTimer associated with each kernel wakelock name being tracked. |
| 884 | */ |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 885 | private final HashMap<String, SamplingTimer> mKernelWakelockStats = new HashMap<>(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 886 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 887 | public Map<String, ? extends Timer> getKernelWakelockStats() { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 888 | return mKernelWakelockStats; |
| 889 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 890 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 891 | String mLastWakeupReason = null; |
| 892 | long mLastWakeupUptimeMs = 0; |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 893 | private final HashMap<String, SamplingTimer> mWakeupReasonStats = new HashMap<>(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 894 | |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 895 | public Map<String, ? extends Timer> getWakeupReasonStats() { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 896 | return mWakeupReasonStats; |
| 897 | } |
| 898 | |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 899 | @Override |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 900 | public long getUahDischarge(int which) { |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 901 | return mDischargeCounter.getCountLocked(which); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 902 | } |
| 903 | |
| 904 | @Override |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 905 | public long getUahDischargeScreenOff(int which) { |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 906 | return mDischargeScreenOffCounter.getCountLocked(which); |
| 907 | } |
| 908 | |
| 909 | @Override |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 910 | public long getUahDischargeScreenDoze(int which) { |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 911 | return mDischargeScreenDozeCounter.getCountLocked(which); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 912 | } |
| 913 | |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 914 | @Override |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 915 | public long getUahDischargeLightDoze(int which) { |
| 916 | return mDischargeLightDozeCounter.getCountLocked(which); |
| 917 | } |
| 918 | |
| 919 | @Override |
| 920 | public long getUahDischargeDeepDoze(int which) { |
| 921 | return mDischargeDeepDozeCounter.getCountLocked(which); |
| 922 | } |
| 923 | |
| 924 | @Override |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 925 | public int getEstimatedBatteryCapacity() { |
| 926 | return mEstimatedBatteryCapacity; |
| 927 | } |
| 928 | |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 929 | @Override |
| 930 | public int getMinLearnedBatteryCapacity() { |
| 931 | return mMinLearnedBatteryCapacity; |
| 932 | } |
| 933 | |
| 934 | @Override |
| 935 | public int getMaxLearnedBatteryCapacity() { |
| 936 | return mMaxLearnedBatteryCapacity; |
| 937 | } |
| 938 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 939 | public BatteryStatsImpl() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 940 | this(new SystemClocks()); |
| 941 | } |
| 942 | |
| 943 | public BatteryStatsImpl(Clocks clocks) { |
| 944 | init(clocks); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 945 | mFile = null; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 946 | mCheckinFile = null; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 947 | mDailyFile = null; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 948 | mHandler = null; |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 949 | mPlatformIdleStateCallback = null; |
Suprabh Shukla | e6e723d | 2017-06-14 16:14:43 -0700 | [diff] [blame] | 950 | mUserInfoProvider = null; |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 951 | mConstants = new Constants(mHandler); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 952 | clearHistoryLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 953 | } |
| 954 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 955 | private void init(Clocks clocks) { |
| 956 | mClocks = clocks; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 957 | } |
| 958 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 959 | public interface TimeBaseObs { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 960 | void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime); |
| 961 | void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime); |
| 962 | } |
| 963 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 964 | // methods are protected not private to be VisibleForTesting |
| 965 | public static class TimeBase { |
| 966 | protected final ArrayList<TimeBaseObs> mObservers = new ArrayList<>(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 967 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 968 | protected long mUptime; |
| 969 | protected long mRealtime; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 970 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 971 | protected boolean mRunning; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 972 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 973 | protected long mPastUptime; |
| 974 | protected long mUptimeStart; |
| 975 | protected long mPastRealtime; |
| 976 | protected long mRealtimeStart; |
| 977 | protected long mUnpluggedUptime; |
| 978 | protected long mUnpluggedRealtime; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 979 | |
| 980 | public void dump(PrintWriter pw, String prefix) { |
| 981 | StringBuilder sb = new StringBuilder(128); |
| 982 | pw.print(prefix); pw.print("mRunning="); pw.println(mRunning); |
| 983 | sb.setLength(0); |
| 984 | sb.append(prefix); |
| 985 | sb.append("mUptime="); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 986 | formatTimeMs(sb, mUptime / 1000); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 987 | pw.println(sb.toString()); |
| 988 | sb.setLength(0); |
| 989 | sb.append(prefix); |
| 990 | sb.append("mRealtime="); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 991 | formatTimeMs(sb, mRealtime / 1000); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 992 | pw.println(sb.toString()); |
| 993 | sb.setLength(0); |
| 994 | sb.append(prefix); |
| 995 | sb.append("mPastUptime="); |
| 996 | formatTimeMs(sb, mPastUptime / 1000); sb.append("mUptimeStart="); |
| 997 | formatTimeMs(sb, mUptimeStart / 1000); |
| 998 | sb.append("mUnpluggedUptime="); formatTimeMs(sb, mUnpluggedUptime / 1000); |
| 999 | pw.println(sb.toString()); |
| 1000 | sb.setLength(0); |
| 1001 | sb.append(prefix); |
| 1002 | sb.append("mPastRealtime="); |
| 1003 | formatTimeMs(sb, mPastRealtime / 1000); sb.append("mRealtimeStart="); |
| 1004 | formatTimeMs(sb, mRealtimeStart / 1000); |
| 1005 | sb.append("mUnpluggedRealtime="); formatTimeMs(sb, mUnpluggedRealtime / 1000); |
| 1006 | pw.println(sb.toString()); |
| 1007 | } |
| 1008 | |
| 1009 | public void add(TimeBaseObs observer) { |
| 1010 | mObservers.add(observer); |
| 1011 | } |
| 1012 | |
| 1013 | public void remove(TimeBaseObs observer) { |
| 1014 | if (!mObservers.remove(observer)) { |
| 1015 | Slog.wtf(TAG, "Removed unknown observer: " + observer); |
| 1016 | } |
| 1017 | } |
| 1018 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1019 | public boolean hasObserver(TimeBaseObs observer) { |
| 1020 | return mObservers.contains(observer); |
| 1021 | } |
| 1022 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1023 | public void init(long uptime, long realtime) { |
| 1024 | mRealtime = 0; |
| 1025 | mUptime = 0; |
| 1026 | mPastUptime = 0; |
| 1027 | mPastRealtime = 0; |
| 1028 | mUptimeStart = uptime; |
| 1029 | mRealtimeStart = realtime; |
| 1030 | mUnpluggedUptime = getUptime(mUptimeStart); |
| 1031 | mUnpluggedRealtime = getRealtime(mRealtimeStart); |
| 1032 | } |
| 1033 | |
| 1034 | public void reset(long uptime, long realtime) { |
| 1035 | if (!mRunning) { |
| 1036 | mPastUptime = 0; |
| 1037 | mPastRealtime = 0; |
| 1038 | } else { |
| 1039 | mUptimeStart = uptime; |
| 1040 | mRealtimeStart = realtime; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1041 | // TODO: Since mUptimeStart was just reset and we are running, getUptime will |
| 1042 | // 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] | 1043 | mUnpluggedUptime = getUptime(uptime); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1044 | // TODO: likewise. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1045 | mUnpluggedRealtime = getRealtime(realtime); |
| 1046 | } |
| 1047 | } |
| 1048 | |
| 1049 | public long computeUptime(long curTime, int which) { |
| 1050 | switch (which) { |
| 1051 | case STATS_SINCE_CHARGED: |
| 1052 | return mUptime + getUptime(curTime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1053 | case STATS_CURRENT: |
| 1054 | return getUptime(curTime); |
| 1055 | case STATS_SINCE_UNPLUGGED: |
| 1056 | return getUptime(curTime) - mUnpluggedUptime; |
| 1057 | } |
| 1058 | return 0; |
| 1059 | } |
| 1060 | |
| 1061 | public long computeRealtime(long curTime, int which) { |
| 1062 | switch (which) { |
| 1063 | case STATS_SINCE_CHARGED: |
| 1064 | return mRealtime + getRealtime(curTime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1065 | case STATS_CURRENT: |
| 1066 | return getRealtime(curTime); |
| 1067 | case STATS_SINCE_UNPLUGGED: |
| 1068 | return getRealtime(curTime) - mUnpluggedRealtime; |
| 1069 | } |
| 1070 | return 0; |
| 1071 | } |
| 1072 | |
| 1073 | public long getUptime(long curTime) { |
| 1074 | long time = mPastUptime; |
| 1075 | if (mRunning) { |
| 1076 | time += curTime - mUptimeStart; |
| 1077 | } |
| 1078 | return time; |
| 1079 | } |
| 1080 | |
| 1081 | public long getRealtime(long curTime) { |
| 1082 | long time = mPastRealtime; |
| 1083 | if (mRunning) { |
| 1084 | time += curTime - mRealtimeStart; |
| 1085 | } |
| 1086 | return time; |
| 1087 | } |
| 1088 | |
| 1089 | public long getUptimeStart() { |
| 1090 | return mUptimeStart; |
| 1091 | } |
| 1092 | |
| 1093 | public long getRealtimeStart() { |
| 1094 | return mRealtimeStart; |
| 1095 | } |
| 1096 | |
| 1097 | public boolean isRunning() { |
| 1098 | return mRunning; |
| 1099 | } |
| 1100 | |
| 1101 | public boolean setRunning(boolean running, long uptime, long realtime) { |
| 1102 | if (mRunning != running) { |
| 1103 | mRunning = running; |
| 1104 | if (running) { |
| 1105 | mUptimeStart = uptime; |
| 1106 | mRealtimeStart = realtime; |
| 1107 | long batteryUptime = mUnpluggedUptime = getUptime(uptime); |
| 1108 | long batteryRealtime = mUnpluggedRealtime = getRealtime(realtime); |
| 1109 | |
| 1110 | for (int i = mObservers.size() - 1; i >= 0; i--) { |
| 1111 | mObservers.get(i).onTimeStarted(realtime, batteryUptime, batteryRealtime); |
| 1112 | } |
| 1113 | } else { |
| 1114 | mPastUptime += uptime - mUptimeStart; |
| 1115 | mPastRealtime += realtime - mRealtimeStart; |
| 1116 | |
| 1117 | long batteryUptime = getUptime(uptime); |
| 1118 | long batteryRealtime = getRealtime(realtime); |
| 1119 | |
| 1120 | for (int i = mObservers.size() - 1; i >= 0; i--) { |
| 1121 | mObservers.get(i).onTimeStopped(realtime, batteryUptime, batteryRealtime); |
| 1122 | } |
| 1123 | } |
| 1124 | return true; |
| 1125 | } |
| 1126 | return false; |
| 1127 | } |
| 1128 | |
| 1129 | public void readSummaryFromParcel(Parcel in) { |
| 1130 | mUptime = in.readLong(); |
| 1131 | mRealtime = in.readLong(); |
| 1132 | } |
| 1133 | |
| 1134 | public void writeSummaryToParcel(Parcel out, long uptime, long realtime) { |
| 1135 | out.writeLong(computeUptime(uptime, STATS_SINCE_CHARGED)); |
| 1136 | out.writeLong(computeRealtime(realtime, STATS_SINCE_CHARGED)); |
| 1137 | } |
| 1138 | |
| 1139 | public void readFromParcel(Parcel in) { |
| 1140 | mRunning = false; |
| 1141 | mUptime = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1142 | mPastUptime = in.readLong(); |
| 1143 | mUptimeStart = in.readLong(); |
Dianne Hackborn | ef640cd | 2014-03-25 14:41:05 -0700 | [diff] [blame] | 1144 | mRealtime = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1145 | mPastRealtime = in.readLong(); |
| 1146 | mRealtimeStart = in.readLong(); |
| 1147 | mUnpluggedUptime = in.readLong(); |
| 1148 | mUnpluggedRealtime = in.readLong(); |
| 1149 | } |
| 1150 | |
| 1151 | public void writeToParcel(Parcel out, long uptime, long realtime) { |
| 1152 | final long runningUptime = getUptime(uptime); |
| 1153 | final long runningRealtime = getRealtime(realtime); |
| 1154 | out.writeLong(mUptime); |
| 1155 | out.writeLong(runningUptime); |
| 1156 | out.writeLong(mUptimeStart); |
Dianne Hackborn | ef640cd | 2014-03-25 14:41:05 -0700 | [diff] [blame] | 1157 | out.writeLong(mRealtime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1158 | out.writeLong(runningRealtime); |
| 1159 | out.writeLong(mRealtimeStart); |
| 1160 | out.writeLong(mUnpluggedUptime); |
| 1161 | out.writeLong(mUnpluggedRealtime); |
| 1162 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1163 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1164 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1165 | /** |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1166 | * State for keeping track of counting information. |
| 1167 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1168 | public static class Counter extends BatteryStats.Counter implements TimeBaseObs { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 1169 | final AtomicInteger mCount = new AtomicInteger(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1170 | final TimeBase mTimeBase; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1171 | int mLoadedCount; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1172 | int mUnpluggedCount; |
| 1173 | int mPluggedCount; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1174 | |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 1175 | public Counter(TimeBase timeBase, Parcel in) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1176 | mTimeBase = timeBase; |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 1177 | mPluggedCount = in.readInt(); |
| 1178 | mCount.set(mPluggedCount); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1179 | mLoadedCount = in.readInt(); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1180 | mUnpluggedCount = in.readInt(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1181 | timeBase.add(this); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1182 | } |
| 1183 | |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 1184 | public Counter(TimeBase timeBase) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1185 | mTimeBase = timeBase; |
| 1186 | timeBase.add(this); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1187 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1188 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1189 | public void writeToParcel(Parcel out) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 1190 | out.writeInt(mCount.get()); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1191 | out.writeInt(mLoadedCount); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1192 | out.writeInt(mUnpluggedCount); |
| 1193 | } |
| 1194 | |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 1195 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1196 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 1197 | mUnpluggedCount = mPluggedCount; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1198 | } |
| 1199 | |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 1200 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1201 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 1202 | mPluggedCount = mCount.get(); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1203 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1204 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1205 | /** |
| 1206 | * Writes a possibly null Counter to a Parcel. |
| 1207 | * |
| 1208 | * @param out the Parcel to be written to. |
| 1209 | * @param counter a Counter, or null. |
| 1210 | */ |
| 1211 | public static void writeCounterToParcel(Parcel out, Counter counter) { |
| 1212 | if (counter == null) { |
| 1213 | out.writeInt(0); // indicates null |
| 1214 | return; |
| 1215 | } |
| 1216 | out.writeInt(1); // indicates non-null |
| 1217 | |
| 1218 | counter.writeToParcel(out); |
| 1219 | } |
| 1220 | |
| 1221 | @Override |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1222 | public int getCountLocked(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 1223 | int val = mCount.get(); |
| 1224 | if (which == STATS_SINCE_UNPLUGGED) { |
| 1225 | val -= mUnpluggedCount; |
| 1226 | } else if (which != STATS_SINCE_CHARGED) { |
| 1227 | val -= mLoadedCount; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1228 | } |
| 1229 | |
| 1230 | return val; |
| 1231 | } |
| 1232 | |
| 1233 | public void logState(Printer pw, String prefix) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 1234 | pw.println(prefix + "mCount=" + mCount.get() |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 1235 | + " mLoadedCount=" + mLoadedCount |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1236 | + " mUnpluggedCount=" + mUnpluggedCount |
| 1237 | + " mPluggedCount=" + mPluggedCount); |
| 1238 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1239 | |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 1240 | @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 1241 | public void stepAtomic() { |
| 1242 | if (mTimeBase.isRunning()) { |
| 1243 | mCount.incrementAndGet(); |
| 1244 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1245 | } |
| 1246 | |
Bookatz | 4ebc064 | 2017-05-11 12:21:19 -0700 | [diff] [blame] | 1247 | void addAtomic(int delta) { |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 1248 | if (mTimeBase.isRunning()) { |
| 1249 | mCount.addAndGet(delta); |
| 1250 | } |
Bookatz | 4ebc064 | 2017-05-11 12:21:19 -0700 | [diff] [blame] | 1251 | } |
| 1252 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1253 | /** |
| 1254 | * Clear state of this counter. |
| 1255 | */ |
| 1256 | void reset(boolean detachIfReset) { |
| 1257 | mCount.set(0); |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 1258 | mLoadedCount = mPluggedCount = mUnpluggedCount = 0; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1259 | if (detachIfReset) { |
| 1260 | detach(); |
| 1261 | } |
| 1262 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1263 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1264 | void detach() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1265 | mTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1266 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1267 | |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 1268 | @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 1269 | public void writeSummaryFromParcelLocked(Parcel out) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 1270 | int count = mCount.get(); |
| 1271 | out.writeInt(count); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1272 | } |
| 1273 | |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 1274 | @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 1275 | public void readSummaryFromParcelLocked(Parcel in) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 1276 | mLoadedCount = in.readInt(); |
| 1277 | mCount.set(mLoadedCount); |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 1278 | mUnpluggedCount = mPluggedCount = mLoadedCount; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1279 | } |
| 1280 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 1281 | |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 1282 | @VisibleForTesting |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1283 | public static class LongSamplingCounterArray extends LongCounterArray implements TimeBaseObs { |
| 1284 | final TimeBase mTimeBase; |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 1285 | public long[] mCounts; |
| 1286 | public long[] mLoadedCounts; |
| 1287 | public long[] mUnpluggedCounts; |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1288 | |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 1289 | private LongSamplingCounterArray(TimeBase timeBase, Parcel in) { |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1290 | mTimeBase = timeBase; |
Sudheer Shanka | e544d16 | 2017-12-28 17:06:20 -0800 | [diff] [blame] | 1291 | mCounts = in.createLongArray(); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1292 | mLoadedCounts = in.createLongArray(); |
| 1293 | mUnpluggedCounts = in.createLongArray(); |
| 1294 | timeBase.add(this); |
| 1295 | } |
| 1296 | |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 1297 | public LongSamplingCounterArray(TimeBase timeBase) { |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1298 | mTimeBase = timeBase; |
| 1299 | timeBase.add(this); |
| 1300 | } |
| 1301 | |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 1302 | private void writeToParcel(Parcel out) { |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1303 | out.writeLongArray(mCounts); |
| 1304 | out.writeLongArray(mLoadedCounts); |
| 1305 | out.writeLongArray(mUnpluggedCounts); |
| 1306 | } |
| 1307 | |
| 1308 | @Override |
| 1309 | public void onTimeStarted(long elapsedRealTime, long baseUptime, long baseRealtime) { |
Sudheer Shanka | e544d16 | 2017-12-28 17:06:20 -0800 | [diff] [blame] | 1310 | mUnpluggedCounts = copyArray(mCounts, mUnpluggedCounts); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1311 | } |
| 1312 | |
| 1313 | @Override |
| 1314 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1315 | } |
| 1316 | |
| 1317 | @Override |
| 1318 | public long[] getCountsLocked(int which) { |
Sudheer Shanka | e544d16 | 2017-12-28 17:06:20 -0800 | [diff] [blame] | 1319 | long[] val = copyArray(mCounts, null); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1320 | if (which == STATS_SINCE_UNPLUGGED) { |
| 1321 | subtract(val, mUnpluggedCounts); |
| 1322 | } else if (which != STATS_SINCE_CHARGED) { |
| 1323 | subtract(val, mLoadedCounts); |
| 1324 | } |
| 1325 | return val; |
| 1326 | } |
| 1327 | |
| 1328 | @Override |
| 1329 | public void logState(Printer pw, String prefix) { |
| 1330 | pw.println(prefix + "mCounts=" + Arrays.toString(mCounts) |
| 1331 | + " mLoadedCounts=" + Arrays.toString(mLoadedCounts) |
Sudheer Shanka | e544d16 | 2017-12-28 17:06:20 -0800 | [diff] [blame] | 1332 | + " mUnpluggedCounts=" + Arrays.toString(mUnpluggedCounts)); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1333 | } |
| 1334 | |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 1335 | public void addCountLocked(long[] counts) { |
Sudheer Shanka | e544d16 | 2017-12-28 17:06:20 -0800 | [diff] [blame] | 1336 | addCountLocked(counts, mTimeBase.isRunning()); |
| 1337 | } |
| 1338 | |
| 1339 | public void addCountLocked(long[] counts, boolean isRunning) { |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1340 | if (counts == null) { |
| 1341 | return; |
| 1342 | } |
Sudheer Shanka | e544d16 | 2017-12-28 17:06:20 -0800 | [diff] [blame] | 1343 | if (isRunning) { |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 1344 | if (mCounts == null) { |
| 1345 | mCounts = new long[counts.length]; |
| 1346 | } |
| 1347 | for (int i = 0; i < counts.length; ++i) { |
| 1348 | mCounts[i] += counts[i]; |
| 1349 | } |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1350 | } |
| 1351 | } |
| 1352 | |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 1353 | public int getSize() { |
| 1354 | return mCounts == null ? 0 : mCounts.length; |
| 1355 | } |
| 1356 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1357 | /** |
| 1358 | * Clear state of this counter. |
| 1359 | */ |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 1360 | public void reset(boolean detachIfReset) { |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1361 | fillArray(mCounts, 0); |
| 1362 | fillArray(mLoadedCounts, 0); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1363 | fillArray(mUnpluggedCounts, 0); |
| 1364 | if (detachIfReset) { |
| 1365 | detach(); |
| 1366 | } |
| 1367 | } |
| 1368 | |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 1369 | public void detach() { |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1370 | mTimeBase.remove(this); |
| 1371 | } |
| 1372 | |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 1373 | private void writeSummaryToParcelLocked(Parcel out) { |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1374 | out.writeLongArray(mCounts); |
| 1375 | } |
| 1376 | |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 1377 | private void readSummaryFromParcelLocked(Parcel in) { |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1378 | mCounts = in.createLongArray(); |
| 1379 | mLoadedCounts = copyArray(mCounts, mLoadedCounts); |
| 1380 | mUnpluggedCounts = copyArray(mCounts, mUnpluggedCounts); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1381 | } |
| 1382 | |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 1383 | public static void writeToParcel(Parcel out, LongSamplingCounterArray counterArray) { |
| 1384 | if (counterArray != null) { |
| 1385 | out.writeInt(1); |
| 1386 | counterArray.writeToParcel(out); |
| 1387 | } else { |
| 1388 | out.writeInt(0); |
| 1389 | } |
| 1390 | } |
| 1391 | |
| 1392 | public static LongSamplingCounterArray readFromParcel(Parcel in, TimeBase timeBase) { |
| 1393 | if (in.readInt() != 0) { |
| 1394 | return new LongSamplingCounterArray(timeBase, in); |
| 1395 | } else { |
| 1396 | return null; |
| 1397 | } |
| 1398 | } |
| 1399 | |
| 1400 | public static void writeSummaryToParcelLocked(Parcel out, |
| 1401 | LongSamplingCounterArray counterArray) { |
| 1402 | if (counterArray != null) { |
| 1403 | out.writeInt(1); |
| 1404 | counterArray.writeSummaryToParcelLocked(out); |
| 1405 | } else { |
| 1406 | out.writeInt(0); |
| 1407 | } |
| 1408 | } |
| 1409 | |
| 1410 | public static LongSamplingCounterArray readSummaryFromParcelLocked(Parcel in, |
| 1411 | TimeBase timeBase) { |
| 1412 | if (in.readInt() != 0) { |
| 1413 | final LongSamplingCounterArray counterArray |
| 1414 | = new LongSamplingCounterArray(timeBase); |
| 1415 | counterArray.readSummaryFromParcelLocked(in); |
| 1416 | return counterArray; |
| 1417 | } else { |
| 1418 | return null; |
| 1419 | } |
| 1420 | } |
| 1421 | |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 1422 | private static void fillArray(long[] a, long val) { |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1423 | if (a != null) { |
| 1424 | Arrays.fill(a, val); |
| 1425 | } |
| 1426 | } |
| 1427 | |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 1428 | private static void subtract(@NonNull long[] val, long[] toSubtract) { |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1429 | if (toSubtract == null) { |
| 1430 | return; |
| 1431 | } |
| 1432 | for (int i = 0; i < val.length; i++) { |
| 1433 | val[i] -= toSubtract[i]; |
| 1434 | } |
| 1435 | } |
| 1436 | |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 1437 | private static long[] copyArray(long[] src, long[] dest) { |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1438 | if (src == null) { |
| 1439 | return null; |
| 1440 | } else { |
| 1441 | if (dest == null) { |
| 1442 | dest = new long[src.length]; |
| 1443 | } |
| 1444 | System.arraycopy(src, 0, dest, 0, src.length); |
| 1445 | return dest; |
| 1446 | } |
| 1447 | } |
| 1448 | } |
| 1449 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1450 | public static class LongSamplingCounter extends LongCounter implements TimeBaseObs { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1451 | final TimeBase mTimeBase; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1452 | long mCount; |
| 1453 | long mLoadedCount; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1454 | long mUnpluggedCount; |
| 1455 | long mPluggedCount; |
| 1456 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1457 | LongSamplingCounter(TimeBase timeBase, Parcel in) { |
| 1458 | mTimeBase = timeBase; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1459 | mPluggedCount = in.readLong(); |
| 1460 | mCount = mPluggedCount; |
| 1461 | mLoadedCount = in.readLong(); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1462 | mUnpluggedCount = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1463 | timeBase.add(this); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1464 | } |
| 1465 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1466 | LongSamplingCounter(TimeBase timeBase) { |
| 1467 | mTimeBase = timeBase; |
| 1468 | timeBase.add(this); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1469 | } |
| 1470 | |
| 1471 | public void writeToParcel(Parcel out) { |
| 1472 | out.writeLong(mCount); |
| 1473 | out.writeLong(mLoadedCount); |
| 1474 | out.writeLong(mUnpluggedCount); |
| 1475 | } |
| 1476 | |
| 1477 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1478 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1479 | mUnpluggedCount = mPluggedCount; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1480 | } |
| 1481 | |
| 1482 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1483 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1484 | mPluggedCount = mCount; |
| 1485 | } |
| 1486 | |
| 1487 | public long getCountLocked(int which) { |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 1488 | long val = mTimeBase.isRunning() ? mCount : mPluggedCount; |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 1489 | if (which == STATS_SINCE_UNPLUGGED) { |
| 1490 | val -= mUnpluggedCount; |
| 1491 | } else if (which != STATS_SINCE_CHARGED) { |
| 1492 | val -= mLoadedCount; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1493 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1494 | return val; |
| 1495 | } |
| 1496 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1497 | @Override |
| 1498 | public void logState(Printer pw, String prefix) { |
| 1499 | pw.println(prefix + "mCount=" + mCount |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 1500 | + " mLoadedCount=" + mLoadedCount |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1501 | + " mUnpluggedCount=" + mUnpluggedCount |
| 1502 | + " mPluggedCount=" + mPluggedCount); |
| 1503 | } |
| 1504 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1505 | void addCountLocked(long count) { |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 1506 | if (mTimeBase.isRunning()) { |
| 1507 | mCount += count; |
| 1508 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1509 | } |
| 1510 | |
| 1511 | /** |
| 1512 | * Clear state of this counter. |
| 1513 | */ |
| 1514 | void reset(boolean detachIfReset) { |
| 1515 | mCount = 0; |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 1516 | mLoadedCount = mPluggedCount = mUnpluggedCount = 0; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1517 | if (detachIfReset) { |
| 1518 | detach(); |
| 1519 | } |
| 1520 | } |
| 1521 | |
| 1522 | void detach() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1523 | mTimeBase.remove(this); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1524 | } |
| 1525 | |
| 1526 | void writeSummaryFromParcelLocked(Parcel out) { |
| 1527 | out.writeLong(mCount); |
| 1528 | } |
| 1529 | |
| 1530 | void readSummaryFromParcelLocked(Parcel in) { |
| 1531 | mLoadedCount = in.readLong(); |
| 1532 | mCount = mLoadedCount; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1533 | mUnpluggedCount = mPluggedCount = mLoadedCount; |
| 1534 | } |
| 1535 | } |
| 1536 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1537 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1538 | * State for keeping track of timing information. |
| 1539 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1540 | public static abstract class Timer extends BatteryStats.Timer implements TimeBaseObs { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1541 | protected final Clocks mClocks; |
| 1542 | protected final int mType; |
| 1543 | protected final TimeBase mTimeBase; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1544 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1545 | protected int mCount; |
| 1546 | protected int mLoadedCount; |
| 1547 | protected int mLastCount; |
| 1548 | protected int mUnpluggedCount; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1549 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1550 | // Times are in microseconds for better accuracy when dividing by the |
| 1551 | // lock count, and are in "battery realtime" units. |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1552 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1553 | /** |
| 1554 | * The total time we have accumulated since the start of the original |
| 1555 | * boot, to the last time something interesting happened in the |
| 1556 | * current run. |
| 1557 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1558 | protected long mTotalTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1559 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1560 | /** |
| 1561 | * The total time we loaded for the previous runs. Subtract this from |
| 1562 | * mTotalTime to find the time for the current run of the system. |
| 1563 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1564 | protected long mLoadedTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1565 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1566 | /** |
| 1567 | * The run time of the last run of the system, as loaded from the |
| 1568 | * saved data. |
| 1569 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1570 | protected long mLastTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1571 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1572 | /** |
| 1573 | * The value of mTotalTime when unplug() was last called. Subtract |
| 1574 | * this from mTotalTime to find the time since the last unplug from |
| 1575 | * power. |
| 1576 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1577 | protected long mUnpluggedTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1578 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 1579 | /** |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1580 | * The total time this timer has been running until the latest mark has been set. |
| 1581 | * Subtract this from mTotalTime to get the time spent running since the mark was set. |
| 1582 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1583 | protected long mTimeBeforeMark; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1584 | |
| 1585 | /** |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 1586 | * Constructs from a parcel. |
| 1587 | * @param type |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1588 | * @param timeBase |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 1589 | * @param in |
| 1590 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1591 | public Timer(Clocks clocks, int type, TimeBase timeBase, Parcel in) { |
| 1592 | mClocks = clocks; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1593 | mType = type; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1594 | mTimeBase = timeBase; |
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 | mCount = in.readInt(); |
| 1597 | mLoadedCount = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1598 | mLastCount = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1599 | mUnpluggedCount = in.readInt(); |
| 1600 | mTotalTime = in.readLong(); |
| 1601 | mLoadedTime = in.readLong(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1602 | mLastTime = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1603 | mUnpluggedTime = in.readLong(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1604 | mTimeBeforeMark = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1605 | timeBase.add(this); |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 1606 | 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] | 1607 | } |
| 1608 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1609 | public Timer(Clocks clocks, int type, TimeBase timeBase) { |
| 1610 | mClocks = clocks; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1611 | mType = type; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1612 | mTimeBase = timeBase; |
| 1613 | timeBase.add(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1614 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1615 | |
| 1616 | protected abstract long computeRunTimeLocked(long curBatteryRealtime); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1617 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1618 | protected abstract int computeCurrentCountLocked(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1619 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1620 | /** |
| 1621 | * Clear state of this timer. Returns true if the timer is inactive |
| 1622 | * so can be completely dropped. |
| 1623 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1624 | public boolean reset(boolean detachIfReset) { |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1625 | mTotalTime = mLoadedTime = mLastTime = mTimeBeforeMark = 0; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1626 | mCount = mLoadedCount = mLastCount = 0; |
| 1627 | if (detachIfReset) { |
| 1628 | detach(); |
| 1629 | } |
| 1630 | return true; |
| 1631 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1632 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1633 | public void detach() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1634 | mTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1635 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1636 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1637 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 1638 | if (DEBUG) Log.i(TAG, "**** WRITING TIMER #" + mType + ": mTotalTime=" |
| 1639 | + computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs))); |
Adam Lesinski | 98f0d46 | 2016-04-19 16:46:20 -0700 | [diff] [blame] | 1640 | out.writeInt(computeCurrentCountLocked()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1641 | out.writeInt(mLoadedCount); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1642 | out.writeInt(mUnpluggedCount); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1643 | out.writeLong(computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs))); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1644 | out.writeLong(mLoadedTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1645 | out.writeLong(mUnpluggedTime); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1646 | out.writeLong(mTimeBeforeMark); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1647 | } |
| 1648 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1649 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1650 | public void onTimeStarted(long elapsedRealtime, long timeBaseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1651 | if (DEBUG && mType < 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1652 | Log.v(TAG, "unplug #" + mType + ": realtime=" + baseRealtime |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1653 | + " old mUnpluggedTime=" + mUnpluggedTime |
| 1654 | + " old mUnpluggedCount=" + mUnpluggedCount); |
| 1655 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1656 | mUnpluggedTime = computeRunTimeLocked(baseRealtime); |
Adam Lesinski | 98f0d46 | 2016-04-19 16:46:20 -0700 | [diff] [blame] | 1657 | mUnpluggedCount = computeCurrentCountLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1658 | if (DEBUG && mType < 0) { |
| 1659 | Log.v(TAG, "unplug #" + mType |
| 1660 | + ": new mUnpluggedTime=" + mUnpluggedTime |
| 1661 | + " new mUnpluggedCount=" + mUnpluggedCount); |
| 1662 | } |
| 1663 | } |
| 1664 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1665 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1666 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1667 | if (DEBUG && mType < 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1668 | Log.v(TAG, "plug #" + mType + ": realtime=" + baseRealtime |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1669 | + " old mTotalTime=" + mTotalTime); |
| 1670 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1671 | mTotalTime = computeRunTimeLocked(baseRealtime); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1672 | mCount = computeCurrentCountLocked(); |
| 1673 | if (DEBUG && mType < 0) { |
| 1674 | Log.v(TAG, "plug #" + mType |
| 1675 | + ": new mTotalTime=" + mTotalTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1676 | } |
| 1677 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1678 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1679 | /** |
| 1680 | * Writes a possibly null Timer to a Parcel. |
| 1681 | * |
| 1682 | * @param out the Parcel to be written to. |
| 1683 | * @param timer a Timer, or null. |
| 1684 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1685 | 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] | 1686 | if (timer == null) { |
| 1687 | out.writeInt(0); // indicates null |
| 1688 | return; |
| 1689 | } |
| 1690 | out.writeInt(1); // indicates non-null |
| 1691 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1692 | timer.writeToParcel(out, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1693 | } |
| 1694 | |
| 1695 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1696 | public long getTotalTimeLocked(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 1697 | long val = computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs)); |
| 1698 | if (which == STATS_SINCE_UNPLUGGED) { |
| 1699 | val -= mUnpluggedTime; |
| 1700 | } else if (which != STATS_SINCE_CHARGED) { |
| 1701 | val -= mLoadedTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1702 | } |
| 1703 | |
| 1704 | return val; |
| 1705 | } |
| 1706 | |
| 1707 | @Override |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1708 | public int getCountLocked(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 1709 | int val = computeCurrentCountLocked(); |
| 1710 | if (which == STATS_SINCE_UNPLUGGED) { |
| 1711 | val -= mUnpluggedCount; |
| 1712 | } else if (which != STATS_SINCE_CHARGED) { |
| 1713 | val -= mLoadedCount; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1714 | } |
| 1715 | |
| 1716 | return val; |
| 1717 | } |
| 1718 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1719 | @Override |
| 1720 | public long getTimeSinceMarkLocked(long elapsedRealtimeUs) { |
| 1721 | long val = computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs)); |
| 1722 | return val - mTimeBeforeMark; |
| 1723 | } |
| 1724 | |
| 1725 | @Override |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1726 | public void logState(Printer pw, String prefix) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 1727 | pw.println(prefix + "mCount=" + mCount |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1728 | + " mLoadedCount=" + mLoadedCount + " mLastCount=" + mLastCount |
| 1729 | + " mUnpluggedCount=" + mUnpluggedCount); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1730 | pw.println(prefix + "mTotalTime=" + mTotalTime |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1731 | + " mLoadedTime=" + mLoadedTime); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1732 | pw.println(prefix + "mLastTime=" + mLastTime |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1733 | + " mUnpluggedTime=" + mUnpluggedTime); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1734 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1735 | |
| 1736 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1737 | public void writeSummaryFromParcelLocked(Parcel out, long elapsedRealtimeUs) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1738 | long runTime = computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs)); |
| 1739 | out.writeLong(runTime); |
Adam Lesinski | 98f0d46 | 2016-04-19 16:46:20 -0700 | [diff] [blame] | 1740 | out.writeInt(computeCurrentCountLocked()); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1741 | } |
| 1742 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1743 | public void readSummaryFromParcelLocked(Parcel in) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1744 | // Multiply by 1000 for backwards compatibility |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1745 | mTotalTime = mLoadedTime = in.readLong(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1746 | mLastTime = 0; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1747 | mUnpluggedTime = mTotalTime; |
| 1748 | mCount = mLoadedCount = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1749 | mLastCount = 0; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1750 | mUnpluggedCount = mCount; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1751 | |
| 1752 | // When reading the summary, we set the mark to be the latest information. |
| 1753 | mTimeBeforeMark = mTotalTime; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1754 | } |
| 1755 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1756 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1757 | /** |
| 1758 | * A counter meant to accept monotonically increasing values to its {@link #update(long, int)} |
| 1759 | * method. The state of the timer according to its {@link TimeBase} will determine how much |
| 1760 | * of the value is recorded. |
| 1761 | * |
| 1762 | * If the value being recorded resets, {@link #endSample()} can be called in order to |
| 1763 | * account for the change. If the value passed in to {@link #update(long, int)} decreased |
| 1764 | * between calls, the {@link #endSample()} is automatically called and the new value is |
| 1765 | * expected to increase monotonically from that point on. |
| 1766 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1767 | public static class SamplingTimer extends Timer { |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1768 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1769 | /** |
| 1770 | * The most recent reported count from /proc/wakelocks. |
| 1771 | */ |
| 1772 | int mCurrentReportedCount; |
| 1773 | |
| 1774 | /** |
| 1775 | * The reported count from /proc/wakelocks when unplug() was last |
| 1776 | * called. |
| 1777 | */ |
| 1778 | int mUnpluggedReportedCount; |
| 1779 | |
| 1780 | /** |
| 1781 | * The most recent reported total_time from /proc/wakelocks. |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1782 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1783 | long mCurrentReportedTotalTime; |
| 1784 | |
| 1785 | |
| 1786 | /** |
| 1787 | * The reported total_time from /proc/wakelocks when unplug() was last |
| 1788 | * called. |
| 1789 | */ |
| 1790 | long mUnpluggedReportedTotalTime; |
| 1791 | |
| 1792 | /** |
| 1793 | * Whether we are currently in a discharge cycle. |
| 1794 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1795 | boolean mTimeBaseRunning; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1796 | |
| 1797 | /** |
| 1798 | * Whether we are currently recording reported values. |
| 1799 | */ |
| 1800 | boolean mTrackingReportedValues; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1801 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1802 | /* |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1803 | * A sequence counter, incremented once for each update of the stats. |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1804 | */ |
| 1805 | int mUpdateVersion; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1806 | |
Adam Lesinski | 98f0d46 | 2016-04-19 16:46:20 -0700 | [diff] [blame] | 1807 | @VisibleForTesting |
| 1808 | public SamplingTimer(Clocks clocks, TimeBase timeBase, Parcel in) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1809 | super(clocks, 0, timeBase, in); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1810 | mCurrentReportedCount = in.readInt(); |
| 1811 | mUnpluggedReportedCount = in.readInt(); |
| 1812 | mCurrentReportedTotalTime = in.readLong(); |
| 1813 | mUnpluggedReportedTotalTime = in.readLong(); |
| 1814 | mTrackingReportedValues = in.readInt() == 1; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1815 | mTimeBaseRunning = timeBase.isRunning(); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1816 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1817 | |
Adam Lesinski | 98f0d46 | 2016-04-19 16:46:20 -0700 | [diff] [blame] | 1818 | @VisibleForTesting |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1819 | public SamplingTimer(Clocks clocks, TimeBase timeBase) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1820 | super(clocks, 0, timeBase); |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1821 | mTrackingReportedValues = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1822 | mTimeBaseRunning = timeBase.isRunning(); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1823 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1824 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1825 | /** |
| 1826 | * Ends the current sample, allowing subsequent values to {@link #update(long, int)} to |
| 1827 | * be less than the values used for a previous invocation. |
| 1828 | */ |
| 1829 | public void endSample() { |
| 1830 | mTotalTime = computeRunTimeLocked(0 /* unused by us */); |
| 1831 | mCount = computeCurrentCountLocked(); |
| 1832 | mUnpluggedReportedTotalTime = mCurrentReportedTotalTime = 0; |
| 1833 | mUnpluggedReportedCount = mCurrentReportedCount = 0; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1834 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1835 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1836 | public void setUpdateVersion(int version) { |
| 1837 | mUpdateVersion = version; |
| 1838 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1839 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1840 | public int getUpdateVersion() { |
| 1841 | return mUpdateVersion; |
| 1842 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1843 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1844 | /** |
| 1845 | * Updates the current recorded values. These are meant to be monotonically increasing |
| 1846 | * and cumulative. If you are dealing with deltas, use {@link #add(long, int)}. |
| 1847 | * |
| 1848 | * If the values being recorded have been reset, the monotonically increasing requirement |
| 1849 | * will be broken. In this case, {@link #endSample()} is automatically called and |
| 1850 | * the total value of totalTime and count are recorded, starting a new monotonically |
| 1851 | * increasing sample. |
| 1852 | * |
| 1853 | * @param totalTime total time of sample in microseconds. |
| 1854 | * @param count total number of times the event being sampled occurred. |
| 1855 | */ |
| 1856 | public void update(long totalTime, int count) { |
| 1857 | if (mTimeBaseRunning && !mTrackingReportedValues) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1858 | // Updating the reported value for the first time. |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1859 | mUnpluggedReportedTotalTime = totalTime; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1860 | mUnpluggedReportedCount = count; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1861 | } |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1862 | |
| 1863 | mTrackingReportedValues = true; |
| 1864 | |
| 1865 | if (totalTime < mCurrentReportedTotalTime || count < mCurrentReportedCount) { |
| 1866 | endSample(); |
| 1867 | } |
| 1868 | |
| 1869 | mCurrentReportedTotalTime = totalTime; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1870 | mCurrentReportedCount = count; |
| 1871 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1872 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1873 | /** |
| 1874 | * Adds deltaTime and deltaCount to the current sample. |
| 1875 | * |
| 1876 | * @param deltaTime additional time recorded since the last sampled event, in microseconds. |
| 1877 | * @param deltaCount additional number of times the event being sampled occurred. |
| 1878 | */ |
| 1879 | public void add(long deltaTime, int deltaCount) { |
| 1880 | update(mCurrentReportedTotalTime + deltaTime, mCurrentReportedCount + deltaCount); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 1881 | } |
| 1882 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1883 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1884 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
| 1885 | super.onTimeStarted(elapsedRealtime, baseUptime, baseRealtime); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1886 | if (mTrackingReportedValues) { |
| 1887 | mUnpluggedReportedTotalTime = mCurrentReportedTotalTime; |
| 1888 | mUnpluggedReportedCount = mCurrentReportedCount; |
| 1889 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1890 | mTimeBaseRunning = true; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1891 | } |
| 1892 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1893 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1894 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
| 1895 | super.onTimeStopped(elapsedRealtime, baseUptime, baseRealtime); |
| 1896 | mTimeBaseRunning = false; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1897 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1898 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1899 | @Override |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1900 | public void logState(Printer pw, String prefix) { |
| 1901 | super.logState(pw, prefix); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1902 | pw.println(prefix + "mCurrentReportedCount=" + mCurrentReportedCount |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1903 | + " mUnpluggedReportedCount=" + mUnpluggedReportedCount |
| 1904 | + " mCurrentReportedTotalTime=" + mCurrentReportedTotalTime |
| 1905 | + " mUnpluggedReportedTotalTime=" + mUnpluggedReportedTotalTime); |
| 1906 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1907 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1908 | @Override |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1909 | protected long computeRunTimeLocked(long curBatteryRealtime) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1910 | return mTotalTime + (mTimeBaseRunning && mTrackingReportedValues |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1911 | ? mCurrentReportedTotalTime - mUnpluggedReportedTotalTime : 0); |
| 1912 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1913 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1914 | @Override |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1915 | protected int computeCurrentCountLocked() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1916 | return mCount + (mTimeBaseRunning && mTrackingReportedValues |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1917 | ? mCurrentReportedCount - mUnpluggedReportedCount : 0); |
| 1918 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1919 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1920 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1921 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
| 1922 | super.writeToParcel(out, elapsedRealtimeUs); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1923 | out.writeInt(mCurrentReportedCount); |
| 1924 | out.writeInt(mUnpluggedReportedCount); |
| 1925 | out.writeLong(mCurrentReportedTotalTime); |
| 1926 | out.writeLong(mUnpluggedReportedTotalTime); |
| 1927 | out.writeInt(mTrackingReportedValues ? 1 : 0); |
| 1928 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1929 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1930 | @Override |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1931 | public boolean reset(boolean detachIfReset) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1932 | super.reset(detachIfReset); |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1933 | mTrackingReportedValues = false; |
| 1934 | mUnpluggedReportedTotalTime = 0; |
| 1935 | mUnpluggedReportedCount = 0; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1936 | return true; |
| 1937 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1938 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1939 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1940 | /** |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1941 | * A timer that increments in batches. It does not run for durations, but just jumps |
| 1942 | * for a pre-determined amount. |
| 1943 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1944 | public static class BatchTimer extends Timer { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1945 | final Uid mUid; |
| 1946 | |
| 1947 | /** |
| 1948 | * The last time at which we updated the timer. This is in elapsed realtime microseconds. |
| 1949 | */ |
| 1950 | long mLastAddedTime; |
| 1951 | |
| 1952 | /** |
| 1953 | * The last duration that we added to the timer. This is in microseconds. |
| 1954 | */ |
| 1955 | long mLastAddedDuration; |
| 1956 | |
| 1957 | /** |
| 1958 | * Whether we are currently in a discharge cycle. |
| 1959 | */ |
| 1960 | boolean mInDischarge; |
| 1961 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1962 | BatchTimer(Clocks clocks, Uid uid, int type, TimeBase timeBase, Parcel in) { |
| 1963 | super(clocks, type, timeBase, in); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1964 | mUid = uid; |
| 1965 | mLastAddedTime = in.readLong(); |
| 1966 | mLastAddedDuration = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1967 | mInDischarge = timeBase.isRunning(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1968 | } |
| 1969 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1970 | BatchTimer(Clocks clocks, Uid uid, int type, TimeBase timeBase) { |
| 1971 | super(clocks, type, timeBase); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1972 | mUid = uid; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1973 | mInDischarge = timeBase.isRunning(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1974 | } |
| 1975 | |
| 1976 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1977 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
| 1978 | super.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1979 | out.writeLong(mLastAddedTime); |
| 1980 | out.writeLong(mLastAddedDuration); |
| 1981 | } |
| 1982 | |
| 1983 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1984 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1985 | recomputeLastDuration(mClocks.elapsedRealtime() * 1000, false); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1986 | mInDischarge = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1987 | super.onTimeStopped(elapsedRealtime, baseUptime, baseRealtime); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1988 | } |
| 1989 | |
| 1990 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1991 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1992 | recomputeLastDuration(elapsedRealtime, false); |
| 1993 | mInDischarge = true; |
| 1994 | // If we are still within the last added duration, then re-added whatever remains. |
| 1995 | if (mLastAddedTime == elapsedRealtime) { |
| 1996 | mTotalTime += mLastAddedDuration; |
| 1997 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1998 | super.onTimeStarted(elapsedRealtime, baseUptime, baseRealtime); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1999 | } |
| 2000 | |
| 2001 | @Override |
| 2002 | public void logState(Printer pw, String prefix) { |
| 2003 | super.logState(pw, prefix); |
| 2004 | pw.println(prefix + "mLastAddedTime=" + mLastAddedTime |
| 2005 | + " mLastAddedDuration=" + mLastAddedDuration); |
| 2006 | } |
| 2007 | |
| 2008 | private long computeOverage(long curTime) { |
| 2009 | if (mLastAddedTime > 0) { |
| 2010 | return mLastTime + mLastAddedDuration - curTime; |
| 2011 | } |
| 2012 | return 0; |
| 2013 | } |
| 2014 | |
| 2015 | private void recomputeLastDuration(long curTime, boolean abort) { |
| 2016 | final long overage = computeOverage(curTime); |
| 2017 | if (overage > 0) { |
| 2018 | // Aborting before the duration ran out -- roll back the remaining |
| 2019 | // duration. Only do this if currently discharging; otherwise we didn't |
| 2020 | // actually add the time. |
| 2021 | if (mInDischarge) { |
| 2022 | mTotalTime -= overage; |
| 2023 | } |
| 2024 | if (abort) { |
| 2025 | mLastAddedTime = 0; |
| 2026 | } else { |
| 2027 | mLastAddedTime = curTime; |
| 2028 | mLastAddedDuration -= overage; |
| 2029 | } |
| 2030 | } |
| 2031 | } |
| 2032 | |
| 2033 | public void addDuration(BatteryStatsImpl stats, long durationMillis) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2034 | final long now = mClocks.elapsedRealtime() * 1000; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 2035 | recomputeLastDuration(now, true); |
| 2036 | mLastAddedTime = now; |
| 2037 | mLastAddedDuration = durationMillis * 1000; |
| 2038 | if (mInDischarge) { |
| 2039 | mTotalTime += mLastAddedDuration; |
| 2040 | mCount++; |
| 2041 | } |
| 2042 | } |
| 2043 | |
| 2044 | public void abortLastDuration(BatteryStatsImpl stats) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2045 | final long now = mClocks.elapsedRealtime() * 1000; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 2046 | recomputeLastDuration(now, true); |
| 2047 | } |
| 2048 | |
| 2049 | @Override |
| 2050 | protected int computeCurrentCountLocked() { |
| 2051 | return mCount; |
| 2052 | } |
| 2053 | |
| 2054 | @Override |
| 2055 | protected long computeRunTimeLocked(long curBatteryRealtime) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2056 | final long overage = computeOverage(mClocks.elapsedRealtime() * 1000); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 2057 | if (overage > 0) { |
| 2058 | return mTotalTime = overage; |
| 2059 | } |
| 2060 | return mTotalTime; |
| 2061 | } |
| 2062 | |
| 2063 | @Override |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2064 | public boolean reset(boolean detachIfReset) { |
| 2065 | final long now = mClocks.elapsedRealtime() * 1000; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 2066 | recomputeLastDuration(now, true); |
| 2067 | boolean stillActive = mLastAddedTime == now; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2068 | super.reset(!stillActive && detachIfReset); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 2069 | return !stillActive; |
| 2070 | } |
| 2071 | } |
| 2072 | |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2073 | |
| 2074 | /** |
| 2075 | * A StopwatchTimer that also tracks the total and max individual |
| 2076 | * time spent active according to the given timebase. Whereas |
| 2077 | * StopwatchTimer apportions the time amongst all in the pool, |
| 2078 | * the total and max durations are not apportioned. |
| 2079 | */ |
| 2080 | public static class DurationTimer extends StopwatchTimer { |
| 2081 | /** |
| 2082 | * The time (in ms) that the timer was last acquired or the time base |
| 2083 | * last (re-)started. Increasing the nesting depth does not reset this time. |
| 2084 | * |
| 2085 | * -1 if the timer is currently not running or the time base is not running. |
| 2086 | * |
| 2087 | * If written to a parcel, the start time is reset, as is mNesting in the base class |
| 2088 | * StopwatchTimer. |
| 2089 | */ |
| 2090 | long mStartTimeMs = -1; |
| 2091 | |
| 2092 | /** |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2093 | * 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] | 2094 | */ |
| 2095 | long mMaxDurationMs; |
| 2096 | |
| 2097 | /** |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2098 | * The time (in ms) that that the timer has been active since most recent |
| 2099 | * stopRunningLocked() or reset(). Not pooled. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2100 | */ |
| 2101 | long mCurrentDurationMs; |
| 2102 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2103 | /** |
| 2104 | * The total time (in ms) that that the timer has been active since most recent reset() |
| 2105 | * prior to the current startRunningLocked. This is the sum of all past currentDurations |
| 2106 | * (but not including the present currentDuration) since reset. Not pooled. |
| 2107 | */ |
| 2108 | long mTotalDurationMs; |
| 2109 | |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2110 | public DurationTimer(Clocks clocks, Uid uid, int type, ArrayList<StopwatchTimer> timerPool, |
| 2111 | TimeBase timeBase, Parcel in) { |
| 2112 | super(clocks, uid, type, timerPool, timeBase, in); |
| 2113 | mMaxDurationMs = in.readLong(); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2114 | mTotalDurationMs = in.readLong(); |
jackqdyulei | 610a0a0 | 2017-08-09 14:02:01 -0700 | [diff] [blame] | 2115 | mCurrentDurationMs = in.readLong(); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2116 | } |
| 2117 | |
| 2118 | public DurationTimer(Clocks clocks, Uid uid, int type, ArrayList<StopwatchTimer> timerPool, |
| 2119 | TimeBase timeBase) { |
| 2120 | super(clocks, uid, type, timerPool, timeBase); |
| 2121 | } |
| 2122 | |
| 2123 | @Override |
| 2124 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
| 2125 | super.writeToParcel(out, elapsedRealtimeUs); |
Kweku Adams | 47db5a8 | 2016-12-09 19:04:50 -0800 | [diff] [blame] | 2126 | out.writeLong(getMaxDurationMsLocked(elapsedRealtimeUs / 1000)); |
jackqdyulei | 610a0a0 | 2017-08-09 14:02:01 -0700 | [diff] [blame] | 2127 | out.writeLong(mTotalDurationMs); |
| 2128 | out.writeLong(getCurrentDurationMsLocked(elapsedRealtimeUs / 1000)); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2129 | } |
| 2130 | |
| 2131 | /** |
| 2132 | * Write the summary to the parcel. |
| 2133 | * |
| 2134 | * Since the time base is probably meaningless after we come back, reading |
| 2135 | * 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] | 2136 | * is the max and total durations. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2137 | */ |
| 2138 | @Override |
| 2139 | public void writeSummaryFromParcelLocked(Parcel out, long elapsedRealtimeUs) { |
| 2140 | super.writeSummaryFromParcelLocked(out, elapsedRealtimeUs); |
Kweku Adams | 47db5a8 | 2016-12-09 19:04:50 -0800 | [diff] [blame] | 2141 | out.writeLong(getMaxDurationMsLocked(elapsedRealtimeUs / 1000)); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2142 | out.writeLong(getTotalDurationMsLocked(elapsedRealtimeUs / 1000)); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2143 | } |
| 2144 | |
| 2145 | /** |
| 2146 | * Read the summary parcel. |
| 2147 | * |
| 2148 | * Has the side effect of stopping the timer. |
| 2149 | */ |
| 2150 | @Override |
| 2151 | public void readSummaryFromParcelLocked(Parcel in) { |
| 2152 | super.readSummaryFromParcelLocked(in); |
| 2153 | mMaxDurationMs = in.readLong(); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2154 | mTotalDurationMs = in.readLong(); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2155 | mStartTimeMs = -1; |
| 2156 | mCurrentDurationMs = 0; |
| 2157 | } |
| 2158 | |
| 2159 | /** |
| 2160 | * The TimeBase time started (again). |
| 2161 | * |
| 2162 | * If the timer is also running, store the start time. |
| 2163 | */ |
| 2164 | public void onTimeStarted(long elapsedRealtimeUs, long baseUptime, long baseRealtime) { |
| 2165 | super.onTimeStarted(elapsedRealtimeUs, baseUptime, baseRealtime); |
| 2166 | if (mNesting > 0) { |
Kweku Adams | 47db5a8 | 2016-12-09 19:04:50 -0800 | [diff] [blame] | 2167 | mStartTimeMs = baseRealtime / 1000; |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2168 | } |
| 2169 | } |
| 2170 | |
| 2171 | /** |
| 2172 | * The TimeBase stopped running. |
| 2173 | * |
| 2174 | * If the timer is running, add the duration into mCurrentDurationMs. |
| 2175 | */ |
| 2176 | @Override |
Kweku Adams | 47db5a8 | 2016-12-09 19:04:50 -0800 | [diff] [blame] | 2177 | public void onTimeStopped(long elapsedRealtimeUs, long baseUptime, long baseRealtimeUs) { |
| 2178 | super.onTimeStopped(elapsedRealtimeUs, baseUptime, baseRealtimeUs); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2179 | if (mNesting > 0) { |
Kweku Adams | 47db5a8 | 2016-12-09 19:04:50 -0800 | [diff] [blame] | 2180 | // baseRealtimeUs has already been converted to the timebase's realtime. |
| 2181 | mCurrentDurationMs += (baseRealtimeUs / 1000) - mStartTimeMs; |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2182 | } |
| 2183 | mStartTimeMs = -1; |
| 2184 | } |
| 2185 | |
| 2186 | @Override |
| 2187 | public void logState(Printer pw, String prefix) { |
| 2188 | super.logState(pw, prefix); |
| 2189 | } |
| 2190 | |
| 2191 | @Override |
| 2192 | public void startRunningLocked(long elapsedRealtimeMs) { |
| 2193 | super.startRunningLocked(elapsedRealtimeMs); |
| 2194 | if (mNesting == 1 && mTimeBase.isRunning()) { |
| 2195 | // Just started |
Kweku Adams | 47db5a8 | 2016-12-09 19:04:50 -0800 | [diff] [blame] | 2196 | mStartTimeMs = mTimeBase.getRealtime(elapsedRealtimeMs * 1000) / 1000; |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2197 | } |
| 2198 | } |
| 2199 | |
| 2200 | /** |
| 2201 | * Decrements the mNesting ref-count on this timer. |
| 2202 | * |
| 2203 | * If it actually stopped (mNesting went to 0), then possibly update |
| 2204 | * mMaxDuration if the current duration was the longest ever. |
| 2205 | */ |
| 2206 | @Override |
| 2207 | public void stopRunningLocked(long elapsedRealtimeMs) { |
Kweku Adams | 47db5a8 | 2016-12-09 19:04:50 -0800 | [diff] [blame] | 2208 | if (mNesting == 1) { |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2209 | final long durationMs = getCurrentDurationMsLocked(elapsedRealtimeMs); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2210 | mTotalDurationMs += durationMs; |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2211 | if (durationMs > mMaxDurationMs) { |
| 2212 | mMaxDurationMs = durationMs; |
| 2213 | } |
| 2214 | mStartTimeMs = -1; |
| 2215 | mCurrentDurationMs = 0; |
| 2216 | } |
Kweku Adams | 47db5a8 | 2016-12-09 19:04:50 -0800 | [diff] [blame] | 2217 | // super method decrements mNesting, which getCurrentDurationMsLocked relies on, |
| 2218 | // so call super.stopRunningLocked after calling getCurrentDurationMsLocked. |
| 2219 | super.stopRunningLocked(elapsedRealtimeMs); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2220 | } |
| 2221 | |
| 2222 | @Override |
| 2223 | public boolean reset(boolean detachIfReset) { |
| 2224 | boolean result = super.reset(detachIfReset); |
| 2225 | mMaxDurationMs = 0; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2226 | mTotalDurationMs = 0; |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2227 | mCurrentDurationMs = 0; |
| 2228 | if (mNesting > 0) { |
| 2229 | mStartTimeMs = mTimeBase.getRealtime(mClocks.elapsedRealtime()*1000) / 1000; |
| 2230 | } else { |
| 2231 | mStartTimeMs = -1; |
| 2232 | } |
| 2233 | return result; |
| 2234 | } |
| 2235 | |
| 2236 | /** |
| 2237 | * Returns the max duration that this timer has ever seen. |
| 2238 | * |
| 2239 | * Note that this time is NOT split between the timers in the timer group that |
| 2240 | * this timer is attached to. It is the TOTAL time. |
| 2241 | */ |
| 2242 | @Override |
| 2243 | public long getMaxDurationMsLocked(long elapsedRealtimeMs) { |
| 2244 | if (mNesting > 0) { |
| 2245 | final long durationMs = getCurrentDurationMsLocked(elapsedRealtimeMs); |
| 2246 | if (durationMs > mMaxDurationMs) { |
| 2247 | return durationMs; |
| 2248 | } |
| 2249 | } |
| 2250 | return mMaxDurationMs; |
| 2251 | } |
| 2252 | |
| 2253 | /** |
| 2254 | * Returns the time since the timer was started. |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2255 | * Returns 0 if the timer is not currently running. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2256 | * |
| 2257 | * Note that this time is NOT split between the timers in the timer group that |
| 2258 | * this timer is attached to. It is the TOTAL time. |
jackqdyulei | 610a0a0 | 2017-08-09 14:02:01 -0700 | [diff] [blame] | 2259 | * |
| 2260 | * Note that if running timer is parceled and unparceled, this method will return |
| 2261 | * current duration value at the time of parceling even though timer may not be |
| 2262 | * currently running. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2263 | */ |
| 2264 | @Override |
| 2265 | public long getCurrentDurationMsLocked(long elapsedRealtimeMs) { |
| 2266 | long durationMs = mCurrentDurationMs; |
Kweku Adams | 47db5a8 | 2016-12-09 19:04:50 -0800 | [diff] [blame] | 2267 | if (mNesting > 0 && mTimeBase.isRunning()) { |
| 2268 | durationMs += (mTimeBase.getRealtime(elapsedRealtimeMs*1000)/1000) |
| 2269 | - mStartTimeMs; |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2270 | } |
| 2271 | return durationMs; |
| 2272 | } |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2273 | |
| 2274 | /** |
| 2275 | * Returns the total cumulative duration that this timer has been on since reset(). |
| 2276 | * If mTimerPool == null, this should be the same |
| 2277 | * as getTotalTimeLocked(elapsedRealtimeMs*1000, STATS_SINCE_CHARGED)/1000. |
| 2278 | * |
| 2279 | * Note that this time is NOT split between the timers in the timer group that |
| 2280 | * this timer is attached to. It is the TOTAL time. For this reason, if mTimerPool != null, |
| 2281 | * the result will not be equivalent to getTotalTimeLocked. |
| 2282 | */ |
| 2283 | @Override |
| 2284 | public long getTotalDurationMsLocked(long elapsedRealtimeMs) { |
| 2285 | return mTotalDurationMs + getCurrentDurationMsLocked(elapsedRealtimeMs); |
| 2286 | } |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2287 | } |
| 2288 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 2289 | /** |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2290 | * State for keeping track of timing information. |
| 2291 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2292 | public static class StopwatchTimer extends Timer { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 2293 | final Uid mUid; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2294 | final ArrayList<StopwatchTimer> mTimerPool; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 2295 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2296 | int mNesting; |
| 2297 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2298 | /** |
| 2299 | * The last time at which we updated the timer. If mNesting is > 0, |
| 2300 | * subtract this from the current battery time to find the amount of |
| 2301 | * time we have been running since we last computed an update. |
| 2302 | */ |
| 2303 | long mUpdateTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2304 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2305 | /** |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2306 | * The total time at which the timer was acquired, to determine if it |
Bookatz | ceebafe | 2017-04-06 11:59:13 -0700 | [diff] [blame] | 2307 | * was actually held for an interesting duration. If time base was not running when timer |
| 2308 | * was acquired, will be -1. |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2309 | */ |
Bookatz | ceebafe | 2017-04-06 11:59:13 -0700 | [diff] [blame] | 2310 | long mAcquireTime = -1; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2311 | |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 2312 | long mTimeout; |
| 2313 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 2314 | /** |
| 2315 | * For partial wake locks, keep track of whether we are in the list |
| 2316 | * to consume CPU cycles. |
| 2317 | */ |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 2318 | @VisibleForTesting |
| 2319 | public boolean mInList; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 2320 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2321 | public StopwatchTimer(Clocks clocks, Uid uid, int type, ArrayList<StopwatchTimer> timerPool, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2322 | TimeBase timeBase, Parcel in) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2323 | super(clocks, type, timeBase, in); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 2324 | mUid = uid; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2325 | mTimerPool = timerPool; |
| 2326 | mUpdateTime = in.readLong(); |
| 2327 | } |
| 2328 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2329 | public StopwatchTimer(Clocks clocks, Uid uid, int type, ArrayList<StopwatchTimer> timerPool, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2330 | TimeBase timeBase) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2331 | super(clocks, type, timeBase); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 2332 | mUid = uid; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2333 | mTimerPool = timerPool; |
| 2334 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2335 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2336 | public void setTimeout(long timeout) { |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 2337 | mTimeout = timeout; |
| 2338 | } |
| 2339 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2340 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
| 2341 | super.writeToParcel(out, elapsedRealtimeUs); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2342 | out.writeLong(mUpdateTime); |
| 2343 | } |
| 2344 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2345 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2346 | if (mNesting > 0) { |
| 2347 | if (DEBUG && mType < 0) { |
| 2348 | Log.v(TAG, "old mUpdateTime=" + mUpdateTime); |
| 2349 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2350 | super.onTimeStopped(elapsedRealtime, baseUptime, baseRealtime); |
| 2351 | mUpdateTime = baseRealtime; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2352 | if (DEBUG && mType < 0) { |
| 2353 | Log.v(TAG, "new mUpdateTime=" + mUpdateTime); |
| 2354 | } |
| 2355 | } |
| 2356 | } |
| 2357 | |
| 2358 | public void logState(Printer pw, String prefix) { |
| 2359 | super.logState(pw, prefix); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 2360 | pw.println(prefix + "mNesting=" + mNesting + " mUpdateTime=" + mUpdateTime |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2361 | + " mAcquireTime=" + mAcquireTime); |
| 2362 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2363 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2364 | public void startRunningLocked(long elapsedRealtimeMs) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2365 | if (mNesting++ == 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2366 | final long batteryRealtime = mTimeBase.getRealtime(elapsedRealtimeMs * 1000); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 2367 | mUpdateTime = batteryRealtime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2368 | if (mTimerPool != null) { |
| 2369 | // Accumulate time to all currently active timers before adding |
| 2370 | // this new one to the pool. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2371 | refreshTimersLocked(batteryRealtime, mTimerPool, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2372 | // Add this timer to the active pool |
| 2373 | mTimerPool.add(this); |
| 2374 | } |
Bookatz | ceebafe | 2017-04-06 11:59:13 -0700 | [diff] [blame] | 2375 | if (mTimeBase.isRunning()) { |
| 2376 | // Increment the count |
| 2377 | mCount++; |
| 2378 | mAcquireTime = mTotalTime; |
| 2379 | } else { |
| 2380 | mAcquireTime = -1; |
| 2381 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2382 | if (DEBUG && mType < 0) { |
| 2383 | Log.v(TAG, "start #" + mType + ": mUpdateTime=" + mUpdateTime |
| 2384 | + " mTotalTime=" + mTotalTime + " mCount=" + mCount |
| 2385 | + " mAcquireTime=" + mAcquireTime); |
| 2386 | } |
| 2387 | } |
| 2388 | } |
| 2389 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2390 | public boolean isRunningLocked() { |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 2391 | return mNesting > 0; |
| 2392 | } |
| 2393 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2394 | public void stopRunningLocked(long elapsedRealtimeMs) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2395 | // Ignore attempt to stop a timer that isn't running |
| 2396 | if (mNesting == 0) { |
| 2397 | return; |
| 2398 | } |
| 2399 | if (--mNesting == 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2400 | final long batteryRealtime = mTimeBase.getRealtime(elapsedRealtimeMs * 1000); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2401 | if (mTimerPool != null) { |
| 2402 | // Accumulate time to all active counters, scaled by the total |
| 2403 | // active in the pool, before taking this one out of the pool. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2404 | refreshTimersLocked(batteryRealtime, mTimerPool, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2405 | // Remove this timer from the active pool |
| 2406 | mTimerPool.remove(this); |
| 2407 | } else { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2408 | mNesting = 1; |
| 2409 | mTotalTime = computeRunTimeLocked(batteryRealtime); |
| 2410 | mNesting = 0; |
| 2411 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2412 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2413 | if (DEBUG && mType < 0) { |
| 2414 | Log.v(TAG, "stop #" + mType + ": mUpdateTime=" + mUpdateTime |
| 2415 | + " mTotalTime=" + mTotalTime + " mCount=" + mCount |
| 2416 | + " mAcquireTime=" + mAcquireTime); |
| 2417 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2418 | |
Bookatz | ceebafe | 2017-04-06 11:59:13 -0700 | [diff] [blame] | 2419 | if (mAcquireTime >= 0 && mTotalTime == mAcquireTime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2420 | // If there was no change in the time, then discard this |
| 2421 | // count. A somewhat cheezy strategy, but hey. |
| 2422 | mCount--; |
| 2423 | } |
| 2424 | } |
| 2425 | } |
| 2426 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2427 | public void stopAllRunningLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 2428 | if (mNesting > 0) { |
| 2429 | mNesting = 1; |
| 2430 | stopRunningLocked(elapsedRealtimeMs); |
| 2431 | } |
| 2432 | } |
| 2433 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2434 | // Update the total time for all other running Timers with the same type as this Timer |
| 2435 | // due to a change in timer count |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2436 | private static long refreshTimersLocked(long batteryRealtime, |
| 2437 | final ArrayList<StopwatchTimer> pool, StopwatchTimer self) { |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 2438 | long selfTime = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2439 | final int N = pool.size(); |
| 2440 | for (int i=N-1; i>= 0; i--) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2441 | final StopwatchTimer t = pool.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2442 | long heldTime = batteryRealtime - t.mUpdateTime; |
| 2443 | if (heldTime > 0) { |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 2444 | final long myTime = heldTime / N; |
| 2445 | if (t == self) { |
| 2446 | selfTime = myTime; |
| 2447 | } |
| 2448 | t.mTotalTime += myTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2449 | } |
| 2450 | t.mUpdateTime = batteryRealtime; |
| 2451 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 2452 | return selfTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2453 | } |
| 2454 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2455 | @Override |
| 2456 | protected long computeRunTimeLocked(long curBatteryRealtime) { |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 2457 | if (mTimeout > 0 && curBatteryRealtime > mUpdateTime + mTimeout) { |
| 2458 | curBatteryRealtime = mUpdateTime + mTimeout; |
| 2459 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2460 | return mTotalTime + (mNesting > 0 |
| 2461 | ? (curBatteryRealtime - mUpdateTime) |
| 2462 | / (mTimerPool != null ? mTimerPool.size() : 1) |
| 2463 | : 0); |
| 2464 | } |
| 2465 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2466 | @Override |
| 2467 | protected int computeCurrentCountLocked() { |
| 2468 | return mCount; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2469 | } |
| 2470 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 2471 | @Override |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2472 | public boolean reset(boolean detachIfReset) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2473 | boolean canDetach = mNesting <= 0; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2474 | super.reset(canDetach && detachIfReset); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2475 | if (mNesting > 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2476 | mUpdateTime = mTimeBase.getRealtime(mClocks.elapsedRealtime() * 1000); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2477 | } |
Bookatz | ceebafe | 2017-04-06 11:59:13 -0700 | [diff] [blame] | 2478 | 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] | 2479 | return canDetach; |
| 2480 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2481 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 2482 | @Override |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2483 | public void detach() { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2484 | super.detach(); |
| 2485 | if (mTimerPool != null) { |
| 2486 | mTimerPool.remove(this); |
| 2487 | } |
| 2488 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2489 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 2490 | @Override |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2491 | public void readSummaryFromParcelLocked(Parcel in) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2492 | super.readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2493 | mNesting = 0; |
| 2494 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 2495 | |
| 2496 | /** |
| 2497 | * Set the mark so that we can query later for the total time the timer has |
| 2498 | * accumulated since this point. The timer can be running or not. |
| 2499 | * |
| 2500 | * @param elapsedRealtimeMs the current elapsed realtime in milliseconds. |
| 2501 | */ |
| 2502 | public void setMark(long elapsedRealtimeMs) { |
| 2503 | final long batteryRealtime = mTimeBase.getRealtime(elapsedRealtimeMs * 1000); |
| 2504 | if (mNesting > 0) { |
| 2505 | // We are running. |
| 2506 | if (mTimerPool != null) { |
| 2507 | refreshTimersLocked(batteryRealtime, mTimerPool, this); |
| 2508 | } else { |
| 2509 | mTotalTime += batteryRealtime - mUpdateTime; |
| 2510 | mUpdateTime = batteryRealtime; |
| 2511 | } |
| 2512 | } |
| 2513 | mTimeBeforeMark = mTotalTime; |
| 2514 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2515 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2516 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2517 | /** |
| 2518 | * State for keeping track of two DurationTimers with different TimeBases, presumably where one |
| 2519 | * TimeBase is effectively a subset of the other. |
| 2520 | */ |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2521 | public static class DualTimer extends DurationTimer { |
| 2522 | // This class both is a DurationTimer and also holds a second DurationTimer. |
| 2523 | // The main timer (this) typically tracks the total time. It may be pooled (but since it's a |
| 2524 | // durationTimer, it also has the unpooled getTotalDurationMsLocked() for |
| 2525 | // STATS_SINCE_CHARGED). |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2526 | // mSubTimer typically tracks only part of the total time, such as background time, as |
| 2527 | // determined by a subTimeBase. It is NOT pooled. |
| 2528 | private final DurationTimer mSubTimer; |
| 2529 | |
| 2530 | /** |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2531 | * Creates a DualTimer to hold a main timer (this) and a mSubTimer. |
| 2532 | * The main timer (this) is based on the given timeBase and timerPool. |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2533 | * 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] | 2534 | * the main timer is. |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2535 | */ |
| 2536 | public DualTimer(Clocks clocks, Uid uid, int type, ArrayList<StopwatchTimer> timerPool, |
| 2537 | TimeBase timeBase, TimeBase subTimeBase, Parcel in) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2538 | super(clocks, uid, type, timerPool, timeBase, in); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2539 | mSubTimer = new DurationTimer(clocks, uid, type, null, subTimeBase, in); |
| 2540 | } |
| 2541 | |
| 2542 | /** |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2543 | * Creates a DualTimer to hold a main timer (this) and a mSubTimer. |
| 2544 | * The main timer (this) is based on the given timeBase and timerPool. |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2545 | * 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] | 2546 | * the main timer is. |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2547 | */ |
| 2548 | public DualTimer(Clocks clocks, Uid uid, int type, ArrayList<StopwatchTimer> timerPool, |
| 2549 | TimeBase timeBase, TimeBase subTimeBase) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2550 | super(clocks, uid, type, timerPool, timeBase); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2551 | mSubTimer = new DurationTimer(clocks, uid, type, null, subTimeBase); |
| 2552 | } |
| 2553 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2554 | /** Get the secondary timer. */ |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2555 | @Override |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2556 | public DurationTimer getSubTimer() { |
| 2557 | return mSubTimer; |
| 2558 | } |
| 2559 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2560 | @Override |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2561 | public void startRunningLocked(long elapsedRealtimeMs) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2562 | super.startRunningLocked(elapsedRealtimeMs); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2563 | mSubTimer.startRunningLocked(elapsedRealtimeMs); |
| 2564 | } |
| 2565 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2566 | @Override |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2567 | public void stopRunningLocked(long elapsedRealtimeMs) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2568 | super.stopRunningLocked(elapsedRealtimeMs); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2569 | mSubTimer.stopRunningLocked(elapsedRealtimeMs); |
| 2570 | } |
| 2571 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2572 | @Override |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2573 | public void stopAllRunningLocked(long elapsedRealtimeMs) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2574 | super.stopAllRunningLocked(elapsedRealtimeMs); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2575 | mSubTimer.stopAllRunningLocked(elapsedRealtimeMs); |
| 2576 | } |
| 2577 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2578 | @Override |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2579 | public boolean reset(boolean detachIfReset) { |
| 2580 | boolean active = false; |
Bookatz | 4a3eda9 | 2017-04-10 13:10:46 -0700 | [diff] [blame] | 2581 | // Do not detach the subTimer explicitly since that'll be done by DualTimer.detach(). |
| 2582 | active |= !mSubTimer.reset(false); |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2583 | active |= !super.reset(detachIfReset); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2584 | return !active; |
| 2585 | } |
| 2586 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2587 | @Override |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2588 | public void detach() { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2589 | mSubTimer.detach(); |
Bookatz | 4a3eda9 | 2017-04-10 13:10:46 -0700 | [diff] [blame] | 2590 | super.detach(); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2591 | } |
| 2592 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2593 | @Override |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2594 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2595 | super.writeToParcel(out, elapsedRealtimeUs); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2596 | mSubTimer.writeToParcel(out, elapsedRealtimeUs); |
| 2597 | } |
| 2598 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2599 | @Override |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2600 | public void writeSummaryFromParcelLocked(Parcel out, long elapsedRealtimeUs) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2601 | super.writeSummaryFromParcelLocked(out, elapsedRealtimeUs); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2602 | mSubTimer.writeSummaryFromParcelLocked(out, elapsedRealtimeUs); |
| 2603 | } |
| 2604 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2605 | @Override |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2606 | public void readSummaryFromParcelLocked(Parcel in) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2607 | super.readSummaryFromParcelLocked(in); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2608 | mSubTimer.readSummaryFromParcelLocked(in); |
| 2609 | } |
| 2610 | } |
| 2611 | |
| 2612 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2613 | public abstract class OverflowArrayMap<T> { |
| 2614 | private static final String OVERFLOW_NAME = "*overflow*"; |
| 2615 | |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame] | 2616 | final int mUid; |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2617 | final ArrayMap<String, T> mMap = new ArrayMap<>(); |
| 2618 | T mCurOverflow; |
| 2619 | ArrayMap<String, MutableInt> mActiveOverflow; |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame] | 2620 | long mLastOverflowTime; |
| 2621 | long mLastOverflowFinishTime; |
| 2622 | long mLastClearTime; |
| 2623 | long mLastCleanupTime; |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2624 | |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame] | 2625 | public OverflowArrayMap(int uid) { |
| 2626 | mUid = uid; |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2627 | } |
| 2628 | |
| 2629 | public ArrayMap<String, T> getMap() { |
| 2630 | return mMap; |
| 2631 | } |
| 2632 | |
| 2633 | public void clear() { |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame] | 2634 | mLastClearTime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2635 | mMap.clear(); |
| 2636 | mCurOverflow = null; |
| 2637 | mActiveOverflow = null; |
| 2638 | } |
| 2639 | |
| 2640 | public void add(String name, T obj) { |
Joe Onorato | 388fc33 | 2016-04-12 17:06:47 -0700 | [diff] [blame] | 2641 | if (name == null) { |
| 2642 | name = ""; |
| 2643 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2644 | mMap.put(name, obj); |
| 2645 | if (OVERFLOW_NAME.equals(name)) { |
| 2646 | mCurOverflow = obj; |
| 2647 | } |
| 2648 | } |
| 2649 | |
| 2650 | public void cleanup() { |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame] | 2651 | mLastCleanupTime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2652 | if (mActiveOverflow != null) { |
| 2653 | if (mActiveOverflow.size() == 0) { |
| 2654 | mActiveOverflow = null; |
| 2655 | } |
| 2656 | } |
| 2657 | if (mActiveOverflow == null) { |
| 2658 | // There is no currently active overflow, so we should no longer have |
| 2659 | // an overflow entry. |
| 2660 | if (mMap.containsKey(OVERFLOW_NAME)) { |
| 2661 | Slog.wtf(TAG, "Cleaning up with no active overflow, but have overflow entry " |
| 2662 | + mMap.get(OVERFLOW_NAME)); |
| 2663 | mMap.remove(OVERFLOW_NAME); |
| 2664 | } |
| 2665 | mCurOverflow = null; |
| 2666 | } else { |
| 2667 | // There is currently active overflow, so we should still have an overflow entry. |
| 2668 | if (mCurOverflow == null || !mMap.containsKey(OVERFLOW_NAME)) { |
| 2669 | Slog.wtf(TAG, "Cleaning up with active overflow, but no overflow entry: cur=" |
| 2670 | + mCurOverflow + " map=" + mMap.get(OVERFLOW_NAME)); |
| 2671 | } |
| 2672 | } |
| 2673 | } |
| 2674 | |
| 2675 | public T startObject(String name) { |
Joe Onorato | 388fc33 | 2016-04-12 17:06:47 -0700 | [diff] [blame] | 2676 | if (name == null) { |
| 2677 | name = ""; |
| 2678 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2679 | T obj = mMap.get(name); |
| 2680 | if (obj != null) { |
| 2681 | return obj; |
| 2682 | } |
| 2683 | |
| 2684 | // No object exists for the given name, but do we currently have it |
| 2685 | // running as part of the overflow? |
| 2686 | if (mActiveOverflow != null) { |
| 2687 | MutableInt over = mActiveOverflow.get(name); |
| 2688 | if (over != null) { |
| 2689 | // We are already actively counting this name in the overflow object. |
| 2690 | obj = mCurOverflow; |
| 2691 | if (obj == null) { |
| 2692 | // Shouldn't be here, but we'll try to recover. |
| 2693 | Slog.wtf(TAG, "Have active overflow " + name + " but null overflow"); |
| 2694 | obj = mCurOverflow = instantiateObject(); |
| 2695 | mMap.put(OVERFLOW_NAME, obj); |
| 2696 | } |
| 2697 | over.value++; |
| 2698 | return obj; |
| 2699 | } |
| 2700 | } |
| 2701 | |
| 2702 | // No object exists for given name nor in the overflow; we need to make |
| 2703 | // a new one. |
| 2704 | final int N = mMap.size(); |
| 2705 | if (N >= MAX_WAKELOCKS_PER_UID) { |
| 2706 | // Went over the limit on number of objects to track; this one goes |
| 2707 | // in to the overflow. |
| 2708 | obj = mCurOverflow; |
| 2709 | if (obj == null) { |
| 2710 | // Need to start overflow now... |
| 2711 | obj = mCurOverflow = instantiateObject(); |
| 2712 | mMap.put(OVERFLOW_NAME, obj); |
| 2713 | } |
| 2714 | if (mActiveOverflow == null) { |
| 2715 | mActiveOverflow = new ArrayMap<>(); |
| 2716 | } |
| 2717 | mActiveOverflow.put(name, new MutableInt(1)); |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame] | 2718 | mLastOverflowTime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2719 | return obj; |
| 2720 | } |
| 2721 | |
| 2722 | // Normal case where we just need to make a new object. |
| 2723 | obj = instantiateObject(); |
| 2724 | mMap.put(name, obj); |
| 2725 | return obj; |
| 2726 | } |
| 2727 | |
| 2728 | public T stopObject(String name) { |
Joe Onorato | 388fc33 | 2016-04-12 17:06:47 -0700 | [diff] [blame] | 2729 | if (name == null) { |
| 2730 | name = ""; |
| 2731 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2732 | T obj = mMap.get(name); |
| 2733 | if (obj != null) { |
| 2734 | return obj; |
| 2735 | } |
| 2736 | |
| 2737 | // No object exists for the given name, but do we currently have it |
| 2738 | // running as part of the overflow? |
| 2739 | if (mActiveOverflow != null) { |
| 2740 | MutableInt over = mActiveOverflow.get(name); |
| 2741 | if (over != null) { |
| 2742 | // We are already actively counting this name in the overflow object. |
| 2743 | obj = mCurOverflow; |
| 2744 | if (obj != null) { |
| 2745 | over.value--; |
| 2746 | if (over.value <= 0) { |
| 2747 | mActiveOverflow.remove(name); |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame] | 2748 | mLastOverflowFinishTime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2749 | } |
| 2750 | return obj; |
| 2751 | } |
| 2752 | } |
| 2753 | } |
| 2754 | |
| 2755 | // Huh, they are stopping an active operation but we can't find one! |
| 2756 | // That's not good. |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame] | 2757 | StringBuilder sb = new StringBuilder(); |
| 2758 | sb.append("Unable to find object for "); |
| 2759 | sb.append(name); |
| 2760 | sb.append(" in uid "); |
| 2761 | sb.append(mUid); |
| 2762 | sb.append(" mapsize="); |
| 2763 | sb.append(mMap.size()); |
| 2764 | sb.append(" activeoverflow="); |
| 2765 | sb.append(mActiveOverflow); |
| 2766 | sb.append(" curoverflow="); |
| 2767 | sb.append(mCurOverflow); |
| 2768 | long now = SystemClock.elapsedRealtime(); |
| 2769 | if (mLastOverflowTime != 0) { |
| 2770 | sb.append(" lastOverflowTime="); |
| 2771 | TimeUtils.formatDuration(mLastOverflowTime-now, sb); |
| 2772 | } |
| 2773 | if (mLastOverflowFinishTime != 0) { |
| 2774 | sb.append(" lastOverflowFinishTime="); |
| 2775 | TimeUtils.formatDuration(mLastOverflowFinishTime-now, sb); |
| 2776 | } |
| 2777 | if (mLastClearTime != 0) { |
| 2778 | sb.append(" lastClearTime="); |
| 2779 | TimeUtils.formatDuration(mLastClearTime-now, sb); |
| 2780 | } |
| 2781 | if (mLastCleanupTime != 0) { |
| 2782 | sb.append(" lastCleanupTime="); |
| 2783 | TimeUtils.formatDuration(mLastCleanupTime-now, sb); |
| 2784 | } |
| 2785 | Slog.wtf(TAG, sb.toString()); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2786 | return null; |
| 2787 | } |
| 2788 | |
| 2789 | public abstract T instantiateObject(); |
| 2790 | } |
| 2791 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2792 | public static class ControllerActivityCounterImpl extends ControllerActivityCounter |
| 2793 | implements Parcelable { |
| 2794 | private final LongSamplingCounter mIdleTimeMillis; |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 2795 | private final LongSamplingCounter mScanTimeMillis; |
Siddharth Ray | ed75470 | 2018-02-15 12:44:37 -0800 | [diff] [blame^] | 2796 | private final LongSamplingCounter mSleepTimeMillis; |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2797 | private final LongSamplingCounter mRxTimeMillis; |
| 2798 | private final LongSamplingCounter[] mTxTimeMillis; |
| 2799 | private final LongSamplingCounter mPowerDrainMaMs; |
| 2800 | |
| 2801 | public ControllerActivityCounterImpl(TimeBase timeBase, int numTxStates) { |
| 2802 | mIdleTimeMillis = new LongSamplingCounter(timeBase); |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 2803 | mScanTimeMillis = new LongSamplingCounter(timeBase); |
Siddharth Ray | ed75470 | 2018-02-15 12:44:37 -0800 | [diff] [blame^] | 2804 | mSleepTimeMillis = new LongSamplingCounter(timeBase); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2805 | mRxTimeMillis = new LongSamplingCounter(timeBase); |
| 2806 | mTxTimeMillis = new LongSamplingCounter[numTxStates]; |
| 2807 | for (int i = 0; i < numTxStates; i++) { |
| 2808 | mTxTimeMillis[i] = new LongSamplingCounter(timeBase); |
| 2809 | } |
| 2810 | mPowerDrainMaMs = new LongSamplingCounter(timeBase); |
| 2811 | } |
| 2812 | |
| 2813 | public ControllerActivityCounterImpl(TimeBase timeBase, int numTxStates, Parcel in) { |
| 2814 | mIdleTimeMillis = new LongSamplingCounter(timeBase, in); |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 2815 | mScanTimeMillis = new LongSamplingCounter(timeBase, in); |
Siddharth Ray | ed75470 | 2018-02-15 12:44:37 -0800 | [diff] [blame^] | 2816 | mSleepTimeMillis = new LongSamplingCounter(timeBase, in); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2817 | mRxTimeMillis = new LongSamplingCounter(timeBase, in); |
| 2818 | final int recordedTxStates = in.readInt(); |
| 2819 | if (recordedTxStates != numTxStates) { |
| 2820 | throw new ParcelFormatException("inconsistent tx state lengths"); |
| 2821 | } |
| 2822 | |
| 2823 | mTxTimeMillis = new LongSamplingCounter[numTxStates]; |
| 2824 | for (int i = 0; i < numTxStates; i++) { |
| 2825 | mTxTimeMillis[i] = new LongSamplingCounter(timeBase, in); |
| 2826 | } |
| 2827 | mPowerDrainMaMs = new LongSamplingCounter(timeBase, in); |
| 2828 | } |
| 2829 | |
| 2830 | public void readSummaryFromParcel(Parcel in) { |
| 2831 | mIdleTimeMillis.readSummaryFromParcelLocked(in); |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 2832 | mScanTimeMillis.readSummaryFromParcelLocked(in); |
Siddharth Ray | ed75470 | 2018-02-15 12:44:37 -0800 | [diff] [blame^] | 2833 | mSleepTimeMillis.readSummaryFromParcelLocked(in); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2834 | mRxTimeMillis.readSummaryFromParcelLocked(in); |
| 2835 | final int recordedTxStates = in.readInt(); |
| 2836 | if (recordedTxStates != mTxTimeMillis.length) { |
| 2837 | throw new ParcelFormatException("inconsistent tx state lengths"); |
| 2838 | } |
| 2839 | for (LongSamplingCounter counter : mTxTimeMillis) { |
| 2840 | counter.readSummaryFromParcelLocked(in); |
| 2841 | } |
| 2842 | mPowerDrainMaMs.readSummaryFromParcelLocked(in); |
| 2843 | } |
| 2844 | |
| 2845 | @Override |
| 2846 | public int describeContents() { |
| 2847 | return 0; |
| 2848 | } |
| 2849 | |
| 2850 | public void writeSummaryToParcel(Parcel dest) { |
| 2851 | mIdleTimeMillis.writeSummaryFromParcelLocked(dest); |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 2852 | mScanTimeMillis.writeSummaryFromParcelLocked(dest); |
Siddharth Ray | ed75470 | 2018-02-15 12:44:37 -0800 | [diff] [blame^] | 2853 | mSleepTimeMillis.writeSummaryFromParcelLocked(dest); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2854 | mRxTimeMillis.writeSummaryFromParcelLocked(dest); |
| 2855 | dest.writeInt(mTxTimeMillis.length); |
| 2856 | for (LongSamplingCounter counter : mTxTimeMillis) { |
| 2857 | counter.writeSummaryFromParcelLocked(dest); |
| 2858 | } |
| 2859 | mPowerDrainMaMs.writeSummaryFromParcelLocked(dest); |
| 2860 | } |
| 2861 | |
| 2862 | @Override |
| 2863 | public void writeToParcel(Parcel dest, int flags) { |
| 2864 | mIdleTimeMillis.writeToParcel(dest); |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 2865 | mScanTimeMillis.writeToParcel(dest); |
Siddharth Ray | ed75470 | 2018-02-15 12:44:37 -0800 | [diff] [blame^] | 2866 | mSleepTimeMillis.writeToParcel(dest); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2867 | mRxTimeMillis.writeToParcel(dest); |
| 2868 | dest.writeInt(mTxTimeMillis.length); |
| 2869 | for (LongSamplingCounter counter : mTxTimeMillis) { |
| 2870 | counter.writeToParcel(dest); |
| 2871 | } |
| 2872 | mPowerDrainMaMs.writeToParcel(dest); |
| 2873 | } |
| 2874 | |
| 2875 | public void reset(boolean detachIfReset) { |
| 2876 | mIdleTimeMillis.reset(detachIfReset); |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 2877 | mScanTimeMillis.reset(detachIfReset); |
Siddharth Ray | ed75470 | 2018-02-15 12:44:37 -0800 | [diff] [blame^] | 2878 | mSleepTimeMillis.reset(detachIfReset); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2879 | mRxTimeMillis.reset(detachIfReset); |
| 2880 | for (LongSamplingCounter counter : mTxTimeMillis) { |
| 2881 | counter.reset(detachIfReset); |
| 2882 | } |
| 2883 | mPowerDrainMaMs.reset(detachIfReset); |
| 2884 | } |
| 2885 | |
| 2886 | public void detach() { |
| 2887 | mIdleTimeMillis.detach(); |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 2888 | mScanTimeMillis.detach(); |
Siddharth Ray | ed75470 | 2018-02-15 12:44:37 -0800 | [diff] [blame^] | 2889 | mSleepTimeMillis.detach(); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2890 | mRxTimeMillis.detach(); |
| 2891 | for (LongSamplingCounter counter : mTxTimeMillis) { |
| 2892 | counter.detach(); |
| 2893 | } |
| 2894 | mPowerDrainMaMs.detach(); |
| 2895 | } |
| 2896 | |
| 2897 | /** |
| 2898 | * @return a LongSamplingCounter, measuring time spent in the idle state in |
| 2899 | * milliseconds. |
| 2900 | */ |
| 2901 | @Override |
| 2902 | public LongSamplingCounter getIdleTimeCounter() { |
Roshan Pius | 8164330 | 2016-03-14 16:45:55 -0700 | [diff] [blame] | 2903 | return mIdleTimeMillis; |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2904 | } |
| 2905 | |
| 2906 | /** |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 2907 | * @return a LongSamplingCounter, measuring time spent in the scan state in |
| 2908 | * milliseconds. |
| 2909 | */ |
| 2910 | @Override |
| 2911 | public LongSamplingCounter getScanTimeCounter() { |
| 2912 | return mScanTimeMillis; |
| 2913 | } |
| 2914 | |
| 2915 | /** |
Siddharth Ray | ed75470 | 2018-02-15 12:44:37 -0800 | [diff] [blame^] | 2916 | * @return a LongSamplingCounter, measuring time spent in the sleep state in |
| 2917 | * milliseconds. |
| 2918 | */ |
| 2919 | @Override |
| 2920 | public LongSamplingCounter getSleepTimeCounter() { |
| 2921 | return mSleepTimeMillis; |
| 2922 | } |
| 2923 | |
| 2924 | /** |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2925 | * @return a LongSamplingCounter, measuring time spent in the receive state in |
| 2926 | * milliseconds. |
| 2927 | */ |
| 2928 | @Override |
| 2929 | public LongSamplingCounter getRxTimeCounter() { |
| 2930 | return mRxTimeMillis; |
| 2931 | } |
| 2932 | |
| 2933 | /** |
| 2934 | * @return a LongSamplingCounter[], measuring time spent in various transmit states in |
| 2935 | * milliseconds. |
| 2936 | */ |
| 2937 | @Override |
| 2938 | public LongSamplingCounter[] getTxTimeCounters() { |
| 2939 | return mTxTimeMillis; |
| 2940 | } |
| 2941 | |
| 2942 | /** |
| 2943 | * @return a LongSamplingCounter, measuring power use in milli-ampere milliseconds (mAmS). |
| 2944 | */ |
| 2945 | @Override |
| 2946 | public LongSamplingCounter getPowerCounter() { |
| 2947 | return mPowerDrainMaMs; |
| 2948 | } |
| 2949 | } |
| 2950 | |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 2951 | /** Get Resource Power Manager stats. Create a new one if it doesn't already exist. */ |
| 2952 | public SamplingTimer getRpmTimerLocked(String name) { |
| 2953 | SamplingTimer rpmt = mRpmStats.get(name); |
| 2954 | if (rpmt == null) { |
| 2955 | rpmt = new SamplingTimer(mClocks, mOnBatteryTimeBase); |
| 2956 | mRpmStats.put(name, rpmt); |
| 2957 | } |
| 2958 | return rpmt; |
| 2959 | } |
| 2960 | |
| 2961 | /** Get Screen-off Resource Power Manager stats. Create new one if it doesn't already exist. */ |
| 2962 | public SamplingTimer getScreenOffRpmTimerLocked(String name) { |
| 2963 | SamplingTimer rpmt = mScreenOffRpmStats.get(name); |
| 2964 | if (rpmt == null) { |
| 2965 | rpmt = new SamplingTimer(mClocks, mOnBatteryScreenOffTimeBase); |
| 2966 | mScreenOffRpmStats.put(name, rpmt); |
| 2967 | } |
| 2968 | return rpmt; |
| 2969 | } |
| 2970 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2971 | /* |
| 2972 | * Get the wakeup reason counter, and create a new one if one |
| 2973 | * doesn't already exist. |
| 2974 | */ |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 2975 | public SamplingTimer getWakeupReasonTimerLocked(String name) { |
| 2976 | SamplingTimer timer = mWakeupReasonStats.get(name); |
| 2977 | if (timer == null) { |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 2978 | timer = new SamplingTimer(mClocks, mOnBatteryTimeBase); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 2979 | mWakeupReasonStats.put(name, timer); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2980 | } |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 2981 | return timer; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2982 | } |
| 2983 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2984 | /* |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2985 | * 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] | 2986 | * doesn't already exist. |
| 2987 | */ |
| 2988 | public SamplingTimer getKernelWakelockTimerLocked(String name) { |
| 2989 | SamplingTimer kwlt = mKernelWakelockStats.get(name); |
| 2990 | if (kwlt == null) { |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 2991 | kwlt = new SamplingTimer(mClocks, mOnBatteryScreenOffTimeBase); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2992 | mKernelWakelockStats.put(name, kwlt); |
| 2993 | } |
| 2994 | return kwlt; |
| 2995 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 2996 | |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 2997 | public SamplingTimer getKernelMemoryTimerLocked(long bucket) { |
| 2998 | SamplingTimer kmt = mKernelMemoryStats.get(bucket); |
| 2999 | if (kmt == null) { |
| 3000 | kmt = new SamplingTimer(mClocks, mOnBatteryTimeBase); |
| 3001 | mKernelMemoryStats.put(bucket, kmt); |
| 3002 | } |
| 3003 | return kmt; |
| 3004 | } |
| 3005 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3006 | private int writeHistoryTag(HistoryTag tag) { |
| 3007 | Integer idxObj = mHistoryTagPool.get(tag); |
| 3008 | int idx; |
| 3009 | if (idxObj != null) { |
| 3010 | idx = idxObj; |
| 3011 | } else { |
| 3012 | idx = mNextHistoryTagIdx; |
| 3013 | HistoryTag key = new HistoryTag(); |
| 3014 | key.setTo(tag); |
| 3015 | tag.poolIdx = idx; |
| 3016 | mHistoryTagPool.put(key, idx); |
| 3017 | mNextHistoryTagIdx++; |
| 3018 | mNumHistoryTagChars += key.string.length() + 1; |
| 3019 | } |
| 3020 | return idx; |
| 3021 | } |
| 3022 | |
| 3023 | private void readHistoryTag(int index, HistoryTag tag) { |
| 3024 | tag.string = mReadHistoryStrings[index]; |
| 3025 | tag.uid = mReadHistoryUids[index]; |
| 3026 | tag.poolIdx = index; |
| 3027 | } |
| 3028 | |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 3029 | /* |
| 3030 | The history delta format uses flags to denote further data in subsequent ints in the parcel. |
| 3031 | |
| 3032 | There is always the first token, which may contain the delta time, or an indicator of |
| 3033 | the length of the time (int or long) following this token. |
| 3034 | |
| 3035 | First token: always present, |
| 3036 | 31 23 15 7 0 |
| 3037 | â–ˆ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â–ˆ |
| 3038 | |
| 3039 | T: the delta time if it is <= 0x7fffd. Otherwise 0x7fffe indicates an int immediately |
| 3040 | follows containing the time, and 0x7ffff indicates a long immediately follows with the |
| 3041 | delta time. |
| 3042 | A: battery level changed and an int follows with battery data. |
| 3043 | B: state changed and an int follows with state change data. |
| 3044 | C: state2 has changed and an int follows with state2 change data. |
| 3045 | D: wakelock/wakereason has changed and an wakelock/wakereason struct follows. |
| 3046 | E: event data has changed and an event struct follows. |
| 3047 | F: battery charge in coulombs has changed and an int with the charge follows. |
| 3048 | G: state flag denoting that the mobile radio was active. |
| 3049 | H: state flag denoting that the wifi radio was active. |
| 3050 | I: state flag denoting that a wifi scan occurred. |
| 3051 | J: state flag denoting that a wifi full lock was held. |
| 3052 | K: state flag denoting that the gps was on. |
| 3053 | L: state flag denoting that a wakelock was held. |
| 3054 | M: state flag denoting that the cpu was running. |
| 3055 | |
| 3056 | Time int/long: if T in the first token is 0x7ffff or 0x7fffe, then an int or long follows |
| 3057 | with the time delta. |
| 3058 | |
| 3059 | Battery level int: if A in the first token is set, |
| 3060 | 31 23 15 7 0 |
| 3061 | â–ˆ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â–ˆ |
| 3062 | |
| 3063 | D: indicates that extra history details follow. |
| 3064 | V: the battery voltage. |
| 3065 | T: the battery temperature. |
| 3066 | L: the battery level (out of 100). |
| 3067 | |
| 3068 | State change int: if B in the first token is set, |
| 3069 | 31 23 15 7 0 |
| 3070 | â–ˆS|S|S|H|H|H|P|Pâ–ˆF|E|D|C|B| | |Aâ–ˆ | | | | | | | â–ˆ | | | | | | | â–ˆ |
| 3071 | |
| 3072 | A: wifi multicast was on. |
| 3073 | B: battery was plugged in. |
| 3074 | C: screen was on. |
| 3075 | D: phone was scanning for signal. |
| 3076 | E: audio was on. |
| 3077 | F: a sensor was active. |
| 3078 | |
| 3079 | State2 change int: if C in the first token is set, |
| 3080 | 31 23 15 7 0 |
| 3081 | â–ˆM|L|K|J|I|H|H|Gâ–ˆF|E|D|C| | | | â–ˆ | | | | | | | â–ˆ |B|B|B|A|A|A|Aâ–ˆ |
| 3082 | |
| 3083 | A: 4 bits indicating the wifi supplicant state: {@link BatteryStats#WIFI_SUPPL_STATE_NAMES}. |
| 3084 | B: 3 bits indicating the wifi signal strength: 0, 1, 2, 3, 4. |
| 3085 | C: a bluetooth scan was active. |
| 3086 | D: the camera was active. |
| 3087 | E: bluetooth was on. |
| 3088 | F: a phone call was active. |
| 3089 | G: the device was charging. |
| 3090 | H: 2 bits indicating the device-idle (doze) state: off, light, full |
| 3091 | I: the flashlight was on. |
| 3092 | J: wifi was on. |
| 3093 | K: wifi was running. |
| 3094 | L: video was playing. |
| 3095 | M: power save mode was on. |
| 3096 | |
| 3097 | Wakelock/wakereason struct: if D in the first token is set, |
| 3098 | TODO(adamlesinski): describe wakelock/wakereason struct. |
| 3099 | |
| 3100 | Event struct: if E in the first token is set, |
| 3101 | TODO(adamlesinski): describe the event struct. |
| 3102 | |
| 3103 | History step details struct: if D in the battery level int is set, |
| 3104 | TODO(adamlesinski): describe the history step details struct. |
| 3105 | |
| 3106 | Battery charge int: if F in the first token is set, an int representing the battery charge |
| 3107 | in coulombs follows. |
| 3108 | */ |
| 3109 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3110 | // Part of initial delta int that specifies the time delta. |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 3111 | static final int DELTA_TIME_MASK = 0x7ffff; |
| 3112 | static final int DELTA_TIME_LONG = 0x7ffff; // The delta is a following long |
| 3113 | static final int DELTA_TIME_INT = 0x7fffe; // The delta is a following int |
| 3114 | 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] | 3115 | // Flag in delta int: a new battery level int follows. |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 3116 | static final int DELTA_BATTERY_LEVEL_FLAG = 0x00080000; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3117 | // 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] | 3118 | static final int DELTA_STATE_FLAG = 0x00100000; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 3119 | // Flag in delta int: a new full state2 int follows. |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 3120 | static final int DELTA_STATE2_FLAG = 0x00200000; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3121 | // Flag in delta int: contains a wakelock or wakeReason tag. |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 3122 | static final int DELTA_WAKELOCK_FLAG = 0x00400000; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3123 | // Flag in delta int: contains an event description. |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 3124 | static final int DELTA_EVENT_FLAG = 0x00800000; |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 3125 | // Flag in delta int: contains the battery charge count in uAh. |
| 3126 | static final int DELTA_BATTERY_CHARGE_FLAG = 0x01000000; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3127 | // These upper bits are the frequently changing state bits. |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 3128 | static final int DELTA_STATE_MASK = 0xfe000000; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 3129 | |
| 3130 | // These are the pieces of battery state that are packed in to the upper bits of |
| 3131 | // 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] | 3132 | // in STATE_BATTERY_MASK. |
| 3133 | static final int STATE_BATTERY_MASK = 0xff000000; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 3134 | static final int STATE_BATTERY_STATUS_MASK = 0x00000007; |
| 3135 | static final int STATE_BATTERY_STATUS_SHIFT = 29; |
| 3136 | static final int STATE_BATTERY_HEALTH_MASK = 0x00000007; |
| 3137 | static final int STATE_BATTERY_HEALTH_SHIFT = 26; |
| 3138 | static final int STATE_BATTERY_PLUG_MASK = 0x00000003; |
| 3139 | static final int STATE_BATTERY_PLUG_SHIFT = 24; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3140 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 3141 | // We use the low bit of the battery state int to indicate that we have full details |
| 3142 | // from a battery level change. |
| 3143 | static final int BATTERY_DELTA_LEVEL_FLAG = 0x00000001; |
| 3144 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3145 | public void writeHistoryDelta(Parcel dest, HistoryItem cur, HistoryItem last) { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3146 | if (last == null || cur.cmd != HistoryItem.CMD_UPDATE) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3147 | dest.writeInt(DELTA_TIME_ABS); |
| 3148 | cur.writeToParcel(dest, 0); |
| 3149 | return; |
| 3150 | } |
| 3151 | |
| 3152 | final long deltaTime = cur.time - last.time; |
| 3153 | final int lastBatteryLevelInt = buildBatteryLevelInt(last); |
| 3154 | final int lastStateInt = buildStateInt(last); |
| 3155 | |
| 3156 | int deltaTimeToken; |
| 3157 | if (deltaTime < 0 || deltaTime > Integer.MAX_VALUE) { |
| 3158 | deltaTimeToken = DELTA_TIME_LONG; |
| 3159 | } else if (deltaTime >= DELTA_TIME_ABS) { |
| 3160 | deltaTimeToken = DELTA_TIME_INT; |
| 3161 | } else { |
| 3162 | deltaTimeToken = (int)deltaTime; |
| 3163 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3164 | int firstToken = deltaTimeToken | (cur.states&DELTA_STATE_MASK); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 3165 | final int includeStepDetails = mLastHistoryStepLevel > cur.batteryLevel |
| 3166 | ? BATTERY_DELTA_LEVEL_FLAG : 0; |
| 3167 | final boolean computeStepDetails = includeStepDetails != 0 |
| 3168 | || mLastHistoryStepDetails == null; |
| 3169 | final int batteryLevelInt = buildBatteryLevelInt(cur) | includeStepDetails; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3170 | final boolean batteryLevelIntChanged = batteryLevelInt != lastBatteryLevelInt; |
| 3171 | if (batteryLevelIntChanged) { |
| 3172 | firstToken |= DELTA_BATTERY_LEVEL_FLAG; |
| 3173 | } |
| 3174 | final int stateInt = buildStateInt(cur); |
| 3175 | final boolean stateIntChanged = stateInt != lastStateInt; |
| 3176 | if (stateIntChanged) { |
| 3177 | firstToken |= DELTA_STATE_FLAG; |
| 3178 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3179 | final boolean state2IntChanged = cur.states2 != last.states2; |
| 3180 | if (state2IntChanged) { |
| 3181 | firstToken |= DELTA_STATE2_FLAG; |
| 3182 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3183 | if (cur.wakelockTag != null || cur.wakeReasonTag != null) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3184 | firstToken |= DELTA_WAKELOCK_FLAG; |
| 3185 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3186 | if (cur.eventCode != HistoryItem.EVENT_NONE) { |
| 3187 | firstToken |= DELTA_EVENT_FLAG; |
| 3188 | } |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 3189 | |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 3190 | final boolean batteryChargeChanged = cur.batteryChargeUAh != last.batteryChargeUAh; |
| 3191 | if (batteryChargeChanged) { |
| 3192 | firstToken |= DELTA_BATTERY_CHARGE_FLAG; |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 3193 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3194 | dest.writeInt(firstToken); |
| 3195 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: firstToken=0x" + Integer.toHexString(firstToken) |
| 3196 | + " deltaTime=" + deltaTime); |
| 3197 | |
| 3198 | if (deltaTimeToken >= DELTA_TIME_INT) { |
| 3199 | if (deltaTimeToken == DELTA_TIME_INT) { |
| 3200 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: int deltaTime=" + (int)deltaTime); |
| 3201 | dest.writeInt((int)deltaTime); |
| 3202 | } else { |
| 3203 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: long deltaTime=" + deltaTime); |
| 3204 | dest.writeLong(deltaTime); |
| 3205 | } |
| 3206 | } |
| 3207 | if (batteryLevelIntChanged) { |
| 3208 | dest.writeInt(batteryLevelInt); |
| 3209 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: batteryToken=0x" |
| 3210 | + Integer.toHexString(batteryLevelInt) |
| 3211 | + " batteryLevel=" + cur.batteryLevel |
| 3212 | + " batteryTemp=" + cur.batteryTemperature |
| 3213 | + " batteryVolt=" + (int)cur.batteryVoltage); |
| 3214 | } |
| 3215 | if (stateIntChanged) { |
| 3216 | dest.writeInt(stateInt); |
| 3217 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: stateToken=0x" |
| 3218 | + Integer.toHexString(stateInt) |
| 3219 | + " batteryStatus=" + cur.batteryStatus |
| 3220 | + " batteryHealth=" + cur.batteryHealth |
| 3221 | + " batteryPlugType=" + cur.batteryPlugType |
| 3222 | + " states=0x" + Integer.toHexString(cur.states)); |
| 3223 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3224 | if (state2IntChanged) { |
| 3225 | dest.writeInt(cur.states2); |
| 3226 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: states2=0x" |
| 3227 | + Integer.toHexString(cur.states2)); |
| 3228 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3229 | if (cur.wakelockTag != null || cur.wakeReasonTag != null) { |
| 3230 | int wakeLockIndex; |
| 3231 | int wakeReasonIndex; |
| 3232 | if (cur.wakelockTag != null) { |
| 3233 | wakeLockIndex = writeHistoryTag(cur.wakelockTag); |
| 3234 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: wakelockTag=#" + cur.wakelockTag.poolIdx |
| 3235 | + " " + cur.wakelockTag.uid + ":" + cur.wakelockTag.string); |
| 3236 | } else { |
| 3237 | wakeLockIndex = 0xffff; |
| 3238 | } |
| 3239 | if (cur.wakeReasonTag != null) { |
| 3240 | wakeReasonIndex = writeHistoryTag(cur.wakeReasonTag); |
| 3241 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: wakeReasonTag=#" + cur.wakeReasonTag.poolIdx |
| 3242 | + " " + cur.wakeReasonTag.uid + ":" + cur.wakeReasonTag.string); |
| 3243 | } else { |
| 3244 | wakeReasonIndex = 0xffff; |
| 3245 | } |
| 3246 | dest.writeInt((wakeReasonIndex<<16) | wakeLockIndex); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3247 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3248 | if (cur.eventCode != HistoryItem.EVENT_NONE) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3249 | int index = writeHistoryTag(cur.eventTag); |
| 3250 | int codeAndIndex = (cur.eventCode&0xffff) | (index<<16); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3251 | dest.writeInt(codeAndIndex); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3252 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: event=" + cur.eventCode + " tag=#" |
| 3253 | + cur.eventTag.poolIdx + " " + cur.eventTag.uid + ":" |
| 3254 | + cur.eventTag.string); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3255 | } |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 3256 | if (computeStepDetails) { |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 3257 | if (mPlatformIdleStateCallback != null) { |
| 3258 | mCurHistoryStepDetails.statPlatformIdleState = |
| 3259 | mPlatformIdleStateCallback.getPlatformLowPowerStats(); |
| 3260 | if (DEBUG) Slog.i(TAG, "WRITE PlatformIdleState:" + |
| 3261 | mCurHistoryStepDetails.statPlatformIdleState); |
Ahmed ElArabawy | d8b4411 | 2017-05-23 21:25:02 +0000 | [diff] [blame] | 3262 | |
| 3263 | mCurHistoryStepDetails.statSubsystemPowerState = |
| 3264 | mPlatformIdleStateCallback.getSubsystemLowPowerStats(); |
| 3265 | if (DEBUG) Slog.i(TAG, "WRITE SubsystemPowerState:" + |
| 3266 | mCurHistoryStepDetails.statSubsystemPowerState); |
| 3267 | |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 3268 | } |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 3269 | computeHistoryStepDetails(mCurHistoryStepDetails, mLastHistoryStepDetails); |
| 3270 | if (includeStepDetails != 0) { |
| 3271 | mCurHistoryStepDetails.writeToParcel(dest); |
| 3272 | } |
| 3273 | cur.stepDetails = mCurHistoryStepDetails; |
| 3274 | mLastHistoryStepDetails = mCurHistoryStepDetails; |
| 3275 | } else { |
| 3276 | cur.stepDetails = null; |
| 3277 | } |
| 3278 | if (mLastHistoryStepLevel < cur.batteryLevel) { |
| 3279 | mLastHistoryStepDetails = null; |
| 3280 | } |
| 3281 | mLastHistoryStepLevel = cur.batteryLevel; |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 3282 | |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 3283 | if (batteryChargeChanged) { |
| 3284 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: batteryChargeUAh=" + cur.batteryChargeUAh); |
| 3285 | dest.writeInt(cur.batteryChargeUAh); |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 3286 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3287 | } |
| 3288 | |
| 3289 | private int buildBatteryLevelInt(HistoryItem h) { |
| 3290 | return ((((int)h.batteryLevel)<<25)&0xfe000000) |
Adam Lesinski | 3944c81 | 2015-11-13 15:54:59 -0800 | [diff] [blame] | 3291 | | ((((int)h.batteryTemperature)<<15)&0x01ff8000) |
| 3292 | | ((((int)h.batteryVoltage)<<1)&0x00007ffe); |
| 3293 | } |
| 3294 | |
| 3295 | private void readBatteryLevelInt(int batteryLevelInt, HistoryItem out) { |
| 3296 | out.batteryLevel = (byte)((batteryLevelInt & 0xfe000000) >>> 25); |
| 3297 | out.batteryTemperature = (short)((batteryLevelInt & 0x01ff8000) >>> 15); |
| 3298 | out.batteryVoltage = (char)((batteryLevelInt & 0x00007ffe) >>> 1); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3299 | } |
| 3300 | |
| 3301 | private int buildStateInt(HistoryItem h) { |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 3302 | int plugType = 0; |
| 3303 | if ((h.batteryPlugType&BatteryManager.BATTERY_PLUGGED_AC) != 0) { |
| 3304 | plugType = 1; |
| 3305 | } else if ((h.batteryPlugType&BatteryManager.BATTERY_PLUGGED_USB) != 0) { |
| 3306 | plugType = 2; |
| 3307 | } else if ((h.batteryPlugType&BatteryManager.BATTERY_PLUGGED_WIRELESS) != 0) { |
| 3308 | plugType = 3; |
| 3309 | } |
| 3310 | return ((h.batteryStatus&STATE_BATTERY_STATUS_MASK)<<STATE_BATTERY_STATUS_SHIFT) |
| 3311 | | ((h.batteryHealth&STATE_BATTERY_HEALTH_MASK)<<STATE_BATTERY_HEALTH_SHIFT) |
| 3312 | | ((plugType&STATE_BATTERY_PLUG_MASK)<<STATE_BATTERY_PLUG_SHIFT) |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 3313 | | (h.states&(~STATE_BATTERY_MASK)); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3314 | } |
| 3315 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 3316 | private void computeHistoryStepDetails(final HistoryStepDetails out, |
| 3317 | final HistoryStepDetails last) { |
| 3318 | final HistoryStepDetails tmp = last != null ? mTmpHistoryStepDetails : out; |
| 3319 | |
| 3320 | // Perform a CPU update right after we do this collection, so we have started |
| 3321 | // collecting good data for the next step. |
| 3322 | requestImmediateCpuUpdate(); |
| 3323 | |
| 3324 | if (last == null) { |
| 3325 | // We are not generating a delta, so all we need to do is reset the stats |
| 3326 | // we will later be doing a delta from. |
| 3327 | final int NU = mUidStats.size(); |
| 3328 | for (int i=0; i<NU; i++) { |
| 3329 | final BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 3330 | uid.mLastStepUserTime = uid.mCurStepUserTime; |
| 3331 | uid.mLastStepSystemTime = uid.mCurStepSystemTime; |
| 3332 | } |
| 3333 | mLastStepCpuUserTime = mCurStepCpuUserTime; |
| 3334 | mLastStepCpuSystemTime = mCurStepCpuSystemTime; |
| 3335 | mLastStepStatUserTime = mCurStepStatUserTime; |
| 3336 | mLastStepStatSystemTime = mCurStepStatSystemTime; |
| 3337 | mLastStepStatIOWaitTime = mCurStepStatIOWaitTime; |
| 3338 | mLastStepStatIrqTime = mCurStepStatIrqTime; |
| 3339 | mLastStepStatSoftIrqTime = mCurStepStatSoftIrqTime; |
| 3340 | mLastStepStatIdleTime = mCurStepStatIdleTime; |
| 3341 | tmp.clear(); |
| 3342 | return; |
| 3343 | } |
| 3344 | if (DEBUG) { |
| 3345 | Slog.d(TAG, "Step stats last: user=" + mLastStepCpuUserTime + " sys=" |
| 3346 | + mLastStepStatSystemTime + " io=" + mLastStepStatIOWaitTime |
| 3347 | + " irq=" + mLastStepStatIrqTime + " sirq=" |
| 3348 | + mLastStepStatSoftIrqTime + " idle=" + mLastStepStatIdleTime); |
| 3349 | Slog.d(TAG, "Step stats cur: user=" + mCurStepCpuUserTime + " sys=" |
| 3350 | + mCurStepStatSystemTime + " io=" + mCurStepStatIOWaitTime |
| 3351 | + " irq=" + mCurStepStatIrqTime + " sirq=" |
| 3352 | + mCurStepStatSoftIrqTime + " idle=" + mCurStepStatIdleTime); |
| 3353 | } |
| 3354 | out.userTime = (int)(mCurStepCpuUserTime - mLastStepCpuUserTime); |
| 3355 | out.systemTime = (int)(mCurStepCpuSystemTime - mLastStepCpuSystemTime); |
| 3356 | out.statUserTime = (int)(mCurStepStatUserTime - mLastStepStatUserTime); |
| 3357 | out.statSystemTime = (int)(mCurStepStatSystemTime - mLastStepStatSystemTime); |
| 3358 | out.statIOWaitTime = (int)(mCurStepStatIOWaitTime - mLastStepStatIOWaitTime); |
| 3359 | out.statIrqTime = (int)(mCurStepStatIrqTime - mLastStepStatIrqTime); |
| 3360 | out.statSoftIrqTime = (int)(mCurStepStatSoftIrqTime - mLastStepStatSoftIrqTime); |
| 3361 | out.statIdlTime = (int)(mCurStepStatIdleTime - mLastStepStatIdleTime); |
| 3362 | out.appCpuUid1 = out.appCpuUid2 = out.appCpuUid3 = -1; |
| 3363 | out.appCpuUTime1 = out.appCpuUTime2 = out.appCpuUTime3 = 0; |
| 3364 | out.appCpuSTime1 = out.appCpuSTime2 = out.appCpuSTime3 = 0; |
| 3365 | final int NU = mUidStats.size(); |
| 3366 | for (int i=0; i<NU; i++) { |
| 3367 | final BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 3368 | final int totalUTime = (int)(uid.mCurStepUserTime - uid.mLastStepUserTime); |
| 3369 | final int totalSTime = (int)(uid.mCurStepSystemTime - uid.mLastStepSystemTime); |
| 3370 | final int totalTime = totalUTime + totalSTime; |
| 3371 | uid.mLastStepUserTime = uid.mCurStepUserTime; |
| 3372 | uid.mLastStepSystemTime = uid.mCurStepSystemTime; |
| 3373 | if (totalTime <= (out.appCpuUTime3+out.appCpuSTime3)) { |
| 3374 | continue; |
| 3375 | } |
| 3376 | if (totalTime <= (out.appCpuUTime2+out.appCpuSTime2)) { |
| 3377 | out.appCpuUid3 = uid.mUid; |
| 3378 | out.appCpuUTime3 = totalUTime; |
| 3379 | out.appCpuSTime3 = totalSTime; |
| 3380 | } else { |
| 3381 | out.appCpuUid3 = out.appCpuUid2; |
| 3382 | out.appCpuUTime3 = out.appCpuUTime2; |
| 3383 | out.appCpuSTime3 = out.appCpuSTime2; |
| 3384 | if (totalTime <= (out.appCpuUTime1+out.appCpuSTime1)) { |
| 3385 | out.appCpuUid2 = uid.mUid; |
| 3386 | out.appCpuUTime2 = totalUTime; |
| 3387 | out.appCpuSTime2 = totalSTime; |
| 3388 | } else { |
| 3389 | out.appCpuUid2 = out.appCpuUid1; |
| 3390 | out.appCpuUTime2 = out.appCpuUTime1; |
| 3391 | out.appCpuSTime2 = out.appCpuSTime1; |
| 3392 | out.appCpuUid1 = uid.mUid; |
| 3393 | out.appCpuUTime1 = totalUTime; |
| 3394 | out.appCpuSTime1 = totalSTime; |
| 3395 | } |
| 3396 | } |
| 3397 | } |
| 3398 | mLastStepCpuUserTime = mCurStepCpuUserTime; |
| 3399 | mLastStepCpuSystemTime = mCurStepCpuSystemTime; |
| 3400 | mLastStepStatUserTime = mCurStepStatUserTime; |
| 3401 | mLastStepStatSystemTime = mCurStepStatSystemTime; |
| 3402 | mLastStepStatIOWaitTime = mCurStepStatIOWaitTime; |
| 3403 | mLastStepStatIrqTime = mCurStepStatIrqTime; |
| 3404 | mLastStepStatSoftIrqTime = mCurStepStatSoftIrqTime; |
| 3405 | mLastStepStatIdleTime = mCurStepStatIdleTime; |
| 3406 | } |
| 3407 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3408 | public void readHistoryDelta(Parcel src, HistoryItem cur) { |
| 3409 | int firstToken = src.readInt(); |
| 3410 | int deltaTimeToken = firstToken&DELTA_TIME_MASK; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3411 | cur.cmd = HistoryItem.CMD_UPDATE; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3412 | cur.numReadInts = 1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3413 | if (DEBUG) Slog.i(TAG, "READ DELTA: firstToken=0x" + Integer.toHexString(firstToken) |
| 3414 | + " deltaTimeToken=" + deltaTimeToken); |
| 3415 | |
| 3416 | if (deltaTimeToken < DELTA_TIME_ABS) { |
| 3417 | cur.time += deltaTimeToken; |
| 3418 | } else if (deltaTimeToken == DELTA_TIME_ABS) { |
| 3419 | cur.time = src.readLong(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3420 | cur.numReadInts += 2; |
| 3421 | if (DEBUG) Slog.i(TAG, "READ DELTA: ABS time=" + cur.time); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3422 | cur.readFromParcel(src); |
| 3423 | return; |
| 3424 | } else if (deltaTimeToken == DELTA_TIME_INT) { |
| 3425 | int delta = src.readInt(); |
| 3426 | cur.time += delta; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3427 | cur.numReadInts += 1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3428 | if (DEBUG) Slog.i(TAG, "READ DELTA: time delta=" + delta + " new time=" + cur.time); |
| 3429 | } else { |
| 3430 | long delta = src.readLong(); |
| 3431 | if (DEBUG) Slog.i(TAG, "READ DELTA: time delta=" + delta + " new time=" + cur.time); |
| 3432 | cur.time += delta; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3433 | cur.numReadInts += 2; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3434 | } |
| 3435 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 3436 | final int batteryLevelInt; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3437 | if ((firstToken&DELTA_BATTERY_LEVEL_FLAG) != 0) { |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 3438 | batteryLevelInt = src.readInt(); |
Adam Lesinski | 3944c81 | 2015-11-13 15:54:59 -0800 | [diff] [blame] | 3439 | readBatteryLevelInt(batteryLevelInt, cur); |
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: batteryToken=0x" |
| 3442 | + Integer.toHexString(batteryLevelInt) |
| 3443 | + " batteryLevel=" + cur.batteryLevel |
| 3444 | + " batteryTemp=" + cur.batteryTemperature |
| 3445 | + " batteryVolt=" + (int)cur.batteryVoltage); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 3446 | } else { |
| 3447 | batteryLevelInt = 0; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3448 | } |
| 3449 | |
| 3450 | if ((firstToken&DELTA_STATE_FLAG) != 0) { |
| 3451 | int stateInt = src.readInt(); |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 3452 | cur.states = (firstToken&DELTA_STATE_MASK) | (stateInt&(~STATE_BATTERY_MASK)); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 3453 | cur.batteryStatus = (byte)((stateInt>>STATE_BATTERY_STATUS_SHIFT) |
| 3454 | & STATE_BATTERY_STATUS_MASK); |
| 3455 | cur.batteryHealth = (byte)((stateInt>>STATE_BATTERY_HEALTH_SHIFT) |
| 3456 | & STATE_BATTERY_HEALTH_MASK); |
| 3457 | cur.batteryPlugType = (byte)((stateInt>>STATE_BATTERY_PLUG_SHIFT) |
| 3458 | & STATE_BATTERY_PLUG_MASK); |
| 3459 | switch (cur.batteryPlugType) { |
| 3460 | case 1: |
| 3461 | cur.batteryPlugType = BatteryManager.BATTERY_PLUGGED_AC; |
| 3462 | break; |
| 3463 | case 2: |
| 3464 | cur.batteryPlugType = BatteryManager.BATTERY_PLUGGED_USB; |
| 3465 | break; |
| 3466 | case 3: |
| 3467 | cur.batteryPlugType = BatteryManager.BATTERY_PLUGGED_WIRELESS; |
| 3468 | break; |
| 3469 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3470 | cur.numReadInts += 1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3471 | if (DEBUG) Slog.i(TAG, "READ DELTA: stateToken=0x" |
| 3472 | + Integer.toHexString(stateInt) |
| 3473 | + " batteryStatus=" + cur.batteryStatus |
| 3474 | + " batteryHealth=" + cur.batteryHealth |
| 3475 | + " batteryPlugType=" + cur.batteryPlugType |
| 3476 | + " states=0x" + Integer.toHexString(cur.states)); |
| 3477 | } else { |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 3478 | cur.states = (firstToken&DELTA_STATE_MASK) | (cur.states&(~STATE_BATTERY_MASK)); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3479 | } |
| 3480 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3481 | if ((firstToken&DELTA_STATE2_FLAG) != 0) { |
| 3482 | cur.states2 = src.readInt(); |
| 3483 | if (DEBUG) Slog.i(TAG, "READ DELTA: states2=0x" |
| 3484 | + Integer.toHexString(cur.states2)); |
| 3485 | } |
| 3486 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3487 | if ((firstToken&DELTA_WAKELOCK_FLAG) != 0) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3488 | int indexes = src.readInt(); |
| 3489 | int wakeLockIndex = indexes&0xffff; |
| 3490 | int wakeReasonIndex = (indexes>>16)&0xffff; |
| 3491 | if (wakeLockIndex != 0xffff) { |
| 3492 | cur.wakelockTag = cur.localWakelockTag; |
| 3493 | readHistoryTag(wakeLockIndex, cur.wakelockTag); |
| 3494 | if (DEBUG) Slog.i(TAG, "READ DELTA: wakelockTag=#" + cur.wakelockTag.poolIdx |
| 3495 | + " " + cur.wakelockTag.uid + ":" + cur.wakelockTag.string); |
| 3496 | } else { |
| 3497 | cur.wakelockTag = null; |
| 3498 | } |
| 3499 | if (wakeReasonIndex != 0xffff) { |
| 3500 | cur.wakeReasonTag = cur.localWakeReasonTag; |
| 3501 | readHistoryTag(wakeReasonIndex, cur.wakeReasonTag); |
| 3502 | if (DEBUG) Slog.i(TAG, "READ DELTA: wakeReasonTag=#" + cur.wakeReasonTag.poolIdx |
| 3503 | + " " + cur.wakeReasonTag.uid + ":" + cur.wakeReasonTag.string); |
| 3504 | } else { |
| 3505 | cur.wakeReasonTag = null; |
| 3506 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3507 | cur.numReadInts += 1; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3508 | } else { |
| 3509 | cur.wakelockTag = null; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3510 | cur.wakeReasonTag = null; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3511 | } |
| 3512 | |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3513 | if ((firstToken&DELTA_EVENT_FLAG) != 0) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3514 | cur.eventTag = cur.localEventTag; |
| 3515 | final int codeAndIndex = src.readInt(); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3516 | cur.eventCode = (codeAndIndex&0xffff); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3517 | final int index = ((codeAndIndex>>16)&0xffff); |
| 3518 | readHistoryTag(index, cur.eventTag); |
| 3519 | cur.numReadInts += 1; |
| 3520 | if (DEBUG) Slog.i(TAG, "READ DELTA: event=" + cur.eventCode + " tag=#" |
| 3521 | + cur.eventTag.poolIdx + " " + cur.eventTag.uid + ":" |
| 3522 | + cur.eventTag.string); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3523 | } else { |
| 3524 | cur.eventCode = HistoryItem.EVENT_NONE; |
| 3525 | } |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 3526 | |
| 3527 | if ((batteryLevelInt&BATTERY_DELTA_LEVEL_FLAG) != 0) { |
| 3528 | cur.stepDetails = mReadHistoryStepDetails; |
| 3529 | cur.stepDetails.readFromParcel(src); |
| 3530 | } else { |
| 3531 | cur.stepDetails = null; |
| 3532 | } |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 3533 | |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 3534 | if ((firstToken&DELTA_BATTERY_CHARGE_FLAG) != 0) { |
| 3535 | cur.batteryChargeUAh = src.readInt(); |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 3536 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3537 | } |
| 3538 | |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 3539 | @Override |
| 3540 | public void commitCurrentHistoryBatchLocked() { |
| 3541 | mHistoryLastWritten.cmd = HistoryItem.CMD_NULL; |
| 3542 | } |
| 3543 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3544 | void addHistoryBufferLocked(long elapsedRealtimeMs, long uptimeMs, HistoryItem cur) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3545 | if (!mHaveBatteryLevel || !mRecordingHistory) { |
| 3546 | return; |
| 3547 | } |
| 3548 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3549 | final long timeDiff = (mHistoryBaseTime+elapsedRealtimeMs) - mHistoryLastWritten.time; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3550 | final int diffStates = mHistoryLastWritten.states^(cur.states&mActiveHistoryStates); |
| 3551 | final int diffStates2 = mHistoryLastWritten.states2^(cur.states2&mActiveHistoryStates2); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3552 | final int lastDiffStates = mHistoryLastWritten.states^mHistoryLastLastWritten.states; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3553 | final int lastDiffStates2 = mHistoryLastWritten.states2^mHistoryLastLastWritten.states2; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3554 | if (DEBUG) Slog.i(TAG, "ADD: tdelta=" + timeDiff + " diff=" |
| 3555 | + Integer.toHexString(diffStates) + " lastDiff=" |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3556 | + Integer.toHexString(lastDiffStates) + " diff2=" |
| 3557 | + Integer.toHexString(diffStates2) + " lastDiff2=" |
| 3558 | + Integer.toHexString(lastDiffStates2)); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3559 | if (mHistoryBufferLastPos >= 0 && mHistoryLastWritten.cmd == HistoryItem.CMD_UPDATE |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3560 | && timeDiff < 1000 && (diffStates&lastDiffStates) == 0 |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3561 | && (diffStates2&lastDiffStates2) == 0 |
| 3562 | && (mHistoryLastWritten.wakelockTag == null || cur.wakelockTag == null) |
| 3563 | && (mHistoryLastWritten.wakeReasonTag == null || cur.wakeReasonTag == null) |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 3564 | && mHistoryLastWritten.stepDetails == null |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3565 | && (mHistoryLastWritten.eventCode == HistoryItem.EVENT_NONE |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3566 | || cur.eventCode == HistoryItem.EVENT_NONE) |
| 3567 | && mHistoryLastWritten.batteryLevel == cur.batteryLevel |
| 3568 | && mHistoryLastWritten.batteryStatus == cur.batteryStatus |
| 3569 | && mHistoryLastWritten.batteryHealth == cur.batteryHealth |
| 3570 | && mHistoryLastWritten.batteryPlugType == cur.batteryPlugType |
| 3571 | && mHistoryLastWritten.batteryTemperature == cur.batteryTemperature |
| 3572 | && mHistoryLastWritten.batteryVoltage == cur.batteryVoltage) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3573 | // 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] | 3574 | // 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] | 3575 | // as long as no bit has changed both between now and the last entry, as |
| 3576 | // well as the last entry and the one before it (so we capture any toggles). |
| 3577 | if (DEBUG) Slog.i(TAG, "ADD: rewinding back to " + mHistoryBufferLastPos); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3578 | mHistoryBuffer.setDataSize(mHistoryBufferLastPos); |
| 3579 | mHistoryBuffer.setDataPosition(mHistoryBufferLastPos); |
| 3580 | mHistoryBufferLastPos = -1; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3581 | elapsedRealtimeMs = mHistoryLastWritten.time - mHistoryBaseTime; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3582 | // If the last written history had a wakelock tag, we need to retain it. |
| 3583 | // Note that the condition above made sure that we aren't in a case where |
| 3584 | // both it and the current history item have a wakelock tag. |
| 3585 | if (mHistoryLastWritten.wakelockTag != null) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3586 | cur.wakelockTag = cur.localWakelockTag; |
| 3587 | cur.wakelockTag.setTo(mHistoryLastWritten.wakelockTag); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3588 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3589 | // If the last written history had a wake reason tag, we need to retain it. |
| 3590 | // Note that the condition above made sure that we aren't in a case where |
| 3591 | // both it and the current history item have a wakelock tag. |
| 3592 | if (mHistoryLastWritten.wakeReasonTag != null) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3593 | cur.wakeReasonTag = cur.localWakeReasonTag; |
| 3594 | cur.wakeReasonTag.setTo(mHistoryLastWritten.wakeReasonTag); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3595 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3596 | // If the last written history had an event, we need to retain it. |
| 3597 | // Note that the condition above made sure that we aren't in a case where |
| 3598 | // both it and the current history item have an event. |
| 3599 | if (mHistoryLastWritten.eventCode != HistoryItem.EVENT_NONE) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3600 | cur.eventCode = mHistoryLastWritten.eventCode; |
| 3601 | cur.eventTag = cur.localEventTag; |
| 3602 | cur.eventTag.setTo(mHistoryLastWritten.eventTag); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3603 | } |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 3604 | mHistoryLastWritten.setTo(mHistoryLastLastWritten); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3605 | } |
| 3606 | |
Adam Lesinski | 4548978 | 2016-12-15 23:45:17 -0800 | [diff] [blame] | 3607 | boolean recordResetDueToOverflow = false; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3608 | final int dataSize = mHistoryBuffer.dataSize(); |
Adam Lesinski | 4548978 | 2016-12-15 23:45:17 -0800 | [diff] [blame] | 3609 | if (dataSize >= MAX_MAX_HISTORY_BUFFER*3) { |
| 3610 | // Clients can't deal with history buffers this large. This only |
| 3611 | // really happens when the device is on charger and interacted with |
| 3612 | // for long periods of time, like in retail mode. Since the device is |
| 3613 | // most likely charged, when unplugged, stats would have reset anyways. |
| 3614 | // Reset the stats and mark that we overflowed. |
| 3615 | // b/32540341 |
| 3616 | resetAllStatsLocked(); |
| 3617 | |
| 3618 | // Mark that we want to set *OVERFLOW* event and the RESET:START |
| 3619 | // events. |
| 3620 | recordResetDueToOverflow = true; |
| 3621 | |
| 3622 | } else if (dataSize >= MAX_HISTORY_BUFFER) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3623 | if (!mHistoryOverflow) { |
| 3624 | mHistoryOverflow = true; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3625 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_UPDATE, cur); |
| 3626 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_OVERFLOW, cur); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3627 | return; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3628 | } |
| 3629 | |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3630 | // After overflow, we allow various bit-wise states to settle to 0. |
| 3631 | boolean writeAnyway = false; |
| 3632 | final int curStates = cur.states & HistoryItem.SETTLE_TO_ZERO_STATES |
| 3633 | & mActiveHistoryStates; |
| 3634 | if (mHistoryLastWritten.states != curStates) { |
| 3635 | // mActiveHistoryStates keeps track of which bits in .states are now being |
| 3636 | // forced to 0. |
| 3637 | int old = mActiveHistoryStates; |
| 3638 | mActiveHistoryStates &= curStates | ~HistoryItem.SETTLE_TO_ZERO_STATES; |
| 3639 | writeAnyway |= old != mActiveHistoryStates; |
| 3640 | } |
| 3641 | final int curStates2 = cur.states2 & HistoryItem.SETTLE_TO_ZERO_STATES2 |
| 3642 | & mActiveHistoryStates2; |
| 3643 | if (mHistoryLastWritten.states2 != curStates2) { |
| 3644 | // mActiveHistoryStates2 keeps track of which bits in .states2 are now being |
| 3645 | // forced to 0. |
| 3646 | int old = mActiveHistoryStates2; |
| 3647 | mActiveHistoryStates2 &= curStates2 | ~HistoryItem.SETTLE_TO_ZERO_STATES2; |
| 3648 | writeAnyway |= old != mActiveHistoryStates2; |
| 3649 | } |
| 3650 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3651 | // Once we've reached the maximum number of items, we only |
| 3652 | // record changes to the battery level and the most interesting states. |
| 3653 | // Once we've reached the maximum maximum number of items, we only |
| 3654 | // record changes to the battery level. |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3655 | if (!writeAnyway && mHistoryLastWritten.batteryLevel == cur.batteryLevel && |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3656 | (dataSize >= MAX_MAX_HISTORY_BUFFER |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3657 | || ((mHistoryLastWritten.states^cur.states) |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3658 | & HistoryItem.MOST_INTERESTING_STATES) == 0 |
| 3659 | || ((mHistoryLastWritten.states2^cur.states2) |
| 3660 | & HistoryItem.MOST_INTERESTING_STATES2) == 0)) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3661 | return; |
| 3662 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3663 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3664 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_UPDATE, cur); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3665 | return; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3666 | } |
| 3667 | |
Adam Lesinski | 4548978 | 2016-12-15 23:45:17 -0800 | [diff] [blame] | 3668 | if (dataSize == 0 || recordResetDueToOverflow) { |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 3669 | // The history is currently empty; we need it to start with a time stamp. |
| 3670 | cur.currentTime = System.currentTimeMillis(); |
Adam Lesinski | 4548978 | 2016-12-15 23:45:17 -0800 | [diff] [blame] | 3671 | if (recordResetDueToOverflow) { |
| 3672 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_OVERFLOW, cur); |
| 3673 | } |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 3674 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_RESET, cur); |
| 3675 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3676 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_UPDATE, cur); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3677 | } |
| 3678 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3679 | private void addHistoryBufferLocked(long elapsedRealtimeMs, long uptimeMs, byte cmd, |
| 3680 | HistoryItem cur) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3681 | if (mIteratingHistory) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3682 | throw new IllegalStateException("Can't do this while iterating history!"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3683 | } |
| 3684 | mHistoryBufferLastPos = mHistoryBuffer.dataPosition(); |
| 3685 | mHistoryLastLastWritten.setTo(mHistoryLastWritten); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3686 | mHistoryLastWritten.setTo(mHistoryBaseTime + elapsedRealtimeMs, cmd, cur); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3687 | mHistoryLastWritten.states &= mActiveHistoryStates; |
| 3688 | mHistoryLastWritten.states2 &= mActiveHistoryStates2; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3689 | writeHistoryDelta(mHistoryBuffer, mHistoryLastWritten, mHistoryLastLastWritten); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3690 | mLastHistoryElapsedRealtime = elapsedRealtimeMs; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3691 | cur.wakelockTag = null; |
| 3692 | cur.wakeReasonTag = null; |
| 3693 | cur.eventCode = HistoryItem.EVENT_NONE; |
| 3694 | cur.eventTag = null; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3695 | if (DEBUG_HISTORY) Slog.i(TAG, "Writing history buffer: was " + mHistoryBufferLastPos |
| 3696 | + " now " + mHistoryBuffer.dataPosition() |
| 3697 | + " size is now " + mHistoryBuffer.dataSize()); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3698 | } |
| 3699 | |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 3700 | int mChangedStates = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3701 | int mChangedStates2 = 0; |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 3702 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3703 | void addHistoryRecordLocked(long elapsedRealtimeMs, long uptimeMs) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3704 | if (mTrackRunningHistoryElapsedRealtime != 0) { |
| 3705 | final long diffElapsed = elapsedRealtimeMs - mTrackRunningHistoryElapsedRealtime; |
| 3706 | final long diffUptime = uptimeMs - mTrackRunningHistoryUptime; |
| 3707 | if (diffUptime < (diffElapsed-20)) { |
| 3708 | final long wakeElapsedTime = elapsedRealtimeMs - (diffElapsed - diffUptime); |
| 3709 | mHistoryAddTmp.setTo(mHistoryLastWritten); |
| 3710 | mHistoryAddTmp.wakelockTag = null; |
| 3711 | mHistoryAddTmp.wakeReasonTag = null; |
| 3712 | mHistoryAddTmp.eventCode = HistoryItem.EVENT_NONE; |
| 3713 | mHistoryAddTmp.states &= ~HistoryItem.STATE_CPU_RUNNING_FLAG; |
| 3714 | addHistoryRecordInnerLocked(wakeElapsedTime, uptimeMs, mHistoryAddTmp); |
| 3715 | } |
| 3716 | } |
| 3717 | mHistoryCur.states |= HistoryItem.STATE_CPU_RUNNING_FLAG; |
| 3718 | mTrackRunningHistoryElapsedRealtime = elapsedRealtimeMs; |
| 3719 | mTrackRunningHistoryUptime = uptimeMs; |
| 3720 | addHistoryRecordInnerLocked(elapsedRealtimeMs, uptimeMs, mHistoryCur); |
| 3721 | } |
| 3722 | |
| 3723 | void addHistoryRecordInnerLocked(long elapsedRealtimeMs, long uptimeMs, HistoryItem cur) { |
| 3724 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, cur); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3725 | |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 3726 | if (!USE_OLD_HISTORY) { |
| 3727 | return; |
| 3728 | } |
| 3729 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3730 | if (!mHaveBatteryLevel || !mRecordingHistory) { |
| 3731 | return; |
| 3732 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3733 | |
| 3734 | // If the current time is basically the same as the last time, |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 3735 | // and no states have since the last recorded entry changed and |
| 3736 | // are now resetting back to their original value, then just collapse |
| 3737 | // into one record. |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3738 | if (mHistoryEnd != null && mHistoryEnd.cmd == HistoryItem.CMD_UPDATE |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3739 | && (mHistoryBaseTime+elapsedRealtimeMs) < (mHistoryEnd.time+1000) |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3740 | && ((mHistoryEnd.states^cur.states)&mChangedStates&mActiveHistoryStates) == 0 |
| 3741 | && ((mHistoryEnd.states2^cur.states2)&mChangedStates2&mActiveHistoryStates2) == 0) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3742 | // If the current is the same as the one before, then we no |
| 3743 | // longer need the entry. |
| 3744 | if (mHistoryLastEnd != null && mHistoryLastEnd.cmd == HistoryItem.CMD_UPDATE |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3745 | && (mHistoryBaseTime+elapsedRealtimeMs) < (mHistoryEnd.time+500) |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3746 | && mHistoryLastEnd.sameNonEvent(cur)) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3747 | mHistoryLastEnd.next = null; |
| 3748 | mHistoryEnd.next = mHistoryCache; |
| 3749 | mHistoryCache = mHistoryEnd; |
| 3750 | mHistoryEnd = mHistoryLastEnd; |
| 3751 | mHistoryLastEnd = null; |
| 3752 | } else { |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3753 | mChangedStates |= mHistoryEnd.states^(cur.states&mActiveHistoryStates); |
| 3754 | mChangedStates2 |= mHistoryEnd.states^(cur.states2&mActiveHistoryStates2); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3755 | mHistoryEnd.setTo(mHistoryEnd.time, HistoryItem.CMD_UPDATE, cur); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3756 | } |
| 3757 | return; |
| 3758 | } |
| 3759 | |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 3760 | mChangedStates = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3761 | mChangedStates2 = 0; |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 3762 | |
| 3763 | if (mNumHistoryItems == MAX_HISTORY_ITEMS |
| 3764 | || mNumHistoryItems == MAX_MAX_HISTORY_ITEMS) { |
Narayan Kamath | 4215157 | 2018-02-05 15:29:04 +0000 | [diff] [blame] | 3765 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_OVERFLOW, cur); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 3766 | } |
| 3767 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3768 | if (mNumHistoryItems >= MAX_HISTORY_ITEMS) { |
| 3769 | // Once we've reached the maximum number of items, we only |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 3770 | // record changes to the battery level and the most interesting states. |
| 3771 | // Once we've reached the maximum maximum number of items, we only |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3772 | // record changes to the battery level. |
| 3773 | if (mHistoryEnd != null && mHistoryEnd.batteryLevel |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3774 | == cur.batteryLevel && |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 3775 | (mNumHistoryItems >= MAX_MAX_HISTORY_ITEMS |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3776 | || ((mHistoryEnd.states^(cur.states&mActiveHistoryStates)) |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 3777 | & HistoryItem.MOST_INTERESTING_STATES) == 0)) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3778 | return; |
| 3779 | } |
| 3780 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3781 | |
Narayan Kamath | 4215157 | 2018-02-05 15:29:04 +0000 | [diff] [blame] | 3782 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_UPDATE, cur); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3783 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3784 | |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3785 | public void addHistoryEventLocked(long elapsedRealtimeMs, long uptimeMs, int code, |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3786 | String name, int uid) { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3787 | mHistoryCur.eventCode = code; |
| 3788 | mHistoryCur.eventTag = mHistoryCur.localEventTag; |
| 3789 | mHistoryCur.eventTag.string = name; |
| 3790 | mHistoryCur.eventTag.uid = uid; |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 3791 | addHistoryRecordLocked(elapsedRealtimeMs, uptimeMs); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3792 | } |
| 3793 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3794 | void addHistoryRecordLocked(long elapsedRealtimeMs, long uptimeMs, byte cmd, HistoryItem cur) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3795 | HistoryItem rec = mHistoryCache; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3796 | if (rec != null) { |
| 3797 | mHistoryCache = rec.next; |
| 3798 | } else { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3799 | rec = new HistoryItem(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3800 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3801 | rec.setTo(mHistoryBaseTime + elapsedRealtimeMs, cmd, cur); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3802 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3803 | addHistoryRecordLocked(rec); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3804 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3805 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3806 | void addHistoryRecordLocked(HistoryItem rec) { |
| 3807 | mNumHistoryItems++; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3808 | rec.next = null; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3809 | mHistoryLastEnd = mHistoryEnd; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3810 | if (mHistoryEnd != null) { |
| 3811 | mHistoryEnd.next = rec; |
| 3812 | mHistoryEnd = rec; |
| 3813 | } else { |
| 3814 | mHistory = mHistoryEnd = rec; |
| 3815 | } |
| 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 clearHistoryLocked() { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3819 | if (DEBUG_HISTORY) Slog.i(TAG, "********** CLEARING HISTORY!"); |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 3820 | if (USE_OLD_HISTORY) { |
| 3821 | if (mHistory != null) { |
| 3822 | mHistoryEnd.next = mHistoryCache; |
| 3823 | mHistoryCache = mHistory; |
| 3824 | mHistory = mHistoryLastEnd = mHistoryEnd = null; |
| 3825 | } |
| 3826 | mNumHistoryItems = 0; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3827 | } |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 3828 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3829 | mHistoryBaseTime = 0; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3830 | mLastHistoryElapsedRealtime = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3831 | mTrackRunningHistoryElapsedRealtime = 0; |
| 3832 | mTrackRunningHistoryUptime = 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3833 | |
| 3834 | mHistoryBuffer.setDataSize(0); |
| 3835 | mHistoryBuffer.setDataPosition(0); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3836 | mHistoryBuffer.setDataCapacity(MAX_HISTORY_BUFFER / 2); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3837 | mHistoryLastLastWritten.clear(); |
| 3838 | mHistoryLastWritten.clear(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3839 | mHistoryTagPool.clear(); |
| 3840 | mNextHistoryTagIdx = 0; |
| 3841 | mNumHistoryTagChars = 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3842 | mHistoryBufferLastPos = -1; |
| 3843 | mHistoryOverflow = false; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3844 | mActiveHistoryStates = 0xffffffff; |
| 3845 | mActiveHistoryStates2 = 0xffffffff; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3846 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3847 | |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 3848 | public void updateTimeBasesLocked(boolean unplugged, int screenState, long uptime, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3849 | long realtime) { |
Mike Ma | a772475 | 2017-10-10 15:29:25 -0700 | [diff] [blame] | 3850 | final boolean screenOff = !isScreenOn(screenState); |
Sudheer Shanka | 9d4ed7c | 2017-07-08 22:10:45 -0700 | [diff] [blame] | 3851 | final boolean updateOnBatteryTimeBase = unplugged != mOnBatteryTimeBase.isRunning(); |
| 3852 | final boolean updateOnBatteryScreenOffTimeBase = |
| 3853 | (unplugged && screenOff) != mOnBatteryScreenOffTimeBase.isRunning(); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3854 | |
Sudheer Shanka | 9d4ed7c | 2017-07-08 22:10:45 -0700 | [diff] [blame] | 3855 | if (updateOnBatteryScreenOffTimeBase || updateOnBatteryTimeBase) { |
| 3856 | if (updateOnBatteryScreenOffTimeBase) { |
| 3857 | updateKernelWakelocksLocked(); |
| 3858 | updateBatteryPropertiesLocked(); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3859 | } |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 3860 | // This if{} is only necessary due to SCREEN_OFF_RPM_STATS_ENABLED, which exists because |
| 3861 | // updateRpmStatsLocked is too slow to run each screen change. When the speed is |
| 3862 | // improved, remove the surrounding if{}. |
| 3863 | if (SCREEN_OFF_RPM_STATS_ENABLED || updateOnBatteryTimeBase) { |
| 3864 | updateRpmStatsLocked(); // if either OnBattery or OnBatteryScreenOff timebase changes. |
| 3865 | } |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 3866 | if (DEBUG_ENERGY_CPU) { |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 3867 | Slog.d(TAG, "Updating cpu time because screen is now " |
| 3868 | + Display.stateToString(screenState) |
Sudheer Shanka | 9d4ed7c | 2017-07-08 22:10:45 -0700 | [diff] [blame] | 3869 | + " and battery is " + (unplugged ? "on" : "off")); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3870 | } |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 3871 | updateCpuTimeLocked(); |
Sudheer Shanka | e544d16 | 2017-12-28 17:06:20 -0800 | [diff] [blame] | 3872 | mExternalSync.scheduleCopyFromAllUidsCpuTimes(mOnBatteryTimeBase.isRunning(), |
| 3873 | mOnBatteryScreenOffTimeBase.isRunning()); |
Sudheer Shanka | 9d4ed7c | 2017-07-08 22:10:45 -0700 | [diff] [blame] | 3874 | |
| 3875 | mOnBatteryTimeBase.setRunning(unplugged, uptime, realtime); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 3876 | if (updateOnBatteryTimeBase) { |
| 3877 | for (int i = mUidStats.size() - 1; i >= 0; --i) { |
| 3878 | mUidStats.valueAt(i).updateOnBatteryBgTimeBase(uptime, realtime); |
Sudheer Shanka | 9d4ed7c | 2017-07-08 22:10:45 -0700 | [diff] [blame] | 3879 | } |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 3880 | } |
| 3881 | if (updateOnBatteryScreenOffTimeBase) { |
| 3882 | mOnBatteryScreenOffTimeBase.setRunning(unplugged && screenOff, uptime, realtime); |
| 3883 | for (int i = mUidStats.size() - 1; i >= 0; --i) { |
| 3884 | mUidStats.valueAt(i).updateOnBatteryScreenOffBgTimeBase(uptime, realtime); |
Sudheer Shanka | 9d4ed7c | 2017-07-08 22:10:45 -0700 | [diff] [blame] | 3885 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3886 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3887 | } |
| 3888 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 3889 | |
Adam Lesinski | e1f480d | 2017-02-15 18:51:23 -0800 | [diff] [blame] | 3890 | private void updateBatteryPropertiesLocked() { |
| 3891 | try { |
| 3892 | IBatteryPropertiesRegistrar registrar = IBatteryPropertiesRegistrar.Stub.asInterface( |
| 3893 | ServiceManager.getService("batteryproperties")); |
| 3894 | registrar.scheduleUpdate(); |
| 3895 | } catch (RemoteException e) { |
| 3896 | // Ignore. |
| 3897 | } |
| 3898 | } |
| 3899 | |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3900 | public void addIsolatedUidLocked(int isolatedUid, int appUid) { |
| 3901 | mIsolatedUids.put(isolatedUid, appUid); |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 3902 | StatsLog.write(StatsLog.ISOLATED_UID_CHANGED, appUid, isolatedUid, |
| 3903 | StatsLog.ISOLATED_UID_CHANGED__EVENT__CREATED); |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 3904 | final Uid u = getUidStatsLocked(appUid); |
| 3905 | u.addIsolatedUid(isolatedUid); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3906 | } |
| 3907 | |
Adam Lesinski | 61db88f | 2015-07-01 15:05:07 -0700 | [diff] [blame] | 3908 | /** |
| 3909 | * Schedules a read of the latest cpu times before removing the isolated UID. |
| 3910 | * @see #removeIsolatedUidLocked(int) |
| 3911 | */ |
| 3912 | public void scheduleRemoveIsolatedUidLocked(int isolatedUid, int appUid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3913 | int curUid = mIsolatedUids.get(isolatedUid, -1); |
| 3914 | if (curUid == appUid) { |
Adam Lesinski | 61db88f | 2015-07-01 15:05:07 -0700 | [diff] [blame] | 3915 | if (mExternalSync != null) { |
| 3916 | mExternalSync.scheduleCpuSyncDueToRemovedUid(isolatedUid); |
| 3917 | } |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3918 | } |
| 3919 | } |
| 3920 | |
Adam Lesinski | 61db88f | 2015-07-01 15:05:07 -0700 | [diff] [blame] | 3921 | /** |
| 3922 | * This should only be called after the cpu times have been read. |
| 3923 | * @see #scheduleRemoveIsolatedUidLocked(int, int) |
| 3924 | */ |
| 3925 | public void removeIsolatedUidLocked(int isolatedUid) { |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 3926 | StatsLog.write( |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 3927 | StatsLog.ISOLATED_UID_CHANGED, mIsolatedUids.get(isolatedUid, -1), |
| 3928 | isolatedUid, StatsLog.ISOLATED_UID_CHANGED__EVENT__REMOVED); |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 3929 | final int idx = mIsolatedUids.indexOfKey(isolatedUid); |
| 3930 | if (idx >= 0) { |
| 3931 | final int ownerUid = mIsolatedUids.valueAt(idx); |
| 3932 | final Uid u = getUidStatsLocked(ownerUid); |
| 3933 | u.removeIsolatedUid(isolatedUid); |
| 3934 | mIsolatedUids.removeAt(idx); |
| 3935 | } |
| 3936 | mKernelUidCpuTimeReader.removeUid(isolatedUid); |
| 3937 | mKernelUidCpuFreqTimeReader.removeUid(isolatedUid); |
Mike Ma | fae87da | 2018-01-19 20:07:20 -0800 | [diff] [blame] | 3938 | if (mConstants.TRACK_CPU_ACTIVE_CLUSTER_TIME) { |
| 3939 | mKernelUidCpuActiveTimeReader.removeUid(isolatedUid); |
| 3940 | mKernelUidCpuClusterTimeReader.removeUid(isolatedUid); |
| 3941 | } |
Adam Lesinski | 61db88f | 2015-07-01 15:05:07 -0700 | [diff] [blame] | 3942 | } |
| 3943 | |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3944 | public int mapUid(int uid) { |
| 3945 | int isolated = mIsolatedUids.get(uid, -1); |
| 3946 | return isolated > 0 ? isolated : uid; |
| 3947 | } |
| 3948 | |
| 3949 | public void noteEventLocked(int code, String name, int uid) { |
| 3950 | uid = mapUid(uid); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 3951 | if (!mActiveEvents.updateState(code, name, uid, 0)) { |
| 3952 | return; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 3953 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3954 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3955 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3956 | addHistoryEventLocked(elapsedRealtime, uptime, code, name, uid); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3957 | } |
| 3958 | |
Dianne Hackborn | d48954f | 2015-07-22 17:20:33 -0700 | [diff] [blame] | 3959 | boolean ensureStartClockTime(final long currentTime) { |
| 3960 | final long ABOUT_ONE_YEAR = 365*24*60*60*1000L; |
| 3961 | if (currentTime > ABOUT_ONE_YEAR && mStartClockTime < (currentTime-ABOUT_ONE_YEAR)) { |
| 3962 | // If the start clock time has changed by more than a year, then presumably |
| 3963 | // the previous time was completely bogus. So we are going to figure out a |
| 3964 | // 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] | 3965 | mStartClockTime = currentTime - (mClocks.elapsedRealtime()-(mRealtimeStart/1000)); |
Dianne Hackborn | d48954f | 2015-07-22 17:20:33 -0700 | [diff] [blame] | 3966 | return true; |
| 3967 | } |
| 3968 | return false; |
| 3969 | } |
| 3970 | |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 3971 | public void noteCurrentTimeChangedLocked() { |
| 3972 | final long currentTime = System.currentTimeMillis(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3973 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3974 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 3975 | recordCurrentTimeChangeLocked(currentTime, elapsedRealtime, uptime); |
Dianne Hackborn | d48954f | 2015-07-22 17:20:33 -0700 | [diff] [blame] | 3976 | ensureStartClockTime(currentTime); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 3977 | } |
| 3978 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3979 | public void noteProcessStartLocked(String name, int uid) { |
| 3980 | uid = mapUid(uid); |
| 3981 | if (isOnBattery()) { |
| 3982 | Uid u = getUidStatsLocked(uid); |
| 3983 | u.getProcessStatsLocked(name).incStartsLocked(); |
| 3984 | } |
| 3985 | if (!mActiveEvents.updateState(HistoryItem.EVENT_PROC_START, name, uid, 0)) { |
| 3986 | return; |
| 3987 | } |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3988 | if (!mRecordAllHistory) { |
| 3989 | return; |
| 3990 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3991 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3992 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3993 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_PROC_START, name, uid); |
| 3994 | } |
| 3995 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 3996 | public void noteProcessCrashLocked(String name, int uid) { |
| 3997 | uid = mapUid(uid); |
| 3998 | if (isOnBattery()) { |
| 3999 | Uid u = getUidStatsLocked(uid); |
| 4000 | u.getProcessStatsLocked(name).incNumCrashesLocked(); |
| 4001 | } |
| 4002 | } |
| 4003 | |
| 4004 | public void noteProcessAnrLocked(String name, int uid) { |
| 4005 | uid = mapUid(uid); |
| 4006 | if (isOnBattery()) { |
| 4007 | Uid u = getUidStatsLocked(uid); |
| 4008 | u.getProcessStatsLocked(name).incNumAnrsLocked(); |
| 4009 | } |
| 4010 | } |
| 4011 | |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 4012 | public void noteUidProcessStateLocked(int uid, int state) { |
Amith Yamasani | fd3caf6 | 2017-07-26 11:48:35 -0700 | [diff] [blame] | 4013 | int parentUid = mapUid(uid); |
| 4014 | if (uid != parentUid) { |
| 4015 | // Isolated UIDs process state is already rolled up into parent, so no need to track |
| 4016 | // Otherwise the parent's process state will get downgraded incorrectly |
| 4017 | return; |
| 4018 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 4019 | getUidStatsLocked(uid).updateUidProcessStateLocked(state); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4020 | } |
| 4021 | |
| 4022 | public void noteProcessFinishLocked(String name, int uid) { |
| 4023 | uid = mapUid(uid); |
| 4024 | if (!mActiveEvents.updateState(HistoryItem.EVENT_PROC_FINISH, name, uid, 0)) { |
| 4025 | return; |
| 4026 | } |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 4027 | if (!mRecordAllHistory) { |
| 4028 | return; |
| 4029 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4030 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4031 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 4032 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_PROC_FINISH, name, uid); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4033 | } |
| 4034 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4035 | public void noteSyncStartLocked(String name, int uid) { |
| 4036 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4037 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4038 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4039 | getUidStatsLocked(uid).noteStartSyncLocked(name, elapsedRealtime); |
| 4040 | if (!mActiveEvents.updateState(HistoryItem.EVENT_SYNC_START, name, uid, 0)) { |
| 4041 | return; |
| 4042 | } |
| 4043 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_SYNC_START, name, uid); |
| 4044 | } |
| 4045 | |
| 4046 | public void noteSyncFinishLocked(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).noteStopSyncLocked(name, elapsedRealtime); |
| 4051 | if (!mActiveEvents.updateState(HistoryItem.EVENT_SYNC_FINISH, name, uid, 0)) { |
| 4052 | return; |
| 4053 | } |
| 4054 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_SYNC_FINISH, name, uid); |
| 4055 | } |
| 4056 | |
| 4057 | public void noteJobStartLocked(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).noteStartJobLocked(name, elapsedRealtime); |
| 4062 | if (!mActiveEvents.updateState(HistoryItem.EVENT_JOB_START, name, uid, 0)) { |
| 4063 | return; |
| 4064 | } |
| 4065 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_JOB_START, name, uid); |
| 4066 | } |
| 4067 | |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 4068 | public void noteJobFinishLocked(String name, int uid, int stopReason) { |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 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 | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 4072 | getUidStatsLocked(uid).noteStopJobLocked(name, elapsedRealtime, stopReason); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4073 | if (!mActiveEvents.updateState(HistoryItem.EVENT_JOB_FINISH, name, uid, 0)) { |
| 4074 | return; |
| 4075 | } |
| 4076 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_JOB_FINISH, name, uid); |
| 4077 | } |
| 4078 | |
Narayan Kamath | 695cf72 | 2017-12-21 18:32:47 +0000 | [diff] [blame] | 4079 | public void noteAlarmStartLocked(String name, WorkSource workSource, int uid) { |
| 4080 | noteAlarmStartOrFinishLocked(HistoryItem.EVENT_ALARM_START, name, workSource, uid); |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 4081 | } |
| 4082 | |
Narayan Kamath | 695cf72 | 2017-12-21 18:32:47 +0000 | [diff] [blame] | 4083 | public void noteAlarmFinishLocked(String name, WorkSource workSource, int uid) { |
| 4084 | noteAlarmStartOrFinishLocked(HistoryItem.EVENT_ALARM_FINISH, name, workSource, uid); |
| 4085 | } |
| 4086 | |
| 4087 | private void noteAlarmStartOrFinishLocked(int historyItem, String name, WorkSource workSource, |
| 4088 | int uid) { |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 4089 | if (!mRecordAllHistory) { |
| 4090 | return; |
| 4091 | } |
Narayan Kamath | 695cf72 | 2017-12-21 18:32:47 +0000 | [diff] [blame] | 4092 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4093 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4094 | final long uptime = mClocks.uptimeMillis(); |
Narayan Kamath | 695cf72 | 2017-12-21 18:32:47 +0000 | [diff] [blame] | 4095 | |
| 4096 | if (workSource != null) { |
| 4097 | for (int i = 0; i < workSource.size(); ++i) { |
| 4098 | uid = mapUid(workSource.get(i)); |
| 4099 | if (mActiveEvents.updateState(historyItem, name, uid, 0)) { |
| 4100 | addHistoryEventLocked(elapsedRealtime, uptime, historyItem, name, uid); |
| 4101 | } |
| 4102 | } |
| 4103 | |
| 4104 | List<WorkChain> workChains = workSource.getWorkChains(); |
| 4105 | if (workChains != null) { |
| 4106 | for (int i = 0; i < workChains.size(); ++i) { |
| 4107 | uid = mapUid(workChains.get(i).getAttributionUid()); |
| 4108 | if (mActiveEvents.updateState(historyItem, name, uid, 0)) { |
| 4109 | addHistoryEventLocked(elapsedRealtime, uptime, historyItem, name, uid); |
| 4110 | } |
| 4111 | } |
| 4112 | } |
| 4113 | } else { |
| 4114 | uid = mapUid(uid); |
| 4115 | |
| 4116 | if (mActiveEvents.updateState(historyItem, name, uid, 0)) { |
| 4117 | addHistoryEventLocked(elapsedRealtime, uptime, historyItem, name, uid); |
| 4118 | } |
| 4119 | } |
| 4120 | } |
| 4121 | |
| 4122 | public void noteWakupAlarmLocked(String packageName, int uid, WorkSource workSource, |
| 4123 | String tag) { |
Narayan Kamath | 695cf72 | 2017-12-21 18:32:47 +0000 | [diff] [blame] | 4124 | if (workSource != null) { |
| 4125 | for (int i = 0; i < workSource.size(); ++i) { |
| 4126 | uid = workSource.get(i); |
| 4127 | final String workSourceName = workSource.getName(i); |
| 4128 | |
Tej Singh | 6f724c4 | 2018-01-03 20:02:03 -0800 | [diff] [blame] | 4129 | if (isOnBattery()) { |
| 4130 | BatteryStatsImpl.Uid.Pkg pkg = getPackageStatsLocked(uid, |
| 4131 | workSourceName != null ? workSourceName : packageName); |
| 4132 | pkg.noteWakeupAlarmLocked(tag); |
| 4133 | } |
Yangster-mac | 2f5daec | 2018-01-16 10:23:15 -0800 | [diff] [blame] | 4134 | StatsLog.write_non_chained(StatsLog.WAKEUP_ALARM_OCCURRED, workSource.get(i), |
| 4135 | workSource.getName(i), tag); |
Narayan Kamath | 695cf72 | 2017-12-21 18:32:47 +0000 | [diff] [blame] | 4136 | } |
| 4137 | |
| 4138 | ArrayList<WorkChain> workChains = workSource.getWorkChains(); |
| 4139 | if (workChains != null) { |
| 4140 | for (int i = 0; i < workChains.size(); ++i) { |
| 4141 | final WorkChain wc = workChains.get(i); |
| 4142 | uid = wc.getAttributionUid(); |
| 4143 | |
Tej Singh | 6f724c4 | 2018-01-03 20:02:03 -0800 | [diff] [blame] | 4144 | if (isOnBattery()) { |
| 4145 | BatteryStatsImpl.Uid.Pkg pkg = getPackageStatsLocked(uid, packageName); |
| 4146 | pkg.noteWakeupAlarmLocked(tag); |
| 4147 | } |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 4148 | StatsLog.write(StatsLog.WAKEUP_ALARM_OCCURRED, wc.getUids(), wc.getTags(), tag); |
Narayan Kamath | 695cf72 | 2017-12-21 18:32:47 +0000 | [diff] [blame] | 4149 | } |
| 4150 | } |
| 4151 | } else { |
Tej Singh | 6f724c4 | 2018-01-03 20:02:03 -0800 | [diff] [blame] | 4152 | if (isOnBattery()) { |
| 4153 | BatteryStatsImpl.Uid.Pkg pkg = getPackageStatsLocked(uid, packageName); |
| 4154 | pkg.noteWakeupAlarmLocked(tag); |
| 4155 | } |
Yangster-mac | 2f5daec | 2018-01-16 10:23:15 -0800 | [diff] [blame] | 4156 | StatsLog.write_non_chained(StatsLog.WAKEUP_ALARM_OCCURRED, uid, null, tag); |
Narayan Kamath | 695cf72 | 2017-12-21 18:32:47 +0000 | [diff] [blame] | 4157 | } |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 4158 | } |
| 4159 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4160 | private void requestWakelockCpuUpdate() { |
| 4161 | if (!mHandler.hasMessages(MSG_UPDATE_WAKELOCKS)) { |
| 4162 | Message m = mHandler.obtainMessage(MSG_UPDATE_WAKELOCKS); |
| 4163 | mHandler.sendMessageDelayed(m, DELAY_UPDATE_WAKELOCKS); |
| 4164 | } |
| 4165 | } |
| 4166 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 4167 | private void requestImmediateCpuUpdate() { |
| 4168 | mHandler.removeMessages(MSG_UPDATE_WAKELOCKS); |
| 4169 | mHandler.sendEmptyMessage(MSG_UPDATE_WAKELOCKS); |
| 4170 | } |
| 4171 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 4172 | public void setRecordAllHistoryLocked(boolean enabled) { |
| 4173 | mRecordAllHistory = enabled; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4174 | if (!enabled) { |
| 4175 | // Clear out any existing state. |
| 4176 | mActiveEvents.removeEvents(HistoryItem.EVENT_WAKE_LOCK); |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 4177 | mActiveEvents.removeEvents(HistoryItem.EVENT_ALARM); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 4178 | // Record the currently running processes as stopping, now that we are no |
| 4179 | // longer tracking them. |
| 4180 | HashMap<String, SparseIntArray> active = mActiveEvents.getStateForEvent( |
| 4181 | HistoryItem.EVENT_PROC); |
| 4182 | if (active != null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4183 | long mSecRealtime = mClocks.elapsedRealtime(); |
| 4184 | final long mSecUptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 4185 | for (HashMap.Entry<String, SparseIntArray> ent : active.entrySet()) { |
| 4186 | SparseIntArray uids = ent.getValue(); |
| 4187 | for (int j=0; j<uids.size(); j++) { |
| 4188 | addHistoryEventLocked(mSecRealtime, mSecUptime, |
| 4189 | HistoryItem.EVENT_PROC_FINISH, ent.getKey(), uids.keyAt(j)); |
| 4190 | } |
| 4191 | } |
| 4192 | } |
| 4193 | } else { |
| 4194 | // Record the currently running processes as starting, now that we are tracking them. |
| 4195 | HashMap<String, SparseIntArray> active = mActiveEvents.getStateForEvent( |
| 4196 | HistoryItem.EVENT_PROC); |
| 4197 | if (active != null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4198 | long mSecRealtime = mClocks.elapsedRealtime(); |
| 4199 | final long mSecUptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 4200 | for (HashMap.Entry<String, SparseIntArray> ent : active.entrySet()) { |
| 4201 | SparseIntArray uids = ent.getValue(); |
| 4202 | for (int j=0; j<uids.size(); j++) { |
| 4203 | addHistoryEventLocked(mSecRealtime, mSecUptime, |
| 4204 | HistoryItem.EVENT_PROC_START, ent.getKey(), uids.keyAt(j)); |
| 4205 | } |
| 4206 | } |
| 4207 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4208 | } |
| 4209 | } |
| 4210 | |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 4211 | public void setNoAutoReset(boolean enabled) { |
| 4212 | mNoAutoReset = enabled; |
| 4213 | } |
| 4214 | |
Amith Yamasani | 674c9bb | 2017-02-01 09:45:17 -0800 | [diff] [blame] | 4215 | public void setPretendScreenOff(boolean pretendScreenOff) { |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4216 | if (mPretendScreenOff != pretendScreenOff) { |
| 4217 | mPretendScreenOff = pretendScreenOff; |
| 4218 | noteScreenStateLocked(pretendScreenOff ? Display.STATE_OFF : Display.STATE_ON); |
| 4219 | } |
Amith Yamasani | 674c9bb | 2017-02-01 09:45:17 -0800 | [diff] [blame] | 4220 | } |
| 4221 | |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 4222 | private String mInitialAcquireWakeName; |
| 4223 | private int mInitialAcquireWakeUid = -1; |
| 4224 | |
Narayan Kamath | 8182202 | 2017-12-08 11:56:01 +0000 | [diff] [blame] | 4225 | public void noteStartWakeLocked(int uid, int pid, WorkChain wc, String name, String historyName, |
| 4226 | int type, boolean unimportantForLogging, long elapsedRealtime, long uptime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4227 | uid = mapUid(uid); |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 4228 | if (type == WAKE_TYPE_PARTIAL) { |
| 4229 | // Only care about partial wake locks, since full wake locks |
| 4230 | // will be canceled when the user puts the screen to sleep. |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4231 | aggregateLastWakeupUptimeLocked(uptime); |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 4232 | if (historyName == null) { |
| 4233 | historyName = name; |
| 4234 | } |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 4235 | if (mRecordAllHistory) { |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 4236 | if (mActiveEvents.updateState(HistoryItem.EVENT_WAKE_LOCK_START, historyName, |
| 4237 | uid, 0)) { |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 4238 | addHistoryEventLocked(elapsedRealtime, uptime, |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 4239 | HistoryItem.EVENT_WAKE_LOCK_START, historyName, uid); |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 4240 | } |
| 4241 | } |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 4242 | if (mWakeLockNesting == 0) { |
| 4243 | mHistoryCur.states |= HistoryItem.STATE_WAKE_LOCK_FLAG; |
| 4244 | if (DEBUG_HISTORY) Slog.v(TAG, "Start wake lock to: " |
| 4245 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4246 | mHistoryCur.wakelockTag = mHistoryCur.localWakelockTag; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4247 | mHistoryCur.wakelockTag.string = mInitialAcquireWakeName = historyName; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 4248 | mHistoryCur.wakelockTag.uid = mInitialAcquireWakeUid = uid; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 4249 | mWakeLockImportant = !unimportantForLogging; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4250 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 4251 | } else if (!mWakeLockImportant && !unimportantForLogging |
| 4252 | && mHistoryLastWritten.cmd == HistoryItem.CMD_UPDATE) { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 4253 | if (mHistoryLastWritten.wakelockTag != null) { |
| 4254 | // We'll try to update the last tag. |
| 4255 | mHistoryLastWritten.wakelockTag = null; |
| 4256 | mHistoryCur.wakelockTag = mHistoryCur.localWakelockTag; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4257 | mHistoryCur.wakelockTag.string = mInitialAcquireWakeName = historyName; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 4258 | mHistoryCur.wakelockTag.uid = mInitialAcquireWakeUid = uid; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4259 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 4260 | } |
| 4261 | mWakeLockImportant = true; |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 4262 | } |
| 4263 | mWakeLockNesting++; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4264 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4265 | if (uid >= 0) { |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 4266 | if (mOnBatteryScreenOffTimeBase.isRunning()) { |
| 4267 | // We only update the cpu time when a wake lock is acquired if the screen is off. |
| 4268 | // If the screen is on, we don't distribute the power amongst partial wakelocks. |
| 4269 | if (DEBUG_ENERGY_CPU) { |
| 4270 | Slog.d(TAG, "Updating cpu time because of +wake_lock"); |
| 4271 | } |
| 4272 | requestWakelockCpuUpdate(); |
| 4273 | } |
Narayan Kamath | 8182202 | 2017-12-08 11:56:01 +0000 | [diff] [blame] | 4274 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4275 | getUidStatsLocked(uid).noteStartWakeLocked(pid, name, type, elapsedRealtime); |
Narayan Kamath | 8182202 | 2017-12-08 11:56:01 +0000 | [diff] [blame] | 4276 | |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 4277 | if (wc != null) { |
Bookatz | 1a1b046 | 2018-01-12 11:47:03 -0800 | [diff] [blame] | 4278 | StatsLog.write(StatsLog.WAKELOCK_STATE_CHANGED, wc.getUids(), wc.getTags(), |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 4279 | getPowerManagerWakeLockLevel(type), name, |
| 4280 | StatsLog.WAKELOCK_STATE_CHANGED__STATE__ACQUIRE); |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 4281 | } else { |
Bookatz | 1a1b046 | 2018-01-12 11:47:03 -0800 | [diff] [blame] | 4282 | StatsLog.write_non_chained(StatsLog.WAKELOCK_STATE_CHANGED, uid, null, |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 4283 | getPowerManagerWakeLockLevel(type), name, |
| 4284 | StatsLog.WAKELOCK_STATE_CHANGED__STATE__ACQUIRE); |
Narayan Kamath | 8182202 | 2017-12-08 11:56:01 +0000 | [diff] [blame] | 4285 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4286 | } |
| 4287 | } |
| 4288 | |
Narayan Kamath | 8182202 | 2017-12-08 11:56:01 +0000 | [diff] [blame] | 4289 | public void noteStopWakeLocked(int uid, int pid, WorkChain wc, String name, String historyName, |
| 4290 | int type, long elapsedRealtime, long uptime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4291 | uid = mapUid(uid); |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 4292 | if (type == WAKE_TYPE_PARTIAL) { |
| 4293 | mWakeLockNesting--; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 4294 | if (mRecordAllHistory) { |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 4295 | if (historyName == null) { |
| 4296 | historyName = name; |
| 4297 | } |
| 4298 | if (mActiveEvents.updateState(HistoryItem.EVENT_WAKE_LOCK_FINISH, historyName, |
| 4299 | uid, 0)) { |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 4300 | addHistoryEventLocked(elapsedRealtime, uptime, |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 4301 | HistoryItem.EVENT_WAKE_LOCK_FINISH, historyName, uid); |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 4302 | } |
| 4303 | } |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 4304 | if (mWakeLockNesting == 0) { |
| 4305 | mHistoryCur.states &= ~HistoryItem.STATE_WAKE_LOCK_FLAG; |
| 4306 | if (DEBUG_HISTORY) Slog.v(TAG, "Stop wake lock to: " |
| 4307 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 4308 | mInitialAcquireWakeName = null; |
| 4309 | mInitialAcquireWakeUid = -1; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4310 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 4311 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4312 | } |
| 4313 | if (uid >= 0) { |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 4314 | if (mOnBatteryScreenOffTimeBase.isRunning()) { |
| 4315 | if (DEBUG_ENERGY_CPU) { |
| 4316 | Slog.d(TAG, "Updating cpu time because of -wake_lock"); |
| 4317 | } |
| 4318 | requestWakelockCpuUpdate(); |
| 4319 | } |
Narayan Kamath | 8182202 | 2017-12-08 11:56:01 +0000 | [diff] [blame] | 4320 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4321 | getUidStatsLocked(uid).noteStopWakeLocked(pid, name, type, elapsedRealtime); |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 4322 | if (wc != null) { |
Bookatz | 1a1b046 | 2018-01-12 11:47:03 -0800 | [diff] [blame] | 4323 | StatsLog.write(StatsLog.WAKELOCK_STATE_CHANGED, wc.getUids(), wc.getTags(), |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 4324 | getPowerManagerWakeLockLevel(type), name, |
| 4325 | StatsLog.WAKELOCK_STATE_CHANGED__STATE__RELEASE); |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 4326 | } else { |
Bookatz | 1a1b046 | 2018-01-12 11:47:03 -0800 | [diff] [blame] | 4327 | StatsLog.write_non_chained(StatsLog.WAKELOCK_STATE_CHANGED, uid, null, |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 4328 | getPowerManagerWakeLockLevel(type), name, |
| 4329 | StatsLog.WAKELOCK_STATE_CHANGED__STATE__RELEASE); |
Narayan Kamath | 8182202 | 2017-12-08 11:56:01 +0000 | [diff] [blame] | 4330 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4331 | } |
| 4332 | } |
| 4333 | |
Bookatz | 1a1b046 | 2018-01-12 11:47:03 -0800 | [diff] [blame] | 4334 | /** |
| 4335 | * Converts BatteryStats wakelock types back into PowerManager wakelock levels. |
| 4336 | * This is the inverse map of Notifier.getBatteryStatsWakeLockMonitorType(). |
| 4337 | * These are estimations, since batterystats loses some of the original data. |
| 4338 | * TODO: Delete this. Instead, StatsLog.write should be called from PowerManager's Notifier. |
| 4339 | */ |
| 4340 | private int getPowerManagerWakeLockLevel(int battertStatsWakelockType) { |
| 4341 | switch (battertStatsWakelockType) { |
| 4342 | // PowerManager.PARTIAL_WAKE_LOCK or PROXIMITY_SCREEN_OFF_WAKE_LOCK |
| 4343 | case BatteryStats.WAKE_TYPE_PARTIAL: |
| 4344 | return PowerManager.PARTIAL_WAKE_LOCK; |
| 4345 | |
| 4346 | // PowerManager.SCREEN_DIM_WAKE_LOCK or SCREEN_BRIGHT_WAKE_LOCK |
| 4347 | case BatteryStats.WAKE_TYPE_FULL: |
| 4348 | return PowerManager.FULL_WAKE_LOCK; |
| 4349 | |
| 4350 | case BatteryStats.WAKE_TYPE_DRAW: |
| 4351 | return PowerManager.DRAW_WAKE_LOCK; |
| 4352 | |
| 4353 | // It appears that nothing can ever make a Window and PowerManager lacks an equivalent. |
| 4354 | case BatteryStats.WAKE_TYPE_WINDOW: |
| 4355 | Slog.e(TAG, "Illegal window wakelock type observed in batterystats."); |
| 4356 | return -1; |
| 4357 | |
| 4358 | default: |
| 4359 | Slog.e(TAG, "Illegal wakelock type in batterystats: " + battertStatsWakelockType); |
| 4360 | return -1; |
| 4361 | } |
| 4362 | } |
| 4363 | |
Dianne Hackborn | a1f1a3c | 2014-02-24 18:12:28 -0800 | [diff] [blame] | 4364 | public void noteStartWakeFromSourceLocked(WorkSource ws, int pid, String name, |
| 4365 | String historyName, int type, boolean unimportantForLogging) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4366 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4367 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 4368 | final int N = ws.size(); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 4369 | for (int i=0; i<N; i++) { |
Narayan Kamath | 8182202 | 2017-12-08 11:56:01 +0000 | [diff] [blame] | 4370 | noteStartWakeLocked(ws.get(i), pid, null, name, historyName, type, |
| 4371 | unimportantForLogging, elapsedRealtime, uptime); |
| 4372 | } |
| 4373 | |
| 4374 | List<WorkChain> wcs = ws.getWorkChains(); |
| 4375 | if (wcs != null) { |
| 4376 | for (int i = 0; i < wcs.size(); ++i) { |
| 4377 | final WorkChain wc = wcs.get(i); |
| 4378 | noteStartWakeLocked(wc.getAttributionUid(), pid, wc, name, historyName, type, |
| 4379 | unimportantForLogging, elapsedRealtime, uptime); |
| 4380 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 4381 | } |
| 4382 | } |
| 4383 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4384 | public void noteChangeWakelockFromSourceLocked(WorkSource ws, int pid, String name, |
| 4385 | String historyName, int type, WorkSource newWs, int newPid, String newName, |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 4386 | String newHistoryName, int newType, boolean newUnimportantForLogging) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4387 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4388 | final long uptime = mClocks.uptimeMillis(); |
Narayan Kamath | 8182202 | 2017-12-08 11:56:01 +0000 | [diff] [blame] | 4389 | |
| 4390 | List<WorkChain>[] wcs = WorkSource.diffChains(ws, newWs); |
| 4391 | |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 4392 | // For correct semantics, we start the need worksources first, so that we won't |
| 4393 | // make inappropriate history items as if all wake locks went away and new ones |
| 4394 | // appeared. This is okay because tracking of wake locks allows nesting. |
Narayan Kamath | 8182202 | 2017-12-08 11:56:01 +0000 | [diff] [blame] | 4395 | // |
| 4396 | // First the starts : |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4397 | final int NN = newWs.size(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 4398 | for (int i=0; i<NN; i++) { |
Narayan Kamath | 8182202 | 2017-12-08 11:56:01 +0000 | [diff] [blame] | 4399 | noteStartWakeLocked(newWs.get(i), newPid, null, newName, newHistoryName, newType, |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4400 | newUnimportantForLogging, elapsedRealtime, uptime); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 4401 | } |
Narayan Kamath | 8182202 | 2017-12-08 11:56:01 +0000 | [diff] [blame] | 4402 | if (wcs != null) { |
| 4403 | List<WorkChain> newChains = wcs[0]; |
| 4404 | if (newChains != null) { |
| 4405 | for (int i = 0; i < newChains.size(); ++i) { |
| 4406 | final WorkChain newChain = newChains.get(i); |
| 4407 | noteStartWakeLocked(newChain.getAttributionUid(), newPid, newChain, newName, |
| 4408 | newHistoryName, newType, newUnimportantForLogging, elapsedRealtime, |
| 4409 | uptime); |
| 4410 | } |
| 4411 | } |
| 4412 | } |
| 4413 | |
| 4414 | // Then the stops : |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 4415 | final int NO = ws.size(); |
| 4416 | for (int i=0; i<NO; i++) { |
Narayan Kamath | 8182202 | 2017-12-08 11:56:01 +0000 | [diff] [blame] | 4417 | noteStopWakeLocked(ws.get(i), pid, null, name, historyName, type, elapsedRealtime, |
| 4418 | uptime); |
| 4419 | } |
| 4420 | if (wcs != null) { |
| 4421 | List<WorkChain> goneChains = wcs[1]; |
| 4422 | if (goneChains != null) { |
| 4423 | for (int i = 0; i < goneChains.size(); ++i) { |
| 4424 | final WorkChain goneChain = goneChains.get(i); |
| 4425 | noteStopWakeLocked(goneChain.getAttributionUid(), pid, goneChain, name, |
| 4426 | historyName, type, elapsedRealtime, uptime); |
| 4427 | } |
| 4428 | } |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 4429 | } |
| 4430 | } |
| 4431 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4432 | public void noteStopWakeFromSourceLocked(WorkSource ws, int pid, String name, |
| 4433 | String historyName, int type) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4434 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4435 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 4436 | final int N = ws.size(); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 4437 | for (int i=0; i<N; i++) { |
Narayan Kamath | 8182202 | 2017-12-08 11:56:01 +0000 | [diff] [blame] | 4438 | noteStopWakeLocked(ws.get(i), pid, null, name, historyName, type, elapsedRealtime, |
| 4439 | uptime); |
| 4440 | } |
| 4441 | |
| 4442 | List<WorkChain> wcs = ws.getWorkChains(); |
| 4443 | if (wcs != null) { |
| 4444 | for (int i = 0; i < wcs.size(); ++i) { |
| 4445 | final WorkChain wc = wcs.get(i); |
| 4446 | noteStopWakeLocked(wc.getAttributionUid(), pid, wc, name, historyName, type, |
| 4447 | elapsedRealtime, uptime); |
| 4448 | } |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 4449 | } |
| 4450 | } |
| 4451 | |
Dianne Hackborn | d0db6f0 | 2016-07-18 14:14:20 -0700 | [diff] [blame] | 4452 | public void noteLongPartialWakelockStart(String name, String historyName, int uid) { |
Yangster-mac | 2f5daec | 2018-01-16 10:23:15 -0800 | [diff] [blame] | 4453 | StatsLog.write_non_chained(StatsLog.LONG_PARTIAL_WAKELOCK_STATE_CHANGED, |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 4454 | uid, null, name, historyName, |
| 4455 | StatsLog.LONG_PARTIAL_WAKELOCK_STATE_CHANGED__STATE__ON); |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 4456 | |
Dianne Hackborn | d0db6f0 | 2016-07-18 14:14:20 -0700 | [diff] [blame] | 4457 | uid = mapUid(uid); |
Narayan Kamath | 96a9256 | 2018-01-02 18:57:17 +0000 | [diff] [blame] | 4458 | noteLongPartialWakeLockStartInternal(name, historyName, uid); |
Narayan Kamath | 96a9256 | 2018-01-02 18:57:17 +0000 | [diff] [blame] | 4459 | } |
| 4460 | |
| 4461 | public void noteLongPartialWakelockStartFromSource(String name, String historyName, |
| 4462 | WorkSource workSource) { |
| 4463 | final int N = workSource.size(); |
| 4464 | for (int i = 0; i < N; ++i) { |
| 4465 | final int uid = mapUid(workSource.get(i)); |
| 4466 | noteLongPartialWakeLockStartInternal(name, historyName, uid); |
Yangster-mac | 2f5daec | 2018-01-16 10:23:15 -0800 | [diff] [blame] | 4467 | StatsLog.write_non_chained(StatsLog.LONG_PARTIAL_WAKELOCK_STATE_CHANGED, |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 4468 | workSource.get(i), workSource.getName(i), name, historyName, |
| 4469 | StatsLog.LONG_PARTIAL_WAKELOCK_STATE_CHANGED__STATE__ON); |
Narayan Kamath | 96a9256 | 2018-01-02 18:57:17 +0000 | [diff] [blame] | 4470 | } |
| 4471 | |
| 4472 | final ArrayList<WorkChain> workChains = workSource.getWorkChains(); |
| 4473 | if (workChains != null) { |
| 4474 | for (int i = 0; i < workChains.size(); ++i) { |
| 4475 | final WorkChain workChain = workChains.get(i); |
| 4476 | final int uid = workChain.getAttributionUid(); |
| 4477 | noteLongPartialWakeLockStartInternal(name, historyName, uid); |
| 4478 | |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 4479 | StatsLog.write(StatsLog.LONG_PARTIAL_WAKELOCK_STATE_CHANGED, |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 4480 | workChain.getUids(), workChain.getTags(), 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 | } |
| 4485 | |
| 4486 | private void noteLongPartialWakeLockStartInternal(String name, String historyName, int uid) { |
Dianne Hackborn | d0db6f0 | 2016-07-18 14:14:20 -0700 | [diff] [blame] | 4487 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4488 | final long uptime = mClocks.uptimeMillis(); |
| 4489 | if (historyName == null) { |
| 4490 | historyName = name; |
| 4491 | } |
| 4492 | if (!mActiveEvents.updateState(HistoryItem.EVENT_LONG_WAKE_LOCK_START, historyName, uid, |
| 4493 | 0)) { |
| 4494 | return; |
| 4495 | } |
| 4496 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_LONG_WAKE_LOCK_START, |
| 4497 | historyName, uid); |
| 4498 | } |
| 4499 | |
| 4500 | public void noteLongPartialWakelockFinish(String name, String historyName, int uid) { |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 4501 | StatsLog.write_non_chained(StatsLog.LONG_PARTIAL_WAKELOCK_STATE_CHANGED, uid, null, |
| 4502 | name, historyName, StatsLog.LONG_PARTIAL_WAKELOCK_STATE_CHANGED__STATE__OFF); |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 4503 | |
Dianne Hackborn | d0db6f0 | 2016-07-18 14:14:20 -0700 | [diff] [blame] | 4504 | uid = mapUid(uid); |
Narayan Kamath | 96a9256 | 2018-01-02 18:57:17 +0000 | [diff] [blame] | 4505 | noteLongPartialWakeLockFinishInternal(name, historyName, uid); |
Narayan Kamath | 96a9256 | 2018-01-02 18:57:17 +0000 | [diff] [blame] | 4506 | } |
| 4507 | |
| 4508 | public void noteLongPartialWakelockFinishFromSource(String name, String historyName, |
| 4509 | WorkSource workSource) { |
| 4510 | final int N = workSource.size(); |
| 4511 | for (int i = 0; i < N; ++i) { |
| 4512 | final int uid = mapUid(workSource.get(i)); |
| 4513 | noteLongPartialWakeLockFinishInternal(name, historyName, uid); |
Yangster-mac | 2f5daec | 2018-01-16 10:23:15 -0800 | [diff] [blame] | 4514 | StatsLog.write_non_chained(StatsLog.LONG_PARTIAL_WAKELOCK_STATE_CHANGED, |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 4515 | workSource.get(i), workSource.getName(i), name, historyName, |
| 4516 | StatsLog.LONG_PARTIAL_WAKELOCK_STATE_CHANGED__STATE__OFF); |
Narayan Kamath | 96a9256 | 2018-01-02 18:57:17 +0000 | [diff] [blame] | 4517 | } |
| 4518 | |
| 4519 | final ArrayList<WorkChain> workChains = workSource.getWorkChains(); |
| 4520 | if (workChains != null) { |
| 4521 | for (int i = 0; i < workChains.size(); ++i) { |
| 4522 | final WorkChain workChain = workChains.get(i); |
| 4523 | final int uid = workChain.getAttributionUid(); |
Narayan Kamath | 96a9256 | 2018-01-02 18:57:17 +0000 | [diff] [blame] | 4524 | noteLongPartialWakeLockFinishInternal(name, historyName, uid); |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 4525 | StatsLog.write(StatsLog.LONG_PARTIAL_WAKELOCK_STATE_CHANGED, |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 4526 | workChain.getUids(), workChain.getTags(), name, historyName, |
| 4527 | StatsLog.LONG_PARTIAL_WAKELOCK_STATE_CHANGED__STATE__OFF); |
Narayan Kamath | 96a9256 | 2018-01-02 18:57:17 +0000 | [diff] [blame] | 4528 | } |
| 4529 | } |
| 4530 | } |
| 4531 | |
| 4532 | private void noteLongPartialWakeLockFinishInternal(String name, String historyName, int uid) { |
Dianne Hackborn | d0db6f0 | 2016-07-18 14:14:20 -0700 | [diff] [blame] | 4533 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4534 | final long uptime = mClocks.uptimeMillis(); |
| 4535 | if (historyName == null) { |
| 4536 | historyName = name; |
| 4537 | } |
| 4538 | if (!mActiveEvents.updateState(HistoryItem.EVENT_LONG_WAKE_LOCK_FINISH, historyName, uid, |
| 4539 | 0)) { |
| 4540 | return; |
| 4541 | } |
| 4542 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_LONG_WAKE_LOCK_FINISH, |
| 4543 | historyName, uid); |
| 4544 | } |
| 4545 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4546 | void aggregateLastWakeupUptimeLocked(long uptimeMs) { |
| 4547 | if (mLastWakeupReason != null) { |
| 4548 | long deltaUptime = uptimeMs - mLastWakeupUptimeMs; |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 4549 | SamplingTimer timer = getWakeupReasonTimerLocked(mLastWakeupReason); |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 4550 | timer.add(deltaUptime * 1000, 1); // time in in microseconds |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 4551 | StatsLog.write(StatsLog.KERNEL_WAKEUP_REPORTED, mLastWakeupReason, |
| 4552 | /* duration_usec */ deltaUptime * 1000); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4553 | mLastWakeupReason = null; |
| 4554 | } |
| 4555 | } |
| 4556 | |
| 4557 | public void noteWakeupReasonLocked(String reason) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4558 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4559 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 4560 | if (DEBUG_HISTORY) Slog.v(TAG, "Wakeup reason \"" + reason +"\": " |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4561 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4562 | aggregateLastWakeupUptimeLocked(uptime); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4563 | mHistoryCur.wakeReasonTag = mHistoryCur.localWakeReasonTag; |
| 4564 | mHistoryCur.wakeReasonTag.string = reason; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4565 | mHistoryCur.wakeReasonTag.uid = 0; |
| 4566 | mLastWakeupReason = reason; |
| 4567 | mLastWakeupUptimeMs = uptime; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4568 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4569 | } |
| 4570 | |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 4571 | public boolean startAddingCpuLocked() { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 4572 | mHandler.removeMessages(MSG_UPDATE_WAKELOCKS); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 4573 | return mOnBatteryInternal; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 4574 | } |
| 4575 | |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 4576 | public void finishAddingCpuLocked(int totalUTime, int totalSTime, int statUserTime, |
| 4577 | int statSystemTime, int statIOWaitTime, int statIrqTime, |
| 4578 | int statSoftIrqTime, int statIdleTime) { |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 4579 | if (DEBUG) Slog.d(TAG, "Adding cpu: tuser=" + totalUTime + " tsys=" + totalSTime |
| 4580 | + " user=" + statUserTime + " sys=" + statSystemTime |
| 4581 | + " io=" + statIOWaitTime + " irq=" + statIrqTime |
| 4582 | + " sirq=" + statSoftIrqTime + " idle=" + statIdleTime); |
| 4583 | mCurStepCpuUserTime += totalUTime; |
| 4584 | mCurStepCpuSystemTime += totalSTime; |
| 4585 | mCurStepStatUserTime += statUserTime; |
| 4586 | mCurStepStatSystemTime += statSystemTime; |
| 4587 | mCurStepStatIOWaitTime += statIOWaitTime; |
| 4588 | mCurStepStatIrqTime += statIrqTime; |
| 4589 | mCurStepStatSoftIrqTime += statSoftIrqTime; |
| 4590 | mCurStepStatIdleTime += statIdleTime; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 4591 | } |
| 4592 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4593 | public void noteProcessDiedLocked(int uid, int pid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4594 | uid = mapUid(uid); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4595 | Uid u = mUidStats.get(uid); |
| 4596 | if (u != null) { |
| 4597 | u.mPids.remove(pid); |
| 4598 | } |
| 4599 | } |
| 4600 | |
| 4601 | public long getProcessWakeTime(int uid, int pid, long realtime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4602 | uid = mapUid(uid); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4603 | Uid u = mUidStats.get(uid); |
| 4604 | if (u != null) { |
| 4605 | Uid.Pid p = u.mPids.get(pid); |
| 4606 | if (p != null) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 4607 | return p.mWakeSumMs + (p.mWakeNesting > 0 ? (realtime - p.mWakeStartMs) : 0); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4608 | } |
| 4609 | } |
| 4610 | return 0; |
| 4611 | } |
| 4612 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 4613 | public void reportExcessiveCpuLocked(int uid, String proc, long overTime, long usedTime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4614 | uid = mapUid(uid); |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 4615 | Uid u = mUidStats.get(uid); |
| 4616 | if (u != null) { |
| 4617 | u.reportExcessiveCpuLocked(proc, overTime, usedTime); |
| 4618 | } |
| 4619 | } |
| 4620 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4621 | int mSensorNesting; |
| 4622 | |
| 4623 | public void noteStartSensorLocked(int uid, int sensor) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4624 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4625 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4626 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4627 | if (mSensorNesting == 0) { |
| 4628 | mHistoryCur.states |= HistoryItem.STATE_SENSOR_ON_FLAG; |
| 4629 | if (DEBUG_HISTORY) Slog.v(TAG, "Start sensor to: " |
| 4630 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4631 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4632 | } |
| 4633 | mSensorNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4634 | getUidStatsLocked(uid).noteStartSensor(sensor, elapsedRealtime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4635 | } |
| 4636 | |
| 4637 | public void noteStopSensorLocked(int uid, int sensor) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4638 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4639 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4640 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4641 | mSensorNesting--; |
| 4642 | if (mSensorNesting == 0) { |
| 4643 | mHistoryCur.states &= ~HistoryItem.STATE_SENSOR_ON_FLAG; |
| 4644 | if (DEBUG_HISTORY) Slog.v(TAG, "Stop sensor to: " |
| 4645 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4646 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4647 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4648 | getUidStatsLocked(uid).noteStopSensor(sensor, elapsedRealtime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4649 | } |
| 4650 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4651 | int mGpsNesting; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4652 | |
Narayan Kamath | 32684dd | 2018-01-08 17:32:51 +0000 | [diff] [blame] | 4653 | public void noteGpsChangedLocked(WorkSource oldWs, WorkSource newWs) { |
| 4654 | for (int i = 0; i < newWs.size(); ++i) { |
| 4655 | noteStartGpsLocked(newWs.get(i), null); |
| 4656 | } |
| 4657 | |
| 4658 | for (int i = 0; i < oldWs.size(); ++i) { |
| 4659 | noteStopGpsLocked((oldWs.get(i)), null); |
| 4660 | } |
| 4661 | |
| 4662 | List<WorkChain>[] wcs = WorkSource.diffChains(oldWs, newWs); |
| 4663 | if (wcs != null) { |
| 4664 | if (wcs[0] != null) { |
| 4665 | final List<WorkChain> newChains = wcs[0]; |
| 4666 | for (int i = 0; i < newChains.size(); ++i) { |
| 4667 | noteStartGpsLocked(-1, newChains.get(i)); |
| 4668 | } |
| 4669 | } |
| 4670 | |
| 4671 | if (wcs[1] != null) { |
| 4672 | final List<WorkChain> goneChains = wcs[1]; |
| 4673 | for (int i = 0; i < goneChains.size(); ++i) { |
| 4674 | noteStopGpsLocked(-1, goneChains.get(i)); |
| 4675 | } |
| 4676 | } |
| 4677 | } |
| 4678 | } |
| 4679 | |
| 4680 | private void noteStartGpsLocked(int uid, WorkChain workChain) { |
| 4681 | uid = getAttributionUid(uid, workChain); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4682 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4683 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4684 | if (mGpsNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4685 | mHistoryCur.states |= HistoryItem.STATE_GPS_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4686 | if (DEBUG_HISTORY) Slog.v(TAG, "Start GPS to: " |
| 4687 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4688 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4689 | } |
| 4690 | mGpsNesting++; |
Narayan Kamath | 32684dd | 2018-01-08 17:32:51 +0000 | [diff] [blame] | 4691 | |
| 4692 | if (workChain == null) { |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 4693 | StatsLog.write_non_chained(StatsLog.GPS_SCAN_STATE_CHANGED, uid, null, |
| 4694 | StatsLog.GPS_SCAN_STATE_CHANGED__STATE__ON); |
Narayan Kamath | 32684dd | 2018-01-08 17:32:51 +0000 | [diff] [blame] | 4695 | } else { |
| 4696 | StatsLog.write(StatsLog.GPS_SCAN_STATE_CHANGED, |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 4697 | workChain.getUids(), workChain.getTags(), |
| 4698 | StatsLog.GPS_SCAN_STATE_CHANGED__STATE__ON); |
Narayan Kamath | 32684dd | 2018-01-08 17:32:51 +0000 | [diff] [blame] | 4699 | } |
| 4700 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4701 | getUidStatsLocked(uid).noteStartGps(elapsedRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4702 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4703 | |
Narayan Kamath | 32684dd | 2018-01-08 17:32:51 +0000 | [diff] [blame] | 4704 | private void noteStopGpsLocked(int uid, WorkChain workChain) { |
| 4705 | uid = getAttributionUid(uid, workChain); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4706 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4707 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4708 | mGpsNesting--; |
| 4709 | if (mGpsNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4710 | mHistoryCur.states &= ~HistoryItem.STATE_GPS_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4711 | if (DEBUG_HISTORY) Slog.v(TAG, "Stop GPS to: " |
| 4712 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4713 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 4714 | stopAllGpsSignalQualityTimersLocked(-1); |
| 4715 | mGpsSignalQualityBin = -1; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4716 | } |
Narayan Kamath | 32684dd | 2018-01-08 17:32:51 +0000 | [diff] [blame] | 4717 | |
| 4718 | if (workChain == null) { |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 4719 | StatsLog.write_non_chained(StatsLog.GPS_SCAN_STATE_CHANGED, uid, null, |
| 4720 | StatsLog.GPS_SCAN_STATE_CHANGED__STATE__OFF); |
Narayan Kamath | 32684dd | 2018-01-08 17:32:51 +0000 | [diff] [blame] | 4721 | } else { |
| 4722 | StatsLog.write(StatsLog.GPS_SCAN_STATE_CHANGED, workChain.getUids(), |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 4723 | workChain.getTags(), StatsLog.GPS_SCAN_STATE_CHANGED__STATE__OFF); |
Narayan Kamath | 32684dd | 2018-01-08 17:32:51 +0000 | [diff] [blame] | 4724 | } |
| 4725 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4726 | getUidStatsLocked(uid).noteStopGps(elapsedRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4727 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 4728 | |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 4729 | public void noteGpsSignalQualityLocked(int signalLevel) { |
| 4730 | if (mGpsNesting == 0) { |
| 4731 | return; |
| 4732 | } |
| 4733 | if (signalLevel < 0 || signalLevel >= GnssMetrics.NUM_GPS_SIGNAL_QUALITY_LEVELS) { |
| 4734 | stopAllGpsSignalQualityTimersLocked(-1); |
| 4735 | return; |
| 4736 | } |
| 4737 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4738 | final long uptime = mClocks.uptimeMillis(); |
| 4739 | if (mGpsSignalQualityBin != signalLevel) { |
| 4740 | if (mGpsSignalQualityBin >= 0) { |
| 4741 | mGpsSignalQualityTimer[mGpsSignalQualityBin].stopRunningLocked(elapsedRealtime); |
| 4742 | } |
| 4743 | if(!mGpsSignalQualityTimer[signalLevel].isRunningLocked()) { |
| 4744 | mGpsSignalQualityTimer[signalLevel].startRunningLocked(elapsedRealtime); |
| 4745 | } |
| 4746 | mHistoryCur.states2 = (mHistoryCur.states2&~HistoryItem.STATE2_GPS_SIGNAL_QUALITY_MASK) |
| 4747 | | (signalLevel << HistoryItem.STATE2_GPS_SIGNAL_QUALITY_SHIFT); |
| 4748 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4749 | mGpsSignalQualityBin = signalLevel; |
| 4750 | } |
| 4751 | return; |
| 4752 | } |
| 4753 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4754 | public void noteScreenStateLocked(int state) { |
Amith Yamasani | 674c9bb | 2017-02-01 09:45:17 -0800 | [diff] [blame] | 4755 | state = mPretendScreenOff ? Display.STATE_OFF : state; |
Santos Cordon | e94f050 | 2017-02-24 12:31:20 -0800 | [diff] [blame] | 4756 | |
| 4757 | // Battery stats relies on there being 4 states. To accommodate this, new states beyond the |
| 4758 | // original 4 are mapped to one of the originals. |
| 4759 | if (state > MAX_TRACKED_SCREEN_STATE) { |
| 4760 | switch (state) { |
| 4761 | case Display.STATE_VR: |
| 4762 | state = Display.STATE_ON; |
| 4763 | break; |
| 4764 | default: |
| 4765 | Slog.wtf(TAG, "Unknown screen state (not mapped): " + state); |
| 4766 | break; |
| 4767 | } |
| 4768 | } |
| 4769 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4770 | if (mScreenState != state) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 4771 | recordDailyStatsIfNeededLocked(true); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4772 | final int oldState = mScreenState; |
| 4773 | mScreenState = state; |
| 4774 | if (DEBUG) Slog.v(TAG, "Screen state: oldState=" + Display.stateToString(oldState) |
| 4775 | + ", newState=" + Display.stateToString(state)); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4776 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 4777 | if (state != Display.STATE_UNKNOWN) { |
| 4778 | int stepState = state-1; |
Santos Cordon | e94f050 | 2017-02-24 12:31:20 -0800 | [diff] [blame] | 4779 | if ((stepState & STEP_LEVEL_MODE_SCREEN_STATE) == stepState) { |
| 4780 | mModStepMode |= (mCurStepMode & STEP_LEVEL_MODE_SCREEN_STATE) ^ stepState; |
| 4781 | mCurStepMode = (mCurStepMode & ~STEP_LEVEL_MODE_SCREEN_STATE) | stepState; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 4782 | } else { |
| 4783 | Slog.wtf(TAG, "Unexpected screen state: " + state); |
| 4784 | } |
| 4785 | } |
| 4786 | |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4787 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4788 | final long uptime = mClocks.uptimeMillis(); |
| 4789 | |
| 4790 | boolean updateHistory = false; |
| 4791 | if (isScreenDoze(state)) { |
| 4792 | mHistoryCur.states |= HistoryItem.STATE_SCREEN_DOZE_FLAG; |
| 4793 | mScreenDozeTimer.startRunningLocked(elapsedRealtime); |
| 4794 | updateHistory = true; |
| 4795 | } else if (isScreenDoze(oldState)) { |
| 4796 | mHistoryCur.states &= ~HistoryItem.STATE_SCREEN_DOZE_FLAG; |
| 4797 | mScreenDozeTimer.stopRunningLocked(elapsedRealtime); |
| 4798 | updateHistory = true; |
| 4799 | } |
| 4800 | if (isScreenOn(state)) { |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4801 | mHistoryCur.states |= HistoryItem.STATE_SCREEN_ON_FLAG; |
| 4802 | if (DEBUG_HISTORY) Slog.v(TAG, "Screen on to: " |
| 4803 | + Integer.toHexString(mHistoryCur.states)); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4804 | mScreenOnTimer.startRunningLocked(elapsedRealtime); |
| 4805 | if (mScreenBrightnessBin >= 0) { |
| 4806 | mScreenBrightnessTimer[mScreenBrightnessBin].startRunningLocked(elapsedRealtime); |
| 4807 | } |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4808 | updateHistory = true; |
| 4809 | } else if (isScreenOn(oldState)) { |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4810 | mHistoryCur.states &= ~HistoryItem.STATE_SCREEN_ON_FLAG; |
| 4811 | if (DEBUG_HISTORY) Slog.v(TAG, "Screen off to: " |
| 4812 | + Integer.toHexString(mHistoryCur.states)); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4813 | mScreenOnTimer.stopRunningLocked(elapsedRealtime); |
| 4814 | if (mScreenBrightnessBin >= 0) { |
| 4815 | mScreenBrightnessTimer[mScreenBrightnessBin].stopRunningLocked(elapsedRealtime); |
| 4816 | } |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4817 | updateHistory = true; |
| 4818 | } |
| 4819 | if (updateHistory) { |
| 4820 | if (DEBUG_HISTORY) Slog.v(TAG, "Screen state to: " |
| 4821 | + Display.stateToString(state)); |
| 4822 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4823 | } |
| 4824 | if (isScreenOn(state)) { |
| 4825 | updateTimeBasesLocked(mOnBatteryTimeBase.isRunning(), state, |
| 4826 | mClocks.uptimeMillis() * 1000, elapsedRealtime * 1000); |
| 4827 | // 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] | 4828 | noteStartWakeLocked(-1, -1, null, "screen", null, WAKE_TYPE_PARTIAL, false, |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4829 | elapsedRealtime, uptime); |
| 4830 | } else if (isScreenOn(oldState)) { |
Narayan Kamath | 8182202 | 2017-12-08 11:56:01 +0000 | [diff] [blame] | 4831 | noteStopWakeLocked(-1, -1, null, "screen", "screen", WAKE_TYPE_PARTIAL, |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4832 | elapsedRealtime, uptime); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4833 | updateTimeBasesLocked(mOnBatteryTimeBase.isRunning(), state, |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4834 | mClocks.uptimeMillis() * 1000, elapsedRealtime * 1000); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 4835 | } |
| 4836 | // Update discharge amounts. |
| 4837 | if (mOnBatteryInternal) { |
| 4838 | updateDischargeScreenLevelsLocked(oldState, state); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 4839 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4840 | } |
| 4841 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4842 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4843 | public void noteScreenBrightnessLocked(int brightness) { |
| 4844 | // Bin the brightness. |
| 4845 | int bin = brightness / (256/NUM_SCREEN_BRIGHTNESS_BINS); |
| 4846 | if (bin < 0) bin = 0; |
| 4847 | else if (bin >= NUM_SCREEN_BRIGHTNESS_BINS) bin = NUM_SCREEN_BRIGHTNESS_BINS-1; |
| 4848 | if (mScreenBrightnessBin != bin) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4849 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4850 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4851 | mHistoryCur.states = (mHistoryCur.states&~HistoryItem.STATE_BRIGHTNESS_MASK) |
| 4852 | | (bin << HistoryItem.STATE_BRIGHTNESS_SHIFT); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4853 | if (DEBUG_HISTORY) Slog.v(TAG, "Screen brightness " + bin + " to: " |
| 4854 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4855 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4856 | if (mScreenState == Display.STATE_ON) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4857 | if (mScreenBrightnessBin >= 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4858 | mScreenBrightnessTimer[mScreenBrightnessBin].stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4859 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4860 | mScreenBrightnessTimer[bin].startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4861 | } |
| 4862 | mScreenBrightnessBin = bin; |
| 4863 | } |
| 4864 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4865 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4866 | public void noteUserActivityLocked(int uid, int event) { |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4867 | if (mOnBatteryInternal) { |
| 4868 | uid = mapUid(uid); |
| 4869 | getUidStatsLocked(uid).noteUserActivityLocked(event); |
| 4870 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4871 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4872 | |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 4873 | public void noteWakeUpLocked(String reason, int reasonUid) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4874 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4875 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 4876 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_SCREEN_WAKE_UP, |
| 4877 | reason, reasonUid); |
| 4878 | } |
| 4879 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4880 | public void noteInteractiveLocked(boolean interactive) { |
| 4881 | if (mInteractive != interactive) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4882 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4883 | mInteractive = interactive; |
| 4884 | if (DEBUG) Slog.v(TAG, "Interactive: " + interactive); |
| 4885 | if (interactive) { |
| 4886 | mInteractiveTimer.startRunningLocked(elapsedRealtime); |
| 4887 | } else { |
| 4888 | mInteractiveTimer.stopRunningLocked(elapsedRealtime); |
| 4889 | } |
| 4890 | } |
| 4891 | } |
| 4892 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 4893 | public void noteConnectivityChangedLocked(int type, String extra) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4894 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4895 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 4896 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_CONNECTIVITY_CHANGED, |
| 4897 | extra, type); |
| 4898 | mNumConnectivityChange++; |
| 4899 | } |
| 4900 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 4901 | private void noteMobileRadioApWakeupLocked(final long elapsedRealtimeMillis, |
| 4902 | final long uptimeMillis, int uid) { |
| 4903 | uid = mapUid(uid); |
| 4904 | addHistoryEventLocked(elapsedRealtimeMillis, uptimeMillis, HistoryItem.EVENT_WAKEUP_AP, "", |
| 4905 | uid); |
| 4906 | getUidStatsLocked(uid).noteMobileRadioApWakeupLocked(); |
| 4907 | } |
| 4908 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 4909 | /** |
| 4910 | * Updates the radio power state and returns true if an external stats collection should occur. |
| 4911 | */ |
| 4912 | public boolean noteMobileRadioPowerStateLocked(int powerState, long timestampNs, int uid) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4913 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4914 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 4915 | if (mMobileRadioPowerState != powerState) { |
| 4916 | long realElapsedRealtimeMs; |
| 4917 | final boolean active = |
| 4918 | powerState == DataConnectionRealTimeInfo.DC_POWER_STATE_MEDIUM |
| 4919 | || powerState == DataConnectionRealTimeInfo.DC_POWER_STATE_HIGH; |
| 4920 | if (active) { |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 4921 | if (uid > 0) { |
| 4922 | noteMobileRadioApWakeupLocked(elapsedRealtime, uptime, uid); |
| 4923 | } |
| 4924 | |
Adam Lesinski | 9acfd81 | 2016-04-19 18:29:50 -0700 | [diff] [blame] | 4925 | mMobileRadioActiveStartTime = realElapsedRealtimeMs = timestampNs / (1000 * 1000); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 4926 | mHistoryCur.states |= HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG; |
| 4927 | } else { |
| 4928 | realElapsedRealtimeMs = timestampNs / (1000*1000); |
Dianne Hackborn | f7097a5 | 2014-05-13 09:56:14 -0700 | [diff] [blame] | 4929 | long lastUpdateTimeMs = mMobileRadioActiveStartTime; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 4930 | if (realElapsedRealtimeMs < lastUpdateTimeMs) { |
| 4931 | Slog.wtf(TAG, "Data connection inactive timestamp " + realElapsedRealtimeMs |
| 4932 | + " is before start time " + lastUpdateTimeMs); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4933 | realElapsedRealtimeMs = elapsedRealtime; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 4934 | } else if (realElapsedRealtimeMs < elapsedRealtime) { |
| 4935 | mMobileRadioActiveAdjustedTime.addCountLocked(elapsedRealtime |
| 4936 | - realElapsedRealtimeMs); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4937 | } |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 4938 | mHistoryCur.states &= ~HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG; |
| 4939 | } |
| 4940 | if (DEBUG_HISTORY) Slog.v(TAG, "Mobile network active " + active + " to: " |
| 4941 | + Integer.toHexString(mHistoryCur.states)); |
| 4942 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4943 | mMobileRadioPowerState = powerState; |
Bookatz | ddccf0a | 2017-11-28 16:48:14 -0800 | [diff] [blame] | 4944 | StatsLog.write(StatsLog.MOBILE_RADIO_POWER_STATE_CHANGED, uid, powerState); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 4945 | if (active) { |
| 4946 | mMobileRadioActiveTimer.startRunningLocked(elapsedRealtime); |
| 4947 | mMobileRadioActivePerAppTimer.startRunningLocked(elapsedRealtime); |
| 4948 | } else { |
| 4949 | mMobileRadioActiveTimer.stopRunningLocked(realElapsedRealtimeMs); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 4950 | mMobileRadioActivePerAppTimer.stopRunningLocked(realElapsedRealtimeMs); |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 4951 | // Tell the caller to collect radio network/power stats. |
| 4952 | return true; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 4953 | } |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 4954 | } |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 4955 | return false; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 4956 | } |
| 4957 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 4958 | public void notePowerSaveModeLocked(boolean enabled) { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4959 | if (mPowerSaveModeEnabled != enabled) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 4960 | int stepState = enabled ? STEP_LEVEL_MODE_POWER_SAVE : 0; |
| 4961 | mModStepMode |= (mCurStepMode&STEP_LEVEL_MODE_POWER_SAVE) ^ stepState; |
| 4962 | mCurStepMode = (mCurStepMode&~STEP_LEVEL_MODE_POWER_SAVE) | stepState; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4963 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4964 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4965 | mPowerSaveModeEnabled = enabled; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4966 | if (enabled) { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4967 | mHistoryCur.states2 |= HistoryItem.STATE2_POWER_SAVE_FLAG; |
| 4968 | if (DEBUG_HISTORY) Slog.v(TAG, "Power save mode enabled to: " |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4969 | + Integer.toHexString(mHistoryCur.states2)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4970 | mPowerSaveModeEnabledTimer.startRunningLocked(elapsedRealtime); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4971 | } else { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4972 | mHistoryCur.states2 &= ~HistoryItem.STATE2_POWER_SAVE_FLAG; |
| 4973 | if (DEBUG_HISTORY) Slog.v(TAG, "Power save mode disabled to: " |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4974 | + Integer.toHexString(mHistoryCur.states2)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4975 | mPowerSaveModeEnabledTimer.stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4976 | } |
| 4977 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 4978 | StatsLog.write(StatsLog.BATTERY_SAVER_MODE_STATE_CHANGED, enabled ? |
| 4979 | StatsLog.BATTERY_SAVER_MODE_STATE_CHANGED__STATE__ON : |
| 4980 | StatsLog.BATTERY_SAVER_MODE_STATE_CHANGED__STATE__OFF); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4981 | } |
| 4982 | } |
| 4983 | |
Bookatz | ddccf0a | 2017-11-28 16:48:14 -0800 | [diff] [blame] | 4984 | public void noteDeviceIdleModeLocked(final int mode, String activeReason, int activeUid) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4985 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4986 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4987 | boolean nowIdling = mode == DEVICE_IDLE_MODE_DEEP; |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4988 | if (mDeviceIdling && !nowIdling && activeReason == null) { |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 4989 | // We don't go out of general idling mode until explicitly taken out of |
| 4990 | // device idle through going active or significant motion. |
| 4991 | nowIdling = true; |
| 4992 | } |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4993 | boolean nowLightIdling = mode == DEVICE_IDLE_MODE_LIGHT; |
| 4994 | if (mDeviceLightIdling && !nowLightIdling && !nowIdling && activeReason == null) { |
| 4995 | // We don't go out of general light idling mode until explicitly taken out of |
| 4996 | // device idle through going active or significant motion. |
| 4997 | nowLightIdling = true; |
| 4998 | } |
| 4999 | if (activeReason != null && (mDeviceIdling || mDeviceLightIdling)) { |
| 5000 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_ACTIVE, |
| 5001 | activeReason, activeUid); |
| 5002 | } |
Bookatz | ddccf0a | 2017-11-28 16:48:14 -0800 | [diff] [blame] | 5003 | if (mDeviceIdling != nowIdling || mDeviceLightIdling != nowLightIdling) { |
| 5004 | int statsmode; |
| 5005 | if (nowIdling) statsmode = DEVICE_IDLE_MODE_DEEP; |
| 5006 | else if (nowLightIdling) statsmode = DEVICE_IDLE_MODE_LIGHT; |
| 5007 | else statsmode = DEVICE_IDLE_MODE_OFF; |
| 5008 | StatsLog.write(StatsLog.DEVICE_IDLING_MODE_STATE_CHANGED, statsmode); |
| 5009 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5010 | if (mDeviceIdling != nowIdling) { |
| 5011 | mDeviceIdling = nowIdling; |
| 5012 | int stepState = nowIdling ? STEP_LEVEL_MODE_DEVICE_IDLE : 0; |
| 5013 | mModStepMode |= (mCurStepMode&STEP_LEVEL_MODE_DEVICE_IDLE) ^ stepState; |
| 5014 | mCurStepMode = (mCurStepMode&~STEP_LEVEL_MODE_DEVICE_IDLE) | stepState; |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 5015 | if (nowIdling) { |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5016 | mDeviceIdlingTimer.startRunningLocked(elapsedRealtime); |
| 5017 | } else { |
| 5018 | mDeviceIdlingTimer.stopRunningLocked(elapsedRealtime); |
| 5019 | } |
| 5020 | } |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 5021 | if (mDeviceLightIdling != nowLightIdling) { |
| 5022 | mDeviceLightIdling = nowLightIdling; |
| 5023 | if (nowLightIdling) { |
| 5024 | mDeviceLightIdlingTimer.startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 5025 | } else { |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 5026 | mDeviceLightIdlingTimer.stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 5027 | } |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 5028 | } |
| 5029 | if (mDeviceIdleMode != mode) { |
| 5030 | mHistoryCur.states2 = (mHistoryCur.states2 & ~HistoryItem.STATE2_DEVICE_IDLE_MASK) |
| 5031 | | (mode << HistoryItem.STATE2_DEVICE_IDLE_SHIFT); |
| 5032 | if (DEBUG_HISTORY) Slog.v(TAG, "Device idle mode changed to: " |
| 5033 | + Integer.toHexString(mHistoryCur.states2)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 5034 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 5035 | long lastDuration = elapsedRealtime - mLastIdleTimeStart; |
| 5036 | mLastIdleTimeStart = elapsedRealtime; |
| 5037 | if (mDeviceIdleMode == DEVICE_IDLE_MODE_LIGHT) { |
| 5038 | if (lastDuration > mLongestLightIdleTime) { |
| 5039 | mLongestLightIdleTime = lastDuration; |
| 5040 | } |
| 5041 | mDeviceIdleModeLightTimer.stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 5042 | } else if (mDeviceIdleMode == DEVICE_IDLE_MODE_DEEP) { |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 5043 | if (lastDuration > mLongestFullIdleTime) { |
| 5044 | mLongestFullIdleTime = lastDuration; |
| 5045 | } |
| 5046 | mDeviceIdleModeFullTimer.stopRunningLocked(elapsedRealtime); |
| 5047 | } |
| 5048 | if (mode == DEVICE_IDLE_MODE_LIGHT) { |
| 5049 | mDeviceIdleModeLightTimer.startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 5050 | } else if (mode == DEVICE_IDLE_MODE_DEEP) { |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 5051 | mDeviceIdleModeFullTimer.startRunningLocked(elapsedRealtime); |
| 5052 | } |
| 5053 | mDeviceIdleMode = mode; |
Bookatz | ddccf0a | 2017-11-28 16:48:14 -0800 | [diff] [blame] | 5054 | StatsLog.write(StatsLog.DEVICE_IDLE_MODE_STATE_CHANGED, mode); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 5055 | } |
| 5056 | } |
| 5057 | |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 5058 | public void notePackageInstalledLocked(String pkgName, long versionCode) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5059 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5060 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 5061 | // XXX need to figure out what to do with long version codes. |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 5062 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_PACKAGE_INSTALLED, |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 5063 | pkgName, (int)versionCode); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5064 | PackageChange pc = new PackageChange(); |
| 5065 | pc.mPackageName = pkgName; |
| 5066 | pc.mUpdate = true; |
| 5067 | pc.mVersionCode = versionCode; |
| 5068 | addPackageChange(pc); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 5069 | } |
| 5070 | |
| 5071 | public void notePackageUninstalledLocked(String pkgName) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5072 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5073 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 5074 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_PACKAGE_UNINSTALLED, |
| 5075 | pkgName, 0); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5076 | PackageChange pc = new PackageChange(); |
| 5077 | pc.mPackageName = pkgName; |
| 5078 | pc.mUpdate = true; |
| 5079 | addPackageChange(pc); |
| 5080 | } |
| 5081 | |
| 5082 | private void addPackageChange(PackageChange pc) { |
| 5083 | if (mDailyPackageChanges == null) { |
| 5084 | mDailyPackageChanges = new ArrayList<>(); |
| 5085 | } |
| 5086 | mDailyPackageChanges.add(pc); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 5087 | } |
| 5088 | |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 5089 | void stopAllGpsSignalQualityTimersLocked(int except) { |
| 5090 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5091 | for (int i = 0; i < GnssMetrics.NUM_GPS_SIGNAL_QUALITY_LEVELS; i++) { |
| 5092 | if (i == except) { |
| 5093 | continue; |
| 5094 | } |
| 5095 | while (mGpsSignalQualityTimer[i].isRunningLocked()) { |
| 5096 | mGpsSignalQualityTimer[i].stopRunningLocked(elapsedRealtime); |
| 5097 | } |
| 5098 | } |
| 5099 | } |
| 5100 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5101 | public void notePhoneOnLocked() { |
| 5102 | if (!mPhoneOn) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5103 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5104 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 5105 | mHistoryCur.states2 |= HistoryItem.STATE2_PHONE_IN_CALL_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5106 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone on to: " |
| 5107 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 5108 | addHistoryRecordLocked(elapsedRealtime, uptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5109 | mPhoneOn = true; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5110 | mPhoneOnTimer.startRunningLocked(elapsedRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5111 | } |
| 5112 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5113 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5114 | public void notePhoneOffLocked() { |
| 5115 | if (mPhoneOn) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5116 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5117 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 5118 | mHistoryCur.states2 &= ~HistoryItem.STATE2_PHONE_IN_CALL_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5119 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone off to: " |
| 5120 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 5121 | addHistoryRecordLocked(elapsedRealtime, uptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5122 | mPhoneOn = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5123 | mPhoneOnTimer.stopRunningLocked(elapsedRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5124 | } |
| 5125 | } |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 5126 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5127 | void stopAllPhoneSignalStrengthTimersLocked(int except) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5128 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 5129 | for (int i = 0; i < SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 5130 | if (i == except) { |
| 5131 | continue; |
| 5132 | } |
| 5133 | while (mPhoneSignalStrengthsTimer[i].isRunningLocked()) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5134 | mPhoneSignalStrengthsTimer[i].stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 5135 | } |
| 5136 | } |
| 5137 | } |
| 5138 | |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5139 | private int fixPhoneServiceState(int state, int signalBin) { |
| 5140 | if (mPhoneSimStateRaw == TelephonyManager.SIM_STATE_ABSENT) { |
| 5141 | // In this case we will always be STATE_OUT_OF_SERVICE, so need |
| 5142 | // to infer that we are scanning from other data. |
| 5143 | if (state == ServiceState.STATE_OUT_OF_SERVICE |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 5144 | && signalBin > SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5145 | state = ServiceState.STATE_IN_SERVICE; |
| 5146 | } |
| 5147 | } |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 5148 | |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5149 | return state; |
| 5150 | } |
| 5151 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5152 | private void updateAllPhoneStateLocked(int state, int simState, int strengthBin) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5153 | boolean scanning = false; |
| 5154 | boolean newHistory = false; |
| 5155 | |
| 5156 | mPhoneServiceStateRaw = state; |
| 5157 | mPhoneSimStateRaw = simState; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5158 | mPhoneSignalStrengthBinRaw = strengthBin; |
| 5159 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5160 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5161 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5162 | |
| 5163 | if (simState == TelephonyManager.SIM_STATE_ABSENT) { |
| 5164 | // In this case we will always be STATE_OUT_OF_SERVICE, so need |
| 5165 | // to infer that we are scanning from other data. |
| 5166 | if (state == ServiceState.STATE_OUT_OF_SERVICE |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5167 | && strengthBin > SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5168 | state = ServiceState.STATE_IN_SERVICE; |
| 5169 | } |
| 5170 | } |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 5171 | |
| 5172 | // If the phone is powered off, stop all timers. |
| 5173 | if (state == ServiceState.STATE_POWER_OFF) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5174 | strengthBin = -1; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 5175 | |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5176 | // If we are in service, make sure the correct signal string timer is running. |
| 5177 | } else if (state == ServiceState.STATE_IN_SERVICE) { |
| 5178 | // Bin will be changed below. |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 5179 | |
| 5180 | // If we're out of service, we are in the lowest signal strength |
| 5181 | // bin and have the scanning bit set. |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 5182 | } else if (state == ServiceState.STATE_OUT_OF_SERVICE) { |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 5183 | scanning = true; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5184 | strengthBin = SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 5185 | if (!mPhoneSignalScanningTimer.isRunningLocked()) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5186 | mHistoryCur.states |= HistoryItem.STATE_PHONE_SCANNING_FLAG; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5187 | newHistory = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5188 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone started scanning to: " |
| 5189 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5190 | mPhoneSignalScanningTimer.startRunningLocked(elapsedRealtime); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 5191 | } |
| 5192 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5193 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 5194 | if (!scanning) { |
| 5195 | // If we are no longer scanning, then stop the scanning timer. |
| 5196 | if (mPhoneSignalScanningTimer.isRunningLocked()) { |
| 5197 | mHistoryCur.states &= ~HistoryItem.STATE_PHONE_SCANNING_FLAG; |
| 5198 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone stopped scanning to: " |
| 5199 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5200 | newHistory = true; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5201 | mPhoneSignalScanningTimer.stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 5202 | } |
| 5203 | } |
| 5204 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5205 | if (mPhoneServiceState != state) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5206 | mHistoryCur.states = (mHistoryCur.states&~HistoryItem.STATE_PHONE_STATE_MASK) |
| 5207 | | (state << HistoryItem.STATE_PHONE_STATE_SHIFT); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5208 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone state " + state + " to: " |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5209 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5210 | newHistory = true; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5211 | mPhoneServiceState = state; |
| 5212 | } |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5213 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5214 | if (mPhoneSignalStrengthBin != strengthBin) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5215 | if (mPhoneSignalStrengthBin >= 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5216 | mPhoneSignalStrengthsTimer[mPhoneSignalStrengthBin].stopRunningLocked( |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5217 | elapsedRealtime); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5218 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5219 | if (strengthBin >= 0) { |
| 5220 | if (!mPhoneSignalStrengthsTimer[strengthBin].isRunningLocked()) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5221 | mPhoneSignalStrengthsTimer[strengthBin].startRunningLocked(elapsedRealtime); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5222 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5223 | mHistoryCur.states = (mHistoryCur.states&~HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_MASK) |
| 5224 | | (strengthBin << HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_SHIFT); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5225 | if (DEBUG_HISTORY) Slog.v(TAG, "Signal strength " + strengthBin + " to: " |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5226 | + Integer.toHexString(mHistoryCur.states)); |
| 5227 | newHistory = true; |
Bookatz | e588524 | 2017-10-24 20:10:31 -0700 | [diff] [blame] | 5228 | StatsLog.write(StatsLog.PHONE_SIGNAL_STRENGTH_CHANGED, strengthBin); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5229 | } else { |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5230 | stopAllPhoneSignalStrengthTimersLocked(-1); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5231 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5232 | mPhoneSignalStrengthBin = strengthBin; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5233 | } |
| 5234 | |
| 5235 | if (newHistory) { |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 5236 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5237 | } |
| 5238 | } |
| 5239 | |
| 5240 | /** |
| 5241 | * Telephony stack updates the phone state. |
| 5242 | * @param state phone state from ServiceState.getState() |
| 5243 | */ |
| 5244 | public void notePhoneStateLocked(int state, int simState) { |
| 5245 | updateAllPhoneStateLocked(state, simState, mPhoneSignalStrengthBinRaw); |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 5246 | } |
| 5247 | |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 5248 | public void notePhoneSignalStrengthLocked(SignalStrength signalStrength) { |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 5249 | // Bin the strength. |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 5250 | int bin = signalStrength.getLevel(); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5251 | updateAllPhoneStateLocked(mPhoneServiceStateRaw, mPhoneSimStateRaw, bin); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 5252 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5253 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 5254 | public void notePhoneDataConnectionStateLocked(int dataType, boolean hasData) { |
| 5255 | int bin = DATA_CONNECTION_NONE; |
| 5256 | if (hasData) { |
| 5257 | switch (dataType) { |
| 5258 | case TelephonyManager.NETWORK_TYPE_EDGE: |
| 5259 | bin = DATA_CONNECTION_EDGE; |
| 5260 | break; |
| 5261 | case TelephonyManager.NETWORK_TYPE_GPRS: |
| 5262 | bin = DATA_CONNECTION_GPRS; |
| 5263 | break; |
| 5264 | case TelephonyManager.NETWORK_TYPE_UMTS: |
| 5265 | bin = DATA_CONNECTION_UMTS; |
| 5266 | break; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5267 | case TelephonyManager.NETWORK_TYPE_CDMA: |
| 5268 | bin = DATA_CONNECTION_CDMA; |
| 5269 | break; |
| 5270 | case TelephonyManager.NETWORK_TYPE_EVDO_0: |
| 5271 | bin = DATA_CONNECTION_EVDO_0; |
| 5272 | break; |
| 5273 | case TelephonyManager.NETWORK_TYPE_EVDO_A: |
| 5274 | bin = DATA_CONNECTION_EVDO_A; |
| 5275 | break; |
| 5276 | case TelephonyManager.NETWORK_TYPE_1xRTT: |
| 5277 | bin = DATA_CONNECTION_1xRTT; |
| 5278 | break; |
| 5279 | case TelephonyManager.NETWORK_TYPE_HSDPA: |
| 5280 | bin = DATA_CONNECTION_HSDPA; |
| 5281 | break; |
| 5282 | case TelephonyManager.NETWORK_TYPE_HSUPA: |
| 5283 | bin = DATA_CONNECTION_HSUPA; |
| 5284 | break; |
| 5285 | case TelephonyManager.NETWORK_TYPE_HSPA: |
| 5286 | bin = DATA_CONNECTION_HSPA; |
| 5287 | break; |
| 5288 | case TelephonyManager.NETWORK_TYPE_IDEN: |
| 5289 | bin = DATA_CONNECTION_IDEN; |
| 5290 | break; |
| 5291 | case TelephonyManager.NETWORK_TYPE_EVDO_B: |
| 5292 | bin = DATA_CONNECTION_EVDO_B; |
| 5293 | break; |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 5294 | case TelephonyManager.NETWORK_TYPE_LTE: |
| 5295 | bin = DATA_CONNECTION_LTE; |
| 5296 | break; |
| 5297 | case TelephonyManager.NETWORK_TYPE_EHRPD: |
| 5298 | bin = DATA_CONNECTION_EHRPD; |
| 5299 | break; |
Patrick Tjin | b71703c | 2013-11-06 09:27:03 -0800 | [diff] [blame] | 5300 | case TelephonyManager.NETWORK_TYPE_HSPAP: |
| 5301 | bin = DATA_CONNECTION_HSPAP; |
| 5302 | break; |
Siddharth Ray | c72081d | 2018-02-13 11:31:54 -0800 | [diff] [blame] | 5303 | case TelephonyManager.NETWORK_TYPE_GSM: |
| 5304 | bin = DATA_CONNECTION_GSM; |
| 5305 | break; |
| 5306 | case TelephonyManager.NETWORK_TYPE_TD_SCDMA: |
| 5307 | bin = DATA_CONNECTION_TD_SCDMA; |
| 5308 | break; |
| 5309 | case TelephonyManager.NETWORK_TYPE_IWLAN: |
| 5310 | bin = DATA_CONNECTION_IWLAN; |
| 5311 | break; |
| 5312 | case TelephonyManager.NETWORK_TYPE_LTE_CA: |
| 5313 | bin = DATA_CONNECTION_LTE_CA; |
| 5314 | break; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 5315 | default: |
| 5316 | bin = DATA_CONNECTION_OTHER; |
| 5317 | break; |
| 5318 | } |
| 5319 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 5320 | if (DEBUG) Log.i(TAG, "Phone Data Connection -> " + dataType + " = " + hasData); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 5321 | if (mPhoneDataConnectionType != bin) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5322 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5323 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5324 | mHistoryCur.states = (mHistoryCur.states&~HistoryItem.STATE_DATA_CONNECTION_MASK) |
| 5325 | | (bin << HistoryItem.STATE_DATA_CONNECTION_SHIFT); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5326 | if (DEBUG_HISTORY) Slog.v(TAG, "Data connection " + bin + " to: " |
| 5327 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 5328 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 5329 | if (mPhoneDataConnectionType >= 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5330 | mPhoneDataConnectionsTimer[mPhoneDataConnectionType].stopRunningLocked( |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5331 | elapsedRealtime); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 5332 | } |
| 5333 | mPhoneDataConnectionType = bin; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5334 | mPhoneDataConnectionsTimer[bin].startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 5335 | } |
| 5336 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5337 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5338 | public void noteWifiOnLocked() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5339 | if (!mWifiOn) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5340 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5341 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5342 | mHistoryCur.states2 |= HistoryItem.STATE2_WIFI_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5343 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI on to: " |
| 5344 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 5345 | addHistoryRecordLocked(elapsedRealtime, uptime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5346 | mWifiOn = true; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5347 | mWifiOnTimer.startRunningLocked(elapsedRealtime); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5348 | scheduleSyncExternalStatsLocked("wifi-off", ExternalStatsSync.UPDATE_WIFI); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5349 | } |
| 5350 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5351 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5352 | public void noteWifiOffLocked() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5353 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5354 | final long uptime = mClocks.uptimeMillis(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5355 | if (mWifiOn) { |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5356 | mHistoryCur.states2 &= ~HistoryItem.STATE2_WIFI_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5357 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI off to: " |
| 5358 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 5359 | addHistoryRecordLocked(elapsedRealtime, uptime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5360 | mWifiOn = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5361 | mWifiOnTimer.stopRunningLocked(elapsedRealtime); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5362 | scheduleSyncExternalStatsLocked("wifi-on", ExternalStatsSync.UPDATE_WIFI); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5363 | } |
| 5364 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 5365 | |
| 5366 | public void noteAudioOnLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5367 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5368 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5369 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 5370 | if (mAudioOnNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5371 | mHistoryCur.states |= HistoryItem.STATE_AUDIO_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5372 | if (DEBUG_HISTORY) Slog.v(TAG, "Audio on to: " |
| 5373 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 5374 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5375 | mAudioOnTimer.startRunningLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 5376 | } |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 5377 | mAudioOnNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5378 | getUidStatsLocked(uid).noteAudioTurnedOnLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 5379 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5380 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 5381 | public void noteAudioOffLocked(int uid) { |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 5382 | if (mAudioOnNesting == 0) { |
| 5383 | return; |
| 5384 | } |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5385 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5386 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5387 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 5388 | if (--mAudioOnNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5389 | mHistoryCur.states &= ~HistoryItem.STATE_AUDIO_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5390 | if (DEBUG_HISTORY) Slog.v(TAG, "Audio off to: " |
| 5391 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 5392 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5393 | mAudioOnTimer.stopRunningLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 5394 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5395 | getUidStatsLocked(uid).noteAudioTurnedOffLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 5396 | } |
| 5397 | |
| 5398 | public void noteVideoOnLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5399 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5400 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5401 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 5402 | if (mVideoOnNesting == 0) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5403 | mHistoryCur.states2 |= HistoryItem.STATE2_VIDEO_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5404 | if (DEBUG_HISTORY) Slog.v(TAG, "Video on to: " |
| 5405 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 5406 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5407 | mVideoOnTimer.startRunningLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 5408 | } |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 5409 | mVideoOnNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5410 | getUidStatsLocked(uid).noteVideoTurnedOnLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 5411 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5412 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 5413 | public void noteVideoOffLocked(int uid) { |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 5414 | if (mVideoOnNesting == 0) { |
| 5415 | return; |
| 5416 | } |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5417 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5418 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5419 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 5420 | if (--mVideoOnNesting == 0) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5421 | mHistoryCur.states2 &= ~HistoryItem.STATE2_VIDEO_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5422 | if (DEBUG_HISTORY) Slog.v(TAG, "Video off to: " |
| 5423 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 5424 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5425 | mVideoOnTimer.stopRunningLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 5426 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5427 | getUidStatsLocked(uid).noteVideoTurnedOffLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 5428 | } |
| 5429 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 5430 | public void noteResetAudioLocked() { |
| 5431 | if (mAudioOnNesting > 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5432 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5433 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 5434 | mAudioOnNesting = 0; |
| 5435 | mHistoryCur.states &= ~HistoryItem.STATE_AUDIO_ON_FLAG; |
| 5436 | if (DEBUG_HISTORY) Slog.v(TAG, "Audio off to: " |
| 5437 | + Integer.toHexString(mHistoryCur.states)); |
| 5438 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 5439 | mAudioOnTimer.stopAllRunningLocked(elapsedRealtime); |
| 5440 | for (int i=0; i<mUidStats.size(); i++) { |
| 5441 | BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 5442 | uid.noteResetAudioLocked(elapsedRealtime); |
| 5443 | } |
| 5444 | } |
| 5445 | } |
| 5446 | |
| 5447 | public void noteResetVideoLocked() { |
| 5448 | if (mVideoOnNesting > 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5449 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5450 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 5451 | mAudioOnNesting = 0; |
| 5452 | mHistoryCur.states2 &= ~HistoryItem.STATE2_VIDEO_ON_FLAG; |
| 5453 | if (DEBUG_HISTORY) Slog.v(TAG, "Video off to: " |
| 5454 | + Integer.toHexString(mHistoryCur.states)); |
| 5455 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 5456 | mVideoOnTimer.stopAllRunningLocked(elapsedRealtime); |
| 5457 | for (int i=0; i<mUidStats.size(); i++) { |
| 5458 | BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 5459 | uid.noteResetVideoLocked(elapsedRealtime); |
| 5460 | } |
| 5461 | } |
| 5462 | } |
| 5463 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5464 | public void noteActivityResumedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5465 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5466 | getUidStatsLocked(uid).noteActivityResumedLocked(mClocks.elapsedRealtime()); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5467 | } |
| 5468 | |
| 5469 | public void noteActivityPausedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5470 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5471 | getUidStatsLocked(uid).noteActivityPausedLocked(mClocks.elapsedRealtime()); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5472 | } |
| 5473 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5474 | public void noteVibratorOnLocked(int uid, long durationMillis) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5475 | uid = mapUid(uid); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5476 | getUidStatsLocked(uid).noteVibratorOnLocked(durationMillis); |
| 5477 | } |
| 5478 | |
| 5479 | public void noteVibratorOffLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5480 | uid = mapUid(uid); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5481 | getUidStatsLocked(uid).noteVibratorOffLocked(); |
| 5482 | } |
| 5483 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5484 | public void noteFlashlightOnLocked(int uid) { |
| 5485 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5486 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5487 | final long uptime = mClocks.uptimeMillis(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5488 | if (mFlashlightOnNesting++ == 0) { |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 5489 | mHistoryCur.states2 |= HistoryItem.STATE2_FLASHLIGHT_FLAG; |
| 5490 | if (DEBUG_HISTORY) Slog.v(TAG, "Flashlight on to: " |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5491 | + Integer.toHexString(mHistoryCur.states2)); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 5492 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 5493 | mFlashlightOnTimer.startRunningLocked(elapsedRealtime); |
| 5494 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5495 | getUidStatsLocked(uid).noteFlashlightTurnedOnLocked(elapsedRealtime); |
| 5496 | } |
| 5497 | |
| 5498 | public void noteFlashlightOffLocked(int uid) { |
| 5499 | if (mFlashlightOnNesting == 0) { |
| 5500 | return; |
| 5501 | } |
| 5502 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5503 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5504 | final long uptime = mClocks.uptimeMillis(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5505 | if (--mFlashlightOnNesting == 0) { |
| 5506 | mHistoryCur.states2 &= ~HistoryItem.STATE2_FLASHLIGHT_FLAG; |
| 5507 | if (DEBUG_HISTORY) Slog.v(TAG, "Flashlight off to: " |
| 5508 | + Integer.toHexString(mHistoryCur.states2)); |
| 5509 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 5510 | mFlashlightOnTimer.stopRunningLocked(elapsedRealtime); |
| 5511 | } |
| 5512 | getUidStatsLocked(uid).noteFlashlightTurnedOffLocked(elapsedRealtime); |
| 5513 | } |
| 5514 | |
| 5515 | public void noteCameraOnLocked(int uid) { |
| 5516 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5517 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5518 | final long uptime = mClocks.uptimeMillis(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5519 | if (mCameraOnNesting++ == 0) { |
| 5520 | mHistoryCur.states2 |= HistoryItem.STATE2_CAMERA_FLAG; |
| 5521 | if (DEBUG_HISTORY) Slog.v(TAG, "Camera on to: " |
| 5522 | + Integer.toHexString(mHistoryCur.states2)); |
| 5523 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 5524 | mCameraOnTimer.startRunningLocked(elapsedRealtime); |
| 5525 | } |
| 5526 | getUidStatsLocked(uid).noteCameraTurnedOnLocked(elapsedRealtime); |
| 5527 | } |
| 5528 | |
| 5529 | public void noteCameraOffLocked(int uid) { |
| 5530 | if (mCameraOnNesting == 0) { |
| 5531 | return; |
| 5532 | } |
| 5533 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5534 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5535 | final long uptime = mClocks.uptimeMillis(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5536 | if (--mCameraOnNesting == 0) { |
| 5537 | mHistoryCur.states2 &= ~HistoryItem.STATE2_CAMERA_FLAG; |
| 5538 | if (DEBUG_HISTORY) Slog.v(TAG, "Camera off to: " |
| 5539 | + Integer.toHexString(mHistoryCur.states2)); |
| 5540 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 5541 | mCameraOnTimer.stopRunningLocked(elapsedRealtime); |
| 5542 | } |
| 5543 | getUidStatsLocked(uid).noteCameraTurnedOffLocked(elapsedRealtime); |
| 5544 | } |
| 5545 | |
| 5546 | public void noteResetCameraLocked() { |
| 5547 | if (mCameraOnNesting > 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5548 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5549 | final long uptime = mClocks.uptimeMillis(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5550 | mCameraOnNesting = 0; |
| 5551 | mHistoryCur.states2 &= ~HistoryItem.STATE2_CAMERA_FLAG; |
| 5552 | if (DEBUG_HISTORY) Slog.v(TAG, "Camera off to: " |
| 5553 | + Integer.toHexString(mHistoryCur.states2)); |
| 5554 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 5555 | mCameraOnTimer.stopAllRunningLocked(elapsedRealtime); |
| 5556 | for (int i=0; i<mUidStats.size(); i++) { |
| 5557 | BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 5558 | uid.noteResetCameraLocked(elapsedRealtime); |
| 5559 | } |
| 5560 | } |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 5561 | } |
| 5562 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5563 | public void noteResetFlashlightLocked() { |
| 5564 | if (mFlashlightOnNesting > 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5565 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5566 | final long uptime = mClocks.uptimeMillis(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5567 | mFlashlightOnNesting = 0; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 5568 | mHistoryCur.states2 &= ~HistoryItem.STATE2_FLASHLIGHT_FLAG; |
| 5569 | if (DEBUG_HISTORY) Slog.v(TAG, "Flashlight off to: " |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5570 | + Integer.toHexString(mHistoryCur.states2)); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 5571 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5572 | mFlashlightOnTimer.stopAllRunningLocked(elapsedRealtime); |
| 5573 | for (int i=0; i<mUidStats.size(); i++) { |
| 5574 | BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 5575 | uid.noteResetFlashlightLocked(elapsedRealtime); |
| 5576 | } |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 5577 | } |
| 5578 | } |
| 5579 | |
Narayan Kamath | 0ebc96c | 2017-12-29 13:32:38 +0000 | [diff] [blame] | 5580 | private void noteBluetoothScanStartedLocked(WorkChain workChain, int uid, |
| 5581 | boolean isUnoptimized) { |
| 5582 | uid = getAttributionUid(uid, workChain); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5583 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5584 | final long uptime = mClocks.uptimeMillis(); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5585 | if (mBluetoothScanNesting == 0) { |
| 5586 | mHistoryCur.states2 |= HistoryItem.STATE2_BLUETOOTH_SCAN_FLAG; |
| 5587 | if (DEBUG_HISTORY) Slog.v(TAG, "BLE scan started for: " |
| 5588 | + Integer.toHexString(mHistoryCur.states2)); |
| 5589 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Adam Lesinski | d9b99be | 2016-03-30 16:58:51 -0700 | [diff] [blame] | 5590 | mBluetoothScanTimer.startRunningLocked(elapsedRealtime); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5591 | } |
| 5592 | mBluetoothScanNesting++; |
Narayan Kamath | 0ebc96c | 2017-12-29 13:32:38 +0000 | [diff] [blame] | 5593 | |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 5594 | if (workChain != null) { |
| 5595 | StatsLog.write(StatsLog.BLE_SCAN_STATE_CHANGED, |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 5596 | workChain.getUids(), workChain.getTags(), |
| 5597 | StatsLog.BLE_SCAN_STATE_CHANGED__STATE__ON); |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 5598 | if (isUnoptimized) { |
| 5599 | StatsLog.write(StatsLog.BLE_UNOPTIMIZED_SCAN_STATE_CHANGED, |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 5600 | workChain.getUids(), workChain.getTags(), |
| 5601 | StatsLog.BLE_UNOPTIMIZED_SCAN_STATE_CHANGED__STATE__ON); |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 5602 | } |
| 5603 | } else { |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 5604 | StatsLog.write_non_chained(StatsLog.BLE_SCAN_STATE_CHANGED, uid, null, |
| 5605 | StatsLog.BLE_SCAN_STATE_CHANGED__STATE__ON); |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 5606 | if (isUnoptimized) { |
Yangster-mac | 2f5daec | 2018-01-16 10:23:15 -0800 | [diff] [blame] | 5607 | StatsLog.write_non_chained(StatsLog.BLE_UNOPTIMIZED_SCAN_STATE_CHANGED, uid, null, |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 5608 | StatsLog.BLE_UNOPTIMIZED_SCAN_STATE_CHANGED__STATE__ON); |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 5609 | } |
Narayan Kamath | 0ebc96c | 2017-12-29 13:32:38 +0000 | [diff] [blame] | 5610 | } |
| 5611 | |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5612 | getUidStatsLocked(uid).noteBluetoothScanStartedLocked(elapsedRealtime, isUnoptimized); |
Narayan Kamath | 0ebc96c | 2017-12-29 13:32:38 +0000 | [diff] [blame] | 5613 | if (workChain != null) { |
| 5614 | getUidStatsLocked(uid).addBluetoothWorkChain(workChain, isUnoptimized); |
| 5615 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5616 | } |
| 5617 | |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5618 | public void noteBluetoothScanStartedFromSourceLocked(WorkSource ws, boolean isUnoptimized) { |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5619 | final int N = ws.size(); |
| 5620 | for (int i = 0; i < N; i++) { |
Narayan Kamath | 0ebc96c | 2017-12-29 13:32:38 +0000 | [diff] [blame] | 5621 | noteBluetoothScanStartedLocked(null, ws.get(i), isUnoptimized); |
| 5622 | } |
| 5623 | |
| 5624 | final List<WorkChain> workChains = ws.getWorkChains(); |
| 5625 | if (workChains != null) { |
| 5626 | for (int i = 0; i < workChains.size(); ++i) { |
| 5627 | noteBluetoothScanStartedLocked(workChains.get(i), -1, isUnoptimized); |
| 5628 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5629 | } |
| 5630 | } |
| 5631 | |
Narayan Kamath | 0ebc96c | 2017-12-29 13:32:38 +0000 | [diff] [blame] | 5632 | private void noteBluetoothScanStoppedLocked(WorkChain workChain, int uid, |
| 5633 | boolean isUnoptimized) { |
| 5634 | uid = getAttributionUid(uid, workChain); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5635 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5636 | final long uptime = mClocks.uptimeMillis(); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5637 | mBluetoothScanNesting--; |
| 5638 | if (mBluetoothScanNesting == 0) { |
| 5639 | mHistoryCur.states2 &= ~HistoryItem.STATE2_BLUETOOTH_SCAN_FLAG; |
| 5640 | if (DEBUG_HISTORY) Slog.v(TAG, "BLE scan stopped for: " |
| 5641 | + Integer.toHexString(mHistoryCur.states2)); |
| 5642 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Adam Lesinski | d9b99be | 2016-03-30 16:58:51 -0700 | [diff] [blame] | 5643 | mBluetoothScanTimer.stopRunningLocked(elapsedRealtime); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5644 | } |
Narayan Kamath | 0ebc96c | 2017-12-29 13:32:38 +0000 | [diff] [blame] | 5645 | |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 5646 | if (workChain != null) { |
| 5647 | StatsLog.write( |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 5648 | StatsLog.BLE_SCAN_STATE_CHANGED, workChain.getUids(), workChain.getTags(), |
| 5649 | StatsLog.BLE_SCAN_STATE_CHANGED__STATE__OFF); |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 5650 | if (isUnoptimized) { |
| 5651 | StatsLog.write(StatsLog.BLE_UNOPTIMIZED_SCAN_STATE_CHANGED, |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 5652 | workChain.getUids(), workChain.getTags(), |
| 5653 | StatsLog.BLE_UNOPTIMIZED_SCAN_STATE_CHANGED__STATE__OFF); |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 5654 | } |
| 5655 | } else { |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 5656 | StatsLog.write_non_chained(StatsLog.BLE_SCAN_STATE_CHANGED, uid, null, |
| 5657 | StatsLog.BLE_SCAN_STATE_CHANGED__STATE__OFF); |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 5658 | if (isUnoptimized) { |
Yangster-mac | 2f5daec | 2018-01-16 10:23:15 -0800 | [diff] [blame] | 5659 | StatsLog.write_non_chained(StatsLog.BLE_UNOPTIMIZED_SCAN_STATE_CHANGED, uid, null, |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 5660 | StatsLog.BLE_UNOPTIMIZED_SCAN_STATE_CHANGED__STATE__OFF); |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 5661 | } |
Narayan Kamath | 0ebc96c | 2017-12-29 13:32:38 +0000 | [diff] [blame] | 5662 | } |
| 5663 | |
Bookatz | 94c5a31 | 2017-07-11 16:49:17 -0700 | [diff] [blame] | 5664 | getUidStatsLocked(uid).noteBluetoothScanStoppedLocked(elapsedRealtime, isUnoptimized); |
Narayan Kamath | 0ebc96c | 2017-12-29 13:32:38 +0000 | [diff] [blame] | 5665 | if (workChain != null) { |
| 5666 | getUidStatsLocked(uid).removeBluetoothWorkChain(workChain, isUnoptimized); |
| 5667 | } |
| 5668 | } |
| 5669 | |
| 5670 | private int getAttributionUid(int uid, WorkChain workChain) { |
| 5671 | if (workChain != null) { |
| 5672 | return mapUid(workChain.getAttributionUid()); |
| 5673 | } |
| 5674 | |
| 5675 | return mapUid(uid); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5676 | } |
| 5677 | |
Bookatz | 94c5a31 | 2017-07-11 16:49:17 -0700 | [diff] [blame] | 5678 | public void noteBluetoothScanStoppedFromSourceLocked(WorkSource ws, boolean isUnoptimized) { |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5679 | final int N = ws.size(); |
| 5680 | for (int i = 0; i < N; i++) { |
Narayan Kamath | 0ebc96c | 2017-12-29 13:32:38 +0000 | [diff] [blame] | 5681 | noteBluetoothScanStoppedLocked(null, ws.get(i), isUnoptimized); |
| 5682 | } |
| 5683 | |
| 5684 | final List<WorkChain> workChains = ws.getWorkChains(); |
| 5685 | if (workChains != null) { |
| 5686 | for (int i = 0; i < workChains.size(); ++i) { |
| 5687 | noteBluetoothScanStoppedLocked(workChains.get(i), -1, isUnoptimized); |
| 5688 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5689 | } |
| 5690 | } |
| 5691 | |
| 5692 | public void noteResetBluetoothScanLocked() { |
| 5693 | if (mBluetoothScanNesting > 0) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5694 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5695 | final long uptime = mClocks.uptimeMillis(); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5696 | mBluetoothScanNesting = 0; |
| 5697 | mHistoryCur.states2 &= ~HistoryItem.STATE2_BLUETOOTH_SCAN_FLAG; |
| 5698 | if (DEBUG_HISTORY) Slog.v(TAG, "BLE can stopped for: " |
| 5699 | + Integer.toHexString(mHistoryCur.states2)); |
| 5700 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 5701 | mBluetoothScanTimer.stopAllRunningLocked(elapsedRealtime); |
Narayan Kamath | 0ebc96c | 2017-12-29 13:32:38 +0000 | [diff] [blame] | 5702 | |
| 5703 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5704 | for (int i=0; i<mUidStats.size(); i++) { |
| 5705 | BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 5706 | uid.noteResetBluetoothScanLocked(elapsedRealtime); |
Narayan Kamath | 0ebc96c | 2017-12-29 13:32:38 +0000 | [diff] [blame] | 5707 | |
Narayan Kamath | 0ebc96c | 2017-12-29 13:32:38 +0000 | [diff] [blame] | 5708 | List<WorkChain> allWorkChains = uid.getAllBluetoothWorkChains(); |
| 5709 | if (allWorkChains != null) { |
| 5710 | for (int j = 0; j < allWorkChains.size(); ++j) { |
Narayan Kamath | 0ebc96c | 2017-12-29 13:32:38 +0000 | [diff] [blame] | 5711 | StatsLog.write(StatsLog.BLE_SCAN_STATE_CHANGED, |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 5712 | allWorkChains.get(j).getUids(), |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 5713 | allWorkChains.get(j).getTags(), |
| 5714 | StatsLog.BLE_SCAN_STATE_CHANGED__STATE__OFF); |
Narayan Kamath | 0ebc96c | 2017-12-29 13:32:38 +0000 | [diff] [blame] | 5715 | } |
Narayan Kamath | 0ebc96c | 2017-12-29 13:32:38 +0000 | [diff] [blame] | 5716 | allWorkChains.clear(); |
| 5717 | } |
| 5718 | |
| 5719 | List<WorkChain> unoptimizedWorkChains = uid.getUnoptimizedBluetoothWorkChains(); |
| 5720 | if (unoptimizedWorkChains != null) { |
| 5721 | for (int j = 0; j < unoptimizedWorkChains.size(); ++j) { |
Narayan Kamath | 0ebc96c | 2017-12-29 13:32:38 +0000 | [diff] [blame] | 5722 | StatsLog.write(StatsLog.BLE_UNOPTIMIZED_SCAN_STATE_CHANGED, |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 5723 | unoptimizedWorkChains.get(j).getUids(), |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 5724 | unoptimizedWorkChains.get(j).getTags(), |
| 5725 | StatsLog.BLE_UNOPTIMIZED_SCAN_STATE_CHANGED__STATE__OFF); |
Narayan Kamath | 0ebc96c | 2017-12-29 13:32:38 +0000 | [diff] [blame] | 5726 | } |
Narayan Kamath | 0ebc96c | 2017-12-29 13:32:38 +0000 | [diff] [blame] | 5727 | unoptimizedWorkChains.clear(); |
| 5728 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5729 | } |
| 5730 | } |
| 5731 | } |
| 5732 | |
Bookatz | 4ebc064 | 2017-05-11 12:21:19 -0700 | [diff] [blame] | 5733 | public void noteBluetoothScanResultsFromSourceLocked(WorkSource ws, int numNewResults) { |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 5734 | final int N = ws.size(); |
| 5735 | for (int i = 0; i < N; i++) { |
| 5736 | int uid = mapUid(ws.get(i)); |
Bookatz | 4ebc064 | 2017-05-11 12:21:19 -0700 | [diff] [blame] | 5737 | getUidStatsLocked(uid).noteBluetoothScanResultsLocked(numNewResults); |
Yangster-mac | 2f5daec | 2018-01-16 10:23:15 -0800 | [diff] [blame] | 5738 | StatsLog.write_non_chained(StatsLog.BLE_SCAN_RESULT_RECEIVED, ws.get(i), ws.getName(i), |
| 5739 | numNewResults); |
Narayan Kamath | 0ebc96c | 2017-12-29 13:32:38 +0000 | [diff] [blame] | 5740 | } |
| 5741 | |
| 5742 | final List<WorkChain> workChains = ws.getWorkChains(); |
| 5743 | if (workChains != null) { |
| 5744 | for (int i = 0; i < workChains.size(); ++i) { |
| 5745 | final WorkChain wc = workChains.get(i); |
| 5746 | int uid = mapUid(wc.getAttributionUid()); |
| 5747 | getUidStatsLocked(uid).noteBluetoothScanResultsLocked(numNewResults); |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 5748 | StatsLog.write(StatsLog.BLE_SCAN_RESULT_RECEIVED, |
| 5749 | wc.getUids(), wc.getTags(), numNewResults); |
Narayan Kamath | 0ebc96c | 2017-12-29 13:32:38 +0000 | [diff] [blame] | 5750 | } |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 5751 | } |
| 5752 | } |
| 5753 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 5754 | private void noteWifiRadioApWakeupLocked(final long elapsedRealtimeMillis, |
| 5755 | final long uptimeMillis, int uid) { |
| 5756 | uid = mapUid(uid); |
| 5757 | addHistoryEventLocked(elapsedRealtimeMillis, uptimeMillis, HistoryItem.EVENT_WAKEUP_AP, "", |
| 5758 | uid); |
| 5759 | getUidStatsLocked(uid).noteWifiRadioApWakeupLocked(); |
| 5760 | } |
| 5761 | |
| 5762 | public void noteWifiRadioPowerState(int powerState, long timestampNs, int uid) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5763 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5764 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 5765 | if (mWifiRadioPowerState != powerState) { |
| 5766 | final boolean active = |
| 5767 | powerState == DataConnectionRealTimeInfo.DC_POWER_STATE_MEDIUM |
| 5768 | || powerState == DataConnectionRealTimeInfo.DC_POWER_STATE_HIGH; |
| 5769 | if (active) { |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 5770 | if (uid > 0) { |
| 5771 | noteWifiRadioApWakeupLocked(elapsedRealtime, uptime, uid); |
| 5772 | } |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 5773 | mHistoryCur.states |= HistoryItem.STATE_WIFI_RADIO_ACTIVE_FLAG; |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 5774 | mWifiActiveTimer.startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 5775 | } else { |
| 5776 | mHistoryCur.states &= ~HistoryItem.STATE_WIFI_RADIO_ACTIVE_FLAG; |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 5777 | mWifiActiveTimer.stopRunningLocked( |
| 5778 | timestampNs / (1000 * 1000)); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 5779 | } |
| 5780 | if (DEBUG_HISTORY) Slog.v(TAG, "Wifi network active " + active + " to: " |
| 5781 | + Integer.toHexString(mHistoryCur.states)); |
| 5782 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 5783 | mWifiRadioPowerState = powerState; |
Bookatz | ddccf0a | 2017-11-28 16:48:14 -0800 | [diff] [blame] | 5784 | StatsLog.write(StatsLog.WIFI_RADIO_POWER_STATE_CHANGED, uid, powerState); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 5785 | } |
| 5786 | } |
| 5787 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5788 | public void noteWifiRunningLocked(WorkSource ws) { |
| 5789 | if (!mGlobalWifiRunning) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5790 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5791 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5792 | mHistoryCur.states2 |= HistoryItem.STATE2_WIFI_RUNNING_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5793 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI running to: " |
| 5794 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 5795 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5796 | mGlobalWifiRunning = true; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5797 | mGlobalWifiRunningTimer.startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5798 | int N = ws.size(); |
| 5799 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5800 | int uid = mapUid(ws.get(i)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5801 | getUidStatsLocked(uid).noteWifiRunningLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5802 | } |
Narayan Kamath | 728c8a0 | 2017-12-28 15:48:07 +0000 | [diff] [blame] | 5803 | |
| 5804 | List<WorkChain> workChains = ws.getWorkChains(); |
| 5805 | if (workChains != null) { |
| 5806 | for (int i = 0; i < workChains.size(); ++i) { |
| 5807 | int uid = mapUid(workChains.get(i).getAttributionUid()); |
| 5808 | getUidStatsLocked(uid).noteWifiRunningLocked(elapsedRealtime); |
| 5809 | } |
| 5810 | } |
| 5811 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5812 | scheduleSyncExternalStatsLocked("wifi-running", ExternalStatsSync.UPDATE_WIFI); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5813 | } else { |
| 5814 | Log.w(TAG, "noteWifiRunningLocked -- called while WIFI running"); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 5815 | } |
| 5816 | } |
| 5817 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5818 | public void noteWifiRunningChangedLocked(WorkSource oldWs, WorkSource newWs) { |
| 5819 | if (mGlobalWifiRunning) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5820 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5821 | int N = oldWs.size(); |
| 5822 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5823 | int uid = mapUid(oldWs.get(i)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5824 | getUidStatsLocked(uid).noteWifiStoppedLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5825 | } |
Narayan Kamath | 728c8a0 | 2017-12-28 15:48:07 +0000 | [diff] [blame] | 5826 | |
| 5827 | List<WorkChain> workChains = oldWs.getWorkChains(); |
| 5828 | if (workChains != null) { |
| 5829 | for (int i = 0; i < workChains.size(); ++i) { |
| 5830 | int uid = mapUid(workChains.get(i).getAttributionUid()); |
| 5831 | getUidStatsLocked(uid).noteWifiStoppedLocked(elapsedRealtime); |
| 5832 | } |
| 5833 | } |
| 5834 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5835 | N = newWs.size(); |
| 5836 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5837 | int uid = mapUid(newWs.get(i)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5838 | getUidStatsLocked(uid).noteWifiRunningLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5839 | } |
Narayan Kamath | 728c8a0 | 2017-12-28 15:48:07 +0000 | [diff] [blame] | 5840 | |
| 5841 | workChains = newWs.getWorkChains(); |
| 5842 | if (workChains != null) { |
| 5843 | for (int i = 0; i < workChains.size(); ++i) { |
| 5844 | int uid = mapUid(workChains.get(i).getAttributionUid()); |
| 5845 | getUidStatsLocked(uid).noteWifiRunningLocked(elapsedRealtime); |
| 5846 | } |
| 5847 | } |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5848 | } else { |
| 5849 | Log.w(TAG, "noteWifiRunningChangedLocked -- called while WIFI not running"); |
| 5850 | } |
| 5851 | } |
| 5852 | |
| 5853 | public void noteWifiStoppedLocked(WorkSource ws) { |
| 5854 | if (mGlobalWifiRunning) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5855 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5856 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5857 | mHistoryCur.states2 &= ~HistoryItem.STATE2_WIFI_RUNNING_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5858 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI stopped to: " |
| 5859 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 5860 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5861 | mGlobalWifiRunning = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5862 | mGlobalWifiRunningTimer.stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5863 | int N = ws.size(); |
| 5864 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5865 | int uid = mapUid(ws.get(i)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5866 | getUidStatsLocked(uid).noteWifiStoppedLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5867 | } |
Narayan Kamath | 728c8a0 | 2017-12-28 15:48:07 +0000 | [diff] [blame] | 5868 | |
| 5869 | List<WorkChain> workChains = ws.getWorkChains(); |
| 5870 | if (workChains != null) { |
| 5871 | for (int i = 0; i < workChains.size(); ++i) { |
| 5872 | int uid = mapUid(workChains.get(i).getAttributionUid()); |
| 5873 | getUidStatsLocked(uid).noteWifiStoppedLocked(elapsedRealtime); |
| 5874 | } |
| 5875 | } |
| 5876 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5877 | scheduleSyncExternalStatsLocked("wifi-stopped", ExternalStatsSync.UPDATE_WIFI); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5878 | } else { |
| 5879 | Log.w(TAG, "noteWifiStoppedLocked -- called while WIFI not running"); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 5880 | } |
| 5881 | } |
| 5882 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5883 | public void noteWifiStateLocked(int wifiState, String accessPoint) { |
| 5884 | if (DEBUG) Log.i(TAG, "WiFi state -> " + wifiState); |
| 5885 | if (mWifiState != wifiState) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5886 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5887 | if (mWifiState >= 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5888 | mWifiStateTimer[mWifiState].stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5889 | } |
| 5890 | mWifiState = wifiState; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5891 | mWifiStateTimer[wifiState].startRunningLocked(elapsedRealtime); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5892 | scheduleSyncExternalStatsLocked("wifi-state", ExternalStatsSync.UPDATE_WIFI); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5893 | } |
| 5894 | } |
| 5895 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5896 | public void noteWifiSupplicantStateChangedLocked(int supplState, boolean failedAuth) { |
| 5897 | if (DEBUG) Log.i(TAG, "WiFi suppl state -> " + supplState); |
| 5898 | if (mWifiSupplState != supplState) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5899 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5900 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5901 | if (mWifiSupplState >= 0) { |
| 5902 | mWifiSupplStateTimer[mWifiSupplState].stopRunningLocked(elapsedRealtime); |
| 5903 | } |
| 5904 | mWifiSupplState = supplState; |
| 5905 | mWifiSupplStateTimer[supplState].startRunningLocked(elapsedRealtime); |
| 5906 | mHistoryCur.states2 = |
| 5907 | (mHistoryCur.states2&~HistoryItem.STATE2_WIFI_SUPPL_STATE_MASK) |
| 5908 | | (supplState << HistoryItem.STATE2_WIFI_SUPPL_STATE_SHIFT); |
| 5909 | if (DEBUG_HISTORY) Slog.v(TAG, "Wifi suppl state " + supplState + " to: " |
| 5910 | + Integer.toHexString(mHistoryCur.states2)); |
| 5911 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 5912 | } |
| 5913 | } |
| 5914 | |
| 5915 | void stopAllWifiSignalStrengthTimersLocked(int except) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5916 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5917 | for (int i = 0; i < NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 5918 | if (i == except) { |
| 5919 | continue; |
| 5920 | } |
| 5921 | while (mWifiSignalStrengthsTimer[i].isRunningLocked()) { |
| 5922 | mWifiSignalStrengthsTimer[i].stopRunningLocked(elapsedRealtime); |
| 5923 | } |
| 5924 | } |
| 5925 | } |
| 5926 | |
| 5927 | public void noteWifiRssiChangedLocked(int newRssi) { |
| 5928 | int strengthBin = WifiManager.calculateSignalLevel(newRssi, NUM_WIFI_SIGNAL_STRENGTH_BINS); |
| 5929 | if (DEBUG) Log.i(TAG, "WiFi rssi -> " + newRssi + " bin=" + strengthBin); |
| 5930 | if (mWifiSignalStrengthBin != strengthBin) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5931 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5932 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5933 | if (mWifiSignalStrengthBin >= 0) { |
| 5934 | mWifiSignalStrengthsTimer[mWifiSignalStrengthBin].stopRunningLocked( |
| 5935 | elapsedRealtime); |
| 5936 | } |
| 5937 | if (strengthBin >= 0) { |
| 5938 | if (!mWifiSignalStrengthsTimer[strengthBin].isRunningLocked()) { |
| 5939 | mWifiSignalStrengthsTimer[strengthBin].startRunningLocked(elapsedRealtime); |
Bookatz | e588524 | 2017-10-24 20:10:31 -0700 | [diff] [blame] | 5940 | StatsLog.write(StatsLog.WIFI_SIGNAL_STRENGTH_CHANGED, strengthBin); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5941 | } |
| 5942 | mHistoryCur.states2 = |
| 5943 | (mHistoryCur.states2&~HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_MASK) |
| 5944 | | (strengthBin << HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_SHIFT); |
| 5945 | if (DEBUG_HISTORY) Slog.v(TAG, "Wifi signal strength " + strengthBin + " to: " |
| 5946 | + Integer.toHexString(mHistoryCur.states2)); |
| 5947 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 5948 | } else { |
| 5949 | stopAllWifiSignalStrengthTimersLocked(-1); |
| 5950 | } |
| 5951 | mWifiSignalStrengthBin = strengthBin; |
| 5952 | } |
| 5953 | } |
| 5954 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5955 | int mWifiFullLockNesting = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5956 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5957 | public void noteFullWifiLockAcquiredLocked(int uid) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5958 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5959 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5960 | if (mWifiFullLockNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5961 | mHistoryCur.states |= HistoryItem.STATE_WIFI_FULL_LOCK_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5962 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI full lock on to: " |
| 5963 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 5964 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5965 | } |
| 5966 | mWifiFullLockNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5967 | getUidStatsLocked(uid).noteFullWifiLockAcquiredLocked(elapsedRealtime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5968 | } |
| 5969 | |
| 5970 | public void noteFullWifiLockReleasedLocked(int uid) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5971 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5972 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5973 | mWifiFullLockNesting--; |
| 5974 | if (mWifiFullLockNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5975 | mHistoryCur.states &= ~HistoryItem.STATE_WIFI_FULL_LOCK_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5976 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI full lock off to: " |
| 5977 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 5978 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5979 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5980 | getUidStatsLocked(uid).noteFullWifiLockReleasedLocked(elapsedRealtime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5981 | } |
| 5982 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5983 | int mWifiScanNesting = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5984 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5985 | public void noteWifiScanStartedLocked(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(); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5988 | if (mWifiScanNesting == 0) { |
| 5989 | mHistoryCur.states |= HistoryItem.STATE_WIFI_SCAN_FLAG; |
| 5990 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI scan started for: " |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5991 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 5992 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5993 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5994 | mWifiScanNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5995 | getUidStatsLocked(uid).noteWifiScanStartedLocked(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 | public void noteWifiScanStoppedLocked(int uid) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5999 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 6000 | final long uptime = mClocks.uptimeMillis(); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 6001 | mWifiScanNesting--; |
| 6002 | if (mWifiScanNesting == 0) { |
| 6003 | mHistoryCur.states &= ~HistoryItem.STATE_WIFI_SCAN_FLAG; |
| 6004 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI scan stopped for: " |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 6005 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 6006 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 6007 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 6008 | getUidStatsLocked(uid).noteWifiScanStoppedLocked(elapsedRealtime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6009 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 6010 | |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6011 | public void noteWifiBatchedScanStartedLocked(int uid, int csph) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6012 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6013 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 6014 | getUidStatsLocked(uid).noteWifiBatchedScanStartedLocked(csph, elapsedRealtime); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6015 | } |
| 6016 | |
| 6017 | public void noteWifiBatchedScanStoppedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6018 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6019 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 6020 | getUidStatsLocked(uid).noteWifiBatchedScanStoppedLocked(elapsedRealtime); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6021 | } |
| 6022 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 6023 | int mWifiMulticastNesting = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6024 | |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 6025 | public void noteWifiMulticastEnabledLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6026 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6027 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 6028 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 6029 | if (mWifiMulticastNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6030 | mHistoryCur.states |= HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 6031 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI multicast on to: " |
| 6032 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 6033 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 6034 | |
| 6035 | // Start Wifi Multicast overall timer |
| 6036 | if (!mWifiMulticastWakelockTimer.isRunningLocked()) { |
| 6037 | if (DEBUG_HISTORY) Slog.v(TAG, "WiFi Multicast Overall Timer Started"); |
| 6038 | mWifiMulticastWakelockTimer.startRunningLocked(elapsedRealtime); |
| 6039 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 6040 | } |
| 6041 | mWifiMulticastNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 6042 | getUidStatsLocked(uid).noteWifiMulticastEnabledLocked(elapsedRealtime); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 6043 | } |
| 6044 | |
| 6045 | public void noteWifiMulticastDisabledLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6046 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6047 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 6048 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 6049 | mWifiMulticastNesting--; |
| 6050 | if (mWifiMulticastNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6051 | mHistoryCur.states &= ~HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 6052 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI multicast off to: " |
| 6053 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 6054 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 6055 | |
| 6056 | // Stop Wifi Multicast overall timer |
| 6057 | if (mWifiMulticastWakelockTimer.isRunningLocked()) { |
| 6058 | if (DEBUG_HISTORY) Slog.v(TAG, "Multicast Overall Timer Stopped"); |
| 6059 | mWifiMulticastWakelockTimer.stopRunningLocked(elapsedRealtime); |
| 6060 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 6061 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 6062 | getUidStatsLocked(uid).noteWifiMulticastDisabledLocked(elapsedRealtime); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 6063 | } |
| 6064 | |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 6065 | public void noteFullWifiLockAcquiredFromSourceLocked(WorkSource ws) { |
| 6066 | int N = ws.size(); |
| 6067 | for (int i=0; i<N; i++) { |
Narayan Kamath | 728c8a0 | 2017-12-28 15:48:07 +0000 | [diff] [blame] | 6068 | final int uid = mapUid(ws.get(i)); |
| 6069 | noteFullWifiLockAcquiredLocked(uid); |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 6070 | StatsLog.write_non_chained(StatsLog.WIFI_LOCK_STATE_CHANGED, ws.get(i), ws.getName(i), |
| 6071 | StatsLog.WIFI_LOCK_STATE_CHANGED__STATE__ON); |
Narayan Kamath | 728c8a0 | 2017-12-28 15:48:07 +0000 | [diff] [blame] | 6072 | } |
| 6073 | |
| 6074 | final List<WorkChain> workChains = ws.getWorkChains(); |
| 6075 | if (workChains != null) { |
| 6076 | for (int i = 0; i < workChains.size(); ++i) { |
| 6077 | final WorkChain workChain = workChains.get(i); |
| 6078 | final int uid = mapUid(workChain.getAttributionUid()); |
| 6079 | noteFullWifiLockAcquiredLocked(uid); |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 6080 | StatsLog.write(StatsLog.WIFI_LOCK_STATE_CHANGED, |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 6081 | workChain.getUids(), workChain.getTags(), |
| 6082 | StatsLog.WIFI_LOCK_STATE_CHANGED__STATE__ON); |
Narayan Kamath | 728c8a0 | 2017-12-28 15:48:07 +0000 | [diff] [blame] | 6083 | } |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 6084 | } |
| 6085 | } |
| 6086 | |
| 6087 | public void noteFullWifiLockReleasedFromSourceLocked(WorkSource ws) { |
| 6088 | int N = ws.size(); |
| 6089 | for (int i=0; i<N; i++) { |
Narayan Kamath | 728c8a0 | 2017-12-28 15:48:07 +0000 | [diff] [blame] | 6090 | final int uid = mapUid(ws.get(i)); |
| 6091 | noteFullWifiLockReleasedLocked(uid); |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 6092 | StatsLog.write_non_chained(StatsLog.WIFI_LOCK_STATE_CHANGED, ws.get(i), ws.getName(i), |
| 6093 | StatsLog.WIFI_LOCK_STATE_CHANGED__STATE__OFF); |
Narayan Kamath | 728c8a0 | 2017-12-28 15:48:07 +0000 | [diff] [blame] | 6094 | } |
| 6095 | |
| 6096 | final List<WorkChain> workChains = ws.getWorkChains(); |
| 6097 | if (workChains != null) { |
| 6098 | for (int i = 0; i < workChains.size(); ++i) { |
| 6099 | final WorkChain workChain = workChains.get(i); |
| 6100 | final int uid = mapUid(workChain.getAttributionUid()); |
| 6101 | noteFullWifiLockReleasedLocked(uid); |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 6102 | StatsLog.write(StatsLog.WIFI_LOCK_STATE_CHANGED, |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 6103 | workChain.getUids(), workChain.getTags(), |
| 6104 | StatsLog.WIFI_LOCK_STATE_CHANGED__STATE__OFF); |
Narayan Kamath | 728c8a0 | 2017-12-28 15:48:07 +0000 | [diff] [blame] | 6105 | } |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 6106 | } |
| 6107 | } |
| 6108 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 6109 | public void noteWifiScanStartedFromSourceLocked(WorkSource ws) { |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 6110 | int N = ws.size(); |
| 6111 | for (int i=0; i<N; i++) { |
Narayan Kamath | 728c8a0 | 2017-12-28 15:48:07 +0000 | [diff] [blame] | 6112 | final int uid = mapUid(ws.get(i)); |
| 6113 | noteWifiScanStartedLocked(uid); |
Yangster-mac | 2f5daec | 2018-01-16 10:23:15 -0800 | [diff] [blame] | 6114 | 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] | 6115 | StatsLog.WIFI_SCAN_STATE_CHANGED__STATE__ON); |
Narayan Kamath | 728c8a0 | 2017-12-28 15:48:07 +0000 | [diff] [blame] | 6116 | } |
| 6117 | |
| 6118 | final List<WorkChain> workChains = ws.getWorkChains(); |
| 6119 | if (workChains != null) { |
| 6120 | for (int i = 0; i < workChains.size(); ++i) { |
| 6121 | final WorkChain workChain = workChains.get(i); |
| 6122 | final int uid = mapUid(workChain.getAttributionUid()); |
| 6123 | noteWifiScanStartedLocked(uid); |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 6124 | StatsLog.write(StatsLog.WIFI_SCAN_STATE_CHANGED, workChain.getUids(), |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 6125 | workChain.getTags(), StatsLog.WIFI_SCAN_STATE_CHANGED__STATE__ON); |
Narayan Kamath | 728c8a0 | 2017-12-28 15:48:07 +0000 | [diff] [blame] | 6126 | } |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 6127 | } |
| 6128 | } |
| 6129 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 6130 | public void noteWifiScanStoppedFromSourceLocked(WorkSource ws) { |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 6131 | int N = ws.size(); |
| 6132 | for (int i=0; i<N; i++) { |
Narayan Kamath | 728c8a0 | 2017-12-28 15:48:07 +0000 | [diff] [blame] | 6133 | final int uid = mapUid(ws.get(i)); |
| 6134 | noteWifiScanStoppedLocked(uid); |
Yangster-mac | 2f5daec | 2018-01-16 10:23:15 -0800 | [diff] [blame] | 6135 | 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] | 6136 | StatsLog.WIFI_SCAN_STATE_CHANGED__STATE__OFF); |
Narayan Kamath | 728c8a0 | 2017-12-28 15:48:07 +0000 | [diff] [blame] | 6137 | } |
| 6138 | |
| 6139 | final List<WorkChain> workChains = ws.getWorkChains(); |
| 6140 | if (workChains != null) { |
| 6141 | for (int i = 0; i < workChains.size(); ++i) { |
| 6142 | final WorkChain workChain = workChains.get(i); |
| 6143 | final int uid = mapUid(workChain.getAttributionUid()); |
| 6144 | noteWifiScanStoppedLocked(uid); |
Yangster-mac | afad8c6 | 2018-01-05 22:30:49 -0800 | [diff] [blame] | 6145 | StatsLog.write(StatsLog.WIFI_SCAN_STATE_CHANGED, |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 6146 | workChain.getUids(), workChain.getTags(), |
| 6147 | StatsLog.WIFI_SCAN_STATE_CHANGED__STATE__OFF); |
Narayan Kamath | 728c8a0 | 2017-12-28 15:48:07 +0000 | [diff] [blame] | 6148 | } |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 6149 | } |
| 6150 | } |
| 6151 | |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6152 | public void noteWifiBatchedScanStartedFromSourceLocked(WorkSource ws, int csph) { |
| 6153 | int N = ws.size(); |
| 6154 | for (int i=0; i<N; i++) { |
| 6155 | noteWifiBatchedScanStartedLocked(ws.get(i), csph); |
| 6156 | } |
Narayan Kamath | 728c8a0 | 2017-12-28 15:48:07 +0000 | [diff] [blame] | 6157 | |
| 6158 | final List<WorkChain> workChains = ws.getWorkChains(); |
| 6159 | if (workChains != null) { |
| 6160 | for (int i = 0; i < workChains.size(); ++i) { |
| 6161 | noteWifiBatchedScanStartedLocked(workChains.get(i).getAttributionUid(), csph); |
| 6162 | } |
| 6163 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6164 | } |
| 6165 | |
| 6166 | public void noteWifiBatchedScanStoppedFromSourceLocked(WorkSource ws) { |
| 6167 | int N = ws.size(); |
| 6168 | for (int i=0; i<N; i++) { |
| 6169 | noteWifiBatchedScanStoppedLocked(ws.get(i)); |
| 6170 | } |
Narayan Kamath | 728c8a0 | 2017-12-28 15:48:07 +0000 | [diff] [blame] | 6171 | |
| 6172 | final List<WorkChain> workChains = ws.getWorkChains(); |
| 6173 | if (workChains != null) { |
| 6174 | for (int i = 0; i < workChains.size(); ++i) { |
| 6175 | noteWifiBatchedScanStoppedLocked(workChains.get(i).getAttributionUid()); |
| 6176 | } |
| 6177 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6178 | } |
| 6179 | |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 6180 | private static String[] includeInStringArray(String[] array, String str) { |
| 6181 | if (ArrayUtils.indexOf(array, str) >= 0) { |
| 6182 | return array; |
| 6183 | } |
| 6184 | String[] newArray = new String[array.length+1]; |
| 6185 | System.arraycopy(array, 0, newArray, 0, array.length); |
| 6186 | newArray[array.length] = str; |
| 6187 | return newArray; |
| 6188 | } |
| 6189 | |
| 6190 | private static String[] excludeFromStringArray(String[] array, String str) { |
| 6191 | int index = ArrayUtils.indexOf(array, str); |
| 6192 | if (index >= 0) { |
| 6193 | String[] newArray = new String[array.length-1]; |
| 6194 | if (index > 0) { |
| 6195 | System.arraycopy(array, 0, newArray, 0, index); |
| 6196 | } |
| 6197 | if (index < array.length-1) { |
| 6198 | System.arraycopy(array, index+1, newArray, index, array.length-index-1); |
| 6199 | } |
| 6200 | return newArray; |
| 6201 | } |
| 6202 | return array; |
| 6203 | } |
| 6204 | |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 6205 | public void noteNetworkInterfaceTypeLocked(String iface, int networkType) { |
Jeff Sharkey | 9da2f1e | 2014-08-14 12:55:00 -0700 | [diff] [blame] | 6206 | if (TextUtils.isEmpty(iface)) return; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6207 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 6208 | synchronized (mModemNetworkLock) { |
| 6209 | if (ConnectivityManager.isNetworkTypeMobile(networkType)) { |
| 6210 | mModemIfaces = includeInStringArray(mModemIfaces, iface); |
| 6211 | if (DEBUG) Slog.d(TAG, "Note mobile iface " + iface + ": " + mModemIfaces); |
| 6212 | } else { |
| 6213 | mModemIfaces = excludeFromStringArray(mModemIfaces, iface); |
| 6214 | if (DEBUG) Slog.d(TAG, "Note non-mobile iface " + iface + ": " + mModemIfaces); |
| 6215 | } |
| 6216 | } |
| 6217 | |
| 6218 | synchronized (mWifiNetworkLock) { |
| 6219 | if (ConnectivityManager.isNetworkTypeWifi(networkType)) { |
| 6220 | mWifiIfaces = includeInStringArray(mWifiIfaces, iface); |
| 6221 | if (DEBUG) Slog.d(TAG, "Note wifi iface " + iface + ": " + mWifiIfaces); |
| 6222 | } else { |
| 6223 | mWifiIfaces = excludeFromStringArray(mWifiIfaces, iface); |
| 6224 | if (DEBUG) Slog.d(TAG, "Note non-wifi iface " + iface + ": " + mWifiIfaces); |
| 6225 | } |
| 6226 | } |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 6227 | } |
| 6228 | |
David Chen | c8a4324 | 2017-10-17 16:23:28 -0700 | [diff] [blame] | 6229 | public String[] getWifiIfaces() { |
| 6230 | synchronized (mWifiNetworkLock) { |
| 6231 | return mWifiIfaces; |
| 6232 | } |
| 6233 | } |
| 6234 | |
| 6235 | public String[] getMobileIfaces() { |
| 6236 | synchronized (mModemNetworkLock) { |
| 6237 | return mModemIfaces; |
| 6238 | } |
| 6239 | } |
| 6240 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6241 | @Override public long getScreenOnTime(long elapsedRealtimeUs, int which) { |
| 6242 | return mScreenOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6243 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6244 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 6245 | @Override public int getScreenOnCount(int which) { |
| 6246 | return mScreenOnTimer.getCountLocked(which); |
| 6247 | } |
| 6248 | |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 6249 | @Override public long getScreenDozeTime(long elapsedRealtimeUs, int which) { |
| 6250 | return mScreenDozeTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 6251 | } |
| 6252 | |
| 6253 | @Override public int getScreenDozeCount(int which) { |
| 6254 | return mScreenDozeTimer.getCountLocked(which); |
| 6255 | } |
| 6256 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6257 | @Override public long getScreenBrightnessTime(int brightnessBin, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6258 | long elapsedRealtimeUs, int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6259 | return mScreenBrightnessTimer[brightnessBin].getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6260 | elapsedRealtimeUs, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6261 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 6262 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 6263 | @Override public Timer getScreenBrightnessTimer(int brightnessBin) { |
| 6264 | return mScreenBrightnessTimer[brightnessBin]; |
| 6265 | } |
| 6266 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 6267 | @Override public long getInteractiveTime(long elapsedRealtimeUs, int which) { |
| 6268 | return mInteractiveTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6269 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6270 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 6271 | @Override public long getPowerSaveModeEnabledTime(long elapsedRealtimeUs, int which) { |
| 6272 | return mPowerSaveModeEnabledTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 6273 | } |
| 6274 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 6275 | @Override public int getPowerSaveModeEnabledCount(int which) { |
| 6276 | return mPowerSaveModeEnabledTimer.getCountLocked(which); |
| 6277 | } |
| 6278 | |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 6279 | @Override public long getDeviceIdleModeTime(int mode, long elapsedRealtimeUs, |
| 6280 | int which) { |
| 6281 | switch (mode) { |
| 6282 | case DEVICE_IDLE_MODE_LIGHT: |
| 6283 | return mDeviceIdleModeLightTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 6284 | case DEVICE_IDLE_MODE_DEEP: |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 6285 | return mDeviceIdleModeFullTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 6286 | } |
| 6287 | return 0; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 6288 | } |
| 6289 | |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 6290 | @Override public int getDeviceIdleModeCount(int mode, int which) { |
| 6291 | switch (mode) { |
| 6292 | case DEVICE_IDLE_MODE_LIGHT: |
| 6293 | return mDeviceIdleModeLightTimer.getCountLocked(which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 6294 | case DEVICE_IDLE_MODE_DEEP: |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 6295 | return mDeviceIdleModeFullTimer.getCountLocked(which); |
| 6296 | } |
| 6297 | return 0; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 6298 | } |
| 6299 | |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 6300 | @Override public long getLongestDeviceIdleModeTime(int mode) { |
| 6301 | switch (mode) { |
| 6302 | case DEVICE_IDLE_MODE_LIGHT: |
| 6303 | return mLongestLightIdleTime; |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 6304 | case DEVICE_IDLE_MODE_DEEP: |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 6305 | return mLongestFullIdleTime; |
| 6306 | } |
| 6307 | return 0; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6308 | } |
| 6309 | |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 6310 | @Override public long getDeviceIdlingTime(int mode, long elapsedRealtimeUs, int which) { |
| 6311 | switch (mode) { |
| 6312 | case DEVICE_IDLE_MODE_LIGHT: |
| 6313 | return mDeviceLightIdlingTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 6314 | case DEVICE_IDLE_MODE_DEEP: |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 6315 | return mDeviceIdlingTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 6316 | } |
| 6317 | return 0; |
| 6318 | } |
| 6319 | |
| 6320 | @Override public int getDeviceIdlingCount(int mode, int which) { |
| 6321 | switch (mode) { |
| 6322 | case DEVICE_IDLE_MODE_LIGHT: |
| 6323 | return mDeviceLightIdlingTimer.getCountLocked(which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 6324 | case DEVICE_IDLE_MODE_DEEP: |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 6325 | return mDeviceIdlingTimer.getCountLocked(which); |
| 6326 | } |
| 6327 | return 0; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6328 | } |
| 6329 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6330 | @Override public int getNumConnectivityChange(int which) { |
| 6331 | int val = mNumConnectivityChange; |
| 6332 | if (which == STATS_CURRENT) { |
| 6333 | val -= mLoadedNumConnectivityChange; |
| 6334 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 6335 | val -= mUnpluggedNumConnectivityChange; |
| 6336 | } |
| 6337 | return val; |
| 6338 | } |
| 6339 | |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 6340 | @Override public long getGpsSignalQualityTime(int strengthBin, |
| 6341 | long elapsedRealtimeUs, int which) { |
| 6342 | if (strengthBin < 0 || strengthBin >= GnssMetrics.NUM_GPS_SIGNAL_QUALITY_LEVELS) { |
| 6343 | return 0; |
| 6344 | } |
| 6345 | return mGpsSignalQualityTimer[strengthBin].getTotalTimeLocked( |
| 6346 | elapsedRealtimeUs, which); |
| 6347 | } |
| 6348 | |
| 6349 | @Override public long getGpsBatteryDrainMaMs() { |
Siddharth Ray | 0ed2e95 | 2018-01-22 11:32:14 -0800 | [diff] [blame] | 6350 | final double opVolt = mPowerProfile.getAveragePower( |
| 6351 | PowerProfile.POWER_GPS_OPERATING_VOLTAGE) / 1000.0; |
| 6352 | if (opVolt == 0) { |
| 6353 | return 0; |
| 6354 | } |
| 6355 | double energyUsedMaMs = 0.0; |
| 6356 | final int which = STATS_SINCE_CHARGED; |
| 6357 | final long rawRealtime = SystemClock.elapsedRealtime() * 1000; |
| 6358 | for(int i=0; i < GnssMetrics.NUM_GPS_SIGNAL_QUALITY_LEVELS; i++) { |
| 6359 | energyUsedMaMs |
| 6360 | += mPowerProfile.getAveragePower(PowerProfile.POWER_GPS_SIGNAL_QUALITY_BASED, i) |
| 6361 | * (getGpsSignalQualityTime(i, rawRealtime, which) / 1000); |
| 6362 | } |
| 6363 | return (long) energyUsedMaMs; |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 6364 | } |
| 6365 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6366 | @Override public long getPhoneOnTime(long elapsedRealtimeUs, int which) { |
| 6367 | return mPhoneOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6368 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 6369 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 6370 | @Override public int getPhoneOnCount(int which) { |
| 6371 | return mPhoneOnTimer.getCountLocked(which); |
| 6372 | } |
| 6373 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 6374 | @Override public long getPhoneSignalStrengthTime(int strengthBin, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6375 | long elapsedRealtimeUs, int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6376 | return mPhoneSignalStrengthsTimer[strengthBin].getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6377 | elapsedRealtimeUs, which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 6378 | } |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 6379 | |
| 6380 | @Override public long getPhoneSignalScanningTime( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6381 | long elapsedRealtimeUs, int which) { |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 6382 | return mPhoneSignalScanningTimer.getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6383 | elapsedRealtimeUs, which); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 6384 | } |
| 6385 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 6386 | @Override public Timer getPhoneSignalScanningTimer() { |
| 6387 | return mPhoneSignalScanningTimer; |
| 6388 | } |
| 6389 | |
Catherine Liu | fb90081 | 2012-07-17 14:12:56 -0500 | [diff] [blame] | 6390 | @Override public int getPhoneSignalStrengthCount(int strengthBin, int which) { |
| 6391 | return mPhoneSignalStrengthsTimer[strengthBin].getCountLocked(which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6392 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6393 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 6394 | @Override public Timer getPhoneSignalStrengthTimer(int strengthBin) { |
| 6395 | return mPhoneSignalStrengthsTimer[strengthBin]; |
| 6396 | } |
| 6397 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 6398 | @Override public long getPhoneDataConnectionTime(int dataType, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6399 | long elapsedRealtimeUs, int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6400 | return mPhoneDataConnectionsTimer[dataType].getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6401 | elapsedRealtimeUs, which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 6402 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6403 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6404 | @Override public int getPhoneDataConnectionCount(int dataType, int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6405 | return mPhoneDataConnectionsTimer[dataType].getCountLocked(which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6406 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6407 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 6408 | @Override public Timer getPhoneDataConnectionTimer(int dataType) { |
| 6409 | return mPhoneDataConnectionsTimer[dataType]; |
| 6410 | } |
| 6411 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6412 | @Override public long getMobileRadioActiveTime(long elapsedRealtimeUs, int which) { |
| 6413 | return mMobileRadioActiveTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 6414 | } |
| 6415 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 6416 | @Override public int getMobileRadioActiveCount(int which) { |
| 6417 | return mMobileRadioActiveTimer.getCountLocked(which); |
| 6418 | } |
| 6419 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 6420 | @Override public long getMobileRadioActiveAdjustedTime(int which) { |
| 6421 | return mMobileRadioActiveAdjustedTime.getCountLocked(which); |
| 6422 | } |
| 6423 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 6424 | @Override public long getMobileRadioActiveUnknownTime(int which) { |
| 6425 | return mMobileRadioActiveUnknownTime.getCountLocked(which); |
| 6426 | } |
| 6427 | |
| 6428 | @Override public int getMobileRadioActiveUnknownCount(int which) { |
| 6429 | return (int)mMobileRadioActiveUnknownCount.getCountLocked(which); |
| 6430 | } |
| 6431 | |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 6432 | @Override public long getWifiMulticastWakelockTime( |
| 6433 | long elapsedRealtimeUs, int which) { |
| 6434 | return mWifiMulticastWakelockTimer.getTotalTimeLocked( |
| 6435 | elapsedRealtimeUs, which); |
| 6436 | } |
| 6437 | |
| 6438 | @Override public int getWifiMulticastWakelockCount(int which) { |
| 6439 | return mWifiMulticastWakelockTimer.getCountLocked(which); |
| 6440 | } |
| 6441 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6442 | @Override public long getWifiOnTime(long elapsedRealtimeUs, int which) { |
| 6443 | return mWifiOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6444 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6445 | |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 6446 | @Override public long getWifiActiveTime(long elapsedRealtimeUs, int which) { |
| 6447 | return mWifiActiveTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 6448 | } |
| 6449 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6450 | @Override public long getGlobalWifiRunningTime(long elapsedRealtimeUs, int which) { |
| 6451 | return mGlobalWifiRunningTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 6452 | } |
| 6453 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 6454 | @Override public long getWifiStateTime(int wifiState, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6455 | long elapsedRealtimeUs, int which) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 6456 | return mWifiStateTimer[wifiState].getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6457 | elapsedRealtimeUs, which); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 6458 | } |
| 6459 | |
| 6460 | @Override public int getWifiStateCount(int wifiState, int which) { |
| 6461 | return mWifiStateTimer[wifiState].getCountLocked(which); |
| 6462 | } |
| 6463 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 6464 | @Override public Timer getWifiStateTimer(int wifiState) { |
| 6465 | return mWifiStateTimer[wifiState]; |
| 6466 | } |
| 6467 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 6468 | @Override public long getWifiSupplStateTime(int state, |
| 6469 | long elapsedRealtimeUs, int which) { |
| 6470 | return mWifiSupplStateTimer[state].getTotalTimeLocked( |
| 6471 | elapsedRealtimeUs, which); |
| 6472 | } |
| 6473 | |
| 6474 | @Override public int getWifiSupplStateCount(int state, int which) { |
| 6475 | return mWifiSupplStateTimer[state].getCountLocked(which); |
| 6476 | } |
| 6477 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 6478 | @Override public Timer getWifiSupplStateTimer(int state) { |
| 6479 | return mWifiSupplStateTimer[state]; |
| 6480 | } |
| 6481 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 6482 | @Override public long getWifiSignalStrengthTime(int strengthBin, |
| 6483 | long elapsedRealtimeUs, int which) { |
| 6484 | return mWifiSignalStrengthsTimer[strengthBin].getTotalTimeLocked( |
| 6485 | elapsedRealtimeUs, which); |
| 6486 | } |
| 6487 | |
| 6488 | @Override public int getWifiSignalStrengthCount(int strengthBin, int which) { |
| 6489 | return mWifiSignalStrengthsTimer[strengthBin].getCountLocked(which); |
| 6490 | } |
| 6491 | |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 6492 | @Override public Timer getWifiSignalStrengthTimer(int strengthBin) { |
| 6493 | return mWifiSignalStrengthsTimer[strengthBin]; |
| 6494 | } |
| 6495 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6496 | @Override |
| 6497 | public ControllerActivityCounter getBluetoothControllerActivity() { |
| 6498 | return mBluetoothActivity; |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 6499 | } |
| 6500 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6501 | @Override |
| 6502 | public ControllerActivityCounter getWifiControllerActivity() { |
| 6503 | return mWifiActivity; |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 6504 | } |
| 6505 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6506 | @Override |
| 6507 | public ControllerActivityCounter getModemControllerActivity() { |
| 6508 | return mModemActivity; |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 6509 | } |
| 6510 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6511 | @Override |
| 6512 | public boolean hasBluetoothActivityReporting() { |
| 6513 | return mHasBluetoothReporting; |
| 6514 | } |
| 6515 | |
| 6516 | @Override |
| 6517 | public boolean hasWifiActivityReporting() { |
| 6518 | return mHasWifiReporting; |
| 6519 | } |
| 6520 | |
| 6521 | @Override |
| 6522 | public boolean hasModemActivityReporting() { |
| 6523 | return mHasModemReporting; |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 6524 | } |
| 6525 | |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 6526 | @Override |
| 6527 | public long getFlashlightOnTime(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 6528 | return mFlashlightOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 6529 | } |
| 6530 | |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 6531 | @Override |
| 6532 | public long getFlashlightOnCount(int which) { |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 6533 | return mFlashlightOnTimer.getCountLocked(which); |
| 6534 | } |
| 6535 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6536 | @Override |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 6537 | public long getCameraOnTime(long elapsedRealtimeUs, int which) { |
| 6538 | return mCameraOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 6539 | } |
| 6540 | |
| 6541 | @Override |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 6542 | public long getBluetoothScanTime(long elapsedRealtimeUs, int which) { |
| 6543 | return mBluetoothScanTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 6544 | } |
| 6545 | |
| 6546 | @Override |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6547 | public long getNetworkActivityBytes(int type, int which) { |
| 6548 | if (type >= 0 && type < mNetworkByteActivityCounters.length) { |
| 6549 | return mNetworkByteActivityCounters[type].getCountLocked(which); |
| 6550 | } else { |
| 6551 | return 0; |
| 6552 | } |
| 6553 | } |
| 6554 | |
| 6555 | @Override |
| 6556 | public long getNetworkActivityPackets(int type, int which) { |
| 6557 | if (type >= 0 && type < mNetworkPacketActivityCounters.length) { |
| 6558 | return mNetworkPacketActivityCounters[type].getCountLocked(which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6559 | } else { |
| 6560 | return 0; |
| 6561 | } |
| 6562 | } |
| 6563 | |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 6564 | @Override public long getStartClockTime() { |
Dianne Hackborn | d48954f | 2015-07-22 17:20:33 -0700 | [diff] [blame] | 6565 | final long currentTime = System.currentTimeMillis(); |
| 6566 | if (ensureStartClockTime(currentTime)) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6567 | recordCurrentTimeChangeLocked(currentTime, mClocks.elapsedRealtime(), |
| 6568 | mClocks.uptimeMillis()); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 6569 | } |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 6570 | return mStartClockTime; |
| 6571 | } |
| 6572 | |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 6573 | @Override public String getStartPlatformVersion() { |
| 6574 | return mStartPlatformVersion; |
| 6575 | } |
| 6576 | |
| 6577 | @Override public String getEndPlatformVersion() { |
| 6578 | return mEndPlatformVersion; |
| 6579 | } |
| 6580 | |
| 6581 | @Override public int getParcelVersion() { |
| 6582 | return VERSION; |
| 6583 | } |
| 6584 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6585 | @Override public boolean getIsOnBattery() { |
| 6586 | return mOnBattery; |
| 6587 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6588 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6589 | @Override public SparseArray<? extends BatteryStats.Uid> getUidStats() { |
| 6590 | return mUidStats; |
| 6591 | } |
| 6592 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 6593 | private static void detachTimerIfNotNull(BatteryStatsImpl.Timer timer) { |
| 6594 | if (timer != null) { |
| 6595 | timer.detach(); |
| 6596 | } |
| 6597 | } |
| 6598 | |
| 6599 | private static boolean resetTimerIfNotNull(BatteryStatsImpl.Timer timer, |
| 6600 | boolean detachIfReset) { |
| 6601 | if (timer != null) { |
| 6602 | return timer.reset(detachIfReset); |
| 6603 | } |
| 6604 | return true; |
| 6605 | } |
| 6606 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 6607 | private static boolean resetTimerIfNotNull(DualTimer timer, boolean detachIfReset) { |
| 6608 | if (timer != null) { |
| 6609 | return timer.reset(detachIfReset); |
| 6610 | } |
| 6611 | return true; |
| 6612 | } |
| 6613 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 6614 | private static void detachLongCounterIfNotNull(LongSamplingCounter counter) { |
| 6615 | if (counter != null) { |
| 6616 | counter.detach(); |
| 6617 | } |
| 6618 | } |
| 6619 | |
| 6620 | private static void resetLongCounterIfNotNull(LongSamplingCounter counter, |
| 6621 | boolean detachIfReset) { |
| 6622 | if (counter != null) { |
| 6623 | counter.reset(detachIfReset); |
| 6624 | } |
| 6625 | } |
| 6626 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6627 | /** |
| 6628 | * The statistics associated with a particular uid. |
| 6629 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6630 | public static class Uid extends BatteryStats.Uid { |
| 6631 | /** |
| 6632 | * BatteryStatsImpl that we are associated with. |
| 6633 | */ |
| 6634 | protected BatteryStatsImpl mBsi; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6635 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6636 | final int mUid; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6637 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 6638 | /** TimeBase for when uid is in background and device is on battery. */ |
| 6639 | @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 6640 | public final TimeBase mOnBatteryBackgroundTimeBase; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 6641 | @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 6642 | public final TimeBase mOnBatteryScreenOffBackgroundTimeBase; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 6643 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 6644 | boolean mWifiRunning; |
| 6645 | StopwatchTimer mWifiRunningTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6646 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6647 | boolean mFullWifiLockOut; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6648 | StopwatchTimer mFullWifiLockTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6649 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 6650 | boolean mWifiScanStarted; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 6651 | DualTimer mWifiScanTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6652 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 6653 | static final int NO_BATCHED_SCAN_STARTED = -1; |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6654 | int mWifiBatchedScanBinStarted = NO_BATCHED_SCAN_STARTED; |
| 6655 | StopwatchTimer[] mWifiBatchedScanTimer; |
| 6656 | |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 6657 | boolean mWifiMulticastEnabled; |
| 6658 | StopwatchTimer mWifiMulticastTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6659 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 6660 | StopwatchTimer mAudioTurnedOnTimer; |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 6661 | StopwatchTimer mVideoTurnedOnTimer; |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 6662 | StopwatchTimer mFlashlightTurnedOnTimer; |
| 6663 | StopwatchTimer mCameraTurnedOnTimer; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6664 | StopwatchTimer mForegroundActivityTimer; |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 6665 | StopwatchTimer mForegroundServiceTimer; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 6666 | /** Total time spent by the uid holding any partial wakelocks. */ |
| 6667 | DualTimer mAggregatedPartialWakelockTimer; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 6668 | DualTimer mBluetoothScanTimer; |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 6669 | DualTimer mBluetoothUnoptimizedScanTimer; |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 6670 | Counter mBluetoothScanResultCounter; |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 6671 | Counter mBluetoothScanResultBgCounter; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6672 | |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 6673 | int mProcessState = ActivityManager.PROCESS_STATE_NONEXISTENT; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 6674 | StopwatchTimer[] mProcessStateTimer; |
| 6675 | |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 6676 | boolean mInForegroundService = false; |
| 6677 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 6678 | BatchTimer mVibratorOnTimer; |
| 6679 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6680 | Counter[] mUserActivityCounters; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6681 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6682 | LongSamplingCounter[] mNetworkByteActivityCounters; |
| 6683 | LongSamplingCounter[] mNetworkPacketActivityCounters; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 6684 | LongSamplingCounter mMobileRadioActiveTime; |
| 6685 | LongSamplingCounter mMobileRadioActiveCount; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6686 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6687 | /** |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 6688 | * How many times this UID woke up the Application Processor due to a Mobile radio packet. |
| 6689 | */ |
| 6690 | private LongSamplingCounter mMobileRadioApWakeupCount; |
| 6691 | |
| 6692 | /** |
| 6693 | * How many times this UID woke up the Application Processor due to a Wifi packet. |
| 6694 | */ |
| 6695 | private LongSamplingCounter mWifiRadioApWakeupCount; |
| 6696 | |
| 6697 | /** |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6698 | * 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] | 6699 | * Can be null if the UID has had no such activity. |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6700 | */ |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6701 | private ControllerActivityCounterImpl mWifiControllerActivity; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6702 | |
| 6703 | /** |
| 6704 | * 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] | 6705 | * Can be null if the UID has had no such activity. |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6706 | */ |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6707 | private ControllerActivityCounterImpl mBluetoothControllerActivity; |
| 6708 | |
| 6709 | /** |
| 6710 | * The amount of time this uid has kept the Modem controller in idle, tx, and rx mode. |
| 6711 | * Can be null if the UID has had no such activity. |
| 6712 | */ |
| 6713 | private ControllerActivityCounterImpl mModemControllerActivity; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6714 | |
| 6715 | /** |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 6716 | * The CPU times we had at the last history details update. |
| 6717 | */ |
| 6718 | long mLastStepUserTime; |
| 6719 | long mLastStepSystemTime; |
| 6720 | long mCurStepUserTime; |
| 6721 | long mCurStepSystemTime; |
| 6722 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6723 | LongSamplingCounter mUserCpuTime; |
| 6724 | LongSamplingCounter mSystemCpuTime; |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 6725 | LongSamplingCounter[][] mCpuClusterSpeedTimesUs; |
Mike Ma | 3d422c3 | 2017-10-25 11:08:57 -0700 | [diff] [blame] | 6726 | LongSamplingCounter mCpuActiveTimeMs; |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 6727 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 6728 | LongSamplingCounterArray mCpuFreqTimeMs; |
| 6729 | LongSamplingCounterArray mScreenOffCpuFreqTimeMs; |
Mike Ma | 3d422c3 | 2017-10-25 11:08:57 -0700 | [diff] [blame] | 6730 | LongSamplingCounterArray mCpuClusterTimesMs; |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 6731 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 6732 | LongSamplingCounterArray[] mProcStateTimeMs; |
| 6733 | LongSamplingCounterArray[] mProcStateScreenOffTimeMs; |
| 6734 | |
| 6735 | IntArray mChildUids; |
| 6736 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 6737 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6738 | * The statistics we have collected for this uid's wake locks. |
| 6739 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6740 | final OverflowArrayMap<Wakelock> mWakelockStats; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6741 | |
| 6742 | /** |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6743 | * The statistics we have collected for this uid's syncs. |
| 6744 | */ |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 6745 | final OverflowArrayMap<DualTimer> mSyncStats; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6746 | |
| 6747 | /** |
| 6748 | * The statistics we have collected for this uid's jobs. |
| 6749 | */ |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 6750 | final OverflowArrayMap<DualTimer> mJobStats; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6751 | |
| 6752 | /** |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 6753 | * Count of the jobs that have completed and the reasons why they completed. |
| 6754 | */ |
| 6755 | final ArrayMap<String, SparseIntArray> mJobCompletions = new ArrayMap<>(); |
| 6756 | |
| 6757 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6758 | * The statistics we have collected for this uid's sensor activations. |
| 6759 | */ |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6760 | final SparseArray<Sensor> mSensorStats = new SparseArray<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6761 | |
| 6762 | /** |
| 6763 | * The statistics we have collected for this uid's processes. |
| 6764 | */ |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6765 | final ArrayMap<String, Proc> mProcessStats = new ArrayMap<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6766 | |
| 6767 | /** |
| 6768 | * The statistics we have collected for this uid's processes. |
| 6769 | */ |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6770 | final ArrayMap<String, Pkg> mPackageStats = new ArrayMap<>(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6771 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6772 | /** |
| 6773 | * The transient wake stats we have collected for this uid's pids. |
| 6774 | */ |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6775 | final SparseArray<Pid> mPids = new SparseArray<>(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6776 | |
Narayan Kamath | 0ebc96c | 2017-12-29 13:32:38 +0000 | [diff] [blame] | 6777 | /** |
| 6778 | * The list of WorkChains associated with active bluetooth scans. |
| 6779 | * |
| 6780 | * NOTE: This is a hack and it only needs to exist because there's a "reset" API that is |
| 6781 | * supposed to stop and log all WorkChains that were currently active. |
| 6782 | */ |
| 6783 | ArrayList<WorkChain> mAllBluetoothChains = null; |
| 6784 | ArrayList<WorkChain> mUnoptimizedBluetoothChains = null; |
| 6785 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6786 | public Uid(BatteryStatsImpl bsi, int uid) { |
| 6787 | mBsi = bsi; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6788 | mUid = uid; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6789 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 6790 | mOnBatteryBackgroundTimeBase = new TimeBase(); |
| 6791 | mOnBatteryBackgroundTimeBase.init(mBsi.mClocks.uptimeMillis() * 1000, |
| 6792 | mBsi.mClocks.elapsedRealtime() * 1000); |
| 6793 | |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 6794 | mOnBatteryScreenOffBackgroundTimeBase = new TimeBase(); |
| 6795 | mOnBatteryScreenOffBackgroundTimeBase.init(mBsi.mClocks.uptimeMillis() * 1000, |
| 6796 | mBsi.mClocks.elapsedRealtime() * 1000); |
| 6797 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6798 | mUserCpuTime = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
| 6799 | mSystemCpuTime = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
Mike Ma | 3d422c3 | 2017-10-25 11:08:57 -0700 | [diff] [blame] | 6800 | mCpuActiveTimeMs = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
| 6801 | mCpuClusterTimesMs = new LongSamplingCounterArray(mBsi.mOnBatteryTimeBase); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6802 | |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame] | 6803 | mWakelockStats = mBsi.new OverflowArrayMap<Wakelock>(uid) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6804 | @Override public Wakelock instantiateObject() { |
| 6805 | return new Wakelock(mBsi, Uid.this); |
| 6806 | } |
| 6807 | }; |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 6808 | mSyncStats = mBsi.new OverflowArrayMap<DualTimer>(uid) { |
| 6809 | @Override public DualTimer instantiateObject() { |
| 6810 | return new DualTimer(mBsi.mClocks, Uid.this, SYNC, null, |
| 6811 | mBsi.mOnBatteryTimeBase, mOnBatteryBackgroundTimeBase); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6812 | } |
| 6813 | }; |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 6814 | mJobStats = mBsi.new OverflowArrayMap<DualTimer>(uid) { |
| 6815 | @Override public DualTimer instantiateObject() { |
| 6816 | return new DualTimer(mBsi.mClocks, Uid.this, JOB, null, |
| 6817 | mBsi.mOnBatteryTimeBase, mOnBatteryBackgroundTimeBase); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6818 | } |
| 6819 | }; |
| 6820 | |
| 6821 | mWifiRunningTimer = new StopwatchTimer(mBsi.mClocks, this, WIFI_RUNNING, |
| 6822 | mBsi.mWifiRunningTimers, mBsi.mOnBatteryTimeBase); |
| 6823 | mFullWifiLockTimer = new StopwatchTimer(mBsi.mClocks, this, FULL_WIFI_LOCK, |
| 6824 | mBsi.mFullWifiLockTimers, mBsi.mOnBatteryTimeBase); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 6825 | mWifiScanTimer = new DualTimer(mBsi.mClocks, this, WIFI_SCAN, |
| 6826 | mBsi.mWifiScanTimers, mBsi.mOnBatteryTimeBase, mOnBatteryBackgroundTimeBase); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6827 | mWifiBatchedScanTimer = new StopwatchTimer[NUM_WIFI_BATCHED_SCAN_BINS]; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6828 | mWifiMulticastTimer = new StopwatchTimer(mBsi.mClocks, this, WIFI_MULTICAST_ENABLED, |
| 6829 | mBsi.mWifiMulticastTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 6830 | mProcessStateTimer = new StopwatchTimer[NUM_PROCESS_STATE]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6831 | } |
| 6832 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 6833 | @VisibleForTesting |
| 6834 | public void setProcessStateForTest(int procState) { |
| 6835 | mProcessState = procState; |
| 6836 | } |
| 6837 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6838 | @Override |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 6839 | public long[] getCpuFreqTimes(int which) { |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 6840 | return nullIfAllZeros(mCpuFreqTimeMs, which); |
| 6841 | } |
| 6842 | |
| 6843 | @Override |
| 6844 | public long[] getScreenOffCpuFreqTimes(int which) { |
| 6845 | return nullIfAllZeros(mScreenOffCpuFreqTimeMs, which); |
| 6846 | } |
| 6847 | |
| 6848 | @Override |
Mike Ma | 3d422c3 | 2017-10-25 11:08:57 -0700 | [diff] [blame] | 6849 | public long getCpuActiveTime() { |
| 6850 | return mCpuActiveTimeMs.getCountLocked(STATS_SINCE_CHARGED); |
| 6851 | } |
| 6852 | |
| 6853 | @Override |
| 6854 | public long[] getCpuClusterTimes() { |
| 6855 | return nullIfAllZeros(mCpuClusterTimesMs, STATS_SINCE_CHARGED); |
| 6856 | } |
| 6857 | |
| 6858 | |
| 6859 | @Override |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 6860 | public long[] getCpuFreqTimes(int which, int procState) { |
| 6861 | if (which < 0 || which >= NUM_PROCESS_STATE) { |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 6862 | return null; |
| 6863 | } |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 6864 | if (mProcStateTimeMs == null) { |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 6865 | return null; |
| 6866 | } |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 6867 | if (!mBsi.mPerProcStateCpuTimesAvailable) { |
| 6868 | mProcStateTimeMs = null; |
| 6869 | return null; |
| 6870 | } |
| 6871 | return nullIfAllZeros(mProcStateTimeMs[procState], which); |
| 6872 | } |
| 6873 | |
| 6874 | @Override |
| 6875 | public long[] getScreenOffCpuFreqTimes(int which, int procState) { |
| 6876 | if (which < 0 || which >= NUM_PROCESS_STATE) { |
| 6877 | return null; |
| 6878 | } |
| 6879 | if (mProcStateScreenOffTimeMs == null) { |
| 6880 | return null; |
| 6881 | } |
| 6882 | if (!mBsi.mPerProcStateCpuTimesAvailable) { |
| 6883 | mProcStateScreenOffTimeMs = null; |
| 6884 | return null; |
| 6885 | } |
| 6886 | return nullIfAllZeros(mProcStateScreenOffTimeMs[procState], which); |
| 6887 | } |
| 6888 | |
| 6889 | public void addIsolatedUid(int isolatedUid) { |
| 6890 | if (mChildUids == null) { |
| 6891 | mChildUids = new IntArray(); |
| 6892 | } else if (mChildUids.indexOf(isolatedUid) >= 0) { |
| 6893 | return; |
| 6894 | } |
| 6895 | mChildUids.add(isolatedUid); |
| 6896 | } |
| 6897 | |
| 6898 | public void removeIsolatedUid(int isolatedUid) { |
| 6899 | final int idx = mChildUids == null ? -1 : mChildUids.indexOf(isolatedUid); |
| 6900 | if (idx < 0) { |
| 6901 | return; |
| 6902 | } |
| 6903 | mChildUids.remove(idx); |
| 6904 | } |
| 6905 | |
| 6906 | private long[] nullIfAllZeros(LongSamplingCounterArray cpuTimesMs, int which) { |
| 6907 | if (cpuTimesMs == null) { |
| 6908 | return null; |
| 6909 | } |
| 6910 | final long[] counts = cpuTimesMs.getCountsLocked(which); |
| 6911 | if (counts == null) { |
| 6912 | return null; |
| 6913 | } |
| 6914 | // Return counts only if at least one of the elements is non-zero. |
| 6915 | for (int i = counts.length - 1; i >= 0; --i) { |
| 6916 | if (counts[i] != 0) { |
| 6917 | return counts; |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 6918 | } |
| 6919 | } |
| 6920 | return null; |
| 6921 | } |
| 6922 | |
Sudheer Shanka | e544d16 | 2017-12-28 17:06:20 -0800 | [diff] [blame] | 6923 | private void addProcStateTimesMs(int procState, long[] cpuTimesMs, boolean onBattery) { |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 6924 | if (mProcStateTimeMs == null) { |
| 6925 | mProcStateTimeMs = new LongSamplingCounterArray[NUM_PROCESS_STATE]; |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 6926 | } |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 6927 | if (mProcStateTimeMs[procState] == null |
| 6928 | || mProcStateTimeMs[procState].getSize() != cpuTimesMs.length) { |
| 6929 | mProcStateTimeMs[procState] = new LongSamplingCounterArray( |
| 6930 | mBsi.mOnBatteryTimeBase); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 6931 | } |
Sudheer Shanka | e544d16 | 2017-12-28 17:06:20 -0800 | [diff] [blame] | 6932 | mProcStateTimeMs[procState].addCountLocked(cpuTimesMs, onBattery); |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 6933 | } |
| 6934 | |
Sudheer Shanka | e544d16 | 2017-12-28 17:06:20 -0800 | [diff] [blame] | 6935 | private void addProcStateScreenOffTimesMs(int procState, long[] cpuTimesMs, |
| 6936 | boolean onBatteryScreenOff) { |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 6937 | if (mProcStateScreenOffTimeMs == null) { |
| 6938 | mProcStateScreenOffTimeMs = new LongSamplingCounterArray[NUM_PROCESS_STATE]; |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 6939 | } |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 6940 | if (mProcStateScreenOffTimeMs[procState] == null |
| 6941 | || mProcStateScreenOffTimeMs[procState].getSize() != cpuTimesMs.length) { |
| 6942 | mProcStateScreenOffTimeMs[procState] = new LongSamplingCounterArray( |
| 6943 | mBsi.mOnBatteryScreenOffTimeBase); |
| 6944 | } |
Sudheer Shanka | e544d16 | 2017-12-28 17:06:20 -0800 | [diff] [blame] | 6945 | mProcStateScreenOffTimeMs[procState].addCountLocked(cpuTimesMs, onBatteryScreenOff); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 6946 | } |
| 6947 | |
| 6948 | @Override |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 6949 | public Timer getAggregatedPartialWakelockTimer() { |
| 6950 | return mAggregatedPartialWakelockTimer; |
| 6951 | } |
| 6952 | |
| 6953 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6954 | public ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> getWakelockStats() { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6955 | return mWakelockStats.getMap(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6956 | } |
| 6957 | |
| 6958 | @Override |
Ahmed ElArabawy | ddd0969 | 2017-10-30 17:58:29 -0700 | [diff] [blame] | 6959 | public Timer getMulticastWakelockStats() { |
| 6960 | return mWifiMulticastTimer; |
| 6961 | } |
| 6962 | |
| 6963 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6964 | public ArrayMap<String, ? extends BatteryStats.Timer> getSyncStats() { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6965 | return mSyncStats.getMap(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6966 | } |
| 6967 | |
| 6968 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6969 | public ArrayMap<String, ? extends BatteryStats.Timer> getJobStats() { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6970 | return mJobStats.getMap(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6971 | } |
| 6972 | |
| 6973 | @Override |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 6974 | public ArrayMap<String, SparseIntArray> getJobCompletionStats() { |
| 6975 | return mJobCompletions; |
| 6976 | } |
| 6977 | |
| 6978 | @Override |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 6979 | public SparseArray<? extends BatteryStats.Uid.Sensor> getSensorStats() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6980 | return mSensorStats; |
| 6981 | } |
| 6982 | |
| 6983 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6984 | public ArrayMap<String, ? extends BatteryStats.Uid.Proc> getProcessStats() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6985 | return mProcessStats; |
| 6986 | } |
| 6987 | |
| 6988 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6989 | public ArrayMap<String, ? extends BatteryStats.Uid.Pkg> getPackageStats() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6990 | return mPackageStats; |
| 6991 | } |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6992 | |
| 6993 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6994 | public int getUid() { |
| 6995 | return mUid; |
| 6996 | } |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6997 | |
| 6998 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6999 | public void noteWifiRunningLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 7000 | if (!mWifiRunning) { |
| 7001 | mWifiRunning = true; |
| 7002 | if (mWifiRunningTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7003 | mWifiRunningTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, WIFI_RUNNING, |
| 7004 | mBsi.mWifiRunningTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7005 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7006 | mWifiRunningTimer.startRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 7007 | } |
| 7008 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7009 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 7010 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7011 | public void noteWifiStoppedLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 7012 | if (mWifiRunning) { |
| 7013 | mWifiRunning = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7014 | mWifiRunningTimer.stopRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 7015 | } |
| 7016 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7017 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 7018 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7019 | public void noteFullWifiLockAcquiredLocked(long elapsedRealtimeMs) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7020 | if (!mFullWifiLockOut) { |
| 7021 | mFullWifiLockOut = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7022 | if (mFullWifiLockTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7023 | mFullWifiLockTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, FULL_WIFI_LOCK, |
| 7024 | mBsi.mFullWifiLockTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7025 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7026 | mFullWifiLockTimer.startRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7027 | } |
| 7028 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7029 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7030 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7031 | public void noteFullWifiLockReleasedLocked(long elapsedRealtimeMs) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7032 | if (mFullWifiLockOut) { |
| 7033 | mFullWifiLockOut = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7034 | mFullWifiLockTimer.stopRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7035 | } |
| 7036 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7037 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7038 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7039 | public void noteWifiScanStartedLocked(long elapsedRealtimeMs) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 7040 | if (!mWifiScanStarted) { |
| 7041 | mWifiScanStarted = true; |
| 7042 | if (mWifiScanTimer == null) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 7043 | mWifiScanTimer = new DualTimer(mBsi.mClocks, Uid.this, WIFI_SCAN, |
| 7044 | mBsi.mWifiScanTimers, mBsi.mOnBatteryTimeBase, |
| 7045 | mOnBatteryBackgroundTimeBase); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7046 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7047 | mWifiScanTimer.startRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7048 | } |
| 7049 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7050 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7051 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7052 | public void noteWifiScanStoppedLocked(long elapsedRealtimeMs) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 7053 | if (mWifiScanStarted) { |
| 7054 | mWifiScanStarted = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7055 | mWifiScanTimer.stopRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7056 | } |
| 7057 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 7058 | |
| 7059 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7060 | public void noteWifiBatchedScanStartedLocked(int csph, long elapsedRealtimeMs) { |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 7061 | int bin = 0; |
Navtej Singh Mann | 3c0ce5c | 2015-06-11 16:53:11 -0700 | [diff] [blame] | 7062 | while (csph > 8 && bin < NUM_WIFI_BATCHED_SCAN_BINS-1) { |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 7063 | csph = csph >> 3; |
| 7064 | bin++; |
| 7065 | } |
| 7066 | |
| 7067 | if (mWifiBatchedScanBinStarted == bin) return; |
| 7068 | |
| 7069 | if (mWifiBatchedScanBinStarted != NO_BATCHED_SCAN_STARTED) { |
| 7070 | mWifiBatchedScanTimer[mWifiBatchedScanBinStarted]. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7071 | stopRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 7072 | } |
| 7073 | mWifiBatchedScanBinStarted = bin; |
| 7074 | if (mWifiBatchedScanTimer[bin] == null) { |
| 7075 | makeWifiBatchedScanBin(bin, null); |
| 7076 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7077 | mWifiBatchedScanTimer[bin].startRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 7078 | } |
| 7079 | |
| 7080 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7081 | public void noteWifiBatchedScanStoppedLocked(long elapsedRealtimeMs) { |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 7082 | if (mWifiBatchedScanBinStarted != NO_BATCHED_SCAN_STARTED) { |
| 7083 | mWifiBatchedScanTimer[mWifiBatchedScanBinStarted]. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7084 | stopRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 7085 | mWifiBatchedScanBinStarted = NO_BATCHED_SCAN_STARTED; |
| 7086 | } |
| 7087 | } |
| 7088 | |
| 7089 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7090 | public void noteWifiMulticastEnabledLocked(long elapsedRealtimeMs) { |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 7091 | if (!mWifiMulticastEnabled) { |
| 7092 | mWifiMulticastEnabled = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7093 | if (mWifiMulticastTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7094 | mWifiMulticastTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, |
| 7095 | WIFI_MULTICAST_ENABLED, mBsi.mWifiMulticastTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7096 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7097 | mWifiMulticastTimer.startRunningLocked(elapsedRealtimeMs); |
Tej Singh | 4503e10 | 2018-01-04 14:35:01 -0800 | [diff] [blame] | 7098 | StatsLog.write_non_chained( |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 7099 | StatsLog.WIFI_MULTICAST_LOCK_STATE_CHANGED, getUid(), null, |
| 7100 | StatsLog.WIFI_MULTICAST_LOCK_STATE_CHANGED__STATE__ON); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 7101 | } |
| 7102 | } |
| 7103 | |
| 7104 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7105 | public void noteWifiMulticastDisabledLocked(long elapsedRealtimeMs) { |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 7106 | if (mWifiMulticastEnabled) { |
| 7107 | mWifiMulticastEnabled = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7108 | mWifiMulticastTimer.stopRunningLocked(elapsedRealtimeMs); |
Tej Singh | 4503e10 | 2018-01-04 14:35:01 -0800 | [diff] [blame] | 7109 | StatsLog.write_non_chained( |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 7110 | StatsLog.WIFI_MULTICAST_LOCK_STATE_CHANGED, getUid(), null, |
| 7111 | StatsLog.WIFI_MULTICAST_LOCK_STATE_CHANGED__STATE__OFF); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 7112 | } |
| 7113 | } |
| 7114 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 7115 | @Override |
| 7116 | public ControllerActivityCounter getWifiControllerActivity() { |
| 7117 | return mWifiControllerActivity; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7118 | } |
| 7119 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 7120 | @Override |
| 7121 | public ControllerActivityCounter getBluetoothControllerActivity() { |
| 7122 | return mBluetoothControllerActivity; |
| 7123 | } |
| 7124 | |
| 7125 | @Override |
| 7126 | public ControllerActivityCounter getModemControllerActivity() { |
| 7127 | return mModemControllerActivity; |
| 7128 | } |
| 7129 | |
| 7130 | public ControllerActivityCounterImpl getOrCreateWifiControllerActivityLocked() { |
| 7131 | if (mWifiControllerActivity == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7132 | mWifiControllerActivity = new ControllerActivityCounterImpl(mBsi.mOnBatteryTimeBase, |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 7133 | NUM_BT_TX_LEVELS); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 7134 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 7135 | return mWifiControllerActivity; |
| 7136 | } |
| 7137 | |
| 7138 | public ControllerActivityCounterImpl getOrCreateBluetoothControllerActivityLocked() { |
| 7139 | if (mBluetoothControllerActivity == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7140 | mBluetoothControllerActivity = new ControllerActivityCounterImpl(mBsi.mOnBatteryTimeBase, |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 7141 | NUM_BT_TX_LEVELS); |
| 7142 | } |
| 7143 | return mBluetoothControllerActivity; |
| 7144 | } |
| 7145 | |
| 7146 | public ControllerActivityCounterImpl getOrCreateModemControllerActivityLocked() { |
| 7147 | if (mModemControllerActivity == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7148 | mModemControllerActivity = new ControllerActivityCounterImpl(mBsi.mOnBatteryTimeBase, |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 7149 | ModemActivityInfo.TX_POWER_LEVELS); |
| 7150 | } |
| 7151 | return mModemControllerActivity; |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 7152 | } |
| 7153 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 7154 | public StopwatchTimer createAudioTurnedOnTimerLocked() { |
| 7155 | if (mAudioTurnedOnTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7156 | mAudioTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, AUDIO_TURNED_ON, |
| 7157 | mBsi.mAudioTurnedOnTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 7158 | } |
| 7159 | return mAudioTurnedOnTimer; |
| 7160 | } |
| 7161 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7162 | public void noteAudioTurnedOnLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 7163 | createAudioTurnedOnTimerLocked().startRunningLocked(elapsedRealtimeMs); |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 7164 | StatsLog.write_non_chained(StatsLog.AUDIO_STATE_CHANGED, getUid(), null, |
| 7165 | StatsLog.AUDIO_STATE_CHANGED__STATE__ON); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 7166 | } |
| 7167 | |
| 7168 | public void noteAudioTurnedOffLocked(long elapsedRealtimeMs) { |
| 7169 | if (mAudioTurnedOnTimer != null) { |
| 7170 | mAudioTurnedOnTimer.stopRunningLocked(elapsedRealtimeMs); |
Bookatz | c1a050a | 2017-10-10 15:49:28 -0700 | [diff] [blame] | 7171 | if (!mAudioTurnedOnTimer.isRunningLocked()) { // only tell statsd if truly stopped |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 7172 | StatsLog.write_non_chained(StatsLog.AUDIO_STATE_CHANGED, getUid(), null, |
| 7173 | StatsLog.AUDIO_STATE_CHANGED__STATE__OFF); |
Bookatz | c1a050a | 2017-10-10 15:49:28 -0700 | [diff] [blame] | 7174 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7175 | } |
| 7176 | } |
| 7177 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 7178 | public void noteResetAudioLocked(long elapsedRealtimeMs) { |
| 7179 | if (mAudioTurnedOnTimer != null) { |
| 7180 | mAudioTurnedOnTimer.stopAllRunningLocked(elapsedRealtimeMs); |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 7181 | StatsLog.write_non_chained(StatsLog.AUDIO_STATE_CHANGED, getUid(), null, |
| 7182 | StatsLog.AUDIO_STATE_CHANGED__STATE__OFF); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7183 | } |
| 7184 | } |
| 7185 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 7186 | public StopwatchTimer createVideoTurnedOnTimerLocked() { |
| 7187 | if (mVideoTurnedOnTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7188 | mVideoTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, VIDEO_TURNED_ON, |
| 7189 | mBsi.mVideoTurnedOnTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 7190 | } |
| 7191 | return mVideoTurnedOnTimer; |
| 7192 | } |
| 7193 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7194 | public void noteVideoTurnedOnLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 7195 | createVideoTurnedOnTimerLocked().startRunningLocked(elapsedRealtimeMs); |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 7196 | StatsLog.write_non_chained(StatsLog.MEDIA_CODEC_ACTIVITY_CHANGED, getUid(), null, |
| 7197 | StatsLog.MEDIA_CODEC_ACTIVITY_CHANGED__STATE__ON); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 7198 | } |
| 7199 | |
| 7200 | public void noteVideoTurnedOffLocked(long elapsedRealtimeMs) { |
| 7201 | if (mVideoTurnedOnTimer != null) { |
| 7202 | mVideoTurnedOnTimer.stopRunningLocked(elapsedRealtimeMs); |
Bookatz | c1a050a | 2017-10-10 15:49:28 -0700 | [diff] [blame] | 7203 | if (!mVideoTurnedOnTimer.isRunningLocked()) { // only tell statsd if truly stopped |
Yangster-mac | 2f5daec | 2018-01-16 10:23:15 -0800 | [diff] [blame] | 7204 | StatsLog.write_non_chained(StatsLog.MEDIA_CODEC_ACTIVITY_CHANGED, getUid(), |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 7205 | null, StatsLog.MEDIA_CODEC_ACTIVITY_CHANGED__STATE__OFF); |
Bookatz | c1a050a | 2017-10-10 15:49:28 -0700 | [diff] [blame] | 7206 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7207 | } |
| 7208 | } |
| 7209 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 7210 | public void noteResetVideoLocked(long elapsedRealtimeMs) { |
| 7211 | if (mVideoTurnedOnTimer != null) { |
| 7212 | mVideoTurnedOnTimer.stopAllRunningLocked(elapsedRealtimeMs); |
Yangster-mac | 2f5daec | 2018-01-16 10:23:15 -0800 | [diff] [blame] | 7213 | StatsLog.write_non_chained(StatsLog.MEDIA_CODEC_ACTIVITY_CHANGED, getUid(), null, |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 7214 | StatsLog.MEDIA_CODEC_ACTIVITY_CHANGED__STATE__OFF); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 7215 | } |
| 7216 | } |
| 7217 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 7218 | public StopwatchTimer createFlashlightTurnedOnTimerLocked() { |
| 7219 | if (mFlashlightTurnedOnTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7220 | mFlashlightTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, |
| 7221 | FLASHLIGHT_TURNED_ON, mBsi.mFlashlightTurnedOnTimers, mBsi.mOnBatteryTimeBase); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 7222 | } |
| 7223 | return mFlashlightTurnedOnTimer; |
| 7224 | } |
| 7225 | |
| 7226 | public void noteFlashlightTurnedOnLocked(long elapsedRealtimeMs) { |
| 7227 | createFlashlightTurnedOnTimerLocked().startRunningLocked(elapsedRealtimeMs); |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 7228 | StatsLog.write_non_chained(StatsLog.FLASHLIGHT_STATE_CHANGED, getUid(), null, |
| 7229 | StatsLog.FLASHLIGHT_STATE_CHANGED__STATE__ON); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 7230 | } |
| 7231 | |
| 7232 | public void noteFlashlightTurnedOffLocked(long elapsedRealtimeMs) { |
| 7233 | if (mFlashlightTurnedOnTimer != null) { |
| 7234 | mFlashlightTurnedOnTimer.stopRunningLocked(elapsedRealtimeMs); |
Bookatz | c1a050a | 2017-10-10 15:49:28 -0700 | [diff] [blame] | 7235 | if (!mFlashlightTurnedOnTimer.isRunningLocked()) { |
Yangster-mac | 2f5daec | 2018-01-16 10:23:15 -0800 | [diff] [blame] | 7236 | StatsLog.write_non_chained(StatsLog.FLASHLIGHT_STATE_CHANGED, getUid(), null, |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 7237 | StatsLog.FLASHLIGHT_STATE_CHANGED__STATE__OFF); |
Bookatz | c1a050a | 2017-10-10 15:49:28 -0700 | [diff] [blame] | 7238 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 7239 | } |
| 7240 | } |
| 7241 | |
| 7242 | public void noteResetFlashlightLocked(long elapsedRealtimeMs) { |
| 7243 | if (mFlashlightTurnedOnTimer != null) { |
| 7244 | mFlashlightTurnedOnTimer.stopAllRunningLocked(elapsedRealtimeMs); |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 7245 | StatsLog.write_non_chained(StatsLog.FLASHLIGHT_STATE_CHANGED, getUid(), null, |
| 7246 | StatsLog.FLASHLIGHT_STATE_CHANGED__STATE__OFF); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 7247 | } |
| 7248 | } |
| 7249 | |
| 7250 | public StopwatchTimer createCameraTurnedOnTimerLocked() { |
| 7251 | if (mCameraTurnedOnTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7252 | mCameraTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, CAMERA_TURNED_ON, |
| 7253 | mBsi.mCameraTurnedOnTimers, mBsi.mOnBatteryTimeBase); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 7254 | } |
| 7255 | return mCameraTurnedOnTimer; |
| 7256 | } |
| 7257 | |
| 7258 | public void noteCameraTurnedOnLocked(long elapsedRealtimeMs) { |
| 7259 | createCameraTurnedOnTimerLocked().startRunningLocked(elapsedRealtimeMs); |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 7260 | StatsLog.write_non_chained(StatsLog.CAMERA_STATE_CHANGED, getUid(), null, |
| 7261 | StatsLog.CAMERA_STATE_CHANGED__STATE__ON); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 7262 | } |
| 7263 | |
| 7264 | public void noteCameraTurnedOffLocked(long elapsedRealtimeMs) { |
| 7265 | if (mCameraTurnedOnTimer != null) { |
| 7266 | mCameraTurnedOnTimer.stopRunningLocked(elapsedRealtimeMs); |
Bookatz | c1a050a | 2017-10-10 15:49:28 -0700 | [diff] [blame] | 7267 | if (!mCameraTurnedOnTimer.isRunningLocked()) { // only tell statsd if truly stopped |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 7268 | StatsLog.write_non_chained(StatsLog.CAMERA_STATE_CHANGED, getUid(), null, |
| 7269 | StatsLog.CAMERA_STATE_CHANGED__STATE__OFF); |
Bookatz | c1a050a | 2017-10-10 15:49:28 -0700 | [diff] [blame] | 7270 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 7271 | } |
| 7272 | } |
| 7273 | |
| 7274 | public void noteResetCameraLocked(long elapsedRealtimeMs) { |
| 7275 | if (mCameraTurnedOnTimer != null) { |
| 7276 | mCameraTurnedOnTimer.stopAllRunningLocked(elapsedRealtimeMs); |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 7277 | StatsLog.write_non_chained(StatsLog.CAMERA_STATE_CHANGED, getUid(), null, |
| 7278 | StatsLog.CAMERA_STATE_CHANGED__STATE__OFF); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 7279 | } |
| 7280 | } |
| 7281 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 7282 | public StopwatchTimer createForegroundActivityTimerLocked() { |
| 7283 | if (mForegroundActivityTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7284 | mForegroundActivityTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, |
| 7285 | FOREGROUND_ACTIVITY, null, mBsi.mOnBatteryTimeBase); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 7286 | } |
| 7287 | return mForegroundActivityTimer; |
| 7288 | } |
| 7289 | |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 7290 | public StopwatchTimer createForegroundServiceTimerLocked() { |
| 7291 | if (mForegroundServiceTimer == null) { |
| 7292 | mForegroundServiceTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, |
| 7293 | FOREGROUND_SERVICE, null, mBsi.mOnBatteryTimeBase); |
| 7294 | } |
| 7295 | return mForegroundServiceTimer; |
| 7296 | } |
| 7297 | |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 7298 | public DualTimer createAggregatedPartialWakelockTimerLocked() { |
| 7299 | if (mAggregatedPartialWakelockTimer == null) { |
| 7300 | mAggregatedPartialWakelockTimer = new DualTimer(mBsi.mClocks, this, |
| 7301 | AGGREGATED_WAKE_TYPE_PARTIAL, null, |
| 7302 | mBsi.mOnBatteryScreenOffTimeBase, mOnBatteryScreenOffBackgroundTimeBase); |
| 7303 | } |
| 7304 | return mAggregatedPartialWakelockTimer; |
| 7305 | } |
| 7306 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 7307 | public DualTimer createBluetoothScanTimerLocked() { |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 7308 | if (mBluetoothScanTimer == null) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 7309 | mBluetoothScanTimer = new DualTimer(mBsi.mClocks, Uid.this, BLUETOOTH_SCAN_ON, |
| 7310 | mBsi.mBluetoothScanOnTimers, mBsi.mOnBatteryTimeBase, |
| 7311 | mOnBatteryBackgroundTimeBase); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 7312 | } |
| 7313 | return mBluetoothScanTimer; |
| 7314 | } |
| 7315 | |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 7316 | public DualTimer createBluetoothUnoptimizedScanTimerLocked() { |
| 7317 | if (mBluetoothUnoptimizedScanTimer == null) { |
| 7318 | mBluetoothUnoptimizedScanTimer = new DualTimer(mBsi.mClocks, Uid.this, |
| 7319 | BLUETOOTH_UNOPTIMIZED_SCAN_ON, null, |
| 7320 | mBsi.mOnBatteryTimeBase, mOnBatteryBackgroundTimeBase); |
| 7321 | } |
| 7322 | return mBluetoothUnoptimizedScanTimer; |
| 7323 | } |
| 7324 | |
Narayan Kamath | 0ebc96c | 2017-12-29 13:32:38 +0000 | [diff] [blame] | 7325 | public void noteBluetoothScanStartedLocked(long elapsedRealtimeMs, |
| 7326 | boolean isUnoptimized) { |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 7327 | createBluetoothScanTimerLocked().startRunningLocked(elapsedRealtimeMs); |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 7328 | if (isUnoptimized) { |
| 7329 | createBluetoothUnoptimizedScanTimerLocked().startRunningLocked(elapsedRealtimeMs); |
| 7330 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 7331 | } |
| 7332 | |
Bookatz | 94c5a31 | 2017-07-11 16:49:17 -0700 | [diff] [blame] | 7333 | public void noteBluetoothScanStoppedLocked(long elapsedRealtimeMs, boolean isUnoptimized) { |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 7334 | if (mBluetoothScanTimer != null) { |
| 7335 | mBluetoothScanTimer.stopRunningLocked(elapsedRealtimeMs); |
| 7336 | } |
Bookatz | 94c5a31 | 2017-07-11 16:49:17 -0700 | [diff] [blame] | 7337 | if (isUnoptimized && mBluetoothUnoptimizedScanTimer != null) { |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 7338 | mBluetoothUnoptimizedScanTimer.stopRunningLocked(elapsedRealtimeMs); |
| 7339 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 7340 | } |
| 7341 | |
Narayan Kamath | 0ebc96c | 2017-12-29 13:32:38 +0000 | [diff] [blame] | 7342 | public void addBluetoothWorkChain(WorkChain workChain, boolean isUnoptimized) { |
| 7343 | if (mAllBluetoothChains == null) { |
| 7344 | mAllBluetoothChains = new ArrayList<WorkChain>(4); |
| 7345 | } |
| 7346 | |
| 7347 | if (isUnoptimized && mUnoptimizedBluetoothChains == null) { |
| 7348 | mUnoptimizedBluetoothChains = new ArrayList<WorkChain>(4); |
| 7349 | } |
| 7350 | |
| 7351 | mAllBluetoothChains.add(workChain); |
| 7352 | if (isUnoptimized) { |
| 7353 | mUnoptimizedBluetoothChains.add(workChain); |
| 7354 | } |
| 7355 | } |
| 7356 | |
| 7357 | public void removeBluetoothWorkChain(WorkChain workChain, boolean isUnoptimized) { |
| 7358 | if (mAllBluetoothChains != null) { |
| 7359 | mAllBluetoothChains.remove(workChain); |
| 7360 | } |
| 7361 | |
| 7362 | if (isUnoptimized && mUnoptimizedBluetoothChains != null) { |
| 7363 | mUnoptimizedBluetoothChains.remove(workChain); |
| 7364 | } |
| 7365 | } |
| 7366 | |
| 7367 | public List<WorkChain> getAllBluetoothWorkChains() { |
| 7368 | return mAllBluetoothChains; |
| 7369 | } |
| 7370 | |
| 7371 | public List<WorkChain> getUnoptimizedBluetoothWorkChains() { |
| 7372 | return mUnoptimizedBluetoothChains; |
| 7373 | } |
| 7374 | |
| 7375 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 7376 | public void noteResetBluetoothScanLocked(long elapsedRealtimeMs) { |
| 7377 | if (mBluetoothScanTimer != null) { |
| 7378 | mBluetoothScanTimer.stopAllRunningLocked(elapsedRealtimeMs); |
| 7379 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 7380 | if (mBluetoothUnoptimizedScanTimer != null) { |
| 7381 | mBluetoothUnoptimizedScanTimer.stopAllRunningLocked(elapsedRealtimeMs); |
| 7382 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 7383 | } |
| 7384 | |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 7385 | public Counter createBluetoothScanResultCounterLocked() { |
| 7386 | if (mBluetoothScanResultCounter == null) { |
| 7387 | mBluetoothScanResultCounter = new Counter(mBsi.mOnBatteryTimeBase); |
| 7388 | } |
| 7389 | return mBluetoothScanResultCounter; |
| 7390 | } |
| 7391 | |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 7392 | public Counter createBluetoothScanResultBgCounterLocked() { |
| 7393 | if (mBluetoothScanResultBgCounter == null) { |
| 7394 | mBluetoothScanResultBgCounter = new Counter(mOnBatteryBackgroundTimeBase); |
| 7395 | } |
| 7396 | return mBluetoothScanResultBgCounter; |
| 7397 | } |
| 7398 | |
Bookatz | 4ebc064 | 2017-05-11 12:21:19 -0700 | [diff] [blame] | 7399 | public void noteBluetoothScanResultsLocked(int numNewResults) { |
| 7400 | createBluetoothScanResultCounterLocked().addAtomic(numNewResults); |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 7401 | // Uses background timebase, so the count will only be incremented if uid in background. |
| 7402 | createBluetoothScanResultBgCounterLocked().addAtomic(numNewResults); |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 7403 | } |
| 7404 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 7405 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7406 | public void noteActivityResumedLocked(long elapsedRealtimeMs) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 7407 | // We always start, since we want multiple foreground PIDs to nest |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7408 | createForegroundActivityTimerLocked().startRunningLocked(elapsedRealtimeMs); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 7409 | } |
| 7410 | |
| 7411 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7412 | public void noteActivityPausedLocked(long elapsedRealtimeMs) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 7413 | if (mForegroundActivityTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7414 | mForegroundActivityTimer.stopRunningLocked(elapsedRealtimeMs); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 7415 | } |
| 7416 | } |
| 7417 | |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 7418 | public void noteForegroundServiceResumedLocked(long elapsedRealtimeMs) { |
| 7419 | createForegroundServiceTimerLocked().startRunningLocked(elapsedRealtimeMs); |
| 7420 | } |
| 7421 | |
| 7422 | public void noteForegroundServicePausedLocked(long elapsedRealtimeMs) { |
| 7423 | if (mForegroundServiceTimer != null) { |
| 7424 | mForegroundServiceTimer.stopRunningLocked(elapsedRealtimeMs); |
| 7425 | } |
| 7426 | } |
| 7427 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 7428 | public BatchTimer createVibratorOnTimerLocked() { |
| 7429 | if (mVibratorOnTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7430 | mVibratorOnTimer = new BatchTimer(mBsi.mClocks, Uid.this, VIBRATOR_ON, |
| 7431 | mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 7432 | } |
| 7433 | return mVibratorOnTimer; |
| 7434 | } |
| 7435 | |
| 7436 | public void noteVibratorOnLocked(long durationMillis) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7437 | createVibratorOnTimerLocked().addDuration(mBsi, durationMillis); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 7438 | } |
| 7439 | |
| 7440 | public void noteVibratorOffLocked() { |
| 7441 | if (mVibratorOnTimer != null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7442 | mVibratorOnTimer.abortLastDuration(mBsi); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7443 | } |
| 7444 | } |
| 7445 | |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7446 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7447 | public long getWifiRunningTime(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 7448 | if (mWifiRunningTimer == null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7449 | return 0; |
| 7450 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7451 | return mWifiRunningTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 7452 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 7453 | |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7454 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7455 | public long getFullWifiLockTime(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7456 | if (mFullWifiLockTimer == null) { |
| 7457 | return 0; |
| 7458 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7459 | return mFullWifiLockTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7460 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7461 | |
| 7462 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7463 | public long getWifiScanTime(long elapsedRealtimeUs, int which) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 7464 | if (mWifiScanTimer == null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7465 | return 0; |
| 7466 | } |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 7467 | return mWifiScanTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7468 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 7469 | |
| 7470 | @Override |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 7471 | public int getWifiScanCount(int which) { |
| 7472 | if (mWifiScanTimer == null) { |
| 7473 | return 0; |
| 7474 | } |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 7475 | return mWifiScanTimer.getCountLocked(which); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 7476 | } |
| 7477 | |
| 7478 | @Override |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7479 | public Timer getWifiScanTimer() { |
| 7480 | return mWifiScanTimer; |
| 7481 | } |
| 7482 | |
| 7483 | @Override |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 7484 | public int getWifiScanBackgroundCount(int which) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 7485 | if (mWifiScanTimer == null || mWifiScanTimer.getSubTimer() == null) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 7486 | return 0; |
| 7487 | } |
| 7488 | return mWifiScanTimer.getSubTimer().getCountLocked(which); |
| 7489 | } |
| 7490 | |
| 7491 | @Override |
| 7492 | public long getWifiScanActualTime(final long elapsedRealtimeUs) { |
| 7493 | if (mWifiScanTimer == null) { |
| 7494 | return 0; |
| 7495 | } |
| 7496 | final long elapsedRealtimeMs = (elapsedRealtimeUs + 500) / 1000; |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 7497 | return mWifiScanTimer.getTotalDurationMsLocked(elapsedRealtimeMs) * 1000; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 7498 | } |
| 7499 | |
| 7500 | @Override |
| 7501 | public long getWifiScanBackgroundTime(final long elapsedRealtimeUs) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 7502 | if (mWifiScanTimer == null || mWifiScanTimer.getSubTimer() == null) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 7503 | return 0; |
| 7504 | } |
| 7505 | final long elapsedRealtimeMs = (elapsedRealtimeUs + 500) / 1000; |
| 7506 | return mWifiScanTimer.getSubTimer().getTotalDurationMsLocked(elapsedRealtimeMs) * 1000; |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 7507 | } |
| 7508 | |
| 7509 | @Override |
Kweku Adams | 103351f | 2017-10-16 14:39:34 -0700 | [diff] [blame] | 7510 | public Timer getWifiScanBackgroundTimer() { |
| 7511 | if (mWifiScanTimer == null) { |
| 7512 | return null; |
| 7513 | } |
| 7514 | return mWifiScanTimer.getSubTimer(); |
| 7515 | } |
| 7516 | |
| 7517 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7518 | public long getWifiBatchedScanTime(int csphBin, long elapsedRealtimeUs, int which) { |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 7519 | if (csphBin < 0 || csphBin >= NUM_WIFI_BATCHED_SCAN_BINS) return 0; |
| 7520 | if (mWifiBatchedScanTimer[csphBin] == null) { |
| 7521 | return 0; |
| 7522 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7523 | return mWifiBatchedScanTimer[csphBin].getTotalTimeLocked(elapsedRealtimeUs, which); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 7524 | } |
| 7525 | |
| 7526 | @Override |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 7527 | public int getWifiBatchedScanCount(int csphBin, int which) { |
| 7528 | if (csphBin < 0 || csphBin >= NUM_WIFI_BATCHED_SCAN_BINS) return 0; |
| 7529 | if (mWifiBatchedScanTimer[csphBin] == null) { |
| 7530 | return 0; |
| 7531 | } |
| 7532 | return mWifiBatchedScanTimer[csphBin].getCountLocked(which); |
| 7533 | } |
| 7534 | |
| 7535 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7536 | public long getWifiMulticastTime(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7537 | if (mWifiMulticastTimer == null) { |
| 7538 | return 0; |
| 7539 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7540 | return mWifiMulticastTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 7541 | } |
| 7542 | |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7543 | @Override |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 7544 | public Timer getAudioTurnedOnTimer() { |
| 7545 | return mAudioTurnedOnTimer; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7546 | } |
| 7547 | |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7548 | @Override |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 7549 | public Timer getVideoTurnedOnTimer() { |
| 7550 | return mVideoTurnedOnTimer; |
| 7551 | } |
| 7552 | |
| 7553 | @Override |
| 7554 | public Timer getFlashlightTurnedOnTimer() { |
| 7555 | return mFlashlightTurnedOnTimer; |
| 7556 | } |
| 7557 | |
| 7558 | @Override |
| 7559 | public Timer getCameraTurnedOnTimer() { |
| 7560 | return mCameraTurnedOnTimer; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7561 | } |
| 7562 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 7563 | @Override |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 7564 | public Timer getForegroundActivityTimer() { |
| 7565 | return mForegroundActivityTimer; |
| 7566 | } |
| 7567 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 7568 | @Override |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 7569 | public Timer getForegroundServiceTimer() { |
| 7570 | return mForegroundServiceTimer; |
| 7571 | } |
| 7572 | |
| 7573 | @Override |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 7574 | public Timer getBluetoothScanTimer() { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 7575 | return mBluetoothScanTimer; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 7576 | } |
| 7577 | |
| 7578 | @Override |
| 7579 | public Timer getBluetoothScanBackgroundTimer() { |
| 7580 | if (mBluetoothScanTimer == null) { |
| 7581 | return null; |
| 7582 | } |
| 7583 | return mBluetoothScanTimer.getSubTimer(); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 7584 | } |
| 7585 | |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 7586 | @Override |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 7587 | public Timer getBluetoothUnoptimizedScanTimer() { |
| 7588 | return mBluetoothUnoptimizedScanTimer; |
| 7589 | } |
| 7590 | |
| 7591 | @Override |
| 7592 | public Timer getBluetoothUnoptimizedScanBackgroundTimer() { |
| 7593 | if (mBluetoothUnoptimizedScanTimer == null) { |
| 7594 | return null; |
| 7595 | } |
| 7596 | return mBluetoothUnoptimizedScanTimer.getSubTimer(); |
| 7597 | } |
| 7598 | |
| 7599 | @Override |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 7600 | public Counter getBluetoothScanResultCounter() { |
| 7601 | return mBluetoothScanResultCounter; |
| 7602 | } |
| 7603 | |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 7604 | @Override |
| 7605 | public Counter getBluetoothScanResultBgCounter() { |
| 7606 | return mBluetoothScanResultBgCounter; |
| 7607 | } |
| 7608 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 7609 | void makeProcessState(int i, Parcel in) { |
| 7610 | if (i < 0 || i >= NUM_PROCESS_STATE) return; |
| 7611 | |
| 7612 | if (in == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7613 | mProcessStateTimer[i] = new StopwatchTimer(mBsi.mClocks, this, PROCESS_STATE, null, |
| 7614 | mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 7615 | } else { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7616 | mProcessStateTimer[i] = new StopwatchTimer(mBsi.mClocks, this, PROCESS_STATE, null, |
| 7617 | mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 7618 | } |
| 7619 | } |
| 7620 | |
| 7621 | @Override |
| 7622 | public long getProcessStateTime(int state, long elapsedRealtimeUs, int which) { |
| 7623 | if (state < 0 || state >= NUM_PROCESS_STATE) return 0; |
| 7624 | if (mProcessStateTimer[state] == null) { |
| 7625 | return 0; |
| 7626 | } |
| 7627 | return mProcessStateTimer[state].getTotalTimeLocked(elapsedRealtimeUs, which); |
| 7628 | } |
| 7629 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 7630 | @Override |
Joe Onorato | 713fec8 | 2016-03-04 10:34:02 -0800 | [diff] [blame] | 7631 | public Timer getProcessStateTimer(int state) { |
| 7632 | if (state < 0 || state >= NUM_PROCESS_STATE) return null; |
| 7633 | return mProcessStateTimer[state]; |
| 7634 | } |
| 7635 | |
| 7636 | @Override |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 7637 | public Timer getVibratorOnTimer() { |
| 7638 | return mVibratorOnTimer; |
| 7639 | } |
| 7640 | |
| 7641 | @Override |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 7642 | public void noteUserActivityLocked(int type) { |
| 7643 | if (mUserActivityCounters == null) { |
| 7644 | initUserActivityLocked(); |
| 7645 | } |
Jeff Brown | df693de | 2012-07-27 12:03:38 -0700 | [diff] [blame] | 7646 | if (type >= 0 && type < NUM_USER_ACTIVITY_TYPES) { |
| 7647 | mUserActivityCounters[type].stepAtomic(); |
| 7648 | } else { |
| 7649 | Slog.w(TAG, "Unknown user activity type " + type + " was specified.", |
| 7650 | new Throwable()); |
| 7651 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 7652 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7653 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 7654 | @Override |
| 7655 | public boolean hasUserActivity() { |
| 7656 | return mUserActivityCounters != null; |
| 7657 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7658 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 7659 | @Override |
| 7660 | public int getUserActivityCount(int type, int which) { |
| 7661 | if (mUserActivityCounters == null) { |
| 7662 | return 0; |
| 7663 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 7664 | return mUserActivityCounters[type].getCountLocked(which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 7665 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7666 | |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 7667 | void makeWifiBatchedScanBin(int i, Parcel in) { |
| 7668 | if (i < 0 || i >= NUM_WIFI_BATCHED_SCAN_BINS) return; |
| 7669 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7670 | ArrayList<StopwatchTimer> collected = mBsi.mWifiBatchedScanTimers.get(i); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 7671 | if (collected == null) { |
| 7672 | collected = new ArrayList<StopwatchTimer>(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7673 | mBsi.mWifiBatchedScanTimers.put(i, collected); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 7674 | } |
| 7675 | if (in == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7676 | mWifiBatchedScanTimer[i] = new StopwatchTimer(mBsi.mClocks, this, WIFI_BATCHED_SCAN, |
| 7677 | collected, mBsi.mOnBatteryTimeBase); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 7678 | } else { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7679 | mWifiBatchedScanTimer[i] = new StopwatchTimer(mBsi.mClocks, this, WIFI_BATCHED_SCAN, |
| 7680 | collected, mBsi.mOnBatteryTimeBase, in); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 7681 | } |
| 7682 | } |
| 7683 | |
| 7684 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 7685 | void initUserActivityLocked() { |
| 7686 | mUserActivityCounters = new Counter[NUM_USER_ACTIVITY_TYPES]; |
| 7687 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7688 | mUserActivityCounters[i] = new Counter(mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 7689 | } |
| 7690 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7691 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 7692 | void noteNetworkActivityLocked(int type, long deltaBytes, long deltaPackets) { |
| 7693 | if (mNetworkByteActivityCounters == null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7694 | initNetworkActivityLocked(); |
| 7695 | } |
| 7696 | if (type >= 0 && type < NUM_NETWORK_ACTIVITY_TYPES) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 7697 | mNetworkByteActivityCounters[type].addCountLocked(deltaBytes); |
| 7698 | mNetworkPacketActivityCounters[type].addCountLocked(deltaPackets); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7699 | } else { |
| 7700 | Slog.w(TAG, "Unknown network activity type " + type + " was specified.", |
| 7701 | new Throwable()); |
| 7702 | } |
| 7703 | } |
| 7704 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 7705 | void noteMobileRadioActiveTimeLocked(long batteryUptime) { |
| 7706 | if (mNetworkByteActivityCounters == null) { |
| 7707 | initNetworkActivityLocked(); |
| 7708 | } |
| 7709 | mMobileRadioActiveTime.addCountLocked(batteryUptime); |
| 7710 | mMobileRadioActiveCount.addCountLocked(1); |
| 7711 | } |
| 7712 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7713 | @Override |
| 7714 | public boolean hasNetworkActivity() { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 7715 | return mNetworkByteActivityCounters != null; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7716 | } |
| 7717 | |
| 7718 | @Override |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 7719 | public long getNetworkActivityBytes(int type, int which) { |
| 7720 | if (mNetworkByteActivityCounters != null && type >= 0 |
| 7721 | && type < mNetworkByteActivityCounters.length) { |
| 7722 | return mNetworkByteActivityCounters[type].getCountLocked(which); |
| 7723 | } else { |
| 7724 | return 0; |
| 7725 | } |
| 7726 | } |
| 7727 | |
| 7728 | @Override |
| 7729 | public long getNetworkActivityPackets(int type, int which) { |
| 7730 | if (mNetworkPacketActivityCounters != null && type >= 0 |
| 7731 | && type < mNetworkPacketActivityCounters.length) { |
| 7732 | return mNetworkPacketActivityCounters[type].getCountLocked(which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7733 | } else { |
| 7734 | return 0; |
| 7735 | } |
| 7736 | } |
| 7737 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 7738 | @Override |
| 7739 | public long getMobileRadioActiveTime(int which) { |
| 7740 | return mMobileRadioActiveTime != null |
| 7741 | ? mMobileRadioActiveTime.getCountLocked(which) : 0; |
| 7742 | } |
| 7743 | |
| 7744 | @Override |
| 7745 | public int getMobileRadioActiveCount(int which) { |
| 7746 | return mMobileRadioActiveCount != null |
| 7747 | ? (int)mMobileRadioActiveCount.getCountLocked(which) : 0; |
| 7748 | } |
| 7749 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7750 | @Override |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 7751 | public long getUserCpuTimeUs(int which) { |
| 7752 | return mUserCpuTime.getCountLocked(which); |
| 7753 | } |
| 7754 | |
| 7755 | @Override |
| 7756 | public long getSystemCpuTimeUs(int which) { |
| 7757 | return mSystemCpuTime.getCountLocked(which); |
| 7758 | } |
| 7759 | |
| 7760 | @Override |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 7761 | public long getTimeAtCpuSpeed(int cluster, int step, int which) { |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 7762 | if (mCpuClusterSpeedTimesUs != null) { |
| 7763 | if (cluster >= 0 && cluster < mCpuClusterSpeedTimesUs.length) { |
| 7764 | final LongSamplingCounter[] cpuSpeedTimesUs = mCpuClusterSpeedTimesUs[cluster]; |
| 7765 | if (cpuSpeedTimesUs != null) { |
| 7766 | if (step >= 0 && step < cpuSpeedTimesUs.length) { |
| 7767 | final LongSamplingCounter c = cpuSpeedTimesUs[step]; |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 7768 | if (c != null) { |
| 7769 | return c.getCountLocked(which); |
| 7770 | } |
| 7771 | } |
| 7772 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 7773 | } |
| 7774 | } |
| 7775 | return 0; |
| 7776 | } |
| 7777 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 7778 | public void noteMobileRadioApWakeupLocked() { |
| 7779 | if (mMobileRadioApWakeupCount == null) { |
| 7780 | mMobileRadioApWakeupCount = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
| 7781 | } |
| 7782 | mMobileRadioApWakeupCount.addCountLocked(1); |
| 7783 | } |
| 7784 | |
| 7785 | @Override |
| 7786 | public long getMobileRadioApWakeupCount(int which) { |
| 7787 | if (mMobileRadioApWakeupCount != null) { |
| 7788 | return mMobileRadioApWakeupCount.getCountLocked(which); |
| 7789 | } |
| 7790 | return 0; |
| 7791 | } |
| 7792 | |
| 7793 | public void noteWifiRadioApWakeupLocked() { |
| 7794 | if (mWifiRadioApWakeupCount == null) { |
| 7795 | mWifiRadioApWakeupCount = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
| 7796 | } |
| 7797 | mWifiRadioApWakeupCount.addCountLocked(1); |
| 7798 | } |
| 7799 | |
| 7800 | @Override |
| 7801 | public long getWifiRadioApWakeupCount(int which) { |
| 7802 | if (mWifiRadioApWakeupCount != null) { |
| 7803 | return mWifiRadioApWakeupCount.getCountLocked(which); |
| 7804 | } |
| 7805 | return 0; |
| 7806 | } |
| 7807 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7808 | void initNetworkActivityLocked() { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 7809 | mNetworkByteActivityCounters = new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
| 7810 | mNetworkPacketActivityCounters = new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7811 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7812 | mNetworkByteActivityCounters[i] = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
| 7813 | mNetworkPacketActivityCounters[i] = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7814 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7815 | mMobileRadioActiveTime = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
| 7816 | mMobileRadioActiveCount = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7817 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 7818 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7819 | /** |
| 7820 | * Clear all stats for this uid. Returns true if the uid is completely |
| 7821 | * inactive so can be dropped. |
| 7822 | */ |
Adam Lesinski | 5f212c8 | 2017-03-13 12:25:13 -0700 | [diff] [blame] | 7823 | @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
Bookatz | 993a0be | 2017-07-21 09:03:23 -0700 | [diff] [blame] | 7824 | public boolean reset(long uptime, long realtime) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7825 | boolean active = false; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7826 | |
Bookatz | 993a0be | 2017-07-21 09:03:23 -0700 | [diff] [blame] | 7827 | mOnBatteryBackgroundTimeBase.init(uptime, realtime); |
| 7828 | mOnBatteryScreenOffBackgroundTimeBase.init(uptime, realtime); |
| 7829 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 7830 | if (mWifiRunningTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7831 | active |= !mWifiRunningTimer.reset(false); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 7832 | active |= mWifiRunning; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7833 | } |
| 7834 | if (mFullWifiLockTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7835 | active |= !mFullWifiLockTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7836 | active |= mFullWifiLockOut; |
| 7837 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 7838 | if (mWifiScanTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7839 | active |= !mWifiScanTimer.reset(false); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 7840 | active |= mWifiScanStarted; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7841 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 7842 | if (mWifiBatchedScanTimer != null) { |
| 7843 | for (int i = 0; i < NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 7844 | if (mWifiBatchedScanTimer[i] != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7845 | active |= !mWifiBatchedScanTimer[i].reset(false); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 7846 | } |
| 7847 | } |
| 7848 | active |= (mWifiBatchedScanBinStarted != NO_BATCHED_SCAN_STARTED); |
| 7849 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7850 | if (mWifiMulticastTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7851 | active |= !mWifiMulticastTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7852 | active |= mWifiMulticastEnabled; |
| 7853 | } |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 7854 | |
| 7855 | active |= !resetTimerIfNotNull(mAudioTurnedOnTimer, false); |
| 7856 | active |= !resetTimerIfNotNull(mVideoTurnedOnTimer, false); |
| 7857 | active |= !resetTimerIfNotNull(mFlashlightTurnedOnTimer, false); |
| 7858 | active |= !resetTimerIfNotNull(mCameraTurnedOnTimer, false); |
| 7859 | active |= !resetTimerIfNotNull(mForegroundActivityTimer, false); |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 7860 | active |= !resetTimerIfNotNull(mForegroundServiceTimer, false); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 7861 | active |= !resetTimerIfNotNull(mAggregatedPartialWakelockTimer, false); |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 7862 | active |= !resetTimerIfNotNull(mBluetoothScanTimer, false); |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 7863 | active |= !resetTimerIfNotNull(mBluetoothUnoptimizedScanTimer, false); |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 7864 | if (mBluetoothScanResultCounter != null) { |
| 7865 | mBluetoothScanResultCounter.reset(false); |
| 7866 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 7867 | if (mBluetoothScanResultBgCounter != null) { |
| 7868 | mBluetoothScanResultBgCounter.reset(false); |
| 7869 | } |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 7870 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 7871 | if (mProcessStateTimer != null) { |
| 7872 | for (int i = 0; i < NUM_PROCESS_STATE; i++) { |
| 7873 | if (mProcessStateTimer[i] != null) { |
| 7874 | active |= !mProcessStateTimer[i].reset(false); |
| 7875 | } |
| 7876 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 7877 | active |= (mProcessState != ActivityManager.PROCESS_STATE_NONEXISTENT); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 7878 | } |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 7879 | if (mVibratorOnTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7880 | if (mVibratorOnTimer.reset(false)) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 7881 | mVibratorOnTimer.detach(); |
| 7882 | mVibratorOnTimer = null; |
| 7883 | } else { |
| 7884 | active = true; |
| 7885 | } |
| 7886 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7887 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7888 | if (mUserActivityCounters != null) { |
| 7889 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
| 7890 | mUserActivityCounters[i].reset(false); |
| 7891 | } |
| 7892 | } |
| 7893 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 7894 | if (mNetworkByteActivityCounters != null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7895 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 7896 | mNetworkByteActivityCounters[i].reset(false); |
| 7897 | mNetworkPacketActivityCounters[i].reset(false); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7898 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 7899 | mMobileRadioActiveTime.reset(false); |
| 7900 | mMobileRadioActiveCount.reset(false); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7901 | } |
| 7902 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 7903 | if (mWifiControllerActivity != null) { |
| 7904 | mWifiControllerActivity.reset(false); |
| 7905 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7906 | |
Adam Lesinski | 1a2b39e | 2016-04-29 17:56:58 -0700 | [diff] [blame] | 7907 | if (mBluetoothControllerActivity != null) { |
| 7908 | mBluetoothControllerActivity.reset(false); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 7909 | } |
| 7910 | |
Adam Lesinski | 1a2b39e | 2016-04-29 17:56:58 -0700 | [diff] [blame] | 7911 | if (mModemControllerActivity != null) { |
| 7912 | mModemControllerActivity.reset(false); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7913 | } |
| 7914 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 7915 | mUserCpuTime.reset(false); |
| 7916 | mSystemCpuTime.reset(false); |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 7917 | |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 7918 | if (mCpuClusterSpeedTimesUs != null) { |
| 7919 | for (LongSamplingCounter[] speeds : mCpuClusterSpeedTimesUs) { |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 7920 | if (speeds != null) { |
| 7921 | for (LongSamplingCounter speed : speeds) { |
| 7922 | if (speed != null) { |
| 7923 | speed.reset(false); |
| 7924 | } |
| 7925 | } |
| 7926 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 7927 | } |
| 7928 | } |
| 7929 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 7930 | if (mCpuFreqTimeMs != null) { |
| 7931 | mCpuFreqTimeMs.reset(false); |
| 7932 | } |
| 7933 | if (mScreenOffCpuFreqTimeMs != null) { |
| 7934 | mScreenOffCpuFreqTimeMs.reset(false); |
| 7935 | } |
| 7936 | |
Mike Ma | 3d422c3 | 2017-10-25 11:08:57 -0700 | [diff] [blame] | 7937 | mCpuActiveTimeMs.reset(false); |
| 7938 | mCpuClusterTimesMs.reset(false); |
| 7939 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 7940 | if (mProcStateTimeMs != null) { |
| 7941 | for (LongSamplingCounterArray counters : mProcStateTimeMs) { |
| 7942 | if (counters != null) { |
| 7943 | counters.reset(false); |
| 7944 | } |
| 7945 | } |
| 7946 | } |
| 7947 | if (mProcStateScreenOffTimeMs != null) { |
| 7948 | for (LongSamplingCounterArray counters : mProcStateScreenOffTimeMs) { |
| 7949 | if (counters != null) { |
| 7950 | counters.reset(false); |
| 7951 | } |
| 7952 | } |
| 7953 | } |
| 7954 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 7955 | resetLongCounterIfNotNull(mMobileRadioApWakeupCount, false); |
| 7956 | resetLongCounterIfNotNull(mWifiRadioApWakeupCount, false); |
| 7957 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7958 | final ArrayMap<String, Wakelock> wakeStats = mWakelockStats.getMap(); |
| 7959 | for (int iw=wakeStats.size()-1; iw>=0; iw--) { |
| 7960 | Wakelock wl = wakeStats.valueAt(iw); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 7961 | if (wl.reset()) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7962 | wakeStats.removeAt(iw); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 7963 | } else { |
| 7964 | active = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7965 | } |
| 7966 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7967 | mWakelockStats.cleanup(); |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 7968 | final ArrayMap<String, DualTimer> syncStats = mSyncStats.getMap(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7969 | for (int is=syncStats.size()-1; is>=0; is--) { |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 7970 | DualTimer timer = syncStats.valueAt(is); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 7971 | if (timer.reset(false)) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7972 | syncStats.removeAt(is); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 7973 | timer.detach(); |
| 7974 | } else { |
| 7975 | active = true; |
| 7976 | } |
| 7977 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7978 | mSyncStats.cleanup(); |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 7979 | final ArrayMap<String, DualTimer> jobStats = mJobStats.getMap(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7980 | for (int ij=jobStats.size()-1; ij>=0; ij--) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 7981 | DualTimer timer = jobStats.valueAt(ij); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 7982 | if (timer.reset(false)) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7983 | jobStats.removeAt(ij); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 7984 | timer.detach(); |
| 7985 | } else { |
| 7986 | active = true; |
| 7987 | } |
| 7988 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7989 | mJobStats.cleanup(); |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 7990 | mJobCompletions.clear(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 7991 | for (int ise=mSensorStats.size()-1; ise>=0; ise--) { |
| 7992 | Sensor s = mSensorStats.valueAt(ise); |
| 7993 | if (s.reset()) { |
| 7994 | mSensorStats.removeAt(ise); |
| 7995 | } else { |
| 7996 | active = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7997 | } |
| 7998 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 7999 | for (int ip=mProcessStats.size()-1; ip>=0; ip--) { |
| 8000 | Proc proc = mProcessStats.valueAt(ip); |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 8001 | proc.detach(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8002 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 8003 | mProcessStats.clear(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 8004 | if (mPids.size() > 0) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 8005 | for (int i=mPids.size()-1; i>=0; i--) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 8006 | Pid pid = mPids.valueAt(i); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 8007 | if (pid.mWakeNesting > 0) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 8008 | active = true; |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 8009 | } else { |
| 8010 | mPids.removeAt(i); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 8011 | } |
| 8012 | } |
| 8013 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8014 | if (mPackageStats.size() > 0) { |
| 8015 | Iterator<Map.Entry<String, Pkg>> it = mPackageStats.entrySet().iterator(); |
| 8016 | while (it.hasNext()) { |
| 8017 | Map.Entry<String, Pkg> pkgEntry = it.next(); |
| 8018 | Pkg p = pkgEntry.getValue(); |
| 8019 | p.detach(); |
| 8020 | if (p.mServiceStats.size() > 0) { |
| 8021 | Iterator<Map.Entry<String, Pkg.Serv>> it2 |
| 8022 | = p.mServiceStats.entrySet().iterator(); |
| 8023 | while (it2.hasNext()) { |
| 8024 | Map.Entry<String, Pkg.Serv> servEntry = it2.next(); |
| 8025 | servEntry.getValue().detach(); |
| 8026 | } |
| 8027 | } |
| 8028 | } |
| 8029 | mPackageStats.clear(); |
| 8030 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8031 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 8032 | mLastStepUserTime = mLastStepSystemTime = 0; |
| 8033 | mCurStepUserTime = mCurStepSystemTime = 0; |
| 8034 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8035 | if (!active) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 8036 | if (mWifiRunningTimer != null) { |
| 8037 | mWifiRunningTimer.detach(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8038 | } |
| 8039 | if (mFullWifiLockTimer != null) { |
| 8040 | mFullWifiLockTimer.detach(); |
| 8041 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 8042 | if (mWifiScanTimer != null) { |
| 8043 | mWifiScanTimer.detach(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8044 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 8045 | for (int i = 0; i < NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 8046 | if (mWifiBatchedScanTimer[i] != null) { |
| 8047 | mWifiBatchedScanTimer[i].detach(); |
| 8048 | } |
| 8049 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8050 | if (mWifiMulticastTimer != null) { |
| 8051 | mWifiMulticastTimer.detach(); |
| 8052 | } |
| 8053 | if (mAudioTurnedOnTimer != null) { |
| 8054 | mAudioTurnedOnTimer.detach(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 8055 | mAudioTurnedOnTimer = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8056 | } |
| 8057 | if (mVideoTurnedOnTimer != null) { |
| 8058 | mVideoTurnedOnTimer.detach(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 8059 | mVideoTurnedOnTimer = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8060 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 8061 | if (mFlashlightTurnedOnTimer != null) { |
| 8062 | mFlashlightTurnedOnTimer.detach(); |
| 8063 | mFlashlightTurnedOnTimer = null; |
| 8064 | } |
| 8065 | if (mCameraTurnedOnTimer != null) { |
| 8066 | mCameraTurnedOnTimer.detach(); |
| 8067 | mCameraTurnedOnTimer = null; |
| 8068 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 8069 | if (mForegroundActivityTimer != null) { |
| 8070 | mForegroundActivityTimer.detach(); |
| 8071 | mForegroundActivityTimer = null; |
| 8072 | } |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 8073 | if (mForegroundServiceTimer != null) { |
| 8074 | mForegroundServiceTimer.detach(); |
| 8075 | mForegroundServiceTimer = null; |
| 8076 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 8077 | if (mAggregatedPartialWakelockTimer != null) { |
| 8078 | mAggregatedPartialWakelockTimer.detach(); |
| 8079 | mAggregatedPartialWakelockTimer = null; |
| 8080 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 8081 | if (mBluetoothScanTimer != null) { |
| 8082 | mBluetoothScanTimer.detach(); |
| 8083 | mBluetoothScanTimer = null; |
| 8084 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 8085 | if (mBluetoothUnoptimizedScanTimer != null) { |
| 8086 | mBluetoothUnoptimizedScanTimer.detach(); |
| 8087 | mBluetoothUnoptimizedScanTimer = null; |
| 8088 | } |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 8089 | if (mBluetoothScanResultCounter != null) { |
| 8090 | mBluetoothScanResultCounter.detach(); |
| 8091 | mBluetoothScanResultCounter = null; |
| 8092 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 8093 | if (mBluetoothScanResultBgCounter != null) { |
| 8094 | mBluetoothScanResultBgCounter.detach(); |
| 8095 | mBluetoothScanResultBgCounter = null; |
| 8096 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8097 | if (mUserActivityCounters != null) { |
| 8098 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
| 8099 | mUserActivityCounters[i].detach(); |
| 8100 | } |
| 8101 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 8102 | if (mNetworkByteActivityCounters != null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 8103 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 8104 | mNetworkByteActivityCounters[i].detach(); |
| 8105 | mNetworkPacketActivityCounters[i].detach(); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 8106 | } |
| 8107 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8108 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8109 | if (mWifiControllerActivity != null) { |
| 8110 | mWifiControllerActivity.detach(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8111 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8112 | |
| 8113 | if (mBluetoothControllerActivity != null) { |
| 8114 | mBluetoothControllerActivity.detach(); |
| 8115 | } |
| 8116 | |
| 8117 | if (mModemControllerActivity != null) { |
| 8118 | mModemControllerActivity.detach(); |
| 8119 | } |
| 8120 | |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 8121 | mPids.clear(); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 8122 | |
| 8123 | mUserCpuTime.detach(); |
| 8124 | mSystemCpuTime.detach(); |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 8125 | |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 8126 | if (mCpuClusterSpeedTimesUs != null) { |
| 8127 | for (LongSamplingCounter[] cpuSpeeds : mCpuClusterSpeedTimesUs) { |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 8128 | if (cpuSpeeds != null) { |
| 8129 | for (LongSamplingCounter c : cpuSpeeds) { |
| 8130 | if (c != null) { |
| 8131 | c.detach(); |
| 8132 | } |
| 8133 | } |
| 8134 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 8135 | } |
| 8136 | } |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 8137 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 8138 | if (mCpuFreqTimeMs != null) { |
| 8139 | mCpuFreqTimeMs.detach(); |
| 8140 | } |
| 8141 | if (mScreenOffCpuFreqTimeMs != null) { |
| 8142 | mScreenOffCpuFreqTimeMs.detach(); |
| 8143 | } |
Mike Ma | 3d422c3 | 2017-10-25 11:08:57 -0700 | [diff] [blame] | 8144 | mCpuActiveTimeMs.detach(); |
| 8145 | mCpuClusterTimesMs.detach(); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 8146 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 8147 | if (mProcStateTimeMs != null) { |
| 8148 | for (LongSamplingCounterArray counters : mProcStateTimeMs) { |
| 8149 | if (counters != null) { |
| 8150 | counters.detach(); |
| 8151 | } |
| 8152 | } |
| 8153 | } |
| 8154 | if (mProcStateScreenOffTimeMs != null) { |
| 8155 | for (LongSamplingCounterArray counters : mProcStateScreenOffTimeMs) { |
| 8156 | if (counters != null) { |
| 8157 | counters.detach(); |
| 8158 | } |
| 8159 | } |
| 8160 | } |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 8161 | detachLongCounterIfNotNull(mMobileRadioApWakeupCount); |
| 8162 | detachLongCounterIfNotNull(mWifiRadioApWakeupCount); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8163 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8164 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8165 | return !active; |
| 8166 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8167 | |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 8168 | void writeJobCompletionsToParcelLocked(Parcel out) { |
| 8169 | int NJC = mJobCompletions.size(); |
| 8170 | out.writeInt(NJC); |
| 8171 | for (int ijc=0; ijc<NJC; ijc++) { |
| 8172 | out.writeString(mJobCompletions.keyAt(ijc)); |
| 8173 | SparseIntArray types = mJobCompletions.valueAt(ijc); |
| 8174 | int NT = types.size(); |
| 8175 | out.writeInt(NT); |
| 8176 | for (int it=0; it<NT; it++) { |
| 8177 | out.writeInt(types.keyAt(it)); |
| 8178 | out.writeInt(types.valueAt(it)); |
| 8179 | } |
| 8180 | } |
| 8181 | } |
| 8182 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 8183 | void writeToParcelLocked(Parcel out, long uptimeUs, long elapsedRealtimeUs) { |
| 8184 | mOnBatteryBackgroundTimeBase.writeToParcel(out, uptimeUs, elapsedRealtimeUs); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 8185 | mOnBatteryScreenOffBackgroundTimeBase.writeToParcel(out, uptimeUs, elapsedRealtimeUs); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 8186 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8187 | final ArrayMap<String, Wakelock> wakeStats = mWakelockStats.getMap(); |
| 8188 | int NW = wakeStats.size(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 8189 | out.writeInt(NW); |
| 8190 | for (int iw=0; iw<NW; iw++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8191 | out.writeString(wakeStats.keyAt(iw)); |
| 8192 | Uid.Wakelock wakelock = wakeStats.valueAt(iw); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8193 | wakelock.writeToParcelLocked(out, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8194 | } |
| 8195 | |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 8196 | final ArrayMap<String, DualTimer> syncStats = mSyncStats.getMap(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8197 | int NS = syncStats.size(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 8198 | out.writeInt(NS); |
| 8199 | for (int is=0; is<NS; is++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8200 | out.writeString(syncStats.keyAt(is)); |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 8201 | DualTimer timer = syncStats.valueAt(is); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 8202 | Timer.writeTimerToParcel(out, timer, elapsedRealtimeUs); |
| 8203 | } |
| 8204 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 8205 | final ArrayMap<String, DualTimer> jobStats = mJobStats.getMap(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8206 | int NJ = jobStats.size(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 8207 | out.writeInt(NJ); |
| 8208 | for (int ij=0; ij<NJ; ij++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8209 | out.writeString(jobStats.keyAt(ij)); |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 8210 | DualTimer timer = jobStats.valueAt(ij); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 8211 | Timer.writeTimerToParcel(out, timer, elapsedRealtimeUs); |
| 8212 | } |
| 8213 | |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 8214 | writeJobCompletionsToParcelLocked(out); |
| 8215 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 8216 | int NSE = mSensorStats.size(); |
| 8217 | out.writeInt(NSE); |
| 8218 | for (int ise=0; ise<NSE; ise++) { |
| 8219 | out.writeInt(mSensorStats.keyAt(ise)); |
| 8220 | Uid.Sensor sensor = mSensorStats.valueAt(ise); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8221 | sensor.writeToParcelLocked(out, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8222 | } |
| 8223 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 8224 | int NP = mProcessStats.size(); |
| 8225 | out.writeInt(NP); |
| 8226 | for (int ip=0; ip<NP; ip++) { |
| 8227 | out.writeString(mProcessStats.keyAt(ip)); |
| 8228 | Uid.Proc proc = mProcessStats.valueAt(ip); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8229 | proc.writeToParcelLocked(out); |
| 8230 | } |
| 8231 | |
| 8232 | out.writeInt(mPackageStats.size()); |
| 8233 | for (Map.Entry<String, Uid.Pkg> pkgEntry : mPackageStats.entrySet()) { |
| 8234 | out.writeString(pkgEntry.getKey()); |
| 8235 | Uid.Pkg pkg = pkgEntry.getValue(); |
| 8236 | pkg.writeToParcelLocked(out); |
| 8237 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8238 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 8239 | if (mWifiRunningTimer != null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8240 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8241 | mWifiRunningTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 8242 | } else { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8243 | out.writeInt(0); |
| 8244 | } |
| 8245 | if (mFullWifiLockTimer != null) { |
| 8246 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8247 | mFullWifiLockTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8248 | } else { |
| 8249 | out.writeInt(0); |
| 8250 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 8251 | if (mWifiScanTimer != null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8252 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8253 | mWifiScanTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8254 | } else { |
| 8255 | out.writeInt(0); |
| 8256 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 8257 | for (int i = 0; i < NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 8258 | if (mWifiBatchedScanTimer[i] != null) { |
| 8259 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8260 | mWifiBatchedScanTimer[i].writeToParcel(out, elapsedRealtimeUs); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 8261 | } else { |
| 8262 | out.writeInt(0); |
| 8263 | } |
| 8264 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8265 | if (mWifiMulticastTimer != null) { |
| 8266 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8267 | mWifiMulticastTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8268 | } else { |
| 8269 | out.writeInt(0); |
| 8270 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8271 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8272 | if (mAudioTurnedOnTimer != null) { |
| 8273 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8274 | mAudioTurnedOnTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8275 | } else { |
| 8276 | out.writeInt(0); |
| 8277 | } |
| 8278 | if (mVideoTurnedOnTimer != null) { |
| 8279 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8280 | mVideoTurnedOnTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8281 | } else { |
| 8282 | out.writeInt(0); |
| 8283 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 8284 | if (mFlashlightTurnedOnTimer != null) { |
| 8285 | out.writeInt(1); |
| 8286 | mFlashlightTurnedOnTimer.writeToParcel(out, elapsedRealtimeUs); |
| 8287 | } else { |
| 8288 | out.writeInt(0); |
| 8289 | } |
| 8290 | if (mCameraTurnedOnTimer != null) { |
| 8291 | out.writeInt(1); |
| 8292 | mCameraTurnedOnTimer.writeToParcel(out, elapsedRealtimeUs); |
| 8293 | } else { |
| 8294 | out.writeInt(0); |
| 8295 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 8296 | if (mForegroundActivityTimer != null) { |
| 8297 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8298 | mForegroundActivityTimer.writeToParcel(out, elapsedRealtimeUs); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 8299 | } else { |
| 8300 | out.writeInt(0); |
| 8301 | } |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 8302 | if (mForegroundServiceTimer != null) { |
| 8303 | out.writeInt(1); |
| 8304 | mForegroundServiceTimer.writeToParcel(out, elapsedRealtimeUs); |
| 8305 | } else { |
| 8306 | out.writeInt(0); |
| 8307 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 8308 | if (mAggregatedPartialWakelockTimer != null) { |
| 8309 | out.writeInt(1); |
| 8310 | mAggregatedPartialWakelockTimer.writeToParcel(out, elapsedRealtimeUs); |
| 8311 | } else { |
| 8312 | out.writeInt(0); |
| 8313 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 8314 | if (mBluetoothScanTimer != null) { |
| 8315 | out.writeInt(1); |
| 8316 | mBluetoothScanTimer.writeToParcel(out, elapsedRealtimeUs); |
| 8317 | } else { |
| 8318 | out.writeInt(0); |
| 8319 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 8320 | if (mBluetoothUnoptimizedScanTimer != null) { |
| 8321 | out.writeInt(1); |
| 8322 | mBluetoothUnoptimizedScanTimer.writeToParcel(out, elapsedRealtimeUs); |
| 8323 | } else { |
| 8324 | out.writeInt(0); |
| 8325 | } |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 8326 | if (mBluetoothScanResultCounter != null) { |
| 8327 | out.writeInt(1); |
| 8328 | mBluetoothScanResultCounter.writeToParcel(out); |
| 8329 | } else { |
| 8330 | out.writeInt(0); |
| 8331 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 8332 | if (mBluetoothScanResultBgCounter != null) { |
| 8333 | out.writeInt(1); |
| 8334 | mBluetoothScanResultBgCounter.writeToParcel(out); |
| 8335 | } else { |
| 8336 | out.writeInt(0); |
| 8337 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 8338 | for (int i = 0; i < NUM_PROCESS_STATE; i++) { |
| 8339 | if (mProcessStateTimer[i] != null) { |
| 8340 | out.writeInt(1); |
| 8341 | mProcessStateTimer[i].writeToParcel(out, elapsedRealtimeUs); |
| 8342 | } else { |
| 8343 | out.writeInt(0); |
| 8344 | } |
| 8345 | } |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 8346 | if (mVibratorOnTimer != null) { |
| 8347 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8348 | mVibratorOnTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 8349 | } else { |
| 8350 | out.writeInt(0); |
| 8351 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8352 | if (mUserActivityCounters != null) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 8353 | out.writeInt(1); |
| 8354 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
| 8355 | mUserActivityCounters[i].writeToParcel(out); |
| 8356 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8357 | } else { |
| 8358 | out.writeInt(0); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 8359 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 8360 | if (mNetworkByteActivityCounters != null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 8361 | out.writeInt(1); |
| 8362 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 8363 | mNetworkByteActivityCounters[i].writeToParcel(out); |
| 8364 | mNetworkPacketActivityCounters[i].writeToParcel(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 8365 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 8366 | mMobileRadioActiveTime.writeToParcel(out); |
| 8367 | mMobileRadioActiveCount.writeToParcel(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 8368 | } else { |
| 8369 | out.writeInt(0); |
| 8370 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8371 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8372 | if (mWifiControllerActivity != null) { |
| 8373 | out.writeInt(1); |
| 8374 | mWifiControllerActivity.writeToParcel(out, 0); |
| 8375 | } else { |
| 8376 | out.writeInt(0); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8377 | } |
| 8378 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8379 | if (mBluetoothControllerActivity != null) { |
| 8380 | out.writeInt(1); |
| 8381 | mBluetoothControllerActivity.writeToParcel(out, 0); |
| 8382 | } else { |
| 8383 | out.writeInt(0); |
| 8384 | } |
| 8385 | |
| 8386 | if (mModemControllerActivity != null) { |
| 8387 | out.writeInt(1); |
| 8388 | mModemControllerActivity.writeToParcel(out, 0); |
| 8389 | } else { |
| 8390 | out.writeInt(0); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8391 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 8392 | |
| 8393 | mUserCpuTime.writeToParcel(out); |
| 8394 | mSystemCpuTime.writeToParcel(out); |
| 8395 | |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 8396 | if (mCpuClusterSpeedTimesUs != null) { |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 8397 | out.writeInt(1); |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 8398 | out.writeInt(mCpuClusterSpeedTimesUs.length); |
| 8399 | for (LongSamplingCounter[] cpuSpeeds : mCpuClusterSpeedTimesUs) { |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 8400 | if (cpuSpeeds != null) { |
| 8401 | out.writeInt(1); |
| 8402 | out.writeInt(cpuSpeeds.length); |
| 8403 | for (LongSamplingCounter c : cpuSpeeds) { |
| 8404 | if (c != null) { |
| 8405 | out.writeInt(1); |
| 8406 | c.writeToParcel(out); |
| 8407 | } else { |
| 8408 | out.writeInt(0); |
| 8409 | } |
| 8410 | } |
| 8411 | } else { |
| 8412 | out.writeInt(0); |
| 8413 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 8414 | } |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 8415 | } else { |
| 8416 | out.writeInt(0); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 8417 | } |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 8418 | |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 8419 | LongSamplingCounterArray.writeToParcel(out, mCpuFreqTimeMs); |
| 8420 | LongSamplingCounterArray.writeToParcel(out, mScreenOffCpuFreqTimeMs); |
Mike Ma | 3d422c3 | 2017-10-25 11:08:57 -0700 | [diff] [blame] | 8421 | |
| 8422 | mCpuActiveTimeMs.writeToParcel(out); |
| 8423 | mCpuClusterTimesMs.writeToParcel(out); |
| 8424 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 8425 | if (mProcStateTimeMs != null) { |
| 8426 | out.writeInt(mProcStateTimeMs.length); |
| 8427 | for (LongSamplingCounterArray counters : mProcStateTimeMs) { |
| 8428 | LongSamplingCounterArray.writeToParcel(out, counters); |
| 8429 | } |
| 8430 | } else { |
| 8431 | out.writeInt(0); |
| 8432 | } |
| 8433 | if (mProcStateScreenOffTimeMs != null) { |
| 8434 | out.writeInt(mProcStateScreenOffTimeMs.length); |
| 8435 | for (LongSamplingCounterArray counters : mProcStateScreenOffTimeMs) { |
| 8436 | LongSamplingCounterArray.writeToParcel(out, counters); |
| 8437 | } |
| 8438 | } else { |
| 8439 | out.writeInt(0); |
| 8440 | } |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 8441 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 8442 | if (mMobileRadioApWakeupCount != null) { |
| 8443 | out.writeInt(1); |
| 8444 | mMobileRadioApWakeupCount.writeToParcel(out); |
| 8445 | } else { |
| 8446 | out.writeInt(0); |
| 8447 | } |
| 8448 | |
| 8449 | if (mWifiRadioApWakeupCount != null) { |
| 8450 | out.writeInt(1); |
| 8451 | mWifiRadioApWakeupCount.writeToParcel(out); |
| 8452 | } else { |
| 8453 | out.writeInt(0); |
| 8454 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8455 | } |
| 8456 | |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 8457 | void readJobCompletionsFromParcelLocked(Parcel in) { |
| 8458 | int numJobCompletions = in.readInt(); |
| 8459 | mJobCompletions.clear(); |
| 8460 | for (int j = 0; j < numJobCompletions; j++) { |
| 8461 | String jobName = in.readString(); |
| 8462 | int numTypes = in.readInt(); |
| 8463 | if (numTypes > 0) { |
| 8464 | SparseIntArray types = new SparseIntArray(); |
| 8465 | for (int k = 0; k < numTypes; k++) { |
| 8466 | int type = in.readInt(); |
| 8467 | int count = in.readInt(); |
| 8468 | types.put(type, count); |
| 8469 | } |
| 8470 | mJobCompletions.put(jobName, types); |
| 8471 | } |
| 8472 | } |
| 8473 | } |
| 8474 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8475 | void readFromParcelLocked(TimeBase timeBase, TimeBase screenOffTimeBase, Parcel in) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 8476 | mOnBatteryBackgroundTimeBase.readFromParcel(in); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 8477 | mOnBatteryScreenOffBackgroundTimeBase.readFromParcel(in); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 8478 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8479 | int numWakelocks = in.readInt(); |
| 8480 | mWakelockStats.clear(); |
| 8481 | for (int j = 0; j < numWakelocks; j++) { |
| 8482 | String wakelockName = in.readString(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8483 | Uid.Wakelock wakelock = new Wakelock(mBsi, this); |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 8484 | wakelock.readFromParcelLocked( |
| 8485 | timeBase, screenOffTimeBase, mOnBatteryScreenOffBackgroundTimeBase, in); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8486 | mWakelockStats.add(wakelockName, wakelock); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8487 | } |
| 8488 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 8489 | int numSyncs = in.readInt(); |
| 8490 | mSyncStats.clear(); |
| 8491 | for (int j = 0; j < numSyncs; j++) { |
| 8492 | String syncName = in.readString(); |
| 8493 | if (in.readInt() != 0) { |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 8494 | mSyncStats.add(syncName, new DualTimer(mBsi.mClocks, Uid.this, SYNC, null, |
| 8495 | mBsi.mOnBatteryTimeBase, mOnBatteryBackgroundTimeBase, in)); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 8496 | } |
| 8497 | } |
| 8498 | |
| 8499 | int numJobs = in.readInt(); |
| 8500 | mJobStats.clear(); |
| 8501 | for (int j = 0; j < numJobs; j++) { |
| 8502 | String jobName = in.readString(); |
| 8503 | if (in.readInt() != 0) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 8504 | mJobStats.add(jobName, new DualTimer(mBsi.mClocks, Uid.this, JOB, null, |
| 8505 | mBsi.mOnBatteryTimeBase, mOnBatteryBackgroundTimeBase, in)); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 8506 | } |
| 8507 | } |
| 8508 | |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 8509 | readJobCompletionsFromParcelLocked(in); |
| 8510 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8511 | int numSensors = in.readInt(); |
| 8512 | mSensorStats.clear(); |
| 8513 | for (int k = 0; k < numSensors; k++) { |
| 8514 | int sensorNumber = in.readInt(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8515 | Uid.Sensor sensor = new Sensor(mBsi, this, sensorNumber); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 8516 | sensor.readFromParcelLocked(mBsi.mOnBatteryTimeBase, mOnBatteryBackgroundTimeBase, |
| 8517 | in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8518 | mSensorStats.put(sensorNumber, sensor); |
| 8519 | } |
| 8520 | |
| 8521 | int numProcs = in.readInt(); |
| 8522 | mProcessStats.clear(); |
| 8523 | for (int k = 0; k < numProcs; k++) { |
| 8524 | String processName = in.readString(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8525 | Uid.Proc proc = new Proc(mBsi, processName); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8526 | proc.readFromParcelLocked(in); |
| 8527 | mProcessStats.put(processName, proc); |
| 8528 | } |
| 8529 | |
| 8530 | int numPkgs = in.readInt(); |
| 8531 | mPackageStats.clear(); |
| 8532 | for (int l = 0; l < numPkgs; l++) { |
| 8533 | String packageName = in.readString(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8534 | Uid.Pkg pkg = new Pkg(mBsi); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8535 | pkg.readFromParcelLocked(in); |
| 8536 | mPackageStats.put(packageName, pkg); |
| 8537 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8538 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 8539 | mWifiRunning = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8540 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8541 | mWifiRunningTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, WIFI_RUNNING, |
| 8542 | mBsi.mWifiRunningTimers, mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 8543 | } else { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 8544 | mWifiRunningTimer = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8545 | } |
| 8546 | mFullWifiLockOut = false; |
| 8547 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8548 | mFullWifiLockTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, FULL_WIFI_LOCK, |
| 8549 | mBsi.mFullWifiLockTimers, mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8550 | } else { |
| 8551 | mFullWifiLockTimer = null; |
| 8552 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 8553 | mWifiScanStarted = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8554 | if (in.readInt() != 0) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 8555 | mWifiScanTimer = new DualTimer(mBsi.mClocks, Uid.this, WIFI_SCAN, |
| 8556 | mBsi.mWifiScanTimers, mBsi.mOnBatteryTimeBase, mOnBatteryBackgroundTimeBase, |
| 8557 | in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8558 | } else { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 8559 | mWifiScanTimer = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8560 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 8561 | mWifiBatchedScanBinStarted = NO_BATCHED_SCAN_STARTED; |
| 8562 | for (int i = 0; i < NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 8563 | if (in.readInt() != 0) { |
| 8564 | makeWifiBatchedScanBin(i, in); |
| 8565 | } else { |
| 8566 | mWifiBatchedScanTimer[i] = null; |
| 8567 | } |
| 8568 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8569 | mWifiMulticastEnabled = false; |
| 8570 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8571 | mWifiMulticastTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, WIFI_MULTICAST_ENABLED, |
| 8572 | mBsi.mWifiMulticastTimers, mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8573 | } else { |
| 8574 | mWifiMulticastTimer = null; |
| 8575 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8576 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8577 | mAudioTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, AUDIO_TURNED_ON, |
| 8578 | mBsi.mAudioTurnedOnTimers, mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8579 | } else { |
| 8580 | mAudioTurnedOnTimer = null; |
| 8581 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8582 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8583 | mVideoTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, VIDEO_TURNED_ON, |
| 8584 | mBsi.mVideoTurnedOnTimers, mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8585 | } else { |
| 8586 | mVideoTurnedOnTimer = null; |
| 8587 | } |
| 8588 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8589 | mFlashlightTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, |
| 8590 | FLASHLIGHT_TURNED_ON, mBsi.mFlashlightTurnedOnTimers, mBsi.mOnBatteryTimeBase, in); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 8591 | } else { |
| 8592 | mFlashlightTurnedOnTimer = null; |
| 8593 | } |
| 8594 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8595 | mCameraTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, CAMERA_TURNED_ON, |
| 8596 | mBsi.mCameraTurnedOnTimers, mBsi.mOnBatteryTimeBase, in); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 8597 | } else { |
| 8598 | mCameraTurnedOnTimer = null; |
| 8599 | } |
| 8600 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8601 | mForegroundActivityTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, |
| 8602 | FOREGROUND_ACTIVITY, null, mBsi.mOnBatteryTimeBase, in); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 8603 | } else { |
| 8604 | mForegroundActivityTimer = null; |
| 8605 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 8606 | if (in.readInt() != 0) { |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 8607 | mForegroundServiceTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, |
| 8608 | FOREGROUND_SERVICE, null, mBsi.mOnBatteryTimeBase, in); |
| 8609 | } else { |
| 8610 | mForegroundServiceTimer = null; |
| 8611 | } |
| 8612 | if (in.readInt() != 0) { |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 8613 | mAggregatedPartialWakelockTimer = new DualTimer(mBsi.mClocks, this, |
| 8614 | AGGREGATED_WAKE_TYPE_PARTIAL, null, |
| 8615 | mBsi.mOnBatteryScreenOffTimeBase, mOnBatteryScreenOffBackgroundTimeBase, |
| 8616 | in); |
| 8617 | } else { |
| 8618 | mAggregatedPartialWakelockTimer = null; |
| 8619 | } |
| 8620 | if (in.readInt() != 0) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 8621 | mBluetoothScanTimer = new DualTimer(mBsi.mClocks, Uid.this, BLUETOOTH_SCAN_ON, |
| 8622 | mBsi.mBluetoothScanOnTimers, mBsi.mOnBatteryTimeBase, |
| 8623 | mOnBatteryBackgroundTimeBase, in); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 8624 | } else { |
| 8625 | mBluetoothScanTimer = null; |
| 8626 | } |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 8627 | if (in.readInt() != 0) { |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 8628 | mBluetoothUnoptimizedScanTimer = new DualTimer(mBsi.mClocks, Uid.this, |
| 8629 | BLUETOOTH_UNOPTIMIZED_SCAN_ON, null, |
| 8630 | mBsi.mOnBatteryTimeBase, mOnBatteryBackgroundTimeBase, in); |
| 8631 | } else { |
| 8632 | mBluetoothUnoptimizedScanTimer = null; |
| 8633 | } |
| 8634 | if (in.readInt() != 0) { |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 8635 | mBluetoothScanResultCounter = new Counter(mBsi.mOnBatteryTimeBase, in); |
| 8636 | } else { |
| 8637 | mBluetoothScanResultCounter = null; |
| 8638 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 8639 | if (in.readInt() != 0) { |
| 8640 | mBluetoothScanResultBgCounter = new Counter(mOnBatteryBackgroundTimeBase, in); |
| 8641 | } else { |
| 8642 | mBluetoothScanResultBgCounter = null; |
| 8643 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 8644 | mProcessState = ActivityManager.PROCESS_STATE_NONEXISTENT; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 8645 | for (int i = 0; i < NUM_PROCESS_STATE; i++) { |
| 8646 | if (in.readInt() != 0) { |
| 8647 | makeProcessState(i, in); |
| 8648 | } else { |
| 8649 | mProcessStateTimer[i] = null; |
| 8650 | } |
| 8651 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 8652 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8653 | mVibratorOnTimer = new BatchTimer(mBsi.mClocks, Uid.this, VIBRATOR_ON, |
| 8654 | mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 8655 | } else { |
| 8656 | mVibratorOnTimer = null; |
| 8657 | } |
| 8658 | if (in.readInt() != 0) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 8659 | mUserActivityCounters = new Counter[NUM_USER_ACTIVITY_TYPES]; |
| 8660 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8661 | mUserActivityCounters[i] = new Counter(mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 8662 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8663 | } else { |
| 8664 | mUserActivityCounters = null; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 8665 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 8666 | if (in.readInt() != 0) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 8667 | mNetworkByteActivityCounters = new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
| 8668 | mNetworkPacketActivityCounters |
| 8669 | = new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 8670 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8671 | mNetworkByteActivityCounters[i] |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8672 | = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8673 | mNetworkPacketActivityCounters[i] |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8674 | = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 8675 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8676 | mMobileRadioActiveTime = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
| 8677 | mMobileRadioActiveCount = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 8678 | } else { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 8679 | mNetworkByteActivityCounters = null; |
| 8680 | mNetworkPacketActivityCounters = null; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 8681 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8682 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8683 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8684 | mWifiControllerActivity = new ControllerActivityCounterImpl(mBsi.mOnBatteryTimeBase, |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8685 | NUM_WIFI_TX_LEVELS, in); |
| 8686 | } else { |
| 8687 | mWifiControllerActivity = null; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8688 | } |
| 8689 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8690 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8691 | mBluetoothControllerActivity = new ControllerActivityCounterImpl(mBsi.mOnBatteryTimeBase, |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8692 | NUM_BT_TX_LEVELS, in); |
| 8693 | } else { |
| 8694 | mBluetoothControllerActivity = null; |
| 8695 | } |
| 8696 | |
| 8697 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8698 | mModemControllerActivity = new ControllerActivityCounterImpl(mBsi.mOnBatteryTimeBase, |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8699 | ModemActivityInfo.TX_POWER_LEVELS, in); |
| 8700 | } else { |
| 8701 | mModemControllerActivity = null; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8702 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 8703 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8704 | mUserCpuTime = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
| 8705 | mSystemCpuTime = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 8706 | |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 8707 | if (in.readInt() != 0) { |
| 8708 | int numCpuClusters = in.readInt(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8709 | if (mBsi.mPowerProfile != null && mBsi.mPowerProfile.getNumCpuClusters() != numCpuClusters) { |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 8710 | throw new ParcelFormatException("Incompatible number of cpu clusters"); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 8711 | } |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 8712 | |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 8713 | mCpuClusterSpeedTimesUs = new LongSamplingCounter[numCpuClusters][]; |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 8714 | for (int cluster = 0; cluster < numCpuClusters; cluster++) { |
| 8715 | if (in.readInt() != 0) { |
| 8716 | int numSpeeds = in.readInt(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8717 | if (mBsi.mPowerProfile != null && |
| 8718 | mBsi.mPowerProfile.getNumSpeedStepsInCpuCluster(cluster) != numSpeeds) { |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 8719 | throw new ParcelFormatException("Incompatible number of cpu speeds"); |
| 8720 | } |
| 8721 | |
| 8722 | final LongSamplingCounter[] cpuSpeeds = new LongSamplingCounter[numSpeeds]; |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 8723 | mCpuClusterSpeedTimesUs[cluster] = cpuSpeeds; |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 8724 | for (int speed = 0; speed < numSpeeds; speed++) { |
| 8725 | if (in.readInt() != 0) { |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 8726 | cpuSpeeds[speed] = new LongSamplingCounter( |
| 8727 | mBsi.mOnBatteryTimeBase, in); |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 8728 | } |
| 8729 | } |
Adam Lesinski | a57a540 | 2015-09-28 10:21:33 -0700 | [diff] [blame] | 8730 | } else { |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 8731 | mCpuClusterSpeedTimesUs[cluster] = null; |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 8732 | } |
| 8733 | } |
| 8734 | } else { |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 8735 | mCpuClusterSpeedTimesUs = null; |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 8736 | } |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 8737 | |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 8738 | mCpuFreqTimeMs = LongSamplingCounterArray.readFromParcel(in, mBsi.mOnBatteryTimeBase); |
| 8739 | mScreenOffCpuFreqTimeMs = LongSamplingCounterArray.readFromParcel( |
| 8740 | in, mBsi.mOnBatteryScreenOffTimeBase); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 8741 | |
Mike Ma | 3d422c3 | 2017-10-25 11:08:57 -0700 | [diff] [blame] | 8742 | mCpuActiveTimeMs = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
| 8743 | mCpuClusterTimesMs = new LongSamplingCounterArray(mBsi.mOnBatteryTimeBase, in); |
| 8744 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 8745 | int length = in.readInt(); |
| 8746 | if (length == NUM_PROCESS_STATE) { |
| 8747 | mProcStateTimeMs = new LongSamplingCounterArray[length]; |
| 8748 | for (int procState = 0; procState < length; ++procState) { |
| 8749 | mProcStateTimeMs[procState] = LongSamplingCounterArray.readFromParcel( |
| 8750 | in, mBsi.mOnBatteryTimeBase); |
| 8751 | } |
| 8752 | } else { |
| 8753 | mProcStateTimeMs = null; |
| 8754 | } |
| 8755 | length = in.readInt(); |
| 8756 | if (length == NUM_PROCESS_STATE) { |
| 8757 | mProcStateScreenOffTimeMs = new LongSamplingCounterArray[length]; |
| 8758 | for (int procState = 0; procState < length; ++procState) { |
| 8759 | mProcStateScreenOffTimeMs[procState] = LongSamplingCounterArray.readFromParcel( |
| 8760 | in, mBsi.mOnBatteryScreenOffTimeBase); |
| 8761 | } |
| 8762 | } else { |
| 8763 | mProcStateScreenOffTimeMs = null; |
| 8764 | } |
| 8765 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 8766 | if (in.readInt() != 0) { |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 8767 | mMobileRadioApWakeupCount = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
| 8768 | } else { |
| 8769 | mMobileRadioApWakeupCount = null; |
| 8770 | } |
| 8771 | |
| 8772 | if (in.readInt() != 0) { |
| 8773 | mWifiRadioApWakeupCount = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
| 8774 | } else { |
| 8775 | mWifiRadioApWakeupCount = null; |
| 8776 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8777 | } |
| 8778 | |
| 8779 | /** |
| 8780 | * The statistics associated with a particular wake lock. |
| 8781 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8782 | public static class Wakelock extends BatteryStats.Uid.Wakelock { |
| 8783 | /** |
| 8784 | * BatteryStatsImpl that we are associated with. |
| 8785 | */ |
| 8786 | protected BatteryStatsImpl mBsi; |
| 8787 | |
| 8788 | /** |
| 8789 | * BatteryStatsImpl that we are associated with. |
| 8790 | */ |
| 8791 | protected Uid mUid; |
| 8792 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8793 | /** |
| 8794 | * How long (in ms) this uid has been keeping the device partially awake. |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 8795 | * 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] | 8796 | */ |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 8797 | DualTimer mTimerPartial; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8798 | |
| 8799 | /** |
| 8800 | * How long (in ms) this uid has been keeping the device fully awake. |
| 8801 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 8802 | StopwatchTimer mTimerFull; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8803 | |
| 8804 | /** |
| 8805 | * How long (in ms) this uid has had a window keeping the device awake. |
| 8806 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 8807 | StopwatchTimer mTimerWindow; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8808 | |
| 8809 | /** |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 8810 | * How long (in ms) this uid has had a draw wake lock. |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 8811 | */ |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 8812 | StopwatchTimer mTimerDraw; |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 8813 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8814 | public Wakelock(BatteryStatsImpl bsi, Uid uid) { |
| 8815 | mBsi = bsi; |
| 8816 | mUid = uid; |
| 8817 | } |
| 8818 | |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 8819 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8820 | * Reads a possibly null Timer from a Parcel. The timer is associated with the |
| 8821 | * proper timer pool from the given BatteryStatsImpl object. |
| 8822 | * |
| 8823 | * @param in the Parcel to be read from. |
| 8824 | * return a new Timer, or null. |
| 8825 | */ |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 8826 | private StopwatchTimer readStopwatchTimerFromParcel(int type, |
| 8827 | ArrayList<StopwatchTimer> pool, TimeBase timeBase, Parcel in) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8828 | if (in.readInt() == 0) { |
| 8829 | return null; |
| 8830 | } |
| 8831 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8832 | 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] | 8833 | } |
| 8834 | |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 8835 | /** |
| 8836 | * Reads a possibly null Timer from a Parcel. The timer is associated with the |
| 8837 | * proper timer pool from the given BatteryStatsImpl object. |
| 8838 | * |
| 8839 | * @param in the Parcel to be read from. |
| 8840 | * return a new Timer, or null. |
| 8841 | */ |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 8842 | private DualTimer readDualTimerFromParcel(int type, ArrayList<StopwatchTimer> pool, |
| 8843 | TimeBase timeBase, TimeBase bgTimeBase, Parcel in) { |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 8844 | if (in.readInt() == 0) { |
| 8845 | return null; |
| 8846 | } |
| 8847 | |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 8848 | return new DualTimer(mBsi.mClocks, mUid, type, pool, timeBase, bgTimeBase, in); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 8849 | } |
| 8850 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8851 | boolean reset() { |
| 8852 | boolean wlactive = false; |
| 8853 | if (mTimerFull != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8854 | wlactive |= !mTimerFull.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8855 | } |
| 8856 | if (mTimerPartial != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8857 | wlactive |= !mTimerPartial.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8858 | } |
| 8859 | if (mTimerWindow != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8860 | wlactive |= !mTimerWindow.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8861 | } |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 8862 | if (mTimerDraw != null) { |
| 8863 | wlactive |= !mTimerDraw.reset(false); |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 8864 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8865 | if (!wlactive) { |
| 8866 | if (mTimerFull != null) { |
| 8867 | mTimerFull.detach(); |
| 8868 | mTimerFull = null; |
| 8869 | } |
| 8870 | if (mTimerPartial != null) { |
| 8871 | mTimerPartial.detach(); |
| 8872 | mTimerPartial = null; |
| 8873 | } |
| 8874 | if (mTimerWindow != null) { |
| 8875 | mTimerWindow.detach(); |
| 8876 | mTimerWindow = null; |
| 8877 | } |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 8878 | if (mTimerDraw != null) { |
| 8879 | mTimerDraw.detach(); |
| 8880 | mTimerDraw = null; |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 8881 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8882 | } |
| 8883 | return !wlactive; |
| 8884 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8885 | |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 8886 | void readFromParcelLocked(TimeBase timeBase, TimeBase screenOffTimeBase, |
| 8887 | TimeBase screenOffBgTimeBase, Parcel in) { |
| 8888 | mTimerPartial = readDualTimerFromParcel(WAKE_TYPE_PARTIAL, |
| 8889 | mBsi.mPartialTimers, screenOffTimeBase, screenOffBgTimeBase, in); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 8890 | mTimerFull = readStopwatchTimerFromParcel(WAKE_TYPE_FULL, |
| 8891 | mBsi.mFullTimers, timeBase, in); |
| 8892 | mTimerWindow = readStopwatchTimerFromParcel(WAKE_TYPE_WINDOW, |
| 8893 | mBsi.mWindowTimers, timeBase, in); |
| 8894 | mTimerDraw = readStopwatchTimerFromParcel(WAKE_TYPE_DRAW, |
| 8895 | mBsi.mDrawTimers, timeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8896 | } |
| 8897 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8898 | void writeToParcelLocked(Parcel out, long elapsedRealtimeUs) { |
| 8899 | Timer.writeTimerToParcel(out, mTimerPartial, elapsedRealtimeUs); |
| 8900 | Timer.writeTimerToParcel(out, mTimerFull, elapsedRealtimeUs); |
| 8901 | Timer.writeTimerToParcel(out, mTimerWindow, elapsedRealtimeUs); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 8902 | Timer.writeTimerToParcel(out, mTimerDraw, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8903 | } |
| 8904 | |
| 8905 | @Override |
| 8906 | public Timer getWakeTime(int type) { |
| 8907 | switch (type) { |
| 8908 | case WAKE_TYPE_FULL: return mTimerFull; |
| 8909 | case WAKE_TYPE_PARTIAL: return mTimerPartial; |
| 8910 | case WAKE_TYPE_WINDOW: return mTimerWindow; |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 8911 | case WAKE_TYPE_DRAW: return mTimerDraw; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8912 | default: throw new IllegalArgumentException("type = " + type); |
| 8913 | } |
| 8914 | } |
| 8915 | } |
| 8916 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8917 | public static class Sensor extends BatteryStats.Uid.Sensor { |
| 8918 | /** |
| 8919 | * BatteryStatsImpl that we are associated with. |
| 8920 | */ |
| 8921 | protected BatteryStatsImpl mBsi; |
| 8922 | |
| 8923 | /** |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 8924 | * Uid that we are associated with. |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8925 | */ |
| 8926 | protected Uid mUid; |
| 8927 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8928 | final int mHandle; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 8929 | DualTimer mTimer; |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 8930 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8931 | public Sensor(BatteryStatsImpl bsi, Uid uid, int handle) { |
| 8932 | mBsi = bsi; |
| 8933 | mUid = uid; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8934 | mHandle = handle; |
| 8935 | } |
| 8936 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 8937 | private DualTimer readTimersFromParcel( |
| 8938 | TimeBase timeBase, TimeBase bgTimeBase, Parcel in) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8939 | if (in.readInt() == 0) { |
| 8940 | return null; |
| 8941 | } |
| 8942 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8943 | ArrayList<StopwatchTimer> pool = mBsi.mSensorTimers.get(mHandle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8944 | if (pool == null) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 8945 | pool = new ArrayList<StopwatchTimer>(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8946 | mBsi.mSensorTimers.put(mHandle, pool); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8947 | } |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 8948 | return new DualTimer(mBsi.mClocks, mUid, 0, pool, timeBase, bgTimeBase, in); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 8949 | } |
| 8950 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8951 | boolean reset() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8952 | if (mTimer.reset(true)) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8953 | mTimer = null; |
| 8954 | return true; |
| 8955 | } |
| 8956 | return false; |
| 8957 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8958 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 8959 | void readFromParcelLocked(TimeBase timeBase, TimeBase bgTimeBase, Parcel in) { |
| 8960 | mTimer = readTimersFromParcel(timeBase, bgTimeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8961 | } |
| 8962 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8963 | void writeToParcelLocked(Parcel out, long elapsedRealtimeUs) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 8964 | Timer.writeTimerToParcel(out, mTimer, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8965 | } |
| 8966 | |
| 8967 | @Override |
| 8968 | public Timer getSensorTime() { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 8969 | return mTimer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8970 | } |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 8971 | |
| 8972 | @Override |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 8973 | public Timer getSensorBackgroundTime() { |
| 8974 | if (mTimer == null) { |
| 8975 | return null; |
| 8976 | } |
| 8977 | return mTimer.getSubTimer(); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 8978 | } |
| 8979 | |
| 8980 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8981 | public int getHandle() { |
| 8982 | return mHandle; |
| 8983 | } |
| 8984 | } |
| 8985 | |
| 8986 | /** |
| 8987 | * The statistics associated with a particular process. |
| 8988 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8989 | public static class Proc extends BatteryStats.Uid.Proc implements TimeBaseObs { |
| 8990 | /** |
| 8991 | * BatteryStatsImpl that we are associated with. |
| 8992 | */ |
| 8993 | protected BatteryStatsImpl mBsi; |
| 8994 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8995 | /** |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 8996 | * The name of this process. |
| 8997 | */ |
| 8998 | final String mName; |
| 8999 | |
| 9000 | /** |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 9001 | * Remains true until removed from the stats. |
| 9002 | */ |
| 9003 | boolean mActive = true; |
| 9004 | |
| 9005 | /** |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 9006 | * Total time (in ms) spent executing in user code. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9007 | */ |
| 9008 | long mUserTime; |
| 9009 | |
| 9010 | /** |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 9011 | * Total time (in ms) spent executing in kernel code. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9012 | */ |
| 9013 | long mSystemTime; |
| 9014 | |
| 9015 | /** |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 9016 | * Amount of time (in ms) the process was running in the foreground. |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 9017 | */ |
| 9018 | long mForegroundTime; |
| 9019 | |
| 9020 | /** |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 9021 | * Number of times the process has been started. |
| 9022 | */ |
| 9023 | int mStarts; |
| 9024 | |
| 9025 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9026 | * Number of times the process has crashed. |
| 9027 | */ |
| 9028 | int mNumCrashes; |
| 9029 | |
| 9030 | /** |
| 9031 | * Number of times the process has had an ANR. |
| 9032 | */ |
| 9033 | int mNumAnrs; |
| 9034 | |
| 9035 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9036 | * The amount of user time loaded from a previous save. |
| 9037 | */ |
| 9038 | long mLoadedUserTime; |
| 9039 | |
| 9040 | /** |
| 9041 | * The amount of system time loaded from a previous save. |
| 9042 | */ |
| 9043 | long mLoadedSystemTime; |
| 9044 | |
| 9045 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 9046 | * The amount of foreground time loaded from a previous save. |
| 9047 | */ |
| 9048 | long mLoadedForegroundTime; |
| 9049 | |
| 9050 | /** |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 9051 | * The number of times the process has started from a previous save. |
| 9052 | */ |
| 9053 | int mLoadedStarts; |
| 9054 | |
| 9055 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9056 | * 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] | 9057 | */ |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9058 | int mLoadedNumCrashes; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9059 | |
| 9060 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9061 | * 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] | 9062 | */ |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9063 | int mLoadedNumAnrs; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 9064 | |
| 9065 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9066 | * The amount of user time when last unplugged. |
| 9067 | */ |
| 9068 | long mUnpluggedUserTime; |
| 9069 | |
| 9070 | /** |
| 9071 | * The amount of system time when last unplugged. |
| 9072 | */ |
| 9073 | long mUnpluggedSystemTime; |
| 9074 | |
| 9075 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 9076 | * The amount of foreground time since unplugged. |
| 9077 | */ |
| 9078 | long mUnpluggedForegroundTime; |
| 9079 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 9080 | /** |
| 9081 | * The number of times the process has started before unplugged. |
| 9082 | */ |
| 9083 | int mUnpluggedStarts; |
| 9084 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 9085 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9086 | * Number of times the process has crashed before unplugged. |
| 9087 | */ |
| 9088 | int mUnpluggedNumCrashes; |
| 9089 | |
| 9090 | /** |
| 9091 | * Number of times the process has had an ANR before unplugged. |
| 9092 | */ |
| 9093 | int mUnpluggedNumAnrs; |
| 9094 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 9095 | ArrayList<ExcessivePower> mExcessivePower; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 9096 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9097 | public Proc(BatteryStatsImpl bsi, String name) { |
| 9098 | mBsi = bsi; |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 9099 | mName = name; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9100 | mBsi.mOnBatteryTimeBase.add(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9101 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 9102 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9103 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9104 | mUnpluggedUserTime = mUserTime; |
| 9105 | mUnpluggedSystemTime = mSystemTime; |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 9106 | mUnpluggedForegroundTime = mForegroundTime; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 9107 | mUnpluggedStarts = mStarts; |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9108 | mUnpluggedNumCrashes = mNumCrashes; |
| 9109 | mUnpluggedNumAnrs = mNumAnrs; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9110 | } |
| 9111 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9112 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9113 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9114 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9115 | void detach() { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 9116 | mActive = false; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9117 | mBsi.mOnBatteryTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9118 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9119 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 9120 | public int countExcessivePowers() { |
| 9121 | return mExcessivePower != null ? mExcessivePower.size() : 0; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 9122 | } |
| 9123 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 9124 | public ExcessivePower getExcessivePower(int i) { |
| 9125 | if (mExcessivePower != null) { |
| 9126 | return mExcessivePower.get(i); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 9127 | } |
| 9128 | return null; |
| 9129 | } |
| 9130 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 9131 | public void addExcessiveCpu(long overTime, long usedTime) { |
| 9132 | if (mExcessivePower == null) { |
| 9133 | mExcessivePower = new ArrayList<ExcessivePower>(); |
| 9134 | } |
| 9135 | ExcessivePower ew = new ExcessivePower(); |
| 9136 | ew.type = ExcessivePower.TYPE_CPU; |
| 9137 | ew.overTime = overTime; |
| 9138 | ew.usedTime = usedTime; |
| 9139 | mExcessivePower.add(ew); |
| 9140 | } |
| 9141 | |
| 9142 | void writeExcessivePowerToParcelLocked(Parcel out) { |
| 9143 | if (mExcessivePower == null) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 9144 | out.writeInt(0); |
| 9145 | return; |
| 9146 | } |
| 9147 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 9148 | final int N = mExcessivePower.size(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 9149 | out.writeInt(N); |
| 9150 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 9151 | ExcessivePower ew = mExcessivePower.get(i); |
| 9152 | out.writeInt(ew.type); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 9153 | out.writeLong(ew.overTime); |
| 9154 | out.writeLong(ew.usedTime); |
| 9155 | } |
| 9156 | } |
| 9157 | |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 9158 | void readExcessivePowerFromParcelLocked(Parcel in) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 9159 | final int N = in.readInt(); |
| 9160 | if (N == 0) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 9161 | mExcessivePower = null; |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 9162 | return; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 9163 | } |
| 9164 | |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 9165 | if (N > 10000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 9166 | throw new ParcelFormatException( |
| 9167 | "File corrupt: too many excessive power entries " + N); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 9168 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9169 | |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 9170 | mExcessivePower = new ArrayList<>(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 9171 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 9172 | ExcessivePower ew = new ExcessivePower(); |
| 9173 | ew.type = in.readInt(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 9174 | ew.overTime = in.readLong(); |
| 9175 | ew.usedTime = in.readLong(); |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 9176 | mExcessivePower.add(ew); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 9177 | } |
| 9178 | } |
| 9179 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9180 | void writeToParcelLocked(Parcel out) { |
| 9181 | out.writeLong(mUserTime); |
| 9182 | out.writeLong(mSystemTime); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 9183 | out.writeLong(mForegroundTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9184 | out.writeInt(mStarts); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9185 | out.writeInt(mNumCrashes); |
| 9186 | out.writeInt(mNumAnrs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9187 | out.writeLong(mLoadedUserTime); |
| 9188 | out.writeLong(mLoadedSystemTime); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 9189 | out.writeLong(mLoadedForegroundTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9190 | out.writeInt(mLoadedStarts); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9191 | out.writeInt(mLoadedNumCrashes); |
| 9192 | out.writeInt(mLoadedNumAnrs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9193 | out.writeLong(mUnpluggedUserTime); |
| 9194 | out.writeLong(mUnpluggedSystemTime); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 9195 | out.writeLong(mUnpluggedForegroundTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9196 | out.writeInt(mUnpluggedStarts); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9197 | out.writeInt(mUnpluggedNumCrashes); |
| 9198 | out.writeInt(mUnpluggedNumAnrs); |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 9199 | writeExcessivePowerToParcelLocked(out); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9200 | } |
| 9201 | |
| 9202 | void readFromParcelLocked(Parcel in) { |
| 9203 | mUserTime = in.readLong(); |
| 9204 | mSystemTime = in.readLong(); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 9205 | mForegroundTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9206 | mStarts = in.readInt(); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9207 | mNumCrashes = in.readInt(); |
| 9208 | mNumAnrs = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9209 | mLoadedUserTime = in.readLong(); |
| 9210 | mLoadedSystemTime = in.readLong(); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 9211 | mLoadedForegroundTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9212 | mLoadedStarts = in.readInt(); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9213 | mLoadedNumCrashes = in.readInt(); |
| 9214 | mLoadedNumAnrs = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9215 | mUnpluggedUserTime = in.readLong(); |
| 9216 | mUnpluggedSystemTime = in.readLong(); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 9217 | mUnpluggedForegroundTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9218 | mUnpluggedStarts = in.readInt(); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9219 | mUnpluggedNumCrashes = in.readInt(); |
| 9220 | mUnpluggedNumAnrs = in.readInt(); |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 9221 | readExcessivePowerFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9222 | } |
| 9223 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 9224 | public void addCpuTimeLocked(int utime, int stime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9225 | mUserTime += utime; |
| 9226 | mSystemTime += stime; |
| 9227 | } |
| 9228 | |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 9229 | public void addForegroundTimeLocked(long ttime) { |
| 9230 | mForegroundTime += ttime; |
| 9231 | } |
| 9232 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9233 | public void incStartsLocked() { |
| 9234 | mStarts++; |
| 9235 | } |
| 9236 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9237 | public void incNumCrashesLocked() { |
| 9238 | mNumCrashes++; |
| 9239 | } |
| 9240 | |
| 9241 | public void incNumAnrsLocked() { |
| 9242 | mNumAnrs++; |
| 9243 | } |
| 9244 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9245 | @Override |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 9246 | public boolean isActive() { |
| 9247 | return mActive; |
| 9248 | } |
| 9249 | |
| 9250 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9251 | public long getUserTime(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 9252 | long val = mUserTime; |
| 9253 | if (which == STATS_CURRENT) { |
| 9254 | val -= mLoadedUserTime; |
| 9255 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 9256 | val -= mUnpluggedUserTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9257 | } |
| 9258 | return val; |
| 9259 | } |
| 9260 | |
| 9261 | @Override |
| 9262 | public long getSystemTime(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 9263 | long val = mSystemTime; |
| 9264 | if (which == STATS_CURRENT) { |
| 9265 | val -= mLoadedSystemTime; |
| 9266 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 9267 | val -= mUnpluggedSystemTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9268 | } |
| 9269 | return val; |
| 9270 | } |
| 9271 | |
| 9272 | @Override |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 9273 | public long getForegroundTime(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 9274 | long val = mForegroundTime; |
| 9275 | if (which == STATS_CURRENT) { |
| 9276 | val -= mLoadedForegroundTime; |
| 9277 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 9278 | val -= mUnpluggedForegroundTime; |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 9279 | } |
| 9280 | return val; |
| 9281 | } |
| 9282 | |
| 9283 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9284 | public int getStarts(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 9285 | int val = mStarts; |
| 9286 | if (which == STATS_CURRENT) { |
| 9287 | val -= mLoadedStarts; |
| 9288 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 9289 | val -= mUnpluggedStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9290 | } |
| 9291 | return val; |
| 9292 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 9293 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9294 | @Override |
| 9295 | public int getNumCrashes(int which) { |
| 9296 | int val = mNumCrashes; |
| 9297 | if (which == STATS_CURRENT) { |
| 9298 | val -= mLoadedNumCrashes; |
| 9299 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 9300 | val -= mUnpluggedNumCrashes; |
| 9301 | } |
| 9302 | return val; |
| 9303 | } |
| 9304 | |
| 9305 | @Override |
| 9306 | public int getNumAnrs(int which) { |
| 9307 | int val = mNumAnrs; |
| 9308 | if (which == STATS_CURRENT) { |
| 9309 | val -= mLoadedNumAnrs; |
| 9310 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 9311 | val -= mUnpluggedNumAnrs; |
| 9312 | } |
| 9313 | return val; |
| 9314 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9315 | } |
| 9316 | |
| 9317 | /** |
| 9318 | * The statistics associated with a particular package. |
| 9319 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9320 | public static class Pkg extends BatteryStats.Uid.Pkg implements TimeBaseObs { |
| 9321 | /** |
| 9322 | * BatteryStatsImpl that we are associated with. |
| 9323 | */ |
| 9324 | protected BatteryStatsImpl mBsi; |
| 9325 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9326 | /** |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 9327 | * Number of times wakeup alarms have occurred for this app. |
Bookatz | 98d4d5c | 2017-08-01 19:07:54 -0700 | [diff] [blame] | 9328 | * On screen-off timebase starting in report v25. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9329 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 9330 | ArrayMap<String, Counter> mWakeupAlarms = new ArrayMap<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9331 | |
| 9332 | /** |
| 9333 | * The statics we have collected for this package's services. |
| 9334 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 9335 | final ArrayMap<String, Serv> mServiceStats = new ArrayMap<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9336 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9337 | public Pkg(BatteryStatsImpl bsi) { |
| 9338 | mBsi = bsi; |
| 9339 | mBsi.mOnBatteryScreenOffTimeBase.add(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9340 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9341 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9342 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9343 | } |
| 9344 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9345 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9346 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9347 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9348 | void detach() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9349 | mBsi.mOnBatteryScreenOffTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9350 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9351 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9352 | void readFromParcelLocked(Parcel in) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 9353 | int numWA = in.readInt(); |
| 9354 | mWakeupAlarms.clear(); |
| 9355 | for (int i=0; i<numWA; i++) { |
| 9356 | String tag = in.readString(); |
Bookatz | 98d4d5c | 2017-08-01 19:07:54 -0700 | [diff] [blame] | 9357 | mWakeupAlarms.put(tag, new Counter(mBsi.mOnBatteryScreenOffTimeBase, in)); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 9358 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9359 | |
| 9360 | int numServs = in.readInt(); |
| 9361 | mServiceStats.clear(); |
| 9362 | for (int m = 0; m < numServs; m++) { |
| 9363 | String serviceName = in.readString(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9364 | Uid.Pkg.Serv serv = new Serv(mBsi); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9365 | mServiceStats.put(serviceName, serv); |
| 9366 | |
| 9367 | serv.readFromParcelLocked(in); |
| 9368 | } |
| 9369 | } |
| 9370 | |
| 9371 | void writeToParcelLocked(Parcel out) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 9372 | int numWA = mWakeupAlarms.size(); |
| 9373 | out.writeInt(numWA); |
| 9374 | for (int i=0; i<numWA; i++) { |
| 9375 | out.writeString(mWakeupAlarms.keyAt(i)); |
| 9376 | mWakeupAlarms.valueAt(i).writeToParcel(out); |
| 9377 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9378 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 9379 | final int NS = mServiceStats.size(); |
| 9380 | out.writeInt(NS); |
| 9381 | for (int i=0; i<NS; i++) { |
| 9382 | out.writeString(mServiceStats.keyAt(i)); |
| 9383 | Uid.Pkg.Serv serv = mServiceStats.valueAt(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9384 | serv.writeToParcelLocked(out); |
| 9385 | } |
| 9386 | } |
| 9387 | |
| 9388 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 9389 | public ArrayMap<String, ? extends BatteryStats.Counter> getWakeupAlarmStats() { |
| 9390 | return mWakeupAlarms; |
| 9391 | } |
| 9392 | |
| 9393 | public void noteWakeupAlarmLocked(String tag) { |
| 9394 | Counter c = mWakeupAlarms.get(tag); |
| 9395 | if (c == null) { |
Bookatz | 98d4d5c | 2017-08-01 19:07:54 -0700 | [diff] [blame] | 9396 | c = new Counter(mBsi.mOnBatteryScreenOffTimeBase); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 9397 | mWakeupAlarms.put(tag, c); |
| 9398 | } |
| 9399 | c.stepAtomic(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9400 | } |
| 9401 | |
| 9402 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 9403 | public ArrayMap<String, ? extends BatteryStats.Uid.Pkg.Serv> getServiceStats() { |
| 9404 | return mServiceStats; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9405 | } |
| 9406 | |
| 9407 | /** |
| 9408 | * The statistics associated with a particular service. |
| 9409 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9410 | public static class Serv extends BatteryStats.Uid.Pkg.Serv implements TimeBaseObs { |
| 9411 | /** |
| 9412 | * BatteryStatsImpl that we are associated with. |
| 9413 | */ |
| 9414 | protected BatteryStatsImpl mBsi; |
| 9415 | |
| 9416 | /** |
| 9417 | * The android package in which this service resides. |
| 9418 | */ |
| 9419 | protected Pkg mPkg; |
| 9420 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9421 | /** |
| 9422 | * Total time (ms in battery uptime) the service has been left started. |
| 9423 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9424 | protected long mStartTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9425 | |
| 9426 | /** |
| 9427 | * If service has been started and not yet stopped, this is |
| 9428 | * when it was started. |
| 9429 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9430 | protected long mRunningSince; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9431 | |
| 9432 | /** |
| 9433 | * True if we are currently running. |
| 9434 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9435 | protected boolean mRunning; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9436 | |
| 9437 | /** |
| 9438 | * Total number of times startService() has been called. |
| 9439 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9440 | protected int mStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9441 | |
| 9442 | /** |
| 9443 | * Total time (ms in battery uptime) the service has been left launched. |
| 9444 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9445 | protected long mLaunchedTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9446 | |
| 9447 | /** |
| 9448 | * If service has been launched and not yet exited, this is |
| 9449 | * when it was launched (ms in battery uptime). |
| 9450 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9451 | protected long mLaunchedSince; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9452 | |
| 9453 | /** |
| 9454 | * True if we are currently launched. |
| 9455 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9456 | protected boolean mLaunched; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9457 | |
| 9458 | /** |
| 9459 | * Total number times the service has been launched. |
| 9460 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9461 | protected int mLaunches; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9462 | |
| 9463 | /** |
| 9464 | * The amount of time spent started loaded from a previous save |
| 9465 | * (ms in battery uptime). |
| 9466 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9467 | protected long mLoadedStartTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9468 | |
| 9469 | /** |
| 9470 | * The number of starts loaded from a previous save. |
| 9471 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9472 | protected int mLoadedStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9473 | |
| 9474 | /** |
| 9475 | * The number of launches loaded from a previous save. |
| 9476 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9477 | protected int mLoadedLaunches; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9478 | |
| 9479 | /** |
| 9480 | * The amount of time spent started as of the last run (ms |
| 9481 | * in battery uptime). |
| 9482 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9483 | protected long mLastStartTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9484 | |
| 9485 | /** |
| 9486 | * The number of starts as of the last run. |
| 9487 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9488 | protected int mLastStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9489 | |
| 9490 | /** |
| 9491 | * The number of launches as of the last run. |
| 9492 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9493 | protected int mLastLaunches; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9494 | |
| 9495 | /** |
| 9496 | * The amount of time spent started when last unplugged (ms |
| 9497 | * in battery uptime). |
| 9498 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9499 | protected long mUnpluggedStartTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9500 | |
| 9501 | /** |
| 9502 | * The number of starts when last unplugged. |
| 9503 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9504 | protected int mUnpluggedStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9505 | |
| 9506 | /** |
| 9507 | * The number of launches when last unplugged. |
| 9508 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9509 | protected int mUnpluggedLaunches; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9510 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9511 | /** |
| 9512 | * Construct a Serv. Also adds it to the on-battery time base as a listener. |
| 9513 | */ |
| 9514 | public Serv(BatteryStatsImpl bsi) { |
| 9515 | mBsi = bsi; |
| 9516 | mBsi.mOnBatteryTimeBase.add(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9517 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9518 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9519 | public void onTimeStarted(long elapsedRealtime, long baseUptime, |
| 9520 | long baseRealtime) { |
| 9521 | mUnpluggedStartTime = getStartTimeToNowLocked(baseUptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9522 | mUnpluggedStarts = mStarts; |
| 9523 | mUnpluggedLaunches = mLaunches; |
| 9524 | } |
| 9525 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9526 | public void onTimeStopped(long elapsedRealtime, long baseUptime, |
| 9527 | long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9528 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9529 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9530 | /** |
| 9531 | * Remove this Serv as a listener from the time base. |
| 9532 | */ |
| 9533 | public void detach() { |
| 9534 | mBsi.mOnBatteryTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9535 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9536 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9537 | public void readFromParcelLocked(Parcel in) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9538 | mStartTime = in.readLong(); |
| 9539 | mRunningSince = in.readLong(); |
| 9540 | mRunning = in.readInt() != 0; |
| 9541 | mStarts = in.readInt(); |
| 9542 | mLaunchedTime = in.readLong(); |
| 9543 | mLaunchedSince = in.readLong(); |
| 9544 | mLaunched = in.readInt() != 0; |
| 9545 | mLaunches = in.readInt(); |
| 9546 | mLoadedStartTime = in.readLong(); |
| 9547 | mLoadedStarts = in.readInt(); |
| 9548 | mLoadedLaunches = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 9549 | mLastStartTime = 0; |
| 9550 | mLastStarts = 0; |
| 9551 | mLastLaunches = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9552 | mUnpluggedStartTime = in.readLong(); |
| 9553 | mUnpluggedStarts = in.readInt(); |
| 9554 | mUnpluggedLaunches = in.readInt(); |
| 9555 | } |
| 9556 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9557 | public void writeToParcelLocked(Parcel out) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9558 | out.writeLong(mStartTime); |
| 9559 | out.writeLong(mRunningSince); |
| 9560 | out.writeInt(mRunning ? 1 : 0); |
| 9561 | out.writeInt(mStarts); |
| 9562 | out.writeLong(mLaunchedTime); |
| 9563 | out.writeLong(mLaunchedSince); |
| 9564 | out.writeInt(mLaunched ? 1 : 0); |
| 9565 | out.writeInt(mLaunches); |
| 9566 | out.writeLong(mLoadedStartTime); |
| 9567 | out.writeInt(mLoadedStarts); |
| 9568 | out.writeInt(mLoadedLaunches); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9569 | out.writeLong(mUnpluggedStartTime); |
| 9570 | out.writeInt(mUnpluggedStarts); |
| 9571 | out.writeInt(mUnpluggedLaunches); |
| 9572 | } |
| 9573 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9574 | public long getLaunchTimeToNowLocked(long batteryUptime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9575 | if (!mLaunched) return mLaunchedTime; |
| 9576 | return mLaunchedTime + batteryUptime - mLaunchedSince; |
| 9577 | } |
| 9578 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9579 | public long getStartTimeToNowLocked(long batteryUptime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9580 | if (!mRunning) return mStartTime; |
| 9581 | return mStartTime + batteryUptime - mRunningSince; |
| 9582 | } |
| 9583 | |
| 9584 | public void startLaunchedLocked() { |
| 9585 | if (!mLaunched) { |
| 9586 | mLaunches++; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9587 | mLaunchedSince = mBsi.getBatteryUptimeLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9588 | mLaunched = true; |
| 9589 | } |
| 9590 | } |
| 9591 | |
| 9592 | public void stopLaunchedLocked() { |
| 9593 | if (mLaunched) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9594 | long time = mBsi.getBatteryUptimeLocked() - mLaunchedSince; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9595 | if (time > 0) { |
| 9596 | mLaunchedTime += time; |
| 9597 | } else { |
| 9598 | mLaunches--; |
| 9599 | } |
| 9600 | mLaunched = false; |
| 9601 | } |
| 9602 | } |
| 9603 | |
| 9604 | public void startRunningLocked() { |
| 9605 | if (!mRunning) { |
| 9606 | mStarts++; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9607 | mRunningSince = mBsi.getBatteryUptimeLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9608 | mRunning = true; |
| 9609 | } |
| 9610 | } |
| 9611 | |
| 9612 | public void stopRunningLocked() { |
| 9613 | if (mRunning) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9614 | long time = mBsi.getBatteryUptimeLocked() - mRunningSince; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9615 | if (time > 0) { |
| 9616 | mStartTime += time; |
| 9617 | } else { |
| 9618 | mStarts--; |
| 9619 | } |
| 9620 | mRunning = false; |
| 9621 | } |
| 9622 | } |
| 9623 | |
| 9624 | public BatteryStatsImpl getBatteryStats() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9625 | return mBsi; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9626 | } |
| 9627 | |
| 9628 | @Override |
| 9629 | public int getLaunches(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 9630 | int val = mLaunches; |
| 9631 | if (which == STATS_CURRENT) { |
| 9632 | val -= mLoadedLaunches; |
| 9633 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 9634 | val -= mUnpluggedLaunches; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9635 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9636 | return val; |
| 9637 | } |
| 9638 | |
| 9639 | @Override |
| 9640 | public long getStartTime(long now, int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 9641 | long val = getStartTimeToNowLocked(now); |
| 9642 | if (which == STATS_CURRENT) { |
| 9643 | val -= mLoadedStartTime; |
| 9644 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 9645 | val -= mUnpluggedStartTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9646 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9647 | return val; |
| 9648 | } |
| 9649 | |
| 9650 | @Override |
| 9651 | public int getStarts(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 9652 | int val = mStarts; |
| 9653 | if (which == STATS_CURRENT) { |
| 9654 | val -= mLoadedStarts; |
| 9655 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 9656 | val -= mUnpluggedStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9657 | } |
| 9658 | |
| 9659 | return val; |
| 9660 | } |
| 9661 | } |
| 9662 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9663 | final Serv newServiceStatsLocked() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9664 | return new Serv(mBsi); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9665 | } |
| 9666 | } |
| 9667 | |
| 9668 | /** |
| 9669 | * Retrieve the statistics object for a particular process, creating |
| 9670 | * if needed. |
| 9671 | */ |
| 9672 | public Proc getProcessStatsLocked(String name) { |
| 9673 | Proc ps = mProcessStats.get(name); |
| 9674 | if (ps == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9675 | ps = new Proc(mBsi, name); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9676 | mProcessStats.put(name, ps); |
| 9677 | } |
| 9678 | |
| 9679 | return ps; |
| 9680 | } |
| 9681 | |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 9682 | public void updateUidProcessStateLocked(int procState) { |
| 9683 | int uidRunningState; |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 9684 | // Make special note of Foreground Services |
| 9685 | final boolean userAwareService = |
| 9686 | (procState == ActivityManager.PROCESS_STATE_FOREGROUND_SERVICE); |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 9687 | uidRunningState = BatteryStats.mapToInternalProcessState(procState); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 9688 | |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 9689 | if (mProcessState == uidRunningState && userAwareService == mInForegroundService) { |
| 9690 | return; |
| 9691 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 9692 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 9693 | final long elapsedRealtimeMs = mBsi.mClocks.elapsedRealtime(); |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 9694 | if (mProcessState != uidRunningState) { |
| 9695 | final long uptimeMs = mBsi.mClocks.uptimeMillis(); |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 9696 | |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 9697 | if (mProcessState != ActivityManager.PROCESS_STATE_NONEXISTENT) { |
| 9698 | mProcessStateTimer[mProcessState].stopRunningLocked(elapsedRealtimeMs); |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 9699 | |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 9700 | if (mBsi.trackPerProcStateCpuTimes()) { |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 9701 | if (mBsi.mPendingUids.size() == 0) { |
Sudheer Shanka | e544d16 | 2017-12-28 17:06:20 -0800 | [diff] [blame] | 9702 | mBsi.mExternalSync.scheduleReadProcStateCpuTimes( |
| 9703 | mBsi.mOnBatteryTimeBase.isRunning(), |
| 9704 | mBsi.mOnBatteryScreenOffTimeBase.isRunning()); |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 9705 | } |
| 9706 | if (mBsi.mPendingUids.indexOfKey(mUid) < 0 |
| 9707 | || ArrayUtils.contains(CRITICAL_PROC_STATES, mProcessState)) { |
| 9708 | mBsi.mPendingUids.put(mUid, mProcessState); |
| 9709 | } |
| 9710 | } else { |
| 9711 | mBsi.mPendingUids.clear(); |
| 9712 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 9713 | } |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 9714 | mProcessState = uidRunningState; |
| 9715 | if (uidRunningState != ActivityManager.PROCESS_STATE_NONEXISTENT) { |
| 9716 | if (mProcessStateTimer[uidRunningState] == null) { |
| 9717 | makeProcessState(uidRunningState, null); |
| 9718 | } |
| 9719 | mProcessStateTimer[uidRunningState].startRunningLocked(elapsedRealtimeMs); |
| 9720 | } |
| 9721 | |
| 9722 | updateOnBatteryBgTimeBase(uptimeMs * 1000, elapsedRealtimeMs * 1000); |
| 9723 | updateOnBatteryScreenOffBgTimeBase(uptimeMs * 1000, elapsedRealtimeMs * 1000); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 9724 | } |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 9725 | |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 9726 | if (userAwareService != mInForegroundService) { |
| 9727 | if (userAwareService) { |
| 9728 | noteForegroundServiceResumedLocked(elapsedRealtimeMs); |
| 9729 | } else { |
| 9730 | noteForegroundServicePausedLocked(elapsedRealtimeMs); |
| 9731 | } |
| 9732 | mInForegroundService = userAwareService; |
| 9733 | } |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 9734 | } |
| 9735 | |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 9736 | /** Whether to consider Uid to be in the background for background timebase purposes. */ |
| 9737 | public boolean isInBackground() { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 9738 | // Note that PROCESS_STATE_CACHED and ActivityManager.PROCESS_STATE_NONEXISTENT is |
| 9739 | // also considered to be 'background' for our purposes, because it's not foreground. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 9740 | return mProcessState >= PROCESS_STATE_BACKGROUND; |
| 9741 | } |
| 9742 | |
| 9743 | public boolean updateOnBatteryBgTimeBase(long uptimeUs, long realtimeUs) { |
| 9744 | boolean on = mBsi.mOnBatteryTimeBase.isRunning() && isInBackground(); |
| 9745 | return mOnBatteryBackgroundTimeBase.setRunning(on, uptimeUs, realtimeUs); |
| 9746 | } |
| 9747 | |
| 9748 | public boolean updateOnBatteryScreenOffBgTimeBase(long uptimeUs, long realtimeUs) { |
| 9749 | boolean on = mBsi.mOnBatteryScreenOffTimeBase.isRunning() && isInBackground(); |
| 9750 | return mOnBatteryScreenOffBackgroundTimeBase.setRunning(on, uptimeUs, realtimeUs); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 9751 | } |
| 9752 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 9753 | public SparseArray<? extends Pid> getPidStats() { |
| 9754 | return mPids; |
| 9755 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9756 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 9757 | public Pid getPidStatsLocked(int pid) { |
| 9758 | Pid p = mPids.get(pid); |
| 9759 | if (p == null) { |
| 9760 | p = new Pid(); |
| 9761 | mPids.put(pid, p); |
| 9762 | } |
| 9763 | return p; |
| 9764 | } |
| 9765 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9766 | /** |
| 9767 | * Retrieve the statistics object for a particular service, creating |
| 9768 | * if needed. |
| 9769 | */ |
| 9770 | public Pkg getPackageStatsLocked(String name) { |
| 9771 | Pkg ps = mPackageStats.get(name); |
| 9772 | if (ps == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9773 | ps = new Pkg(mBsi); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9774 | mPackageStats.put(name, ps); |
| 9775 | } |
| 9776 | |
| 9777 | return ps; |
| 9778 | } |
| 9779 | |
| 9780 | /** |
| 9781 | * Retrieve the statistics object for a particular service, creating |
| 9782 | * if needed. |
| 9783 | */ |
| 9784 | public Pkg.Serv getServiceStatsLocked(String pkg, String serv) { |
| 9785 | Pkg ps = getPackageStatsLocked(pkg); |
| 9786 | Pkg.Serv ss = ps.mServiceStats.get(serv); |
| 9787 | if (ss == null) { |
| 9788 | ss = ps.newServiceStatsLocked(); |
| 9789 | ps.mServiceStats.put(serv, ss); |
| 9790 | } |
| 9791 | |
| 9792 | return ss; |
| 9793 | } |
| 9794 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 9795 | public void readSyncSummaryFromParcelLocked(String name, Parcel in) { |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 9796 | DualTimer timer = mSyncStats.instantiateObject(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 9797 | timer.readSummaryFromParcelLocked(in); |
| 9798 | mSyncStats.add(name, timer); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 9799 | } |
| 9800 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 9801 | public void readJobSummaryFromParcelLocked(String name, Parcel in) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 9802 | DualTimer timer = mJobStats.instantiateObject(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 9803 | timer.readSummaryFromParcelLocked(in); |
| 9804 | mJobStats.add(name, timer); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 9805 | } |
| 9806 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 9807 | public void readWakeSummaryFromParcelLocked(String wlName, Parcel in) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9808 | Wakelock wl = new Wakelock(mBsi, this); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 9809 | mWakelockStats.add(wlName, wl); |
| 9810 | if (in.readInt() != 0) { |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 9811 | getWakelockTimerLocked(wl, WAKE_TYPE_FULL).readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9812 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 9813 | if (in.readInt() != 0) { |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 9814 | getWakelockTimerLocked(wl, WAKE_TYPE_PARTIAL).readSummaryFromParcelLocked(in); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 9815 | } |
| 9816 | if (in.readInt() != 0) { |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 9817 | getWakelockTimerLocked(wl, WAKE_TYPE_WINDOW).readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9818 | } |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 9819 | if (in.readInt() != 0) { |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 9820 | getWakelockTimerLocked(wl, WAKE_TYPE_DRAW).readSummaryFromParcelLocked(in); |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 9821 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9822 | } |
| 9823 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 9824 | public DualTimer getSensorTimerLocked(int sensor, boolean create) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9825 | Sensor se = mSensorStats.get(sensor); |
| 9826 | if (se == null) { |
| 9827 | if (!create) { |
| 9828 | return null; |
| 9829 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9830 | se = new Sensor(mBsi, this, sensor); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9831 | mSensorStats.put(sensor, se); |
| 9832 | } |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 9833 | DualTimer t = se.mTimer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9834 | if (t != null) { |
| 9835 | return t; |
| 9836 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9837 | ArrayList<StopwatchTimer> timers = mBsi.mSensorTimers.get(sensor); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9838 | if (timers == null) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 9839 | timers = new ArrayList<StopwatchTimer>(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9840 | mBsi.mSensorTimers.put(sensor, timers); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9841 | } |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 9842 | t = new DualTimer(mBsi.mClocks, this, BatteryStats.SENSOR, timers, |
| 9843 | mBsi.mOnBatteryTimeBase, mOnBatteryBackgroundTimeBase); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9844 | se.mTimer = t; |
| 9845 | return t; |
| 9846 | } |
| 9847 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 9848 | public void noteStartSyncLocked(String name, long elapsedRealtimeMs) { |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 9849 | DualTimer t = mSyncStats.startObject(name); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 9850 | if (t != null) { |
| 9851 | t.startRunningLocked(elapsedRealtimeMs); |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 9852 | StatsLog.write_non_chained(StatsLog.SYNC_STATE_CHANGED, getUid(), null, name, |
| 9853 | StatsLog.SYNC_STATE_CHANGED__STATE__ON); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 9854 | } |
| 9855 | } |
| 9856 | |
| 9857 | public void noteStopSyncLocked(String name, long elapsedRealtimeMs) { |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 9858 | DualTimer t = mSyncStats.stopObject(name); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 9859 | if (t != null) { |
| 9860 | t.stopRunningLocked(elapsedRealtimeMs); |
Bookatz | c1a050a | 2017-10-10 15:49:28 -0700 | [diff] [blame] | 9861 | if (!t.isRunningLocked()) { // only tell statsd if truly stopped |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 9862 | StatsLog.write_non_chained(StatsLog.SYNC_STATE_CHANGED, getUid(), null, name, |
| 9863 | StatsLog.SYNC_STATE_CHANGED__STATE__OFF); |
Bookatz | c1a050a | 2017-10-10 15:49:28 -0700 | [diff] [blame] | 9864 | } |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 9865 | } |
| 9866 | } |
| 9867 | |
| 9868 | public void noteStartJobLocked(String name, long elapsedRealtimeMs) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 9869 | DualTimer t = mJobStats.startObject(name); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 9870 | if (t != null) { |
| 9871 | t.startRunningLocked(elapsedRealtimeMs); |
Yangster-mac | 2f5daec | 2018-01-16 10:23:15 -0800 | [diff] [blame] | 9872 | StatsLog.write_non_chained(StatsLog.SCHEDULED_JOB_STATE_CHANGED, getUid(), null, |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 9873 | name, StatsLog.SCHEDULED_JOB_STATE_CHANGED__STATE__STARTED); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 9874 | } |
| 9875 | } |
| 9876 | |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 9877 | public void noteStopJobLocked(String name, long elapsedRealtimeMs, int stopReason) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 9878 | DualTimer t = mJobStats.stopObject(name); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 9879 | if (t != null) { |
| 9880 | t.stopRunningLocked(elapsedRealtimeMs); |
Bookatz | c1a050a | 2017-10-10 15:49:28 -0700 | [diff] [blame] | 9881 | if (!t.isRunningLocked()) { // only tell statsd if truly stopped |
Yangster-mac | 2f5daec | 2018-01-16 10:23:15 -0800 | [diff] [blame] | 9882 | StatsLog.write_non_chained(StatsLog.SCHEDULED_JOB_STATE_CHANGED, getUid(), null, |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 9883 | name, StatsLog.SCHEDULED_JOB_STATE_CHANGED__STATE__FINISHED); |
Bookatz | c1a050a | 2017-10-10 15:49:28 -0700 | [diff] [blame] | 9884 | } |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 9885 | } |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 9886 | if (mBsi.mOnBatteryTimeBase.isRunning()) { |
| 9887 | SparseIntArray types = mJobCompletions.get(name); |
| 9888 | if (types == null) { |
| 9889 | types = new SparseIntArray(); |
| 9890 | mJobCompletions.put(name, types); |
| 9891 | } |
| 9892 | int last = types.get(stopReason, 0); |
| 9893 | types.put(stopReason, last + 1); |
| 9894 | } |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 9895 | } |
| 9896 | |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 9897 | public StopwatchTimer getWakelockTimerLocked(Wakelock wl, int type) { |
| 9898 | if (wl == null) { |
| 9899 | return null; |
| 9900 | } |
| 9901 | switch (type) { |
| 9902 | case WAKE_TYPE_PARTIAL: { |
| 9903 | DualTimer t = wl.mTimerPartial; |
| 9904 | if (t == null) { |
| 9905 | t = new DualTimer(mBsi.mClocks, this, WAKE_TYPE_PARTIAL, |
| 9906 | mBsi.mPartialTimers, mBsi.mOnBatteryScreenOffTimeBase, |
| 9907 | mOnBatteryScreenOffBackgroundTimeBase); |
| 9908 | wl.mTimerPartial = t; |
| 9909 | } |
| 9910 | return t; |
| 9911 | } |
| 9912 | case WAKE_TYPE_FULL: { |
| 9913 | StopwatchTimer t = wl.mTimerFull; |
| 9914 | if (t == null) { |
| 9915 | t = new StopwatchTimer(mBsi.mClocks, this, WAKE_TYPE_FULL, |
| 9916 | mBsi.mFullTimers, mBsi.mOnBatteryTimeBase); |
| 9917 | wl.mTimerFull = t; |
| 9918 | } |
| 9919 | return t; |
| 9920 | } |
| 9921 | case WAKE_TYPE_WINDOW: { |
| 9922 | StopwatchTimer t = wl.mTimerWindow; |
| 9923 | if (t == null) { |
| 9924 | t = new StopwatchTimer(mBsi.mClocks, this, WAKE_TYPE_WINDOW, |
| 9925 | mBsi.mWindowTimers, mBsi.mOnBatteryTimeBase); |
| 9926 | wl.mTimerWindow = t; |
| 9927 | } |
| 9928 | return t; |
| 9929 | } |
| 9930 | case WAKE_TYPE_DRAW: { |
| 9931 | StopwatchTimer t = wl.mTimerDraw; |
| 9932 | if (t == null) { |
| 9933 | t = new StopwatchTimer(mBsi.mClocks, this, WAKE_TYPE_DRAW, |
| 9934 | mBsi.mDrawTimers, mBsi.mOnBatteryTimeBase); |
| 9935 | wl.mTimerDraw = t; |
| 9936 | } |
| 9937 | return t; |
| 9938 | } |
| 9939 | default: |
| 9940 | throw new IllegalArgumentException("type=" + type); |
| 9941 | } |
| 9942 | } |
| 9943 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9944 | public void noteStartWakeLocked(int pid, String name, int type, long elapsedRealtimeMs) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 9945 | Wakelock wl = mWakelockStats.startObject(name); |
| 9946 | if (wl != null) { |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 9947 | getWakelockTimerLocked(wl, type).startRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9948 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 9949 | if (type == WAKE_TYPE_PARTIAL) { |
| 9950 | createAggregatedPartialWakelockTimerLocked().startRunningLocked(elapsedRealtimeMs); |
| 9951 | if (pid >= 0) { |
| 9952 | Pid p = getPidStatsLocked(pid); |
| 9953 | if (p.mWakeNesting++ == 0) { |
| 9954 | p.mWakeStartMs = elapsedRealtimeMs; |
| 9955 | } |
Dianne Hackborn | b8071d79 | 2010-09-09 16:45:15 -0700 | [diff] [blame] | 9956 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 9957 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9958 | } |
| 9959 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9960 | public void noteStopWakeLocked(int pid, String name, int type, long elapsedRealtimeMs) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 9961 | Wakelock wl = mWakelockStats.stopObject(name); |
| 9962 | if (wl != null) { |
Bookatz | d674624 | 2017-10-24 18:39:35 -0700 | [diff] [blame] | 9963 | StopwatchTimer wlt = getWakelockTimerLocked(wl, type); |
| 9964 | wlt.stopRunningLocked(elapsedRealtimeMs); |
| 9965 | if (!wlt.isRunningLocked()) { // only tell statsd if truly stopped |
Bookatz | d674624 | 2017-10-24 18:39:35 -0700 | [diff] [blame] | 9966 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9967 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 9968 | if (type == WAKE_TYPE_PARTIAL) { |
| 9969 | if (mAggregatedPartialWakelockTimer != null) { |
| 9970 | mAggregatedPartialWakelockTimer.stopRunningLocked(elapsedRealtimeMs); |
| 9971 | } |
| 9972 | if (pid >= 0) { |
| 9973 | Pid p = mPids.get(pid); |
| 9974 | if (p != null && p.mWakeNesting > 0) { |
| 9975 | if (p.mWakeNesting-- == 1) { |
| 9976 | p.mWakeSumMs += elapsedRealtimeMs - p.mWakeStartMs; |
| 9977 | p.mWakeStartMs = 0; |
| 9978 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 9979 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 9980 | } |
| 9981 | } |
| 9982 | } |
| 9983 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 9984 | public void reportExcessiveCpuLocked(String proc, long overTime, long usedTime) { |
| 9985 | Proc p = getProcessStatsLocked(proc); |
| 9986 | if (p != null) { |
| 9987 | p.addExcessiveCpu(overTime, usedTime); |
| 9988 | } |
| 9989 | } |
| 9990 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9991 | public void noteStartSensor(int sensor, long elapsedRealtimeMs) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 9992 | DualTimer t = getSensorTimerLocked(sensor, /* create= */ true); |
Amith Yamasani | 154d124 | 2017-02-16 10:01:48 -0800 | [diff] [blame] | 9993 | t.startRunningLocked(elapsedRealtimeMs); |
Narayan Kamath | 32684dd | 2018-01-08 17:32:51 +0000 | [diff] [blame] | 9994 | if (sensor != Sensor.GPS) { |
Yangster-mac | 2f5daec | 2018-01-16 10:23:15 -0800 | [diff] [blame] | 9995 | StatsLog.write_non_chained(StatsLog.SENSOR_STATE_CHANGED, getUid(), null, sensor, |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 9996 | StatsLog.SENSOR_STATE_CHANGED__STATE__ON); |
Bookatz | c1a050a | 2017-10-10 15:49:28 -0700 | [diff] [blame] | 9997 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9998 | } |
| 9999 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10000 | public void noteStopSensor(int sensor, long elapsedRealtimeMs) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10001 | // Don't create a timer if one doesn't already exist |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 10002 | DualTimer t = getSensorTimerLocked(sensor, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10003 | if (t != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10004 | t.stopRunningLocked(elapsedRealtimeMs); |
Narayan Kamath | 32684dd | 2018-01-08 17:32:51 +0000 | [diff] [blame] | 10005 | if (sensor != Sensor.GPS) { |
| 10006 | StatsLog.write_non_chained(StatsLog.SENSOR_STATE_CHANGED, getUid(), null, |
Bookatz | 9086762 | 2018-01-31 15:05:57 -0800 | [diff] [blame] | 10007 | sensor, StatsLog.SENSOR_STATE_CHANGED__STATE__OFF); |
Bookatz | c1a050a | 2017-10-10 15:49:28 -0700 | [diff] [blame] | 10008 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10009 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10010 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10011 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10012 | public void noteStartGps(long elapsedRealtimeMs) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 10013 | noteStartSensor(Sensor.GPS, elapsedRealtimeMs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10014 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10015 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10016 | public void noteStopGps(long elapsedRealtimeMs) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 10017 | noteStopSensor(Sensor.GPS, elapsedRealtimeMs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10018 | } |
| 10019 | |
| 10020 | public BatteryStatsImpl getBatteryStats() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10021 | return mBsi; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10022 | } |
| 10023 | } |
| 10024 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 10025 | public long[] getCpuFreqs() { |
| 10026 | return mCpuFreqs; |
| 10027 | } |
| 10028 | |
Suprabh Shukla | e6e723d | 2017-06-14 16:14:43 -0700 | [diff] [blame] | 10029 | public BatteryStatsImpl(File systemDir, Handler handler, PlatformIdleStateCallback cb, |
| 10030 | UserInfoProvider userInfoProvider) { |
| 10031 | this(new SystemClocks(), systemDir, handler, cb, userInfoProvider); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 10032 | } |
| 10033 | |
Suprabh Shukla | e6e723d | 2017-06-14 16:14:43 -0700 | [diff] [blame] | 10034 | private BatteryStatsImpl(Clocks clocks, File systemDir, Handler handler, |
| 10035 | PlatformIdleStateCallback cb, |
| 10036 | UserInfoProvider userInfoProvider) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10037 | init(clocks); |
| 10038 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 10039 | if (systemDir != null) { |
| 10040 | mFile = new JournaledFile(new File(systemDir, "batterystats.bin"), |
| 10041 | new File(systemDir, "batterystats.bin.tmp")); |
| 10042 | } else { |
| 10043 | mFile = null; |
| 10044 | } |
| 10045 | mCheckinFile = new AtomicFile(new File(systemDir, "batterystats-checkin.bin")); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10046 | mDailyFile = new AtomicFile(new File(systemDir, "batterystats-daily.xml")); |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 10047 | mHandler = new MyHandler(handler.getLooper()); |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 10048 | mConstants = new Constants(mHandler); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10049 | mStartCount++; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10050 | mScreenOnTimer = new StopwatchTimer(mClocks, null, -1, null, mOnBatteryTimeBase); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 10051 | mScreenDozeTimer = new StopwatchTimer(mClocks, null, -1, null, mOnBatteryTimeBase); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 10052 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10053 | mScreenBrightnessTimer[i] = new StopwatchTimer(mClocks, null, -100-i, null, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10054 | mOnBatteryTimeBase); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 10055 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10056 | mInteractiveTimer = new StopwatchTimer(mClocks, null, -10, null, mOnBatteryTimeBase); |
| 10057 | mPowerSaveModeEnabledTimer = new StopwatchTimer(mClocks, null, -2, null, |
| 10058 | mOnBatteryTimeBase); |
| 10059 | mDeviceIdleModeLightTimer = new StopwatchTimer(mClocks, null, -11, null, |
| 10060 | mOnBatteryTimeBase); |
| 10061 | mDeviceIdleModeFullTimer = new StopwatchTimer(mClocks, null, -14, null, mOnBatteryTimeBase); |
| 10062 | mDeviceLightIdlingTimer = new StopwatchTimer(mClocks, null, -15, null, mOnBatteryTimeBase); |
| 10063 | mDeviceIdlingTimer = new StopwatchTimer(mClocks, null, -12, null, mOnBatteryTimeBase); |
| 10064 | mPhoneOnTimer = new StopwatchTimer(mClocks, null, -3, null, mOnBatteryTimeBase); |
| 10065 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
| 10066 | mPhoneSignalStrengthsTimer[i] = new StopwatchTimer(mClocks, null, -200-i, null, |
| 10067 | mOnBatteryTimeBase); |
| 10068 | } |
| 10069 | mPhoneSignalScanningTimer = new StopwatchTimer(mClocks, null, -200+1, null, |
| 10070 | mOnBatteryTimeBase); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 10071 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10072 | mPhoneDataConnectionsTimer[i] = new StopwatchTimer(mClocks, null, -300-i, null, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10073 | mOnBatteryTimeBase); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 10074 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 10075 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10076 | mNetworkByteActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase); |
| 10077 | mNetworkPacketActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 10078 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 10079 | mWifiActivity = new ControllerActivityCounterImpl(mOnBatteryTimeBase, NUM_WIFI_TX_LEVELS); |
| 10080 | mBluetoothActivity = new ControllerActivityCounterImpl(mOnBatteryTimeBase, |
| 10081 | NUM_BT_TX_LEVELS); |
| 10082 | mModemActivity = new ControllerActivityCounterImpl(mOnBatteryTimeBase, |
| 10083 | ModemActivityInfo.TX_POWER_LEVELS); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10084 | mMobileRadioActiveTimer = new StopwatchTimer(mClocks, null, -400, null, mOnBatteryTimeBase); |
| 10085 | mMobileRadioActivePerAppTimer = new StopwatchTimer(mClocks, null, -401, null, |
| 10086 | mOnBatteryTimeBase); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10087 | mMobileRadioActiveAdjustedTime = new LongSamplingCounter(mOnBatteryTimeBase); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10088 | mMobileRadioActiveUnknownTime = new LongSamplingCounter(mOnBatteryTimeBase); |
| 10089 | mMobileRadioActiveUnknownCount = new LongSamplingCounter(mOnBatteryTimeBase); |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 10090 | mWifiMulticastWakelockTimer = new StopwatchTimer(mClocks, null, |
| 10091 | WIFI_AGGREGATE_MULTICAST_ENABLED, null, mOnBatteryTimeBase); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10092 | mWifiOnTimer = new StopwatchTimer(mClocks, null, -4, null, mOnBatteryTimeBase); |
| 10093 | mGlobalWifiRunningTimer = new StopwatchTimer(mClocks, null, -5, null, mOnBatteryTimeBase); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 10094 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10095 | mWifiStateTimer[i] = new StopwatchTimer(mClocks, null, -600-i, null, |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 10096 | mOnBatteryTimeBase); |
| 10097 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10098 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 10099 | mWifiSupplStateTimer[i] = new StopwatchTimer(mClocks, null, -700-i, null, |
| 10100 | mOnBatteryTimeBase); |
| 10101 | } |
| 10102 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 10103 | mWifiSignalStrengthsTimer[i] = new StopwatchTimer(mClocks, null, -800-i, null, |
| 10104 | mOnBatteryTimeBase); |
| 10105 | } |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 10106 | mWifiActiveTimer = new StopwatchTimer(mClocks, null, -900, null, mOnBatteryTimeBase); |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 10107 | for (int i=0; i< GnssMetrics.NUM_GPS_SIGNAL_QUALITY_LEVELS; i++) { |
| 10108 | mGpsSignalQualityTimer[i] = new StopwatchTimer(mClocks, null, -1000-i, null, |
| 10109 | mOnBatteryTimeBase); |
| 10110 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10111 | mAudioOnTimer = new StopwatchTimer(mClocks, null, -7, null, mOnBatteryTimeBase); |
| 10112 | mVideoOnTimer = new StopwatchTimer(mClocks, null, -8, null, mOnBatteryTimeBase); |
| 10113 | mFlashlightOnTimer = new StopwatchTimer(mClocks, null, -9, null, mOnBatteryTimeBase); |
| 10114 | mCameraOnTimer = new StopwatchTimer(mClocks, null, -13, null, mOnBatteryTimeBase); |
| 10115 | mBluetoothScanTimer = new StopwatchTimer(mClocks, null, -14, null, mOnBatteryTimeBase); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 10116 | mDischargeScreenOffCounter = new LongSamplingCounter(mOnBatteryScreenOffTimeBase); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 10117 | mDischargeScreenDozeCounter = new LongSamplingCounter(mOnBatteryTimeBase); |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 10118 | mDischargeLightDozeCounter = new LongSamplingCounter(mOnBatteryTimeBase); |
| 10119 | mDischargeDeepDozeCounter = new LongSamplingCounter(mOnBatteryTimeBase); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 10120 | mDischargeCounter = new LongSamplingCounter(mOnBatteryTimeBase); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10121 | mOnBattery = mOnBatteryInternal = false; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10122 | long uptime = mClocks.uptimeMillis() * 1000; |
| 10123 | long realtime = mClocks.elapsedRealtime() * 1000; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10124 | initTimes(uptime, realtime); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 10125 | mStartPlatformVersion = mEndPlatformVersion = Build.ID; |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 10126 | mDischargeStartLevel = 0; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10127 | mDischargeUnplugLevel = 0; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 10128 | mDischargePlugLevel = -1; |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 10129 | mDischargeCurrentLevel = 0; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 10130 | mCurrentBatteryLevel = 0; |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 10131 | initDischarge(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10132 | clearHistoryLocked(); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10133 | updateDailyDeadlineLocked(); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 10134 | mPlatformIdleStateCallback = cb; |
Suprabh Shukla | e6e723d | 2017-06-14 16:14:43 -0700 | [diff] [blame] | 10135 | mUserInfoProvider = userInfoProvider; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10136 | } |
| 10137 | |
| 10138 | public BatteryStatsImpl(Parcel p) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10139 | this(new SystemClocks(), p); |
| 10140 | } |
| 10141 | |
| 10142 | public BatteryStatsImpl(Clocks clocks, Parcel p) { |
| 10143 | init(clocks); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10144 | mFile = null; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 10145 | mCheckinFile = null; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10146 | mDailyFile = null; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 10147 | mHandler = null; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 10148 | mExternalSync = null; |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 10149 | mConstants = new Constants(mHandler); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10150 | clearHistoryLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10151 | readFromParcel(p); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 10152 | mPlatformIdleStateCallback = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10153 | } |
| 10154 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 10155 | public void setPowerProfileLocked(PowerProfile profile) { |
| 10156 | mPowerProfile = profile; |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 10157 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 10158 | // We need to initialize the KernelCpuSpeedReaders to read from |
| 10159 | // the first cpu of each core. Once we have the PowerProfile, we have access to this |
| 10160 | // information. |
| 10161 | final int numClusters = mPowerProfile.getNumCpuClusters(); |
| 10162 | mKernelCpuSpeedReaders = new KernelCpuSpeedReader[numClusters]; |
| 10163 | int firstCpuOfCluster = 0; |
| 10164 | for (int i = 0; i < numClusters; i++) { |
| 10165 | final int numSpeedSteps = mPowerProfile.getNumSpeedStepsInCpuCluster(i); |
| 10166 | mKernelCpuSpeedReaders[i] = new KernelCpuSpeedReader(firstCpuOfCluster, |
| 10167 | numSpeedSteps); |
| 10168 | firstCpuOfCluster += mPowerProfile.getNumCoresInCpuCluster(i); |
| 10169 | } |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 10170 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 10171 | if (mEstimatedBatteryCapacity == -1) { |
| 10172 | // Initialize the estimated battery capacity to a known preset one. |
| 10173 | mEstimatedBatteryCapacity = (int) mPowerProfile.getBatteryCapacity(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 10174 | } |
| 10175 | } |
| 10176 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 10177 | public void setCallback(BatteryCallback cb) { |
| 10178 | mCallback = cb; |
| 10179 | } |
| 10180 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 10181 | public void setRadioScanningTimeoutLocked(long timeout) { |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 10182 | if (mPhoneSignalScanningTimer != null) { |
| 10183 | mPhoneSignalScanningTimer.setTimeout(timeout); |
| 10184 | } |
| 10185 | } |
| 10186 | |
Adam Lesinski | b3a1bad | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 10187 | public void setExternalStatsSyncLocked(ExternalStatsSync sync) { |
| 10188 | mExternalSync = sync; |
| 10189 | } |
| 10190 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10191 | public void updateDailyDeadlineLocked() { |
| 10192 | // Get the current time. |
| 10193 | long currentTime = mDailyStartTime = System.currentTimeMillis(); |
| 10194 | Calendar calDeadline = Calendar.getInstance(); |
| 10195 | calDeadline.setTimeInMillis(currentTime); |
| 10196 | |
| 10197 | // Move time up to the next day, ranging from 1am to 3pm. |
| 10198 | calDeadline.set(Calendar.DAY_OF_YEAR, calDeadline.get(Calendar.DAY_OF_YEAR) + 1); |
| 10199 | calDeadline.set(Calendar.MILLISECOND, 0); |
| 10200 | calDeadline.set(Calendar.SECOND, 0); |
| 10201 | calDeadline.set(Calendar.MINUTE, 0); |
| 10202 | calDeadline.set(Calendar.HOUR_OF_DAY, 1); |
| 10203 | mNextMinDailyDeadline = calDeadline.getTimeInMillis(); |
| 10204 | calDeadline.set(Calendar.HOUR_OF_DAY, 3); |
| 10205 | mNextMaxDailyDeadline = calDeadline.getTimeInMillis(); |
| 10206 | } |
| 10207 | |
| 10208 | public void recordDailyStatsIfNeededLocked(boolean settled) { |
| 10209 | long currentTime = System.currentTimeMillis(); |
| 10210 | if (currentTime >= mNextMaxDailyDeadline) { |
| 10211 | recordDailyStatsLocked(); |
| 10212 | } else if (settled && currentTime >= mNextMinDailyDeadline) { |
| 10213 | recordDailyStatsLocked(); |
| 10214 | } else if (currentTime < (mDailyStartTime-(1000*60*60*24))) { |
| 10215 | recordDailyStatsLocked(); |
| 10216 | } |
| 10217 | } |
| 10218 | |
| 10219 | public void recordDailyStatsLocked() { |
| 10220 | DailyItem item = new DailyItem(); |
| 10221 | item.mStartTime = mDailyStartTime; |
| 10222 | item.mEndTime = System.currentTimeMillis(); |
| 10223 | boolean hasData = false; |
| 10224 | if (mDailyDischargeStepTracker.mNumStepDurations > 0) { |
| 10225 | hasData = true; |
| 10226 | item.mDischargeSteps = new LevelStepTracker( |
| 10227 | mDailyDischargeStepTracker.mNumStepDurations, |
| 10228 | mDailyDischargeStepTracker.mStepDurations); |
| 10229 | } |
| 10230 | if (mDailyChargeStepTracker.mNumStepDurations > 0) { |
| 10231 | hasData = true; |
| 10232 | item.mChargeSteps = new LevelStepTracker( |
| 10233 | mDailyChargeStepTracker.mNumStepDurations, |
| 10234 | mDailyChargeStepTracker.mStepDurations); |
| 10235 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 10236 | if (mDailyPackageChanges != null) { |
| 10237 | hasData = true; |
| 10238 | item.mPackageChanges = mDailyPackageChanges; |
| 10239 | mDailyPackageChanges = null; |
| 10240 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10241 | mDailyDischargeStepTracker.init(); |
| 10242 | mDailyChargeStepTracker.init(); |
| 10243 | updateDailyDeadlineLocked(); |
| 10244 | |
| 10245 | if (hasData) { |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 10246 | final long startTime = SystemClock.uptimeMillis(); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10247 | mDailyItems.add(item); |
| 10248 | while (mDailyItems.size() > MAX_DAILY_ITEMS) { |
| 10249 | mDailyItems.remove(0); |
| 10250 | } |
| 10251 | final ByteArrayOutputStream memStream = new ByteArrayOutputStream(); |
| 10252 | try { |
| 10253 | XmlSerializer out = new FastXmlSerializer(); |
Wojciech Staszkiewicz | 9e9e2e7 | 2015-05-08 14:58:46 +0100 | [diff] [blame] | 10254 | out.setOutput(memStream, StandardCharsets.UTF_8.name()); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10255 | writeDailyItemsLocked(out); |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 10256 | final long initialTime = SystemClock.uptimeMillis() - startTime; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10257 | BackgroundThread.getHandler().post(new Runnable() { |
| 10258 | @Override |
| 10259 | public void run() { |
| 10260 | synchronized (mCheckinFile) { |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 10261 | final long startTime2 = SystemClock.uptimeMillis(); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10262 | FileOutputStream stream = null; |
| 10263 | try { |
| 10264 | stream = mDailyFile.startWrite(); |
| 10265 | memStream.writeTo(stream); |
| 10266 | stream.flush(); |
| 10267 | FileUtils.sync(stream); |
| 10268 | stream.close(); |
| 10269 | mDailyFile.finishWrite(stream); |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 10270 | com.android.internal.logging.EventLogTags.writeCommitSysConfigFile( |
| 10271 | "batterystats-daily", |
| 10272 | initialTime + SystemClock.uptimeMillis() - startTime2); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10273 | } catch (IOException e) { |
| 10274 | Slog.w("BatteryStats", |
| 10275 | "Error writing battery daily items", e); |
| 10276 | mDailyFile.failWrite(stream); |
| 10277 | } |
| 10278 | } |
| 10279 | } |
| 10280 | }); |
| 10281 | } catch (IOException e) { |
| 10282 | } |
| 10283 | } |
| 10284 | } |
| 10285 | |
| 10286 | private void writeDailyItemsLocked(XmlSerializer out) throws IOException { |
| 10287 | StringBuilder sb = new StringBuilder(64); |
| 10288 | out.startDocument(null, true); |
| 10289 | out.startTag(null, "daily-items"); |
| 10290 | for (int i=0; i<mDailyItems.size(); i++) { |
| 10291 | final DailyItem dit = mDailyItems.get(i); |
| 10292 | out.startTag(null, "item"); |
| 10293 | out.attribute(null, "start", Long.toString(dit.mStartTime)); |
| 10294 | out.attribute(null, "end", Long.toString(dit.mEndTime)); |
| 10295 | writeDailyLevelSteps(out, "dis", dit.mDischargeSteps, sb); |
| 10296 | writeDailyLevelSteps(out, "chg", dit.mChargeSteps, sb); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 10297 | if (dit.mPackageChanges != null) { |
| 10298 | for (int j=0; j<dit.mPackageChanges.size(); j++) { |
| 10299 | PackageChange pc = dit.mPackageChanges.get(j); |
| 10300 | if (pc.mUpdate) { |
| 10301 | out.startTag(null, "upd"); |
| 10302 | out.attribute(null, "pkg", pc.mPackageName); |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 10303 | out.attribute(null, "ver", Long.toString(pc.mVersionCode)); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 10304 | out.endTag(null, "upd"); |
| 10305 | } else { |
| 10306 | out.startTag(null, "rem"); |
| 10307 | out.attribute(null, "pkg", pc.mPackageName); |
| 10308 | out.endTag(null, "rem"); |
| 10309 | } |
| 10310 | } |
| 10311 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10312 | out.endTag(null, "item"); |
| 10313 | } |
| 10314 | out.endTag(null, "daily-items"); |
| 10315 | out.endDocument(); |
| 10316 | } |
| 10317 | |
| 10318 | private void writeDailyLevelSteps(XmlSerializer out, String tag, LevelStepTracker steps, |
| 10319 | StringBuilder tmpBuilder) throws IOException { |
| 10320 | if (steps != null) { |
| 10321 | out.startTag(null, tag); |
| 10322 | out.attribute(null, "n", Integer.toString(steps.mNumStepDurations)); |
| 10323 | for (int i=0; i<steps.mNumStepDurations; i++) { |
| 10324 | out.startTag(null, "s"); |
| 10325 | tmpBuilder.setLength(0); |
| 10326 | steps.encodeEntryAt(i, tmpBuilder); |
| 10327 | out.attribute(null, "v", tmpBuilder.toString()); |
| 10328 | out.endTag(null, "s"); |
| 10329 | } |
| 10330 | out.endTag(null, tag); |
| 10331 | } |
| 10332 | } |
| 10333 | |
| 10334 | public void readDailyStatsLocked() { |
| 10335 | Slog.d(TAG, "Reading daily items from " + mDailyFile.getBaseFile()); |
| 10336 | mDailyItems.clear(); |
| 10337 | FileInputStream stream; |
| 10338 | try { |
| 10339 | stream = mDailyFile.openRead(); |
| 10340 | } catch (FileNotFoundException e) { |
| 10341 | return; |
| 10342 | } |
| 10343 | try { |
| 10344 | XmlPullParser parser = Xml.newPullParser(); |
Wojciech Staszkiewicz | 9e9e2e7 | 2015-05-08 14:58:46 +0100 | [diff] [blame] | 10345 | parser.setInput(stream, StandardCharsets.UTF_8.name()); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10346 | readDailyItemsLocked(parser); |
| 10347 | } catch (XmlPullParserException e) { |
| 10348 | } finally { |
| 10349 | try { |
| 10350 | stream.close(); |
| 10351 | } catch (IOException e) { |
| 10352 | } |
| 10353 | } |
| 10354 | } |
| 10355 | |
| 10356 | private void readDailyItemsLocked(XmlPullParser parser) { |
| 10357 | try { |
| 10358 | int type; |
| 10359 | while ((type = parser.next()) != XmlPullParser.START_TAG |
| 10360 | && type != XmlPullParser.END_DOCUMENT) { |
| 10361 | ; |
| 10362 | } |
| 10363 | |
| 10364 | if (type != XmlPullParser.START_TAG) { |
| 10365 | throw new IllegalStateException("no start tag found"); |
| 10366 | } |
| 10367 | |
| 10368 | int outerDepth = parser.getDepth(); |
| 10369 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 10370 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 10371 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 10372 | continue; |
| 10373 | } |
| 10374 | |
| 10375 | String tagName = parser.getName(); |
| 10376 | if (tagName.equals("item")) { |
| 10377 | readDailyItemTagLocked(parser); |
| 10378 | } else { |
| 10379 | Slog.w(TAG, "Unknown element under <daily-items>: " |
| 10380 | + parser.getName()); |
| 10381 | XmlUtils.skipCurrentTag(parser); |
| 10382 | } |
| 10383 | } |
| 10384 | |
| 10385 | } catch (IllegalStateException e) { |
| 10386 | Slog.w(TAG, "Failed parsing daily " + e); |
| 10387 | } catch (NullPointerException e) { |
| 10388 | Slog.w(TAG, "Failed parsing daily " + e); |
| 10389 | } catch (NumberFormatException e) { |
| 10390 | Slog.w(TAG, "Failed parsing daily " + e); |
| 10391 | } catch (XmlPullParserException e) { |
| 10392 | Slog.w(TAG, "Failed parsing daily " + e); |
| 10393 | } catch (IOException e) { |
| 10394 | Slog.w(TAG, "Failed parsing daily " + e); |
| 10395 | } catch (IndexOutOfBoundsException e) { |
| 10396 | Slog.w(TAG, "Failed parsing daily " + e); |
| 10397 | } |
| 10398 | } |
| 10399 | |
| 10400 | void readDailyItemTagLocked(XmlPullParser parser) throws NumberFormatException, |
| 10401 | XmlPullParserException, IOException { |
| 10402 | DailyItem dit = new DailyItem(); |
| 10403 | String attr = parser.getAttributeValue(null, "start"); |
| 10404 | if (attr != null) { |
| 10405 | dit.mStartTime = Long.parseLong(attr); |
| 10406 | } |
| 10407 | attr = parser.getAttributeValue(null, "end"); |
| 10408 | if (attr != null) { |
| 10409 | dit.mEndTime = Long.parseLong(attr); |
| 10410 | } |
| 10411 | int outerDepth = parser.getDepth(); |
| 10412 | int type; |
| 10413 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 10414 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 10415 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 10416 | continue; |
| 10417 | } |
| 10418 | |
| 10419 | String tagName = parser.getName(); |
| 10420 | if (tagName.equals("dis")) { |
| 10421 | readDailyItemTagDetailsLocked(parser, dit, false, "dis"); |
| 10422 | } else if (tagName.equals("chg")) { |
| 10423 | readDailyItemTagDetailsLocked(parser, dit, true, "chg"); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 10424 | } else if (tagName.equals("upd")) { |
| 10425 | if (dit.mPackageChanges == null) { |
| 10426 | dit.mPackageChanges = new ArrayList<>(); |
| 10427 | } |
| 10428 | PackageChange pc = new PackageChange(); |
| 10429 | pc.mUpdate = true; |
| 10430 | pc.mPackageName = parser.getAttributeValue(null, "pkg"); |
| 10431 | String verStr = parser.getAttributeValue(null, "ver"); |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 10432 | pc.mVersionCode = verStr != null ? Long.parseLong(verStr) : 0; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 10433 | dit.mPackageChanges.add(pc); |
| 10434 | XmlUtils.skipCurrentTag(parser); |
| 10435 | } else if (tagName.equals("rem")) { |
| 10436 | if (dit.mPackageChanges == null) { |
| 10437 | dit.mPackageChanges = new ArrayList<>(); |
| 10438 | } |
| 10439 | PackageChange pc = new PackageChange(); |
| 10440 | pc.mUpdate = false; |
| 10441 | pc.mPackageName = parser.getAttributeValue(null, "pkg"); |
| 10442 | dit.mPackageChanges.add(pc); |
| 10443 | XmlUtils.skipCurrentTag(parser); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10444 | } else { |
| 10445 | Slog.w(TAG, "Unknown element under <item>: " |
| 10446 | + parser.getName()); |
| 10447 | XmlUtils.skipCurrentTag(parser); |
| 10448 | } |
| 10449 | } |
| 10450 | mDailyItems.add(dit); |
| 10451 | } |
| 10452 | |
| 10453 | void readDailyItemTagDetailsLocked(XmlPullParser parser, DailyItem dit, boolean isCharge, |
| 10454 | String tag) |
| 10455 | throws NumberFormatException, XmlPullParserException, IOException { |
| 10456 | final String numAttr = parser.getAttributeValue(null, "n"); |
| 10457 | if (numAttr == null) { |
| 10458 | Slog.w(TAG, "Missing 'n' attribute at " + parser.getPositionDescription()); |
| 10459 | XmlUtils.skipCurrentTag(parser); |
| 10460 | return; |
| 10461 | } |
| 10462 | final int num = Integer.parseInt(numAttr); |
| 10463 | LevelStepTracker steps = new LevelStepTracker(num); |
| 10464 | if (isCharge) { |
| 10465 | dit.mChargeSteps = steps; |
| 10466 | } else { |
| 10467 | dit.mDischargeSteps = steps; |
| 10468 | } |
| 10469 | int i = 0; |
| 10470 | int outerDepth = parser.getDepth(); |
| 10471 | int type; |
| 10472 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 10473 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 10474 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 10475 | continue; |
| 10476 | } |
| 10477 | |
| 10478 | String tagName = parser.getName(); |
| 10479 | if ("s".equals(tagName)) { |
| 10480 | if (i < num) { |
| 10481 | String valueAttr = parser.getAttributeValue(null, "v"); |
| 10482 | if (valueAttr != null) { |
| 10483 | steps.decodeEntryAt(i, valueAttr); |
| 10484 | i++; |
| 10485 | } |
| 10486 | } |
| 10487 | } else { |
| 10488 | Slog.w(TAG, "Unknown element under <" + tag + ">: " |
| 10489 | + parser.getName()); |
| 10490 | XmlUtils.skipCurrentTag(parser); |
| 10491 | } |
| 10492 | } |
| 10493 | steps.mNumStepDurations = i; |
| 10494 | } |
| 10495 | |
| 10496 | @Override |
| 10497 | public DailyItem getDailyItemLocked(int daysAgo) { |
| 10498 | int index = mDailyItems.size()-1-daysAgo; |
| 10499 | return index >= 0 ? mDailyItems.get(index) : null; |
| 10500 | } |
| 10501 | |
| 10502 | @Override |
| 10503 | public long getCurrentDailyStartTime() { |
| 10504 | return mDailyStartTime; |
| 10505 | } |
| 10506 | |
| 10507 | @Override |
| 10508 | public long getNextMinDailyDeadline() { |
| 10509 | return mNextMinDailyDeadline; |
| 10510 | } |
| 10511 | |
| 10512 | @Override |
| 10513 | public long getNextMaxDailyDeadline() { |
| 10514 | return mNextMaxDailyDeadline; |
| 10515 | } |
| 10516 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10517 | @Override |
| 10518 | public boolean startIteratingOldHistoryLocked() { |
| 10519 | if (DEBUG_HISTORY) Slog.i(TAG, "ITERATING: buff size=" + mHistoryBuffer.dataSize() |
| 10520 | + " pos=" + mHistoryBuffer.dataPosition()); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 10521 | if ((mHistoryIterator = mHistory) == null) { |
| 10522 | return false; |
| 10523 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10524 | mHistoryBuffer.setDataPosition(0); |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 10525 | mHistoryReadTmp.clear(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10526 | mReadOverflow = false; |
| 10527 | mIteratingHistory = true; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 10528 | return true; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 10529 | } |
| 10530 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10531 | @Override |
| 10532 | public boolean getNextOldHistoryLocked(HistoryItem out) { |
| 10533 | boolean end = mHistoryBuffer.dataPosition() >= mHistoryBuffer.dataSize(); |
| 10534 | if (!end) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 10535 | readHistoryDelta(mHistoryBuffer, mHistoryReadTmp); |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 10536 | mReadOverflow |= mHistoryReadTmp.cmd == HistoryItem.CMD_OVERFLOW; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10537 | } |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 10538 | HistoryItem cur = mHistoryIterator; |
| 10539 | if (cur == null) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10540 | if (!mReadOverflow && !end) { |
| 10541 | Slog.w(TAG, "Old history ends before new history!"); |
| 10542 | } |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 10543 | return false; |
| 10544 | } |
| 10545 | out.setTo(cur); |
| 10546 | mHistoryIterator = cur.next; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10547 | if (!mReadOverflow) { |
| 10548 | if (end) { |
| 10549 | Slog.w(TAG, "New history ends before old history!"); |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 10550 | } else if (!out.same(mHistoryReadTmp)) { |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 10551 | PrintWriter pw = new FastPrintWriter(new LogWriter(android.util.Log.WARN, TAG)); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10552 | pw.println("Histories differ!"); |
| 10553 | pw.println("Old history:"); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 10554 | (new HistoryPrinter()).printNextItem(pw, out, 0, false, true); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10555 | pw.println("New history:"); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 10556 | (new HistoryPrinter()).printNextItem(pw, mHistoryReadTmp, 0, false, |
| 10557 | true); |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 10558 | pw.flush(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10559 | } |
| 10560 | } |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 10561 | return true; |
| 10562 | } |
| 10563 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10564 | @Override |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10565 | public void finishIteratingOldHistoryLocked() { |
| 10566 | mIteratingHistory = false; |
| 10567 | mHistoryBuffer.setDataPosition(mHistoryBuffer.dataSize()); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 10568 | mHistoryIterator = null; |
| 10569 | } |
| 10570 | |
| 10571 | public int getHistoryTotalSize() { |
| 10572 | return MAX_HISTORY_BUFFER; |
| 10573 | } |
| 10574 | |
| 10575 | public int getHistoryUsedSize() { |
| 10576 | return mHistoryBuffer.dataSize(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10577 | } |
| 10578 | |
| 10579 | @Override |
| 10580 | public boolean startIteratingHistoryLocked() { |
| 10581 | if (DEBUG_HISTORY) Slog.i(TAG, "ITERATING: buff size=" + mHistoryBuffer.dataSize() |
| 10582 | + " pos=" + mHistoryBuffer.dataPosition()); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 10583 | if (mHistoryBuffer.dataSize() <= 0) { |
| 10584 | return false; |
| 10585 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10586 | mHistoryBuffer.setDataPosition(0); |
| 10587 | mReadOverflow = false; |
| 10588 | mIteratingHistory = true; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 10589 | mReadHistoryStrings = new String[mHistoryTagPool.size()]; |
| 10590 | mReadHistoryUids = new int[mHistoryTagPool.size()]; |
| 10591 | mReadHistoryChars = 0; |
| 10592 | for (HashMap.Entry<HistoryTag, Integer> ent : mHistoryTagPool.entrySet()) { |
| 10593 | final HistoryTag tag = ent.getKey(); |
| 10594 | final int idx = ent.getValue(); |
| 10595 | mReadHistoryStrings[idx] = tag.string; |
| 10596 | mReadHistoryUids[idx] = tag.uid; |
| 10597 | mReadHistoryChars += tag.string.length() + 1; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 10598 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 10599 | return true; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10600 | } |
| 10601 | |
| 10602 | @Override |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 10603 | public int getHistoryStringPoolSize() { |
| 10604 | return mReadHistoryStrings.length; |
| 10605 | } |
| 10606 | |
| 10607 | @Override |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 10608 | public int getHistoryStringPoolBytes() { |
| 10609 | // Each entry is a fixed 12 bytes: 4 for index, 4 for uid, 4 for string size |
| 10610 | // Each string character is 2 bytes. |
| 10611 | return (mReadHistoryStrings.length * 12) + (mReadHistoryChars * 2); |
| 10612 | } |
| 10613 | |
| 10614 | @Override |
| 10615 | public String getHistoryTagPoolString(int index) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 10616 | return mReadHistoryStrings[index]; |
| 10617 | } |
| 10618 | |
| 10619 | @Override |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 10620 | public int getHistoryTagPoolUid(int index) { |
| 10621 | return mReadHistoryUids[index]; |
| 10622 | } |
| 10623 | |
| 10624 | @Override |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10625 | public boolean getNextHistoryLocked(HistoryItem out) { |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 10626 | final int pos = mHistoryBuffer.dataPosition(); |
| 10627 | if (pos == 0) { |
| 10628 | out.clear(); |
| 10629 | } |
| 10630 | boolean end = pos >= mHistoryBuffer.dataSize(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10631 | if (end) { |
| 10632 | return false; |
| 10633 | } |
| 10634 | |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 10635 | final long lastRealtime = out.time; |
| 10636 | final long lastWalltime = out.currentTime; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 10637 | readHistoryDelta(mHistoryBuffer, out); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 10638 | if (out.cmd != HistoryItem.CMD_CURRENT_TIME |
| 10639 | && out.cmd != HistoryItem.CMD_RESET && lastWalltime != 0) { |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 10640 | out.currentTime = lastWalltime + (out.time - lastRealtime); |
| 10641 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10642 | return true; |
| 10643 | } |
| 10644 | |
| 10645 | @Override |
| 10646 | public void finishIteratingHistoryLocked() { |
| 10647 | mIteratingHistory = false; |
| 10648 | mHistoryBuffer.setDataPosition(mHistoryBuffer.dataSize()); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 10649 | mReadHistoryStrings = null; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 10650 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10651 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 10652 | @Override |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 10653 | public long getHistoryBaseTime() { |
| 10654 | return mHistoryBaseTime; |
| 10655 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10656 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 10657 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10658 | public int getStartCount() { |
| 10659 | return mStartCount; |
| 10660 | } |
| 10661 | |
| 10662 | public boolean isOnBattery() { |
| 10663 | return mOnBattery; |
| 10664 | } |
| 10665 | |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 10666 | public boolean isCharging() { |
| 10667 | return mCharging; |
| 10668 | } |
| 10669 | |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 10670 | public boolean isScreenOn(int state) { |
Chris Phoenix | 10a4a64 | 2017-09-25 13:21:00 -0700 | [diff] [blame] | 10671 | return state == Display.STATE_ON || state == Display.STATE_VR |
| 10672 | || state == Display.STATE_ON_SUSPEND; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 10673 | } |
| 10674 | |
| 10675 | public boolean isScreenOff(int state) { |
| 10676 | return state == Display.STATE_OFF; |
| 10677 | } |
| 10678 | |
| 10679 | public boolean isScreenDoze(int state) { |
| 10680 | return state == Display.STATE_DOZE || state == Display.STATE_DOZE_SUSPEND; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 10681 | } |
| 10682 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10683 | void initTimes(long uptime, long realtime) { |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 10684 | mStartClockTime = System.currentTimeMillis(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10685 | mOnBatteryTimeBase.init(uptime, realtime); |
| 10686 | mOnBatteryScreenOffTimeBase.init(uptime, realtime); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 10687 | mRealtime = 0; |
| 10688 | mUptime = 0; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10689 | mRealtimeStart = realtime; |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 10690 | mUptimeStart = uptime; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10691 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10692 | |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 10693 | void initDischarge() { |
| 10694 | mLowDischargeAmountSinceCharge = 0; |
| 10695 | mHighDischargeAmountSinceCharge = 0; |
| 10696 | mDischargeAmountScreenOn = 0; |
| 10697 | mDischargeAmountScreenOnSinceCharge = 0; |
| 10698 | mDischargeAmountScreenOff = 0; |
| 10699 | mDischargeAmountScreenOffSinceCharge = 0; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 10700 | mDischargeAmountScreenDoze = 0; |
| 10701 | mDischargeAmountScreenDozeSinceCharge = 0; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10702 | mDischargeStepTracker.init(); |
| 10703 | mChargeStepTracker.init(); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 10704 | mDischargeScreenOffCounter.reset(false); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 10705 | mDischargeScreenDozeCounter.reset(false); |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 10706 | mDischargeLightDozeCounter.reset(false); |
| 10707 | mDischargeDeepDozeCounter.reset(false); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 10708 | mDischargeCounter.reset(false); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 10709 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 10710 | |
| 10711 | public void resetAllStatsCmdLocked() { |
| 10712 | resetAllStatsLocked(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10713 | final long mSecUptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 10714 | long uptime = mSecUptime * 1000; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10715 | long mSecRealtime = mClocks.elapsedRealtime(); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 10716 | long realtime = mSecRealtime * 1000; |
| 10717 | mDischargeStartLevel = mHistoryCur.batteryLevel; |
| 10718 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 10719 | addHistoryRecordLocked(mSecRealtime, mSecUptime); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 10720 | mDischargeCurrentLevel = mDischargeUnplugLevel = mDischargePlugLevel |
| 10721 | = mCurrentBatteryLevel = mHistoryCur.batteryLevel; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10722 | mOnBatteryTimeBase.reset(uptime, realtime); |
| 10723 | mOnBatteryScreenOffTimeBase.reset(uptime, realtime); |
| 10724 | if ((mHistoryCur.states&HistoryItem.STATE_BATTERY_PLUGGED_FLAG) == 0) { |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 10725 | if (isScreenOn(mScreenState)) { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 10726 | mDischargeScreenOnUnplugLevel = mHistoryCur.batteryLevel; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 10727 | mDischargeScreenDozeUnplugLevel = 0; |
| 10728 | mDischargeScreenOffUnplugLevel = 0; |
| 10729 | } else if (isScreenDoze(mScreenState)) { |
| 10730 | mDischargeScreenOnUnplugLevel = 0; |
| 10731 | mDischargeScreenDozeUnplugLevel = mHistoryCur.batteryLevel; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 10732 | mDischargeScreenOffUnplugLevel = 0; |
| 10733 | } else { |
| 10734 | mDischargeScreenOnUnplugLevel = 0; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 10735 | mDischargeScreenDozeUnplugLevel = 0; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 10736 | mDischargeScreenOffUnplugLevel = mHistoryCur.batteryLevel; |
| 10737 | } |
| 10738 | mDischargeAmountScreenOn = 0; |
| 10739 | mDischargeAmountScreenOff = 0; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 10740 | mDischargeAmountScreenDoze = 0; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 10741 | } |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 10742 | initActiveHistoryEventsLocked(mSecRealtime, mSecUptime); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 10743 | } |
| 10744 | |
| 10745 | private void resetAllStatsLocked() { |
Adam Lesinski | 8ce3694 | 2016-05-26 16:05:35 -0700 | [diff] [blame] | 10746 | final long uptimeMillis = mClocks.uptimeMillis(); |
| 10747 | final long elapsedRealtimeMillis = mClocks.elapsedRealtime(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10748 | mStartCount = 0; |
Adam Lesinski | 8ce3694 | 2016-05-26 16:05:35 -0700 | [diff] [blame] | 10749 | initTimes(uptimeMillis * 1000, elapsedRealtimeMillis * 1000); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10750 | mScreenOnTimer.reset(false); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 10751 | mScreenDozeTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10752 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10753 | mScreenBrightnessTimer[i].reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10754 | } |
Adam Lesinski | 1a76a62 | 2016-06-22 10:28:47 -0700 | [diff] [blame] | 10755 | |
| 10756 | if (mPowerProfile != null) { |
| 10757 | mEstimatedBatteryCapacity = (int) mPowerProfile.getBatteryCapacity(); |
| 10758 | } else { |
| 10759 | mEstimatedBatteryCapacity = -1; |
| 10760 | } |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 10761 | mMinLearnedBatteryCapacity = -1; |
| 10762 | mMaxLearnedBatteryCapacity = -1; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 10763 | mInteractiveTimer.reset(false); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 10764 | mPowerSaveModeEnabledTimer.reset(false); |
Adam Lesinski | 8ce3694 | 2016-05-26 16:05:35 -0700 | [diff] [blame] | 10765 | mLastIdleTimeStart = elapsedRealtimeMillis; |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 10766 | mLongestLightIdleTime = 0; |
| 10767 | mLongestFullIdleTime = 0; |
| 10768 | mDeviceIdleModeLightTimer.reset(false); |
| 10769 | mDeviceIdleModeFullTimer.reset(false); |
| 10770 | mDeviceLightIdlingTimer.reset(false); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 10771 | mDeviceIdlingTimer.reset(false); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10772 | mPhoneOnTimer.reset(false); |
| 10773 | mAudioOnTimer.reset(false); |
| 10774 | mVideoOnTimer.reset(false); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 10775 | mFlashlightOnTimer.reset(false); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 10776 | mCameraOnTimer.reset(false); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 10777 | mBluetoothScanTimer.reset(false); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 10778 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10779 | mPhoneSignalStrengthsTimer[i].reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10780 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10781 | mPhoneSignalScanningTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10782 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10783 | mPhoneDataConnectionsTimer[i].reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10784 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 10785 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 10786 | mNetworkByteActivityCounters[i].reset(false); |
| 10787 | mNetworkPacketActivityCounters[i].reset(false); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 10788 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10789 | mMobileRadioActiveTimer.reset(false); |
| 10790 | mMobileRadioActivePerAppTimer.reset(false); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10791 | mMobileRadioActiveAdjustedTime.reset(false); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 10792 | mMobileRadioActiveUnknownTime.reset(false); |
| 10793 | mMobileRadioActiveUnknownCount.reset(false); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10794 | mWifiOnTimer.reset(false); |
| 10795 | mGlobalWifiRunningTimer.reset(false); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 10796 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10797 | mWifiStateTimer[i].reset(false); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 10798 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 10799 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 10800 | mWifiSupplStateTimer[i].reset(false); |
| 10801 | } |
| 10802 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 10803 | mWifiSignalStrengthsTimer[i].reset(false); |
| 10804 | } |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 10805 | mWifiMulticastWakelockTimer.reset(false); |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 10806 | mWifiActiveTimer.reset(false); |
| 10807 | mWifiActivity.reset(false); |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 10808 | for (int i=0; i< GnssMetrics.NUM_GPS_SIGNAL_QUALITY_LEVELS; i++) { |
| 10809 | mGpsSignalQualityTimer[i].reset(false); |
| 10810 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 10811 | mBluetoothActivity.reset(false); |
| 10812 | mModemActivity.reset(false); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 10813 | mNumConnectivityChange = mLoadedNumConnectivityChange = mUnpluggedNumConnectivityChange = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10814 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10815 | for (int i=0; i<mUidStats.size(); i++) { |
Bookatz | 993a0be | 2017-07-21 09:03:23 -0700 | [diff] [blame] | 10816 | if (mUidStats.valueAt(i).reset(uptimeMillis * 1000, elapsedRealtimeMillis * 1000)) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10817 | mUidStats.remove(mUidStats.keyAt(i)); |
| 10818 | i--; |
| 10819 | } |
| 10820 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10821 | |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 10822 | if (mRpmStats.size() > 0) { |
| 10823 | for (SamplingTimer timer : mRpmStats.values()) { |
| 10824 | mOnBatteryTimeBase.remove(timer); |
| 10825 | } |
| 10826 | mRpmStats.clear(); |
| 10827 | } |
| 10828 | if (mScreenOffRpmStats.size() > 0) { |
| 10829 | for (SamplingTimer timer : mScreenOffRpmStats.values()) { |
| 10830 | mOnBatteryScreenOffTimeBase.remove(timer); |
| 10831 | } |
| 10832 | mScreenOffRpmStats.clear(); |
| 10833 | } |
| 10834 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10835 | if (mKernelWakelockStats.size() > 0) { |
| 10836 | for (SamplingTimer timer : mKernelWakelockStats.values()) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10837 | mOnBatteryScreenOffTimeBase.remove(timer); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10838 | } |
| 10839 | mKernelWakelockStats.clear(); |
| 10840 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10841 | |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 10842 | if (mKernelMemoryStats.size() > 0) { |
| 10843 | for (int i = 0; i < mKernelMemoryStats.size(); i++) { |
| 10844 | mOnBatteryTimeBase.remove(mKernelMemoryStats.valueAt(i)); |
| 10845 | } |
| 10846 | mKernelMemoryStats.clear(); |
| 10847 | } |
| 10848 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10849 | if (mWakeupReasonStats.size() > 0) { |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 10850 | for (SamplingTimer timer : mWakeupReasonStats.values()) { |
| 10851 | mOnBatteryTimeBase.remove(timer); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10852 | } |
| 10853 | mWakeupReasonStats.clear(); |
| 10854 | } |
| 10855 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 10856 | mLastHistoryStepDetails = null; |
| 10857 | mLastStepCpuUserTime = mLastStepCpuSystemTime = 0; |
| 10858 | mCurStepCpuUserTime = mCurStepCpuSystemTime = 0; |
| 10859 | mLastStepCpuUserTime = mCurStepCpuUserTime = 0; |
| 10860 | mLastStepCpuSystemTime = mCurStepCpuSystemTime = 0; |
| 10861 | mLastStepStatUserTime = mCurStepStatUserTime = 0; |
| 10862 | mLastStepStatSystemTime = mCurStepStatSystemTime = 0; |
| 10863 | mLastStepStatIOWaitTime = mCurStepStatIOWaitTime = 0; |
| 10864 | mLastStepStatIrqTime = mCurStepStatIrqTime = 0; |
| 10865 | mLastStepStatSoftIrqTime = mCurStepStatSoftIrqTime = 0; |
| 10866 | mLastStepStatIdleTime = mCurStepStatIdleTime = 0; |
| 10867 | |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 10868 | initDischarge(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10869 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10870 | clearHistoryLocked(); |
| 10871 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10872 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 10873 | private void initActiveHistoryEventsLocked(long elapsedRealtimeMs, long uptimeMs) { |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 10874 | for (int i=0; i<HistoryItem.EVENT_COUNT; i++) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 10875 | if (!mRecordAllHistory && i == HistoryItem.EVENT_PROC) { |
| 10876 | // Not recording process starts/stops. |
| 10877 | continue; |
| 10878 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 10879 | HashMap<String, SparseIntArray> active = mActiveEvents.getStateForEvent(i); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 10880 | if (active == null) { |
| 10881 | continue; |
| 10882 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 10883 | for (HashMap.Entry<String, SparseIntArray> ent : active.entrySet()) { |
| 10884 | SparseIntArray uids = ent.getValue(); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 10885 | for (int j=0; j<uids.size(); j++) { |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 10886 | addHistoryEventLocked(elapsedRealtimeMs, uptimeMs, i, ent.getKey(), |
| 10887 | uids.keyAt(j)); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 10888 | } |
| 10889 | } |
| 10890 | } |
| 10891 | } |
| 10892 | |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 10893 | void updateDischargeScreenLevelsLocked(int oldState, int newState) { |
| 10894 | updateOldDischargeScreenLevelLocked(oldState); |
| 10895 | updateNewDischargeScreenLevelLocked(newState); |
| 10896 | } |
| 10897 | |
| 10898 | private void updateOldDischargeScreenLevelLocked(int state) { |
| 10899 | if (isScreenOn(state)) { |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 10900 | int diff = mDischargeScreenOnUnplugLevel - mDischargeCurrentLevel; |
| 10901 | if (diff > 0) { |
| 10902 | mDischargeAmountScreenOn += diff; |
| 10903 | mDischargeAmountScreenOnSinceCharge += diff; |
| 10904 | } |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 10905 | } else if (isScreenDoze(state)) { |
| 10906 | int diff = mDischargeScreenDozeUnplugLevel - mDischargeCurrentLevel; |
| 10907 | if (diff > 0) { |
| 10908 | mDischargeAmountScreenDoze += diff; |
| 10909 | mDischargeAmountScreenDozeSinceCharge += diff; |
| 10910 | } |
| 10911 | } else if (isScreenOff(state)){ |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 10912 | int diff = mDischargeScreenOffUnplugLevel - mDischargeCurrentLevel; |
| 10913 | if (diff > 0) { |
| 10914 | mDischargeAmountScreenOff += diff; |
| 10915 | mDischargeAmountScreenOffSinceCharge += diff; |
| 10916 | } |
| 10917 | } |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 10918 | } |
| 10919 | |
| 10920 | private void updateNewDischargeScreenLevelLocked(int state) { |
| 10921 | if (isScreenOn(state)) { |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 10922 | mDischargeScreenOnUnplugLevel = mDischargeCurrentLevel; |
| 10923 | mDischargeScreenOffUnplugLevel = 0; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 10924 | mDischargeScreenDozeUnplugLevel = 0; |
| 10925 | } else if (isScreenDoze(state)){ |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 10926 | mDischargeScreenOnUnplugLevel = 0; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 10927 | mDischargeScreenDozeUnplugLevel = mDischargeCurrentLevel; |
| 10928 | mDischargeScreenOffUnplugLevel = 0; |
| 10929 | } else if (isScreenOff(state)) { |
| 10930 | mDischargeScreenOnUnplugLevel = 0; |
| 10931 | mDischargeScreenDozeUnplugLevel = 0; |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 10932 | mDischargeScreenOffUnplugLevel = mDischargeCurrentLevel; |
| 10933 | } |
| 10934 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 10935 | |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 10936 | public void pullPendingStateUpdatesLocked() { |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 10937 | if (mOnBatteryInternal) { |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 10938 | updateDischargeScreenLevelsLocked(mScreenState, mScreenState); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 10939 | } |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 10940 | } |
| 10941 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 10942 | private final NetworkStatsFactory mNetworkStatsFactory = new NetworkStatsFactory(); |
| 10943 | private final Pools.Pool<NetworkStats> mNetworkStatsPool = new Pools.SynchronizedPool<>(6); |
| 10944 | |
| 10945 | private final Object mWifiNetworkLock = new Object(); |
| 10946 | |
| 10947 | @GuardedBy("mWifiNetworkLock") |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 10948 | private String[] mWifiIfaces = EmptyArray.STRING; |
| 10949 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 10950 | @GuardedBy("mWifiNetworkLock") |
| 10951 | private NetworkStats mLastWifiNetworkStats = new NetworkStats(0, -1); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 10952 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 10953 | private final Object mModemNetworkLock = new Object(); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 10954 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 10955 | @GuardedBy("mModemNetworkLock") |
| 10956 | private String[] mModemIfaces = EmptyArray.STRING; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 10957 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 10958 | @GuardedBy("mModemNetworkLock") |
| 10959 | private NetworkStats mLastModemNetworkStats = new NetworkStats(0, -1); |
| 10960 | |
| 10961 | private NetworkStats readNetworkStatsLocked(String[] ifaces) { |
| 10962 | try { |
| 10963 | if (!ArrayUtils.isEmpty(ifaces)) { |
| 10964 | return mNetworkStatsFactory.readNetworkStatsDetail(NetworkStats.UID_ALL, ifaces, |
| 10965 | NetworkStats.TAG_NONE, mNetworkStatsPool.acquire()); |
| 10966 | } |
| 10967 | } catch (IOException e) { |
| 10968 | 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] | 10969 | } |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 10970 | return null; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 10971 | } |
| 10972 | |
Chenjie Yu | 8908339 | 2018-01-11 14:53:31 -0800 | [diff] [blame] | 10973 | /** |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 10974 | * Distribute WiFi energy info and network traffic to apps. |
| 10975 | * @param info The energy information from the WiFi controller. |
| 10976 | */ |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 10977 | public void updateWifiState(@Nullable final WifiActivityEnergyInfo info) { |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 10978 | if (DEBUG_ENERGY) { |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 10979 | Slog.d(TAG, "Updating wifi stats: " + Arrays.toString(mWifiIfaces)); |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 10980 | } |
| 10981 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 10982 | // 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] | 10983 | NetworkStats delta = null; |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 10984 | synchronized (mWifiNetworkLock) { |
| 10985 | final NetworkStats latestStats = readNetworkStatsLocked(mWifiIfaces); |
| 10986 | if (latestStats != null) { |
| 10987 | delta = NetworkStats.subtract(latestStats, mLastWifiNetworkStats, null, null, |
| 10988 | mNetworkStatsPool.acquire()); |
| 10989 | mNetworkStatsPool.release(mLastWifiNetworkStats); |
| 10990 | mLastWifiNetworkStats = latestStats; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 10991 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 10992 | } |
| 10993 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 10994 | synchronized (this) { |
| 10995 | if (!mOnBatteryInternal) { |
| 10996 | if (delta != null) { |
| 10997 | mNetworkStatsPool.release(delta); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 10998 | } |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 10999 | return; |
| 11000 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11001 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11002 | final long elapsedRealtimeMs = mClocks.elapsedRealtime(); |
| 11003 | SparseLongArray rxPackets = new SparseLongArray(); |
| 11004 | SparseLongArray txPackets = new SparseLongArray(); |
| 11005 | long totalTxPackets = 0; |
| 11006 | long totalRxPackets = 0; |
| 11007 | if (delta != null) { |
| 11008 | NetworkStats.Entry entry = new NetworkStats.Entry(); |
| 11009 | final int size = delta.size(); |
| 11010 | for (int i = 0; i < size; i++) { |
| 11011 | entry = delta.getValues(i, entry); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11012 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11013 | if (DEBUG_ENERGY) { |
| 11014 | Slog.d(TAG, "Wifi uid " + entry.uid + ": delta rx=" + entry.rxBytes |
| 11015 | + " tx=" + entry.txBytes + " rxPackets=" + entry.rxPackets |
| 11016 | + " txPackets=" + entry.txPackets); |
| 11017 | } |
| 11018 | |
| 11019 | if (entry.rxBytes == 0 && entry.txBytes == 0) { |
| 11020 | // Skip the lookup below since there is no work to do. |
| 11021 | continue; |
| 11022 | } |
| 11023 | |
| 11024 | final Uid u = getUidStatsLocked(mapUid(entry.uid)); |
| 11025 | if (entry.rxBytes != 0) { |
| 11026 | u.noteNetworkActivityLocked(NETWORK_WIFI_RX_DATA, entry.rxBytes, |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 11027 | entry.rxPackets); |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11028 | if (entry.set == NetworkStats.SET_DEFAULT) { // Background transfers |
| 11029 | u.noteNetworkActivityLocked(NETWORK_WIFI_BG_RX_DATA, entry.rxBytes, |
| 11030 | entry.rxPackets); |
| 11031 | } |
| 11032 | mNetworkByteActivityCounters[NETWORK_WIFI_RX_DATA].addCountLocked( |
| 11033 | entry.rxBytes); |
| 11034 | mNetworkPacketActivityCounters[NETWORK_WIFI_RX_DATA].addCountLocked( |
| 11035 | entry.rxPackets); |
| 11036 | |
| 11037 | rxPackets.put(u.getUid(), entry.rxPackets); |
| 11038 | |
| 11039 | // Sum the total number of packets so that the Rx Power can |
| 11040 | // be evenly distributed amongst the apps. |
| 11041 | totalRxPackets += entry.rxPackets; |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 11042 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 11043 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11044 | if (entry.txBytes != 0) { |
| 11045 | u.noteNetworkActivityLocked(NETWORK_WIFI_TX_DATA, entry.txBytes, |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 11046 | entry.txPackets); |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11047 | if (entry.set == NetworkStats.SET_DEFAULT) { // Background transfers |
| 11048 | u.noteNetworkActivityLocked(NETWORK_WIFI_BG_TX_DATA, entry.txBytes, |
| 11049 | entry.txPackets); |
| 11050 | } |
| 11051 | mNetworkByteActivityCounters[NETWORK_WIFI_TX_DATA].addCountLocked( |
| 11052 | entry.txBytes); |
| 11053 | mNetworkPacketActivityCounters[NETWORK_WIFI_TX_DATA].addCountLocked( |
| 11054 | entry.txPackets); |
| 11055 | |
| 11056 | txPackets.put(u.getUid(), entry.txPackets); |
| 11057 | |
| 11058 | // Sum the total number of packets so that the Tx Power can |
| 11059 | // be evenly distributed amongst the apps. |
| 11060 | totalTxPackets += entry.txPackets; |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 11061 | } |
Adam Lesinski | ba88e68 | 2015-12-08 12:06:55 -0800 | [diff] [blame] | 11062 | } |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11063 | mNetworkStatsPool.release(delta); |
| 11064 | delta = null; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 11065 | } |
| 11066 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11067 | if (info != null) { |
| 11068 | mHasWifiReporting = true; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 11069 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11070 | // Measured in mAms |
| 11071 | final long txTimeMs = info.getControllerTxTimeMillis(); |
| 11072 | final long rxTimeMs = info.getControllerRxTimeMillis(); |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 11073 | final long scanTimeMs = info.getControllerScanTimeMillis(); |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11074 | final long idleTimeMs = info.getControllerIdleTimeMillis(); |
| 11075 | final long totalTimeMs = txTimeMs + rxTimeMs + idleTimeMs; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 11076 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11077 | long leftOverRxTimeMs = rxTimeMs; |
| 11078 | long leftOverTxTimeMs = txTimeMs; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 11079 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 11080 | if (DEBUG_ENERGY) { |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11081 | Slog.d(TAG, "------ BEGIN WiFi power blaming ------"); |
| 11082 | Slog.d(TAG, " Tx Time: " + txTimeMs + " ms"); |
| 11083 | Slog.d(TAG, " Rx Time: " + rxTimeMs + " ms"); |
| 11084 | Slog.d(TAG, " Idle Time: " + idleTimeMs + " ms"); |
| 11085 | Slog.d(TAG, " Total Time: " + totalTimeMs + " ms"); |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 11086 | Slog.d(TAG, " Scan Time: " + scanTimeMs + " ms"); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 11087 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 11088 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11089 | long totalWifiLockTimeMs = 0; |
| 11090 | long totalScanTimeMs = 0; |
| 11091 | |
| 11092 | // On the first pass, collect some totals so that we can normalize power |
| 11093 | // calculations if we need to. |
| 11094 | final int uidStatsSize = mUidStats.size(); |
| 11095 | for (int i = 0; i < uidStatsSize; i++) { |
| 11096 | final Uid uid = mUidStats.valueAt(i); |
| 11097 | |
| 11098 | // Sum the total scan power for all apps. |
| 11099 | totalScanTimeMs += uid.mWifiScanTimer.getTimeSinceMarkLocked( |
| 11100 | elapsedRealtimeMs * 1000) / 1000; |
| 11101 | |
| 11102 | // Sum the total time holding wifi lock for all apps. |
| 11103 | totalWifiLockTimeMs += uid.mFullWifiLockTimer.getTimeSinceMarkLocked( |
| 11104 | elapsedRealtimeMs * 1000) / 1000; |
| 11105 | } |
| 11106 | |
| 11107 | if (DEBUG_ENERGY && totalScanTimeMs > rxTimeMs) { |
| 11108 | Slog.d(TAG, |
| 11109 | " !Estimated scan time > Actual rx time (" + totalScanTimeMs + " ms > " |
| 11110 | + rxTimeMs + " ms). Normalizing scan time."); |
| 11111 | } |
| 11112 | if (DEBUG_ENERGY && totalScanTimeMs > txTimeMs) { |
| 11113 | Slog.d(TAG, |
| 11114 | " !Estimated scan time > Actual tx time (" + totalScanTimeMs + " ms > " |
| 11115 | + txTimeMs + " ms). Normalizing scan time."); |
| 11116 | } |
| 11117 | |
| 11118 | // Actually assign and distribute power usage to apps. |
| 11119 | for (int i = 0; i < uidStatsSize; i++) { |
| 11120 | final Uid uid = mUidStats.valueAt(i); |
| 11121 | |
| 11122 | long scanTimeSinceMarkMs = uid.mWifiScanTimer.getTimeSinceMarkLocked( |
| 11123 | elapsedRealtimeMs * 1000) / 1000; |
| 11124 | if (scanTimeSinceMarkMs > 0) { |
| 11125 | // Set the new mark so that next time we get new data since this point. |
| 11126 | uid.mWifiScanTimer.setMark(elapsedRealtimeMs); |
| 11127 | |
| 11128 | long scanRxTimeSinceMarkMs = scanTimeSinceMarkMs; |
| 11129 | long scanTxTimeSinceMarkMs = scanTimeSinceMarkMs; |
| 11130 | |
| 11131 | // Our total scan time is more than the reported Tx/Rx time. |
| 11132 | // This is possible because the cost of a scan is approximate. |
| 11133 | // Let's normalize the result so that we evenly blame each app |
| 11134 | // scanning. |
| 11135 | // |
| 11136 | // This means that we may have apps that transmitted/received packets not be |
| 11137 | // blamed for this, but this is fine as scans are relatively more expensive. |
| 11138 | if (totalScanTimeMs > rxTimeMs) { |
| 11139 | scanRxTimeSinceMarkMs = (rxTimeMs * scanRxTimeSinceMarkMs) / |
| 11140 | totalScanTimeMs; |
| 11141 | } |
| 11142 | if (totalScanTimeMs > txTimeMs) { |
| 11143 | scanTxTimeSinceMarkMs = (txTimeMs * scanTxTimeSinceMarkMs) / |
| 11144 | totalScanTimeMs; |
| 11145 | } |
| 11146 | |
| 11147 | if (DEBUG_ENERGY) { |
| 11148 | Slog.d(TAG, " ScanTime for UID " + uid.getUid() + ": Rx:" |
| 11149 | + scanRxTimeSinceMarkMs + " ms Tx:" |
| 11150 | + scanTxTimeSinceMarkMs + " ms)"); |
| 11151 | } |
| 11152 | |
| 11153 | ControllerActivityCounterImpl activityCounter = |
| 11154 | uid.getOrCreateWifiControllerActivityLocked(); |
| 11155 | activityCounter.getRxTimeCounter().addCountLocked(scanRxTimeSinceMarkMs); |
| 11156 | activityCounter.getTxTimeCounters()[0].addCountLocked( |
| 11157 | scanTxTimeSinceMarkMs); |
| 11158 | leftOverRxTimeMs -= scanRxTimeSinceMarkMs; |
| 11159 | leftOverTxTimeMs -= scanTxTimeSinceMarkMs; |
| 11160 | } |
| 11161 | |
| 11162 | // Distribute evenly the power consumed while Idle to each app holding a WiFi |
| 11163 | // lock. |
| 11164 | final long wifiLockTimeSinceMarkMs = |
| 11165 | uid.mFullWifiLockTimer.getTimeSinceMarkLocked( |
| 11166 | elapsedRealtimeMs * 1000) / 1000; |
| 11167 | if (wifiLockTimeSinceMarkMs > 0) { |
| 11168 | // Set the new mark so that next time we get new data since this point. |
| 11169 | uid.mFullWifiLockTimer.setMark(elapsedRealtimeMs); |
| 11170 | |
| 11171 | final long myIdleTimeMs = (wifiLockTimeSinceMarkMs * idleTimeMs) |
| 11172 | / totalWifiLockTimeMs; |
| 11173 | if (DEBUG_ENERGY) { |
| 11174 | Slog.d(TAG, " IdleTime for UID " + uid.getUid() + ": " |
| 11175 | + myIdleTimeMs + " ms"); |
| 11176 | } |
| 11177 | uid.getOrCreateWifiControllerActivityLocked().getIdleTimeCounter() |
| 11178 | .addCountLocked(myIdleTimeMs); |
| 11179 | } |
| 11180 | } |
| 11181 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 11182 | if (DEBUG_ENERGY) { |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11183 | Slog.d(TAG, " New RxPower: " + leftOverRxTimeMs + " ms"); |
| 11184 | Slog.d(TAG, " New TxPower: " + leftOverTxTimeMs + " ms"); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 11185 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 11186 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11187 | // Distribute the remaining Tx power appropriately between all apps that transmitted |
| 11188 | // packets. |
| 11189 | for (int i = 0; i < txPackets.size(); i++) { |
| 11190 | final Uid uid = getUidStatsLocked(txPackets.keyAt(i)); |
| 11191 | final long myTxTimeMs = (txPackets.valueAt(i) * leftOverTxTimeMs) |
| 11192 | / totalTxPackets; |
| 11193 | if (DEBUG_ENERGY) { |
| 11194 | Slog.d(TAG, " TxTime for UID " + uid.getUid() + ": " + myTxTimeMs + " ms"); |
| 11195 | } |
| 11196 | uid.getOrCreateWifiControllerActivityLocked().getTxTimeCounters()[0] |
| 11197 | .addCountLocked(myTxTimeMs); |
| 11198 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 11199 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11200 | // Distribute the remaining Rx power appropriately between all apps that received |
| 11201 | // packets. |
| 11202 | for (int i = 0; i < rxPackets.size(); i++) { |
| 11203 | final Uid uid = getUidStatsLocked(rxPackets.keyAt(i)); |
| 11204 | final long myRxTimeMs = (rxPackets.valueAt(i) * leftOverRxTimeMs) |
| 11205 | / totalRxPackets; |
| 11206 | if (DEBUG_ENERGY) { |
| 11207 | Slog.d(TAG, " RxTime for UID " + uid.getUid() + ": " + myRxTimeMs + " ms"); |
| 11208 | } |
| 11209 | uid.getOrCreateWifiControllerActivityLocked().getRxTimeCounter() |
| 11210 | .addCountLocked(myRxTimeMs); |
| 11211 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 11212 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11213 | // Any left over power use will be picked up by the WiFi category in BatteryStatsHelper. |
| 11214 | |
| 11215 | |
| 11216 | // Update WiFi controller stats. |
| 11217 | mWifiActivity.getRxTimeCounter().addCountLocked(info.getControllerRxTimeMillis()); |
| 11218 | mWifiActivity.getTxTimeCounters()[0].addCountLocked( |
| 11219 | info.getControllerTxTimeMillis()); |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 11220 | mWifiActivity.getScanTimeCounter().addCountLocked( |
| 11221 | info.getControllerScanTimeMillis()); |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11222 | mWifiActivity.getIdleTimeCounter().addCountLocked( |
| 11223 | info.getControllerIdleTimeMillis()); |
| 11224 | |
| 11225 | // POWER_WIFI_CONTROLLER_OPERATING_VOLTAGE is measured in mV, so convert to V. |
| 11226 | final double opVolt = mPowerProfile.getAveragePower( |
| 11227 | PowerProfile.POWER_WIFI_CONTROLLER_OPERATING_VOLTAGE) / 1000.0; |
| 11228 | if (opVolt != 0) { |
| 11229 | // We store the power drain as mAms. |
| 11230 | mWifiActivity.getPowerCounter().addCountLocked( |
| 11231 | (long) (info.getControllerEnergyUsed() / opVolt)); |
| 11232 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 11233 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11234 | } |
| 11235 | } |
| 11236 | |
Chenjie Yu | 8908339 | 2018-01-11 14:53:31 -0800 | [diff] [blame] | 11237 | private ModemActivityInfo mLastModemActivityInfo = |
| 11238 | new ModemActivityInfo(0, 0, 0, new int[0], 0, 0); |
| 11239 | |
Chenjie Yu | a54e54d | 2018-02-14 20:12:52 -0800 | [diff] [blame] | 11240 | private ModemActivityInfo getDeltaModemActivityInfo(ModemActivityInfo activityInfo) { |
| 11241 | if (activityInfo == null) { |
| 11242 | return null; |
| 11243 | } |
| 11244 | int[] txTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS]; |
| 11245 | for (int i = 0; i < ModemActivityInfo.TX_POWER_LEVELS; i++) { |
| 11246 | txTimeMs[i] = activityInfo.getTxTimeMillis()[i] |
| 11247 | - mLastModemActivityInfo.getTxTimeMillis()[i]; |
| 11248 | } |
| 11249 | ModemActivityInfo deltaInfo = new ModemActivityInfo(activityInfo.getTimestamp(), |
| 11250 | activityInfo.getSleepTimeMillis() - mLastModemActivityInfo.getSleepTimeMillis(), |
| 11251 | activityInfo.getIdleTimeMillis() - mLastModemActivityInfo.getIdleTimeMillis(), |
| 11252 | txTimeMs, |
| 11253 | activityInfo.getRxTimeMillis() - mLastModemActivityInfo.getRxTimeMillis(), |
| 11254 | activityInfo.getEnergyUsed() - mLastModemActivityInfo.getEnergyUsed()); |
| 11255 | mLastModemActivityInfo = activityInfo; |
| 11256 | return deltaInfo; |
| 11257 | } |
| 11258 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11259 | /** |
| 11260 | * Distribute Cell radio energy info and network traffic to apps. |
| 11261 | */ |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11262 | public void updateMobileRadioState(@Nullable final ModemActivityInfo activityInfo) { |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 11263 | if (DEBUG_ENERGY) { |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 11264 | Slog.d(TAG, "Updating mobile radio stats with " + activityInfo); |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 11265 | } |
Chenjie Yu | a54e54d | 2018-02-14 20:12:52 -0800 | [diff] [blame] | 11266 | ModemActivityInfo deltaInfo = getDeltaModemActivityInfo(activityInfo); |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 11267 | |
Siddharth Ray | f5e796a | 2018-01-22 18:18:17 -0800 | [diff] [blame] | 11268 | // Add modem tx power to history. |
Chenjie Yu | a54e54d | 2018-02-14 20:12:52 -0800 | [diff] [blame] | 11269 | addModemTxPowerToHistory(deltaInfo); |
Siddharth Ray | f5e796a | 2018-01-22 18:18:17 -0800 | [diff] [blame] | 11270 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11271 | // 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] | 11272 | NetworkStats delta = null; |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11273 | synchronized (mModemNetworkLock) { |
| 11274 | final NetworkStats latestStats = readNetworkStatsLocked(mModemIfaces); |
| 11275 | if (latestStats != null) { |
| 11276 | delta = NetworkStats.subtract(latestStats, mLastModemNetworkStats, null, null, |
| 11277 | mNetworkStatsPool.acquire()); |
| 11278 | mNetworkStatsPool.release(mLastModemNetworkStats); |
| 11279 | mLastModemNetworkStats = latestStats; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 11280 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11281 | } |
| 11282 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11283 | synchronized (this) { |
| 11284 | if (!mOnBatteryInternal) { |
| 11285 | if (delta != null) { |
| 11286 | mNetworkStatsPool.release(delta); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 11287 | } |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11288 | return; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 11289 | } |
| 11290 | |
Chenjie Yu | a54e54d | 2018-02-14 20:12:52 -0800 | [diff] [blame] | 11291 | if (deltaInfo != null) { |
Siddharth Ray | 2038af8 | 2018-01-17 17:40:26 -0800 | [diff] [blame] | 11292 | mHasModemReporting = true; |
| 11293 | mModemActivity.getIdleTimeCounter().addCountLocked( |
Chenjie Yu | a54e54d | 2018-02-14 20:12:52 -0800 | [diff] [blame] | 11294 | deltaInfo.getIdleTimeMillis()); |
Siddharth Ray | ed75470 | 2018-02-15 12:44:37 -0800 | [diff] [blame^] | 11295 | mModemActivity.getSleepTimeCounter().addCountLocked( |
| 11296 | deltaInfo.getSleepTimeMillis()); |
Chenjie Yu | a54e54d | 2018-02-14 20:12:52 -0800 | [diff] [blame] | 11297 | mModemActivity.getRxTimeCounter().addCountLocked(deltaInfo.getRxTimeMillis()); |
Siddharth Ray | 2038af8 | 2018-01-17 17:40:26 -0800 | [diff] [blame] | 11298 | for (int lvl = 0; lvl < ModemActivityInfo.TX_POWER_LEVELS; lvl++) { |
| 11299 | mModemActivity.getTxTimeCounters()[lvl] |
Chenjie Yu | a54e54d | 2018-02-14 20:12:52 -0800 | [diff] [blame] | 11300 | .addCountLocked(deltaInfo.getTxTimeMillis()[lvl]); |
Siddharth Ray | 2038af8 | 2018-01-17 17:40:26 -0800 | [diff] [blame] | 11301 | } |
| 11302 | |
| 11303 | // POWER_MODEM_CONTROLLER_OPERATING_VOLTAGE is measured in mV, so convert to V. |
| 11304 | final double opVolt = mPowerProfile.getAveragePower( |
| 11305 | PowerProfile.POWER_MODEM_CONTROLLER_OPERATING_VOLTAGE) / 1000.0; |
| 11306 | if (opVolt != 0) { |
| 11307 | double energyUsed = |
Chenjie Yu | a54e54d | 2018-02-14 20:12:52 -0800 | [diff] [blame] | 11308 | deltaInfo.getSleepTimeMillis() * |
Siddharth Ray | 2038af8 | 2018-01-17 17:40:26 -0800 | [diff] [blame] | 11309 | mPowerProfile.getAveragePower(PowerProfile.POWER_MODEM_CONTROLLER_SLEEP) |
Chenjie Yu | a54e54d | 2018-02-14 20:12:52 -0800 | [diff] [blame] | 11310 | + deltaInfo.getIdleTimeMillis() * |
Siddharth Ray | 2038af8 | 2018-01-17 17:40:26 -0800 | [diff] [blame] | 11311 | mPowerProfile.getAveragePower(PowerProfile.POWER_MODEM_CONTROLLER_IDLE) |
Chenjie Yu | a54e54d | 2018-02-14 20:12:52 -0800 | [diff] [blame] | 11312 | + deltaInfo.getRxTimeMillis() * |
Siddharth Ray | 2038af8 | 2018-01-17 17:40:26 -0800 | [diff] [blame] | 11313 | mPowerProfile.getAveragePower(PowerProfile.POWER_MODEM_CONTROLLER_RX); |
Chenjie Yu | a54e54d | 2018-02-14 20:12:52 -0800 | [diff] [blame] | 11314 | int[] txTimeMs = deltaInfo.getTxTimeMillis(); |
Chenjie Yu | 8908339 | 2018-01-11 14:53:31 -0800 | [diff] [blame] | 11315 | for (int i = 0; i < Math.min(txTimeMs.length, |
Chenjie Yu | a54e54d | 2018-02-14 20:12:52 -0800 | [diff] [blame] | 11316 | SignalStrength.NUM_SIGNAL_STRENGTH_BINS); i++) { |
Chenjie Yu | 8908339 | 2018-01-11 14:53:31 -0800 | [diff] [blame] | 11317 | energyUsed += txTimeMs[i] * mPowerProfile.getAveragePower( |
Chenjie Yu | a54e54d | 2018-02-14 20:12:52 -0800 | [diff] [blame] | 11318 | PowerProfile.POWER_MODEM_CONTROLLER_TX, i); |
Siddharth Ray | 2038af8 | 2018-01-17 17:40:26 -0800 | [diff] [blame] | 11319 | } |
| 11320 | |
| 11321 | // We store the power drain as mAms. |
| 11322 | mModemActivity.getPowerCounter().addCountLocked((long) energyUsed); |
| 11323 | } |
| 11324 | } |
| 11325 | |
Adam Lesinski | b3a1bad | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11326 | final long elapsedRealtimeMs = mClocks.elapsedRealtime(); |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11327 | long radioTime = mMobileRadioActivePerAppTimer.getTimeSinceMarkLocked( |
| 11328 | elapsedRealtimeMs * 1000); |
| 11329 | mMobileRadioActivePerAppTimer.setMark(elapsedRealtimeMs); |
| 11330 | |
| 11331 | long totalRxPackets = 0; |
| 11332 | long totalTxPackets = 0; |
| 11333 | if (delta != null) { |
| 11334 | NetworkStats.Entry entry = new NetworkStats.Entry(); |
| 11335 | final int size = delta.size(); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 11336 | for (int i = 0; i < size; i++) { |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11337 | entry = delta.getValues(i, entry); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 11338 | if (entry.rxPackets == 0 && entry.txPackets == 0) { |
| 11339 | continue; |
| 11340 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11341 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11342 | if (DEBUG_ENERGY) { |
| 11343 | Slog.d(TAG, "Mobile uid " + entry.uid + ": delta rx=" + entry.rxBytes |
| 11344 | + " tx=" + entry.txBytes + " rxPackets=" + entry.rxPackets |
| 11345 | + " txPackets=" + entry.txPackets); |
| 11346 | } |
| 11347 | |
| 11348 | totalRxPackets += entry.rxPackets; |
| 11349 | totalTxPackets += entry.txPackets; |
| 11350 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 11351 | final Uid u = getUidStatsLocked(mapUid(entry.uid)); |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11352 | u.noteNetworkActivityLocked(NETWORK_MOBILE_RX_DATA, entry.rxBytes, |
| 11353 | entry.rxPackets); |
| 11354 | u.noteNetworkActivityLocked(NETWORK_MOBILE_TX_DATA, entry.txBytes, |
| 11355 | entry.txPackets); |
| 11356 | if (entry.set == NetworkStats.SET_DEFAULT) { // Background transfers |
| 11357 | u.noteNetworkActivityLocked(NETWORK_MOBILE_BG_RX_DATA, |
| 11358 | entry.rxBytes, entry.rxPackets); |
| 11359 | u.noteNetworkActivityLocked(NETWORK_MOBILE_BG_TX_DATA, |
| 11360 | entry.txBytes, entry.txPackets); |
| 11361 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 11362 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11363 | mNetworkByteActivityCounters[NETWORK_MOBILE_RX_DATA].addCountLocked( |
| 11364 | entry.rxBytes); |
| 11365 | mNetworkByteActivityCounters[NETWORK_MOBILE_TX_DATA].addCountLocked( |
| 11366 | entry.txBytes); |
| 11367 | mNetworkPacketActivityCounters[NETWORK_MOBILE_RX_DATA].addCountLocked( |
| 11368 | entry.rxPackets); |
| 11369 | mNetworkPacketActivityCounters[NETWORK_MOBILE_TX_DATA].addCountLocked( |
| 11370 | entry.txPackets); |
| 11371 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 11372 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11373 | // Now distribute proportional blame to the apps that did networking. |
| 11374 | long totalPackets = totalRxPackets + totalTxPackets; |
| 11375 | if (totalPackets > 0) { |
| 11376 | for (int i = 0; i < size; i++) { |
| 11377 | entry = delta.getValues(i, entry); |
| 11378 | if (entry.rxPackets == 0 && entry.txPackets == 0) { |
| 11379 | continue; |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 11380 | } |
| 11381 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11382 | final Uid u = getUidStatsLocked(mapUid(entry.uid)); |
| 11383 | |
| 11384 | // Distribute total radio active time in to this app. |
| 11385 | final long appPackets = entry.rxPackets + entry.txPackets; |
| 11386 | final long appRadioTime = (radioTime * appPackets) / totalPackets; |
| 11387 | u.noteMobileRadioActiveTimeLocked(appRadioTime); |
| 11388 | |
| 11389 | // Remove this app from the totals, so that we don't lose any time |
| 11390 | // due to rounding. |
| 11391 | radioTime -= appRadioTime; |
| 11392 | totalPackets -= appPackets; |
| 11393 | |
Chenjie Yu | a54e54d | 2018-02-14 20:12:52 -0800 | [diff] [blame] | 11394 | if (deltaInfo != null) { |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11395 | ControllerActivityCounterImpl activityCounter = |
| 11396 | u.getOrCreateModemControllerActivityLocked(); |
| 11397 | if (totalRxPackets > 0 && entry.rxPackets > 0) { |
Chenjie Yu | a54e54d | 2018-02-14 20:12:52 -0800 | [diff] [blame] | 11398 | final long rxMs = (entry.rxPackets * deltaInfo.getRxTimeMillis()) |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11399 | / totalRxPackets; |
| 11400 | activityCounter.getRxTimeCounter().addCountLocked(rxMs); |
| 11401 | } |
| 11402 | |
| 11403 | if (totalTxPackets > 0 && entry.txPackets > 0) { |
| 11404 | for (int lvl = 0; lvl < ModemActivityInfo.TX_POWER_LEVELS; lvl++) { |
| 11405 | long txMs = |
Chenjie Yu | a54e54d | 2018-02-14 20:12:52 -0800 | [diff] [blame] | 11406 | entry.txPackets * deltaInfo.getTxTimeMillis()[lvl]; |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11407 | txMs /= totalTxPackets; |
| 11408 | activityCounter.getTxTimeCounters()[lvl].addCountLocked(txMs); |
| 11409 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 11410 | } |
| 11411 | } |
| 11412 | } |
| 11413 | } |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 11414 | |
| 11415 | if (radioTime > 0) { |
| 11416 | // Whoops, there is some radio time we can't blame on an app! |
| 11417 | mMobileRadioActiveUnknownTime.addCountLocked(radioTime); |
| 11418 | mMobileRadioActiveUnknownCount.addCountLocked(1); |
| 11419 | } |
| 11420 | |
| 11421 | mNetworkStatsPool.release(delta); |
| 11422 | delta = null; |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 11423 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11424 | } |
| 11425 | } |
| 11426 | |
Chenjie Yu | 8908339 | 2018-01-11 14:53:31 -0800 | [diff] [blame] | 11427 | // Cache last value for comparison. |
| 11428 | private BluetoothActivityEnergyInfo mLastBluetoothActivityEnergyInfo = |
| 11429 | new BluetoothActivityEnergyInfo(0, 0, 0, 0, 0, 0); |
| 11430 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11431 | /** |
Siddharth Ray | f5e796a | 2018-01-22 18:18:17 -0800 | [diff] [blame] | 11432 | * Add modem tx power to history |
| 11433 | * Device is said to be in high cellular transmit power when it has spent most of the transmit |
| 11434 | * time at the highest power level. |
| 11435 | * @param activityInfo |
| 11436 | */ |
| 11437 | private void addModemTxPowerToHistory(final ModemActivityInfo activityInfo) { |
| 11438 | if (activityInfo == null) { |
| 11439 | return; |
| 11440 | } |
| 11441 | int[] txTimeMs = activityInfo.getTxTimeMillis(); |
| 11442 | if (txTimeMs == null || txTimeMs.length != ModemActivityInfo.TX_POWER_LEVELS) { |
| 11443 | return; |
| 11444 | } |
| 11445 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 11446 | final long uptime = mClocks.uptimeMillis(); |
| 11447 | int levelMaxTimeSpent = 0; |
| 11448 | for (int i = 1; i < txTimeMs.length; i++) { |
| 11449 | if (txTimeMs[i] > txTimeMs[levelMaxTimeSpent]) { |
| 11450 | levelMaxTimeSpent = i; |
| 11451 | } |
| 11452 | } |
| 11453 | if (levelMaxTimeSpent == ModemActivityInfo.TX_POWER_LEVELS - 1) { |
| 11454 | if (!mIsCellularTxPowerHigh) { |
| 11455 | mHistoryCur.states2 |= HistoryItem.STATE2_CELLULAR_HIGH_TX_POWER_FLAG; |
| 11456 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 11457 | mIsCellularTxPowerHigh = true; |
| 11458 | } |
| 11459 | return; |
| 11460 | } |
| 11461 | if (mIsCellularTxPowerHigh) { |
| 11462 | mHistoryCur.states2 &= ~HistoryItem.STATE2_CELLULAR_HIGH_TX_POWER_FLAG; |
| 11463 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 11464 | mIsCellularTxPowerHigh = false; |
| 11465 | } |
| 11466 | return; |
| 11467 | } |
| 11468 | |
| 11469 | /** |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11470 | * Distribute Bluetooth energy info and network traffic to apps. |
| 11471 | * @param info The energy information from the bluetooth controller. |
| 11472 | */ |
| 11473 | public void updateBluetoothStateLocked(@Nullable final BluetoothActivityEnergyInfo info) { |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 11474 | if (DEBUG_ENERGY) { |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 11475 | Slog.d(TAG, "Updating bluetooth stats: " + info); |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 11476 | } |
| 11477 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 11478 | if (info == null || !mOnBatteryInternal) { |
| 11479 | return; |
| 11480 | } |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 11481 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 11482 | mHasBluetoothReporting = true; |
| 11483 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 11484 | final long elapsedRealtimeMs = mClocks.elapsedRealtime(); |
Chenjie Yu | 8908339 | 2018-01-11 14:53:31 -0800 | [diff] [blame] | 11485 | final long rxTimeMs = info.getControllerRxTimeMillis() - |
| 11486 | mLastBluetoothActivityEnergyInfo.getControllerRxTimeMillis(); |
| 11487 | final long txTimeMs = info.getControllerTxTimeMillis() - |
| 11488 | mLastBluetoothActivityEnergyInfo.getControllerTxTimeMillis(); |
| 11489 | final long idleTimeMs = info.getControllerIdleTimeMillis() - |
| 11490 | mLastBluetoothActivityEnergyInfo.getControllerIdleTimeMillis(); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 11491 | if (DEBUG_ENERGY) { |
| 11492 | Slog.d(TAG, "------ BEGIN BLE power blaming ------"); |
| 11493 | Slog.d(TAG, " Tx Time: " + txTimeMs + " ms"); |
| 11494 | Slog.d(TAG, " Rx Time: " + rxTimeMs + " ms"); |
Chenjie Yu | 8908339 | 2018-01-11 14:53:31 -0800 | [diff] [blame] | 11495 | Slog.d(TAG, " Idle Time: " + idleTimeMs + " ms"); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 11496 | } |
| 11497 | |
| 11498 | long totalScanTimeMs = 0; |
| 11499 | |
| 11500 | final int uidCount = mUidStats.size(); |
| 11501 | for (int i = 0; i < uidCount; i++) { |
| 11502 | final Uid u = mUidStats.valueAt(i); |
| 11503 | if (u.mBluetoothScanTimer == null) { |
| 11504 | continue; |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 11505 | } |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 11506 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 11507 | totalScanTimeMs += u.mBluetoothScanTimer.getTimeSinceMarkLocked( |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 11508 | elapsedRealtimeMs * 1000) / 1000; |
| 11509 | } |
| 11510 | |
| 11511 | final boolean normalizeScanRxTime = (totalScanTimeMs > rxTimeMs); |
| 11512 | final boolean normalizeScanTxTime = (totalScanTimeMs > txTimeMs); |
| 11513 | |
| 11514 | if (DEBUG_ENERGY) { |
| 11515 | Slog.d(TAG, "Normalizing scan power for RX=" + normalizeScanRxTime |
| 11516 | + " TX=" + normalizeScanTxTime); |
| 11517 | } |
| 11518 | |
| 11519 | long leftOverRxTimeMs = rxTimeMs; |
| 11520 | long leftOverTxTimeMs = txTimeMs; |
| 11521 | |
| 11522 | for (int i = 0; i < uidCount; i++) { |
| 11523 | final Uid u = mUidStats.valueAt(i); |
| 11524 | if (u.mBluetoothScanTimer == null) { |
| 11525 | continue; |
| 11526 | } |
| 11527 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 11528 | long scanTimeSinceMarkMs = u.mBluetoothScanTimer.getTimeSinceMarkLocked( |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 11529 | elapsedRealtimeMs * 1000) / 1000; |
| 11530 | if (scanTimeSinceMarkMs > 0) { |
| 11531 | // Set the new mark so that next time we get new data since this point. |
| 11532 | u.mBluetoothScanTimer.setMark(elapsedRealtimeMs); |
| 11533 | |
| 11534 | long scanTimeRxSinceMarkMs = scanTimeSinceMarkMs; |
| 11535 | long scanTimeTxSinceMarkMs = scanTimeSinceMarkMs; |
| 11536 | |
| 11537 | if (normalizeScanRxTime) { |
| 11538 | // Scan time is longer than the total rx time in the controller, |
| 11539 | // so distribute the scan time proportionately. This means regular traffic |
| 11540 | // will not blamed, but scans are more expensive anyways. |
| 11541 | scanTimeRxSinceMarkMs = (rxTimeMs * scanTimeRxSinceMarkMs) / totalScanTimeMs; |
| 11542 | } |
| 11543 | |
| 11544 | if (normalizeScanTxTime) { |
| 11545 | // Scan time is longer than the total tx time in the controller, |
| 11546 | // so distribute the scan time proportionately. This means regular traffic |
| 11547 | // will not blamed, but scans are more expensive anyways. |
| 11548 | scanTimeTxSinceMarkMs = (txTimeMs * scanTimeTxSinceMarkMs) / totalScanTimeMs; |
| 11549 | } |
| 11550 | |
| 11551 | final ControllerActivityCounterImpl counter = |
| 11552 | u.getOrCreateBluetoothControllerActivityLocked(); |
| 11553 | counter.getRxTimeCounter().addCountLocked(scanTimeRxSinceMarkMs); |
| 11554 | counter.getTxTimeCounters()[0].addCountLocked(scanTimeTxSinceMarkMs); |
| 11555 | |
| 11556 | leftOverRxTimeMs -= scanTimeRxSinceMarkMs; |
| 11557 | leftOverTxTimeMs -= scanTimeTxSinceMarkMs; |
| 11558 | } |
| 11559 | } |
| 11560 | |
| 11561 | if (DEBUG_ENERGY) { |
| 11562 | Slog.d(TAG, "Left over time for traffic RX=" + leftOverRxTimeMs |
| 11563 | + " TX=" + leftOverTxTimeMs); |
| 11564 | } |
| 11565 | |
| 11566 | // |
| 11567 | // Now distribute blame to apps that did bluetooth traffic. |
| 11568 | // |
| 11569 | |
| 11570 | long totalTxBytes = 0; |
| 11571 | long totalRxBytes = 0; |
| 11572 | |
| 11573 | final UidTraffic[] uidTraffic = info.getUidTraffic(); |
Chenjie Yu | 8908339 | 2018-01-11 14:53:31 -0800 | [diff] [blame] | 11574 | final UidTraffic[] lastUidTraffic = mLastBluetoothActivityEnergyInfo.getUidTraffic(); |
| 11575 | final ArrayList<UidTraffic> deltaTraffic = new ArrayList<>(); |
| 11576 | int m = 0, n = 0; |
| 11577 | for (; m < uidTraffic.length && n < lastUidTraffic.length; m++) { |
| 11578 | final UidTraffic traffic = uidTraffic[m]; |
| 11579 | final UidTraffic lastTraffic = lastUidTraffic[n]; |
| 11580 | if (traffic.getUid() == lastTraffic.getUid()) { |
| 11581 | deltaTraffic.add(new UidTraffic(traffic.getUid(), |
| 11582 | traffic.getRxBytes() - lastTraffic.getRxBytes(), |
| 11583 | traffic.getTxBytes() - lastTraffic.getTxBytes())); |
| 11584 | n++; |
| 11585 | } |
| 11586 | } |
| 11587 | for (; m < uidTraffic.length; m ++) { |
| 11588 | deltaTraffic.add(uidTraffic[m]); |
| 11589 | } |
| 11590 | |
| 11591 | for (int i = 0, j = 0; i < deltaTraffic.size(); i++) { |
| 11592 | final UidTraffic traffic = deltaTraffic.get(i); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 11593 | |
| 11594 | // Add to the global counters. |
| 11595 | mNetworkByteActivityCounters[NETWORK_BT_RX_DATA].addCountLocked( |
| 11596 | traffic.getRxBytes()); |
| 11597 | mNetworkByteActivityCounters[NETWORK_BT_TX_DATA].addCountLocked( |
| 11598 | traffic.getTxBytes()); |
| 11599 | |
| 11600 | // Add to the UID counters. |
| 11601 | final Uid u = getUidStatsLocked(mapUid(traffic.getUid())); |
| 11602 | u.noteNetworkActivityLocked(NETWORK_BT_RX_DATA, traffic.getRxBytes(), 0); |
| 11603 | u.noteNetworkActivityLocked(NETWORK_BT_TX_DATA, traffic.getTxBytes(), 0); |
| 11604 | |
| 11605 | // Calculate the total traffic. |
| 11606 | totalTxBytes += traffic.getTxBytes(); |
| 11607 | totalRxBytes += traffic.getRxBytes(); |
| 11608 | } |
| 11609 | |
| 11610 | if ((totalTxBytes != 0 || totalRxBytes != 0) && |
| 11611 | (leftOverRxTimeMs != 0 || leftOverTxTimeMs != 0)) { |
Chenjie Yu | 8908339 | 2018-01-11 14:53:31 -0800 | [diff] [blame] | 11612 | for (int i = 0; i < deltaTraffic.size(); i++) { |
| 11613 | final UidTraffic traffic = deltaTraffic.get(i); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 11614 | |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 11615 | final Uid u = getUidStatsLocked(mapUid(traffic.getUid())); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 11616 | final ControllerActivityCounterImpl counter = |
| 11617 | u.getOrCreateBluetoothControllerActivityLocked(); |
| 11618 | |
| 11619 | if (totalRxBytes > 0 && traffic.getRxBytes() > 0) { |
| 11620 | final long timeRxMs = (leftOverRxTimeMs * traffic.getRxBytes()) / totalRxBytes; |
| 11621 | |
| 11622 | if (DEBUG_ENERGY) { |
| 11623 | Slog.d(TAG, "UID=" + traffic.getUid() + " rx_bytes=" + traffic.getRxBytes() |
| 11624 | + " rx_time=" + timeRxMs); |
| 11625 | } |
| 11626 | counter.getRxTimeCounter().addCountLocked(timeRxMs); |
| 11627 | leftOverRxTimeMs -= timeRxMs; |
| 11628 | } |
| 11629 | |
| 11630 | if (totalTxBytes > 0 && traffic.getTxBytes() > 0) { |
| 11631 | final long timeTxMs = (leftOverTxTimeMs * traffic.getTxBytes()) / totalTxBytes; |
| 11632 | |
| 11633 | if (DEBUG_ENERGY) { |
| 11634 | Slog.d(TAG, "UID=" + traffic.getUid() + " tx_bytes=" + traffic.getTxBytes() |
| 11635 | + " tx_time=" + timeTxMs); |
| 11636 | } |
| 11637 | |
| 11638 | counter.getTxTimeCounters()[0].addCountLocked(timeTxMs); |
| 11639 | leftOverTxTimeMs -= timeTxMs; |
| 11640 | } |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 11641 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11642 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 11643 | |
Chenjie Yu | 8908339 | 2018-01-11 14:53:31 -0800 | [diff] [blame] | 11644 | mBluetoothActivity.getRxTimeCounter().addCountLocked(rxTimeMs); |
| 11645 | mBluetoothActivity.getTxTimeCounters()[0].addCountLocked(txTimeMs); |
| 11646 | mBluetoothActivity.getIdleTimeCounter().addCountLocked(idleTimeMs); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 11647 | |
| 11648 | // POWER_BLUETOOTH_CONTROLLER_OPERATING_VOLTAGE is measured in mV, so convert to V. |
| 11649 | final double opVolt = mPowerProfile.getAveragePower( |
| 11650 | PowerProfile.POWER_BLUETOOTH_CONTROLLER_OPERATING_VOLTAGE) / 1000.0; |
| 11651 | if (opVolt != 0) { |
| 11652 | // We store the power drain as mAms. |
| 11653 | mBluetoothActivity.getPowerCounter().addCountLocked( |
Chenjie Yu | 8908339 | 2018-01-11 14:53:31 -0800 | [diff] [blame] | 11654 | (long) ((info.getControllerEnergyUsed() - |
| 11655 | mLastBluetoothActivityEnergyInfo.getControllerEnergyUsed() )/ opVolt)); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 11656 | } |
Chenjie Yu | 8908339 | 2018-01-11 14:53:31 -0800 | [diff] [blame] | 11657 | mLastBluetoothActivityEnergyInfo = info; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11658 | } |
| 11659 | |
| 11660 | /** |
Bookatz | 0b8a050 | 2017-09-13 11:51:52 -0700 | [diff] [blame] | 11661 | * Read and record Resource Power Manager (RPM) state and voter times. |
| 11662 | * If RPM stats were fetched more recently than RPM_STATS_UPDATE_FREQ_MS ago, uses the old data |
| 11663 | * instead of fetching it anew. |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 11664 | */ |
| 11665 | public void updateRpmStatsLocked() { |
| 11666 | if (mPlatformIdleStateCallback == null) return; |
Bookatz | 0b8a050 | 2017-09-13 11:51:52 -0700 | [diff] [blame] | 11667 | long now = SystemClock.elapsedRealtime(); |
| 11668 | if (now - mLastRpmStatsUpdateTimeMs >= RPM_STATS_UPDATE_FREQ_MS) { |
| 11669 | mPlatformIdleStateCallback.fillLowPowerStats(mTmpRpmStats); |
| 11670 | mLastRpmStatsUpdateTimeMs = now; |
| 11671 | } |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 11672 | |
| 11673 | for (Map.Entry<String, RpmStats.PowerStatePlatformSleepState> pstate |
| 11674 | : mTmpRpmStats.mPlatformLowPowerStats.entrySet()) { |
| 11675 | |
| 11676 | // Update values for this platform state. |
| 11677 | final String pName = pstate.getKey(); |
| 11678 | final long pTimeUs = pstate.getValue().mTimeMs * 1000; |
| 11679 | final int pCount = pstate.getValue().mCount; |
| 11680 | getRpmTimerLocked(pName).update(pTimeUs, pCount); |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 11681 | if (SCREEN_OFF_RPM_STATS_ENABLED) { |
| 11682 | getScreenOffRpmTimerLocked(pName).update(pTimeUs, pCount); |
| 11683 | } |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 11684 | |
| 11685 | // Update values for each voter of this platform state. |
| 11686 | for (Map.Entry<String, RpmStats.PowerStateElement> voter |
| 11687 | : pstate.getValue().mVoters.entrySet()) { |
| 11688 | final String vName = pName + "." + voter.getKey(); |
| 11689 | final long vTimeUs = voter.getValue().mTimeMs * 1000; |
| 11690 | final int vCount = voter.getValue().mCount; |
| 11691 | getRpmTimerLocked(vName).update(vTimeUs, vCount); |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 11692 | if (SCREEN_OFF_RPM_STATS_ENABLED) { |
| 11693 | getScreenOffRpmTimerLocked(vName).update(vTimeUs, vCount); |
| 11694 | } |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 11695 | } |
| 11696 | } |
| 11697 | |
| 11698 | for (Map.Entry<String, RpmStats.PowerStateSubsystem> subsys |
| 11699 | : mTmpRpmStats.mSubsystemLowPowerStats.entrySet()) { |
| 11700 | |
| 11701 | final String subsysName = subsys.getKey(); |
| 11702 | for (Map.Entry<String, RpmStats.PowerStateElement> sstate |
| 11703 | : subsys.getValue().mStates.entrySet()) { |
| 11704 | final String name = subsysName + "." + sstate.getKey(); |
| 11705 | final long timeUs = sstate.getValue().mTimeMs * 1000; |
| 11706 | final int count = sstate.getValue().mCount; |
| 11707 | getRpmTimerLocked(name).update(timeUs, count); |
Bookatz | 82b34117 | 2017-09-07 19:06:08 -0700 | [diff] [blame] | 11708 | if (SCREEN_OFF_RPM_STATS_ENABLED) { |
| 11709 | getScreenOffRpmTimerLocked(name).update(timeUs, count); |
| 11710 | } |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 11711 | } |
| 11712 | } |
| 11713 | } |
| 11714 | |
| 11715 | /** |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11716 | * Read and distribute kernel wake lock use across apps. |
| 11717 | */ |
| 11718 | public void updateKernelWakelocksLocked() { |
| 11719 | final KernelWakelockStats wakelockStats = mKernelWakelockReader.readKernelWakelockStats( |
| 11720 | mTmpWakelockStats); |
| 11721 | if (wakelockStats == null) { |
| 11722 | // Not crashing might make board bringup easier. |
| 11723 | Slog.w(TAG, "Couldn't get kernel wake lock stats"); |
| 11724 | return; |
| 11725 | } |
| 11726 | |
| 11727 | for (Map.Entry<String, KernelWakelockStats.Entry> ent : wakelockStats.entrySet()) { |
| 11728 | String name = ent.getKey(); |
| 11729 | KernelWakelockStats.Entry kws = ent.getValue(); |
| 11730 | |
| 11731 | SamplingTimer kwlt = mKernelWakelockStats.get(name); |
| 11732 | if (kwlt == null) { |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 11733 | kwlt = new SamplingTimer(mClocks, mOnBatteryScreenOffTimeBase); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11734 | mKernelWakelockStats.put(name, kwlt); |
| 11735 | } |
Adam Lesinski | d84ad30 | 2016-05-17 18:31:02 -0700 | [diff] [blame] | 11736 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 11737 | kwlt.update(kws.mTotalTime, kws.mCount); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11738 | kwlt.setUpdateVersion(kws.mVersion); |
| 11739 | } |
| 11740 | |
Adam Lesinski | fbabe7d | 2015-08-03 14:37:38 -0700 | [diff] [blame] | 11741 | int numWakelocksSetStale = 0; |
Adam Lesinski | d84ad30 | 2016-05-17 18:31:02 -0700 | [diff] [blame] | 11742 | // Set timers to stale if they didn't appear in /d/wakeup_sources (or /proc/wakelocks) |
| 11743 | // this time. |
| 11744 | for (Map.Entry<String, SamplingTimer> ent : mKernelWakelockStats.entrySet()) { |
| 11745 | SamplingTimer st = ent.getValue(); |
| 11746 | if (st.getUpdateVersion() != wakelockStats.kernelWakelockVersion) { |
| 11747 | st.endSample(); |
| 11748 | numWakelocksSetStale++; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11749 | } |
| 11750 | } |
Adam Lesinski | fbabe7d | 2015-08-03 14:37:38 -0700 | [diff] [blame] | 11751 | |
Adam Lesinski | d84ad30 | 2016-05-17 18:31:02 -0700 | [diff] [blame] | 11752 | // Record whether we've seen a non-zero time (for debugging b/22716723). |
| 11753 | if (wakelockStats.isEmpty()) { |
Adam Lesinski | fbabe7d | 2015-08-03 14:37:38 -0700 | [diff] [blame] | 11754 | Slog.wtf(TAG, "All kernel wakelocks had time of zero"); |
| 11755 | } |
| 11756 | |
| 11757 | if (numWakelocksSetStale == mKernelWakelockStats.size()) { |
| 11758 | Slog.wtf(TAG, "All kernel wakelocks were set stale. new version=" + |
| 11759 | wakelockStats.kernelWakelockVersion); |
| 11760 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 11761 | } |
| 11762 | |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 11763 | // We use an anonymous class to access these variables, |
| 11764 | // so they can't live on the stack or they'd have to be |
| 11765 | // final MutableLong objects (more allocations). |
| 11766 | // Used in updateCpuTimeLocked(). |
| 11767 | long mTempTotalCpuUserTimeUs; |
| 11768 | long mTempTotalCpuSystemTimeUs; |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 11769 | long[][] mWakeLockAllocationsUs; |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 11770 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 11771 | /** |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 11772 | * Reads the newest memory stats from the kernel. |
| 11773 | */ |
| 11774 | public void updateKernelMemoryBandwidthLocked() { |
| 11775 | mKernelMemoryBandwidthStats.updateStats(); |
| 11776 | LongSparseLongArray bandwidthEntries = mKernelMemoryBandwidthStats.getBandwidthEntries(); |
| 11777 | final int bandwidthEntryCount = bandwidthEntries.size(); |
| 11778 | int index; |
| 11779 | for (int i = 0; i < bandwidthEntryCount; i++) { |
| 11780 | SamplingTimer timer; |
| 11781 | if ((index = mKernelMemoryStats.indexOfKey(bandwidthEntries.keyAt(i))) >= 0) { |
| 11782 | timer = mKernelMemoryStats.valueAt(index); |
| 11783 | } else { |
| 11784 | timer = new SamplingTimer(mClocks, mOnBatteryTimeBase); |
| 11785 | mKernelMemoryStats.put(bandwidthEntries.keyAt(i), timer); |
| 11786 | } |
| 11787 | timer.update(bandwidthEntries.valueAt(i), 1); |
| 11788 | if (DEBUG_MEMORY) { |
| 11789 | Slog.d(TAG, String.format("Added entry %d and updated timer to: " |
| 11790 | + "mUnpluggedReportedTotalTime %d size %d", bandwidthEntries.keyAt(i), |
| 11791 | mKernelMemoryStats.get( |
| 11792 | bandwidthEntries.keyAt(i)).mUnpluggedReportedTotalTime, |
| 11793 | mKernelMemoryStats.size())); |
| 11794 | } |
| 11795 | } |
| 11796 | } |
| 11797 | |
| 11798 | /** |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 11799 | * Read and distribute CPU usage across apps. If their are partial wakelocks being held |
| 11800 | * and we are on battery with screen off, we give more of the cpu time to those apps holding |
| 11801 | * wakelocks. If the screen is on, we just assign the actual cpu time an app used. |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 11802 | */ |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 11803 | public void updateCpuTimeLocked() { |
Adam Lesinski | 52290c9c | 2015-09-21 16:54:52 -0700 | [diff] [blame] | 11804 | if (mPowerProfile == null) { |
| 11805 | return; |
| 11806 | } |
| 11807 | |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 11808 | if (DEBUG_ENERGY_CPU) { |
| 11809 | Slog.d(TAG, "!Cpu updating!"); |
| 11810 | } |
| 11811 | |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 11812 | if (mCpuFreqs == null) { |
| 11813 | mCpuFreqs = mKernelUidCpuFreqTimeReader.readFreqs(mPowerProfile); |
| 11814 | } |
| 11815 | |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 11816 | // Calculate the wakelocks we have to distribute amongst. The system is excluded as it is |
| 11817 | // usually holding the wakelock on behalf of an app. |
| 11818 | // And Only distribute cpu power to wakelocks if the screen is off and we're on battery. |
| 11819 | ArrayList<StopwatchTimer> partialTimersToConsider = null; |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 11820 | if (mOnBatteryScreenOffTimeBase.isRunning()) { |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 11821 | partialTimersToConsider = new ArrayList<>(); |
| 11822 | for (int i = mPartialTimers.size() - 1; i >= 0; --i) { |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 11823 | final StopwatchTimer timer = mPartialTimers.get(i); |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 11824 | // Since the collection and blaming of wakelocks can be scheduled to run after |
| 11825 | // some delay, the mPartialTimers list may have new entries. We can't blame |
| 11826 | // the newly added timer for past cpu time, so we only consider timers that |
| 11827 | // were present for one round of collection. Once a timer has gone through |
| 11828 | // a round of collection, its mInList field is set to true. |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 11829 | if (timer.mInList && timer.mUid != null && timer.mUid.mUid != Process.SYSTEM_UID) { |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 11830 | partialTimersToConsider.add(timer); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 11831 | } |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 11832 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 11833 | } |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 11834 | markPartialTimersAsEligible(); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 11835 | |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 11836 | // When the battery is not on, we don't attribute the cpu times to any timers but we still |
| 11837 | // need to take the snapshots. |
| 11838 | if (!mOnBatteryInternal) { |
| 11839 | mKernelUidCpuTimeReader.readDelta(null); |
| 11840 | mKernelUidCpuFreqTimeReader.readDelta(null); |
Mike Ma | fae87da | 2018-01-19 20:07:20 -0800 | [diff] [blame] | 11841 | if (mConstants.TRACK_CPU_ACTIVE_CLUSTER_TIME) { |
| 11842 | mKernelUidCpuActiveTimeReader.readDelta(null); |
| 11843 | mKernelUidCpuClusterTimeReader.readDelta(null); |
| 11844 | } |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 11845 | for (int cluster = mKernelCpuSpeedReaders.length - 1; cluster >= 0; --cluster) { |
| 11846 | mKernelCpuSpeedReaders[cluster].readDelta(); |
| 11847 | } |
| 11848 | return; |
| 11849 | } |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 11850 | |
Suprabh Shukla | e6e723d | 2017-06-14 16:14:43 -0700 | [diff] [blame] | 11851 | mUserInfoProvider.refreshUserIds(); |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 11852 | final SparseLongArray updatedUids = mKernelUidCpuFreqTimeReader.perClusterTimesAvailable() |
| 11853 | ? null : new SparseLongArray(); |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 11854 | readKernelUidCpuTimesLocked(partialTimersToConsider, updatedUids); |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 11855 | // updatedUids=null means /proc/uid_time_in_state provides snapshots of per-cluster cpu |
| 11856 | // freqs, so no need to approximate these values. |
| 11857 | if (updatedUids != null) { |
| 11858 | updateClusterSpeedTimes(updatedUids); |
Sudheer Shanka | 671985f | 2017-05-19 11:33:42 -0700 | [diff] [blame] | 11859 | } |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 11860 | readKernelUidCpuFreqTimesLocked(partialTimersToConsider); |
Mike Ma | fae87da | 2018-01-19 20:07:20 -0800 | [diff] [blame] | 11861 | if (mConstants.TRACK_CPU_ACTIVE_CLUSTER_TIME) { |
| 11862 | readKernelUidCpuActiveTimesLocked(); |
| 11863 | readKernelUidCpuClusterTimesLocked(); |
| 11864 | } |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 11865 | } |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 11866 | |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 11867 | /** |
| 11868 | * Mark the current partial timers as gone through a collection so that they will be |
| 11869 | * considered in the next cpu times distribution to wakelock holders. |
| 11870 | */ |
| 11871 | @VisibleForTesting |
| 11872 | public void markPartialTimersAsEligible() { |
| 11873 | if (ArrayUtils.referenceEquals(mPartialTimers, mLastPartialTimers)) { |
| 11874 | // No difference, so each timer is now considered for the next collection. |
| 11875 | for (int i = mPartialTimers.size() - 1; i >= 0; --i) { |
| 11876 | mPartialTimers.get(i).mInList = true; |
| 11877 | } |
| 11878 | } else { |
| 11879 | // The lists are different, meaning we added (or removed a timer) since the last |
| 11880 | // collection. |
| 11881 | for (int i = mLastPartialTimers.size() - 1; i >= 0; --i) { |
| 11882 | mLastPartialTimers.get(i).mInList = false; |
| 11883 | } |
| 11884 | mLastPartialTimers.clear(); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 11885 | |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 11886 | // Mark the current timers as gone through a collection. |
| 11887 | final int numPartialTimers = mPartialTimers.size(); |
| 11888 | for (int i = 0; i < numPartialTimers; ++i) { |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 11889 | final StopwatchTimer timer = mPartialTimers.get(i); |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 11890 | timer.mInList = true; |
| 11891 | mLastPartialTimers.add(timer); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 11892 | } |
| 11893 | } |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 11894 | } |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 11895 | |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 11896 | /** |
| 11897 | * Take snapshot of cpu times (aggregated over all uids) at different frequencies and |
| 11898 | * calculate cpu times spent by each uid at different frequencies. |
| 11899 | * |
| 11900 | * @param updatedUids The uids for which times spent at different frequencies are calculated. |
| 11901 | */ |
| 11902 | @VisibleForTesting |
| 11903 | public void updateClusterSpeedTimes(@NonNull SparseLongArray updatedUids) { |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 11904 | long totalCpuClustersTimeMs = 0; |
Sudheer Shanka | 2fc52d4 | 2017-06-16 17:29:19 -0700 | [diff] [blame] | 11905 | // Read the time spent for each cluster at various cpu frequencies. |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 11906 | final long[][] clusterSpeedTimesMs = new long[mKernelCpuSpeedReaders.length][]; |
Sudheer Shanka | 2fc52d4 | 2017-06-16 17:29:19 -0700 | [diff] [blame] | 11907 | for (int cluster = 0; cluster < mKernelCpuSpeedReaders.length; cluster++) { |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 11908 | clusterSpeedTimesMs[cluster] = mKernelCpuSpeedReaders[cluster].readDelta(); |
| 11909 | if (clusterSpeedTimesMs[cluster] != null) { |
| 11910 | for (int speed = clusterSpeedTimesMs[cluster].length - 1; speed >= 0; --speed) { |
| 11911 | totalCpuClustersTimeMs += clusterSpeedTimesMs[cluster][speed]; |
Sudheer Shanka | 2fc52d4 | 2017-06-16 17:29:19 -0700 | [diff] [blame] | 11912 | } |
| 11913 | } |
| 11914 | } |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 11915 | if (totalCpuClustersTimeMs != 0) { |
Sudheer Shanka | 2fc52d4 | 2017-06-16 17:29:19 -0700 | [diff] [blame] | 11916 | // We have cpu times per freq aggregated over all uids but we need the times per uid. |
| 11917 | // So, we distribute total time spent by an uid to different cpu freqs based on the |
| 11918 | // amount of time cpu was running at that freq. |
| 11919 | final int updatedUidsCount = updatedUids.size(); |
| 11920 | for (int i = 0; i < updatedUidsCount; ++i) { |
| 11921 | final Uid u = getUidStatsLocked(updatedUids.keyAt(i)); |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 11922 | final long appCpuTimeUs = updatedUids.valueAt(i); |
Sudheer Shanka | 2fc52d4 | 2017-06-16 17:29:19 -0700 | [diff] [blame] | 11923 | // Add the cpu speeds to this UID. |
| 11924 | final int numClusters = mPowerProfile.getNumCpuClusters(); |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 11925 | if (u.mCpuClusterSpeedTimesUs == null || |
| 11926 | u.mCpuClusterSpeedTimesUs.length != numClusters) { |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 11927 | u.mCpuClusterSpeedTimesUs = new LongSamplingCounter[numClusters][]; |
Sudheer Shanka | 2fc52d4 | 2017-06-16 17:29:19 -0700 | [diff] [blame] | 11928 | } |
| 11929 | |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 11930 | for (int cluster = 0; cluster < clusterSpeedTimesMs.length; cluster++) { |
| 11931 | final int speedsInCluster = clusterSpeedTimesMs[cluster].length; |
| 11932 | if (u.mCpuClusterSpeedTimesUs[cluster] == null || speedsInCluster != |
| 11933 | u.mCpuClusterSpeedTimesUs[cluster].length) { |
| 11934 | u.mCpuClusterSpeedTimesUs[cluster] |
| 11935 | = new LongSamplingCounter[speedsInCluster]; |
Sudheer Shanka | 2fc52d4 | 2017-06-16 17:29:19 -0700 | [diff] [blame] | 11936 | } |
| 11937 | |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 11938 | final LongSamplingCounter[] cpuSpeeds = u.mCpuClusterSpeedTimesUs[cluster]; |
Sudheer Shanka | 2fc52d4 | 2017-06-16 17:29:19 -0700 | [diff] [blame] | 11939 | for (int speed = 0; speed < speedsInCluster; speed++) { |
| 11940 | if (cpuSpeeds[speed] == null) { |
| 11941 | cpuSpeeds[speed] = new LongSamplingCounter(mOnBatteryTimeBase); |
| 11942 | } |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 11943 | cpuSpeeds[speed].addCountLocked(appCpuTimeUs |
| 11944 | * clusterSpeedTimesMs[cluster][speed] |
| 11945 | / totalCpuClustersTimeMs); |
Sudheer Shanka | 2fc52d4 | 2017-06-16 17:29:19 -0700 | [diff] [blame] | 11946 | } |
| 11947 | } |
| 11948 | } |
| 11949 | } |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 11950 | } |
Sudheer Shanka | 2fc52d4 | 2017-06-16 17:29:19 -0700 | [diff] [blame] | 11951 | |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 11952 | /** |
| 11953 | * Take a snapshot of the cpu times spent by each uid and update the corresponding counters. |
| 11954 | * If {@param partialTimers} is not null and empty, then we assign a portion of cpu times to |
| 11955 | * wakelock holders. |
| 11956 | * |
| 11957 | * @param partialTimers The wakelock holders among which the cpu times will be distributed. |
| 11958 | * @param updatedUids If not null, then the uids found in the snapshot will be added to this. |
| 11959 | */ |
| 11960 | @VisibleForTesting |
| 11961 | public void readKernelUidCpuTimesLocked(@Nullable ArrayList<StopwatchTimer> partialTimers, |
| 11962 | @Nullable SparseLongArray updatedUids) { |
| 11963 | mTempTotalCpuUserTimeUs = mTempTotalCpuSystemTimeUs = 0; |
| 11964 | final int numWakelocks = partialTimers == null ? 0 : partialTimers.size(); |
| 11965 | final long startTimeMs = mClocks.uptimeMillis(); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 11966 | |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 11967 | mKernelUidCpuTimeReader.readDelta((uid, userTimeUs, systemTimeUs) -> { |
| 11968 | uid = mapUid(uid); |
| 11969 | if (Process.isIsolated(uid)) { |
| 11970 | // This could happen if the isolated uid mapping was removed before that process |
| 11971 | // was actually killed. |
| 11972 | mKernelUidCpuTimeReader.removeUid(uid); |
| 11973 | Slog.d(TAG, "Got readings for an isolated uid with no mapping: " + uid); |
| 11974 | return; |
| 11975 | } |
| 11976 | if (!mUserInfoProvider.exists(UserHandle.getUserId(uid))) { |
| 11977 | Slog.d(TAG, "Got readings for an invalid user's uid " + uid); |
| 11978 | mKernelUidCpuTimeReader.removeUid(uid); |
| 11979 | return; |
| 11980 | } |
| 11981 | final Uid u = getUidStatsLocked(uid); |
| 11982 | |
| 11983 | // Accumulate the total system and user time. |
| 11984 | mTempTotalCpuUserTimeUs += userTimeUs; |
| 11985 | mTempTotalCpuSystemTimeUs += systemTimeUs; |
| 11986 | |
| 11987 | StringBuilder sb = null; |
| 11988 | if (DEBUG_ENERGY_CPU) { |
| 11989 | sb = new StringBuilder(); |
| 11990 | sb.append(" got time for uid=").append(u.mUid).append(": u="); |
| 11991 | TimeUtils.formatDuration(userTimeUs / 1000, sb); |
| 11992 | sb.append(" s="); |
| 11993 | TimeUtils.formatDuration(systemTimeUs / 1000, sb); |
| 11994 | sb.append("\n"); |
| 11995 | } |
| 11996 | |
| 11997 | if (numWakelocks > 0) { |
| 11998 | // We have wakelocks being held, so only give a portion of the |
| 11999 | // time to the process. The rest will be distributed among wakelock |
| 12000 | // holders. |
| 12001 | userTimeUs = (userTimeUs * WAKE_LOCK_WEIGHT) / 100; |
| 12002 | systemTimeUs = (systemTimeUs * WAKE_LOCK_WEIGHT) / 100; |
| 12003 | } |
| 12004 | |
| 12005 | if (sb != null) { |
| 12006 | sb.append(" adding to uid=").append(u.mUid).append(": u="); |
| 12007 | TimeUtils.formatDuration(userTimeUs / 1000, sb); |
| 12008 | sb.append(" s="); |
| 12009 | TimeUtils.formatDuration(systemTimeUs / 1000, sb); |
| 12010 | Slog.d(TAG, sb.toString()); |
| 12011 | } |
| 12012 | |
| 12013 | u.mUserCpuTime.addCountLocked(userTimeUs); |
| 12014 | u.mSystemCpuTime.addCountLocked(systemTimeUs); |
| 12015 | if (updatedUids != null) { |
| 12016 | updatedUids.put(u.getUid(), userTimeUs + systemTimeUs); |
| 12017 | } |
| 12018 | }); |
| 12019 | |
| 12020 | final long elapsedTimeMs = mClocks.uptimeMillis() - startTimeMs; |
| 12021 | if (DEBUG_ENERGY_CPU || elapsedTimeMs >= 100) { |
| 12022 | Slog.d(TAG, "Reading cpu stats took " + elapsedTimeMs + "ms"); |
| 12023 | } |
| 12024 | |
| 12025 | if (numWakelocks > 0) { |
| 12026 | // Distribute a portion of the total cpu time to wakelock holders. |
| 12027 | mTempTotalCpuUserTimeUs = (mTempTotalCpuUserTimeUs * (100 - WAKE_LOCK_WEIGHT)) / 100; |
| 12028 | mTempTotalCpuSystemTimeUs = |
| 12029 | (mTempTotalCpuSystemTimeUs * (100 - WAKE_LOCK_WEIGHT)) / 100; |
| 12030 | |
| 12031 | for (int i = 0; i < numWakelocks; ++i) { |
| 12032 | final StopwatchTimer timer = partialTimers.get(i); |
| 12033 | final int userTimeUs = (int) (mTempTotalCpuUserTimeUs / (numWakelocks - i)); |
| 12034 | final int systemTimeUs = (int) (mTempTotalCpuSystemTimeUs / (numWakelocks - i)); |
| 12035 | |
| 12036 | if (DEBUG_ENERGY_CPU) { |
| 12037 | final StringBuilder sb = new StringBuilder(); |
| 12038 | sb.append(" Distributing wakelock uid=").append(timer.mUid.mUid) |
| 12039 | .append(": u="); |
| 12040 | TimeUtils.formatDuration(userTimeUs / 1000, sb); |
| 12041 | sb.append(" s="); |
| 12042 | TimeUtils.formatDuration(systemTimeUs / 1000, sb); |
| 12043 | Slog.d(TAG, sb.toString()); |
| 12044 | } |
| 12045 | |
| 12046 | timer.mUid.mUserCpuTime.addCountLocked(userTimeUs); |
| 12047 | timer.mUid.mSystemCpuTime.addCountLocked(systemTimeUs); |
| 12048 | if (updatedUids != null) { |
| 12049 | final int uid = timer.mUid.getUid(); |
| 12050 | updatedUids.put(uid, updatedUids.get(uid, 0) + userTimeUs + systemTimeUs); |
| 12051 | } |
| 12052 | |
| 12053 | final Uid.Proc proc = timer.mUid.getProcessStatsLocked("*wakelock*"); |
| 12054 | proc.addCpuTimeLocked(userTimeUs / 1000, systemTimeUs / 1000); |
| 12055 | |
| 12056 | mTempTotalCpuUserTimeUs -= userTimeUs; |
| 12057 | mTempTotalCpuSystemTimeUs -= systemTimeUs; |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 12058 | } |
| 12059 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 12060 | } |
| 12061 | |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 12062 | /** |
| 12063 | * Take a snapshot of the cpu times spent by each uid in each freq and update the |
| 12064 | * corresponding counters. |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 12065 | * |
| 12066 | * @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] | 12067 | */ |
| 12068 | @VisibleForTesting |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 12069 | public void readKernelUidCpuFreqTimesLocked(@Nullable ArrayList<StopwatchTimer> partialTimers) { |
| 12070 | final boolean perClusterTimesAvailable = |
| 12071 | mKernelUidCpuFreqTimeReader.perClusterTimesAvailable(); |
| 12072 | final int numWakelocks = partialTimers == null ? 0 : partialTimers.size(); |
| 12073 | final int numClusters = mPowerProfile.getNumCpuClusters(); |
| 12074 | mWakeLockAllocationsUs = null; |
Sudheer Shanka | ac5b88f | 2017-12-11 15:36:35 -0800 | [diff] [blame] | 12075 | final long startTimeMs = mClocks.uptimeMillis(); |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 12076 | mKernelUidCpuFreqTimeReader.readDelta((uid, cpuFreqTimeMs) -> { |
| 12077 | uid = mapUid(uid); |
| 12078 | if (Process.isIsolated(uid)) { |
| 12079 | mKernelUidCpuFreqTimeReader.removeUid(uid); |
| 12080 | Slog.d(TAG, "Got freq readings for an isolated uid with no mapping: " + uid); |
| 12081 | return; |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 12082 | } |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 12083 | if (!mUserInfoProvider.exists(UserHandle.getUserId(uid))) { |
| 12084 | Slog.d(TAG, "Got freq readings for an invalid user's uid " + uid); |
| 12085 | mKernelUidCpuFreqTimeReader.removeUid(uid); |
| 12086 | return; |
| 12087 | } |
| 12088 | final Uid u = getUidStatsLocked(uid); |
| 12089 | if (u.mCpuFreqTimeMs == null || u.mCpuFreqTimeMs.getSize() != cpuFreqTimeMs.length) { |
| 12090 | u.mCpuFreqTimeMs = new LongSamplingCounterArray(mOnBatteryTimeBase); |
| 12091 | } |
| 12092 | u.mCpuFreqTimeMs.addCountLocked(cpuFreqTimeMs); |
| 12093 | if (u.mScreenOffCpuFreqTimeMs == null || |
| 12094 | u.mScreenOffCpuFreqTimeMs.getSize() != cpuFreqTimeMs.length) { |
| 12095 | u.mScreenOffCpuFreqTimeMs = new LongSamplingCounterArray( |
| 12096 | mOnBatteryScreenOffTimeBase); |
| 12097 | } |
| 12098 | u.mScreenOffCpuFreqTimeMs.addCountLocked(cpuFreqTimeMs); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 12099 | |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 12100 | if (perClusterTimesAvailable) { |
| 12101 | if (u.mCpuClusterSpeedTimesUs == null || |
| 12102 | u.mCpuClusterSpeedTimesUs.length != numClusters) { |
| 12103 | u.mCpuClusterSpeedTimesUs = new LongSamplingCounter[numClusters][]; |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 12104 | } |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 12105 | if (numWakelocks > 0 && mWakeLockAllocationsUs == null) { |
| 12106 | mWakeLockAllocationsUs = new long[numClusters][]; |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 12107 | } |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 12108 | |
| 12109 | int freqIndex = 0; |
| 12110 | for (int cluster = 0; cluster < numClusters; ++cluster) { |
| 12111 | final int speedsInCluster = mPowerProfile.getNumSpeedStepsInCpuCluster(cluster); |
| 12112 | if (u.mCpuClusterSpeedTimesUs[cluster] == null || |
| 12113 | u.mCpuClusterSpeedTimesUs[cluster].length != speedsInCluster) { |
| 12114 | u.mCpuClusterSpeedTimesUs[cluster] |
| 12115 | = new LongSamplingCounter[speedsInCluster]; |
| 12116 | } |
| 12117 | if (numWakelocks > 0 && mWakeLockAllocationsUs[cluster] == null) { |
| 12118 | mWakeLockAllocationsUs[cluster] = new long[speedsInCluster]; |
| 12119 | } |
| 12120 | final LongSamplingCounter[] cpuTimesUs = u.mCpuClusterSpeedTimesUs[cluster]; |
| 12121 | for (int speed = 0; speed < speedsInCluster; ++speed) { |
| 12122 | if (cpuTimesUs[speed] == null) { |
| 12123 | cpuTimesUs[speed] = new LongSamplingCounter(mOnBatteryTimeBase); |
| 12124 | } |
| 12125 | final long appAllocationUs; |
| 12126 | if (mWakeLockAllocationsUs != null) { |
| 12127 | appAllocationUs = |
| 12128 | (cpuFreqTimeMs[freqIndex] * 1000 * WAKE_LOCK_WEIGHT) / 100; |
| 12129 | mWakeLockAllocationsUs[cluster][speed] += |
| 12130 | (cpuFreqTimeMs[freqIndex] * 1000 - appAllocationUs); |
| 12131 | } else { |
| 12132 | appAllocationUs = cpuFreqTimeMs[freqIndex] * 1000; |
| 12133 | } |
| 12134 | cpuTimesUs[speed].addCountLocked(appAllocationUs); |
| 12135 | freqIndex++; |
| 12136 | } |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 12137 | } |
Sudheer Shanka | 3838323 | 2017-07-25 09:55:03 -0700 | [diff] [blame] | 12138 | } |
| 12139 | }); |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 12140 | |
Sudheer Shanka | ac5b88f | 2017-12-11 15:36:35 -0800 | [diff] [blame] | 12141 | final long elapsedTimeMs = mClocks.uptimeMillis() - startTimeMs; |
| 12142 | if (DEBUG_ENERGY_CPU || elapsedTimeMs >= 100) { |
| 12143 | Slog.d(TAG, "Reading cpu freq times took " + elapsedTimeMs + "ms"); |
| 12144 | } |
| 12145 | |
Sudheer Shanka | b8ad594 | 2017-08-08 12:16:09 -0700 | [diff] [blame] | 12146 | if (mWakeLockAllocationsUs != null) { |
| 12147 | for (int i = 0; i < numWakelocks; ++i) { |
| 12148 | final Uid u = partialTimers.get(i).mUid; |
| 12149 | if (u.mCpuClusterSpeedTimesUs == null || |
| 12150 | u.mCpuClusterSpeedTimesUs.length != numClusters) { |
| 12151 | u.mCpuClusterSpeedTimesUs = new LongSamplingCounter[numClusters][]; |
| 12152 | } |
| 12153 | |
| 12154 | for (int cluster = 0; cluster < numClusters; ++cluster) { |
| 12155 | final int speedsInCluster = mPowerProfile.getNumSpeedStepsInCpuCluster(cluster); |
| 12156 | if (u.mCpuClusterSpeedTimesUs[cluster] == null || |
| 12157 | u.mCpuClusterSpeedTimesUs[cluster].length != speedsInCluster) { |
| 12158 | u.mCpuClusterSpeedTimesUs[cluster] |
| 12159 | = new LongSamplingCounter[speedsInCluster]; |
| 12160 | } |
| 12161 | final LongSamplingCounter[] cpuTimeUs = u.mCpuClusterSpeedTimesUs[cluster]; |
| 12162 | for (int speed = 0; speed < speedsInCluster; ++speed) { |
| 12163 | if (cpuTimeUs[speed] == null) { |
| 12164 | cpuTimeUs[speed] = new LongSamplingCounter(mOnBatteryTimeBase); |
| 12165 | } |
| 12166 | final long allocationUs = |
| 12167 | mWakeLockAllocationsUs[cluster][speed] / (numWakelocks - i); |
| 12168 | cpuTimeUs[speed].addCountLocked(allocationUs); |
| 12169 | mWakeLockAllocationsUs[cluster][speed] -= allocationUs; |
| 12170 | } |
| 12171 | } |
| 12172 | } |
| 12173 | } |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 12174 | } |
| 12175 | |
Mike Ma | 3d422c3 | 2017-10-25 11:08:57 -0700 | [diff] [blame] | 12176 | /** |
| 12177 | * Take a snapshot of the cpu active times spent by each uid and update the corresponding |
| 12178 | * counters. |
| 12179 | */ |
| 12180 | @VisibleForTesting |
| 12181 | public void readKernelUidCpuActiveTimesLocked() { |
| 12182 | final long startTimeMs = mClocks.uptimeMillis(); |
| 12183 | mKernelUidCpuActiveTimeReader.readDelta((uid, cpuActiveTimesUs) -> { |
| 12184 | uid = mapUid(uid); |
| 12185 | if (Process.isIsolated(uid)) { |
| 12186 | mKernelUidCpuActiveTimeReader.removeUid(uid); |
| 12187 | Slog.w(TAG, "Got active times for an isolated uid with no mapping: " + uid); |
| 12188 | return; |
| 12189 | } |
| 12190 | if (!mUserInfoProvider.exists(UserHandle.getUserId(uid))) { |
| 12191 | Slog.w(TAG, "Got active times for an invalid user's uid " + uid); |
| 12192 | mKernelUidCpuActiveTimeReader.removeUid(uid); |
| 12193 | return; |
| 12194 | } |
| 12195 | final Uid u = getUidStatsLocked(uid); |
| 12196 | u.mCpuActiveTimeMs.addCountLocked(cpuActiveTimesUs); |
| 12197 | }); |
| 12198 | |
| 12199 | final long elapsedTimeMs = mClocks.uptimeMillis() - startTimeMs; |
| 12200 | if (DEBUG_ENERGY_CPU || elapsedTimeMs >= 100) { |
| 12201 | Slog.d(TAG, "Reading cpu active times took " + elapsedTimeMs + "ms"); |
| 12202 | } |
| 12203 | } |
| 12204 | |
| 12205 | /** |
| 12206 | * Take a snapshot of the cpu cluster times spent by each uid and update the corresponding |
| 12207 | * counters. |
| 12208 | */ |
| 12209 | @VisibleForTesting |
| 12210 | public void readKernelUidCpuClusterTimesLocked() { |
| 12211 | final long startTimeMs = mClocks.uptimeMillis(); |
| 12212 | mKernelUidCpuClusterTimeReader.readDelta((uid, cpuClusterTimesUs) -> { |
| 12213 | uid = mapUid(uid); |
| 12214 | if (Process.isIsolated(uid)) { |
| 12215 | mKernelUidCpuClusterTimeReader.removeUid(uid); |
| 12216 | Slog.w(TAG, "Got cluster times for an isolated uid with no mapping: " + uid); |
| 12217 | return; |
| 12218 | } |
| 12219 | if (!mUserInfoProvider.exists(UserHandle.getUserId(uid))) { |
| 12220 | Slog.w(TAG, "Got cluster times for an invalid user's uid " + uid); |
| 12221 | mKernelUidCpuClusterTimeReader.removeUid(uid); |
| 12222 | return; |
| 12223 | } |
| 12224 | final Uid u = getUidStatsLocked(uid); |
| 12225 | u.mCpuClusterTimesMs.addCountLocked(cpuClusterTimesUs); |
| 12226 | }); |
| 12227 | |
| 12228 | final long elapsedTimeMs = mClocks.uptimeMillis() - startTimeMs; |
| 12229 | if (DEBUG_ENERGY_CPU || elapsedTimeMs >= 100) { |
| 12230 | Slog.d(TAG, "Reading cpu cluster times took " + elapsedTimeMs + "ms"); |
| 12231 | } |
| 12232 | } |
| 12233 | |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 12234 | boolean setChargingLocked(boolean charging) { |
| 12235 | if (mCharging != charging) { |
| 12236 | mCharging = charging; |
| 12237 | if (charging) { |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 12238 | mHistoryCur.states2 |= HistoryItem.STATE2_CHARGING_FLAG; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 12239 | } else { |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 12240 | mHistoryCur.states2 &= ~HistoryItem.STATE2_CHARGING_FLAG; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 12241 | } |
| 12242 | mHandler.sendEmptyMessage(MSG_REPORT_CHARGING); |
| 12243 | return true; |
| 12244 | } |
| 12245 | return false; |
| 12246 | } |
| 12247 | |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 12248 | protected void setOnBatteryLocked(final long mSecRealtime, final long mSecUptime, |
| 12249 | final boolean onBattery, final int oldStatus, final int level, final int chargeUAh) { |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 12250 | boolean doWrite = false; |
| 12251 | Message m = mHandler.obtainMessage(MSG_REPORT_POWER_CHANGE); |
| 12252 | m.arg1 = onBattery ? 1 : 0; |
| 12253 | mHandler.sendMessage(m); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 12254 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 12255 | final long uptime = mSecUptime * 1000; |
| 12256 | final long realtime = mSecRealtime * 1000; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 12257 | final int screenState = mScreenState; |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 12258 | if (onBattery) { |
| 12259 | // We will reset our status if we are unplugging after the |
| 12260 | // battery was last full, or the level is at 100, or |
| 12261 | // we have gone through a significant charge (from a very low |
| 12262 | // level to a now very high level). |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 12263 | boolean reset = false; |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 12264 | if (!mNoAutoReset && (oldStatus == BatteryManager.BATTERY_STATUS_FULL |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 12265 | || level >= 90 |
Dianne Hackborn | fb3809c | 2014-09-29 18:31:22 -0700 | [diff] [blame] | 12266 | || (mDischargeCurrentLevel < 20 && level >= 80) |
| 12267 | || (getHighDischargeAmountSinceCharge() >= 200 |
| 12268 | && mHistoryBuffer.dataSize() >= MAX_HISTORY_BUFFER))) { |
Dianne Hackborn | 73d6a82 | 2014-09-29 10:52:47 -0700 | [diff] [blame] | 12269 | Slog.i(TAG, "Resetting battery stats: level=" + level + " status=" + oldStatus |
Dianne Hackborn | fb3809c | 2014-09-29 18:31:22 -0700 | [diff] [blame] | 12270 | + " dischargeLevel=" + mDischargeCurrentLevel |
Dianne Hackborn | 73d6a82 | 2014-09-29 10:52:47 -0700 | [diff] [blame] | 12271 | + " lowAmount=" + getLowDischargeAmountSinceCharge() |
| 12272 | + " highAmount=" + getHighDischargeAmountSinceCharge()); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 12273 | // Before we write, collect a snapshot of the final aggregated |
| 12274 | // stats to be reported in the next checkin. Only do this if we have |
| 12275 | // a sufficient amount of data to make it interesting. |
| 12276 | if (getLowDischargeAmountSinceCharge() >= 20) { |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 12277 | final long startTime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 12278 | final Parcel parcel = Parcel.obtain(); |
| 12279 | writeSummaryToParcel(parcel, true); |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 12280 | final long initialTime = SystemClock.uptimeMillis() - startTime; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 12281 | BackgroundThread.getHandler().post(new Runnable() { |
| 12282 | @Override public void run() { |
| 12283 | synchronized (mCheckinFile) { |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 12284 | final long startTime2 = SystemClock.uptimeMillis(); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 12285 | FileOutputStream stream = null; |
| 12286 | try { |
| 12287 | stream = mCheckinFile.startWrite(); |
| 12288 | stream.write(parcel.marshall()); |
| 12289 | stream.flush(); |
| 12290 | FileUtils.sync(stream); |
| 12291 | stream.close(); |
| 12292 | mCheckinFile.finishWrite(stream); |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 12293 | com.android.internal.logging.EventLogTags.writeCommitSysConfigFile( |
| 12294 | "batterystats-checkin", |
| 12295 | initialTime + SystemClock.uptimeMillis() - startTime2); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 12296 | } catch (IOException e) { |
| 12297 | Slog.w("BatteryStats", |
| 12298 | "Error writing checkin battery statistics", e); |
| 12299 | mCheckinFile.failWrite(stream); |
| 12300 | } finally { |
| 12301 | parcel.recycle(); |
| 12302 | } |
| 12303 | } |
| 12304 | } |
| 12305 | }); |
| 12306 | } |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 12307 | doWrite = true; |
| 12308 | resetAllStatsLocked(); |
Ying Wai (Daniel) Fan | 442ab76 | 2017-01-31 22:00:10 -0800 | [diff] [blame] | 12309 | if (chargeUAh > 0 && level > 0) { |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 12310 | // 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] | 12311 | mEstimatedBatteryCapacity = (int) ((chargeUAh / 1000) / (level / 100.0)); |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 12312 | } |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 12313 | mDischargeStartLevel = level; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 12314 | reset = true; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 12315 | mDischargeStepTracker.init(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 12316 | } |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 12317 | if (mCharging) { |
| 12318 | setChargingLocked(false); |
| 12319 | } |
| 12320 | mLastChargingStateLevel = level; |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 12321 | mOnBattery = mOnBatteryInternal = true; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 12322 | mLastDischargeStepLevel = level; |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 12323 | mMinDischargeStepLevel = level; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 12324 | mDischargeStepTracker.clearTime(); |
| 12325 | mDailyDischargeStepTracker.clearTime(); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 12326 | mInitStepMode = mCurStepMode; |
| 12327 | mModStepMode = 0; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 12328 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 12329 | mHistoryCur.batteryLevel = (byte)level; |
| 12330 | mHistoryCur.states &= ~HistoryItem.STATE_BATTERY_PLUGGED_FLAG; |
| 12331 | if (DEBUG_HISTORY) Slog.v(TAG, "Battery unplugged to: " |
| 12332 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 12333 | if (reset) { |
| 12334 | mRecordingHistory = true; |
| 12335 | startRecordingHistory(mSecRealtime, mSecUptime, reset); |
| 12336 | } |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 12337 | addHistoryRecordLocked(mSecRealtime, mSecUptime); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 12338 | mDischargeCurrentLevel = mDischargeUnplugLevel = level; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 12339 | if (isScreenOn(screenState)) { |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 12340 | mDischargeScreenOnUnplugLevel = level; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 12341 | mDischargeScreenDozeUnplugLevel = 0; |
| 12342 | mDischargeScreenOffUnplugLevel = 0; |
| 12343 | } else if (isScreenDoze(screenState)) { |
| 12344 | mDischargeScreenOnUnplugLevel = 0; |
| 12345 | mDischargeScreenDozeUnplugLevel = level; |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 12346 | mDischargeScreenOffUnplugLevel = 0; |
| 12347 | } else { |
| 12348 | mDischargeScreenOnUnplugLevel = 0; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 12349 | mDischargeScreenDozeUnplugLevel = 0; |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 12350 | mDischargeScreenOffUnplugLevel = level; |
| 12351 | } |
| 12352 | mDischargeAmountScreenOn = 0; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 12353 | mDischargeAmountScreenDoze = 0; |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 12354 | mDischargeAmountScreenOff = 0; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 12355 | updateTimeBasesLocked(true, screenState, uptime, realtime); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 12356 | } else { |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 12357 | mLastChargingStateLevel = level; |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 12358 | mOnBattery = mOnBatteryInternal = false; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 12359 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 12360 | mHistoryCur.batteryLevel = (byte)level; |
| 12361 | mHistoryCur.states |= HistoryItem.STATE_BATTERY_PLUGGED_FLAG; |
| 12362 | if (DEBUG_HISTORY) Slog.v(TAG, "Battery plugged to: " |
| 12363 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 12364 | addHistoryRecordLocked(mSecRealtime, mSecUptime); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 12365 | mDischargeCurrentLevel = mDischargePlugLevel = level; |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 12366 | if (level < mDischargeUnplugLevel) { |
| 12367 | mLowDischargeAmountSinceCharge += mDischargeUnplugLevel-level-1; |
| 12368 | mHighDischargeAmountSinceCharge += mDischargeUnplugLevel-level; |
| 12369 | } |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 12370 | updateDischargeScreenLevelsLocked(screenState, screenState); |
| 12371 | updateTimeBasesLocked(false, screenState, uptime, realtime); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 12372 | mChargeStepTracker.init(); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 12373 | mLastChargeStepLevel = level; |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 12374 | mMaxChargeStepLevel = level; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 12375 | mInitStepMode = mCurStepMode; |
| 12376 | mModStepMode = 0; |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 12377 | } |
| 12378 | if (doWrite || (mLastWriteTime + (60 * 1000)) < mSecRealtime) { |
| 12379 | if (mFile != null) { |
| 12380 | writeAsyncLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12381 | } |
| 12382 | } |
| 12383 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 12384 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 12385 | private void startRecordingHistory(final long elapsedRealtimeMs, final long uptimeMs, |
| 12386 | boolean reset) { |
| 12387 | mRecordingHistory = true; |
| 12388 | mHistoryCur.currentTime = System.currentTimeMillis(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 12389 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, |
| 12390 | reset ? HistoryItem.CMD_RESET : HistoryItem.CMD_CURRENT_TIME, |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 12391 | mHistoryCur); |
| 12392 | mHistoryCur.currentTime = 0; |
| 12393 | if (reset) { |
| 12394 | initActiveHistoryEventsLocked(elapsedRealtimeMs, uptimeMs); |
| 12395 | } |
| 12396 | } |
| 12397 | |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 12398 | private void recordCurrentTimeChangeLocked(final long currentTime, final long elapsedRealtimeMs, |
| 12399 | final long uptimeMs) { |
| 12400 | if (mRecordingHistory) { |
| 12401 | mHistoryCur.currentTime = currentTime; |
| 12402 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_CURRENT_TIME, |
| 12403 | mHistoryCur); |
| 12404 | mHistoryCur.currentTime = 0; |
| 12405 | } |
| 12406 | } |
| 12407 | |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 12408 | private void recordShutdownLocked(final long elapsedRealtimeMs, final long uptimeMs) { |
| 12409 | if (mRecordingHistory) { |
| 12410 | mHistoryCur.currentTime = System.currentTimeMillis(); |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 12411 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_SHUTDOWN, |
| 12412 | mHistoryCur); |
| 12413 | mHistoryCur.currentTime = 0; |
| 12414 | } |
| 12415 | } |
| 12416 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 12417 | private void scheduleSyncExternalStatsLocked(String reason, int updateFlags) { |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 12418 | if (mExternalSync != null) { |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 12419 | mExternalSync.scheduleSync(reason, updateFlags); |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 12420 | } |
| 12421 | } |
| 12422 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 12423 | // This should probably be exposed in the API, though it's not critical |
Bookatz | 1a1b046 | 2018-01-12 11:47:03 -0800 | [diff] [blame] | 12424 | public static final int BATTERY_PLUGGED_NONE = OsProtoEnums.BATTERY_PLUGGED_NONE; // = 0 |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 12425 | |
Bookatz | 8c6571b | 2017-10-24 15:04:41 -0700 | [diff] [blame] | 12426 | public void setBatteryStateLocked(final int status, final int health, final int plugType, |
| 12427 | final int level, /* not final */ int temp, final int volt, final int chargeUAh, |
| 12428 | final int chargeFullUAh) { |
Adam Lesinski | 29ddfe5 | 2017-03-29 19:29:00 -0700 | [diff] [blame] | 12429 | // Temperature is encoded without the signed bit, so clamp any negative temperatures to 0. |
| 12430 | temp = Math.max(0, temp); |
| 12431 | |
Bookatz | 8c6571b | 2017-10-24 15:04:41 -0700 | [diff] [blame] | 12432 | reportChangesToStatsLog(mHaveBatteryLevel ? mHistoryCur : null, |
| 12433 | status, plugType, level, temp); |
| 12434 | |
Todd Poynor | 1acf06a | 2017-12-07 19:19:35 -0800 | [diff] [blame] | 12435 | final boolean onBattery = |
| 12436 | plugType == BATTERY_PLUGGED_NONE && |
| 12437 | status != BatteryManager.BATTERY_STATUS_UNKNOWN; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 12438 | final long uptime = mClocks.uptimeMillis(); |
| 12439 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 12440 | if (!mHaveBatteryLevel) { |
| 12441 | mHaveBatteryLevel = true; |
| 12442 | // We start out assuming that the device is plugged in (not |
| 12443 | // on battery). If our first report is now that we are indeed |
| 12444 | // plugged in, then twiddle our state to correctly reflect that |
| 12445 | // since we won't be going through the full setOnBattery(). |
| 12446 | if (onBattery == mOnBattery) { |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 12447 | if (onBattery) { |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 12448 | mHistoryCur.states &= ~HistoryItem.STATE_BATTERY_PLUGGED_FLAG; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 12449 | } else { |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 12450 | mHistoryCur.states |= HistoryItem.STATE_BATTERY_PLUGGED_FLAG; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 12451 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 12452 | } |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 12453 | // Always start out assuming charging, that will be updated later. |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 12454 | mHistoryCur.states2 |= HistoryItem.STATE2_CHARGING_FLAG; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 12455 | mHistoryCur.batteryStatus = (byte)status; |
| 12456 | mHistoryCur.batteryLevel = (byte)level; |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 12457 | mHistoryCur.batteryChargeUAh = chargeUAh; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 12458 | mMaxChargeStepLevel = mMinDischargeStepLevel = |
| 12459 | mLastChargeStepLevel = mLastDischargeStepLevel = level; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 12460 | mLastChargingStateLevel = level; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 12461 | } else if (mCurrentBatteryLevel != level || mOnBattery != onBattery) { |
| 12462 | recordDailyStatsIfNeededLocked(level >= 100 && onBattery); |
| 12463 | } |
| 12464 | int oldStatus = mHistoryCur.batteryStatus; |
| 12465 | if (onBattery) { |
| 12466 | mDischargeCurrentLevel = level; |
| 12467 | if (!mRecordingHistory) { |
| 12468 | mRecordingHistory = true; |
| 12469 | startRecordingHistory(elapsedRealtime, uptime, true); |
| 12470 | } |
Todd Poynor | 1acf06a | 2017-12-07 19:19:35 -0800 | [diff] [blame] | 12471 | } else if (level < 96 && |
| 12472 | status != BatteryManager.BATTERY_STATUS_UNKNOWN) { |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 12473 | if (!mRecordingHistory) { |
| 12474 | mRecordingHistory = true; |
| 12475 | startRecordingHistory(elapsedRealtime, uptime, true); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 12476 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 12477 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 12478 | mCurrentBatteryLevel = level; |
| 12479 | if (mDischargePlugLevel < 0) { |
| 12480 | mDischargePlugLevel = level; |
Marco Nelissen | d859331 | 2009-04-30 14:45:06 -0700 | [diff] [blame] | 12481 | } |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 12482 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 12483 | if (onBattery != mOnBattery) { |
| 12484 | mHistoryCur.batteryLevel = (byte)level; |
| 12485 | mHistoryCur.batteryStatus = (byte)status; |
| 12486 | mHistoryCur.batteryHealth = (byte)health; |
| 12487 | mHistoryCur.batteryPlugType = (byte)plugType; |
| 12488 | mHistoryCur.batteryTemperature = (short)temp; |
| 12489 | mHistoryCur.batteryVoltage = (char)volt; |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 12490 | if (chargeUAh < mHistoryCur.batteryChargeUAh) { |
| 12491 | // Only record discharges |
| 12492 | final long chargeDiff = mHistoryCur.batteryChargeUAh - chargeUAh; |
| 12493 | mDischargeCounter.addCountLocked(chargeDiff); |
| 12494 | mDischargeScreenOffCounter.addCountLocked(chargeDiff); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 12495 | if (isScreenDoze(mScreenState)) { |
| 12496 | mDischargeScreenDozeCounter.addCountLocked(chargeDiff); |
| 12497 | } |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 12498 | if (mDeviceIdleMode == DEVICE_IDLE_MODE_LIGHT) { |
| 12499 | mDischargeLightDozeCounter.addCountLocked(chargeDiff); |
| 12500 | } else if (mDeviceIdleMode == DEVICE_IDLE_MODE_DEEP) { |
| 12501 | mDischargeDeepDozeCounter.addCountLocked(chargeDiff); |
| 12502 | } |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 12503 | } |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 12504 | mHistoryCur.batteryChargeUAh = chargeUAh; |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 12505 | setOnBatteryLocked(elapsedRealtime, uptime, onBattery, oldStatus, level, chargeUAh); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 12506 | } else { |
| 12507 | boolean changed = false; |
| 12508 | if (mHistoryCur.batteryLevel != level) { |
| 12509 | mHistoryCur.batteryLevel = (byte)level; |
| 12510 | changed = true; |
Marco Nelissen | d859331 | 2009-04-30 14:45:06 -0700 | [diff] [blame] | 12511 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 12512 | // TODO(adamlesinski): Schedule the creation of a HistoryStepDetails record |
| 12513 | // which will pull external stats. |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 12514 | scheduleSyncExternalStatsLocked("battery-level", ExternalStatsSync.UPDATE_ALL); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 12515 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 12516 | if (mHistoryCur.batteryStatus != status) { |
| 12517 | mHistoryCur.batteryStatus = (byte)status; |
| 12518 | changed = true; |
| 12519 | } |
| 12520 | if (mHistoryCur.batteryHealth != health) { |
| 12521 | mHistoryCur.batteryHealth = (byte)health; |
| 12522 | changed = true; |
| 12523 | } |
| 12524 | if (mHistoryCur.batteryPlugType != plugType) { |
| 12525 | mHistoryCur.batteryPlugType = (byte)plugType; |
| 12526 | changed = true; |
| 12527 | } |
| 12528 | if (temp >= (mHistoryCur.batteryTemperature+10) |
| 12529 | || temp <= (mHistoryCur.batteryTemperature-10)) { |
| 12530 | mHistoryCur.batteryTemperature = (short)temp; |
| 12531 | changed = true; |
| 12532 | } |
| 12533 | if (volt > (mHistoryCur.batteryVoltage+20) |
| 12534 | || volt < (mHistoryCur.batteryVoltage-20)) { |
| 12535 | mHistoryCur.batteryVoltage = (char)volt; |
| 12536 | changed = true; |
| 12537 | } |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 12538 | if (chargeUAh >= (mHistoryCur.batteryChargeUAh+10) |
| 12539 | || chargeUAh <= (mHistoryCur.batteryChargeUAh-10)) { |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 12540 | if (chargeUAh < mHistoryCur.batteryChargeUAh) { |
| 12541 | // Only record discharges |
| 12542 | final long chargeDiff = mHistoryCur.batteryChargeUAh - chargeUAh; |
| 12543 | mDischargeCounter.addCountLocked(chargeDiff); |
| 12544 | mDischargeScreenOffCounter.addCountLocked(chargeDiff); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 12545 | if (isScreenDoze(mScreenState)) { |
| 12546 | mDischargeScreenDozeCounter.addCountLocked(chargeDiff); |
| 12547 | } |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 12548 | if (mDeviceIdleMode == DEVICE_IDLE_MODE_LIGHT) { |
| 12549 | mDischargeLightDozeCounter.addCountLocked(chargeDiff); |
| 12550 | } else if (mDeviceIdleMode == DEVICE_IDLE_MODE_DEEP) { |
| 12551 | mDischargeDeepDozeCounter.addCountLocked(chargeDiff); |
| 12552 | } |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 12553 | } |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 12554 | mHistoryCur.batteryChargeUAh = chargeUAh; |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 12555 | changed = true; |
| 12556 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 12557 | long modeBits = (((long)mInitStepMode) << STEP_LEVEL_INITIAL_MODE_SHIFT) |
| 12558 | | (((long)mModStepMode) << STEP_LEVEL_MODIFIED_MODE_SHIFT) |
| 12559 | | (((long)(level&0xff)) << STEP_LEVEL_LEVEL_SHIFT); |
| 12560 | if (onBattery) { |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 12561 | changed |= setChargingLocked(false); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 12562 | if (mLastDischargeStepLevel != level && mMinDischargeStepLevel > level) { |
| 12563 | mDischargeStepTracker.addLevelSteps(mLastDischargeStepLevel - level, |
| 12564 | modeBits, elapsedRealtime); |
| 12565 | mDailyDischargeStepTracker.addLevelSteps(mLastDischargeStepLevel - level, |
| 12566 | modeBits, elapsedRealtime); |
| 12567 | mLastDischargeStepLevel = level; |
| 12568 | mMinDischargeStepLevel = level; |
| 12569 | mInitStepMode = mCurStepMode; |
| 12570 | mModStepMode = 0; |
| 12571 | } |
| 12572 | } else { |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 12573 | if (level >= 90) { |
| 12574 | // If the battery level is at least 90%, always consider the device to be |
| 12575 | // charging even if it happens to go down a level. |
| 12576 | changed |= setChargingLocked(true); |
| 12577 | mLastChargeStepLevel = level; |
| 12578 | } if (!mCharging) { |
| 12579 | if (mLastChargeStepLevel < level) { |
| 12580 | // We have not reporting that we are charging, but the level has now |
| 12581 | // gone up, so consider the state to be charging. |
| 12582 | changed |= setChargingLocked(true); |
| 12583 | mLastChargeStepLevel = level; |
| 12584 | } |
| 12585 | } else { |
| 12586 | if (mLastChargeStepLevel > level) { |
| 12587 | // We had reported that the device was charging, but here we are with |
| 12588 | // power connected and the level going down. Looks like the current |
| 12589 | // power supplied isn't enough, so consider the device to now be |
| 12590 | // discharging. |
| 12591 | changed |= setChargingLocked(false); |
| 12592 | mLastChargeStepLevel = level; |
| 12593 | } |
| 12594 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 12595 | if (mLastChargeStepLevel != level && mMaxChargeStepLevel < level) { |
| 12596 | mChargeStepTracker.addLevelSteps(level - mLastChargeStepLevel, |
| 12597 | modeBits, elapsedRealtime); |
| 12598 | mDailyChargeStepTracker.addLevelSteps(level - mLastChargeStepLevel, |
| 12599 | modeBits, elapsedRealtime); |
| 12600 | mLastChargeStepLevel = level; |
| 12601 | mMaxChargeStepLevel = level; |
| 12602 | mInitStepMode = mCurStepMode; |
| 12603 | mModStepMode = 0; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 12604 | } |
| 12605 | } |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 12606 | if (changed) { |
| 12607 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 12608 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 12609 | } |
Todd Poynor | 1acf06a | 2017-12-07 19:19:35 -0800 | [diff] [blame] | 12610 | if (!onBattery && |
| 12611 | (status == BatteryManager.BATTERY_STATUS_FULL || |
| 12612 | status == BatteryManager.BATTERY_STATUS_UNKNOWN)) { |
| 12613 | // We don't record history while we are plugged in and fully charged |
| 12614 | // (or when battery is not present). The next time we are |
| 12615 | // unplugged, history will be cleared. |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 12616 | mRecordingHistory = DEBUG; |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 12617 | } |
Adam Lesinski | 041d917 | 2016-12-12 12:03:56 -0800 | [diff] [blame] | 12618 | |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 12619 | if (mMinLearnedBatteryCapacity == -1) { |
| 12620 | mMinLearnedBatteryCapacity = chargeFullUAh; |
| 12621 | } else { |
| 12622 | Math.min(mMinLearnedBatteryCapacity, chargeFullUAh); |
Adam Lesinski | 041d917 | 2016-12-12 12:03:56 -0800 | [diff] [blame] | 12623 | } |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 12624 | mMaxLearnedBatteryCapacity = Math.max(mMaxLearnedBatteryCapacity, chargeFullUAh); |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 12625 | } |
| 12626 | |
Bookatz | 8c6571b | 2017-10-24 15:04:41 -0700 | [diff] [blame] | 12627 | // Inform StatsLog of setBatteryState changes. |
| 12628 | // If this is the first reporting, pass in recentPast == null. |
| 12629 | private void reportChangesToStatsLog(HistoryItem recentPast, |
| 12630 | final int status, final int plugType, final int level, final int temp) { |
| 12631 | |
| 12632 | if (recentPast == null || recentPast.batteryStatus != status) { |
| 12633 | StatsLog.write(StatsLog.CHARGING_STATE_CHANGED, status); |
| 12634 | } |
| 12635 | if (recentPast == null || recentPast.batteryPlugType != plugType) { |
| 12636 | StatsLog.write(StatsLog.PLUGGED_STATE_CHANGED, plugType); |
| 12637 | } |
| 12638 | if (recentPast == null || recentPast.batteryLevel != level) { |
| 12639 | StatsLog.write(StatsLog.BATTERY_LEVEL_CHANGED, level); |
| 12640 | } |
| 12641 | // Let's just always print the temperature, regardless of whether it changed. |
| 12642 | StatsLog.write(StatsLog.DEVICE_TEMPERATURE_REPORTED, temp); |
| 12643 | } |
| 12644 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12645 | public long getAwakeTimeBattery() { |
| 12646 | return computeBatteryUptime(getBatteryUptimeLocked(), STATS_CURRENT); |
| 12647 | } |
| 12648 | |
| 12649 | public long getAwakeTimePlugged() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 12650 | return (mClocks.uptimeMillis() * 1000) - getAwakeTimeBattery(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12651 | } |
| 12652 | |
| 12653 | @Override |
| 12654 | public long computeUptime(long curTime, int which) { |
| 12655 | switch (which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 12656 | case STATS_SINCE_CHARGED: return mUptime + (curTime-mUptimeStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12657 | case STATS_CURRENT: return (curTime-mUptimeStart); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 12658 | case STATS_SINCE_UNPLUGGED: return (curTime-mOnBatteryTimeBase.getUptimeStart()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12659 | } |
| 12660 | return 0; |
| 12661 | } |
| 12662 | |
| 12663 | @Override |
| 12664 | public long computeRealtime(long curTime, int which) { |
| 12665 | switch (which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 12666 | case STATS_SINCE_CHARGED: return mRealtime + (curTime-mRealtimeStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12667 | case STATS_CURRENT: return (curTime-mRealtimeStart); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 12668 | case STATS_SINCE_UNPLUGGED: return (curTime-mOnBatteryTimeBase.getRealtimeStart()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12669 | } |
| 12670 | return 0; |
| 12671 | } |
| 12672 | |
| 12673 | @Override |
| 12674 | public long computeBatteryUptime(long curTime, int which) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 12675 | return mOnBatteryTimeBase.computeUptime(curTime, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12676 | } |
| 12677 | |
| 12678 | @Override |
| 12679 | public long computeBatteryRealtime(long curTime, int which) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 12680 | return mOnBatteryTimeBase.computeRealtime(curTime, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12681 | } |
| 12682 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 12683 | @Override |
| 12684 | public long computeBatteryScreenOffUptime(long curTime, int which) { |
| 12685 | return mOnBatteryScreenOffTimeBase.computeUptime(curTime, which); |
| 12686 | } |
| 12687 | |
| 12688 | @Override |
| 12689 | public long computeBatteryScreenOffRealtime(long curTime, int which) { |
| 12690 | return mOnBatteryScreenOffTimeBase.computeRealtime(curTime, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12691 | } |
| 12692 | |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 12693 | private long computeTimePerLevel(long[] steps, int numSteps) { |
| 12694 | // For now we'll do a simple average across all steps. |
| 12695 | if (numSteps <= 0) { |
| 12696 | return -1; |
| 12697 | } |
| 12698 | long total = 0; |
| 12699 | for (int i=0; i<numSteps; i++) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 12700 | total += steps[i] & STEP_LEVEL_TIME_MASK; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 12701 | } |
| 12702 | return total / numSteps; |
| 12703 | /* |
| 12704 | long[] buckets = new long[numSteps]; |
| 12705 | int numBuckets = 0; |
| 12706 | int numToAverage = 4; |
| 12707 | int i = 0; |
| 12708 | while (i < numSteps) { |
| 12709 | long totalTime = 0; |
| 12710 | int num = 0; |
| 12711 | for (int j=0; j<numToAverage && (i+j)<numSteps; j++) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 12712 | totalTime += steps[i+j] & STEP_LEVEL_TIME_MASK; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 12713 | num++; |
| 12714 | } |
| 12715 | buckets[numBuckets] = totalTime / num; |
| 12716 | numBuckets++; |
| 12717 | numToAverage *= 2; |
| 12718 | i += num; |
| 12719 | } |
| 12720 | if (numBuckets < 1) { |
| 12721 | return -1; |
| 12722 | } |
| 12723 | long averageTime = buckets[numBuckets-1]; |
| 12724 | for (i=numBuckets-2; i>=0; i--) { |
| 12725 | averageTime = (averageTime + buckets[i]) / 2; |
| 12726 | } |
| 12727 | return averageTime; |
| 12728 | */ |
| 12729 | } |
| 12730 | |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 12731 | @Override |
| 12732 | public long computeBatteryTimeRemaining(long curTime) { |
| 12733 | if (!mOnBattery) { |
| 12734 | return -1; |
| 12735 | } |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 12736 | /* Simple implementation just looks at the average discharge per level across the |
| 12737 | entire sample period. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 12738 | int discharge = (getLowDischargeAmountSinceCharge()+getHighDischargeAmountSinceCharge())/2; |
| 12739 | if (discharge < 2) { |
| 12740 | return -1; |
| 12741 | } |
| 12742 | long duration = computeBatteryRealtime(curTime, STATS_SINCE_CHARGED); |
| 12743 | if (duration < 1000*1000) { |
| 12744 | return -1; |
| 12745 | } |
| 12746 | long usPerLevel = duration/discharge; |
| 12747 | return usPerLevel * mCurrentBatteryLevel; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 12748 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 12749 | if (mDischargeStepTracker.mNumStepDurations < 1) { |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 12750 | return -1; |
| 12751 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 12752 | long msPerLevel = mDischargeStepTracker.computeTimePerLevel(); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 12753 | if (msPerLevel <= 0) { |
| 12754 | return -1; |
| 12755 | } |
| 12756 | return (msPerLevel * mCurrentBatteryLevel) * 1000; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 12757 | } |
| 12758 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 12759 | @Override |
| 12760 | public LevelStepTracker getDischargeLevelStepTracker() { |
| 12761 | return mDischargeStepTracker; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 12762 | } |
| 12763 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 12764 | @Override |
| 12765 | public LevelStepTracker getDailyDischargeLevelStepTracker() { |
| 12766 | return mDailyDischargeStepTracker; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 12767 | } |
| 12768 | |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 12769 | @Override |
| 12770 | public long computeChargeTimeRemaining(long curTime) { |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 12771 | if (mOnBattery) { |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 12772 | // Not yet working. |
| 12773 | return -1; |
| 12774 | } |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 12775 | /* Broken |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 12776 | int curLevel = mCurrentBatteryLevel; |
| 12777 | int plugLevel = mDischargePlugLevel; |
| 12778 | if (plugLevel < 0 || curLevel < (plugLevel+1)) { |
| 12779 | return -1; |
| 12780 | } |
| 12781 | long duration = computeBatteryRealtime(curTime, STATS_SINCE_UNPLUGGED); |
| 12782 | if (duration < 1000*1000) { |
| 12783 | return -1; |
| 12784 | } |
| 12785 | long usPerLevel = duration/(curLevel-plugLevel); |
| 12786 | return usPerLevel * (100-curLevel); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 12787 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 12788 | if (mChargeStepTracker.mNumStepDurations < 1) { |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 12789 | return -1; |
| 12790 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 12791 | long msPerLevel = mChargeStepTracker.computeTimePerLevel(); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 12792 | if (msPerLevel <= 0) { |
| 12793 | return -1; |
| 12794 | } |
| 12795 | return (msPerLevel * (100-mCurrentBatteryLevel)) * 1000; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 12796 | } |
| 12797 | |
Siddharth Ray | a1fd057 | 2017-11-13 14:20:47 -0800 | [diff] [blame] | 12798 | /*@hide */ |
| 12799 | public CellularBatteryStats getCellularBatteryStats() { |
| 12800 | CellularBatteryStats s = new CellularBatteryStats(); |
| 12801 | final int which = STATS_SINCE_CHARGED; |
| 12802 | final long rawRealTime = SystemClock.elapsedRealtime() * 1000; |
| 12803 | final ControllerActivityCounter counter = getModemControllerActivity(); |
Siddharth Ray | ed75470 | 2018-02-15 12:44:37 -0800 | [diff] [blame^] | 12804 | final long sleepTimeMs = counter.getSleepTimeCounter().getCountLocked(which); |
Siddharth Ray | a1fd057 | 2017-11-13 14:20:47 -0800 | [diff] [blame] | 12805 | final long idleTimeMs = counter.getIdleTimeCounter().getCountLocked(which); |
| 12806 | final long rxTimeMs = counter.getRxTimeCounter().getCountLocked(which); |
| 12807 | final long energyConsumedMaMs = counter.getPowerCounter().getCountLocked(which); |
| 12808 | long[] timeInRatMs = new long[BatteryStats.NUM_DATA_CONNECTION_TYPES]; |
| 12809 | for (int i = 0; i < timeInRatMs.length; i++) { |
| 12810 | timeInRatMs[i] = getPhoneDataConnectionTime(i, rawRealTime, which) / 1000; |
| 12811 | } |
| 12812 | long[] timeInRxSignalStrengthLevelMs = new long[SignalStrength.NUM_SIGNAL_STRENGTH_BINS]; |
| 12813 | for (int i = 0; i < timeInRxSignalStrengthLevelMs.length; i++) { |
| 12814 | timeInRxSignalStrengthLevelMs[i] |
| 12815 | = getPhoneSignalStrengthTime(i, rawRealTime, which) / 1000; |
| 12816 | } |
| 12817 | long[] txTimeMs = new long[Math.min(ModemActivityInfo.TX_POWER_LEVELS, |
| 12818 | counter.getTxTimeCounters().length)]; |
| 12819 | long totalTxTimeMs = 0; |
| 12820 | for (int i = 0; i < txTimeMs.length; i++) { |
| 12821 | txTimeMs[i] = counter.getTxTimeCounters()[i].getCountLocked(which); |
| 12822 | totalTxTimeMs += txTimeMs[i]; |
| 12823 | } |
Siddharth Ray | a1fd057 | 2017-11-13 14:20:47 -0800 | [diff] [blame] | 12824 | s.setLoggingDurationMs(computeBatteryRealtime(rawRealTime, which) / 1000); |
| 12825 | s.setKernelActiveTimeMs(getMobileRadioActiveTime(rawRealTime, which) / 1000); |
| 12826 | s.setNumPacketsTx(getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which)); |
| 12827 | s.setNumBytesTx(getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which)); |
| 12828 | s.setNumPacketsRx(getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which)); |
| 12829 | s.setNumBytesRx(getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which)); |
| 12830 | s.setSleepTimeMs(sleepTimeMs); |
| 12831 | s.setIdleTimeMs(idleTimeMs); |
| 12832 | s.setRxTimeMs(rxTimeMs); |
| 12833 | s.setEnergyConsumedMaMs(energyConsumedMaMs); |
| 12834 | s.setTimeInRatMs(timeInRatMs); |
| 12835 | s.setTimeInRxSignalStrengthLevelMs(timeInRxSignalStrengthLevelMs); |
| 12836 | s.setTxTimeMs(txTimeMs); |
| 12837 | return s; |
| 12838 | } |
| 12839 | |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 12840 | /*@hide */ |
| 12841 | public WifiBatteryStats getWifiBatteryStats() { |
| 12842 | WifiBatteryStats s = new WifiBatteryStats(); |
| 12843 | final int which = STATS_SINCE_CHARGED; |
| 12844 | final long rawRealTime = SystemClock.elapsedRealtime() * 1000; |
| 12845 | final ControllerActivityCounter counter = getWifiControllerActivity(); |
| 12846 | final long idleTimeMs = counter.getIdleTimeCounter().getCountLocked(which); |
| 12847 | final long scanTimeMs = counter.getScanTimeCounter().getCountLocked(which); |
| 12848 | final long rxTimeMs = counter.getRxTimeCounter().getCountLocked(which); |
| 12849 | final long txTimeMs = counter.getTxTimeCounters()[0].getCountLocked(which); |
| 12850 | final long totalControllerActivityTimeMs |
| 12851 | = computeBatteryRealtime(SystemClock.elapsedRealtime() * 1000, which) / 1000; |
| 12852 | final long sleepTimeMs |
| 12853 | = totalControllerActivityTimeMs - (idleTimeMs + rxTimeMs + txTimeMs); |
| 12854 | final long energyConsumedMaMs = counter.getPowerCounter().getCountLocked(which); |
| 12855 | long numAppScanRequest = 0; |
| 12856 | for (int i = 0; i < mUidStats.size(); i++) { |
| 12857 | numAppScanRequest += mUidStats.valueAt(i).mWifiScanTimer.getCountLocked(which); |
| 12858 | } |
| 12859 | long[] timeInStateMs = new long[NUM_WIFI_STATES]; |
| 12860 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 12861 | timeInStateMs[i] = getWifiStateTime(i, rawRealTime, which) / 1000; |
| 12862 | } |
| 12863 | long[] timeInSupplStateMs = new long[NUM_WIFI_SUPPL_STATES]; |
| 12864 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 12865 | timeInSupplStateMs[i] = getWifiSupplStateTime(i, rawRealTime, which) / 1000; |
| 12866 | } |
| 12867 | long[] timeSignalStrengthTimeMs = new long[NUM_WIFI_SIGNAL_STRENGTH_BINS]; |
| 12868 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 12869 | timeSignalStrengthTimeMs[i] = getWifiSignalStrengthTime(i, rawRealTime, which) / 1000; |
| 12870 | } |
| 12871 | s.setLoggingDurationMs(computeBatteryRealtime(rawRealTime, which) / 1000); |
| 12872 | s.setKernelActiveTimeMs(getWifiActiveTime(rawRealTime, which) / 1000); |
| 12873 | s.setNumPacketsTx(getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which)); |
| 12874 | s.setNumBytesTx(getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which)); |
| 12875 | s.setNumPacketsRx(getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which)); |
| 12876 | s.setNumBytesRx(getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which)); |
| 12877 | s.setSleepTimeMs(sleepTimeMs); |
| 12878 | s.setIdleTimeMs(idleTimeMs); |
| 12879 | s.setRxTimeMs(rxTimeMs); |
| 12880 | s.setTxTimeMs(txTimeMs); |
| 12881 | s.setScanTimeMs(scanTimeMs); |
| 12882 | s.setEnergyConsumedMaMs(energyConsumedMaMs); |
| 12883 | s.setNumAppScanRequest(numAppScanRequest); |
| 12884 | s.setTimeInStateMs(timeInStateMs); |
| 12885 | s.setTimeInSupplicantStateMs(timeInSupplStateMs); |
| 12886 | s.setTimeInRxSignalStrengthLevelMs(timeSignalStrengthTimeMs); |
| 12887 | return s; |
| 12888 | } |
| 12889 | |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 12890 | /*@hide */ |
| 12891 | public GpsBatteryStats getGpsBatteryStats() { |
| 12892 | GpsBatteryStats s = new GpsBatteryStats(); |
| 12893 | final int which = STATS_SINCE_CHARGED; |
| 12894 | final long rawRealTime = SystemClock.elapsedRealtime() * 1000; |
| 12895 | s.setLoggingDurationMs(computeBatteryRealtime(rawRealTime, which) / 1000); |
| 12896 | s.setEnergyConsumedMaMs(getGpsBatteryDrainMaMs()); |
| 12897 | long[] time = new long[GnssMetrics.NUM_GPS_SIGNAL_QUALITY_LEVELS]; |
| 12898 | for (int i=0; i<time.length; i++) { |
| 12899 | time[i] = getGpsSignalQualityTime(i, rawRealTime, which) / 1000; |
| 12900 | } |
| 12901 | s.setTimeInGpsSignalQualityLevel(time); |
| 12902 | return s; |
| 12903 | } |
| 12904 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 12905 | @Override |
| 12906 | public LevelStepTracker getChargeLevelStepTracker() { |
| 12907 | return mChargeStepTracker; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 12908 | } |
| 12909 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 12910 | @Override |
| 12911 | public LevelStepTracker getDailyChargeLevelStepTracker() { |
| 12912 | return mDailyChargeStepTracker; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 12913 | } |
| 12914 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 12915 | @Override |
| 12916 | public ArrayList<PackageChange> getDailyPackageChanges() { |
| 12917 | return mDailyPackageChanges; |
| 12918 | } |
| 12919 | |
Joe Onorato | e1acd63 | 2016-02-23 13:25:10 -0800 | [diff] [blame] | 12920 | protected long getBatteryUptimeLocked() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 12921 | return mOnBatteryTimeBase.getUptime(mClocks.uptimeMillis() * 1000); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12922 | } |
| 12923 | |
| 12924 | @Override |
| 12925 | public long getBatteryUptime(long curTime) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 12926 | return mOnBatteryTimeBase.getUptime(curTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12927 | } |
| 12928 | |
| 12929 | @Override |
| 12930 | public long getBatteryRealtime(long curTime) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 12931 | return mOnBatteryTimeBase.getRealtime(curTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12932 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 12933 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 12934 | @Override |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 12935 | public int getDischargeStartLevel() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 12936 | synchronized(this) { |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 12937 | return getDischargeStartLevelLocked(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 12938 | } |
| 12939 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 12940 | |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 12941 | public int getDischargeStartLevelLocked() { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 12942 | return mDischargeUnplugLevel; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 12943 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 12944 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 12945 | @Override |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 12946 | public int getDischargeCurrentLevel() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 12947 | synchronized(this) { |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 12948 | return getDischargeCurrentLevelLocked(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 12949 | } |
| 12950 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 12951 | |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 12952 | public int getDischargeCurrentLevelLocked() { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 12953 | return mDischargeCurrentLevel; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 12954 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12955 | |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 12956 | @Override |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 12957 | public int getLowDischargeAmountSinceCharge() { |
| 12958 | synchronized(this) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 12959 | int val = mLowDischargeAmountSinceCharge; |
| 12960 | if (mOnBattery && mDischargeCurrentLevel < mDischargeUnplugLevel) { |
| 12961 | val += mDischargeUnplugLevel-mDischargeCurrentLevel-1; |
| 12962 | } |
| 12963 | return val; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 12964 | } |
| 12965 | } |
| 12966 | |
| 12967 | @Override |
| 12968 | public int getHighDischargeAmountSinceCharge() { |
| 12969 | synchronized(this) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 12970 | int val = mHighDischargeAmountSinceCharge; |
| 12971 | if (mOnBattery && mDischargeCurrentLevel < mDischargeUnplugLevel) { |
| 12972 | val += mDischargeUnplugLevel-mDischargeCurrentLevel; |
| 12973 | } |
| 12974 | return val; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 12975 | } |
| 12976 | } |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 12977 | |
| 12978 | @Override |
| 12979 | public int getDischargeAmount(int which) { |
| 12980 | int dischargeAmount = which == STATS_SINCE_CHARGED |
| 12981 | ? getHighDischargeAmountSinceCharge() |
| 12982 | : (getDischargeStartLevel() - getDischargeCurrentLevel()); |
| 12983 | if (dischargeAmount < 0) { |
| 12984 | dischargeAmount = 0; |
| 12985 | } |
| 12986 | return dischargeAmount; |
| 12987 | } |
| 12988 | |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 12989 | @Override |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 12990 | public int getDischargeAmountScreenOn() { |
| 12991 | synchronized(this) { |
| 12992 | int val = mDischargeAmountScreenOn; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 12993 | if (mOnBattery && isScreenOn(mScreenState) |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 12994 | && mDischargeCurrentLevel < mDischargeScreenOnUnplugLevel) { |
| 12995 | val += mDischargeScreenOnUnplugLevel-mDischargeCurrentLevel; |
| 12996 | } |
| 12997 | return val; |
| 12998 | } |
| 12999 | } |
| 13000 | |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 13001 | @Override |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 13002 | public int getDischargeAmountScreenOnSinceCharge() { |
| 13003 | synchronized(this) { |
| 13004 | int val = mDischargeAmountScreenOnSinceCharge; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 13005 | if (mOnBattery && isScreenOn(mScreenState) |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 13006 | && mDischargeCurrentLevel < mDischargeScreenOnUnplugLevel) { |
| 13007 | val += mDischargeScreenOnUnplugLevel-mDischargeCurrentLevel; |
| 13008 | } |
| 13009 | return val; |
| 13010 | } |
| 13011 | } |
| 13012 | |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 13013 | @Override |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 13014 | public int getDischargeAmountScreenOff() { |
| 13015 | synchronized(this) { |
| 13016 | int val = mDischargeAmountScreenOff; |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 13017 | if (mOnBattery && isScreenOff(mScreenState) |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 13018 | && mDischargeCurrentLevel < mDischargeScreenOffUnplugLevel) { |
| 13019 | val += mDischargeScreenOffUnplugLevel-mDischargeCurrentLevel; |
| 13020 | } |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 13021 | // For backward compatibility, doze discharge is counted into screen off. |
| 13022 | return val + getDischargeAmountScreenDoze(); |
| 13023 | } |
| 13024 | } |
| 13025 | |
| 13026 | @Override |
| 13027 | public int getDischargeAmountScreenOffSinceCharge() { |
| 13028 | synchronized(this) { |
| 13029 | int val = mDischargeAmountScreenOffSinceCharge; |
| 13030 | if (mOnBattery && isScreenOff(mScreenState) |
| 13031 | && mDischargeCurrentLevel < mDischargeScreenOffUnplugLevel) { |
| 13032 | val += mDischargeScreenOffUnplugLevel-mDischargeCurrentLevel; |
| 13033 | } |
| 13034 | // For backward compatibility, doze discharge is counted into screen off. |
| 13035 | return val + getDischargeAmountScreenDozeSinceCharge(); |
| 13036 | } |
| 13037 | } |
| 13038 | |
| 13039 | @Override |
| 13040 | public int getDischargeAmountScreenDoze() { |
| 13041 | synchronized(this) { |
| 13042 | int val = mDischargeAmountScreenDoze; |
| 13043 | if (mOnBattery && isScreenDoze(mScreenState) |
| 13044 | && mDischargeCurrentLevel < mDischargeScreenDozeUnplugLevel) { |
| 13045 | val += mDischargeScreenDozeUnplugLevel-mDischargeCurrentLevel; |
| 13046 | } |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 13047 | return val; |
| 13048 | } |
| 13049 | } |
| 13050 | |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 13051 | @Override |
| 13052 | public int getDischargeAmountScreenDozeSinceCharge() { |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 13053 | synchronized(this) { |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 13054 | int val = mDischargeAmountScreenDozeSinceCharge; |
| 13055 | if (mOnBattery && isScreenDoze(mScreenState) |
| 13056 | && mDischargeCurrentLevel < mDischargeScreenDozeUnplugLevel) { |
| 13057 | val += mDischargeScreenDozeUnplugLevel-mDischargeCurrentLevel; |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 13058 | } |
| 13059 | return val; |
| 13060 | } |
| 13061 | } |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 13062 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13063 | /** |
| 13064 | * Retrieve the statistics object for a particular uid, creating if needed. |
| 13065 | */ |
| 13066 | public Uid getUidStatsLocked(int uid) { |
| 13067 | Uid u = mUidStats.get(uid); |
| 13068 | if (u == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 13069 | u = new Uid(this, uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13070 | mUidStats.put(uid, u); |
| 13071 | } |
| 13072 | return u; |
| 13073 | } |
| 13074 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 13075 | /** |
| 13076 | * Retrieve the statistics object for a particular uid. Returns null if the object is not |
| 13077 | * available. |
| 13078 | */ |
| 13079 | public Uid getAvailableUidStatsLocked(int uid) { |
| 13080 | Uid u = mUidStats.get(uid); |
| 13081 | return u; |
| 13082 | } |
| 13083 | |
Suprabh Shukla | e6e723d | 2017-06-14 16:14:43 -0700 | [diff] [blame] | 13084 | public void onCleanupUserLocked(int userId) { |
| 13085 | final int firstUidForUser = UserHandle.getUid(userId, 0); |
| 13086 | final int lastUidForUser = UserHandle.getUid(userId, UserHandle.PER_USER_RANGE - 1); |
| 13087 | mKernelUidCpuFreqTimeReader.removeUidsInRange(firstUidForUser, lastUidForUser); |
| 13088 | mKernelUidCpuTimeReader.removeUidsInRange(firstUidForUser, lastUidForUser); |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 13089 | if (mKernelSingleUidTimeReader != null) { |
| 13090 | mKernelSingleUidTimeReader.removeUidsInRange(firstUidForUser, lastUidForUser); |
| 13091 | } |
Suprabh Shukla | e6e723d | 2017-06-14 16:14:43 -0700 | [diff] [blame] | 13092 | } |
| 13093 | |
| 13094 | public void onUserRemovedLocked(int userId) { |
| 13095 | final int firstUidForUser = UserHandle.getUid(userId, 0); |
| 13096 | final int lastUidForUser = UserHandle.getUid(userId, UserHandle.PER_USER_RANGE - 1); |
| 13097 | mUidStats.put(firstUidForUser, null); |
| 13098 | mUidStats.put(lastUidForUser, null); |
| 13099 | final int firstIndex = mUidStats.indexOfKey(firstUidForUser); |
| 13100 | final int lastIndex = mUidStats.indexOfKey(lastUidForUser); |
| 13101 | mUidStats.removeAtRange(firstIndex, lastIndex - firstIndex + 1); |
| 13102 | } |
| 13103 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13104 | /** |
| 13105 | * Remove the statistics object for a particular uid. |
| 13106 | */ |
| 13107 | public void removeUidStatsLocked(int uid) { |
Adam Lesinski | b83ffee | 2015-05-12 14:43:47 -0700 | [diff] [blame] | 13108 | mKernelUidCpuTimeReader.removeUid(uid); |
Sudheer Shanka | 6d8dcec | 2017-06-01 12:09:03 -0700 | [diff] [blame] | 13109 | mKernelUidCpuFreqTimeReader.removeUid(uid); |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 13110 | if (mKernelSingleUidTimeReader != null) { |
| 13111 | mKernelSingleUidTimeReader.removeUid(uid); |
| 13112 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13113 | mUidStats.remove(uid); |
| 13114 | } |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 13115 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13116 | /** |
| 13117 | * Retrieve the statistics object for a particular process, creating |
| 13118 | * if needed. |
| 13119 | */ |
| 13120 | public Uid.Proc getProcessStatsLocked(int uid, String name) { |
Dianne Hackborn | bbb7472 | 2014-03-13 09:50:24 -0700 | [diff] [blame] | 13121 | uid = mapUid(uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13122 | Uid u = getUidStatsLocked(uid); |
| 13123 | return u.getProcessStatsLocked(name); |
| 13124 | } |
| 13125 | |
| 13126 | /** |
| 13127 | * Retrieve the statistics object for a particular process, creating |
| 13128 | * if needed. |
| 13129 | */ |
| 13130 | public Uid.Pkg getPackageStatsLocked(int uid, String pkg) { |
Dianne Hackborn | bbb7472 | 2014-03-13 09:50:24 -0700 | [diff] [blame] | 13131 | uid = mapUid(uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13132 | Uid u = getUidStatsLocked(uid); |
| 13133 | return u.getPackageStatsLocked(pkg); |
| 13134 | } |
| 13135 | |
| 13136 | /** |
| 13137 | * Retrieve the statistics object for a particular service, creating |
| 13138 | * if needed. |
| 13139 | */ |
| 13140 | public Uid.Pkg.Serv getServiceStatsLocked(int uid, String pkg, String name) { |
Dianne Hackborn | bbb7472 | 2014-03-13 09:50:24 -0700 | [diff] [blame] | 13141 | uid = mapUid(uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13142 | Uid u = getUidStatsLocked(uid); |
| 13143 | return u.getServiceStatsLocked(pkg, name); |
| 13144 | } |
| 13145 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 13146 | public void shutdownLocked() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 13147 | recordShutdownLocked(mClocks.elapsedRealtime(), mClocks.uptimeMillis()); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 13148 | writeSyncLocked(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 13149 | mShuttingDown = true; |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 13150 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 13151 | |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 13152 | public boolean trackPerProcStateCpuTimes() { |
| 13153 | return mConstants.TRACK_CPU_TIMES_BY_PROC_STATE && mPerProcStateCpuTimesAvailable; |
| 13154 | } |
| 13155 | |
| 13156 | public void systemServicesReady(Context context) { |
| 13157 | mConstants.startObserving(context.getContentResolver()); |
| 13158 | } |
| 13159 | |
| 13160 | @VisibleForTesting |
| 13161 | public final class Constants extends ContentObserver { |
| 13162 | public static final String KEY_TRACK_CPU_TIMES_BY_PROC_STATE |
| 13163 | = "track_cpu_times_by_proc_state"; |
Mike Ma | fae87da | 2018-01-19 20:07:20 -0800 | [diff] [blame] | 13164 | public static final String KEY_TRACK_CPU_ACTIVE_CLUSTER_TIME |
| 13165 | = "track_cpu_active_cluster_time"; |
| 13166 | public static final String KEY_READ_BINARY_CPU_TIME |
| 13167 | = "read_binary_cpu_time"; |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 13168 | |
| 13169 | private static final boolean DEFAULT_TRACK_CPU_TIMES_BY_PROC_STATE = true; |
Mike Ma | fae87da | 2018-01-19 20:07:20 -0800 | [diff] [blame] | 13170 | private static final boolean DEFAULT_TRACK_CPU_ACTIVE_CLUSTER_TIME = true; |
| 13171 | private static final boolean DEFAULT_READ_BINARY_CPU_TIME = false; |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 13172 | |
| 13173 | 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] | 13174 | public boolean TRACK_CPU_ACTIVE_CLUSTER_TIME = DEFAULT_TRACK_CPU_ACTIVE_CLUSTER_TIME; |
| 13175 | // Not used right now. |
| 13176 | public boolean READ_BINARY_CPU_TIME = DEFAULT_READ_BINARY_CPU_TIME; |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 13177 | |
| 13178 | private ContentResolver mResolver; |
| 13179 | private final KeyValueListParser mParser = new KeyValueListParser(','); |
| 13180 | |
| 13181 | public Constants(Handler handler) { |
| 13182 | super(handler); |
| 13183 | } |
| 13184 | |
| 13185 | public void startObserving(ContentResolver resolver) { |
| 13186 | mResolver = resolver; |
| 13187 | mResolver.registerContentObserver( |
| 13188 | Settings.Global.getUriFor(Settings.Global.BATTERY_STATS_CONSTANTS), |
| 13189 | false /* notifyForDescendants */, this); |
| 13190 | updateConstants(); |
| 13191 | } |
| 13192 | |
| 13193 | @Override |
| 13194 | public void onChange(boolean selfChange, Uri uri) { |
| 13195 | updateConstants(); |
| 13196 | } |
| 13197 | |
| 13198 | private void updateConstants() { |
| 13199 | synchronized (BatteryStatsImpl.this) { |
| 13200 | try { |
| 13201 | mParser.setString(Settings.Global.getString(mResolver, |
| 13202 | Settings.Global.BATTERY_STATS_CONSTANTS)); |
| 13203 | } catch (IllegalArgumentException e) { |
| 13204 | // Failed to parse the settings string, log this and move on |
| 13205 | // with defaults. |
| 13206 | Slog.e(TAG, "Bad batterystats settings", e); |
| 13207 | } |
| 13208 | |
| 13209 | updateTrackCpuTimesByProcStateLocked(TRACK_CPU_TIMES_BY_PROC_STATE, |
| 13210 | mParser.getBoolean(KEY_TRACK_CPU_TIMES_BY_PROC_STATE, |
| 13211 | DEFAULT_TRACK_CPU_TIMES_BY_PROC_STATE)); |
Mike Ma | fae87da | 2018-01-19 20:07:20 -0800 | [diff] [blame] | 13212 | TRACK_CPU_ACTIVE_CLUSTER_TIME = mParser.getBoolean( |
| 13213 | KEY_TRACK_CPU_ACTIVE_CLUSTER_TIME, DEFAULT_TRACK_CPU_ACTIVE_CLUSTER_TIME); |
| 13214 | READ_BINARY_CPU_TIME = mParser.getBoolean( |
| 13215 | KEY_READ_BINARY_CPU_TIME, DEFAULT_READ_BINARY_CPU_TIME); |
| 13216 | |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 13217 | } |
| 13218 | } |
| 13219 | |
| 13220 | private void updateTrackCpuTimesByProcStateLocked(boolean wasEnabled, boolean isEnabled) { |
| 13221 | TRACK_CPU_TIMES_BY_PROC_STATE = isEnabled; |
| 13222 | if (isEnabled && !wasEnabled) { |
| 13223 | mKernelSingleUidTimeReader.markDataAsStale(true); |
| 13224 | mExternalSync.scheduleCpuSyncDueToSettingChange(); |
| 13225 | } |
| 13226 | } |
| 13227 | |
| 13228 | public void dumpLocked(PrintWriter pw) { |
| 13229 | pw.print(KEY_TRACK_CPU_TIMES_BY_PROC_STATE); pw.print("="); |
| 13230 | pw.println(TRACK_CPU_TIMES_BY_PROC_STATE); |
Mike Ma | fae87da | 2018-01-19 20:07:20 -0800 | [diff] [blame] | 13231 | pw.print(KEY_TRACK_CPU_ACTIVE_CLUSTER_TIME); pw.print("="); |
| 13232 | pw.println(TRACK_CPU_ACTIVE_CLUSTER_TIME); |
| 13233 | pw.print(KEY_READ_BINARY_CPU_TIME); pw.print("="); |
| 13234 | pw.println(READ_BINARY_CPU_TIME); |
Sudheer Shanka | 5c19b89 | 2018-01-05 17:25:46 -0800 | [diff] [blame] | 13235 | } |
| 13236 | } |
| 13237 | |
| 13238 | public void dumpConstantsLocked(PrintWriter pw) { |
| 13239 | mConstants.dumpLocked(pw); |
| 13240 | } |
| 13241 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 13242 | Parcel mPendingWrite = null; |
| 13243 | final ReentrantLock mWriteLock = new ReentrantLock(); |
| 13244 | |
| 13245 | public void writeAsyncLocked() { |
| 13246 | writeLocked(false); |
| 13247 | } |
| 13248 | |
| 13249 | public void writeSyncLocked() { |
| 13250 | writeLocked(true); |
| 13251 | } |
| 13252 | |
| 13253 | void writeLocked(boolean sync) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 13254 | if (mFile == null) { |
| 13255 | 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] | 13256 | return; |
| 13257 | } |
| 13258 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 13259 | if (mShuttingDown) { |
| 13260 | return; |
| 13261 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 13262 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 13263 | Parcel out = Parcel.obtain(); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 13264 | writeSummaryToParcel(out, true); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 13265 | mLastWriteTime = mClocks.elapsedRealtime(); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 13266 | |
| 13267 | if (mPendingWrite != null) { |
| 13268 | mPendingWrite.recycle(); |
| 13269 | } |
| 13270 | mPendingWrite = out; |
| 13271 | |
| 13272 | if (sync) { |
| 13273 | commitPendingDataToDisk(); |
| 13274 | } else { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 13275 | BackgroundThread.getHandler().post(new Runnable() { |
| 13276 | @Override public void run() { |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 13277 | commitPendingDataToDisk(); |
| 13278 | } |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 13279 | }); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 13280 | } |
| 13281 | } |
| 13282 | |
| 13283 | public void commitPendingDataToDisk() { |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 13284 | final Parcel next; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 13285 | synchronized (this) { |
| 13286 | next = mPendingWrite; |
| 13287 | mPendingWrite = null; |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 13288 | if (next == null) { |
| 13289 | return; |
| 13290 | } |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 13291 | } |
| 13292 | |
Amith Yamasani | d245086 | 2017-02-07 15:58:24 -0800 | [diff] [blame] | 13293 | mWriteLock.lock(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13294 | try { |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 13295 | final long startTime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 13296 | FileOutputStream stream = new FileOutputStream(mFile.chooseForWrite()); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 13297 | stream.write(next.marshall()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13298 | stream.flush(); |
Dianne Hackborn | 8bdf593 | 2010-10-15 12:54:40 -0700 | [diff] [blame] | 13299 | FileUtils.sync(stream); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13300 | stream.close(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 13301 | mFile.commit(); |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 13302 | com.android.internal.logging.EventLogTags.writeCommitSysConfigFile( |
| 13303 | "batterystats", SystemClock.uptimeMillis() - startTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13304 | } catch (IOException e) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 13305 | Slog.w("BatteryStats", "Error writing battery statistics", e); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 13306 | mFile.rollback(); |
| 13307 | } finally { |
| 13308 | next.recycle(); |
| 13309 | mWriteLock.unlock(); |
Suchi Amalapurapu | 8550f25 | 2009-09-29 15:20:32 -0700 | [diff] [blame] | 13310 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13311 | } |
| 13312 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13313 | public void readLocked() { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 13314 | if (mDailyFile != null) { |
| 13315 | readDailyStatsLocked(); |
| 13316 | } |
| 13317 | |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 13318 | if (mFile == null) { |
| 13319 | 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] | 13320 | return; |
| 13321 | } |
| 13322 | |
| 13323 | mUidStats.clear(); |
| 13324 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13325 | try { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 13326 | File file = mFile.chooseForRead(); |
| 13327 | if (!file.exists()) { |
| 13328 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13329 | } |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 13330 | FileInputStream stream = new FileInputStream(file); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13331 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 13332 | byte[] raw = BatteryStatsHelper.readFully(stream); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13333 | Parcel in = Parcel.obtain(); |
| 13334 | in.unmarshall(raw, 0, raw.length); |
| 13335 | in.setDataPosition(0); |
| 13336 | stream.close(); |
| 13337 | |
| 13338 | readSummaryFromParcel(in); |
Dianne Hackborn | 00e2521 | 2014-02-19 10:49:24 -0800 | [diff] [blame] | 13339 | } catch(Exception e) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 13340 | Slog.e("BatteryStats", "Error reading battery statistics", e); |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 13341 | resetAllStatsLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13342 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 13343 | |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 13344 | mEndPlatformVersion = Build.ID; |
| 13345 | |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 13346 | if (mHistoryBuffer.dataPosition() > 0) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 13347 | mRecordingHistory = true; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 13348 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 13349 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 13350 | if (USE_OLD_HISTORY) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 13351 | addHistoryRecordLocked(elapsedRealtime, uptime, HistoryItem.CMD_START, mHistoryCur); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 13352 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 13353 | addHistoryBufferLocked(elapsedRealtime, uptime, HistoryItem.CMD_START, mHistoryCur); |
| 13354 | startRecordingHistory(elapsedRealtime, uptime, false); |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 13355 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 13356 | |
| 13357 | recordDailyStatsIfNeededLocked(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13358 | } |
| 13359 | |
| 13360 | public int describeContents() { |
| 13361 | return 0; |
| 13362 | } |
| 13363 | |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 13364 | void readHistory(Parcel in, boolean andOldHistory) throws ParcelFormatException { |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 13365 | final long historyBaseTime = in.readLong(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 13366 | |
| 13367 | mHistoryBuffer.setDataSize(0); |
| 13368 | mHistoryBuffer.setDataPosition(0); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 13369 | mHistoryTagPool.clear(); |
| 13370 | mNextHistoryTagIdx = 0; |
| 13371 | mNumHistoryTagChars = 0; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 13372 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 13373 | int numTags = in.readInt(); |
| 13374 | for (int i=0; i<numTags; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 13375 | int idx = in.readInt(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 13376 | String str = in.readString(); |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 13377 | if (str == null) { |
| 13378 | throw new ParcelFormatException("null history tag string"); |
| 13379 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 13380 | int uid = in.readInt(); |
| 13381 | HistoryTag tag = new HistoryTag(); |
| 13382 | tag.string = str; |
| 13383 | tag.uid = uid; |
| 13384 | tag.poolIdx = idx; |
| 13385 | mHistoryTagPool.put(tag, idx); |
| 13386 | if (idx >= mNextHistoryTagIdx) { |
| 13387 | mNextHistoryTagIdx = idx+1; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 13388 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 13389 | mNumHistoryTagChars += tag.string.length() + 1; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 13390 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 13391 | |
| 13392 | int bufSize = in.readInt(); |
| 13393 | int curPos = in.dataPosition(); |
| 13394 | if (bufSize >= (MAX_MAX_HISTORY_BUFFER*3)) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 13395 | throw new ParcelFormatException("File corrupt: history data buffer too large " + |
| 13396 | bufSize); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 13397 | } else if ((bufSize&~3) != bufSize) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 13398 | throw new ParcelFormatException("File corrupt: history data buffer not aligned " + |
| 13399 | bufSize); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 13400 | } else { |
| 13401 | if (DEBUG_HISTORY) Slog.i(TAG, "***************** READING NEW HISTORY: " + bufSize |
| 13402 | + " bytes at " + curPos); |
| 13403 | mHistoryBuffer.appendFrom(in, curPos, bufSize); |
| 13404 | in.setDataPosition(curPos + bufSize); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 13405 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 13406 | |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 13407 | if (andOldHistory) { |
| 13408 | readOldHistory(in); |
| 13409 | } |
| 13410 | |
| 13411 | if (DEBUG_HISTORY) { |
| 13412 | StringBuilder sb = new StringBuilder(128); |
| 13413 | sb.append("****************** OLD mHistoryBaseTime: "); |
| 13414 | TimeUtils.formatDuration(mHistoryBaseTime, sb); |
| 13415 | Slog.i(TAG, sb.toString()); |
| 13416 | } |
| 13417 | mHistoryBaseTime = historyBaseTime; |
| 13418 | if (DEBUG_HISTORY) { |
| 13419 | StringBuilder sb = new StringBuilder(128); |
| 13420 | sb.append("****************** NEW mHistoryBaseTime: "); |
| 13421 | TimeUtils.formatDuration(mHistoryBaseTime, sb); |
| 13422 | Slog.i(TAG, sb.toString()); |
| 13423 | } |
| 13424 | |
| 13425 | // We are just arbitrarily going to insert 1 minute from the sample of |
| 13426 | // the last run until samples in this run. |
| 13427 | if (mHistoryBaseTime > 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 13428 | long oldnow = mClocks.elapsedRealtime(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 13429 | mHistoryBaseTime = mHistoryBaseTime - oldnow + 1; |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 13430 | if (DEBUG_HISTORY) { |
| 13431 | StringBuilder sb = new StringBuilder(128); |
| 13432 | sb.append("****************** ADJUSTED mHistoryBaseTime: "); |
| 13433 | TimeUtils.formatDuration(mHistoryBaseTime, sb); |
| 13434 | Slog.i(TAG, sb.toString()); |
| 13435 | } |
Dianne Hackborn | 1e4b9f3 | 2010-06-23 14:10:57 -0700 | [diff] [blame] | 13436 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 13437 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 13438 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 13439 | void readOldHistory(Parcel in) { |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 13440 | if (!USE_OLD_HISTORY) { |
| 13441 | return; |
| 13442 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 13443 | mHistory = mHistoryEnd = mHistoryCache = null; |
| 13444 | long time; |
Conley Owens | 5e3357f | 2011-05-02 09:59:30 -0700 | [diff] [blame] | 13445 | while (in.dataAvail() > 0 && (time=in.readLong()) >= 0) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 13446 | HistoryItem rec = new HistoryItem(time, in); |
| 13447 | addHistoryRecordLocked(rec); |
| 13448 | } |
| 13449 | } |
| 13450 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 13451 | void writeHistory(Parcel out, boolean inclData, boolean andOldHistory) { |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 13452 | if (DEBUG_HISTORY) { |
| 13453 | StringBuilder sb = new StringBuilder(128); |
| 13454 | sb.append("****************** WRITING mHistoryBaseTime: "); |
| 13455 | TimeUtils.formatDuration(mHistoryBaseTime, sb); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 13456 | sb.append(" mLastHistoryElapsedRealtime: "); |
| 13457 | TimeUtils.formatDuration(mLastHistoryElapsedRealtime, sb); |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 13458 | Slog.i(TAG, sb.toString()); |
| 13459 | } |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 13460 | out.writeLong(mHistoryBaseTime + mLastHistoryElapsedRealtime); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 13461 | if (!inclData) { |
| 13462 | out.writeInt(0); |
| 13463 | out.writeInt(0); |
| 13464 | return; |
| 13465 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 13466 | out.writeInt(mHistoryTagPool.size()); |
| 13467 | for (HashMap.Entry<HistoryTag, Integer> ent : mHistoryTagPool.entrySet()) { |
| 13468 | HistoryTag tag = ent.getKey(); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 13469 | out.writeInt(ent.getValue()); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 13470 | out.writeString(tag.string); |
| 13471 | out.writeInt(tag.uid); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 13472 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 13473 | out.writeInt(mHistoryBuffer.dataSize()); |
| 13474 | if (DEBUG_HISTORY) Slog.i(TAG, "***************** WRITING HISTORY: " |
| 13475 | + mHistoryBuffer.dataSize() + " bytes at " + out.dataPosition()); |
| 13476 | out.appendFrom(mHistoryBuffer, 0, mHistoryBuffer.dataSize()); |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 13477 | |
| 13478 | if (andOldHistory) { |
| 13479 | writeOldHistory(out); |
| 13480 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 13481 | } |
| 13482 | |
| 13483 | void writeOldHistory(Parcel out) { |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 13484 | if (!USE_OLD_HISTORY) { |
| 13485 | return; |
| 13486 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 13487 | HistoryItem rec = mHistory; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 13488 | while (rec != null) { |
| 13489 | if (rec.time >= 0) rec.writeToParcel(out, 0); |
| 13490 | rec = rec.next; |
| 13491 | } |
| 13492 | out.writeLong(-1); |
| 13493 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 13494 | |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 13495 | public void readSummaryFromParcel(Parcel in) throws ParcelFormatException { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13496 | final int version = in.readInt(); |
| 13497 | if (version != VERSION) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 13498 | Slog.w("BatteryStats", "readFromParcel: version got " + version |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13499 | + ", expected " + VERSION + "; erasing old stats"); |
| 13500 | return; |
| 13501 | } |
| 13502 | |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 13503 | readHistory(in, true); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 13504 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13505 | mStartCount = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13506 | mUptime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13507 | mRealtime = in.readLong(); |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 13508 | mStartClockTime = in.readLong(); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 13509 | mStartPlatformVersion = in.readString(); |
| 13510 | mEndPlatformVersion = in.readString(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 13511 | mOnBatteryTimeBase.readSummaryFromParcel(in); |
| 13512 | mOnBatteryScreenOffTimeBase.readSummaryFromParcel(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 13513 | mDischargeUnplugLevel = in.readInt(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 13514 | mDischargePlugLevel = in.readInt(); |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 13515 | mDischargeCurrentLevel = in.readInt(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 13516 | mCurrentBatteryLevel = in.readInt(); |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 13517 | mEstimatedBatteryCapacity = in.readInt(); |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 13518 | mMinLearnedBatteryCapacity = in.readInt(); |
| 13519 | mMaxLearnedBatteryCapacity = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 13520 | mLowDischargeAmountSinceCharge = in.readInt(); |
| 13521 | mHighDischargeAmountSinceCharge = in.readInt(); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 13522 | mDischargeAmountScreenOnSinceCharge = in.readInt(); |
| 13523 | mDischargeAmountScreenOffSinceCharge = in.readInt(); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 13524 | mDischargeAmountScreenDozeSinceCharge = in.readInt(); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 13525 | mDischargeStepTracker.readFromParcel(in); |
| 13526 | mChargeStepTracker.readFromParcel(in); |
| 13527 | mDailyDischargeStepTracker.readFromParcel(in); |
| 13528 | mDailyChargeStepTracker.readFromParcel(in); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 13529 | mDischargeCounter.readSummaryFromParcelLocked(in); |
| 13530 | mDischargeScreenOffCounter.readSummaryFromParcelLocked(in); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 13531 | mDischargeScreenDozeCounter.readSummaryFromParcelLocked(in); |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 13532 | mDischargeLightDozeCounter.readSummaryFromParcelLocked(in); |
| 13533 | mDischargeDeepDozeCounter.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 13534 | int NPKG = in.readInt(); |
| 13535 | if (NPKG > 0) { |
| 13536 | mDailyPackageChanges = new ArrayList<>(NPKG); |
| 13537 | while (NPKG > 0) { |
| 13538 | NPKG--; |
| 13539 | PackageChange pc = new PackageChange(); |
| 13540 | pc.mPackageName = in.readString(); |
| 13541 | pc.mUpdate = in.readInt() != 0; |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 13542 | pc.mVersionCode = in.readLong(); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 13543 | mDailyPackageChanges.add(pc); |
| 13544 | } |
| 13545 | } else { |
| 13546 | mDailyPackageChanges = null; |
| 13547 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 13548 | mDailyStartTime = in.readLong(); |
| 13549 | mNextMinDailyDeadline = in.readLong(); |
| 13550 | mNextMaxDailyDeadline = in.readLong(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 13551 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13552 | mStartCount++; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 13553 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 13554 | mScreenState = Display.STATE_UNKNOWN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13555 | mScreenOnTimer.readSummaryFromParcelLocked(in); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 13556 | mScreenDozeTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 13557 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
| 13558 | mScreenBrightnessTimer[i].readSummaryFromParcelLocked(in); |
| 13559 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 13560 | mInteractive = false; |
| 13561 | mInteractiveTimer.readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13562 | mPhoneOn = false; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 13563 | mPowerSaveModeEnabledTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 13564 | mLongestLightIdleTime = in.readLong(); |
| 13565 | mLongestFullIdleTime = in.readLong(); |
| 13566 | mDeviceIdleModeLightTimer.readSummaryFromParcelLocked(in); |
| 13567 | mDeviceIdleModeFullTimer.readSummaryFromParcelLocked(in); |
| 13568 | mDeviceLightIdlingTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 13569 | mDeviceIdlingTimer.readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13570 | mPhoneOnTimer.readSummaryFromParcelLocked(in); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 13571 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 13572 | mPhoneSignalStrengthsTimer[i].readSummaryFromParcelLocked(in); |
| 13573 | } |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 13574 | mPhoneSignalScanningTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 13575 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
| 13576 | mPhoneDataConnectionsTimer[i].readSummaryFromParcelLocked(in); |
| 13577 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 13578 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 13579 | mNetworkByteActivityCounters[i].readSummaryFromParcelLocked(in); |
| 13580 | mNetworkPacketActivityCounters[i].readSummaryFromParcelLocked(in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 13581 | } |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 13582 | mMobileRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 13583 | mMobileRadioActiveTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 13584 | mMobileRadioActivePerAppTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 13585 | mMobileRadioActiveAdjustedTime.readSummaryFromParcelLocked(in); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 13586 | mMobileRadioActiveUnknownTime.readSummaryFromParcelLocked(in); |
| 13587 | mMobileRadioActiveUnknownCount.readSummaryFromParcelLocked(in); |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 13588 | mWifiMulticastWakelockTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 13589 | mWifiRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 13590 | mWifiOn = false; |
| 13591 | mWifiOnTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 13592 | mGlobalWifiRunning = false; |
| 13593 | mGlobalWifiRunningTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 13594 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 13595 | mWifiStateTimer[i].readSummaryFromParcelLocked(in); |
| 13596 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 13597 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 13598 | mWifiSupplStateTimer[i].readSummaryFromParcelLocked(in); |
| 13599 | } |
| 13600 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 13601 | mWifiSignalStrengthsTimer[i].readSummaryFromParcelLocked(in); |
| 13602 | } |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 13603 | mWifiActiveTimer.readSummaryFromParcelLocked(in); |
| 13604 | mWifiActivity.readSummaryFromParcel(in); |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 13605 | for (int i=0; i<GnssMetrics.NUM_GPS_SIGNAL_QUALITY_LEVELS; i++) { |
| 13606 | mGpsSignalQualityTimer[i].readSummaryFromParcelLocked(in); |
| 13607 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 13608 | mBluetoothActivity.readSummaryFromParcel(in); |
| 13609 | mModemActivity.readSummaryFromParcel(in); |
| 13610 | mHasWifiReporting = in.readInt() != 0; |
| 13611 | mHasBluetoothReporting = in.readInt() != 0; |
| 13612 | mHasModemReporting = in.readInt() != 0; |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 13613 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 13614 | mNumConnectivityChange = mLoadedNumConnectivityChange = in.readInt(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 13615 | mFlashlightOnNesting = 0; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 13616 | mFlashlightOnTimer.readSummaryFromParcelLocked(in); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 13617 | mCameraOnNesting = 0; |
| 13618 | mCameraOnTimer.readSummaryFromParcelLocked(in); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 13619 | mBluetoothScanNesting = 0; |
| 13620 | mBluetoothScanTimer.readSummaryFromParcelLocked(in); |
Siddharth Ray | f5e796a | 2018-01-22 18:18:17 -0800 | [diff] [blame] | 13621 | mIsCellularTxPowerHigh = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13622 | |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 13623 | int NRPMS = in.readInt(); |
| 13624 | if (NRPMS > 10000) { |
| 13625 | throw new ParcelFormatException("File corrupt: too many rpm stats " + NRPMS); |
| 13626 | } |
| 13627 | for (int irpm = 0; irpm < NRPMS; irpm++) { |
| 13628 | if (in.readInt() != 0) { |
| 13629 | String rpmName = in.readString(); |
| 13630 | getRpmTimerLocked(rpmName).readSummaryFromParcelLocked(in); |
| 13631 | } |
| 13632 | } |
| 13633 | int NSORPMS = in.readInt(); |
| 13634 | if (NSORPMS > 10000) { |
| 13635 | throw new ParcelFormatException("File corrupt: too many screen-off rpm stats " + NSORPMS); |
| 13636 | } |
| 13637 | for (int irpm = 0; irpm < NSORPMS; irpm++) { |
| 13638 | if (in.readInt() != 0) { |
| 13639 | String rpmName = in.readString(); |
| 13640 | getScreenOffRpmTimerLocked(rpmName).readSummaryFromParcelLocked(in); |
| 13641 | } |
| 13642 | } |
| 13643 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 13644 | int NKW = in.readInt(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 13645 | if (NKW > 10000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 13646 | throw new ParcelFormatException("File corrupt: too many kernel wake locks " + NKW); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 13647 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 13648 | for (int ikw = 0; ikw < NKW; ikw++) { |
| 13649 | if (in.readInt() != 0) { |
| 13650 | String kwltName = in.readString(); |
| 13651 | getKernelWakelockTimerLocked(kwltName).readSummaryFromParcelLocked(in); |
| 13652 | } |
| 13653 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 13654 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 13655 | int NWR = in.readInt(); |
| 13656 | if (NWR > 10000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 13657 | throw new ParcelFormatException("File corrupt: too many wakeup reasons " + NWR); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 13658 | } |
| 13659 | for (int iwr = 0; iwr < NWR; iwr++) { |
| 13660 | if (in.readInt() != 0) { |
| 13661 | String reasonName = in.readString(); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 13662 | getWakeupReasonTimerLocked(reasonName).readSummaryFromParcelLocked(in); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 13663 | } |
| 13664 | } |
| 13665 | |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 13666 | int NMS = in.readInt(); |
| 13667 | for (int ims = 0; ims < NMS; ims++) { |
| 13668 | if (in.readInt() != 0) { |
| 13669 | long kmstName = in.readLong(); |
| 13670 | getKernelMemoryTimerLocked(kmstName).readSummaryFromParcelLocked(in); |
| 13671 | } |
| 13672 | } |
| 13673 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13674 | final int NU = in.readInt(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 13675 | if (NU > 10000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 13676 | throw new ParcelFormatException("File corrupt: too many uids " + NU); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 13677 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13678 | for (int iu = 0; iu < NU; iu++) { |
| 13679 | int uid = in.readInt(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 13680 | Uid u = new Uid(this, uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13681 | mUidStats.put(uid, u); |
| 13682 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 13683 | u.mOnBatteryBackgroundTimeBase.readSummaryFromParcel(in); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 13684 | u.mOnBatteryScreenOffBackgroundTimeBase.readSummaryFromParcel(in); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 13685 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 13686 | u.mWifiRunning = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 13687 | if (in.readInt() != 0) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 13688 | u.mWifiRunningTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 13689 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 13690 | u.mFullWifiLockOut = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 13691 | if (in.readInt() != 0) { |
| 13692 | u.mFullWifiLockTimer.readSummaryFromParcelLocked(in); |
| 13693 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 13694 | u.mWifiScanStarted = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 13695 | if (in.readInt() != 0) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 13696 | u.mWifiScanTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 13697 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 13698 | u.mWifiBatchedScanBinStarted = Uid.NO_BATCHED_SCAN_STARTED; |
| 13699 | for (int i = 0; i < Uid.NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 13700 | if (in.readInt() != 0) { |
| 13701 | u.makeWifiBatchedScanBin(i, null); |
| 13702 | u.mWifiBatchedScanTimer[i].readSummaryFromParcelLocked(in); |
| 13703 | } |
| 13704 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 13705 | u.mWifiMulticastEnabled = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 13706 | if (in.readInt() != 0) { |
| 13707 | u.mWifiMulticastTimer.readSummaryFromParcelLocked(in); |
| 13708 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 13709 | if (in.readInt() != 0) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 13710 | u.createAudioTurnedOnTimerLocked().readSummaryFromParcelLocked(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 13711 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 13712 | if (in.readInt() != 0) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 13713 | u.createVideoTurnedOnTimerLocked().readSummaryFromParcelLocked(in); |
| 13714 | } |
| 13715 | if (in.readInt() != 0) { |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 13716 | u.createFlashlightTurnedOnTimerLocked().readSummaryFromParcelLocked(in); |
| 13717 | } |
| 13718 | if (in.readInt() != 0) { |
| 13719 | u.createCameraTurnedOnTimerLocked().readSummaryFromParcelLocked(in); |
| 13720 | } |
| 13721 | if (in.readInt() != 0) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 13722 | u.createForegroundActivityTimerLocked().readSummaryFromParcelLocked(in); |
| 13723 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 13724 | if (in.readInt() != 0) { |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 13725 | u.createForegroundServiceTimerLocked().readSummaryFromParcelLocked(in); |
| 13726 | } |
| 13727 | if (in.readInt() != 0) { |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 13728 | u.createAggregatedPartialWakelockTimerLocked().readSummaryFromParcelLocked(in); |
| 13729 | } |
| 13730 | if (in.readInt() != 0) { |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 13731 | u.createBluetoothScanTimerLocked().readSummaryFromParcelLocked(in); |
| 13732 | } |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 13733 | if (in.readInt() != 0) { |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 13734 | u.createBluetoothUnoptimizedScanTimerLocked().readSummaryFromParcelLocked(in); |
| 13735 | } |
| 13736 | if (in.readInt() != 0) { |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 13737 | u.createBluetoothScanResultCounterLocked().readSummaryFromParcelLocked(in); |
| 13738 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 13739 | if (in.readInt() != 0) { |
| 13740 | u.createBluetoothScanResultBgCounterLocked().readSummaryFromParcelLocked(in); |
| 13741 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 13742 | u.mProcessState = ActivityManager.PROCESS_STATE_NONEXISTENT; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 13743 | for (int i = 0; i < Uid.NUM_PROCESS_STATE; i++) { |
| 13744 | if (in.readInt() != 0) { |
| 13745 | u.makeProcessState(i, null); |
| 13746 | u.mProcessStateTimer[i].readSummaryFromParcelLocked(in); |
| 13747 | } |
| 13748 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 13749 | if (in.readInt() != 0) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 13750 | u.createVibratorOnTimerLocked().readSummaryFromParcelLocked(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 13751 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 13752 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 13753 | if (in.readInt() != 0) { |
| 13754 | if (u.mUserActivityCounters == null) { |
| 13755 | u.initUserActivityLocked(); |
| 13756 | } |
| 13757 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
| 13758 | u.mUserActivityCounters[i].readSummaryFromParcelLocked(in); |
| 13759 | } |
| 13760 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 13761 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 13762 | if (in.readInt() != 0) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 13763 | if (u.mNetworkByteActivityCounters == null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 13764 | u.initNetworkActivityLocked(); |
| 13765 | } |
| 13766 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 13767 | u.mNetworkByteActivityCounters[i].readSummaryFromParcelLocked(in); |
| 13768 | u.mNetworkPacketActivityCounters[i].readSummaryFromParcelLocked(in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 13769 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 13770 | u.mMobileRadioActiveTime.readSummaryFromParcelLocked(in); |
| 13771 | u.mMobileRadioActiveCount.readSummaryFromParcelLocked(in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 13772 | } |
| 13773 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 13774 | u.mUserCpuTime.readSummaryFromParcelLocked(in); |
| 13775 | u.mSystemCpuTime.readSummaryFromParcelLocked(in); |
| 13776 | |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 13777 | if (in.readInt() != 0) { |
| 13778 | final int numClusters = in.readInt(); |
| 13779 | if (mPowerProfile != null && mPowerProfile.getNumCpuClusters() != numClusters) { |
| 13780 | throw new ParcelFormatException("Incompatible cpu cluster arrangement"); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 13781 | } |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 13782 | |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 13783 | u.mCpuClusterSpeedTimesUs = new LongSamplingCounter[numClusters][]; |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 13784 | for (int cluster = 0; cluster < numClusters; cluster++) { |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 13785 | if (in.readInt() != 0) { |
Adam Lesinski | a57a540 | 2015-09-28 10:21:33 -0700 | [diff] [blame] | 13786 | final int NSB = in.readInt(); |
| 13787 | if (mPowerProfile != null && |
| 13788 | mPowerProfile.getNumSpeedStepsInCpuCluster(cluster) != NSB) { |
| 13789 | throw new ParcelFormatException("File corrupt: too many speed bins " + |
| 13790 | NSB); |
| 13791 | } |
| 13792 | |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 13793 | u.mCpuClusterSpeedTimesUs[cluster] = new LongSamplingCounter[NSB]; |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 13794 | for (int speed = 0; speed < NSB; speed++) { |
| 13795 | if (in.readInt() != 0) { |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 13796 | u.mCpuClusterSpeedTimesUs[cluster][speed] = new LongSamplingCounter( |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 13797 | mOnBatteryTimeBase); |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 13798 | u.mCpuClusterSpeedTimesUs[cluster][speed].readSummaryFromParcelLocked(in); |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 13799 | } |
| 13800 | } |
Adam Lesinski | a57a540 | 2015-09-28 10:21:33 -0700 | [diff] [blame] | 13801 | } else { |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 13802 | u.mCpuClusterSpeedTimesUs[cluster] = null; |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 13803 | } |
| 13804 | } |
| 13805 | } else { |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 13806 | u.mCpuClusterSpeedTimesUs = null; |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 13807 | } |
| 13808 | |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 13809 | u.mCpuFreqTimeMs = LongSamplingCounterArray.readSummaryFromParcelLocked( |
| 13810 | in, mOnBatteryTimeBase); |
| 13811 | u.mScreenOffCpuFreqTimeMs = LongSamplingCounterArray.readSummaryFromParcelLocked( |
| 13812 | in, mOnBatteryScreenOffTimeBase); |
Mike Ma | 3d422c3 | 2017-10-25 11:08:57 -0700 | [diff] [blame] | 13813 | |
| 13814 | u.mCpuActiveTimeMs.readSummaryFromParcelLocked(in); |
| 13815 | u.mCpuClusterTimesMs.readSummaryFromParcelLocked(in); |
| 13816 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 13817 | int length = in.readInt(); |
| 13818 | if (length == Uid.NUM_PROCESS_STATE) { |
| 13819 | u.mProcStateTimeMs = new LongSamplingCounterArray[length]; |
| 13820 | for (int procState = 0; procState < length; ++procState) { |
| 13821 | u.mProcStateTimeMs[procState] |
| 13822 | = LongSamplingCounterArray.readSummaryFromParcelLocked( |
| 13823 | in, mOnBatteryTimeBase); |
| 13824 | } |
| 13825 | } else { |
| 13826 | u.mProcStateTimeMs = null; |
| 13827 | } |
| 13828 | length = in.readInt(); |
| 13829 | if (length == Uid.NUM_PROCESS_STATE) { |
| 13830 | u.mProcStateScreenOffTimeMs = new LongSamplingCounterArray[length]; |
| 13831 | for (int procState = 0; procState < length; ++procState) { |
| 13832 | u.mProcStateScreenOffTimeMs[procState] |
| 13833 | = LongSamplingCounterArray.readSummaryFromParcelLocked( |
| 13834 | in, mOnBatteryScreenOffTimeBase); |
| 13835 | } |
| 13836 | } else { |
| 13837 | u.mProcStateScreenOffTimeMs = null; |
| 13838 | } |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 13839 | |
| 13840 | if (in.readInt() != 0) { |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 13841 | u.mMobileRadioApWakeupCount = new LongSamplingCounter(mOnBatteryTimeBase); |
| 13842 | u.mMobileRadioApWakeupCount.readSummaryFromParcelLocked(in); |
| 13843 | } else { |
| 13844 | u.mMobileRadioApWakeupCount = null; |
| 13845 | } |
| 13846 | |
| 13847 | if (in.readInt() != 0) { |
| 13848 | u.mWifiRadioApWakeupCount = new LongSamplingCounter(mOnBatteryTimeBase); |
| 13849 | u.mWifiRadioApWakeupCount.readSummaryFromParcelLocked(in); |
| 13850 | } else { |
| 13851 | u.mWifiRadioApWakeupCount = null; |
| 13852 | } |
| 13853 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13854 | int NW = in.readInt(); |
Dianne Hackborn | cb99a72 | 2016-10-03 17:00:02 -0700 | [diff] [blame] | 13855 | if (NW > (MAX_WAKELOCKS_PER_UID+1)) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 13856 | throw new ParcelFormatException("File corrupt: too many wake locks " + NW); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 13857 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13858 | for (int iw = 0; iw < NW; iw++) { |
| 13859 | String wlName = in.readString(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 13860 | u.readWakeSummaryFromParcelLocked(wlName, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13861 | } |
| 13862 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 13863 | int NS = in.readInt(); |
Dianne Hackborn | cb99a72 | 2016-10-03 17:00:02 -0700 | [diff] [blame] | 13864 | if (NS > (MAX_WAKELOCKS_PER_UID+1)) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 13865 | throw new ParcelFormatException("File corrupt: too many syncs " + NS); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 13866 | } |
| 13867 | for (int is = 0; is < NS; is++) { |
| 13868 | String name = in.readString(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 13869 | u.readSyncSummaryFromParcelLocked(name, in); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 13870 | } |
| 13871 | |
| 13872 | int NJ = in.readInt(); |
Dianne Hackborn | cb99a72 | 2016-10-03 17:00:02 -0700 | [diff] [blame] | 13873 | if (NJ > (MAX_WAKELOCKS_PER_UID+1)) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 13874 | throw new ParcelFormatException("File corrupt: too many job timers " + NJ); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 13875 | } |
| 13876 | for (int ij = 0; ij < NJ; ij++) { |
| 13877 | String name = in.readString(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 13878 | u.readJobSummaryFromParcelLocked(name, in); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 13879 | } |
| 13880 | |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 13881 | u.readJobCompletionsFromParcelLocked(in); |
| 13882 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13883 | int NP = in.readInt(); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 13884 | if (NP > 1000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 13885 | throw new ParcelFormatException("File corrupt: too many sensors " + NP); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 13886 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13887 | for (int is = 0; is < NP; is++) { |
| 13888 | int seNumber = in.readInt(); |
| 13889 | if (in.readInt() != 0) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 13890 | u.getSensorTimerLocked(seNumber, true).readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13891 | } |
| 13892 | } |
| 13893 | |
| 13894 | NP = in.readInt(); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 13895 | if (NP > 1000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 13896 | throw new ParcelFormatException("File corrupt: too many processes " + NP); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 13897 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13898 | for (int ip = 0; ip < NP; ip++) { |
| 13899 | String procName = in.readString(); |
| 13900 | Uid.Proc p = u.getProcessStatsLocked(procName); |
| 13901 | p.mUserTime = p.mLoadedUserTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13902 | p.mSystemTime = p.mLoadedSystemTime = in.readLong(); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 13903 | p.mForegroundTime = p.mLoadedForegroundTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13904 | p.mStarts = p.mLoadedStarts = in.readInt(); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 13905 | p.mNumCrashes = p.mLoadedNumCrashes = in.readInt(); |
| 13906 | p.mNumAnrs = p.mLoadedNumAnrs = in.readInt(); |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 13907 | p.readExcessivePowerFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13908 | } |
| 13909 | |
| 13910 | NP = in.readInt(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 13911 | if (NP > 10000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 13912 | throw new ParcelFormatException("File corrupt: too many packages " + NP); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 13913 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13914 | for (int ip = 0; ip < NP; ip++) { |
| 13915 | String pkgName = in.readString(); |
| 13916 | Uid.Pkg p = u.getPackageStatsLocked(pkgName); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 13917 | final int NWA = in.readInt(); |
| 13918 | if (NWA > 1000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 13919 | throw new ParcelFormatException("File corrupt: too many wakeup alarms " + NWA); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 13920 | } |
| 13921 | p.mWakeupAlarms.clear(); |
| 13922 | for (int iwa=0; iwa<NWA; iwa++) { |
| 13923 | String tag = in.readString(); |
Bookatz | 98d4d5c | 2017-08-01 19:07:54 -0700 | [diff] [blame] | 13924 | Counter c = new Counter(mOnBatteryScreenOffTimeBase); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 13925 | c.readSummaryFromParcelLocked(in); |
| 13926 | p.mWakeupAlarms.put(tag, c); |
| 13927 | } |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 13928 | NS = in.readInt(); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 13929 | if (NS > 1000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 13930 | throw new ParcelFormatException("File corrupt: too many services " + NS); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 13931 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13932 | for (int is = 0; is < NS; is++) { |
| 13933 | String servName = in.readString(); |
| 13934 | Uid.Pkg.Serv s = u.getServiceStatsLocked(pkgName, servName); |
| 13935 | s.mStartTime = s.mLoadedStartTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13936 | s.mStarts = s.mLoadedStarts = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13937 | s.mLaunches = s.mLoadedLaunches = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13938 | } |
| 13939 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13940 | } |
| 13941 | } |
| 13942 | |
| 13943 | /** |
| 13944 | * Writes a summary of the statistics to a Parcel, in a format suitable to be written to |
| 13945 | * disk. This format does not allow a lossless round-trip. |
| 13946 | * |
| 13947 | * @param out the Parcel to be written to. |
| 13948 | */ |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 13949 | public void writeSummaryToParcel(Parcel out, boolean inclHistory) { |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 13950 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 13951 | |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 13952 | // Pull the clock time. This may update the time and make a new history entry |
| 13953 | // if we had originally pulled a time before the RTC was set. |
| 13954 | long startClockTime = getStartClockTime(); |
| 13955 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 13956 | final long NOW_SYS = mClocks.uptimeMillis() * 1000; |
| 13957 | final long NOWREAL_SYS = mClocks.elapsedRealtime() * 1000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13958 | |
| 13959 | out.writeInt(VERSION); |
| 13960 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 13961 | writeHistory(out, inclHistory, true); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 13962 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13963 | out.writeInt(mStartCount); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 13964 | out.writeLong(computeUptime(NOW_SYS, STATS_SINCE_CHARGED)); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 13965 | out.writeLong(computeRealtime(NOWREAL_SYS, STATS_SINCE_CHARGED)); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 13966 | out.writeLong(startClockTime); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 13967 | out.writeString(mStartPlatformVersion); |
| 13968 | out.writeString(mEndPlatformVersion); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 13969 | mOnBatteryTimeBase.writeSummaryToParcel(out, NOW_SYS, NOWREAL_SYS); |
| 13970 | mOnBatteryScreenOffTimeBase.writeSummaryToParcel(out, NOW_SYS, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 13971 | out.writeInt(mDischargeUnplugLevel); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 13972 | out.writeInt(mDischargePlugLevel); |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 13973 | out.writeInt(mDischargeCurrentLevel); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 13974 | out.writeInt(mCurrentBatteryLevel); |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 13975 | out.writeInt(mEstimatedBatteryCapacity); |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 13976 | out.writeInt(mMinLearnedBatteryCapacity); |
| 13977 | out.writeInt(mMaxLearnedBatteryCapacity); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 13978 | out.writeInt(getLowDischargeAmountSinceCharge()); |
| 13979 | out.writeInt(getHighDischargeAmountSinceCharge()); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 13980 | out.writeInt(getDischargeAmountScreenOnSinceCharge()); |
| 13981 | out.writeInt(getDischargeAmountScreenOffSinceCharge()); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 13982 | out.writeInt(getDischargeAmountScreenDozeSinceCharge()); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 13983 | mDischargeStepTracker.writeToParcel(out); |
| 13984 | mChargeStepTracker.writeToParcel(out); |
| 13985 | mDailyDischargeStepTracker.writeToParcel(out); |
| 13986 | mDailyChargeStepTracker.writeToParcel(out); |
Adam Lesinski | 67c134f | 2016-06-10 15:15:08 -0700 | [diff] [blame] | 13987 | mDischargeCounter.writeSummaryFromParcelLocked(out); |
| 13988 | mDischargeScreenOffCounter.writeSummaryFromParcelLocked(out); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 13989 | mDischargeScreenDozeCounter.writeSummaryFromParcelLocked(out); |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 13990 | mDischargeLightDozeCounter.writeSummaryFromParcelLocked(out); |
| 13991 | mDischargeDeepDozeCounter.writeSummaryFromParcelLocked(out); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 13992 | if (mDailyPackageChanges != null) { |
| 13993 | final int NPKG = mDailyPackageChanges.size(); |
| 13994 | out.writeInt(NPKG); |
| 13995 | for (int i=0; i<NPKG; i++) { |
| 13996 | PackageChange pc = mDailyPackageChanges.get(i); |
| 13997 | out.writeString(pc.mPackageName); |
| 13998 | out.writeInt(pc.mUpdate ? 1 : 0); |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 13999 | out.writeLong(pc.mVersionCode); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 14000 | } |
| 14001 | } else { |
| 14002 | out.writeInt(0); |
| 14003 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 14004 | out.writeLong(mDailyStartTime); |
| 14005 | out.writeLong(mNextMinDailyDeadline); |
| 14006 | out.writeLong(mNextMaxDailyDeadline); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14007 | |
| 14008 | mScreenOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 14009 | mScreenDozeTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 14010 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14011 | mScreenBrightnessTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 14012 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 14013 | mInteractiveTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 14014 | mPowerSaveModeEnabledTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 14015 | out.writeLong(mLongestLightIdleTime); |
| 14016 | out.writeLong(mLongestFullIdleTime); |
| 14017 | mDeviceIdleModeLightTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14018 | mDeviceIdleModeFullTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14019 | mDeviceLightIdlingTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 14020 | mDeviceIdlingTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14021 | mPhoneOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 14022 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14023 | mPhoneSignalStrengthsTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 14024 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14025 | mPhoneSignalScanningTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 14026 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14027 | mPhoneDataConnectionsTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 14028 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 14029 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 14030 | mNetworkByteActivityCounters[i].writeSummaryFromParcelLocked(out); |
| 14031 | mNetworkPacketActivityCounters[i].writeSummaryFromParcelLocked(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 14032 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14033 | mMobileRadioActiveTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14034 | mMobileRadioActivePerAppTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 14035 | mMobileRadioActiveAdjustedTime.writeSummaryFromParcelLocked(out); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 14036 | mMobileRadioActiveUnknownTime.writeSummaryFromParcelLocked(out); |
| 14037 | mMobileRadioActiveUnknownCount.writeSummaryFromParcelLocked(out); |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 14038 | mWifiMulticastWakelockTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14039 | mWifiOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14040 | mGlobalWifiRunningTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 14041 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14042 | mWifiStateTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 14043 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 14044 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 14045 | mWifiSupplStateTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14046 | } |
| 14047 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 14048 | mWifiSignalStrengthsTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14049 | } |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 14050 | mWifiActiveTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14051 | mWifiActivity.writeSummaryToParcel(out); |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 14052 | for (int i=0; i< GnssMetrics.NUM_GPS_SIGNAL_QUALITY_LEVELS; i++) { |
| 14053 | mGpsSignalQualityTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14054 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 14055 | mBluetoothActivity.writeSummaryToParcel(out); |
| 14056 | mModemActivity.writeSummaryToParcel(out); |
| 14057 | out.writeInt(mHasWifiReporting ? 1 : 0); |
| 14058 | out.writeInt(mHasBluetoothReporting ? 1 : 0); |
| 14059 | out.writeInt(mHasModemReporting ? 1 : 0); |
| 14060 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 14061 | out.writeInt(mNumConnectivityChange); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 14062 | mFlashlightOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 14063 | mCameraOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 14064 | mBluetoothScanTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14065 | |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 14066 | out.writeInt(mRpmStats.size()); |
| 14067 | for (Map.Entry<String, SamplingTimer> ent : mRpmStats.entrySet()) { |
| 14068 | Timer rpmt = ent.getValue(); |
| 14069 | if (rpmt != null) { |
| 14070 | out.writeInt(1); |
| 14071 | out.writeString(ent.getKey()); |
| 14072 | rpmt.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14073 | } else { |
| 14074 | out.writeInt(0); |
| 14075 | } |
| 14076 | } |
| 14077 | out.writeInt(mScreenOffRpmStats.size()); |
| 14078 | for (Map.Entry<String, SamplingTimer> ent : mScreenOffRpmStats.entrySet()) { |
| 14079 | Timer rpmt = ent.getValue(); |
| 14080 | if (rpmt != null) { |
| 14081 | out.writeInt(1); |
| 14082 | out.writeString(ent.getKey()); |
| 14083 | rpmt.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14084 | } else { |
| 14085 | out.writeInt(0); |
| 14086 | } |
| 14087 | } |
| 14088 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 14089 | out.writeInt(mKernelWakelockStats.size()); |
| 14090 | for (Map.Entry<String, SamplingTimer> ent : mKernelWakelockStats.entrySet()) { |
| 14091 | Timer kwlt = ent.getValue(); |
| 14092 | if (kwlt != null) { |
| 14093 | out.writeInt(1); |
| 14094 | out.writeString(ent.getKey()); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 14095 | kwlt.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14096 | } else { |
| 14097 | out.writeInt(0); |
| 14098 | } |
| 14099 | } |
| 14100 | |
| 14101 | out.writeInt(mWakeupReasonStats.size()); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 14102 | for (Map.Entry<String, SamplingTimer> ent : mWakeupReasonStats.entrySet()) { |
| 14103 | SamplingTimer timer = ent.getValue(); |
| 14104 | if (timer != null) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 14105 | out.writeInt(1); |
| 14106 | out.writeString(ent.getKey()); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 14107 | timer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 14108 | } else { |
| 14109 | out.writeInt(0); |
| 14110 | } |
| 14111 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 14112 | |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 14113 | out.writeInt(mKernelMemoryStats.size()); |
| 14114 | for (int i = 0; i < mKernelMemoryStats.size(); i++) { |
| 14115 | Timer kmt = mKernelMemoryStats.valueAt(i); |
| 14116 | if (kmt != null) { |
| 14117 | out.writeInt(1); |
| 14118 | out.writeLong(mKernelMemoryStats.keyAt(i)); |
| 14119 | kmt.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14120 | } else { |
| 14121 | out.writeInt(0); |
| 14122 | } |
| 14123 | } |
| 14124 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14125 | final int NU = mUidStats.size(); |
| 14126 | out.writeInt(NU); |
| 14127 | for (int iu = 0; iu < NU; iu++) { |
| 14128 | out.writeInt(mUidStats.keyAt(iu)); |
| 14129 | Uid u = mUidStats.valueAt(iu); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 14130 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 14131 | u.mOnBatteryBackgroundTimeBase.writeSummaryToParcel(out, NOW_SYS, NOWREAL_SYS); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 14132 | u.mOnBatteryScreenOffBackgroundTimeBase.writeSummaryToParcel(out, NOW_SYS, NOWREAL_SYS); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 14133 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 14134 | if (u.mWifiRunningTimer != null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 14135 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14136 | u.mWifiRunningTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 14137 | } else { |
| 14138 | out.writeInt(0); |
| 14139 | } |
| 14140 | if (u.mFullWifiLockTimer != null) { |
| 14141 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14142 | u.mFullWifiLockTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 14143 | } else { |
| 14144 | out.writeInt(0); |
| 14145 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 14146 | if (u.mWifiScanTimer != null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 14147 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14148 | u.mWifiScanTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 14149 | } else { |
| 14150 | out.writeInt(0); |
| 14151 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 14152 | for (int i = 0; i < Uid.NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 14153 | if (u.mWifiBatchedScanTimer[i] != null) { |
| 14154 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14155 | u.mWifiBatchedScanTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 14156 | } else { |
| 14157 | out.writeInt(0); |
| 14158 | } |
| 14159 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 14160 | if (u.mWifiMulticastTimer != null) { |
| 14161 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14162 | u.mWifiMulticastTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 14163 | } else { |
| 14164 | out.writeInt(0); |
| 14165 | } |
| 14166 | if (u.mAudioTurnedOnTimer != null) { |
| 14167 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14168 | u.mAudioTurnedOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 14169 | } else { |
| 14170 | out.writeInt(0); |
| 14171 | } |
| 14172 | if (u.mVideoTurnedOnTimer != null) { |
| 14173 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14174 | u.mVideoTurnedOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 14175 | } else { |
| 14176 | out.writeInt(0); |
| 14177 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 14178 | if (u.mFlashlightTurnedOnTimer != null) { |
| 14179 | out.writeInt(1); |
| 14180 | u.mFlashlightTurnedOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14181 | } else { |
| 14182 | out.writeInt(0); |
| 14183 | } |
| 14184 | if (u.mCameraTurnedOnTimer != null) { |
| 14185 | out.writeInt(1); |
| 14186 | u.mCameraTurnedOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14187 | } else { |
| 14188 | out.writeInt(0); |
| 14189 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 14190 | if (u.mForegroundActivityTimer != null) { |
| 14191 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14192 | u.mForegroundActivityTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 14193 | } else { |
| 14194 | out.writeInt(0); |
| 14195 | } |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 14196 | if (u.mForegroundServiceTimer != null) { |
| 14197 | out.writeInt(1); |
| 14198 | u.mForegroundServiceTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14199 | } else { |
| 14200 | out.writeInt(0); |
| 14201 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 14202 | if (u.mAggregatedPartialWakelockTimer != null) { |
| 14203 | out.writeInt(1); |
| 14204 | u.mAggregatedPartialWakelockTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14205 | } else { |
| 14206 | out.writeInt(0); |
| 14207 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 14208 | if (u.mBluetoothScanTimer != null) { |
| 14209 | out.writeInt(1); |
| 14210 | u.mBluetoothScanTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14211 | } else { |
| 14212 | out.writeInt(0); |
| 14213 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 14214 | if (u.mBluetoothUnoptimizedScanTimer != null) { |
| 14215 | out.writeInt(1); |
| 14216 | u.mBluetoothUnoptimizedScanTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14217 | } else { |
| 14218 | out.writeInt(0); |
| 14219 | } |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 14220 | if (u.mBluetoothScanResultCounter != null) { |
| 14221 | out.writeInt(1); |
| 14222 | u.mBluetoothScanResultCounter.writeSummaryFromParcelLocked(out); |
| 14223 | } else { |
| 14224 | out.writeInt(0); |
| 14225 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 14226 | if (u.mBluetoothScanResultBgCounter != null) { |
| 14227 | out.writeInt(1); |
| 14228 | u.mBluetoothScanResultBgCounter.writeSummaryFromParcelLocked(out); |
| 14229 | } else { |
| 14230 | out.writeInt(0); |
| 14231 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 14232 | for (int i = 0; i < Uid.NUM_PROCESS_STATE; i++) { |
| 14233 | if (u.mProcessStateTimer[i] != null) { |
| 14234 | out.writeInt(1); |
| 14235 | u.mProcessStateTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14236 | } else { |
| 14237 | out.writeInt(0); |
| 14238 | } |
| 14239 | } |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 14240 | if (u.mVibratorOnTimer != null) { |
| 14241 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14242 | u.mVibratorOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 14243 | } else { |
| 14244 | out.writeInt(0); |
| 14245 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14246 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 14247 | if (u.mUserActivityCounters == null) { |
| 14248 | out.writeInt(0); |
| 14249 | } else { |
| 14250 | out.writeInt(1); |
| 14251 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
| 14252 | u.mUserActivityCounters[i].writeSummaryFromParcelLocked(out); |
| 14253 | } |
| 14254 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 14255 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 14256 | if (u.mNetworkByteActivityCounters == null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 14257 | out.writeInt(0); |
| 14258 | } else { |
| 14259 | out.writeInt(1); |
| 14260 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 14261 | u.mNetworkByteActivityCounters[i].writeSummaryFromParcelLocked(out); |
| 14262 | u.mNetworkPacketActivityCounters[i].writeSummaryFromParcelLocked(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 14263 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 14264 | u.mMobileRadioActiveTime.writeSummaryFromParcelLocked(out); |
| 14265 | u.mMobileRadioActiveCount.writeSummaryFromParcelLocked(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 14266 | } |
| 14267 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 14268 | u.mUserCpuTime.writeSummaryFromParcelLocked(out); |
| 14269 | u.mSystemCpuTime.writeSummaryFromParcelLocked(out); |
| 14270 | |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 14271 | if (u.mCpuClusterSpeedTimesUs != null) { |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 14272 | out.writeInt(1); |
Sudheer Shanka | af85741 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 14273 | out.writeInt(u.mCpuClusterSpeedTimesUs.length); |
| 14274 | for (LongSamplingCounter[] cpuSpeeds : u.mCpuClusterSpeedTimesUs) { |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 14275 | if (cpuSpeeds != null) { |
| 14276 | out.writeInt(1); |
| 14277 | out.writeInt(cpuSpeeds.length); |
| 14278 | for (LongSamplingCounter c : cpuSpeeds) { |
| 14279 | if (c != null) { |
| 14280 | out.writeInt(1); |
| 14281 | c.writeSummaryFromParcelLocked(out); |
| 14282 | } else { |
| 14283 | out.writeInt(0); |
| 14284 | } |
| 14285 | } |
| 14286 | } else { |
| 14287 | out.writeInt(0); |
| 14288 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 14289 | } |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 14290 | } else { |
| 14291 | out.writeInt(0); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 14292 | } |
| 14293 | |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 14294 | LongSamplingCounterArray.writeSummaryToParcelLocked(out, u.mCpuFreqTimeMs); |
| 14295 | LongSamplingCounterArray.writeSummaryToParcelLocked(out, u.mScreenOffCpuFreqTimeMs); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 14296 | |
Mike Ma | 3d422c3 | 2017-10-25 11:08:57 -0700 | [diff] [blame] | 14297 | u.mCpuActiveTimeMs.writeSummaryFromParcelLocked(out); |
| 14298 | u.mCpuClusterTimesMs.writeSummaryToParcelLocked(out); |
| 14299 | |
Sudheer Shanka | b2f83c1 | 2017-11-13 19:25:01 -0800 | [diff] [blame] | 14300 | if (u.mProcStateTimeMs != null) { |
| 14301 | out.writeInt(u.mProcStateTimeMs.length); |
| 14302 | for (LongSamplingCounterArray counters : u.mProcStateTimeMs) { |
| 14303 | LongSamplingCounterArray.writeSummaryToParcelLocked(out, counters); |
| 14304 | } |
| 14305 | } else { |
| 14306 | out.writeInt(0); |
| 14307 | } |
| 14308 | if (u.mProcStateScreenOffTimeMs != null) { |
| 14309 | out.writeInt(u.mProcStateScreenOffTimeMs.length); |
| 14310 | for (LongSamplingCounterArray counters : u.mProcStateScreenOffTimeMs) { |
| 14311 | LongSamplingCounterArray.writeSummaryToParcelLocked(out, counters); |
| 14312 | } |
| 14313 | } else { |
| 14314 | out.writeInt(0); |
| 14315 | } |
| 14316 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 14317 | if (u.mMobileRadioApWakeupCount != null) { |
| 14318 | out.writeInt(1); |
| 14319 | u.mMobileRadioApWakeupCount.writeSummaryFromParcelLocked(out); |
| 14320 | } else { |
| 14321 | out.writeInt(0); |
| 14322 | } |
| 14323 | |
| 14324 | if (u.mWifiRadioApWakeupCount != null) { |
| 14325 | out.writeInt(1); |
| 14326 | u.mWifiRadioApWakeupCount.writeSummaryFromParcelLocked(out); |
| 14327 | } else { |
| 14328 | out.writeInt(0); |
| 14329 | } |
| 14330 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 14331 | final ArrayMap<String, Uid.Wakelock> wakeStats = u.mWakelockStats.getMap(); |
| 14332 | int NW = wakeStats.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14333 | out.writeInt(NW); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 14334 | for (int iw=0; iw<NW; iw++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 14335 | out.writeString(wakeStats.keyAt(iw)); |
| 14336 | Uid.Wakelock wl = wakeStats.valueAt(iw); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 14337 | if (wl.mTimerFull != null) { |
| 14338 | out.writeInt(1); |
| 14339 | wl.mTimerFull.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14340 | } else { |
| 14341 | out.writeInt(0); |
| 14342 | } |
| 14343 | if (wl.mTimerPartial != null) { |
| 14344 | out.writeInt(1); |
| 14345 | wl.mTimerPartial.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14346 | } else { |
| 14347 | out.writeInt(0); |
| 14348 | } |
| 14349 | if (wl.mTimerWindow != null) { |
| 14350 | out.writeInt(1); |
| 14351 | wl.mTimerWindow.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14352 | } else { |
| 14353 | out.writeInt(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14354 | } |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 14355 | if (wl.mTimerDraw != null) { |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 14356 | out.writeInt(1); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 14357 | wl.mTimerDraw.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 14358 | } else { |
| 14359 | out.writeInt(0); |
| 14360 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14361 | } |
| 14362 | |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 14363 | final ArrayMap<String, DualTimer> syncStats = u.mSyncStats.getMap(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 14364 | int NS = syncStats.size(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 14365 | out.writeInt(NS); |
| 14366 | for (int is=0; is<NS; is++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 14367 | out.writeString(syncStats.keyAt(is)); |
| 14368 | syncStats.valueAt(is).writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 14369 | } |
| 14370 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 14371 | final ArrayMap<String, DualTimer> jobStats = u.mJobStats.getMap(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 14372 | int NJ = jobStats.size(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 14373 | out.writeInt(NJ); |
| 14374 | for (int ij=0; ij<NJ; ij++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 14375 | out.writeString(jobStats.keyAt(ij)); |
| 14376 | jobStats.valueAt(ij).writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 14377 | } |
| 14378 | |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 14379 | u.writeJobCompletionsToParcelLocked(out); |
| 14380 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14381 | int NSE = u.mSensorStats.size(); |
| 14382 | out.writeInt(NSE); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 14383 | for (int ise=0; ise<NSE; ise++) { |
| 14384 | out.writeInt(u.mSensorStats.keyAt(ise)); |
| 14385 | Uid.Sensor se = u.mSensorStats.valueAt(ise); |
| 14386 | if (se.mTimer != null) { |
| 14387 | out.writeInt(1); |
| 14388 | se.mTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 14389 | } else { |
| 14390 | out.writeInt(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14391 | } |
| 14392 | } |
| 14393 | |
| 14394 | int NP = u.mProcessStats.size(); |
| 14395 | out.writeInt(NP); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 14396 | for (int ip=0; ip<NP; ip++) { |
| 14397 | out.writeString(u.mProcessStats.keyAt(ip)); |
| 14398 | Uid.Proc ps = u.mProcessStats.valueAt(ip); |
| 14399 | out.writeLong(ps.mUserTime); |
| 14400 | out.writeLong(ps.mSystemTime); |
| 14401 | out.writeLong(ps.mForegroundTime); |
| 14402 | out.writeInt(ps.mStarts); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 14403 | out.writeInt(ps.mNumCrashes); |
| 14404 | out.writeInt(ps.mNumAnrs); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 14405 | ps.writeExcessivePowerToParcelLocked(out); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14406 | } |
| 14407 | |
| 14408 | NP = u.mPackageStats.size(); |
| 14409 | out.writeInt(NP); |
| 14410 | if (NP > 0) { |
| 14411 | for (Map.Entry<String, BatteryStatsImpl.Uid.Pkg> ent |
| 14412 | : u.mPackageStats.entrySet()) { |
| 14413 | out.writeString(ent.getKey()); |
| 14414 | Uid.Pkg ps = ent.getValue(); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 14415 | final int NWA = ps.mWakeupAlarms.size(); |
| 14416 | out.writeInt(NWA); |
| 14417 | for (int iwa=0; iwa<NWA; iwa++) { |
| 14418 | out.writeString(ps.mWakeupAlarms.keyAt(iwa)); |
| 14419 | ps.mWakeupAlarms.valueAt(iwa).writeSummaryFromParcelLocked(out); |
| 14420 | } |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 14421 | NS = ps.mServiceStats.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14422 | out.writeInt(NS); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 14423 | for (int is=0; is<NS; is++) { |
| 14424 | out.writeString(ps.mServiceStats.keyAt(is)); |
| 14425 | BatteryStatsImpl.Uid.Pkg.Serv ss = ps.mServiceStats.valueAt(is); |
| 14426 | long time = ss.getStartTimeToNowLocked( |
| 14427 | mOnBatteryTimeBase.getUptime(NOW_SYS)); |
| 14428 | out.writeLong(time); |
| 14429 | out.writeInt(ss.mStarts); |
| 14430 | out.writeInt(ss.mLaunches); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14431 | } |
| 14432 | } |
| 14433 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14434 | } |
| 14435 | } |
| 14436 | |
| 14437 | public void readFromParcel(Parcel in) { |
| 14438 | readFromParcelLocked(in); |
| 14439 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 14440 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14441 | void readFromParcelLocked(Parcel in) { |
| 14442 | int magic = in.readInt(); |
| 14443 | if (magic != MAGIC) { |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 14444 | throw new ParcelFormatException("Bad magic number: #" + Integer.toHexString(magic)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14445 | } |
| 14446 | |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 14447 | readHistory(in, false); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 14448 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14449 | mStartCount = in.readInt(); |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 14450 | mStartClockTime = in.readLong(); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 14451 | mStartPlatformVersion = in.readString(); |
| 14452 | mEndPlatformVersion = in.readString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14453 | mUptime = in.readLong(); |
| 14454 | mUptimeStart = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14455 | mRealtime = in.readLong(); |
| 14456 | mRealtimeStart = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14457 | mOnBattery = in.readInt() != 0; |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 14458 | mEstimatedBatteryCapacity = in.readInt(); |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 14459 | mMinLearnedBatteryCapacity = in.readInt(); |
| 14460 | mMaxLearnedBatteryCapacity = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14461 | mOnBatteryInternal = false; // we are no longer really running. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14462 | mOnBatteryTimeBase.readFromParcel(in); |
| 14463 | mOnBatteryScreenOffTimeBase.readFromParcel(in); |
| 14464 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 14465 | mScreenState = Display.STATE_UNKNOWN; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14466 | mScreenOnTimer = new StopwatchTimer(mClocks, null, -1, null, mOnBatteryTimeBase, in); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 14467 | mScreenDozeTimer = new StopwatchTimer(mClocks, null, -1, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14468 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14469 | mScreenBrightnessTimer[i] = new StopwatchTimer(mClocks, null, -100-i, null, |
| 14470 | mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14471 | } |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 14472 | mInteractive = false; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14473 | mInteractiveTimer = new StopwatchTimer(mClocks, null, -10, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14474 | mPhoneOn = false; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14475 | mPowerSaveModeEnabledTimer = new StopwatchTimer(mClocks, null, -2, null, |
| 14476 | mOnBatteryTimeBase, in); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 14477 | mLongestLightIdleTime = in.readLong(); |
| 14478 | mLongestFullIdleTime = in.readLong(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14479 | mDeviceIdleModeLightTimer = new StopwatchTimer(mClocks, null, -14, null, |
| 14480 | mOnBatteryTimeBase, in); |
| 14481 | mDeviceIdleModeFullTimer = new StopwatchTimer(mClocks, null, -11, null, |
| 14482 | mOnBatteryTimeBase, in); |
| 14483 | mDeviceLightIdlingTimer = new StopwatchTimer(mClocks, null, -15, null, |
| 14484 | mOnBatteryTimeBase, in); |
| 14485 | mDeviceIdlingTimer = new StopwatchTimer(mClocks, null, -12, null, mOnBatteryTimeBase, in); |
| 14486 | mPhoneOnTimer = new StopwatchTimer(mClocks, null, -3, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14487 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14488 | mPhoneSignalStrengthsTimer[i] = new StopwatchTimer(mClocks, null, -200-i, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14489 | null, mOnBatteryTimeBase, in); |
| 14490 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14491 | mPhoneSignalScanningTimer = new StopwatchTimer(mClocks, null, -200+1, null, |
| 14492 | mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14493 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14494 | mPhoneDataConnectionsTimer[i] = new StopwatchTimer(mClocks, null, -300-i, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14495 | null, mOnBatteryTimeBase, in); |
| 14496 | } |
| 14497 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
| 14498 | mNetworkByteActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 14499 | mNetworkPacketActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 14500 | } |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 14501 | mMobileRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14502 | mMobileRadioActiveTimer = new StopwatchTimer(mClocks, null, -400, null, |
| 14503 | mOnBatteryTimeBase, in); |
Kweku Adams | 87b19ec | 2017-10-09 12:40:03 -0700 | [diff] [blame] | 14504 | mMobileRadioActivePerAppTimer = new StopwatchTimer(mClocks, null, -401, null, |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14505 | mOnBatteryTimeBase, in); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 14506 | mMobileRadioActiveAdjustedTime = new LongSamplingCounter(mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14507 | mMobileRadioActiveUnknownTime = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 14508 | mMobileRadioActiveUnknownCount = new LongSamplingCounter(mOnBatteryTimeBase, in); |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 14509 | mWifiMulticastWakelockTimer = new StopwatchTimer(mClocks, null, -4, null, |
| 14510 | mOnBatteryTimeBase, in); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 14511 | mWifiRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14512 | mWifiOn = false; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14513 | mWifiOnTimer = new StopwatchTimer(mClocks, null, -4, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14514 | mGlobalWifiRunning = false; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14515 | mGlobalWifiRunningTimer = new StopwatchTimer(mClocks, null, -5, null, |
| 14516 | mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14517 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14518 | mWifiStateTimer[i] = new StopwatchTimer(mClocks, null, -600-i, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14519 | null, mOnBatteryTimeBase, in); |
| 14520 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 14521 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14522 | mWifiSupplStateTimer[i] = new StopwatchTimer(mClocks, null, -700-i, |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 14523 | null, mOnBatteryTimeBase, in); |
| 14524 | } |
| 14525 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14526 | mWifiSignalStrengthsTimer[i] = new StopwatchTimer(mClocks, null, -800-i, |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 14527 | null, mOnBatteryTimeBase, in); |
| 14528 | } |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 14529 | mWifiActiveTimer = new StopwatchTimer(mClocks, null, -900, null, |
| 14530 | mOnBatteryTimeBase, in); |
| 14531 | mWifiActivity = new ControllerActivityCounterImpl(mOnBatteryTimeBase, |
| 14532 | NUM_WIFI_TX_LEVELS, in); |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 14533 | for (int i=0; i<GnssMetrics.NUM_GPS_SIGNAL_QUALITY_LEVELS; i++) { |
| 14534 | mGpsSignalQualityTimer[i] = new StopwatchTimer(mClocks, null, -1000-i, |
| 14535 | null, mOnBatteryTimeBase, in); |
| 14536 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 14537 | mBluetoothActivity = new ControllerActivityCounterImpl(mOnBatteryTimeBase, |
| 14538 | NUM_BT_TX_LEVELS, in); |
| 14539 | mModemActivity = new ControllerActivityCounterImpl(mOnBatteryTimeBase, |
| 14540 | ModemActivityInfo.TX_POWER_LEVELS, in); |
| 14541 | mHasWifiReporting = in.readInt() != 0; |
| 14542 | mHasBluetoothReporting = in.readInt() != 0; |
| 14543 | mHasModemReporting = in.readInt() != 0; |
| 14544 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 14545 | mNumConnectivityChange = in.readInt(); |
| 14546 | mLoadedNumConnectivityChange = in.readInt(); |
| 14547 | mUnpluggedNumConnectivityChange = in.readInt(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 14548 | mAudioOnNesting = 0; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14549 | mAudioOnTimer = new StopwatchTimer(mClocks, null, -7, null, mOnBatteryTimeBase); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 14550 | mVideoOnNesting = 0; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14551 | mVideoOnTimer = new StopwatchTimer(mClocks, null, -8, null, mOnBatteryTimeBase); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 14552 | mFlashlightOnNesting = 0; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14553 | mFlashlightOnTimer = new StopwatchTimer(mClocks, null, -9, null, mOnBatteryTimeBase, in); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 14554 | mCameraOnNesting = 0; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14555 | mCameraOnTimer = new StopwatchTimer(mClocks, null, -13, null, mOnBatteryTimeBase, in); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 14556 | mBluetoothScanNesting = 0; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14557 | mBluetoothScanTimer = new StopwatchTimer(mClocks, null, -14, null, mOnBatteryTimeBase, in); |
Siddharth Ray | f5e796a | 2018-01-22 18:18:17 -0800 | [diff] [blame] | 14558 | mIsCellularTxPowerHigh = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 14559 | mDischargeUnplugLevel = in.readInt(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 14560 | mDischargePlugLevel = in.readInt(); |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 14561 | mDischargeCurrentLevel = in.readInt(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 14562 | mCurrentBatteryLevel = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 14563 | mLowDischargeAmountSinceCharge = in.readInt(); |
| 14564 | mHighDischargeAmountSinceCharge = in.readInt(); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 14565 | mDischargeAmountScreenOn = in.readInt(); |
| 14566 | mDischargeAmountScreenOnSinceCharge = in.readInt(); |
| 14567 | mDischargeAmountScreenOff = in.readInt(); |
| 14568 | mDischargeAmountScreenOffSinceCharge = in.readInt(); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 14569 | mDischargeAmountScreenDoze = in.readInt(); |
| 14570 | mDischargeAmountScreenDozeSinceCharge = in.readInt(); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 14571 | mDischargeStepTracker.readFromParcel(in); |
| 14572 | mChargeStepTracker.readFromParcel(in); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 14573 | mDischargeCounter = new LongSamplingCounter(mOnBatteryTimeBase, in); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 14574 | mDischargeScreenOffCounter = new LongSamplingCounter(mOnBatteryScreenOffTimeBase, in); |
| 14575 | mDischargeScreenDozeCounter = new LongSamplingCounter(mOnBatteryTimeBase, in); |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 14576 | mDischargeLightDozeCounter = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 14577 | mDischargeDeepDozeCounter = new LongSamplingCounter(mOnBatteryTimeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14578 | mLastWriteTime = in.readLong(); |
| 14579 | |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 14580 | mRpmStats.clear(); |
| 14581 | int NRPMS = in.readInt(); |
| 14582 | for (int irpm = 0; irpm < NRPMS; irpm++) { |
| 14583 | if (in.readInt() != 0) { |
| 14584 | String rpmName = in.readString(); |
| 14585 | SamplingTimer rpmt = new SamplingTimer(mClocks, mOnBatteryTimeBase, in); |
| 14586 | mRpmStats.put(rpmName, rpmt); |
| 14587 | } |
| 14588 | } |
| 14589 | mScreenOffRpmStats.clear(); |
| 14590 | int NSORPMS = in.readInt(); |
| 14591 | for (int irpm = 0; irpm < NSORPMS; irpm++) { |
| 14592 | if (in.readInt() != 0) { |
| 14593 | String rpmName = in.readString(); |
| 14594 | SamplingTimer rpmt = new SamplingTimer(mClocks, mOnBatteryScreenOffTimeBase, in); |
| 14595 | mScreenOffRpmStats.put(rpmName, rpmt); |
| 14596 | } |
| 14597 | } |
| 14598 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 14599 | mKernelWakelockStats.clear(); |
| 14600 | int NKW = in.readInt(); |
| 14601 | for (int ikw = 0; ikw < NKW; ikw++) { |
| 14602 | if (in.readInt() != 0) { |
| 14603 | String wakelockName = in.readString(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14604 | SamplingTimer kwlt = new SamplingTimer(mClocks, mOnBatteryScreenOffTimeBase, in); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 14605 | mKernelWakelockStats.put(wakelockName, kwlt); |
| 14606 | } |
| 14607 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 14608 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 14609 | mWakeupReasonStats.clear(); |
| 14610 | int NWR = in.readInt(); |
| 14611 | for (int iwr = 0; iwr < NWR; iwr++) { |
| 14612 | if (in.readInt() != 0) { |
| 14613 | String reasonName = in.readString(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14614 | SamplingTimer timer = new SamplingTimer(mClocks, mOnBatteryTimeBase, in); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 14615 | mWakeupReasonStats.put(reasonName, timer); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 14616 | } |
| 14617 | } |
| 14618 | |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 14619 | mKernelMemoryStats.clear(); |
| 14620 | int nmt = in.readInt(); |
| 14621 | for (int imt = 0; imt < nmt; imt++) { |
| 14622 | if (in.readInt() != 0) { |
| 14623 | Long bucket = in.readLong(); |
| 14624 | SamplingTimer kmt = new SamplingTimer(mClocks, mOnBatteryTimeBase, in); |
| 14625 | mKernelMemoryStats.put(bucket, kmt); |
| 14626 | } |
| 14627 | } |
| 14628 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14629 | mPartialTimers.clear(); |
| 14630 | mFullTimers.clear(); |
| 14631 | mWindowTimers.clear(); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 14632 | mWifiRunningTimers.clear(); |
| 14633 | mFullWifiLockTimers.clear(); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 14634 | mWifiScanTimers.clear(); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 14635 | mWifiBatchedScanTimers.clear(); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 14636 | mWifiMulticastTimers.clear(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 14637 | mAudioTurnedOnTimers.clear(); |
| 14638 | mVideoTurnedOnTimers.clear(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 14639 | mFlashlightTurnedOnTimers.clear(); |
| 14640 | mCameraTurnedOnTimers.clear(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14641 | |
| 14642 | int numUids = in.readInt(); |
| 14643 | mUidStats.clear(); |
| 14644 | for (int i = 0; i < numUids; i++) { |
| 14645 | int uid = in.readInt(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14646 | Uid u = new Uid(this, uid); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14647 | u.readFromParcelLocked(mOnBatteryTimeBase, mOnBatteryScreenOffTimeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14648 | mUidStats.append(uid, u); |
| 14649 | } |
| 14650 | } |
| 14651 | |
| 14652 | public void writeToParcel(Parcel out, int flags) { |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 14653 | writeToParcelLocked(out, true, flags); |
| 14654 | } |
| 14655 | |
| 14656 | public void writeToParcelWithoutUids(Parcel out, int flags) { |
| 14657 | writeToParcelLocked(out, false, flags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14658 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 14659 | |
| 14660 | @SuppressWarnings("unused") |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 14661 | void writeToParcelLocked(Parcel out, boolean inclUids, int flags) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 14662 | // Need to update with current kernel wake lock counts. |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 14663 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 14664 | |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 14665 | // Pull the clock time. This may update the time and make a new history entry |
| 14666 | // if we had originally pulled a time before the RTC was set. |
| 14667 | long startClockTime = getStartClockTime(); |
| 14668 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 14669 | final long uSecUptime = mClocks.uptimeMillis() * 1000; |
| 14670 | final long uSecRealtime = mClocks.elapsedRealtime() * 1000; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14671 | final long batteryRealtime = mOnBatteryTimeBase.getRealtime(uSecRealtime); |
| 14672 | final long batteryScreenOffRealtime = mOnBatteryScreenOffTimeBase.getRealtime(uSecRealtime); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 14673 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14674 | out.writeInt(MAGIC); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 14675 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 14676 | writeHistory(out, true, false); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 14677 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14678 | out.writeInt(mStartCount); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 14679 | out.writeLong(startClockTime); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 14680 | out.writeString(mStartPlatformVersion); |
| 14681 | out.writeString(mEndPlatformVersion); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14682 | out.writeLong(mUptime); |
| 14683 | out.writeLong(mUptimeStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14684 | out.writeLong(mRealtime); |
| 14685 | out.writeLong(mRealtimeStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14686 | out.writeInt(mOnBattery ? 1 : 0); |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 14687 | out.writeInt(mEstimatedBatteryCapacity); |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 14688 | out.writeInt(mMinLearnedBatteryCapacity); |
| 14689 | out.writeInt(mMaxLearnedBatteryCapacity); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14690 | mOnBatteryTimeBase.writeToParcel(out, uSecUptime, uSecRealtime); |
| 14691 | mOnBatteryScreenOffTimeBase.writeToParcel(out, uSecUptime, uSecRealtime); |
| 14692 | |
| 14693 | mScreenOnTimer.writeToParcel(out, uSecRealtime); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 14694 | mScreenDozeTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14695 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
| 14696 | mScreenBrightnessTimer[i].writeToParcel(out, uSecRealtime); |
| 14697 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 14698 | mInteractiveTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 14699 | mPowerSaveModeEnabledTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 14700 | out.writeLong(mLongestLightIdleTime); |
| 14701 | out.writeLong(mLongestFullIdleTime); |
| 14702 | mDeviceIdleModeLightTimer.writeToParcel(out, uSecRealtime); |
| 14703 | mDeviceIdleModeFullTimer.writeToParcel(out, uSecRealtime); |
| 14704 | mDeviceLightIdlingTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 14705 | mDeviceIdlingTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14706 | mPhoneOnTimer.writeToParcel(out, uSecRealtime); |
| 14707 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
| 14708 | mPhoneSignalStrengthsTimer[i].writeToParcel(out, uSecRealtime); |
| 14709 | } |
| 14710 | mPhoneSignalScanningTimer.writeToParcel(out, uSecRealtime); |
| 14711 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
| 14712 | mPhoneDataConnectionsTimer[i].writeToParcel(out, uSecRealtime); |
| 14713 | } |
| 14714 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
| 14715 | mNetworkByteActivityCounters[i].writeToParcel(out); |
| 14716 | mNetworkPacketActivityCounters[i].writeToParcel(out); |
| 14717 | } |
| 14718 | mMobileRadioActiveTimer.writeToParcel(out, uSecRealtime); |
| 14719 | mMobileRadioActivePerAppTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 14720 | mMobileRadioActiveAdjustedTime.writeToParcel(out); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14721 | mMobileRadioActiveUnknownTime.writeToParcel(out); |
| 14722 | mMobileRadioActiveUnknownCount.writeToParcel(out); |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 14723 | mWifiMulticastWakelockTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14724 | mWifiOnTimer.writeToParcel(out, uSecRealtime); |
| 14725 | mGlobalWifiRunningTimer.writeToParcel(out, uSecRealtime); |
| 14726 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 14727 | mWifiStateTimer[i].writeToParcel(out, uSecRealtime); |
| 14728 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 14729 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 14730 | mWifiSupplStateTimer[i].writeToParcel(out, uSecRealtime); |
| 14731 | } |
| 14732 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 14733 | mWifiSignalStrengthsTimer[i].writeToParcel(out, uSecRealtime); |
| 14734 | } |
Siddharth Ray | b50a684 | 2017-12-14 15:15:28 -0800 | [diff] [blame] | 14735 | mWifiActiveTimer.writeToParcel(out, uSecRealtime); |
| 14736 | mWifiActivity.writeToParcel(out, 0); |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 14737 | for (int i=0; i< GnssMetrics.NUM_GPS_SIGNAL_QUALITY_LEVELS; i++) { |
| 14738 | mGpsSignalQualityTimer[i].writeToParcel(out, uSecRealtime); |
| 14739 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 14740 | mBluetoothActivity.writeToParcel(out, 0); |
| 14741 | mModemActivity.writeToParcel(out, 0); |
| 14742 | out.writeInt(mHasWifiReporting ? 1 : 0); |
| 14743 | out.writeInt(mHasBluetoothReporting ? 1 : 0); |
| 14744 | out.writeInt(mHasModemReporting ? 1 : 0); |
| 14745 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 14746 | out.writeInt(mNumConnectivityChange); |
| 14747 | out.writeInt(mLoadedNumConnectivityChange); |
| 14748 | out.writeInt(mUnpluggedNumConnectivityChange); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 14749 | mFlashlightOnTimer.writeToParcel(out, uSecRealtime); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 14750 | mCameraOnTimer.writeToParcel(out, uSecRealtime); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 14751 | mBluetoothScanTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 14752 | out.writeInt(mDischargeUnplugLevel); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 14753 | out.writeInt(mDischargePlugLevel); |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 14754 | out.writeInt(mDischargeCurrentLevel); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 14755 | out.writeInt(mCurrentBatteryLevel); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 14756 | out.writeInt(mLowDischargeAmountSinceCharge); |
| 14757 | out.writeInt(mHighDischargeAmountSinceCharge); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 14758 | out.writeInt(mDischargeAmountScreenOn); |
| 14759 | out.writeInt(mDischargeAmountScreenOnSinceCharge); |
| 14760 | out.writeInt(mDischargeAmountScreenOff); |
| 14761 | out.writeInt(mDischargeAmountScreenOffSinceCharge); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 14762 | out.writeInt(mDischargeAmountScreenDoze); |
| 14763 | out.writeInt(mDischargeAmountScreenDozeSinceCharge); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 14764 | mDischargeStepTracker.writeToParcel(out); |
| 14765 | mChargeStepTracker.writeToParcel(out); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 14766 | mDischargeCounter.writeToParcel(out); |
| 14767 | mDischargeScreenOffCounter.writeToParcel(out); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 14768 | mDischargeScreenDozeCounter.writeToParcel(out); |
Mike Ma | 15313c9 | 2017-11-15 17:58:21 -0800 | [diff] [blame] | 14769 | mDischargeLightDozeCounter.writeToParcel(out); |
| 14770 | mDischargeDeepDozeCounter.writeToParcel(out); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14771 | out.writeLong(mLastWriteTime); |
| 14772 | |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame] | 14773 | out.writeInt(mRpmStats.size()); |
| 14774 | for (Map.Entry<String, SamplingTimer> ent : mRpmStats.entrySet()) { |
| 14775 | SamplingTimer rpmt = ent.getValue(); |
| 14776 | if (rpmt != null) { |
| 14777 | out.writeInt(1); |
| 14778 | out.writeString(ent.getKey()); |
| 14779 | rpmt.writeToParcel(out, uSecRealtime); |
| 14780 | } else { |
| 14781 | out.writeInt(0); |
| 14782 | } |
| 14783 | } |
| 14784 | out.writeInt(mScreenOffRpmStats.size()); |
| 14785 | for (Map.Entry<String, SamplingTimer> ent : mScreenOffRpmStats.entrySet()) { |
| 14786 | SamplingTimer rpmt = ent.getValue(); |
| 14787 | if (rpmt != null) { |
| 14788 | out.writeInt(1); |
| 14789 | out.writeString(ent.getKey()); |
| 14790 | rpmt.writeToParcel(out, uSecRealtime); |
| 14791 | } else { |
| 14792 | out.writeInt(0); |
| 14793 | } |
| 14794 | } |
| 14795 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 14796 | if (inclUids) { |
| 14797 | out.writeInt(mKernelWakelockStats.size()); |
| 14798 | for (Map.Entry<String, SamplingTimer> ent : mKernelWakelockStats.entrySet()) { |
| 14799 | SamplingTimer kwlt = ent.getValue(); |
| 14800 | if (kwlt != null) { |
| 14801 | out.writeInt(1); |
| 14802 | out.writeString(ent.getKey()); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 14803 | kwlt.writeToParcel(out, uSecRealtime); |
| 14804 | } else { |
| 14805 | out.writeInt(0); |
| 14806 | } |
| 14807 | } |
| 14808 | out.writeInt(mWakeupReasonStats.size()); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 14809 | for (Map.Entry<String, SamplingTimer> ent : mWakeupReasonStats.entrySet()) { |
| 14810 | SamplingTimer timer = ent.getValue(); |
| 14811 | if (timer != null) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 14812 | out.writeInt(1); |
| 14813 | out.writeString(ent.getKey()); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 14814 | timer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 14815 | } else { |
| 14816 | out.writeInt(0); |
| 14817 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 14818 | } |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 14819 | } else { |
Bookatz | ba78b2b | 2017-10-10 11:06:33 -0700 | [diff] [blame] | 14820 | out.writeInt(0); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 14821 | out.writeInt(0); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 14822 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 14823 | |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 14824 | out.writeInt(mKernelMemoryStats.size()); |
| 14825 | for (int i = 0; i < mKernelMemoryStats.size(); i++) { |
| 14826 | SamplingTimer kmt = mKernelMemoryStats.valueAt(i); |
| 14827 | if (kmt != null) { |
| 14828 | out.writeInt(1); |
| 14829 | out.writeLong(mKernelMemoryStats.keyAt(i)); |
| 14830 | kmt.writeToParcel(out, uSecRealtime); |
| 14831 | } else { |
| 14832 | out.writeInt(0); |
| 14833 | } |
| 14834 | } |
| 14835 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 14836 | if (inclUids) { |
| 14837 | int size = mUidStats.size(); |
| 14838 | out.writeInt(size); |
| 14839 | for (int i = 0; i < size; i++) { |
| 14840 | out.writeInt(mUidStats.keyAt(i)); |
| 14841 | Uid uid = mUidStats.valueAt(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14842 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 14843 | uid.writeToParcelLocked(out, uSecUptime, uSecRealtime); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 14844 | } |
| 14845 | } else { |
| 14846 | out.writeInt(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14847 | } |
| 14848 | } |
| 14849 | |
| 14850 | public static final Parcelable.Creator<BatteryStatsImpl> CREATOR = |
| 14851 | new Parcelable.Creator<BatteryStatsImpl>() { |
| 14852 | public BatteryStatsImpl createFromParcel(Parcel in) { |
| 14853 | return new BatteryStatsImpl(in); |
| 14854 | } |
| 14855 | |
| 14856 | public BatteryStatsImpl[] newArray(int size) { |
| 14857 | return new BatteryStatsImpl[size]; |
| 14858 | } |
| 14859 | }; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 14860 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 14861 | public void prepareForDumpLocked() { |
| 14862 | // Need to retrieve current kernel wake lock stats before printing. |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 14863 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 14864 | |
| 14865 | // Pull the clock time. This may update the time and make a new history entry |
| 14866 | // if we had originally pulled a time before the RTC was set. |
| 14867 | getStartClockTime(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 14868 | } |
| 14869 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 14870 | 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] | 14871 | if (DEBUG) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 14872 | pw.println("mOnBatteryTimeBase:"); |
| 14873 | mOnBatteryTimeBase.dump(pw, " "); |
| 14874 | pw.println("mOnBatteryScreenOffTimeBase:"); |
| 14875 | mOnBatteryScreenOffTimeBase.dump(pw, " "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 14876 | Printer pr = new PrintWriterPrinter(pw); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 14877 | pr.println("*** Screen on timer:"); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 14878 | mScreenOnTimer.logState(pr, " "); |
Mike Ma | c2f518a | 2017-09-19 16:06:03 -0700 | [diff] [blame] | 14879 | pr.println("*** Screen doze timer:"); |
| 14880 | mScreenDozeTimer.logState(pr, " "); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 14881 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 14882 | pr.println("*** Screen brightness #" + i + ":"); |
| 14883 | mScreenBrightnessTimer[i].logState(pr, " "); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 14884 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 14885 | pr.println("*** Interactive timer:"); |
| 14886 | mInteractiveTimer.logState(pr, " "); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 14887 | pr.println("*** Power save mode timer:"); |
| 14888 | mPowerSaveModeEnabledTimer.logState(pr, " "); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 14889 | pr.println("*** Device idle mode light timer:"); |
| 14890 | mDeviceIdleModeLightTimer.logState(pr, " "); |
| 14891 | pr.println("*** Device idle mode full timer:"); |
| 14892 | mDeviceIdleModeFullTimer.logState(pr, " "); |
| 14893 | pr.println("*** Device light idling timer:"); |
| 14894 | mDeviceLightIdlingTimer.logState(pr, " "); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 14895 | pr.println("*** Device idling timer:"); |
| 14896 | mDeviceIdlingTimer.logState(pr, " "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 14897 | pr.println("*** Phone timer:"); |
| 14898 | mPhoneOnTimer.logState(pr, " "); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 14899 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 14900 | pr.println("*** Phone signal strength #" + i + ":"); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 14901 | mPhoneSignalStrengthsTimer[i].logState(pr, " "); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 14902 | } |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 14903 | pr.println("*** Signal scanning :"); |
| 14904 | mPhoneSignalScanningTimer.logState(pr, " "); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 14905 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 14906 | pr.println("*** Data connection type #" + i + ":"); |
| 14907 | mPhoneDataConnectionsTimer[i].logState(pr, " "); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 14908 | } |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 14909 | pr.println("*** mMobileRadioPowerState=" + mMobileRadioPowerState); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 14910 | pr.println("*** Mobile network active timer:"); |
| 14911 | mMobileRadioActiveTimer.logState(pr, " "); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 14912 | pr.println("*** Mobile network active adjusted timer:"); |
| 14913 | mMobileRadioActiveAdjustedTime.logState(pr, " "); |
Ahmed ElArabawy | f88571f | 2017-11-28 12:18:10 -0800 | [diff] [blame] | 14914 | pr.println("*** Wifi Multicast WakeLock Timer:"); |
| 14915 | mWifiMulticastWakelockTimer.logState(pr, " "); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 14916 | pr.println("*** mWifiRadioPowerState=" + mWifiRadioPowerState); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 14917 | pr.println("*** Wifi timer:"); |
| 14918 | mWifiOnTimer.logState(pr, " "); |
| 14919 | pr.println("*** WifiRunning timer:"); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 14920 | mGlobalWifiRunningTimer.logState(pr, " "); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 14921 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 14922 | pr.println("*** Wifi state #" + i + ":"); |
| 14923 | mWifiStateTimer[i].logState(pr, " "); |
| 14924 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 14925 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 14926 | pr.println("*** Wifi suppl state #" + i + ":"); |
| 14927 | mWifiSupplStateTimer[i].logState(pr, " "); |
| 14928 | } |
| 14929 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 14930 | pr.println("*** Wifi signal strength #" + i + ":"); |
| 14931 | mWifiSignalStrengthsTimer[i].logState(pr, " "); |
| 14932 | } |
Siddharth Ray | 78ccaf5 | 2017-12-23 16:16:21 -0800 | [diff] [blame] | 14933 | for (int i=0; i<GnssMetrics.NUM_GPS_SIGNAL_QUALITY_LEVELS; i++) { |
| 14934 | pr.println("*** GPS signal quality #" + i + ":"); |
| 14935 | mGpsSignalQualityTimer[i].logState(pr, " "); |
| 14936 | } |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 14937 | pr.println("*** Flashlight timer:"); |
| 14938 | mFlashlightOnTimer.logState(pr, " "); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 14939 | pr.println("*** Camera timer:"); |
| 14940 | mCameraOnTimer.logState(pr, " "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14941 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 14942 | super.dumpLocked(context, pw, flags, reqUid, histStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14943 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14944 | } |