Bookatz | 9472641 | 2017-08-31 09:26:15 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 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 | package com.android.server.stats; |
| 17 | |
Chenjie Yu | 05013b3 | 2017-11-21 10:21:41 -0800 | [diff] [blame] | 18 | import android.annotation.Nullable; |
Rajeev Kumar | 22d92b7 | 2018-02-07 18:38:36 -0800 | [diff] [blame] | 19 | import android.app.ActivityManagerInternal; |
Bookatz | 9472641 | 2017-08-31 09:26:15 -0700 | [diff] [blame] | 20 | import android.app.AlarmManager; |
| 21 | import android.app.PendingIntent; |
Rajeev Kumar | 22d92b7 | 2018-02-07 18:38:36 -0800 | [diff] [blame] | 22 | import android.app.ProcessMemoryState; |
Bookatz | c697797 | 2018-01-16 16:55:05 -0800 | [diff] [blame] | 23 | import android.app.StatsManager; |
Chenjie Yu | 9d7720b | 2018-01-24 10:34:48 -0800 | [diff] [blame] | 24 | import android.bluetooth.BluetoothActivityEnergyInfo; |
| 25 | import android.bluetooth.BluetoothAdapter; |
| 26 | import android.bluetooth.UidTraffic; |
Bookatz | 9472641 | 2017-08-31 09:26:15 -0700 | [diff] [blame] | 27 | import android.content.BroadcastReceiver; |
| 28 | import android.content.Context; |
| 29 | import android.content.Intent; |
David Chen | de70169 | 2017-10-05 13:16:02 -0700 | [diff] [blame] | 30 | import android.content.IntentFilter; |
Bookatz | c697797 | 2018-01-16 16:55:05 -0800 | [diff] [blame] | 31 | import android.content.IntentSender; |
David Chen | de70169 | 2017-10-05 13:16:02 -0700 | [diff] [blame] | 32 | import android.content.pm.PackageInfo; |
| 33 | import android.content.pm.PackageManager; |
| 34 | import android.content.pm.UserInfo; |
David Chen | c8a4324 | 2017-10-17 16:23:28 -0700 | [diff] [blame] | 35 | import android.net.NetworkStats; |
Chenjie Yu | 05013b3 | 2017-11-21 10:21:41 -0800 | [diff] [blame] | 36 | import android.net.wifi.IWifiManager; |
| 37 | import android.net.wifi.WifiActivityEnergyInfo; |
David Chen | c8a4324 | 2017-10-17 16:23:28 -0700 | [diff] [blame] | 38 | import android.os.BatteryStatsInternal; |
Bookatz | 9472641 | 2017-08-31 09:26:15 -0700 | [diff] [blame] | 39 | import android.os.Binder; |
David Chen | de70169 | 2017-10-05 13:16:02 -0700 | [diff] [blame] | 40 | import android.os.Bundle; |
Chenjie Yu | 937d742 | 2018-01-10 16:37:53 -0800 | [diff] [blame] | 41 | import android.os.Environment; |
yro | e26c97b | 2018-03-27 10:30:11 -0700 | [diff] [blame] | 42 | import android.os.FileUtils; |
Bookatz | b487b55 | 2017-09-18 11:26:01 -0700 | [diff] [blame] | 43 | import android.os.IBinder; |
Bookatz | 9472641 | 2017-08-31 09:26:15 -0700 | [diff] [blame] | 44 | import android.os.IStatsCompanionService; |
| 45 | import android.os.IStatsManager; |
Chenjie Yu | 05013b3 | 2017-11-21 10:21:41 -0800 | [diff] [blame] | 46 | import android.os.Parcelable; |
Bookatz | 9472641 | 2017-08-31 09:26:15 -0700 | [diff] [blame] | 47 | import android.os.Process; |
Bookatz | 1b0b114 | 2017-09-08 11:58:42 -0700 | [diff] [blame] | 48 | import android.os.RemoteException; |
Bookatz | 9472641 | 2017-08-31 09:26:15 -0700 | [diff] [blame] | 49 | import android.os.ServiceManager; |
Chenjie Yu | 937d742 | 2018-01-10 16:37:53 -0800 | [diff] [blame] | 50 | import android.os.StatFs; |
Chenjie Yu | 9d7720b | 2018-01-24 10:34:48 -0800 | [diff] [blame] | 51 | import android.os.StatsDimensionsValue; |
David Chen | 1481fe1 | 2017-10-16 13:16:34 -0700 | [diff] [blame] | 52 | import android.os.StatsLogEventWrapper; |
Chenjie Yu | 05013b3 | 2017-11-21 10:21:41 -0800 | [diff] [blame] | 53 | import android.os.SynchronousResultReceiver; |
Chenjie Yu | 937d742 | 2018-01-10 16:37:53 -0800 | [diff] [blame] | 54 | import android.os.SystemClock; |
David Chen | de70169 | 2017-10-05 13:16:02 -0700 | [diff] [blame] | 55 | import android.os.UserHandle; |
| 56 | import android.os.UserManager; |
Chenjie Yu | 937d742 | 2018-01-10 16:37:53 -0800 | [diff] [blame] | 57 | import android.telephony.ModemActivityInfo; |
| 58 | import android.telephony.TelephonyManager; |
Bookatz | 9472641 | 2017-08-31 09:26:15 -0700 | [diff] [blame] | 59 | import android.util.Slog; |
David Chen | c8a4324 | 2017-10-17 16:23:28 -0700 | [diff] [blame] | 60 | import android.util.StatsLog; |
| 61 | |
| 62 | import com.android.internal.annotations.GuardedBy; |
| 63 | import com.android.internal.net.NetworkStatsFactory; |
Chenjie Yu | 937d742 | 2018-01-10 16:37:53 -0800 | [diff] [blame] | 64 | import com.android.internal.os.KernelCpuSpeedReader; |
Chenjie Yu | ec67661 | 2018-03-07 09:19:17 -0800 | [diff] [blame] | 65 | import com.android.internal.os.KernelUidCpuTimeReader; |
| 66 | import com.android.internal.os.KernelUidCpuClusterTimeReader; |
| 67 | import com.android.internal.os.KernelUidCpuActiveTimeReader; |
| 68 | import com.android.internal.os.KernelUidCpuFreqTimeReader; |
David Chen | c8a4324 | 2017-10-17 16:23:28 -0700 | [diff] [blame] | 69 | import com.android.internal.os.KernelWakelockReader; |
| 70 | import com.android.internal.os.KernelWakelockStats; |
Chenjie Yu | 7f8def9 | 2017-11-03 09:33:15 -0700 | [diff] [blame] | 71 | import com.android.internal.os.PowerProfile; |
yro | e26c97b | 2018-03-27 10:30:11 -0700 | [diff] [blame] | 72 | import com.android.internal.util.DumpUtils; |
David Chen | c8a4324 | 2017-10-17 16:23:28 -0700 | [diff] [blame] | 73 | import com.android.server.LocalServices; |
| 74 | import com.android.server.SystemService; |
Bookatz | 9472641 | 2017-08-31 09:26:15 -0700 | [diff] [blame] | 75 | |
yro | e26c97b | 2018-03-27 10:30:11 -0700 | [diff] [blame] | 76 | import java.io.File; |
| 77 | import java.io.FileDescriptor; |
Chenjie Yu | ec67661 | 2018-03-07 09:19:17 -0800 | [diff] [blame] | 78 | import java.io.IOException; |
yro | e26c97b | 2018-03-27 10:30:11 -0700 | [diff] [blame] | 79 | import java.io.PrintWriter; |
David Chen | de70169 | 2017-10-05 13:16:02 -0700 | [diff] [blame] | 80 | import java.util.ArrayList; |
Bookatz | 058d869 | 2018-03-06 09:53:47 -0800 | [diff] [blame] | 81 | import java.util.Arrays; |
yro | e26c97b | 2018-03-27 10:30:11 -0700 | [diff] [blame] | 82 | import java.util.HashMap; |
| 83 | import java.util.HashSet; |
David Chen | de70169 | 2017-10-05 13:16:02 -0700 | [diff] [blame] | 84 | import java.util.List; |
Bookatz | c68a9d2 | 2017-09-27 14:09:55 -0700 | [diff] [blame] | 85 | import java.util.Map; |
yro | e26c97b | 2018-03-27 10:30:11 -0700 | [diff] [blame] | 86 | import java.util.concurrent.TimeUnit; |
Chenjie Yu | 05013b3 | 2017-11-21 10:21:41 -0800 | [diff] [blame] | 87 | import java.util.concurrent.TimeoutException; |
Bookatz | c68a9d2 | 2017-09-27 14:09:55 -0700 | [diff] [blame] | 88 | |
Bookatz | 9472641 | 2017-08-31 09:26:15 -0700 | [diff] [blame] | 89 | /** |
| 90 | * Helper service for statsd (the native stats management service in cmds/statsd/). |
| 91 | * Used for registering and receiving alarms on behalf of statsd. |
David Chen | 1481fe1 | 2017-10-16 13:16:34 -0700 | [diff] [blame] | 92 | * |
Bookatz | 6bc51d7 | 2017-09-28 16:43:40 -0700 | [diff] [blame] | 93 | * @hide |
Bookatz | 9472641 | 2017-08-31 09:26:15 -0700 | [diff] [blame] | 94 | */ |
| 95 | public class StatsCompanionService extends IStatsCompanionService.Stub { |
Chenjie Yu | 05013b3 | 2017-11-21 10:21:41 -0800 | [diff] [blame] | 96 | /** |
| 97 | * How long to wait on an individual subsystem to return its stats. |
| 98 | */ |
| 99 | private static final long EXTERNAL_STATS_SYNC_TIMEOUT_MILLIS = 2000; |
yro | e26c97b | 2018-03-27 10:30:11 -0700 | [diff] [blame] | 100 | private static final long MILLIS_IN_A_DAY = TimeUnit.DAYS.toMillis(1); |
Chenjie Yu | 05013b3 | 2017-11-21 10:21:41 -0800 | [diff] [blame] | 101 | |
| 102 | public static final String RESULT_RECEIVER_CONTROLLER_KEY = "controller_activity"; |
yro | e26c97b | 2018-03-27 10:30:11 -0700 | [diff] [blame] | 103 | public static final String CONFIG_DIR = "/data/misc/stats-service"; |
Chenjie Yu | 05013b3 | 2017-11-21 10:21:41 -0800 | [diff] [blame] | 104 | |
Bookatz | 9472641 | 2017-08-31 09:26:15 -0700 | [diff] [blame] | 105 | static final String TAG = "StatsCompanionService"; |
Tej Singh | 484524a | 2018-02-01 15:10:05 -0800 | [diff] [blame] | 106 | static final boolean DEBUG = false; |
Bookatz | c697797 | 2018-01-16 16:55:05 -0800 | [diff] [blame] | 107 | |
David Chen | 661f791 | 2018-01-22 17:46:24 -0800 | [diff] [blame] | 108 | public static final int CODE_DATA_BROADCAST = 1; |
Bookatz | c697797 | 2018-01-16 16:55:05 -0800 | [diff] [blame] | 109 | public static final int CODE_SUBSCRIBER_BROADCAST = 1; |
David Chen | d37bc23 | 2018-04-12 18:05:11 -0700 | [diff] [blame] | 110 | /** |
| 111 | * The last report time is provided with each intent registered to |
| 112 | * StatsManager#setFetchReportsOperation. This allows easy de-duping in the receiver if |
| 113 | * statsd is requesting the client to retrieve the same statsd data. The last report time |
| 114 | * corresponds to the last_report_elapsed_nanos that will provided in the current |
| 115 | * ConfigMetricsReport, and this timestamp also corresponds to the |
| 116 | * current_report_elapsed_nanos of the most recently obtained ConfigMetricsReport. |
| 117 | */ |
| 118 | public static final String EXTRA_LAST_REPORT_TIME = "android.app.extra.LAST_REPORT_TIME"; |
yro | e26c97b | 2018-03-27 10:30:11 -0700 | [diff] [blame] | 119 | public static final int DEATH_THRESHOLD = 10; |
Bookatz | c697797 | 2018-01-16 16:55:05 -0800 | [diff] [blame] | 120 | |
Bookatz | 9472641 | 2017-08-31 09:26:15 -0700 | [diff] [blame] | 121 | private final Context mContext; |
| 122 | private final AlarmManager mAlarmManager; |
Bookatz | b487b55 | 2017-09-18 11:26:01 -0700 | [diff] [blame] | 123 | @GuardedBy("sStatsdLock") |
Bookatz | 1b0b114 | 2017-09-08 11:58:42 -0700 | [diff] [blame] | 124 | private static IStatsManager sStatsd; |
Bookatz | b487b55 | 2017-09-18 11:26:01 -0700 | [diff] [blame] | 125 | private static final Object sStatsdLock = new Object(); |
Bookatz | 9472641 | 2017-08-31 09:26:15 -0700 | [diff] [blame] | 126 | |
| 127 | private final PendingIntent mAnomalyAlarmIntent; |
Chenjie Yu | b3dda41 | 2017-10-24 13:41:59 -0700 | [diff] [blame] | 128 | private final PendingIntent mPullingAlarmIntent; |
Yangster-mac | 932ecec | 2018-02-01 10:23:52 -0800 | [diff] [blame] | 129 | private final PendingIntent mPeriodicAlarmIntent; |
David Chen | de70169 | 2017-10-05 13:16:02 -0700 | [diff] [blame] | 130 | private final BroadcastReceiver mAppUpdateReceiver; |
David Chen | 47e8f4d | 2017-10-11 15:34:13 -0700 | [diff] [blame] | 131 | private final BroadcastReceiver mUserUpdateReceiver; |
yro | 947fbce | 2017-11-15 22:50:23 -0800 | [diff] [blame] | 132 | private final ShutdownEventReceiver mShutdownEventReceiver; |
Chenjie Yu | 7f8def9 | 2017-11-03 09:33:15 -0700 | [diff] [blame] | 133 | private final KernelWakelockReader mKernelWakelockReader = new KernelWakelockReader(); |
| 134 | private final KernelWakelockStats mTmpWakelockStats = new KernelWakelockStats(); |
Chenjie Yu | 05013b3 | 2017-11-21 10:21:41 -0800 | [diff] [blame] | 135 | private IWifiManager mWifiManager = null; |
| 136 | private TelephonyManager mTelephony = null; |
Chenjie Yu | 937d742 | 2018-01-10 16:37:53 -0800 | [diff] [blame] | 137 | private final StatFs mStatFsData = new StatFs(Environment.getDataDirectory().getAbsolutePath()); |
| 138 | private final StatFs mStatFsSystem = |
David Chen | 661f791 | 2018-01-22 17:46:24 -0800 | [diff] [blame] | 139 | new StatFs(Environment.getRootDirectory().getAbsolutePath()); |
Chenjie Yu | 937d742 | 2018-01-10 16:37:53 -0800 | [diff] [blame] | 140 | private final StatFs mStatFsTemp = |
David Chen | 661f791 | 2018-01-22 17:46:24 -0800 | [diff] [blame] | 141 | new StatFs(Environment.getDownloadCacheDirectory().getAbsolutePath()); |
yro | e26c97b | 2018-03-27 10:30:11 -0700 | [diff] [blame] | 142 | @GuardedBy("sStatsdLock") |
| 143 | private final HashSet<Long> mDeathTimeMillis = new HashSet<>(); |
| 144 | @GuardedBy("sStatsdLock") |
| 145 | private final HashMap<Long, String> mDeletedFiles = new HashMap<>(); |
Bookatz | 9472641 | 2017-08-31 09:26:15 -0700 | [diff] [blame] | 146 | |
Chenjie Yu | ec67661 | 2018-03-07 09:19:17 -0800 | [diff] [blame] | 147 | private KernelUidCpuTimeReader mKernelUidCpuTimeReader = new KernelUidCpuTimeReader(); |
| 148 | private KernelCpuSpeedReader[] mKernelCpuSpeedReaders; |
| 149 | private KernelUidCpuFreqTimeReader mKernelUidCpuFreqTimeReader = |
| 150 | new KernelUidCpuFreqTimeReader(); |
| 151 | private KernelUidCpuActiveTimeReader mKernelUidCpuActiveTimeReader = |
| 152 | new KernelUidCpuActiveTimeReader(); |
| 153 | private KernelUidCpuClusterTimeReader mKernelUidCpuClusterTimeReader = |
| 154 | new KernelUidCpuClusterTimeReader(); |
| 155 | |
Bookatz | 9472641 | 2017-08-31 09:26:15 -0700 | [diff] [blame] | 156 | public StatsCompanionService(Context context) { |
| 157 | super(); |
| 158 | mContext = context; |
| 159 | mAlarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE); |
| 160 | |
| 161 | mAnomalyAlarmIntent = PendingIntent.getBroadcast(mContext, 0, |
| 162 | new Intent(mContext, AnomalyAlarmReceiver.class), 0); |
Chenjie Yu | b3dda41 | 2017-10-24 13:41:59 -0700 | [diff] [blame] | 163 | mPullingAlarmIntent = PendingIntent.getBroadcast( |
David Chen | 661f791 | 2018-01-22 17:46:24 -0800 | [diff] [blame] | 164 | mContext, 0, new Intent(mContext, PullingAlarmReceiver.class), 0); |
Yangster-mac | 932ecec | 2018-02-01 10:23:52 -0800 | [diff] [blame] | 165 | mPeriodicAlarmIntent = PendingIntent.getBroadcast( |
| 166 | mContext, 0, new Intent(mContext, PeriodicAlarmReceiver.class), 0); |
David Chen | de70169 | 2017-10-05 13:16:02 -0700 | [diff] [blame] | 167 | mAppUpdateReceiver = new AppUpdateReceiver(); |
David Chen | 47e8f4d | 2017-10-11 15:34:13 -0700 | [diff] [blame] | 168 | mUserUpdateReceiver = new BroadcastReceiver() { |
| 169 | @Override |
| 170 | public void onReceive(Context context, Intent intent) { |
| 171 | synchronized (sStatsdLock) { |
| 172 | sStatsd = fetchStatsdService(); |
| 173 | if (sStatsd == null) { |
Bookatz | 111ed73 | 2018-02-16 15:54:05 -0800 | [diff] [blame] | 174 | Slog.w(TAG, "Could not access statsd for UserUpdateReceiver"); |
David Chen | 47e8f4d | 2017-10-11 15:34:13 -0700 | [diff] [blame] | 175 | return; |
| 176 | } |
| 177 | try { |
| 178 | // Pull the latest state of UID->app name, version mapping. |
| 179 | // Needed since the new user basically has a version of every app. |
| 180 | informAllUidsLocked(context); |
| 181 | } catch (RemoteException e) { |
David Chen | 1481fe1 | 2017-10-16 13:16:34 -0700 | [diff] [blame] | 182 | Slog.e(TAG, "Failed to inform statsd latest update of all apps", e); |
yro | e26c97b | 2018-03-27 10:30:11 -0700 | [diff] [blame] | 183 | forgetEverythingLocked(); |
David Chen | 47e8f4d | 2017-10-11 15:34:13 -0700 | [diff] [blame] | 184 | } |
| 185 | } |
| 186 | } |
| 187 | }; |
yro | 947fbce | 2017-11-15 22:50:23 -0800 | [diff] [blame] | 188 | mShutdownEventReceiver = new ShutdownEventReceiver(); |
Bookatz | 111ed73 | 2018-02-16 15:54:05 -0800 | [diff] [blame] | 189 | if (DEBUG) Slog.d(TAG, "Registered receiver for ACTION_PACKAGE_REPLACED and ADDED."); |
Chenjie Yu | 7f8def9 | 2017-11-03 09:33:15 -0700 | [diff] [blame] | 190 | PowerProfile powerProfile = new PowerProfile(context); |
| 191 | final int numClusters = powerProfile.getNumCpuClusters(); |
| 192 | mKernelCpuSpeedReaders = new KernelCpuSpeedReader[numClusters]; |
| 193 | int firstCpuOfCluster = 0; |
| 194 | for (int i = 0; i < numClusters; i++) { |
| 195 | final int numSpeedSteps = powerProfile.getNumSpeedStepsInCpuCluster(i); |
| 196 | mKernelCpuSpeedReaders[i] = new KernelCpuSpeedReader(firstCpuOfCluster, |
David Chen | 661f791 | 2018-01-22 17:46:24 -0800 | [diff] [blame] | 197 | numSpeedSteps); |
Chenjie Yu | 7f8def9 | 2017-11-03 09:33:15 -0700 | [diff] [blame] | 198 | firstCpuOfCluster += powerProfile.getNumCoresInCpuCluster(i); |
| 199 | } |
Chenjie Yu | ec67661 | 2018-03-07 09:19:17 -0800 | [diff] [blame] | 200 | // use default throttling in |
| 201 | // frameworks/base/core/java/com/android/internal/os/KernelCpuProcReader |
| 202 | mKernelUidCpuFreqTimeReader.setThrottleInterval(0); |
| 203 | long[] freqs = mKernelUidCpuFreqTimeReader.readFreqs(powerProfile); |
Chenjie Yu | ec67661 | 2018-03-07 09:19:17 -0800 | [diff] [blame] | 204 | mKernelUidCpuClusterTimeReader.setThrottleInterval(0); |
| 205 | mKernelUidCpuActiveTimeReader.setThrottleInterval(0); |
Bookatz | 9472641 | 2017-08-31 09:26:15 -0700 | [diff] [blame] | 206 | } |
| 207 | |
David Chen | adaf8b3 | 2017-11-03 15:42:08 -0700 | [diff] [blame] | 208 | @Override |
David Chen | d37bc23 | 2018-04-12 18:05:11 -0700 | [diff] [blame] | 209 | public void sendDataBroadcast(IBinder intentSenderBinder, long lastReportTimeNs) { |
Bookatz | 3692082 | 2018-01-26 09:18:07 -0800 | [diff] [blame] | 210 | enforceCallingPermission(); |
David Chen | 661f791 | 2018-01-22 17:46:24 -0800 | [diff] [blame] | 211 | IntentSender intentSender = new IntentSender(intentSenderBinder); |
| 212 | Intent intent = new Intent(); |
David Chen | d37bc23 | 2018-04-12 18:05:11 -0700 | [diff] [blame] | 213 | intent.putExtra(EXTRA_LAST_REPORT_TIME, lastReportTimeNs); |
David Chen | 661f791 | 2018-01-22 17:46:24 -0800 | [diff] [blame] | 214 | try { |
| 215 | intentSender.sendIntent(mContext, CODE_DATA_BROADCAST, intent, null, null); |
| 216 | } catch (IntentSender.SendIntentException e) { |
| 217 | Slog.w(TAG, "Unable to send using IntentSender"); |
| 218 | } |
David Chen | adaf8b3 | 2017-11-03 15:42:08 -0700 | [diff] [blame] | 219 | } |
| 220 | |
Bookatz | c697797 | 2018-01-16 16:55:05 -0800 | [diff] [blame] | 221 | @Override |
| 222 | public void sendSubscriberBroadcast(IBinder intentSenderBinder, long configUid, long configKey, |
| 223 | long subscriptionId, long subscriptionRuleId, |
Bookatz | 058d869 | 2018-03-06 09:53:47 -0800 | [diff] [blame] | 224 | String[] cookies, |
Bookatz | c697797 | 2018-01-16 16:55:05 -0800 | [diff] [blame] | 225 | StatsDimensionsValue dimensionsValue) { |
Bookatz | c697797 | 2018-01-16 16:55:05 -0800 | [diff] [blame] | 226 | enforceCallingPermission(); |
| 227 | IntentSender intentSender = new IntentSender(intentSenderBinder); |
| 228 | Intent intent = new Intent() |
| 229 | .putExtra(StatsManager.EXTRA_STATS_CONFIG_UID, configUid) |
| 230 | .putExtra(StatsManager.EXTRA_STATS_CONFIG_KEY, configKey) |
| 231 | .putExtra(StatsManager.EXTRA_STATS_SUBSCRIPTION_ID, subscriptionId) |
| 232 | .putExtra(StatsManager.EXTRA_STATS_SUBSCRIPTION_RULE_ID, subscriptionRuleId) |
| 233 | .putExtra(StatsManager.EXTRA_STATS_DIMENSIONS_VALUE, dimensionsValue); |
Bookatz | 058d869 | 2018-03-06 09:53:47 -0800 | [diff] [blame] | 234 | |
| 235 | ArrayList<String> cookieList = new ArrayList<>(cookies.length); |
| 236 | for (String cookie : cookies) { cookieList.add(cookie); } |
| 237 | intent.putStringArrayListExtra( |
| 238 | StatsManager.EXTRA_STATS_BROADCAST_SUBSCRIBER_COOKIES, cookieList); |
| 239 | |
Bookatz | 1476ef2 | 2018-02-13 12:26:01 -0800 | [diff] [blame] | 240 | if (DEBUG) { |
Bookatz | 058d869 | 2018-03-06 09:53:47 -0800 | [diff] [blame] | 241 | Slog.d(TAG, String.format( |
| 242 | "Statsd sendSubscriberBroadcast with params {%d %d %d %d %s %s}", |
| 243 | configUid, configKey, subscriptionId, subscriptionRuleId, |
| 244 | Arrays.toString(cookies), dimensionsValue)); |
Bookatz | 1476ef2 | 2018-02-13 12:26:01 -0800 | [diff] [blame] | 245 | } |
Bookatz | c697797 | 2018-01-16 16:55:05 -0800 | [diff] [blame] | 246 | try { |
| 247 | intentSender.sendIntent(mContext, CODE_SUBSCRIBER_BROADCAST, intent, null, null); |
| 248 | } catch (IntentSender.SendIntentException e) { |
| 249 | Slog.w(TAG, "Unable to send using IntentSender from uid " + configUid |
| 250 | + "; presumably it had been cancelled."); |
Bookatz | c697797 | 2018-01-16 16:55:05 -0800 | [diff] [blame] | 251 | } |
| 252 | } |
| 253 | |
David Chen | 1481fe1 | 2017-10-16 13:16:34 -0700 | [diff] [blame] | 254 | private final static int[] toIntArray(List<Integer> list) { |
David Chen | de70169 | 2017-10-05 13:16:02 -0700 | [diff] [blame] | 255 | int[] ret = new int[list.size()]; |
David Chen | 1481fe1 | 2017-10-16 13:16:34 -0700 | [diff] [blame] | 256 | for (int i = 0; i < ret.length; i++) { |
David Chen | de70169 | 2017-10-05 13:16:02 -0700 | [diff] [blame] | 257 | ret[i] = list.get(i); |
| 258 | } |
| 259 | return ret; |
| 260 | } |
| 261 | |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 262 | private final static long[] toLongArray(List<Long> list) { |
| 263 | long[] ret = new long[list.size()]; |
| 264 | for (int i = 0; i < ret.length; i++) { |
| 265 | ret[i] = list.get(i); |
| 266 | } |
| 267 | return ret; |
| 268 | } |
| 269 | |
David Chen | de70169 | 2017-10-05 13:16:02 -0700 | [diff] [blame] | 270 | // Assumes that sStatsdLock is held. |
Andreas Gampe | a36dc62 | 2018-02-05 17:19:22 -0800 | [diff] [blame] | 271 | @GuardedBy("sStatsdLock") |
David Chen | de70169 | 2017-10-05 13:16:02 -0700 | [diff] [blame] | 272 | private final void informAllUidsLocked(Context context) throws RemoteException { |
| 273 | UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE); |
| 274 | PackageManager pm = context.getPackageManager(); |
| 275 | final List<UserInfo> users = um.getUsers(true); |
| 276 | if (DEBUG) { |
Bookatz | 111ed73 | 2018-02-16 15:54:05 -0800 | [diff] [blame] | 277 | Slog.d(TAG, "Iterating over " + users.size() + " profiles."); |
David Chen | de70169 | 2017-10-05 13:16:02 -0700 | [diff] [blame] | 278 | } |
| 279 | |
Rajeev Kumar | 22d92b7 | 2018-02-07 18:38:36 -0800 | [diff] [blame] | 280 | List<Integer> uids = new ArrayList<>(); |
| 281 | List<Long> versions = new ArrayList<>(); |
| 282 | List<String> apps = new ArrayList<>(); |
David Chen | de70169 | 2017-10-05 13:16:02 -0700 | [diff] [blame] | 283 | |
| 284 | // Add in all the apps for every user/profile. |
| 285 | for (UserInfo profile : users) { |
David Chen | bd12527 | 2018-04-04 19:02:50 -0700 | [diff] [blame] | 286 | List<PackageInfo> pi = |
David Chen | d37bc23 | 2018-04-12 18:05:11 -0700 | [diff] [blame] | 287 | pm.getInstalledPackagesAsUser(PackageManager.MATCH_KNOWN_PACKAGES, profile.id); |
David Chen | 1481fe1 | 2017-10-16 13:16:34 -0700 | [diff] [blame] | 288 | for (int j = 0; j < pi.size(); j++) { |
| 289 | if (pi.get(j).applicationInfo != null) { |
| 290 | uids.add(pi.get(j).applicationInfo.uid); |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 291 | versions.add(pi.get(j).getLongVersionCode()); |
David Chen | 1481fe1 | 2017-10-16 13:16:34 -0700 | [diff] [blame] | 292 | apps.add(pi.get(j).packageName); |
| 293 | } |
| 294 | } |
David Chen | de70169 | 2017-10-05 13:16:02 -0700 | [diff] [blame] | 295 | } |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 296 | sStatsd.informAllUidData(toIntArray(uids), toLongArray(versions), apps.toArray(new |
David Chen | 1481fe1 | 2017-10-16 13:16:34 -0700 | [diff] [blame] | 297 | String[apps.size()])); |
David Chen | de70169 | 2017-10-05 13:16:02 -0700 | [diff] [blame] | 298 | if (DEBUG) { |
Bookatz | 111ed73 | 2018-02-16 15:54:05 -0800 | [diff] [blame] | 299 | Slog.d(TAG, "Sent data for " + uids.size() + " apps"); |
David Chen | de70169 | 2017-10-05 13:16:02 -0700 | [diff] [blame] | 300 | } |
| 301 | } |
| 302 | |
Bookatz | 3692082 | 2018-01-26 09:18:07 -0800 | [diff] [blame] | 303 | private final static class AppUpdateReceiver extends BroadcastReceiver { |
David Chen | de70169 | 2017-10-05 13:16:02 -0700 | [diff] [blame] | 304 | @Override |
| 305 | public void onReceive(Context context, Intent intent) { |
David Chen | 47e8f4d | 2017-10-11 15:34:13 -0700 | [diff] [blame] | 306 | /** |
| 307 | * App updates actually consist of REMOVE, ADD, and then REPLACE broadcasts. To avoid |
| 308 | * waste, we ignore the REMOVE and ADD broadcasts that contain the replacing flag. |
David Chen | d689689 | 2017-10-25 11:49:03 -0700 | [diff] [blame] | 309 | * If we can't find the value for EXTRA_REPLACING, we default to false. |
David Chen | 47e8f4d | 2017-10-11 15:34:13 -0700 | [diff] [blame] | 310 | */ |
David Chen | d689689 | 2017-10-25 11:49:03 -0700 | [diff] [blame] | 311 | if (!intent.getAction().equals(Intent.ACTION_PACKAGE_REPLACED) |
| 312 | && intent.getBooleanExtra(Intent.EXTRA_REPLACING, false)) { |
David Chen | 47e8f4d | 2017-10-11 15:34:13 -0700 | [diff] [blame] | 313 | return; // Keep only replacing or normal add and remove. |
| 314 | } |
Tej Singh | 90d3aa0 | 2018-03-08 19:07:58 -0800 | [diff] [blame] | 315 | if (DEBUG) Slog.d(TAG, "StatsCompanionService noticed an app was updated."); |
David Chen | de70169 | 2017-10-05 13:16:02 -0700 | [diff] [blame] | 316 | synchronized (sStatsdLock) { |
| 317 | if (sStatsd == null) { |
yro | f6d1ca5 | 2017-11-15 15:38:34 -0800 | [diff] [blame] | 318 | Slog.w(TAG, "Could not access statsd to inform it of an app update"); |
David Chen | de70169 | 2017-10-05 13:16:02 -0700 | [diff] [blame] | 319 | return; |
| 320 | } |
| 321 | try { |
| 322 | if (intent.getAction().equals(Intent.ACTION_PACKAGE_REMOVED)) { |
| 323 | Bundle b = intent.getExtras(); |
| 324 | int uid = b.getInt(Intent.EXTRA_UID); |
| 325 | boolean replacing = intent.getBooleanExtra(Intent.EXTRA_REPLACING, false); |
| 326 | if (!replacing) { |
| 327 | // Don't bother sending an update if we're right about to get another |
| 328 | // intent for the new version that's added. |
| 329 | PackageManager pm = context.getPackageManager(); |
| 330 | String app = intent.getData().getSchemeSpecificPart(); |
| 331 | sStatsd.informOnePackageRemoved(app, uid); |
| 332 | } |
| 333 | } else { |
| 334 | PackageManager pm = context.getPackageManager(); |
| 335 | Bundle b = intent.getExtras(); |
| 336 | int uid = b.getInt(Intent.EXTRA_UID); |
| 337 | String app = intent.getData().getSchemeSpecificPart(); |
| 338 | PackageInfo pi = pm.getPackageInfo(app, PackageManager.MATCH_ANY_USER); |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 339 | sStatsd.informOnePackage(app, uid, pi.getLongVersionCode()); |
David Chen | de70169 | 2017-10-05 13:16:02 -0700 | [diff] [blame] | 340 | } |
| 341 | } catch (Exception e) { |
| 342 | Slog.w(TAG, "Failed to inform statsd of an app update", e); |
| 343 | } |
| 344 | } |
| 345 | } |
David Chen | 1481fe1 | 2017-10-16 13:16:34 -0700 | [diff] [blame] | 346 | } |
David Chen | de70169 | 2017-10-05 13:16:02 -0700 | [diff] [blame] | 347 | |
Bookatz | 582870e | 2018-02-06 14:24:49 -0800 | [diff] [blame] | 348 | public final static class AnomalyAlarmReceiver extends BroadcastReceiver { |
Bookatz | 9472641 | 2017-08-31 09:26:15 -0700 | [diff] [blame] | 349 | @Override |
Bookatz | b487b55 | 2017-09-18 11:26:01 -0700 | [diff] [blame] | 350 | public void onReceive(Context context, Intent intent) { |
Bookatz | 66fe061 | 2018-02-07 18:51:48 -0800 | [diff] [blame] | 351 | Slog.i(TAG, "StatsCompanionService believes an anomaly has occurred at time " |
| 352 | + System.currentTimeMillis() + "ms."); |
Bookatz | b487b55 | 2017-09-18 11:26:01 -0700 | [diff] [blame] | 353 | synchronized (sStatsdLock) { |
| 354 | if (sStatsd == null) { |
| 355 | Slog.w(TAG, "Could not access statsd to inform it of anomaly alarm firing"); |
| 356 | return; |
| 357 | } |
| 358 | try { |
| 359 | // Two-way call to statsd to retain AlarmManager wakelock |
| 360 | sStatsd.informAnomalyAlarmFired(); |
| 361 | } catch (RemoteException e) { |
| 362 | Slog.w(TAG, "Failed to inform statsd of anomaly alarm firing", e); |
| 363 | } |
Bookatz | 9472641 | 2017-08-31 09:26:15 -0700 | [diff] [blame] | 364 | } |
Bookatz | b487b55 | 2017-09-18 11:26:01 -0700 | [diff] [blame] | 365 | // AlarmManager releases its own wakelock here. |
Bookatz | 9472641 | 2017-08-31 09:26:15 -0700 | [diff] [blame] | 366 | } |
David Chen | 1481fe1 | 2017-10-16 13:16:34 -0700 | [diff] [blame] | 367 | } |
Bookatz | b487b55 | 2017-09-18 11:26:01 -0700 | [diff] [blame] | 368 | |
Bookatz | 582870e | 2018-02-06 14:24:49 -0800 | [diff] [blame] | 369 | public final static class PullingAlarmReceiver extends BroadcastReceiver { |
David Chen | 661f791 | 2018-01-22 17:46:24 -0800 | [diff] [blame] | 370 | @Override |
| 371 | public void onReceive(Context context, Intent intent) { |
| 372 | if (DEBUG) |
| 373 | Slog.d(TAG, "Time to poll something."); |
| 374 | synchronized (sStatsdLock) { |
| 375 | if (sStatsd == null) { |
| 376 | Slog.w(TAG, "Could not access statsd to inform it of pulling alarm firing."); |
| 377 | return; |
| 378 | } |
| 379 | try { |
| 380 | // Two-way call to statsd to retain AlarmManager wakelock |
| 381 | sStatsd.informPollAlarmFired(); |
| 382 | } catch (RemoteException e) { |
| 383 | Slog.w(TAG, "Failed to inform statsd of pulling alarm firing.", e); |
| 384 | } |
| 385 | } |
Bookatz | b487b55 | 2017-09-18 11:26:01 -0700 | [diff] [blame] | 386 | } |
David Chen | 1481fe1 | 2017-10-16 13:16:34 -0700 | [diff] [blame] | 387 | } |
Bookatz | 9472641 | 2017-08-31 09:26:15 -0700 | [diff] [blame] | 388 | |
Yangster-mac | 932ecec | 2018-02-01 10:23:52 -0800 | [diff] [blame] | 389 | public final static class PeriodicAlarmReceiver extends BroadcastReceiver { |
| 390 | @Override |
| 391 | public void onReceive(Context context, Intent intent) { |
| 392 | if (DEBUG) |
Yangster-mac | c04feba | 2018-04-02 14:37:33 -0700 | [diff] [blame] | 393 | Slog.d(TAG, "Time to trigger periodic alarm."); |
Yangster-mac | 932ecec | 2018-02-01 10:23:52 -0800 | [diff] [blame] | 394 | synchronized (sStatsdLock) { |
| 395 | if (sStatsd == null) { |
| 396 | Slog.w(TAG, "Could not access statsd to inform it of periodic alarm firing."); |
| 397 | return; |
| 398 | } |
| 399 | try { |
| 400 | // Two-way call to statsd to retain AlarmManager wakelock |
| 401 | sStatsd.informAlarmForSubscriberTriggeringFired(); |
| 402 | } catch (RemoteException e) { |
| 403 | Slog.w(TAG, "Failed to inform statsd of periodic alarm firing.", e); |
| 404 | } |
| 405 | } |
| 406 | // AlarmManager releases its own wakelock here. |
| 407 | } |
| 408 | } |
| 409 | |
| 410 | public final static class ShutdownEventReceiver extends BroadcastReceiver { |
yro | 947fbce | 2017-11-15 22:50:23 -0800 | [diff] [blame] | 411 | @Override |
| 412 | public void onReceive(Context context, Intent intent) { |
| 413 | /** |
| 414 | * Skip immediately if intent is not relevant to device shutdown. |
| 415 | */ |
| 416 | if (!intent.getAction().equals(Intent.ACTION_REBOOT) |
David Chen | 661f791 | 2018-01-22 17:46:24 -0800 | [diff] [blame] | 417 | && !(intent.getAction().equals(Intent.ACTION_SHUTDOWN) |
| 418 | && (intent.getFlags() & Intent.FLAG_RECEIVER_FOREGROUND) != 0)) { |
| 419 | return; |
yro | 947fbce | 2017-11-15 22:50:23 -0800 | [diff] [blame] | 420 | } |
yro | f7a3bcb | 2018-01-24 17:18:55 -0800 | [diff] [blame] | 421 | |
yro | 947fbce | 2017-11-15 22:50:23 -0800 | [diff] [blame] | 422 | Slog.i(TAG, "StatsCompanionService noticed a shutdown."); |
| 423 | synchronized (sStatsdLock) { |
| 424 | if (sStatsd == null) { |
| 425 | Slog.w(TAG, "Could not access statsd to inform it of a shutdown event."); |
| 426 | return; |
| 427 | } |
| 428 | try { |
Yangster-mac | 892f3d3 | 2018-05-02 14:16:48 -0700 | [diff] [blame] | 429 | sStatsd.informDeviceShutdown(); |
yro | 947fbce | 2017-11-15 22:50:23 -0800 | [diff] [blame] | 430 | } catch (Exception e) { |
| 431 | Slog.w(TAG, "Failed to inform statsd of a shutdown event.", e); |
| 432 | } |
| 433 | } |
| 434 | } |
| 435 | } |
| 436 | |
Bookatz | 9472641 | 2017-08-31 09:26:15 -0700 | [diff] [blame] | 437 | @Override // Binder call |
| 438 | public void setAnomalyAlarm(long timestampMs) { |
| 439 | enforceCallingPermission(); |
| 440 | if (DEBUG) Slog.d(TAG, "Setting anomaly alarm for " + timestampMs); |
| 441 | final long callingToken = Binder.clearCallingIdentity(); |
| 442 | try { |
Yangster-mac | 330af58 | 2018-02-08 15:24:38 -0800 | [diff] [blame] | 443 | // using ELAPSED_REALTIME, not ELAPSED_REALTIME_WAKEUP, so if device is asleep, will |
| 444 | // only fire when it awakens. |
| 445 | // This alarm is inexact, leaving its exactness completely up to the OS optimizations. |
Bookatz | 9472641 | 2017-08-31 09:26:15 -0700 | [diff] [blame] | 446 | // AlarmManager will automatically cancel any previous mAnomalyAlarmIntent alarm. |
Yangster-mac | 330af58 | 2018-02-08 15:24:38 -0800 | [diff] [blame] | 447 | mAlarmManager.setExact(AlarmManager.ELAPSED_REALTIME, timestampMs, mAnomalyAlarmIntent); |
Bookatz | 9472641 | 2017-08-31 09:26:15 -0700 | [diff] [blame] | 448 | } finally { |
| 449 | Binder.restoreCallingIdentity(callingToken); |
| 450 | } |
| 451 | } |
| 452 | |
| 453 | @Override // Binder call |
| 454 | public void cancelAnomalyAlarm() { |
| 455 | enforceCallingPermission(); |
| 456 | if (DEBUG) Slog.d(TAG, "Cancelling anomaly alarm"); |
| 457 | final long callingToken = Binder.clearCallingIdentity(); |
| 458 | try { |
| 459 | mAlarmManager.cancel(mAnomalyAlarmIntent); |
| 460 | } finally { |
| 461 | Binder.restoreCallingIdentity(callingToken); |
| 462 | } |
| 463 | } |
| 464 | |
| 465 | @Override // Binder call |
Yangster-mac | 932ecec | 2018-02-01 10:23:52 -0800 | [diff] [blame] | 466 | public void setAlarmForSubscriberTriggering(long timestampMs) { |
| 467 | enforceCallingPermission(); |
| 468 | if (DEBUG) |
Yangster-mac | c04feba | 2018-04-02 14:37:33 -0700 | [diff] [blame] | 469 | Slog.d(TAG, "Setting periodic alarm in about " + |
| 470 | (timestampMs - SystemClock.elapsedRealtime())); |
Yangster-mac | 932ecec | 2018-02-01 10:23:52 -0800 | [diff] [blame] | 471 | final long callingToken = Binder.clearCallingIdentity(); |
| 472 | try { |
| 473 | // using ELAPSED_REALTIME, not ELAPSED_REALTIME_WAKEUP, so if device is asleep, will |
| 474 | // only fire when it awakens. |
Yangster-mac | c04feba | 2018-04-02 14:37:33 -0700 | [diff] [blame] | 475 | mAlarmManager.setExact(AlarmManager.ELAPSED_REALTIME, timestampMs, mPeriodicAlarmIntent); |
Yangster-mac | 932ecec | 2018-02-01 10:23:52 -0800 | [diff] [blame] | 476 | } finally { |
| 477 | Binder.restoreCallingIdentity(callingToken); |
| 478 | } |
| 479 | } |
| 480 | |
| 481 | @Override // Binder call |
| 482 | public void cancelAlarmForSubscriberTriggering() { |
| 483 | enforceCallingPermission(); |
| 484 | if (DEBUG) |
| 485 | Slog.d(TAG, "Cancelling periodic alarm"); |
| 486 | final long callingToken = Binder.clearCallingIdentity(); |
| 487 | try { |
| 488 | mAlarmManager.cancel(mPeriodicAlarmIntent); |
| 489 | } finally { |
| 490 | Binder.restoreCallingIdentity(callingToken); |
| 491 | } |
| 492 | } |
| 493 | |
| 494 | @Override // Binder call |
Chenjie Yu | 1a0a941 | 2018-03-28 10:07:22 -0700 | [diff] [blame] | 495 | public void setPullingAlarm(long nextPullTimeMs) { |
| 496 | enforceCallingPermission(); |
| 497 | if (DEBUG) |
| 498 | Slog.d(TAG, |
| 499 | "Setting pulling alarm in about " + (nextPullTimeMs - SystemClock.elapsedRealtime())); |
| 500 | final long callingToken = Binder.clearCallingIdentity(); |
| 501 | try { |
| 502 | // using ELAPSED_REALTIME, not ELAPSED_REALTIME_WAKEUP, so if device is asleep, will |
| 503 | // only fire when it awakens. |
| 504 | mAlarmManager.setExact(AlarmManager.ELAPSED_REALTIME, nextPullTimeMs, mPullingAlarmIntent); |
| 505 | } finally { |
| 506 | Binder.restoreCallingIdentity(callingToken); |
| 507 | } |
Bookatz | 9472641 | 2017-08-31 09:26:15 -0700 | [diff] [blame] | 508 | } |
| 509 | |
| 510 | @Override // Binder call |
Chenjie Yu | 1a0a941 | 2018-03-28 10:07:22 -0700 | [diff] [blame] | 511 | public void cancelPullingAlarm() { |
| 512 | enforceCallingPermission(); |
| 513 | if (DEBUG) |
| 514 | Slog.d(TAG, "Cancelling pulling alarm"); |
| 515 | final long callingToken = Binder.clearCallingIdentity(); |
| 516 | try { |
| 517 | mAlarmManager.cancel(mPullingAlarmIntent); |
| 518 | } finally { |
| 519 | Binder.restoreCallingIdentity(callingToken); |
| 520 | } |
Bookatz | 9472641 | 2017-08-31 09:26:15 -0700 | [diff] [blame] | 521 | } |
| 522 | |
Chenjie Yu | 9d7720b | 2018-01-24 10:34:48 -0800 | [diff] [blame] | 523 | private void addNetworkStats( |
David Chen | 661f791 | 2018-01-22 17:46:24 -0800 | [diff] [blame] | 524 | int tag, List<StatsLogEventWrapper> ret, NetworkStats stats, boolean withFGBG) { |
| 525 | int size = stats.size(); |
Yangster-mac | c552b35 | 2018-02-22 10:00:45 -0800 | [diff] [blame] | 526 | long elapsedNanos = SystemClock.elapsedRealtimeNanos(); |
David Chen | 661f791 | 2018-01-22 17:46:24 -0800 | [diff] [blame] | 527 | NetworkStats.Entry entry = new NetworkStats.Entry(); // For recycling |
| 528 | for (int j = 0; j < size; j++) { |
| 529 | stats.getValues(j, entry); |
Yangster-mac | c552b35 | 2018-02-22 10:00:45 -0800 | [diff] [blame] | 530 | StatsLogEventWrapper e = new StatsLogEventWrapper(elapsedNanos, tag, withFGBG ? 6 : 5); |
David Chen | 661f791 | 2018-01-22 17:46:24 -0800 | [diff] [blame] | 531 | e.writeInt(entry.uid); |
| 532 | if (withFGBG) { |
| 533 | e.writeInt(entry.set); |
| 534 | } |
| 535 | e.writeLong(entry.rxBytes); |
| 536 | e.writeLong(entry.rxPackets); |
| 537 | e.writeLong(entry.txBytes); |
| 538 | e.writeLong(entry.txPackets); |
| 539 | ret.add(e); |
David Chen | c8a4324 | 2017-10-17 16:23:28 -0700 | [diff] [blame] | 540 | } |
David Chen | c8a4324 | 2017-10-17 16:23:28 -0700 | [diff] [blame] | 541 | } |
| 542 | |
| 543 | /** |
| 544 | * Allows rollups per UID but keeping the set (foreground/background) slicing. |
| 545 | * Adapted from groupedByUid in frameworks/base/core/java/android/net/NetworkStats.java |
| 546 | */ |
| 547 | private NetworkStats rollupNetworkStatsByFGBG(NetworkStats stats) { |
| 548 | final NetworkStats ret = new NetworkStats(stats.getElapsedRealtime(), 1); |
| 549 | |
| 550 | final NetworkStats.Entry entry = new NetworkStats.Entry(); |
| 551 | entry.iface = NetworkStats.IFACE_ALL; |
| 552 | entry.tag = NetworkStats.TAG_NONE; |
| 553 | entry.metered = NetworkStats.METERED_ALL; |
| 554 | entry.roaming = NetworkStats.ROAMING_ALL; |
| 555 | |
| 556 | int size = stats.size(); |
| 557 | NetworkStats.Entry recycle = new NetworkStats.Entry(); // Used for retrieving values |
| 558 | for (int i = 0; i < size; i++) { |
| 559 | stats.getValues(i, recycle); |
| 560 | |
| 561 | // Skip specific tags, since already counted in TAG_NONE |
| 562 | if (recycle.tag != NetworkStats.TAG_NONE) continue; |
| 563 | |
| 564 | entry.set = recycle.set; // Allows slicing by background/foreground |
| 565 | entry.uid = recycle.uid; |
| 566 | entry.rxBytes = recycle.rxBytes; |
| 567 | entry.rxPackets = recycle.rxPackets; |
| 568 | entry.txBytes = recycle.txBytes; |
| 569 | entry.txPackets = recycle.txPackets; |
| 570 | // Operations purposefully omitted since we don't use them for statsd. |
| 571 | ret.combineValues(entry); |
| 572 | } |
| 573 | return ret; |
| 574 | } |
| 575 | |
Chenjie Yu | 05013b3 | 2017-11-21 10:21:41 -0800 | [diff] [blame] | 576 | /** |
| 577 | * Helper method to extract the Parcelable controller info from a |
| 578 | * SynchronousResultReceiver. |
| 579 | */ |
| 580 | private static <T extends Parcelable> T awaitControllerInfo( |
| 581 | @Nullable SynchronousResultReceiver receiver) { |
| 582 | if (receiver == null) { |
| 583 | return null; |
| 584 | } |
| 585 | |
| 586 | try { |
| 587 | final SynchronousResultReceiver.Result result = |
| 588 | receiver.awaitResult(EXTERNAL_STATS_SYNC_TIMEOUT_MILLIS); |
| 589 | if (result.bundle != null) { |
| 590 | // This is the final destination for the Bundle. |
| 591 | result.bundle.setDefusable(true); |
| 592 | |
| 593 | final T data = result.bundle.getParcelable( |
| 594 | RESULT_RECEIVER_CONTROLLER_KEY); |
| 595 | if (data != null) { |
| 596 | return data; |
| 597 | } |
| 598 | } |
| 599 | Slog.e(TAG, "no controller energy info supplied for " + receiver.getName()); |
| 600 | } catch (TimeoutException e) { |
| 601 | Slog.w(TAG, "timeout reading " + receiver.getName() + " stats"); |
| 602 | } |
| 603 | return null; |
| 604 | } |
| 605 | |
Chenjie Yu | 9d7720b | 2018-01-24 10:34:48 -0800 | [diff] [blame] | 606 | private void pullKernelWakelock(int tagId, List<StatsLogEventWrapper> pulledData) { |
David Chen | 661f791 | 2018-01-22 17:46:24 -0800 | [diff] [blame] | 607 | final KernelWakelockStats wakelockStats = |
| 608 | mKernelWakelockReader.readKernelWakelockStats(mTmpWakelockStats); |
Yangster-mac | c552b35 | 2018-02-22 10:00:45 -0800 | [diff] [blame] | 609 | long elapsedNanos = SystemClock.elapsedRealtimeNanos(); |
David Chen | 661f791 | 2018-01-22 17:46:24 -0800 | [diff] [blame] | 610 | for (Map.Entry<String, KernelWakelockStats.Entry> ent : wakelockStats.entrySet()) { |
| 611 | String name = ent.getKey(); |
| 612 | KernelWakelockStats.Entry kws = ent.getValue(); |
Yangster-mac | c552b35 | 2018-02-22 10:00:45 -0800 | [diff] [blame] | 613 | StatsLogEventWrapper e = new StatsLogEventWrapper(elapsedNanos, tagId, 4); |
David Chen | 661f791 | 2018-01-22 17:46:24 -0800 | [diff] [blame] | 614 | e.writeString(name); |
| 615 | e.writeInt(kws.mCount); |
| 616 | e.writeInt(kws.mVersion); |
| 617 | e.writeLong(kws.mTotalTime); |
| 618 | pulledData.add(e); |
| 619 | } |
Chenjie Yu | 9d7720b | 2018-01-24 10:34:48 -0800 | [diff] [blame] | 620 | } |
| 621 | |
| 622 | private void pullWifiBytesTransfer(int tagId, List<StatsLogEventWrapper> pulledData) { |
David Chen | 661f791 | 2018-01-22 17:46:24 -0800 | [diff] [blame] | 623 | long token = Binder.clearCallingIdentity(); |
| 624 | try { |
| 625 | // TODO: Consider caching the following call to get BatteryStatsInternal. |
| 626 | BatteryStatsInternal bs = LocalServices.getService(BatteryStatsInternal.class); |
| 627 | String[] ifaces = bs.getWifiIfaces(); |
| 628 | if (ifaces.length == 0) { |
| 629 | return; |
| 630 | } |
| 631 | NetworkStatsFactory nsf = new NetworkStatsFactory(); |
| 632 | // Combine all the metrics per Uid into one record. |
| 633 | NetworkStats stats = |
| 634 | nsf.readNetworkStatsDetail(NetworkStats.UID_ALL, ifaces, NetworkStats.TAG_NONE, null) |
| 635 | .groupedByUid(); |
| 636 | addNetworkStats(tagId, pulledData, stats, false); |
| 637 | } catch (java.io.IOException e) { |
| 638 | Slog.e(TAG, "Pulling netstats for wifi bytes has error", e); |
| 639 | } finally { |
| 640 | Binder.restoreCallingIdentity(token); |
Chenjie Yu | 9d7720b | 2018-01-24 10:34:48 -0800 | [diff] [blame] | 641 | } |
Chenjie Yu | 9d7720b | 2018-01-24 10:34:48 -0800 | [diff] [blame] | 642 | } |
| 643 | |
| 644 | private void pullWifiBytesTransferByFgBg(int tagId, List<StatsLogEventWrapper> pulledData) { |
David Chen | 661f791 | 2018-01-22 17:46:24 -0800 | [diff] [blame] | 645 | long token = Binder.clearCallingIdentity(); |
| 646 | try { |
| 647 | BatteryStatsInternal bs = LocalServices.getService(BatteryStatsInternal.class); |
| 648 | String[] ifaces = bs.getWifiIfaces(); |
| 649 | if (ifaces.length == 0) { |
| 650 | return; |
| 651 | } |
| 652 | NetworkStatsFactory nsf = new NetworkStatsFactory(); |
| 653 | NetworkStats stats = rollupNetworkStatsByFGBG( |
| 654 | nsf.readNetworkStatsDetail(NetworkStats.UID_ALL, ifaces, NetworkStats.TAG_NONE, null)); |
| 655 | addNetworkStats(tagId, pulledData, stats, true); |
| 656 | } catch (java.io.IOException e) { |
| 657 | Slog.e(TAG, "Pulling netstats for wifi bytes w/ fg/bg has error", e); |
| 658 | } finally { |
| 659 | Binder.restoreCallingIdentity(token); |
Chenjie Yu | 9d7720b | 2018-01-24 10:34:48 -0800 | [diff] [blame] | 660 | } |
Chenjie Yu | 9d7720b | 2018-01-24 10:34:48 -0800 | [diff] [blame] | 661 | } |
| 662 | |
| 663 | private void pullMobileBytesTransfer(int tagId, List<StatsLogEventWrapper> pulledData) { |
David Chen | 661f791 | 2018-01-22 17:46:24 -0800 | [diff] [blame] | 664 | long token = Binder.clearCallingIdentity(); |
| 665 | try { |
| 666 | BatteryStatsInternal bs = LocalServices.getService(BatteryStatsInternal.class); |
| 667 | String[] ifaces = bs.getMobileIfaces(); |
| 668 | if (ifaces.length == 0) { |
| 669 | return; |
| 670 | } |
| 671 | NetworkStatsFactory nsf = new NetworkStatsFactory(); |
| 672 | // Combine all the metrics per Uid into one record. |
| 673 | NetworkStats stats = |
| 674 | nsf.readNetworkStatsDetail(NetworkStats.UID_ALL, ifaces, NetworkStats.TAG_NONE, null) |
| 675 | .groupedByUid(); |
| 676 | addNetworkStats(tagId, pulledData, stats, false); |
| 677 | } catch (java.io.IOException e) { |
| 678 | Slog.e(TAG, "Pulling netstats for mobile bytes has error", e); |
| 679 | } finally { |
| 680 | Binder.restoreCallingIdentity(token); |
Chenjie Yu | 9d7720b | 2018-01-24 10:34:48 -0800 | [diff] [blame] | 681 | } |
Chenjie Yu | 9d7720b | 2018-01-24 10:34:48 -0800 | [diff] [blame] | 682 | } |
| 683 | |
| 684 | private void pullBluetoothBytesTransfer(int tagId, List<StatsLogEventWrapper> pulledData) { |
David Chen | 661f791 | 2018-01-22 17:46:24 -0800 | [diff] [blame] | 685 | BluetoothActivityEnergyInfo info = pullBluetoothData(); |
Yangster-mac | c552b35 | 2018-02-22 10:00:45 -0800 | [diff] [blame] | 686 | long elapsedNanos = SystemClock.elapsedRealtimeNanos(); |
Chenjie Yu | 9e59f93 | 2018-03-30 16:41:38 -0700 | [diff] [blame] | 687 | if (info.getUidTraffic() != null) { |
| 688 | for (UidTraffic traffic : info.getUidTraffic()) { |
| 689 | StatsLogEventWrapper e = new StatsLogEventWrapper(elapsedNanos, tagId, 3); |
| 690 | e.writeInt(traffic.getUid()); |
| 691 | e.writeLong(traffic.getRxBytes()); |
| 692 | e.writeLong(traffic.getTxBytes()); |
| 693 | pulledData.add(e); |
| 694 | } |
David Chen | 661f791 | 2018-01-22 17:46:24 -0800 | [diff] [blame] | 695 | } |
Chenjie Yu | 9d7720b | 2018-01-24 10:34:48 -0800 | [diff] [blame] | 696 | } |
| 697 | |
| 698 | private void pullMobileBytesTransferByFgBg(int tagId, List<StatsLogEventWrapper> pulledData) { |
David Chen | 661f791 | 2018-01-22 17:46:24 -0800 | [diff] [blame] | 699 | long token = Binder.clearCallingIdentity(); |
| 700 | try { |
| 701 | BatteryStatsInternal bs = LocalServices.getService(BatteryStatsInternal.class); |
| 702 | String[] ifaces = bs.getMobileIfaces(); |
| 703 | if (ifaces.length == 0) { |
| 704 | return; |
| 705 | } |
| 706 | NetworkStatsFactory nsf = new NetworkStatsFactory(); |
| 707 | NetworkStats stats = rollupNetworkStatsByFGBG( |
| 708 | nsf.readNetworkStatsDetail(NetworkStats.UID_ALL, ifaces, NetworkStats.TAG_NONE, null)); |
| 709 | addNetworkStats(tagId, pulledData, stats, true); |
| 710 | } catch (java.io.IOException e) { |
| 711 | Slog.e(TAG, "Pulling netstats for mobile bytes w/ fg/bg has error", e); |
| 712 | } finally { |
| 713 | Binder.restoreCallingIdentity(token); |
Chenjie Yu | 9d7720b | 2018-01-24 10:34:48 -0800 | [diff] [blame] | 714 | } |
Chenjie Yu | 9d7720b | 2018-01-24 10:34:48 -0800 | [diff] [blame] | 715 | } |
| 716 | |
| 717 | private void pullCpuTimePerFreq(int tagId, List<StatsLogEventWrapper> pulledData) { |
Yangster-mac | c552b35 | 2018-02-22 10:00:45 -0800 | [diff] [blame] | 718 | long elapsedNanos = SystemClock.elapsedRealtimeNanos(); |
David Chen | 661f791 | 2018-01-22 17:46:24 -0800 | [diff] [blame] | 719 | for (int cluster = 0; cluster < mKernelCpuSpeedReaders.length; cluster++) { |
| 720 | long[] clusterTimeMs = mKernelCpuSpeedReaders[cluster].readAbsolute(); |
| 721 | if (clusterTimeMs != null) { |
| 722 | for (int speed = clusterTimeMs.length - 1; speed >= 0; --speed) { |
Yangster-mac | c552b35 | 2018-02-22 10:00:45 -0800 | [diff] [blame] | 723 | StatsLogEventWrapper e = new StatsLogEventWrapper(elapsedNanos, tagId, 3); |
David Chen | 661f791 | 2018-01-22 17:46:24 -0800 | [diff] [blame] | 724 | e.writeInt(cluster); |
| 725 | e.writeInt(speed); |
| 726 | e.writeLong(clusterTimeMs[speed]); |
| 727 | pulledData.add(e); |
| 728 | } |
| 729 | } |
Chenjie Yu | 9d7720b | 2018-01-24 10:34:48 -0800 | [diff] [blame] | 730 | } |
Chenjie Yu | 9d7720b | 2018-01-24 10:34:48 -0800 | [diff] [blame] | 731 | } |
| 732 | |
Chenjie Yu | ec67661 | 2018-03-07 09:19:17 -0800 | [diff] [blame] | 733 | private void pullKernelUidCpuTime(int tagId, List<StatsLogEventWrapper> pulledData) { |
| 734 | long elapsedNanos = SystemClock.elapsedRealtimeNanos(); |
| 735 | mKernelUidCpuTimeReader.readAbsolute((uid, userTimeUs, systemTimeUs) -> { |
| 736 | StatsLogEventWrapper e = new StatsLogEventWrapper(elapsedNanos, tagId, 3); |
| 737 | e.writeInt(uid); |
| 738 | e.writeLong(userTimeUs); |
| 739 | e.writeLong(systemTimeUs); |
| 740 | pulledData.add(e); |
| 741 | }); |
| 742 | } |
| 743 | |
| 744 | private void pullKernelUidCpuFreqTime(int tagId, List<StatsLogEventWrapper> pulledData) { |
| 745 | long elapsedNanos = SystemClock.elapsedRealtimeNanos(); |
| 746 | mKernelUidCpuFreqTimeReader.readAbsolute((uid, cpuFreqTimeMs) -> { |
| 747 | for (int freqIndex = 0; freqIndex < cpuFreqTimeMs.length; ++freqIndex) { |
Chenjie Yu | 4460e3c | 2018-03-14 17:12:59 -0700 | [diff] [blame] | 748 | if(cpuFreqTimeMs[freqIndex] != 0) { |
| 749 | StatsLogEventWrapper e = new StatsLogEventWrapper(elapsedNanos, tagId, 3); |
| 750 | e.writeInt(uid); |
| 751 | e.writeInt(freqIndex); |
| 752 | e.writeLong(cpuFreqTimeMs[freqIndex]); |
| 753 | pulledData.add(e); |
| 754 | } |
Chenjie Yu | ec67661 | 2018-03-07 09:19:17 -0800 | [diff] [blame] | 755 | } |
| 756 | }); |
| 757 | } |
| 758 | |
| 759 | private void pullKernelUidCpuClusterTime(int tagId, List<StatsLogEventWrapper> pulledData) { |
| 760 | long elapsedNanos = SystemClock.elapsedRealtimeNanos(); |
| 761 | mKernelUidCpuClusterTimeReader.readAbsolute((uid, cpuClusterTimesMs) -> { |
| 762 | for (int i = 0; i < cpuClusterTimesMs.length; i++) { |
| 763 | StatsLogEventWrapper e = new StatsLogEventWrapper(elapsedNanos, tagId, 3); |
| 764 | e.writeInt(uid); |
| 765 | e.writeInt(i); |
| 766 | e.writeLong(cpuClusterTimesMs[i]); |
| 767 | pulledData.add(e); |
| 768 | } |
| 769 | }); |
| 770 | } |
| 771 | |
| 772 | private void pullKernelUidCpuActiveTime(int tagId, List<StatsLogEventWrapper> pulledData) { |
| 773 | long elapsedNanos = SystemClock.elapsedRealtimeNanos(); |
| 774 | mKernelUidCpuActiveTimeReader.readAbsolute((uid, cpuActiveTimesMs) -> { |
| 775 | StatsLogEventWrapper e = new StatsLogEventWrapper(elapsedNanos, tagId, 2); |
| 776 | e.writeInt(uid); |
| 777 | e.writeLong((long)cpuActiveTimesMs); |
| 778 | pulledData.add(e); |
| 779 | }); |
| 780 | } |
| 781 | |
Chenjie Yu | 5caaa9d | 2018-03-06 15:48:54 -0800 | [diff] [blame] | 782 | private void pullWifiActivityInfo(int tagId, List<StatsLogEventWrapper> pulledData) { |
David Chen | 661f791 | 2018-01-22 17:46:24 -0800 | [diff] [blame] | 783 | long token = Binder.clearCallingIdentity(); |
| 784 | if (mWifiManager == null) { |
| 785 | mWifiManager = |
| 786 | IWifiManager.Stub.asInterface(ServiceManager.getService(Context.WIFI_SERVICE)); |
Chenjie Yu | 9d7720b | 2018-01-24 10:34:48 -0800 | [diff] [blame] | 787 | } |
David Chen | 661f791 | 2018-01-22 17:46:24 -0800 | [diff] [blame] | 788 | if (mWifiManager != null) { |
| 789 | try { |
| 790 | SynchronousResultReceiver wifiReceiver = new SynchronousResultReceiver("wifi"); |
| 791 | mWifiManager.requestActivityInfo(wifiReceiver); |
| 792 | final WifiActivityEnergyInfo wifiInfo = awaitControllerInfo(wifiReceiver); |
Yangster-mac | c552b35 | 2018-02-22 10:00:45 -0800 | [diff] [blame] | 793 | StatsLogEventWrapper e = new StatsLogEventWrapper(SystemClock.elapsedRealtimeNanos(), tagId, 6); |
David Chen | 661f791 | 2018-01-22 17:46:24 -0800 | [diff] [blame] | 794 | e.writeLong(wifiInfo.getTimeStamp()); |
| 795 | e.writeInt(wifiInfo.getStackState()); |
| 796 | e.writeLong(wifiInfo.getControllerTxTimeMillis()); |
| 797 | e.writeLong(wifiInfo.getControllerRxTimeMillis()); |
| 798 | e.writeLong(wifiInfo.getControllerIdleTimeMillis()); |
| 799 | e.writeLong(wifiInfo.getControllerEnergyUsed()); |
| 800 | pulledData.add(e); |
| 801 | } catch (RemoteException e) { |
| 802 | Slog.e(TAG, "Pulling wifiManager for wifi controller activity energy info has error", e); |
| 803 | } finally { |
| 804 | Binder.restoreCallingIdentity(token); |
| 805 | } |
| 806 | } |
Chenjie Yu | 9d7720b | 2018-01-24 10:34:48 -0800 | [diff] [blame] | 807 | } |
| 808 | |
| 809 | private void pullModemActivityInfo(int tagId, List<StatsLogEventWrapper> pulledData) { |
David Chen | 661f791 | 2018-01-22 17:46:24 -0800 | [diff] [blame] | 810 | long token = Binder.clearCallingIdentity(); |
| 811 | if (mTelephony == null) { |
| 812 | mTelephony = TelephonyManager.from(mContext); |
| 813 | } |
| 814 | if (mTelephony != null) { |
| 815 | SynchronousResultReceiver modemReceiver = new SynchronousResultReceiver("telephony"); |
| 816 | mTelephony.requestModemActivityInfo(modemReceiver); |
| 817 | final ModemActivityInfo modemInfo = awaitControllerInfo(modemReceiver); |
David Chen | 56ae0d9 | 2018-05-11 16:00:22 -0700 | [diff] [blame] | 818 | StatsLogEventWrapper e = new StatsLogEventWrapper(SystemClock.elapsedRealtimeNanos(), tagId, 10); |
David Chen | 661f791 | 2018-01-22 17:46:24 -0800 | [diff] [blame] | 819 | e.writeLong(modemInfo.getTimestamp()); |
| 820 | e.writeLong(modemInfo.getSleepTimeMillis()); |
| 821 | e.writeLong(modemInfo.getIdleTimeMillis()); |
| 822 | e.writeLong(modemInfo.getTxTimeMillis()[0]); |
| 823 | e.writeLong(modemInfo.getTxTimeMillis()[1]); |
| 824 | e.writeLong(modemInfo.getTxTimeMillis()[2]); |
| 825 | e.writeLong(modemInfo.getTxTimeMillis()[3]); |
| 826 | e.writeLong(modemInfo.getTxTimeMillis()[4]); |
| 827 | e.writeLong(modemInfo.getRxTimeMillis()); |
| 828 | e.writeLong(modemInfo.getEnergyUsed()); |
| 829 | pulledData.add(e); |
| 830 | } |
Chenjie Yu | 9d7720b | 2018-01-24 10:34:48 -0800 | [diff] [blame] | 831 | } |
| 832 | |
| 833 | private void pullBluetoothActivityInfo(int tagId, List<StatsLogEventWrapper> pulledData) { |
David Chen | 661f791 | 2018-01-22 17:46:24 -0800 | [diff] [blame] | 834 | BluetoothActivityEnergyInfo info = pullBluetoothData(); |
Yangster-mac | c552b35 | 2018-02-22 10:00:45 -0800 | [diff] [blame] | 835 | StatsLogEventWrapper e = new StatsLogEventWrapper(SystemClock.elapsedRealtimeNanos(), tagId, 6); |
David Chen | 661f791 | 2018-01-22 17:46:24 -0800 | [diff] [blame] | 836 | e.writeLong(info.getTimeStamp()); |
| 837 | e.writeInt(info.getBluetoothStackState()); |
| 838 | e.writeLong(info.getControllerTxTimeMillis()); |
| 839 | e.writeLong(info.getControllerRxTimeMillis()); |
| 840 | e.writeLong(info.getControllerIdleTimeMillis()); |
| 841 | e.writeLong(info.getControllerEnergyUsed()); |
| 842 | pulledData.add(e); |
Chenjie Yu | 9d7720b | 2018-01-24 10:34:48 -0800 | [diff] [blame] | 843 | } |
| 844 | |
| 845 | private synchronized BluetoothActivityEnergyInfo pullBluetoothData() { |
Chenjie Yu | c2d6544 | 2018-02-01 22:27:17 -0800 | [diff] [blame] | 846 | final BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); |
David Chen | 661f791 | 2018-01-22 17:46:24 -0800 | [diff] [blame] | 847 | if (adapter != null) { |
| 848 | SynchronousResultReceiver bluetoothReceiver = new SynchronousResultReceiver("bluetooth"); |
| 849 | adapter.requestControllerActivityEnergyInfo(bluetoothReceiver); |
| 850 | return awaitControllerInfo(bluetoothReceiver); |
| 851 | } else { |
| 852 | Slog.e(TAG, "Failed to get bluetooth adapter!"); |
| 853 | return null; |
| 854 | } |
Chenjie Yu | 9d7720b | 2018-01-24 10:34:48 -0800 | [diff] [blame] | 855 | } |
| 856 | |
| 857 | private void pullSystemElapsedRealtime(int tagId, List<StatsLogEventWrapper> pulledData) { |
Yangster-mac | c552b35 | 2018-02-22 10:00:45 -0800 | [diff] [blame] | 858 | StatsLogEventWrapper e = new StatsLogEventWrapper(SystemClock.elapsedRealtimeNanos(), tagId, 1); |
David Chen | 661f791 | 2018-01-22 17:46:24 -0800 | [diff] [blame] | 859 | e.writeLong(SystemClock.elapsedRealtime()); |
| 860 | pulledData.add(e); |
Chenjie Yu | 9d7720b | 2018-01-24 10:34:48 -0800 | [diff] [blame] | 861 | } |
| 862 | |
| 863 | private void pullDiskSpace(int tagId, List<StatsLogEventWrapper> pulledData) { |
Yangster-mac | c552b35 | 2018-02-22 10:00:45 -0800 | [diff] [blame] | 864 | StatsLogEventWrapper e = new StatsLogEventWrapper(SystemClock.elapsedRealtimeNanos(), tagId, 3); |
David Chen | 661f791 | 2018-01-22 17:46:24 -0800 | [diff] [blame] | 865 | e.writeLong(mStatFsData.getAvailableBytes()); |
| 866 | e.writeLong(mStatFsSystem.getAvailableBytes()); |
| 867 | e.writeLong(mStatFsTemp.getAvailableBytes()); |
| 868 | pulledData.add(e); |
Chenjie Yu | 9d7720b | 2018-01-24 10:34:48 -0800 | [diff] [blame] | 869 | } |
| 870 | |
| 871 | private void pullSystemUpTime(int tagId, List<StatsLogEventWrapper> pulledData) { |
Yangster-mac | c552b35 | 2018-02-22 10:00:45 -0800 | [diff] [blame] | 872 | StatsLogEventWrapper e = new StatsLogEventWrapper(SystemClock.elapsedRealtimeNanos(), tagId, 1); |
David Chen | 661f791 | 2018-01-22 17:46:24 -0800 | [diff] [blame] | 873 | e.writeLong(SystemClock.uptimeMillis()); |
| 874 | pulledData.add(e); |
Chenjie Yu | 9d7720b | 2018-01-24 10:34:48 -0800 | [diff] [blame] | 875 | } |
| 876 | |
Rajeev Kumar | 22d92b7 | 2018-02-07 18:38:36 -0800 | [diff] [blame] | 877 | private void pullProcessMemoryState(int tagId, List<StatsLogEventWrapper> pulledData) { |
| 878 | List<ProcessMemoryState> processMemoryStates = |
| 879 | LocalServices.getService(ActivityManagerInternal.class) |
| 880 | .getMemoryStateForProcesses(); |
Yangster-mac | c552b35 | 2018-02-22 10:00:45 -0800 | [diff] [blame] | 881 | long elapsedNanos = SystemClock.elapsedRealtimeNanos(); |
Rajeev Kumar | 22d92b7 | 2018-02-07 18:38:36 -0800 | [diff] [blame] | 882 | for (ProcessMemoryState processMemoryState : processMemoryStates) { |
Yangster-mac | c552b35 | 2018-02-22 10:00:45 -0800 | [diff] [blame] | 883 | StatsLogEventWrapper e = new StatsLogEventWrapper(elapsedNanos, tagId, 8 /* fields */); |
Rajeev Kumar | 22d92b7 | 2018-02-07 18:38:36 -0800 | [diff] [blame] | 884 | e.writeInt(processMemoryState.uid); |
| 885 | e.writeString(processMemoryState.processName); |
| 886 | e.writeInt(processMemoryState.oomScore); |
| 887 | e.writeLong(processMemoryState.pgfault); |
| 888 | e.writeLong(processMemoryState.pgmajfault); |
| 889 | e.writeLong(processMemoryState.rssInBytes); |
| 890 | e.writeLong(processMemoryState.cacheInBytes); |
| 891 | e.writeLong(processMemoryState.swapInBytes); |
| 892 | pulledData.add(e); |
| 893 | } |
| 894 | } |
| 895 | |
Chenjie Yu | 05013b3 | 2017-11-21 10:21:41 -0800 | [diff] [blame] | 896 | /** |
Chenjie Yu | 9d7720b | 2018-01-24 10:34:48 -0800 | [diff] [blame] | 897 | * Pulls various data. |
Chenjie Yu | 05013b3 | 2017-11-21 10:21:41 -0800 | [diff] [blame] | 898 | */ |
Bookatz | c68a9d2 | 2017-09-27 14:09:55 -0700 | [diff] [blame] | 899 | @Override // Binder call |
Chenjie Yu | 5305e1d | 2017-10-31 13:49:36 -0700 | [diff] [blame] | 900 | public StatsLogEventWrapper[] pullData(int tagId) { |
Bookatz | c68a9d2 | 2017-09-27 14:09:55 -0700 | [diff] [blame] | 901 | enforceCallingPermission(); |
David Chen | c8a4324 | 2017-10-17 16:23:28 -0700 | [diff] [blame] | 902 | if (DEBUG) |
Chenjie Yu | 5305e1d | 2017-10-31 13:49:36 -0700 | [diff] [blame] | 903 | Slog.d(TAG, "Pulling " + tagId); |
Rajeev Kumar | 22d92b7 | 2018-02-07 18:38:36 -0800 | [diff] [blame] | 904 | List<StatsLogEventWrapper> ret = new ArrayList<>(); |
Chenjie Yu | 5305e1d | 2017-10-31 13:49:36 -0700 | [diff] [blame] | 905 | switch (tagId) { |
Chenjie Yu | 31d14d7 | 2017-12-12 17:54:33 -0800 | [diff] [blame] | 906 | case StatsLog.WIFI_BYTES_TRANSFER: { |
David Chen | 661f791 | 2018-01-22 17:46:24 -0800 | [diff] [blame] | 907 | pullWifiBytesTransfer(tagId, ret); |
| 908 | break; |
David Chen | c8a4324 | 2017-10-17 16:23:28 -0700 | [diff] [blame] | 909 | } |
Chenjie Yu | 31d14d7 | 2017-12-12 17:54:33 -0800 | [diff] [blame] | 910 | case StatsLog.MOBILE_BYTES_TRANSFER: { |
David Chen | 661f791 | 2018-01-22 17:46:24 -0800 | [diff] [blame] | 911 | pullMobileBytesTransfer(tagId, ret); |
| 912 | break; |
David Chen | c8a4324 | 2017-10-17 16:23:28 -0700 | [diff] [blame] | 913 | } |
Chenjie Yu | 31d14d7 | 2017-12-12 17:54:33 -0800 | [diff] [blame] | 914 | case StatsLog.WIFI_BYTES_TRANSFER_BY_FG_BG: { |
David Chen | 661f791 | 2018-01-22 17:46:24 -0800 | [diff] [blame] | 915 | pullWifiBytesTransferByFgBg(tagId, ret); |
| 916 | break; |
David Chen | c8a4324 | 2017-10-17 16:23:28 -0700 | [diff] [blame] | 917 | } |
Chenjie Yu | 31d14d7 | 2017-12-12 17:54:33 -0800 | [diff] [blame] | 918 | case StatsLog.MOBILE_BYTES_TRANSFER_BY_FG_BG: { |
David Chen | 661f791 | 2018-01-22 17:46:24 -0800 | [diff] [blame] | 919 | pullMobileBytesTransferByFgBg(tagId, ret); |
| 920 | break; |
Chenjie Yu | 9d7720b | 2018-01-24 10:34:48 -0800 | [diff] [blame] | 921 | } |
| 922 | case StatsLog.BLUETOOTH_BYTES_TRANSFER: { |
David Chen | 661f791 | 2018-01-22 17:46:24 -0800 | [diff] [blame] | 923 | pullBluetoothBytesTransfer(tagId, ret); |
| 924 | break; |
David Chen | c8a4324 | 2017-10-17 16:23:28 -0700 | [diff] [blame] | 925 | } |
Chenjie Yu | 31d14d7 | 2017-12-12 17:54:33 -0800 | [diff] [blame] | 926 | case StatsLog.KERNEL_WAKELOCK: { |
David Chen | 661f791 | 2018-01-22 17:46:24 -0800 | [diff] [blame] | 927 | pullKernelWakelock(tagId, ret); |
| 928 | break; |
David Chen | 1481fe1 | 2017-10-16 13:16:34 -0700 | [diff] [blame] | 929 | } |
Chenjie Yu | 31d14d7 | 2017-12-12 17:54:33 -0800 | [diff] [blame] | 930 | case StatsLog.CPU_TIME_PER_FREQ: { |
David Chen | 661f791 | 2018-01-22 17:46:24 -0800 | [diff] [blame] | 931 | pullCpuTimePerFreq(tagId, ret); |
| 932 | break; |
Chenjie Yu | 7f8def9 | 2017-11-03 09:33:15 -0700 | [diff] [blame] | 933 | } |
Chenjie Yu | ec67661 | 2018-03-07 09:19:17 -0800 | [diff] [blame] | 934 | case StatsLog.CPU_TIME_PER_UID: { |
| 935 | pullKernelUidCpuTime(tagId, ret); |
| 936 | break; |
| 937 | } |
| 938 | case StatsLog.CPU_TIME_PER_UID_FREQ: { |
| 939 | pullKernelUidCpuFreqTime(tagId, ret); |
| 940 | break; |
| 941 | } |
| 942 | case StatsLog.CPU_CLUSTER_TIME: { |
| 943 | pullKernelUidCpuClusterTime(tagId, ret); |
| 944 | break; |
| 945 | } |
| 946 | case StatsLog.CPU_ACTIVE_TIME: { |
| 947 | pullKernelUidCpuActiveTime(tagId, ret); |
| 948 | break; |
| 949 | } |
Chenjie Yu | 5caaa9d | 2018-03-06 15:48:54 -0800 | [diff] [blame] | 950 | case StatsLog.WIFI_ACTIVITY_INFO: { |
| 951 | pullWifiActivityInfo(tagId, ret); |
David Chen | 661f791 | 2018-01-22 17:46:24 -0800 | [diff] [blame] | 952 | break; |
Chenjie Yu | 05013b3 | 2017-11-21 10:21:41 -0800 | [diff] [blame] | 953 | } |
Chenjie Yu | 31d14d7 | 2017-12-12 17:54:33 -0800 | [diff] [blame] | 954 | case StatsLog.MODEM_ACTIVITY_INFO: { |
David Chen | 661f791 | 2018-01-22 17:46:24 -0800 | [diff] [blame] | 955 | pullModemActivityInfo(tagId, ret); |
| 956 | break; |
Chenjie Yu | 05013b3 | 2017-11-21 10:21:41 -0800 | [diff] [blame] | 957 | } |
Chenjie Yu | 9d7720b | 2018-01-24 10:34:48 -0800 | [diff] [blame] | 958 | case StatsLog.BLUETOOTH_ACTIVITY_INFO: { |
David Chen | 661f791 | 2018-01-22 17:46:24 -0800 | [diff] [blame] | 959 | pullBluetoothActivityInfo(tagId, ret); |
| 960 | break; |
Chenjie Yu | 937d742 | 2018-01-10 16:37:53 -0800 | [diff] [blame] | 961 | } |
| 962 | case StatsLog.SYSTEM_UPTIME: { |
David Chen | 661f791 | 2018-01-22 17:46:24 -0800 | [diff] [blame] | 963 | pullSystemUpTime(tagId, ret); |
| 964 | break; |
Chenjie Yu | 9d7720b | 2018-01-24 10:34:48 -0800 | [diff] [blame] | 965 | } |
| 966 | case StatsLog.SYSTEM_ELAPSED_REALTIME: { |
David Chen | 661f791 | 2018-01-22 17:46:24 -0800 | [diff] [blame] | 967 | pullSystemElapsedRealtime(tagId, ret); |
| 968 | break; |
Chenjie Yu | 9d7720b | 2018-01-24 10:34:48 -0800 | [diff] [blame] | 969 | } |
| 970 | case StatsLog.DISK_SPACE: { |
David Chen | 661f791 | 2018-01-22 17:46:24 -0800 | [diff] [blame] | 971 | pullDiskSpace(tagId, ret); |
| 972 | break; |
Chenjie Yu | 9da105b | 2018-01-13 12:41:08 -0800 | [diff] [blame] | 973 | } |
Rajeev Kumar | 22d92b7 | 2018-02-07 18:38:36 -0800 | [diff] [blame] | 974 | case StatsLog.PROCESS_MEMORY_STATE: { |
| 975 | pullProcessMemoryState(tagId, ret); |
| 976 | break; |
| 977 | } |
Bookatz | c68a9d2 | 2017-09-27 14:09:55 -0700 | [diff] [blame] | 978 | default: |
Chenjie Yu | 5305e1d | 2017-10-31 13:49:36 -0700 | [diff] [blame] | 979 | Slog.w(TAG, "No such tagId data as " + tagId); |
Bookatz | c68a9d2 | 2017-09-27 14:09:55 -0700 | [diff] [blame] | 980 | return null; |
| 981 | } |
Chenjie Yu | 9d7720b | 2018-01-24 10:34:48 -0800 | [diff] [blame] | 982 | return ret.toArray(new StatsLogEventWrapper[ret.size()]); |
Bookatz | c68a9d2 | 2017-09-27 14:09:55 -0700 | [diff] [blame] | 983 | } |
| 984 | |
| 985 | @Override // Binder call |
Bookatz | b487b55 | 2017-09-18 11:26:01 -0700 | [diff] [blame] | 986 | public void statsdReady() { |
| 987 | enforceCallingPermission(); |
| 988 | if (DEBUG) Slog.d(TAG, "learned that statsdReady"); |
| 989 | sayHiToStatsd(); // tell statsd that we're ready too and link to it |
Bookatz | 8178408 | 2018-02-09 14:26:42 -0800 | [diff] [blame] | 990 | mContext.sendBroadcastAsUser( |
| 991 | new Intent(StatsManager.ACTION_STATSD_STARTED) |
| 992 | .addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND), |
Bookatz | 0eb58ae39 | 2018-01-25 15:49:26 -0800 | [diff] [blame] | 993 | UserHandle.SYSTEM, |
Bookatz | 5c800e3 | 2018-01-24 14:59:52 -0800 | [diff] [blame] | 994 | android.Manifest.permission.DUMP); |
Bookatz | b487b55 | 2017-09-18 11:26:01 -0700 | [diff] [blame] | 995 | } |
| 996 | |
David Chen | c136f45 | 2017-11-27 11:52:26 -0800 | [diff] [blame] | 997 | @Override |
| 998 | public void triggerUidSnapshot() { |
David Chen | 661f791 | 2018-01-22 17:46:24 -0800 | [diff] [blame] | 999 | enforceCallingPermission(); |
| 1000 | synchronized (sStatsdLock) { |
David Chen | 35045cb | 2018-03-23 22:21:47 -0700 | [diff] [blame] | 1001 | final long token = Binder.clearCallingIdentity(); |
David Chen | 661f791 | 2018-01-22 17:46:24 -0800 | [diff] [blame] | 1002 | try { |
| 1003 | informAllUidsLocked(mContext); |
| 1004 | } catch (RemoteException e) { |
| 1005 | Slog.e(TAG, "Failed to trigger uid snapshot.", e); |
David Chen | 35045cb | 2018-03-23 22:21:47 -0700 | [diff] [blame] | 1006 | } finally { |
| 1007 | restoreCallingIdentity(token); |
David Chen | 661f791 | 2018-01-22 17:46:24 -0800 | [diff] [blame] | 1008 | } |
David Chen | c136f45 | 2017-11-27 11:52:26 -0800 | [diff] [blame] | 1009 | } |
David Chen | c136f45 | 2017-11-27 11:52:26 -0800 | [diff] [blame] | 1010 | } |
| 1011 | |
Bookatz | 9472641 | 2017-08-31 09:26:15 -0700 | [diff] [blame] | 1012 | private void enforceCallingPermission() { |
| 1013 | if (Binder.getCallingPid() == Process.myPid()) { |
| 1014 | return; |
| 1015 | } |
| 1016 | mContext.enforceCallingPermission(android.Manifest.permission.STATSCOMPANION, null); |
| 1017 | } |
| 1018 | |
Bookatz | b487b55 | 2017-09-18 11:26:01 -0700 | [diff] [blame] | 1019 | // Lifecycle and related code |
| 1020 | |
David Chen | 1481fe1 | 2017-10-16 13:16:34 -0700 | [diff] [blame] | 1021 | /** |
| 1022 | * Fetches the statsd IBinder service |
| 1023 | */ |
Bookatz | b487b55 | 2017-09-18 11:26:01 -0700 | [diff] [blame] | 1024 | private static IStatsManager fetchStatsdService() { |
| 1025 | return IStatsManager.Stub.asInterface(ServiceManager.getService("stats")); |
| 1026 | } |
| 1027 | |
| 1028 | public static final class Lifecycle extends SystemService { |
| 1029 | private StatsCompanionService mStatsCompanionService; |
| 1030 | |
| 1031 | public Lifecycle(Context context) { |
| 1032 | super(context); |
| 1033 | } |
| 1034 | |
| 1035 | @Override |
| 1036 | public void onStart() { |
| 1037 | mStatsCompanionService = new StatsCompanionService(getContext()); |
| 1038 | try { |
| 1039 | publishBinderService(Context.STATS_COMPANION_SERVICE, mStatsCompanionService); |
| 1040 | if (DEBUG) Slog.d(TAG, "Published " + Context.STATS_COMPANION_SERVICE); |
| 1041 | } catch (Exception e) { |
| 1042 | Slog.e(TAG, "Failed to publishBinderService", e); |
| 1043 | } |
| 1044 | } |
| 1045 | |
| 1046 | @Override |
| 1047 | public void onBootPhase(int phase) { |
| 1048 | super.onBootPhase(phase); |
| 1049 | if (phase == PHASE_THIRD_PARTY_APPS_CAN_START) { |
| 1050 | mStatsCompanionService.systemReady(); |
| 1051 | } |
| 1052 | } |
| 1053 | } |
| 1054 | |
David Chen | 1481fe1 | 2017-10-16 13:16:34 -0700 | [diff] [blame] | 1055 | /** |
| 1056 | * Now that the android system is ready, StatsCompanion is ready too, so inform statsd. |
| 1057 | */ |
Bookatz | b487b55 | 2017-09-18 11:26:01 -0700 | [diff] [blame] | 1058 | private void systemReady() { |
| 1059 | if (DEBUG) Slog.d(TAG, "Learned that systemReady"); |
| 1060 | sayHiToStatsd(); |
| 1061 | } |
| 1062 | |
David Chen | 1481fe1 | 2017-10-16 13:16:34 -0700 | [diff] [blame] | 1063 | /** |
| 1064 | * Tells statsd that statscompanion is ready. If the binder call returns, link to statsd. |
| 1065 | */ |
Bookatz | b487b55 | 2017-09-18 11:26:01 -0700 | [diff] [blame] | 1066 | private void sayHiToStatsd() { |
| 1067 | synchronized (sStatsdLock) { |
| 1068 | if (sStatsd != null) { |
| 1069 | Slog.e(TAG, "Trying to fetch statsd, but it was already fetched", |
| 1070 | new IllegalStateException("sStatsd is not null when being fetched")); |
| 1071 | return; |
| 1072 | } |
| 1073 | sStatsd = fetchStatsdService(); |
| 1074 | if (sStatsd == null) { |
Bookatz | 111ed73 | 2018-02-16 15:54:05 -0800 | [diff] [blame] | 1075 | Slog.i(TAG, "Could not yet find statsd to tell it that StatsCompanion is alive."); |
Bookatz | b487b55 | 2017-09-18 11:26:01 -0700 | [diff] [blame] | 1076 | return; |
| 1077 | } |
| 1078 | if (DEBUG) Slog.d(TAG, "Saying hi to statsd"); |
| 1079 | try { |
| 1080 | sStatsd.statsCompanionReady(); |
| 1081 | // If the statsCompanionReady two-way binder call returns, link to statsd. |
| 1082 | try { |
| 1083 | sStatsd.asBinder().linkToDeath(new StatsdDeathRecipient(), 0); |
| 1084 | } catch (RemoteException e) { |
| 1085 | Slog.e(TAG, "linkToDeath(StatsdDeathRecipient) failed", e); |
yro | e26c97b | 2018-03-27 10:30:11 -0700 | [diff] [blame] | 1086 | forgetEverythingLocked(); |
Bookatz | b487b55 | 2017-09-18 11:26:01 -0700 | [diff] [blame] | 1087 | } |
yro | 947fbce | 2017-11-15 22:50:23 -0800 | [diff] [blame] | 1088 | // Setup broadcast receiver for updates. |
David Chen | de70169 | 2017-10-05 13:16:02 -0700 | [diff] [blame] | 1089 | IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_REPLACED); |
| 1090 | filter.addAction(Intent.ACTION_PACKAGE_ADDED); |
| 1091 | filter.addAction(Intent.ACTION_PACKAGE_REMOVED); |
| 1092 | filter.addDataScheme("package"); |
| 1093 | mContext.registerReceiverAsUser(mAppUpdateReceiver, UserHandle.ALL, filter, null, |
David Chen | 1481fe1 | 2017-10-16 13:16:34 -0700 | [diff] [blame] | 1094 | null); |
David Chen | 47e8f4d | 2017-10-11 15:34:13 -0700 | [diff] [blame] | 1095 | |
| 1096 | // Setup receiver for user initialize (which happens once for a new user) and |
| 1097 | // if a user is removed. |
| 1098 | filter = new IntentFilter(Intent.ACTION_USER_INITIALIZE); |
| 1099 | filter.addAction(Intent.ACTION_USER_REMOVED); |
| 1100 | mContext.registerReceiverAsUser(mUserUpdateReceiver, UserHandle.ALL, |
David Chen | 1481fe1 | 2017-10-16 13:16:34 -0700 | [diff] [blame] | 1101 | filter, null, null); |
David Chen | 47e8f4d | 2017-10-11 15:34:13 -0700 | [diff] [blame] | 1102 | |
yro | 947fbce | 2017-11-15 22:50:23 -0800 | [diff] [blame] | 1103 | // Setup receiver for device reboots or shutdowns. |
| 1104 | filter = new IntentFilter(Intent.ACTION_REBOOT); |
| 1105 | filter.addAction(Intent.ACTION_SHUTDOWN); |
| 1106 | mContext.registerReceiverAsUser( |
| 1107 | mShutdownEventReceiver, UserHandle.ALL, filter, null, null); |
Yao Chen | 0f21710 | 2018-01-09 10:33:15 -0800 | [diff] [blame] | 1108 | final long token = Binder.clearCallingIdentity(); |
| 1109 | try { |
| 1110 | // Pull the latest state of UID->app name, version mapping when statsd starts. |
| 1111 | informAllUidsLocked(mContext); |
| 1112 | } finally { |
| 1113 | restoreCallingIdentity(token); |
| 1114 | } |
Bookatz | 111ed73 | 2018-02-16 15:54:05 -0800 | [diff] [blame] | 1115 | Slog.i(TAG, "Told statsd that StatsCompanionService is alive."); |
Bookatz | b487b55 | 2017-09-18 11:26:01 -0700 | [diff] [blame] | 1116 | } catch (RemoteException e) { |
| 1117 | Slog.e(TAG, "Failed to inform statsd that statscompanion is ready", e); |
yro | e26c97b | 2018-03-27 10:30:11 -0700 | [diff] [blame] | 1118 | forgetEverythingLocked(); |
Bookatz | b487b55 | 2017-09-18 11:26:01 -0700 | [diff] [blame] | 1119 | } |
| 1120 | } |
| 1121 | } |
| 1122 | |
| 1123 | private class StatsdDeathRecipient implements IBinder.DeathRecipient { |
| 1124 | @Override |
| 1125 | public void binderDied() { |
| 1126 | Slog.i(TAG, "Statsd is dead - erase all my knowledge."); |
yro | e26c97b | 2018-03-27 10:30:11 -0700 | [diff] [blame] | 1127 | synchronized (sStatsdLock) { |
| 1128 | long now = SystemClock.elapsedRealtime(); |
| 1129 | for (Long timeMillis : mDeathTimeMillis) { |
| 1130 | long ageMillis = now - timeMillis; |
| 1131 | if (ageMillis > MILLIS_IN_A_DAY) { |
| 1132 | mDeathTimeMillis.remove(timeMillis); |
| 1133 | } |
| 1134 | } |
| 1135 | for (Long timeMillis : mDeletedFiles.keySet()) { |
| 1136 | long ageMillis = now - timeMillis; |
| 1137 | if (ageMillis > MILLIS_IN_A_DAY * 7) { |
| 1138 | mDeletedFiles.remove(timeMillis); |
| 1139 | } |
| 1140 | } |
| 1141 | mDeathTimeMillis.add(now); |
| 1142 | if (mDeathTimeMillis.size() >= DEATH_THRESHOLD) { |
| 1143 | mDeathTimeMillis.clear(); |
| 1144 | File[] configs = FileUtils.listFilesOrEmpty(new File(CONFIG_DIR)); |
| 1145 | if (configs.length > 0) { |
| 1146 | String fileName = configs[0].getName(); |
| 1147 | if (configs[0].delete()) { |
| 1148 | mDeletedFiles.put(now, fileName); |
| 1149 | } |
| 1150 | } |
| 1151 | } |
| 1152 | forgetEverythingLocked(); |
| 1153 | } |
Bookatz | b487b55 | 2017-09-18 11:26:01 -0700 | [diff] [blame] | 1154 | } |
| 1155 | } |
| 1156 | |
yro | e26c97b | 2018-03-27 10:30:11 -0700 | [diff] [blame] | 1157 | private void forgetEverythingLocked() { |
| 1158 | sStatsd = null; |
| 1159 | mContext.unregisterReceiver(mAppUpdateReceiver); |
| 1160 | mContext.unregisterReceiver(mUserUpdateReceiver); |
| 1161 | mContext.unregisterReceiver(mShutdownEventReceiver); |
| 1162 | cancelAnomalyAlarm(); |
| 1163 | cancelPullingAlarm(); |
| 1164 | } |
| 1165 | |
| 1166 | @Override |
| 1167 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
| 1168 | if (!DumpUtils.checkDumpPermission(mContext, TAG, writer)) return; |
| 1169 | |
Bookatz | b487b55 | 2017-09-18 11:26:01 -0700 | [diff] [blame] | 1170 | synchronized (sStatsdLock) { |
yro | e26c97b | 2018-03-27 10:30:11 -0700 | [diff] [blame] | 1171 | writer.println("Number of configuration files deleted: " + mDeletedFiles.size()); |
| 1172 | if (mDeletedFiles.size() > 0) { |
| 1173 | writer.println(" timestamp, deleted file name"); |
| 1174 | } |
| 1175 | long lastBootMillis = |
| 1176 | SystemClock.currentThreadTimeMillis() - SystemClock.elapsedRealtime(); |
| 1177 | for (Long elapsedMillis : mDeletedFiles.keySet()) { |
| 1178 | long deletionMillis = lastBootMillis + elapsedMillis; |
| 1179 | writer.println(" " + deletionMillis + ", " + mDeletedFiles.get(elapsedMillis)); |
| 1180 | } |
Bookatz | b487b55 | 2017-09-18 11:26:01 -0700 | [diff] [blame] | 1181 | } |
| 1182 | } |
| 1183 | |
Bookatz | 9472641 | 2017-08-31 09:26:15 -0700 | [diff] [blame] | 1184 | } |