Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 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 android.app; |
| 18 | |
Svet Ganov | 16a1689 | 2015-04-16 10:32:04 -0700 | [diff] [blame] | 19 | import android.Manifest; |
Jeff Sharkey | 7095ab9 | 2019-08-20 16:50:28 -0600 | [diff] [blame] | 20 | import android.annotation.CallbackExecutor; |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 21 | import android.annotation.IntDef; |
Svet Ganov | 00a46ef | 2019-03-29 21:13:03 -0700 | [diff] [blame] | 22 | import android.annotation.IntRange; |
Svetoslav Ganov | 2d20fb4 | 2018-02-08 15:52:10 -0800 | [diff] [blame] | 23 | import android.annotation.NonNull; |
Hai Zhang | b777668 | 2018-09-25 15:10:57 -0700 | [diff] [blame] | 24 | import android.annotation.Nullable; |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 25 | import android.annotation.RequiresPermission; |
Jeff Davidson | 0554260 | 2014-08-11 14:07:27 -0700 | [diff] [blame] | 26 | import android.annotation.SystemApi; |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 27 | import android.annotation.SystemService; |
Peter Visontay | 5a2a1ef | 2017-12-18 20:34:03 +0000 | [diff] [blame] | 28 | import android.annotation.TestApi; |
Jeff Davidson | 0554260 | 2014-08-11 14:07:27 -0700 | [diff] [blame] | 29 | import android.app.usage.UsageStatsManager; |
Philip P. Moltmann | 7641cd0 | 2020-03-11 14:42:43 -0700 | [diff] [blame] | 30 | import android.compat.Compatibility; |
Philip P. Moltmann | b2bc651 | 2020-01-24 15:34:34 -0800 | [diff] [blame] | 31 | import android.compat.annotation.ChangeId; |
| 32 | import android.compat.annotation.EnabledAfter; |
Artur Satayev | c895b1b | 2019-12-10 17:47:51 +0000 | [diff] [blame] | 33 | import android.compat.annotation.UnsupportedAppUsage; |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 34 | import android.content.ContentResolver; |
Jeff Davidson | 0554260 | 2014-08-11 14:07:27 -0700 | [diff] [blame] | 35 | import android.content.Context; |
Ng Zhi An | 65a99b6 | 2018-10-01 11:57:53 -0700 | [diff] [blame] | 36 | import android.content.pm.PackageManager; |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 37 | import android.content.pm.ParceledListSlice; |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 38 | import android.database.DatabaseUtils; |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame] | 39 | import android.media.AudioAttributes.AttributeUsage; |
Dianne Hackborn | e98f5db | 2013-07-17 17:23:25 -0700 | [diff] [blame] | 40 | import android.os.Binder; |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 41 | import android.os.Build; |
| 42 | import android.os.Handler; |
| 43 | import android.os.HandlerExecutor; |
| 44 | import android.os.HandlerThread; |
Dianne Hackborn | e98f5db | 2013-07-17 17:23:25 -0700 | [diff] [blame] | 45 | import android.os.IBinder; |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 46 | import android.os.Looper; |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 47 | import android.os.Parcel; |
| 48 | import android.os.Parcelable; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 49 | import android.os.Process; |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 50 | import android.os.RemoteCallback; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 51 | import android.os.RemoteException; |
Stanislav Zholnin | 90516b9 | 2020-01-20 14:03:06 +0000 | [diff] [blame] | 52 | import android.os.ServiceManager; |
| 53 | import android.os.SystemClock; |
Jeff Davidson | 0554260 | 2014-08-11 14:07:27 -0700 | [diff] [blame] | 54 | import android.os.UserManager; |
| 55 | import android.util.ArrayMap; |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 56 | import android.util.ArraySet; |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 57 | import android.util.LongSparseArray; |
| 58 | import android.util.LongSparseLongArray; |
Philip P. Moltmann | d8c0bda | 2019-12-19 19:55:35 -0800 | [diff] [blame] | 59 | import android.util.Pools; |
Ng Zhi An | 65a99b6 | 2018-10-01 11:57:53 -0700 | [diff] [blame] | 60 | import android.util.SparseArray; |
Jeff Davidson | 0554260 | 2014-08-11 14:07:27 -0700 | [diff] [blame] | 61 | |
Svet Ganov | b3d2ae2 | 2018-12-17 22:06:15 -0800 | [diff] [blame] | 62 | import com.android.internal.annotations.GuardedBy; |
Svet Ganov | 23c88db | 2019-01-22 20:38:11 -0800 | [diff] [blame] | 63 | import com.android.internal.annotations.Immutable; |
Svetoslav Ganov | 2d20fb4 | 2018-02-08 15:52:10 -0800 | [diff] [blame] | 64 | import com.android.internal.app.IAppOpsActiveCallback; |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 65 | import com.android.internal.app.IAppOpsAsyncNotedCallback; |
Jeff Davidson | 0554260 | 2014-08-11 14:07:27 -0700 | [diff] [blame] | 66 | import com.android.internal.app.IAppOpsCallback; |
Svet Ganov | b3d2ae2 | 2018-12-17 22:06:15 -0800 | [diff] [blame] | 67 | import com.android.internal.app.IAppOpsNotedCallback; |
Jeff Davidson | 0554260 | 2014-08-11 14:07:27 -0700 | [diff] [blame] | 68 | import com.android.internal.app.IAppOpsService; |
Adam Bookatz | 182862e | 2020-04-27 21:58:22 -0700 | [diff] [blame] | 69 | import com.android.internal.app.IAppOpsStartedCallback; |
Stanislav Zholnin | 90516b9 | 2020-01-20 14:03:06 +0000 | [diff] [blame] | 70 | import com.android.internal.app.MessageSamplingConfig; |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 71 | import com.android.internal.os.RuntimeInit; |
| 72 | import com.android.internal.os.ZygoteInit; |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 73 | import com.android.internal.util.ArrayUtils; |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 74 | import com.android.internal.util.DataClass; |
Muhammad Qureshi | 317061a | 2020-03-02 13:15:51 -0800 | [diff] [blame] | 75 | import com.android.internal.util.FrameworkStatsLog; |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 76 | import com.android.internal.util.Parcelling; |
Svetoslav Ganov | 2d20fb4 | 2018-02-08 15:52:10 -0800 | [diff] [blame] | 77 | import com.android.internal.util.Preconditions; |
Jeff Davidson | 0554260 | 2014-08-11 14:07:27 -0700 | [diff] [blame] | 78 | |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 79 | import java.lang.annotation.ElementType; |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 80 | import java.lang.annotation.Retention; |
| 81 | import java.lang.annotation.RetentionPolicy; |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 82 | import java.lang.annotation.Target; |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 83 | import java.lang.reflect.Method; |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 84 | import java.math.BigDecimal; |
| 85 | import java.math.RoundingMode; |
Jeff Davidson | 0554260 | 2014-08-11 14:07:27 -0700 | [diff] [blame] | 86 | import java.util.ArrayList; |
Peter Visontay | 5a2a1ef | 2017-12-18 20:34:03 +0000 | [diff] [blame] | 87 | import java.util.Arrays; |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 88 | import java.util.BitSet; |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 89 | import java.util.Collections; |
Jeff Davidson | 0554260 | 2014-08-11 14:07:27 -0700 | [diff] [blame] | 90 | import java.util.HashMap; |
| 91 | import java.util.List; |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 92 | import java.util.Map; |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 93 | import java.util.Objects; |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 94 | import java.util.concurrent.Executor; |
| 95 | import java.util.function.Consumer; |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 96 | import java.util.function.Supplier; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 97 | |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 98 | /** |
Philip P. Moltmann | a04b9ab | 2020-02-13 09:54:04 -0800 | [diff] [blame] | 99 | * App-ops are used for two purposes: Access control and tracking. |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 100 | * |
Philip P. Moltmann | a04b9ab | 2020-02-13 09:54:04 -0800 | [diff] [blame] | 101 | * <p>App-ops cover a wide variety of functionality from helping with runtime permissions access |
| 102 | * control and tracking to battery consumption tracking. |
Philip P. Moltmann | 9e36700 | 2020-02-03 17:01:05 -0800 | [diff] [blame] | 103 | * |
Philip P. Moltmann | a04b9ab | 2020-02-13 09:54:04 -0800 | [diff] [blame] | 104 | * <h2>Access control</h2> |
| 105 | * |
| 106 | * <p>App-ops can either be controlled for each uid or for each package. Which one is used depends |
| 107 | * on the API provider maintaining this app-op. For any security or privacy related app-op the |
| 108 | * provider needs to control the app-op for per uid as all security and privacy is based on uid in |
| 109 | * Android. |
| 110 | * |
| 111 | * <p>To control access the app-op can be set to a mode to: |
| 112 | * <dl> |
| 113 | * <dt>{@link #MODE_DEFAULT} |
| 114 | * <dd>Default behavior, might differ from app-op or app-op |
| 115 | * <dt>{@link #MODE_ALLOWED} |
| 116 | * <dd>Allow the access |
| 117 | * <dt>{@link #MODE_IGNORED} |
| 118 | * <dd>Don't allow the access, i.e. don't perform the requested action or return no or dummy |
| 119 | * data |
| 120 | * <dt>{@link #MODE_ERRORED} |
| 121 | * <dd>Throw a {@link SecurityException} on access. This can be suppressed by using a |
| 122 | * {@code ...noThrow} method to check the mode |
| 123 | * </dl> |
| 124 | * |
| 125 | * <p>API providers need to check the mode returned by {@link #noteOp} if they are are allowing |
| 126 | * access to operations gated by the app-op. {@link #unsafeCheckOp} should be used to check the |
| 127 | * mode if no access is granted. E.g. this can be used for displaying app-op state in the UI or |
| 128 | * when checking the state before later calling {@link #noteOp} anyway. |
| 129 | * |
| 130 | * <p>If an operation refers to a time span (e.g. a audio-recording session) the API provider |
| 131 | * should use {@link #startOp} and {@link #finishOp} instead of {@link #noteOp}. |
| 132 | * |
| 133 | * <h3>Runtime permissions and app-ops</h3> |
| 134 | * |
| 135 | * <p>Each platform defined runtime permission (beside background modifiers) has an associated app |
| 136 | * op which is used for tracking but also to allow for silent failures. I.e. if the runtime |
| 137 | * permission is denied the caller gets a {@link SecurityException}, but if the permission is |
| 138 | * granted and the app-op is {@link #MODE_IGNORED} then the callers gets dummy behavior, e.g. |
| 139 | * location callbacks would not happen. |
| 140 | * |
| 141 | * <h3>App-op permissions</h3> |
| 142 | * |
| 143 | * <p>App-ops permissions are platform defined permissions that can be overridden. The security |
| 144 | * check for app-op permissions should by {@link #MODE_DEFAULT default} check the permission grant |
| 145 | * state. If the app-op state is set to {@link #MODE_ALLOWED} or {@link #MODE_IGNORED} the app-op |
| 146 | * state should be checked instead of the permission grant state. |
| 147 | * |
| 148 | * <p>This functionality allows to grant access by default to apps fulfilling the requirements for |
| 149 | * a certain permission level. Still the behavior can be overridden when needed. |
| 150 | * |
| 151 | * <h2>Tracking</h2> |
| 152 | * |
| 153 | * <p>App-ops track many important events, including all accesses to runtime permission protected |
| 154 | * APIs. This is done by tracking when an app-op was {@link #noteOp noted} or |
| 155 | * {@link #startOp started}. The tracked data can only be read by system components. |
| 156 | * |
| 157 | * <p><b>Only {@link #noteOp}/{@link #startOp} are tracked; {@link #unsafeCheckOp} is not tracked. |
| 158 | * Hence it is important to eventually call {@link #noteOp} or {@link #startOp} when providing |
| 159 | * access to protected operations or data.</b> |
| 160 | * |
| 161 | * <p>Some apps are forwarding access to other apps. E.g. an app might get the location from the |
| 162 | * system's location provider and then send the location further to a 3rd app. In this case the |
| 163 | * app passing on the data needs to call {@link #noteProxyOp} to signal the access proxying. This |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 164 | * might also make sense inside of a single app if the access is forwarded between two parts of |
| 165 | * the tagged with different attribution tags. |
Philip P. Moltmann | a04b9ab | 2020-02-13 09:54:04 -0800 | [diff] [blame] | 166 | * |
Philip P. Moltmann | 5892a8f | 2020-03-03 12:05:55 -0800 | [diff] [blame] | 167 | * <p>An app can register an {@link OnOpNotedCallback} to get informed about what accesses the |
Philip P. Moltmann | a04b9ab | 2020-02-13 09:54:04 -0800 | [diff] [blame] | 168 | * system is tracking for it. As each runtime permission has an associated app-op this API is |
| 169 | * particularly useful for an app that want to find unexpected private data accesses. |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 170 | */ |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 171 | @SystemService(Context.APP_OPS_SERVICE) |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 172 | public class AppOpsManager { |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 173 | /** |
Philip P. Moltmann | b2bc651 | 2020-01-24 15:34:34 -0800 | [diff] [blame] | 174 | * This is a subtle behavior change to {@link #startWatchingMode}. |
| 175 | * |
| 176 | * Before this change the system called back for the switched op. After the change the system |
| 177 | * will call back for the actually requested op or all switched ops if no op is specified. |
| 178 | * |
| 179 | * @hide |
| 180 | */ |
| 181 | @ChangeId |
| 182 | @EnabledAfter(targetSdkVersion = Build.VERSION_CODES.Q) |
| 183 | public static final long CALL_BACK_ON_CHANGED_LISTENER_WITH_SWITCHED_OP_CHANGE = 148180766L; |
| 184 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 185 | final Context mContext; |
Svet Ganov | b3d2ae2 | 2018-12-17 22:06:15 -0800 | [diff] [blame] | 186 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 187 | @UnsupportedAppUsage |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 188 | final IAppOpsService mService; |
Svet Ganov | b3d2ae2 | 2018-12-17 22:06:15 -0800 | [diff] [blame] | 189 | |
Stanislav Zholnin | 90516b9 | 2020-01-20 14:03:06 +0000 | [diff] [blame] | 190 | /** |
| 191 | * Service for the application context, to be used by static methods via |
| 192 | * {@link #getService()} |
| 193 | */ |
| 194 | @GuardedBy("sLock") |
| 195 | static IAppOpsService sService; |
| 196 | |
Svet Ganov | b3d2ae2 | 2018-12-17 22:06:15 -0800 | [diff] [blame] | 197 | @GuardedBy("mModeWatchers") |
| 198 | private final ArrayMap<OnOpChangedListener, IAppOpsCallback> mModeWatchers = |
| 199 | new ArrayMap<>(); |
| 200 | |
| 201 | @GuardedBy("mActiveWatchers") |
| 202 | private final ArrayMap<OnOpActiveChangedListener, IAppOpsActiveCallback> mActiveWatchers = |
| 203 | new ArrayMap<>(); |
| 204 | |
Adam Bookatz | 182862e | 2020-04-27 21:58:22 -0700 | [diff] [blame] | 205 | @GuardedBy("mStartedWatchers") |
| 206 | private final ArrayMap<OnOpStartedListener, IAppOpsStartedCallback> mStartedWatchers = |
| 207 | new ArrayMap<>(); |
| 208 | |
Svet Ganov | b3d2ae2 | 2018-12-17 22:06:15 -0800 | [diff] [blame] | 209 | @GuardedBy("mNotedWatchers") |
| 210 | private final ArrayMap<OnOpNotedListener, IAppOpsNotedCallback> mNotedWatchers = |
Svetoslav Ganov | 2d20fb4 | 2018-02-08 15:52:10 -0800 | [diff] [blame] | 211 | new ArrayMap<>(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 212 | |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 213 | private static final Object sLock = new Object(); |
| 214 | |
Philip P. Moltmann | 5892a8f | 2020-03-03 12:05:55 -0800 | [diff] [blame] | 215 | /** Current {@link OnOpNotedCallback}. Change via {@link #setOnOpNotedCallback} */ |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 216 | @GuardedBy("sLock") |
Philip P. Moltmann | 5892a8f | 2020-03-03 12:05:55 -0800 | [diff] [blame] | 217 | private static @Nullable OnOpNotedCallback sOnOpNotedCallback; |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 218 | |
Stanislav Zholnin | 90516b9 | 2020-01-20 14:03:06 +0000 | [diff] [blame] | 219 | /** |
| 220 | * Additional collector that collect accesses and forwards a few of them them via |
| 221 | * {@link IAppOpsService#reportRuntimeAppOpAccessMessageAndGetConfig}. |
| 222 | */ |
Philip P. Moltmann | 5892a8f | 2020-03-03 12:05:55 -0800 | [diff] [blame] | 223 | private static OnOpNotedCallback sMessageCollector = |
| 224 | new OnOpNotedCallback() { |
Stanislav Zholnin | 90516b9 | 2020-01-20 14:03:06 +0000 | [diff] [blame] | 225 | @Override |
| 226 | public void onNoted(@NonNull SyncNotedAppOp op) { |
| 227 | reportStackTraceIfNeeded(op); |
| 228 | } |
| 229 | |
| 230 | @Override |
| 231 | public void onAsyncNoted(@NonNull AsyncNotedAppOp asyncOp) { |
| 232 | // collected directly in AppOpsService |
| 233 | } |
| 234 | |
| 235 | @Override |
| 236 | public void onSelfNoted(@NonNull SyncNotedAppOp op) { |
| 237 | reportStackTraceIfNeeded(op); |
| 238 | } |
| 239 | |
| 240 | private void reportStackTraceIfNeeded(@NonNull SyncNotedAppOp op) { |
Stanislav Zholnin | d4968a0 | 2020-04-18 21:01:13 +0100 | [diff] [blame] | 241 | if (!isCollectingStackTraces()) { |
Stanislav Zholnin | 90516b9 | 2020-01-20 14:03:06 +0000 | [diff] [blame] | 242 | return; |
| 243 | } |
Stanislav Zholnin | 90516b9 | 2020-01-20 14:03:06 +0000 | [diff] [blame] | 244 | MessageSamplingConfig config = sConfig; |
| 245 | if (leftCircularDistance(strOpToOp(op.getOp()), config.getSampledOpCode(), |
| 246 | _NUM_OP) <= config.getAcceptableLeftDistance() |
| 247 | || config.getExpirationTimeSinceBootMillis() |
| 248 | < SystemClock.elapsedRealtime()) { |
| 249 | String stackTrace = getFormattedStackTrace(); |
| 250 | try { |
| 251 | sConfig = getService().reportRuntimeAppOpAccessMessageAndGetConfig( |
| 252 | ActivityThread.currentOpPackageName(), op, stackTrace); |
| 253 | } catch (RemoteException e) { |
| 254 | e.rethrowFromSystemServer(); |
| 255 | } |
| 256 | } |
| 257 | } |
| 258 | }; |
| 259 | |
Philip P. Moltmann | 6c6403e | 2019-12-09 10:08:29 -0800 | [diff] [blame] | 260 | static IBinder sClientId; |
Dianne Hackborn | e98f5db | 2013-07-17 17:23:25 -0700 | [diff] [blame] | 261 | |
Philip P. Moltmann | e565c7b | 2020-01-28 13:15:52 -0800 | [diff] [blame] | 262 | /** |
| 263 | * How many seconds we want for a drop in uid state from top to settle before applying it. |
| 264 | * |
| 265 | * <>Set a parameter to {@link android.provider.Settings.Global#APP_OPS_CONSTANTS} |
| 266 | * |
| 267 | * @hide |
| 268 | */ |
| 269 | @TestApi |
| 270 | public static final String KEY_TOP_STATE_SETTLE_TIME = "top_state_settle_time"; |
| 271 | |
| 272 | /** |
| 273 | * How many second we want for a drop in uid state from foreground to settle before applying it. |
| 274 | * |
| 275 | * <>Set a parameter to {@link android.provider.Settings.Global#APP_OPS_CONSTANTS} |
| 276 | * |
| 277 | * @hide |
| 278 | */ |
| 279 | @TestApi |
| 280 | public static final String KEY_FG_SERVICE_STATE_SETTLE_TIME = |
| 281 | "fg_service_state_settle_time"; |
| 282 | |
| 283 | /** |
| 284 | * How many seconds we want for a drop in uid state from background to settle before applying |
| 285 | * it. |
| 286 | * |
| 287 | * <>Set a parameter to {@link android.provider.Settings.Global#APP_OPS_CONSTANTS} |
| 288 | * |
| 289 | * @hide |
| 290 | */ |
| 291 | @TestApi |
| 292 | public static final String KEY_BG_STATE_SETTLE_TIME = "bg_state_settle_time"; |
| 293 | |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 294 | /** @hide */ |
| 295 | @Retention(RetentionPolicy.SOURCE) |
| 296 | @IntDef(flag = true, prefix = { "HISTORICAL_MODE_" }, value = { |
| 297 | HISTORICAL_MODE_DISABLED, |
| 298 | HISTORICAL_MODE_ENABLED_ACTIVE, |
| 299 | HISTORICAL_MODE_ENABLED_PASSIVE |
| 300 | }) |
| 301 | public @interface HistoricalMode {} |
| 302 | |
| 303 | /** |
| 304 | * Mode in which app op history is completely disabled. |
| 305 | * @hide |
| 306 | */ |
| 307 | @TestApi |
| 308 | public static final int HISTORICAL_MODE_DISABLED = 0; |
| 309 | |
| 310 | /** |
| 311 | * Mode in which app op history is enabled and app ops performed by apps would |
| 312 | * be tracked. This is the mode in which the feature is completely enabled. |
| 313 | * @hide |
| 314 | */ |
| 315 | @TestApi |
| 316 | public static final int HISTORICAL_MODE_ENABLED_ACTIVE = 1; |
| 317 | |
| 318 | /** |
| 319 | * Mode in which app op history is enabled but app ops performed by apps would |
| 320 | * not be tracked and the only way to add ops to the history is via explicit calls |
| 321 | * to dedicated APIs. This mode is useful for testing to allow full control of |
| 322 | * the historical content. |
| 323 | * @hide |
| 324 | */ |
| 325 | @TestApi |
| 326 | public static final int HISTORICAL_MODE_ENABLED_PASSIVE = 2; |
| 327 | |
| 328 | /** @hide */ |
| 329 | @Retention(RetentionPolicy.SOURCE) |
| 330 | @IntDef(flag = true, prefix = { "MODE_" }, value = { |
| 331 | MODE_ALLOWED, |
| 332 | MODE_IGNORED, |
| 333 | MODE_ERRORED, |
| 334 | MODE_DEFAULT, |
| 335 | MODE_FOREGROUND |
| 336 | }) |
| 337 | public @interface Mode {} |
| 338 | |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 339 | /** |
| 340 | * Result from {@link #checkOp}, {@link #noteOp}, {@link #startOp}: the given caller is |
| 341 | * allowed to perform the given operation. |
| 342 | */ |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 343 | public static final int MODE_ALLOWED = 0; |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 344 | |
| 345 | /** |
| 346 | * Result from {@link #checkOp}, {@link #noteOp}, {@link #startOp}: the given caller is |
| 347 | * not allowed to perform the given operation, and this attempt should |
| 348 | * <em>silently fail</em> (it should not cause the app to crash). |
| 349 | */ |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 350 | public static final int MODE_IGNORED = 1; |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 351 | |
| 352 | /** |
| 353 | * Result from {@link #checkOpNoThrow}, {@link #noteOpNoThrow}, {@link #startOpNoThrow}: the |
| 354 | * given caller is not allowed to perform the given operation, and this attempt should |
| 355 | * cause it to have a fatal error, typically a {@link SecurityException}. |
| 356 | */ |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 357 | public static final int MODE_ERRORED = 2; |
| 358 | |
Dianne Hackborn | 33f5ddd | 2014-07-21 15:35:45 -0700 | [diff] [blame] | 359 | /** |
| 360 | * Result from {@link #checkOp}, {@link #noteOp}, {@link #startOp}: the given caller should |
| 361 | * use its default security check. This mode is not normally used; it should only be used |
| 362 | * with appop permissions, and callers must explicitly check for it and deal with it. |
| 363 | */ |
| 364 | public static final int MODE_DEFAULT = 3; |
| 365 | |
Dianne Hackborn | cd1f30b | 2018-04-23 17:38:09 -0700 | [diff] [blame] | 366 | /** |
Dianne Hackborn | c216a26 | 2018-04-26 13:46:22 -0700 | [diff] [blame] | 367 | * Special mode that means "allow only when app is in foreground." This is <b>not</b> |
Dianne Hackborn | f8709f5 | 2019-02-04 16:31:24 -0800 | [diff] [blame] | 368 | * returned from {@link #unsafeCheckOp}, {@link #noteOp}, {@link #startOp}. Rather, |
| 369 | * {@link #unsafeCheckOp} will always return {@link #MODE_ALLOWED} (because it is always |
| 370 | * possible for it to be ultimately allowed, depending on the app's background state), |
| 371 | * and {@link #noteOp} and {@link #startOp} will return {@link #MODE_ALLOWED} when the app |
| 372 | * being checked is currently in the foreground, otherwise {@link #MODE_IGNORED}. |
| 373 | * |
| 374 | * <p>The only place you will this normally see this value is through |
| 375 | * {@link #unsafeCheckOpRaw}, which returns the actual raw mode of the op. Note that because |
| 376 | * you can't know the current state of the app being checked (and it can change at any |
| 377 | * point), you can only treat the result here as an indication that it will vary between |
| 378 | * {@link #MODE_ALLOWED} and {@link #MODE_IGNORED} depending on changes in the background |
| 379 | * state of the app. You thus must always use {@link #noteOp} or {@link #startOp} to do |
| 380 | * the actual check for access to the op.</p> |
Dianne Hackborn | c216a26 | 2018-04-26 13:46:22 -0700 | [diff] [blame] | 381 | */ |
| 382 | public static final int MODE_FOREGROUND = 4; |
| 383 | |
Dianne Hackborn | 65a4f25 | 2018-05-08 17:30:48 -0700 | [diff] [blame] | 384 | /** |
| 385 | * Flag for {@link #startWatchingMode(String, String, int, OnOpChangedListener)}: |
| 386 | * Also get reports if the foreground state of an op's uid changes. This only works |
| 387 | * when watching a particular op, not when watching a package. |
Dianne Hackborn | 65a4f25 | 2018-05-08 17:30:48 -0700 | [diff] [blame] | 388 | */ |
| 389 | public static final int WATCH_FOREGROUND_CHANGES = 1 << 0; |
Dianne Hackborn | c216a26 | 2018-04-26 13:46:22 -0700 | [diff] [blame] | 390 | |
Philip P. Moltmann | 7641cd0 | 2020-03-11 14:42:43 -0700 | [diff] [blame] | 391 | /** |
| 392 | * Flag for {@link #startWatchingMode} that causes the callback to happen on the switch-op |
| 393 | * instead the op the callback was registered. (This simulates pre-R behavior). |
| 394 | * |
| 395 | * @hide |
| 396 | */ |
| 397 | public static final int CALL_BACK_ON_SWITCHED_OP = 1 << 1; |
David Cheung | 2ead966 | 2020-02-19 16:11:06 -0800 | [diff] [blame] | 398 | |
| 399 | /** |
| 400 | * Flag to determine whether we should log noteOp/startOp calls to make sure they |
| 401 | * are correctly used |
| 402 | * |
| 403 | * @hide |
| 404 | */ |
| 405 | public static final boolean NOTE_OP_COLLECTION_ENABLED = false; |
| 406 | |
Dianne Hackborn | c216a26 | 2018-04-26 13:46:22 -0700 | [diff] [blame] | 407 | /** |
| 408 | * @hide |
| 409 | */ |
| 410 | public static final String[] MODE_NAMES = new String[] { |
| 411 | "allow", // MODE_ALLOWED |
| 412 | "ignore", // MODE_IGNORED |
| 413 | "deny", // MODE_ERRORED |
| 414 | "default", // MODE_DEFAULT |
| 415 | "foreground", // MODE_FOREGROUND |
| 416 | }; |
| 417 | |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 418 | /** @hide */ |
| 419 | @Retention(RetentionPolicy.SOURCE) |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 420 | @IntDef(prefix = { "UID_STATE_" }, value = { |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 421 | UID_STATE_PERSISTENT, |
| 422 | UID_STATE_TOP, |
Amith Yamasani | a0a30a1 | 2019-01-22 11:38:06 -0800 | [diff] [blame] | 423 | UID_STATE_FOREGROUND_SERVICE_LOCATION, |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 424 | UID_STATE_FOREGROUND_SERVICE, |
| 425 | UID_STATE_FOREGROUND, |
| 426 | UID_STATE_BACKGROUND, |
| 427 | UID_STATE_CACHED |
| 428 | }) |
| 429 | public @interface UidState {} |
| 430 | |
Dianne Hackborn | c216a26 | 2018-04-26 13:46:22 -0700 | [diff] [blame] | 431 | /** |
Svet Ganov | 05fcd22 | 2019-07-08 16:30:45 -0700 | [diff] [blame] | 432 | * Uid state: The UID is a foreground persistent app. The lower the UID |
| 433 | * state the more important the UID is for the user. |
Dianne Hackborn | cd1f30b | 2018-04-23 17:38:09 -0700 | [diff] [blame] | 434 | * @hide |
| 435 | */ |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 436 | @TestApi |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 437 | @SystemApi |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 438 | public static final int UID_STATE_PERSISTENT = 100; |
Dianne Hackborn | cd1f30b | 2018-04-23 17:38:09 -0700 | [diff] [blame] | 439 | |
| 440 | /** |
Svet Ganov | 05fcd22 | 2019-07-08 16:30:45 -0700 | [diff] [blame] | 441 | * Uid state: The UID is top foreground app. The lower the UID |
| 442 | * state the more important the UID is for the user. |
Dianne Hackborn | cd1f30b | 2018-04-23 17:38:09 -0700 | [diff] [blame] | 443 | * @hide |
| 444 | */ |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 445 | @TestApi |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 446 | @SystemApi |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 447 | public static final int UID_STATE_TOP = 200; |
Dianne Hackborn | cd1f30b | 2018-04-23 17:38:09 -0700 | [diff] [blame] | 448 | |
| 449 | /** |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 450 | * Uid state: The UID is running a foreground service of location type. |
Svet Ganov | 05fcd22 | 2019-07-08 16:30:45 -0700 | [diff] [blame] | 451 | * The lower the UID state the more important the UID is for the user. |
Hui Yu | 2696932 | 2019-08-21 14:56:35 -0700 | [diff] [blame] | 452 | * This uid state is a counterpart to PROCESS_STATE_FOREGROUND_SERVICE_LOCATION which has been |
| 453 | * deprecated. |
Amith Yamasani | a0a30a1 | 2019-01-22 11:38:06 -0800 | [diff] [blame] | 454 | * @hide |
Hui Yu | 2696932 | 2019-08-21 14:56:35 -0700 | [diff] [blame] | 455 | * @deprecated |
Amith Yamasani | a0a30a1 | 2019-01-22 11:38:06 -0800 | [diff] [blame] | 456 | */ |
| 457 | @TestApi |
| 458 | @SystemApi |
Hui Yu | 2696932 | 2019-08-21 14:56:35 -0700 | [diff] [blame] | 459 | @Deprecated |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 460 | public static final int UID_STATE_FOREGROUND_SERVICE_LOCATION = 300; |
Amith Yamasani | a0a30a1 | 2019-01-22 11:38:06 -0800 | [diff] [blame] | 461 | |
| 462 | /** |
Svet Ganov | 05fcd22 | 2019-07-08 16:30:45 -0700 | [diff] [blame] | 463 | * Uid state: The UID is running a foreground service. The lower the UID |
| 464 | * state the more important the UID is for the user. |
Dianne Hackborn | cd1f30b | 2018-04-23 17:38:09 -0700 | [diff] [blame] | 465 | * @hide |
| 466 | */ |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 467 | @TestApi |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 468 | @SystemApi |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 469 | public static final int UID_STATE_FOREGROUND_SERVICE = 400; |
Dianne Hackborn | cd1f30b | 2018-04-23 17:38:09 -0700 | [diff] [blame] | 470 | |
| 471 | /** |
Svet Ganov | 05fcd22 | 2019-07-08 16:30:45 -0700 | [diff] [blame] | 472 | * Uid state: The UID is a foreground app. The lower the UID |
| 473 | * state the more important the UID is for the user. |
Dianne Hackborn | cd1f30b | 2018-04-23 17:38:09 -0700 | [diff] [blame] | 474 | * @hide |
| 475 | */ |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 476 | @TestApi |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 477 | @SystemApi |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 478 | public static final int UID_STATE_FOREGROUND = 500; |
Dianne Hackborn | cd1f30b | 2018-04-23 17:38:09 -0700 | [diff] [blame] | 479 | |
| 480 | /** |
Hui Yu | 2696932 | 2019-08-21 14:56:35 -0700 | [diff] [blame] | 481 | * The max, which is min priority, UID state for which any app op |
| 482 | * would be considered as performed in the foreground. |
| 483 | * @hide |
| 484 | */ |
| 485 | public static final int UID_STATE_MAX_LAST_NON_RESTRICTED = UID_STATE_FOREGROUND; |
| 486 | |
| 487 | /** |
Svet Ganov | 05fcd22 | 2019-07-08 16:30:45 -0700 | [diff] [blame] | 488 | * Uid state: The UID is a background app. The lower the UID |
| 489 | * state the more important the UID is for the user. |
Dianne Hackborn | cd1f30b | 2018-04-23 17:38:09 -0700 | [diff] [blame] | 490 | * @hide |
| 491 | */ |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 492 | @TestApi |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 493 | @SystemApi |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 494 | public static final int UID_STATE_BACKGROUND = 600; |
Dianne Hackborn | cd1f30b | 2018-04-23 17:38:09 -0700 | [diff] [blame] | 495 | |
| 496 | /** |
Svet Ganov | 05fcd22 | 2019-07-08 16:30:45 -0700 | [diff] [blame] | 497 | * Uid state: The UID is a cached app. The lower the UID |
| 498 | * state the more important the UID is for the user. |
Dianne Hackborn | cd1f30b | 2018-04-23 17:38:09 -0700 | [diff] [blame] | 499 | * @hide |
| 500 | */ |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 501 | @TestApi |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 502 | @SystemApi |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 503 | public static final int UID_STATE_CACHED = 700; |
Dianne Hackborn | cd1f30b | 2018-04-23 17:38:09 -0700 | [diff] [blame] | 504 | |
| 505 | /** |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 506 | * Uid state: The UID state with the highest priority. |
Dianne Hackborn | cd1f30b | 2018-04-23 17:38:09 -0700 | [diff] [blame] | 507 | * @hide |
| 508 | */ |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 509 | public static final int MAX_PRIORITY_UID_STATE = UID_STATE_PERSISTENT; |
| 510 | |
| 511 | /** |
| 512 | * Uid state: The UID state with the lowest priority. |
| 513 | * @hide |
| 514 | */ |
| 515 | public static final int MIN_PRIORITY_UID_STATE = UID_STATE_CACHED; |
| 516 | |
| 517 | /** |
Hui Yu | 2696932 | 2019-08-21 14:56:35 -0700 | [diff] [blame] | 518 | * Resolves the first unrestricted state given an app op. |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 519 | * @param op The op to resolve. |
| 520 | * @return The last restricted UID state. |
| 521 | * |
| 522 | * @hide |
| 523 | */ |
| 524 | public static int resolveFirstUnrestrictedUidState(int op) { |
Hui Yu | 2696932 | 2019-08-21 14:56:35 -0700 | [diff] [blame] | 525 | return UID_STATE_FOREGROUND; |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 526 | } |
| 527 | |
| 528 | /** |
Hui Yu | 2696932 | 2019-08-21 14:56:35 -0700 | [diff] [blame] | 529 | * Resolves the last restricted state given an app op. |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 530 | * @param op The op to resolve. |
| 531 | * @return The last restricted UID state. |
| 532 | * |
| 533 | * @hide |
| 534 | */ |
| 535 | public static int resolveLastRestrictedUidState(int op) { |
Hui Yu | 2696932 | 2019-08-21 14:56:35 -0700 | [diff] [blame] | 536 | return UID_STATE_BACKGROUND; |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 537 | } |
| 538 | |
| 539 | /** @hide Note: Keep these sorted */ |
| 540 | public static final int[] UID_STATES = { |
| 541 | UID_STATE_PERSISTENT, |
| 542 | UID_STATE_TOP, |
| 543 | UID_STATE_FOREGROUND_SERVICE_LOCATION, |
| 544 | UID_STATE_FOREGROUND_SERVICE, |
| 545 | UID_STATE_FOREGROUND, |
| 546 | UID_STATE_BACKGROUND, |
| 547 | UID_STATE_CACHED |
| 548 | }; |
| 549 | |
| 550 | /** @hide */ |
| 551 | public static String getUidStateName(@UidState int uidState) { |
| 552 | switch (uidState) { |
| 553 | case UID_STATE_PERSISTENT: |
| 554 | return "pers"; |
| 555 | case UID_STATE_TOP: |
| 556 | return "top"; |
| 557 | case UID_STATE_FOREGROUND_SERVICE_LOCATION: |
| 558 | return "fgsvcl"; |
| 559 | case UID_STATE_FOREGROUND_SERVICE: |
| 560 | return "fgsvc"; |
| 561 | case UID_STATE_FOREGROUND: |
| 562 | return "fg"; |
| 563 | case UID_STATE_BACKGROUND: |
| 564 | return "bg"; |
| 565 | case UID_STATE_CACHED: |
| 566 | return "cch"; |
| 567 | default: |
| 568 | return "unknown"; |
| 569 | } |
| 570 | } |
| 571 | |
| 572 | /** |
| 573 | * Flag: non proxy operations. These are operations |
| 574 | * performed on behalf of the app itself and not on behalf of |
| 575 | * another one. |
| 576 | * |
| 577 | * @hide |
| 578 | */ |
| 579 | @TestApi |
| 580 | @SystemApi |
| 581 | public static final int OP_FLAG_SELF = 0x1; |
| 582 | |
| 583 | /** |
| 584 | * Flag: trusted proxy operations. These are operations |
| 585 | * performed on behalf of another app by a trusted app. |
| 586 | * Which is work a trusted app blames on another app. |
| 587 | * |
| 588 | * @hide |
| 589 | */ |
| 590 | @TestApi |
| 591 | @SystemApi |
| 592 | public static final int OP_FLAG_TRUSTED_PROXY = 0x2; |
| 593 | |
| 594 | /** |
| 595 | * Flag: untrusted proxy operations. These are operations |
| 596 | * performed on behalf of another app by an untrusted app. |
| 597 | * Which is work an untrusted app blames on another app. |
| 598 | * |
| 599 | * @hide |
| 600 | */ |
| 601 | @TestApi |
| 602 | @SystemApi |
| 603 | public static final int OP_FLAG_UNTRUSTED_PROXY = 0x4; |
| 604 | |
| 605 | /** |
| 606 | * Flag: trusted proxied operations. These are operations |
| 607 | * performed by a trusted other app on behalf of an app. |
| 608 | * Which is work an app was blamed for by a trusted app. |
| 609 | * |
| 610 | * @hide |
| 611 | */ |
| 612 | @TestApi |
| 613 | @SystemApi |
| 614 | public static final int OP_FLAG_TRUSTED_PROXIED = 0x8; |
| 615 | |
| 616 | /** |
| 617 | * Flag: untrusted proxied operations. These are operations |
| 618 | * performed by an untrusted other app on behalf of an app. |
| 619 | * Which is work an app was blamed for by an untrusted app. |
| 620 | * |
| 621 | * @hide |
| 622 | */ |
| 623 | @TestApi |
| 624 | @SystemApi |
| 625 | public static final int OP_FLAG_UNTRUSTED_PROXIED = 0x10; |
| 626 | |
| 627 | /** |
| 628 | * Flags: all operations. These include operations matched |
| 629 | * by {@link #OP_FLAG_SELF}, {@link #OP_FLAG_TRUSTED_PROXIED}, |
| 630 | * {@link #OP_FLAG_UNTRUSTED_PROXIED}, {@link #OP_FLAG_TRUSTED_PROXIED}, |
| 631 | * {@link #OP_FLAG_UNTRUSTED_PROXIED}. |
| 632 | * |
| 633 | * @hide |
| 634 | */ |
| 635 | @TestApi |
| 636 | @SystemApi |
| 637 | public static final int OP_FLAGS_ALL = |
| 638 | OP_FLAG_SELF |
| 639 | | OP_FLAG_TRUSTED_PROXY |
| 640 | | OP_FLAG_UNTRUSTED_PROXY |
| 641 | | OP_FLAG_TRUSTED_PROXIED |
| 642 | | OP_FLAG_UNTRUSTED_PROXIED; |
| 643 | |
| 644 | /** |
| 645 | * Flags: all trusted operations which is ones either the app did {@link #OP_FLAG_SELF}, |
| 646 | * or it was blamed for by a trusted app {@link #OP_FLAG_TRUSTED_PROXIED}, or ones the |
| 647 | * app if untrusted blamed on other apps {@link #OP_FLAG_UNTRUSTED_PROXY}. |
| 648 | * |
| 649 | * @hide |
| 650 | */ |
| 651 | @SystemApi |
| 652 | public static final int OP_FLAGS_ALL_TRUSTED = AppOpsManager.OP_FLAG_SELF |
| 653 | | AppOpsManager.OP_FLAG_UNTRUSTED_PROXY |
| 654 | | AppOpsManager.OP_FLAG_TRUSTED_PROXIED; |
| 655 | |
| 656 | /** @hide */ |
| 657 | @Retention(RetentionPolicy.SOURCE) |
| 658 | @IntDef(flag = true, prefix = { "FLAG_" }, value = { |
| 659 | OP_FLAG_SELF, |
| 660 | OP_FLAG_TRUSTED_PROXY, |
| 661 | OP_FLAG_UNTRUSTED_PROXY, |
| 662 | OP_FLAG_TRUSTED_PROXIED, |
| 663 | OP_FLAG_UNTRUSTED_PROXIED |
| 664 | }) |
| 665 | public @interface OpFlags {} |
| 666 | |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 667 | /** @hide */ |
| 668 | public static final String getFlagName(@OpFlags int flag) { |
| 669 | switch (flag) { |
| 670 | case OP_FLAG_SELF: |
| 671 | return "s"; |
| 672 | case OP_FLAG_TRUSTED_PROXY: |
| 673 | return "tp"; |
| 674 | case OP_FLAG_UNTRUSTED_PROXY: |
| 675 | return "up"; |
| 676 | case OP_FLAG_TRUSTED_PROXIED: |
| 677 | return "tpd"; |
| 678 | case OP_FLAG_UNTRUSTED_PROXIED: |
| 679 | return "upd"; |
| 680 | default: |
| 681 | return "unknown"; |
| 682 | } |
| 683 | } |
| 684 | |
Muhammad Qureshi | 317061a | 2020-03-02 13:15:51 -0800 | [diff] [blame] | 685 | // These constants are redefined here to work around a metalava limitation/bug where |
| 686 | // @IntDef is not able to see @hide symbols when they are hidden via package hiding: |
| 687 | // frameworks/base/core/java/com/android/internal/package.html |
| 688 | |
| 689 | /** @hide */ |
| 690 | public static final int SAMPLING_STRATEGY_DEFAULT = |
| 691 | FrameworkStatsLog.RUNTIME_APP_OP_ACCESS__SAMPLING_STRATEGY__DEFAULT; |
| 692 | |
| 693 | /** @hide */ |
| 694 | public static final int SAMPLING_STRATEGY_UNIFORM = |
| 695 | FrameworkStatsLog.RUNTIME_APP_OP_ACCESS__SAMPLING_STRATEGY__UNIFORM; |
| 696 | |
| 697 | /** @hide */ |
| 698 | public static final int SAMPLING_STRATEGY_RARELY_USED = |
| 699 | FrameworkStatsLog.RUNTIME_APP_OP_ACCESS__SAMPLING_STRATEGY__RARELY_USED; |
| 700 | |
Stanislav Zholnin | 4c32385 | 2020-03-04 18:03:24 +0000 | [diff] [blame] | 701 | /** @hide */ |
| 702 | public static final int SAMPLING_STRATEGY_BOOT_TIME_SAMPLING = |
| 703 | FrameworkStatsLog.RUNTIME_APP_OP_ACCESS__SAMPLING_STRATEGY__BOOT_TIME_SAMPLING; |
| 704 | |
Stanislav Zholnin | 90516b9 | 2020-01-20 14:03:06 +0000 | [diff] [blame] | 705 | /** |
| 706 | * Strategies used for message sampling |
| 707 | * @hide |
| 708 | */ |
| 709 | @Retention(RetentionPolicy.SOURCE) |
Muhammad Qureshi | 317061a | 2020-03-02 13:15:51 -0800 | [diff] [blame] | 710 | @IntDef(prefix = {"SAMPLING_STRATEGY_"}, value = { |
| 711 | SAMPLING_STRATEGY_DEFAULT, |
| 712 | SAMPLING_STRATEGY_UNIFORM, |
Stanislav Zholnin | 4c32385 | 2020-03-04 18:03:24 +0000 | [diff] [blame] | 713 | SAMPLING_STRATEGY_RARELY_USED, |
| 714 | SAMPLING_STRATEGY_BOOT_TIME_SAMPLING |
Stanislav Zholnin | 90516b9 | 2020-01-20 14:03:06 +0000 | [diff] [blame] | 715 | }) |
| 716 | public @interface SamplingStrategy {} |
| 717 | |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 718 | private static final int UID_STATE_OFFSET = 31; |
| 719 | private static final int FLAGS_MASK = 0xFFFFFFFF; |
| 720 | |
| 721 | /** |
| 722 | * Key for a data bucket storing app op state. The bucket |
| 723 | * is composed of the uid state and state flags. This way |
| 724 | * we can query data for given uid state and a set of flags where |
| 725 | * the flags control which type of data to get. For example, |
| 726 | * one can get the ops an app did on behalf of other apps |
| 727 | * while in the background. |
| 728 | * |
| 729 | * @hide |
| 730 | */ |
| 731 | @Retention(RetentionPolicy.SOURCE) |
| 732 | @Target({ElementType.METHOD, ElementType.PARAMETER, ElementType.FIELD}) |
| 733 | public @interface DataBucketKey { |
| 734 | } |
| 735 | |
| 736 | /** @hide */ |
| 737 | public static String keyToString(@DataBucketKey long key) { |
| 738 | final int uidState = extractUidStateFromKey(key); |
| 739 | final int flags = extractFlagsFromKey(key); |
| 740 | return "[" + getUidStateName(uidState) + "-" + flagsToString(flags) + "]"; |
| 741 | } |
| 742 | |
| 743 | /** @hide */ |
| 744 | public static @DataBucketKey long makeKey(@UidState int uidState, @OpFlags int flags) { |
| 745 | return ((long) uidState << UID_STATE_OFFSET) | flags; |
| 746 | } |
| 747 | |
| 748 | /** @hide */ |
| 749 | public static int extractUidStateFromKey(@DataBucketKey long key) { |
| 750 | return (int) (key >> UID_STATE_OFFSET); |
| 751 | } |
| 752 | |
| 753 | /** @hide */ |
| 754 | public static int extractFlagsFromKey(@DataBucketKey long key) { |
| 755 | return (int) (key & FLAGS_MASK); |
| 756 | } |
| 757 | |
| 758 | /** @hide */ |
| 759 | public static String flagsToString(@OpFlags int flags) { |
| 760 | final StringBuilder flagsBuilder = new StringBuilder(); |
| 761 | while (flags != 0) { |
| 762 | final int flag = 1 << Integer.numberOfTrailingZeros(flags); |
| 763 | flags &= ~flag; |
| 764 | if (flagsBuilder.length() > 0) { |
| 765 | flagsBuilder.append('|'); |
| 766 | } |
| 767 | flagsBuilder.append(getFlagName(flag)); |
| 768 | } |
| 769 | return flagsBuilder.toString(); |
| 770 | } |
Dianne Hackborn | cd1f30b | 2018-04-23 17:38:09 -0700 | [diff] [blame] | 771 | |
Daniel Sandler | fde19b1 | 2013-01-17 00:21:05 -0500 | [diff] [blame] | 772 | // when adding one of these: |
| 773 | // - increment _NUM_OP |
Peter Visontay | 5a2a1ef | 2017-12-18 20:34:03 +0000 | [diff] [blame] | 774 | // - define an OPSTR_* constant (marked as @SystemApi) |
Svetoslav Ganov | eaca4c5 | 2016-05-05 18:08:00 -0700 | [diff] [blame] | 775 | // - add rows to sOpToSwitch, sOpToString, sOpNames, sOpToPerms, sOpDefault |
Daniel Sandler | fde19b1 | 2013-01-17 00:21:05 -0500 | [diff] [blame] | 776 | // - add descriptive strings to Settings/res/values/arrays.xml |
David Christie | 0b83745 | 2013-07-29 16:02:13 -0700 | [diff] [blame] | 777 | // - add the op to the appropriate template in AppOpsState.OpsTemplate (settings app) |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 778 | |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 779 | /** @hide No operation specified. */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 780 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 781 | public static final int OP_NONE = AppProtoEnums.APP_OP_NONE; |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 782 | /** @hide Access to coarse location information. */ |
Artur Satayev | f0b7d0b | 2019-11-04 11:16:45 +0000 | [diff] [blame] | 783 | @UnsupportedAppUsage |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 784 | @TestApi |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 785 | public static final int OP_COARSE_LOCATION = AppProtoEnums.APP_OP_COARSE_LOCATION; |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 786 | /** @hide Access to fine location information. */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 787 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 788 | public static final int OP_FINE_LOCATION = AppProtoEnums.APP_OP_FINE_LOCATION; |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 789 | /** @hide Causing GPS to run. */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 790 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 791 | public static final int OP_GPS = AppProtoEnums.APP_OP_GPS; |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 792 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 793 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 794 | public static final int OP_VIBRATE = AppProtoEnums.APP_OP_VIBRATE; |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 795 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 796 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 797 | public static final int OP_READ_CONTACTS = AppProtoEnums.APP_OP_READ_CONTACTS; |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 798 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 799 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 800 | public static final int OP_WRITE_CONTACTS = AppProtoEnums.APP_OP_WRITE_CONTACTS; |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 801 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 802 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 803 | public static final int OP_READ_CALL_LOG = AppProtoEnums.APP_OP_READ_CALL_LOG; |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 804 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 805 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 806 | public static final int OP_WRITE_CALL_LOG = AppProtoEnums.APP_OP_WRITE_CALL_LOG; |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 807 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 808 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 809 | public static final int OP_READ_CALENDAR = AppProtoEnums.APP_OP_READ_CALENDAR; |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 810 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 811 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 812 | public static final int OP_WRITE_CALENDAR = AppProtoEnums.APP_OP_WRITE_CALENDAR; |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 813 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 814 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 815 | public static final int OP_WIFI_SCAN = AppProtoEnums.APP_OP_WIFI_SCAN; |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 816 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 817 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 818 | public static final int OP_POST_NOTIFICATION = AppProtoEnums.APP_OP_POST_NOTIFICATION; |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 819 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 820 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 821 | public static final int OP_NEIGHBORING_CELLS = AppProtoEnums.APP_OP_NEIGHBORING_CELLS; |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 822 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 823 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 824 | public static final int OP_CALL_PHONE = AppProtoEnums.APP_OP_CALL_PHONE; |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 825 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 826 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 827 | public static final int OP_READ_SMS = AppProtoEnums.APP_OP_READ_SMS; |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 828 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 829 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 830 | public static final int OP_WRITE_SMS = AppProtoEnums.APP_OP_WRITE_SMS; |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 831 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 832 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 833 | public static final int OP_RECEIVE_SMS = AppProtoEnums.APP_OP_RECEIVE_SMS; |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 834 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 835 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 836 | public static final int OP_RECEIVE_EMERGECY_SMS = |
| 837 | AppProtoEnums.APP_OP_RECEIVE_EMERGENCY_SMS; |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 838 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 839 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 840 | public static final int OP_RECEIVE_MMS = AppProtoEnums.APP_OP_RECEIVE_MMS; |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 841 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 842 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 843 | public static final int OP_RECEIVE_WAP_PUSH = AppProtoEnums.APP_OP_RECEIVE_WAP_PUSH; |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 844 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 845 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 846 | public static final int OP_SEND_SMS = AppProtoEnums.APP_OP_SEND_SMS; |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 847 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 848 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 849 | public static final int OP_READ_ICC_SMS = AppProtoEnums.APP_OP_READ_ICC_SMS; |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 850 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 851 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 852 | public static final int OP_WRITE_ICC_SMS = AppProtoEnums.APP_OP_WRITE_ICC_SMS; |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 853 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 854 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 855 | public static final int OP_WRITE_SETTINGS = AppProtoEnums.APP_OP_WRITE_SETTINGS; |
Peter Visontay | 96449f6 | 2017-12-11 18:50:03 +0000 | [diff] [blame] | 856 | /** @hide Required to draw on top of other apps. */ |
Artur Satayev | f0b7d0b | 2019-11-04 11:16:45 +0000 | [diff] [blame] | 857 | @UnsupportedAppUsage |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 858 | @TestApi |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 859 | public static final int OP_SYSTEM_ALERT_WINDOW = AppProtoEnums.APP_OP_SYSTEM_ALERT_WINDOW; |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 860 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 861 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 862 | public static final int OP_ACCESS_NOTIFICATIONS = |
| 863 | AppProtoEnums.APP_OP_ACCESS_NOTIFICATIONS; |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 864 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 865 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 866 | public static final int OP_CAMERA = AppProtoEnums.APP_OP_CAMERA; |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 867 | /** @hide */ |
Artur Satayev | f0b7d0b | 2019-11-04 11:16:45 +0000 | [diff] [blame] | 868 | @UnsupportedAppUsage |
Svet Ganov | a7a0db6 | 2018-02-27 20:08:01 -0800 | [diff] [blame] | 869 | @TestApi |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 870 | public static final int OP_RECORD_AUDIO = AppProtoEnums.APP_OP_RECORD_AUDIO; |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 871 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 872 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 873 | public static final int OP_PLAY_AUDIO = AppProtoEnums.APP_OP_PLAY_AUDIO; |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 874 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 875 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 876 | public static final int OP_READ_CLIPBOARD = AppProtoEnums.APP_OP_READ_CLIPBOARD; |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 877 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 878 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 879 | public static final int OP_WRITE_CLIPBOARD = AppProtoEnums.APP_OP_WRITE_CLIPBOARD; |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 880 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 881 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 882 | public static final int OP_TAKE_MEDIA_BUTTONS = AppProtoEnums.APP_OP_TAKE_MEDIA_BUTTONS; |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 883 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 884 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 885 | public static final int OP_TAKE_AUDIO_FOCUS = AppProtoEnums.APP_OP_TAKE_AUDIO_FOCUS; |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 886 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 887 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 888 | public static final int OP_AUDIO_MASTER_VOLUME = AppProtoEnums.APP_OP_AUDIO_MASTER_VOLUME; |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 889 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 890 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 891 | public static final int OP_AUDIO_VOICE_VOLUME = AppProtoEnums.APP_OP_AUDIO_VOICE_VOLUME; |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 892 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 893 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 894 | public static final int OP_AUDIO_RING_VOLUME = AppProtoEnums.APP_OP_AUDIO_RING_VOLUME; |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 895 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 896 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 897 | public static final int OP_AUDIO_MEDIA_VOLUME = AppProtoEnums.APP_OP_AUDIO_MEDIA_VOLUME; |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 898 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 899 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 900 | public static final int OP_AUDIO_ALARM_VOLUME = AppProtoEnums.APP_OP_AUDIO_ALARM_VOLUME; |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 901 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 902 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 903 | public static final int OP_AUDIO_NOTIFICATION_VOLUME = |
| 904 | AppProtoEnums.APP_OP_AUDIO_NOTIFICATION_VOLUME; |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 905 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 906 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 907 | public static final int OP_AUDIO_BLUETOOTH_VOLUME = |
| 908 | AppProtoEnums.APP_OP_AUDIO_BLUETOOTH_VOLUME; |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 909 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 910 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 911 | public static final int OP_WAKE_LOCK = AppProtoEnums.APP_OP_WAKE_LOCK; |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 912 | /** @hide Continually monitoring location data. */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 913 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 914 | public static final int OP_MONITOR_LOCATION = |
| 915 | AppProtoEnums.APP_OP_MONITOR_LOCATION; |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 916 | /** @hide Continually monitoring location data with a relatively high power request. */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 917 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 918 | public static final int OP_MONITOR_HIGH_POWER_LOCATION = |
| 919 | AppProtoEnums.APP_OP_MONITOR_HIGH_POWER_LOCATION; |
Dianne Hackborn | e22b3b1 | 2014-05-07 18:06:44 -0700 | [diff] [blame] | 920 | /** @hide Retrieve current usage stats via {@link UsageStatsManager}. */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 921 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 922 | public static final int OP_GET_USAGE_STATS = AppProtoEnums.APP_OP_GET_USAGE_STATS; |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 923 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 924 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 925 | public static final int OP_MUTE_MICROPHONE = AppProtoEnums.APP_OP_MUTE_MICROPHONE; |
Emily Bernier | 22c921a | 2014-05-28 11:01:32 -0400 | [diff] [blame] | 926 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 927 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 928 | public static final int OP_TOAST_WINDOW = AppProtoEnums.APP_OP_TOAST_WINDOW; |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 929 | /** @hide Capture the device's display contents and/or audio */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 930 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 931 | public static final int OP_PROJECT_MEDIA = AppProtoEnums.APP_OP_PROJECT_MEDIA; |
Benedict Wong | 3eb9520 | 2019-11-05 12:50:59 -0800 | [diff] [blame] | 932 | /** |
| 933 | * Start (without additional user intervention) a VPN connection, as used by {@link |
| 934 | * android.net.VpnService} along with as Platform VPN connections, as used by {@link |
| 935 | * android.net.VpnManager} |
| 936 | * |
| 937 | * <p>This appop is granted to apps that have already been given user consent to start |
| 938 | * VpnService based VPN connections. As this is a superset of OP_ACTIVATE_PLATFORM_VPN, this |
| 939 | * appop also allows the starting of Platform VPNs. |
| 940 | * |
| 941 | * @hide |
| 942 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 943 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 944 | public static final int OP_ACTIVATE_VPN = AppProtoEnums.APP_OP_ACTIVATE_VPN; |
Benjamin Franz | f3ece36 | 2015-02-11 10:51:10 +0000 | [diff] [blame] | 945 | /** @hide Access the WallpaperManagerAPI to write wallpapers. */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 946 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 947 | public static final int OP_WRITE_WALLPAPER = AppProtoEnums.APP_OP_WRITE_WALLPAPER; |
Dianne Hackborn | d59a5d5 | 2015-04-04 14:52:14 -0700 | [diff] [blame] | 948 | /** @hide Received the assist structure from an app. */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 949 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 950 | public static final int OP_ASSIST_STRUCTURE = AppProtoEnums.APP_OP_ASSIST_STRUCTURE; |
Dianne Hackborn | d59a5d5 | 2015-04-04 14:52:14 -0700 | [diff] [blame] | 951 | /** @hide Received a screenshot from assist. */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 952 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 953 | public static final int OP_ASSIST_SCREENSHOT = AppProtoEnums.APP_OP_ASSIST_SCREENSHOT; |
Svet Ganov | 16a1689 | 2015-04-16 10:32:04 -0700 | [diff] [blame] | 954 | /** @hide Read the phone state. */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 955 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 956 | public static final int OP_READ_PHONE_STATE = AppProtoEnums.APP_OP_READ_PHONE_STATE; |
Svet Ganov | c330009 | 2015-04-17 09:07:22 -0700 | [diff] [blame] | 957 | /** @hide Add voicemail messages to the voicemail content provider. */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 958 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 959 | public static final int OP_ADD_VOICEMAIL = AppProtoEnums.APP_OP_ADD_VOICEMAIL; |
Svetoslav | 5335b67 | 2015-04-29 12:00:51 -0700 | [diff] [blame] | 960 | /** @hide Access APIs for SIP calling over VOIP or WiFi. */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 961 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 962 | public static final int OP_USE_SIP = AppProtoEnums.APP_OP_USE_SIP; |
Svetoslav | c656e6f | 2015-04-29 14:08:16 -0700 | [diff] [blame] | 963 | /** @hide Intercept outgoing calls. */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 964 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 965 | public static final int OP_PROCESS_OUTGOING_CALLS = |
| 966 | AppProtoEnums.APP_OP_PROCESS_OUTGOING_CALLS; |
Svetoslav | 4af76a5 | 2015-04-29 15:29:46 -0700 | [diff] [blame] | 967 | /** @hide User the fingerprint API. */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 968 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 969 | public static final int OP_USE_FINGERPRINT = AppProtoEnums.APP_OP_USE_FINGERPRINT; |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 970 | /** @hide Access to body sensors such as heart rate, etc. */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 971 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 972 | public static final int OP_BODY_SENSORS = AppProtoEnums.APP_OP_BODY_SENSORS; |
Svet Ganov | ede4316 | 2015-05-02 17:42:44 -0700 | [diff] [blame] | 973 | /** @hide Read previously received cell broadcast messages. */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 974 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 975 | public static final int OP_READ_CELL_BROADCASTS = AppProtoEnums.APP_OP_READ_CELL_BROADCASTS; |
Svet Ganov | f7e9cf4 | 2015-05-13 10:40:31 -0700 | [diff] [blame] | 976 | /** @hide Inject mock location into the system. */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 977 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 978 | public static final int OP_MOCK_LOCATION = AppProtoEnums.APP_OP_MOCK_LOCATION; |
Svet Ganov | 921c7df | 2015-06-29 21:51:41 -0700 | [diff] [blame] | 979 | /** @hide Read external storage. */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 980 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 981 | public static final int OP_READ_EXTERNAL_STORAGE = AppProtoEnums.APP_OP_READ_EXTERNAL_STORAGE; |
Svet Ganov | 921c7df | 2015-06-29 21:51:41 -0700 | [diff] [blame] | 982 | /** @hide Write external storage. */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 983 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 984 | public static final int OP_WRITE_EXTERNAL_STORAGE = |
| 985 | AppProtoEnums.APP_OP_WRITE_EXTERNAL_STORAGE; |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 986 | /** @hide Turned on the screen. */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 987 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 988 | public static final int OP_TURN_SCREEN_ON = AppProtoEnums.APP_OP_TURN_SCREEN_ON; |
Svetoslav | f3f02ac | 2015-09-08 14:36:35 -0700 | [diff] [blame] | 989 | /** @hide Get device accounts. */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 990 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 991 | public static final int OP_GET_ACCOUNTS = AppProtoEnums.APP_OP_GET_ACCOUNTS; |
Dianne Hackborn | bef28fe | 2015-10-29 17:57:11 -0700 | [diff] [blame] | 992 | /** @hide Control whether an application is allowed to run in the background. */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 993 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 994 | public static final int OP_RUN_IN_BACKGROUND = |
Stanislav Zholnin | 5c88c73 | 2020-03-29 21:46:35 +0100 | [diff] [blame] | 995 | AppProtoEnums.APP_OP_RUN_IN_BACKGROUND; |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 996 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 997 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 998 | public static final int OP_AUDIO_ACCESSIBILITY_VOLUME = |
| 999 | AppProtoEnums.APP_OP_AUDIO_ACCESSIBILITY_VOLUME; |
Chad Brubaker | 73ec8f9 | 2016-11-10 11:24:40 -0800 | [diff] [blame] | 1000 | /** @hide Read the phone number. */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 1001 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 1002 | public static final int OP_READ_PHONE_NUMBERS = AppProtoEnums.APP_OP_READ_PHONE_NUMBERS; |
Suprabh Shukla | 2f34b1a | 2016-12-16 14:47:25 -0800 | [diff] [blame] | 1003 | /** @hide Request package installs through package installer */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 1004 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 1005 | public static final int OP_REQUEST_INSTALL_PACKAGES = |
| 1006 | AppProtoEnums.APP_OP_REQUEST_INSTALL_PACKAGES; |
Winson Chung | f4ac063 | 2017-03-17 12:34:12 -0700 | [diff] [blame] | 1007 | /** @hide Enter picture-in-picture. */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 1008 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 1009 | public static final int OP_PICTURE_IN_PICTURE = AppProtoEnums.APP_OP_PICTURE_IN_PICTURE; |
Chad Brubaker | 97b383f | 2017-02-02 15:04:35 -0800 | [diff] [blame] | 1010 | /** @hide Instant app start foreground service. */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 1011 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 1012 | public static final int OP_INSTANT_APP_START_FOREGROUND = |
| 1013 | AppProtoEnums.APP_OP_INSTANT_APP_START_FOREGROUND; |
Eugene Susla | cae3d3e | 2017-01-31 11:08:11 -0800 | [diff] [blame] | 1014 | /** @hide Answer incoming phone calls */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 1015 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 1016 | public static final int OP_ANSWER_PHONE_CALLS = AppProtoEnums.APP_OP_ANSWER_PHONE_CALLS; |
Suprabh Shukla | 3ac1daa | 2017-07-14 12:15:27 -0700 | [diff] [blame] | 1017 | /** @hide Run jobs when in background */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 1018 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 1019 | public static final int OP_RUN_ANY_IN_BACKGROUND = AppProtoEnums.APP_OP_RUN_ANY_IN_BACKGROUND; |
Peter Visontay | 1246d9e | 2017-10-17 17:02:45 +0100 | [diff] [blame] | 1020 | /** @hide Change Wi-Fi connectivity state */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 1021 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 1022 | public static final int OP_CHANGE_WIFI_STATE = AppProtoEnums.APP_OP_CHANGE_WIFI_STATE; |
Peter Visontay | f2e3836 | 2017-11-27 15:27:16 +0000 | [diff] [blame] | 1023 | /** @hide Request package deletion through package installer */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 1024 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 1025 | public static final int OP_REQUEST_DELETE_PACKAGES = |
| 1026 | AppProtoEnums.APP_OP_REQUEST_DELETE_PACKAGES; |
Peter Visontay | 1195083 | 2017-11-14 19:34:59 +0000 | [diff] [blame] | 1027 | /** @hide Bind an accessibility service. */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 1028 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 1029 | public static final int OP_BIND_ACCESSIBILITY_SERVICE = |
| 1030 | AppProtoEnums.APP_OP_BIND_ACCESSIBILITY_SERVICE; |
Tyler Gunn | 79bc1ec | 2018-01-22 15:17:54 -0800 | [diff] [blame] | 1031 | /** @hide Continue handover of a call from another app */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 1032 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 1033 | public static final int OP_ACCEPT_HANDOVER = AppProtoEnums.APP_OP_ACCEPT_HANDOVER; |
Nathan Harold | 1bb42067 | 2018-03-14 17:08:53 -0700 | [diff] [blame] | 1034 | /** @hide Create and Manage IPsec Tunnels */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 1035 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 1036 | public static final int OP_MANAGE_IPSEC_TUNNELS = AppProtoEnums.APP_OP_MANAGE_IPSEC_TUNNELS; |
Dianne Hackborn | e9d9b4b | 2018-03-28 13:51:46 -0700 | [diff] [blame] | 1037 | /** @hide Any app start foreground service. */ |
Artur Satayev | f0b7d0b | 2019-11-04 11:16:45 +0000 | [diff] [blame] | 1038 | @UnsupportedAppUsage |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 1039 | @TestApi |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 1040 | public static final int OP_START_FOREGROUND = AppProtoEnums.APP_OP_START_FOREGROUND; |
Jean-Michel Trivi | 3f0945a | 2016-11-11 10:05:18 -0800 | [diff] [blame] | 1041 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 1042 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 1043 | public static final int OP_BLUETOOTH_SCAN = AppProtoEnums.APP_OP_BLUETOOTH_SCAN; |
Kevin Chyn | b3c05aa | 2018-09-21 16:50:32 -0700 | [diff] [blame] | 1044 | /** @hide Use the BiometricPrompt/BiometricManager APIs. */ |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 1045 | public static final int OP_USE_BIOMETRIC = AppProtoEnums.APP_OP_USE_BIOMETRIC; |
Zimuzo | 6cbf9cc | 2018-10-05 12:05:58 +0100 | [diff] [blame] | 1046 | /** @hide Physical activity recognition. */ |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 1047 | public static final int OP_ACTIVITY_RECOGNITION = AppProtoEnums.APP_OP_ACTIVITY_RECOGNITION; |
Hongming Jin | 228cd01 | 2018-11-09 14:47:50 -0800 | [diff] [blame] | 1048 | /** @hide Financial app sms read. */ |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 1049 | public static final int OP_SMS_FINANCIAL_TRANSACTIONS = |
| 1050 | AppProtoEnums.APP_OP_SMS_FINANCIAL_TRANSACTIONS; |
Jeff Sharkey | d2a1f0d | 2018-11-19 10:32:52 -0700 | [diff] [blame] | 1051 | /** @hide Read media of audio type. */ |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 1052 | public static final int OP_READ_MEDIA_AUDIO = AppProtoEnums.APP_OP_READ_MEDIA_AUDIO; |
Jeff Sharkey | d2a1f0d | 2018-11-19 10:32:52 -0700 | [diff] [blame] | 1053 | /** @hide Write media of audio type. */ |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 1054 | public static final int OP_WRITE_MEDIA_AUDIO = AppProtoEnums.APP_OP_WRITE_MEDIA_AUDIO; |
Jeff Sharkey | d2a1f0d | 2018-11-19 10:32:52 -0700 | [diff] [blame] | 1055 | /** @hide Read media of video type. */ |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 1056 | public static final int OP_READ_MEDIA_VIDEO = AppProtoEnums.APP_OP_READ_MEDIA_VIDEO; |
Jeff Sharkey | d2a1f0d | 2018-11-19 10:32:52 -0700 | [diff] [blame] | 1057 | /** @hide Write media of video type. */ |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 1058 | public static final int OP_WRITE_MEDIA_VIDEO = AppProtoEnums.APP_OP_WRITE_MEDIA_VIDEO; |
Jeff Sharkey | d2a1f0d | 2018-11-19 10:32:52 -0700 | [diff] [blame] | 1059 | /** @hide Read media of image type. */ |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 1060 | public static final int OP_READ_MEDIA_IMAGES = AppProtoEnums.APP_OP_READ_MEDIA_IMAGES; |
Jeff Sharkey | d2a1f0d | 2018-11-19 10:32:52 -0700 | [diff] [blame] | 1061 | /** @hide Write media of image type. */ |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 1062 | public static final int OP_WRITE_MEDIA_IMAGES = AppProtoEnums.APP_OP_WRITE_MEDIA_IMAGES; |
Jeff Sharkey | e82cbb1 | 2018-12-06 15:53:11 -0700 | [diff] [blame] | 1063 | /** @hide Has a legacy (non-isolated) view of storage. */ |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 1064 | public static final int OP_LEGACY_STORAGE = AppProtoEnums.APP_OP_LEGACY_STORAGE; |
Jackal Guo | 8dc791e | 2019-01-14 10:26:42 +0800 | [diff] [blame] | 1065 | /** @hide Accessing accessibility features */ |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 1066 | public static final int OP_ACCESS_ACCESSIBILITY = AppProtoEnums.APP_OP_ACCESS_ACCESSIBILITY; |
Michael Groover | 656ef91 | 2019-04-09 17:09:57 -0700 | [diff] [blame] | 1067 | /** @hide Read the device identifiers (IMEI / MEID, IMSI, SIM / Build serial) */ |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 1068 | public static final int OP_READ_DEVICE_IDENTIFIERS = |
| 1069 | AppProtoEnums.APP_OP_READ_DEVICE_IDENTIFIERS; |
Philip P. Moltmann | 89b044f | 2019-09-13 15:12:34 -0700 | [diff] [blame] | 1070 | /** @hide Read location metadata from media */ |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 1071 | public static final int OP_ACCESS_MEDIA_LOCATION = AppProtoEnums.APP_OP_ACCESS_MEDIA_LOCATION; |
Patrick Baumann | 6c1c809 | 2019-06-27 14:55:44 -0700 | [diff] [blame] | 1072 | /** @hide Query all apps on device, regardless of declarations in the calling app manifest */ |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 1073 | public static final int OP_QUERY_ALL_PACKAGES = AppProtoEnums.APP_OP_QUERY_ALL_PACKAGES; |
Philip P. Moltmann | b43dfe3 | 2019-11-11 14:14:49 -0800 | [diff] [blame] | 1074 | /** @hide Access all external storage */ |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 1075 | public static final int OP_MANAGE_EXTERNAL_STORAGE = |
| 1076 | AppProtoEnums.APP_OP_MANAGE_EXTERNAL_STORAGE; |
kholoud mohamed | 20ded1f | 2019-12-03 17:52:38 +0000 | [diff] [blame] | 1077 | /** @hide Communicate cross-profile within the same profile group. */ |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 1078 | public static final int OP_INTERACT_ACROSS_PROFILES = |
| 1079 | AppProtoEnums.APP_OP_INTERACT_ACROSS_PROFILES; |
Benedict Wong | 3eb9520 | 2019-11-05 12:50:59 -0800 | [diff] [blame] | 1080 | /** |
| 1081 | * Start (without additional user intervention) a Platform VPN connection, as used by {@link |
| 1082 | * android.net.VpnManager} |
| 1083 | * |
| 1084 | * <p>This appop is granted to apps that have already been given user consent to start Platform |
| 1085 | * VPN connections. This appop is insufficient to start VpnService based VPNs; OP_ACTIVATE_VPN |
| 1086 | * is needed for that. |
| 1087 | * |
| 1088 | * @hide |
| 1089 | */ |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 1090 | public static final int OP_ACTIVATE_PLATFORM_VPN = AppProtoEnums.APP_OP_ACTIVATE_PLATFORM_VPN; |
Todd Kennedy | 0f00675 | 2020-04-29 09:37:10 -0700 | [diff] [blame] | 1091 | /** @hide Controls whether or not read logs are available for incremental installations. */ |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 1092 | public static final int OP_LOADER_USAGE_STATS = AppProtoEnums.APP_OP_LOADER_USAGE_STATS; |
Ricardo Correa | acdc827 | 2020-03-24 11:02:54 -0700 | [diff] [blame] | 1093 | |
| 1094 | // App op deprecated/removed. |
| 1095 | private static final int OP_DEPRECATED_1 = AppProtoEnums.APP_OP_DEPRECATED_1; |
Patrick Baumann | 6c1c809 | 2019-06-27 14:55:44 -0700 | [diff] [blame] | 1096 | |
Eugene Susla | 5fc2d76 | 2020-03-04 13:53:10 -0800 | [diff] [blame] | 1097 | /** @hide Auto-revoke app permissions if app is unused for an extended period */ |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 1098 | public static final int OP_AUTO_REVOKE_PERMISSIONS_IF_UNUSED = |
| 1099 | AppProtoEnums.APP_OP_AUTO_REVOKE_PERMISSIONS_IF_UNUSED; |
Eugene Susla | 5fc2d76 | 2020-03-04 13:53:10 -0800 | [diff] [blame] | 1100 | |
Eugene Susla | 922cd08 | 2020-03-11 12:38:17 -0700 | [diff] [blame] | 1101 | /** |
| 1102 | * Whether {@link #OP_AUTO_REVOKE_PERMISSIONS_IF_UNUSED} is allowed to be changed by |
| 1103 | * the installer |
| 1104 | * |
| 1105 | * @hide |
| 1106 | */ |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 1107 | public static final int OP_AUTO_REVOKE_MANAGED_BY_INSTALLER = |
| 1108 | AppProtoEnums.APP_OP_AUTO_REVOKE_MANAGED_BY_INSTALLER; |
Eugene Susla | 922cd08 | 2020-03-11 12:38:17 -0700 | [diff] [blame] | 1109 | |
Dianne Hackborn | e04f13d | 2018-05-02 12:51:52 -0700 | [diff] [blame] | 1110 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 1111 | @UnsupportedAppUsage |
Eugene Susla | 922cd08 | 2020-03-11 12:38:17 -0700 | [diff] [blame] | 1112 | public static final int _NUM_OP = 99; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1113 | |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 1114 | /** Access to coarse location information. */ |
Svet Ganov | 6e8f67c | 2015-04-29 17:35:19 -0700 | [diff] [blame] | 1115 | public static final String OPSTR_COARSE_LOCATION = "android:coarse_location"; |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 1116 | /** Access to fine location information. */ |
| 1117 | public static final String OPSTR_FINE_LOCATION = |
| 1118 | "android:fine_location"; |
| 1119 | /** Continually monitoring location data. */ |
| 1120 | public static final String OPSTR_MONITOR_LOCATION |
| 1121 | = "android:monitor_location"; |
| 1122 | /** Continually monitoring location data with a relatively high power request. */ |
| 1123 | public static final String OPSTR_MONITOR_HIGH_POWER_LOCATION |
| 1124 | = "android:monitor_location_high_power"; |
Dianne Hackborn | 5064e7c | 2014-09-02 10:57:16 -0700 | [diff] [blame] | 1125 | /** Access to {@link android.app.usage.UsageStatsManager}. */ |
| 1126 | public static final String OPSTR_GET_USAGE_STATS |
| 1127 | = "android:get_usage_stats"; |
Jeff Davidson | 0554260 | 2014-08-11 14:07:27 -0700 | [diff] [blame] | 1128 | /** Activate a VPN connection without user intervention. @hide */ |
Peter Visontay | 5a2a1ef | 2017-12-18 20:34:03 +0000 | [diff] [blame] | 1129 | @SystemApi @TestApi |
Svet Ganov | 6e8f67c | 2015-04-29 17:35:19 -0700 | [diff] [blame] | 1130 | public static final String OPSTR_ACTIVATE_VPN |
| 1131 | = "android:activate_vpn"; |
Svet Ganov | 715cf2a | 2015-06-13 17:31:29 -0700 | [diff] [blame] | 1132 | /** Allows an application to read the user's contacts data. */ |
Svet Ganov | 6e8f67c | 2015-04-29 17:35:19 -0700 | [diff] [blame] | 1133 | public static final String OPSTR_READ_CONTACTS |
| 1134 | = "android:read_contacts"; |
Svet Ganov | 715cf2a | 2015-06-13 17:31:29 -0700 | [diff] [blame] | 1135 | /** Allows an application to write to the user's contacts data. */ |
Svet Ganov | 6e8f67c | 2015-04-29 17:35:19 -0700 | [diff] [blame] | 1136 | public static final String OPSTR_WRITE_CONTACTS |
| 1137 | = "android:write_contacts"; |
Svet Ganov | 715cf2a | 2015-06-13 17:31:29 -0700 | [diff] [blame] | 1138 | /** Allows an application to read the user's call log. */ |
Svet Ganov | 6e8f67c | 2015-04-29 17:35:19 -0700 | [diff] [blame] | 1139 | public static final String OPSTR_READ_CALL_LOG |
| 1140 | = "android:read_call_log"; |
Svet Ganov | 715cf2a | 2015-06-13 17:31:29 -0700 | [diff] [blame] | 1141 | /** Allows an application to write to the user's call log. */ |
Svet Ganov | 6e8f67c | 2015-04-29 17:35:19 -0700 | [diff] [blame] | 1142 | public static final String OPSTR_WRITE_CALL_LOG |
| 1143 | = "android:write_call_log"; |
Svet Ganov | 715cf2a | 2015-06-13 17:31:29 -0700 | [diff] [blame] | 1144 | /** Allows an application to read the user's calendar data. */ |
Svet Ganov | 6e8f67c | 2015-04-29 17:35:19 -0700 | [diff] [blame] | 1145 | public static final String OPSTR_READ_CALENDAR |
| 1146 | = "android:read_calendar"; |
Svet Ganov | 715cf2a | 2015-06-13 17:31:29 -0700 | [diff] [blame] | 1147 | /** Allows an application to write to the user's calendar data. */ |
Svet Ganov | 6e8f67c | 2015-04-29 17:35:19 -0700 | [diff] [blame] | 1148 | public static final String OPSTR_WRITE_CALENDAR |
| 1149 | = "android:write_calendar"; |
Svet Ganov | 715cf2a | 2015-06-13 17:31:29 -0700 | [diff] [blame] | 1150 | /** Allows an application to initiate a phone call. */ |
Svet Ganov | 6e8f67c | 2015-04-29 17:35:19 -0700 | [diff] [blame] | 1151 | public static final String OPSTR_CALL_PHONE |
| 1152 | = "android:call_phone"; |
Svet Ganov | 715cf2a | 2015-06-13 17:31:29 -0700 | [diff] [blame] | 1153 | /** Allows an application to read SMS messages. */ |
Svet Ganov | 6e8f67c | 2015-04-29 17:35:19 -0700 | [diff] [blame] | 1154 | public static final String OPSTR_READ_SMS |
| 1155 | = "android:read_sms"; |
Svet Ganov | 715cf2a | 2015-06-13 17:31:29 -0700 | [diff] [blame] | 1156 | /** Allows an application to receive SMS messages. */ |
Svet Ganov | 6e8f67c | 2015-04-29 17:35:19 -0700 | [diff] [blame] | 1157 | public static final String OPSTR_RECEIVE_SMS |
| 1158 | = "android:receive_sms"; |
Svet Ganov | 715cf2a | 2015-06-13 17:31:29 -0700 | [diff] [blame] | 1159 | /** Allows an application to receive MMS messages. */ |
Svet Ganov | 6e8f67c | 2015-04-29 17:35:19 -0700 | [diff] [blame] | 1160 | public static final String OPSTR_RECEIVE_MMS |
| 1161 | = "android:receive_mms"; |
Svet Ganov | 715cf2a | 2015-06-13 17:31:29 -0700 | [diff] [blame] | 1162 | /** Allows an application to receive WAP push messages. */ |
Svet Ganov | 6e8f67c | 2015-04-29 17:35:19 -0700 | [diff] [blame] | 1163 | public static final String OPSTR_RECEIVE_WAP_PUSH |
| 1164 | = "android:receive_wap_push"; |
Svet Ganov | 715cf2a | 2015-06-13 17:31:29 -0700 | [diff] [blame] | 1165 | /** Allows an application to send SMS messages. */ |
Svet Ganov | 6e8f67c | 2015-04-29 17:35:19 -0700 | [diff] [blame] | 1166 | public static final String OPSTR_SEND_SMS |
| 1167 | = "android:send_sms"; |
Svet Ganov | 715cf2a | 2015-06-13 17:31:29 -0700 | [diff] [blame] | 1168 | /** Required to be able to access the camera device. */ |
Svet Ganov | 6e8f67c | 2015-04-29 17:35:19 -0700 | [diff] [blame] | 1169 | public static final String OPSTR_CAMERA |
| 1170 | = "android:camera"; |
Svet Ganov | 715cf2a | 2015-06-13 17:31:29 -0700 | [diff] [blame] | 1171 | /** Required to be able to access the microphone device. */ |
Svet Ganov | 6e8f67c | 2015-04-29 17:35:19 -0700 | [diff] [blame] | 1172 | public static final String OPSTR_RECORD_AUDIO |
| 1173 | = "android:record_audio"; |
Svet Ganov | 715cf2a | 2015-06-13 17:31:29 -0700 | [diff] [blame] | 1174 | /** Required to access phone state related information. */ |
Svet Ganov | 6e8f67c | 2015-04-29 17:35:19 -0700 | [diff] [blame] | 1175 | public static final String OPSTR_READ_PHONE_STATE |
| 1176 | = "android:read_phone_state"; |
Svet Ganov | 715cf2a | 2015-06-13 17:31:29 -0700 | [diff] [blame] | 1177 | /** Required to access phone state related information. */ |
Svet Ganov | 6e8f67c | 2015-04-29 17:35:19 -0700 | [diff] [blame] | 1178 | public static final String OPSTR_ADD_VOICEMAIL |
| 1179 | = "android:add_voicemail"; |
Svet Ganov | 715cf2a | 2015-06-13 17:31:29 -0700 | [diff] [blame] | 1180 | /** Access APIs for SIP calling over VOIP or WiFi */ |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 1181 | public static final String OPSTR_USE_SIP |
| 1182 | = "android:use_sip"; |
Svet Ganov | e8e8942 | 2016-09-22 19:56:50 -0700 | [diff] [blame] | 1183 | /** Access APIs for diverting outgoing calls */ |
Svet Ganov | 824ad6e | 2016-09-22 19:36:53 -0700 | [diff] [blame] | 1184 | public static final String OPSTR_PROCESS_OUTGOING_CALLS |
| 1185 | = "android:process_outgoing_calls"; |
Svet Ganov | 715cf2a | 2015-06-13 17:31:29 -0700 | [diff] [blame] | 1186 | /** Use the fingerprint API. */ |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 1187 | public static final String OPSTR_USE_FINGERPRINT |
| 1188 | = "android:use_fingerprint"; |
Svet Ganov | 715cf2a | 2015-06-13 17:31:29 -0700 | [diff] [blame] | 1189 | /** Access to body sensors such as heart rate, etc. */ |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 1190 | public static final String OPSTR_BODY_SENSORS |
| 1191 | = "android:body_sensors"; |
Svet Ganov | 715cf2a | 2015-06-13 17:31:29 -0700 | [diff] [blame] | 1192 | /** Read previously received cell broadcast messages. */ |
Svet Ganov | ede4316 | 2015-05-02 17:42:44 -0700 | [diff] [blame] | 1193 | public static final String OPSTR_READ_CELL_BROADCASTS |
| 1194 | = "android:read_cell_broadcasts"; |
Svet Ganov | f7e9cf4 | 2015-05-13 10:40:31 -0700 | [diff] [blame] | 1195 | /** Inject mock location into the system. */ |
| 1196 | public static final String OPSTR_MOCK_LOCATION |
| 1197 | = "android:mock_location"; |
Svet Ganov | 921c7df | 2015-06-29 21:51:41 -0700 | [diff] [blame] | 1198 | /** Read external storage. */ |
| 1199 | public static final String OPSTR_READ_EXTERNAL_STORAGE |
| 1200 | = "android:read_external_storage"; |
| 1201 | /** Write external storage. */ |
| 1202 | public static final String OPSTR_WRITE_EXTERNAL_STORAGE |
| 1203 | = "android:write_external_storage"; |
Billy Lau | 24b9c83 | 2015-07-20 17:34:09 +0100 | [diff] [blame] | 1204 | /** Required to draw on top of other apps. */ |
| 1205 | public static final String OPSTR_SYSTEM_ALERT_WINDOW |
| 1206 | = "android:system_alert_window"; |
Philip P. Moltmann | a04b9ab | 2020-02-13 09:54:04 -0800 | [diff] [blame] | 1207 | /** Required to write/modify/update system settings. */ |
Billy Lau | 24b9c83 | 2015-07-20 17:34:09 +0100 | [diff] [blame] | 1208 | public static final String OPSTR_WRITE_SETTINGS |
| 1209 | = "android:write_settings"; |
Svetoslav | f3f02ac | 2015-09-08 14:36:35 -0700 | [diff] [blame] | 1210 | /** @hide Get device accounts. */ |
Peter Visontay | 5a2a1ef | 2017-12-18 20:34:03 +0000 | [diff] [blame] | 1211 | @SystemApi @TestApi |
Svetoslav | f3f02ac | 2015-09-08 14:36:35 -0700 | [diff] [blame] | 1212 | public static final String OPSTR_GET_ACCOUNTS |
| 1213 | = "android:get_accounts"; |
Chad Brubaker | 0c1651f | 2017-03-30 16:29:10 -0700 | [diff] [blame] | 1214 | public static final String OPSTR_READ_PHONE_NUMBERS |
| 1215 | = "android:read_phone_numbers"; |
Winson Chung | f4ac063 | 2017-03-17 12:34:12 -0700 | [diff] [blame] | 1216 | /** Access to picture-in-picture. */ |
| 1217 | public static final String OPSTR_PICTURE_IN_PICTURE |
| 1218 | = "android:picture_in_picture"; |
Chad Brubaker | 97b383f | 2017-02-02 15:04:35 -0800 | [diff] [blame] | 1219 | /** @hide */ |
Peter Visontay | 5a2a1ef | 2017-12-18 20:34:03 +0000 | [diff] [blame] | 1220 | @SystemApi @TestApi |
Chad Brubaker | 97b383f | 2017-02-02 15:04:35 -0800 | [diff] [blame] | 1221 | public static final String OPSTR_INSTANT_APP_START_FOREGROUND |
| 1222 | = "android:instant_app_start_foreground"; |
Eugene Susla | cae3d3e | 2017-01-31 11:08:11 -0800 | [diff] [blame] | 1223 | /** Answer incoming phone calls */ |
| 1224 | public static final String OPSTR_ANSWER_PHONE_CALLS |
| 1225 | = "android:answer_phone_calls"; |
Tyler Gunn | 79bc1ec | 2018-01-22 15:17:54 -0800 | [diff] [blame] | 1226 | /** |
| 1227 | * Accept call handover |
| 1228 | * @hide |
| 1229 | */ |
| 1230 | @SystemApi @TestApi |
| 1231 | public static final String OPSTR_ACCEPT_HANDOVER |
| 1232 | = "android:accept_handover"; |
Peter Visontay | 5a2a1ef | 2017-12-18 20:34:03 +0000 | [diff] [blame] | 1233 | /** @hide */ |
| 1234 | @SystemApi @TestApi |
| 1235 | public static final String OPSTR_GPS = "android:gps"; |
| 1236 | /** @hide */ |
| 1237 | @SystemApi @TestApi |
| 1238 | public static final String OPSTR_VIBRATE = "android:vibrate"; |
| 1239 | /** @hide */ |
| 1240 | @SystemApi @TestApi |
| 1241 | public static final String OPSTR_WIFI_SCAN = "android:wifi_scan"; |
| 1242 | /** @hide */ |
| 1243 | @SystemApi @TestApi |
| 1244 | public static final String OPSTR_POST_NOTIFICATION = "android:post_notification"; |
| 1245 | /** @hide */ |
| 1246 | @SystemApi @TestApi |
| 1247 | public static final String OPSTR_NEIGHBORING_CELLS = "android:neighboring_cells"; |
| 1248 | /** @hide */ |
| 1249 | @SystemApi @TestApi |
| 1250 | public static final String OPSTR_WRITE_SMS = "android:write_sms"; |
| 1251 | /** @hide */ |
| 1252 | @SystemApi @TestApi |
| 1253 | public static final String OPSTR_RECEIVE_EMERGENCY_BROADCAST = |
| 1254 | "android:receive_emergency_broadcast"; |
| 1255 | /** @hide */ |
| 1256 | @SystemApi @TestApi |
| 1257 | public static final String OPSTR_READ_ICC_SMS = "android:read_icc_sms"; |
| 1258 | /** @hide */ |
| 1259 | @SystemApi @TestApi |
| 1260 | public static final String OPSTR_WRITE_ICC_SMS = "android:write_icc_sms"; |
| 1261 | /** @hide */ |
| 1262 | @SystemApi @TestApi |
| 1263 | public static final String OPSTR_ACCESS_NOTIFICATIONS = "android:access_notifications"; |
| 1264 | /** @hide */ |
| 1265 | @SystemApi @TestApi |
| 1266 | public static final String OPSTR_PLAY_AUDIO = "android:play_audio"; |
| 1267 | /** @hide */ |
| 1268 | @SystemApi @TestApi |
| 1269 | public static final String OPSTR_READ_CLIPBOARD = "android:read_clipboard"; |
| 1270 | /** @hide */ |
| 1271 | @SystemApi @TestApi |
| 1272 | public static final String OPSTR_WRITE_CLIPBOARD = "android:write_clipboard"; |
| 1273 | /** @hide */ |
| 1274 | @SystemApi @TestApi |
| 1275 | public static final String OPSTR_TAKE_MEDIA_BUTTONS = "android:take_media_buttons"; |
| 1276 | /** @hide */ |
| 1277 | @SystemApi @TestApi |
| 1278 | public static final String OPSTR_TAKE_AUDIO_FOCUS = "android:take_audio_focus"; |
| 1279 | /** @hide */ |
| 1280 | @SystemApi @TestApi |
| 1281 | public static final String OPSTR_AUDIO_MASTER_VOLUME = "android:audio_master_volume"; |
| 1282 | /** @hide */ |
| 1283 | @SystemApi @TestApi |
| 1284 | public static final String OPSTR_AUDIO_VOICE_VOLUME = "android:audio_voice_volume"; |
| 1285 | /** @hide */ |
| 1286 | @SystemApi @TestApi |
| 1287 | public static final String OPSTR_AUDIO_RING_VOLUME = "android:audio_ring_volume"; |
| 1288 | /** @hide */ |
| 1289 | @SystemApi @TestApi |
| 1290 | public static final String OPSTR_AUDIO_MEDIA_VOLUME = "android:audio_media_volume"; |
| 1291 | /** @hide */ |
| 1292 | @SystemApi @TestApi |
| 1293 | public static final String OPSTR_AUDIO_ALARM_VOLUME = "android:audio_alarm_volume"; |
| 1294 | /** @hide */ |
| 1295 | @SystemApi @TestApi |
| 1296 | public static final String OPSTR_AUDIO_NOTIFICATION_VOLUME = |
| 1297 | "android:audio_notification_volume"; |
| 1298 | /** @hide */ |
| 1299 | @SystemApi @TestApi |
| 1300 | public static final String OPSTR_AUDIO_BLUETOOTH_VOLUME = "android:audio_bluetooth_volume"; |
| 1301 | /** @hide */ |
| 1302 | @SystemApi @TestApi |
| 1303 | public static final String OPSTR_WAKE_LOCK = "android:wake_lock"; |
| 1304 | /** @hide */ |
| 1305 | @SystemApi @TestApi |
| 1306 | public static final String OPSTR_MUTE_MICROPHONE = "android:mute_microphone"; |
| 1307 | /** @hide */ |
| 1308 | @SystemApi @TestApi |
| 1309 | public static final String OPSTR_TOAST_WINDOW = "android:toast_window"; |
| 1310 | /** @hide */ |
| 1311 | @SystemApi @TestApi |
| 1312 | public static final String OPSTR_PROJECT_MEDIA = "android:project_media"; |
| 1313 | /** @hide */ |
| 1314 | @SystemApi @TestApi |
| 1315 | public static final String OPSTR_WRITE_WALLPAPER = "android:write_wallpaper"; |
| 1316 | /** @hide */ |
| 1317 | @SystemApi @TestApi |
| 1318 | public static final String OPSTR_ASSIST_STRUCTURE = "android:assist_structure"; |
| 1319 | /** @hide */ |
| 1320 | @SystemApi @TestApi |
| 1321 | public static final String OPSTR_ASSIST_SCREENSHOT = "android:assist_screenshot"; |
| 1322 | /** @hide */ |
| 1323 | @SystemApi @TestApi |
| 1324 | public static final String OPSTR_TURN_SCREEN_ON = "android:turn_screen_on"; |
| 1325 | /** @hide */ |
| 1326 | @SystemApi @TestApi |
| 1327 | public static final String OPSTR_RUN_IN_BACKGROUND = "android:run_in_background"; |
| 1328 | /** @hide */ |
| 1329 | @SystemApi @TestApi |
| 1330 | public static final String OPSTR_AUDIO_ACCESSIBILITY_VOLUME = |
| 1331 | "android:audio_accessibility_volume"; |
| 1332 | /** @hide */ |
| 1333 | @SystemApi @TestApi |
| 1334 | public static final String OPSTR_REQUEST_INSTALL_PACKAGES = "android:request_install_packages"; |
| 1335 | /** @hide */ |
| 1336 | @SystemApi @TestApi |
| 1337 | public static final String OPSTR_RUN_ANY_IN_BACKGROUND = "android:run_any_in_background"; |
| 1338 | /** @hide */ |
| 1339 | @SystemApi @TestApi |
Peter Visontay | a382a8e | 2018-03-16 16:06:57 +0000 | [diff] [blame] | 1340 | public static final String OPSTR_CHANGE_WIFI_STATE = "android:change_wifi_state"; |
Peter Visontay | 5a2a1ef | 2017-12-18 20:34:03 +0000 | [diff] [blame] | 1341 | /** @hide */ |
| 1342 | @SystemApi @TestApi |
Peter Visontay | a382a8e | 2018-03-16 16:06:57 +0000 | [diff] [blame] | 1343 | public static final String OPSTR_REQUEST_DELETE_PACKAGES = "android:request_delete_packages"; |
Peter Visontay | 5a2a1ef | 2017-12-18 20:34:03 +0000 | [diff] [blame] | 1344 | /** @hide */ |
| 1345 | @SystemApi @TestApi |
Peter Visontay | a382a8e | 2018-03-16 16:06:57 +0000 | [diff] [blame] | 1346 | public static final String OPSTR_BIND_ACCESSIBILITY_SERVICE = |
| 1347 | "android:bind_accessibility_service"; |
Nathan Harold | 1bb42067 | 2018-03-14 17:08:53 -0700 | [diff] [blame] | 1348 | /** @hide */ |
| 1349 | @SystemApi @TestApi |
| 1350 | public static final String OPSTR_MANAGE_IPSEC_TUNNELS = "android:manage_ipsec_tunnels"; |
Dianne Hackborn | e9d9b4b | 2018-03-28 13:51:46 -0700 | [diff] [blame] | 1351 | /** @hide */ |
| 1352 | @SystemApi @TestApi |
| 1353 | public static final String OPSTR_START_FOREGROUND = "android:start_foreground"; |
Dianne Hackborn | e04f13d | 2018-05-02 12:51:52 -0700 | [diff] [blame] | 1354 | /** @hide */ |
| 1355 | public static final String OPSTR_BLUETOOTH_SCAN = "android:bluetooth_scan"; |
Peter Visontay | 5a2a1ef | 2017-12-18 20:34:03 +0000 | [diff] [blame] | 1356 | |
Kevin Chyn | b3c05aa | 2018-09-21 16:50:32 -0700 | [diff] [blame] | 1357 | /** @hide Use the BiometricPrompt/BiometricManager APIs. */ |
| 1358 | public static final String OPSTR_USE_BIOMETRIC = "android:use_biometric"; |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 1359 | |
Zimuzo | 6cbf9cc | 2018-10-05 12:05:58 +0100 | [diff] [blame] | 1360 | /** @hide Recognize physical activity. */ |
| 1361 | public static final String OPSTR_ACTIVITY_RECOGNITION = "android:activity_recognition"; |
| 1362 | |
Hongming Jin | 228cd01 | 2018-11-09 14:47:50 -0800 | [diff] [blame] | 1363 | /** @hide Financial app read sms. */ |
| 1364 | public static final String OPSTR_SMS_FINANCIAL_TRANSACTIONS = |
| 1365 | "android:sms_financial_transactions"; |
| 1366 | |
Jeff Sharkey | d2a1f0d | 2018-11-19 10:32:52 -0700 | [diff] [blame] | 1367 | /** @hide Read media of audio type. */ |
Jeff Sharkey | 5997cc8 | 2019-08-21 11:14:40 -0600 | [diff] [blame] | 1368 | @SystemApi @TestApi |
Jeff Sharkey | d2a1f0d | 2018-11-19 10:32:52 -0700 | [diff] [blame] | 1369 | public static final String OPSTR_READ_MEDIA_AUDIO = "android:read_media_audio"; |
| 1370 | /** @hide Write media of audio type. */ |
Jeff Sharkey | 5997cc8 | 2019-08-21 11:14:40 -0600 | [diff] [blame] | 1371 | @SystemApi @TestApi |
Jeff Sharkey | d2a1f0d | 2018-11-19 10:32:52 -0700 | [diff] [blame] | 1372 | public static final String OPSTR_WRITE_MEDIA_AUDIO = "android:write_media_audio"; |
| 1373 | /** @hide Read media of video type. */ |
Jeff Sharkey | 5997cc8 | 2019-08-21 11:14:40 -0600 | [diff] [blame] | 1374 | @SystemApi @TestApi |
Jeff Sharkey | d2a1f0d | 2018-11-19 10:32:52 -0700 | [diff] [blame] | 1375 | public static final String OPSTR_READ_MEDIA_VIDEO = "android:read_media_video"; |
| 1376 | /** @hide Write media of video type. */ |
Jeff Sharkey | 5997cc8 | 2019-08-21 11:14:40 -0600 | [diff] [blame] | 1377 | @SystemApi @TestApi |
Jeff Sharkey | d2a1f0d | 2018-11-19 10:32:52 -0700 | [diff] [blame] | 1378 | public static final String OPSTR_WRITE_MEDIA_VIDEO = "android:write_media_video"; |
| 1379 | /** @hide Read media of image type. */ |
Jeff Sharkey | 5997cc8 | 2019-08-21 11:14:40 -0600 | [diff] [blame] | 1380 | @SystemApi @TestApi |
Jeff Sharkey | d2a1f0d | 2018-11-19 10:32:52 -0700 | [diff] [blame] | 1381 | public static final String OPSTR_READ_MEDIA_IMAGES = "android:read_media_images"; |
| 1382 | /** @hide Write media of image type. */ |
Jeff Sharkey | 5997cc8 | 2019-08-21 11:14:40 -0600 | [diff] [blame] | 1383 | @SystemApi @TestApi |
Jeff Sharkey | d2a1f0d | 2018-11-19 10:32:52 -0700 | [diff] [blame] | 1384 | public static final String OPSTR_WRITE_MEDIA_IMAGES = "android:write_media_images"; |
Jeff Sharkey | e82cbb1 | 2018-12-06 15:53:11 -0700 | [diff] [blame] | 1385 | /** @hide Has a legacy (non-isolated) view of storage. */ |
Jeff Sharkey | 5997cc8 | 2019-08-21 11:14:40 -0600 | [diff] [blame] | 1386 | @SystemApi @TestApi |
Jeff Sharkey | e82cbb1 | 2018-12-06 15:53:11 -0700 | [diff] [blame] | 1387 | public static final String OPSTR_LEGACY_STORAGE = "android:legacy_storage"; |
Philip P. Moltmann | 89b044f | 2019-09-13 15:12:34 -0700 | [diff] [blame] | 1388 | /** @hide Read location metadata from media */ |
| 1389 | public static final String OPSTR_ACCESS_MEDIA_LOCATION = "android:access_media_location"; |
Jeff Sharkey | 5997cc8 | 2019-08-21 11:14:40 -0600 | [diff] [blame] | 1390 | |
Jackal Guo | 8dc791e | 2019-01-14 10:26:42 +0800 | [diff] [blame] | 1391 | /** @hide Interact with accessibility. */ |
Joel Galenson | ff4fe20 | 2019-02-06 14:43:58 -0800 | [diff] [blame] | 1392 | @SystemApi |
Jackal Guo | 8dc791e | 2019-01-14 10:26:42 +0800 | [diff] [blame] | 1393 | public static final String OPSTR_ACCESS_ACCESSIBILITY = "android:access_accessibility"; |
Michael Groover | 656ef91 | 2019-04-09 17:09:57 -0700 | [diff] [blame] | 1394 | /** @hide Read device identifiers */ |
| 1395 | public static final String OPSTR_READ_DEVICE_IDENTIFIERS = "android:read_device_identifiers"; |
Patrick Baumann | 6c1c809 | 2019-06-27 14:55:44 -0700 | [diff] [blame] | 1396 | /** @hide Query all packages on device */ |
| 1397 | public static final String OPSTR_QUERY_ALL_PACKAGES = "android:query_all_packages"; |
Philip P. Moltmann | b43dfe3 | 2019-11-11 14:14:49 -0800 | [diff] [blame] | 1398 | /** @hide Access all external storage */ |
| 1399 | @SystemApi |
shafik | 2a20790 | 2020-04-08 17:49:47 +0100 | [diff] [blame] | 1400 | @TestApi |
Philip P. Moltmann | b43dfe3 | 2019-11-11 14:14:49 -0800 | [diff] [blame] | 1401 | public static final String OPSTR_MANAGE_EXTERNAL_STORAGE = |
| 1402 | "android:manage_external_storage"; |
Jeff Sharkey | d2a1f0d | 2018-11-19 10:32:52 -0700 | [diff] [blame] | 1403 | |
Eugene Susla | 5fc2d76 | 2020-03-04 13:53:10 -0800 | [diff] [blame] | 1404 | /** @hide Auto-revoke app permissions if app is unused for an extended period */ |
| 1405 | @SystemApi |
| 1406 | public static final String OPSTR_AUTO_REVOKE_PERMISSIONS_IF_UNUSED = |
| 1407 | "android:auto_revoke_permissions_if_unused"; |
| 1408 | |
Eugene Susla | 1d7a791 | 2020-03-14 09:16:29 -0700 | [diff] [blame] | 1409 | /** @hide Auto-revoke app permissions if app is unused for an extended period */ |
Eugene Susla | f3ce46a | 2020-03-14 10:28:09 -0700 | [diff] [blame] | 1410 | @SystemApi |
Eugene Susla | 1d7a791 | 2020-03-14 09:16:29 -0700 | [diff] [blame] | 1411 | public static final String OPSTR_AUTO_REVOKE_MANAGED_BY_INSTALLER = |
| 1412 | "android:auto_revoke_managed_by_installer"; |
| 1413 | |
kholoud mohamed | 20ded1f | 2019-12-03 17:52:38 +0000 | [diff] [blame] | 1414 | /** @hide Communicate cross-profile within the same profile group. */ |
| 1415 | @SystemApi |
| 1416 | public static final String OPSTR_INTERACT_ACROSS_PROFILES = "android:interact_across_profiles"; |
Benedict Wong | 3eb9520 | 2019-11-05 12:50:59 -0800 | [diff] [blame] | 1417 | /** @hide Start Platform VPN without user intervention */ |
| 1418 | public static final String OPSTR_ACTIVATE_PLATFORM_VPN = "android:activate_platform_vpn"; |
Todd Kennedy | b0948d4 | 2020-01-27 15:20:07 -0800 | [diff] [blame] | 1419 | /** @hide */ |
| 1420 | @SystemApi |
| 1421 | public static final String OPSTR_LOADER_USAGE_STATS = "android:loader_usage_stats"; |
kholoud mohamed | 20ded1f | 2019-12-03 17:52:38 +0000 | [diff] [blame] | 1422 | |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 1423 | |
| 1424 | /** {@link #sAppOpsToNote} not initialized yet for this op */ |
| 1425 | private static final byte SHOULD_COLLECT_NOTE_OP_NOT_INITIALIZED = 0; |
| 1426 | /** Should not collect noting of this app-op in {@link #sAppOpsToNote} */ |
| 1427 | private static final byte SHOULD_NOT_COLLECT_NOTE_OP = 1; |
| 1428 | /** Should collect noting of this app-op in {@link #sAppOpsToNote} */ |
| 1429 | private static final byte SHOULD_COLLECT_NOTE_OP = 2; |
| 1430 | |
| 1431 | @Retention(RetentionPolicy.SOURCE) |
| 1432 | @IntDef(flag = true, prefix = { "SHOULD_" }, value = { |
| 1433 | SHOULD_COLLECT_NOTE_OP_NOT_INITIALIZED, |
| 1434 | SHOULD_NOT_COLLECT_NOTE_OP, |
| 1435 | SHOULD_COLLECT_NOTE_OP |
| 1436 | }) |
| 1437 | private @interface ShouldCollectNoteOp {} |
| 1438 | |
Svet Ganov | da0acdf | 2017-02-15 10:28:51 -0800 | [diff] [blame] | 1439 | private static final int[] RUNTIME_AND_APPOP_PERMISSIONS_OPS = { |
| 1440 | // RUNTIME PERMISSIONS |
Svetoslav Ganov | eaca4c5 | 2016-05-05 18:08:00 -0700 | [diff] [blame] | 1441 | // Contacts |
| 1442 | OP_READ_CONTACTS, |
| 1443 | OP_WRITE_CONTACTS, |
| 1444 | OP_GET_ACCOUNTS, |
| 1445 | // Calendar |
| 1446 | OP_READ_CALENDAR, |
| 1447 | OP_WRITE_CALENDAR, |
| 1448 | // SMS |
| 1449 | OP_SEND_SMS, |
| 1450 | OP_RECEIVE_SMS, |
| 1451 | OP_READ_SMS, |
| 1452 | OP_RECEIVE_WAP_PUSH, |
| 1453 | OP_RECEIVE_MMS, |
| 1454 | OP_READ_CELL_BROADCASTS, |
| 1455 | // Storage |
| 1456 | OP_READ_EXTERNAL_STORAGE, |
| 1457 | OP_WRITE_EXTERNAL_STORAGE, |
Philip P. Moltmann | 89b044f | 2019-09-13 15:12:34 -0700 | [diff] [blame] | 1458 | OP_ACCESS_MEDIA_LOCATION, |
Svetoslav Ganov | eaca4c5 | 2016-05-05 18:08:00 -0700 | [diff] [blame] | 1459 | // Location |
| 1460 | OP_COARSE_LOCATION, |
| 1461 | OP_FINE_LOCATION, |
| 1462 | // Phone |
| 1463 | OP_READ_PHONE_STATE, |
Chad Brubaker | 0c1651f | 2017-03-30 16:29:10 -0700 | [diff] [blame] | 1464 | OP_READ_PHONE_NUMBERS, |
Svetoslav Ganov | eaca4c5 | 2016-05-05 18:08:00 -0700 | [diff] [blame] | 1465 | OP_CALL_PHONE, |
| 1466 | OP_READ_CALL_LOG, |
| 1467 | OP_WRITE_CALL_LOG, |
| 1468 | OP_ADD_VOICEMAIL, |
| 1469 | OP_USE_SIP, |
| 1470 | OP_PROCESS_OUTGOING_CALLS, |
Eugene Susla | cae3d3e | 2017-01-31 11:08:11 -0800 | [diff] [blame] | 1471 | OP_ANSWER_PHONE_CALLS, |
Tyler Gunn | 79bc1ec | 2018-01-22 15:17:54 -0800 | [diff] [blame] | 1472 | OP_ACCEPT_HANDOVER, |
Svetoslav Ganov | eaca4c5 | 2016-05-05 18:08:00 -0700 | [diff] [blame] | 1473 | // Microphone |
| 1474 | OP_RECORD_AUDIO, |
| 1475 | // Camera |
| 1476 | OP_CAMERA, |
| 1477 | // Body sensors |
Svet Ganov | da0acdf | 2017-02-15 10:28:51 -0800 | [diff] [blame] | 1478 | OP_BODY_SENSORS, |
Zimuzo | 6cbf9cc | 2018-10-05 12:05:58 +0100 | [diff] [blame] | 1479 | // Activity recognition |
| 1480 | OP_ACTIVITY_RECOGNITION, |
Jeff Sharkey | d2a1f0d | 2018-11-19 10:32:52 -0700 | [diff] [blame] | 1481 | // Aural |
| 1482 | OP_READ_MEDIA_AUDIO, |
| 1483 | OP_WRITE_MEDIA_AUDIO, |
| 1484 | // Visual |
| 1485 | OP_READ_MEDIA_VIDEO, |
| 1486 | OP_WRITE_MEDIA_VIDEO, |
| 1487 | OP_READ_MEDIA_IMAGES, |
| 1488 | OP_WRITE_MEDIA_IMAGES, |
Svet Ganov | da0acdf | 2017-02-15 10:28:51 -0800 | [diff] [blame] | 1489 | |
| 1490 | // APPOP PERMISSIONS |
| 1491 | OP_ACCESS_NOTIFICATIONS, |
| 1492 | OP_SYSTEM_ALERT_WINDOW, |
| 1493 | OP_WRITE_SETTINGS, |
| 1494 | OP_REQUEST_INSTALL_PACKAGES, |
Dianne Hackborn | e9d9b4b | 2018-03-28 13:51:46 -0700 | [diff] [blame] | 1495 | OP_START_FOREGROUND, |
Hongming Jin | 228cd01 | 2018-11-09 14:47:50 -0800 | [diff] [blame] | 1496 | OP_SMS_FINANCIAL_TRANSACTIONS, |
Philip P. Moltmann | 4b38fbe | 2019-09-13 21:33:07 -0700 | [diff] [blame] | 1497 | OP_MANAGE_IPSEC_TUNNELS, |
shafik | 77cabc7 | 2020-01-03 16:22:50 +0000 | [diff] [blame] | 1498 | OP_INSTANT_APP_START_FOREGROUND, |
| 1499 | OP_MANAGE_EXTERNAL_STORAGE, |
Todd Kennedy | b0948d4 | 2020-01-27 15:20:07 -0800 | [diff] [blame] | 1500 | OP_INTERACT_ACROSS_PROFILES, |
| 1501 | OP_LOADER_USAGE_STATS, |
Svetoslav Ganov | eaca4c5 | 2016-05-05 18:08:00 -0700 | [diff] [blame] | 1502 | }; |
| 1503 | |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 1504 | /** |
| 1505 | * This maps each operation to the operation that serves as the |
| 1506 | * switch to determine whether it is allowed. Generally this is |
| 1507 | * a 1:1 mapping, but for some things (like location) that have |
| 1508 | * multiple low-level operations being tracked that should be |
David Christie | 0b83745 | 2013-07-29 16:02:13 -0700 | [diff] [blame] | 1509 | * presented to the user as one switch then this can be used to |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 1510 | * make them all controlled by the same single operation. |
| 1511 | */ |
| 1512 | private static int[] sOpToSwitch = new int[] { |
Dianne Hackborn | c216a26 | 2018-04-26 13:46:22 -0700 | [diff] [blame] | 1513 | OP_COARSE_LOCATION, // COARSE_LOCATION |
| 1514 | OP_COARSE_LOCATION, // FINE_LOCATION |
| 1515 | OP_COARSE_LOCATION, // GPS |
| 1516 | OP_VIBRATE, // VIBRATE |
| 1517 | OP_READ_CONTACTS, // READ_CONTACTS |
| 1518 | OP_WRITE_CONTACTS, // WRITE_CONTACTS |
| 1519 | OP_READ_CALL_LOG, // READ_CALL_LOG |
| 1520 | OP_WRITE_CALL_LOG, // WRITE_CALL_LOG |
| 1521 | OP_READ_CALENDAR, // READ_CALENDAR |
| 1522 | OP_WRITE_CALENDAR, // WRITE_CALENDAR |
| 1523 | OP_COARSE_LOCATION, // WIFI_SCAN |
| 1524 | OP_POST_NOTIFICATION, // POST_NOTIFICATION |
| 1525 | OP_COARSE_LOCATION, // NEIGHBORING_CELLS |
| 1526 | OP_CALL_PHONE, // CALL_PHONE |
| 1527 | OP_READ_SMS, // READ_SMS |
| 1528 | OP_WRITE_SMS, // WRITE_SMS |
| 1529 | OP_RECEIVE_SMS, // RECEIVE_SMS |
| 1530 | OP_RECEIVE_SMS, // RECEIVE_EMERGECY_SMS |
| 1531 | OP_RECEIVE_MMS, // RECEIVE_MMS |
| 1532 | OP_RECEIVE_WAP_PUSH, // RECEIVE_WAP_PUSH |
| 1533 | OP_SEND_SMS, // SEND_SMS |
| 1534 | OP_READ_SMS, // READ_ICC_SMS |
| 1535 | OP_WRITE_SMS, // WRITE_ICC_SMS |
| 1536 | OP_WRITE_SETTINGS, // WRITE_SETTINGS |
| 1537 | OP_SYSTEM_ALERT_WINDOW, // SYSTEM_ALERT_WINDOW |
| 1538 | OP_ACCESS_NOTIFICATIONS, // ACCESS_NOTIFICATIONS |
| 1539 | OP_CAMERA, // CAMERA |
| 1540 | OP_RECORD_AUDIO, // RECORD_AUDIO |
| 1541 | OP_PLAY_AUDIO, // PLAY_AUDIO |
| 1542 | OP_READ_CLIPBOARD, // READ_CLIPBOARD |
| 1543 | OP_WRITE_CLIPBOARD, // WRITE_CLIPBOARD |
| 1544 | OP_TAKE_MEDIA_BUTTONS, // TAKE_MEDIA_BUTTONS |
| 1545 | OP_TAKE_AUDIO_FOCUS, // TAKE_AUDIO_FOCUS |
| 1546 | OP_AUDIO_MASTER_VOLUME, // AUDIO_MASTER_VOLUME |
| 1547 | OP_AUDIO_VOICE_VOLUME, // AUDIO_VOICE_VOLUME |
| 1548 | OP_AUDIO_RING_VOLUME, // AUDIO_RING_VOLUME |
| 1549 | OP_AUDIO_MEDIA_VOLUME, // AUDIO_MEDIA_VOLUME |
| 1550 | OP_AUDIO_ALARM_VOLUME, // AUDIO_ALARM_VOLUME |
| 1551 | OP_AUDIO_NOTIFICATION_VOLUME, // AUDIO_NOTIFICATION_VOLUME |
| 1552 | OP_AUDIO_BLUETOOTH_VOLUME, // AUDIO_BLUETOOTH_VOLUME |
| 1553 | OP_WAKE_LOCK, // WAKE_LOCK |
| 1554 | OP_COARSE_LOCATION, // MONITOR_LOCATION |
| 1555 | OP_COARSE_LOCATION, // MONITOR_HIGH_POWER_LOCATION |
| 1556 | OP_GET_USAGE_STATS, // GET_USAGE_STATS |
| 1557 | OP_MUTE_MICROPHONE, // MUTE_MICROPHONE |
| 1558 | OP_TOAST_WINDOW, // TOAST_WINDOW |
| 1559 | OP_PROJECT_MEDIA, // PROJECT_MEDIA |
| 1560 | OP_ACTIVATE_VPN, // ACTIVATE_VPN |
| 1561 | OP_WRITE_WALLPAPER, // WRITE_WALLPAPER |
| 1562 | OP_ASSIST_STRUCTURE, // ASSIST_STRUCTURE |
| 1563 | OP_ASSIST_SCREENSHOT, // ASSIST_SCREENSHOT |
| 1564 | OP_READ_PHONE_STATE, // READ_PHONE_STATE |
| 1565 | OP_ADD_VOICEMAIL, // ADD_VOICEMAIL |
| 1566 | OP_USE_SIP, // USE_SIP |
| 1567 | OP_PROCESS_OUTGOING_CALLS, // PROCESS_OUTGOING_CALLS |
| 1568 | OP_USE_FINGERPRINT, // USE_FINGERPRINT |
| 1569 | OP_BODY_SENSORS, // BODY_SENSORS |
| 1570 | OP_READ_CELL_BROADCASTS, // READ_CELL_BROADCASTS |
| 1571 | OP_MOCK_LOCATION, // MOCK_LOCATION |
| 1572 | OP_READ_EXTERNAL_STORAGE, // READ_EXTERNAL_STORAGE |
| 1573 | OP_WRITE_EXTERNAL_STORAGE, // WRITE_EXTERNAL_STORAGE |
| 1574 | OP_TURN_SCREEN_ON, // TURN_SCREEN_ON |
| 1575 | OP_GET_ACCOUNTS, // GET_ACCOUNTS |
| 1576 | OP_RUN_IN_BACKGROUND, // RUN_IN_BACKGROUND |
| 1577 | OP_AUDIO_ACCESSIBILITY_VOLUME, // AUDIO_ACCESSIBILITY_VOLUME |
| 1578 | OP_READ_PHONE_NUMBERS, // READ_PHONE_NUMBERS |
| 1579 | OP_REQUEST_INSTALL_PACKAGES, // REQUEST_INSTALL_PACKAGES |
| 1580 | OP_PICTURE_IN_PICTURE, // ENTER_PICTURE_IN_PICTURE_ON_HIDE |
| 1581 | OP_INSTANT_APP_START_FOREGROUND, // INSTANT_APP_START_FOREGROUND |
| 1582 | OP_ANSWER_PHONE_CALLS, // ANSWER_PHONE_CALLS |
| 1583 | OP_RUN_ANY_IN_BACKGROUND, // OP_RUN_ANY_IN_BACKGROUND |
| 1584 | OP_CHANGE_WIFI_STATE, // OP_CHANGE_WIFI_STATE |
| 1585 | OP_REQUEST_DELETE_PACKAGES, // OP_REQUEST_DELETE_PACKAGES |
| 1586 | OP_BIND_ACCESSIBILITY_SERVICE, // OP_BIND_ACCESSIBILITY_SERVICE |
| 1587 | OP_ACCEPT_HANDOVER, // ACCEPT_HANDOVER |
| 1588 | OP_MANAGE_IPSEC_TUNNELS, // MANAGE_IPSEC_HANDOVERS |
| 1589 | OP_START_FOREGROUND, // START_FOREGROUND |
Dianne Hackborn | e04f13d | 2018-05-02 12:51:52 -0700 | [diff] [blame] | 1590 | OP_COARSE_LOCATION, // BLUETOOTH_SCAN |
Kevin Chyn | b3c05aa | 2018-09-21 16:50:32 -0700 | [diff] [blame] | 1591 | OP_USE_BIOMETRIC, // BIOMETRIC |
Zimuzo | 6cbf9cc | 2018-10-05 12:05:58 +0100 | [diff] [blame] | 1592 | OP_ACTIVITY_RECOGNITION, // ACTIVITY_RECOGNITION |
Hongming Jin | 228cd01 | 2018-11-09 14:47:50 -0800 | [diff] [blame] | 1593 | OP_SMS_FINANCIAL_TRANSACTIONS, // SMS_FINANCIAL_TRANSACTIONS |
Jeff Sharkey | d2a1f0d | 2018-11-19 10:32:52 -0700 | [diff] [blame] | 1594 | OP_READ_MEDIA_AUDIO, // READ_MEDIA_AUDIO |
| 1595 | OP_WRITE_MEDIA_AUDIO, // WRITE_MEDIA_AUDIO |
| 1596 | OP_READ_MEDIA_VIDEO, // READ_MEDIA_VIDEO |
| 1597 | OP_WRITE_MEDIA_VIDEO, // WRITE_MEDIA_VIDEO |
| 1598 | OP_READ_MEDIA_IMAGES, // READ_MEDIA_IMAGES |
| 1599 | OP_WRITE_MEDIA_IMAGES, // WRITE_MEDIA_IMAGES |
Jeff Sharkey | e82cbb1 | 2018-12-06 15:53:11 -0700 | [diff] [blame] | 1600 | OP_LEGACY_STORAGE, // LEGACY_STORAGE |
Jackal Guo | 8dc791e | 2019-01-14 10:26:42 +0800 | [diff] [blame] | 1601 | OP_ACCESS_ACCESSIBILITY, // ACCESS_ACCESSIBILITY |
Michael Groover | 656ef91 | 2019-04-09 17:09:57 -0700 | [diff] [blame] | 1602 | OP_READ_DEVICE_IDENTIFIERS, // READ_DEVICE_IDENTIFIERS |
Philip P. Moltmann | 89b044f | 2019-09-13 15:12:34 -0700 | [diff] [blame] | 1603 | OP_ACCESS_MEDIA_LOCATION, // ACCESS_MEDIA_LOCATION |
Patrick Baumann | 6c1c809 | 2019-06-27 14:55:44 -0700 | [diff] [blame] | 1604 | OP_QUERY_ALL_PACKAGES, // QUERY_ALL_PACKAGES |
Philip P. Moltmann | b43dfe3 | 2019-11-11 14:14:49 -0800 | [diff] [blame] | 1605 | OP_MANAGE_EXTERNAL_STORAGE, // MANAGE_EXTERNAL_STORAGE |
kholoud mohamed | 20ded1f | 2019-12-03 17:52:38 +0000 | [diff] [blame] | 1606 | OP_INTERACT_ACROSS_PROFILES, //INTERACT_ACROSS_PROFILES |
Benedict Wong | 3eb9520 | 2019-11-05 12:50:59 -0800 | [diff] [blame] | 1607 | OP_ACTIVATE_PLATFORM_VPN, // ACTIVATE_PLATFORM_VPN |
Todd Kennedy | b0948d4 | 2020-01-27 15:20:07 -0800 | [diff] [blame] | 1608 | OP_LOADER_USAGE_STATS, // LOADER_USAGE_STATS |
Ricardo Correa | acdc827 | 2020-03-24 11:02:54 -0700 | [diff] [blame] | 1609 | OP_DEPRECATED_1, // deprecated |
Eugene Susla | 5fc2d76 | 2020-03-04 13:53:10 -0800 | [diff] [blame] | 1610 | OP_AUTO_REVOKE_PERMISSIONS_IF_UNUSED, //AUTO_REVOKE_PERMISSIONS_IF_UNUSED |
Eugene Susla | 922cd08 | 2020-03-11 12:38:17 -0700 | [diff] [blame] | 1611 | OP_AUTO_REVOKE_MANAGED_BY_INSTALLER, //OP_AUTO_REVOKE_MANAGED_BY_INSTALLER |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 1612 | }; |
| 1613 | |
| 1614 | /** |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 1615 | * This maps each operation to the public string constant for it. |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 1616 | */ |
Peter Visontay | 5a2a1ef | 2017-12-18 20:34:03 +0000 | [diff] [blame] | 1617 | private static String[] sOpToString = new String[]{ |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 1618 | OPSTR_COARSE_LOCATION, |
| 1619 | OPSTR_FINE_LOCATION, |
Peter Visontay | 5a2a1ef | 2017-12-18 20:34:03 +0000 | [diff] [blame] | 1620 | OPSTR_GPS, |
| 1621 | OPSTR_VIBRATE, |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 1622 | OPSTR_READ_CONTACTS, |
| 1623 | OPSTR_WRITE_CONTACTS, |
| 1624 | OPSTR_READ_CALL_LOG, |
| 1625 | OPSTR_WRITE_CALL_LOG, |
| 1626 | OPSTR_READ_CALENDAR, |
| 1627 | OPSTR_WRITE_CALENDAR, |
Peter Visontay | 5a2a1ef | 2017-12-18 20:34:03 +0000 | [diff] [blame] | 1628 | OPSTR_WIFI_SCAN, |
| 1629 | OPSTR_POST_NOTIFICATION, |
| 1630 | OPSTR_NEIGHBORING_CELLS, |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 1631 | OPSTR_CALL_PHONE, |
| 1632 | OPSTR_READ_SMS, |
Peter Visontay | 5a2a1ef | 2017-12-18 20:34:03 +0000 | [diff] [blame] | 1633 | OPSTR_WRITE_SMS, |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 1634 | OPSTR_RECEIVE_SMS, |
Peter Visontay | 5a2a1ef | 2017-12-18 20:34:03 +0000 | [diff] [blame] | 1635 | OPSTR_RECEIVE_EMERGENCY_BROADCAST, |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 1636 | OPSTR_RECEIVE_MMS, |
| 1637 | OPSTR_RECEIVE_WAP_PUSH, |
| 1638 | OPSTR_SEND_SMS, |
Peter Visontay | 5a2a1ef | 2017-12-18 20:34:03 +0000 | [diff] [blame] | 1639 | OPSTR_READ_ICC_SMS, |
| 1640 | OPSTR_WRITE_ICC_SMS, |
Billy Lau | 24b9c83 | 2015-07-20 17:34:09 +0100 | [diff] [blame] | 1641 | OPSTR_WRITE_SETTINGS, |
| 1642 | OPSTR_SYSTEM_ALERT_WINDOW, |
Peter Visontay | 5a2a1ef | 2017-12-18 20:34:03 +0000 | [diff] [blame] | 1643 | OPSTR_ACCESS_NOTIFICATIONS, |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 1644 | OPSTR_CAMERA, |
| 1645 | OPSTR_RECORD_AUDIO, |
Peter Visontay | 5a2a1ef | 2017-12-18 20:34:03 +0000 | [diff] [blame] | 1646 | OPSTR_PLAY_AUDIO, |
| 1647 | OPSTR_READ_CLIPBOARD, |
| 1648 | OPSTR_WRITE_CLIPBOARD, |
| 1649 | OPSTR_TAKE_MEDIA_BUTTONS, |
| 1650 | OPSTR_TAKE_AUDIO_FOCUS, |
| 1651 | OPSTR_AUDIO_MASTER_VOLUME, |
| 1652 | OPSTR_AUDIO_VOICE_VOLUME, |
| 1653 | OPSTR_AUDIO_RING_VOLUME, |
| 1654 | OPSTR_AUDIO_MEDIA_VOLUME, |
| 1655 | OPSTR_AUDIO_ALARM_VOLUME, |
| 1656 | OPSTR_AUDIO_NOTIFICATION_VOLUME, |
| 1657 | OPSTR_AUDIO_BLUETOOTH_VOLUME, |
| 1658 | OPSTR_WAKE_LOCK, |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 1659 | OPSTR_MONITOR_LOCATION, |
| 1660 | OPSTR_MONITOR_HIGH_POWER_LOCATION, |
Dianne Hackborn | 5064e7c | 2014-09-02 10:57:16 -0700 | [diff] [blame] | 1661 | OPSTR_GET_USAGE_STATS, |
Peter Visontay | 5a2a1ef | 2017-12-18 20:34:03 +0000 | [diff] [blame] | 1662 | OPSTR_MUTE_MICROPHONE, |
| 1663 | OPSTR_TOAST_WINDOW, |
| 1664 | OPSTR_PROJECT_MEDIA, |
Jeff Davidson | 0554260 | 2014-08-11 14:07:27 -0700 | [diff] [blame] | 1665 | OPSTR_ACTIVATE_VPN, |
Peter Visontay | 5a2a1ef | 2017-12-18 20:34:03 +0000 | [diff] [blame] | 1666 | OPSTR_WRITE_WALLPAPER, |
| 1667 | OPSTR_ASSIST_STRUCTURE, |
| 1668 | OPSTR_ASSIST_SCREENSHOT, |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 1669 | OPSTR_READ_PHONE_STATE, |
| 1670 | OPSTR_ADD_VOICEMAIL, |
| 1671 | OPSTR_USE_SIP, |
Svet Ganov | 824ad6e | 2016-09-22 19:36:53 -0700 | [diff] [blame] | 1672 | OPSTR_PROCESS_OUTGOING_CALLS, |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 1673 | OPSTR_USE_FINGERPRINT, |
Svet Ganov | ede4316 | 2015-05-02 17:42:44 -0700 | [diff] [blame] | 1674 | OPSTR_BODY_SENSORS, |
Svet Ganov | f7e9cf4 | 2015-05-13 10:40:31 -0700 | [diff] [blame] | 1675 | OPSTR_READ_CELL_BROADCASTS, |
Svet Ganov | 921c7df | 2015-06-29 21:51:41 -0700 | [diff] [blame] | 1676 | OPSTR_MOCK_LOCATION, |
| 1677 | OPSTR_READ_EXTERNAL_STORAGE, |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 1678 | OPSTR_WRITE_EXTERNAL_STORAGE, |
Peter Visontay | 5a2a1ef | 2017-12-18 20:34:03 +0000 | [diff] [blame] | 1679 | OPSTR_TURN_SCREEN_ON, |
Dianne Hackborn | bef28fe | 2015-10-29 17:57:11 -0700 | [diff] [blame] | 1680 | OPSTR_GET_ACCOUNTS, |
Peter Visontay | 5a2a1ef | 2017-12-18 20:34:03 +0000 | [diff] [blame] | 1681 | OPSTR_RUN_IN_BACKGROUND, |
| 1682 | OPSTR_AUDIO_ACCESSIBILITY_VOLUME, |
Chad Brubaker | 0c1651f | 2017-03-30 16:29:10 -0700 | [diff] [blame] | 1683 | OPSTR_READ_PHONE_NUMBERS, |
Peter Visontay | 5a2a1ef | 2017-12-18 20:34:03 +0000 | [diff] [blame] | 1684 | OPSTR_REQUEST_INSTALL_PACKAGES, |
Winson Chung | f4ac063 | 2017-03-17 12:34:12 -0700 | [diff] [blame] | 1685 | OPSTR_PICTURE_IN_PICTURE, |
Chad Brubaker | 97b383f | 2017-02-02 15:04:35 -0800 | [diff] [blame] | 1686 | OPSTR_INSTANT_APP_START_FOREGROUND, |
Eugene Susla | cae3d3e | 2017-01-31 11:08:11 -0800 | [diff] [blame] | 1687 | OPSTR_ANSWER_PHONE_CALLS, |
Peter Visontay | 5a2a1ef | 2017-12-18 20:34:03 +0000 | [diff] [blame] | 1688 | OPSTR_RUN_ANY_IN_BACKGROUND, |
| 1689 | OPSTR_CHANGE_WIFI_STATE, |
| 1690 | OPSTR_REQUEST_DELETE_PACKAGES, |
| 1691 | OPSTR_BIND_ACCESSIBILITY_SERVICE, |
Tyler Gunn | 79bc1ec | 2018-01-22 15:17:54 -0800 | [diff] [blame] | 1692 | OPSTR_ACCEPT_HANDOVER, |
Nathan Harold | 1bb42067 | 2018-03-14 17:08:53 -0700 | [diff] [blame] | 1693 | OPSTR_MANAGE_IPSEC_TUNNELS, |
Dianne Hackborn | e9d9b4b | 2018-03-28 13:51:46 -0700 | [diff] [blame] | 1694 | OPSTR_START_FOREGROUND, |
Dianne Hackborn | e04f13d | 2018-05-02 12:51:52 -0700 | [diff] [blame] | 1695 | OPSTR_BLUETOOTH_SCAN, |
Kevin Chyn | b3c05aa | 2018-09-21 16:50:32 -0700 | [diff] [blame] | 1696 | OPSTR_USE_BIOMETRIC, |
Zimuzo | 6cbf9cc | 2018-10-05 12:05:58 +0100 | [diff] [blame] | 1697 | OPSTR_ACTIVITY_RECOGNITION, |
Hongming Jin | 228cd01 | 2018-11-09 14:47:50 -0800 | [diff] [blame] | 1698 | OPSTR_SMS_FINANCIAL_TRANSACTIONS, |
Jeff Sharkey | d2a1f0d | 2018-11-19 10:32:52 -0700 | [diff] [blame] | 1699 | OPSTR_READ_MEDIA_AUDIO, |
| 1700 | OPSTR_WRITE_MEDIA_AUDIO, |
| 1701 | OPSTR_READ_MEDIA_VIDEO, |
| 1702 | OPSTR_WRITE_MEDIA_VIDEO, |
| 1703 | OPSTR_READ_MEDIA_IMAGES, |
| 1704 | OPSTR_WRITE_MEDIA_IMAGES, |
Jeff Sharkey | e82cbb1 | 2018-12-06 15:53:11 -0700 | [diff] [blame] | 1705 | OPSTR_LEGACY_STORAGE, |
Jackal Guo | 8dc791e | 2019-01-14 10:26:42 +0800 | [diff] [blame] | 1706 | OPSTR_ACCESS_ACCESSIBILITY, |
Michael Groover | 656ef91 | 2019-04-09 17:09:57 -0700 | [diff] [blame] | 1707 | OPSTR_READ_DEVICE_IDENTIFIERS, |
Philip P. Moltmann | 89b044f | 2019-09-13 15:12:34 -0700 | [diff] [blame] | 1708 | OPSTR_ACCESS_MEDIA_LOCATION, |
Patrick Baumann | 6c1c809 | 2019-06-27 14:55:44 -0700 | [diff] [blame] | 1709 | OPSTR_QUERY_ALL_PACKAGES, |
Philip P. Moltmann | b43dfe3 | 2019-11-11 14:14:49 -0800 | [diff] [blame] | 1710 | OPSTR_MANAGE_EXTERNAL_STORAGE, |
kholoud mohamed | 20ded1f | 2019-12-03 17:52:38 +0000 | [diff] [blame] | 1711 | OPSTR_INTERACT_ACROSS_PROFILES, |
Benedict Wong | 3eb9520 | 2019-11-05 12:50:59 -0800 | [diff] [blame] | 1712 | OPSTR_ACTIVATE_PLATFORM_VPN, |
Todd Kennedy | b0948d4 | 2020-01-27 15:20:07 -0800 | [diff] [blame] | 1713 | OPSTR_LOADER_USAGE_STATS, |
Ricardo Correa | acdc827 | 2020-03-24 11:02:54 -0700 | [diff] [blame] | 1714 | "", // deprecated |
Eugene Susla | 5fc2d76 | 2020-03-04 13:53:10 -0800 | [diff] [blame] | 1715 | OPSTR_AUTO_REVOKE_PERMISSIONS_IF_UNUSED, |
Eugene Susla | 1d7a791 | 2020-03-14 09:16:29 -0700 | [diff] [blame] | 1716 | OPSTR_AUTO_REVOKE_MANAGED_BY_INSTALLER, |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 1717 | }; |
| 1718 | |
| 1719 | /** |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 1720 | * This provides a simple name for each operation to be used |
| 1721 | * in debug output. |
| 1722 | */ |
Dianne Hackborn | 5e45ee6 | 2013-01-24 19:13:44 -0800 | [diff] [blame] | 1723 | private static String[] sOpNames = new String[] { |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 1724 | "COARSE_LOCATION", |
| 1725 | "FINE_LOCATION", |
| 1726 | "GPS", |
| 1727 | "VIBRATE", |
| 1728 | "READ_CONTACTS", |
| 1729 | "WRITE_CONTACTS", |
| 1730 | "READ_CALL_LOG", |
| 1731 | "WRITE_CALL_LOG", |
| 1732 | "READ_CALENDAR", |
| 1733 | "WRITE_CALENDAR", |
| 1734 | "WIFI_SCAN", |
| 1735 | "POST_NOTIFICATION", |
| 1736 | "NEIGHBORING_CELLS", |
| 1737 | "CALL_PHONE", |
Dianne Hackborn | f51f612 | 2013-02-04 18:23:34 -0800 | [diff] [blame] | 1738 | "READ_SMS", |
| 1739 | "WRITE_SMS", |
| 1740 | "RECEIVE_SMS", |
| 1741 | "RECEIVE_EMERGECY_SMS", |
| 1742 | "RECEIVE_MMS", |
| 1743 | "RECEIVE_WAP_PUSH", |
| 1744 | "SEND_SMS", |
| 1745 | "READ_ICC_SMS", |
| 1746 | "WRITE_ICC_SMS", |
Dianne Hackborn | 961321f | 2013-02-05 17:22:41 -0800 | [diff] [blame] | 1747 | "WRITE_SETTINGS", |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 1748 | "SYSTEM_ALERT_WINDOW", |
Daniel Sandler | fde19b1 | 2013-01-17 00:21:05 -0500 | [diff] [blame] | 1749 | "ACCESS_NOTIFICATIONS", |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 1750 | "CAMERA", |
| 1751 | "RECORD_AUDIO", |
| 1752 | "PLAY_AUDIO", |
Dianne Hackborn | efcc1a2 | 2013-02-25 18:02:35 -0800 | [diff] [blame] | 1753 | "READ_CLIPBOARD", |
| 1754 | "WRITE_CLIPBOARD", |
Dianne Hackborn | ba50b97c | 2013-04-30 15:04:46 -0700 | [diff] [blame] | 1755 | "TAKE_MEDIA_BUTTONS", |
| 1756 | "TAKE_AUDIO_FOCUS", |
| 1757 | "AUDIO_MASTER_VOLUME", |
| 1758 | "AUDIO_VOICE_VOLUME", |
| 1759 | "AUDIO_RING_VOLUME", |
| 1760 | "AUDIO_MEDIA_VOLUME", |
| 1761 | "AUDIO_ALARM_VOLUME", |
| 1762 | "AUDIO_NOTIFICATION_VOLUME", |
| 1763 | "AUDIO_BLUETOOTH_VOLUME", |
Dianne Hackborn | 713df15 | 2013-05-17 11:27:57 -0700 | [diff] [blame] | 1764 | "WAKE_LOCK", |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 1765 | "MONITOR_LOCATION", |
David Christie | 0b83745 | 2013-07-29 16:02:13 -0700 | [diff] [blame] | 1766 | "MONITOR_HIGH_POWER_LOCATION", |
Emily Bernier | 22c921a | 2014-05-28 11:01:32 -0400 | [diff] [blame] | 1767 | "GET_USAGE_STATS", |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 1768 | "MUTE_MICROPHONE", |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 1769 | "TOAST_WINDOW", |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 1770 | "PROJECT_MEDIA", |
Jeff Davidson | 0554260 | 2014-08-11 14:07:27 -0700 | [diff] [blame] | 1771 | "ACTIVATE_VPN", |
Benjamin Franz | f3ece36 | 2015-02-11 10:51:10 +0000 | [diff] [blame] | 1772 | "WRITE_WALLPAPER", |
Dianne Hackborn | d59a5d5 | 2015-04-04 14:52:14 -0700 | [diff] [blame] | 1773 | "ASSIST_STRUCTURE", |
Svet Ganov | 16a1689 | 2015-04-16 10:32:04 -0700 | [diff] [blame] | 1774 | "ASSIST_SCREENSHOT", |
Eugene Susla | e4ee2c2 | 2018-11-05 12:23:30 -0800 | [diff] [blame] | 1775 | "READ_PHONE_STATE", |
Svetoslav | 5335b67 | 2015-04-29 12:00:51 -0700 | [diff] [blame] | 1776 | "ADD_VOICEMAIL", |
Svetoslav | c656e6f | 2015-04-29 14:08:16 -0700 | [diff] [blame] | 1777 | "USE_SIP", |
Svetoslav | 4af76a5 | 2015-04-29 15:29:46 -0700 | [diff] [blame] | 1778 | "PROCESS_OUTGOING_CALLS", |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 1779 | "USE_FINGERPRINT", |
Svet Ganov | ede4316 | 2015-05-02 17:42:44 -0700 | [diff] [blame] | 1780 | "BODY_SENSORS", |
Svet Ganov | f7e9cf4 | 2015-05-13 10:40:31 -0700 | [diff] [blame] | 1781 | "READ_CELL_BROADCASTS", |
Svet Ganov | 921c7df | 2015-06-29 21:51:41 -0700 | [diff] [blame] | 1782 | "MOCK_LOCATION", |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 1783 | "READ_EXTERNAL_STORAGE", |
| 1784 | "WRITE_EXTERNAL_STORAGE", |
| 1785 | "TURN_ON_SCREEN", |
Svetoslav | f3f02ac | 2015-09-08 14:36:35 -0700 | [diff] [blame] | 1786 | "GET_ACCOUNTS", |
Dianne Hackborn | bef28fe | 2015-10-29 17:57:11 -0700 | [diff] [blame] | 1787 | "RUN_IN_BACKGROUND", |
Jean-Michel Trivi | 3f0945a | 2016-11-11 10:05:18 -0800 | [diff] [blame] | 1788 | "AUDIO_ACCESSIBILITY_VOLUME", |
Chad Brubaker | 0c1651f | 2017-03-30 16:29:10 -0700 | [diff] [blame] | 1789 | "READ_PHONE_NUMBERS", |
Suprabh Shukla | 2f34b1a | 2016-12-16 14:47:25 -0800 | [diff] [blame] | 1790 | "REQUEST_INSTALL_PACKAGES", |
Winson Chung | f4ac063 | 2017-03-17 12:34:12 -0700 | [diff] [blame] | 1791 | "PICTURE_IN_PICTURE", |
Chad Brubaker | 97b383f | 2017-02-02 15:04:35 -0800 | [diff] [blame] | 1792 | "INSTANT_APP_START_FOREGROUND", |
Eugene Susla | cae3d3e | 2017-01-31 11:08:11 -0800 | [diff] [blame] | 1793 | "ANSWER_PHONE_CALLS", |
Suprabh Shukla | 3ac1daa | 2017-07-14 12:15:27 -0700 | [diff] [blame] | 1794 | "RUN_ANY_IN_BACKGROUND", |
Peter Visontay | 1246d9e | 2017-10-17 17:02:45 +0100 | [diff] [blame] | 1795 | "CHANGE_WIFI_STATE", |
Peter Visontay | f2e3836 | 2017-11-27 15:27:16 +0000 | [diff] [blame] | 1796 | "REQUEST_DELETE_PACKAGES", |
Peter Visontay | 1195083 | 2017-11-14 19:34:59 +0000 | [diff] [blame] | 1797 | "BIND_ACCESSIBILITY_SERVICE", |
Tyler Gunn | 79bc1ec | 2018-01-22 15:17:54 -0800 | [diff] [blame] | 1798 | "ACCEPT_HANDOVER", |
Nathan Harold | 1bb42067 | 2018-03-14 17:08:53 -0700 | [diff] [blame] | 1799 | "MANAGE_IPSEC_TUNNELS", |
Dianne Hackborn | e9d9b4b | 2018-03-28 13:51:46 -0700 | [diff] [blame] | 1800 | "START_FOREGROUND", |
Dianne Hackborn | e04f13d | 2018-05-02 12:51:52 -0700 | [diff] [blame] | 1801 | "BLUETOOTH_SCAN", |
Kevin Chyn | b3c05aa | 2018-09-21 16:50:32 -0700 | [diff] [blame] | 1802 | "USE_BIOMETRIC", |
Zimuzo | 6cbf9cc | 2018-10-05 12:05:58 +0100 | [diff] [blame] | 1803 | "ACTIVITY_RECOGNITION", |
Hongming Jin | 228cd01 | 2018-11-09 14:47:50 -0800 | [diff] [blame] | 1804 | "SMS_FINANCIAL_TRANSACTIONS", |
Jeff Sharkey | d2a1f0d | 2018-11-19 10:32:52 -0700 | [diff] [blame] | 1805 | "READ_MEDIA_AUDIO", |
| 1806 | "WRITE_MEDIA_AUDIO", |
| 1807 | "READ_MEDIA_VIDEO", |
| 1808 | "WRITE_MEDIA_VIDEO", |
| 1809 | "READ_MEDIA_IMAGES", |
| 1810 | "WRITE_MEDIA_IMAGES", |
Jeff Sharkey | e82cbb1 | 2018-12-06 15:53:11 -0700 | [diff] [blame] | 1811 | "LEGACY_STORAGE", |
Jackal Guo | 8dc791e | 2019-01-14 10:26:42 +0800 | [diff] [blame] | 1812 | "ACCESS_ACCESSIBILITY", |
Michael Groover | 656ef91 | 2019-04-09 17:09:57 -0700 | [diff] [blame] | 1813 | "READ_DEVICE_IDENTIFIERS", |
Philip P. Moltmann | 89b044f | 2019-09-13 15:12:34 -0700 | [diff] [blame] | 1814 | "ACCESS_MEDIA_LOCATION", |
Patrick Baumann | 6c1c809 | 2019-06-27 14:55:44 -0700 | [diff] [blame] | 1815 | "QUERY_ALL_PACKAGES", |
kholoud mohamed | 20ded1f | 2019-12-03 17:52:38 +0000 | [diff] [blame] | 1816 | "MANAGE_EXTERNAL_STORAGE", |
Benedict Wong | 3eb9520 | 2019-11-05 12:50:59 -0800 | [diff] [blame] | 1817 | "INTERACT_ACROSS_PROFILES", |
| 1818 | "ACTIVATE_PLATFORM_VPN", |
Todd Kennedy | b0948d4 | 2020-01-27 15:20:07 -0800 | [diff] [blame] | 1819 | "LOADER_USAGE_STATS", |
Ricardo Correa | acdc827 | 2020-03-24 11:02:54 -0700 | [diff] [blame] | 1820 | "deprecated", |
Eugene Susla | 5fc2d76 | 2020-03-04 13:53:10 -0800 | [diff] [blame] | 1821 | "AUTO_REVOKE_PERMISSIONS_IF_UNUSED", |
Eugene Susla | 1d7a791 | 2020-03-14 09:16:29 -0700 | [diff] [blame] | 1822 | "AUTO_REVOKE_MANAGED_BY_INSTALLER", |
Dianne Hackborn | 5e45ee6 | 2013-01-24 19:13:44 -0800 | [diff] [blame] | 1823 | }; |
| 1824 | |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 1825 | /** |
| 1826 | * This optionally maps a permission to an operation. If there |
| 1827 | * is no permission associated with an operation, it is null. |
| 1828 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 1829 | @UnsupportedAppUsage |
Dianne Hackborn | 5e45ee6 | 2013-01-24 19:13:44 -0800 | [diff] [blame] | 1830 | private static String[] sOpPerms = new String[] { |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 1831 | android.Manifest.permission.ACCESS_COARSE_LOCATION, |
| 1832 | android.Manifest.permission.ACCESS_FINE_LOCATION, |
| 1833 | null, |
| 1834 | android.Manifest.permission.VIBRATE, |
| 1835 | android.Manifest.permission.READ_CONTACTS, |
| 1836 | android.Manifest.permission.WRITE_CONTACTS, |
| 1837 | android.Manifest.permission.READ_CALL_LOG, |
| 1838 | android.Manifest.permission.WRITE_CALL_LOG, |
| 1839 | android.Manifest.permission.READ_CALENDAR, |
| 1840 | android.Manifest.permission.WRITE_CALENDAR, |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 1841 | android.Manifest.permission.ACCESS_WIFI_STATE, |
Robert Craig | f97616c | 2013-10-07 12:32:02 -0400 | [diff] [blame] | 1842 | null, // no permission required for notifications |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 1843 | null, // neighboring cells shares the coarse location perm |
| 1844 | android.Manifest.permission.CALL_PHONE, |
Dianne Hackborn | f51f612 | 2013-02-04 18:23:34 -0800 | [diff] [blame] | 1845 | android.Manifest.permission.READ_SMS, |
Svetoslav | 6c58957 | 2015-04-16 16:19:24 -0700 | [diff] [blame] | 1846 | null, // no permission required for writing sms |
Dianne Hackborn | f51f612 | 2013-02-04 18:23:34 -0800 | [diff] [blame] | 1847 | android.Manifest.permission.RECEIVE_SMS, |
| 1848 | android.Manifest.permission.RECEIVE_EMERGENCY_BROADCAST, |
| 1849 | android.Manifest.permission.RECEIVE_MMS, |
| 1850 | android.Manifest.permission.RECEIVE_WAP_PUSH, |
| 1851 | android.Manifest.permission.SEND_SMS, |
| 1852 | android.Manifest.permission.READ_SMS, |
Svetoslav | 6c58957 | 2015-04-16 16:19:24 -0700 | [diff] [blame] | 1853 | null, // no permission required for writing icc sms |
Dianne Hackborn | 961321f | 2013-02-05 17:22:41 -0800 | [diff] [blame] | 1854 | android.Manifest.permission.WRITE_SETTINGS, |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 1855 | android.Manifest.permission.SYSTEM_ALERT_WINDOW, |
Daniel Sandler | fde19b1 | 2013-01-17 00:21:05 -0500 | [diff] [blame] | 1856 | android.Manifest.permission.ACCESS_NOTIFICATIONS, |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 1857 | android.Manifest.permission.CAMERA, |
| 1858 | android.Manifest.permission.RECORD_AUDIO, |
| 1859 | null, // no permission for playing audio |
Dianne Hackborn | efcc1a2 | 2013-02-25 18:02:35 -0800 | [diff] [blame] | 1860 | null, // no permission for reading clipboard |
| 1861 | null, // no permission for writing clipboard |
Dianne Hackborn | ba50b97c | 2013-04-30 15:04:46 -0700 | [diff] [blame] | 1862 | null, // no permission for taking media buttons |
| 1863 | null, // no permission for taking audio focus |
| 1864 | null, // no permission for changing master volume |
| 1865 | null, // no permission for changing voice volume |
| 1866 | null, // no permission for changing ring volume |
| 1867 | null, // no permission for changing media volume |
| 1868 | null, // no permission for changing alarm volume |
| 1869 | null, // no permission for changing notification volume |
| 1870 | null, // no permission for changing bluetooth volume |
Dianne Hackborn | 713df15 | 2013-05-17 11:27:57 -0700 | [diff] [blame] | 1871 | android.Manifest.permission.WAKE_LOCK, |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 1872 | null, // no permission for generic location monitoring |
David Christie | 0b83745 | 2013-07-29 16:02:13 -0700 | [diff] [blame] | 1873 | null, // no permission for high power location monitoring |
Dianne Hackborn | e22b3b1 | 2014-05-07 18:06:44 -0700 | [diff] [blame] | 1874 | android.Manifest.permission.PACKAGE_USAGE_STATS, |
Emily Bernier | 22c921a | 2014-05-28 11:01:32 -0400 | [diff] [blame] | 1875 | null, // no permission for muting/unmuting microphone |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 1876 | null, // no permission for displaying toasts |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 1877 | null, // no permission for projecting media |
Jeff Davidson | 0554260 | 2014-08-11 14:07:27 -0700 | [diff] [blame] | 1878 | null, // no permission for activating vpn |
Benjamin Franz | f3ece36 | 2015-02-11 10:51:10 +0000 | [diff] [blame] | 1879 | null, // no permission for supporting wallpaper |
Dianne Hackborn | d59a5d5 | 2015-04-04 14:52:14 -0700 | [diff] [blame] | 1880 | null, // no permission for receiving assist structure |
| 1881 | null, // no permission for receiving assist screenshot |
Svet Ganov | c330009 | 2015-04-17 09:07:22 -0700 | [diff] [blame] | 1882 | Manifest.permission.READ_PHONE_STATE, |
Svetoslav | 5335b67 | 2015-04-29 12:00:51 -0700 | [diff] [blame] | 1883 | Manifest.permission.ADD_VOICEMAIL, |
Svetoslav | c656e6f | 2015-04-29 14:08:16 -0700 | [diff] [blame] | 1884 | Manifest.permission.USE_SIP, |
Svetoslav | 4af76a5 | 2015-04-29 15:29:46 -0700 | [diff] [blame] | 1885 | Manifest.permission.PROCESS_OUTGOING_CALLS, |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 1886 | Manifest.permission.USE_FINGERPRINT, |
Svet Ganov | ede4316 | 2015-05-02 17:42:44 -0700 | [diff] [blame] | 1887 | Manifest.permission.BODY_SENSORS, |
Svet Ganov | f7e9cf4 | 2015-05-13 10:40:31 -0700 | [diff] [blame] | 1888 | Manifest.permission.READ_CELL_BROADCASTS, |
Svet Ganov | 921c7df | 2015-06-29 21:51:41 -0700 | [diff] [blame] | 1889 | null, |
| 1890 | Manifest.permission.READ_EXTERNAL_STORAGE, |
| 1891 | Manifest.permission.WRITE_EXTERNAL_STORAGE, |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 1892 | null, // no permission for turning the screen on |
Dianne Hackborn | bef28fe | 2015-10-29 17:57:11 -0700 | [diff] [blame] | 1893 | Manifest.permission.GET_ACCOUNTS, |
| 1894 | null, // no permission for running in background |
Jean-Michel Trivi | 3f0945a | 2016-11-11 10:05:18 -0800 | [diff] [blame] | 1895 | null, // no permission for changing accessibility volume |
Chad Brubaker | 0c1651f | 2017-03-30 16:29:10 -0700 | [diff] [blame] | 1896 | Manifest.permission.READ_PHONE_NUMBERS, |
Suprabh Shukla | 2f34b1a | 2016-12-16 14:47:25 -0800 | [diff] [blame] | 1897 | Manifest.permission.REQUEST_INSTALL_PACKAGES, |
Winson Chung | 59fda9e | 2017-01-20 16:14:51 -0800 | [diff] [blame] | 1898 | null, // no permission for entering picture-in-picture on hide |
Chad Brubaker | 97b383f | 2017-02-02 15:04:35 -0800 | [diff] [blame] | 1899 | Manifest.permission.INSTANT_APP_FOREGROUND_SERVICE, |
Eugene Susla | cae3d3e | 2017-01-31 11:08:11 -0800 | [diff] [blame] | 1900 | Manifest.permission.ANSWER_PHONE_CALLS, |
Suprabh Shukla | 3ac1daa | 2017-07-14 12:15:27 -0700 | [diff] [blame] | 1901 | null, // no permission for OP_RUN_ANY_IN_BACKGROUND |
Peter Visontay | 1246d9e | 2017-10-17 17:02:45 +0100 | [diff] [blame] | 1902 | Manifest.permission.CHANGE_WIFI_STATE, |
Peter Visontay | f2e3836 | 2017-11-27 15:27:16 +0000 | [diff] [blame] | 1903 | Manifest.permission.REQUEST_DELETE_PACKAGES, |
Peter Visontay | 1195083 | 2017-11-14 19:34:59 +0000 | [diff] [blame] | 1904 | Manifest.permission.BIND_ACCESSIBILITY_SERVICE, |
Tyler Gunn | 79bc1ec | 2018-01-22 15:17:54 -0800 | [diff] [blame] | 1905 | Manifest.permission.ACCEPT_HANDOVER, |
Philip P. Moltmann | 4b38fbe | 2019-09-13 21:33:07 -0700 | [diff] [blame] | 1906 | Manifest.permission.MANAGE_IPSEC_TUNNELS, |
Dianne Hackborn | e9d9b4b | 2018-03-28 13:51:46 -0700 | [diff] [blame] | 1907 | Manifest.permission.FOREGROUND_SERVICE, |
Dianne Hackborn | e04f13d | 2018-05-02 12:51:52 -0700 | [diff] [blame] | 1908 | null, // no permission for OP_BLUETOOTH_SCAN |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 1909 | Manifest.permission.USE_BIOMETRIC, |
Zimuzo | 6cbf9cc | 2018-10-05 12:05:58 +0100 | [diff] [blame] | 1910 | Manifest.permission.ACTIVITY_RECOGNITION, |
Hongming Jin | 228cd01 | 2018-11-09 14:47:50 -0800 | [diff] [blame] | 1911 | Manifest.permission.SMS_FINANCIAL_TRANSACTIONS, |
Philip P. Moltmann | 129a0b0 | 2019-03-27 12:24:45 -0700 | [diff] [blame] | 1912 | null, |
Jeff Sharkey | 9787a945 | 2018-11-18 17:53:02 -0700 | [diff] [blame] | 1913 | null, // no permission for OP_WRITE_MEDIA_AUDIO |
Philip P. Moltmann | 129a0b0 | 2019-03-27 12:24:45 -0700 | [diff] [blame] | 1914 | null, |
Jeff Sharkey | 9787a945 | 2018-11-18 17:53:02 -0700 | [diff] [blame] | 1915 | null, // no permission for OP_WRITE_MEDIA_VIDEO |
Philip P. Moltmann | 129a0b0 | 2019-03-27 12:24:45 -0700 | [diff] [blame] | 1916 | null, |
Jeff Sharkey | 9787a945 | 2018-11-18 17:53:02 -0700 | [diff] [blame] | 1917 | null, // no permission for OP_WRITE_MEDIA_IMAGES |
Jeff Sharkey | e82cbb1 | 2018-12-06 15:53:11 -0700 | [diff] [blame] | 1918 | null, // no permission for OP_LEGACY_STORAGE |
Jackal Guo | 8dc791e | 2019-01-14 10:26:42 +0800 | [diff] [blame] | 1919 | null, // no permission for OP_ACCESS_ACCESSIBILITY |
Michael Groover | 656ef91 | 2019-04-09 17:09:57 -0700 | [diff] [blame] | 1920 | null, // no direct permission for OP_READ_DEVICE_IDENTIFIERS |
Philip P. Moltmann | 89b044f | 2019-09-13 15:12:34 -0700 | [diff] [blame] | 1921 | Manifest.permission.ACCESS_MEDIA_LOCATION, |
Patrick Baumann | 6c1c809 | 2019-06-27 14:55:44 -0700 | [diff] [blame] | 1922 | null, // no permission for OP_QUERY_ALL_PACKAGES |
shafik | 77cabc7 | 2020-01-03 16:22:50 +0000 | [diff] [blame] | 1923 | Manifest.permission.MANAGE_EXTERNAL_STORAGE, |
kholoud mohamed | 20ded1f | 2019-12-03 17:52:38 +0000 | [diff] [blame] | 1924 | android.Manifest.permission.INTERACT_ACROSS_PROFILES, |
Benedict Wong | 3eb9520 | 2019-11-05 12:50:59 -0800 | [diff] [blame] | 1925 | null, // no permission for OP_ACTIVATE_PLATFORM_VPN |
Todd Kennedy | b0948d4 | 2020-01-27 15:20:07 -0800 | [diff] [blame] | 1926 | android.Manifest.permission.LOADER_USAGE_STATS, |
Ricardo Correa | acdc827 | 2020-03-24 11:02:54 -0700 | [diff] [blame] | 1927 | null, // deprecated operation |
Eugene Susla | 5fc2d76 | 2020-03-04 13:53:10 -0800 | [diff] [blame] | 1928 | null, // no permission for OP_AUTO_REVOKE_PERMISSIONS_IF_UNUSED |
Eugene Susla | 922cd08 | 2020-03-11 12:38:17 -0700 | [diff] [blame] | 1929 | null, // no permission for OP_AUTO_REVOKE_MANAGED_BY_INSTALLER |
Dianne Hackborn | 5e45ee6 | 2013-01-24 19:13:44 -0800 | [diff] [blame] | 1930 | }; |
| 1931 | |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 1932 | /** |
Jason Monk | 6206299 | 2014-05-06 09:55:28 -0400 | [diff] [blame] | 1933 | * Specifies whether an Op should be restricted by a user restriction. |
| 1934 | * Each Op should be filled with a restriction string from UserManager or |
| 1935 | * null to specify it is not affected by any user restriction. |
| 1936 | */ |
| 1937 | private static String[] sOpRestrictions = new String[] { |
Julia Reynolds | 9854d57 | 2014-07-02 14:46:02 -0400 | [diff] [blame] | 1938 | UserManager.DISALLOW_SHARE_LOCATION, //COARSE_LOCATION |
| 1939 | UserManager.DISALLOW_SHARE_LOCATION, //FINE_LOCATION |
| 1940 | UserManager.DISALLOW_SHARE_LOCATION, //GPS |
Jason Monk | 6206299 | 2014-05-06 09:55:28 -0400 | [diff] [blame] | 1941 | null, //VIBRATE |
| 1942 | null, //READ_CONTACTS |
| 1943 | null, //WRITE_CONTACTS |
Yorke Lee | 15f83c6 | 2014-08-13 14:14:29 -0700 | [diff] [blame] | 1944 | UserManager.DISALLOW_OUTGOING_CALLS, //READ_CALL_LOG |
| 1945 | UserManager.DISALLOW_OUTGOING_CALLS, //WRITE_CALL_LOG |
Jason Monk | 6206299 | 2014-05-06 09:55:28 -0400 | [diff] [blame] | 1946 | null, //READ_CALENDAR |
| 1947 | null, //WRITE_CALENDAR |
Julia Reynolds | 9854d57 | 2014-07-02 14:46:02 -0400 | [diff] [blame] | 1948 | UserManager.DISALLOW_SHARE_LOCATION, //WIFI_SCAN |
Jason Monk | 6206299 | 2014-05-06 09:55:28 -0400 | [diff] [blame] | 1949 | null, //POST_NOTIFICATION |
| 1950 | null, //NEIGHBORING_CELLS |
| 1951 | null, //CALL_PHONE |
Amith Yamasani | 41c1ded | 2014-08-05 11:15:05 -0700 | [diff] [blame] | 1952 | UserManager.DISALLOW_SMS, //READ_SMS |
| 1953 | UserManager.DISALLOW_SMS, //WRITE_SMS |
| 1954 | UserManager.DISALLOW_SMS, //RECEIVE_SMS |
| 1955 | null, //RECEIVE_EMERGENCY_SMS |
| 1956 | UserManager.DISALLOW_SMS, //RECEIVE_MMS |
Jason Monk | 6206299 | 2014-05-06 09:55:28 -0400 | [diff] [blame] | 1957 | null, //RECEIVE_WAP_PUSH |
Amith Yamasani | 41c1ded | 2014-08-05 11:15:05 -0700 | [diff] [blame] | 1958 | UserManager.DISALLOW_SMS, //SEND_SMS |
| 1959 | UserManager.DISALLOW_SMS, //READ_ICC_SMS |
| 1960 | UserManager.DISALLOW_SMS, //WRITE_ICC_SMS |
Jason Monk | 6206299 | 2014-05-06 09:55:28 -0400 | [diff] [blame] | 1961 | null, //WRITE_SETTINGS |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 1962 | UserManager.DISALLOW_CREATE_WINDOWS, //SYSTEM_ALERT_WINDOW |
Jason Monk | 6206299 | 2014-05-06 09:55:28 -0400 | [diff] [blame] | 1963 | null, //ACCESS_NOTIFICATIONS |
Makoto Onuki | 759a763 | 2015-10-28 16:43:10 -0700 | [diff] [blame] | 1964 | UserManager.DISALLOW_CAMERA, //CAMERA |
Fyodor Kupolov | b501330 | 2015-04-17 17:59:14 -0700 | [diff] [blame] | 1965 | UserManager.DISALLOW_RECORD_AUDIO, //RECORD_AUDIO |
Jason Monk | 6206299 | 2014-05-06 09:55:28 -0400 | [diff] [blame] | 1966 | null, //PLAY_AUDIO |
| 1967 | null, //READ_CLIPBOARD |
| 1968 | null, //WRITE_CLIPBOARD |
| 1969 | null, //TAKE_MEDIA_BUTTONS |
| 1970 | null, //TAKE_AUDIO_FOCUS |
Emily Bernier | 45775c4 | 2014-05-16 15:12:04 -0400 | [diff] [blame] | 1971 | UserManager.DISALLOW_ADJUST_VOLUME, //AUDIO_MASTER_VOLUME |
| 1972 | UserManager.DISALLOW_ADJUST_VOLUME, //AUDIO_VOICE_VOLUME |
| 1973 | UserManager.DISALLOW_ADJUST_VOLUME, //AUDIO_RING_VOLUME |
| 1974 | UserManager.DISALLOW_ADJUST_VOLUME, //AUDIO_MEDIA_VOLUME |
| 1975 | UserManager.DISALLOW_ADJUST_VOLUME, //AUDIO_ALARM_VOLUME |
| 1976 | UserManager.DISALLOW_ADJUST_VOLUME, //AUDIO_NOTIFICATION_VOLUME |
| 1977 | UserManager.DISALLOW_ADJUST_VOLUME, //AUDIO_BLUETOOTH_VOLUME |
Jason Monk | 6206299 | 2014-05-06 09:55:28 -0400 | [diff] [blame] | 1978 | null, //WAKE_LOCK |
Julia Reynolds | 9854d57 | 2014-07-02 14:46:02 -0400 | [diff] [blame] | 1979 | UserManager.DISALLOW_SHARE_LOCATION, //MONITOR_LOCATION |
| 1980 | UserManager.DISALLOW_SHARE_LOCATION, //MONITOR_HIGH_POWER_LOCATION |
Jason Monk | 6206299 | 2014-05-06 09:55:28 -0400 | [diff] [blame] | 1981 | null, //GET_USAGE_STATS |
Emily Bernier | 22c921a | 2014-05-28 11:01:32 -0400 | [diff] [blame] | 1982 | UserManager.DISALLOW_UNMUTE_MICROPHONE, // MUTE_MICROPHONE |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 1983 | UserManager.DISALLOW_CREATE_WINDOWS, // TOAST_WINDOW |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 1984 | null, //PROJECT_MEDIA |
Tony Mak | 33d03a9 | 2016-06-02 15:01:16 +0100 | [diff] [blame] | 1985 | null, // ACTIVATE_VPN |
Benjamin Franz | f3ece36 | 2015-02-11 10:51:10 +0000 | [diff] [blame] | 1986 | UserManager.DISALLOW_WALLPAPER, // WRITE_WALLPAPER |
Dianne Hackborn | d59a5d5 | 2015-04-04 14:52:14 -0700 | [diff] [blame] | 1987 | null, // ASSIST_STRUCTURE |
| 1988 | null, // ASSIST_SCREENSHOT |
Svet Ganov | c330009 | 2015-04-17 09:07:22 -0700 | [diff] [blame] | 1989 | null, // READ_PHONE_STATE |
Svetoslav | 5335b67 | 2015-04-29 12:00:51 -0700 | [diff] [blame] | 1990 | null, // ADD_VOICEMAIL |
Svetoslav | c656e6f | 2015-04-29 14:08:16 -0700 | [diff] [blame] | 1991 | null, // USE_SIP |
Svetoslav | 4af76a5 | 2015-04-29 15:29:46 -0700 | [diff] [blame] | 1992 | null, // PROCESS_OUTGOING_CALLS |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 1993 | null, // USE_FINGERPRINT |
Svet Ganov | ede4316 | 2015-05-02 17:42:44 -0700 | [diff] [blame] | 1994 | null, // BODY_SENSORS |
Svet Ganov | f7e9cf4 | 2015-05-13 10:40:31 -0700 | [diff] [blame] | 1995 | null, // READ_CELL_BROADCASTS |
Svet Ganov | 921c7df | 2015-06-29 21:51:41 -0700 | [diff] [blame] | 1996 | null, // MOCK_LOCATION |
| 1997 | null, // READ_EXTERNAL_STORAGE |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 1998 | null, // WRITE_EXTERNAL_STORAGE |
| 1999 | null, // TURN_ON_SCREEN |
Svetoslav | f3f02ac | 2015-09-08 14:36:35 -0700 | [diff] [blame] | 2000 | null, // GET_ACCOUNTS |
Dianne Hackborn | bef28fe | 2015-10-29 17:57:11 -0700 | [diff] [blame] | 2001 | null, // RUN_IN_BACKGROUND |
Jean-Michel Trivi | 3f0945a | 2016-11-11 10:05:18 -0800 | [diff] [blame] | 2002 | UserManager.DISALLOW_ADJUST_VOLUME, //AUDIO_ACCESSIBILITY_VOLUME |
Chad Brubaker | 0c1651f | 2017-03-30 16:29:10 -0700 | [diff] [blame] | 2003 | null, // READ_PHONE_NUMBERS |
Suprabh Shukla | 2f34b1a | 2016-12-16 14:47:25 -0800 | [diff] [blame] | 2004 | null, // REQUEST_INSTALL_PACKAGES |
Winson Chung | 59fda9e | 2017-01-20 16:14:51 -0800 | [diff] [blame] | 2005 | null, // ENTER_PICTURE_IN_PICTURE_ON_HIDE |
Chad Brubaker | 97b383f | 2017-02-02 15:04:35 -0800 | [diff] [blame] | 2006 | null, // INSTANT_APP_START_FOREGROUND |
Eugene Susla | cae3d3e | 2017-01-31 11:08:11 -0800 | [diff] [blame] | 2007 | null, // ANSWER_PHONE_CALLS |
Suprabh Shukla | 3ac1daa | 2017-07-14 12:15:27 -0700 | [diff] [blame] | 2008 | null, // OP_RUN_ANY_IN_BACKGROUND |
Peter Visontay | 1246d9e | 2017-10-17 17:02:45 +0100 | [diff] [blame] | 2009 | null, // OP_CHANGE_WIFI_STATE |
Peter Visontay | f2e3836 | 2017-11-27 15:27:16 +0000 | [diff] [blame] | 2010 | null, // REQUEST_DELETE_PACKAGES |
Peter Visontay | 1195083 | 2017-11-14 19:34:59 +0000 | [diff] [blame] | 2011 | null, // OP_BIND_ACCESSIBILITY_SERVICE |
Tyler Gunn | 79bc1ec | 2018-01-22 15:17:54 -0800 | [diff] [blame] | 2012 | null, // ACCEPT_HANDOVER |
Nathan Harold | 1bb42067 | 2018-03-14 17:08:53 -0700 | [diff] [blame] | 2013 | null, // MANAGE_IPSEC_TUNNELS |
Dianne Hackborn | e9d9b4b | 2018-03-28 13:51:46 -0700 | [diff] [blame] | 2014 | null, // START_FOREGROUND |
Dianne Hackborn | e04f13d | 2018-05-02 12:51:52 -0700 | [diff] [blame] | 2015 | null, // maybe should be UserManager.DISALLOW_SHARE_LOCATION, //BLUETOOTH_SCAN |
Kevin Chyn | b3c05aa | 2018-09-21 16:50:32 -0700 | [diff] [blame] | 2016 | null, // USE_BIOMETRIC |
Zimuzo | 6cbf9cc | 2018-10-05 12:05:58 +0100 | [diff] [blame] | 2017 | null, // ACTIVITY_RECOGNITION |
Hongming Jin | 228cd01 | 2018-11-09 14:47:50 -0800 | [diff] [blame] | 2018 | UserManager.DISALLOW_SMS, // SMS_FINANCIAL_TRANSACTIONS |
Jeff Sharkey | d2a1f0d | 2018-11-19 10:32:52 -0700 | [diff] [blame] | 2019 | null, // READ_MEDIA_AUDIO |
| 2020 | null, // WRITE_MEDIA_AUDIO |
| 2021 | null, // READ_MEDIA_VIDEO |
| 2022 | null, // WRITE_MEDIA_VIDEO |
| 2023 | null, // READ_MEDIA_IMAGES |
| 2024 | null, // WRITE_MEDIA_IMAGES |
Jeff Sharkey | e82cbb1 | 2018-12-06 15:53:11 -0700 | [diff] [blame] | 2025 | null, // LEGACY_STORAGE |
Jackal Guo | 8dc791e | 2019-01-14 10:26:42 +0800 | [diff] [blame] | 2026 | null, // ACCESS_ACCESSIBILITY |
Michael Groover | 656ef91 | 2019-04-09 17:09:57 -0700 | [diff] [blame] | 2027 | null, // READ_DEVICE_IDENTIFIERS |
Philip P. Moltmann | 89b044f | 2019-09-13 15:12:34 -0700 | [diff] [blame] | 2028 | null, // ACCESS_MEDIA_LOCATION |
Patrick Baumann | 6c1c809 | 2019-06-27 14:55:44 -0700 | [diff] [blame] | 2029 | null, // QUERY_ALL_PACKAGES |
Philip P. Moltmann | b43dfe3 | 2019-11-11 14:14:49 -0800 | [diff] [blame] | 2030 | null, // MANAGE_EXTERNAL_STORAGE |
kholoud mohamed | 20ded1f | 2019-12-03 17:52:38 +0000 | [diff] [blame] | 2031 | null, // INTERACT_ACROSS_PROFILES |
Benedict Wong | 3eb9520 | 2019-11-05 12:50:59 -0800 | [diff] [blame] | 2032 | null, // ACTIVATE_PLATFORM_VPN |
Todd Kennedy | b0948d4 | 2020-01-27 15:20:07 -0800 | [diff] [blame] | 2033 | null, // LOADER_USAGE_STATS |
Ricardo Correa | acdc827 | 2020-03-24 11:02:54 -0700 | [diff] [blame] | 2034 | null, // deprecated operation |
Eugene Susla | 5fc2d76 | 2020-03-04 13:53:10 -0800 | [diff] [blame] | 2035 | null, // AUTO_REVOKE_PERMISSIONS_IF_UNUSED |
Eugene Susla | 1d7a791 | 2020-03-14 09:16:29 -0700 | [diff] [blame] | 2036 | null, // AUTO_REVOKE_MANAGED_BY_INSTALLER |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 2037 | }; |
| 2038 | |
| 2039 | /** |
Philip P. Moltmann | ad787aa | 2020-03-10 09:49:22 -0700 | [diff] [blame] | 2040 | * In which cases should an app be allowed to bypass the {@link #setUserRestriction user |
| 2041 | * restriction} for a certain app-op. |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 2042 | */ |
Philip P. Moltmann | ad787aa | 2020-03-10 09:49:22 -0700 | [diff] [blame] | 2043 | private static RestrictionBypass[] sOpAllowSystemRestrictionBypass = new RestrictionBypass[] { |
| 2044 | new RestrictionBypass(true, false), //COARSE_LOCATION |
| 2045 | new RestrictionBypass(true, false), //FINE_LOCATION |
| 2046 | null, //GPS |
| 2047 | null, //VIBRATE |
| 2048 | null, //READ_CONTACTS |
| 2049 | null, //WRITE_CONTACTS |
| 2050 | null, //READ_CALL_LOG |
| 2051 | null, //WRITE_CALL_LOG |
| 2052 | null, //READ_CALENDAR |
| 2053 | null, //WRITE_CALENDAR |
| 2054 | new RestrictionBypass(true, false), //WIFI_SCAN |
| 2055 | null, //POST_NOTIFICATION |
| 2056 | null, //NEIGHBORING_CELLS |
| 2057 | null, //CALL_PHONE |
| 2058 | null, //READ_SMS |
| 2059 | null, //WRITE_SMS |
| 2060 | null, //RECEIVE_SMS |
| 2061 | null, //RECEIVE_EMERGECY_SMS |
| 2062 | null, //RECEIVE_MMS |
| 2063 | null, //RECEIVE_WAP_PUSH |
| 2064 | null, //SEND_SMS |
| 2065 | null, //READ_ICC_SMS |
| 2066 | null, //WRITE_ICC_SMS |
| 2067 | null, //WRITE_SETTINGS |
| 2068 | new RestrictionBypass(true, false), //SYSTEM_ALERT_WINDOW |
| 2069 | null, //ACCESS_NOTIFICATIONS |
| 2070 | null, //CAMERA |
| 2071 | new RestrictionBypass(false, true), //RECORD_AUDIO |
| 2072 | null, //PLAY_AUDIO |
| 2073 | null, //READ_CLIPBOARD |
| 2074 | null, //WRITE_CLIPBOARD |
| 2075 | null, //TAKE_MEDIA_BUTTONS |
| 2076 | null, //TAKE_AUDIO_FOCUS |
| 2077 | null, //AUDIO_MASTER_VOLUME |
| 2078 | null, //AUDIO_VOICE_VOLUME |
| 2079 | null, //AUDIO_RING_VOLUME |
| 2080 | null, //AUDIO_MEDIA_VOLUME |
| 2081 | null, //AUDIO_ALARM_VOLUME |
| 2082 | null, //AUDIO_NOTIFICATION_VOLUME |
| 2083 | null, //AUDIO_BLUETOOTH_VOLUME |
| 2084 | null, //WAKE_LOCK |
| 2085 | null, //MONITOR_LOCATION |
| 2086 | null, //MONITOR_HIGH_POWER_LOCATION |
| 2087 | null, //GET_USAGE_STATS |
| 2088 | null, //MUTE_MICROPHONE |
| 2089 | new RestrictionBypass(true, false), //TOAST_WINDOW |
| 2090 | null, //PROJECT_MEDIA |
| 2091 | null, //ACTIVATE_VPN |
| 2092 | null, //WALLPAPER |
| 2093 | null, //ASSIST_STRUCTURE |
| 2094 | null, //ASSIST_SCREENSHOT |
| 2095 | null, //READ_PHONE_STATE |
| 2096 | null, //ADD_VOICEMAIL |
| 2097 | null, // USE_SIP |
| 2098 | null, // PROCESS_OUTGOING_CALLS |
| 2099 | null, // USE_FINGERPRINT |
| 2100 | null, // BODY_SENSORS |
| 2101 | null, // READ_CELL_BROADCASTS |
| 2102 | null, // MOCK_LOCATION |
| 2103 | null, // READ_EXTERNAL_STORAGE |
| 2104 | null, // WRITE_EXTERNAL_STORAGE |
| 2105 | null, // TURN_ON_SCREEN |
| 2106 | null, // GET_ACCOUNTS |
| 2107 | null, // RUN_IN_BACKGROUND |
| 2108 | null, // AUDIO_ACCESSIBILITY_VOLUME |
| 2109 | null, // READ_PHONE_NUMBERS |
| 2110 | null, // REQUEST_INSTALL_PACKAGES |
| 2111 | null, // ENTER_PICTURE_IN_PICTURE_ON_HIDE |
| 2112 | null, // INSTANT_APP_START_FOREGROUND |
| 2113 | null, // ANSWER_PHONE_CALLS |
| 2114 | null, // OP_RUN_ANY_IN_BACKGROUND |
| 2115 | null, // OP_CHANGE_WIFI_STATE |
| 2116 | null, // OP_REQUEST_DELETE_PACKAGES |
| 2117 | null, // OP_BIND_ACCESSIBILITY_SERVICE |
| 2118 | null, // ACCEPT_HANDOVER |
| 2119 | null, // MANAGE_IPSEC_HANDOVERS |
| 2120 | null, // START_FOREGROUND |
| 2121 | new RestrictionBypass(true, false), // BLUETOOTH_SCAN |
| 2122 | null, // USE_BIOMETRIC |
| 2123 | null, // ACTIVITY_RECOGNITION |
| 2124 | null, // SMS_FINANCIAL_TRANSACTIONS |
| 2125 | null, // READ_MEDIA_AUDIO |
| 2126 | null, // WRITE_MEDIA_AUDIO |
| 2127 | null, // READ_MEDIA_VIDEO |
| 2128 | null, // WRITE_MEDIA_VIDEO |
| 2129 | null, // READ_MEDIA_IMAGES |
| 2130 | null, // WRITE_MEDIA_IMAGES |
| 2131 | null, // LEGACY_STORAGE |
| 2132 | null, // ACCESS_ACCESSIBILITY |
| 2133 | null, // READ_DEVICE_IDENTIFIERS |
| 2134 | null, // ACCESS_MEDIA_LOCATION |
| 2135 | null, // QUERY_ALL_PACKAGES |
| 2136 | null, // MANAGE_EXTERNAL_STORAGE |
| 2137 | null, // INTERACT_ACROSS_PROFILES |
| 2138 | null, // ACTIVATE_PLATFORM_VPN |
| 2139 | null, // LOADER_USAGE_STATS |
Ricardo Correa | acdc827 | 2020-03-24 11:02:54 -0700 | [diff] [blame] | 2140 | null, // deprecated operation |
Philip P. Moltmann | ad787aa | 2020-03-10 09:49:22 -0700 | [diff] [blame] | 2141 | null, // AUTO_REVOKE_PERMISSIONS_IF_UNUSED |
Eugene Susla | 1d7a791 | 2020-03-14 09:16:29 -0700 | [diff] [blame] | 2142 | null, // AUTO_REVOKE_MANAGED_BY_INSTALLER |
Jason Monk | 6206299 | 2014-05-06 09:55:28 -0400 | [diff] [blame] | 2143 | }; |
| 2144 | |
| 2145 | /** |
David Braun | f5d8319 | 2013-09-16 13:43:51 -0700 | [diff] [blame] | 2146 | * This specifies the default mode for each operation. |
| 2147 | */ |
| 2148 | private static int[] sOpDefaultMode = new int[] { |
Eugene Susla | 9351985 | 2018-06-13 16:44:31 -0700 | [diff] [blame] | 2149 | AppOpsManager.MODE_ALLOWED, // COARSE_LOCATION |
| 2150 | AppOpsManager.MODE_ALLOWED, // FINE_LOCATION |
| 2151 | AppOpsManager.MODE_ALLOWED, // GPS |
| 2152 | AppOpsManager.MODE_ALLOWED, // VIBRATE |
| 2153 | AppOpsManager.MODE_ALLOWED, // READ_CONTACTS |
| 2154 | AppOpsManager.MODE_ALLOWED, // WRITE_CONTACTS |
Svet Ganov | d563e93 | 2019-04-14 13:07:41 -0700 | [diff] [blame] | 2155 | AppOpsManager.MODE_ALLOWED, // READ_CALL_LOG |
| 2156 | AppOpsManager.MODE_ALLOWED, // WRITE_CALL_LOG |
Eugene Susla | 9351985 | 2018-06-13 16:44:31 -0700 | [diff] [blame] | 2157 | AppOpsManager.MODE_ALLOWED, // READ_CALENDAR |
| 2158 | AppOpsManager.MODE_ALLOWED, // WRITE_CALENDAR |
| 2159 | AppOpsManager.MODE_ALLOWED, // WIFI_SCAN |
| 2160 | AppOpsManager.MODE_ALLOWED, // POST_NOTIFICATION |
| 2161 | AppOpsManager.MODE_ALLOWED, // NEIGHBORING_CELLS |
| 2162 | AppOpsManager.MODE_ALLOWED, // CALL_PHONE |
Svet Ganov | d563e93 | 2019-04-14 13:07:41 -0700 | [diff] [blame] | 2163 | AppOpsManager.MODE_ALLOWED, // READ_SMS |
Eugene Susla | aaff007 | 2018-10-30 13:35:03 -0700 | [diff] [blame] | 2164 | AppOpsManager.MODE_IGNORED, // WRITE_SMS |
Svet Ganov | d563e93 | 2019-04-14 13:07:41 -0700 | [diff] [blame] | 2165 | AppOpsManager.MODE_ALLOWED, // RECEIVE_SMS |
Eugene Susla | 9351985 | 2018-06-13 16:44:31 -0700 | [diff] [blame] | 2166 | AppOpsManager.MODE_ALLOWED, // RECEIVE_EMERGENCY_BROADCAST |
Svet Ganov | d563e93 | 2019-04-14 13:07:41 -0700 | [diff] [blame] | 2167 | AppOpsManager.MODE_ALLOWED, // RECEIVE_MMS |
| 2168 | AppOpsManager.MODE_ALLOWED, // RECEIVE_WAP_PUSH |
| 2169 | AppOpsManager.MODE_ALLOWED, // SEND_SMS |
Eugene Susla | 9351985 | 2018-06-13 16:44:31 -0700 | [diff] [blame] | 2170 | AppOpsManager.MODE_ALLOWED, // READ_ICC_SMS |
| 2171 | AppOpsManager.MODE_ALLOWED, // WRITE_ICC_SMS |
| 2172 | AppOpsManager.MODE_DEFAULT, // WRITE_SETTINGS |
Ng Zhi An | 65a99b6 | 2018-10-01 11:57:53 -0700 | [diff] [blame] | 2173 | getSystemAlertWindowDefault(), // SYSTEM_ALERT_WINDOW |
Eugene Susla | 9351985 | 2018-06-13 16:44:31 -0700 | [diff] [blame] | 2174 | AppOpsManager.MODE_ALLOWED, // ACCESS_NOTIFICATIONS |
| 2175 | AppOpsManager.MODE_ALLOWED, // CAMERA |
| 2176 | AppOpsManager.MODE_ALLOWED, // RECORD_AUDIO |
| 2177 | AppOpsManager.MODE_ALLOWED, // PLAY_AUDIO |
| 2178 | AppOpsManager.MODE_ALLOWED, // READ_CLIPBOARD |
| 2179 | AppOpsManager.MODE_ALLOWED, // WRITE_CLIPBOARD |
| 2180 | AppOpsManager.MODE_ALLOWED, // TAKE_MEDIA_BUTTONS |
| 2181 | AppOpsManager.MODE_ALLOWED, // TAKE_AUDIO_FOCUS |
| 2182 | AppOpsManager.MODE_ALLOWED, // AUDIO_MASTER_VOLUME |
| 2183 | AppOpsManager.MODE_ALLOWED, // AUDIO_VOICE_VOLUME |
| 2184 | AppOpsManager.MODE_ALLOWED, // AUDIO_RING_VOLUME |
| 2185 | AppOpsManager.MODE_ALLOWED, // AUDIO_MEDIA_VOLUME |
| 2186 | AppOpsManager.MODE_ALLOWED, // AUDIO_ALARM_VOLUME |
| 2187 | AppOpsManager.MODE_ALLOWED, // AUDIO_NOTIFICATION_VOLUME |
| 2188 | AppOpsManager.MODE_ALLOWED, // AUDIO_BLUETOOTH_VOLUME |
| 2189 | AppOpsManager.MODE_ALLOWED, // WAKE_LOCK |
| 2190 | AppOpsManager.MODE_ALLOWED, // MONITOR_LOCATION |
| 2191 | AppOpsManager.MODE_ALLOWED, // MONITOR_HIGH_POWER_LOCATION |
| 2192 | AppOpsManager.MODE_DEFAULT, // GET_USAGE_STATS |
| 2193 | AppOpsManager.MODE_ALLOWED, // MUTE_MICROPHONE |
| 2194 | AppOpsManager.MODE_ALLOWED, // TOAST_WINDOW |
| 2195 | AppOpsManager.MODE_IGNORED, // PROJECT_MEDIA |
| 2196 | AppOpsManager.MODE_IGNORED, // ACTIVATE_VPN |
| 2197 | AppOpsManager.MODE_ALLOWED, // WRITE_WALLPAPER |
| 2198 | AppOpsManager.MODE_ALLOWED, // ASSIST_STRUCTURE |
| 2199 | AppOpsManager.MODE_ALLOWED, // ASSIST_SCREENSHOT |
| 2200 | AppOpsManager.MODE_ALLOWED, // READ_PHONE_STATE |
| 2201 | AppOpsManager.MODE_ALLOWED, // ADD_VOICEMAIL |
| 2202 | AppOpsManager.MODE_ALLOWED, // USE_SIP |
Svet Ganov | d563e93 | 2019-04-14 13:07:41 -0700 | [diff] [blame] | 2203 | AppOpsManager.MODE_ALLOWED, // PROCESS_OUTGOING_CALLS |
Eugene Susla | 9351985 | 2018-06-13 16:44:31 -0700 | [diff] [blame] | 2204 | AppOpsManager.MODE_ALLOWED, // USE_FINGERPRINT |
| 2205 | AppOpsManager.MODE_ALLOWED, // BODY_SENSORS |
Svet Ganov | d563e93 | 2019-04-14 13:07:41 -0700 | [diff] [blame] | 2206 | AppOpsManager.MODE_ALLOWED, // READ_CELL_BROADCASTS |
Eugene Susla | 9351985 | 2018-06-13 16:44:31 -0700 | [diff] [blame] | 2207 | AppOpsManager.MODE_ERRORED, // MOCK_LOCATION |
| 2208 | AppOpsManager.MODE_ALLOWED, // READ_EXTERNAL_STORAGE |
| 2209 | AppOpsManager.MODE_ALLOWED, // WRITE_EXTERNAL_STORAGE |
| 2210 | AppOpsManager.MODE_ALLOWED, // TURN_SCREEN_ON |
| 2211 | AppOpsManager.MODE_ALLOWED, // GET_ACCOUNTS |
| 2212 | AppOpsManager.MODE_ALLOWED, // RUN_IN_BACKGROUND |
| 2213 | AppOpsManager.MODE_ALLOWED, // AUDIO_ACCESSIBILITY_VOLUME |
| 2214 | AppOpsManager.MODE_ALLOWED, // READ_PHONE_NUMBERS |
| 2215 | AppOpsManager.MODE_DEFAULT, // REQUEST_INSTALL_PACKAGES |
| 2216 | AppOpsManager.MODE_ALLOWED, // PICTURE_IN_PICTURE |
| 2217 | AppOpsManager.MODE_DEFAULT, // INSTANT_APP_START_FOREGROUND |
| 2218 | AppOpsManager.MODE_ALLOWED, // ANSWER_PHONE_CALLS |
| 2219 | AppOpsManager.MODE_ALLOWED, // RUN_ANY_IN_BACKGROUND |
| 2220 | AppOpsManager.MODE_ALLOWED, // CHANGE_WIFI_STATE |
| 2221 | AppOpsManager.MODE_ALLOWED, // REQUEST_DELETE_PACKAGES |
| 2222 | AppOpsManager.MODE_ALLOWED, // BIND_ACCESSIBILITY_SERVICE |
| 2223 | AppOpsManager.MODE_ALLOWED, // ACCEPT_HANDOVER |
| 2224 | AppOpsManager.MODE_ERRORED, // MANAGE_IPSEC_TUNNELS |
| 2225 | AppOpsManager.MODE_ALLOWED, // START_FOREGROUND |
| 2226 | AppOpsManager.MODE_ALLOWED, // BLUETOOTH_SCAN |
| 2227 | AppOpsManager.MODE_ALLOWED, // USE_BIOMETRIC |
Zimuzo | 6cbf9cc | 2018-10-05 12:05:58 +0100 | [diff] [blame] | 2228 | AppOpsManager.MODE_ALLOWED, // ACTIVITY_RECOGNITION |
Hongming Jin | 228cd01 | 2018-11-09 14:47:50 -0800 | [diff] [blame] | 2229 | AppOpsManager.MODE_DEFAULT, // SMS_FINANCIAL_TRANSACTIONS |
Jeff Sharkey | d2a1f0d | 2018-11-19 10:32:52 -0700 | [diff] [blame] | 2230 | AppOpsManager.MODE_ALLOWED, // READ_MEDIA_AUDIO |
Jeff Sharkey | 9787a945 | 2018-11-18 17:53:02 -0700 | [diff] [blame] | 2231 | AppOpsManager.MODE_ERRORED, // WRITE_MEDIA_AUDIO |
Jeff Sharkey | d2a1f0d | 2018-11-19 10:32:52 -0700 | [diff] [blame] | 2232 | AppOpsManager.MODE_ALLOWED, // READ_MEDIA_VIDEO |
Jeff Sharkey | 9787a945 | 2018-11-18 17:53:02 -0700 | [diff] [blame] | 2233 | AppOpsManager.MODE_ERRORED, // WRITE_MEDIA_VIDEO |
Jeff Sharkey | d2a1f0d | 2018-11-19 10:32:52 -0700 | [diff] [blame] | 2234 | AppOpsManager.MODE_ALLOWED, // READ_MEDIA_IMAGES |
Jeff Sharkey | 9787a945 | 2018-11-18 17:53:02 -0700 | [diff] [blame] | 2235 | AppOpsManager.MODE_ERRORED, // WRITE_MEDIA_IMAGES |
Jeff Sharkey | e82cbb1 | 2018-12-06 15:53:11 -0700 | [diff] [blame] | 2236 | AppOpsManager.MODE_DEFAULT, // LEGACY_STORAGE |
Jackal Guo | 8dc791e | 2019-01-14 10:26:42 +0800 | [diff] [blame] | 2237 | AppOpsManager.MODE_ALLOWED, // ACCESS_ACCESSIBILITY |
Michael Groover | 656ef91 | 2019-04-09 17:09:57 -0700 | [diff] [blame] | 2238 | AppOpsManager.MODE_ERRORED, // READ_DEVICE_IDENTIFIERS |
Philip P. Moltmann | 89b044f | 2019-09-13 15:12:34 -0700 | [diff] [blame] | 2239 | AppOpsManager.MODE_ALLOWED, // ALLOW_MEDIA_LOCATION |
Patrick Baumann | 6c1c809 | 2019-06-27 14:55:44 -0700 | [diff] [blame] | 2240 | AppOpsManager.MODE_DEFAULT, // QUERY_ALL_PACKAGES |
Philip P. Moltmann | b43dfe3 | 2019-11-11 14:14:49 -0800 | [diff] [blame] | 2241 | AppOpsManager.MODE_DEFAULT, // MANAGE_EXTERNAL_STORAGE |
kholoud mohamed | 20ded1f | 2019-12-03 17:52:38 +0000 | [diff] [blame] | 2242 | AppOpsManager.MODE_DEFAULT, // INTERACT_ACROSS_PROFILES |
Benedict Wong | 3eb9520 | 2019-11-05 12:50:59 -0800 | [diff] [blame] | 2243 | AppOpsManager.MODE_IGNORED, // ACTIVATE_PLATFORM_VPN |
Todd Kennedy | b0948d4 | 2020-01-27 15:20:07 -0800 | [diff] [blame] | 2244 | AppOpsManager.MODE_DEFAULT, // LOADER_USAGE_STATS |
Ricardo Correa | acdc827 | 2020-03-24 11:02:54 -0700 | [diff] [blame] | 2245 | AppOpsManager.MODE_IGNORED, // deprecated operation |
Eugene Susla | 5fc2d76 | 2020-03-04 13:53:10 -0800 | [diff] [blame] | 2246 | AppOpsManager.MODE_DEFAULT, // OP_AUTO_REVOKE_PERMISSIONS_IF_UNUSED |
Eugene Susla | 922cd08 | 2020-03-11 12:38:17 -0700 | [diff] [blame] | 2247 | AppOpsManager.MODE_ALLOWED, // OP_AUTO_REVOKE_MANAGED_BY_INSTALLER |
David Braun | f5d8319 | 2013-09-16 13:43:51 -0700 | [diff] [blame] | 2248 | }; |
| 2249 | |
Dianne Hackborn | 8828d3a | 2013-09-25 16:47:10 -0700 | [diff] [blame] | 2250 | /** |
| 2251 | * This specifies whether each option is allowed to be reset |
| 2252 | * when resetting all app preferences. Disable reset for |
| 2253 | * app ops that are under strong control of some part of the |
| 2254 | * system (such as OP_WRITE_SMS, which should be allowed only |
| 2255 | * for whichever app is selected as the current SMS app). |
| 2256 | */ |
| 2257 | private static boolean[] sOpDisableReset = new boolean[] { |
Eugene Susla | 9351985 | 2018-06-13 16:44:31 -0700 | [diff] [blame] | 2258 | false, // COARSE_LOCATION |
| 2259 | false, // FINE_LOCATION |
| 2260 | false, // GPS |
| 2261 | false, // VIBRATE |
| 2262 | false, // READ_CONTACTS |
| 2263 | false, // WRITE_CONTACTS |
| 2264 | false, // READ_CALL_LOG |
| 2265 | false, // WRITE_CALL_LOG |
| 2266 | false, // READ_CALENDAR |
| 2267 | false, // WRITE_CALENDAR |
| 2268 | false, // WIFI_SCAN |
| 2269 | false, // POST_NOTIFICATION |
| 2270 | false, // NEIGHBORING_CELLS |
| 2271 | false, // CALL_PHONE |
| 2272 | true, // READ_SMS |
| 2273 | true, // WRITE_SMS |
| 2274 | true, // RECEIVE_SMS |
| 2275 | false, // RECEIVE_EMERGENCY_BROADCAST |
| 2276 | false, // RECEIVE_MMS |
| 2277 | true, // RECEIVE_WAP_PUSH |
| 2278 | true, // SEND_SMS |
| 2279 | false, // READ_ICC_SMS |
| 2280 | false, // WRITE_ICC_SMS |
| 2281 | false, // WRITE_SETTINGS |
| 2282 | false, // SYSTEM_ALERT_WINDOW |
| 2283 | false, // ACCESS_NOTIFICATIONS |
| 2284 | false, // CAMERA |
| 2285 | false, // RECORD_AUDIO |
| 2286 | false, // PLAY_AUDIO |
| 2287 | false, // READ_CLIPBOARD |
| 2288 | false, // WRITE_CLIPBOARD |
| 2289 | false, // TAKE_MEDIA_BUTTONS |
| 2290 | false, // TAKE_AUDIO_FOCUS |
| 2291 | false, // AUDIO_MASTER_VOLUME |
| 2292 | false, // AUDIO_VOICE_VOLUME |
| 2293 | false, // AUDIO_RING_VOLUME |
| 2294 | false, // AUDIO_MEDIA_VOLUME |
| 2295 | false, // AUDIO_ALARM_VOLUME |
| 2296 | false, // AUDIO_NOTIFICATION_VOLUME |
| 2297 | false, // AUDIO_BLUETOOTH_VOLUME |
| 2298 | false, // WAKE_LOCK |
| 2299 | false, // MONITOR_LOCATION |
| 2300 | false, // MONITOR_HIGH_POWER_LOCATION |
| 2301 | false, // GET_USAGE_STATS |
| 2302 | false, // MUTE_MICROPHONE |
| 2303 | false, // TOAST_WINDOW |
| 2304 | false, // PROJECT_MEDIA |
| 2305 | false, // ACTIVATE_VPN |
| 2306 | false, // WRITE_WALLPAPER |
| 2307 | false, // ASSIST_STRUCTURE |
| 2308 | false, // ASSIST_SCREENSHOT |
| 2309 | false, // READ_PHONE_STATE |
| 2310 | false, // ADD_VOICEMAIL |
| 2311 | false, // USE_SIP |
| 2312 | false, // PROCESS_OUTGOING_CALLS |
| 2313 | false, // USE_FINGERPRINT |
| 2314 | false, // BODY_SENSORS |
| 2315 | true, // READ_CELL_BROADCASTS |
| 2316 | false, // MOCK_LOCATION |
| 2317 | false, // READ_EXTERNAL_STORAGE |
| 2318 | false, // WRITE_EXTERNAL_STORAGE |
| 2319 | false, // TURN_SCREEN_ON |
| 2320 | false, // GET_ACCOUNTS |
| 2321 | false, // RUN_IN_BACKGROUND |
| 2322 | false, // AUDIO_ACCESSIBILITY_VOLUME |
| 2323 | false, // READ_PHONE_NUMBERS |
| 2324 | false, // REQUEST_INSTALL_PACKAGES |
| 2325 | false, // PICTURE_IN_PICTURE |
| 2326 | false, // INSTANT_APP_START_FOREGROUND |
Eugene Susla | cae3d3e | 2017-01-31 11:08:11 -0800 | [diff] [blame] | 2327 | false, // ANSWER_PHONE_CALLS |
Eugene Susla | 9351985 | 2018-06-13 16:44:31 -0700 | [diff] [blame] | 2328 | false, // RUN_ANY_IN_BACKGROUND |
| 2329 | false, // CHANGE_WIFI_STATE |
| 2330 | false, // REQUEST_DELETE_PACKAGES |
| 2331 | false, // BIND_ACCESSIBILITY_SERVICE |
Tyler Gunn | 79bc1ec | 2018-01-22 15:17:54 -0800 | [diff] [blame] | 2332 | false, // ACCEPT_HANDOVER |
Nathan Harold | 1bb42067 | 2018-03-14 17:08:53 -0700 | [diff] [blame] | 2333 | false, // MANAGE_IPSEC_TUNNELS |
Dianne Hackborn | e9d9b4b | 2018-03-28 13:51:46 -0700 | [diff] [blame] | 2334 | false, // START_FOREGROUND |
Dianne Hackborn | e04f13d | 2018-05-02 12:51:52 -0700 | [diff] [blame] | 2335 | false, // BLUETOOTH_SCAN |
Kevin Chyn | b3c05aa | 2018-09-21 16:50:32 -0700 | [diff] [blame] | 2336 | false, // USE_BIOMETRIC |
Zimuzo | 6cbf9cc | 2018-10-05 12:05:58 +0100 | [diff] [blame] | 2337 | false, // ACTIVITY_RECOGNITION |
Hongming Jin | 228cd01 | 2018-11-09 14:47:50 -0800 | [diff] [blame] | 2338 | false, // SMS_FINANCIAL_TRANSACTIONS |
Jeff Sharkey | d2a1f0d | 2018-11-19 10:32:52 -0700 | [diff] [blame] | 2339 | false, // READ_MEDIA_AUDIO |
| 2340 | false, // WRITE_MEDIA_AUDIO |
| 2341 | false, // READ_MEDIA_VIDEO |
| 2342 | false, // WRITE_MEDIA_VIDEO |
| 2343 | false, // READ_MEDIA_IMAGES |
| 2344 | false, // WRITE_MEDIA_IMAGES |
Zim | c72c9d1 | 2019-11-27 15:49:33 +0000 | [diff] [blame] | 2345 | true, // LEGACY_STORAGE |
Jackal Guo | 8dc791e | 2019-01-14 10:26:42 +0800 | [diff] [blame] | 2346 | false, // ACCESS_ACCESSIBILITY |
Michael Groover | 656ef91 | 2019-04-09 17:09:57 -0700 | [diff] [blame] | 2347 | false, // READ_DEVICE_IDENTIFIERS |
Philip P. Moltmann | 89b044f | 2019-09-13 15:12:34 -0700 | [diff] [blame] | 2348 | false, // ACCESS_MEDIA_LOCATION |
Patrick Baumann | 6c1c809 | 2019-06-27 14:55:44 -0700 | [diff] [blame] | 2349 | false, // QUERY_ALL_PACKAGES |
Philip P. Moltmann | b43dfe3 | 2019-11-11 14:14:49 -0800 | [diff] [blame] | 2350 | false, // MANAGE_EXTERNAL_STORAGE |
kholoud mohamed | 20ded1f | 2019-12-03 17:52:38 +0000 | [diff] [blame] | 2351 | false, // INTERACT_ACROSS_PROFILES |
Benedict Wong | 3eb9520 | 2019-11-05 12:50:59 -0800 | [diff] [blame] | 2352 | false, // ACTIVATE_PLATFORM_VPN |
Todd Kennedy | b0948d4 | 2020-01-27 15:20:07 -0800 | [diff] [blame] | 2353 | false, // LOADER_USAGE_STATS |
Ricardo Correa | acdc827 | 2020-03-24 11:02:54 -0700 | [diff] [blame] | 2354 | false, // deprecated operation |
Eugene Susla | 5fc2d76 | 2020-03-04 13:53:10 -0800 | [diff] [blame] | 2355 | false, // AUTO_REVOKE_PERMISSIONS_IF_UNUSED |
Eugene Susla | 1d7a791 | 2020-03-14 09:16:29 -0700 | [diff] [blame] | 2356 | false, // AUTO_REVOKE_MANAGED_BY_INSTALLER |
Dianne Hackborn | 8828d3a | 2013-09-25 16:47:10 -0700 | [diff] [blame] | 2357 | }; |
| 2358 | |
Svet Ganov | fbf01f7 | 2015-04-28 18:39:06 -0700 | [diff] [blame] | 2359 | /** |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 2360 | * Mapping from an app op name to the app op code. |
Svet Ganov | fbf01f7 | 2015-04-28 18:39:06 -0700 | [diff] [blame] | 2361 | */ |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 2362 | private static HashMap<String, Integer> sOpStrToOp = new HashMap<>(); |
Svet Ganov | fbf01f7 | 2015-04-28 18:39:06 -0700 | [diff] [blame] | 2363 | |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 2364 | /** |
| 2365 | * Mapping from a permission to the corresponding app op. |
| 2366 | */ |
Svet Ganov | da0acdf | 2017-02-15 10:28:51 -0800 | [diff] [blame] | 2367 | private static HashMap<String, Integer> sPermToOp = new HashMap<>(); |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 2368 | |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 2369 | /** |
| 2370 | * Set to the uid of the caller if this thread is currently executing a two-way binder |
| 2371 | * transaction. Not set if this thread is currently not executing a two way binder transaction. |
| 2372 | * |
| 2373 | * @see #startNotedAppOpsCollection |
Philip P. Moltmann | da554e4 | 2019-12-20 11:21:02 -0800 | [diff] [blame] | 2374 | * @see #getNotedOpCollectionMode |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 2375 | */ |
| 2376 | private static final ThreadLocal<Integer> sBinderThreadCallingUid = new ThreadLocal<>(); |
| 2377 | |
| 2378 | /** |
| 2379 | * If a thread is currently executing a two-way binder transaction, this stores the op-codes of |
| 2380 | * the app-ops that were noted during this transaction. |
| 2381 | * |
Philip P. Moltmann | da554e4 | 2019-12-20 11:21:02 -0800 | [diff] [blame] | 2382 | * @see #getNotedOpCollectionMode |
| 2383 | * @see #collectNotedOpSync |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 2384 | */ |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 2385 | private static final ThreadLocal<ArrayMap<String, long[]>> sAppOpsNotedInThisBinderTransaction = |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 2386 | new ThreadLocal<>(); |
| 2387 | |
| 2388 | /** Whether noting for an appop should be collected */ |
| 2389 | private static final @ShouldCollectNoteOp byte[] sAppOpsToNote = new byte[_NUM_OP]; |
| 2390 | |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 2391 | static { |
| 2392 | if (sOpToSwitch.length != _NUM_OP) { |
Dianne Hackborn | 8828d3a | 2013-09-25 16:47:10 -0700 | [diff] [blame] | 2393 | throw new IllegalStateException("sOpToSwitch length " + sOpToSwitch.length |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 2394 | + " should be " + _NUM_OP); |
| 2395 | } |
| 2396 | if (sOpToString.length != _NUM_OP) { |
Dianne Hackborn | 8828d3a | 2013-09-25 16:47:10 -0700 | [diff] [blame] | 2397 | throw new IllegalStateException("sOpToString length " + sOpToString.length |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 2398 | + " should be " + _NUM_OP); |
| 2399 | } |
| 2400 | if (sOpNames.length != _NUM_OP) { |
Dianne Hackborn | 8828d3a | 2013-09-25 16:47:10 -0700 | [diff] [blame] | 2401 | throw new IllegalStateException("sOpNames length " + sOpNames.length |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 2402 | + " should be " + _NUM_OP); |
| 2403 | } |
| 2404 | if (sOpPerms.length != _NUM_OP) { |
Dianne Hackborn | 8828d3a | 2013-09-25 16:47:10 -0700 | [diff] [blame] | 2405 | throw new IllegalStateException("sOpPerms length " + sOpPerms.length |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 2406 | + " should be " + _NUM_OP); |
| 2407 | } |
| 2408 | if (sOpDefaultMode.length != _NUM_OP) { |
Dianne Hackborn | 8828d3a | 2013-09-25 16:47:10 -0700 | [diff] [blame] | 2409 | throw new IllegalStateException("sOpDefaultMode length " + sOpDefaultMode.length |
| 2410 | + " should be " + _NUM_OP); |
| 2411 | } |
| 2412 | if (sOpDisableReset.length != _NUM_OP) { |
| 2413 | throw new IllegalStateException("sOpDisableReset length " + sOpDisableReset.length |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 2414 | + " should be " + _NUM_OP); |
| 2415 | } |
Jason Monk | 6206299 | 2014-05-06 09:55:28 -0400 | [diff] [blame] | 2416 | if (sOpRestrictions.length != _NUM_OP) { |
| 2417 | throw new IllegalStateException("sOpRestrictions length " + sOpRestrictions.length |
| 2418 | + " should be " + _NUM_OP); |
| 2419 | } |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 2420 | if (sOpAllowSystemRestrictionBypass.length != _NUM_OP) { |
| 2421 | throw new IllegalStateException("sOpAllowSYstemRestrictionsBypass length " |
| 2422 | + sOpRestrictions.length + " should be " + _NUM_OP); |
| 2423 | } |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 2424 | for (int i=0; i<_NUM_OP; i++) { |
| 2425 | if (sOpToString[i] != null) { |
| 2426 | sOpStrToOp.put(sOpToString[i], i); |
| 2427 | } |
| 2428 | } |
Svet Ganov | da0acdf | 2017-02-15 10:28:51 -0800 | [diff] [blame] | 2429 | for (int op : RUNTIME_AND_APPOP_PERMISSIONS_OPS) { |
Svetoslav Ganov | eaca4c5 | 2016-05-05 18:08:00 -0700 | [diff] [blame] | 2430 | if (sOpPerms[op] != null) { |
Svet Ganov | da0acdf | 2017-02-15 10:28:51 -0800 | [diff] [blame] | 2431 | sPermToOp.put(sOpPerms[op], op); |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 2432 | } |
| 2433 | } |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 2434 | |
| 2435 | if ((_NUM_OP + Long.SIZE - 1) / Long.SIZE != 2) { |
| 2436 | // The code currently assumes that the length of sAppOpsNotedInThisBinderTransaction is |
| 2437 | // two longs |
| 2438 | throw new IllegalStateException("notedAppOps collection code assumes < 128 appops"); |
| 2439 | } |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 2440 | } |
| 2441 | |
Stanislav Zholnin | 90516b9 | 2020-01-20 14:03:06 +0000 | [diff] [blame] | 2442 | /** Config used to control app ops access messages sampling */ |
| 2443 | private static MessageSamplingConfig sConfig = |
| 2444 | new MessageSamplingConfig(OP_NONE, 0, 0); |
| 2445 | |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 2446 | /** @hide */ |
| 2447 | public static final String KEY_HISTORICAL_OPS = "historical_ops"; |
| 2448 | |
Chad Brubaker | 7c6dba6 | 2019-01-23 15:51:43 -0800 | [diff] [blame] | 2449 | /** System properties for debug logging of noteOp call sites */ |
| 2450 | private static final String DEBUG_LOGGING_ENABLE_PROP = "appops.logging_enabled"; |
| 2451 | private static final String DEBUG_LOGGING_PACKAGES_PROP = "appops.logging_packages"; |
| 2452 | private static final String DEBUG_LOGGING_OPS_PROP = "appops.logging_ops"; |
| 2453 | private static final String DEBUG_LOGGING_TAG = "AppOpsManager"; |
| 2454 | |
David Braun | f5d8319 | 2013-09-16 13:43:51 -0700 | [diff] [blame] | 2455 | /** |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 2456 | * Retrieve the op switch that controls the given operation. |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 2457 | * @hide |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 2458 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 2459 | @UnsupportedAppUsage |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 2460 | public static int opToSwitch(int op) { |
| 2461 | return sOpToSwitch[op]; |
| 2462 | } |
| 2463 | |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 2464 | /** |
| 2465 | * Retrieve a non-localized name for the operation, for debugging output. |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 2466 | * @hide |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 2467 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 2468 | @UnsupportedAppUsage |
Dianne Hackborn | 5e45ee6 | 2013-01-24 19:13:44 -0800 | [diff] [blame] | 2469 | public static String opToName(int op) { |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 2470 | if (op == OP_NONE) return "NONE"; |
Dianne Hackborn | 5e45ee6 | 2013-01-24 19:13:44 -0800 | [diff] [blame] | 2471 | return op < sOpNames.length ? sOpNames[op] : ("Unknown(" + op + ")"); |
| 2472 | } |
| 2473 | |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 2474 | /** |
Svet Ganov | 65f1b9e | 2019-01-17 19:19:40 -0800 | [diff] [blame] | 2475 | * Retrieve a non-localized public name for the operation. |
| 2476 | * |
| 2477 | * @hide |
| 2478 | */ |
| 2479 | public static @NonNull String opToPublicName(int op) { |
| 2480 | return sOpToString[op]; |
| 2481 | } |
| 2482 | |
| 2483 | /** |
Dianne Hackborn | 7b7c58b | 2014-12-02 18:32:20 -0800 | [diff] [blame] | 2484 | * @hide |
| 2485 | */ |
| 2486 | public static int strDebugOpToOp(String op) { |
| 2487 | for (int i=0; i<sOpNames.length; i++) { |
| 2488 | if (sOpNames[i].equals(op)) { |
| 2489 | return i; |
| 2490 | } |
| 2491 | } |
| 2492 | throw new IllegalArgumentException("Unknown operation string: " + op); |
| 2493 | } |
| 2494 | |
| 2495 | /** |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 2496 | * Retrieve the permission associated with an operation, or null if there is not one. |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 2497 | * @hide |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 2498 | */ |
Artur Satayev | f0b7d0b | 2019-11-04 11:16:45 +0000 | [diff] [blame] | 2499 | @UnsupportedAppUsage |
Philip P. Moltmann | 3311515 | 2018-04-11 13:39:36 -0700 | [diff] [blame] | 2500 | @TestApi |
Dianne Hackborn | 5e45ee6 | 2013-01-24 19:13:44 -0800 | [diff] [blame] | 2501 | public static String opToPermission(int op) { |
| 2502 | return sOpPerms[op]; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 2503 | } |
| 2504 | |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 2505 | /** |
Hai Zhang | b777668 | 2018-09-25 15:10:57 -0700 | [diff] [blame] | 2506 | * Retrieve the permission associated with an operation, or null if there is not one. |
| 2507 | * |
| 2508 | * @param op The operation name. |
| 2509 | * |
| 2510 | * @hide |
| 2511 | */ |
| 2512 | @Nullable |
| 2513 | @SystemApi |
| 2514 | public static String opToPermission(@NonNull String op) { |
| 2515 | return opToPermission(strOpToOp(op)); |
| 2516 | } |
| 2517 | |
| 2518 | /** |
Jason Monk | 6206299 | 2014-05-06 09:55:28 -0400 | [diff] [blame] | 2519 | * Retrieve the user restriction associated with an operation, or null if there is not one. |
| 2520 | * @hide |
| 2521 | */ |
| 2522 | public static String opToRestriction(int op) { |
| 2523 | return sOpRestrictions[op]; |
| 2524 | } |
| 2525 | |
| 2526 | /** |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 2527 | * Retrieve the app op code for a permission, or null if there is not one. |
Svet Ganov | da0acdf | 2017-02-15 10:28:51 -0800 | [diff] [blame] | 2528 | * This API is intended to be used for mapping runtime or appop permissions |
| 2529 | * to the corresponding app op. |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 2530 | * @hide |
| 2531 | */ |
Artur Satayev | f0b7d0b | 2019-11-04 11:16:45 +0000 | [diff] [blame] | 2532 | @UnsupportedAppUsage |
Philip P. Moltmann | 3311515 | 2018-04-11 13:39:36 -0700 | [diff] [blame] | 2533 | @TestApi |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 2534 | public static int permissionToOpCode(String permission) { |
Svet Ganov | da0acdf | 2017-02-15 10:28:51 -0800 | [diff] [blame] | 2535 | Integer boxedOpCode = sPermToOp.get(permission); |
Svet Ganov | 019d230 | 2015-05-04 11:07:38 -0700 | [diff] [blame] | 2536 | return boxedOpCode != null ? boxedOpCode : OP_NONE; |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 2537 | } |
| 2538 | |
| 2539 | /** |
Philip P. Moltmann | ad787aa | 2020-03-10 09:49:22 -0700 | [diff] [blame] | 2540 | * Retrieve whether the op allows to bypass the user restriction. |
| 2541 | * |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 2542 | * @hide |
| 2543 | */ |
Philip P. Moltmann | ad787aa | 2020-03-10 09:49:22 -0700 | [diff] [blame] | 2544 | public static RestrictionBypass opAllowSystemBypassRestriction(int op) { |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 2545 | return sOpAllowSystemRestrictionBypass[op]; |
| 2546 | } |
| 2547 | |
| 2548 | /** |
David Braun | f5d8319 | 2013-09-16 13:43:51 -0700 | [diff] [blame] | 2549 | * Retrieve the default mode for the operation. |
| 2550 | * @hide |
| 2551 | */ |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 2552 | public static @Mode int opToDefaultMode(int op) { |
David Braun | f5d8319 | 2013-09-16 13:43:51 -0700 | [diff] [blame] | 2553 | return sOpDefaultMode[op]; |
| 2554 | } |
| 2555 | |
| 2556 | /** |
Hai Zhang | c595f11 | 2018-11-06 14:20:38 -0800 | [diff] [blame] | 2557 | * Retrieve the default mode for the app op. |
| 2558 | * |
| 2559 | * @param appOp The app op name |
| 2560 | * |
| 2561 | * @return the default mode for the app op |
| 2562 | * |
| 2563 | * @hide |
| 2564 | */ |
Svet Ganov | 8e5bf96 | 2019-03-19 23:59:03 -0700 | [diff] [blame] | 2565 | @TestApi |
Hai Zhang | c595f11 | 2018-11-06 14:20:38 -0800 | [diff] [blame] | 2566 | @SystemApi |
| 2567 | public static int opToDefaultMode(@NonNull String appOp) { |
| 2568 | return opToDefaultMode(strOpToOp(appOp)); |
| 2569 | } |
| 2570 | |
| 2571 | /** |
Svet Ganov | 82f09bc | 2018-01-12 22:08:40 -0800 | [diff] [blame] | 2572 | * Retrieve the human readable mode. |
| 2573 | * @hide |
| 2574 | */ |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 2575 | public static String modeToName(@Mode int mode) { |
Dianne Hackborn | c216a26 | 2018-04-26 13:46:22 -0700 | [diff] [blame] | 2576 | if (mode >= 0 && mode < MODE_NAMES.length) { |
| 2577 | return MODE_NAMES[mode]; |
Svet Ganov | 82f09bc | 2018-01-12 22:08:40 -0800 | [diff] [blame] | 2578 | } |
Dianne Hackborn | c216a26 | 2018-04-26 13:46:22 -0700 | [diff] [blame] | 2579 | return "mode=" + mode; |
Svet Ganov | 82f09bc | 2018-01-12 22:08:40 -0800 | [diff] [blame] | 2580 | } |
| 2581 | |
| 2582 | /** |
Dianne Hackborn | 8828d3a | 2013-09-25 16:47:10 -0700 | [diff] [blame] | 2583 | * Retrieve whether the op allows itself to be reset. |
| 2584 | * @hide |
| 2585 | */ |
| 2586 | public static boolean opAllowsReset(int op) { |
| 2587 | return !sOpDisableReset[op]; |
| 2588 | } |
| 2589 | |
| 2590 | /** |
Soonil Nagarkar | 4523f96 | 2020-04-14 19:04:41 -0700 | [diff] [blame] | 2591 | * Returns a listenerId suitable for use with {@link #noteOp(int, int, String, String, String)}. |
| 2592 | * |
| 2593 | * This is intended for use client side, when the receiver id must be created before the |
| 2594 | * associated call is made to the system server. If using {@link PendingIntent} as the receiver, |
| 2595 | * avoid using this method as it will include a pointless additional x-process call. Instead to |
| 2596 | * prefer passing the PendingIntent to the system server, and then invoking |
| 2597 | * {@link #toReceiverId(PendingIntent)} instead. |
| 2598 | * |
| 2599 | * @param obj the receiver in use |
| 2600 | * @return a string representation of the receiver suitable for app ops use |
| 2601 | * @hide |
| 2602 | */ |
| 2603 | // TODO: this should probably be @SystemApi as well |
| 2604 | public static @NonNull String toReceiverId(@NonNull Object obj) { |
| 2605 | if (obj instanceof PendingIntent) { |
| 2606 | return toReceiverId((PendingIntent) obj); |
| 2607 | } else { |
| 2608 | return obj.getClass().getName() + "@" + System.identityHashCode(obj); |
| 2609 | } |
| 2610 | } |
| 2611 | |
| 2612 | /** |
| 2613 | * Returns a listenerId suitable for use with {@link #noteOp(int, int, String, String, String)}. |
| 2614 | * |
| 2615 | * This is intended for use server side, where ActivityManagerService can be referenced without |
| 2616 | * an additional x-process call. |
| 2617 | * |
| 2618 | * @param pendingIntent the pendingIntent in use |
| 2619 | * @return a string representation of the pending intent suitable for app ops use |
| 2620 | * @see #toReceiverId(Object) |
| 2621 | * @hide |
| 2622 | */ |
| 2623 | // TODO: this should probably be @SystemApi as well |
| 2624 | public static @NonNull String toReceiverId(@NonNull PendingIntent pendingIntent) { |
| 2625 | return pendingIntent.getTag(""); |
| 2626 | } |
| 2627 | |
| 2628 | /** |
Philip P. Moltmann | ad787aa | 2020-03-10 09:49:22 -0700 | [diff] [blame] | 2629 | * When to not enforce {@link #setUserRestriction restrictions}. |
| 2630 | * |
| 2631 | * @hide |
| 2632 | */ |
| 2633 | public static class RestrictionBypass { |
| 2634 | /** Does the app need to be privileged to bypass the restriction */ |
| 2635 | public boolean isPrivileged; |
| 2636 | |
| 2637 | /** |
| 2638 | * Does the app need to have the EXEMPT_FROM_AUDIO_RESTRICTIONS permission to bypass the |
| 2639 | * restriction |
| 2640 | */ |
| 2641 | public boolean isRecordAudioRestrictionExcept; |
| 2642 | |
| 2643 | public RestrictionBypass(boolean isPrivileged, boolean isRecordAudioRestrictionExcept) { |
| 2644 | this.isPrivileged = isPrivileged; |
| 2645 | this.isRecordAudioRestrictionExcept = isRecordAudioRestrictionExcept; |
| 2646 | } |
| 2647 | |
| 2648 | public static RestrictionBypass UNRESTRICTED = new RestrictionBypass(true, true); |
| 2649 | } |
| 2650 | |
| 2651 | /** |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 2652 | * Class holding all of the operation information associated with an app. |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 2653 | * @hide |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 2654 | */ |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 2655 | @TestApi |
Dianne Hackborn | f0c322a | 2018-06-13 15:24:04 -0700 | [diff] [blame] | 2656 | @SystemApi |
| 2657 | public static final class PackageOps implements Parcelable { |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 2658 | private final String mPackageName; |
| 2659 | private final int mUid; |
| 2660 | private final List<OpEntry> mEntries; |
| 2661 | |
Dianne Hackborn | f0c322a | 2018-06-13 15:24:04 -0700 | [diff] [blame] | 2662 | /** |
| 2663 | * @hide |
| 2664 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 2665 | @UnsupportedAppUsage |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 2666 | public PackageOps(String packageName, int uid, List<OpEntry> entries) { |
| 2667 | mPackageName = packageName; |
| 2668 | mUid = uid; |
| 2669 | mEntries = entries; |
| 2670 | } |
| 2671 | |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 2672 | /** |
| 2673 | * @return The name of the package. |
| 2674 | */ |
| 2675 | public @NonNull String getPackageName() { |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 2676 | return mPackageName; |
| 2677 | } |
| 2678 | |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 2679 | /** |
| 2680 | * @return The uid of the package. |
| 2681 | */ |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 2682 | public int getUid() { |
| 2683 | return mUid; |
| 2684 | } |
| 2685 | |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 2686 | /** |
| 2687 | * @return The ops of the package. |
| 2688 | */ |
Dianne Hackborn | 6287849 | 2019-03-11 15:57:07 -0700 | [diff] [blame] | 2689 | public @NonNull List<OpEntry> getOps() { |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 2690 | return mEntries; |
| 2691 | } |
| 2692 | |
| 2693 | @Override |
| 2694 | public int describeContents() { |
| 2695 | return 0; |
| 2696 | } |
| 2697 | |
| 2698 | @Override |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 2699 | public void writeToParcel(@NonNull Parcel dest, int flags) { |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 2700 | dest.writeString(mPackageName); |
| 2701 | dest.writeInt(mUid); |
| 2702 | dest.writeInt(mEntries.size()); |
| 2703 | for (int i=0; i<mEntries.size(); i++) { |
| 2704 | mEntries.get(i).writeToParcel(dest, flags); |
| 2705 | } |
| 2706 | } |
| 2707 | |
| 2708 | PackageOps(Parcel source) { |
| 2709 | mPackageName = source.readString(); |
| 2710 | mUid = source.readInt(); |
| 2711 | mEntries = new ArrayList<OpEntry>(); |
| 2712 | final int N = source.readInt(); |
| 2713 | for (int i=0; i<N; i++) { |
| 2714 | mEntries.add(OpEntry.CREATOR.createFromParcel(source)); |
| 2715 | } |
| 2716 | } |
| 2717 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 2718 | public static final @android.annotation.NonNull Creator<PackageOps> CREATOR = new Creator<PackageOps>() { |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 2719 | @Override public PackageOps createFromParcel(Parcel source) { |
| 2720 | return new PackageOps(source); |
| 2721 | } |
| 2722 | |
| 2723 | @Override public PackageOps[] newArray(int size) { |
| 2724 | return new PackageOps[size]; |
| 2725 | } |
| 2726 | }; |
| 2727 | } |
| 2728 | |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 2729 | /** |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 2730 | * Proxy information for a {@link #noteOp} event |
| 2731 | * |
| 2732 | * @hide |
| 2733 | */ |
| 2734 | @TestApi |
| 2735 | @SystemApi |
Philip P. Moltmann | d8c0bda | 2019-12-19 19:55:35 -0800 | [diff] [blame] | 2736 | // @DataClass(genHiddenConstructor = true, genHiddenCopyConstructor = true) |
| 2737 | // genHiddenCopyConstructor does not work for @hide @SystemApi classes |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 2738 | public static final class OpEventProxyInfo implements Parcelable { |
| 2739 | /** UID of the proxy app that noted the op */ |
Philip P. Moltmann | d8c0bda | 2019-12-19 19:55:35 -0800 | [diff] [blame] | 2740 | private @IntRange(from = 0) int mUid; |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 2741 | /** Package of the proxy that noted the op */ |
Philip P. Moltmann | d8c0bda | 2019-12-19 19:55:35 -0800 | [diff] [blame] | 2742 | private @Nullable String mPackageName; |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 2743 | /** Attribution tag of the proxy that noted the op */ |
| 2744 | private @Nullable String mAttributionTag; |
Philip P. Moltmann | d8c0bda | 2019-12-19 19:55:35 -0800 | [diff] [blame] | 2745 | |
| 2746 | /** |
| 2747 | * Reinit existing object with new state. |
| 2748 | * |
| 2749 | * @param uid UID of the proxy app that noted the op |
| 2750 | * @param packageName Package of the proxy that noted the op |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 2751 | * @param attributionTag attribution tag of the proxy that noted the op |
Philip P. Moltmann | d8c0bda | 2019-12-19 19:55:35 -0800 | [diff] [blame] | 2752 | * |
| 2753 | * @hide |
| 2754 | */ |
| 2755 | public void reinit(@IntRange(from = 0) int uid, @Nullable String packageName, |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 2756 | @Nullable String attributionTag) { |
Philip P. Moltmann | d8c0bda | 2019-12-19 19:55:35 -0800 | [diff] [blame] | 2757 | mUid = Preconditions.checkArgumentNonnegative(uid); |
| 2758 | mPackageName = packageName; |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 2759 | mAttributionTag = attributionTag; |
Philip P. Moltmann | d8c0bda | 2019-12-19 19:55:35 -0800 | [diff] [blame] | 2760 | } |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 2761 | |
| 2762 | |
| 2763 | |
| 2764 | // Code below generated by codegen v1.0.14. |
| 2765 | // |
| 2766 | // DO NOT MODIFY! |
| 2767 | // CHECKSTYLE:OFF Generated code |
| 2768 | // |
| 2769 | // To regenerate run: |
| 2770 | // $ codegen $ANDROID_BUILD_TOP/frameworks/base/core/java/android/app/AppOpsManager.java |
| 2771 | // |
| 2772 | // To exclude the generated code from IntelliJ auto-formatting enable (one-time): |
| 2773 | // Settings > Editor > Code Style > Formatter Control |
| 2774 | //@formatter:off |
| 2775 | |
| 2776 | |
| 2777 | /** |
| 2778 | * Creates a new OpEventProxyInfo. |
| 2779 | * |
| 2780 | * @param uid |
| 2781 | * UID of the proxy app that noted the op |
| 2782 | * @param packageName |
| 2783 | * Package of the proxy that noted the op |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 2784 | * @param attributionTag |
| 2785 | * Attribution tag of the proxy that noted the op |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 2786 | * @hide |
| 2787 | */ |
| 2788 | @DataClass.Generated.Member |
| 2789 | public OpEventProxyInfo( |
| 2790 | @IntRange(from = 0) int uid, |
| 2791 | @Nullable String packageName, |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 2792 | @Nullable String attributionTag) { |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 2793 | this.mUid = uid; |
| 2794 | com.android.internal.util.AnnotationValidations.validate( |
| 2795 | IntRange.class, null, mUid, |
| 2796 | "from", 0); |
| 2797 | this.mPackageName = packageName; |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 2798 | this.mAttributionTag = attributionTag; |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 2799 | |
| 2800 | // onConstructed(); // You can define this method to get a callback |
| 2801 | } |
| 2802 | |
| 2803 | /** |
Philip P. Moltmann | d8c0bda | 2019-12-19 19:55:35 -0800 | [diff] [blame] | 2804 | * Copy constructor |
| 2805 | * |
| 2806 | * @hide |
| 2807 | */ |
| 2808 | @DataClass.Generated.Member |
| 2809 | public OpEventProxyInfo(@NonNull OpEventProxyInfo orig) { |
| 2810 | mUid = orig.mUid; |
| 2811 | mPackageName = orig.mPackageName; |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 2812 | mAttributionTag = orig.mAttributionTag; |
Philip P. Moltmann | d8c0bda | 2019-12-19 19:55:35 -0800 | [diff] [blame] | 2813 | } |
| 2814 | |
| 2815 | /** |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 2816 | * UID of the proxy app that noted the op |
| 2817 | */ |
| 2818 | @DataClass.Generated.Member |
| 2819 | public @IntRange(from = 0) int getUid() { |
| 2820 | return mUid; |
| 2821 | } |
| 2822 | |
| 2823 | /** |
| 2824 | * Package of the proxy that noted the op |
| 2825 | */ |
| 2826 | @DataClass.Generated.Member |
| 2827 | public @Nullable String getPackageName() { |
| 2828 | return mPackageName; |
| 2829 | } |
| 2830 | |
| 2831 | /** |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 2832 | * Attribution tag of the proxy that noted the op |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 2833 | */ |
| 2834 | @DataClass.Generated.Member |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 2835 | public @Nullable String getAttributionTag() { |
| 2836 | return mAttributionTag; |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 2837 | } |
| 2838 | |
| 2839 | @Override |
| 2840 | @DataClass.Generated.Member |
| 2841 | public void writeToParcel(@NonNull Parcel dest, int flags) { |
| 2842 | // You can override field parcelling by defining methods like: |
| 2843 | // void parcelFieldName(Parcel dest, int flags) { ... } |
| 2844 | |
| 2845 | byte flg = 0; |
| 2846 | if (mPackageName != null) flg |= 0x2; |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 2847 | if (mAttributionTag != null) flg |= 0x4; |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 2848 | dest.writeByte(flg); |
| 2849 | dest.writeInt(mUid); |
| 2850 | if (mPackageName != null) dest.writeString(mPackageName); |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 2851 | if (mAttributionTag != null) dest.writeString(mAttributionTag); |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 2852 | } |
| 2853 | |
| 2854 | @Override |
| 2855 | @DataClass.Generated.Member |
| 2856 | public int describeContents() { return 0; } |
| 2857 | |
| 2858 | /** @hide */ |
| 2859 | @SuppressWarnings({"unchecked", "RedundantCast"}) |
| 2860 | @DataClass.Generated.Member |
| 2861 | /* package-private */ OpEventProxyInfo(@NonNull Parcel in) { |
| 2862 | // You can override field unparcelling by defining methods like: |
| 2863 | // static FieldType unparcelFieldName(Parcel in) { ... } |
| 2864 | |
| 2865 | byte flg = in.readByte(); |
| 2866 | int uid = in.readInt(); |
| 2867 | String packageName = (flg & 0x2) == 0 ? null : in.readString(); |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 2868 | String attributionTag = (flg & 0x4) == 0 ? null : in.readString(); |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 2869 | |
| 2870 | this.mUid = uid; |
| 2871 | com.android.internal.util.AnnotationValidations.validate( |
| 2872 | IntRange.class, null, mUid, |
| 2873 | "from", 0); |
| 2874 | this.mPackageName = packageName; |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 2875 | this.mAttributionTag = attributionTag; |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 2876 | |
| 2877 | // onConstructed(); // You can define this method to get a callback |
| 2878 | } |
| 2879 | |
| 2880 | @DataClass.Generated.Member |
| 2881 | public static final @NonNull Parcelable.Creator<OpEventProxyInfo> CREATOR |
| 2882 | = new Parcelable.Creator<OpEventProxyInfo>() { |
| 2883 | @Override |
| 2884 | public OpEventProxyInfo[] newArray(int size) { |
| 2885 | return new OpEventProxyInfo[size]; |
| 2886 | } |
| 2887 | |
| 2888 | @Override |
| 2889 | public OpEventProxyInfo createFromParcel(@NonNull Parcel in) { |
| 2890 | return new OpEventProxyInfo(in); |
| 2891 | } |
| 2892 | }; |
| 2893 | |
Philip P. Moltmann | d8c0bda | 2019-12-19 19:55:35 -0800 | [diff] [blame] | 2894 | /* |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 2895 | @DataClass.Generated( |
Philip P. Moltmann | d8c0bda | 2019-12-19 19:55:35 -0800 | [diff] [blame] | 2896 | time = 1576814974615L, |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 2897 | codegenVersion = "1.0.14", |
| 2898 | sourceFile = "frameworks/base/core/java/android/app/AppOpsManager.java", |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 2899 | inputSignatures = "private @android.annotation.IntRange(from=0L) int mUid\nprivate @android.annotation.Nullable java.lang.String mPackageName\nprivate @android.annotation.Nullable java.lang.String mAttributionTag\npublic void reinit(int,java.lang.String,java.lang.String)\nclass OpEventProxyInfo extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genHiddenConstructor=true, genHiddenCopyConstructor=true)") |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 2900 | @Deprecated |
| 2901 | private void __metadata() {} |
Philip P. Moltmann | d8c0bda | 2019-12-19 19:55:35 -0800 | [diff] [blame] | 2902 | */ |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 2903 | |
| 2904 | //@formatter:on |
| 2905 | // End of generated code |
| 2906 | |
| 2907 | } |
| 2908 | |
| 2909 | /** |
| 2910 | * Description of a {@link #noteOp} or {@link #startOp} event |
| 2911 | * |
| 2912 | * @hide |
| 2913 | */ |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 2914 | //@DataClass codegen verifier is broken |
| 2915 | public static final class NoteOpEvent implements Parcelable { |
| 2916 | /** Time of noteOp event */ |
Philip P. Moltmann | d8c0bda | 2019-12-19 19:55:35 -0800 | [diff] [blame] | 2917 | private @IntRange(from = 0) long mNoteTime; |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 2918 | /** The duration of this event (in case this is a startOp event, -1 otherwise). */ |
Philip P. Moltmann | d8c0bda | 2019-12-19 19:55:35 -0800 | [diff] [blame] | 2919 | private @IntRange(from = -1) long mDuration; |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 2920 | /** Proxy information of the noteOp event */ |
Philip P. Moltmann | d8c0bda | 2019-12-19 19:55:35 -0800 | [diff] [blame] | 2921 | private @Nullable OpEventProxyInfo mProxy; |
| 2922 | |
| 2923 | /** |
| 2924 | * Reinit existing object with new state. |
| 2925 | * |
| 2926 | * @param noteTime Time of noteOp event |
| 2927 | * @param duration The duration of this event (in case this is a startOp event, |
| 2928 | * -1 otherwise). |
| 2929 | * @param proxy Proxy information of the noteOp event |
| 2930 | * @param proxyPool The pool to release previous {@link OpEventProxyInfo} to |
| 2931 | */ |
| 2932 | public void reinit(@IntRange(from = 0) long noteTime, |
| 2933 | @IntRange(from = -1) long duration, |
| 2934 | @Nullable OpEventProxyInfo proxy, |
| 2935 | @NonNull Pools.Pool<OpEventProxyInfo> proxyPool) { |
| 2936 | mNoteTime = Preconditions.checkArgumentNonnegative(noteTime); |
| 2937 | mDuration = Preconditions.checkArgumentInRange(duration, -1L, Long.MAX_VALUE, |
| 2938 | "duration"); |
| 2939 | |
| 2940 | if (mProxy != null) { |
| 2941 | proxyPool.release(mProxy); |
| 2942 | } |
| 2943 | mProxy = proxy; |
| 2944 | } |
| 2945 | |
| 2946 | /** |
| 2947 | * Copy constructor |
| 2948 | * |
| 2949 | * @hide |
| 2950 | */ |
| 2951 | public NoteOpEvent(@NonNull NoteOpEvent original) { |
| 2952 | this(original.mNoteTime, original.mDuration, |
| 2953 | original.mProxy != null ? new OpEventProxyInfo(original.mProxy) : null); |
| 2954 | } |
| 2955 | |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 2956 | |
| 2957 | |
| 2958 | // Code below generated by codegen v1.0.14. |
| 2959 | // |
| 2960 | // DO NOT MODIFY! |
| 2961 | // CHECKSTYLE:OFF Generated code |
| 2962 | // |
| 2963 | // To regenerate run: |
| 2964 | // $ codegen $ANDROID_BUILD_TOP/frameworks/base/core/java/android/app/AppOpsManager.java |
| 2965 | // |
| 2966 | // To exclude the generated code from IntelliJ auto-formatting enable (one-time): |
| 2967 | // Settings > Editor > Code Style > Formatter Control |
| 2968 | //@formatter:off |
| 2969 | |
| 2970 | |
| 2971 | /** |
| 2972 | * Creates a new NoteOpEvent. |
| 2973 | * |
| 2974 | * @param noteTime |
| 2975 | * Time of noteOp event |
| 2976 | * @param duration |
| 2977 | * The duration of this event (in case this is a startOp event, -1 otherwise). |
| 2978 | * @param proxy |
| 2979 | * Proxy information of the noteOp event |
| 2980 | */ |
| 2981 | @DataClass.Generated.Member |
| 2982 | public NoteOpEvent( |
| 2983 | @IntRange(from = 0) long noteTime, |
| 2984 | @IntRange(from = -1) long duration, |
| 2985 | @Nullable OpEventProxyInfo proxy) { |
Philip P. Moltmann | d8c0bda | 2019-12-19 19:55:35 -0800 | [diff] [blame] | 2986 | this.mNoteTime = noteTime; |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 2987 | com.android.internal.util.AnnotationValidations.validate( |
Philip P. Moltmann | d8c0bda | 2019-12-19 19:55:35 -0800 | [diff] [blame] | 2988 | IntRange.class, null, mNoteTime, |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 2989 | "from", 0); |
Philip P. Moltmann | d8c0bda | 2019-12-19 19:55:35 -0800 | [diff] [blame] | 2990 | this.mDuration = duration; |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 2991 | com.android.internal.util.AnnotationValidations.validate( |
Philip P. Moltmann | d8c0bda | 2019-12-19 19:55:35 -0800 | [diff] [blame] | 2992 | IntRange.class, null, mDuration, |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 2993 | "from", -1); |
Philip P. Moltmann | d8c0bda | 2019-12-19 19:55:35 -0800 | [diff] [blame] | 2994 | this.mProxy = proxy; |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 2995 | |
| 2996 | // onConstructed(); // You can define this method to get a callback |
| 2997 | } |
| 2998 | |
Philip P. Moltmann | d8c0bda | 2019-12-19 19:55:35 -0800 | [diff] [blame] | 2999 | /** |
| 3000 | * Time of noteOp event |
| 3001 | */ |
| 3002 | @DataClass.Generated.Member |
| 3003 | public @IntRange(from = 0) long getNoteTime() { |
| 3004 | return mNoteTime; |
| 3005 | } |
| 3006 | |
| 3007 | /** |
| 3008 | * The duration of this event (in case this is a startOp event, -1 otherwise). |
| 3009 | */ |
| 3010 | @DataClass.Generated.Member |
| 3011 | public @IntRange(from = -1) long getDuration() { |
| 3012 | return mDuration; |
| 3013 | } |
| 3014 | |
| 3015 | /** |
| 3016 | * Proxy information of the noteOp event |
| 3017 | */ |
| 3018 | @DataClass.Generated.Member |
| 3019 | public @Nullable OpEventProxyInfo getProxy() { |
| 3020 | return mProxy; |
| 3021 | } |
| 3022 | |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3023 | @Override |
| 3024 | @DataClass.Generated.Member |
| 3025 | public void writeToParcel(@NonNull Parcel dest, int flags) { |
| 3026 | // You can override field parcelling by defining methods like: |
| 3027 | // void parcelFieldName(Parcel dest, int flags) { ... } |
| 3028 | |
| 3029 | byte flg = 0; |
Philip P. Moltmann | d8c0bda | 2019-12-19 19:55:35 -0800 | [diff] [blame] | 3030 | if (mProxy != null) flg |= 0x4; |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3031 | dest.writeByte(flg); |
Philip P. Moltmann | d8c0bda | 2019-12-19 19:55:35 -0800 | [diff] [blame] | 3032 | dest.writeLong(mNoteTime); |
| 3033 | dest.writeLong(mDuration); |
| 3034 | if (mProxy != null) dest.writeTypedObject(mProxy, flags); |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3035 | } |
| 3036 | |
| 3037 | @Override |
| 3038 | @DataClass.Generated.Member |
| 3039 | public int describeContents() { return 0; } |
| 3040 | |
| 3041 | /** @hide */ |
| 3042 | @SuppressWarnings({"unchecked", "RedundantCast"}) |
| 3043 | @DataClass.Generated.Member |
| 3044 | /* package-private */ NoteOpEvent(@NonNull Parcel in) { |
| 3045 | // You can override field unparcelling by defining methods like: |
| 3046 | // static FieldType unparcelFieldName(Parcel in) { ... } |
| 3047 | |
| 3048 | byte flg = in.readByte(); |
Philip P. Moltmann | d8c0bda | 2019-12-19 19:55:35 -0800 | [diff] [blame] | 3049 | long noteTime = in.readLong(); |
| 3050 | long duration = in.readLong(); |
| 3051 | OpEventProxyInfo proxy = (flg & 0x4) == 0 ? null : (OpEventProxyInfo) in.readTypedObject(OpEventProxyInfo.CREATOR); |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3052 | |
Philip P. Moltmann | d8c0bda | 2019-12-19 19:55:35 -0800 | [diff] [blame] | 3053 | this.mNoteTime = noteTime; |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3054 | com.android.internal.util.AnnotationValidations.validate( |
Philip P. Moltmann | d8c0bda | 2019-12-19 19:55:35 -0800 | [diff] [blame] | 3055 | IntRange.class, null, mNoteTime, |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3056 | "from", 0); |
Philip P. Moltmann | d8c0bda | 2019-12-19 19:55:35 -0800 | [diff] [blame] | 3057 | this.mDuration = duration; |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3058 | com.android.internal.util.AnnotationValidations.validate( |
Philip P. Moltmann | d8c0bda | 2019-12-19 19:55:35 -0800 | [diff] [blame] | 3059 | IntRange.class, null, mDuration, |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3060 | "from", -1); |
Philip P. Moltmann | d8c0bda | 2019-12-19 19:55:35 -0800 | [diff] [blame] | 3061 | this.mProxy = proxy; |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3062 | |
| 3063 | // onConstructed(); // You can define this method to get a callback |
| 3064 | } |
| 3065 | |
| 3066 | @DataClass.Generated.Member |
| 3067 | public static final @NonNull Parcelable.Creator<NoteOpEvent> CREATOR |
| 3068 | = new Parcelable.Creator<NoteOpEvent>() { |
| 3069 | @Override |
| 3070 | public NoteOpEvent[] newArray(int size) { |
| 3071 | return new NoteOpEvent[size]; |
| 3072 | } |
| 3073 | |
| 3074 | @Override |
| 3075 | public NoteOpEvent createFromParcel(@NonNull Parcel in) { |
| 3076 | return new NoteOpEvent(in); |
| 3077 | } |
| 3078 | }; |
| 3079 | |
| 3080 | /* |
| 3081 | @DataClass.Generated( |
Philip P. Moltmann | d8c0bda | 2019-12-19 19:55:35 -0800 | [diff] [blame] | 3082 | time = 1576811792274L, |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3083 | codegenVersion = "1.0.14", |
| 3084 | sourceFile = "frameworks/base/core/java/android/app/AppOpsManager.java", |
Philip P. Moltmann | d8c0bda | 2019-12-19 19:55:35 -0800 | [diff] [blame] | 3085 | inputSignatures = "private @android.annotation.IntRange(from=0L) long mNoteTime\nprivate @android.annotation.IntRange(from=-1) long mDuration\nprivate @android.annotation.Nullable android.app.OpEventProxyInfo mProxy\npublic void reinit(long,long,android.app.OpEventProxyInfo,android.util.Pools.Pool<android.app.OpEventProxyInfo>)\npublic @java.lang.Override java.lang.Object clone()\nclass NoteOpEvent extends java.lang.Object implements [android.os.Parcelable, java.lang.Cloneable]\n@com.android.internal.util.DataClass") |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3086 | @Deprecated |
| 3087 | private void __metadata() {} |
| 3088 | */ |
| 3089 | |
| 3090 | |
| 3091 | //@formatter:on |
| 3092 | // End of generated code |
| 3093 | |
| 3094 | } |
| 3095 | |
| 3096 | /** |
| 3097 | * Last {@link #noteOp} and {@link #startOp} events performed for a single op and a specific |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 3098 | * {@link Context#createAttributionContext(String) attribution} for all uidModes and opFlags. |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3099 | * |
| 3100 | * @hide |
| 3101 | */ |
| 3102 | @TestApi |
| 3103 | @SystemApi |
| 3104 | @Immutable |
| 3105 | // @DataClass(genHiddenConstructor = true) codegen verifier is broken |
| 3106 | @DataClass.Suppress({"getAccessEvents", "getRejectEvents", "getOp"}) |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 3107 | public static final class AttributedOpEntry implements Parcelable { |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3108 | /** The code of the op */ |
| 3109 | private final @IntRange(from = 0, to = _NUM_OP - 1) int mOp; |
| 3110 | /** Whether the op is running */ |
| 3111 | private final boolean mRunning; |
| 3112 | /** The access events */ |
| 3113 | @DataClass.ParcelWith(LongSparseArrayParceling.class) |
| 3114 | private final @Nullable LongSparseArray<NoteOpEvent> mAccessEvents; |
| 3115 | /** The rejection events */ |
| 3116 | @DataClass.ParcelWith(LongSparseArrayParceling.class) |
| 3117 | private final @Nullable LongSparseArray<NoteOpEvent> mRejectEvents; |
| 3118 | |
| 3119 | /** |
| 3120 | * Returns all keys for which we have events. |
| 3121 | * |
| 3122 | * @hide |
| 3123 | */ |
| 3124 | public @NonNull ArraySet<Long> collectKeys() { |
| 3125 | ArraySet<Long> keys = new ArraySet<>(); |
| 3126 | |
| 3127 | if (mAccessEvents != null) { |
| 3128 | int numEvents = mAccessEvents.size(); |
| 3129 | for (int i = 0; i < numEvents; i++) { |
| 3130 | keys.add(mAccessEvents.keyAt(i)); |
| 3131 | } |
| 3132 | } |
| 3133 | |
| 3134 | if (mRejectEvents != null) { |
| 3135 | int numEvents = mRejectEvents.size(); |
| 3136 | for (int i = 0; i < numEvents; i++) { |
| 3137 | keys.add(mRejectEvents.keyAt(i)); |
| 3138 | } |
| 3139 | } |
| 3140 | |
| 3141 | return keys; |
| 3142 | } |
| 3143 | |
| 3144 | /** |
| 3145 | * Return the last access time. |
| 3146 | * |
| 3147 | * @param flags The op flags |
| 3148 | * |
| 3149 | * @return the last access time (in milliseconds since epoch start (January 1, 1970 |
Philip P. Moltmann | 7c0524f | 2020-02-06 09:21:31 -0800 | [diff] [blame] | 3150 | * 00:00:00.000 GMT - Gregorian)) or {@code -1} if there was no access |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3151 | * |
| 3152 | * @see #getLastAccessForegroundTime(int) |
| 3153 | * @see #getLastAccessBackgroundTime(int) |
| 3154 | * @see #getLastAccessTime(int, int, int) |
| 3155 | * @see OpEntry#getLastAccessTime(int) |
| 3156 | */ |
| 3157 | public long getLastAccessTime(@OpFlags int flags) { |
| 3158 | return getLastAccessTime(MAX_PRIORITY_UID_STATE, MIN_PRIORITY_UID_STATE, flags); |
| 3159 | } |
| 3160 | |
| 3161 | /** |
| 3162 | * Return the last foreground access time. |
| 3163 | * |
| 3164 | * @param flags The op flags |
| 3165 | * |
| 3166 | * @return the last access time (in milliseconds since epoch start (January 1, 1970 |
Philip P. Moltmann | 7c0524f | 2020-02-06 09:21:31 -0800 | [diff] [blame] | 3167 | * 00:00:00.000 GMT - Gregorian)) or {@code -1} if there was no foreground access |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3168 | * |
| 3169 | * @see #getLastAccessTime(int) |
| 3170 | * @see #getLastAccessBackgroundTime(int) |
| 3171 | * @see #getLastAccessTime(int, int, int) |
| 3172 | * @see OpEntry#getLastAccessForegroundTime(int) |
| 3173 | */ |
| 3174 | public long getLastAccessForegroundTime(@OpFlags int flags) { |
| 3175 | return getLastAccessTime(MAX_PRIORITY_UID_STATE, resolveFirstUnrestrictedUidState(mOp), |
| 3176 | flags); |
| 3177 | } |
| 3178 | |
| 3179 | /** |
| 3180 | * Return the last background access time. |
| 3181 | * |
| 3182 | * @param flags The op flags |
| 3183 | * |
| 3184 | * @return the last access time (in milliseconds since epoch start (January 1, 1970 |
Philip P. Moltmann | 7c0524f | 2020-02-06 09:21:31 -0800 | [diff] [blame] | 3185 | * 00:00:00.000 GMT - Gregorian)) or {@code -1} if there was no background access |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3186 | * |
| 3187 | * @see #getLastAccessTime(int) |
| 3188 | * @see #getLastAccessForegroundTime(int) |
| 3189 | * @see #getLastAccessTime(int, int, int) |
| 3190 | * @see OpEntry#getLastAccessBackgroundTime(int) |
| 3191 | */ |
| 3192 | public long getLastAccessBackgroundTime(@OpFlags int flags) { |
| 3193 | return getLastAccessTime(resolveLastRestrictedUidState(mOp), MIN_PRIORITY_UID_STATE, |
| 3194 | flags); |
| 3195 | } |
| 3196 | |
| 3197 | /** |
| 3198 | * Return the last access event. |
| 3199 | * |
| 3200 | * @param flags The op flags |
| 3201 | * |
Philip P. Moltmann | 7c0524f | 2020-02-06 09:21:31 -0800 | [diff] [blame] | 3202 | * @return the last access event of {@code null} if there was no access |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3203 | */ |
| 3204 | private @Nullable NoteOpEvent getLastAccessEvent(@UidState int fromUidState, |
| 3205 | @UidState int toUidState, @OpFlags int flags) { |
| 3206 | return getLastEvent(mAccessEvents, fromUidState, toUidState, flags); |
| 3207 | } |
| 3208 | |
| 3209 | /** |
| 3210 | * Return the last access time. |
| 3211 | * |
| 3212 | * @param fromUidState The lowest UID state for which to query |
| 3213 | * @param toUidState The highest UID state for which to query (inclusive) |
| 3214 | * @param flags The op flags |
| 3215 | * |
| 3216 | * @return the last access time (in milliseconds since epoch start (January 1, 1970 |
Philip P. Moltmann | 7c0524f | 2020-02-06 09:21:31 -0800 | [diff] [blame] | 3217 | * 00:00:00.000 GMT - Gregorian)) or {@code -1} if there was no access |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3218 | * |
| 3219 | * @see #getLastAccessTime(int) |
| 3220 | * @see #getLastAccessForegroundTime(int) |
| 3221 | * @see #getLastAccessBackgroundTime(int) |
| 3222 | * @see OpEntry#getLastAccessTime(int, int, int) |
| 3223 | */ |
| 3224 | public long getLastAccessTime(@UidState int fromUidState, @UidState int toUidState, |
| 3225 | @OpFlags int flags) { |
| 3226 | NoteOpEvent lastEvent = getLastAccessEvent(fromUidState, toUidState, flags); |
| 3227 | if (lastEvent == null) { |
| 3228 | return -1; |
| 3229 | } |
| 3230 | |
Philip P. Moltmann | d8c0bda | 2019-12-19 19:55:35 -0800 | [diff] [blame] | 3231 | return lastEvent.getNoteTime(); |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3232 | } |
| 3233 | |
| 3234 | /** |
| 3235 | * Return the last rejection time. |
| 3236 | * |
| 3237 | * @param flags The op flags |
| 3238 | * |
| 3239 | * @return the last rejection time (in milliseconds since epoch start (January 1, 1970 |
Philip P. Moltmann | 7c0524f | 2020-02-06 09:21:31 -0800 | [diff] [blame] | 3240 | * 00:00:00.000 GMT - Gregorian)) or {@code -1} if there was no rejection |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3241 | * |
| 3242 | * @see #getLastRejectForegroundTime(int) |
| 3243 | * @see #getLastRejectBackgroundTime(int) |
| 3244 | * @see #getLastRejectTime(int, int, int) |
| 3245 | * @see OpEntry#getLastRejectTime(int) |
| 3246 | */ |
| 3247 | public long getLastRejectTime(@OpFlags int flags) { |
| 3248 | return getLastRejectTime(MAX_PRIORITY_UID_STATE, MIN_PRIORITY_UID_STATE, flags); |
| 3249 | } |
| 3250 | |
| 3251 | /** |
| 3252 | * Return the last foreground rejection time. |
| 3253 | * |
| 3254 | * @param flags The op flags |
| 3255 | * |
| 3256 | * @return the last rejection time (in milliseconds since epoch start (January 1, 1970 |
Philip P. Moltmann | 7c0524f | 2020-02-06 09:21:31 -0800 | [diff] [blame] | 3257 | * 00:00:00.000 GMT - Gregorian)) or {@code -1} if there was no foreground rejection |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3258 | * |
| 3259 | * @see #getLastRejectTime(int) |
| 3260 | * @see #getLastRejectBackgroundTime(int) |
| 3261 | * @see #getLastRejectTime(int, int, int) |
| 3262 | * @see OpEntry#getLastRejectForegroundTime(int) |
| 3263 | */ |
| 3264 | public long getLastRejectForegroundTime(@OpFlags int flags) { |
| 3265 | return getLastRejectTime(MAX_PRIORITY_UID_STATE, resolveFirstUnrestrictedUidState(mOp), |
| 3266 | flags); |
| 3267 | } |
| 3268 | |
| 3269 | /** |
| 3270 | * Return the last background rejection time. |
| 3271 | * |
| 3272 | * @param flags The op flags |
| 3273 | * |
| 3274 | * @return the last rejection time (in milliseconds since epoch start (January 1, 1970 |
Philip P. Moltmann | 7c0524f | 2020-02-06 09:21:31 -0800 | [diff] [blame] | 3275 | * 00:00:00.000 GMT - Gregorian)) or {@code -1} if there was no background rejection |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3276 | * |
| 3277 | * @see #getLastRejectTime(int) |
| 3278 | * @see #getLastRejectForegroundTime(int) |
| 3279 | * @see #getLastRejectTime(int, int, int) |
| 3280 | * @see OpEntry#getLastRejectBackgroundTime(int) |
| 3281 | */ |
| 3282 | public long getLastRejectBackgroundTime(@OpFlags int flags) { |
| 3283 | return getLastRejectTime(resolveLastRestrictedUidState(mOp), MIN_PRIORITY_UID_STATE, |
| 3284 | flags); |
| 3285 | } |
| 3286 | |
| 3287 | /** |
| 3288 | * Return the last background rejection event. |
| 3289 | * |
| 3290 | * @param flags The op flags |
| 3291 | * |
Philip P. Moltmann | 7c0524f | 2020-02-06 09:21:31 -0800 | [diff] [blame] | 3292 | * @return the last rejection event of {@code null} if there was no rejection |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3293 | * |
| 3294 | * @see #getLastRejectTime(int) |
| 3295 | * @see #getLastRejectForegroundTime(int) |
| 3296 | * @see #getLastRejectBackgroundTime(int) |
| 3297 | * @see OpEntry#getLastRejectTime(int, int, int) |
| 3298 | */ |
| 3299 | private @Nullable NoteOpEvent getLastRejectEvent(@UidState int fromUidState, |
| 3300 | @UidState int toUidState, @OpFlags int flags) { |
| 3301 | return getLastEvent(mRejectEvents, fromUidState, toUidState, flags); |
| 3302 | } |
| 3303 | |
| 3304 | /** |
| 3305 | * Return the last rejection time. |
| 3306 | * |
| 3307 | * @param fromUidState The lowest UID state for which to query |
| 3308 | * @param toUidState The highest UID state for which to query (inclusive) |
| 3309 | * @param flags The op flags |
| 3310 | * |
Philip P. Moltmann | 7c0524f | 2020-02-06 09:21:31 -0800 | [diff] [blame] | 3311 | * @return the last access time (in milliseconds since epoch) or {@code -1} if there was no |
| 3312 | * rejection |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3313 | * |
| 3314 | * @see #getLastRejectTime(int) |
| 3315 | * @see #getLastRejectForegroundTime(int) |
| 3316 | * @see #getLastRejectForegroundTime(int) |
| 3317 | * @see #getLastRejectTime(int, int, int) |
| 3318 | * @see OpEntry#getLastRejectTime(int, int, int) |
| 3319 | */ |
| 3320 | public long getLastRejectTime(@UidState int fromUidState, @UidState int toUidState, |
| 3321 | @OpFlags int flags) { |
| 3322 | NoteOpEvent lastEvent = getLastRejectEvent(fromUidState, toUidState, flags); |
| 3323 | if (lastEvent == null) { |
| 3324 | return -1; |
| 3325 | } |
| 3326 | |
Philip P. Moltmann | d8c0bda | 2019-12-19 19:55:35 -0800 | [diff] [blame] | 3327 | return lastEvent.getNoteTime(); |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3328 | } |
| 3329 | |
| 3330 | /** |
| 3331 | * Return the duration in milliseconds of the last the access. |
| 3332 | * |
| 3333 | * @param flags The op flags |
| 3334 | * |
Philip P. Moltmann | 7c0524f | 2020-02-06 09:21:31 -0800 | [diff] [blame] | 3335 | * @return the duration in milliseconds or {@code -1} if there was no rejection |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3336 | * |
| 3337 | * @see #getLastForegroundDuration(int) |
| 3338 | * @see #getLastBackgroundDuration(int) |
| 3339 | * @see #getLastDuration(int, int, int) |
| 3340 | * @see OpEntry#getLastDuration(int) |
| 3341 | */ |
| 3342 | public long getLastDuration(@OpFlags int flags) { |
| 3343 | return getLastDuration(MAX_PRIORITY_UID_STATE, MIN_PRIORITY_UID_STATE, flags); |
| 3344 | } |
| 3345 | |
| 3346 | /** |
| 3347 | * Return the duration in milliseconds of the last foreground access. |
| 3348 | * |
| 3349 | * @param flags The op flags |
| 3350 | * |
Philip P. Moltmann | 7c0524f | 2020-02-06 09:21:31 -0800 | [diff] [blame] | 3351 | * @return the duration in milliseconds or {@code -1} if there was no foreground rejection |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3352 | * |
| 3353 | * @see #getLastDuration(int) |
| 3354 | * @see #getLastBackgroundDuration(int) |
| 3355 | * @see #getLastDuration(int, int, int) |
| 3356 | * @see OpEntry#getLastForegroundDuration(int) |
| 3357 | */ |
| 3358 | public long getLastForegroundDuration(@OpFlags int flags) { |
| 3359 | return getLastDuration(MAX_PRIORITY_UID_STATE, resolveFirstUnrestrictedUidState(mOp), |
| 3360 | flags); |
| 3361 | } |
| 3362 | |
| 3363 | /** |
| 3364 | * Return the duration in milliseconds of the last background access. |
| 3365 | * |
| 3366 | * @param flags The op flags |
| 3367 | * |
Philip P. Moltmann | 7c0524f | 2020-02-06 09:21:31 -0800 | [diff] [blame] | 3368 | * @return the duration in milliseconds or {@code -1} if there was no background rejection |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3369 | * |
| 3370 | * @see #getLastDuration(int) |
| 3371 | * @see #getLastForegroundDuration(int) |
| 3372 | * @see #getLastDuration(int, int, int) |
| 3373 | * @see OpEntry#getLastBackgroundDuration(int) |
| 3374 | */ |
| 3375 | public long getLastBackgroundDuration(@OpFlags int flags) { |
| 3376 | return getLastDuration(resolveLastRestrictedUidState(mOp), MIN_PRIORITY_UID_STATE, |
| 3377 | flags); |
| 3378 | } |
| 3379 | |
| 3380 | /** |
| 3381 | * Return the duration in milliseconds of the last access. |
| 3382 | * |
| 3383 | * @param fromUidState The lowest UID state for which to query |
| 3384 | * @param toUidState The highest UID state for which to query (inclusive) |
| 3385 | * @param flags The op flags |
| 3386 | * |
Philip P. Moltmann | 7c0524f | 2020-02-06 09:21:31 -0800 | [diff] [blame] | 3387 | * @return the duration in milliseconds or {@code -1} if there was no rejection |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3388 | * |
| 3389 | * @see #getLastDuration(int) |
| 3390 | * @see #getLastForegroundDuration(int) |
| 3391 | * @see #getLastBackgroundDuration(int) |
| 3392 | * @see #getLastDuration(int, int, int) |
| 3393 | * @see OpEntry#getLastDuration(int, int, int) |
| 3394 | */ |
| 3395 | public long getLastDuration(@UidState int fromUidState, @UidState int toUidState, |
| 3396 | @OpFlags int flags) { |
| 3397 | NoteOpEvent lastEvent = getLastAccessEvent(fromUidState, toUidState, flags);; |
| 3398 | if (lastEvent == null) { |
| 3399 | return -1; |
| 3400 | } |
| 3401 | |
Philip P. Moltmann | d8c0bda | 2019-12-19 19:55:35 -0800 | [diff] [blame] | 3402 | return lastEvent.getDuration(); |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3403 | } |
| 3404 | |
| 3405 | /** |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 3406 | * Gets the proxy info of the app that performed the last access on behalf of this |
| 3407 | * attribution and as a result blamed the op on this attribution. |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3408 | * |
| 3409 | * @param flags The op flags |
| 3410 | * |
Philip P. Moltmann | 7c0524f | 2020-02-06 09:21:31 -0800 | [diff] [blame] | 3411 | * @return The proxy info or {@code null} if there was no proxy access |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3412 | * |
| 3413 | * @see #getLastForegroundProxyInfo(int) |
| 3414 | * @see #getLastBackgroundProxyInfo(int) |
| 3415 | * @see #getLastProxyInfo(int, int, int) |
| 3416 | * @see OpEntry#getLastProxyInfo(int) |
| 3417 | */ |
| 3418 | public @Nullable OpEventProxyInfo getLastProxyInfo(@OpFlags int flags) { |
| 3419 | return getLastProxyInfo(MAX_PRIORITY_UID_STATE, MIN_PRIORITY_UID_STATE, flags); |
| 3420 | } |
| 3421 | |
| 3422 | /** |
| 3423 | * Gets the proxy info of the app that performed the last foreground access on behalf of |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 3424 | * this attribution and as a result blamed the op on this attribution. |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3425 | * |
| 3426 | * @param flags The op flags |
| 3427 | * |
Philip P. Moltmann | 7c0524f | 2020-02-06 09:21:31 -0800 | [diff] [blame] | 3428 | * @return The proxy info or {@code null} if there was no proxy access |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3429 | * |
| 3430 | * @see #getLastProxyInfo(int) |
| 3431 | * @see #getLastBackgroundProxyInfo(int) |
| 3432 | * @see #getLastProxyInfo(int, int, int) |
| 3433 | * @see OpEntry#getLastForegroundProxyInfo(int) |
| 3434 | */ |
| 3435 | public @Nullable OpEventProxyInfo getLastForegroundProxyInfo(@OpFlags int flags) { |
| 3436 | return getLastProxyInfo(MAX_PRIORITY_UID_STATE, resolveFirstUnrestrictedUidState(mOp), |
| 3437 | flags); |
| 3438 | } |
| 3439 | |
| 3440 | /** |
| 3441 | * Gets the proxy info of the app that performed the last background access on behalf of |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 3442 | * this attribution and as a result blamed the op on this attribution. |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3443 | * |
| 3444 | * @param flags The op flags |
| 3445 | * |
Philip P. Moltmann | 7c0524f | 2020-02-06 09:21:31 -0800 | [diff] [blame] | 3446 | * @return The proxy info or {@code null} if there was no proxy background access |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3447 | * |
| 3448 | * @see #getLastProxyInfo(int) |
| 3449 | * @see #getLastForegroundProxyInfo(int) |
| 3450 | * @see #getLastProxyInfo(int, int, int) |
| 3451 | * @see OpEntry#getLastBackgroundProxyInfo(int) |
| 3452 | */ |
| 3453 | public @Nullable OpEventProxyInfo getLastBackgroundProxyInfo(@OpFlags int flags) { |
| 3454 | return getLastProxyInfo(resolveLastRestrictedUidState(mOp), MIN_PRIORITY_UID_STATE, |
| 3455 | flags); |
| 3456 | } |
| 3457 | |
| 3458 | /** |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 3459 | * Gets the proxy info of the app that performed the last access on behalf of this |
| 3460 | * attribution and as a result blamed the op on this attribution. |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3461 | * |
| 3462 | * @param fromUidState The lowest UID state for which to query |
| 3463 | * @param toUidState The highest UID state for which to query (inclusive) |
| 3464 | * @param flags The op flags |
| 3465 | * |
Philip P. Moltmann | 7c0524f | 2020-02-06 09:21:31 -0800 | [diff] [blame] | 3466 | * @return The proxy info or {@code null} if there was no proxy foreground access |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3467 | * |
| 3468 | * @see #getLastProxyInfo(int) |
| 3469 | * @see #getLastForegroundProxyInfo(int) |
| 3470 | * @see #getLastBackgroundProxyInfo(int) |
| 3471 | * @see OpEntry#getLastProxyInfo(int, int, int) |
| 3472 | */ |
| 3473 | public @Nullable OpEventProxyInfo getLastProxyInfo(@UidState int fromUidState, |
| 3474 | @UidState int toUidState, @OpFlags int flags) { |
| 3475 | NoteOpEvent lastEvent = getLastAccessEvent(fromUidState, toUidState, flags); |
| 3476 | if (lastEvent == null) { |
| 3477 | return null; |
| 3478 | } |
| 3479 | |
Philip P. Moltmann | d8c0bda | 2019-12-19 19:55:35 -0800 | [diff] [blame] | 3480 | return lastEvent.getProxy(); |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3481 | } |
| 3482 | |
| 3483 | private static class LongSparseArrayParceling implements |
| 3484 | Parcelling<LongSparseArray<NoteOpEvent>> { |
| 3485 | @Override |
| 3486 | public void parcel(@Nullable LongSparseArray<NoteOpEvent> array, @NonNull Parcel dest, |
| 3487 | int parcelFlags) { |
| 3488 | if (array == null) { |
| 3489 | dest.writeInt(-1); |
| 3490 | return; |
| 3491 | } |
| 3492 | |
| 3493 | int numEntries = array.size(); |
| 3494 | dest.writeInt(numEntries); |
| 3495 | |
| 3496 | for (int i = 0; i < numEntries; i++) { |
| 3497 | dest.writeLong(array.keyAt(i)); |
| 3498 | dest.writeParcelable(array.valueAt(i), parcelFlags); |
| 3499 | } |
| 3500 | } |
| 3501 | |
| 3502 | @Override |
| 3503 | public @Nullable LongSparseArray<NoteOpEvent> unparcel(@NonNull Parcel source) { |
| 3504 | int numEntries = source.readInt(); |
| 3505 | if (numEntries == -1) { |
| 3506 | return null; |
| 3507 | } |
| 3508 | |
| 3509 | LongSparseArray<NoteOpEvent> array = new LongSparseArray<>(numEntries); |
| 3510 | |
| 3511 | for (int i = 0; i < numEntries; i++) { |
| 3512 | array.put(source.readLong(), source.readParcelable(null)); |
| 3513 | } |
| 3514 | |
| 3515 | return array; |
| 3516 | } |
| 3517 | } |
| 3518 | |
| 3519 | |
| 3520 | |
| 3521 | // Code below generated by codegen v1.0.14. |
| 3522 | // |
| 3523 | // DO NOT MODIFY! |
| 3524 | // CHECKSTYLE:OFF Generated code |
| 3525 | // |
| 3526 | // To regenerate run: |
| 3527 | // $ codegen $ANDROID_BUILD_TOP/frameworks/base/core/java/android/app/AppOpsManager.java |
| 3528 | // |
| 3529 | // To exclude the generated code from IntelliJ auto-formatting enable (one-time): |
| 3530 | // Settings > Editor > Code Style > Formatter Control |
| 3531 | //@formatter:off |
| 3532 | |
| 3533 | |
| 3534 | /** |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 3535 | * Creates a new OpAttributionEntry. |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3536 | * |
| 3537 | * @param op |
| 3538 | * The code of the op |
| 3539 | * @param running |
| 3540 | * Whether the op is running |
| 3541 | * @param accessEvents |
| 3542 | * The access events |
| 3543 | * @param rejectEvents |
| 3544 | * The rejection events |
| 3545 | * @hide |
| 3546 | */ |
| 3547 | @DataClass.Generated.Member |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 3548 | public AttributedOpEntry( |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3549 | @IntRange(from = 0, to = _NUM_OP - 1) int op, |
| 3550 | boolean running, |
| 3551 | @Nullable LongSparseArray<NoteOpEvent> accessEvents, |
| 3552 | @Nullable LongSparseArray<NoteOpEvent> rejectEvents) { |
| 3553 | this.mOp = op; |
| 3554 | com.android.internal.util.AnnotationValidations.validate( |
| 3555 | IntRange.class, null, mOp, |
| 3556 | "from", 0, |
| 3557 | "to", _NUM_OP - 1); |
| 3558 | this.mRunning = running; |
| 3559 | this.mAccessEvents = accessEvents; |
| 3560 | this.mRejectEvents = rejectEvents; |
| 3561 | |
| 3562 | // onConstructed(); // You can define this method to get a callback |
| 3563 | } |
| 3564 | |
| 3565 | /** |
| 3566 | * Whether the op is running |
| 3567 | */ |
| 3568 | @DataClass.Generated.Member |
| 3569 | public boolean isRunning() { |
| 3570 | return mRunning; |
| 3571 | } |
| 3572 | |
| 3573 | @DataClass.Generated.Member |
| 3574 | static Parcelling<LongSparseArray<NoteOpEvent>> sParcellingForAccessEvents = |
| 3575 | Parcelling.Cache.get( |
| 3576 | LongSparseArrayParceling.class); |
| 3577 | static { |
| 3578 | if (sParcellingForAccessEvents == null) { |
| 3579 | sParcellingForAccessEvents = Parcelling.Cache.put( |
| 3580 | new LongSparseArrayParceling()); |
| 3581 | } |
| 3582 | } |
| 3583 | |
| 3584 | @DataClass.Generated.Member |
| 3585 | static Parcelling<LongSparseArray<NoteOpEvent>> sParcellingForRejectEvents = |
| 3586 | Parcelling.Cache.get( |
| 3587 | LongSparseArrayParceling.class); |
| 3588 | static { |
| 3589 | if (sParcellingForRejectEvents == null) { |
| 3590 | sParcellingForRejectEvents = Parcelling.Cache.put( |
| 3591 | new LongSparseArrayParceling()); |
| 3592 | } |
| 3593 | } |
| 3594 | |
| 3595 | @Override |
| 3596 | @DataClass.Generated.Member |
| 3597 | public void writeToParcel(@NonNull Parcel dest, int flags) { |
| 3598 | // You can override field parcelling by defining methods like: |
| 3599 | // void parcelFieldName(Parcel dest, int flags) { ... } |
| 3600 | |
| 3601 | byte flg = 0; |
| 3602 | if (mRunning) flg |= 0x2; |
| 3603 | if (mAccessEvents != null) flg |= 0x4; |
| 3604 | if (mRejectEvents != null) flg |= 0x8; |
| 3605 | dest.writeByte(flg); |
| 3606 | dest.writeInt(mOp); |
| 3607 | sParcellingForAccessEvents.parcel(mAccessEvents, dest, flags); |
| 3608 | sParcellingForRejectEvents.parcel(mRejectEvents, dest, flags); |
| 3609 | } |
| 3610 | |
| 3611 | @Override |
| 3612 | @DataClass.Generated.Member |
| 3613 | public int describeContents() { return 0; } |
| 3614 | |
| 3615 | /** @hide */ |
| 3616 | @SuppressWarnings({"unchecked", "RedundantCast"}) |
| 3617 | @DataClass.Generated.Member |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 3618 | /* package-private */ AttributedOpEntry(@NonNull Parcel in) { |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3619 | // You can override field unparcelling by defining methods like: |
| 3620 | // static FieldType unparcelFieldName(Parcel in) { ... } |
| 3621 | |
| 3622 | byte flg = in.readByte(); |
| 3623 | boolean running = (flg & 0x2) != 0; |
| 3624 | int op = in.readInt(); |
| 3625 | LongSparseArray<NoteOpEvent> accessEvents = sParcellingForAccessEvents.unparcel(in); |
| 3626 | LongSparseArray<NoteOpEvent> rejectEvents = sParcellingForRejectEvents.unparcel(in); |
| 3627 | |
| 3628 | this.mOp = op; |
| 3629 | com.android.internal.util.AnnotationValidations.validate( |
| 3630 | IntRange.class, null, mOp, |
| 3631 | "from", 0, |
| 3632 | "to", _NUM_OP - 1); |
| 3633 | this.mRunning = running; |
| 3634 | this.mAccessEvents = accessEvents; |
| 3635 | this.mRejectEvents = rejectEvents; |
| 3636 | |
| 3637 | // onConstructed(); // You can define this method to get a callback |
| 3638 | } |
| 3639 | |
| 3640 | @DataClass.Generated.Member |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 3641 | public static final @NonNull Parcelable.Creator<AttributedOpEntry> CREATOR |
| 3642 | = new Parcelable.Creator<AttributedOpEntry>() { |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3643 | @Override |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 3644 | public AttributedOpEntry[] newArray(int size) { |
| 3645 | return new AttributedOpEntry[size]; |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3646 | } |
| 3647 | |
| 3648 | @Override |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 3649 | public AttributedOpEntry createFromParcel(@NonNull Parcel in) { |
| 3650 | return new AttributedOpEntry(in); |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3651 | } |
| 3652 | }; |
| 3653 | |
| 3654 | /* |
| 3655 | @DataClass.Generated( |
| 3656 | time = 1574809856239L, |
| 3657 | codegenVersion = "1.0.14", |
| 3658 | sourceFile = "frameworks/base/core/java/android/app/AppOpsManager.java", |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 3659 | inputSignatures = "private final @android.annotation.IntRange(from=0L, to=_NUM_OP - 1) int mOp\nprivate final boolean mRunning\nprivate final @com.android.internal.util.DataClass.ParcelWith(android.app.OpAttributionEntry.LongSparseArrayParceling.class) @android.annotation.Nullable android.util.LongSparseArray<android.app.NoteOpEvent> mAccessEvents\nprivate final @com.android.internal.util.DataClass.ParcelWith(android.app.OpAttributionEntry.LongSparseArrayParceling.class) @android.annotation.Nullable android.util.LongSparseArray<android.app.NoteOpEvent> mRejectEvents\npublic @android.annotation.NonNull android.util.ArraySet<java.lang.Long> collectKeys()\npublic @android.app.UidState int getLastAccessUidState(int)\npublic @android.app.UidState int getLastForegroundAccessUidState(int)\npublic @android.app.UidState int getLastBackgroundAccessUidState(int)\npublic @android.app.UidState int getLastRejectUidState(int)\npublic @android.app.UidState int getLastForegroundRejectUidState(int)\npublic @android.app.UidState int getLastBackgroundRejectUidState(int)\npublic long getAccessTime(int,int)\npublic long getRejectTime(int,int)\npublic long getDuration(int,int)\npublic int getProxyUid(int,int)\npublic @android.annotation.Nullable java.lang.String getProxyPackageName(int,int)\npublic @android.annotation.Nullable java.lang.String getProxyAttributionTag(int,int)\nclass OpAttributionEntry extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genHiddenConstructor=true)") |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3660 | @Deprecated |
| 3661 | private void __metadata() {} |
| 3662 | */ |
| 3663 | |
| 3664 | |
| 3665 | //@formatter:on |
| 3666 | // End of generated code |
| 3667 | |
| 3668 | } |
| 3669 | |
| 3670 | /** |
| 3671 | * Last {@link #noteOp} and {@link #startOp} events performed for a single op for all uidModes |
| 3672 | * and opFlags. |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3673 | * |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 3674 | * @hide |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 3675 | */ |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 3676 | @TestApi |
| 3677 | @Immutable |
Dianne Hackborn | f0c322a | 2018-06-13 15:24:04 -0700 | [diff] [blame] | 3678 | @SystemApi |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3679 | // @DataClass(genHiddenConstructor = true) codegen verifier is broken |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3680 | public static final class OpEntry implements Parcelable { |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3681 | /** The code of the op */ |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3682 | private final @IntRange(from = 0, to = _NUM_OP - 1) int mOp; |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3683 | /** The mode of the op */ |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3684 | private final @Mode int mMode; |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 3685 | /** The attributed entries by attribution tag */ |
| 3686 | private final @NonNull Map<String, AttributedOpEntry> mAttributedOpEntries; |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3687 | |
| 3688 | /** |
| 3689 | * @hide |
| 3690 | */ |
Philip P. Moltmann | ac44350 | 2020-05-11 13:15:12 -0700 | [diff] [blame] | 3691 | @UnsupportedAppUsage(/*maxTargetSdk = Build.VERSION_CODES.R,*/ publicAlternatives = "{@code " |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3692 | + "#getOpStr()}") |
| 3693 | public int getOp() { |
| 3694 | return mOp; |
| 3695 | } |
| 3696 | |
| 3697 | /** |
| 3698 | * @return This entry's op string name, such as {@link #OPSTR_COARSE_LOCATION}. |
| 3699 | */ |
| 3700 | public @NonNull String getOpStr() { |
| 3701 | return sOpToString[mOp]; |
| 3702 | } |
| 3703 | |
| 3704 | /** |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3705 | * @hide |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3706 | * |
| 3707 | * @deprecated Use {@link #getLastAccessTime(int)} instead |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3708 | */ |
| 3709 | @Deprecated |
Philip P. Moltmann | ac44350 | 2020-05-11 13:15:12 -0700 | [diff] [blame] | 3710 | @UnsupportedAppUsage(/*maxTargetSdk = Build.VERSION_CODES.R,*/ publicAlternatives = "{@code " |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3711 | + "#getLastAccessTime(int)}") |
| 3712 | public long getTime() { |
| 3713 | return getLastAccessTime(OP_FLAGS_ALL); |
| 3714 | } |
| 3715 | |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3716 | /** |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3717 | * Return the last access time. |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3718 | * |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3719 | * @param flags The op flags |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3720 | * |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3721 | * @return the last access time (in milliseconds since epoch start (January 1, 1970 |
Philip P. Moltmann | 7c0524f | 2020-02-06 09:21:31 -0800 | [diff] [blame] | 3722 | * 00:00:00.000 GMT - Gregorian)) or {@code -1} if there was no access |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3723 | * |
| 3724 | * @see #getLastAccessForegroundTime(int) |
| 3725 | * @see #getLastAccessBackgroundTime(int) |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3726 | * @see #getLastAccessTime(int, int, int) |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 3727 | * @see AttributedOpEntry#getLastAccessTime(int) |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3728 | */ |
| 3729 | public long getLastAccessTime(@OpFlags int flags) { |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3730 | return getLastAccessTime(MAX_PRIORITY_UID_STATE, MIN_PRIORITY_UID_STATE, flags); |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3731 | } |
| 3732 | |
| 3733 | /** |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3734 | * Return the last foreground access time. |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3735 | * |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3736 | * @param flags The op flags |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3737 | * |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3738 | * @return the last access time (in milliseconds since epoch start (January 1, 1970 |
Philip P. Moltmann | 7c0524f | 2020-02-06 09:21:31 -0800 | [diff] [blame] | 3739 | * 00:00:00.000 GMT - Gregorian)) or {@code -1} if there was no foreground access |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3740 | * |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3741 | * @see #getLastAccessTime(int) |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3742 | * @see #getLastAccessBackgroundTime(int) |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3743 | * @see #getLastAccessTime(int, int, int) |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 3744 | * @see AttributedOpEntry#getLastAccessForegroundTime(int) |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3745 | */ |
| 3746 | public long getLastAccessForegroundTime(@OpFlags int flags) { |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3747 | return getLastAccessTime(MAX_PRIORITY_UID_STATE, resolveFirstUnrestrictedUidState(mOp), |
| 3748 | flags); |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3749 | } |
| 3750 | |
| 3751 | /** |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3752 | * Return the last background access time. |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3753 | * |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3754 | * @param flags The op flags |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3755 | * |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3756 | * @return the last access time (in milliseconds since epoch start (January 1, 1970 |
Philip P. Moltmann | 7c0524f | 2020-02-06 09:21:31 -0800 | [diff] [blame] | 3757 | * 00:00:00.000 GMT - Gregorian)) or {@code -1} if there was no background access |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3758 | * |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3759 | * @see #getLastAccessTime(int) |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3760 | * @see #getLastAccessForegroundTime(int) |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3761 | * @see #getLastAccessTime(int, int, int) |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 3762 | * @see AttributedOpEntry#getLastAccessBackgroundTime(int) |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3763 | */ |
| 3764 | public long getLastAccessBackgroundTime(@OpFlags int flags) { |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3765 | return getLastAccessTime(resolveLastRestrictedUidState(mOp), MIN_PRIORITY_UID_STATE, |
| 3766 | flags); |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3767 | } |
| 3768 | |
| 3769 | /** |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3770 | * Return the last access event. |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3771 | * |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3772 | * @param flags The op flags |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3773 | * |
Philip P. Moltmann | 7c0524f | 2020-02-06 09:21:31 -0800 | [diff] [blame] | 3774 | * @return the last access event of {@code null} if there was no access |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3775 | */ |
| 3776 | private @Nullable NoteOpEvent getLastAccessEvent(@UidState int fromUidState, |
| 3777 | @UidState int toUidState, @OpFlags int flags) { |
| 3778 | NoteOpEvent lastAccessEvent = null; |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 3779 | for (AttributedOpEntry attributionEntry : mAttributedOpEntries.values()) { |
| 3780 | NoteOpEvent lastAttributionAccessEvent = attributionEntry.getLastAccessEvent( |
| 3781 | fromUidState, toUidState, flags); |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3782 | |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 3783 | if (lastAccessEvent == null || (lastAttributionAccessEvent != null |
| 3784 | && lastAttributionAccessEvent.getNoteTime() |
| 3785 | > lastAccessEvent.getNoteTime())) { |
| 3786 | lastAccessEvent = lastAttributionAccessEvent; |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3787 | } |
| 3788 | } |
| 3789 | |
| 3790 | return lastAccessEvent; |
| 3791 | } |
| 3792 | |
| 3793 | /** |
| 3794 | * Return the last access time. |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3795 | * |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3796 | * @param fromUidState the lowest uid state to query |
| 3797 | * @param toUidState the highest uid state to query (inclusive) |
| 3798 | * @param flags The op flags |
| 3799 | * |
| 3800 | * @return the last access time (in milliseconds since epoch start (January 1, 1970 |
Philip P. Moltmann | 7c0524f | 2020-02-06 09:21:31 -0800 | [diff] [blame] | 3801 | * 00:00:00.000 GMT - Gregorian)) or {@code -1} if there was no access |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3802 | * |
| 3803 | * @see #getLastAccessTime(int) |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3804 | * @see #getLastAccessForegroundTime(int) |
| 3805 | * @see #getLastAccessBackgroundTime(int) |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 3806 | * @see AttributedOpEntry#getLastAccessTime(int, int, int) |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3807 | */ |
| 3808 | public long getLastAccessTime(@UidState int fromUidState, @UidState int toUidState, |
| 3809 | @OpFlags int flags) { |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3810 | NoteOpEvent lastEvent = getLastAccessEvent(fromUidState, toUidState, flags);; |
| 3811 | |
| 3812 | if (lastEvent == null) { |
| 3813 | return -1; |
| 3814 | } |
| 3815 | |
Philip P. Moltmann | d8c0bda | 2019-12-19 19:55:35 -0800 | [diff] [blame] | 3816 | return lastEvent.getNoteTime(); |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3817 | } |
| 3818 | |
| 3819 | /** |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3820 | * @hide |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3821 | * |
| 3822 | * @deprecated Use {@link #getLastRejectTime(int)} instead |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3823 | */ |
| 3824 | @Deprecated |
Philip P. Moltmann | ac44350 | 2020-05-11 13:15:12 -0700 | [diff] [blame] | 3825 | @UnsupportedAppUsage(/*maxTargetSdk = Build.VERSION_CODES.R,*/ publicAlternatives = "{@code " |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3826 | + "#getLastRejectTime(int)}") |
| 3827 | public long getRejectTime() { |
| 3828 | return getLastRejectTime(OP_FLAGS_ALL); |
| 3829 | } |
| 3830 | |
| 3831 | /** |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3832 | * Return the last rejection time. |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3833 | * |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3834 | * @param flags The op flags |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3835 | * |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3836 | * @return the last rejection time (in milliseconds since epoch start (January 1, 1970 |
Philip P. Moltmann | 7c0524f | 2020-02-06 09:21:31 -0800 | [diff] [blame] | 3837 | * 00:00:00.000 GMT - Gregorian)) or {@code -1} if there was no rejection |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3838 | * |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3839 | * @see #getLastRejectForegroundTime(int) |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3840 | * @see #getLastRejectBackgroundTime(int) |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3841 | * @see #getLastRejectTime(int, int, int) |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 3842 | * @see AttributedOpEntry#getLastRejectTime(int) |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3843 | */ |
| 3844 | public long getLastRejectTime(@OpFlags int flags) { |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3845 | return getLastRejectTime(MAX_PRIORITY_UID_STATE, MIN_PRIORITY_UID_STATE, flags); |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3846 | } |
| 3847 | |
| 3848 | /** |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3849 | * Return the last foreground rejection time. |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3850 | * |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3851 | * @param flags The op flags |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3852 | * |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3853 | * @return the last rejection time (in milliseconds since epoch start (January 1, 1970 |
Philip P. Moltmann | 7c0524f | 2020-02-06 09:21:31 -0800 | [diff] [blame] | 3854 | * 00:00:00.000 GMT - Gregorian)) or {@code -1} if there was no foreground rejection |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3855 | * |
| 3856 | * @see #getLastRejectTime(int) |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3857 | * @see #getLastRejectBackgroundTime(int) |
| 3858 | * @see #getLastRejectTime(int, int, int) |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 3859 | * @see AttributedOpEntry#getLastRejectForegroundTime(int) |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3860 | */ |
| 3861 | public long getLastRejectForegroundTime(@OpFlags int flags) { |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3862 | return getLastRejectTime(MAX_PRIORITY_UID_STATE, resolveFirstUnrestrictedUidState(mOp), |
| 3863 | flags); |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3864 | } |
| 3865 | |
| 3866 | /** |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3867 | * Return the last background rejection time. |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3868 | * |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3869 | * @param flags The op flags |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3870 | * |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3871 | * @return the last rejection time (in milliseconds since epoch start (January 1, 1970 |
Philip P. Moltmann | 7c0524f | 2020-02-06 09:21:31 -0800 | [diff] [blame] | 3872 | * 00:00:00.000 GMT - Gregorian)) or {@code -1} if there was no background rejection |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3873 | * |
| 3874 | * @see #getLastRejectTime(int) |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3875 | * @see #getLastRejectForegroundTime(int) |
| 3876 | * @see #getLastRejectTime(int, int, int) |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 3877 | * @see AttributedOpEntry#getLastRejectBackgroundTime(int) |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3878 | */ |
| 3879 | public long getLastRejectBackgroundTime(@OpFlags int flags) { |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3880 | return getLastRejectTime(resolveLastRestrictedUidState(mOp), MIN_PRIORITY_UID_STATE, |
| 3881 | flags); |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3882 | } |
| 3883 | |
| 3884 | /** |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3885 | * Return the last rejection event. |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3886 | * |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3887 | * @param flags The op flags |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3888 | * |
Philip P. Moltmann | 7c0524f | 2020-02-06 09:21:31 -0800 | [diff] [blame] | 3889 | * @return the last reject event of {@code null} if there was no rejection |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3890 | */ |
| 3891 | private @Nullable NoteOpEvent getLastRejectEvent(@UidState int fromUidState, |
| 3892 | @UidState int toUidState, @OpFlags int flags) { |
| 3893 | NoteOpEvent lastAccessEvent = null; |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 3894 | for (AttributedOpEntry attributionEntry : mAttributedOpEntries.values()) { |
| 3895 | NoteOpEvent lastAttributionAccessEvent = attributionEntry.getLastRejectEvent( |
| 3896 | fromUidState, toUidState, flags); |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3897 | |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 3898 | if (lastAccessEvent == null || (lastAttributionAccessEvent != null |
| 3899 | && lastAttributionAccessEvent.getNoteTime() |
| 3900 | > lastAccessEvent.getNoteTime())) { |
| 3901 | lastAccessEvent = lastAttributionAccessEvent; |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3902 | } |
| 3903 | } |
| 3904 | |
| 3905 | return lastAccessEvent; |
| 3906 | } |
| 3907 | |
| 3908 | /** |
| 3909 | * Return the last rejection time. |
| 3910 | * |
| 3911 | * @param fromUidState the lowest uid state to query |
| 3912 | * @param toUidState the highest uid state to query (inclusive) |
| 3913 | * @param flags The op flags |
| 3914 | * |
| 3915 | * @return the last rejection time (in milliseconds since epoch start (January 1, 1970 |
Philip P. Moltmann | 7c0524f | 2020-02-06 09:21:31 -0800 | [diff] [blame] | 3916 | * 00:00:00.000 GMT - Gregorian)) or {@code -1} if there was no rejection |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3917 | * |
| 3918 | * @see #getLastRejectTime(int) |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3919 | * @see #getLastRejectForegroundTime(int) |
| 3920 | * @see #getLastRejectBackgroundTime(int) |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3921 | * @see #getLastRejectTime(int, int, int) |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 3922 | * @see AttributedOpEntry#getLastRejectTime(int, int, int) |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3923 | */ |
| 3924 | public long getLastRejectTime(@UidState int fromUidState, @UidState int toUidState, |
| 3925 | @OpFlags int flags) { |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3926 | NoteOpEvent lastEvent = getLastRejectEvent(fromUidState, toUidState, flags); |
| 3927 | if (lastEvent == null) { |
| 3928 | return -1; |
| 3929 | } |
| 3930 | |
Philip P. Moltmann | d8c0bda | 2019-12-19 19:55:35 -0800 | [diff] [blame] | 3931 | return lastEvent.getNoteTime(); |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3932 | } |
| 3933 | |
| 3934 | /** |
| 3935 | * @return Whether the operation is running. |
| 3936 | */ |
| 3937 | public boolean isRunning() { |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 3938 | for (AttributedOpEntry opAttributionEntry : mAttributedOpEntries.values()) { |
| 3939 | if (opAttributionEntry.isRunning()) { |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3940 | return true; |
| 3941 | } |
| 3942 | } |
| 3943 | |
| 3944 | return false; |
| 3945 | } |
| 3946 | |
| 3947 | /** |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3948 | * @deprecated Use {@link #getLastDuration(int)} instead |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3949 | */ |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3950 | @Deprecated |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3951 | public long getDuration() { |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3952 | return getLastDuration(OP_FLAGS_ALL); |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3953 | } |
| 3954 | |
| 3955 | /** |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3956 | * Return the duration in milliseconds of the last the access. |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3957 | * |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3958 | * @param flags The op flags |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3959 | * |
Philip P. Moltmann | 7c0524f | 2020-02-06 09:21:31 -0800 | [diff] [blame] | 3960 | * @return the duration in milliseconds or {@code -1} if there was no access |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3961 | * |
| 3962 | * @see #getLastForegroundDuration(int) |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3963 | * @see #getLastBackgroundDuration(int) |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3964 | * @see #getLastDuration(int, int, int) |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 3965 | * @see AttributedOpEntry#getLastDuration(int) |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3966 | */ |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3967 | public long getLastDuration(@OpFlags int flags) { |
| 3968 | return getLastDuration(MAX_PRIORITY_UID_STATE, MIN_PRIORITY_UID_STATE, flags); |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3969 | } |
| 3970 | |
| 3971 | /** |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3972 | * Return the duration in milliseconds of the last foreground access. |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3973 | * |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3974 | * @param flags The op flags |
| 3975 | * |
Philip P. Moltmann | 7c0524f | 2020-02-06 09:21:31 -0800 | [diff] [blame] | 3976 | * @return the duration in milliseconds or {@code -1} if there was no foreground access |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3977 | * |
| 3978 | * @see #getLastDuration(int) |
| 3979 | * @see #getLastBackgroundDuration(int) |
| 3980 | * @see #getLastDuration(int, int, int) |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 3981 | * @see AttributedOpEntry#getLastForegroundDuration(int) |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3982 | */ |
| 3983 | public long getLastForegroundDuration(@OpFlags int flags) { |
| 3984 | return getLastDuration(MAX_PRIORITY_UID_STATE, resolveFirstUnrestrictedUidState(mOp), |
| 3985 | flags); |
| 3986 | } |
| 3987 | |
| 3988 | /** |
| 3989 | * Return the duration in milliseconds of the last background access. |
| 3990 | * |
| 3991 | * @param flags The op flags |
| 3992 | * |
Philip P. Moltmann | 7c0524f | 2020-02-06 09:21:31 -0800 | [diff] [blame] | 3993 | * @return the duration in milliseconds or {@code -1} if there was no background access |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3994 | * |
| 3995 | * @see #getLastDuration(int) |
| 3996 | * @see #getLastForegroundDuration(int) |
| 3997 | * @see #getLastDuration(int, int, int) |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 3998 | * @see AttributedOpEntry#getLastBackgroundDuration(int) |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3999 | */ |
| 4000 | public long getLastBackgroundDuration(@OpFlags int flags) { |
| 4001 | return getLastDuration(resolveLastRestrictedUidState(mOp), MIN_PRIORITY_UID_STATE, |
| 4002 | flags); |
| 4003 | } |
| 4004 | |
| 4005 | /** |
| 4006 | * Return the duration in milliseconds of the last access. |
| 4007 | * |
| 4008 | * @param fromUidState The lowest UID state for which to query |
| 4009 | * @param toUidState The highest UID state for which to query (inclusive) |
| 4010 | * @param flags The op flags |
| 4011 | * |
Philip P. Moltmann | 7c0524f | 2020-02-06 09:21:31 -0800 | [diff] [blame] | 4012 | * @return the duration in milliseconds or {@code -1} if there was no access |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 4013 | * |
| 4014 | * @see #getLastDuration(int) |
| 4015 | * @see #getLastForegroundDuration(int) |
| 4016 | * @see #getLastBackgroundDuration(int) |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 4017 | * @see AttributedOpEntry#getLastDuration(int, int, int) |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 4018 | */ |
| 4019 | public long getLastDuration(@UidState int fromUidState, @UidState int toUidState, |
| 4020 | @OpFlags int flags) { |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 4021 | NoteOpEvent lastEvent = getLastAccessEvent(fromUidState, toUidState, flags); |
| 4022 | if (lastEvent == null) { |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 4023 | return -1; |
| 4024 | } |
| 4025 | |
Philip P. Moltmann | d8c0bda | 2019-12-19 19:55:35 -0800 | [diff] [blame] | 4026 | return lastEvent.getDuration(); |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 4027 | } |
| 4028 | |
| 4029 | /** |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 4030 | * @deprecated Use {@link #getLastProxyInfo(int)} instead |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 4031 | */ |
| 4032 | @Deprecated |
| 4033 | public int getProxyUid() { |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 4034 | OpEventProxyInfo proxy = getLastProxyInfo(OP_FLAGS_ALL); |
| 4035 | if (proxy == null) { |
| 4036 | return Process.INVALID_UID; |
| 4037 | } |
| 4038 | |
| 4039 | return proxy.getUid(); |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 4040 | } |
| 4041 | |
| 4042 | /** |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 4043 | * @deprecated Use {@link #getLastProxyInfo(int)} instead |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 4044 | */ |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 4045 | @Deprecated |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 4046 | public int getProxyUid(@UidState int uidState, @OpFlags int flags) { |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 4047 | OpEventProxyInfo proxy = getLastProxyInfo(uidState, uidState, flags); |
| 4048 | if (proxy == null) { |
| 4049 | return Process.INVALID_UID; |
| 4050 | } |
| 4051 | |
| 4052 | return proxy.getUid(); |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 4053 | } |
| 4054 | |
| 4055 | /** |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 4056 | * @deprecated Use {@link #getLastProxyInfo(int)} instead |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 4057 | */ |
| 4058 | @Deprecated |
| 4059 | public @Nullable String getProxyPackageName() { |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 4060 | OpEventProxyInfo proxy = getLastProxyInfo(OP_FLAGS_ALL); |
| 4061 | if (proxy == null) { |
| 4062 | return null; |
| 4063 | } |
| 4064 | |
| 4065 | return proxy.getPackageName(); |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 4066 | } |
| 4067 | |
| 4068 | /** |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 4069 | * @deprecated Use {@link #getLastProxyInfo(int)} instead |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 4070 | */ |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 4071 | @Deprecated |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 4072 | public @Nullable String getProxyPackageName(@UidState int uidState, @OpFlags int flags) { |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 4073 | OpEventProxyInfo proxy = getLastProxyInfo(uidState, uidState, flags); |
| 4074 | if (proxy == null) { |
| 4075 | return null; |
| 4076 | } |
| 4077 | |
| 4078 | return proxy.getPackageName(); |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 4079 | } |
| 4080 | |
| 4081 | /** |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 4082 | * Gets the proxy info of the app that performed the last access on behalf of this app and |
| 4083 | * as a result blamed the op on this app. |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 4084 | * |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 4085 | * @param flags The op flags |
| 4086 | * |
Philip P. Moltmann | 7c0524f | 2020-02-06 09:21:31 -0800 | [diff] [blame] | 4087 | * @return The proxy info or {@code null} if there was no proxy access |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 4088 | * |
| 4089 | * @see #getLastForegroundProxyInfo(int) |
| 4090 | * @see #getLastBackgroundProxyInfo(int) |
| 4091 | * @see #getLastProxyInfo(int, int, int) |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 4092 | * @see AttributedOpEntry#getLastProxyInfo(int) |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 4093 | */ |
| 4094 | public @Nullable OpEventProxyInfo getLastProxyInfo(@OpFlags int flags) { |
| 4095 | return getLastProxyInfo(MAX_PRIORITY_UID_STATE, MIN_PRIORITY_UID_STATE, flags); |
| 4096 | } |
| 4097 | |
| 4098 | /** |
| 4099 | * Gets the proxy info of the app that performed the last foreground access on behalf of |
| 4100 | * this app and as a result blamed the op on this app. |
| 4101 | * |
| 4102 | * @param flags The op flags |
| 4103 | * |
Philip P. Moltmann | 7c0524f | 2020-02-06 09:21:31 -0800 | [diff] [blame] | 4104 | * @return The proxy info or {@code null} if there was no foreground proxy access |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 4105 | * |
| 4106 | * @see #getLastProxyInfo(int) |
| 4107 | * @see #getLastBackgroundProxyInfo(int) |
| 4108 | * @see #getLastProxyInfo(int, int, int) |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 4109 | * @see AttributedOpEntry#getLastForegroundProxyInfo(int) |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 4110 | */ |
| 4111 | public @Nullable OpEventProxyInfo getLastForegroundProxyInfo(@OpFlags int flags) { |
| 4112 | return getLastProxyInfo(MAX_PRIORITY_UID_STATE, resolveFirstUnrestrictedUidState(mOp), |
| 4113 | flags); |
| 4114 | } |
| 4115 | |
| 4116 | /** |
| 4117 | * Gets the proxy info of the app that performed the last background access on behalf of |
| 4118 | * this app and as a result blamed the op on this app. |
| 4119 | * |
| 4120 | * @param flags The op flags |
| 4121 | * |
Philip P. Moltmann | 7c0524f | 2020-02-06 09:21:31 -0800 | [diff] [blame] | 4122 | * @return The proxy info or {@code null} if there was no background proxy access |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 4123 | * |
| 4124 | * @see #getLastProxyInfo(int) |
| 4125 | * @see #getLastForegroundProxyInfo(int) |
| 4126 | * @see #getLastProxyInfo(int, int, int) |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 4127 | * @see AttributedOpEntry#getLastBackgroundProxyInfo(int) |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 4128 | */ |
| 4129 | public @Nullable OpEventProxyInfo getLastBackgroundProxyInfo(@OpFlags int flags) { |
| 4130 | return getLastProxyInfo(resolveLastRestrictedUidState(mOp), MIN_PRIORITY_UID_STATE, |
| 4131 | flags); |
| 4132 | } |
| 4133 | |
| 4134 | /** |
| 4135 | * Gets the proxy info of the app that performed the last access on behalf of this app and |
| 4136 | * as a result blamed the op on this app. |
| 4137 | * |
| 4138 | * @param fromUidState The lowest UID state for which to query |
| 4139 | * @param toUidState The highest UID state for which to query (inclusive) |
| 4140 | * @param flags The op flags |
| 4141 | * |
Philip P. Moltmann | 7c0524f | 2020-02-06 09:21:31 -0800 | [diff] [blame] | 4142 | * @return The proxy info or {@code null} if there was no proxy access |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 4143 | * |
| 4144 | * @see #getLastProxyInfo(int) |
| 4145 | * @see #getLastForegroundProxyInfo(int) |
| 4146 | * @see #getLastBackgroundProxyInfo(int) |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 4147 | * @see AttributedOpEntry#getLastProxyInfo(int, int, int) |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 4148 | */ |
| 4149 | public @Nullable OpEventProxyInfo getLastProxyInfo(@UidState int fromUidState, |
| 4150 | @UidState int toUidState, @OpFlags int flags) { |
| 4151 | NoteOpEvent lastEvent = getLastAccessEvent(fromUidState, toUidState, flags); |
| 4152 | if (lastEvent == null) { |
| 4153 | return null; |
| 4154 | } |
| 4155 | |
Philip P. Moltmann | d8c0bda | 2019-12-19 19:55:35 -0800 | [diff] [blame] | 4156 | return lastEvent.getProxy(); |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 4157 | } |
| 4158 | |
| 4159 | |
| 4160 | |
| 4161 | // Code below generated by codegen v1.0.14. |
| 4162 | // |
| 4163 | // DO NOT MODIFY! |
| 4164 | // CHECKSTYLE:OFF Generated code |
| 4165 | // |
| 4166 | // To regenerate run: |
| 4167 | // $ codegen $ANDROID_BUILD_TOP/frameworks/base/core/java/android/app/AppOpsManager.java |
| 4168 | // |
| 4169 | // To exclude the generated code from IntelliJ auto-formatting enable (one-time): |
| 4170 | // Settings > Editor > Code Style > Formatter Control |
| 4171 | //@formatter:off |
| 4172 | |
| 4173 | |
| 4174 | /** |
| 4175 | * Creates a new OpEntry. |
| 4176 | * |
| 4177 | * @param op |
| 4178 | * The code of the op |
| 4179 | * @param mode |
| 4180 | * The mode of the op |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 4181 | * @param attributedOpEntries |
| 4182 | * The attributions that have been used when noting the op |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 4183 | * @hide |
| 4184 | */ |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 4185 | @DataClass.Generated.Member |
| 4186 | public OpEntry( |
| 4187 | @IntRange(from = 0, to = _NUM_OP - 1) int op, |
| 4188 | @Mode int mode, |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 4189 | @NonNull Map<String, AttributedOpEntry> attributedOpEntries) { |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 4190 | this.mOp = op; |
| 4191 | com.android.internal.util.AnnotationValidations.validate( |
| 4192 | IntRange.class, null, mOp, |
| 4193 | "from", 0, |
| 4194 | "to", _NUM_OP - 1); |
| 4195 | this.mMode = mode; |
| 4196 | com.android.internal.util.AnnotationValidations.validate( |
| 4197 | Mode.class, null, mMode); |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 4198 | this.mAttributedOpEntries = attributedOpEntries; |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 4199 | com.android.internal.util.AnnotationValidations.validate( |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 4200 | NonNull.class, null, mAttributedOpEntries); |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 4201 | |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 4202 | // onConstructed(); // You can define this method to get a callback |
| 4203 | } |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 4204 | |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 4205 | /** |
| 4206 | * The mode of the op |
| 4207 | */ |
| 4208 | @DataClass.Generated.Member |
| 4209 | public @Mode int getMode() { |
| 4210 | return mMode; |
| 4211 | } |
| 4212 | |
| 4213 | /** |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 4214 | * The attributed entries keyed by attribution tag. |
Philip P. Moltmann | 3f9ee36 | 2020-02-06 09:32:28 -0800 | [diff] [blame] | 4215 | * |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 4216 | * @see Context#createAttributionContext(String) |
Philip P. Moltmann | 3f9ee36 | 2020-02-06 09:32:28 -0800 | [diff] [blame] | 4217 | * @see #noteOp(String, int, String, String, String) |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 4218 | */ |
| 4219 | @DataClass.Generated.Member |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 4220 | public @NonNull Map<String, AttributedOpEntry> getAttributedOpEntries() { |
| 4221 | return mAttributedOpEntries; |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 4222 | } |
| 4223 | |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 4224 | @Override |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 4225 | @DataClass.Generated.Member |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 4226 | public void writeToParcel(Parcel dest, int flags) { |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 4227 | // You can override field parcelling by defining methods like: |
| 4228 | // void parcelFieldName(Parcel dest, int flags) { ... } |
| 4229 | |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 4230 | dest.writeInt(mOp); |
Dianne Hackborn | 5e45ee6 | 2013-01-24 19:13:44 -0800 | [diff] [blame] | 4231 | dest.writeInt(mMode); |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 4232 | dest.writeMap(mAttributedOpEntries); |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 4233 | } |
| 4234 | |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 4235 | @Override |
| 4236 | @DataClass.Generated.Member |
| 4237 | public int describeContents() { return 0; } |
| 4238 | |
| 4239 | /** @hide */ |
| 4240 | @SuppressWarnings({"unchecked", "RedundantCast"}) |
| 4241 | @DataClass.Generated.Member |
| 4242 | /* package-private */ OpEntry(@NonNull Parcel in) { |
| 4243 | // You can override field unparcelling by defining methods like: |
| 4244 | // static FieldType unparcelFieldName(Parcel in) { ... } |
| 4245 | |
| 4246 | int op = in.readInt(); |
| 4247 | int mode = in.readInt(); |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 4248 | Map<String, AttributedOpEntry> attributions = new java.util.LinkedHashMap<>(); |
| 4249 | in.readMap(attributions, AttributedOpEntry.class.getClassLoader()); |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 4250 | |
| 4251 | this.mOp = op; |
| 4252 | com.android.internal.util.AnnotationValidations.validate( |
| 4253 | IntRange.class, null, mOp, |
| 4254 | "from", 0, |
| 4255 | "to", _NUM_OP - 1); |
| 4256 | this.mMode = mode; |
| 4257 | com.android.internal.util.AnnotationValidations.validate( |
| 4258 | Mode.class, null, mMode); |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 4259 | this.mAttributedOpEntries = attributions; |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 4260 | com.android.internal.util.AnnotationValidations.validate( |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 4261 | NonNull.class, null, mAttributedOpEntries); |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 4262 | |
| 4263 | // onConstructed(); // You can define this method to get a callback |
| 4264 | } |
| 4265 | |
| 4266 | @DataClass.Generated.Member |
| 4267 | public static final @NonNull Parcelable.Creator<OpEntry> CREATOR |
| 4268 | = new Parcelable.Creator<OpEntry>() { |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 4269 | @Override |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 4270 | public OpEntry[] newArray(int size) { |
| 4271 | return new OpEntry[size]; |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 4272 | } |
| 4273 | |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 4274 | @Override |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 4275 | public OpEntry createFromParcel(@NonNull Parcel in) { |
| 4276 | return new OpEntry(in); |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 4277 | } |
| 4278 | }; |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 4279 | |
| 4280 | /* |
| 4281 | @DataClass.Generated( |
| 4282 | time = 1574809856259L, |
| 4283 | codegenVersion = "1.0.14", |
| 4284 | sourceFile = "frameworks/base/core/java/android/app/AppOpsManager.java", |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 4285 | inputSignatures = "private final @android.annotation.IntRange(from=0L, to=_NUM_OP - 1) int mOp\nprivate final @android.app.Mode int mMode\nprivate final @android.annotation.NonNull java.util.Map<java.lang.String,android.app.OpAttributionEntry> mAttributions\npublic @android.annotation.UnsupportedAppUsage(maxTargetSdk=Build.VERSION_CODES.Q, publicAlternatives=\"{@code \" + \"#getOpStr()}\") int getOp()\npublic @android.annotation.NonNull java.lang.String getOpStr()\npublic @java.lang.Deprecated @android.annotation.UnsupportedAppUsage(maxTargetSdk=Build.VERSION_CODES.Q, publicAlternatives=\"{@code \" + \"#getAccessTime(int, int)}\") long getTime()\npublic @java.lang.Deprecated long getLastAccessTime(int)\npublic @java.lang.Deprecated long getLastAccessForegroundTime(int)\npublic @java.lang.Deprecated long getLastAccessBackgroundTime(int)\npublic @java.lang.Deprecated long getLastAccessTime(int,int,int)\npublic @java.lang.Deprecated @android.annotation.UnsupportedAppUsage(maxTargetSdk=Build.VERSION_CODES.Q, publicAlternatives=\"{@code \" + \"#getLastRejectTime(int, int, int)}\") long getRejectTime()\npublic @java.lang.Deprecated long getLastRejectTime(int)\npublic @java.lang.Deprecated long getLastRejectForegroundTime(int)\npublic @java.lang.Deprecated long getLastRejectBackgroundTime(int)\npublic @java.lang.Deprecated long getLastRejectTime(int,int,int)\npublic long getAccessTime(int,int)\npublic long getRejectTime(int,int)\npublic boolean isRunning()\nprivate android.app.NoteOpEvent getLastAccessEvent(int,int,int)\npublic @java.lang.Deprecated long getDuration()\npublic @java.lang.Deprecated long getLastForegroundDuration(int)\npublic @java.lang.Deprecated long getLastBackgroundDuration(int)\npublic @java.lang.Deprecated long getLastDuration(int,int,int)\npublic @java.lang.Deprecated int getProxyUid()\npublic @java.lang.Deprecated @android.annotation.Nullable java.lang.String getProxyPackageName()\nprivate @android.app.UidState int getLastAccessUidStateForFlagsInStatesOfAllAttributions(int,int,int)\npublic @android.app.UidState int getLastAccessUidState(int)\npublic @android.app.UidState int getLastForegroundAccessUidState(int)\npublic @android.app.UidState int getLastBackgroundAccessUidState(int)\nprivate @android.app.UidState int getLastRejectUidStateForFlagsInStatesOfAllAttributions(int,int,int)\npublic @android.app.UidState int getLastRejectUidState(int)\npublic @android.app.UidState int getLastForegroundRejectUidState(int)\npublic @android.app.UidState int getLastBackgroundRejectUidState(int)\npublic long getDuration(int,int)\npublic int getProxyUid(int,int)\nprivate int getProxyUid(int,int,int)\npublic @android.annotation.Nullable java.lang.String getProxyPackageName(int,int)\nprivate @android.annotation.Nullable java.lang.String getProxyPackageName(int,int,int)\nclass OpEntry extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genHiddenConstructor=true)") |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 4286 | @Deprecated |
| 4287 | private void __metadata() {} |
| 4288 | */ |
| 4289 | |
| 4290 | |
| 4291 | //@formatter:on |
| 4292 | // End of generated code |
| 4293 | |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 4294 | } |
| 4295 | |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 4296 | /** @hide */ |
| 4297 | public interface HistoricalOpsVisitor { |
| 4298 | void visitHistoricalOps(@NonNull HistoricalOps ops); |
| 4299 | void visitHistoricalUidOps(@NonNull HistoricalUidOps ops); |
| 4300 | void visitHistoricalPackageOps(@NonNull HistoricalPackageOps ops); |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 4301 | void visitHistoricalAttributionOps(@NonNull AttributedHistoricalOps ops); |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 4302 | void visitHistoricalOp(@NonNull HistoricalOp ops); |
| 4303 | } |
| 4304 | |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 4305 | /** |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 4306 | * Specifies what parameters to filter historical appop requests for |
| 4307 | * |
| 4308 | * @hide |
| 4309 | */ |
| 4310 | @Retention(RetentionPolicy.SOURCE) |
| 4311 | @IntDef(flag = true, prefix = { "FILTER_BY_" }, value = { |
| 4312 | FILTER_BY_UID, |
| 4313 | FILTER_BY_PACKAGE_NAME, |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 4314 | FILTER_BY_ATTRIBUTION_TAG, |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 4315 | FILTER_BY_OP_NAMES |
| 4316 | }) |
| 4317 | public @interface HistoricalOpsRequestFilter {} |
| 4318 | |
| 4319 | /** |
| 4320 | * Filter historical appop request by uid. |
| 4321 | * |
| 4322 | * @hide |
| 4323 | */ |
| 4324 | public static final int FILTER_BY_UID = 1<<0; |
| 4325 | |
| 4326 | /** |
| 4327 | * Filter historical appop request by package name. |
| 4328 | * |
| 4329 | * @hide |
| 4330 | */ |
| 4331 | public static final int FILTER_BY_PACKAGE_NAME = 1<<1; |
| 4332 | |
| 4333 | /** |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 4334 | * Filter historical appop request by attribution tag. |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 4335 | * |
| 4336 | * @hide |
| 4337 | */ |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 4338 | public static final int FILTER_BY_ATTRIBUTION_TAG = 1<<2; |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 4339 | |
| 4340 | /** |
| 4341 | * Filter historical appop request by op names. |
| 4342 | * |
| 4343 | * @hide |
| 4344 | */ |
| 4345 | public static final int FILTER_BY_OP_NAMES = 1<<3; |
| 4346 | |
| 4347 | /** |
Svet Ganov | 23c88db | 2019-01-22 20:38:11 -0800 | [diff] [blame] | 4348 | * Request for getting historical app op usage. The request acts |
| 4349 | * as a filtering criteria when querying historical op usage. |
| 4350 | * |
| 4351 | * @hide |
| 4352 | */ |
| 4353 | @Immutable |
| 4354 | @TestApi |
| 4355 | @SystemApi |
| 4356 | public static final class HistoricalOpsRequest { |
| 4357 | private final int mUid; |
| 4358 | private final @Nullable String mPackageName; |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 4359 | private final @Nullable String mAttributionTag; |
Svet Ganov | 23c88db | 2019-01-22 20:38:11 -0800 | [diff] [blame] | 4360 | private final @Nullable List<String> mOpNames; |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 4361 | private final @HistoricalOpsRequestFilter int mFilter; |
Svet Ganov | 23c88db | 2019-01-22 20:38:11 -0800 | [diff] [blame] | 4362 | private final long mBeginTimeMillis; |
| 4363 | private final long mEndTimeMillis; |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 4364 | private final @OpFlags int mFlags; |
Svet Ganov | 23c88db | 2019-01-22 20:38:11 -0800 | [diff] [blame] | 4365 | |
| 4366 | private HistoricalOpsRequest(int uid, @Nullable String packageName, |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 4367 | @Nullable String attributionTag, @Nullable List<String> opNames, |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 4368 | @HistoricalOpsRequestFilter int filter, long beginTimeMillis, |
| 4369 | long endTimeMillis, @OpFlags int flags) { |
Svet Ganov | 23c88db | 2019-01-22 20:38:11 -0800 | [diff] [blame] | 4370 | mUid = uid; |
| 4371 | mPackageName = packageName; |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 4372 | mAttributionTag = attributionTag; |
Svet Ganov | 23c88db | 2019-01-22 20:38:11 -0800 | [diff] [blame] | 4373 | mOpNames = opNames; |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 4374 | mFilter = filter; |
Svet Ganov | 23c88db | 2019-01-22 20:38:11 -0800 | [diff] [blame] | 4375 | mBeginTimeMillis = beginTimeMillis; |
| 4376 | mEndTimeMillis = endTimeMillis; |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 4377 | mFlags = flags; |
Svet Ganov | 23c88db | 2019-01-22 20:38:11 -0800 | [diff] [blame] | 4378 | } |
| 4379 | |
| 4380 | /** |
| 4381 | * Builder for creating a {@link HistoricalOpsRequest}. |
| 4382 | * |
| 4383 | * @hide |
| 4384 | */ |
| 4385 | @TestApi |
| 4386 | @SystemApi |
| 4387 | public static final class Builder { |
| 4388 | private int mUid = Process.INVALID_UID; |
| 4389 | private @Nullable String mPackageName; |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 4390 | private @Nullable String mAttributionTag; |
Svet Ganov | 23c88db | 2019-01-22 20:38:11 -0800 | [diff] [blame] | 4391 | private @Nullable List<String> mOpNames; |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 4392 | private @HistoricalOpsRequestFilter int mFilter; |
Svet Ganov | 23c88db | 2019-01-22 20:38:11 -0800 | [diff] [blame] | 4393 | private final long mBeginTimeMillis; |
| 4394 | private final long mEndTimeMillis; |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 4395 | private @OpFlags int mFlags = OP_FLAGS_ALL; |
Svet Ganov | 23c88db | 2019-01-22 20:38:11 -0800 | [diff] [blame] | 4396 | |
| 4397 | /** |
| 4398 | * Creates a new builder. |
| 4399 | * |
| 4400 | * @param beginTimeMillis The beginning of the interval in milliseconds since |
| 4401 | * epoch start (January 1, 1970 00:00:00.000 GMT - Gregorian). Must be non |
| 4402 | * negative. |
| 4403 | * @param endTimeMillis The end of the interval in milliseconds since |
| 4404 | * epoch start (January 1, 1970 00:00:00.000 GMT - Gregorian). Must be after |
| 4405 | * {@code beginTimeMillis}. Pass {@link Long#MAX_VALUE} to get the most recent |
| 4406 | * history including ops that happen while this call is in flight. |
| 4407 | */ |
| 4408 | public Builder(long beginTimeMillis, long endTimeMillis) { |
| 4409 | Preconditions.checkArgument(beginTimeMillis >= 0 && beginTimeMillis < endTimeMillis, |
| 4410 | "beginTimeMillis must be non negative and lesser than endTimeMillis"); |
| 4411 | mBeginTimeMillis = beginTimeMillis; |
| 4412 | mEndTimeMillis = endTimeMillis; |
| 4413 | } |
| 4414 | |
| 4415 | /** |
| 4416 | * Sets the UID to query for. |
| 4417 | * |
| 4418 | * @param uid The uid. Pass {@link android.os.Process#INVALID_UID} for any uid. |
| 4419 | * @return This builder. |
| 4420 | */ |
| 4421 | public @NonNull Builder setUid(int uid) { |
| 4422 | Preconditions.checkArgument(uid == Process.INVALID_UID || uid >= 0, |
| 4423 | "uid must be " + Process.INVALID_UID + " or non negative"); |
| 4424 | mUid = uid; |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 4425 | |
| 4426 | if (uid == Process.INVALID_UID) { |
| 4427 | mFilter &= ~FILTER_BY_UID; |
| 4428 | } else { |
| 4429 | mFilter |= FILTER_BY_UID; |
| 4430 | } |
| 4431 | |
Svet Ganov | 23c88db | 2019-01-22 20:38:11 -0800 | [diff] [blame] | 4432 | return this; |
| 4433 | } |
| 4434 | |
| 4435 | /** |
| 4436 | * Sets the package to query for. |
| 4437 | * |
| 4438 | * @param packageName The package name. <code>Null</code> for any package. |
| 4439 | * @return This builder. |
| 4440 | */ |
| 4441 | public @NonNull Builder setPackageName(@Nullable String packageName) { |
| 4442 | mPackageName = packageName; |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 4443 | |
| 4444 | if (packageName == null) { |
| 4445 | mFilter &= ~FILTER_BY_PACKAGE_NAME; |
| 4446 | } else { |
| 4447 | mFilter |= FILTER_BY_PACKAGE_NAME; |
| 4448 | } |
| 4449 | |
| 4450 | return this; |
| 4451 | } |
| 4452 | |
| 4453 | /** |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 4454 | * Sets the attribution tag to query for. |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 4455 | * |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 4456 | * @param attributionTag attribution tag |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 4457 | * @return This builder. |
| 4458 | */ |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 4459 | public @NonNull Builder setAttributionTag(@Nullable String attributionTag) { |
| 4460 | mAttributionTag = attributionTag; |
| 4461 | mFilter |= FILTER_BY_ATTRIBUTION_TAG; |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 4462 | |
Svet Ganov | 23c88db | 2019-01-22 20:38:11 -0800 | [diff] [blame] | 4463 | return this; |
| 4464 | } |
| 4465 | |
| 4466 | /** |
| 4467 | * Sets the op names to query for. |
| 4468 | * |
| 4469 | * @param opNames The op names. <code>Null</code> for any op. |
| 4470 | * @return This builder. |
| 4471 | */ |
| 4472 | public @NonNull Builder setOpNames(@Nullable List<String> opNames) { |
| 4473 | if (opNames != null) { |
| 4474 | final int opCount = opNames.size(); |
| 4475 | for (int i = 0; i < opCount; i++) { |
| 4476 | Preconditions.checkArgument(AppOpsManager.strOpToOp( |
| 4477 | opNames.get(i)) != AppOpsManager.OP_NONE); |
| 4478 | } |
| 4479 | } |
| 4480 | mOpNames = opNames; |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 4481 | |
| 4482 | if (mOpNames == null) { |
| 4483 | mFilter &= ~FILTER_BY_OP_NAMES; |
| 4484 | } else { |
| 4485 | mFilter |= FILTER_BY_OP_NAMES; |
| 4486 | } |
| 4487 | |
Svet Ganov | 23c88db | 2019-01-22 20:38:11 -0800 | [diff] [blame] | 4488 | return this; |
| 4489 | } |
| 4490 | |
| 4491 | /** |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 4492 | * Sets the op flags to query for. The flags specify the type of |
| 4493 | * op data being queried. |
| 4494 | * |
| 4495 | * @param flags The flags which are any combination of |
| 4496 | * {@link #OP_FLAG_SELF}, {@link #OP_FLAG_TRUSTED_PROXY}, |
| 4497 | * {@link #OP_FLAG_UNTRUSTED_PROXY}, {@link #OP_FLAG_TRUSTED_PROXIED}, |
| 4498 | * {@link #OP_FLAG_UNTRUSTED_PROXIED}. You can use {@link #OP_FLAGS_ALL} |
| 4499 | * for any flag. |
| 4500 | * @return This builder. |
| 4501 | */ |
| 4502 | public @NonNull Builder setFlags(@OpFlags int flags) { |
| 4503 | Preconditions.checkFlagsArgument(flags, OP_FLAGS_ALL); |
| 4504 | mFlags = flags; |
| 4505 | return this; |
| 4506 | } |
| 4507 | |
| 4508 | /** |
Svet Ganov | 23c88db | 2019-01-22 20:38:11 -0800 | [diff] [blame] | 4509 | * @return a new {@link HistoricalOpsRequest}. |
| 4510 | */ |
| 4511 | public @NonNull HistoricalOpsRequest build() { |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 4512 | return new HistoricalOpsRequest(mUid, mPackageName, mAttributionTag, mOpNames, |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 4513 | mFilter, mBeginTimeMillis, mEndTimeMillis, mFlags); |
Svet Ganov | 23c88db | 2019-01-22 20:38:11 -0800 | [diff] [blame] | 4514 | } |
| 4515 | } |
| 4516 | } |
| 4517 | |
| 4518 | /** |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 4519 | * This class represents historical app op state of all UIDs for a given time interval. |
| 4520 | * |
| 4521 | * @hide |
| 4522 | */ |
| 4523 | @TestApi |
| 4524 | @SystemApi |
| 4525 | public static final class HistoricalOps implements Parcelable { |
| 4526 | private long mBeginTimeMillis; |
| 4527 | private long mEndTimeMillis; |
| 4528 | private @Nullable SparseArray<HistoricalUidOps> mHistoricalUidOps; |
| 4529 | |
| 4530 | /** @hide */ |
| 4531 | @TestApi |
| 4532 | public HistoricalOps(long beginTimeMillis, long endTimeMillis) { |
| 4533 | Preconditions.checkState(beginTimeMillis <= endTimeMillis); |
| 4534 | mBeginTimeMillis = beginTimeMillis; |
| 4535 | mEndTimeMillis = endTimeMillis; |
| 4536 | } |
| 4537 | |
| 4538 | /** @hide */ |
| 4539 | public HistoricalOps(@NonNull HistoricalOps other) { |
| 4540 | mBeginTimeMillis = other.mBeginTimeMillis; |
| 4541 | mEndTimeMillis = other.mEndTimeMillis; |
| 4542 | Preconditions.checkState(mBeginTimeMillis <= mEndTimeMillis); |
| 4543 | if (other.mHistoricalUidOps != null) { |
| 4544 | final int opCount = other.getUidCount(); |
| 4545 | for (int i = 0; i < opCount; i++) { |
| 4546 | final HistoricalUidOps origOps = other.getUidOpsAt(i); |
| 4547 | final HistoricalUidOps clonedOps = new HistoricalUidOps(origOps); |
| 4548 | if (mHistoricalUidOps == null) { |
| 4549 | mHistoricalUidOps = new SparseArray<>(opCount); |
| 4550 | } |
| 4551 | mHistoricalUidOps.put(clonedOps.getUid(), clonedOps); |
| 4552 | } |
| 4553 | } |
| 4554 | } |
| 4555 | |
| 4556 | private HistoricalOps(Parcel parcel) { |
| 4557 | mBeginTimeMillis = parcel.readLong(); |
| 4558 | mEndTimeMillis = parcel.readLong(); |
| 4559 | final int[] uids = parcel.createIntArray(); |
| 4560 | if (!ArrayUtils.isEmpty(uids)) { |
| 4561 | final ParceledListSlice<HistoricalUidOps> listSlice = parcel.readParcelable( |
| 4562 | HistoricalOps.class.getClassLoader()); |
| 4563 | final List<HistoricalUidOps> uidOps = (listSlice != null) |
| 4564 | ? listSlice.getList() : null; |
| 4565 | if (uidOps == null) { |
| 4566 | return; |
| 4567 | } |
| 4568 | for (int i = 0; i < uids.length; i++) { |
| 4569 | if (mHistoricalUidOps == null) { |
| 4570 | mHistoricalUidOps = new SparseArray<>(); |
| 4571 | } |
| 4572 | mHistoricalUidOps.put(uids[i], uidOps.get(i)); |
| 4573 | } |
| 4574 | } |
| 4575 | } |
| 4576 | |
| 4577 | /** |
| 4578 | * Splice a piece from the beginning of these ops. |
| 4579 | * |
| 4580 | * @param splicePoint The fraction of the data to be spliced off. |
| 4581 | * |
| 4582 | * @hide |
| 4583 | */ |
| 4584 | public @NonNull HistoricalOps spliceFromBeginning(double splicePoint) { |
| 4585 | return splice(splicePoint, true); |
| 4586 | } |
| 4587 | |
| 4588 | /** |
| 4589 | * Splice a piece from the end of these ops. |
| 4590 | * |
| 4591 | * @param fractionToRemove The fraction of the data to be spliced off. |
| 4592 | * |
| 4593 | * @hide |
| 4594 | */ |
| 4595 | public @NonNull HistoricalOps spliceFromEnd(double fractionToRemove) { |
| 4596 | return splice(fractionToRemove, false); |
| 4597 | } |
| 4598 | |
| 4599 | /** |
| 4600 | * Splice a piece from the beginning or end of these ops. |
| 4601 | * |
| 4602 | * @param fractionToRemove The fraction of the data to be spliced off. |
| 4603 | * @param beginning Whether to splice off the beginning or the end. |
| 4604 | * |
| 4605 | * @return The spliced off part. |
| 4606 | * |
| 4607 | * @hide |
| 4608 | */ |
| 4609 | private @Nullable HistoricalOps splice(double fractionToRemove, boolean beginning) { |
| 4610 | final long spliceBeginTimeMills; |
| 4611 | final long spliceEndTimeMills; |
| 4612 | if (beginning) { |
| 4613 | spliceBeginTimeMills = mBeginTimeMillis; |
| 4614 | spliceEndTimeMills = (long) (mBeginTimeMillis |
| 4615 | + getDurationMillis() * fractionToRemove); |
| 4616 | mBeginTimeMillis = spliceEndTimeMills; |
| 4617 | } else { |
| 4618 | spliceBeginTimeMills = (long) (mEndTimeMillis |
| 4619 | - getDurationMillis() * fractionToRemove); |
| 4620 | spliceEndTimeMills = mEndTimeMillis; |
| 4621 | mEndTimeMillis = spliceBeginTimeMills; |
| 4622 | } |
| 4623 | |
| 4624 | HistoricalOps splice = null; |
| 4625 | final int uidCount = getUidCount(); |
| 4626 | for (int i = 0; i < uidCount; i++) { |
| 4627 | final HistoricalUidOps origOps = getUidOpsAt(i); |
| 4628 | final HistoricalUidOps spliceOps = origOps.splice(fractionToRemove); |
| 4629 | if (spliceOps != null) { |
| 4630 | if (splice == null) { |
| 4631 | splice = new HistoricalOps(spliceBeginTimeMills, spliceEndTimeMills); |
| 4632 | } |
| 4633 | if (splice.mHistoricalUidOps == null) { |
| 4634 | splice.mHistoricalUidOps = new SparseArray<>(); |
| 4635 | } |
| 4636 | splice.mHistoricalUidOps.put(spliceOps.getUid(), spliceOps); |
| 4637 | } |
| 4638 | } |
| 4639 | return splice; |
| 4640 | } |
| 4641 | |
| 4642 | /** |
| 4643 | * Merge the passed ops into the current ones. The time interval is a |
| 4644 | * union of the current and passed in one and the passed in data is |
| 4645 | * folded into the data of this instance. |
| 4646 | * |
| 4647 | * @hide |
| 4648 | */ |
| 4649 | public void merge(@NonNull HistoricalOps other) { |
| 4650 | mBeginTimeMillis = Math.min(mBeginTimeMillis, other.mBeginTimeMillis); |
| 4651 | mEndTimeMillis = Math.max(mEndTimeMillis, other.mEndTimeMillis); |
| 4652 | final int uidCount = other.getUidCount(); |
| 4653 | for (int i = 0; i < uidCount; i++) { |
| 4654 | final HistoricalUidOps otherUidOps = other.getUidOpsAt(i); |
| 4655 | final HistoricalUidOps thisUidOps = getUidOps(otherUidOps.getUid()); |
| 4656 | if (thisUidOps != null) { |
| 4657 | thisUidOps.merge(otherUidOps); |
| 4658 | } else { |
| 4659 | if (mHistoricalUidOps == null) { |
| 4660 | mHistoricalUidOps = new SparseArray<>(); |
| 4661 | } |
| 4662 | mHistoricalUidOps.put(otherUidOps.getUid(), otherUidOps); |
| 4663 | } |
| 4664 | } |
| 4665 | } |
| 4666 | |
| 4667 | /** |
| 4668 | * AppPermissionUsage the ops to leave only the data we filter for. |
| 4669 | * |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 4670 | * @param uid Uid to filter for. |
| 4671 | * @param packageName Package to filter for. |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 4672 | * @param attributionTag attribution tag to filter for |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 4673 | * @param opNames Ops to filter for. |
| 4674 | * @param filter Which parameters to filter on. |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 4675 | * @param beginTimeMillis The begin time to filter for or {@link Long#MIN_VALUE} for all. |
| 4676 | * @param endTimeMillis The end time to filter for or {@link Long#MAX_VALUE} for all. |
| 4677 | * |
| 4678 | * @hide |
| 4679 | */ |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 4680 | public void filter(int uid, @Nullable String packageName, @Nullable String attributionTag, |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 4681 | @Nullable String[] opNames, @HistoricalOpsRequestFilter int filter, |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 4682 | long beginTimeMillis, long endTimeMillis) { |
| 4683 | final long durationMillis = getDurationMillis(); |
| 4684 | mBeginTimeMillis = Math.max(mBeginTimeMillis, beginTimeMillis); |
| 4685 | mEndTimeMillis = Math.min(mEndTimeMillis, endTimeMillis); |
| 4686 | final double scaleFactor = Math.min((double) (endTimeMillis - beginTimeMillis) |
| 4687 | / (double) durationMillis, 1); |
| 4688 | final int uidCount = getUidCount(); |
| 4689 | for (int i = uidCount - 1; i >= 0; i--) { |
| 4690 | final HistoricalUidOps uidOp = mHistoricalUidOps.valueAt(i); |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 4691 | if ((filter & FILTER_BY_UID) != 0 && uid != uidOp.getUid()) { |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 4692 | mHistoricalUidOps.removeAt(i); |
| 4693 | } else { |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 4694 | uidOp.filter(packageName, attributionTag, opNames, filter, scaleFactor); |
Stanislav Zholnin | 0d9499c | 2020-01-16 13:39:50 +0000 | [diff] [blame] | 4695 | if (uidOp.getPackageCount() == 0) { |
| 4696 | mHistoricalUidOps.removeAt(i); |
| 4697 | } |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 4698 | } |
| 4699 | } |
| 4700 | } |
| 4701 | |
| 4702 | /** @hide */ |
| 4703 | public boolean isEmpty() { |
| 4704 | if (getBeginTimeMillis() >= getEndTimeMillis()) { |
| 4705 | return true; |
| 4706 | } |
| 4707 | final int uidCount = getUidCount(); |
| 4708 | for (int i = uidCount - 1; i >= 0; i--) { |
| 4709 | final HistoricalUidOps uidOp = mHistoricalUidOps.valueAt(i); |
| 4710 | if (!uidOp.isEmpty()) { |
| 4711 | return false; |
| 4712 | } |
| 4713 | } |
| 4714 | return true; |
| 4715 | } |
| 4716 | |
| 4717 | /** @hide */ |
| 4718 | public long getDurationMillis() { |
| 4719 | return mEndTimeMillis - mBeginTimeMillis; |
| 4720 | } |
| 4721 | |
| 4722 | /** @hide */ |
| 4723 | @TestApi |
| 4724 | public void increaseAccessCount(int opCode, int uid, @NonNull String packageName, |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 4725 | @Nullable String attributionTag, @UidState int uidState, @OpFlags int flags, |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 4726 | long increment) { |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 4727 | getOrCreateHistoricalUidOps(uid).increaseAccessCount(opCode, |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 4728 | packageName, attributionTag, uidState, flags, increment); |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 4729 | } |
| 4730 | |
| 4731 | /** @hide */ |
| 4732 | @TestApi |
| 4733 | public void increaseRejectCount(int opCode, int uid, @NonNull String packageName, |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 4734 | @Nullable String attributionTag, @UidState int uidState, @OpFlags int flags, |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 4735 | long increment) { |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 4736 | getOrCreateHistoricalUidOps(uid).increaseRejectCount(opCode, |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 4737 | packageName, attributionTag, uidState, flags, increment); |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 4738 | } |
| 4739 | |
| 4740 | /** @hide */ |
| 4741 | @TestApi |
| 4742 | public void increaseAccessDuration(int opCode, int uid, @NonNull String packageName, |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 4743 | @Nullable String attributionTag, @UidState int uidState, @OpFlags int flags, |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 4744 | long increment) { |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 4745 | getOrCreateHistoricalUidOps(uid).increaseAccessDuration(opCode, |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 4746 | packageName, attributionTag, uidState, flags, increment); |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 4747 | } |
| 4748 | |
| 4749 | /** @hide */ |
| 4750 | @TestApi |
| 4751 | public void offsetBeginAndEndTime(long offsetMillis) { |
| 4752 | mBeginTimeMillis += offsetMillis; |
| 4753 | mEndTimeMillis += offsetMillis; |
| 4754 | } |
| 4755 | |
| 4756 | /** @hide */ |
| 4757 | public void setBeginAndEndTime(long beginTimeMillis, long endTimeMillis) { |
| 4758 | mBeginTimeMillis = beginTimeMillis; |
| 4759 | mEndTimeMillis = endTimeMillis; |
| 4760 | } |
| 4761 | |
| 4762 | /** @hide */ |
| 4763 | public void setBeginTime(long beginTimeMillis) { |
| 4764 | mBeginTimeMillis = beginTimeMillis; |
| 4765 | } |
| 4766 | |
| 4767 | /** @hide */ |
| 4768 | public void setEndTime(long endTimeMillis) { |
| 4769 | mEndTimeMillis = endTimeMillis; |
| 4770 | } |
| 4771 | |
| 4772 | /** |
| 4773 | * @return The beginning of the interval in milliseconds since |
| 4774 | * epoch start (January 1, 1970 00:00:00.000 GMT - Gregorian). |
| 4775 | */ |
| 4776 | public long getBeginTimeMillis() { |
| 4777 | return mBeginTimeMillis; |
| 4778 | } |
| 4779 | |
| 4780 | /** |
| 4781 | * @return The end of the interval in milliseconds since |
| 4782 | * epoch start (January 1, 1970 00:00:00.000 GMT - Gregorian). |
| 4783 | */ |
| 4784 | public long getEndTimeMillis() { |
| 4785 | return mEndTimeMillis; |
| 4786 | } |
| 4787 | |
| 4788 | /** |
| 4789 | * Gets number of UIDs with historical ops. |
| 4790 | * |
| 4791 | * @return The number of UIDs with historical ops. |
| 4792 | * |
| 4793 | * @see #getUidOpsAt(int) |
| 4794 | */ |
Svet Ganov | 00a46ef | 2019-03-29 21:13:03 -0700 | [diff] [blame] | 4795 | public @IntRange(from = 0) int getUidCount() { |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 4796 | if (mHistoricalUidOps == null) { |
| 4797 | return 0; |
| 4798 | } |
| 4799 | return mHistoricalUidOps.size(); |
| 4800 | } |
| 4801 | |
| 4802 | /** |
| 4803 | * Gets the historical UID ops at a given index. |
| 4804 | * |
| 4805 | * @param index The index. |
| 4806 | * |
| 4807 | * @return The historical UID ops at the given index. |
| 4808 | * |
| 4809 | * @see #getUidCount() |
| 4810 | */ |
Svet Ganov | 00a46ef | 2019-03-29 21:13:03 -0700 | [diff] [blame] | 4811 | public @NonNull HistoricalUidOps getUidOpsAt(@IntRange(from = 0) int index) { |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 4812 | if (mHistoricalUidOps == null) { |
| 4813 | throw new IndexOutOfBoundsException(); |
| 4814 | } |
| 4815 | return mHistoricalUidOps.valueAt(index); |
| 4816 | } |
| 4817 | |
| 4818 | /** |
| 4819 | * Gets the historical UID ops for a given UID. |
| 4820 | * |
| 4821 | * @param uid The UID. |
| 4822 | * |
| 4823 | * @return The historical ops for the UID. |
| 4824 | */ |
| 4825 | public @Nullable HistoricalUidOps getUidOps(int uid) { |
| 4826 | if (mHistoricalUidOps == null) { |
| 4827 | return null; |
| 4828 | } |
| 4829 | return mHistoricalUidOps.get(uid); |
| 4830 | } |
| 4831 | |
Winson | 4e3b435 | 2019-05-07 16:29:59 -0700 | [diff] [blame] | 4832 | /** @hide */ |
| 4833 | public void clearHistory(int uid, @NonNull String packageName) { |
| 4834 | HistoricalUidOps historicalUidOps = getOrCreateHistoricalUidOps(uid); |
| 4835 | historicalUidOps.clearHistory(packageName); |
| 4836 | if (historicalUidOps.isEmpty()) { |
| 4837 | mHistoricalUidOps.remove(uid); |
| 4838 | } |
| 4839 | } |
| 4840 | |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 4841 | @Override |
| 4842 | public int describeContents() { |
| 4843 | return 0; |
| 4844 | } |
| 4845 | |
| 4846 | @Override |
| 4847 | public void writeToParcel(Parcel parcel, int flags) { |
| 4848 | parcel.writeLong(mBeginTimeMillis); |
| 4849 | parcel.writeLong(mEndTimeMillis); |
| 4850 | if (mHistoricalUidOps != null) { |
| 4851 | final int uidCount = mHistoricalUidOps.size(); |
| 4852 | parcel.writeInt(uidCount); |
| 4853 | for (int i = 0; i < uidCount; i++) { |
| 4854 | parcel.writeInt(mHistoricalUidOps.keyAt(i)); |
| 4855 | } |
| 4856 | final List<HistoricalUidOps> opsList = new ArrayList<>(uidCount); |
| 4857 | for (int i = 0; i < uidCount; i++) { |
| 4858 | opsList.add(mHistoricalUidOps.valueAt(i)); |
| 4859 | } |
| 4860 | parcel.writeParcelable(new ParceledListSlice<>(opsList), flags); |
| 4861 | } else { |
| 4862 | parcel.writeInt(-1); |
| 4863 | } |
| 4864 | } |
| 4865 | |
| 4866 | /** |
| 4867 | * Accepts a visitor to traverse the ops tree. |
| 4868 | * |
| 4869 | * @param visitor The visitor. |
| 4870 | * |
| 4871 | * @hide |
| 4872 | */ |
| 4873 | public void accept(@NonNull HistoricalOpsVisitor visitor) { |
| 4874 | visitor.visitHistoricalOps(this); |
| 4875 | final int uidCount = getUidCount(); |
| 4876 | for (int i = 0; i < uidCount; i++) { |
| 4877 | getUidOpsAt(i).accept(visitor); |
| 4878 | } |
| 4879 | } |
| 4880 | |
| 4881 | private @NonNull HistoricalUidOps getOrCreateHistoricalUidOps(int uid) { |
| 4882 | if (mHistoricalUidOps == null) { |
| 4883 | mHistoricalUidOps = new SparseArray<>(); |
| 4884 | } |
| 4885 | HistoricalUidOps historicalUidOp = mHistoricalUidOps.get(uid); |
| 4886 | if (historicalUidOp == null) { |
| 4887 | historicalUidOp = new HistoricalUidOps(uid); |
| 4888 | mHistoricalUidOps.put(uid, historicalUidOp); |
| 4889 | } |
| 4890 | return historicalUidOp; |
| 4891 | } |
| 4892 | |
| 4893 | /** |
| 4894 | * @return Rounded value up at the 0.5 boundary. |
| 4895 | * |
| 4896 | * @hide |
| 4897 | */ |
| 4898 | public static double round(double value) { |
| 4899 | final BigDecimal decimalScale = new BigDecimal(value); |
| 4900 | return decimalScale.setScale(0, RoundingMode.HALF_UP).doubleValue(); |
| 4901 | } |
| 4902 | |
| 4903 | @Override |
Aurimas Liutikas | 4d1699d | 2019-08-28 13:01:05 -0700 | [diff] [blame] | 4904 | public boolean equals(@Nullable Object obj) { |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 4905 | if (this == obj) { |
| 4906 | return true; |
| 4907 | } |
| 4908 | if (obj == null || getClass() != obj.getClass()) { |
| 4909 | return false; |
| 4910 | } |
| 4911 | final HistoricalOps other = (HistoricalOps) obj; |
| 4912 | if (mBeginTimeMillis != other.mBeginTimeMillis) { |
| 4913 | return false; |
| 4914 | } |
| 4915 | if (mEndTimeMillis != other.mEndTimeMillis) { |
| 4916 | return false; |
| 4917 | } |
| 4918 | if (mHistoricalUidOps == null) { |
| 4919 | if (other.mHistoricalUidOps != null) { |
| 4920 | return false; |
| 4921 | } |
| 4922 | } else if (!mHistoricalUidOps.equals(other.mHistoricalUidOps)) { |
| 4923 | return false; |
| 4924 | } |
| 4925 | return true; |
| 4926 | } |
| 4927 | |
| 4928 | @Override |
| 4929 | public int hashCode() { |
| 4930 | int result = (int) (mBeginTimeMillis ^ (mBeginTimeMillis >>> 32)); |
| 4931 | result = 31 * result + mHistoricalUidOps.hashCode(); |
| 4932 | return result; |
| 4933 | } |
| 4934 | |
Aurimas Liutikas | 4d1699d | 2019-08-28 13:01:05 -0700 | [diff] [blame] | 4935 | @NonNull |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 4936 | @Override |
| 4937 | public String toString() { |
| 4938 | return getClass().getSimpleName() + "[from:" |
| 4939 | + mBeginTimeMillis + " to:" + mEndTimeMillis + "]"; |
| 4940 | } |
| 4941 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 4942 | public static final @android.annotation.NonNull Creator<HistoricalOps> CREATOR = new Creator<HistoricalOps>() { |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 4943 | @Override |
| 4944 | public @NonNull HistoricalOps createFromParcel(@NonNull Parcel parcel) { |
| 4945 | return new HistoricalOps(parcel); |
| 4946 | } |
| 4947 | |
| 4948 | @Override |
| 4949 | public @NonNull HistoricalOps[] newArray(int size) { |
| 4950 | return new HistoricalOps[size]; |
| 4951 | } |
| 4952 | }; |
| 4953 | } |
| 4954 | |
| 4955 | /** |
| 4956 | * This class represents historical app op state for a UID. |
| 4957 | * |
| 4958 | * @hide |
| 4959 | */ |
| 4960 | @TestApi |
| 4961 | @SystemApi |
| 4962 | public static final class HistoricalUidOps implements Parcelable { |
| 4963 | private final int mUid; |
| 4964 | private @Nullable ArrayMap<String, HistoricalPackageOps> mHistoricalPackageOps; |
| 4965 | |
| 4966 | /** @hide */ |
| 4967 | public HistoricalUidOps(int uid) { |
| 4968 | mUid = uid; |
| 4969 | } |
| 4970 | |
| 4971 | private HistoricalUidOps(@NonNull HistoricalUidOps other) { |
| 4972 | mUid = other.mUid; |
| 4973 | final int opCount = other.getPackageCount(); |
| 4974 | for (int i = 0; i < opCount; i++) { |
| 4975 | final HistoricalPackageOps origOps = other.getPackageOpsAt(i); |
| 4976 | final HistoricalPackageOps cloneOps = new HistoricalPackageOps(origOps); |
| 4977 | if (mHistoricalPackageOps == null) { |
| 4978 | mHistoricalPackageOps = new ArrayMap<>(opCount); |
| 4979 | } |
| 4980 | mHistoricalPackageOps.put(cloneOps.getPackageName(), cloneOps); |
| 4981 | } |
| 4982 | } |
| 4983 | |
| 4984 | private HistoricalUidOps(@NonNull Parcel parcel) { |
| 4985 | // No arg check since we always read from a trusted source. |
| 4986 | mUid = parcel.readInt(); |
| 4987 | mHistoricalPackageOps = parcel.createTypedArrayMap(HistoricalPackageOps.CREATOR); |
| 4988 | } |
| 4989 | |
| 4990 | private @Nullable HistoricalUidOps splice(double fractionToRemove) { |
| 4991 | HistoricalUidOps splice = null; |
| 4992 | final int packageCount = getPackageCount(); |
| 4993 | for (int i = 0; i < packageCount; i++) { |
| 4994 | final HistoricalPackageOps origOps = getPackageOpsAt(i); |
| 4995 | final HistoricalPackageOps spliceOps = origOps.splice(fractionToRemove); |
| 4996 | if (spliceOps != null) { |
| 4997 | if (splice == null) { |
| 4998 | splice = new HistoricalUidOps(mUid); |
| 4999 | } |
| 5000 | if (splice.mHistoricalPackageOps == null) { |
| 5001 | splice.mHistoricalPackageOps = new ArrayMap<>(); |
| 5002 | } |
| 5003 | splice.mHistoricalPackageOps.put(spliceOps.getPackageName(), spliceOps); |
| 5004 | } |
| 5005 | } |
| 5006 | return splice; |
| 5007 | } |
| 5008 | |
| 5009 | private void merge(@NonNull HistoricalUidOps other) { |
| 5010 | final int packageCount = other.getPackageCount(); |
| 5011 | for (int i = 0; i < packageCount; i++) { |
| 5012 | final HistoricalPackageOps otherPackageOps = other.getPackageOpsAt(i); |
| 5013 | final HistoricalPackageOps thisPackageOps = getPackageOps( |
| 5014 | otherPackageOps.getPackageName()); |
| 5015 | if (thisPackageOps != null) { |
| 5016 | thisPackageOps.merge(otherPackageOps); |
| 5017 | } else { |
| 5018 | if (mHistoricalPackageOps == null) { |
| 5019 | mHistoricalPackageOps = new ArrayMap<>(); |
| 5020 | } |
| 5021 | mHistoricalPackageOps.put(otherPackageOps.getPackageName(), otherPackageOps); |
| 5022 | } |
| 5023 | } |
| 5024 | } |
| 5025 | |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5026 | private void filter(@Nullable String packageName, @Nullable String attributionTag, |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5027 | @Nullable String[] opNames, @HistoricalOpsRequestFilter int filter, |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5028 | double fractionToRemove) { |
| 5029 | final int packageCount = getPackageCount(); |
| 5030 | for (int i = packageCount - 1; i >= 0; i--) { |
| 5031 | final HistoricalPackageOps packageOps = getPackageOpsAt(i); |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5032 | if ((filter & FILTER_BY_PACKAGE_NAME) != 0 && !packageName.equals( |
| 5033 | packageOps.getPackageName())) { |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5034 | mHistoricalPackageOps.removeAt(i); |
| 5035 | } else { |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5036 | packageOps.filter(attributionTag, opNames, filter, fractionToRemove); |
| 5037 | if (packageOps.getAttributedOpsCount() == 0) { |
Stanislav Zholnin | 0d9499c | 2020-01-16 13:39:50 +0000 | [diff] [blame] | 5038 | mHistoricalPackageOps.removeAt(i); |
| 5039 | } |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5040 | } |
| 5041 | } |
| 5042 | } |
| 5043 | |
| 5044 | private boolean isEmpty() { |
| 5045 | final int packageCount = getPackageCount(); |
| 5046 | for (int i = packageCount - 1; i >= 0; i--) { |
| 5047 | final HistoricalPackageOps packageOps = mHistoricalPackageOps.valueAt(i); |
| 5048 | if (!packageOps.isEmpty()) { |
| 5049 | return false; |
| 5050 | } |
| 5051 | } |
| 5052 | return true; |
| 5053 | } |
| 5054 | |
| 5055 | private void increaseAccessCount(int opCode, @NonNull String packageName, |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5056 | @Nullable String attributionTag, @UidState int uidState, @OpFlags int flags, |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5057 | long increment) { |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5058 | getOrCreateHistoricalPackageOps(packageName).increaseAccessCount( |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5059 | opCode, attributionTag, uidState, flags, increment); |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5060 | } |
| 5061 | |
| 5062 | private void increaseRejectCount(int opCode, @NonNull String packageName, |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5063 | @Nullable String attributionTag, @UidState int uidState, @OpFlags int flags, |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5064 | long increment) { |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5065 | getOrCreateHistoricalPackageOps(packageName).increaseRejectCount( |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5066 | opCode, attributionTag, uidState, flags, increment); |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5067 | } |
| 5068 | |
| 5069 | private void increaseAccessDuration(int opCode, @NonNull String packageName, |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5070 | @Nullable String attributionTag, @UidState int uidState, @OpFlags int flags, |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5071 | long increment) { |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5072 | getOrCreateHistoricalPackageOps(packageName).increaseAccessDuration( |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5073 | opCode, attributionTag, uidState, flags, increment); |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5074 | } |
| 5075 | |
| 5076 | /** |
| 5077 | * @return The UID for which the data is related. |
| 5078 | */ |
| 5079 | public int getUid() { |
| 5080 | return mUid; |
| 5081 | } |
| 5082 | |
| 5083 | /** |
| 5084 | * Gets number of packages with historical ops. |
| 5085 | * |
| 5086 | * @return The number of packages with historical ops. |
| 5087 | * |
| 5088 | * @see #getPackageOpsAt(int) |
| 5089 | */ |
Svet Ganov | 00a46ef | 2019-03-29 21:13:03 -0700 | [diff] [blame] | 5090 | public @IntRange(from = 0) int getPackageCount() { |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5091 | if (mHistoricalPackageOps == null) { |
| 5092 | return 0; |
| 5093 | } |
| 5094 | return mHistoricalPackageOps.size(); |
| 5095 | } |
| 5096 | |
| 5097 | /** |
| 5098 | * Gets the historical package ops at a given index. |
| 5099 | * |
| 5100 | * @param index The index. |
| 5101 | * |
| 5102 | * @return The historical package ops at the given index. |
| 5103 | * |
| 5104 | * @see #getPackageCount() |
| 5105 | */ |
Svet Ganov | 00a46ef | 2019-03-29 21:13:03 -0700 | [diff] [blame] | 5106 | public @NonNull HistoricalPackageOps getPackageOpsAt(@IntRange(from = 0) int index) { |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5107 | if (mHistoricalPackageOps == null) { |
| 5108 | throw new IndexOutOfBoundsException(); |
| 5109 | } |
| 5110 | return mHistoricalPackageOps.valueAt(index); |
| 5111 | } |
| 5112 | |
| 5113 | /** |
| 5114 | * Gets the historical package ops for a given package. |
| 5115 | * |
| 5116 | * @param packageName The package. |
| 5117 | * |
| 5118 | * @return The historical ops for the package. |
| 5119 | */ |
| 5120 | public @Nullable HistoricalPackageOps getPackageOps(@NonNull String packageName) { |
| 5121 | if (mHistoricalPackageOps == null) { |
| 5122 | return null; |
| 5123 | } |
| 5124 | return mHistoricalPackageOps.get(packageName); |
| 5125 | } |
| 5126 | |
Winson | 4e3b435 | 2019-05-07 16:29:59 -0700 | [diff] [blame] | 5127 | private void clearHistory(@NonNull String packageName) { |
| 5128 | if (mHistoricalPackageOps != null) { |
| 5129 | mHistoricalPackageOps.remove(packageName); |
| 5130 | } |
| 5131 | } |
| 5132 | |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5133 | @Override |
| 5134 | public int describeContents() { |
| 5135 | return 0; |
| 5136 | } |
| 5137 | |
| 5138 | @Override |
| 5139 | public void writeToParcel(Parcel parcel, int flags) { |
| 5140 | parcel.writeInt(mUid); |
| 5141 | parcel.writeTypedArrayMap(mHistoricalPackageOps, flags); |
| 5142 | } |
| 5143 | |
| 5144 | private void accept(@NonNull HistoricalOpsVisitor visitor) { |
| 5145 | visitor.visitHistoricalUidOps(this); |
| 5146 | final int packageCount = getPackageCount(); |
| 5147 | for (int i = 0; i < packageCount; i++) { |
| 5148 | getPackageOpsAt(i).accept(visitor); |
| 5149 | } |
| 5150 | } |
| 5151 | |
| 5152 | private @NonNull HistoricalPackageOps getOrCreateHistoricalPackageOps( |
| 5153 | @NonNull String packageName) { |
| 5154 | if (mHistoricalPackageOps == null) { |
| 5155 | mHistoricalPackageOps = new ArrayMap<>(); |
| 5156 | } |
| 5157 | HistoricalPackageOps historicalPackageOp = mHistoricalPackageOps.get(packageName); |
| 5158 | if (historicalPackageOp == null) { |
| 5159 | historicalPackageOp = new HistoricalPackageOps(packageName); |
| 5160 | mHistoricalPackageOps.put(packageName, historicalPackageOp); |
| 5161 | } |
| 5162 | return historicalPackageOp; |
| 5163 | } |
| 5164 | |
| 5165 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 5166 | public static final @android.annotation.NonNull Creator<HistoricalUidOps> CREATOR = new Creator<HistoricalUidOps>() { |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5167 | @Override |
| 5168 | public @NonNull HistoricalUidOps createFromParcel(@NonNull Parcel parcel) { |
| 5169 | return new HistoricalUidOps(parcel); |
| 5170 | } |
| 5171 | |
| 5172 | @Override |
| 5173 | public @NonNull HistoricalUidOps[] newArray(int size) { |
| 5174 | return new HistoricalUidOps[size]; |
| 5175 | } |
| 5176 | }; |
| 5177 | |
| 5178 | @Override |
Aurimas Liutikas | 4d1699d | 2019-08-28 13:01:05 -0700 | [diff] [blame] | 5179 | public boolean equals(@Nullable Object obj) { |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5180 | if (this == obj) { |
| 5181 | return true; |
| 5182 | } |
| 5183 | if (obj == null || getClass() != obj.getClass()) { |
| 5184 | return false; |
| 5185 | } |
| 5186 | final HistoricalUidOps other = (HistoricalUidOps) obj; |
| 5187 | if (mUid != other.mUid) { |
| 5188 | return false; |
| 5189 | } |
| 5190 | if (mHistoricalPackageOps == null) { |
| 5191 | if (other.mHistoricalPackageOps != null) { |
| 5192 | return false; |
| 5193 | } |
| 5194 | } else if (!mHistoricalPackageOps.equals(other.mHistoricalPackageOps)) { |
| 5195 | return false; |
| 5196 | } |
| 5197 | return true; |
| 5198 | } |
| 5199 | |
| 5200 | @Override |
| 5201 | public int hashCode() { |
| 5202 | int result = mUid; |
| 5203 | result = 31 * result + (mHistoricalPackageOps != null |
| 5204 | ? mHistoricalPackageOps.hashCode() : 0); |
| 5205 | return result; |
| 5206 | } |
| 5207 | } |
| 5208 | |
| 5209 | /** |
| 5210 | * This class represents historical app op information about a package. |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 5211 | * |
| 5212 | * @hide |
| 5213 | */ |
| 5214 | @TestApi |
| 5215 | @SystemApi |
| 5216 | public static final class HistoricalPackageOps implements Parcelable { |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 5217 | private final @NonNull String mPackageName; |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5218 | private @Nullable ArrayMap<String, AttributedHistoricalOps> mAttributedHistoricalOps; |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 5219 | |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5220 | /** @hide */ |
| 5221 | public HistoricalPackageOps(@NonNull String packageName) { |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 5222 | mPackageName = packageName; |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 5223 | } |
| 5224 | |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5225 | private HistoricalPackageOps(@NonNull HistoricalPackageOps other) { |
| 5226 | mPackageName = other.mPackageName; |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5227 | final int opCount = other.getAttributedOpsCount(); |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5228 | for (int i = 0; i < opCount; i++) { |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5229 | final AttributedHistoricalOps origOps = other.getAttributedOpsAt(i); |
| 5230 | final AttributedHistoricalOps cloneOps = new AttributedHistoricalOps(origOps); |
| 5231 | if (mAttributedHistoricalOps == null) { |
| 5232 | mAttributedHistoricalOps = new ArrayMap<>(opCount); |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5233 | } |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5234 | mAttributedHistoricalOps.put(cloneOps.getTag(), cloneOps); |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5235 | } |
| 5236 | } |
| 5237 | |
| 5238 | private HistoricalPackageOps(@NonNull Parcel parcel) { |
| 5239 | mPackageName = parcel.readString(); |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5240 | mAttributedHistoricalOps = parcel.createTypedArrayMap(AttributedHistoricalOps.CREATOR); |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5241 | } |
| 5242 | |
| 5243 | private @Nullable HistoricalPackageOps splice(double fractionToRemove) { |
| 5244 | HistoricalPackageOps splice = null; |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5245 | final int attributionCount = getAttributedOpsCount(); |
| 5246 | for (int i = 0; i < attributionCount; i++) { |
| 5247 | final AttributedHistoricalOps origOps = getAttributedOpsAt(i); |
| 5248 | final AttributedHistoricalOps spliceOps = origOps.splice(fractionToRemove); |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5249 | if (spliceOps != null) { |
| 5250 | if (splice == null) { |
| 5251 | splice = new HistoricalPackageOps(mPackageName); |
| 5252 | } |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5253 | if (splice.mAttributedHistoricalOps == null) { |
| 5254 | splice.mAttributedHistoricalOps = new ArrayMap<>(); |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5255 | } |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5256 | splice.mAttributedHistoricalOps.put(spliceOps.getTag(), spliceOps); |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5257 | } |
| 5258 | } |
| 5259 | return splice; |
| 5260 | } |
| 5261 | |
| 5262 | private void merge(@NonNull HistoricalPackageOps other) { |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5263 | final int attributionCount = other.getAttributedOpsCount(); |
| 5264 | for (int i = 0; i < attributionCount; i++) { |
| 5265 | final AttributedHistoricalOps otherAttributionOps = other.getAttributedOpsAt(i); |
| 5266 | final AttributedHistoricalOps thisAttributionOps = getAttributedOps( |
| 5267 | otherAttributionOps.getTag()); |
| 5268 | if (thisAttributionOps != null) { |
| 5269 | thisAttributionOps.merge(otherAttributionOps); |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5270 | } else { |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5271 | if (mAttributedHistoricalOps == null) { |
| 5272 | mAttributedHistoricalOps = new ArrayMap<>(); |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5273 | } |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5274 | mAttributedHistoricalOps.put(otherAttributionOps.getTag(), |
| 5275 | otherAttributionOps); |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5276 | } |
| 5277 | } |
| 5278 | } |
| 5279 | |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5280 | private void filter(@Nullable String attributionTag, @Nullable String[] opNames, |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5281 | @HistoricalOpsRequestFilter int filter, double fractionToRemove) { |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5282 | final int attributionCount = getAttributedOpsCount(); |
| 5283 | for (int i = attributionCount - 1; i >= 0; i--) { |
| 5284 | final AttributedHistoricalOps attributionOps = getAttributedOpsAt(i); |
| 5285 | if ((filter & FILTER_BY_ATTRIBUTION_TAG) != 0 && !Objects.equals(attributionTag, |
| 5286 | attributionOps.getTag())) { |
| 5287 | mAttributedHistoricalOps.removeAt(i); |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5288 | } else { |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5289 | attributionOps.filter(opNames, filter, fractionToRemove); |
| 5290 | if (attributionOps.getOpCount() == 0) { |
| 5291 | mAttributedHistoricalOps.removeAt(i); |
Stanislav Zholnin | 0d9499c | 2020-01-16 13:39:50 +0000 | [diff] [blame] | 5292 | } |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5293 | } |
| 5294 | } |
| 5295 | } |
| 5296 | |
| 5297 | private void accept(@NonNull HistoricalOpsVisitor visitor) { |
| 5298 | visitor.visitHistoricalPackageOps(this); |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5299 | final int attributionCount = getAttributedOpsCount(); |
| 5300 | for (int i = 0; i < attributionCount; i++) { |
| 5301 | getAttributedOpsAt(i).accept(visitor); |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5302 | } |
| 5303 | } |
| 5304 | |
| 5305 | private boolean isEmpty() { |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5306 | final int attributionCount = getAttributedOpsCount(); |
| 5307 | for (int i = attributionCount - 1; i >= 0; i--) { |
| 5308 | final AttributedHistoricalOps attributionOps = mAttributedHistoricalOps.valueAt(i); |
| 5309 | if (!attributionOps.isEmpty()) { |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5310 | return false; |
| 5311 | } |
| 5312 | } |
| 5313 | return true; |
| 5314 | } |
| 5315 | |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5316 | private void increaseAccessCount(int opCode, @Nullable String attributionTag, |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5317 | @UidState int uidState, @OpFlags int flags, long increment) { |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5318 | getOrCreateAttributedHistoricalOps(attributionTag).increaseAccessCount( |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5319 | opCode, uidState, flags, increment); |
| 5320 | } |
| 5321 | |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5322 | private void increaseRejectCount(int opCode, @Nullable String attributionTag, |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5323 | @UidState int uidState, @OpFlags int flags, long increment) { |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5324 | getOrCreateAttributedHistoricalOps(attributionTag).increaseRejectCount( |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5325 | opCode, uidState, flags, increment); |
| 5326 | } |
| 5327 | |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5328 | private void increaseAccessDuration(int opCode, @Nullable String attributionTag, |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5329 | @UidState int uidState, @OpFlags int flags, long increment) { |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5330 | getOrCreateAttributedHistoricalOps(attributionTag).increaseAccessDuration( |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5331 | opCode, uidState, flags, increment); |
| 5332 | } |
| 5333 | |
| 5334 | /** |
| 5335 | * Gets the package name which the data represents. |
| 5336 | * |
| 5337 | * @return The package name which the data represents. |
| 5338 | */ |
| 5339 | public @NonNull String getPackageName() { |
| 5340 | return mPackageName; |
| 5341 | } |
| 5342 | |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5343 | private @NonNull AttributedHistoricalOps getOrCreateAttributedHistoricalOps( |
| 5344 | @Nullable String attributionTag) { |
| 5345 | if (mAttributedHistoricalOps == null) { |
| 5346 | mAttributedHistoricalOps = new ArrayMap<>(); |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5347 | } |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5348 | AttributedHistoricalOps historicalAttributionOp = mAttributedHistoricalOps.get( |
| 5349 | attributionTag); |
| 5350 | if (historicalAttributionOp == null) { |
| 5351 | historicalAttributionOp = new AttributedHistoricalOps(attributionTag); |
| 5352 | mAttributedHistoricalOps.put(attributionTag, historicalAttributionOp); |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5353 | } |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5354 | return historicalAttributionOp; |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5355 | } |
| 5356 | |
| 5357 | /** |
| 5358 | * Gets number historical app ops. |
| 5359 | * |
| 5360 | * @return The number historical app ops. |
| 5361 | * @see #getOpAt(int) |
| 5362 | */ |
| 5363 | public @IntRange(from = 0) int getOpCount() { |
| 5364 | int numOps = 0; |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5365 | int numAttributions = getAttributedOpsCount(); |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5366 | |
| 5367 | for (int code = 0; code < _NUM_OP; code++) { |
| 5368 | String opName = opToPublicName(code); |
| 5369 | |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5370 | for (int attributionNum = 0; attributionNum < numAttributions; attributionNum++) { |
| 5371 | if (getAttributedOpsAt(attributionNum).getOp(opName) != null) { |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5372 | numOps++; |
| 5373 | break; |
| 5374 | } |
| 5375 | } |
| 5376 | } |
| 5377 | |
| 5378 | return numOps; |
| 5379 | } |
| 5380 | |
| 5381 | /** |
| 5382 | * Gets the historical op at a given index. |
| 5383 | * |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5384 | * <p>This combines the counts from all attributions. |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5385 | * |
| 5386 | * @param index The index to lookup. |
| 5387 | * @return The op at the given index. |
| 5388 | * @see #getOpCount() |
| 5389 | */ |
| 5390 | public @NonNull HistoricalOp getOpAt(@IntRange(from = 0) int index) { |
| 5391 | int numOpsFound = 0; |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5392 | int numAttributions = getAttributedOpsCount(); |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5393 | |
| 5394 | for (int code = 0; code < _NUM_OP; code++) { |
| 5395 | String opName = opToPublicName(code); |
| 5396 | |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5397 | for (int attributionNum = 0; attributionNum < numAttributions; attributionNum++) { |
| 5398 | if (getAttributedOpsAt(attributionNum).getOp(opName) != null) { |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5399 | if (numOpsFound == index) { |
| 5400 | return getOp(opName); |
| 5401 | } else { |
| 5402 | numOpsFound++; |
| 5403 | break; |
| 5404 | } |
| 5405 | } |
| 5406 | } |
| 5407 | } |
| 5408 | |
| 5409 | throw new IndexOutOfBoundsException(); |
| 5410 | } |
| 5411 | |
| 5412 | /** |
| 5413 | * Gets the historical entry for a given op name. |
| 5414 | * |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5415 | * <p>This combines the counts from all attributions. |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5416 | * |
| 5417 | * @param opName The op name. |
| 5418 | * @return The historical entry for that op name. |
| 5419 | */ |
| 5420 | public @Nullable HistoricalOp getOp(@NonNull String opName) { |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5421 | if (mAttributedHistoricalOps == null) { |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5422 | return null; |
| 5423 | } |
| 5424 | |
| 5425 | HistoricalOp combinedOp = null; |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5426 | int numAttributions = getAttributedOpsCount(); |
| 5427 | for (int i = 0; i < numAttributions; i++) { |
| 5428 | HistoricalOp attributionOp = getAttributedOpsAt(i).getOp(opName); |
| 5429 | if (attributionOp != null) { |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5430 | if (combinedOp == null) { |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5431 | combinedOp = new HistoricalOp(attributionOp); |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5432 | } else { |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5433 | combinedOp.merge(attributionOp); |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5434 | } |
| 5435 | } |
| 5436 | } |
| 5437 | |
| 5438 | return combinedOp; |
| 5439 | } |
| 5440 | |
| 5441 | @Override |
| 5442 | public int describeContents() { |
| 5443 | return 0; |
| 5444 | } |
| 5445 | |
| 5446 | @Override |
| 5447 | public void writeToParcel(@NonNull Parcel parcel, int flags) { |
| 5448 | parcel.writeString(mPackageName); |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5449 | parcel.writeTypedArrayMap(mAttributedHistoricalOps, flags); |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5450 | } |
| 5451 | |
| 5452 | public static final @android.annotation.NonNull Creator<HistoricalPackageOps> CREATOR = |
| 5453 | new Creator<HistoricalPackageOps>() { |
| 5454 | @Override |
| 5455 | public @NonNull HistoricalPackageOps createFromParcel(@NonNull Parcel parcel) { |
| 5456 | return new HistoricalPackageOps(parcel); |
| 5457 | } |
| 5458 | |
| 5459 | @Override |
| 5460 | public @NonNull HistoricalPackageOps[] newArray(int size) { |
| 5461 | return new HistoricalPackageOps[size]; |
| 5462 | } |
| 5463 | }; |
| 5464 | |
| 5465 | @Override |
| 5466 | public boolean equals(@Nullable Object obj) { |
| 5467 | if (this == obj) { |
| 5468 | return true; |
| 5469 | } |
| 5470 | if (obj == null || getClass() != obj.getClass()) { |
| 5471 | return false; |
| 5472 | } |
| 5473 | final HistoricalPackageOps other = (HistoricalPackageOps) obj; |
| 5474 | if (!mPackageName.equals(other.mPackageName)) { |
| 5475 | return false; |
| 5476 | } |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5477 | if (mAttributedHistoricalOps == null) { |
| 5478 | if (other.mAttributedHistoricalOps != null) { |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5479 | return false; |
| 5480 | } |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5481 | } else if (!mAttributedHistoricalOps.equals(other.mAttributedHistoricalOps)) { |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5482 | return false; |
| 5483 | } |
| 5484 | return true; |
| 5485 | } |
| 5486 | |
| 5487 | @Override |
| 5488 | public int hashCode() { |
| 5489 | int result = mPackageName != null ? mPackageName.hashCode() : 0; |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5490 | result = 31 * result + (mAttributedHistoricalOps != null |
| 5491 | ? mAttributedHistoricalOps.hashCode() : 0); |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5492 | return result; |
| 5493 | } |
| 5494 | |
| 5495 | /** |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5496 | * Gets number of attributed historical ops. |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5497 | * |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5498 | * @return The number of attribution with historical ops. |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5499 | * |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5500 | * @see #getAttributedOpsAt(int) |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5501 | */ |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5502 | public @IntRange(from = 0) int getAttributedOpsCount() { |
| 5503 | if (mAttributedHistoricalOps == null) { |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5504 | return 0; |
| 5505 | } |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5506 | return mAttributedHistoricalOps.size(); |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5507 | } |
| 5508 | |
| 5509 | /** |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5510 | * Gets the attributed historical ops at a given index. |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5511 | * |
| 5512 | * @param index The index. |
| 5513 | * |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5514 | * @return The historical attribution ops at the given index. |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5515 | * |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5516 | * @see #getAttributedOpsCount() |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5517 | */ |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5518 | public @NonNull AttributedHistoricalOps getAttributedOpsAt(@IntRange(from = 0) int index) { |
| 5519 | if (mAttributedHistoricalOps == null) { |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5520 | throw new IndexOutOfBoundsException(); |
| 5521 | } |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5522 | return mAttributedHistoricalOps.valueAt(index); |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5523 | } |
| 5524 | |
| 5525 | /** |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5526 | * Gets the attributed historical ops for a given attribution tag. |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5527 | * |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5528 | * @param attributionTag The attribution tag. |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5529 | * |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5530 | * @return The historical ops for the attribution. |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5531 | */ |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5532 | public @Nullable AttributedHistoricalOps getAttributedOps(@NonNull String attributionTag) { |
| 5533 | if (mAttributedHistoricalOps == null) { |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5534 | return null; |
| 5535 | } |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5536 | return mAttributedHistoricalOps.get(attributionTag); |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5537 | } |
| 5538 | } |
| 5539 | |
| 5540 | /** |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5541 | * This class represents historical app op information about a attribution in a package. |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5542 | * |
| 5543 | * @hide |
| 5544 | */ |
| 5545 | @TestApi |
| 5546 | @SystemApi |
| 5547 | /* codegen verifier cannot deal with nested class parameters |
| 5548 | @DataClass(genHiddenConstructor = true, |
| 5549 | genEqualsHashCode = true, genHiddenCopyConstructor = true) */ |
| 5550 | @DataClass.Suppress("getHistoricalOps") |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5551 | public static final class AttributedHistoricalOps implements Parcelable { |
| 5552 | /** {@link Context#createAttributionContext attribution} tag */ |
| 5553 | private final @Nullable String mTag; |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5554 | |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5555 | /** Ops for this attribution */ |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5556 | private @Nullable ArrayMap<String, HistoricalOp> mHistoricalOps; |
| 5557 | |
| 5558 | /** @hide */ |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5559 | public AttributedHistoricalOps(@NonNull String tag) { |
| 5560 | mTag = tag; |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5561 | } |
| 5562 | |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5563 | private AttributedHistoricalOps(@NonNull AttributedHistoricalOps other) { |
| 5564 | mTag = other.mTag; |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5565 | final int opCount = other.getOpCount(); |
| 5566 | for (int i = 0; i < opCount; i++) { |
| 5567 | final HistoricalOp origOp = other.getOpAt(i); |
| 5568 | final HistoricalOp cloneOp = new HistoricalOp(origOp); |
| 5569 | if (mHistoricalOps == null) { |
| 5570 | mHistoricalOps = new ArrayMap<>(opCount); |
| 5571 | } |
| 5572 | mHistoricalOps.put(cloneOp.getOpName(), cloneOp); |
| 5573 | } |
| 5574 | } |
| 5575 | |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5576 | private @Nullable AttributedHistoricalOps splice(double fractionToRemove) { |
| 5577 | AttributedHistoricalOps splice = null; |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5578 | final int opCount = getOpCount(); |
| 5579 | for (int i = 0; i < opCount; i++) { |
| 5580 | final HistoricalOp origOps = getOpAt(i); |
| 5581 | final HistoricalOp spliceOps = origOps.splice(fractionToRemove); |
| 5582 | if (spliceOps != null) { |
| 5583 | if (splice == null) { |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5584 | splice = new AttributedHistoricalOps(mTag, null); |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5585 | } |
| 5586 | if (splice.mHistoricalOps == null) { |
| 5587 | splice.mHistoricalOps = new ArrayMap<>(); |
| 5588 | } |
| 5589 | splice.mHistoricalOps.put(spliceOps.getOpName(), spliceOps); |
| 5590 | } |
| 5591 | } |
| 5592 | return splice; |
| 5593 | } |
| 5594 | |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5595 | private void merge(@NonNull AttributedHistoricalOps other) { |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5596 | final int opCount = other.getOpCount(); |
| 5597 | for (int i = 0; i < opCount; i++) { |
| 5598 | final HistoricalOp otherOp = other.getOpAt(i); |
| 5599 | final HistoricalOp thisOp = getOp(otherOp.getOpName()); |
| 5600 | if (thisOp != null) { |
| 5601 | thisOp.merge(otherOp); |
| 5602 | } else { |
| 5603 | if (mHistoricalOps == null) { |
| 5604 | mHistoricalOps = new ArrayMap<>(); |
| 5605 | } |
| 5606 | mHistoricalOps.put(otherOp.getOpName(), otherOp); |
| 5607 | } |
| 5608 | } |
| 5609 | } |
| 5610 | |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5611 | private void filter(@Nullable String[] opNames, @HistoricalOpsRequestFilter int filter, |
| 5612 | double scaleFactor) { |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5613 | final int opCount = getOpCount(); |
| 5614 | for (int i = opCount - 1; i >= 0; i--) { |
| 5615 | final HistoricalOp op = mHistoricalOps.valueAt(i); |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5616 | if ((filter & FILTER_BY_OP_NAMES) != 0 && !ArrayUtils.contains(opNames, |
| 5617 | op.getOpName())) { |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5618 | mHistoricalOps.removeAt(i); |
| 5619 | } else { |
| 5620 | op.filter(scaleFactor); |
| 5621 | } |
| 5622 | } |
| 5623 | } |
| 5624 | |
| 5625 | private boolean isEmpty() { |
| 5626 | final int opCount = getOpCount(); |
| 5627 | for (int i = opCount - 1; i >= 0; i--) { |
| 5628 | final HistoricalOp op = mHistoricalOps.valueAt(i); |
| 5629 | if (!op.isEmpty()) { |
| 5630 | return false; |
| 5631 | } |
| 5632 | } |
| 5633 | return true; |
| 5634 | } |
| 5635 | |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 5636 | private void increaseAccessCount(int opCode, @UidState int uidState, |
| 5637 | @OpFlags int flags, long increment) { |
| 5638 | getOrCreateHistoricalOp(opCode).increaseAccessCount(uidState, flags, increment); |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5639 | } |
| 5640 | |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 5641 | private void increaseRejectCount(int opCode, @UidState int uidState, |
| 5642 | @OpFlags int flags, long increment) { |
| 5643 | getOrCreateHistoricalOp(opCode).increaseRejectCount(uidState, flags, increment); |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5644 | } |
| 5645 | |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 5646 | private void increaseAccessDuration(int opCode, @UidState int uidState, |
| 5647 | @OpFlags int flags, long increment) { |
| 5648 | getOrCreateHistoricalOp(opCode).increaseAccessDuration(uidState, flags, increment); |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 5649 | } |
| 5650 | |
| 5651 | /** |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5652 | * Gets number historical app ops. |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 5653 | * |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5654 | * @return The number historical app ops. |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5655 | * @see #getOpAt(int) |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 5656 | */ |
Svet Ganov | 00a46ef | 2019-03-29 21:13:03 -0700 | [diff] [blame] | 5657 | public @IntRange(from = 0) int getOpCount() { |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5658 | if (mHistoricalOps == null) { |
| 5659 | return 0; |
| 5660 | } |
| 5661 | return mHistoricalOps.size(); |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 5662 | } |
| 5663 | |
| 5664 | /** |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5665 | * Gets the historical op at a given index. |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 5666 | * |
| 5667 | * @param index The index to lookup. |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5668 | * @return The op at the given index. |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5669 | * @see #getOpCount() |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 5670 | */ |
Svet Ganov | 00a46ef | 2019-03-29 21:13:03 -0700 | [diff] [blame] | 5671 | public @NonNull HistoricalOp getOpAt(@IntRange(from = 0) int index) { |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5672 | if (mHistoricalOps == null) { |
| 5673 | throw new IndexOutOfBoundsException(); |
| 5674 | } |
| 5675 | return mHistoricalOps.valueAt(index); |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 5676 | } |
| 5677 | |
| 5678 | /** |
| 5679 | * Gets the historical entry for a given op name. |
| 5680 | * |
| 5681 | * @param opName The op name. |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 5682 | * @return The historical entry for that op name. |
| 5683 | */ |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5684 | public @Nullable HistoricalOp getOp(@NonNull String opName) { |
| 5685 | if (mHistoricalOps == null) { |
| 5686 | return null; |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 5687 | } |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5688 | return mHistoricalOps.get(opName); |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 5689 | } |
| 5690 | |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5691 | private void accept(@NonNull HistoricalOpsVisitor visitor) { |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5692 | visitor.visitHistoricalAttributionOps(this); |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5693 | final int opCount = getOpCount(); |
| 5694 | for (int i = 0; i < opCount; i++) { |
| 5695 | getOpAt(i).accept(visitor); |
| 5696 | } |
| 5697 | } |
| 5698 | |
| 5699 | private @NonNull HistoricalOp getOrCreateHistoricalOp(int opCode) { |
| 5700 | if (mHistoricalOps == null) { |
| 5701 | mHistoricalOps = new ArrayMap<>(); |
| 5702 | } |
| 5703 | final String opStr = sOpToString[opCode]; |
| 5704 | HistoricalOp op = mHistoricalOps.get(opStr); |
| 5705 | if (op == null) { |
| 5706 | op = new HistoricalOp(opCode); |
| 5707 | mHistoricalOps.put(opStr, op); |
| 5708 | } |
| 5709 | return op; |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 5710 | } |
| 5711 | |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5712 | |
| 5713 | |
| 5714 | // Code below generated by codegen v1.0.14. |
| 5715 | // |
| 5716 | // DO NOT MODIFY! |
| 5717 | // CHECKSTYLE:OFF Generated code |
| 5718 | // |
| 5719 | // To regenerate run: |
| 5720 | // $ codegen $ANDROID_BUILD_TOP/frameworks/base/core/java/android/app/AppOpsManager.java |
| 5721 | // |
| 5722 | // To exclude the generated code from IntelliJ auto-formatting enable (one-time): |
| 5723 | // Settings > Editor > Code Style > Formatter Control |
| 5724 | //@formatter:off |
| 5725 | |
| 5726 | |
| 5727 | /** |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5728 | * Creates a new HistoricalAttributionOps. |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5729 | * |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5730 | * @param tag |
| 5731 | * {@link Context#createAttributionContext attribution} tag |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5732 | * @param historicalOps |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5733 | * Ops for this attribution |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5734 | * @hide |
| 5735 | */ |
| 5736 | @DataClass.Generated.Member |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5737 | public AttributedHistoricalOps( |
| 5738 | @Nullable String tag, |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5739 | @Nullable ArrayMap<String,HistoricalOp> historicalOps) { |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5740 | this.mTag = tag; |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5741 | this.mHistoricalOps = historicalOps; |
| 5742 | |
| 5743 | // onConstructed(); // You can define this method to get a callback |
| 5744 | } |
| 5745 | |
| 5746 | /** |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5747 | * {@link Context#createAttributionContext attribution} tag |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5748 | */ |
| 5749 | @DataClass.Generated.Member |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5750 | public @Nullable String getTag() { |
| 5751 | return mTag; |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5752 | } |
| 5753 | |
| 5754 | @Override |
| 5755 | @DataClass.Generated.Member |
| 5756 | public boolean equals(@Nullable Object o) { |
| 5757 | // You can override field equality logic by defining either of the methods like: |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5758 | // boolean fieldNameEquals(HistoricalAttributionOps other) { ... } |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5759 | // boolean fieldNameEquals(FieldType otherValue) { ... } |
| 5760 | |
| 5761 | if (this == o) return true; |
| 5762 | if (o == null || getClass() != o.getClass()) return false; |
| 5763 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5764 | AttributedHistoricalOps that = (AttributedHistoricalOps) o; |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5765 | //noinspection PointlessBooleanExpression |
| 5766 | return true |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5767 | && Objects.equals(mTag, that.mTag) |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5768 | && Objects.equals(mHistoricalOps, that.mHistoricalOps); |
| 5769 | } |
| 5770 | |
| 5771 | @Override |
| 5772 | @DataClass.Generated.Member |
| 5773 | public int hashCode() { |
| 5774 | // You can override field hashCode logic by defining methods like: |
| 5775 | // int fieldNameHashCode() { ... } |
| 5776 | |
| 5777 | int _hash = 1; |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5778 | _hash = 31 * _hash + Objects.hashCode(mTag); |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5779 | _hash = 31 * _hash + Objects.hashCode(mHistoricalOps); |
| 5780 | return _hash; |
| 5781 | } |
| 5782 | |
| 5783 | @Override |
| 5784 | @DataClass.Generated.Member |
| 5785 | public void writeToParcel(@NonNull Parcel dest, int flags) { |
| 5786 | // You can override field parcelling by defining methods like: |
| 5787 | // void parcelFieldName(Parcel dest, int flags) { ... } |
| 5788 | |
| 5789 | byte flg = 0; |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5790 | if (mTag != null) flg |= 0x1; |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5791 | if (mHistoricalOps != null) flg |= 0x2; |
| 5792 | dest.writeByte(flg); |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5793 | if (mTag != null) dest.writeString(mTag); |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5794 | if (mHistoricalOps != null) dest.writeMap(mHistoricalOps); |
| 5795 | } |
| 5796 | |
| 5797 | @Override |
| 5798 | @DataClass.Generated.Member |
| 5799 | public int describeContents() { return 0; } |
| 5800 | |
| 5801 | /** @hide */ |
| 5802 | @SuppressWarnings({"unchecked", "RedundantCast"}) |
| 5803 | @DataClass.Generated.Member |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5804 | /* package-private */ AttributedHistoricalOps(@NonNull Parcel in) { |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5805 | // You can override field unparcelling by defining methods like: |
| 5806 | // static FieldType unparcelFieldName(Parcel in) { ... } |
| 5807 | |
| 5808 | byte flg = in.readByte(); |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5809 | String attributionTag = (flg & 0x1) == 0 ? null : in.readString(); |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5810 | ArrayMap<String,HistoricalOp> historicalOps = null; |
| 5811 | if ((flg & 0x2) != 0) { |
| 5812 | historicalOps = new ArrayMap(); |
| 5813 | in.readMap(historicalOps, HistoricalOp.class.getClassLoader()); |
| 5814 | } |
| 5815 | |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5816 | this.mTag = attributionTag; |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5817 | this.mHistoricalOps = historicalOps; |
| 5818 | |
| 5819 | // onConstructed(); // You can define this method to get a callback |
| 5820 | } |
| 5821 | |
| 5822 | @DataClass.Generated.Member |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5823 | public static final @NonNull Parcelable.Creator<AttributedHistoricalOps> CREATOR |
| 5824 | = new Parcelable.Creator<AttributedHistoricalOps>() { |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 5825 | @Override |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5826 | public AttributedHistoricalOps[] newArray(int size) { |
| 5827 | return new AttributedHistoricalOps[size]; |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 5828 | } |
| 5829 | |
| 5830 | @Override |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5831 | public AttributedHistoricalOps createFromParcel(@NonNull Parcel in) { |
| 5832 | return new AttributedHistoricalOps(in); |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 5833 | } |
| 5834 | }; |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5835 | |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5836 | /* |
| 5837 | @DataClass.Generated( |
| 5838 | time = 1578113234821L, |
| 5839 | codegenVersion = "1.0.14", |
| 5840 | sourceFile = "frameworks/base/core/java/android/app/AppOpsManager.java", |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5841 | inputSignatures = "private final @android.annotation.Nullable java.lang.String mAttributionTag\nprivate @android.annotation.Nullable android.util.ArrayMap<java.lang.String,android.app.HistoricalOp> mHistoricalOps\nprivate @android.annotation.Nullable android.app.HistoricalAttributionOps splice(double)\nprivate void merge(android.app.HistoricalAttributionOps)\nprivate void filter(java.lang.String[],int,double)\nprivate boolean isEmpty()\nprivate void increaseAccessCount(int,int,int,long)\nprivate void increaseRejectCount(int,int,int,long)\nprivate void increaseAccessDuration(int,int,int,long)\npublic @android.annotation.IntRange(from=0L) int getOpCount()\npublic @android.annotation.NonNull android.app.HistoricalOp getOpAt(int)\npublic @android.annotation.Nullable android.app.HistoricalOp getOp(java.lang.String)\nprivate void accept(android.app.HistoricalOpsVisitor)\nprivate @android.annotation.NonNull android.app.HistoricalOp getOrCreateHistoricalOp(int)\nclass HistoricalAttributionOps extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genHiddenConstructor=true, genEqualsHashCode=true, genHiddenCopyConstructor=true)") |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5842 | @Deprecated |
| 5843 | private void __metadata() {} |
| 5844 | */ |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5845 | |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5846 | //@formatter:on |
| 5847 | // End of generated code |
| 5848 | |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 5849 | } |
| 5850 | |
| 5851 | /** |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5852 | * This class represents historical information about an app op. |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 5853 | * |
| 5854 | * @hide |
| 5855 | */ |
| 5856 | @TestApi |
| 5857 | @SystemApi |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5858 | public static final class HistoricalOp implements Parcelable { |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 5859 | private final int mOp; |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 5860 | private @Nullable LongSparseLongArray mAccessCount; |
| 5861 | private @Nullable LongSparseLongArray mRejectCount; |
| 5862 | private @Nullable LongSparseLongArray mAccessDuration; |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 5863 | |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5864 | /** @hide */ |
| 5865 | public HistoricalOp(int op) { |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 5866 | mOp = op; |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 5867 | } |
| 5868 | |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5869 | private HistoricalOp(@NonNull HistoricalOp other) { |
| 5870 | mOp = other.mOp; |
| 5871 | if (other.mAccessCount != null) { |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 5872 | mAccessCount = other.mAccessCount.clone(); |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5873 | } |
| 5874 | if (other.mRejectCount != null) { |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 5875 | mRejectCount = other.mRejectCount.clone(); |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5876 | } |
| 5877 | if (other.mAccessDuration != null) { |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 5878 | mAccessDuration = other.mAccessDuration.clone(); |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5879 | } |
| 5880 | } |
| 5881 | |
| 5882 | private HistoricalOp(@NonNull Parcel parcel) { |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 5883 | mOp = parcel.readInt(); |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 5884 | mAccessCount = readLongSparseLongArrayFromParcel(parcel); |
| 5885 | mRejectCount = readLongSparseLongArrayFromParcel(parcel); |
| 5886 | mAccessDuration = readLongSparseLongArrayFromParcel(parcel); |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 5887 | } |
| 5888 | |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5889 | private void filter(double scaleFactor) { |
| 5890 | scale(mAccessCount, scaleFactor); |
| 5891 | scale(mRejectCount, scaleFactor); |
| 5892 | scale(mAccessDuration, scaleFactor); |
| 5893 | } |
| 5894 | |
| 5895 | private boolean isEmpty() { |
| 5896 | return !hasData(mAccessCount) |
| 5897 | && !hasData(mRejectCount) |
| 5898 | && !hasData(mAccessDuration); |
| 5899 | } |
| 5900 | |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 5901 | private boolean hasData(@NonNull LongSparseLongArray array) { |
| 5902 | return (array != null && array.size() > 0); |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5903 | } |
| 5904 | |
| 5905 | private @Nullable HistoricalOp splice(double fractionToRemove) { |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 5906 | final HistoricalOp splice = new HistoricalOp(mOp); |
| 5907 | splice(mAccessCount, splice::getOrCreateAccessCount, fractionToRemove); |
| 5908 | splice(mRejectCount, splice::getOrCreateRejectCount, fractionToRemove); |
| 5909 | splice(mAccessDuration, splice::getOrCreateAccessDuration, fractionToRemove); |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5910 | return splice; |
| 5911 | } |
| 5912 | |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 5913 | private static void splice(@Nullable LongSparseLongArray sourceContainer, |
| 5914 | @NonNull Supplier<LongSparseLongArray> destContainerProvider, |
| 5915 | double fractionToRemove) { |
| 5916 | if (sourceContainer != null) { |
| 5917 | final int size = sourceContainer.size(); |
| 5918 | for (int i = 0; i < size; i++) { |
| 5919 | final long key = sourceContainer.keyAt(i); |
| 5920 | final long value = sourceContainer.valueAt(i); |
| 5921 | final long removedFraction = Math.round(value * fractionToRemove); |
| 5922 | if (removedFraction > 0) { |
| 5923 | destContainerProvider.get().put(key, removedFraction); |
| 5924 | sourceContainer.put(key, value - removedFraction); |
| 5925 | } |
| 5926 | } |
| 5927 | } |
| 5928 | } |
| 5929 | |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5930 | private void merge(@NonNull HistoricalOp other) { |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 5931 | merge(this::getOrCreateAccessCount, other.mAccessCount); |
| 5932 | merge(this::getOrCreateRejectCount, other.mRejectCount); |
| 5933 | merge(this::getOrCreateAccessDuration, other.mAccessDuration); |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5934 | } |
| 5935 | |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 5936 | private void increaseAccessCount(@UidState int uidState, @OpFlags int flags, |
| 5937 | long increment) { |
| 5938 | increaseCount(getOrCreateAccessCount(), uidState, flags, increment); |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5939 | } |
| 5940 | |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 5941 | private void increaseRejectCount(@UidState int uidState, @OpFlags int flags, |
| 5942 | long increment) { |
| 5943 | increaseCount(getOrCreateRejectCount(), uidState, flags, increment); |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5944 | } |
| 5945 | |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 5946 | private void increaseAccessDuration(@UidState int uidState, @OpFlags int flags, |
| 5947 | long increment) { |
| 5948 | increaseCount(getOrCreateAccessDuration(), uidState, flags, increment); |
| 5949 | } |
| 5950 | |
| 5951 | private void increaseCount(@NonNull LongSparseLongArray counts, |
| 5952 | @UidState int uidState, @OpFlags int flags, long increment) { |
| 5953 | while (flags != 0) { |
| 5954 | final int flag = 1 << Integer.numberOfTrailingZeros(flags); |
| 5955 | flags &= ~flag; |
| 5956 | final long key = makeKey(uidState, flag); |
| 5957 | counts.put(key, counts.get(key) + increment); |
| 5958 | } |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 5959 | } |
| 5960 | |
| 5961 | /** |
| 5962 | * Gets the op name. |
| 5963 | * |
| 5964 | * @return The op name. |
| 5965 | */ |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5966 | public @NonNull String getOpName() { |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 5967 | return sOpToString[mOp]; |
| 5968 | } |
| 5969 | |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5970 | /** @hide */ |
| 5971 | public int getOpCode() { |
| 5972 | return mOp; |
| 5973 | } |
| 5974 | |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 5975 | /** |
| 5976 | * Gets the number times the op was accessed (performed) in the foreground. |
| 5977 | * |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 5978 | * @param flags The flags which are any combination of |
| 5979 | * {@link #OP_FLAG_SELF}, {@link #OP_FLAG_TRUSTED_PROXY}, |
| 5980 | * {@link #OP_FLAG_UNTRUSTED_PROXY}, {@link #OP_FLAG_TRUSTED_PROXIED}, |
| 5981 | * {@link #OP_FLAG_UNTRUSTED_PROXIED}. You can use {@link #OP_FLAGS_ALL} |
| 5982 | * for any flag. |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 5983 | * @return The times the op was accessed in the foreground. |
| 5984 | * |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 5985 | * @see #getBackgroundAccessCount(int) |
| 5986 | * @see #getAccessCount(int, int, int) |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 5987 | */ |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 5988 | public long getForegroundAccessCount(@OpFlags int flags) { |
| 5989 | return sumForFlagsInStates(mAccessCount, MAX_PRIORITY_UID_STATE, |
| 5990 | resolveFirstUnrestrictedUidState(mOp), flags); |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 5991 | } |
| 5992 | |
| 5993 | /** |
| 5994 | * Gets the number times the op was accessed (performed) in the background. |
| 5995 | * |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 5996 | * @param flags The flags which are any combination of |
| 5997 | * {@link #OP_FLAG_SELF}, {@link #OP_FLAG_TRUSTED_PROXY}, |
| 5998 | * {@link #OP_FLAG_UNTRUSTED_PROXY}, {@link #OP_FLAG_TRUSTED_PROXIED}, |
| 5999 | * {@link #OP_FLAG_UNTRUSTED_PROXIED}. You can use {@link #OP_FLAGS_ALL} |
| 6000 | * for any flag. |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 6001 | * @return The times the op was accessed in the background. |
| 6002 | * |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 6003 | * @see #getForegroundAccessCount(int) |
| 6004 | * @see #getAccessCount(int, int, int) |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 6005 | */ |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 6006 | public long getBackgroundAccessCount(@OpFlags int flags) { |
| 6007 | return sumForFlagsInStates(mAccessCount, resolveLastRestrictedUidState(mOp), |
| 6008 | MIN_PRIORITY_UID_STATE, flags); |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 6009 | } |
| 6010 | |
| 6011 | /** |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 6012 | * Gets the number times the op was accessed (performed) for a |
| 6013 | * range of uid states. |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 6014 | * |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 6015 | * @param fromUidState The UID state from which to query. Could be one of |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 6016 | * {@link #UID_STATE_PERSISTENT}, {@link #UID_STATE_TOP}, |
| 6017 | * {@link #UID_STATE_FOREGROUND_SERVICE}, {@link #UID_STATE_FOREGROUND}, |
| 6018 | * {@link #UID_STATE_BACKGROUND}, {@link #UID_STATE_CACHED}. |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 6019 | * @param toUidState The UID state to which to query. |
| 6020 | * @param flags The flags which are any combination of |
| 6021 | * {@link #OP_FLAG_SELF}, {@link #OP_FLAG_TRUSTED_PROXY}, |
| 6022 | * {@link #OP_FLAG_UNTRUSTED_PROXY}, {@link #OP_FLAG_TRUSTED_PROXIED}, |
| 6023 | * {@link #OP_FLAG_UNTRUSTED_PROXIED}. You can use {@link #OP_FLAGS_ALL} |
| 6024 | * for any flag. |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 6025 | * |
| 6026 | * @return The times the op was accessed for the given UID state. |
| 6027 | * |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 6028 | * @see #getForegroundAccessCount(int) |
| 6029 | * @see #getBackgroundAccessCount(int) |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 6030 | */ |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 6031 | public long getAccessCount(@UidState int fromUidState, @UidState int toUidState, |
| 6032 | @OpFlags int flags) { |
| 6033 | return sumForFlagsInStates(mAccessCount, fromUidState, toUidState, flags); |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 6034 | } |
| 6035 | |
| 6036 | /** |
| 6037 | * Gets the number times the op was rejected in the foreground. |
| 6038 | * |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 6039 | * @param flags The flags which are any combination of |
| 6040 | * {@link #OP_FLAG_SELF}, {@link #OP_FLAG_TRUSTED_PROXY}, |
| 6041 | * {@link #OP_FLAG_UNTRUSTED_PROXY}, {@link #OP_FLAG_TRUSTED_PROXIED}, |
| 6042 | * {@link #OP_FLAG_UNTRUSTED_PROXIED}. You can use {@link #OP_FLAGS_ALL} |
| 6043 | * for any flag. |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 6044 | * @return The times the op was rejected in the foreground. |
| 6045 | * |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 6046 | * @see #getBackgroundRejectCount(int) |
| 6047 | * @see #getRejectCount(int, int, int) |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 6048 | */ |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 6049 | public long getForegroundRejectCount(@OpFlags int flags) { |
| 6050 | return sumForFlagsInStates(mRejectCount, MAX_PRIORITY_UID_STATE, |
| 6051 | resolveFirstUnrestrictedUidState(mOp), flags); |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 6052 | } |
| 6053 | |
| 6054 | /** |
| 6055 | * Gets the number times the op was rejected in the background. |
| 6056 | * |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 6057 | * @param flags The flags which are any combination of |
| 6058 | * {@link #OP_FLAG_SELF}, {@link #OP_FLAG_TRUSTED_PROXY}, |
| 6059 | * {@link #OP_FLAG_UNTRUSTED_PROXY}, {@link #OP_FLAG_TRUSTED_PROXIED}, |
| 6060 | * {@link #OP_FLAG_UNTRUSTED_PROXIED}. You can use {@link #OP_FLAGS_ALL} |
| 6061 | * for any flag. |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 6062 | * @return The times the op was rejected in the background. |
| 6063 | * |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 6064 | * @see #getForegroundRejectCount(int) |
| 6065 | * @see #getRejectCount(int, int, int) |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 6066 | */ |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 6067 | public long getBackgroundRejectCount(@OpFlags int flags) { |
| 6068 | return sumForFlagsInStates(mRejectCount, resolveLastRestrictedUidState(mOp), |
| 6069 | MIN_PRIORITY_UID_STATE, flags); |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 6070 | } |
| 6071 | |
| 6072 | /** |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 6073 | * Gets the number times the op was rejected for a given range of UID states. |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 6074 | * |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 6075 | * @param fromUidState The UID state from which to query. Could be one of |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 6076 | * {@link #UID_STATE_PERSISTENT}, {@link #UID_STATE_TOP}, |
| 6077 | * {@link #UID_STATE_FOREGROUND_SERVICE}, {@link #UID_STATE_FOREGROUND}, |
| 6078 | * {@link #UID_STATE_BACKGROUND}, {@link #UID_STATE_CACHED}. |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 6079 | * @param toUidState The UID state to which to query. |
| 6080 | * @param flags The flags which are any combination of |
| 6081 | * {@link #OP_FLAG_SELF}, {@link #OP_FLAG_TRUSTED_PROXY}, |
| 6082 | * {@link #OP_FLAG_UNTRUSTED_PROXY}, {@link #OP_FLAG_TRUSTED_PROXIED}, |
| 6083 | * {@link #OP_FLAG_UNTRUSTED_PROXIED}. You can use {@link #OP_FLAGS_ALL} |
| 6084 | * for any flag. |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 6085 | * |
| 6086 | * @return The times the op was rejected for the given UID state. |
| 6087 | * |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 6088 | * @see #getForegroundRejectCount(int) |
| 6089 | * @see #getBackgroundRejectCount(int) |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 6090 | */ |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 6091 | public long getRejectCount(@UidState int fromUidState, @UidState int toUidState, |
| 6092 | @OpFlags int flags) { |
| 6093 | return sumForFlagsInStates(mRejectCount, fromUidState, toUidState, flags); |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 6094 | } |
| 6095 | |
| 6096 | /** |
| 6097 | * Gets the total duration the app op was accessed (performed) in the foreground. |
Svet Ganov | 6f672a3 | 2019-07-08 16:40:42 -0700 | [diff] [blame] | 6098 | * The duration is in wall time. |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 6099 | * |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 6100 | * @param flags The flags which are any combination of |
| 6101 | * {@link #OP_FLAG_SELF}, {@link #OP_FLAG_TRUSTED_PROXY}, |
| 6102 | * {@link #OP_FLAG_UNTRUSTED_PROXY}, {@link #OP_FLAG_TRUSTED_PROXIED}, |
| 6103 | * {@link #OP_FLAG_UNTRUSTED_PROXIED}. You can use {@link #OP_FLAGS_ALL} |
| 6104 | * for any flag. |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 6105 | * @return The total duration the app op was accessed in the foreground. |
| 6106 | * |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 6107 | * @see #getBackgroundAccessDuration(int) |
| 6108 | * @see #getAccessDuration(int, int, int) |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 6109 | */ |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 6110 | public long getForegroundAccessDuration(@OpFlags int flags) { |
| 6111 | return sumForFlagsInStates(mAccessDuration, MAX_PRIORITY_UID_STATE, |
| 6112 | resolveFirstUnrestrictedUidState(mOp), flags); |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 6113 | } |
| 6114 | |
| 6115 | /** |
| 6116 | * Gets the total duration the app op was accessed (performed) in the background. |
Svet Ganov | 6f672a3 | 2019-07-08 16:40:42 -0700 | [diff] [blame] | 6117 | * The duration is in wall time. |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 6118 | * |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 6119 | * @param flags The flags which are any combination of |
| 6120 | * {@link #OP_FLAG_SELF}, {@link #OP_FLAG_TRUSTED_PROXY}, |
| 6121 | * {@link #OP_FLAG_UNTRUSTED_PROXY}, {@link #OP_FLAG_TRUSTED_PROXIED}, |
| 6122 | * {@link #OP_FLAG_UNTRUSTED_PROXIED}. You can use {@link #OP_FLAGS_ALL} |
| 6123 | * for any flag. |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 6124 | * @return The total duration the app op was accessed in the background. |
| 6125 | * |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 6126 | * @see #getForegroundAccessDuration(int) |
| 6127 | * @see #getAccessDuration(int, int, int) |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 6128 | */ |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 6129 | public long getBackgroundAccessDuration(@OpFlags int flags) { |
| 6130 | return sumForFlagsInStates(mAccessDuration, resolveLastRestrictedUidState(mOp), |
| 6131 | MIN_PRIORITY_UID_STATE, flags); |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 6132 | } |
| 6133 | |
| 6134 | /** |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 6135 | * Gets the total duration the app op was accessed (performed) for a given |
Svet Ganov | 6f672a3 | 2019-07-08 16:40:42 -0700 | [diff] [blame] | 6136 | * range of UID states. The duration is in wall time. |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 6137 | * |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 6138 | * @param fromUidState The UID state from which to query. Could be one of |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 6139 | * {@link #UID_STATE_PERSISTENT}, {@link #UID_STATE_TOP}, |
| 6140 | * {@link #UID_STATE_FOREGROUND_SERVICE}, {@link #UID_STATE_FOREGROUND}, |
| 6141 | * {@link #UID_STATE_BACKGROUND}, {@link #UID_STATE_CACHED}. |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 6142 | * @param toUidState The UID state from which to query. |
| 6143 | * @param flags The flags which are any combination of |
| 6144 | * {@link #OP_FLAG_SELF}, {@link #OP_FLAG_TRUSTED_PROXY}, |
| 6145 | * {@link #OP_FLAG_UNTRUSTED_PROXY}, {@link #OP_FLAG_TRUSTED_PROXIED}, |
| 6146 | * {@link #OP_FLAG_UNTRUSTED_PROXIED}. You can use {@link #OP_FLAGS_ALL} |
| 6147 | * for any flag. |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 6148 | * |
| 6149 | * @return The total duration the app op was accessed for the given UID state. |
| 6150 | * |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 6151 | * @see #getForegroundAccessDuration(int) |
| 6152 | * @see #getBackgroundAccessDuration(int) |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 6153 | */ |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 6154 | public long getAccessDuration(@UidState int fromUidState, @UidState int toUidState, |
| 6155 | @OpFlags int flags) { |
| 6156 | return sumForFlagsInStates(mAccessDuration, fromUidState, toUidState, flags); |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 6157 | } |
| 6158 | |
| 6159 | @Override |
| 6160 | public int describeContents() { |
| 6161 | return 0; |
| 6162 | } |
| 6163 | |
| 6164 | @Override |
| 6165 | public void writeToParcel(Parcel parcel, int flags) { |
| 6166 | parcel.writeInt(mOp); |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 6167 | writeLongSparseLongArrayToParcel(mAccessCount, parcel); |
| 6168 | writeLongSparseLongArrayToParcel(mRejectCount, parcel); |
| 6169 | writeLongSparseLongArrayToParcel(mAccessDuration, parcel); |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 6170 | } |
| 6171 | |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 6172 | @Override |
Aurimas Liutikas | 4d1699d | 2019-08-28 13:01:05 -0700 | [diff] [blame] | 6173 | public boolean equals(@Nullable Object obj) { |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 6174 | if (this == obj) { |
| 6175 | return true; |
| 6176 | } |
| 6177 | if (obj == null || getClass() != obj.getClass()) { |
| 6178 | return false; |
| 6179 | } |
| 6180 | final HistoricalOp other = (HistoricalOp) obj; |
| 6181 | if (mOp != other.mOp) { |
| 6182 | return false; |
| 6183 | } |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 6184 | if (!equalsLongSparseLongArray(mAccessCount, other.mAccessCount)) { |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 6185 | return false; |
| 6186 | } |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 6187 | if (!equalsLongSparseLongArray(mRejectCount, other.mRejectCount)) { |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 6188 | return false; |
| 6189 | } |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 6190 | return equalsLongSparseLongArray(mAccessDuration, other.mAccessDuration); |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 6191 | } |
| 6192 | |
| 6193 | @Override |
| 6194 | public int hashCode() { |
| 6195 | int result = mOp; |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 6196 | result = 31 * result + Objects.hashCode(mAccessCount); |
| 6197 | result = 31 * result + Objects.hashCode(mRejectCount); |
| 6198 | result = 31 * result + Objects.hashCode(mAccessDuration); |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 6199 | return result; |
| 6200 | } |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 6201 | |
| 6202 | private void accept(@NonNull HistoricalOpsVisitor visitor) { |
| 6203 | visitor.visitHistoricalOp(this); |
| 6204 | } |
| 6205 | |
| 6206 | private @NonNull LongSparseLongArray getOrCreateAccessCount() { |
| 6207 | if (mAccessCount == null) { |
| 6208 | mAccessCount = new LongSparseLongArray(); |
| 6209 | } |
| 6210 | return mAccessCount; |
| 6211 | } |
| 6212 | |
| 6213 | private @NonNull LongSparseLongArray getOrCreateRejectCount() { |
| 6214 | if (mRejectCount == null) { |
| 6215 | mRejectCount = new LongSparseLongArray(); |
| 6216 | } |
| 6217 | return mRejectCount; |
| 6218 | } |
| 6219 | |
| 6220 | private @NonNull LongSparseLongArray getOrCreateAccessDuration() { |
| 6221 | if (mAccessDuration == null) { |
| 6222 | mAccessDuration = new LongSparseLongArray(); |
| 6223 | } |
| 6224 | return mAccessDuration; |
| 6225 | } |
| 6226 | |
| 6227 | /** |
| 6228 | * Multiplies the entries in the array with the passed in scale factor and |
| 6229 | * rounds the result at up 0.5 boundary. |
| 6230 | * |
| 6231 | * @param data The data to scale. |
| 6232 | * @param scaleFactor The scale factor. |
| 6233 | */ |
| 6234 | private static void scale(@NonNull LongSparseLongArray data, double scaleFactor) { |
| 6235 | if (data != null) { |
| 6236 | final int size = data.size(); |
| 6237 | for (int i = 0; i < size; i++) { |
| 6238 | data.put(data.keyAt(i), (long) HistoricalOps.round( |
| 6239 | (double) data.valueAt(i) * scaleFactor)); |
| 6240 | } |
| 6241 | } |
| 6242 | } |
| 6243 | |
| 6244 | /** |
| 6245 | * Merges two arrays while lazily acquiring the destination. |
| 6246 | * |
| 6247 | * @param thisSupplier The destination supplier. |
| 6248 | * @param other The array to merge in. |
| 6249 | */ |
| 6250 | private static void merge(@NonNull Supplier<LongSparseLongArray> thisSupplier, |
| 6251 | @Nullable LongSparseLongArray other) { |
| 6252 | if (other != null) { |
| 6253 | final int otherSize = other.size(); |
| 6254 | for (int i = 0; i < otherSize; i++) { |
| 6255 | final LongSparseLongArray that = thisSupplier.get(); |
| 6256 | final long otherKey = other.keyAt(i); |
| 6257 | final long otherValue = other.valueAt(i); |
| 6258 | that.put(otherKey, that.get(otherKey) + otherValue); |
| 6259 | } |
| 6260 | } |
| 6261 | } |
| 6262 | |
| 6263 | /** @hide */ |
| 6264 | public @Nullable LongSparseArray<Object> collectKeys() { |
| 6265 | LongSparseArray<Object> result = AppOpsManager.collectKeys(mAccessCount, |
| 6266 | null /*result*/); |
| 6267 | result = AppOpsManager.collectKeys(mRejectCount, result); |
| 6268 | result = AppOpsManager.collectKeys(mAccessDuration, result); |
| 6269 | return result; |
| 6270 | } |
| 6271 | |
| 6272 | public static final @android.annotation.NonNull Creator<HistoricalOp> CREATOR = |
| 6273 | new Creator<HistoricalOp>() { |
| 6274 | @Override |
| 6275 | public @NonNull HistoricalOp createFromParcel(@NonNull Parcel source) { |
| 6276 | return new HistoricalOp(source); |
| 6277 | } |
| 6278 | |
| 6279 | @Override |
| 6280 | public @NonNull HistoricalOp[] newArray(int size) { |
| 6281 | return new HistoricalOp[size]; |
| 6282 | } |
| 6283 | }; |
| 6284 | } |
| 6285 | |
| 6286 | /** |
| 6287 | * Computes the sum of the counts for the given flags in between the begin and |
| 6288 | * end UID states. |
| 6289 | * |
| 6290 | * @param counts The data array. |
Philip P. Moltmann | 4052d36 | 2019-09-19 14:52:38 -0700 | [diff] [blame] | 6291 | * @param beginUidState The beginning UID state (inclusive). |
| 6292 | * @param endUidState The end UID state (inclusive). |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 6293 | * @param flags The UID flags. |
| 6294 | * @return The sum. |
| 6295 | */ |
| 6296 | private static long sumForFlagsInStates(@Nullable LongSparseLongArray counts, |
| 6297 | @UidState int beginUidState, @UidState int endUidState, @OpFlags int flags) { |
| 6298 | if (counts == null) { |
| 6299 | return 0; |
| 6300 | } |
| 6301 | long sum = 0; |
| 6302 | while (flags != 0) { |
| 6303 | final int flag = 1 << Integer.numberOfTrailingZeros(flags); |
| 6304 | flags &= ~flag; |
| 6305 | for (int uidState : UID_STATES) { |
| 6306 | if (uidState < beginUidState || uidState > endUidState) { |
| 6307 | continue; |
| 6308 | } |
| 6309 | final long key = makeKey(uidState, flag); |
| 6310 | sum += counts.get(key); |
| 6311 | } |
| 6312 | } |
| 6313 | return sum; |
| 6314 | } |
| 6315 | |
| 6316 | /** |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 6317 | * Callback for notification of changes to operation state. |
| 6318 | */ |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 6319 | public interface OnOpChangedListener { |
| 6320 | public void onOpChanged(String op, String packageName); |
| 6321 | } |
| 6322 | |
| 6323 | /** |
Svetoslav Ganov | 2d20fb4 | 2018-02-08 15:52:10 -0800 | [diff] [blame] | 6324 | * Callback for notification of changes to operation active state. |
Svetoslav Ganov | 2d20fb4 | 2018-02-08 15:52:10 -0800 | [diff] [blame] | 6325 | */ |
| 6326 | public interface OnOpActiveChangedListener { |
| 6327 | /** |
Philip P. Moltmann | a04b9ab | 2020-02-13 09:54:04 -0800 | [diff] [blame] | 6328 | * Called when the active state of an app-op changes. |
Svetoslav Ganov | 2d20fb4 | 2018-02-08 15:52:10 -0800 | [diff] [blame] | 6329 | * |
Jeff Sharkey | 7095ab9 | 2019-08-20 16:50:28 -0600 | [diff] [blame] | 6330 | * @param op The operation that changed. |
Svetoslav Ganov | 2d20fb4 | 2018-02-08 15:52:10 -0800 | [diff] [blame] | 6331 | * @param packageName The package performing the operation. |
| 6332 | * @param active Whether the operation became active or inactive. |
| 6333 | */ |
Jeff Sharkey | 7095ab9 | 2019-08-20 16:50:28 -0600 | [diff] [blame] | 6334 | void onOpActiveChanged(@NonNull String op, int uid, @NonNull String packageName, |
| 6335 | boolean active); |
Svetoslav Ganov | 2d20fb4 | 2018-02-08 15:52:10 -0800 | [diff] [blame] | 6336 | } |
| 6337 | |
| 6338 | /** |
Svet Ganov | b3d2ae2 | 2018-12-17 22:06:15 -0800 | [diff] [blame] | 6339 | * Callback for notification of an op being noted. |
| 6340 | * |
| 6341 | * @hide |
| 6342 | */ |
| 6343 | public interface OnOpNotedListener { |
| 6344 | /** |
| 6345 | * Called when an op was noted. |
| 6346 | * |
| 6347 | * @param code The op code. |
| 6348 | * @param uid The UID performing the operation. |
| 6349 | * @param packageName The package performing the operation. |
| 6350 | * @param result The result of the note. |
| 6351 | */ |
Fabian Kozynski | 0b4592c | 2018-12-20 12:58:45 -0500 | [diff] [blame] | 6352 | void onOpNoted(int code, int uid, String packageName, int result); |
Svet Ganov | b3d2ae2 | 2018-12-17 22:06:15 -0800 | [diff] [blame] | 6353 | } |
| 6354 | |
| 6355 | /** |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 6356 | * Callback for notification of changes to operation state. |
| 6357 | * This allows you to see the raw op codes instead of strings. |
| 6358 | * @hide |
| 6359 | */ |
| 6360 | public static class OnOpChangedInternalListener implements OnOpChangedListener { |
| 6361 | public void onOpChanged(String op, String packageName) { } |
| 6362 | public void onOpChanged(int op, String packageName) { } |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 6363 | } |
| 6364 | |
Jeff Sharkey | 7095ab9 | 2019-08-20 16:50:28 -0600 | [diff] [blame] | 6365 | /** |
| 6366 | * Callback for notification of changes to operation state. |
| 6367 | * This allows you to see the raw op codes instead of strings. |
| 6368 | * @hide |
| 6369 | */ |
| 6370 | public interface OnOpActiveChangedInternalListener extends OnOpActiveChangedListener { |
| 6371 | default void onOpActiveChanged(String op, int uid, String packageName, boolean active) { } |
| 6372 | default void onOpActiveChanged(int op, int uid, String packageName, boolean active) { } |
| 6373 | } |
| 6374 | |
Adam Bookatz | 182862e | 2020-04-27 21:58:22 -0700 | [diff] [blame] | 6375 | /** |
| 6376 | * Callback for notification of an op being started. |
| 6377 | * |
| 6378 | * @hide |
| 6379 | */ |
| 6380 | public interface OnOpStartedListener { |
| 6381 | /** |
| 6382 | * Called when an op was started. |
| 6383 | * |
| 6384 | * Note: This is only for op starts. It is not called when an op is noted or stopped. |
| 6385 | * |
| 6386 | * @param op The op code. |
| 6387 | * @param uid The UID performing the operation. |
| 6388 | * @param packageName The package performing the operation. |
| 6389 | * @param result The result of the start. |
| 6390 | */ |
| 6391 | void onOpStarted(int op, int uid, String packageName, int result); |
| 6392 | } |
| 6393 | |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 6394 | AppOpsManager(Context context, IAppOpsService service) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 6395 | mContext = context; |
| 6396 | mService = service; |
| 6397 | } |
| 6398 | |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 6399 | /** |
| 6400 | * Retrieve current operation state for all applications. |
| 6401 | * |
Winson | 6a864b5 | 2019-05-10 10:34:14 -0700 | [diff] [blame] | 6402 | * The mode of the ops returned are set for the package but may not reflect their effective |
| 6403 | * state due to UID policy or because it's controlled by a different master op. |
| 6404 | * |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 6405 | * Use {@link #unsafeCheckOp(String, int, String)}} or |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 6406 | * {@link #noteOp(String, int, String, String, String)} if the effective mode is needed. |
Winson | 6a864b5 | 2019-05-10 10:34:14 -0700 | [diff] [blame] | 6407 | * |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 6408 | * @param ops The set of operations you are interested in, or null if you want all of them. |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 6409 | * @hide |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 6410 | */ |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 6411 | @SystemApi |
| 6412 | @RequiresPermission(android.Manifest.permission.GET_APP_OPS_STATS) |
| 6413 | public @NonNull List<AppOpsManager.PackageOps> getPackagesForOps(@Nullable String[] ops) { |
| 6414 | final int opCount = ops.length; |
| 6415 | final int[] opCodes = new int[opCount]; |
| 6416 | for (int i = 0; i < opCount; i++) { |
| 6417 | opCodes[i] = sOpStrToOp.get(ops[i]); |
| 6418 | } |
| 6419 | final List<AppOpsManager.PackageOps> result = getPackagesForOps(opCodes); |
| 6420 | return (result != null) ? result : Collections.emptyList(); |
| 6421 | } |
| 6422 | |
| 6423 | /** |
| 6424 | * Retrieve current operation state for all applications. |
| 6425 | * |
Winson | 6a864b5 | 2019-05-10 10:34:14 -0700 | [diff] [blame] | 6426 | * The mode of the ops returned are set for the package but may not reflect their effective |
| 6427 | * state due to UID policy or because it's controlled by a different master op. |
| 6428 | * |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 6429 | * Use {@link #unsafeCheckOp(String, int, String)}} or |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 6430 | * {@link #noteOp(String, int, String, String, String)} if the effective mode is needed. |
Winson | 6a864b5 | 2019-05-10 10:34:14 -0700 | [diff] [blame] | 6431 | * |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 6432 | * @param ops The set of operations you are interested in, or null if you want all of them. |
| 6433 | * @hide |
| 6434 | */ |
Dianne Hackborn | c216a26 | 2018-04-26 13:46:22 -0700 | [diff] [blame] | 6435 | @RequiresPermission(android.Manifest.permission.GET_APP_OPS_STATS) |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 6436 | @UnsupportedAppUsage |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 6437 | public List<AppOpsManager.PackageOps> getPackagesForOps(int[] ops) { |
| 6438 | try { |
| 6439 | return mService.getPackagesForOps(ops); |
| 6440 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 6441 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 6442 | } |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 6443 | } |
| 6444 | |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 6445 | /** |
| 6446 | * Retrieve current operation state for one application. |
| 6447 | * |
Winson | 6a864b5 | 2019-05-10 10:34:14 -0700 | [diff] [blame] | 6448 | * The mode of the ops returned are set for the package but may not reflect their effective |
| 6449 | * state due to UID policy or because it's controlled by a different master op. |
| 6450 | * |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 6451 | * Use {@link #unsafeCheckOp(String, int, String)}} or |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 6452 | * {@link #noteOp(String, int, String, String, String)} if the effective mode is needed. |
Winson | 6a864b5 | 2019-05-10 10:34:14 -0700 | [diff] [blame] | 6453 | * |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 6454 | * @param uid The uid of the application of interest. |
| 6455 | * @param packageName The name of the application of interest. |
| 6456 | * @param ops The set of operations you are interested in, or null if you want all of them. |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 6457 | * |
| 6458 | * @deprecated The int op codes are not stable and you should use the string based op |
| 6459 | * names which are stable and namespaced. Use |
| 6460 | * {@link #getOpsForPackage(int, String, String...)})}. |
| 6461 | * |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 6462 | * @hide |
Suprabh Shukla | 169bed7 | 2019-05-13 13:54:58 -0700 | [diff] [blame] | 6463 | * @removed |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 6464 | */ |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 6465 | @Deprecated |
Dianne Hackborn | f0c322a | 2018-06-13 15:24:04 -0700 | [diff] [blame] | 6466 | @SystemApi |
Dianne Hackborn | c216a26 | 2018-04-26 13:46:22 -0700 | [diff] [blame] | 6467 | @RequiresPermission(android.Manifest.permission.GET_APP_OPS_STATS) |
Dianne Hackborn | 6287849 | 2019-03-11 15:57:07 -0700 | [diff] [blame] | 6468 | public @NonNull List<PackageOps> getOpsForPackage(int uid, @NonNull String packageName, |
| 6469 | @Nullable int[] ops) { |
Dianne Hackborn | 72e3983 | 2013-01-18 18:36:09 -0800 | [diff] [blame] | 6470 | try { |
| 6471 | return mService.getOpsForPackage(uid, packageName, ops); |
| 6472 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 6473 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 72e3983 | 2013-01-18 18:36:09 -0800 | [diff] [blame] | 6474 | } |
Dianne Hackborn | 72e3983 | 2013-01-18 18:36:09 -0800 | [diff] [blame] | 6475 | } |
| 6476 | |
Svet Ganov | ae0e03a | 2016-02-25 18:22:10 -0800 | [diff] [blame] | 6477 | /** |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 6478 | * Retrieve current operation state for one application. The UID and the |
| 6479 | * package must match. |
| 6480 | * |
Winson | 6a864b5 | 2019-05-10 10:34:14 -0700 | [diff] [blame] | 6481 | * The mode of the ops returned are set for the package but may not reflect their effective |
| 6482 | * state due to UID policy or because it's controlled by a different master op. |
| 6483 | * |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 6484 | * Use {@link #unsafeCheckOp(String, int, String)}} or |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 6485 | * {@link #noteOp(String, int, String, String, String)} if the effective mode is needed. |
Winson | 6a864b5 | 2019-05-10 10:34:14 -0700 | [diff] [blame] | 6486 | * |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 6487 | * @param uid The uid of the application of interest. |
| 6488 | * @param packageName The name of the application of interest. |
| 6489 | * @param ops The set of operations you are interested in, or null if you want all of them. |
| 6490 | * |
| 6491 | * @hide |
| 6492 | */ |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 6493 | @TestApi |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 6494 | @SystemApi |
| 6495 | @RequiresPermission(android.Manifest.permission.GET_APP_OPS_STATS) |
| 6496 | public @NonNull List<AppOpsManager.PackageOps> getOpsForPackage(int uid, |
| 6497 | @NonNull String packageName, @Nullable String... ops) { |
| 6498 | int[] opCodes = null; |
| 6499 | if (ops != null) { |
| 6500 | opCodes = new int[ops.length]; |
| 6501 | for (int i = 0; i < ops.length; i++) { |
| 6502 | opCodes[i] = strOpToOp(ops[i]); |
| 6503 | } |
| 6504 | } |
| 6505 | try { |
| 6506 | final List<PackageOps> result = mService.getOpsForPackage(uid, packageName, opCodes); |
| 6507 | if (result == null) { |
| 6508 | return Collections.emptyList(); |
| 6509 | } |
| 6510 | return result; |
| 6511 | } catch (RemoteException e) { |
| 6512 | throw e.rethrowFromSystemServer(); |
| 6513 | } |
| 6514 | } |
| 6515 | |
| 6516 | /** |
| 6517 | * Retrieve historical app op stats for a period. |
| 6518 | * |
Svet Ganov | 23c88db | 2019-01-22 20:38:11 -0800 | [diff] [blame] | 6519 | * @param request A request object describing the data being queried for. |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 6520 | * @param executor Executor on which to run the callback. If <code>null</code> |
| 6521 | * the callback is executed on the default executor running on the main thread. |
| 6522 | * @param callback Callback on which to deliver the result. |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 6523 | * |
| 6524 | * @throws IllegalArgumentException If any of the argument contracts is violated. |
| 6525 | * |
| 6526 | * @hide |
| 6527 | */ |
| 6528 | @TestApi |
| 6529 | @SystemApi |
| 6530 | @RequiresPermission(android.Manifest.permission.GET_APP_OPS_STATS) |
Svet Ganov | 23c88db | 2019-01-22 20:38:11 -0800 | [diff] [blame] | 6531 | public void getHistoricalOps(@NonNull HistoricalOpsRequest request, |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 6532 | @NonNull Executor executor, @NonNull Consumer<HistoricalOps> callback) { |
Daulet Zhanguzin | 0af97d6 | 2019-12-30 15:41:28 +0000 | [diff] [blame] | 6533 | Objects.requireNonNull(executor, "executor cannot be null"); |
| 6534 | Objects.requireNonNull(callback, "callback cannot be null"); |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 6535 | try { |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 6536 | mService.getHistoricalOps(request.mUid, request.mPackageName, request.mAttributionTag, |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 6537 | request.mOpNames, request.mFilter, request.mBeginTimeMillis, |
| 6538 | request.mEndTimeMillis, request.mFlags, new RemoteCallback((result) -> { |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 6539 | final HistoricalOps ops = result.getParcelable(KEY_HISTORICAL_OPS); |
| 6540 | final long identity = Binder.clearCallingIdentity(); |
| 6541 | try { |
| 6542 | executor.execute(() -> callback.accept(ops)); |
| 6543 | } finally { |
| 6544 | Binder.restoreCallingIdentity(identity); |
| 6545 | } |
| 6546 | })); |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 6547 | } catch (RemoteException e) { |
| 6548 | throw e.rethrowFromSystemServer(); |
| 6549 | } |
| 6550 | } |
| 6551 | |
| 6552 | /** |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 6553 | * Retrieve historical app op stats for a period. |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 6554 | * <p> |
| 6555 | * This method queries only the on disk state and the returned ops are raw, |
| 6556 | * which is their times are relative to the history start as opposed to the |
| 6557 | * epoch start. |
| 6558 | * |
Svet Ganov | 23c88db | 2019-01-22 20:38:11 -0800 | [diff] [blame] | 6559 | * @param request A request object describing the data being queried for. |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 6560 | * @param executor Executor on which to run the callback. If <code>null</code> |
| 6561 | * the callback is executed on the default executor running on the main thread. |
| 6562 | * @param callback Callback on which to deliver the result. |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 6563 | * |
| 6564 | * @throws IllegalArgumentException If any of the argument contracts is violated. |
| 6565 | * |
| 6566 | * @hide |
| 6567 | */ |
| 6568 | @TestApi |
Svet Ganov | 8e5bf96 | 2019-03-19 23:59:03 -0700 | [diff] [blame] | 6569 | @RequiresPermission(Manifest.permission.MANAGE_APPOPS) |
Svet Ganov | 23c88db | 2019-01-22 20:38:11 -0800 | [diff] [blame] | 6570 | public void getHistoricalOpsFromDiskRaw(@NonNull HistoricalOpsRequest request, |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 6571 | @Nullable Executor executor, @NonNull Consumer<HistoricalOps> callback) { |
Daulet Zhanguzin | 0af97d6 | 2019-12-30 15:41:28 +0000 | [diff] [blame] | 6572 | Objects.requireNonNull(executor, "executor cannot be null"); |
| 6573 | Objects.requireNonNull(callback, "callback cannot be null"); |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 6574 | try { |
Svet Ganov | 23c88db | 2019-01-22 20:38:11 -0800 | [diff] [blame] | 6575 | mService.getHistoricalOpsFromDiskRaw(request.mUid, request.mPackageName, |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 6576 | request.mAttributionTag, request.mOpNames, request.mFilter, |
| 6577 | request.mBeginTimeMillis, request.mEndTimeMillis, request.mFlags, |
| 6578 | new RemoteCallback((result) -> { |
Svet Ganov | 23c88db | 2019-01-22 20:38:11 -0800 | [diff] [blame] | 6579 | final HistoricalOps ops = result.getParcelable(KEY_HISTORICAL_OPS); |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 6580 | final long identity = Binder.clearCallingIdentity(); |
| 6581 | try { |
| 6582 | executor.execute(() -> callback.accept(ops)); |
| 6583 | } finally { |
| 6584 | Binder.restoreCallingIdentity(identity); |
| 6585 | } |
| 6586 | })); |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 6587 | } catch (RemoteException e) { |
| 6588 | throw e.rethrowFromSystemServer(); |
| 6589 | } |
| 6590 | } |
| 6591 | |
| 6592 | /** |
Svet Ganov | 8e5bf96 | 2019-03-19 23:59:03 -0700 | [diff] [blame] | 6593 | * Reloads the non historical state to allow testing the read/write path. |
| 6594 | * |
| 6595 | * @hide |
| 6596 | */ |
| 6597 | @TestApi |
| 6598 | @RequiresPermission(Manifest.permission.MANAGE_APPOPS) |
| 6599 | public void reloadNonHistoricalState() { |
| 6600 | try { |
| 6601 | mService.reloadNonHistoricalState(); |
| 6602 | } catch (RemoteException e) { |
| 6603 | throw e.rethrowFromSystemServer(); |
| 6604 | } |
| 6605 | } |
| 6606 | |
| 6607 | /** |
Svet Ganov | ae0e03a | 2016-02-25 18:22:10 -0800 | [diff] [blame] | 6608 | * Sets given app op in the specified mode for app ops in the UID. |
| 6609 | * This applies to all apps currently in the UID or installed in |
| 6610 | * this UID in the future. |
| 6611 | * |
| 6612 | * @param code The app op. |
| 6613 | * @param uid The UID for which to set the app. |
| 6614 | * @param mode The app op mode to set. |
| 6615 | * @hide |
| 6616 | */ |
Dianne Hackborn | bf1b57d | 2018-03-07 12:42:47 -0800 | [diff] [blame] | 6617 | @RequiresPermission(android.Manifest.permission.MANAGE_APP_OPS_MODES) |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 6618 | public void setUidMode(int code, int uid, @Mode int mode) { |
Svet Ganov | 2af5708 | 2015-07-30 08:44:20 -0700 | [diff] [blame] | 6619 | try { |
| 6620 | mService.setUidMode(code, uid, mode); |
| 6621 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 6622 | throw e.rethrowFromSystemServer(); |
Svet Ganov | 2af5708 | 2015-07-30 08:44:20 -0700 | [diff] [blame] | 6623 | } |
| 6624 | } |
| 6625 | |
Svet Ganov | ae0e03a | 2016-02-25 18:22:10 -0800 | [diff] [blame] | 6626 | /** |
| 6627 | * Sets given app op in the specified mode for app ops in the UID. |
| 6628 | * This applies to all apps currently in the UID or installed in |
| 6629 | * this UID in the future. |
| 6630 | * |
| 6631 | * @param appOp The app op. |
| 6632 | * @param uid The UID for which to set the app. |
| 6633 | * @param mode The app op mode to set. |
| 6634 | * @hide |
| 6635 | */ |
| 6636 | @SystemApi |
Eugene Susla | 9351985 | 2018-06-13 16:44:31 -0700 | [diff] [blame] | 6637 | @TestApi |
Dianne Hackborn | bf1b57d | 2018-03-07 12:42:47 -0800 | [diff] [blame] | 6638 | @RequiresPermission(android.Manifest.permission.MANAGE_APP_OPS_MODES) |
Philip P. Moltmann | a04b9ab | 2020-02-13 09:54:04 -0800 | [diff] [blame] | 6639 | public void setUidMode(@NonNull String appOp, int uid, @Mode int mode) { |
Svet Ganov | ae0e03a | 2016-02-25 18:22:10 -0800 | [diff] [blame] | 6640 | try { |
| 6641 | mService.setUidMode(AppOpsManager.strOpToOp(appOp), uid, mode); |
| 6642 | } catch (RemoteException e) { |
| 6643 | throw e.rethrowFromSystemServer(); |
| 6644 | } |
| 6645 | } |
| 6646 | |
Svet Ganov | 2af5708 | 2015-07-30 08:44:20 -0700 | [diff] [blame] | 6647 | /** @hide */ |
Svet Ganov | 9cea80cd | 2016-02-16 11:47:00 -0800 | [diff] [blame] | 6648 | public void setUserRestriction(int code, boolean restricted, IBinder token) { |
Ruben Brunk | 29931bc | 2016-03-11 00:24:26 -0800 | [diff] [blame] | 6649 | setUserRestriction(code, restricted, token, /*exceptionPackages*/null); |
| 6650 | } |
| 6651 | |
| 6652 | /** @hide */ |
| 6653 | public void setUserRestriction(int code, boolean restricted, IBinder token, |
| 6654 | String[] exceptionPackages) { |
Svetoslav Ganov | e33f613 | 2016-06-01 16:25:31 -0700 | [diff] [blame] | 6655 | setUserRestrictionForUser(code, restricted, token, exceptionPackages, mContext.getUserId()); |
| 6656 | } |
| 6657 | |
| 6658 | /** @hide */ |
| 6659 | public void setUserRestrictionForUser(int code, boolean restricted, IBinder token, |
| 6660 | String[] exceptionPackages, int userId) { |
Svet Ganov | 9cea80cd | 2016-02-16 11:47:00 -0800 | [diff] [blame] | 6661 | try { |
Svetoslav Ganov | e33f613 | 2016-06-01 16:25:31 -0700 | [diff] [blame] | 6662 | mService.setUserRestriction(code, restricted, token, userId, exceptionPackages); |
Svet Ganov | 9cea80cd | 2016-02-16 11:47:00 -0800 | [diff] [blame] | 6663 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 6664 | throw e.rethrowFromSystemServer(); |
Svet Ganov | 9cea80cd | 2016-02-16 11:47:00 -0800 | [diff] [blame] | 6665 | } |
| 6666 | } |
| 6667 | |
| 6668 | /** @hide */ |
Artur Satayev | f0b7d0b | 2019-11-04 11:16:45 +0000 | [diff] [blame] | 6669 | @UnsupportedAppUsage |
Peter Visontay | b97fbc8 | 2017-12-21 16:23:55 +0000 | [diff] [blame] | 6670 | @TestApi |
Dianne Hackborn | bf1b57d | 2018-03-07 12:42:47 -0800 | [diff] [blame] | 6671 | @RequiresPermission(android.Manifest.permission.MANAGE_APP_OPS_MODES) |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 6672 | public void setMode(int code, int uid, String packageName, @Mode int mode) { |
Dianne Hackborn | 5e45ee6 | 2013-01-24 19:13:44 -0800 | [diff] [blame] | 6673 | try { |
| 6674 | mService.setMode(code, uid, packageName, mode); |
| 6675 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 6676 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 5e45ee6 | 2013-01-24 19:13:44 -0800 | [diff] [blame] | 6677 | } |
| 6678 | } |
| 6679 | |
John Spurlock | 1af30c7 | 2014-03-10 08:33:35 -0400 | [diff] [blame] | 6680 | /** |
Dianne Hackborn | bf1b57d | 2018-03-07 12:42:47 -0800 | [diff] [blame] | 6681 | * Change the operating mode for the given op in the given app package. You must pass |
| 6682 | * in both the uid and name of the application whose mode is being modified; if these |
| 6683 | * do not match, the modification will not be applied. |
| 6684 | * |
| 6685 | * @param op The operation to modify. One of the OPSTR_* constants. |
| 6686 | * @param uid The user id of the application whose mode will be changed. |
| 6687 | * @param packageName The name of the application package name whose mode will |
| 6688 | * be changed. |
| 6689 | * @hide |
| 6690 | */ |
Svet Ganov | 8e5bf96 | 2019-03-19 23:59:03 -0700 | [diff] [blame] | 6691 | @TestApi |
Dianne Hackborn | bf1b57d | 2018-03-07 12:42:47 -0800 | [diff] [blame] | 6692 | @SystemApi |
| 6693 | @RequiresPermission(android.Manifest.permission.MANAGE_APP_OPS_MODES) |
Philip P. Moltmann | a04b9ab | 2020-02-13 09:54:04 -0800 | [diff] [blame] | 6694 | public void setMode(@NonNull String op, int uid, @Nullable String packageName, |
| 6695 | @Mode int mode) { |
Dianne Hackborn | bf1b57d | 2018-03-07 12:42:47 -0800 | [diff] [blame] | 6696 | try { |
| 6697 | mService.setMode(strOpToOp(op), uid, packageName, mode); |
| 6698 | } catch (RemoteException e) { |
| 6699 | throw e.rethrowFromSystemServer(); |
| 6700 | } |
| 6701 | } |
| 6702 | |
| 6703 | /** |
John Spurlock | 1af30c7 | 2014-03-10 08:33:35 -0400 | [diff] [blame] | 6704 | * Set a non-persisted restriction on an audio operation at a stream-level. |
| 6705 | * Restrictions are temporary additional constraints imposed on top of the persisted rules |
| 6706 | * defined by {@link #setMode}. |
| 6707 | * |
| 6708 | * @param code The operation to restrict. |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame] | 6709 | * @param usage The {@link android.media.AudioAttributes} usage value. |
John Spurlock | 1af30c7 | 2014-03-10 08:33:35 -0400 | [diff] [blame] | 6710 | * @param mode The restriction mode (MODE_IGNORED,MODE_ERRORED) or MODE_ALLOWED to unrestrict. |
| 6711 | * @param exceptionPackages Optional list of packages to exclude from the restriction. |
| 6712 | * @hide |
| 6713 | */ |
Dianne Hackborn | bf1b57d | 2018-03-07 12:42:47 -0800 | [diff] [blame] | 6714 | @RequiresPermission(android.Manifest.permission.MANAGE_APP_OPS_MODES) |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 6715 | @UnsupportedAppUsage |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 6716 | public void setRestriction(int code, @AttributeUsage int usage, @Mode int mode, |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame] | 6717 | String[] exceptionPackages) { |
John Spurlock | 1af30c7 | 2014-03-10 08:33:35 -0400 | [diff] [blame] | 6718 | try { |
| 6719 | final int uid = Binder.getCallingUid(); |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame] | 6720 | mService.setAudioRestriction(code, usage, uid, mode, exceptionPackages); |
John Spurlock | 1af30c7 | 2014-03-10 08:33:35 -0400 | [diff] [blame] | 6721 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 6722 | throw e.rethrowFromSystemServer(); |
John Spurlock | 1af30c7 | 2014-03-10 08:33:35 -0400 | [diff] [blame] | 6723 | } |
| 6724 | } |
| 6725 | |
Dianne Hackborn | 607b414 | 2013-08-02 18:10:10 -0700 | [diff] [blame] | 6726 | /** @hide */ |
Dianne Hackborn | bf1b57d | 2018-03-07 12:42:47 -0800 | [diff] [blame] | 6727 | @RequiresPermission(android.Manifest.permission.MANAGE_APP_OPS_MODES) |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 6728 | @UnsupportedAppUsage |
Dianne Hackborn | 607b414 | 2013-08-02 18:10:10 -0700 | [diff] [blame] | 6729 | public void resetAllModes() { |
| 6730 | try { |
Jeff Sharkey | ad357d1 | 2018-02-02 13:25:31 -0700 | [diff] [blame] | 6731 | mService.resetAllModes(mContext.getUserId(), null); |
Dianne Hackborn | 607b414 | 2013-08-02 18:10:10 -0700 | [diff] [blame] | 6732 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 6733 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 607b414 | 2013-08-02 18:10:10 -0700 | [diff] [blame] | 6734 | } |
| 6735 | } |
| 6736 | |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 6737 | /** |
Philip P. Moltmann | a04b9ab | 2020-02-13 09:54:04 -0800 | [diff] [blame] | 6738 | * Gets the app-op name associated with a given permission. |
| 6739 | * |
| 6740 | * <p>The app-op name is one of the public constants defined |
Svet Ganov | fbf01f7 | 2015-04-28 18:39:06 -0700 | [diff] [blame] | 6741 | * in this class such as {@link #OPSTR_COARSE_LOCATION}. |
Svetoslav Ganov | eaca4c5 | 2016-05-05 18:08:00 -0700 | [diff] [blame] | 6742 | * This API is intended to be used for mapping runtime |
Philip P. Moltmann | a04b9ab | 2020-02-13 09:54:04 -0800 | [diff] [blame] | 6743 | * permissions to the corresponding app-op. |
Svet Ganov | fbf01f7 | 2015-04-28 18:39:06 -0700 | [diff] [blame] | 6744 | * |
| 6745 | * @param permission The permission. |
Philip P. Moltmann | a04b9ab | 2020-02-13 09:54:04 -0800 | [diff] [blame] | 6746 | * @return The app-op associated with the permission or {@code null}. |
Svet Ganov | fbf01f7 | 2015-04-28 18:39:06 -0700 | [diff] [blame] | 6747 | */ |
Philip P. Moltmann | a04b9ab | 2020-02-13 09:54:04 -0800 | [diff] [blame] | 6748 | public static @Nullable String permissionToOp(@NonNull String permission) { |
Svet Ganov | da0acdf | 2017-02-15 10:28:51 -0800 | [diff] [blame] | 6749 | final Integer opCode = sPermToOp.get(permission); |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 6750 | if (opCode == null) { |
| 6751 | return null; |
| 6752 | } |
| 6753 | return sOpToString[opCode]; |
Svet Ganov | fbf01f7 | 2015-04-28 18:39:06 -0700 | [diff] [blame] | 6754 | } |
| 6755 | |
| 6756 | /** |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 6757 | * Monitor for changes to the operating mode for the given op in the given app package. |
Svetoslav Ganov | 2d20fb4 | 2018-02-08 15:52:10 -0800 | [diff] [blame] | 6758 | * You can watch op changes only for your UID. |
| 6759 | * |
Dianne Hackborn | e4cb66f | 2013-10-02 10:34:02 -0700 | [diff] [blame] | 6760 | * @param op The operation to monitor, one of OPSTR_*. |
| 6761 | * @param packageName The name of the application to monitor. |
| 6762 | * @param callback Where to report changes. |
| 6763 | */ |
Dianne Hackborn | 6287849 | 2019-03-11 15:57:07 -0700 | [diff] [blame] | 6764 | public void startWatchingMode(@NonNull String op, @Nullable String packageName, |
| 6765 | @NonNull final OnOpChangedListener callback) { |
Dianne Hackborn | e4cb66f | 2013-10-02 10:34:02 -0700 | [diff] [blame] | 6766 | startWatchingMode(strOpToOp(op), packageName, callback); |
| 6767 | } |
| 6768 | |
| 6769 | /** |
| 6770 | * Monitor for changes to the operating mode for the given op in the given app package. |
Dianne Hackborn | 65a4f25 | 2018-05-08 17:30:48 -0700 | [diff] [blame] | 6771 | * You can watch op changes only for your UID. |
| 6772 | * |
| 6773 | * @param op The operation to monitor, one of OPSTR_*. |
| 6774 | * @param packageName The name of the application to monitor. |
| 6775 | * @param flags Option flags: any combination of {@link #WATCH_FOREGROUND_CHANGES} or 0. |
| 6776 | * @param callback Where to report changes. |
Dianne Hackborn | 65a4f25 | 2018-05-08 17:30:48 -0700 | [diff] [blame] | 6777 | */ |
Dianne Hackborn | 6287849 | 2019-03-11 15:57:07 -0700 | [diff] [blame] | 6778 | public void startWatchingMode(@NonNull String op, @Nullable String packageName, int flags, |
| 6779 | @NonNull final OnOpChangedListener callback) { |
Dianne Hackborn | 65a4f25 | 2018-05-08 17:30:48 -0700 | [diff] [blame] | 6780 | startWatchingMode(strOpToOp(op), packageName, flags, callback); |
| 6781 | } |
| 6782 | |
| 6783 | /** |
| 6784 | * Monitor for changes to the operating mode for the given op in the given app package. |
Svetoslav Ganov | 2d20fb4 | 2018-02-08 15:52:10 -0800 | [diff] [blame] | 6785 | * |
| 6786 | * <p> If you don't hold the {@link android.Manifest.permission#WATCH_APPOPS} permission |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 6787 | * you can watch changes only for your UID. |
Svetoslav Ganov | 2d20fb4 | 2018-02-08 15:52:10 -0800 | [diff] [blame] | 6788 | * |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 6789 | * @param op The operation to monitor, one of OP_*. |
| 6790 | * @param packageName The name of the application to monitor. |
| 6791 | * @param callback Where to report changes. |
Dianne Hackborn | e4cb66f | 2013-10-02 10:34:02 -0700 | [diff] [blame] | 6792 | * @hide |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 6793 | */ |
Jeff Sharkey | bf6b213 | 2018-02-27 11:16:37 -0700 | [diff] [blame] | 6794 | @RequiresPermission(value=android.Manifest.permission.WATCH_APPOPS, conditional=true) |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 6795 | public void startWatchingMode(int op, String packageName, final OnOpChangedListener callback) { |
Dianne Hackborn | 65a4f25 | 2018-05-08 17:30:48 -0700 | [diff] [blame] | 6796 | startWatchingMode(op, packageName, 0, callback); |
| 6797 | } |
| 6798 | |
| 6799 | /** |
| 6800 | * Monitor for changes to the operating mode for the given op in the given app package. |
| 6801 | * |
| 6802 | * <p> If you don't hold the {@link android.Manifest.permission#WATCH_APPOPS} permission |
| 6803 | * you can watch changes only for your UID. |
| 6804 | * |
| 6805 | * @param op The operation to monitor, one of OP_*. |
| 6806 | * @param packageName The name of the application to monitor. |
| 6807 | * @param flags Option flags: any combination of {@link #WATCH_FOREGROUND_CHANGES} or 0. |
| 6808 | * @param callback Where to report changes. |
| 6809 | * @hide |
| 6810 | */ |
| 6811 | @RequiresPermission(value=android.Manifest.permission.WATCH_APPOPS, conditional=true) |
| 6812 | public void startWatchingMode(int op, String packageName, int flags, |
| 6813 | final OnOpChangedListener callback) { |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 6814 | synchronized (mModeWatchers) { |
| 6815 | IAppOpsCallback cb = mModeWatchers.get(callback); |
| 6816 | if (cb == null) { |
| 6817 | cb = new IAppOpsCallback.Stub() { |
Dianne Hackborn | bef28fe | 2015-10-29 17:57:11 -0700 | [diff] [blame] | 6818 | public void opChanged(int op, int uid, String packageName) { |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 6819 | if (callback instanceof OnOpChangedInternalListener) { |
| 6820 | ((OnOpChangedInternalListener)callback).onOpChanged(op, packageName); |
| 6821 | } |
| 6822 | if (sOpToString[op] != null) { |
| 6823 | callback.onOpChanged(sOpToString[op], packageName); |
| 6824 | } |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 6825 | } |
| 6826 | }; |
| 6827 | mModeWatchers.put(callback, cb); |
| 6828 | } |
Philip P. Moltmann | 7641cd0 | 2020-03-11 14:42:43 -0700 | [diff] [blame] | 6829 | |
| 6830 | // See CALL_BACK_ON_CHANGED_LISTENER_WITH_SWITCHED_OP_CHANGE |
| 6831 | if (!Compatibility.isChangeEnabled( |
| 6832 | CALL_BACK_ON_CHANGED_LISTENER_WITH_SWITCHED_OP_CHANGE)) { |
| 6833 | flags |= CALL_BACK_ON_SWITCHED_OP; |
| 6834 | } |
| 6835 | |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 6836 | try { |
Dianne Hackborn | 65a4f25 | 2018-05-08 17:30:48 -0700 | [diff] [blame] | 6837 | mService.startWatchingModeWithFlags(op, packageName, flags, cb); |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 6838 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 6839 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 6840 | } |
| 6841 | } |
| 6842 | } |
| 6843 | |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 6844 | /** |
| 6845 | * Stop monitoring that was previously started with {@link #startWatchingMode}. All |
| 6846 | * monitoring associated with this callback will be removed. |
| 6847 | */ |
Dianne Hackborn | 6287849 | 2019-03-11 15:57:07 -0700 | [diff] [blame] | 6848 | public void stopWatchingMode(@NonNull OnOpChangedListener callback) { |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 6849 | synchronized (mModeWatchers) { |
Svet Ganov | b3d2ae2 | 2018-12-17 22:06:15 -0800 | [diff] [blame] | 6850 | IAppOpsCallback cb = mModeWatchers.remove(callback); |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 6851 | if (cb != null) { |
| 6852 | try { |
| 6853 | mService.stopWatchingMode(cb); |
| 6854 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 6855 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 6856 | } |
| 6857 | } |
| 6858 | } |
| 6859 | } |
| 6860 | |
Jeff Sharkey | 7095ab9 | 2019-08-20 16:50:28 -0600 | [diff] [blame] | 6861 | /** {@hide} */ |
| 6862 | @Deprecated |
| 6863 | public void startWatchingActive(@NonNull int[] ops, |
| 6864 | @NonNull OnOpActiveChangedListener callback) { |
| 6865 | final String[] strOps = new String[ops.length]; |
| 6866 | for (int i = 0; i < ops.length; i++) { |
| 6867 | strOps[i] = opToPublicName(ops[i]); |
| 6868 | } |
| 6869 | startWatchingActive(strOps, mContext.getMainExecutor(), callback); |
| 6870 | } |
| 6871 | |
Svetoslav Ganov | 2d20fb4 | 2018-02-08 15:52:10 -0800 | [diff] [blame] | 6872 | /** |
Philip P. Moltmann | a04b9ab | 2020-02-13 09:54:04 -0800 | [diff] [blame] | 6873 | * Start watching for changes to the active state of app-ops. An app-op may be |
Svetoslav Ganov | 2d20fb4 | 2018-02-08 15:52:10 -0800 | [diff] [blame] | 6874 | * long running and it has a clear start and stop delimiters. If an op is being |
| 6875 | * started or stopped by any package you will get a callback. To change the |
| 6876 | * watched ops for a registered callback you need to unregister and register it |
| 6877 | * again. |
| 6878 | * |
Jeff Sharkey | 7095ab9 | 2019-08-20 16:50:28 -0600 | [diff] [blame] | 6879 | * <p> If you don't hold the {@code android.Manifest.permission#WATCH_APPOPS} permission |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 6880 | * you can watch changes only for your UID. |
| 6881 | * |
Jeff Sharkey | 7095ab9 | 2019-08-20 16:50:28 -0600 | [diff] [blame] | 6882 | * @param ops The operations to watch. |
Svetoslav Ganov | 2d20fb4 | 2018-02-08 15:52:10 -0800 | [diff] [blame] | 6883 | * @param callback Where to report changes. |
| 6884 | * |
Jeff Sharkey | 7095ab9 | 2019-08-20 16:50:28 -0600 | [diff] [blame] | 6885 | * @see #stopWatchingActive |
Svetoslav Ganov | 2d20fb4 | 2018-02-08 15:52:10 -0800 | [diff] [blame] | 6886 | */ |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 6887 | // TODO: Uncomment below annotation once b/73559440 is fixed |
| 6888 | // @RequiresPermission(value=Manifest.permission.WATCH_APPOPS, conditional=true) |
Jeff Sharkey | 7095ab9 | 2019-08-20 16:50:28 -0600 | [diff] [blame] | 6889 | public void startWatchingActive(@NonNull String[] ops, |
| 6890 | @CallbackExecutor @NonNull Executor executor, |
Svetoslav Ganov | 2d20fb4 | 2018-02-08 15:52:10 -0800 | [diff] [blame] | 6891 | @NonNull OnOpActiveChangedListener callback) { |
Jeff Sharkey | 7095ab9 | 2019-08-20 16:50:28 -0600 | [diff] [blame] | 6892 | Objects.requireNonNull(ops); |
| 6893 | Objects.requireNonNull(executor); |
| 6894 | Objects.requireNonNull(callback); |
Svetoslav Ganov | 2d20fb4 | 2018-02-08 15:52:10 -0800 | [diff] [blame] | 6895 | IAppOpsActiveCallback cb; |
| 6896 | synchronized (mActiveWatchers) { |
| 6897 | cb = mActiveWatchers.get(callback); |
| 6898 | if (cb != null) { |
| 6899 | return; |
| 6900 | } |
| 6901 | cb = new IAppOpsActiveCallback.Stub() { |
| 6902 | @Override |
| 6903 | public void opActiveChanged(int op, int uid, String packageName, boolean active) { |
Jeff Sharkey | 7095ab9 | 2019-08-20 16:50:28 -0600 | [diff] [blame] | 6904 | executor.execute(() -> { |
| 6905 | if (callback instanceof OnOpActiveChangedInternalListener) { |
| 6906 | ((OnOpActiveChangedInternalListener) callback).onOpActiveChanged(op, |
| 6907 | uid, packageName, active); |
| 6908 | } |
| 6909 | if (sOpToString[op] != null) { |
| 6910 | callback.onOpActiveChanged(sOpToString[op], uid, packageName, active); |
| 6911 | } |
| 6912 | }); |
Svetoslav Ganov | 2d20fb4 | 2018-02-08 15:52:10 -0800 | [diff] [blame] | 6913 | } |
| 6914 | }; |
| 6915 | mActiveWatchers.put(callback, cb); |
| 6916 | } |
Jeff Sharkey | 7095ab9 | 2019-08-20 16:50:28 -0600 | [diff] [blame] | 6917 | final int[] rawOps = new int[ops.length]; |
| 6918 | for (int i = 0; i < ops.length; i++) { |
| 6919 | rawOps[i] = strOpToOp(ops[i]); |
| 6920 | } |
Svetoslav Ganov | 2d20fb4 | 2018-02-08 15:52:10 -0800 | [diff] [blame] | 6921 | try { |
Jeff Sharkey | 7095ab9 | 2019-08-20 16:50:28 -0600 | [diff] [blame] | 6922 | mService.startWatchingActive(rawOps, cb); |
Svetoslav Ganov | 2d20fb4 | 2018-02-08 15:52:10 -0800 | [diff] [blame] | 6923 | } catch (RemoteException e) { |
| 6924 | throw e.rethrowFromSystemServer(); |
| 6925 | } |
| 6926 | } |
| 6927 | |
| 6928 | /** |
Philip P. Moltmann | a04b9ab | 2020-02-13 09:54:04 -0800 | [diff] [blame] | 6929 | * Stop watching for changes to the active state of an app-op. An app-op may be |
Svetoslav Ganov | 2d20fb4 | 2018-02-08 15:52:10 -0800 | [diff] [blame] | 6930 | * long running and it has a clear start and stop delimiters. Unregistering a |
| 6931 | * non-registered callback has no effect. |
| 6932 | * |
Jeff Sharkey | 7095ab9 | 2019-08-20 16:50:28 -0600 | [diff] [blame] | 6933 | * @see #startWatchingActive |
Svetoslav Ganov | 2d20fb4 | 2018-02-08 15:52:10 -0800 | [diff] [blame] | 6934 | */ |
| 6935 | public void stopWatchingActive(@NonNull OnOpActiveChangedListener callback) { |
| 6936 | synchronized (mActiveWatchers) { |
Svet Ganov | b3d2ae2 | 2018-12-17 22:06:15 -0800 | [diff] [blame] | 6937 | final IAppOpsActiveCallback cb = mActiveWatchers.remove(callback); |
Svetoslav Ganov | 2d20fb4 | 2018-02-08 15:52:10 -0800 | [diff] [blame] | 6938 | if (cb != null) { |
| 6939 | try { |
| 6940 | mService.stopWatchingActive(cb); |
| 6941 | } catch (RemoteException e) { |
| 6942 | throw e.rethrowFromSystemServer(); |
| 6943 | } |
| 6944 | } |
| 6945 | } |
| 6946 | } |
| 6947 | |
Svet Ganov | b3d2ae2 | 2018-12-17 22:06:15 -0800 | [diff] [blame] | 6948 | /** |
Adam Bookatz | 182862e | 2020-04-27 21:58:22 -0700 | [diff] [blame] | 6949 | * Start watching for started app-ops. |
| 6950 | * An app-op may be long running and it has a clear start delimiter. |
| 6951 | * If an op start is attempted by any package, you will get a callback. |
| 6952 | * To change the watched ops for a registered callback you need to unregister and register it |
| 6953 | * again. |
| 6954 | * |
| 6955 | * <p> If you don't hold the {@code android.Manifest.permission#WATCH_APPOPS} permission |
| 6956 | * you can watch changes only for your UID. |
| 6957 | * |
| 6958 | * @param ops The operations to watch. |
| 6959 | * @param callback Where to report changes. |
| 6960 | * |
| 6961 | * @see #stopWatchingStarted(OnOpStartedListener) |
| 6962 | * @see #startWatchingActive(int[], OnOpActiveChangedListener) |
| 6963 | * @see #startWatchingNoted(int[], OnOpNotedListener) |
| 6964 | * @see #startOp(int, int, String, boolean, String, String) |
| 6965 | * @see #finishOp(int, int, String, String) |
| 6966 | * |
| 6967 | * @hide |
| 6968 | */ |
| 6969 | @RequiresPermission(value=Manifest.permission.WATCH_APPOPS, conditional=true) |
| 6970 | public void startWatchingStarted(@NonNull int[] ops, @NonNull OnOpStartedListener callback) { |
| 6971 | IAppOpsStartedCallback cb; |
| 6972 | synchronized (mStartedWatchers) { |
| 6973 | if (mStartedWatchers.containsKey(callback)) { |
| 6974 | return; |
| 6975 | } |
| 6976 | cb = new IAppOpsStartedCallback.Stub() { |
| 6977 | @Override |
| 6978 | public void opStarted(int op, int uid, String packageName, int mode) { |
| 6979 | callback.onOpStarted(op, uid, packageName, mode); |
| 6980 | } |
| 6981 | }; |
| 6982 | mStartedWatchers.put(callback, cb); |
| 6983 | } |
| 6984 | try { |
| 6985 | mService.startWatchingStarted(ops, cb); |
| 6986 | } catch (RemoteException e) { |
| 6987 | throw e.rethrowFromSystemServer(); |
| 6988 | } |
| 6989 | } |
| 6990 | |
| 6991 | /** |
| 6992 | * Stop watching for started app-ops. |
| 6993 | * An app-op may be long running and it has a clear start delimiter. |
| 6994 | * Henceforth, if an op start is attempted by any package, you will not get a callback. |
| 6995 | * Unregistering a non-registered callback has no effect. |
| 6996 | * |
| 6997 | * @see #startWatchingStarted(int[], OnOpStartedListener) |
| 6998 | * @see #startOp(int, int, String, boolean, String, String) |
| 6999 | * |
| 7000 | * @hide |
| 7001 | */ |
| 7002 | public void stopWatchingStarted(@NonNull OnOpStartedListener callback) { |
| 7003 | synchronized (mStartedWatchers) { |
| 7004 | final IAppOpsStartedCallback cb = mStartedWatchers.remove(callback); |
| 7005 | if (cb != null) { |
| 7006 | try { |
| 7007 | mService.stopWatchingStarted(cb); |
| 7008 | } catch (RemoteException e) { |
| 7009 | throw e.rethrowFromSystemServer(); |
| 7010 | } |
| 7011 | } |
| 7012 | } |
| 7013 | } |
| 7014 | |
| 7015 | /** |
Svet Ganov | b3d2ae2 | 2018-12-17 22:06:15 -0800 | [diff] [blame] | 7016 | * Start watching for noted app ops. An app op may be immediate or long running. |
| 7017 | * Immediate ops are noted while long running ones are started and stopped. This |
| 7018 | * method allows registering a listener to be notified when an app op is noted. If |
| 7019 | * an op is being noted by any package you will get a callback. To change the |
| 7020 | * watched ops for a registered callback you need to unregister and register it again. |
| 7021 | * |
| 7022 | * <p> If you don't hold the {@link android.Manifest.permission#WATCH_APPOPS} permission |
| 7023 | * you can watch changes only for your UID. |
| 7024 | * |
| 7025 | * @param ops The ops to watch. |
| 7026 | * @param callback Where to report changes. |
| 7027 | * |
| 7028 | * @see #startWatchingActive(int[], OnOpActiveChangedListener) |
Adam Bookatz | 182862e | 2020-04-27 21:58:22 -0700 | [diff] [blame] | 7029 | * @see #startWatchingStarted(int[], OnOpStartedListener) |
Svet Ganov | b3d2ae2 | 2018-12-17 22:06:15 -0800 | [diff] [blame] | 7030 | * @see #stopWatchingNoted(OnOpNotedListener) |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7031 | * @see #noteOp(String, int, String, String, String) |
Svet Ganov | b3d2ae2 | 2018-12-17 22:06:15 -0800 | [diff] [blame] | 7032 | * |
| 7033 | * @hide |
| 7034 | */ |
| 7035 | @RequiresPermission(value=Manifest.permission.WATCH_APPOPS, conditional=true) |
Fabian Kozynski | 0b4592c | 2018-12-20 12:58:45 -0500 | [diff] [blame] | 7036 | public void startWatchingNoted(@NonNull int[] ops, @NonNull OnOpNotedListener callback) { |
Svet Ganov | b3d2ae2 | 2018-12-17 22:06:15 -0800 | [diff] [blame] | 7037 | IAppOpsNotedCallback cb; |
| 7038 | synchronized (mNotedWatchers) { |
| 7039 | cb = mNotedWatchers.get(callback); |
| 7040 | if (cb != null) { |
| 7041 | return; |
| 7042 | } |
| 7043 | cb = new IAppOpsNotedCallback.Stub() { |
| 7044 | @Override |
| 7045 | public void opNoted(int op, int uid, String packageName, int mode) { |
Fabian Kozynski | 0b4592c | 2018-12-20 12:58:45 -0500 | [diff] [blame] | 7046 | callback.onOpNoted(op, uid, packageName, mode); |
Svet Ganov | b3d2ae2 | 2018-12-17 22:06:15 -0800 | [diff] [blame] | 7047 | } |
| 7048 | }; |
| 7049 | mNotedWatchers.put(callback, cb); |
| 7050 | } |
| 7051 | try { |
Fabian Kozynski | 0b4592c | 2018-12-20 12:58:45 -0500 | [diff] [blame] | 7052 | mService.startWatchingNoted(ops, cb); |
Svet Ganov | b3d2ae2 | 2018-12-17 22:06:15 -0800 | [diff] [blame] | 7053 | } catch (RemoteException e) { |
| 7054 | throw e.rethrowFromSystemServer(); |
| 7055 | } |
| 7056 | } |
| 7057 | |
| 7058 | /** |
| 7059 | * Stop watching for noted app ops. An app op may be immediate or long running. |
| 7060 | * Unregistering a non-registered callback has no effect. |
| 7061 | * |
Fabian Kozynski | 0b4592c | 2018-12-20 12:58:45 -0500 | [diff] [blame] | 7062 | * @see #startWatchingNoted(int[], OnOpNotedListener) |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7063 | * @see #noteOp(String, int, String, String, String) |
Svet Ganov | b3d2ae2 | 2018-12-17 22:06:15 -0800 | [diff] [blame] | 7064 | * |
| 7065 | * @hide |
| 7066 | */ |
| 7067 | public void stopWatchingNoted(@NonNull OnOpNotedListener callback) { |
| 7068 | synchronized (mNotedWatchers) { |
Adam Bookatz | 182862e | 2020-04-27 21:58:22 -0700 | [diff] [blame] | 7069 | final IAppOpsNotedCallback cb = mNotedWatchers.remove(callback); |
Svet Ganov | b3d2ae2 | 2018-12-17 22:06:15 -0800 | [diff] [blame] | 7070 | if (cb != null) { |
| 7071 | try { |
| 7072 | mService.stopWatchingNoted(cb); |
| 7073 | } catch (RemoteException e) { |
| 7074 | throw e.rethrowFromSystemServer(); |
| 7075 | } |
| 7076 | } |
| 7077 | } |
| 7078 | } |
| 7079 | |
Dianne Hackborn | 95d7853 | 2013-09-11 09:51:14 -0700 | [diff] [blame] | 7080 | private String buildSecurityExceptionMsg(int op, int uid, String packageName) { |
| 7081 | return packageName + " from uid " + uid + " not allowed to perform " + sOpNames[op]; |
| 7082 | } |
| 7083 | |
Adam Lesinski | b5cf61b | 2014-08-18 16:10:28 -0700 | [diff] [blame] | 7084 | /** |
| 7085 | * {@hide} |
| 7086 | */ |
Artur Satayev | f0b7d0b | 2019-11-04 11:16:45 +0000 | [diff] [blame] | 7087 | @UnsupportedAppUsage |
Philip P. Moltmann | 3311515 | 2018-04-11 13:39:36 -0700 | [diff] [blame] | 7088 | @TestApi |
Dianne Hackborn | 6287849 | 2019-03-11 15:57:07 -0700 | [diff] [blame] | 7089 | public static int strOpToOp(@NonNull String op) { |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 7090 | Integer val = sOpStrToOp.get(op); |
| 7091 | if (val == null) { |
| 7092 | throw new IllegalArgumentException("Unknown operation string: " + op); |
| 7093 | } |
| 7094 | return val; |
| 7095 | } |
| 7096 | |
| 7097 | /** |
| 7098 | * Do a quick check for whether an application might be able to perform an operation. |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7099 | * This is <em>not</em> a security check; you must use {@link #noteOp(String, int, String, |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7100 | * String, String)} or {@link #startOp(String, int, String, String, String)} for your actual |
| 7101 | * security checks, which also ensure that the given uid and package name are consistent. This |
| 7102 | * function can just be used for a quick check to see if an operation has been disabled for the |
| 7103 | * application, as an early reject of some work. This does not modify the time stamp or other |
| 7104 | * data about the operation. |
Dianne Hackborn | c216a26 | 2018-04-26 13:46:22 -0700 | [diff] [blame] | 7105 | * |
| 7106 | * <p>Important things this will not do (which you need to ultimate use |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7107 | * {@link #noteOp(String, int, String, String, String)} or |
| 7108 | * {@link #startOp(String, int, String, String, String)} to cover):</p> |
Dianne Hackborn | c216a26 | 2018-04-26 13:46:22 -0700 | [diff] [blame] | 7109 | * <ul> |
| 7110 | * <li>Verifying the uid and package are consistent, so callers can't spoof |
| 7111 | * their identity.</li> |
| 7112 | * <li>Taking into account the current foreground/background state of the |
| 7113 | * app; apps whose mode varies by this state will always be reported |
| 7114 | * as {@link #MODE_ALLOWED}.</li> |
| 7115 | * </ul> |
| 7116 | * |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 7117 | * @param op The operation to check. One of the OPSTR_* constants. |
| 7118 | * @param uid The user id of the application attempting to perform the operation. |
| 7119 | * @param packageName The name of the application attempting to perform the operation. |
| 7120 | * @return Returns {@link #MODE_ALLOWED} if the operation is allowed, or |
| 7121 | * {@link #MODE_IGNORED} if it is not allowed and should be silently ignored (without |
| 7122 | * causing the app to crash). |
| 7123 | * @throws SecurityException If the app has been configured to crash on this op. |
| 7124 | */ |
Dianne Hackborn | 6287849 | 2019-03-11 15:57:07 -0700 | [diff] [blame] | 7125 | public int unsafeCheckOp(@NonNull String op, int uid, @NonNull String packageName) { |
Dianne Hackborn | f0c322a | 2018-06-13 15:24:04 -0700 | [diff] [blame] | 7126 | return checkOp(strOpToOp(op), uid, packageName); |
| 7127 | } |
| 7128 | |
| 7129 | /** |
| 7130 | * @deprecated Renamed to {@link #unsafeCheckOp(String, int, String)}. |
| 7131 | */ |
| 7132 | @Deprecated |
Dianne Hackborn | 6287849 | 2019-03-11 15:57:07 -0700 | [diff] [blame] | 7133 | public int checkOp(@NonNull String op, int uid, @NonNull String packageName) { |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 7134 | return checkOp(strOpToOp(op), uid, packageName); |
| 7135 | } |
| 7136 | |
| 7137 | /** |
John Spurlock | 925b85e | 2014-03-10 16:52:11 -0400 | [diff] [blame] | 7138 | * Like {@link #checkOp} but instead of throwing a {@link SecurityException} it |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 7139 | * returns {@link #MODE_ERRORED}. |
| 7140 | */ |
Dianne Hackborn | 6287849 | 2019-03-11 15:57:07 -0700 | [diff] [blame] | 7141 | public int unsafeCheckOpNoThrow(@NonNull String op, int uid, @NonNull String packageName) { |
Dianne Hackborn | f0c322a | 2018-06-13 15:24:04 -0700 | [diff] [blame] | 7142 | return checkOpNoThrow(strOpToOp(op), uid, packageName); |
| 7143 | } |
| 7144 | |
| 7145 | /** |
| 7146 | * @deprecated Renamed to {@link #unsafeCheckOpNoThrow(String, int, String)}. |
| 7147 | */ |
| 7148 | @Deprecated |
Dianne Hackborn | 6287849 | 2019-03-11 15:57:07 -0700 | [diff] [blame] | 7149 | public int checkOpNoThrow(@NonNull String op, int uid, @NonNull String packageName) { |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 7150 | return checkOpNoThrow(strOpToOp(op), uid, packageName); |
| 7151 | } |
| 7152 | |
| 7153 | /** |
Dianne Hackborn | 65a4f25 | 2018-05-08 17:30:48 -0700 | [diff] [blame] | 7154 | * Like {@link #checkOp} but returns the <em>raw</em> mode associated with the op. |
| 7155 | * Does not throw a security exception, does not translate {@link #MODE_FOREGROUND}. |
Dianne Hackborn | 65a4f25 | 2018-05-08 17:30:48 -0700 | [diff] [blame] | 7156 | */ |
Dianne Hackborn | 6287849 | 2019-03-11 15:57:07 -0700 | [diff] [blame] | 7157 | public int unsafeCheckOpRaw(@NonNull String op, int uid, @NonNull String packageName) { |
Adam Bookatz | 3876793 | 2020-02-05 12:13:40 -0800 | [diff] [blame] | 7158 | return unsafeCheckOpRawNoThrow(op, uid, packageName); |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 7159 | } |
| 7160 | |
| 7161 | /** |
| 7162 | * Like {@link #unsafeCheckOpNoThrow(String, int, String)} but returns the <em>raw</em> |
| 7163 | * mode associated with the op. Does not throw a security exception, does not translate |
| 7164 | * {@link #MODE_FOREGROUND}. |
| 7165 | */ |
| 7166 | public int unsafeCheckOpRawNoThrow(@NonNull String op, int uid, @NonNull String packageName) { |
Adam Bookatz | 3876793 | 2020-02-05 12:13:40 -0800 | [diff] [blame] | 7167 | return unsafeCheckOpRawNoThrow(strOpToOp(op), uid, packageName); |
| 7168 | } |
| 7169 | |
| 7170 | /** |
| 7171 | * Returns the <em>raw</em> mode associated with the op. |
| 7172 | * Does not throw a security exception, does not translate {@link #MODE_FOREGROUND}. |
| 7173 | * @hide |
| 7174 | */ |
| 7175 | public int unsafeCheckOpRawNoThrow(int op, int uid, @NonNull String packageName) { |
Dianne Hackborn | 65a4f25 | 2018-05-08 17:30:48 -0700 | [diff] [blame] | 7176 | try { |
Adam Bookatz | 3876793 | 2020-02-05 12:13:40 -0800 | [diff] [blame] | 7177 | return mService.checkOperationRaw(op, uid, packageName); |
Dianne Hackborn | 65a4f25 | 2018-05-08 17:30:48 -0700 | [diff] [blame] | 7178 | } catch (RemoteException e) { |
| 7179 | throw e.rethrowFromSystemServer(); |
| 7180 | } |
| 7181 | } |
| 7182 | |
| 7183 | /** |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7184 | * @deprecated Use {@link #noteOp(String, int, String, String, String)} instead |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7185 | */ |
| 7186 | @Deprecated |
| 7187 | public int noteOp(@NonNull String op, int uid, @NonNull String packageName) { |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7188 | return noteOp(op, uid, packageName, null, null); |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7189 | } |
| 7190 | |
| 7191 | /** |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7192 | * @deprecated Use {@link #noteOp(String, int, String, String, String)} instead |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7193 | * |
| 7194 | * @hide |
| 7195 | */ |
| 7196 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.Q, publicAlternatives = "Use {@link " |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7197 | + "#noteOp(java.lang.String, int, java.lang.String, java.lang.String, " |
| 7198 | + "java.lang.String)} instead") |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7199 | @Deprecated |
| 7200 | public int noteOp(int op) { |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7201 | return noteOp(op, Process.myUid(), mContext.getOpPackageName(), null, null); |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7202 | } |
| 7203 | |
| 7204 | /** |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7205 | * @deprecated Use {@link #noteOp(String, int, String, String, String)} instead |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7206 | * |
| 7207 | * @hide |
| 7208 | */ |
| 7209 | @Deprecated |
| 7210 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.Q, publicAlternatives = "Use {@link " |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7211 | + "#noteOp(java.lang.String, int, java.lang.String, java.lang.String, " |
| 7212 | + "java.lang.String)} instead") |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7213 | public int noteOp(int op, int uid, @Nullable String packageName) { |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7214 | return noteOp(op, uid, packageName, null, null); |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7215 | } |
| 7216 | |
| 7217 | /** |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 7218 | * Make note of an application performing an operation. Note that you must pass |
| 7219 | * in both the uid and name of the application to be checked; this function will verify |
| 7220 | * that these two match, and if not, return {@link #MODE_IGNORED}. If this call |
| 7221 | * succeeds, the last execution time of the operation for this app will be updated to |
| 7222 | * the current time. |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7223 | * |
Philip P. Moltmann | 9e36700 | 2020-02-03 17:01:05 -0800 | [diff] [blame] | 7224 | * <p>If this is a check that is not preceding the protected operation, use |
| 7225 | * {@link #unsafeCheckOp} instead. |
| 7226 | * |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 7227 | * @param op The operation to note. One of the OPSTR_* constants. |
| 7228 | * @param uid The user id of the application attempting to perform the operation. |
| 7229 | * @param packageName The name of the application attempting to perform the operation. |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 7230 | * @param attributionTag The {@link Context#createAttributionContext attribution tag} or {@code |
| 7231 | * null} for default attribution |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7232 | * @param message A message describing the reason the op was noted |
Philip P. Moltmann | 0d05e48 | 2019-02-08 13:05:25 -0800 | [diff] [blame] | 7233 | * |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7234 | * @return Returns {@link #MODE_ALLOWED} if the operation is allowed, or |
| 7235 | * {@link #MODE_IGNORED} if it is not allowed and should be silently ignored (without |
| 7236 | * causing the app to crash). |
| 7237 | * |
| 7238 | * @throws SecurityException If the app has been configured to crash on this op. |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 7239 | */ |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7240 | public int noteOp(@NonNull String op, int uid, @Nullable String packageName, |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 7241 | @Nullable String attributionTag, @Nullable String message) { |
| 7242 | return noteOp(strOpToOp(op), uid, packageName, attributionTag, message); |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 7243 | } |
| 7244 | |
| 7245 | /** |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7246 | * Make note of an application performing an operation. Note that you must pass |
| 7247 | * in both the uid and name of the application to be checked; this function will verify |
| 7248 | * that these two match, and if not, return {@link #MODE_IGNORED}. If this call |
| 7249 | * succeeds, the last execution time of the operation for this app will be updated to |
| 7250 | * the current time. |
| 7251 | * |
Philip P. Moltmann | 9e36700 | 2020-02-03 17:01:05 -0800 | [diff] [blame] | 7252 | * <p>If this is a check that is not preceding the protected operation, use |
| 7253 | * {@link #unsafeCheckOp} instead. |
| 7254 | * |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7255 | * @param op The operation to note. One of the OP_* constants. |
| 7256 | * @param uid The user id of the application attempting to perform the operation. |
| 7257 | * @param packageName The name of the application attempting to perform the operation. |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 7258 | * @param attributionTag The {@link Context#createAttributionContext attribution tag} or {@code |
| 7259 | * null} for default attribution |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7260 | * @param message A message describing the reason the op was noted |
| 7261 | * |
| 7262 | * @return Returns {@link #MODE_ALLOWED} if the operation is allowed, or |
| 7263 | * {@link #MODE_IGNORED} if it is not allowed and should be silently ignored (without |
| 7264 | * causing the app to crash). |
| 7265 | * |
| 7266 | * @throws SecurityException If the app has been configured to crash on this op. |
| 7267 | * |
| 7268 | * @hide |
| 7269 | */ |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 7270 | public int noteOp(int op, int uid, @Nullable String packageName, |
| 7271 | @Nullable String attributionTag, @Nullable String message) { |
| 7272 | final int mode = noteOpNoThrow(op, uid, packageName, attributionTag, message); |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7273 | if (mode == MODE_ERRORED) { |
| 7274 | throw new SecurityException(buildSecurityExceptionMsg(op, uid, packageName)); |
| 7275 | } |
| 7276 | return mode; |
| 7277 | } |
| 7278 | |
| 7279 | /** |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7280 | * @deprecated Use {@link #noteOpNoThrow(String, int, String, String, String)} instead |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7281 | */ |
| 7282 | @Deprecated |
| 7283 | public int noteOpNoThrow(@NonNull String op, int uid, @NonNull String packageName) { |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7284 | return noteOpNoThrow(op, uid, packageName, null, null); |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7285 | } |
| 7286 | |
| 7287 | /** |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7288 | * @deprecated Use {@link #noteOpNoThrow(int, int, String, String, String)} instead |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7289 | * |
| 7290 | * @hide |
| 7291 | */ |
| 7292 | @Deprecated |
| 7293 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.Q, publicAlternatives = "Use {@link " |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7294 | + "#noteOpNoThrow(java.lang.String, int, java.lang.String, java.lang.String, " |
| 7295 | + "java.lang.String)} instead") |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7296 | public int noteOpNoThrow(int op, int uid, String packageName) { |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7297 | return noteOpNoThrow(op, uid, packageName, null, null); |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7298 | } |
| 7299 | |
| 7300 | /** |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7301 | * Like {@link #noteOp(String, int, String, String, String)} but instead of throwing a |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7302 | * {@link SecurityException} it returns {@link #MODE_ERRORED}. |
| 7303 | * |
| 7304 | * @param op The operation to note. One of the OPSTR_* constants. |
| 7305 | * @param uid The user id of the application attempting to perform the operation. |
| 7306 | * @param packageName The name of the application attempting to perform the operation. |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 7307 | * @param attributionTag The {@link Context#createAttributionContext attribution tag} or {@code |
| 7308 | * null} for default attribution |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7309 | * @param message A message describing the reason the op was noted |
| 7310 | * |
| 7311 | * @return Returns {@link #MODE_ALLOWED} if the operation is allowed, or |
| 7312 | * {@link #MODE_IGNORED} if it is not allowed and should be silently ignored (without |
| 7313 | * causing the app to crash). |
| 7314 | */ |
| 7315 | public int noteOpNoThrow(@NonNull String op, int uid, @NonNull String packageName, |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 7316 | @Nullable String attributionTag, @Nullable String message) { |
| 7317 | return noteOpNoThrow(strOpToOp(op), uid, packageName, attributionTag, message); |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7318 | } |
| 7319 | |
| 7320 | /** |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7321 | * Like {@link #noteOp(String, int, String, String, String)} but instead of throwing a |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7322 | * {@link SecurityException} it returns {@link #MODE_ERRORED}. |
| 7323 | * |
| 7324 | * @param op The operation to note. One of the OP_* constants. |
| 7325 | * @param uid The user id of the application attempting to perform the operation. |
| 7326 | * @param packageName The name of the application attempting to perform the operation. |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 7327 | * @param attributionTag The {@link Context#createAttributionContext attribution tag} or {@code |
| 7328 | * null} for default attribution |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7329 | * @param message A message describing the reason the op was noted |
| 7330 | * |
| 7331 | * @return Returns {@link #MODE_ALLOWED} if the operation is allowed, or |
| 7332 | * {@link #MODE_IGNORED} if it is not allowed and should be silently ignored (without |
| 7333 | * causing the app to crash). |
| 7334 | * |
| 7335 | * @hide |
| 7336 | */ |
| 7337 | public int noteOpNoThrow(int op, int uid, @Nullable String packageName, |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 7338 | @Nullable String attributionTag, @Nullable String message) { |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7339 | try { |
David Cheung | 2ead966 | 2020-02-19 16:11:06 -0800 | [diff] [blame] | 7340 | collectNoteOpCallsForValidation(op); |
Philip P. Moltmann | da554e4 | 2019-12-20 11:21:02 -0800 | [diff] [blame] | 7341 | int collectionMode = getNotedOpCollectionMode(uid, packageName, op); |
| 7342 | if (collectionMode == COLLECT_ASYNC) { |
| 7343 | if (message == null) { |
| 7344 | // Set stack trace as default message |
| 7345 | message = getFormattedStackTrace(); |
| 7346 | } |
| 7347 | } |
| 7348 | |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 7349 | int mode = mService.noteOperation(op, uid, packageName, attributionTag, |
Philip P. Moltmann | da554e4 | 2019-12-20 11:21:02 -0800 | [diff] [blame] | 7350 | collectionMode == COLLECT_ASYNC, message); |
| 7351 | |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7352 | if (mode == MODE_ALLOWED) { |
Philip P. Moltmann | da554e4 | 2019-12-20 11:21:02 -0800 | [diff] [blame] | 7353 | if (collectionMode == COLLECT_SELF) { |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 7354 | collectNotedOpForSelf(op, attributionTag); |
Philip P. Moltmann | da554e4 | 2019-12-20 11:21:02 -0800 | [diff] [blame] | 7355 | } else if (collectionMode == COLLECT_SYNC) { |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 7356 | collectNotedOpSync(op, attributionTag); |
Philip P. Moltmann | da554e4 | 2019-12-20 11:21:02 -0800 | [diff] [blame] | 7357 | } |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7358 | } |
| 7359 | |
| 7360 | return mode; |
| 7361 | } catch (RemoteException e) { |
| 7362 | throw e.rethrowFromSystemServer(); |
| 7363 | } |
| 7364 | } |
| 7365 | |
| 7366 | /** |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7367 | * @deprecated Use {@link #noteProxyOp(String, String, int, String, String)} instead |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7368 | */ |
| 7369 | @Deprecated |
| 7370 | public int noteProxyOp(@NonNull String op, @NonNull String proxiedPackageName) { |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7371 | return noteProxyOp(op, proxiedPackageName, Binder.getCallingUid(), null, null); |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7372 | } |
| 7373 | |
| 7374 | /** |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7375 | * @deprecated Use {@link #noteProxyOp(String, String, int, String, String)} instead |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7376 | * |
| 7377 | * @hide |
| 7378 | */ |
| 7379 | @Deprecated |
| 7380 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.Q, publicAlternatives = "Use {@link " |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7381 | + "#noteProxyOp(java.lang.String, java.lang.String, int, java.lang.String, " |
| 7382 | + "java.lang.String)} instead") |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7383 | public int noteProxyOp(int op, @Nullable String proxiedPackageName) { |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7384 | return noteProxyOp(op, proxiedPackageName, Binder.getCallingUid(), null, null); |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7385 | } |
| 7386 | |
| 7387 | /** |
| 7388 | * Make note of an application performing an operation on behalf of another application when |
| 7389 | * handling an IPC. This function will verify that the calling uid and proxied package name |
| 7390 | * match, and if not, return {@link #MODE_IGNORED}. If this call succeeds, the last execution |
| 7391 | * time of the operation for the proxied app and your app will be updated to the current time. |
| 7392 | * |
| 7393 | * @param op The operation to note. One of the OP_* constants. |
| 7394 | * @param proxiedPackageName The name of the application calling into the proxy application. |
| 7395 | * @param proxiedUid The uid of the proxied application |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 7396 | * @param proxiedAttributionTag The proxied {@link Context#createAttributionContext |
| 7397 | * attribution tag} or {@code null} for default attribution |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7398 | * @param message A message describing the reason the op was noted |
| 7399 | * |
| 7400 | * @return Returns {@link #MODE_ALLOWED} if the operation is allowed, or {@link #MODE_IGNORED} |
| 7401 | * if it is not allowed and should be silently ignored (without causing the app to crash). |
| 7402 | * |
| 7403 | * @throws SecurityException If the proxy or proxied app has been configured to crash on this |
| 7404 | * op. |
| 7405 | * |
| 7406 | * @hide |
| 7407 | */ |
| 7408 | public int noteProxyOp(int op, @Nullable String proxiedPackageName, int proxiedUid, |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 7409 | @Nullable String proxiedAttributionTag, @Nullable String message) { |
| 7410 | int mode = noteProxyOpNoThrow(op, proxiedPackageName, proxiedUid, proxiedAttributionTag, |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7411 | message); |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7412 | if (mode == MODE_ERRORED) { |
| 7413 | throw new SecurityException("Proxy package " + mContext.getOpPackageName() |
| 7414 | + " from uid " + Process.myUid() + " or calling package " + proxiedPackageName |
| 7415 | + " from uid " + proxiedUid + " not allowed to perform " + sOpNames[op]); |
| 7416 | } |
| 7417 | return mode; |
| 7418 | } |
| 7419 | |
| 7420 | /** |
| 7421 | * Make note of an application performing an operation on behalf of another application when |
| 7422 | * handling an IPC. This function will verify that the calling uid and proxied package name |
| 7423 | * match, and if not, return {@link #MODE_IGNORED}. If this call succeeds, the last execution |
| 7424 | * time of the operation for the proxied app and your app will be updated to the current time. |
| 7425 | * |
| 7426 | * @param op The operation to note. One of the OPSTR_* constants. |
| 7427 | * @param proxiedPackageName The name of the application calling into the proxy application. |
| 7428 | * @param proxiedUid The uid of the proxied application |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 7429 | * @param proxiedAttributionTag The proxied {@link Context#createAttributionContext |
| 7430 | * attribution tag} or {@code null} for default attribution |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7431 | * @param message A message describing the reason the op was noted |
| 7432 | * |
| 7433 | * @return Returns {@link #MODE_ALLOWED} if the operation is allowed, or {@link #MODE_IGNORED} |
| 7434 | * if it is not allowed and should be silently ignored (without causing the app to crash). |
| 7435 | * |
| 7436 | * @throws SecurityException If the proxy or proxied app has been configured to crash on this |
| 7437 | * op. |
| 7438 | */ |
| 7439 | public int noteProxyOp(@NonNull String op, @Nullable String proxiedPackageName, int proxiedUid, |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 7440 | @Nullable String proxiedAttributionTag, @Nullable String message) { |
| 7441 | return noteProxyOp(strOpToOp(op), proxiedPackageName, proxiedUid, proxiedAttributionTag, |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7442 | message); |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7443 | } |
| 7444 | |
| 7445 | /** |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7446 | * @deprecated Use {@link #noteProxyOpNoThrow(String, String, int, String, String)} instead |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7447 | */ |
| 7448 | @Deprecated |
| 7449 | public int noteProxyOpNoThrow(@NonNull String op, @NonNull String proxiedPackageName) { |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7450 | return noteProxyOpNoThrow(op, proxiedPackageName, Binder.getCallingUid(), null, null); |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7451 | } |
| 7452 | |
| 7453 | /** |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7454 | * @deprecated Use {@link #noteProxyOpNoThrow(String, String, int, String, String)} instead |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7455 | */ |
| 7456 | @Deprecated |
| 7457 | public int noteProxyOpNoThrow(@NonNull String op, @Nullable String proxiedPackageName, |
| 7458 | int proxiedUid) { |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7459 | return noteProxyOpNoThrow(op, proxiedPackageName, proxiedUid, null, null); |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7460 | } |
| 7461 | |
| 7462 | /** |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7463 | * Like {@link #noteProxyOp(String, String, int, String, String)} but instead |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7464 | * of throwing a {@link SecurityException} it returns {@link #MODE_ERRORED}. |
Philip P. Moltmann | 0d05e48 | 2019-02-08 13:05:25 -0800 | [diff] [blame] | 7465 | * |
| 7466 | * <p>This API requires package with the {@code proxiedPackageName} to belong to |
| 7467 | * {@code proxiedUid}. |
| 7468 | * |
| 7469 | * @param op The op to note |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7470 | * @param proxiedPackageName The package to note the op for |
| 7471 | * @param proxiedUid The uid the package belongs to |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 7472 | * @param proxiedAttributionTag The proxied {@link Context#createAttributionContext |
| 7473 | * attribution tag} or {@code null} for default attribution |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7474 | * @param message A message describing the reason the op was noted |
| 7475 | */ |
| 7476 | public int noteProxyOpNoThrow(@NonNull String op, @Nullable String proxiedPackageName, |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 7477 | int proxiedUid, @Nullable String proxiedAttributionTag, @Nullable String message) { |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7478 | return noteProxyOpNoThrow(strOpToOp(op), proxiedPackageName, proxiedUid, |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 7479 | proxiedAttributionTag, message); |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7480 | } |
| 7481 | |
| 7482 | /** |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7483 | * Like {@link #noteProxyOp(int, String, int, String, String)} but instead |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7484 | * of throwing a {@link SecurityException} it returns {@link #MODE_ERRORED}. |
| 7485 | * |
| 7486 | * @param op The op to note |
Philip P. Moltmann | 0d05e48 | 2019-02-08 13:05:25 -0800 | [diff] [blame] | 7487 | * @param proxiedPackageName The package to note the op for or {@code null} if the op should be |
| 7488 | * noted for the "android" package |
| 7489 | * @param proxiedUid The uid the package belongs to |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 7490 | * @param proxiedAttributionTag The proxied {@link Context#createAttributionContext |
| 7491 | * attribution tag} or {@code null} for default attribution |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7492 | * @param message A message describing the reason the op was noted |
| 7493 | * |
| 7494 | * @hide |
Philip P. Moltmann | 0d05e48 | 2019-02-08 13:05:25 -0800 | [diff] [blame] | 7495 | */ |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7496 | public int noteProxyOpNoThrow(int op, @Nullable String proxiedPackageName, int proxiedUid, |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 7497 | @Nullable String proxiedAttributionTag, @Nullable String message) { |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7498 | int myUid = Process.myUid(); |
Philip P. Moltmann | 0d05e48 | 2019-02-08 13:05:25 -0800 | [diff] [blame] | 7499 | |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7500 | try { |
David Cheung | 2ead966 | 2020-02-19 16:11:06 -0800 | [diff] [blame] | 7501 | collectNoteOpCallsForValidation(op); |
Philip P. Moltmann | da554e4 | 2019-12-20 11:21:02 -0800 | [diff] [blame] | 7502 | int collectionMode = getNotedOpCollectionMode(proxiedUid, proxiedPackageName, op); |
| 7503 | if (collectionMode == COLLECT_ASYNC) { |
| 7504 | if (message == null) { |
| 7505 | // Set stack trace as default message |
| 7506 | message = getFormattedStackTrace(); |
| 7507 | } |
| 7508 | } |
| 7509 | |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7510 | int mode = mService.noteProxyOperation(op, proxiedUid, proxiedPackageName, |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 7511 | proxiedAttributionTag, myUid, mContext.getOpPackageName(), |
| 7512 | mContext.getAttributionTag(), collectionMode == COLLECT_ASYNC, message); |
Philip P. Moltmann | da554e4 | 2019-12-20 11:21:02 -0800 | [diff] [blame] | 7513 | |
| 7514 | if (mode == MODE_ALLOWED) { |
| 7515 | if (collectionMode == COLLECT_SELF) { |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 7516 | collectNotedOpForSelf(op, proxiedAttributionTag); |
Philip P. Moltmann | da554e4 | 2019-12-20 11:21:02 -0800 | [diff] [blame] | 7517 | } else if (collectionMode == COLLECT_SYNC |
| 7518 | // Only collect app-ops when the proxy is trusted |
| 7519 | && mContext.checkPermission(Manifest.permission.UPDATE_APP_OPS_STATS, -1, |
| 7520 | myUid) == PackageManager.PERMISSION_GRANTED) { |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 7521 | collectNotedOpSync(op, proxiedAttributionTag); |
Philip P. Moltmann | da554e4 | 2019-12-20 11:21:02 -0800 | [diff] [blame] | 7522 | } |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7523 | } |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 7524 | |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7525 | return mode; |
| 7526 | } catch (RemoteException e) { |
| 7527 | throw e.rethrowFromSystemServer(); |
| 7528 | } |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 7529 | } |
| 7530 | |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 7531 | /** |
| 7532 | * Do a quick check for whether an application might be able to perform an operation. |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7533 | * This is <em>not</em> a security check; you must use {@link #noteOp(String, int, String, |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7534 | * String, String)} or {@link #startOp(int, int, String, boolean, String, String)} for your |
| 7535 | * actual security checks, which also ensure that the given uid and package name are consistent. |
| 7536 | * This function can just be used for a quick check to see if an operation has been disabled for |
| 7537 | * the application, as an early reject of some work. This does not modify the time stamp or |
| 7538 | * other data about the operation. |
Dianne Hackborn | c216a26 | 2018-04-26 13:46:22 -0700 | [diff] [blame] | 7539 | * |
| 7540 | * <p>Important things this will not do (which you need to ultimate use |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7541 | * {@link #noteOp(String, int, String, String, String)} or |
| 7542 | * {@link #startOp(int, int, String, boolean, String, String)} to cover):</p> |
Dianne Hackborn | c216a26 | 2018-04-26 13:46:22 -0700 | [diff] [blame] | 7543 | * <ul> |
| 7544 | * <li>Verifying the uid and package are consistent, so callers can't spoof |
| 7545 | * their identity.</li> |
| 7546 | * <li>Taking into account the current foreground/background state of the |
| 7547 | * app; apps whose mode varies by this state will always be reported |
| 7548 | * as {@link #MODE_ALLOWED}.</li> |
| 7549 | * </ul> |
| 7550 | * |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 7551 | * @param op The operation to check. One of the OP_* constants. |
| 7552 | * @param uid The user id of the application attempting to perform the operation. |
| 7553 | * @param packageName The name of the application attempting to perform the operation. |
| 7554 | * @return Returns {@link #MODE_ALLOWED} if the operation is allowed, or |
| 7555 | * {@link #MODE_IGNORED} if it is not allowed and should be silently ignored (without |
| 7556 | * causing the app to crash). |
| 7557 | * @throws SecurityException If the app has been configured to crash on this op. |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 7558 | * @hide |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 7559 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 7560 | @UnsupportedAppUsage |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 7561 | public int checkOp(int op, int uid, String packageName) { |
| 7562 | try { |
| 7563 | int mode = mService.checkOperation(op, uid, packageName); |
| 7564 | if (mode == MODE_ERRORED) { |
Dianne Hackborn | 95d7853 | 2013-09-11 09:51:14 -0700 | [diff] [blame] | 7565 | throw new SecurityException(buildSecurityExceptionMsg(op, uid, packageName)); |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 7566 | } |
| 7567 | return mode; |
| 7568 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 7569 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 7570 | } |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 7571 | } |
| 7572 | |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 7573 | /** |
| 7574 | * Like {@link #checkOp} but instead of throwing a {@link SecurityException} it |
| 7575 | * returns {@link #MODE_ERRORED}. |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 7576 | * @hide |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 7577 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 7578 | @UnsupportedAppUsage |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 7579 | public int checkOpNoThrow(int op, int uid, String packageName) { |
| 7580 | try { |
Dianne Hackborn | 65a4f25 | 2018-05-08 17:30:48 -0700 | [diff] [blame] | 7581 | int mode = mService.checkOperation(op, uid, packageName); |
| 7582 | return mode == AppOpsManager.MODE_FOREGROUND ? AppOpsManager.MODE_ALLOWED : mode; |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 7583 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 7584 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 7585 | } |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 7586 | } |
| 7587 | |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 7588 | /** |
Philip P. Moltmann | a04b9ab | 2020-02-13 09:54:04 -0800 | [diff] [blame] | 7589 | * @deprecated Use {@link PackageManager#getPackageUid} instead |
Jeff Sharkey | 911d7f4 | 2013-09-05 18:11:45 -0700 | [diff] [blame] | 7590 | */ |
Philip P. Moltmann | a04b9ab | 2020-02-13 09:54:04 -0800 | [diff] [blame] | 7591 | @Deprecated |
Dianne Hackborn | 6287849 | 2019-03-11 15:57:07 -0700 | [diff] [blame] | 7592 | public void checkPackage(int uid, @NonNull String packageName) { |
Jeff Sharkey | 911d7f4 | 2013-09-05 18:11:45 -0700 | [diff] [blame] | 7593 | try { |
| 7594 | if (mService.checkPackage(uid, packageName) != MODE_ALLOWED) { |
| 7595 | throw new SecurityException( |
| 7596 | "Package " + packageName + " does not belong to " + uid); |
| 7597 | } |
| 7598 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 7599 | throw e.rethrowFromSystemServer(); |
Jeff Sharkey | 911d7f4 | 2013-09-05 18:11:45 -0700 | [diff] [blame] | 7600 | } |
| 7601 | } |
| 7602 | |
| 7603 | /** |
John Spurlock | 1af30c7 | 2014-03-10 08:33:35 -0400 | [diff] [blame] | 7604 | * Like {@link #checkOp} but at a stream-level for audio operations. |
| 7605 | * @hide |
| 7606 | */ |
| 7607 | public int checkAudioOp(int op, int stream, int uid, String packageName) { |
| 7608 | try { |
| 7609 | final int mode = mService.checkAudioOperation(op, stream, uid, packageName); |
| 7610 | if (mode == MODE_ERRORED) { |
| 7611 | throw new SecurityException(buildSecurityExceptionMsg(op, uid, packageName)); |
| 7612 | } |
| 7613 | return mode; |
| 7614 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 7615 | throw e.rethrowFromSystemServer(); |
John Spurlock | 1af30c7 | 2014-03-10 08:33:35 -0400 | [diff] [blame] | 7616 | } |
John Spurlock | 1af30c7 | 2014-03-10 08:33:35 -0400 | [diff] [blame] | 7617 | } |
| 7618 | |
| 7619 | /** |
| 7620 | * Like {@link #checkAudioOp} but instead of throwing a {@link SecurityException} it |
| 7621 | * returns {@link #MODE_ERRORED}. |
| 7622 | * @hide |
| 7623 | */ |
| 7624 | public int checkAudioOpNoThrow(int op, int stream, int uid, String packageName) { |
| 7625 | try { |
| 7626 | return mService.checkAudioOperation(op, stream, uid, packageName); |
| 7627 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 7628 | throw e.rethrowFromSystemServer(); |
John Spurlock | 1af30c7 | 2014-03-10 08:33:35 -0400 | [diff] [blame] | 7629 | } |
John Spurlock | 1af30c7 | 2014-03-10 08:33:35 -0400 | [diff] [blame] | 7630 | } |
| 7631 | |
Philip P. Moltmann | 6c6403e | 2019-12-09 10:08:29 -0800 | [diff] [blame] | 7632 | /** |
| 7633 | * @deprecated Use own local {@link android.os.Binder#Binder()} |
| 7634 | * |
| 7635 | * @hide |
| 7636 | */ |
| 7637 | @Deprecated |
| 7638 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.Q, publicAlternatives = "Create own " |
| 7639 | + "local {@link android.os.Binder}") |
Dianne Hackborn | e98f5db | 2013-07-17 17:23:25 -0700 | [diff] [blame] | 7640 | public static IBinder getToken(IAppOpsService service) { |
Philip P. Moltmann | 6c6403e | 2019-12-09 10:08:29 -0800 | [diff] [blame] | 7641 | return getClientId(); |
Dianne Hackborn | e98f5db | 2013-07-17 17:23:25 -0700 | [diff] [blame] | 7642 | } |
| 7643 | |
Philip P. Moltmann | 6c6403e | 2019-12-09 10:08:29 -0800 | [diff] [blame] | 7644 | /** @hide */ |
| 7645 | public static IBinder getClientId() { |
| 7646 | synchronized (AppOpsManager.class) { |
| 7647 | if (sClientId == null) { |
| 7648 | sClientId = new Binder(); |
| 7649 | } |
| 7650 | |
| 7651 | return sClientId; |
| 7652 | } |
| 7653 | } |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7654 | |
Stanislav Zholnin | 90516b9 | 2020-01-20 14:03:06 +0000 | [diff] [blame] | 7655 | /** @hide */ |
| 7656 | private static IAppOpsService getService() { |
| 7657 | synchronized (sLock) { |
| 7658 | if (sService == null) { |
| 7659 | sService = IAppOpsService.Stub.asInterface( |
| 7660 | ServiceManager.getService(Context.APP_OPS_SERVICE)); |
| 7661 | } |
| 7662 | return sService; |
| 7663 | } |
| 7664 | } |
| 7665 | |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7666 | /** |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7667 | * @deprecated use {@link #startOp(String, int, String, String, String)} instead |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7668 | */ |
| 7669 | @Deprecated |
| 7670 | public int startOp(@NonNull String op, int uid, @NonNull String packageName) { |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7671 | return startOp(op, uid, packageName, null, null); |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 7672 | } |
| 7673 | |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 7674 | /** |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7675 | * @deprecated Use {@link #startOp(int, int, String, boolean, String, String)} instead |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 7676 | * |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 7677 | * @hide |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 7678 | */ |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7679 | @Deprecated |
| 7680 | public int startOp(int op) { |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7681 | return startOp(op, Process.myUid(), mContext.getOpPackageName(), false, null, null); |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 7682 | } |
| 7683 | |
| 7684 | /** |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7685 | * @deprecated Use {@link #startOp(int, int, String, boolean, String, String)} instead |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7686 | * |
| 7687 | * @hide |
| 7688 | */ |
| 7689 | @Deprecated |
| 7690 | public int startOp(int op, int uid, String packageName) { |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7691 | return startOp(op, uid, packageName, false, null, null); |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7692 | } |
| 7693 | |
| 7694 | /** |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7695 | * @deprecated Use {@link #startOp(int, int, String, boolean, String, String)} instead |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7696 | * |
| 7697 | * @hide |
| 7698 | */ |
| 7699 | @Deprecated |
| 7700 | public int startOp(int op, int uid, String packageName, boolean startIfModeDefault) { |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7701 | return startOp(op, uid, packageName, startIfModeDefault, null, null); |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7702 | } |
| 7703 | |
| 7704 | /** |
| 7705 | * Report that an application has started executing a long-running operation. |
| 7706 | * |
| 7707 | * @param op The operation to start. One of the OPSTR_* constants. |
| 7708 | * @param uid The user id of the application attempting to perform the operation. |
| 7709 | * @param packageName The name of the application attempting to perform the operation. |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 7710 | * @param attributionTag The {@link Context#createAttributionContext attribution tag} or |
| 7711 | * {@code null} for default attribution |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7712 | * @param message Description why op was started |
| 7713 | * |
| 7714 | * @return Returns {@link #MODE_ALLOWED} if the operation is allowed, or |
| 7715 | * {@link #MODE_IGNORED} if it is not allowed and should be silently ignored (without |
| 7716 | * causing the app to crash). |
| 7717 | * |
| 7718 | * @throws SecurityException If the app has been configured to crash on this op or |
| 7719 | * the package is not in the passed in UID. |
| 7720 | */ |
| 7721 | public int startOp(@NonNull String op, int uid, @Nullable String packageName, |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 7722 | @Nullable String attributionTag, @Nullable String message) { |
| 7723 | return startOp(strOpToOp(op), uid, packageName, false, attributionTag, message); |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7724 | } |
| 7725 | |
| 7726 | /** |
| 7727 | * Report that an application has started executing a long-running operation. |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 7728 | * |
| 7729 | * @param op The operation to start. One of the OP_* constants. |
| 7730 | * @param uid The user id of the application attempting to perform the operation. |
| 7731 | * @param packageName The name of the application attempting to perform the operation. |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 7732 | * @param attributionTag The {@link Context#createAttributionContext attribution tag} or |
| 7733 | * {@code null} for default attribution |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7734 | * @param startIfModeDefault Whether to start if mode is {@link #MODE_DEFAULT}. |
| 7735 | * @param message Description why op was started |
| 7736 | * |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 7737 | * @return Returns {@link #MODE_ALLOWED} if the operation is allowed, or |
| 7738 | * {@link #MODE_IGNORED} if it is not allowed and should be silently ignored (without |
| 7739 | * causing the app to crash). |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 7740 | * |
| 7741 | * @throws SecurityException If the app has been configured to crash on this op or |
| 7742 | * the package is not in the passed in UID. |
| 7743 | * |
| 7744 | * @hide |
| 7745 | */ |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7746 | public int startOp(int op, int uid, @Nullable String packageName, boolean startIfModeDefault, |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 7747 | @Nullable String attributionTag, @Nullable String message) { |
| 7748 | final int mode = startOpNoThrow(op, uid, packageName, startIfModeDefault, attributionTag, |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7749 | message); |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 7750 | if (mode == MODE_ERRORED) { |
| 7751 | throw new SecurityException(buildSecurityExceptionMsg(op, uid, packageName)); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 7752 | } |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 7753 | return mode; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 7754 | } |
| 7755 | |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 7756 | /** |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7757 | * @deprecated use {@link #startOpNoThrow(String, int, String, String, String)} instead |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 7758 | */ |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7759 | @Deprecated |
| 7760 | public int startOpNoThrow(@NonNull String op, int uid, @NonNull String packageName) { |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7761 | return startOpNoThrow(op, uid, packageName, null, null); |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 7762 | } |
| 7763 | |
| 7764 | /** |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7765 | * @deprecated Use {@link #startOpNoThrow(int, int, String, boolean, String, String} instead |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7766 | * |
| 7767 | * @hide |
| 7768 | */ |
| 7769 | @Deprecated |
| 7770 | public int startOpNoThrow(int op, int uid, String packageName) { |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7771 | return startOpNoThrow(op, uid, packageName, false, null, null); |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7772 | } |
| 7773 | |
| 7774 | /** |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7775 | * @deprecated Use {@link #startOpNoThrow(int, int, String, boolean, String, String} instead |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7776 | * |
| 7777 | * @hide |
| 7778 | */ |
| 7779 | @Deprecated |
| 7780 | public int startOpNoThrow(int op, int uid, String packageName, boolean startIfModeDefault) { |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7781 | return startOpNoThrow(op, uid, packageName, startIfModeDefault, null, null); |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7782 | } |
| 7783 | |
| 7784 | /** |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7785 | * Like {@link #startOp(String, int, String, String, String)} but instead of throwing a |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 7786 | * {@link SecurityException} it returns {@link #MODE_ERRORED}. |
| 7787 | * |
| 7788 | * @param op The operation to start. One of the OP_* constants. |
| 7789 | * @param uid The user id of the application attempting to perform the operation. |
| 7790 | * @param packageName The name of the application attempting to perform the operation. |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 7791 | * @param attributionTag The {@link Context#createAttributionContext attribution tag} or |
| 7792 | * {@code null} for default attribution |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7793 | * @param message Description why op was started |
| 7794 | * |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 7795 | * @return Returns {@link #MODE_ALLOWED} if the operation is allowed, or |
| 7796 | * {@link #MODE_IGNORED} if it is not allowed and should be silently ignored (without |
| 7797 | * causing the app to crash). |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7798 | */ |
| 7799 | public int startOpNoThrow(@NonNull String op, int uid, @NonNull String packageName, |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 7800 | @NonNull String attributionTag, @Nullable String message) { |
| 7801 | return startOpNoThrow(strOpToOp(op), uid, packageName, false, attributionTag, message); |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7802 | } |
| 7803 | |
| 7804 | /** |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7805 | * Like {@link #startOp(int, int, String, boolean, String, String)} but instead of throwing a |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7806 | * {@link SecurityException} it returns {@link #MODE_ERRORED}. |
| 7807 | * |
| 7808 | * @param op The operation to start. One of the OP_* constants. |
| 7809 | * @param uid The user id of the application attempting to perform the operation. |
| 7810 | * @param packageName The name of the application attempting to perform the operation. |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 7811 | * @param attributionTag The {@link Context#createAttributionContext attribution tag} or |
| 7812 | * {@code null} for default attribution |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 7813 | * @param startIfModeDefault Whether to start if mode is {@link #MODE_DEFAULT}. |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7814 | * @param message Description why op was started |
| 7815 | * |
| 7816 | * @return Returns {@link #MODE_ALLOWED} if the operation is allowed, or |
| 7817 | * {@link #MODE_IGNORED} if it is not allowed and should be silently ignored (without |
| 7818 | * causing the app to crash). |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 7819 | * |
| 7820 | * @hide |
| 7821 | */ |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7822 | public int startOpNoThrow(int op, int uid, @NonNull String packageName, |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 7823 | boolean startIfModeDefault, @Nullable String attributionTag, @Nullable String message) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 7824 | try { |
David Cheung | 2ead966 | 2020-02-19 16:11:06 -0800 | [diff] [blame] | 7825 | collectNoteOpCallsForValidation(op); |
Philip P. Moltmann | da554e4 | 2019-12-20 11:21:02 -0800 | [diff] [blame] | 7826 | int collectionMode = getNotedOpCollectionMode(uid, packageName, op); |
| 7827 | if (collectionMode == COLLECT_ASYNC) { |
| 7828 | if (message == null) { |
| 7829 | // Set stack trace as default message |
| 7830 | message = getFormattedStackTrace(); |
| 7831 | } |
| 7832 | } |
| 7833 | |
Philip P. Moltmann | 6c6403e | 2019-12-09 10:08:29 -0800 | [diff] [blame] | 7834 | int mode = mService.startOperation(getClientId(), op, uid, packageName, |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 7835 | attributionTag, startIfModeDefault, collectionMode == COLLECT_ASYNC, message); |
Philip P. Moltmann | da554e4 | 2019-12-20 11:21:02 -0800 | [diff] [blame] | 7836 | |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7837 | if (mode == MODE_ALLOWED) { |
Philip P. Moltmann | da554e4 | 2019-12-20 11:21:02 -0800 | [diff] [blame] | 7838 | if (collectionMode == COLLECT_SELF) { |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 7839 | collectNotedOpForSelf(op, attributionTag); |
Philip P. Moltmann | da554e4 | 2019-12-20 11:21:02 -0800 | [diff] [blame] | 7840 | } else if (collectionMode == COLLECT_SYNC) { |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 7841 | collectNotedOpSync(op, attributionTag); |
Philip P. Moltmann | da554e4 | 2019-12-20 11:21:02 -0800 | [diff] [blame] | 7842 | } |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7843 | } |
| 7844 | |
| 7845 | return mode; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 7846 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 7847 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 7848 | } |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 7849 | } |
| 7850 | |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 7851 | /** |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7852 | * @deprecated Use {@link #finishOp(String, int, String, String)} instead |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7853 | * |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 7854 | * @hide |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 7855 | */ |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7856 | @Deprecated |
| 7857 | public void finishOp(int op) { |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7858 | finishOp(op, Process.myUid(), mContext.getOpPackageName(), null); |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7859 | } |
| 7860 | |
| 7861 | /** |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7862 | * @deprecated Use {@link #finishOp(String, int, String, String)} instead |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7863 | */ |
| 7864 | public void finishOp(@NonNull String op, int uid, @NonNull String packageName) { |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7865 | finishOp(strOpToOp(op), uid, packageName, null); |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7866 | } |
| 7867 | |
| 7868 | /** |
| 7869 | * Report that an application is no longer performing an operation that had previously |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7870 | * been started with {@link #startOp(String, int, String, String, String)}. There is no |
| 7871 | * validation of input or result; the parameters supplied here must be the exact same ones |
| 7872 | * previously passed in when starting the operation. |
| 7873 | */ |
| 7874 | public void finishOp(@NonNull String op, int uid, @NonNull String packageName, |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 7875 | @Nullable String attributionTag) { |
| 7876 | finishOp(strOpToOp(op), uid, packageName, attributionTag); |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7877 | } |
| 7878 | |
| 7879 | /** |
| 7880 | * @deprecated Use {@link #finishOp(int, int, String, String)} instead |
| 7881 | * |
| 7882 | * @hide |
| 7883 | */ |
| 7884 | public void finishOp(int op, int uid, @NonNull String packageName) { |
| 7885 | finishOp(op, uid, packageName, null); |
| 7886 | } |
| 7887 | |
| 7888 | /** |
| 7889 | * Report that an application is no longer performing an operation that had previously |
| 7890 | * been started with {@link #startOp(int, int, String, boolean, String, String)}. There is no |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7891 | * validation of input or result; the parameters supplied here must be the exact same ones |
| 7892 | * previously passed in when starting the operation. |
| 7893 | * |
| 7894 | * @hide |
| 7895 | */ |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7896 | public void finishOp(int op, int uid, @NonNull String packageName, |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 7897 | @Nullable String attributionTag) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 7898 | try { |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 7899 | mService.finishOperation(getClientId(), op, uid, packageName, attributionTag); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 7900 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 7901 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 7902 | } |
| 7903 | } |
| 7904 | |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 7905 | /** |
Philip P. Moltmann | a04b9ab | 2020-02-13 09:54:04 -0800 | [diff] [blame] | 7906 | * Checks whether the given op for a package is active, i.e. did someone call {@link #startOp} |
| 7907 | * without {@link #finishOp} yet. |
Jeff Sharkey | 7095ab9 | 2019-08-20 16:50:28 -0600 | [diff] [blame] | 7908 | * <p> |
| 7909 | * If you don't hold the {@code android.Manifest.permission#WATCH_APPOPS} |
| 7910 | * permission you can query only for your UID. |
| 7911 | * |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7912 | * @see #finishOp(String, int, String, String) |
| 7913 | * @see #startOp(String, int, String, String, String) |
Jeff Sharkey | 7095ab9 | 2019-08-20 16:50:28 -0600 | [diff] [blame] | 7914 | */ |
| 7915 | public boolean isOpActive(@NonNull String op, int uid, @NonNull String packageName) { |
| 7916 | return isOperationActive(strOpToOp(op), uid, packageName); |
| 7917 | } |
| 7918 | |
| 7919 | /** |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7920 | * Start collection of noted appops on this thread. |
| 7921 | * |
| 7922 | * <p>Called at the beginning of a two way binder transaction. |
| 7923 | * |
| 7924 | * @see #finishNotedAppOpsCollection() |
| 7925 | * |
| 7926 | * @hide |
| 7927 | */ |
| 7928 | public static void startNotedAppOpsCollection(int callingUid) { |
| 7929 | sBinderThreadCallingUid.set(callingUid); |
| 7930 | } |
| 7931 | |
| 7932 | /** |
| 7933 | * State of a temporarily paused noted app-ops collection. |
| 7934 | * |
| 7935 | * @see #pauseNotedAppOpsCollection() |
| 7936 | * |
| 7937 | * @hide |
| 7938 | */ |
| 7939 | public static class PausedNotedAppOpsCollection { |
| 7940 | final int mUid; |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7941 | final @Nullable ArrayMap<String, long[]> mCollectedNotedAppOps; |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7942 | |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7943 | PausedNotedAppOpsCollection(int uid, @Nullable ArrayMap<String, |
| 7944 | long[]> collectedNotedAppOps) { |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7945 | mUid = uid; |
| 7946 | mCollectedNotedAppOps = collectedNotedAppOps; |
| 7947 | } |
| 7948 | } |
| 7949 | |
| 7950 | /** |
| 7951 | * Temporarily suspend collection of noted app-ops when binder-thread calls into the other |
| 7952 | * process. During such a call there might be call-backs coming back on the same thread which |
| 7953 | * should not be accounted to the current collection. |
| 7954 | * |
| 7955 | * @return a state needed to resume the collection |
| 7956 | * |
| 7957 | * @hide |
| 7958 | */ |
| 7959 | public static @Nullable PausedNotedAppOpsCollection pauseNotedAppOpsCollection() { |
| 7960 | Integer previousUid = sBinderThreadCallingUid.get(); |
| 7961 | if (previousUid != null) { |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7962 | ArrayMap<String, long[]> previousCollectedNotedAppOps = |
| 7963 | sAppOpsNotedInThisBinderTransaction.get(); |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7964 | |
| 7965 | sBinderThreadCallingUid.remove(); |
| 7966 | sAppOpsNotedInThisBinderTransaction.remove(); |
| 7967 | |
| 7968 | return new PausedNotedAppOpsCollection(previousUid, previousCollectedNotedAppOps); |
| 7969 | } |
| 7970 | |
| 7971 | return null; |
| 7972 | } |
| 7973 | |
| 7974 | /** |
| 7975 | * Resume a collection paused via {@link #pauseNotedAppOpsCollection}. |
| 7976 | * |
| 7977 | * @param prevCollection The state of the previous collection |
| 7978 | * |
| 7979 | * @hide |
| 7980 | */ |
| 7981 | public static void resumeNotedAppOpsCollection( |
| 7982 | @Nullable PausedNotedAppOpsCollection prevCollection) { |
| 7983 | if (prevCollection != null) { |
| 7984 | sBinderThreadCallingUid.set(prevCollection.mUid); |
| 7985 | |
| 7986 | if (prevCollection.mCollectedNotedAppOps != null) { |
| 7987 | sAppOpsNotedInThisBinderTransaction.set(prevCollection.mCollectedNotedAppOps); |
| 7988 | } |
| 7989 | } |
| 7990 | } |
| 7991 | |
| 7992 | /** |
| 7993 | * Finish collection of noted appops on this thread. |
| 7994 | * |
| 7995 | * <p>Called at the end of a two way binder transaction. |
| 7996 | * |
| 7997 | * @see #startNotedAppOpsCollection(int) |
| 7998 | * |
| 7999 | * @hide |
| 8000 | */ |
| 8001 | public static void finishNotedAppOpsCollection() { |
| 8002 | sBinderThreadCallingUid.remove(); |
| 8003 | sAppOpsNotedInThisBinderTransaction.remove(); |
| 8004 | } |
| 8005 | |
| 8006 | /** |
Philip P. Moltmann | da554e4 | 2019-12-20 11:21:02 -0800 | [diff] [blame] | 8007 | * Collect a noted op for the current process. |
| 8008 | * |
| 8009 | * @param op The noted op |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 8010 | * @param attributionTag The attribution tag the op is noted for |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8011 | */ |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 8012 | private void collectNotedOpForSelf(int op, @Nullable String attributionTag) { |
Philip P. Moltmann | da554e4 | 2019-12-20 11:21:02 -0800 | [diff] [blame] | 8013 | synchronized (sLock) { |
Philip P. Moltmann | 5892a8f | 2020-03-03 12:05:55 -0800 | [diff] [blame] | 8014 | if (sOnOpNotedCallback != null) { |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 8015 | sOnOpNotedCallback.onSelfNoted(new SyncNotedAppOp(op, attributionTag)); |
Philip P. Moltmann | da554e4 | 2019-12-20 11:21:02 -0800 | [diff] [blame] | 8016 | } |
| 8017 | } |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 8018 | sMessageCollector.onSelfNoted(new SyncNotedAppOp(op, attributionTag)); |
Philip P. Moltmann | da554e4 | 2019-12-20 11:21:02 -0800 | [diff] [blame] | 8019 | } |
| 8020 | |
| 8021 | /** |
| 8022 | * Collect a noted op when inside of a two-way binder call. |
| 8023 | * |
| 8024 | * <p> Delivered to caller via {@link #prefixParcelWithAppOpsIfNeeded} |
| 8025 | * |
| 8026 | * @param op The noted op |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 8027 | * @param attributionTag The attribution tag the op is noted for |
Philip P. Moltmann | da554e4 | 2019-12-20 11:21:02 -0800 | [diff] [blame] | 8028 | */ |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 8029 | private void collectNotedOpSync(int op, @Nullable String attributionTag) { |
Philip P. Moltmann | da554e4 | 2019-12-20 11:21:02 -0800 | [diff] [blame] | 8030 | // If this is inside of a two-way binder call: |
| 8031 | // We are inside of a two-way binder call. Delivered to caller via |
| 8032 | // {@link #prefixParcelWithAppOpsIfNeeded} |
| 8033 | ArrayMap<String, long[]> appOpsNoted = sAppOpsNotedInThisBinderTransaction.get(); |
| 8034 | if (appOpsNoted == null) { |
| 8035 | appOpsNoted = new ArrayMap<>(1); |
| 8036 | sAppOpsNotedInThisBinderTransaction.set(appOpsNoted); |
| 8037 | } |
| 8038 | |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 8039 | long[] appOpsNotedForAttribution = appOpsNoted.get(attributionTag); |
| 8040 | if (appOpsNotedForAttribution == null) { |
| 8041 | appOpsNotedForAttribution = new long[2]; |
| 8042 | appOpsNoted.put(attributionTag, appOpsNotedForAttribution); |
Philip P. Moltmann | da554e4 | 2019-12-20 11:21:02 -0800 | [diff] [blame] | 8043 | } |
| 8044 | |
| 8045 | if (op < 64) { |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 8046 | appOpsNotedForAttribution[0] |= 1L << op; |
Philip P. Moltmann | da554e4 | 2019-12-20 11:21:02 -0800 | [diff] [blame] | 8047 | } else { |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 8048 | appOpsNotedForAttribution[1] |= 1L << (op - 64); |
Philip P. Moltmann | da554e4 | 2019-12-20 11:21:02 -0800 | [diff] [blame] | 8049 | } |
| 8050 | } |
| 8051 | |
| 8052 | /** @hide */ |
| 8053 | @Retention(RetentionPolicy.SOURCE) |
| 8054 | @IntDef(value = { |
| 8055 | DONT_COLLECT, |
| 8056 | COLLECT_SELF, |
| 8057 | COLLECT_SYNC, |
| 8058 | COLLECT_ASYNC |
| 8059 | }) |
| 8060 | private @interface NotedOpCollectionMode {} |
| 8061 | private static final int DONT_COLLECT = 0; |
| 8062 | private static final int COLLECT_SELF = 1; |
| 8063 | private static final int COLLECT_SYNC = 2; |
| 8064 | private static final int COLLECT_ASYNC = 3; |
| 8065 | |
| 8066 | /** |
| 8067 | * Mark an app-op as noted. |
| 8068 | */ |
| 8069 | private @NotedOpCollectionMode int getNotedOpCollectionMode(int uid, |
| 8070 | @Nullable String packageName, int op) { |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 8071 | if (packageName == null) { |
| 8072 | packageName = "android"; |
| 8073 | } |
| 8074 | |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8075 | // check it the appops needs to be collected and cache result |
Philip P. Moltmann | da554e4 | 2019-12-20 11:21:02 -0800 | [diff] [blame] | 8076 | if (sAppOpsToNote[op] == SHOULD_COLLECT_NOTE_OP_NOT_INITIALIZED) { |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8077 | boolean shouldCollectNotes; |
| 8078 | try { |
Philip P. Moltmann | da554e4 | 2019-12-20 11:21:02 -0800 | [diff] [blame] | 8079 | shouldCollectNotes = mService.shouldCollectNotes(op); |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8080 | } catch (RemoteException e) { |
Philip P. Moltmann | da554e4 | 2019-12-20 11:21:02 -0800 | [diff] [blame] | 8081 | return DONT_COLLECT; |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8082 | } |
| 8083 | |
| 8084 | if (shouldCollectNotes) { |
Philip P. Moltmann | da554e4 | 2019-12-20 11:21:02 -0800 | [diff] [blame] | 8085 | sAppOpsToNote[op] = SHOULD_COLLECT_NOTE_OP; |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8086 | } else { |
Philip P. Moltmann | da554e4 | 2019-12-20 11:21:02 -0800 | [diff] [blame] | 8087 | sAppOpsToNote[op] = SHOULD_NOT_COLLECT_NOTE_OP; |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8088 | } |
| 8089 | } |
| 8090 | |
Philip P. Moltmann | da554e4 | 2019-12-20 11:21:02 -0800 | [diff] [blame] | 8091 | if (sAppOpsToNote[op] != SHOULD_COLLECT_NOTE_OP) { |
| 8092 | return DONT_COLLECT; |
| 8093 | } |
| 8094 | |
| 8095 | synchronized (sLock) { |
| 8096 | if (uid == Process.myUid() |
| 8097 | && packageName.equals(ActivityThread.currentOpPackageName())) { |
| 8098 | return COLLECT_SELF; |
| 8099 | } |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8100 | } |
| 8101 | |
| 8102 | Integer binderUid = sBinderThreadCallingUid.get(); |
| 8103 | |
Philip P. Moltmann | 9bcc406 | 2019-09-06 12:27:59 -0700 | [diff] [blame] | 8104 | if (binderUid != null && binderUid == uid) { |
Philip P. Moltmann | da554e4 | 2019-12-20 11:21:02 -0800 | [diff] [blame] | 8105 | return COLLECT_SYNC; |
Philip P. Moltmann | 9bcc406 | 2019-09-06 12:27:59 -0700 | [diff] [blame] | 8106 | } else { |
Philip P. Moltmann | da554e4 | 2019-12-20 11:21:02 -0800 | [diff] [blame] | 8107 | return COLLECT_ASYNC; |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8108 | } |
| 8109 | } |
| 8110 | |
| 8111 | /** |
| 8112 | * Append app-ops noted in the current two-way binder transaction to parcel. |
| 8113 | * |
| 8114 | * <p>This is called on the callee side of a two way binder transaction just before the |
| 8115 | * transaction returns. |
| 8116 | * |
| 8117 | * @param p the parcel to append the noted app-ops to |
| 8118 | * |
| 8119 | * @hide |
| 8120 | */ |
| 8121 | public static void prefixParcelWithAppOpsIfNeeded(@NonNull Parcel p) { |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 8122 | ArrayMap<String, long[]> notedAppOps = sAppOpsNotedInThisBinderTransaction.get(); |
| 8123 | if (notedAppOps == null) { |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8124 | return; |
| 8125 | } |
| 8126 | |
| 8127 | p.writeInt(Parcel.EX_HAS_NOTED_APPOPS_REPLY_HEADER); |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 8128 | |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 8129 | int numAttributionWithNotesAppOps = notedAppOps.size(); |
| 8130 | p.writeInt(numAttributionWithNotesAppOps); |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 8131 | |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 8132 | for (int i = 0; i < numAttributionWithNotesAppOps; i++) { |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 8133 | p.writeString(notedAppOps.keyAt(i)); |
| 8134 | p.writeLong(notedAppOps.valueAt(i)[0]); |
| 8135 | p.writeLong(notedAppOps.valueAt(i)[1]); |
| 8136 | } |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8137 | } |
| 8138 | |
| 8139 | /** |
| 8140 | * Read app-ops noted during a two-way binder transaction from parcel. |
| 8141 | * |
| 8142 | * <p>This is called on the calling side of a two way binder transaction just after the |
| 8143 | * transaction returns. |
| 8144 | * |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8145 | * @param p The parcel to read from |
| 8146 | * |
| 8147 | * @hide |
| 8148 | */ |
| 8149 | public static void readAndLogNotedAppops(@NonNull Parcel p) { |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 8150 | int numAttributionsWithNotedAppOps = p.readInt(); |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8151 | |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 8152 | for (int i = 0; i < numAttributionsWithNotedAppOps; i++) { |
| 8153 | String attributionTag = p.readString(); |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 8154 | long[] rawNotedAppOps = new long[2]; |
| 8155 | rawNotedAppOps[0] = p.readLong(); |
| 8156 | rawNotedAppOps[1] = p.readLong(); |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8157 | |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 8158 | if (rawNotedAppOps[0] != 0 || rawNotedAppOps[1] != 0) { |
| 8159 | BitSet notedAppOps = BitSet.valueOf(rawNotedAppOps); |
| 8160 | |
| 8161 | synchronized (sLock) { |
| 8162 | for (int code = notedAppOps.nextSetBit(0); code != -1; |
| 8163 | code = notedAppOps.nextSetBit(code + 1)) { |
Philip P. Moltmann | 5892a8f | 2020-03-03 12:05:55 -0800 | [diff] [blame] | 8164 | if (sOnOpNotedCallback != null) { |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 8165 | sOnOpNotedCallback.onNoted(new SyncNotedAppOp(code, attributionTag)); |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 8166 | } |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8167 | } |
| 8168 | } |
Stanislav Zholnin | 90516b9 | 2020-01-20 14:03:06 +0000 | [diff] [blame] | 8169 | for (int code = notedAppOps.nextSetBit(0); code != -1; |
| 8170 | code = notedAppOps.nextSetBit(code + 1)) { |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 8171 | sMessageCollector.onNoted(new SyncNotedAppOp(code, attributionTag)); |
Stanislav Zholnin | 90516b9 | 2020-01-20 14:03:06 +0000 | [diff] [blame] | 8172 | } |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8173 | } |
| 8174 | } |
| 8175 | } |
| 8176 | |
| 8177 | /** |
Philip P. Moltmann | 5892a8f | 2020-03-03 12:05:55 -0800 | [diff] [blame] | 8178 | * Set a new {@link OnOpNotedCallback}. |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8179 | * |
Philip P. Moltmann | 5892a8f | 2020-03-03 12:05:55 -0800 | [diff] [blame] | 8180 | * <p>There can only ever be one collector per process. If there currently is another callback |
| 8181 | * set, this will fail. |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8182 | * |
Philip P. Moltmann | 5892a8f | 2020-03-03 12:05:55 -0800 | [diff] [blame] | 8183 | * @param asyncExecutor executor to execute {@link OnOpNotedCallback#onAsyncNoted} on, {@code |
| 8184 | * null} to unset |
| 8185 | * @param callback listener to set, {@code null} to unset |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8186 | * |
Philip P. Moltmann | 5892a8f | 2020-03-03 12:05:55 -0800 | [diff] [blame] | 8187 | * @throws IllegalStateException If another callback is already registered |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8188 | */ |
Philip P. Moltmann | 5892a8f | 2020-03-03 12:05:55 -0800 | [diff] [blame] | 8189 | public void setOnOpNotedCallback(@Nullable @CallbackExecutor Executor asyncExecutor, |
| 8190 | @Nullable OnOpNotedCallback callback) { |
| 8191 | Preconditions.checkState((callback == null) == (asyncExecutor == null)); |
| 8192 | |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8193 | synchronized (sLock) { |
Philip P. Moltmann | 5892a8f | 2020-03-03 12:05:55 -0800 | [diff] [blame] | 8194 | if (callback == null) { |
| 8195 | Preconditions.checkState(sOnOpNotedCallback != null, |
| 8196 | "No callback is currently registered"); |
| 8197 | |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8198 | try { |
| 8199 | mService.stopWatchingAsyncNoted(mContext.getPackageName(), |
Philip P. Moltmann | 5892a8f | 2020-03-03 12:05:55 -0800 | [diff] [blame] | 8200 | sOnOpNotedCallback.mAsyncCb); |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8201 | } catch (RemoteException e) { |
| 8202 | e.rethrowFromSystemServer(); |
| 8203 | } |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8204 | |
Philip P. Moltmann | 5892a8f | 2020-03-03 12:05:55 -0800 | [diff] [blame] | 8205 | sOnOpNotedCallback = null; |
| 8206 | } else { |
| 8207 | Preconditions.checkState(sOnOpNotedCallback == null, |
| 8208 | "Another callback is already registered"); |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8209 | |
Philip P. Moltmann | 5892a8f | 2020-03-03 12:05:55 -0800 | [diff] [blame] | 8210 | callback.mAsyncExecutor = asyncExecutor; |
| 8211 | sOnOpNotedCallback = callback; |
| 8212 | |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8213 | List<AsyncNotedAppOp> missedAsyncOps = null; |
| 8214 | try { |
| 8215 | mService.startWatchingAsyncNoted(mContext.getPackageName(), |
Philip P. Moltmann | 5892a8f | 2020-03-03 12:05:55 -0800 | [diff] [blame] | 8216 | sOnOpNotedCallback.mAsyncCb); |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8217 | missedAsyncOps = mService.extractAsyncOps(mContext.getPackageName()); |
| 8218 | } catch (RemoteException e) { |
| 8219 | e.rethrowFromSystemServer(); |
| 8220 | } |
| 8221 | |
| 8222 | if (missedAsyncOps != null) { |
| 8223 | int numMissedAsyncOps = missedAsyncOps.size(); |
| 8224 | for (int i = 0; i < numMissedAsyncOps; i++) { |
| 8225 | final AsyncNotedAppOp asyncNotedAppOp = missedAsyncOps.get(i); |
Philip P. Moltmann | 5892a8f | 2020-03-03 12:05:55 -0800 | [diff] [blame] | 8226 | if (sOnOpNotedCallback != null) { |
| 8227 | sOnOpNotedCallback.getAsyncNotedExecutor().execute( |
| 8228 | () -> sOnOpNotedCallback.onAsyncNoted(asyncNotedAppOp)); |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8229 | } |
| 8230 | } |
| 8231 | } |
| 8232 | } |
| 8233 | } |
| 8234 | } |
| 8235 | |
Philip P. Moltmann | 5892a8f | 2020-03-03 12:05:55 -0800 | [diff] [blame] | 8236 | // TODO moltmann: Remove |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8237 | /** |
Philip P. Moltmann | 5892a8f | 2020-03-03 12:05:55 -0800 | [diff] [blame] | 8238 | * Will be removed before R ships, leave it just to not break apps immediately. |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8239 | * |
Philip P. Moltmann | 5892a8f | 2020-03-03 12:05:55 -0800 | [diff] [blame] | 8240 | * @removed |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8241 | * |
| 8242 | * @hide |
| 8243 | */ |
Philip P. Moltmann | 5892a8f | 2020-03-03 12:05:55 -0800 | [diff] [blame] | 8244 | @SystemApi |
| 8245 | @Deprecated |
| 8246 | public void setNotedAppOpsCollector(@Nullable AppOpsCollector collector) { |
| 8247 | synchronized (sLock) { |
| 8248 | if (collector != null) { |
| 8249 | if (isListeningForOpNoted()) { |
| 8250 | setOnOpNotedCallback(null, null); |
| 8251 | } |
| 8252 | setOnOpNotedCallback(new HandlerExecutor(Handler.getMain()), collector); |
| 8253 | } else if (sOnOpNotedCallback != null) { |
| 8254 | setOnOpNotedCallback(null, null); |
| 8255 | } |
| 8256 | } |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8257 | } |
| 8258 | |
| 8259 | /** |
Philip P. Moltmann | 5892a8f | 2020-03-03 12:05:55 -0800 | [diff] [blame] | 8260 | * @return {@code true} iff the process currently is currently collecting noted appops. |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8261 | * |
Philip P. Moltmann | 5892a8f | 2020-03-03 12:05:55 -0800 | [diff] [blame] | 8262 | * @see #setOnOpNotedCallback |
| 8263 | * |
| 8264 | * @hide |
| 8265 | */ |
| 8266 | public static boolean isListeningForOpNoted() { |
Stanislav Zholnin | d4968a0 | 2020-04-18 21:01:13 +0100 | [diff] [blame] | 8267 | return sOnOpNotedCallback != null || isCollectingStackTraces(); |
| 8268 | } |
| 8269 | |
| 8270 | /** |
| 8271 | * @return {@code true} iff the process is currently sampled for stacktrace collection. |
| 8272 | * |
| 8273 | * @see #setOnOpNotedCallback |
| 8274 | * |
| 8275 | * @hide |
| 8276 | */ |
| 8277 | private static boolean isCollectingStackTraces() { |
| 8278 | if (sConfig.getSampledOpCode() == OP_NONE && |
| 8279 | sConfig.getExpirationTimeSinceBootMillis() >= SystemClock.elapsedRealtime()) { |
| 8280 | return false; |
| 8281 | } |
| 8282 | return true; |
Philip P. Moltmann | 5892a8f | 2020-03-03 12:05:55 -0800 | [diff] [blame] | 8283 | } |
| 8284 | |
| 8285 | /** |
| 8286 | * Callback an app can {@link #setOnOpNotedCallback set} to monitor the app-ops the |
| 8287 | * system has tracked for it. I.e. each time any app calls {@link #noteOp} or {@link #startOp} |
| 8288 | * one of a method of this object is called. |
| 8289 | * |
| 8290 | * <p><b>There will be a call for all app-ops related to runtime permissions, but not |
Philip P. Moltmann | a04b9ab | 2020-02-13 09:54:04 -0800 | [diff] [blame] | 8291 | * necessarily for all other app-ops. |
Philip P. Moltmann | 9e36700 | 2020-02-03 17:01:05 -0800 | [diff] [blame] | 8292 | * |
| 8293 | * <pre> |
Philip P. Moltmann | 5892a8f | 2020-03-03 12:05:55 -0800 | [diff] [blame] | 8294 | * setOnOpNotedCallback(getMainExecutor(), new OnOpNotedCallback() { |
Philip P. Moltmann | 9e36700 | 2020-02-03 17:01:05 -0800 | [diff] [blame] | 8295 | * ArraySet<Pair<String, String>> opsNotedForThisProcess = new ArraySet<>(); |
| 8296 | * |
| 8297 | * private synchronized void addAccess(String op, String accessLocation) { |
Philip P. Moltmann | a04b9ab | 2020-02-13 09:54:04 -0800 | [diff] [blame] | 8298 | * // Ops are often noted when runtime permission protected APIs were called. |
Philip P. Moltmann | 9e36700 | 2020-02-03 17:01:05 -0800 | [diff] [blame] | 8299 | * // In this case permissionToOp() allows to resolve the permission<->op |
| 8300 | * opsNotedForThisProcess.add(new Pair(accessType, accessLocation)); |
| 8301 | * } |
| 8302 | * |
| 8303 | * public void onNoted(SyncNotedAppOp op) { |
| 8304 | * // Accesses is currently happening, hence stack trace describes location of access |
| 8305 | * addAccess(op.getOp(), Arrays.toString(Thread.currentThread().getStackTrace())); |
| 8306 | * } |
| 8307 | * |
| 8308 | * public void onSelfNoted(SyncNotedAppOp op) { |
| 8309 | * onNoted(op); |
| 8310 | * } |
| 8311 | * |
| 8312 | * public void onAsyncNoted(AsyncNotedAppOp asyncOp) { |
| 8313 | * // Stack trace is not useful for async ops as accessed happened on different thread |
| 8314 | * addAccess(asyncOp.getOp(), asyncOp.getMessage()); |
| 8315 | * } |
| 8316 | * }); |
| 8317 | * </pre> |
| 8318 | * |
Philip P. Moltmann | 5892a8f | 2020-03-03 12:05:55 -0800 | [diff] [blame] | 8319 | * @see #setOnOpNotedCallback |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8320 | */ |
Philip P. Moltmann | 5892a8f | 2020-03-03 12:05:55 -0800 | [diff] [blame] | 8321 | public abstract static class OnOpNotedCallback { |
| 8322 | private @NonNull Executor mAsyncExecutor; |
| 8323 | |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8324 | /** Callback registered with the system. This will receive the async notes ops */ |
| 8325 | private final IAppOpsAsyncNotedCallback mAsyncCb = new IAppOpsAsyncNotedCallback.Stub() { |
| 8326 | @Override |
| 8327 | public void opNoted(AsyncNotedAppOp op) { |
Daulet Zhanguzin | 0af97d6 | 2019-12-30 15:41:28 +0000 | [diff] [blame] | 8328 | Objects.requireNonNull(op); |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8329 | |
Philip P. Moltmann | 5892a8f | 2020-03-03 12:05:55 -0800 | [diff] [blame] | 8330 | long token = Binder.clearCallingIdentity(); |
| 8331 | try { |
| 8332 | getAsyncNotedExecutor().execute(() -> onAsyncNoted(op)); |
| 8333 | } finally { |
| 8334 | Binder.restoreCallingIdentity(token); |
| 8335 | } |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8336 | } |
| 8337 | }; |
| 8338 | |
Philip P. Moltmann | 5892a8f | 2020-03-03 12:05:55 -0800 | [diff] [blame] | 8339 | // TODO moltmann: Remove |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8340 | /** |
Philip P. Moltmann | 5892a8f | 2020-03-03 12:05:55 -0800 | [diff] [blame] | 8341 | * Will be removed before R ships. |
| 8342 | * |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8343 | * @return The executor for the system to use when calling {@link #onAsyncNoted}. |
Philip P. Moltmann | 5892a8f | 2020-03-03 12:05:55 -0800 | [diff] [blame] | 8344 | * |
| 8345 | * @hide |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8346 | */ |
Philip P. Moltmann | 5892a8f | 2020-03-03 12:05:55 -0800 | [diff] [blame] | 8347 | protected @NonNull Executor getAsyncNotedExecutor() { |
| 8348 | return mAsyncExecutor; |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8349 | } |
| 8350 | |
| 8351 | /** |
Philip P. Moltmann | a04b9ab | 2020-02-13 09:54:04 -0800 | [diff] [blame] | 8352 | * Called when an app-op was {@link #noteOp noted} for this package inside of a synchronous |
| 8353 | * API call, i.e. a API call that returned data or waited until the action was performed. |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8354 | * |
Philip P. Moltmann | a04b9ab | 2020-02-13 09:54:04 -0800 | [diff] [blame] | 8355 | * <p>Called on the calling thread before the API returns. This allows the app to e.g. |
| 8356 | * collect stack traces to figure out where the access came from. |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8357 | * |
Philip P. Moltmann | 5892a8f | 2020-03-03 12:05:55 -0800 | [diff] [blame] | 8358 | * @param op op noted |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8359 | */ |
| 8360 | public abstract void onNoted(@NonNull SyncNotedAppOp op); |
| 8361 | |
| 8362 | /** |
Philip P. Moltmann | a04b9ab | 2020-02-13 09:54:04 -0800 | [diff] [blame] | 8363 | * Called when this app noted an app-op for its own package, |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8364 | * |
Philip P. Moltmann | a04b9ab | 2020-02-13 09:54:04 -0800 | [diff] [blame] | 8365 | * <p>This is very similar to {@link #onNoted} only that the tracking was not caused by the |
| 8366 | * API provider in a separate process, but by one in the app's own process. |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8367 | * |
Philip P. Moltmann | 5892a8f | 2020-03-03 12:05:55 -0800 | [diff] [blame] | 8368 | * @param op op noted |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8369 | */ |
| 8370 | public abstract void onSelfNoted(@NonNull SyncNotedAppOp op); |
| 8371 | |
| 8372 | /** |
| 8373 | * Called when an app-op was noted for this package which cannot be delivered via the other |
| 8374 | * two mechanisms. |
| 8375 | * |
| 8376 | * <p>Called as soon as possible after the app-op was noted, but the delivery delay is not |
| 8377 | * guaranteed. Due to how async calls work in Android this might even be delivered slightly |
| 8378 | * before the private data is delivered to the app. |
| 8379 | * |
Philip P. Moltmann | 5892a8f | 2020-03-03 12:05:55 -0800 | [diff] [blame] | 8380 | * <p>If the app is not running or no {@link OnOpNotedCallback} is registered a small amount |
| 8381 | * of noted app-ops are buffered and then delivered as soon as a listener is registered. |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8382 | * |
Philip P. Moltmann | 5892a8f | 2020-03-03 12:05:55 -0800 | [diff] [blame] | 8383 | * @param asyncOp op noted |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8384 | */ |
| 8385 | public abstract void onAsyncNoted(@NonNull AsyncNotedAppOp asyncOp); |
| 8386 | } |
| 8387 | |
Philip P. Moltmann | 5892a8f | 2020-03-03 12:05:55 -0800 | [diff] [blame] | 8388 | // TODO moltmann: Remove |
| 8389 | /** |
| 8390 | * Will be removed before R ships, leave it just to not break apps immediately. |
| 8391 | * |
| 8392 | * @removed |
| 8393 | * |
| 8394 | * @hide |
| 8395 | */ |
| 8396 | @SystemApi |
| 8397 | @Deprecated |
| 8398 | public abstract static class AppOpsCollector extends OnOpNotedCallback { |
| 8399 | public @NonNull Executor getAsyncNotedExecutor() { |
| 8400 | return new HandlerExecutor(Handler.getMain()); |
| 8401 | } |
| 8402 | }; |
| 8403 | |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8404 | /** |
| 8405 | * Generate a stack trace used for noted app-ops logging. |
| 8406 | * |
| 8407 | * <p>This strips away the first few and last few stack trace elements as they are not |
| 8408 | * interesting to apps. |
| 8409 | */ |
| 8410 | private static String getFormattedStackTrace() { |
| 8411 | StackTraceElement[] trace = new Exception().getStackTrace(); |
| 8412 | |
| 8413 | int firstInteresting = 0; |
| 8414 | for (int i = 0; i < trace.length; i++) { |
| 8415 | if (trace[i].getClassName().startsWith(AppOpsManager.class.getName()) |
| 8416 | || trace[i].getClassName().startsWith(Parcel.class.getName()) |
| 8417 | || trace[i].getClassName().contains("$Stub$Proxy") |
| 8418 | || trace[i].getClassName().startsWith(DatabaseUtils.class.getName()) |
| 8419 | || trace[i].getClassName().startsWith("android.content.ContentProviderProxy") |
| 8420 | || trace[i].getClassName().startsWith(ContentResolver.class.getName())) { |
| 8421 | firstInteresting = i; |
| 8422 | } else { |
| 8423 | break; |
| 8424 | } |
| 8425 | } |
| 8426 | |
| 8427 | int lastInteresting = trace.length - 1; |
| 8428 | for (int i = trace.length - 1; i >= 0; i--) { |
| 8429 | if (trace[i].getClassName().startsWith(HandlerThread.class.getName()) |
| 8430 | || trace[i].getClassName().startsWith(Handler.class.getName()) |
| 8431 | || trace[i].getClassName().startsWith(Looper.class.getName()) |
| 8432 | || trace[i].getClassName().startsWith(Binder.class.getName()) |
| 8433 | || trace[i].getClassName().startsWith(RuntimeInit.class.getName()) |
| 8434 | || trace[i].getClassName().startsWith(ZygoteInit.class.getName()) |
| 8435 | || trace[i].getClassName().startsWith(ActivityThread.class.getName()) |
| 8436 | || trace[i].getClassName().startsWith(Method.class.getName()) |
| 8437 | || trace[i].getClassName().startsWith("com.android.server.SystemServer")) { |
| 8438 | lastInteresting = i; |
| 8439 | } else { |
| 8440 | break; |
| 8441 | } |
| 8442 | } |
| 8443 | |
| 8444 | StringBuilder sb = new StringBuilder(); |
| 8445 | for (int i = firstInteresting; i <= lastInteresting; i++) { |
Stanislav Zholnin | 90516b9 | 2020-01-20 14:03:06 +0000 | [diff] [blame] | 8446 | if (i != firstInteresting) { |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8447 | sb.append('\n'); |
| 8448 | } |
Stanislav Zholnin | 90516b9 | 2020-01-20 14:03:06 +0000 | [diff] [blame] | 8449 | if (sb.length() + trace[i].toString().length() > 600) { |
| 8450 | break; |
| 8451 | } |
| 8452 | sb.append(trace[i]); |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8453 | } |
| 8454 | |
| 8455 | return sb.toString(); |
| 8456 | } |
| 8457 | |
| 8458 | /** |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 8459 | * Checks whether the given op for a UID and package is active. |
| 8460 | * |
| 8461 | * <p> If you don't hold the {@link android.Manifest.permission#WATCH_APPOPS} permission |
| 8462 | * you can query only for your UID. |
| 8463 | * |
| 8464 | * @see #startWatchingActive(int[], OnOpActiveChangedListener) |
| 8465 | * @see #stopWatchingMode(OnOpChangedListener) |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 8466 | * @see #finishOp(int, int, String, String) |
| 8467 | * @see #startOp(int, int, String, boolean, String, String) |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 8468 | * |
| 8469 | * @hide */ |
| 8470 | @TestApi |
| 8471 | // TODO: Uncomment below annotation once b/73559440 is fixed |
| 8472 | // @RequiresPermission(value=Manifest.permission.WATCH_APPOPS, conditional=true) |
Jeff Sharkey | 35e46d2 | 2017-06-09 10:01:20 -0600 | [diff] [blame] | 8473 | public boolean isOperationActive(int code, int uid, String packageName) { |
| 8474 | try { |
| 8475 | return mService.isOperationActive(code, uid, packageName); |
| 8476 | } catch (RemoteException e) { |
| 8477 | throw e.rethrowFromSystemServer(); |
| 8478 | } |
| 8479 | } |
Peter Visontay | 5a2a1ef | 2017-12-18 20:34:03 +0000 | [diff] [blame] | 8480 | |
| 8481 | /** |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 8482 | * Configures the app ops persistence for testing. |
| 8483 | * |
| 8484 | * @param mode The mode in which the historical registry operates. |
| 8485 | * @param baseSnapshotInterval The base interval on which we would be persisting a snapshot of |
| 8486 | * the historical data. The history is recursive where every subsequent step encompasses |
| 8487 | * {@code compressionStep} longer interval with {@code compressionStep} distance between |
| 8488 | * snapshots. |
| 8489 | * @param compressionStep The compression step in every iteration. |
| 8490 | * |
| 8491 | * @see #HISTORICAL_MODE_DISABLED |
| 8492 | * @see #HISTORICAL_MODE_ENABLED_ACTIVE |
| 8493 | * @see #HISTORICAL_MODE_ENABLED_PASSIVE |
| 8494 | * |
| 8495 | * @hide |
| 8496 | */ |
| 8497 | @TestApi |
| 8498 | @RequiresPermission(Manifest.permission.MANAGE_APPOPS) |
| 8499 | public void setHistoryParameters(@HistoricalMode int mode, long baseSnapshotInterval, |
| 8500 | int compressionStep) { |
| 8501 | try { |
| 8502 | mService.setHistoryParameters(mode, baseSnapshotInterval, compressionStep); |
| 8503 | } catch (RemoteException e) { |
| 8504 | throw e.rethrowFromSystemServer(); |
| 8505 | } |
| 8506 | } |
| 8507 | |
| 8508 | /** |
| 8509 | * Offsets the history by the given duration. |
| 8510 | * |
| 8511 | * @param offsetMillis The offset duration. |
| 8512 | * |
| 8513 | * @hide |
| 8514 | */ |
| 8515 | @TestApi |
| 8516 | @RequiresPermission(Manifest.permission.MANAGE_APPOPS) |
| 8517 | public void offsetHistory(long offsetMillis) { |
| 8518 | try { |
| 8519 | mService.offsetHistory(offsetMillis); |
| 8520 | } catch (RemoteException e) { |
| 8521 | throw e.rethrowFromSystemServer(); |
| 8522 | } |
| 8523 | } |
| 8524 | |
| 8525 | /** |
| 8526 | * Adds ops to the history directly. This could be useful for testing especially |
| 8527 | * when the historical registry operates in {@link #HISTORICAL_MODE_ENABLED_PASSIVE} |
| 8528 | * mode. |
| 8529 | * |
| 8530 | * @param ops The ops to add to the history. |
| 8531 | * |
| 8532 | * @see #setHistoryParameters(int, long, int) |
| 8533 | * @see #HISTORICAL_MODE_ENABLED_PASSIVE |
| 8534 | * |
| 8535 | * @hide |
| 8536 | */ |
| 8537 | @TestApi |
| 8538 | @RequiresPermission(Manifest.permission.MANAGE_APPOPS) |
| 8539 | public void addHistoricalOps(@NonNull HistoricalOps ops) { |
| 8540 | try { |
| 8541 | mService.addHistoricalOps(ops); |
| 8542 | } catch (RemoteException e) { |
| 8543 | throw e.rethrowFromSystemServer(); |
| 8544 | } |
| 8545 | } |
| 8546 | |
| 8547 | /** |
| 8548 | * Resets the app ops persistence for testing. |
| 8549 | * |
| 8550 | * @see #setHistoryParameters(int, long, int) |
| 8551 | * |
| 8552 | * @hide |
| 8553 | */ |
| 8554 | @TestApi |
| 8555 | @RequiresPermission(Manifest.permission.MANAGE_APPOPS) |
| 8556 | public void resetHistoryParameters() { |
| 8557 | try { |
| 8558 | mService.resetHistoryParameters(); |
| 8559 | } catch (RemoteException e) { |
| 8560 | throw e.rethrowFromSystemServer(); |
| 8561 | } |
| 8562 | } |
| 8563 | |
| 8564 | /** |
| 8565 | * Clears all app ops history. |
| 8566 | * |
| 8567 | * @hide |
| 8568 | */ |
| 8569 | @TestApi |
| 8570 | @RequiresPermission(Manifest.permission.MANAGE_APPOPS) |
| 8571 | public void clearHistory() { |
| 8572 | try { |
| 8573 | mService.clearHistory(); |
| 8574 | } catch (RemoteException e) { |
| 8575 | throw e.rethrowFromSystemServer(); |
| 8576 | } |
| 8577 | } |
| 8578 | |
| 8579 | /** |
Stanislav Zholnin | 90516b9 | 2020-01-20 14:03:06 +0000 | [diff] [blame] | 8580 | * Pulls current AppOps access report and picks package and op to watch for next access report |
Stanislav Zholnin | b2ed79a | 2020-03-24 14:14:45 +0000 | [diff] [blame] | 8581 | * Returns null if no reports were collected since last call. There is no guarantee of report |
| 8582 | * collection, hence this method should be called periodically even if no report was collected |
| 8583 | * to pick different package and op to watch. |
Stanislav Zholnin | 90516b9 | 2020-01-20 14:03:06 +0000 | [diff] [blame] | 8584 | * @hide |
| 8585 | */ |
| 8586 | @SystemApi |
| 8587 | @TestApi |
| 8588 | @RequiresPermission(Manifest.permission.GET_APP_OPS_STATS) |
| 8589 | public @Nullable RuntimeAppOpAccessMessage collectRuntimeAppOpAccessMessage() { |
| 8590 | try { |
| 8591 | return mService.collectRuntimeAppOpAccessMessage(); |
| 8592 | } catch (RemoteException e) { |
| 8593 | throw e.rethrowFromSystemServer(); |
| 8594 | } |
| 8595 | } |
| 8596 | |
| 8597 | /** |
Peter Visontay | 5a2a1ef | 2017-12-18 20:34:03 +0000 | [diff] [blame] | 8598 | * Returns all supported operation names. |
| 8599 | * @hide |
| 8600 | */ |
| 8601 | @SystemApi |
| 8602 | @TestApi |
| 8603 | public static String[] getOpStrs() { |
| 8604 | return Arrays.copyOf(sOpToString, sOpToString.length); |
| 8605 | } |
Dianne Hackborn | c216a26 | 2018-04-26 13:46:22 -0700 | [diff] [blame] | 8606 | |
Philip P. Moltmann | 2457681 | 2018-05-07 10:42:05 -0700 | [diff] [blame] | 8607 | |
| 8608 | /** |
| 8609 | * @return number of App ops |
| 8610 | * @hide |
| 8611 | */ |
| 8612 | @TestApi |
| 8613 | public static int getNumOps() { |
| 8614 | return _NUM_OP; |
| 8615 | } |
| 8616 | |
Dianne Hackborn | c216a26 | 2018-04-26 13:46:22 -0700 | [diff] [blame] | 8617 | /** |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 8618 | * Gets the last of the event. |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 8619 | * |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 8620 | * @param events The events |
| 8621 | * @param flags The UID flags |
| 8622 | * @param beginUidState The maximum UID state (inclusive) |
| 8623 | * @param endUidState The minimum UID state (inclusive) |
| 8624 | * |
| 8625 | * @return The last event of {@code null} |
Dianne Hackborn | c216a26 | 2018-04-26 13:46:22 -0700 | [diff] [blame] | 8626 | */ |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 8627 | private static @Nullable NoteOpEvent getLastEvent( |
| 8628 | @Nullable LongSparseArray<NoteOpEvent> events, @UidState int beginUidState, |
| 8629 | @UidState int endUidState, @OpFlags int flags) { |
| 8630 | if (events == null) { |
| 8631 | return null; |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 8632 | } |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 8633 | |
| 8634 | NoteOpEvent lastEvent = null; |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 8635 | while (flags != 0) { |
| 8636 | final int flag = 1 << Integer.numberOfTrailingZeros(flags); |
| 8637 | flags &= ~flag; |
| 8638 | for (int uidState : UID_STATES) { |
| 8639 | if (uidState < beginUidState || uidState > endUidState) { |
| 8640 | continue; |
| 8641 | } |
| 8642 | final long key = makeKey(uidState, flag); |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 8643 | |
| 8644 | NoteOpEvent event = events.get(key); |
Philip P. Moltmann | d8c0bda | 2019-12-19 19:55:35 -0800 | [diff] [blame] | 8645 | if (lastEvent == null |
| 8646 | || event != null && event.getNoteTime() > lastEvent.getNoteTime()) { |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 8647 | lastEvent = event; |
| 8648 | } |
Dianne Hackborn | c216a26 | 2018-04-26 13:46:22 -0700 | [diff] [blame] | 8649 | } |
| 8650 | } |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 8651 | |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 8652 | return lastEvent; |
| 8653 | } |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 8654 | |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 8655 | private static boolean equalsLongSparseLongArray(@Nullable LongSparseLongArray a, |
| 8656 | @Nullable LongSparseLongArray b) { |
| 8657 | if (a == b) { |
| 8658 | return true; |
| 8659 | } |
| 8660 | |
| 8661 | if (a == null || b == null) { |
| 8662 | return false; |
| 8663 | } |
| 8664 | |
| 8665 | if (a.size() != b.size()) { |
| 8666 | return false; |
| 8667 | } |
| 8668 | |
| 8669 | int numEntries = a.size(); |
| 8670 | for (int i = 0; i < numEntries; i++) { |
| 8671 | if (a.keyAt(i) != b.keyAt(i) || a.valueAt(i) != b.valueAt(i)) { |
| 8672 | return false; |
| 8673 | } |
| 8674 | } |
| 8675 | |
| 8676 | return true; |
| 8677 | } |
| 8678 | |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 8679 | private static void writeLongSparseLongArrayToParcel( |
| 8680 | @Nullable LongSparseLongArray array, @NonNull Parcel parcel) { |
| 8681 | if (array != null) { |
| 8682 | final int size = array.size(); |
| 8683 | parcel.writeInt(size); |
| 8684 | for (int i = 0; i < size; i++) { |
| 8685 | parcel.writeLong(array.keyAt(i)); |
| 8686 | parcel.writeLong(array.valueAt(i)); |
| 8687 | } |
| 8688 | } else { |
| 8689 | parcel.writeInt(-1); |
| 8690 | } |
| 8691 | } |
| 8692 | |
| 8693 | private static @Nullable LongSparseLongArray readLongSparseLongArrayFromParcel( |
| 8694 | @NonNull Parcel parcel) { |
| 8695 | final int size = parcel.readInt(); |
| 8696 | if (size < 0) { |
| 8697 | return null; |
| 8698 | } |
| 8699 | final LongSparseLongArray array = new LongSparseLongArray(size); |
| 8700 | for (int i = 0; i < size; i++) { |
| 8701 | array.append(parcel.readLong(), parcel.readLong()); |
| 8702 | } |
| 8703 | return array; |
| 8704 | } |
| 8705 | |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 8706 | /** |
| 8707 | * Collects the keys from an array to the result creating the result if needed. |
| 8708 | * |
| 8709 | * @param array The array whose keys to collect. |
| 8710 | * @param result The optional result store collected keys. |
| 8711 | * @return The result collected keys array. |
| 8712 | */ |
| 8713 | private static LongSparseArray<Object> collectKeys(@Nullable LongSparseLongArray array, |
| 8714 | @Nullable LongSparseArray<Object> result) { |
| 8715 | if (array != null) { |
| 8716 | if (result == null) { |
| 8717 | result = new LongSparseArray<>(); |
| 8718 | } |
| 8719 | final int accessSize = array.size(); |
| 8720 | for (int i = 0; i < accessSize; i++) { |
| 8721 | result.put(array.keyAt(i), null); |
| 8722 | } |
| 8723 | } |
| 8724 | return result; |
Dianne Hackborn | c216a26 | 2018-04-26 13:46:22 -0700 | [diff] [blame] | 8725 | } |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 8726 | |
| 8727 | /** @hide */ |
| 8728 | public static String uidStateToString(@UidState int uidState) { |
| 8729 | switch (uidState) { |
| 8730 | case UID_STATE_PERSISTENT: { |
| 8731 | return "UID_STATE_PERSISTENT"; |
| 8732 | } |
| 8733 | case UID_STATE_TOP: { |
| 8734 | return "UID_STATE_TOP"; |
| 8735 | } |
Amith Yamasani | a0a30a1 | 2019-01-22 11:38:06 -0800 | [diff] [blame] | 8736 | case UID_STATE_FOREGROUND_SERVICE_LOCATION: { |
| 8737 | return "UID_STATE_FOREGROUND_SERVICE_LOCATION"; |
| 8738 | } |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 8739 | case UID_STATE_FOREGROUND_SERVICE: { |
| 8740 | return "UID_STATE_FOREGROUND_SERVICE"; |
| 8741 | } |
| 8742 | case UID_STATE_FOREGROUND: { |
| 8743 | return "UID_STATE_FOREGROUND"; |
| 8744 | } |
| 8745 | case UID_STATE_BACKGROUND: { |
| 8746 | return "UID_STATE_BACKGROUND"; |
| 8747 | } |
| 8748 | case UID_STATE_CACHED: { |
| 8749 | return "UID_STATE_CACHED"; |
| 8750 | } |
| 8751 | default: { |
| 8752 | return "UNKNOWN"; |
| 8753 | } |
| 8754 | } |
| 8755 | } |
| 8756 | |
| 8757 | /** @hide */ |
| 8758 | public static int parseHistoricalMode(@NonNull String mode) { |
| 8759 | switch (mode) { |
| 8760 | case "HISTORICAL_MODE_ENABLED_ACTIVE": { |
| 8761 | return HISTORICAL_MODE_ENABLED_ACTIVE; |
| 8762 | } |
| 8763 | case "HISTORICAL_MODE_ENABLED_PASSIVE": { |
| 8764 | return HISTORICAL_MODE_ENABLED_PASSIVE; |
| 8765 | } |
| 8766 | default: { |
| 8767 | return HISTORICAL_MODE_DISABLED; |
| 8768 | } |
| 8769 | } |
| 8770 | } |
| 8771 | |
| 8772 | /** @hide */ |
| 8773 | public static String historicalModeToString(@HistoricalMode int mode) { |
| 8774 | switch (mode) { |
| 8775 | case HISTORICAL_MODE_DISABLED: { |
| 8776 | return "HISTORICAL_MODE_DISABLED"; |
| 8777 | } |
| 8778 | case HISTORICAL_MODE_ENABLED_ACTIVE: { |
| 8779 | return "HISTORICAL_MODE_ENABLED_ACTIVE"; |
| 8780 | } |
| 8781 | case HISTORICAL_MODE_ENABLED_PASSIVE: { |
| 8782 | return "HISTORICAL_MODE_ENABLED_PASSIVE"; |
| 8783 | } |
| 8784 | default: { |
| 8785 | return "UNKNOWN"; |
| 8786 | } |
| 8787 | } |
| 8788 | } |
Ng Zhi An | 65a99b6 | 2018-10-01 11:57:53 -0700 | [diff] [blame] | 8789 | |
| 8790 | private static int getSystemAlertWindowDefault() { |
| 8791 | final Context context = ActivityThread.currentApplication(); |
| 8792 | if (context == null) { |
| 8793 | return AppOpsManager.MODE_DEFAULT; |
| 8794 | } |
| 8795 | |
| 8796 | // system alert window is disable on low ram phones starting from Q |
| 8797 | final PackageManager pm = context.getPackageManager(); |
| 8798 | // TVs are constantly plugged in and has less concern for memory/power |
| 8799 | if (ActivityManager.isLowRamDeviceStatic() |
| 8800 | && !pm.hasSystemFeature(PackageManager.FEATURE_LEANBACK, 0)) { |
| 8801 | return AppOpsManager.MODE_IGNORED; |
| 8802 | } |
| 8803 | |
| 8804 | return AppOpsManager.MODE_DEFAULT; |
| 8805 | } |
Stanislav Zholnin | 90516b9 | 2020-01-20 14:03:06 +0000 | [diff] [blame] | 8806 | |
| 8807 | /** |
| 8808 | * Calculate left circular distance for two numbers modulo size. |
| 8809 | * @hide |
| 8810 | */ |
| 8811 | public static int leftCircularDistance(int from, int to, int size) { |
| 8812 | return (to + size - from) % size; |
| 8813 | } |
David Cheung | 2ead966 | 2020-02-19 16:11:06 -0800 | [diff] [blame] | 8814 | |
| 8815 | /** |
| 8816 | * Helper method for noteOp, startOp and noteProxyOp to call AppOpsService to collect/log |
| 8817 | * stack traces |
| 8818 | * |
| 8819 | * <p> For each call, the stacktrace op code, package name and long version code will be |
| 8820 | * passed along where it will be logged/collected |
| 8821 | * |
| 8822 | * @param op The operation to note |
| 8823 | */ |
| 8824 | private void collectNoteOpCallsForValidation(int op) { |
| 8825 | if (NOTE_OP_COLLECTION_ENABLED) { |
| 8826 | try { |
| 8827 | mService.collectNoteOpCallsForValidation(getFormattedStackTrace(), |
| 8828 | op, mContext.getOpPackageName(), mContext.getApplicationInfo().longVersionCode); |
| 8829 | } catch (RemoteException e) { |
| 8830 | // Swallow error, only meant for logging ops, should not affect flow of the code |
| 8831 | } |
| 8832 | } |
| 8833 | } |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 8834 | } |