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 | |
Stanislav Zholnin | e44f134 | 2020-06-02 20:26:20 +0100 | [diff] [blame] | 185 | private static final int MAX_UNFORWARDED_OPS = 10; |
| 186 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 187 | final Context mContext; |
Svet Ganov | b3d2ae2 | 2018-12-17 22:06:15 -0800 | [diff] [blame] | 188 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 189 | @UnsupportedAppUsage |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 190 | final IAppOpsService mService; |
Svet Ganov | b3d2ae2 | 2018-12-17 22:06:15 -0800 | [diff] [blame] | 191 | |
Stanislav Zholnin | 90516b9 | 2020-01-20 14:03:06 +0000 | [diff] [blame] | 192 | /** |
| 193 | * Service for the application context, to be used by static methods via |
| 194 | * {@link #getService()} |
| 195 | */ |
| 196 | @GuardedBy("sLock") |
| 197 | static IAppOpsService sService; |
| 198 | |
Svet Ganov | b3d2ae2 | 2018-12-17 22:06:15 -0800 | [diff] [blame] | 199 | @GuardedBy("mModeWatchers") |
| 200 | private final ArrayMap<OnOpChangedListener, IAppOpsCallback> mModeWatchers = |
| 201 | new ArrayMap<>(); |
| 202 | |
| 203 | @GuardedBy("mActiveWatchers") |
| 204 | private final ArrayMap<OnOpActiveChangedListener, IAppOpsActiveCallback> mActiveWatchers = |
| 205 | new ArrayMap<>(); |
| 206 | |
Adam Bookatz | 182862e | 2020-04-27 21:58:22 -0700 | [diff] [blame] | 207 | @GuardedBy("mStartedWatchers") |
| 208 | private final ArrayMap<OnOpStartedListener, IAppOpsStartedCallback> mStartedWatchers = |
| 209 | new ArrayMap<>(); |
| 210 | |
Svet Ganov | b3d2ae2 | 2018-12-17 22:06:15 -0800 | [diff] [blame] | 211 | @GuardedBy("mNotedWatchers") |
| 212 | private final ArrayMap<OnOpNotedListener, IAppOpsNotedCallback> mNotedWatchers = |
Svetoslav Ganov | 2d20fb4 | 2018-02-08 15:52:10 -0800 | [diff] [blame] | 213 | new ArrayMap<>(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 214 | |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 215 | private static final Object sLock = new Object(); |
| 216 | |
Philip P. Moltmann | 5892a8f | 2020-03-03 12:05:55 -0800 | [diff] [blame] | 217 | /** Current {@link OnOpNotedCallback}. Change via {@link #setOnOpNotedCallback} */ |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 218 | @GuardedBy("sLock") |
Philip P. Moltmann | 5892a8f | 2020-03-03 12:05:55 -0800 | [diff] [blame] | 219 | private static @Nullable OnOpNotedCallback sOnOpNotedCallback; |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 220 | |
Stanislav Zholnin | 90516b9 | 2020-01-20 14:03:06 +0000 | [diff] [blame] | 221 | /** |
Stanislav Zholnin | e44f134 | 2020-06-02 20:26:20 +0100 | [diff] [blame] | 222 | * Sync note-ops collected from {@link #readAndLogNotedAppops(Parcel)} that have not been |
| 223 | * delivered to a callback yet. |
| 224 | * |
| 225 | * Similar to {@link com.android.server.appop.AppOpsService#mUnforwardedAsyncNotedOps} for |
| 226 | * {@link COLLECT_ASYNC}. Used in situation when AppOpsManager asks to collect stacktrace with |
| 227 | * {@link #sMessageCollector}, which forces {@link COLLECT_SYNC} mode. |
| 228 | */ |
| 229 | @GuardedBy("sLock") |
Stanislav Zholnin | 456b496 | 2020-06-18 16:52:50 +0100 | [diff] [blame] | 230 | private static ArrayList<AsyncNotedAppOp> sUnforwardedOps = new ArrayList<>(); |
Stanislav Zholnin | e44f134 | 2020-06-02 20:26:20 +0100 | [diff] [blame] | 231 | |
| 232 | /** |
Stanislav Zholnin | 90516b9 | 2020-01-20 14:03:06 +0000 | [diff] [blame] | 233 | * Additional collector that collect accesses and forwards a few of them them via |
| 234 | * {@link IAppOpsService#reportRuntimeAppOpAccessMessageAndGetConfig}. |
| 235 | */ |
Philip P. Moltmann | 5892a8f | 2020-03-03 12:05:55 -0800 | [diff] [blame] | 236 | private static OnOpNotedCallback sMessageCollector = |
| 237 | new OnOpNotedCallback() { |
Stanislav Zholnin | 90516b9 | 2020-01-20 14:03:06 +0000 | [diff] [blame] | 238 | @Override |
| 239 | public void onNoted(@NonNull SyncNotedAppOp op) { |
| 240 | reportStackTraceIfNeeded(op); |
| 241 | } |
| 242 | |
| 243 | @Override |
| 244 | public void onAsyncNoted(@NonNull AsyncNotedAppOp asyncOp) { |
| 245 | // collected directly in AppOpsService |
| 246 | } |
| 247 | |
| 248 | @Override |
| 249 | public void onSelfNoted(@NonNull SyncNotedAppOp op) { |
| 250 | reportStackTraceIfNeeded(op); |
| 251 | } |
| 252 | |
| 253 | private void reportStackTraceIfNeeded(@NonNull SyncNotedAppOp op) { |
Stanislav Zholnin | d4968a0 | 2020-04-18 21:01:13 +0100 | [diff] [blame] | 254 | if (!isCollectingStackTraces()) { |
Stanislav Zholnin | 90516b9 | 2020-01-20 14:03:06 +0000 | [diff] [blame] | 255 | return; |
| 256 | } |
Stanislav Zholnin | 90516b9 | 2020-01-20 14:03:06 +0000 | [diff] [blame] | 257 | MessageSamplingConfig config = sConfig; |
| 258 | if (leftCircularDistance(strOpToOp(op.getOp()), config.getSampledOpCode(), |
| 259 | _NUM_OP) <= config.getAcceptableLeftDistance() |
| 260 | || config.getExpirationTimeSinceBootMillis() |
| 261 | < SystemClock.elapsedRealtime()) { |
| 262 | String stackTrace = getFormattedStackTrace(); |
| 263 | try { |
Stanislav Zholnin | 9edce64 | 2020-06-15 17:28:33 +0100 | [diff] [blame] | 264 | String packageName = ActivityThread.currentOpPackageName(); |
Stanislav Zholnin | 90516b9 | 2020-01-20 14:03:06 +0000 | [diff] [blame] | 265 | sConfig = getService().reportRuntimeAppOpAccessMessageAndGetConfig( |
Stanislav Zholnin | 9edce64 | 2020-06-15 17:28:33 +0100 | [diff] [blame] | 266 | packageName == null ? "" : packageName, op, stackTrace); |
Stanislav Zholnin | 90516b9 | 2020-01-20 14:03:06 +0000 | [diff] [blame] | 267 | } catch (RemoteException e) { |
| 268 | e.rethrowFromSystemServer(); |
| 269 | } |
| 270 | } |
| 271 | } |
| 272 | }; |
| 273 | |
Philip P. Moltmann | 6c6403e | 2019-12-09 10:08:29 -0800 | [diff] [blame] | 274 | static IBinder sClientId; |
Dianne Hackborn | e98f5db | 2013-07-17 17:23:25 -0700 | [diff] [blame] | 275 | |
Philip P. Moltmann | e565c7b | 2020-01-28 13:15:52 -0800 | [diff] [blame] | 276 | /** |
| 277 | * How many seconds we want for a drop in uid state from top to settle before applying it. |
| 278 | * |
| 279 | * <>Set a parameter to {@link android.provider.Settings.Global#APP_OPS_CONSTANTS} |
| 280 | * |
| 281 | * @hide |
| 282 | */ |
| 283 | @TestApi |
| 284 | public static final String KEY_TOP_STATE_SETTLE_TIME = "top_state_settle_time"; |
| 285 | |
| 286 | /** |
| 287 | * How many second we want for a drop in uid state from foreground to settle before applying it. |
| 288 | * |
| 289 | * <>Set a parameter to {@link android.provider.Settings.Global#APP_OPS_CONSTANTS} |
| 290 | * |
| 291 | * @hide |
| 292 | */ |
| 293 | @TestApi |
| 294 | public static final String KEY_FG_SERVICE_STATE_SETTLE_TIME = |
| 295 | "fg_service_state_settle_time"; |
| 296 | |
| 297 | /** |
| 298 | * How many seconds we want for a drop in uid state from background to settle before applying |
| 299 | * it. |
| 300 | * |
| 301 | * <>Set a parameter to {@link android.provider.Settings.Global#APP_OPS_CONSTANTS} |
| 302 | * |
| 303 | * @hide |
| 304 | */ |
| 305 | @TestApi |
| 306 | public static final String KEY_BG_STATE_SETTLE_TIME = "bg_state_settle_time"; |
| 307 | |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 308 | /** @hide */ |
| 309 | @Retention(RetentionPolicy.SOURCE) |
| 310 | @IntDef(flag = true, prefix = { "HISTORICAL_MODE_" }, value = { |
| 311 | HISTORICAL_MODE_DISABLED, |
| 312 | HISTORICAL_MODE_ENABLED_ACTIVE, |
| 313 | HISTORICAL_MODE_ENABLED_PASSIVE |
| 314 | }) |
| 315 | public @interface HistoricalMode {} |
| 316 | |
| 317 | /** |
| 318 | * Mode in which app op history is completely disabled. |
| 319 | * @hide |
| 320 | */ |
| 321 | @TestApi |
| 322 | public static final int HISTORICAL_MODE_DISABLED = 0; |
| 323 | |
| 324 | /** |
| 325 | * Mode in which app op history is enabled and app ops performed by apps would |
| 326 | * be tracked. This is the mode in which the feature is completely enabled. |
| 327 | * @hide |
| 328 | */ |
| 329 | @TestApi |
| 330 | public static final int HISTORICAL_MODE_ENABLED_ACTIVE = 1; |
| 331 | |
| 332 | /** |
| 333 | * Mode in which app op history is enabled but app ops performed by apps would |
| 334 | * not be tracked and the only way to add ops to the history is via explicit calls |
| 335 | * to dedicated APIs. This mode is useful for testing to allow full control of |
| 336 | * the historical content. |
| 337 | * @hide |
| 338 | */ |
| 339 | @TestApi |
| 340 | public static final int HISTORICAL_MODE_ENABLED_PASSIVE = 2; |
| 341 | |
| 342 | /** @hide */ |
| 343 | @Retention(RetentionPolicy.SOURCE) |
| 344 | @IntDef(flag = true, prefix = { "MODE_" }, value = { |
| 345 | MODE_ALLOWED, |
| 346 | MODE_IGNORED, |
| 347 | MODE_ERRORED, |
| 348 | MODE_DEFAULT, |
| 349 | MODE_FOREGROUND |
| 350 | }) |
| 351 | public @interface Mode {} |
| 352 | |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 353 | /** |
| 354 | * Result from {@link #checkOp}, {@link #noteOp}, {@link #startOp}: the given caller is |
| 355 | * allowed to perform the given operation. |
| 356 | */ |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 357 | public static final int MODE_ALLOWED = 0; |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 358 | |
| 359 | /** |
| 360 | * Result from {@link #checkOp}, {@link #noteOp}, {@link #startOp}: the given caller is |
| 361 | * not allowed to perform the given operation, and this attempt should |
| 362 | * <em>silently fail</em> (it should not cause the app to crash). |
| 363 | */ |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 364 | public static final int MODE_IGNORED = 1; |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 365 | |
| 366 | /** |
| 367 | * Result from {@link #checkOpNoThrow}, {@link #noteOpNoThrow}, {@link #startOpNoThrow}: the |
| 368 | * given caller is not allowed to perform the given operation, and this attempt should |
| 369 | * cause it to have a fatal error, typically a {@link SecurityException}. |
| 370 | */ |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 371 | public static final int MODE_ERRORED = 2; |
| 372 | |
Dianne Hackborn | 33f5ddd | 2014-07-21 15:35:45 -0700 | [diff] [blame] | 373 | /** |
| 374 | * Result from {@link #checkOp}, {@link #noteOp}, {@link #startOp}: the given caller should |
| 375 | * use its default security check. This mode is not normally used; it should only be used |
| 376 | * with appop permissions, and callers must explicitly check for it and deal with it. |
| 377 | */ |
| 378 | public static final int MODE_DEFAULT = 3; |
| 379 | |
Dianne Hackborn | cd1f30b | 2018-04-23 17:38:09 -0700 | [diff] [blame] | 380 | /** |
Dianne Hackborn | c216a26 | 2018-04-26 13:46:22 -0700 | [diff] [blame] | 381 | * 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] | 382 | * returned from {@link #unsafeCheckOp}, {@link #noteOp}, {@link #startOp}. Rather, |
| 383 | * {@link #unsafeCheckOp} will always return {@link #MODE_ALLOWED} (because it is always |
| 384 | * possible for it to be ultimately allowed, depending on the app's background state), |
| 385 | * and {@link #noteOp} and {@link #startOp} will return {@link #MODE_ALLOWED} when the app |
| 386 | * being checked is currently in the foreground, otherwise {@link #MODE_IGNORED}. |
| 387 | * |
| 388 | * <p>The only place you will this normally see this value is through |
| 389 | * {@link #unsafeCheckOpRaw}, which returns the actual raw mode of the op. Note that because |
| 390 | * you can't know the current state of the app being checked (and it can change at any |
| 391 | * point), you can only treat the result here as an indication that it will vary between |
| 392 | * {@link #MODE_ALLOWED} and {@link #MODE_IGNORED} depending on changes in the background |
| 393 | * state of the app. You thus must always use {@link #noteOp} or {@link #startOp} to do |
| 394 | * the actual check for access to the op.</p> |
Dianne Hackborn | c216a26 | 2018-04-26 13:46:22 -0700 | [diff] [blame] | 395 | */ |
| 396 | public static final int MODE_FOREGROUND = 4; |
| 397 | |
Dianne Hackborn | 65a4f25 | 2018-05-08 17:30:48 -0700 | [diff] [blame] | 398 | /** |
| 399 | * Flag for {@link #startWatchingMode(String, String, int, OnOpChangedListener)}: |
| 400 | * Also get reports if the foreground state of an op's uid changes. This only works |
| 401 | * when watching a particular op, not when watching a package. |
Dianne Hackborn | 65a4f25 | 2018-05-08 17:30:48 -0700 | [diff] [blame] | 402 | */ |
| 403 | public static final int WATCH_FOREGROUND_CHANGES = 1 << 0; |
Dianne Hackborn | c216a26 | 2018-04-26 13:46:22 -0700 | [diff] [blame] | 404 | |
Philip P. Moltmann | 7641cd0 | 2020-03-11 14:42:43 -0700 | [diff] [blame] | 405 | /** |
| 406 | * Flag for {@link #startWatchingMode} that causes the callback to happen on the switch-op |
| 407 | * instead the op the callback was registered. (This simulates pre-R behavior). |
| 408 | * |
| 409 | * @hide |
| 410 | */ |
| 411 | public static final int CALL_BACK_ON_SWITCHED_OP = 1 << 1; |
David Cheung | 2ead966 | 2020-02-19 16:11:06 -0800 | [diff] [blame] | 412 | |
| 413 | /** |
| 414 | * Flag to determine whether we should log noteOp/startOp calls to make sure they |
| 415 | * are correctly used |
| 416 | * |
| 417 | * @hide |
| 418 | */ |
| 419 | public static final boolean NOTE_OP_COLLECTION_ENABLED = false; |
| 420 | |
Dianne Hackborn | c216a26 | 2018-04-26 13:46:22 -0700 | [diff] [blame] | 421 | /** |
| 422 | * @hide |
| 423 | */ |
| 424 | public static final String[] MODE_NAMES = new String[] { |
| 425 | "allow", // MODE_ALLOWED |
| 426 | "ignore", // MODE_IGNORED |
| 427 | "deny", // MODE_ERRORED |
| 428 | "default", // MODE_DEFAULT |
| 429 | "foreground", // MODE_FOREGROUND |
| 430 | }; |
| 431 | |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 432 | /** @hide */ |
| 433 | @Retention(RetentionPolicy.SOURCE) |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 434 | @IntDef(prefix = { "UID_STATE_" }, value = { |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 435 | UID_STATE_PERSISTENT, |
| 436 | UID_STATE_TOP, |
Amith Yamasani | a0a30a1 | 2019-01-22 11:38:06 -0800 | [diff] [blame] | 437 | UID_STATE_FOREGROUND_SERVICE_LOCATION, |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 438 | UID_STATE_FOREGROUND_SERVICE, |
| 439 | UID_STATE_FOREGROUND, |
| 440 | UID_STATE_BACKGROUND, |
| 441 | UID_STATE_CACHED |
| 442 | }) |
| 443 | public @interface UidState {} |
| 444 | |
Dianne Hackborn | c216a26 | 2018-04-26 13:46:22 -0700 | [diff] [blame] | 445 | /** |
Svet Ganov | 05fcd22 | 2019-07-08 16:30:45 -0700 | [diff] [blame] | 446 | * Uid state: The UID is a foreground persistent app. The lower the UID |
| 447 | * state the more important the UID is for the user. |
Dianne Hackborn | cd1f30b | 2018-04-23 17:38:09 -0700 | [diff] [blame] | 448 | * @hide |
| 449 | */ |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 450 | @TestApi |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 451 | @SystemApi |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 452 | public static final int UID_STATE_PERSISTENT = 100; |
Dianne Hackborn | cd1f30b | 2018-04-23 17:38:09 -0700 | [diff] [blame] | 453 | |
| 454 | /** |
Svet Ganov | 05fcd22 | 2019-07-08 16:30:45 -0700 | [diff] [blame] | 455 | * Uid state: The UID is top foreground app. The lower the UID |
| 456 | * state the more important the UID is for the user. |
Dianne Hackborn | cd1f30b | 2018-04-23 17:38:09 -0700 | [diff] [blame] | 457 | * @hide |
| 458 | */ |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 459 | @TestApi |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 460 | @SystemApi |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 461 | public static final int UID_STATE_TOP = 200; |
Dianne Hackborn | cd1f30b | 2018-04-23 17:38:09 -0700 | [diff] [blame] | 462 | |
| 463 | /** |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 464 | * Uid state: The UID is running a foreground service of location type. |
Svet Ganov | 05fcd22 | 2019-07-08 16:30:45 -0700 | [diff] [blame] | 465 | * 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] | 466 | * This uid state is a counterpart to PROCESS_STATE_FOREGROUND_SERVICE_LOCATION which has been |
| 467 | * deprecated. |
Amith Yamasani | a0a30a1 | 2019-01-22 11:38:06 -0800 | [diff] [blame] | 468 | * @hide |
Hui Yu | 2696932 | 2019-08-21 14:56:35 -0700 | [diff] [blame] | 469 | * @deprecated |
Amith Yamasani | a0a30a1 | 2019-01-22 11:38:06 -0800 | [diff] [blame] | 470 | */ |
| 471 | @TestApi |
| 472 | @SystemApi |
Hui Yu | 2696932 | 2019-08-21 14:56:35 -0700 | [diff] [blame] | 473 | @Deprecated |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 474 | public static final int UID_STATE_FOREGROUND_SERVICE_LOCATION = 300; |
Amith Yamasani | a0a30a1 | 2019-01-22 11:38:06 -0800 | [diff] [blame] | 475 | |
| 476 | /** |
Svet Ganov | 05fcd22 | 2019-07-08 16:30:45 -0700 | [diff] [blame] | 477 | * Uid state: The UID is running a foreground service. The lower the UID |
| 478 | * state the more important the UID is for the user. |
Dianne Hackborn | cd1f30b | 2018-04-23 17:38:09 -0700 | [diff] [blame] | 479 | * @hide |
| 480 | */ |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 481 | @TestApi |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 482 | @SystemApi |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 483 | public static final int UID_STATE_FOREGROUND_SERVICE = 400; |
Dianne Hackborn | cd1f30b | 2018-04-23 17:38:09 -0700 | [diff] [blame] | 484 | |
| 485 | /** |
Svet Ganov | 05fcd22 | 2019-07-08 16:30:45 -0700 | [diff] [blame] | 486 | * Uid state: The UID is a foreground app. The lower the UID |
| 487 | * state the more important the UID is for the user. |
Dianne Hackborn | cd1f30b | 2018-04-23 17:38:09 -0700 | [diff] [blame] | 488 | * @hide |
| 489 | */ |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 490 | @TestApi |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 491 | @SystemApi |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 492 | public static final int UID_STATE_FOREGROUND = 500; |
Dianne Hackborn | cd1f30b | 2018-04-23 17:38:09 -0700 | [diff] [blame] | 493 | |
| 494 | /** |
Hui Yu | 2696932 | 2019-08-21 14:56:35 -0700 | [diff] [blame] | 495 | * The max, which is min priority, UID state for which any app op |
| 496 | * would be considered as performed in the foreground. |
| 497 | * @hide |
| 498 | */ |
| 499 | public static final int UID_STATE_MAX_LAST_NON_RESTRICTED = UID_STATE_FOREGROUND; |
| 500 | |
| 501 | /** |
Svet Ganov | 05fcd22 | 2019-07-08 16:30:45 -0700 | [diff] [blame] | 502 | * Uid state: The UID is a background app. The lower the UID |
| 503 | * state the more important the UID is for the user. |
Dianne Hackborn | cd1f30b | 2018-04-23 17:38:09 -0700 | [diff] [blame] | 504 | * @hide |
| 505 | */ |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 506 | @TestApi |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 507 | @SystemApi |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 508 | public static final int UID_STATE_BACKGROUND = 600; |
Dianne Hackborn | cd1f30b | 2018-04-23 17:38:09 -0700 | [diff] [blame] | 509 | |
| 510 | /** |
Svet Ganov | 05fcd22 | 2019-07-08 16:30:45 -0700 | [diff] [blame] | 511 | * Uid state: The UID is a cached app. The lower the UID |
| 512 | * state the more important the UID is for the user. |
Dianne Hackborn | cd1f30b | 2018-04-23 17:38:09 -0700 | [diff] [blame] | 513 | * @hide |
| 514 | */ |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 515 | @TestApi |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 516 | @SystemApi |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 517 | public static final int UID_STATE_CACHED = 700; |
Dianne Hackborn | cd1f30b | 2018-04-23 17:38:09 -0700 | [diff] [blame] | 518 | |
| 519 | /** |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 520 | * Uid state: The UID state with the highest priority. |
Dianne Hackborn | cd1f30b | 2018-04-23 17:38:09 -0700 | [diff] [blame] | 521 | * @hide |
| 522 | */ |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 523 | public static final int MAX_PRIORITY_UID_STATE = UID_STATE_PERSISTENT; |
| 524 | |
| 525 | /** |
| 526 | * Uid state: The UID state with the lowest priority. |
| 527 | * @hide |
| 528 | */ |
| 529 | public static final int MIN_PRIORITY_UID_STATE = UID_STATE_CACHED; |
| 530 | |
| 531 | /** |
Hui Yu | 2696932 | 2019-08-21 14:56:35 -0700 | [diff] [blame] | 532 | * Resolves the first unrestricted state given an app op. |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 533 | * @param op The op to resolve. |
| 534 | * @return The last restricted UID state. |
| 535 | * |
| 536 | * @hide |
| 537 | */ |
| 538 | public static int resolveFirstUnrestrictedUidState(int op) { |
Hui Yu | 2696932 | 2019-08-21 14:56:35 -0700 | [diff] [blame] | 539 | return UID_STATE_FOREGROUND; |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 540 | } |
| 541 | |
| 542 | /** |
Hui Yu | 2696932 | 2019-08-21 14:56:35 -0700 | [diff] [blame] | 543 | * Resolves the last restricted state given an app op. |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 544 | * @param op The op to resolve. |
| 545 | * @return The last restricted UID state. |
| 546 | * |
| 547 | * @hide |
| 548 | */ |
| 549 | public static int resolveLastRestrictedUidState(int op) { |
Hui Yu | 2696932 | 2019-08-21 14:56:35 -0700 | [diff] [blame] | 550 | return UID_STATE_BACKGROUND; |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 551 | } |
| 552 | |
| 553 | /** @hide Note: Keep these sorted */ |
| 554 | public static final int[] UID_STATES = { |
| 555 | UID_STATE_PERSISTENT, |
| 556 | UID_STATE_TOP, |
| 557 | UID_STATE_FOREGROUND_SERVICE_LOCATION, |
| 558 | UID_STATE_FOREGROUND_SERVICE, |
| 559 | UID_STATE_FOREGROUND, |
| 560 | UID_STATE_BACKGROUND, |
| 561 | UID_STATE_CACHED |
| 562 | }; |
| 563 | |
| 564 | /** @hide */ |
| 565 | public static String getUidStateName(@UidState int uidState) { |
| 566 | switch (uidState) { |
| 567 | case UID_STATE_PERSISTENT: |
| 568 | return "pers"; |
| 569 | case UID_STATE_TOP: |
| 570 | return "top"; |
| 571 | case UID_STATE_FOREGROUND_SERVICE_LOCATION: |
| 572 | return "fgsvcl"; |
| 573 | case UID_STATE_FOREGROUND_SERVICE: |
| 574 | return "fgsvc"; |
| 575 | case UID_STATE_FOREGROUND: |
| 576 | return "fg"; |
| 577 | case UID_STATE_BACKGROUND: |
| 578 | return "bg"; |
| 579 | case UID_STATE_CACHED: |
| 580 | return "cch"; |
| 581 | default: |
| 582 | return "unknown"; |
| 583 | } |
| 584 | } |
| 585 | |
| 586 | /** |
| 587 | * Flag: non proxy operations. These are operations |
| 588 | * performed on behalf of the app itself and not on behalf of |
| 589 | * another one. |
| 590 | * |
| 591 | * @hide |
| 592 | */ |
| 593 | @TestApi |
| 594 | @SystemApi |
| 595 | public static final int OP_FLAG_SELF = 0x1; |
| 596 | |
| 597 | /** |
| 598 | * Flag: trusted proxy operations. These are operations |
| 599 | * performed on behalf of another app by a trusted app. |
| 600 | * Which is work a trusted app blames on another app. |
| 601 | * |
| 602 | * @hide |
| 603 | */ |
| 604 | @TestApi |
| 605 | @SystemApi |
| 606 | public static final int OP_FLAG_TRUSTED_PROXY = 0x2; |
| 607 | |
| 608 | /** |
| 609 | * Flag: untrusted proxy operations. These are operations |
| 610 | * performed on behalf of another app by an untrusted app. |
| 611 | * Which is work an untrusted app blames on another app. |
| 612 | * |
| 613 | * @hide |
| 614 | */ |
| 615 | @TestApi |
| 616 | @SystemApi |
| 617 | public static final int OP_FLAG_UNTRUSTED_PROXY = 0x4; |
| 618 | |
| 619 | /** |
| 620 | * Flag: trusted proxied operations. These are operations |
| 621 | * performed by a trusted other app on behalf of an app. |
| 622 | * Which is work an app was blamed for by a trusted app. |
| 623 | * |
| 624 | * @hide |
| 625 | */ |
| 626 | @TestApi |
| 627 | @SystemApi |
| 628 | public static final int OP_FLAG_TRUSTED_PROXIED = 0x8; |
| 629 | |
| 630 | /** |
| 631 | * Flag: untrusted proxied operations. These are operations |
| 632 | * performed by an untrusted other app on behalf of an app. |
| 633 | * Which is work an app was blamed for by an untrusted app. |
| 634 | * |
| 635 | * @hide |
| 636 | */ |
| 637 | @TestApi |
| 638 | @SystemApi |
| 639 | public static final int OP_FLAG_UNTRUSTED_PROXIED = 0x10; |
| 640 | |
| 641 | /** |
| 642 | * Flags: all operations. These include operations matched |
| 643 | * by {@link #OP_FLAG_SELF}, {@link #OP_FLAG_TRUSTED_PROXIED}, |
| 644 | * {@link #OP_FLAG_UNTRUSTED_PROXIED}, {@link #OP_FLAG_TRUSTED_PROXIED}, |
| 645 | * {@link #OP_FLAG_UNTRUSTED_PROXIED}. |
| 646 | * |
| 647 | * @hide |
| 648 | */ |
| 649 | @TestApi |
| 650 | @SystemApi |
| 651 | public static final int OP_FLAGS_ALL = |
| 652 | OP_FLAG_SELF |
| 653 | | OP_FLAG_TRUSTED_PROXY |
| 654 | | OP_FLAG_UNTRUSTED_PROXY |
| 655 | | OP_FLAG_TRUSTED_PROXIED |
| 656 | | OP_FLAG_UNTRUSTED_PROXIED; |
| 657 | |
| 658 | /** |
| 659 | * Flags: all trusted operations which is ones either the app did {@link #OP_FLAG_SELF}, |
| 660 | * or it was blamed for by a trusted app {@link #OP_FLAG_TRUSTED_PROXIED}, or ones the |
| 661 | * app if untrusted blamed on other apps {@link #OP_FLAG_UNTRUSTED_PROXY}. |
| 662 | * |
| 663 | * @hide |
| 664 | */ |
| 665 | @SystemApi |
| 666 | public static final int OP_FLAGS_ALL_TRUSTED = AppOpsManager.OP_FLAG_SELF |
| 667 | | AppOpsManager.OP_FLAG_UNTRUSTED_PROXY |
| 668 | | AppOpsManager.OP_FLAG_TRUSTED_PROXIED; |
| 669 | |
| 670 | /** @hide */ |
| 671 | @Retention(RetentionPolicy.SOURCE) |
| 672 | @IntDef(flag = true, prefix = { "FLAG_" }, value = { |
| 673 | OP_FLAG_SELF, |
| 674 | OP_FLAG_TRUSTED_PROXY, |
| 675 | OP_FLAG_UNTRUSTED_PROXY, |
| 676 | OP_FLAG_TRUSTED_PROXIED, |
| 677 | OP_FLAG_UNTRUSTED_PROXIED |
| 678 | }) |
| 679 | public @interface OpFlags {} |
| 680 | |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 681 | /** @hide */ |
| 682 | public static final String getFlagName(@OpFlags int flag) { |
| 683 | switch (flag) { |
| 684 | case OP_FLAG_SELF: |
| 685 | return "s"; |
| 686 | case OP_FLAG_TRUSTED_PROXY: |
| 687 | return "tp"; |
| 688 | case OP_FLAG_UNTRUSTED_PROXY: |
| 689 | return "up"; |
| 690 | case OP_FLAG_TRUSTED_PROXIED: |
| 691 | return "tpd"; |
| 692 | case OP_FLAG_UNTRUSTED_PROXIED: |
| 693 | return "upd"; |
| 694 | default: |
| 695 | return "unknown"; |
| 696 | } |
| 697 | } |
| 698 | |
Muhammad Qureshi | 317061a | 2020-03-02 13:15:51 -0800 | [diff] [blame] | 699 | // These constants are redefined here to work around a metalava limitation/bug where |
| 700 | // @IntDef is not able to see @hide symbols when they are hidden via package hiding: |
| 701 | // frameworks/base/core/java/com/android/internal/package.html |
| 702 | |
| 703 | /** @hide */ |
| 704 | public static final int SAMPLING_STRATEGY_DEFAULT = |
| 705 | FrameworkStatsLog.RUNTIME_APP_OP_ACCESS__SAMPLING_STRATEGY__DEFAULT; |
| 706 | |
| 707 | /** @hide */ |
| 708 | public static final int SAMPLING_STRATEGY_UNIFORM = |
| 709 | FrameworkStatsLog.RUNTIME_APP_OP_ACCESS__SAMPLING_STRATEGY__UNIFORM; |
| 710 | |
| 711 | /** @hide */ |
| 712 | public static final int SAMPLING_STRATEGY_RARELY_USED = |
| 713 | FrameworkStatsLog.RUNTIME_APP_OP_ACCESS__SAMPLING_STRATEGY__RARELY_USED; |
| 714 | |
Stanislav Zholnin | 4c32385 | 2020-03-04 18:03:24 +0000 | [diff] [blame] | 715 | /** @hide */ |
| 716 | public static final int SAMPLING_STRATEGY_BOOT_TIME_SAMPLING = |
| 717 | FrameworkStatsLog.RUNTIME_APP_OP_ACCESS__SAMPLING_STRATEGY__BOOT_TIME_SAMPLING; |
| 718 | |
Stanislav Zholnin | 90516b9 | 2020-01-20 14:03:06 +0000 | [diff] [blame] | 719 | /** |
| 720 | * Strategies used for message sampling |
| 721 | * @hide |
| 722 | */ |
| 723 | @Retention(RetentionPolicy.SOURCE) |
Muhammad Qureshi | 317061a | 2020-03-02 13:15:51 -0800 | [diff] [blame] | 724 | @IntDef(prefix = {"SAMPLING_STRATEGY_"}, value = { |
| 725 | SAMPLING_STRATEGY_DEFAULT, |
| 726 | SAMPLING_STRATEGY_UNIFORM, |
Stanislav Zholnin | 4c32385 | 2020-03-04 18:03:24 +0000 | [diff] [blame] | 727 | SAMPLING_STRATEGY_RARELY_USED, |
| 728 | SAMPLING_STRATEGY_BOOT_TIME_SAMPLING |
Stanislav Zholnin | 90516b9 | 2020-01-20 14:03:06 +0000 | [diff] [blame] | 729 | }) |
| 730 | public @interface SamplingStrategy {} |
| 731 | |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 732 | private static final int UID_STATE_OFFSET = 31; |
| 733 | private static final int FLAGS_MASK = 0xFFFFFFFF; |
| 734 | |
| 735 | /** |
| 736 | * Key for a data bucket storing app op state. The bucket |
| 737 | * is composed of the uid state and state flags. This way |
| 738 | * we can query data for given uid state and a set of flags where |
| 739 | * the flags control which type of data to get. For example, |
| 740 | * one can get the ops an app did on behalf of other apps |
| 741 | * while in the background. |
| 742 | * |
| 743 | * @hide |
| 744 | */ |
| 745 | @Retention(RetentionPolicy.SOURCE) |
| 746 | @Target({ElementType.METHOD, ElementType.PARAMETER, ElementType.FIELD}) |
| 747 | public @interface DataBucketKey { |
| 748 | } |
| 749 | |
| 750 | /** @hide */ |
| 751 | public static String keyToString(@DataBucketKey long key) { |
| 752 | final int uidState = extractUidStateFromKey(key); |
| 753 | final int flags = extractFlagsFromKey(key); |
| 754 | return "[" + getUidStateName(uidState) + "-" + flagsToString(flags) + "]"; |
| 755 | } |
| 756 | |
| 757 | /** @hide */ |
| 758 | public static @DataBucketKey long makeKey(@UidState int uidState, @OpFlags int flags) { |
| 759 | return ((long) uidState << UID_STATE_OFFSET) | flags; |
| 760 | } |
| 761 | |
| 762 | /** @hide */ |
| 763 | public static int extractUidStateFromKey(@DataBucketKey long key) { |
| 764 | return (int) (key >> UID_STATE_OFFSET); |
| 765 | } |
| 766 | |
| 767 | /** @hide */ |
| 768 | public static int extractFlagsFromKey(@DataBucketKey long key) { |
| 769 | return (int) (key & FLAGS_MASK); |
| 770 | } |
| 771 | |
| 772 | /** @hide */ |
| 773 | public static String flagsToString(@OpFlags int flags) { |
| 774 | final StringBuilder flagsBuilder = new StringBuilder(); |
| 775 | while (flags != 0) { |
| 776 | final int flag = 1 << Integer.numberOfTrailingZeros(flags); |
| 777 | flags &= ~flag; |
| 778 | if (flagsBuilder.length() > 0) { |
| 779 | flagsBuilder.append('|'); |
| 780 | } |
| 781 | flagsBuilder.append(getFlagName(flag)); |
| 782 | } |
| 783 | return flagsBuilder.toString(); |
| 784 | } |
Dianne Hackborn | cd1f30b | 2018-04-23 17:38:09 -0700 | [diff] [blame] | 785 | |
Daniel Sandler | fde19b1 | 2013-01-17 00:21:05 -0500 | [diff] [blame] | 786 | // when adding one of these: |
| 787 | // - increment _NUM_OP |
Peter Visontay | 5a2a1ef | 2017-12-18 20:34:03 +0000 | [diff] [blame] | 788 | // - define an OPSTR_* constant (marked as @SystemApi) |
Svetoslav Ganov | eaca4c5 | 2016-05-05 18:08:00 -0700 | [diff] [blame] | 789 | // - add rows to sOpToSwitch, sOpToString, sOpNames, sOpToPerms, sOpDefault |
Daniel Sandler | fde19b1 | 2013-01-17 00:21:05 -0500 | [diff] [blame] | 790 | // - add descriptive strings to Settings/res/values/arrays.xml |
David Christie | 0b83745 | 2013-07-29 16:02:13 -0700 | [diff] [blame] | 791 | // - add the op to the appropriate template in AppOpsState.OpsTemplate (settings app) |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 792 | |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 793 | /** @hide No operation specified. */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 794 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 795 | public static final int OP_NONE = AppProtoEnums.APP_OP_NONE; |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 796 | /** @hide Access to coarse location information. */ |
Artur Satayev | f0b7d0b | 2019-11-04 11:16:45 +0000 | [diff] [blame] | 797 | @UnsupportedAppUsage |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 798 | @TestApi |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 799 | public static final int OP_COARSE_LOCATION = AppProtoEnums.APP_OP_COARSE_LOCATION; |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 800 | /** @hide Access to fine location information. */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 801 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 802 | public static final int OP_FINE_LOCATION = AppProtoEnums.APP_OP_FINE_LOCATION; |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 803 | /** @hide Causing GPS to run. */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 804 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 805 | public static final int OP_GPS = AppProtoEnums.APP_OP_GPS; |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 806 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 807 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 808 | public static final int OP_VIBRATE = AppProtoEnums.APP_OP_VIBRATE; |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 809 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 810 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 811 | public static final int OP_READ_CONTACTS = AppProtoEnums.APP_OP_READ_CONTACTS; |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 812 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 813 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 814 | public static final int OP_WRITE_CONTACTS = AppProtoEnums.APP_OP_WRITE_CONTACTS; |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 815 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 816 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 817 | 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] | 818 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 819 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 820 | 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] | 821 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 822 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 823 | public static final int OP_READ_CALENDAR = AppProtoEnums.APP_OP_READ_CALENDAR; |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 824 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 825 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 826 | public static final int OP_WRITE_CALENDAR = AppProtoEnums.APP_OP_WRITE_CALENDAR; |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 827 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 828 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 829 | public static final int OP_WIFI_SCAN = AppProtoEnums.APP_OP_WIFI_SCAN; |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 830 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 831 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 832 | public static final int OP_POST_NOTIFICATION = AppProtoEnums.APP_OP_POST_NOTIFICATION; |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 833 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 834 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 835 | public static final int OP_NEIGHBORING_CELLS = AppProtoEnums.APP_OP_NEIGHBORING_CELLS; |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 836 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 837 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 838 | public static final int OP_CALL_PHONE = AppProtoEnums.APP_OP_CALL_PHONE; |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 839 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 840 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 841 | public static final int OP_READ_SMS = AppProtoEnums.APP_OP_READ_SMS; |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 842 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 843 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 844 | public static final int OP_WRITE_SMS = AppProtoEnums.APP_OP_WRITE_SMS; |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 845 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 846 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 847 | public static final int OP_RECEIVE_SMS = AppProtoEnums.APP_OP_RECEIVE_SMS; |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 848 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 849 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 850 | public static final int OP_RECEIVE_EMERGECY_SMS = |
| 851 | AppProtoEnums.APP_OP_RECEIVE_EMERGENCY_SMS; |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 852 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 853 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 854 | public static final int OP_RECEIVE_MMS = AppProtoEnums.APP_OP_RECEIVE_MMS; |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 855 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 856 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 857 | 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] | 858 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 859 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 860 | public static final int OP_SEND_SMS = AppProtoEnums.APP_OP_SEND_SMS; |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 861 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 862 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 863 | 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] | 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_WRITE_ICC_SMS = AppProtoEnums.APP_OP_WRITE_ICC_SMS; |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 867 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 868 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 869 | public static final int OP_WRITE_SETTINGS = AppProtoEnums.APP_OP_WRITE_SETTINGS; |
Peter Visontay | 96449f6 | 2017-12-11 18:50:03 +0000 | [diff] [blame] | 870 | /** @hide Required to draw on top of other apps. */ |
Artur Satayev | f0b7d0b | 2019-11-04 11:16:45 +0000 | [diff] [blame] | 871 | @UnsupportedAppUsage |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 872 | @TestApi |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 873 | 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] | 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_ACCESS_NOTIFICATIONS = |
| 877 | AppProtoEnums.APP_OP_ACCESS_NOTIFICATIONS; |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 878 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 879 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 880 | public static final int OP_CAMERA = AppProtoEnums.APP_OP_CAMERA; |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 881 | /** @hide */ |
Artur Satayev | f0b7d0b | 2019-11-04 11:16:45 +0000 | [diff] [blame] | 882 | @UnsupportedAppUsage |
Svet Ganov | a7a0db6 | 2018-02-27 20:08:01 -0800 | [diff] [blame] | 883 | @TestApi |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 884 | public static final int OP_RECORD_AUDIO = AppProtoEnums.APP_OP_RECORD_AUDIO; |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 885 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 886 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 887 | public static final int OP_PLAY_AUDIO = AppProtoEnums.APP_OP_PLAY_AUDIO; |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 888 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 889 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 890 | public static final int OP_READ_CLIPBOARD = AppProtoEnums.APP_OP_READ_CLIPBOARD; |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 891 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 892 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 893 | public static final int OP_WRITE_CLIPBOARD = AppProtoEnums.APP_OP_WRITE_CLIPBOARD; |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 894 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 895 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 896 | 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] | 897 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 898 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 899 | 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] | 900 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 901 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 902 | 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] | 903 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 904 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 905 | 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] | 906 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 907 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 908 | 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] | 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_AUDIO_MEDIA_VOLUME = AppProtoEnums.APP_OP_AUDIO_MEDIA_VOLUME; |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 912 | /** @hide */ |
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_AUDIO_ALARM_VOLUME = AppProtoEnums.APP_OP_AUDIO_ALARM_VOLUME; |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 915 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 916 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 917 | public static final int OP_AUDIO_NOTIFICATION_VOLUME = |
| 918 | AppProtoEnums.APP_OP_AUDIO_NOTIFICATION_VOLUME; |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 919 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 920 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 921 | public static final int OP_AUDIO_BLUETOOTH_VOLUME = |
| 922 | AppProtoEnums.APP_OP_AUDIO_BLUETOOTH_VOLUME; |
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_WAKE_LOCK = AppProtoEnums.APP_OP_WAKE_LOCK; |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 926 | /** @hide Continually monitoring location data. */ |
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_MONITOR_LOCATION = |
| 929 | AppProtoEnums.APP_OP_MONITOR_LOCATION; |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 930 | /** @hide Continually monitoring location data with a relatively high power request. */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 931 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 932 | public static final int OP_MONITOR_HIGH_POWER_LOCATION = |
| 933 | AppProtoEnums.APP_OP_MONITOR_HIGH_POWER_LOCATION; |
Dianne Hackborn | e22b3b1 | 2014-05-07 18:06:44 -0700 | [diff] [blame] | 934 | /** @hide Retrieve current usage stats via {@link UsageStatsManager}. */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 935 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 936 | 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] | 937 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 938 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 939 | public static final int OP_MUTE_MICROPHONE = AppProtoEnums.APP_OP_MUTE_MICROPHONE; |
Emily Bernier | 22c921a | 2014-05-28 11:01:32 -0400 | [diff] [blame] | 940 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 941 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 942 | public static final int OP_TOAST_WINDOW = AppProtoEnums.APP_OP_TOAST_WINDOW; |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 943 | /** @hide Capture the device's display contents and/or audio */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 944 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 945 | public static final int OP_PROJECT_MEDIA = AppProtoEnums.APP_OP_PROJECT_MEDIA; |
Benedict Wong | 3eb9520 | 2019-11-05 12:50:59 -0800 | [diff] [blame] | 946 | /** |
| 947 | * Start (without additional user intervention) a VPN connection, as used by {@link |
| 948 | * android.net.VpnService} along with as Platform VPN connections, as used by {@link |
| 949 | * android.net.VpnManager} |
| 950 | * |
| 951 | * <p>This appop is granted to apps that have already been given user consent to start |
| 952 | * VpnService based VPN connections. As this is a superset of OP_ACTIVATE_PLATFORM_VPN, this |
| 953 | * appop also allows the starting of Platform VPNs. |
| 954 | * |
| 955 | * @hide |
| 956 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 957 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 958 | public static final int OP_ACTIVATE_VPN = AppProtoEnums.APP_OP_ACTIVATE_VPN; |
Benjamin Franz | f3ece36 | 2015-02-11 10:51:10 +0000 | [diff] [blame] | 959 | /** @hide Access the WallpaperManagerAPI to write wallpapers. */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 960 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 961 | public static final int OP_WRITE_WALLPAPER = AppProtoEnums.APP_OP_WRITE_WALLPAPER; |
Dianne Hackborn | d59a5d5 | 2015-04-04 14:52:14 -0700 | [diff] [blame] | 962 | /** @hide Received the assist structure from an app. */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 963 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 964 | public static final int OP_ASSIST_STRUCTURE = AppProtoEnums.APP_OP_ASSIST_STRUCTURE; |
Dianne Hackborn | d59a5d5 | 2015-04-04 14:52:14 -0700 | [diff] [blame] | 965 | /** @hide Received a screenshot from assist. */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 966 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 967 | public static final int OP_ASSIST_SCREENSHOT = AppProtoEnums.APP_OP_ASSIST_SCREENSHOT; |
Svet Ganov | 16a1689 | 2015-04-16 10:32:04 -0700 | [diff] [blame] | 968 | /** @hide Read the phone state. */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 969 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 970 | 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] | 971 | /** @hide Add voicemail messages to the voicemail content provider. */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 972 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 973 | public static final int OP_ADD_VOICEMAIL = AppProtoEnums.APP_OP_ADD_VOICEMAIL; |
Svetoslav | 5335b67 | 2015-04-29 12:00:51 -0700 | [diff] [blame] | 974 | /** @hide Access APIs for SIP calling over VOIP or WiFi. */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 975 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 976 | public static final int OP_USE_SIP = AppProtoEnums.APP_OP_USE_SIP; |
Svetoslav | c656e6f | 2015-04-29 14:08:16 -0700 | [diff] [blame] | 977 | /** @hide Intercept outgoing calls. */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 978 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 979 | public static final int OP_PROCESS_OUTGOING_CALLS = |
| 980 | AppProtoEnums.APP_OP_PROCESS_OUTGOING_CALLS; |
Svetoslav | 4af76a5 | 2015-04-29 15:29:46 -0700 | [diff] [blame] | 981 | /** @hide User the fingerprint API. */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 982 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 983 | public static final int OP_USE_FINGERPRINT = AppProtoEnums.APP_OP_USE_FINGERPRINT; |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 984 | /** @hide Access to body sensors such as heart rate, etc. */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 985 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 986 | public static final int OP_BODY_SENSORS = AppProtoEnums.APP_OP_BODY_SENSORS; |
Svet Ganov | ede4316 | 2015-05-02 17:42:44 -0700 | [diff] [blame] | 987 | /** @hide Read previously received cell broadcast messages. */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 988 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 989 | 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] | 990 | /** @hide Inject mock location into the system. */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 991 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 992 | public static final int OP_MOCK_LOCATION = AppProtoEnums.APP_OP_MOCK_LOCATION; |
Svet Ganov | 921c7df | 2015-06-29 21:51:41 -0700 | [diff] [blame] | 993 | /** @hide Read external storage. */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 994 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 995 | 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] | 996 | /** @hide Write external storage. */ |
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_WRITE_EXTERNAL_STORAGE = |
| 999 | AppProtoEnums.APP_OP_WRITE_EXTERNAL_STORAGE; |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 1000 | /** @hide Turned on the screen. */ |
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_TURN_SCREEN_ON = AppProtoEnums.APP_OP_TURN_SCREEN_ON; |
Svetoslav | f3f02ac | 2015-09-08 14:36:35 -0700 | [diff] [blame] | 1003 | /** @hide Get device accounts. */ |
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_GET_ACCOUNTS = AppProtoEnums.APP_OP_GET_ACCOUNTS; |
Dianne Hackborn | bef28fe | 2015-10-29 17:57:11 -0700 | [diff] [blame] | 1006 | /** @hide Control whether an application is allowed to run in the background. */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 1007 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 1008 | public static final int OP_RUN_IN_BACKGROUND = |
Stanislav Zholnin | 5c88c73 | 2020-03-29 21:46:35 +0100 | [diff] [blame] | 1009 | AppProtoEnums.APP_OP_RUN_IN_BACKGROUND; |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 1010 | /** @hide */ |
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_AUDIO_ACCESSIBILITY_VOLUME = |
| 1013 | AppProtoEnums.APP_OP_AUDIO_ACCESSIBILITY_VOLUME; |
Chad Brubaker | 73ec8f9 | 2016-11-10 11:24:40 -0800 | [diff] [blame] | 1014 | /** @hide Read the phone number. */ |
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_READ_PHONE_NUMBERS = AppProtoEnums.APP_OP_READ_PHONE_NUMBERS; |
Suprabh Shukla | 2f34b1a | 2016-12-16 14:47:25 -0800 | [diff] [blame] | 1017 | /** @hide Request package installs through package installer */ |
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_REQUEST_INSTALL_PACKAGES = |
| 1020 | AppProtoEnums.APP_OP_REQUEST_INSTALL_PACKAGES; |
Winson Chung | f4ac063 | 2017-03-17 12:34:12 -0700 | [diff] [blame] | 1021 | /** @hide Enter picture-in-picture. */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 1022 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 1023 | 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] | 1024 | /** @hide Instant app start foreground service. */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 1025 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 1026 | public static final int OP_INSTANT_APP_START_FOREGROUND = |
| 1027 | AppProtoEnums.APP_OP_INSTANT_APP_START_FOREGROUND; |
Eugene Susla | cae3d3e | 2017-01-31 11:08:11 -0800 | [diff] [blame] | 1028 | /** @hide Answer incoming phone calls */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 1029 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 1030 | 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] | 1031 | /** @hide Run jobs when in background */ |
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_RUN_ANY_IN_BACKGROUND = AppProtoEnums.APP_OP_RUN_ANY_IN_BACKGROUND; |
Peter Visontay | 1246d9e | 2017-10-17 17:02:45 +0100 | [diff] [blame] | 1034 | /** @hide Change Wi-Fi connectivity state */ |
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_CHANGE_WIFI_STATE = AppProtoEnums.APP_OP_CHANGE_WIFI_STATE; |
Peter Visontay | f2e3836 | 2017-11-27 15:27:16 +0000 | [diff] [blame] | 1037 | /** @hide Request package deletion through package installer */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 1038 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 1039 | public static final int OP_REQUEST_DELETE_PACKAGES = |
| 1040 | AppProtoEnums.APP_OP_REQUEST_DELETE_PACKAGES; |
Peter Visontay | 1195083 | 2017-11-14 19:34:59 +0000 | [diff] [blame] | 1041 | /** @hide Bind an accessibility service. */ |
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_BIND_ACCESSIBILITY_SERVICE = |
| 1044 | AppProtoEnums.APP_OP_BIND_ACCESSIBILITY_SERVICE; |
Tyler Gunn | 79bc1ec | 2018-01-22 15:17:54 -0800 | [diff] [blame] | 1045 | /** @hide Continue handover of a call from another app */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 1046 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 1047 | public static final int OP_ACCEPT_HANDOVER = AppProtoEnums.APP_OP_ACCEPT_HANDOVER; |
Nathan Harold | 1bb42067 | 2018-03-14 17:08:53 -0700 | [diff] [blame] | 1048 | /** @hide Create and Manage IPsec Tunnels */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 1049 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 1050 | 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] | 1051 | /** @hide Any app start foreground service. */ |
Artur Satayev | f0b7d0b | 2019-11-04 11:16:45 +0000 | [diff] [blame] | 1052 | @UnsupportedAppUsage |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 1053 | @TestApi |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 1054 | 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] | 1055 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 1056 | @UnsupportedAppUsage |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 1057 | public static final int OP_BLUETOOTH_SCAN = AppProtoEnums.APP_OP_BLUETOOTH_SCAN; |
Kevin Chyn | b3c05aa | 2018-09-21 16:50:32 -0700 | [diff] [blame] | 1058 | /** @hide Use the BiometricPrompt/BiometricManager APIs. */ |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 1059 | public static final int OP_USE_BIOMETRIC = AppProtoEnums.APP_OP_USE_BIOMETRIC; |
Zimuzo | 6cbf9cc | 2018-10-05 12:05:58 +0100 | [diff] [blame] | 1060 | /** @hide Physical activity recognition. */ |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 1061 | public static final int OP_ACTIVITY_RECOGNITION = AppProtoEnums.APP_OP_ACTIVITY_RECOGNITION; |
Hongming Jin | 228cd01 | 2018-11-09 14:47:50 -0800 | [diff] [blame] | 1062 | /** @hide Financial app sms read. */ |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 1063 | public static final int OP_SMS_FINANCIAL_TRANSACTIONS = |
| 1064 | AppProtoEnums.APP_OP_SMS_FINANCIAL_TRANSACTIONS; |
Jeff Sharkey | d2a1f0d | 2018-11-19 10:32:52 -0700 | [diff] [blame] | 1065 | /** @hide Read media of audio type. */ |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 1066 | 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] | 1067 | /** @hide Write media of audio type. */ |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 1068 | 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] | 1069 | /** @hide Read media of video type. */ |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 1070 | 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] | 1071 | /** @hide Write media of video type. */ |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 1072 | 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] | 1073 | /** @hide Read media of image type. */ |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 1074 | 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] | 1075 | /** @hide Write media of image type. */ |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 1076 | 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] | 1077 | /** @hide Has a legacy (non-isolated) view of storage. */ |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 1078 | public static final int OP_LEGACY_STORAGE = AppProtoEnums.APP_OP_LEGACY_STORAGE; |
Jackal Guo | 8dc791e | 2019-01-14 10:26:42 +0800 | [diff] [blame] | 1079 | /** @hide Accessing accessibility features */ |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 1080 | public static final int OP_ACCESS_ACCESSIBILITY = AppProtoEnums.APP_OP_ACCESS_ACCESSIBILITY; |
Michael Groover | 656ef91 | 2019-04-09 17:09:57 -0700 | [diff] [blame] | 1081 | /** @hide Read the device identifiers (IMEI / MEID, IMSI, SIM / Build serial) */ |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 1082 | public static final int OP_READ_DEVICE_IDENTIFIERS = |
| 1083 | AppProtoEnums.APP_OP_READ_DEVICE_IDENTIFIERS; |
Philip P. Moltmann | 89b044f | 2019-09-13 15:12:34 -0700 | [diff] [blame] | 1084 | /** @hide Read location metadata from media */ |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 1085 | 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] | 1086 | /** @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] | 1087 | 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] | 1088 | /** @hide Access all external storage */ |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 1089 | public static final int OP_MANAGE_EXTERNAL_STORAGE = |
| 1090 | AppProtoEnums.APP_OP_MANAGE_EXTERNAL_STORAGE; |
kholoud mohamed | 20ded1f | 2019-12-03 17:52:38 +0000 | [diff] [blame] | 1091 | /** @hide Communicate cross-profile within the same profile group. */ |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 1092 | public static final int OP_INTERACT_ACROSS_PROFILES = |
| 1093 | AppProtoEnums.APP_OP_INTERACT_ACROSS_PROFILES; |
Benedict Wong | 3eb9520 | 2019-11-05 12:50:59 -0800 | [diff] [blame] | 1094 | /** |
| 1095 | * Start (without additional user intervention) a Platform VPN connection, as used by {@link |
| 1096 | * android.net.VpnManager} |
| 1097 | * |
| 1098 | * <p>This appop is granted to apps that have already been given user consent to start Platform |
| 1099 | * VPN connections. This appop is insufficient to start VpnService based VPNs; OP_ACTIVATE_VPN |
| 1100 | * is needed for that. |
| 1101 | * |
| 1102 | * @hide |
| 1103 | */ |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 1104 | 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] | 1105 | /** @hide Controls whether or not read logs are available for incremental installations. */ |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 1106 | 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] | 1107 | |
| 1108 | // App op deprecated/removed. |
| 1109 | private static final int OP_DEPRECATED_1 = AppProtoEnums.APP_OP_DEPRECATED_1; |
Patrick Baumann | 6c1c809 | 2019-06-27 14:55:44 -0700 | [diff] [blame] | 1110 | |
Eugene Susla | 5fc2d76 | 2020-03-04 13:53:10 -0800 | [diff] [blame] | 1111 | /** @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] | 1112 | public static final int OP_AUTO_REVOKE_PERMISSIONS_IF_UNUSED = |
| 1113 | AppProtoEnums.APP_OP_AUTO_REVOKE_PERMISSIONS_IF_UNUSED; |
Eugene Susla | 5fc2d76 | 2020-03-04 13:53:10 -0800 | [diff] [blame] | 1114 | |
Eugene Susla | 922cd08 | 2020-03-11 12:38:17 -0700 | [diff] [blame] | 1115 | /** |
| 1116 | * Whether {@link #OP_AUTO_REVOKE_PERMISSIONS_IF_UNUSED} is allowed to be changed by |
| 1117 | * the installer |
| 1118 | * |
| 1119 | * @hide |
| 1120 | */ |
Stanislav Zholnin | d5378e9 | 2020-03-15 18:37:12 +0000 | [diff] [blame] | 1121 | public static final int OP_AUTO_REVOKE_MANAGED_BY_INSTALLER = |
| 1122 | AppProtoEnums.APP_OP_AUTO_REVOKE_MANAGED_BY_INSTALLER; |
Eugene Susla | 922cd08 | 2020-03-11 12:38:17 -0700 | [diff] [blame] | 1123 | |
Dianne Hackborn | e04f13d | 2018-05-02 12:51:52 -0700 | [diff] [blame] | 1124 | /** @hide */ |
Nikita Ioffe | ac095e5 | 2020-06-08 22:24:06 +0100 | [diff] [blame] | 1125 | public static final int OP_NO_ISOLATED_STORAGE = AppProtoEnums.APP_OP_NO_ISOLATED_STORAGE; |
| 1126 | |
| 1127 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 1128 | @UnsupportedAppUsage |
Nikita Ioffe | ac095e5 | 2020-06-08 22:24:06 +0100 | [diff] [blame] | 1129 | public static final int _NUM_OP = 100; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1130 | |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 1131 | /** Access to coarse location information. */ |
Svet Ganov | 6e8f67c | 2015-04-29 17:35:19 -0700 | [diff] [blame] | 1132 | public static final String OPSTR_COARSE_LOCATION = "android:coarse_location"; |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 1133 | /** Access to fine location information. */ |
| 1134 | public static final String OPSTR_FINE_LOCATION = |
| 1135 | "android:fine_location"; |
| 1136 | /** Continually monitoring location data. */ |
| 1137 | public static final String OPSTR_MONITOR_LOCATION |
| 1138 | = "android:monitor_location"; |
| 1139 | /** Continually monitoring location data with a relatively high power request. */ |
| 1140 | public static final String OPSTR_MONITOR_HIGH_POWER_LOCATION |
| 1141 | = "android:monitor_location_high_power"; |
Dianne Hackborn | 5064e7c | 2014-09-02 10:57:16 -0700 | [diff] [blame] | 1142 | /** Access to {@link android.app.usage.UsageStatsManager}. */ |
| 1143 | public static final String OPSTR_GET_USAGE_STATS |
| 1144 | = "android:get_usage_stats"; |
Jeff Davidson | 0554260 | 2014-08-11 14:07:27 -0700 | [diff] [blame] | 1145 | /** Activate a VPN connection without user intervention. @hide */ |
Peter Visontay | 5a2a1ef | 2017-12-18 20:34:03 +0000 | [diff] [blame] | 1146 | @SystemApi @TestApi |
Svet Ganov | 6e8f67c | 2015-04-29 17:35:19 -0700 | [diff] [blame] | 1147 | public static final String OPSTR_ACTIVATE_VPN |
| 1148 | = "android:activate_vpn"; |
Svet Ganov | 715cf2a | 2015-06-13 17:31:29 -0700 | [diff] [blame] | 1149 | /** Allows an application to read the user's contacts data. */ |
Svet Ganov | 6e8f67c | 2015-04-29 17:35:19 -0700 | [diff] [blame] | 1150 | public static final String OPSTR_READ_CONTACTS |
| 1151 | = "android:read_contacts"; |
Svet Ganov | 715cf2a | 2015-06-13 17:31:29 -0700 | [diff] [blame] | 1152 | /** Allows an application to write to the user's contacts data. */ |
Svet Ganov | 6e8f67c | 2015-04-29 17:35:19 -0700 | [diff] [blame] | 1153 | public static final String OPSTR_WRITE_CONTACTS |
| 1154 | = "android:write_contacts"; |
Svet Ganov | 715cf2a | 2015-06-13 17:31:29 -0700 | [diff] [blame] | 1155 | /** Allows an application to read the user's call log. */ |
Svet Ganov | 6e8f67c | 2015-04-29 17:35:19 -0700 | [diff] [blame] | 1156 | public static final String OPSTR_READ_CALL_LOG |
| 1157 | = "android:read_call_log"; |
Svet Ganov | 715cf2a | 2015-06-13 17:31:29 -0700 | [diff] [blame] | 1158 | /** Allows an application to write to the user's call log. */ |
Svet Ganov | 6e8f67c | 2015-04-29 17:35:19 -0700 | [diff] [blame] | 1159 | public static final String OPSTR_WRITE_CALL_LOG |
| 1160 | = "android:write_call_log"; |
Svet Ganov | 715cf2a | 2015-06-13 17:31:29 -0700 | [diff] [blame] | 1161 | /** Allows an application to read the user's calendar data. */ |
Svet Ganov | 6e8f67c | 2015-04-29 17:35:19 -0700 | [diff] [blame] | 1162 | public static final String OPSTR_READ_CALENDAR |
| 1163 | = "android:read_calendar"; |
Svet Ganov | 715cf2a | 2015-06-13 17:31:29 -0700 | [diff] [blame] | 1164 | /** Allows an application to write to the user's calendar data. */ |
Svet Ganov | 6e8f67c | 2015-04-29 17:35:19 -0700 | [diff] [blame] | 1165 | public static final String OPSTR_WRITE_CALENDAR |
| 1166 | = "android:write_calendar"; |
Svet Ganov | 715cf2a | 2015-06-13 17:31:29 -0700 | [diff] [blame] | 1167 | /** Allows an application to initiate a phone call. */ |
Svet Ganov | 6e8f67c | 2015-04-29 17:35:19 -0700 | [diff] [blame] | 1168 | public static final String OPSTR_CALL_PHONE |
| 1169 | = "android:call_phone"; |
Svet Ganov | 715cf2a | 2015-06-13 17:31:29 -0700 | [diff] [blame] | 1170 | /** Allows an application to read SMS messages. */ |
Svet Ganov | 6e8f67c | 2015-04-29 17:35:19 -0700 | [diff] [blame] | 1171 | public static final String OPSTR_READ_SMS |
| 1172 | = "android:read_sms"; |
Svet Ganov | 715cf2a | 2015-06-13 17:31:29 -0700 | [diff] [blame] | 1173 | /** Allows an application to receive SMS messages. */ |
Svet Ganov | 6e8f67c | 2015-04-29 17:35:19 -0700 | [diff] [blame] | 1174 | public static final String OPSTR_RECEIVE_SMS |
| 1175 | = "android:receive_sms"; |
Svet Ganov | 715cf2a | 2015-06-13 17:31:29 -0700 | [diff] [blame] | 1176 | /** Allows an application to receive MMS messages. */ |
Svet Ganov | 6e8f67c | 2015-04-29 17:35:19 -0700 | [diff] [blame] | 1177 | public static final String OPSTR_RECEIVE_MMS |
| 1178 | = "android:receive_mms"; |
Svet Ganov | 715cf2a | 2015-06-13 17:31:29 -0700 | [diff] [blame] | 1179 | /** Allows an application to receive WAP push messages. */ |
Svet Ganov | 6e8f67c | 2015-04-29 17:35:19 -0700 | [diff] [blame] | 1180 | public static final String OPSTR_RECEIVE_WAP_PUSH |
| 1181 | = "android:receive_wap_push"; |
Svet Ganov | 715cf2a | 2015-06-13 17:31:29 -0700 | [diff] [blame] | 1182 | /** Allows an application to send SMS messages. */ |
Svet Ganov | 6e8f67c | 2015-04-29 17:35:19 -0700 | [diff] [blame] | 1183 | public static final String OPSTR_SEND_SMS |
| 1184 | = "android:send_sms"; |
Svet Ganov | 715cf2a | 2015-06-13 17:31:29 -0700 | [diff] [blame] | 1185 | /** Required to be able to access the camera device. */ |
Svet Ganov | 6e8f67c | 2015-04-29 17:35:19 -0700 | [diff] [blame] | 1186 | public static final String OPSTR_CAMERA |
| 1187 | = "android:camera"; |
Svet Ganov | 715cf2a | 2015-06-13 17:31:29 -0700 | [diff] [blame] | 1188 | /** Required to be able to access the microphone device. */ |
Svet Ganov | 6e8f67c | 2015-04-29 17:35:19 -0700 | [diff] [blame] | 1189 | public static final String OPSTR_RECORD_AUDIO |
| 1190 | = "android:record_audio"; |
Svet Ganov | 715cf2a | 2015-06-13 17:31:29 -0700 | [diff] [blame] | 1191 | /** Required to access phone state related information. */ |
Svet Ganov | 6e8f67c | 2015-04-29 17:35:19 -0700 | [diff] [blame] | 1192 | public static final String OPSTR_READ_PHONE_STATE |
| 1193 | = "android:read_phone_state"; |
Svet Ganov | 715cf2a | 2015-06-13 17:31:29 -0700 | [diff] [blame] | 1194 | /** Required to access phone state related information. */ |
Svet Ganov | 6e8f67c | 2015-04-29 17:35:19 -0700 | [diff] [blame] | 1195 | public static final String OPSTR_ADD_VOICEMAIL |
| 1196 | = "android:add_voicemail"; |
Svet Ganov | 715cf2a | 2015-06-13 17:31:29 -0700 | [diff] [blame] | 1197 | /** Access APIs for SIP calling over VOIP or WiFi */ |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 1198 | public static final String OPSTR_USE_SIP |
| 1199 | = "android:use_sip"; |
Svet Ganov | e8e8942 | 2016-09-22 19:56:50 -0700 | [diff] [blame] | 1200 | /** Access APIs for diverting outgoing calls */ |
Svet Ganov | 824ad6e | 2016-09-22 19:36:53 -0700 | [diff] [blame] | 1201 | public static final String OPSTR_PROCESS_OUTGOING_CALLS |
| 1202 | = "android:process_outgoing_calls"; |
Svet Ganov | 715cf2a | 2015-06-13 17:31:29 -0700 | [diff] [blame] | 1203 | /** Use the fingerprint API. */ |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 1204 | public static final String OPSTR_USE_FINGERPRINT |
| 1205 | = "android:use_fingerprint"; |
Svet Ganov | 715cf2a | 2015-06-13 17:31:29 -0700 | [diff] [blame] | 1206 | /** Access to body sensors such as heart rate, etc. */ |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 1207 | public static final String OPSTR_BODY_SENSORS |
| 1208 | = "android:body_sensors"; |
Svet Ganov | 715cf2a | 2015-06-13 17:31:29 -0700 | [diff] [blame] | 1209 | /** Read previously received cell broadcast messages. */ |
Svet Ganov | ede4316 | 2015-05-02 17:42:44 -0700 | [diff] [blame] | 1210 | public static final String OPSTR_READ_CELL_BROADCASTS |
| 1211 | = "android:read_cell_broadcasts"; |
Svet Ganov | f7e9cf4 | 2015-05-13 10:40:31 -0700 | [diff] [blame] | 1212 | /** Inject mock location into the system. */ |
| 1213 | public static final String OPSTR_MOCK_LOCATION |
| 1214 | = "android:mock_location"; |
Svet Ganov | 921c7df | 2015-06-29 21:51:41 -0700 | [diff] [blame] | 1215 | /** Read external storage. */ |
| 1216 | public static final String OPSTR_READ_EXTERNAL_STORAGE |
| 1217 | = "android:read_external_storage"; |
| 1218 | /** Write external storage. */ |
| 1219 | public static final String OPSTR_WRITE_EXTERNAL_STORAGE |
| 1220 | = "android:write_external_storage"; |
Billy Lau | 24b9c83 | 2015-07-20 17:34:09 +0100 | [diff] [blame] | 1221 | /** Required to draw on top of other apps. */ |
| 1222 | public static final String OPSTR_SYSTEM_ALERT_WINDOW |
| 1223 | = "android:system_alert_window"; |
Philip P. Moltmann | a04b9ab | 2020-02-13 09:54:04 -0800 | [diff] [blame] | 1224 | /** Required to write/modify/update system settings. */ |
Billy Lau | 24b9c83 | 2015-07-20 17:34:09 +0100 | [diff] [blame] | 1225 | public static final String OPSTR_WRITE_SETTINGS |
| 1226 | = "android:write_settings"; |
Svetoslav | f3f02ac | 2015-09-08 14:36:35 -0700 | [diff] [blame] | 1227 | /** @hide Get device accounts. */ |
Peter Visontay | 5a2a1ef | 2017-12-18 20:34:03 +0000 | [diff] [blame] | 1228 | @SystemApi @TestApi |
Svetoslav | f3f02ac | 2015-09-08 14:36:35 -0700 | [diff] [blame] | 1229 | public static final String OPSTR_GET_ACCOUNTS |
| 1230 | = "android:get_accounts"; |
Chad Brubaker | 0c1651f | 2017-03-30 16:29:10 -0700 | [diff] [blame] | 1231 | public static final String OPSTR_READ_PHONE_NUMBERS |
| 1232 | = "android:read_phone_numbers"; |
Winson Chung | f4ac063 | 2017-03-17 12:34:12 -0700 | [diff] [blame] | 1233 | /** Access to picture-in-picture. */ |
| 1234 | public static final String OPSTR_PICTURE_IN_PICTURE |
| 1235 | = "android:picture_in_picture"; |
Chad Brubaker | 97b383f | 2017-02-02 15:04:35 -0800 | [diff] [blame] | 1236 | /** @hide */ |
Peter Visontay | 5a2a1ef | 2017-12-18 20:34:03 +0000 | [diff] [blame] | 1237 | @SystemApi @TestApi |
Chad Brubaker | 97b383f | 2017-02-02 15:04:35 -0800 | [diff] [blame] | 1238 | public static final String OPSTR_INSTANT_APP_START_FOREGROUND |
| 1239 | = "android:instant_app_start_foreground"; |
Eugene Susla | cae3d3e | 2017-01-31 11:08:11 -0800 | [diff] [blame] | 1240 | /** Answer incoming phone calls */ |
| 1241 | public static final String OPSTR_ANSWER_PHONE_CALLS |
| 1242 | = "android:answer_phone_calls"; |
Tyler Gunn | 79bc1ec | 2018-01-22 15:17:54 -0800 | [diff] [blame] | 1243 | /** |
| 1244 | * Accept call handover |
| 1245 | * @hide |
| 1246 | */ |
| 1247 | @SystemApi @TestApi |
| 1248 | public static final String OPSTR_ACCEPT_HANDOVER |
| 1249 | = "android:accept_handover"; |
Peter Visontay | 5a2a1ef | 2017-12-18 20:34:03 +0000 | [diff] [blame] | 1250 | /** @hide */ |
| 1251 | @SystemApi @TestApi |
| 1252 | public static final String OPSTR_GPS = "android:gps"; |
| 1253 | /** @hide */ |
| 1254 | @SystemApi @TestApi |
| 1255 | public static final String OPSTR_VIBRATE = "android:vibrate"; |
| 1256 | /** @hide */ |
| 1257 | @SystemApi @TestApi |
| 1258 | public static final String OPSTR_WIFI_SCAN = "android:wifi_scan"; |
| 1259 | /** @hide */ |
| 1260 | @SystemApi @TestApi |
| 1261 | public static final String OPSTR_POST_NOTIFICATION = "android:post_notification"; |
| 1262 | /** @hide */ |
| 1263 | @SystemApi @TestApi |
| 1264 | public static final String OPSTR_NEIGHBORING_CELLS = "android:neighboring_cells"; |
| 1265 | /** @hide */ |
| 1266 | @SystemApi @TestApi |
| 1267 | public static final String OPSTR_WRITE_SMS = "android:write_sms"; |
| 1268 | /** @hide */ |
| 1269 | @SystemApi @TestApi |
| 1270 | public static final String OPSTR_RECEIVE_EMERGENCY_BROADCAST = |
| 1271 | "android:receive_emergency_broadcast"; |
| 1272 | /** @hide */ |
| 1273 | @SystemApi @TestApi |
| 1274 | public static final String OPSTR_READ_ICC_SMS = "android:read_icc_sms"; |
| 1275 | /** @hide */ |
| 1276 | @SystemApi @TestApi |
| 1277 | public static final String OPSTR_WRITE_ICC_SMS = "android:write_icc_sms"; |
| 1278 | /** @hide */ |
| 1279 | @SystemApi @TestApi |
| 1280 | public static final String OPSTR_ACCESS_NOTIFICATIONS = "android:access_notifications"; |
| 1281 | /** @hide */ |
| 1282 | @SystemApi @TestApi |
| 1283 | public static final String OPSTR_PLAY_AUDIO = "android:play_audio"; |
| 1284 | /** @hide */ |
| 1285 | @SystemApi @TestApi |
| 1286 | public static final String OPSTR_READ_CLIPBOARD = "android:read_clipboard"; |
| 1287 | /** @hide */ |
| 1288 | @SystemApi @TestApi |
| 1289 | public static final String OPSTR_WRITE_CLIPBOARD = "android:write_clipboard"; |
| 1290 | /** @hide */ |
| 1291 | @SystemApi @TestApi |
| 1292 | public static final String OPSTR_TAKE_MEDIA_BUTTONS = "android:take_media_buttons"; |
| 1293 | /** @hide */ |
| 1294 | @SystemApi @TestApi |
| 1295 | public static final String OPSTR_TAKE_AUDIO_FOCUS = "android:take_audio_focus"; |
| 1296 | /** @hide */ |
| 1297 | @SystemApi @TestApi |
| 1298 | public static final String OPSTR_AUDIO_MASTER_VOLUME = "android:audio_master_volume"; |
| 1299 | /** @hide */ |
| 1300 | @SystemApi @TestApi |
| 1301 | public static final String OPSTR_AUDIO_VOICE_VOLUME = "android:audio_voice_volume"; |
| 1302 | /** @hide */ |
| 1303 | @SystemApi @TestApi |
| 1304 | public static final String OPSTR_AUDIO_RING_VOLUME = "android:audio_ring_volume"; |
| 1305 | /** @hide */ |
| 1306 | @SystemApi @TestApi |
| 1307 | public static final String OPSTR_AUDIO_MEDIA_VOLUME = "android:audio_media_volume"; |
| 1308 | /** @hide */ |
| 1309 | @SystemApi @TestApi |
| 1310 | public static final String OPSTR_AUDIO_ALARM_VOLUME = "android:audio_alarm_volume"; |
| 1311 | /** @hide */ |
| 1312 | @SystemApi @TestApi |
| 1313 | public static final String OPSTR_AUDIO_NOTIFICATION_VOLUME = |
| 1314 | "android:audio_notification_volume"; |
| 1315 | /** @hide */ |
| 1316 | @SystemApi @TestApi |
| 1317 | public static final String OPSTR_AUDIO_BLUETOOTH_VOLUME = "android:audio_bluetooth_volume"; |
| 1318 | /** @hide */ |
| 1319 | @SystemApi @TestApi |
| 1320 | public static final String OPSTR_WAKE_LOCK = "android:wake_lock"; |
| 1321 | /** @hide */ |
| 1322 | @SystemApi @TestApi |
| 1323 | public static final String OPSTR_MUTE_MICROPHONE = "android:mute_microphone"; |
| 1324 | /** @hide */ |
| 1325 | @SystemApi @TestApi |
| 1326 | public static final String OPSTR_TOAST_WINDOW = "android:toast_window"; |
| 1327 | /** @hide */ |
| 1328 | @SystemApi @TestApi |
| 1329 | public static final String OPSTR_PROJECT_MEDIA = "android:project_media"; |
| 1330 | /** @hide */ |
| 1331 | @SystemApi @TestApi |
| 1332 | public static final String OPSTR_WRITE_WALLPAPER = "android:write_wallpaper"; |
| 1333 | /** @hide */ |
| 1334 | @SystemApi @TestApi |
| 1335 | public static final String OPSTR_ASSIST_STRUCTURE = "android:assist_structure"; |
| 1336 | /** @hide */ |
| 1337 | @SystemApi @TestApi |
| 1338 | public static final String OPSTR_ASSIST_SCREENSHOT = "android:assist_screenshot"; |
| 1339 | /** @hide */ |
| 1340 | @SystemApi @TestApi |
| 1341 | public static final String OPSTR_TURN_SCREEN_ON = "android:turn_screen_on"; |
| 1342 | /** @hide */ |
| 1343 | @SystemApi @TestApi |
| 1344 | public static final String OPSTR_RUN_IN_BACKGROUND = "android:run_in_background"; |
| 1345 | /** @hide */ |
| 1346 | @SystemApi @TestApi |
| 1347 | public static final String OPSTR_AUDIO_ACCESSIBILITY_VOLUME = |
| 1348 | "android:audio_accessibility_volume"; |
| 1349 | /** @hide */ |
| 1350 | @SystemApi @TestApi |
| 1351 | public static final String OPSTR_REQUEST_INSTALL_PACKAGES = "android:request_install_packages"; |
| 1352 | /** @hide */ |
| 1353 | @SystemApi @TestApi |
| 1354 | public static final String OPSTR_RUN_ANY_IN_BACKGROUND = "android:run_any_in_background"; |
| 1355 | /** @hide */ |
| 1356 | @SystemApi @TestApi |
Peter Visontay | a382a8e | 2018-03-16 16:06:57 +0000 | [diff] [blame] | 1357 | public static final String OPSTR_CHANGE_WIFI_STATE = "android:change_wifi_state"; |
Peter Visontay | 5a2a1ef | 2017-12-18 20:34:03 +0000 | [diff] [blame] | 1358 | /** @hide */ |
| 1359 | @SystemApi @TestApi |
Peter Visontay | a382a8e | 2018-03-16 16:06:57 +0000 | [diff] [blame] | 1360 | public static final String OPSTR_REQUEST_DELETE_PACKAGES = "android:request_delete_packages"; |
Peter Visontay | 5a2a1ef | 2017-12-18 20:34:03 +0000 | [diff] [blame] | 1361 | /** @hide */ |
| 1362 | @SystemApi @TestApi |
Peter Visontay | a382a8e | 2018-03-16 16:06:57 +0000 | [diff] [blame] | 1363 | public static final String OPSTR_BIND_ACCESSIBILITY_SERVICE = |
| 1364 | "android:bind_accessibility_service"; |
Nathan Harold | 1bb42067 | 2018-03-14 17:08:53 -0700 | [diff] [blame] | 1365 | /** @hide */ |
| 1366 | @SystemApi @TestApi |
| 1367 | public static final String OPSTR_MANAGE_IPSEC_TUNNELS = "android:manage_ipsec_tunnels"; |
Dianne Hackborn | e9d9b4b | 2018-03-28 13:51:46 -0700 | [diff] [blame] | 1368 | /** @hide */ |
| 1369 | @SystemApi @TestApi |
| 1370 | public static final String OPSTR_START_FOREGROUND = "android:start_foreground"; |
Dianne Hackborn | e04f13d | 2018-05-02 12:51:52 -0700 | [diff] [blame] | 1371 | /** @hide */ |
| 1372 | public static final String OPSTR_BLUETOOTH_SCAN = "android:bluetooth_scan"; |
Peter Visontay | 5a2a1ef | 2017-12-18 20:34:03 +0000 | [diff] [blame] | 1373 | |
Kevin Chyn | b3c05aa | 2018-09-21 16:50:32 -0700 | [diff] [blame] | 1374 | /** @hide Use the BiometricPrompt/BiometricManager APIs. */ |
| 1375 | public static final String OPSTR_USE_BIOMETRIC = "android:use_biometric"; |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 1376 | |
Zimuzo | 6cbf9cc | 2018-10-05 12:05:58 +0100 | [diff] [blame] | 1377 | /** @hide Recognize physical activity. */ |
| 1378 | public static final String OPSTR_ACTIVITY_RECOGNITION = "android:activity_recognition"; |
| 1379 | |
Hongming Jin | 228cd01 | 2018-11-09 14:47:50 -0800 | [diff] [blame] | 1380 | /** @hide Financial app read sms. */ |
| 1381 | public static final String OPSTR_SMS_FINANCIAL_TRANSACTIONS = |
| 1382 | "android:sms_financial_transactions"; |
| 1383 | |
Jeff Sharkey | d2a1f0d | 2018-11-19 10:32:52 -0700 | [diff] [blame] | 1384 | /** @hide Read media of audio type. */ |
Jeff Sharkey | 5997cc8 | 2019-08-21 11:14:40 -0600 | [diff] [blame] | 1385 | @SystemApi @TestApi |
Jeff Sharkey | d2a1f0d | 2018-11-19 10:32:52 -0700 | [diff] [blame] | 1386 | public static final String OPSTR_READ_MEDIA_AUDIO = "android:read_media_audio"; |
| 1387 | /** @hide Write media of audio type. */ |
Jeff Sharkey | 5997cc8 | 2019-08-21 11:14:40 -0600 | [diff] [blame] | 1388 | @SystemApi @TestApi |
Jeff Sharkey | d2a1f0d | 2018-11-19 10:32:52 -0700 | [diff] [blame] | 1389 | public static final String OPSTR_WRITE_MEDIA_AUDIO = "android:write_media_audio"; |
| 1390 | /** @hide Read media of video type. */ |
Jeff Sharkey | 5997cc8 | 2019-08-21 11:14:40 -0600 | [diff] [blame] | 1391 | @SystemApi @TestApi |
Jeff Sharkey | d2a1f0d | 2018-11-19 10:32:52 -0700 | [diff] [blame] | 1392 | public static final String OPSTR_READ_MEDIA_VIDEO = "android:read_media_video"; |
| 1393 | /** @hide Write media of video type. */ |
Jeff Sharkey | 5997cc8 | 2019-08-21 11:14:40 -0600 | [diff] [blame] | 1394 | @SystemApi @TestApi |
Jeff Sharkey | d2a1f0d | 2018-11-19 10:32:52 -0700 | [diff] [blame] | 1395 | public static final String OPSTR_WRITE_MEDIA_VIDEO = "android:write_media_video"; |
| 1396 | /** @hide Read media of image type. */ |
Jeff Sharkey | 5997cc8 | 2019-08-21 11:14:40 -0600 | [diff] [blame] | 1397 | @SystemApi @TestApi |
Jeff Sharkey | d2a1f0d | 2018-11-19 10:32:52 -0700 | [diff] [blame] | 1398 | public static final String OPSTR_READ_MEDIA_IMAGES = "android:read_media_images"; |
| 1399 | /** @hide Write media of image type. */ |
Jeff Sharkey | 5997cc8 | 2019-08-21 11:14:40 -0600 | [diff] [blame] | 1400 | @SystemApi @TestApi |
Jeff Sharkey | d2a1f0d | 2018-11-19 10:32:52 -0700 | [diff] [blame] | 1401 | public static final String OPSTR_WRITE_MEDIA_IMAGES = "android:write_media_images"; |
Jeff Sharkey | e82cbb1 | 2018-12-06 15:53:11 -0700 | [diff] [blame] | 1402 | /** @hide Has a legacy (non-isolated) view of storage. */ |
Jeff Sharkey | 5997cc8 | 2019-08-21 11:14:40 -0600 | [diff] [blame] | 1403 | @SystemApi @TestApi |
Jeff Sharkey | e82cbb1 | 2018-12-06 15:53:11 -0700 | [diff] [blame] | 1404 | public static final String OPSTR_LEGACY_STORAGE = "android:legacy_storage"; |
Philip P. Moltmann | 89b044f | 2019-09-13 15:12:34 -0700 | [diff] [blame] | 1405 | /** @hide Read location metadata from media */ |
| 1406 | public static final String OPSTR_ACCESS_MEDIA_LOCATION = "android:access_media_location"; |
Jeff Sharkey | 5997cc8 | 2019-08-21 11:14:40 -0600 | [diff] [blame] | 1407 | |
Jackal Guo | 8dc791e | 2019-01-14 10:26:42 +0800 | [diff] [blame] | 1408 | /** @hide Interact with accessibility. */ |
Joel Galenson | ff4fe20 | 2019-02-06 14:43:58 -0800 | [diff] [blame] | 1409 | @SystemApi |
Jackal Guo | 8dc791e | 2019-01-14 10:26:42 +0800 | [diff] [blame] | 1410 | public static final String OPSTR_ACCESS_ACCESSIBILITY = "android:access_accessibility"; |
Michael Groover | 656ef91 | 2019-04-09 17:09:57 -0700 | [diff] [blame] | 1411 | /** @hide Read device identifiers */ |
| 1412 | public static final String OPSTR_READ_DEVICE_IDENTIFIERS = "android:read_device_identifiers"; |
Patrick Baumann | 6c1c809 | 2019-06-27 14:55:44 -0700 | [diff] [blame] | 1413 | /** @hide Query all packages on device */ |
| 1414 | 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] | 1415 | /** @hide Access all external storage */ |
| 1416 | @SystemApi |
shafik | 2a20790 | 2020-04-08 17:49:47 +0100 | [diff] [blame] | 1417 | @TestApi |
Philip P. Moltmann | b43dfe3 | 2019-11-11 14:14:49 -0800 | [diff] [blame] | 1418 | public static final String OPSTR_MANAGE_EXTERNAL_STORAGE = |
| 1419 | "android:manage_external_storage"; |
Jeff Sharkey | d2a1f0d | 2018-11-19 10:32:52 -0700 | [diff] [blame] | 1420 | |
Eugene Susla | 5fc2d76 | 2020-03-04 13:53:10 -0800 | [diff] [blame] | 1421 | /** @hide Auto-revoke app permissions if app is unused for an extended period */ |
| 1422 | @SystemApi |
| 1423 | public static final String OPSTR_AUTO_REVOKE_PERMISSIONS_IF_UNUSED = |
| 1424 | "android:auto_revoke_permissions_if_unused"; |
| 1425 | |
Eugene Susla | 1d7a791 | 2020-03-14 09:16:29 -0700 | [diff] [blame] | 1426 | /** @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] | 1427 | @SystemApi |
Eugene Susla | 1d7a791 | 2020-03-14 09:16:29 -0700 | [diff] [blame] | 1428 | public static final String OPSTR_AUTO_REVOKE_MANAGED_BY_INSTALLER = |
| 1429 | "android:auto_revoke_managed_by_installer"; |
| 1430 | |
kholoud mohamed | 20ded1f | 2019-12-03 17:52:38 +0000 | [diff] [blame] | 1431 | /** @hide Communicate cross-profile within the same profile group. */ |
| 1432 | @SystemApi |
| 1433 | public static final String OPSTR_INTERACT_ACROSS_PROFILES = "android:interact_across_profiles"; |
Benedict Wong | 3eb9520 | 2019-11-05 12:50:59 -0800 | [diff] [blame] | 1434 | /** @hide Start Platform VPN without user intervention */ |
| 1435 | public static final String OPSTR_ACTIVATE_PLATFORM_VPN = "android:activate_platform_vpn"; |
Todd Kennedy | b0948d4 | 2020-01-27 15:20:07 -0800 | [diff] [blame] | 1436 | /** @hide */ |
| 1437 | @SystemApi |
| 1438 | public static final String OPSTR_LOADER_USAGE_STATS = "android:loader_usage_stats"; |
kholoud mohamed | 20ded1f | 2019-12-03 17:52:38 +0000 | [diff] [blame] | 1439 | |
Nikita Ioffe | ac095e5 | 2020-06-08 22:24:06 +0100 | [diff] [blame] | 1440 | /** |
| 1441 | * AppOp granted to apps that we are started via {@code am instrument -e --no-isolated-storage} |
| 1442 | * |
| 1443 | * @hide |
| 1444 | */ |
| 1445 | public static final String OPSTR_NO_ISOLATED_STORAGE = "android:no_isolated_storage"; |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 1446 | |
| 1447 | /** {@link #sAppOpsToNote} not initialized yet for this op */ |
| 1448 | private static final byte SHOULD_COLLECT_NOTE_OP_NOT_INITIALIZED = 0; |
| 1449 | /** Should not collect noting of this app-op in {@link #sAppOpsToNote} */ |
| 1450 | private static final byte SHOULD_NOT_COLLECT_NOTE_OP = 1; |
| 1451 | /** Should collect noting of this app-op in {@link #sAppOpsToNote} */ |
| 1452 | private static final byte SHOULD_COLLECT_NOTE_OP = 2; |
| 1453 | |
| 1454 | @Retention(RetentionPolicy.SOURCE) |
| 1455 | @IntDef(flag = true, prefix = { "SHOULD_" }, value = { |
| 1456 | SHOULD_COLLECT_NOTE_OP_NOT_INITIALIZED, |
| 1457 | SHOULD_NOT_COLLECT_NOTE_OP, |
| 1458 | SHOULD_COLLECT_NOTE_OP |
| 1459 | }) |
| 1460 | private @interface ShouldCollectNoteOp {} |
| 1461 | |
Svet Ganov | da0acdf | 2017-02-15 10:28:51 -0800 | [diff] [blame] | 1462 | private static final int[] RUNTIME_AND_APPOP_PERMISSIONS_OPS = { |
| 1463 | // RUNTIME PERMISSIONS |
Svetoslav Ganov | eaca4c5 | 2016-05-05 18:08:00 -0700 | [diff] [blame] | 1464 | // Contacts |
| 1465 | OP_READ_CONTACTS, |
| 1466 | OP_WRITE_CONTACTS, |
| 1467 | OP_GET_ACCOUNTS, |
| 1468 | // Calendar |
| 1469 | OP_READ_CALENDAR, |
| 1470 | OP_WRITE_CALENDAR, |
| 1471 | // SMS |
| 1472 | OP_SEND_SMS, |
| 1473 | OP_RECEIVE_SMS, |
| 1474 | OP_READ_SMS, |
| 1475 | OP_RECEIVE_WAP_PUSH, |
| 1476 | OP_RECEIVE_MMS, |
| 1477 | OP_READ_CELL_BROADCASTS, |
| 1478 | // Storage |
| 1479 | OP_READ_EXTERNAL_STORAGE, |
| 1480 | OP_WRITE_EXTERNAL_STORAGE, |
Philip P. Moltmann | 89b044f | 2019-09-13 15:12:34 -0700 | [diff] [blame] | 1481 | OP_ACCESS_MEDIA_LOCATION, |
Svetoslav Ganov | eaca4c5 | 2016-05-05 18:08:00 -0700 | [diff] [blame] | 1482 | // Location |
| 1483 | OP_COARSE_LOCATION, |
| 1484 | OP_FINE_LOCATION, |
| 1485 | // Phone |
| 1486 | OP_READ_PHONE_STATE, |
Chad Brubaker | 0c1651f | 2017-03-30 16:29:10 -0700 | [diff] [blame] | 1487 | OP_READ_PHONE_NUMBERS, |
Svetoslav Ganov | eaca4c5 | 2016-05-05 18:08:00 -0700 | [diff] [blame] | 1488 | OP_CALL_PHONE, |
| 1489 | OP_READ_CALL_LOG, |
| 1490 | OP_WRITE_CALL_LOG, |
| 1491 | OP_ADD_VOICEMAIL, |
| 1492 | OP_USE_SIP, |
| 1493 | OP_PROCESS_OUTGOING_CALLS, |
Eugene Susla | cae3d3e | 2017-01-31 11:08:11 -0800 | [diff] [blame] | 1494 | OP_ANSWER_PHONE_CALLS, |
Tyler Gunn | 79bc1ec | 2018-01-22 15:17:54 -0800 | [diff] [blame] | 1495 | OP_ACCEPT_HANDOVER, |
Svetoslav Ganov | eaca4c5 | 2016-05-05 18:08:00 -0700 | [diff] [blame] | 1496 | // Microphone |
| 1497 | OP_RECORD_AUDIO, |
| 1498 | // Camera |
| 1499 | OP_CAMERA, |
| 1500 | // Body sensors |
Svet Ganov | da0acdf | 2017-02-15 10:28:51 -0800 | [diff] [blame] | 1501 | OP_BODY_SENSORS, |
Zimuzo | 6cbf9cc | 2018-10-05 12:05:58 +0100 | [diff] [blame] | 1502 | // Activity recognition |
| 1503 | OP_ACTIVITY_RECOGNITION, |
Jeff Sharkey | d2a1f0d | 2018-11-19 10:32:52 -0700 | [diff] [blame] | 1504 | // Aural |
| 1505 | OP_READ_MEDIA_AUDIO, |
| 1506 | OP_WRITE_MEDIA_AUDIO, |
| 1507 | // Visual |
| 1508 | OP_READ_MEDIA_VIDEO, |
| 1509 | OP_WRITE_MEDIA_VIDEO, |
| 1510 | OP_READ_MEDIA_IMAGES, |
| 1511 | OP_WRITE_MEDIA_IMAGES, |
Svet Ganov | da0acdf | 2017-02-15 10:28:51 -0800 | [diff] [blame] | 1512 | |
| 1513 | // APPOP PERMISSIONS |
| 1514 | OP_ACCESS_NOTIFICATIONS, |
| 1515 | OP_SYSTEM_ALERT_WINDOW, |
| 1516 | OP_WRITE_SETTINGS, |
| 1517 | OP_REQUEST_INSTALL_PACKAGES, |
Dianne Hackborn | e9d9b4b | 2018-03-28 13:51:46 -0700 | [diff] [blame] | 1518 | OP_START_FOREGROUND, |
Hongming Jin | 228cd01 | 2018-11-09 14:47:50 -0800 | [diff] [blame] | 1519 | OP_SMS_FINANCIAL_TRANSACTIONS, |
Philip P. Moltmann | 4b38fbe | 2019-09-13 21:33:07 -0700 | [diff] [blame] | 1520 | OP_MANAGE_IPSEC_TUNNELS, |
shafik | 77cabc7 | 2020-01-03 16:22:50 +0000 | [diff] [blame] | 1521 | OP_INSTANT_APP_START_FOREGROUND, |
| 1522 | OP_MANAGE_EXTERNAL_STORAGE, |
Todd Kennedy | b0948d4 | 2020-01-27 15:20:07 -0800 | [diff] [blame] | 1523 | OP_INTERACT_ACROSS_PROFILES, |
| 1524 | OP_LOADER_USAGE_STATS, |
Svetoslav Ganov | eaca4c5 | 2016-05-05 18:08:00 -0700 | [diff] [blame] | 1525 | }; |
| 1526 | |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 1527 | /** |
| 1528 | * This maps each operation to the operation that serves as the |
| 1529 | * switch to determine whether it is allowed. Generally this is |
| 1530 | * a 1:1 mapping, but for some things (like location) that have |
| 1531 | * multiple low-level operations being tracked that should be |
David Christie | 0b83745 | 2013-07-29 16:02:13 -0700 | [diff] [blame] | 1532 | * 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] | 1533 | * make them all controlled by the same single operation. |
| 1534 | */ |
| 1535 | private static int[] sOpToSwitch = new int[] { |
Dianne Hackborn | c216a26 | 2018-04-26 13:46:22 -0700 | [diff] [blame] | 1536 | OP_COARSE_LOCATION, // COARSE_LOCATION |
| 1537 | OP_COARSE_LOCATION, // FINE_LOCATION |
| 1538 | OP_COARSE_LOCATION, // GPS |
| 1539 | OP_VIBRATE, // VIBRATE |
| 1540 | OP_READ_CONTACTS, // READ_CONTACTS |
| 1541 | OP_WRITE_CONTACTS, // WRITE_CONTACTS |
| 1542 | OP_READ_CALL_LOG, // READ_CALL_LOG |
| 1543 | OP_WRITE_CALL_LOG, // WRITE_CALL_LOG |
| 1544 | OP_READ_CALENDAR, // READ_CALENDAR |
| 1545 | OP_WRITE_CALENDAR, // WRITE_CALENDAR |
| 1546 | OP_COARSE_LOCATION, // WIFI_SCAN |
| 1547 | OP_POST_NOTIFICATION, // POST_NOTIFICATION |
| 1548 | OP_COARSE_LOCATION, // NEIGHBORING_CELLS |
| 1549 | OP_CALL_PHONE, // CALL_PHONE |
| 1550 | OP_READ_SMS, // READ_SMS |
| 1551 | OP_WRITE_SMS, // WRITE_SMS |
| 1552 | OP_RECEIVE_SMS, // RECEIVE_SMS |
| 1553 | OP_RECEIVE_SMS, // RECEIVE_EMERGECY_SMS |
| 1554 | OP_RECEIVE_MMS, // RECEIVE_MMS |
| 1555 | OP_RECEIVE_WAP_PUSH, // RECEIVE_WAP_PUSH |
| 1556 | OP_SEND_SMS, // SEND_SMS |
| 1557 | OP_READ_SMS, // READ_ICC_SMS |
| 1558 | OP_WRITE_SMS, // WRITE_ICC_SMS |
| 1559 | OP_WRITE_SETTINGS, // WRITE_SETTINGS |
| 1560 | OP_SYSTEM_ALERT_WINDOW, // SYSTEM_ALERT_WINDOW |
| 1561 | OP_ACCESS_NOTIFICATIONS, // ACCESS_NOTIFICATIONS |
| 1562 | OP_CAMERA, // CAMERA |
| 1563 | OP_RECORD_AUDIO, // RECORD_AUDIO |
| 1564 | OP_PLAY_AUDIO, // PLAY_AUDIO |
| 1565 | OP_READ_CLIPBOARD, // READ_CLIPBOARD |
| 1566 | OP_WRITE_CLIPBOARD, // WRITE_CLIPBOARD |
| 1567 | OP_TAKE_MEDIA_BUTTONS, // TAKE_MEDIA_BUTTONS |
| 1568 | OP_TAKE_AUDIO_FOCUS, // TAKE_AUDIO_FOCUS |
| 1569 | OP_AUDIO_MASTER_VOLUME, // AUDIO_MASTER_VOLUME |
| 1570 | OP_AUDIO_VOICE_VOLUME, // AUDIO_VOICE_VOLUME |
| 1571 | OP_AUDIO_RING_VOLUME, // AUDIO_RING_VOLUME |
| 1572 | OP_AUDIO_MEDIA_VOLUME, // AUDIO_MEDIA_VOLUME |
| 1573 | OP_AUDIO_ALARM_VOLUME, // AUDIO_ALARM_VOLUME |
| 1574 | OP_AUDIO_NOTIFICATION_VOLUME, // AUDIO_NOTIFICATION_VOLUME |
| 1575 | OP_AUDIO_BLUETOOTH_VOLUME, // AUDIO_BLUETOOTH_VOLUME |
| 1576 | OP_WAKE_LOCK, // WAKE_LOCK |
| 1577 | OP_COARSE_LOCATION, // MONITOR_LOCATION |
| 1578 | OP_COARSE_LOCATION, // MONITOR_HIGH_POWER_LOCATION |
| 1579 | OP_GET_USAGE_STATS, // GET_USAGE_STATS |
| 1580 | OP_MUTE_MICROPHONE, // MUTE_MICROPHONE |
| 1581 | OP_TOAST_WINDOW, // TOAST_WINDOW |
| 1582 | OP_PROJECT_MEDIA, // PROJECT_MEDIA |
| 1583 | OP_ACTIVATE_VPN, // ACTIVATE_VPN |
| 1584 | OP_WRITE_WALLPAPER, // WRITE_WALLPAPER |
| 1585 | OP_ASSIST_STRUCTURE, // ASSIST_STRUCTURE |
| 1586 | OP_ASSIST_SCREENSHOT, // ASSIST_SCREENSHOT |
| 1587 | OP_READ_PHONE_STATE, // READ_PHONE_STATE |
| 1588 | OP_ADD_VOICEMAIL, // ADD_VOICEMAIL |
| 1589 | OP_USE_SIP, // USE_SIP |
| 1590 | OP_PROCESS_OUTGOING_CALLS, // PROCESS_OUTGOING_CALLS |
| 1591 | OP_USE_FINGERPRINT, // USE_FINGERPRINT |
| 1592 | OP_BODY_SENSORS, // BODY_SENSORS |
| 1593 | OP_READ_CELL_BROADCASTS, // READ_CELL_BROADCASTS |
| 1594 | OP_MOCK_LOCATION, // MOCK_LOCATION |
| 1595 | OP_READ_EXTERNAL_STORAGE, // READ_EXTERNAL_STORAGE |
| 1596 | OP_WRITE_EXTERNAL_STORAGE, // WRITE_EXTERNAL_STORAGE |
| 1597 | OP_TURN_SCREEN_ON, // TURN_SCREEN_ON |
| 1598 | OP_GET_ACCOUNTS, // GET_ACCOUNTS |
| 1599 | OP_RUN_IN_BACKGROUND, // RUN_IN_BACKGROUND |
| 1600 | OP_AUDIO_ACCESSIBILITY_VOLUME, // AUDIO_ACCESSIBILITY_VOLUME |
| 1601 | OP_READ_PHONE_NUMBERS, // READ_PHONE_NUMBERS |
| 1602 | OP_REQUEST_INSTALL_PACKAGES, // REQUEST_INSTALL_PACKAGES |
| 1603 | OP_PICTURE_IN_PICTURE, // ENTER_PICTURE_IN_PICTURE_ON_HIDE |
| 1604 | OP_INSTANT_APP_START_FOREGROUND, // INSTANT_APP_START_FOREGROUND |
| 1605 | OP_ANSWER_PHONE_CALLS, // ANSWER_PHONE_CALLS |
| 1606 | OP_RUN_ANY_IN_BACKGROUND, // OP_RUN_ANY_IN_BACKGROUND |
| 1607 | OP_CHANGE_WIFI_STATE, // OP_CHANGE_WIFI_STATE |
| 1608 | OP_REQUEST_DELETE_PACKAGES, // OP_REQUEST_DELETE_PACKAGES |
| 1609 | OP_BIND_ACCESSIBILITY_SERVICE, // OP_BIND_ACCESSIBILITY_SERVICE |
| 1610 | OP_ACCEPT_HANDOVER, // ACCEPT_HANDOVER |
| 1611 | OP_MANAGE_IPSEC_TUNNELS, // MANAGE_IPSEC_HANDOVERS |
| 1612 | OP_START_FOREGROUND, // START_FOREGROUND |
Dianne Hackborn | e04f13d | 2018-05-02 12:51:52 -0700 | [diff] [blame] | 1613 | OP_COARSE_LOCATION, // BLUETOOTH_SCAN |
Kevin Chyn | b3c05aa | 2018-09-21 16:50:32 -0700 | [diff] [blame] | 1614 | OP_USE_BIOMETRIC, // BIOMETRIC |
Zimuzo | 6cbf9cc | 2018-10-05 12:05:58 +0100 | [diff] [blame] | 1615 | OP_ACTIVITY_RECOGNITION, // ACTIVITY_RECOGNITION |
Hongming Jin | 228cd01 | 2018-11-09 14:47:50 -0800 | [diff] [blame] | 1616 | OP_SMS_FINANCIAL_TRANSACTIONS, // SMS_FINANCIAL_TRANSACTIONS |
Jeff Sharkey | d2a1f0d | 2018-11-19 10:32:52 -0700 | [diff] [blame] | 1617 | OP_READ_MEDIA_AUDIO, // READ_MEDIA_AUDIO |
| 1618 | OP_WRITE_MEDIA_AUDIO, // WRITE_MEDIA_AUDIO |
| 1619 | OP_READ_MEDIA_VIDEO, // READ_MEDIA_VIDEO |
| 1620 | OP_WRITE_MEDIA_VIDEO, // WRITE_MEDIA_VIDEO |
| 1621 | OP_READ_MEDIA_IMAGES, // READ_MEDIA_IMAGES |
| 1622 | OP_WRITE_MEDIA_IMAGES, // WRITE_MEDIA_IMAGES |
Jeff Sharkey | e82cbb1 | 2018-12-06 15:53:11 -0700 | [diff] [blame] | 1623 | OP_LEGACY_STORAGE, // LEGACY_STORAGE |
Jackal Guo | 8dc791e | 2019-01-14 10:26:42 +0800 | [diff] [blame] | 1624 | OP_ACCESS_ACCESSIBILITY, // ACCESS_ACCESSIBILITY |
Michael Groover | 656ef91 | 2019-04-09 17:09:57 -0700 | [diff] [blame] | 1625 | OP_READ_DEVICE_IDENTIFIERS, // READ_DEVICE_IDENTIFIERS |
Philip P. Moltmann | 89b044f | 2019-09-13 15:12:34 -0700 | [diff] [blame] | 1626 | OP_ACCESS_MEDIA_LOCATION, // ACCESS_MEDIA_LOCATION |
Patrick Baumann | 6c1c809 | 2019-06-27 14:55:44 -0700 | [diff] [blame] | 1627 | OP_QUERY_ALL_PACKAGES, // QUERY_ALL_PACKAGES |
Philip P. Moltmann | b43dfe3 | 2019-11-11 14:14:49 -0800 | [diff] [blame] | 1628 | OP_MANAGE_EXTERNAL_STORAGE, // MANAGE_EXTERNAL_STORAGE |
kholoud mohamed | 20ded1f | 2019-12-03 17:52:38 +0000 | [diff] [blame] | 1629 | OP_INTERACT_ACROSS_PROFILES, //INTERACT_ACROSS_PROFILES |
Benedict Wong | 3eb9520 | 2019-11-05 12:50:59 -0800 | [diff] [blame] | 1630 | OP_ACTIVATE_PLATFORM_VPN, // ACTIVATE_PLATFORM_VPN |
Todd Kennedy | b0948d4 | 2020-01-27 15:20:07 -0800 | [diff] [blame] | 1631 | OP_LOADER_USAGE_STATS, // LOADER_USAGE_STATS |
Ricardo Correa | acdc827 | 2020-03-24 11:02:54 -0700 | [diff] [blame] | 1632 | OP_DEPRECATED_1, // deprecated |
Eugene Susla | 5fc2d76 | 2020-03-04 13:53:10 -0800 | [diff] [blame] | 1633 | OP_AUTO_REVOKE_PERMISSIONS_IF_UNUSED, //AUTO_REVOKE_PERMISSIONS_IF_UNUSED |
Eugene Susla | 922cd08 | 2020-03-11 12:38:17 -0700 | [diff] [blame] | 1634 | OP_AUTO_REVOKE_MANAGED_BY_INSTALLER, //OP_AUTO_REVOKE_MANAGED_BY_INSTALLER |
Nikita Ioffe | ac095e5 | 2020-06-08 22:24:06 +0100 | [diff] [blame] | 1635 | OP_NO_ISOLATED_STORAGE, // NO_ISOLATED_STORAGE |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 1636 | }; |
| 1637 | |
| 1638 | /** |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 1639 | * This maps each operation to the public string constant for it. |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 1640 | */ |
Peter Visontay | 5a2a1ef | 2017-12-18 20:34:03 +0000 | [diff] [blame] | 1641 | private static String[] sOpToString = new String[]{ |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 1642 | OPSTR_COARSE_LOCATION, |
| 1643 | OPSTR_FINE_LOCATION, |
Peter Visontay | 5a2a1ef | 2017-12-18 20:34:03 +0000 | [diff] [blame] | 1644 | OPSTR_GPS, |
| 1645 | OPSTR_VIBRATE, |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 1646 | OPSTR_READ_CONTACTS, |
| 1647 | OPSTR_WRITE_CONTACTS, |
| 1648 | OPSTR_READ_CALL_LOG, |
| 1649 | OPSTR_WRITE_CALL_LOG, |
| 1650 | OPSTR_READ_CALENDAR, |
| 1651 | OPSTR_WRITE_CALENDAR, |
Peter Visontay | 5a2a1ef | 2017-12-18 20:34:03 +0000 | [diff] [blame] | 1652 | OPSTR_WIFI_SCAN, |
| 1653 | OPSTR_POST_NOTIFICATION, |
| 1654 | OPSTR_NEIGHBORING_CELLS, |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 1655 | OPSTR_CALL_PHONE, |
| 1656 | OPSTR_READ_SMS, |
Peter Visontay | 5a2a1ef | 2017-12-18 20:34:03 +0000 | [diff] [blame] | 1657 | OPSTR_WRITE_SMS, |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 1658 | OPSTR_RECEIVE_SMS, |
Peter Visontay | 5a2a1ef | 2017-12-18 20:34:03 +0000 | [diff] [blame] | 1659 | OPSTR_RECEIVE_EMERGENCY_BROADCAST, |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 1660 | OPSTR_RECEIVE_MMS, |
| 1661 | OPSTR_RECEIVE_WAP_PUSH, |
| 1662 | OPSTR_SEND_SMS, |
Peter Visontay | 5a2a1ef | 2017-12-18 20:34:03 +0000 | [diff] [blame] | 1663 | OPSTR_READ_ICC_SMS, |
| 1664 | OPSTR_WRITE_ICC_SMS, |
Billy Lau | 24b9c83 | 2015-07-20 17:34:09 +0100 | [diff] [blame] | 1665 | OPSTR_WRITE_SETTINGS, |
| 1666 | OPSTR_SYSTEM_ALERT_WINDOW, |
Peter Visontay | 5a2a1ef | 2017-12-18 20:34:03 +0000 | [diff] [blame] | 1667 | OPSTR_ACCESS_NOTIFICATIONS, |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 1668 | OPSTR_CAMERA, |
| 1669 | OPSTR_RECORD_AUDIO, |
Peter Visontay | 5a2a1ef | 2017-12-18 20:34:03 +0000 | [diff] [blame] | 1670 | OPSTR_PLAY_AUDIO, |
| 1671 | OPSTR_READ_CLIPBOARD, |
| 1672 | OPSTR_WRITE_CLIPBOARD, |
| 1673 | OPSTR_TAKE_MEDIA_BUTTONS, |
| 1674 | OPSTR_TAKE_AUDIO_FOCUS, |
| 1675 | OPSTR_AUDIO_MASTER_VOLUME, |
| 1676 | OPSTR_AUDIO_VOICE_VOLUME, |
| 1677 | OPSTR_AUDIO_RING_VOLUME, |
| 1678 | OPSTR_AUDIO_MEDIA_VOLUME, |
| 1679 | OPSTR_AUDIO_ALARM_VOLUME, |
| 1680 | OPSTR_AUDIO_NOTIFICATION_VOLUME, |
| 1681 | OPSTR_AUDIO_BLUETOOTH_VOLUME, |
| 1682 | OPSTR_WAKE_LOCK, |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 1683 | OPSTR_MONITOR_LOCATION, |
| 1684 | OPSTR_MONITOR_HIGH_POWER_LOCATION, |
Dianne Hackborn | 5064e7c | 2014-09-02 10:57:16 -0700 | [diff] [blame] | 1685 | OPSTR_GET_USAGE_STATS, |
Peter Visontay | 5a2a1ef | 2017-12-18 20:34:03 +0000 | [diff] [blame] | 1686 | OPSTR_MUTE_MICROPHONE, |
| 1687 | OPSTR_TOAST_WINDOW, |
| 1688 | OPSTR_PROJECT_MEDIA, |
Jeff Davidson | 0554260 | 2014-08-11 14:07:27 -0700 | [diff] [blame] | 1689 | OPSTR_ACTIVATE_VPN, |
Peter Visontay | 5a2a1ef | 2017-12-18 20:34:03 +0000 | [diff] [blame] | 1690 | OPSTR_WRITE_WALLPAPER, |
| 1691 | OPSTR_ASSIST_STRUCTURE, |
| 1692 | OPSTR_ASSIST_SCREENSHOT, |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 1693 | OPSTR_READ_PHONE_STATE, |
| 1694 | OPSTR_ADD_VOICEMAIL, |
| 1695 | OPSTR_USE_SIP, |
Svet Ganov | 824ad6e | 2016-09-22 19:36:53 -0700 | [diff] [blame] | 1696 | OPSTR_PROCESS_OUTGOING_CALLS, |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 1697 | OPSTR_USE_FINGERPRINT, |
Svet Ganov | ede4316 | 2015-05-02 17:42:44 -0700 | [diff] [blame] | 1698 | OPSTR_BODY_SENSORS, |
Svet Ganov | f7e9cf4 | 2015-05-13 10:40:31 -0700 | [diff] [blame] | 1699 | OPSTR_READ_CELL_BROADCASTS, |
Svet Ganov | 921c7df | 2015-06-29 21:51:41 -0700 | [diff] [blame] | 1700 | OPSTR_MOCK_LOCATION, |
| 1701 | OPSTR_READ_EXTERNAL_STORAGE, |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 1702 | OPSTR_WRITE_EXTERNAL_STORAGE, |
Peter Visontay | 5a2a1ef | 2017-12-18 20:34:03 +0000 | [diff] [blame] | 1703 | OPSTR_TURN_SCREEN_ON, |
Dianne Hackborn | bef28fe | 2015-10-29 17:57:11 -0700 | [diff] [blame] | 1704 | OPSTR_GET_ACCOUNTS, |
Peter Visontay | 5a2a1ef | 2017-12-18 20:34:03 +0000 | [diff] [blame] | 1705 | OPSTR_RUN_IN_BACKGROUND, |
| 1706 | OPSTR_AUDIO_ACCESSIBILITY_VOLUME, |
Chad Brubaker | 0c1651f | 2017-03-30 16:29:10 -0700 | [diff] [blame] | 1707 | OPSTR_READ_PHONE_NUMBERS, |
Peter Visontay | 5a2a1ef | 2017-12-18 20:34:03 +0000 | [diff] [blame] | 1708 | OPSTR_REQUEST_INSTALL_PACKAGES, |
Winson Chung | f4ac063 | 2017-03-17 12:34:12 -0700 | [diff] [blame] | 1709 | OPSTR_PICTURE_IN_PICTURE, |
Chad Brubaker | 97b383f | 2017-02-02 15:04:35 -0800 | [diff] [blame] | 1710 | OPSTR_INSTANT_APP_START_FOREGROUND, |
Eugene Susla | cae3d3e | 2017-01-31 11:08:11 -0800 | [diff] [blame] | 1711 | OPSTR_ANSWER_PHONE_CALLS, |
Peter Visontay | 5a2a1ef | 2017-12-18 20:34:03 +0000 | [diff] [blame] | 1712 | OPSTR_RUN_ANY_IN_BACKGROUND, |
| 1713 | OPSTR_CHANGE_WIFI_STATE, |
| 1714 | OPSTR_REQUEST_DELETE_PACKAGES, |
| 1715 | OPSTR_BIND_ACCESSIBILITY_SERVICE, |
Tyler Gunn | 79bc1ec | 2018-01-22 15:17:54 -0800 | [diff] [blame] | 1716 | OPSTR_ACCEPT_HANDOVER, |
Nathan Harold | 1bb42067 | 2018-03-14 17:08:53 -0700 | [diff] [blame] | 1717 | OPSTR_MANAGE_IPSEC_TUNNELS, |
Dianne Hackborn | e9d9b4b | 2018-03-28 13:51:46 -0700 | [diff] [blame] | 1718 | OPSTR_START_FOREGROUND, |
Dianne Hackborn | e04f13d | 2018-05-02 12:51:52 -0700 | [diff] [blame] | 1719 | OPSTR_BLUETOOTH_SCAN, |
Kevin Chyn | b3c05aa | 2018-09-21 16:50:32 -0700 | [diff] [blame] | 1720 | OPSTR_USE_BIOMETRIC, |
Zimuzo | 6cbf9cc | 2018-10-05 12:05:58 +0100 | [diff] [blame] | 1721 | OPSTR_ACTIVITY_RECOGNITION, |
Hongming Jin | 228cd01 | 2018-11-09 14:47:50 -0800 | [diff] [blame] | 1722 | OPSTR_SMS_FINANCIAL_TRANSACTIONS, |
Jeff Sharkey | d2a1f0d | 2018-11-19 10:32:52 -0700 | [diff] [blame] | 1723 | OPSTR_READ_MEDIA_AUDIO, |
| 1724 | OPSTR_WRITE_MEDIA_AUDIO, |
| 1725 | OPSTR_READ_MEDIA_VIDEO, |
| 1726 | OPSTR_WRITE_MEDIA_VIDEO, |
| 1727 | OPSTR_READ_MEDIA_IMAGES, |
| 1728 | OPSTR_WRITE_MEDIA_IMAGES, |
Jeff Sharkey | e82cbb1 | 2018-12-06 15:53:11 -0700 | [diff] [blame] | 1729 | OPSTR_LEGACY_STORAGE, |
Jackal Guo | 8dc791e | 2019-01-14 10:26:42 +0800 | [diff] [blame] | 1730 | OPSTR_ACCESS_ACCESSIBILITY, |
Michael Groover | 656ef91 | 2019-04-09 17:09:57 -0700 | [diff] [blame] | 1731 | OPSTR_READ_DEVICE_IDENTIFIERS, |
Philip P. Moltmann | 89b044f | 2019-09-13 15:12:34 -0700 | [diff] [blame] | 1732 | OPSTR_ACCESS_MEDIA_LOCATION, |
Patrick Baumann | 6c1c809 | 2019-06-27 14:55:44 -0700 | [diff] [blame] | 1733 | OPSTR_QUERY_ALL_PACKAGES, |
Philip P. Moltmann | b43dfe3 | 2019-11-11 14:14:49 -0800 | [diff] [blame] | 1734 | OPSTR_MANAGE_EXTERNAL_STORAGE, |
kholoud mohamed | 20ded1f | 2019-12-03 17:52:38 +0000 | [diff] [blame] | 1735 | OPSTR_INTERACT_ACROSS_PROFILES, |
Benedict Wong | 3eb9520 | 2019-11-05 12:50:59 -0800 | [diff] [blame] | 1736 | OPSTR_ACTIVATE_PLATFORM_VPN, |
Todd Kennedy | b0948d4 | 2020-01-27 15:20:07 -0800 | [diff] [blame] | 1737 | OPSTR_LOADER_USAGE_STATS, |
Ricardo Correa | acdc827 | 2020-03-24 11:02:54 -0700 | [diff] [blame] | 1738 | "", // deprecated |
Eugene Susla | 5fc2d76 | 2020-03-04 13:53:10 -0800 | [diff] [blame] | 1739 | OPSTR_AUTO_REVOKE_PERMISSIONS_IF_UNUSED, |
Eugene Susla | 1d7a791 | 2020-03-14 09:16:29 -0700 | [diff] [blame] | 1740 | OPSTR_AUTO_REVOKE_MANAGED_BY_INSTALLER, |
Nikita Ioffe | ac095e5 | 2020-06-08 22:24:06 +0100 | [diff] [blame] | 1741 | OPSTR_NO_ISOLATED_STORAGE, |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 1742 | }; |
| 1743 | |
| 1744 | /** |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 1745 | * This provides a simple name for each operation to be used |
| 1746 | * in debug output. |
| 1747 | */ |
Dianne Hackborn | 5e45ee6 | 2013-01-24 19:13:44 -0800 | [diff] [blame] | 1748 | private static String[] sOpNames = new String[] { |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 1749 | "COARSE_LOCATION", |
| 1750 | "FINE_LOCATION", |
| 1751 | "GPS", |
| 1752 | "VIBRATE", |
| 1753 | "READ_CONTACTS", |
| 1754 | "WRITE_CONTACTS", |
| 1755 | "READ_CALL_LOG", |
| 1756 | "WRITE_CALL_LOG", |
| 1757 | "READ_CALENDAR", |
| 1758 | "WRITE_CALENDAR", |
| 1759 | "WIFI_SCAN", |
| 1760 | "POST_NOTIFICATION", |
| 1761 | "NEIGHBORING_CELLS", |
| 1762 | "CALL_PHONE", |
Dianne Hackborn | f51f612 | 2013-02-04 18:23:34 -0800 | [diff] [blame] | 1763 | "READ_SMS", |
| 1764 | "WRITE_SMS", |
| 1765 | "RECEIVE_SMS", |
| 1766 | "RECEIVE_EMERGECY_SMS", |
| 1767 | "RECEIVE_MMS", |
| 1768 | "RECEIVE_WAP_PUSH", |
| 1769 | "SEND_SMS", |
| 1770 | "READ_ICC_SMS", |
| 1771 | "WRITE_ICC_SMS", |
Dianne Hackborn | 961321f | 2013-02-05 17:22:41 -0800 | [diff] [blame] | 1772 | "WRITE_SETTINGS", |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 1773 | "SYSTEM_ALERT_WINDOW", |
Daniel Sandler | fde19b1 | 2013-01-17 00:21:05 -0500 | [diff] [blame] | 1774 | "ACCESS_NOTIFICATIONS", |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 1775 | "CAMERA", |
| 1776 | "RECORD_AUDIO", |
| 1777 | "PLAY_AUDIO", |
Dianne Hackborn | efcc1a2 | 2013-02-25 18:02:35 -0800 | [diff] [blame] | 1778 | "READ_CLIPBOARD", |
| 1779 | "WRITE_CLIPBOARD", |
Dianne Hackborn | ba50b97c | 2013-04-30 15:04:46 -0700 | [diff] [blame] | 1780 | "TAKE_MEDIA_BUTTONS", |
| 1781 | "TAKE_AUDIO_FOCUS", |
| 1782 | "AUDIO_MASTER_VOLUME", |
| 1783 | "AUDIO_VOICE_VOLUME", |
| 1784 | "AUDIO_RING_VOLUME", |
| 1785 | "AUDIO_MEDIA_VOLUME", |
| 1786 | "AUDIO_ALARM_VOLUME", |
| 1787 | "AUDIO_NOTIFICATION_VOLUME", |
| 1788 | "AUDIO_BLUETOOTH_VOLUME", |
Dianne Hackborn | 713df15 | 2013-05-17 11:27:57 -0700 | [diff] [blame] | 1789 | "WAKE_LOCK", |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 1790 | "MONITOR_LOCATION", |
David Christie | 0b83745 | 2013-07-29 16:02:13 -0700 | [diff] [blame] | 1791 | "MONITOR_HIGH_POWER_LOCATION", |
Emily Bernier | 22c921a | 2014-05-28 11:01:32 -0400 | [diff] [blame] | 1792 | "GET_USAGE_STATS", |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 1793 | "MUTE_MICROPHONE", |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 1794 | "TOAST_WINDOW", |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 1795 | "PROJECT_MEDIA", |
Jeff Davidson | 0554260 | 2014-08-11 14:07:27 -0700 | [diff] [blame] | 1796 | "ACTIVATE_VPN", |
Benjamin Franz | f3ece36 | 2015-02-11 10:51:10 +0000 | [diff] [blame] | 1797 | "WRITE_WALLPAPER", |
Dianne Hackborn | d59a5d5 | 2015-04-04 14:52:14 -0700 | [diff] [blame] | 1798 | "ASSIST_STRUCTURE", |
Svet Ganov | 16a1689 | 2015-04-16 10:32:04 -0700 | [diff] [blame] | 1799 | "ASSIST_SCREENSHOT", |
Eugene Susla | e4ee2c2 | 2018-11-05 12:23:30 -0800 | [diff] [blame] | 1800 | "READ_PHONE_STATE", |
Svetoslav | 5335b67 | 2015-04-29 12:00:51 -0700 | [diff] [blame] | 1801 | "ADD_VOICEMAIL", |
Svetoslav | c656e6f | 2015-04-29 14:08:16 -0700 | [diff] [blame] | 1802 | "USE_SIP", |
Svetoslav | 4af76a5 | 2015-04-29 15:29:46 -0700 | [diff] [blame] | 1803 | "PROCESS_OUTGOING_CALLS", |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 1804 | "USE_FINGERPRINT", |
Svet Ganov | ede4316 | 2015-05-02 17:42:44 -0700 | [diff] [blame] | 1805 | "BODY_SENSORS", |
Svet Ganov | f7e9cf4 | 2015-05-13 10:40:31 -0700 | [diff] [blame] | 1806 | "READ_CELL_BROADCASTS", |
Svet Ganov | 921c7df | 2015-06-29 21:51:41 -0700 | [diff] [blame] | 1807 | "MOCK_LOCATION", |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 1808 | "READ_EXTERNAL_STORAGE", |
| 1809 | "WRITE_EXTERNAL_STORAGE", |
| 1810 | "TURN_ON_SCREEN", |
Svetoslav | f3f02ac | 2015-09-08 14:36:35 -0700 | [diff] [blame] | 1811 | "GET_ACCOUNTS", |
Dianne Hackborn | bef28fe | 2015-10-29 17:57:11 -0700 | [diff] [blame] | 1812 | "RUN_IN_BACKGROUND", |
Jean-Michel Trivi | 3f0945a | 2016-11-11 10:05:18 -0800 | [diff] [blame] | 1813 | "AUDIO_ACCESSIBILITY_VOLUME", |
Chad Brubaker | 0c1651f | 2017-03-30 16:29:10 -0700 | [diff] [blame] | 1814 | "READ_PHONE_NUMBERS", |
Suprabh Shukla | 2f34b1a | 2016-12-16 14:47:25 -0800 | [diff] [blame] | 1815 | "REQUEST_INSTALL_PACKAGES", |
Winson Chung | f4ac063 | 2017-03-17 12:34:12 -0700 | [diff] [blame] | 1816 | "PICTURE_IN_PICTURE", |
Chad Brubaker | 97b383f | 2017-02-02 15:04:35 -0800 | [diff] [blame] | 1817 | "INSTANT_APP_START_FOREGROUND", |
Eugene Susla | cae3d3e | 2017-01-31 11:08:11 -0800 | [diff] [blame] | 1818 | "ANSWER_PHONE_CALLS", |
Suprabh Shukla | 3ac1daa | 2017-07-14 12:15:27 -0700 | [diff] [blame] | 1819 | "RUN_ANY_IN_BACKGROUND", |
Peter Visontay | 1246d9e | 2017-10-17 17:02:45 +0100 | [diff] [blame] | 1820 | "CHANGE_WIFI_STATE", |
Peter Visontay | f2e3836 | 2017-11-27 15:27:16 +0000 | [diff] [blame] | 1821 | "REQUEST_DELETE_PACKAGES", |
Peter Visontay | 1195083 | 2017-11-14 19:34:59 +0000 | [diff] [blame] | 1822 | "BIND_ACCESSIBILITY_SERVICE", |
Tyler Gunn | 79bc1ec | 2018-01-22 15:17:54 -0800 | [diff] [blame] | 1823 | "ACCEPT_HANDOVER", |
Nathan Harold | 1bb42067 | 2018-03-14 17:08:53 -0700 | [diff] [blame] | 1824 | "MANAGE_IPSEC_TUNNELS", |
Dianne Hackborn | e9d9b4b | 2018-03-28 13:51:46 -0700 | [diff] [blame] | 1825 | "START_FOREGROUND", |
Dianne Hackborn | e04f13d | 2018-05-02 12:51:52 -0700 | [diff] [blame] | 1826 | "BLUETOOTH_SCAN", |
Kevin Chyn | b3c05aa | 2018-09-21 16:50:32 -0700 | [diff] [blame] | 1827 | "USE_BIOMETRIC", |
Zimuzo | 6cbf9cc | 2018-10-05 12:05:58 +0100 | [diff] [blame] | 1828 | "ACTIVITY_RECOGNITION", |
Hongming Jin | 228cd01 | 2018-11-09 14:47:50 -0800 | [diff] [blame] | 1829 | "SMS_FINANCIAL_TRANSACTIONS", |
Jeff Sharkey | d2a1f0d | 2018-11-19 10:32:52 -0700 | [diff] [blame] | 1830 | "READ_MEDIA_AUDIO", |
| 1831 | "WRITE_MEDIA_AUDIO", |
| 1832 | "READ_MEDIA_VIDEO", |
| 1833 | "WRITE_MEDIA_VIDEO", |
| 1834 | "READ_MEDIA_IMAGES", |
| 1835 | "WRITE_MEDIA_IMAGES", |
Jeff Sharkey | e82cbb1 | 2018-12-06 15:53:11 -0700 | [diff] [blame] | 1836 | "LEGACY_STORAGE", |
Jackal Guo | 8dc791e | 2019-01-14 10:26:42 +0800 | [diff] [blame] | 1837 | "ACCESS_ACCESSIBILITY", |
Michael Groover | 656ef91 | 2019-04-09 17:09:57 -0700 | [diff] [blame] | 1838 | "READ_DEVICE_IDENTIFIERS", |
Philip P. Moltmann | 89b044f | 2019-09-13 15:12:34 -0700 | [diff] [blame] | 1839 | "ACCESS_MEDIA_LOCATION", |
Patrick Baumann | 6c1c809 | 2019-06-27 14:55:44 -0700 | [diff] [blame] | 1840 | "QUERY_ALL_PACKAGES", |
kholoud mohamed | 20ded1f | 2019-12-03 17:52:38 +0000 | [diff] [blame] | 1841 | "MANAGE_EXTERNAL_STORAGE", |
Benedict Wong | 3eb9520 | 2019-11-05 12:50:59 -0800 | [diff] [blame] | 1842 | "INTERACT_ACROSS_PROFILES", |
| 1843 | "ACTIVATE_PLATFORM_VPN", |
Todd Kennedy | b0948d4 | 2020-01-27 15:20:07 -0800 | [diff] [blame] | 1844 | "LOADER_USAGE_STATS", |
Ricardo Correa | acdc827 | 2020-03-24 11:02:54 -0700 | [diff] [blame] | 1845 | "deprecated", |
Eugene Susla | 5fc2d76 | 2020-03-04 13:53:10 -0800 | [diff] [blame] | 1846 | "AUTO_REVOKE_PERMISSIONS_IF_UNUSED", |
Eugene Susla | 1d7a791 | 2020-03-14 09:16:29 -0700 | [diff] [blame] | 1847 | "AUTO_REVOKE_MANAGED_BY_INSTALLER", |
Nikita Ioffe | ac095e5 | 2020-06-08 22:24:06 +0100 | [diff] [blame] | 1848 | "NO_ISOLATED_STORAGE", |
Dianne Hackborn | 5e45ee6 | 2013-01-24 19:13:44 -0800 | [diff] [blame] | 1849 | }; |
| 1850 | |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 1851 | /** |
| 1852 | * This optionally maps a permission to an operation. If there |
| 1853 | * is no permission associated with an operation, it is null. |
| 1854 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 1855 | @UnsupportedAppUsage |
Dianne Hackborn | 5e45ee6 | 2013-01-24 19:13:44 -0800 | [diff] [blame] | 1856 | private static String[] sOpPerms = new String[] { |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 1857 | android.Manifest.permission.ACCESS_COARSE_LOCATION, |
| 1858 | android.Manifest.permission.ACCESS_FINE_LOCATION, |
| 1859 | null, |
| 1860 | android.Manifest.permission.VIBRATE, |
| 1861 | android.Manifest.permission.READ_CONTACTS, |
| 1862 | android.Manifest.permission.WRITE_CONTACTS, |
| 1863 | android.Manifest.permission.READ_CALL_LOG, |
| 1864 | android.Manifest.permission.WRITE_CALL_LOG, |
| 1865 | android.Manifest.permission.READ_CALENDAR, |
| 1866 | android.Manifest.permission.WRITE_CALENDAR, |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 1867 | android.Manifest.permission.ACCESS_WIFI_STATE, |
Robert Craig | f97616c | 2013-10-07 12:32:02 -0400 | [diff] [blame] | 1868 | null, // no permission required for notifications |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 1869 | null, // neighboring cells shares the coarse location perm |
| 1870 | android.Manifest.permission.CALL_PHONE, |
Dianne Hackborn | f51f612 | 2013-02-04 18:23:34 -0800 | [diff] [blame] | 1871 | android.Manifest.permission.READ_SMS, |
Svetoslav | 6c58957 | 2015-04-16 16:19:24 -0700 | [diff] [blame] | 1872 | null, // no permission required for writing sms |
Dianne Hackborn | f51f612 | 2013-02-04 18:23:34 -0800 | [diff] [blame] | 1873 | android.Manifest.permission.RECEIVE_SMS, |
| 1874 | android.Manifest.permission.RECEIVE_EMERGENCY_BROADCAST, |
| 1875 | android.Manifest.permission.RECEIVE_MMS, |
| 1876 | android.Manifest.permission.RECEIVE_WAP_PUSH, |
| 1877 | android.Manifest.permission.SEND_SMS, |
| 1878 | android.Manifest.permission.READ_SMS, |
Svetoslav | 6c58957 | 2015-04-16 16:19:24 -0700 | [diff] [blame] | 1879 | null, // no permission required for writing icc sms |
Dianne Hackborn | 961321f | 2013-02-05 17:22:41 -0800 | [diff] [blame] | 1880 | android.Manifest.permission.WRITE_SETTINGS, |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 1881 | android.Manifest.permission.SYSTEM_ALERT_WINDOW, |
Daniel Sandler | fde19b1 | 2013-01-17 00:21:05 -0500 | [diff] [blame] | 1882 | android.Manifest.permission.ACCESS_NOTIFICATIONS, |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 1883 | android.Manifest.permission.CAMERA, |
| 1884 | android.Manifest.permission.RECORD_AUDIO, |
| 1885 | null, // no permission for playing audio |
Dianne Hackborn | efcc1a2 | 2013-02-25 18:02:35 -0800 | [diff] [blame] | 1886 | null, // no permission for reading clipboard |
| 1887 | null, // no permission for writing clipboard |
Dianne Hackborn | ba50b97c | 2013-04-30 15:04:46 -0700 | [diff] [blame] | 1888 | null, // no permission for taking media buttons |
| 1889 | null, // no permission for taking audio focus |
| 1890 | null, // no permission for changing master volume |
| 1891 | null, // no permission for changing voice volume |
| 1892 | null, // no permission for changing ring volume |
| 1893 | null, // no permission for changing media volume |
| 1894 | null, // no permission for changing alarm volume |
| 1895 | null, // no permission for changing notification volume |
| 1896 | null, // no permission for changing bluetooth volume |
Dianne Hackborn | 713df15 | 2013-05-17 11:27:57 -0700 | [diff] [blame] | 1897 | android.Manifest.permission.WAKE_LOCK, |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 1898 | null, // no permission for generic location monitoring |
David Christie | 0b83745 | 2013-07-29 16:02:13 -0700 | [diff] [blame] | 1899 | null, // no permission for high power location monitoring |
Dianne Hackborn | e22b3b1 | 2014-05-07 18:06:44 -0700 | [diff] [blame] | 1900 | android.Manifest.permission.PACKAGE_USAGE_STATS, |
Emily Bernier | 22c921a | 2014-05-28 11:01:32 -0400 | [diff] [blame] | 1901 | null, // no permission for muting/unmuting microphone |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 1902 | null, // no permission for displaying toasts |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 1903 | null, // no permission for projecting media |
Jeff Davidson | 0554260 | 2014-08-11 14:07:27 -0700 | [diff] [blame] | 1904 | null, // no permission for activating vpn |
Benjamin Franz | f3ece36 | 2015-02-11 10:51:10 +0000 | [diff] [blame] | 1905 | null, // no permission for supporting wallpaper |
Dianne Hackborn | d59a5d5 | 2015-04-04 14:52:14 -0700 | [diff] [blame] | 1906 | null, // no permission for receiving assist structure |
| 1907 | null, // no permission for receiving assist screenshot |
Svet Ganov | c330009 | 2015-04-17 09:07:22 -0700 | [diff] [blame] | 1908 | Manifest.permission.READ_PHONE_STATE, |
Svetoslav | 5335b67 | 2015-04-29 12:00:51 -0700 | [diff] [blame] | 1909 | Manifest.permission.ADD_VOICEMAIL, |
Svetoslav | c656e6f | 2015-04-29 14:08:16 -0700 | [diff] [blame] | 1910 | Manifest.permission.USE_SIP, |
Svetoslav | 4af76a5 | 2015-04-29 15:29:46 -0700 | [diff] [blame] | 1911 | Manifest.permission.PROCESS_OUTGOING_CALLS, |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 1912 | Manifest.permission.USE_FINGERPRINT, |
Svet Ganov | ede4316 | 2015-05-02 17:42:44 -0700 | [diff] [blame] | 1913 | Manifest.permission.BODY_SENSORS, |
Svet Ganov | f7e9cf4 | 2015-05-13 10:40:31 -0700 | [diff] [blame] | 1914 | Manifest.permission.READ_CELL_BROADCASTS, |
Svet Ganov | 921c7df | 2015-06-29 21:51:41 -0700 | [diff] [blame] | 1915 | null, |
| 1916 | Manifest.permission.READ_EXTERNAL_STORAGE, |
| 1917 | Manifest.permission.WRITE_EXTERNAL_STORAGE, |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 1918 | null, // no permission for turning the screen on |
Dianne Hackborn | bef28fe | 2015-10-29 17:57:11 -0700 | [diff] [blame] | 1919 | Manifest.permission.GET_ACCOUNTS, |
| 1920 | null, // no permission for running in background |
Jean-Michel Trivi | 3f0945a | 2016-11-11 10:05:18 -0800 | [diff] [blame] | 1921 | null, // no permission for changing accessibility volume |
Chad Brubaker | 0c1651f | 2017-03-30 16:29:10 -0700 | [diff] [blame] | 1922 | Manifest.permission.READ_PHONE_NUMBERS, |
Suprabh Shukla | 2f34b1a | 2016-12-16 14:47:25 -0800 | [diff] [blame] | 1923 | Manifest.permission.REQUEST_INSTALL_PACKAGES, |
Winson Chung | 59fda9e | 2017-01-20 16:14:51 -0800 | [diff] [blame] | 1924 | null, // no permission for entering picture-in-picture on hide |
Chad Brubaker | 97b383f | 2017-02-02 15:04:35 -0800 | [diff] [blame] | 1925 | Manifest.permission.INSTANT_APP_FOREGROUND_SERVICE, |
Eugene Susla | cae3d3e | 2017-01-31 11:08:11 -0800 | [diff] [blame] | 1926 | Manifest.permission.ANSWER_PHONE_CALLS, |
Suprabh Shukla | 3ac1daa | 2017-07-14 12:15:27 -0700 | [diff] [blame] | 1927 | null, // no permission for OP_RUN_ANY_IN_BACKGROUND |
Peter Visontay | 1246d9e | 2017-10-17 17:02:45 +0100 | [diff] [blame] | 1928 | Manifest.permission.CHANGE_WIFI_STATE, |
Peter Visontay | f2e3836 | 2017-11-27 15:27:16 +0000 | [diff] [blame] | 1929 | Manifest.permission.REQUEST_DELETE_PACKAGES, |
Peter Visontay | 1195083 | 2017-11-14 19:34:59 +0000 | [diff] [blame] | 1930 | Manifest.permission.BIND_ACCESSIBILITY_SERVICE, |
Tyler Gunn | 79bc1ec | 2018-01-22 15:17:54 -0800 | [diff] [blame] | 1931 | Manifest.permission.ACCEPT_HANDOVER, |
Philip P. Moltmann | 4b38fbe | 2019-09-13 21:33:07 -0700 | [diff] [blame] | 1932 | Manifest.permission.MANAGE_IPSEC_TUNNELS, |
Dianne Hackborn | e9d9b4b | 2018-03-28 13:51:46 -0700 | [diff] [blame] | 1933 | Manifest.permission.FOREGROUND_SERVICE, |
Dianne Hackborn | e04f13d | 2018-05-02 12:51:52 -0700 | [diff] [blame] | 1934 | null, // no permission for OP_BLUETOOTH_SCAN |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 1935 | Manifest.permission.USE_BIOMETRIC, |
Zimuzo | 6cbf9cc | 2018-10-05 12:05:58 +0100 | [diff] [blame] | 1936 | Manifest.permission.ACTIVITY_RECOGNITION, |
Hongming Jin | 228cd01 | 2018-11-09 14:47:50 -0800 | [diff] [blame] | 1937 | Manifest.permission.SMS_FINANCIAL_TRANSACTIONS, |
Philip P. Moltmann | 129a0b0 | 2019-03-27 12:24:45 -0700 | [diff] [blame] | 1938 | null, |
Jeff Sharkey | 9787a945 | 2018-11-18 17:53:02 -0700 | [diff] [blame] | 1939 | null, // no permission for OP_WRITE_MEDIA_AUDIO |
Philip P. Moltmann | 129a0b0 | 2019-03-27 12:24:45 -0700 | [diff] [blame] | 1940 | null, |
Jeff Sharkey | 9787a945 | 2018-11-18 17:53:02 -0700 | [diff] [blame] | 1941 | null, // no permission for OP_WRITE_MEDIA_VIDEO |
Philip P. Moltmann | 129a0b0 | 2019-03-27 12:24:45 -0700 | [diff] [blame] | 1942 | null, |
Jeff Sharkey | 9787a945 | 2018-11-18 17:53:02 -0700 | [diff] [blame] | 1943 | null, // no permission for OP_WRITE_MEDIA_IMAGES |
Jeff Sharkey | e82cbb1 | 2018-12-06 15:53:11 -0700 | [diff] [blame] | 1944 | null, // no permission for OP_LEGACY_STORAGE |
Jackal Guo | 8dc791e | 2019-01-14 10:26:42 +0800 | [diff] [blame] | 1945 | null, // no permission for OP_ACCESS_ACCESSIBILITY |
Michael Groover | 656ef91 | 2019-04-09 17:09:57 -0700 | [diff] [blame] | 1946 | null, // no direct permission for OP_READ_DEVICE_IDENTIFIERS |
Philip P. Moltmann | 89b044f | 2019-09-13 15:12:34 -0700 | [diff] [blame] | 1947 | Manifest.permission.ACCESS_MEDIA_LOCATION, |
Patrick Baumann | 6c1c809 | 2019-06-27 14:55:44 -0700 | [diff] [blame] | 1948 | null, // no permission for OP_QUERY_ALL_PACKAGES |
shafik | 77cabc7 | 2020-01-03 16:22:50 +0000 | [diff] [blame] | 1949 | Manifest.permission.MANAGE_EXTERNAL_STORAGE, |
kholoud mohamed | 20ded1f | 2019-12-03 17:52:38 +0000 | [diff] [blame] | 1950 | android.Manifest.permission.INTERACT_ACROSS_PROFILES, |
Benedict Wong | 3eb9520 | 2019-11-05 12:50:59 -0800 | [diff] [blame] | 1951 | null, // no permission for OP_ACTIVATE_PLATFORM_VPN |
Todd Kennedy | b0948d4 | 2020-01-27 15:20:07 -0800 | [diff] [blame] | 1952 | android.Manifest.permission.LOADER_USAGE_STATS, |
Ricardo Correa | acdc827 | 2020-03-24 11:02:54 -0700 | [diff] [blame] | 1953 | null, // deprecated operation |
Eugene Susla | 5fc2d76 | 2020-03-04 13:53:10 -0800 | [diff] [blame] | 1954 | null, // no permission for OP_AUTO_REVOKE_PERMISSIONS_IF_UNUSED |
Eugene Susla | 922cd08 | 2020-03-11 12:38:17 -0700 | [diff] [blame] | 1955 | null, // no permission for OP_AUTO_REVOKE_MANAGED_BY_INSTALLER |
Nikita Ioffe | ac095e5 | 2020-06-08 22:24:06 +0100 | [diff] [blame] | 1956 | null, // no permission for OP_NO_ISOLATED_STORAGE |
Dianne Hackborn | 5e45ee6 | 2013-01-24 19:13:44 -0800 | [diff] [blame] | 1957 | }; |
| 1958 | |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 1959 | /** |
Jason Monk | 6206299 | 2014-05-06 09:55:28 -0400 | [diff] [blame] | 1960 | * Specifies whether an Op should be restricted by a user restriction. |
| 1961 | * Each Op should be filled with a restriction string from UserManager or |
| 1962 | * null to specify it is not affected by any user restriction. |
| 1963 | */ |
| 1964 | private static String[] sOpRestrictions = new String[] { |
Julia Reynolds | 9854d57 | 2014-07-02 14:46:02 -0400 | [diff] [blame] | 1965 | UserManager.DISALLOW_SHARE_LOCATION, //COARSE_LOCATION |
| 1966 | UserManager.DISALLOW_SHARE_LOCATION, //FINE_LOCATION |
| 1967 | UserManager.DISALLOW_SHARE_LOCATION, //GPS |
Jason Monk | 6206299 | 2014-05-06 09:55:28 -0400 | [diff] [blame] | 1968 | null, //VIBRATE |
| 1969 | null, //READ_CONTACTS |
| 1970 | null, //WRITE_CONTACTS |
Yorke Lee | 15f83c6 | 2014-08-13 14:14:29 -0700 | [diff] [blame] | 1971 | UserManager.DISALLOW_OUTGOING_CALLS, //READ_CALL_LOG |
| 1972 | UserManager.DISALLOW_OUTGOING_CALLS, //WRITE_CALL_LOG |
Jason Monk | 6206299 | 2014-05-06 09:55:28 -0400 | [diff] [blame] | 1973 | null, //READ_CALENDAR |
| 1974 | null, //WRITE_CALENDAR |
Julia Reynolds | 9854d57 | 2014-07-02 14:46:02 -0400 | [diff] [blame] | 1975 | UserManager.DISALLOW_SHARE_LOCATION, //WIFI_SCAN |
Jason Monk | 6206299 | 2014-05-06 09:55:28 -0400 | [diff] [blame] | 1976 | null, //POST_NOTIFICATION |
| 1977 | null, //NEIGHBORING_CELLS |
| 1978 | null, //CALL_PHONE |
Amith Yamasani | 41c1ded | 2014-08-05 11:15:05 -0700 | [diff] [blame] | 1979 | UserManager.DISALLOW_SMS, //READ_SMS |
| 1980 | UserManager.DISALLOW_SMS, //WRITE_SMS |
| 1981 | UserManager.DISALLOW_SMS, //RECEIVE_SMS |
| 1982 | null, //RECEIVE_EMERGENCY_SMS |
| 1983 | UserManager.DISALLOW_SMS, //RECEIVE_MMS |
Jason Monk | 6206299 | 2014-05-06 09:55:28 -0400 | [diff] [blame] | 1984 | null, //RECEIVE_WAP_PUSH |
Amith Yamasani | 41c1ded | 2014-08-05 11:15:05 -0700 | [diff] [blame] | 1985 | UserManager.DISALLOW_SMS, //SEND_SMS |
| 1986 | UserManager.DISALLOW_SMS, //READ_ICC_SMS |
| 1987 | UserManager.DISALLOW_SMS, //WRITE_ICC_SMS |
Jason Monk | 6206299 | 2014-05-06 09:55:28 -0400 | [diff] [blame] | 1988 | null, //WRITE_SETTINGS |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 1989 | UserManager.DISALLOW_CREATE_WINDOWS, //SYSTEM_ALERT_WINDOW |
Jason Monk | 6206299 | 2014-05-06 09:55:28 -0400 | [diff] [blame] | 1990 | null, //ACCESS_NOTIFICATIONS |
Makoto Onuki | 759a763 | 2015-10-28 16:43:10 -0700 | [diff] [blame] | 1991 | UserManager.DISALLOW_CAMERA, //CAMERA |
Fyodor Kupolov | b501330 | 2015-04-17 17:59:14 -0700 | [diff] [blame] | 1992 | UserManager.DISALLOW_RECORD_AUDIO, //RECORD_AUDIO |
Jason Monk | 6206299 | 2014-05-06 09:55:28 -0400 | [diff] [blame] | 1993 | null, //PLAY_AUDIO |
| 1994 | null, //READ_CLIPBOARD |
| 1995 | null, //WRITE_CLIPBOARD |
| 1996 | null, //TAKE_MEDIA_BUTTONS |
| 1997 | null, //TAKE_AUDIO_FOCUS |
Emily Bernier | 45775c4 | 2014-05-16 15:12:04 -0400 | [diff] [blame] | 1998 | UserManager.DISALLOW_ADJUST_VOLUME, //AUDIO_MASTER_VOLUME |
| 1999 | UserManager.DISALLOW_ADJUST_VOLUME, //AUDIO_VOICE_VOLUME |
| 2000 | UserManager.DISALLOW_ADJUST_VOLUME, //AUDIO_RING_VOLUME |
| 2001 | UserManager.DISALLOW_ADJUST_VOLUME, //AUDIO_MEDIA_VOLUME |
| 2002 | UserManager.DISALLOW_ADJUST_VOLUME, //AUDIO_ALARM_VOLUME |
| 2003 | UserManager.DISALLOW_ADJUST_VOLUME, //AUDIO_NOTIFICATION_VOLUME |
| 2004 | UserManager.DISALLOW_ADJUST_VOLUME, //AUDIO_BLUETOOTH_VOLUME |
Jason Monk | 6206299 | 2014-05-06 09:55:28 -0400 | [diff] [blame] | 2005 | null, //WAKE_LOCK |
Julia Reynolds | 9854d57 | 2014-07-02 14:46:02 -0400 | [diff] [blame] | 2006 | UserManager.DISALLOW_SHARE_LOCATION, //MONITOR_LOCATION |
| 2007 | UserManager.DISALLOW_SHARE_LOCATION, //MONITOR_HIGH_POWER_LOCATION |
Jason Monk | 6206299 | 2014-05-06 09:55:28 -0400 | [diff] [blame] | 2008 | null, //GET_USAGE_STATS |
Emily Bernier | 22c921a | 2014-05-28 11:01:32 -0400 | [diff] [blame] | 2009 | UserManager.DISALLOW_UNMUTE_MICROPHONE, // MUTE_MICROPHONE |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 2010 | UserManager.DISALLOW_CREATE_WINDOWS, // TOAST_WINDOW |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 2011 | null, //PROJECT_MEDIA |
Tony Mak | 33d03a9 | 2016-06-02 15:01:16 +0100 | [diff] [blame] | 2012 | null, // ACTIVATE_VPN |
Benjamin Franz | f3ece36 | 2015-02-11 10:51:10 +0000 | [diff] [blame] | 2013 | UserManager.DISALLOW_WALLPAPER, // WRITE_WALLPAPER |
Dianne Hackborn | d59a5d5 | 2015-04-04 14:52:14 -0700 | [diff] [blame] | 2014 | null, // ASSIST_STRUCTURE |
| 2015 | null, // ASSIST_SCREENSHOT |
Svet Ganov | c330009 | 2015-04-17 09:07:22 -0700 | [diff] [blame] | 2016 | null, // READ_PHONE_STATE |
Svetoslav | 5335b67 | 2015-04-29 12:00:51 -0700 | [diff] [blame] | 2017 | null, // ADD_VOICEMAIL |
Svetoslav | c656e6f | 2015-04-29 14:08:16 -0700 | [diff] [blame] | 2018 | null, // USE_SIP |
Svetoslav | 4af76a5 | 2015-04-29 15:29:46 -0700 | [diff] [blame] | 2019 | null, // PROCESS_OUTGOING_CALLS |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 2020 | null, // USE_FINGERPRINT |
Svet Ganov | ede4316 | 2015-05-02 17:42:44 -0700 | [diff] [blame] | 2021 | null, // BODY_SENSORS |
Svet Ganov | f7e9cf4 | 2015-05-13 10:40:31 -0700 | [diff] [blame] | 2022 | null, // READ_CELL_BROADCASTS |
Svet Ganov | 921c7df | 2015-06-29 21:51:41 -0700 | [diff] [blame] | 2023 | null, // MOCK_LOCATION |
| 2024 | null, // READ_EXTERNAL_STORAGE |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 2025 | null, // WRITE_EXTERNAL_STORAGE |
| 2026 | null, // TURN_ON_SCREEN |
Svetoslav | f3f02ac | 2015-09-08 14:36:35 -0700 | [diff] [blame] | 2027 | null, // GET_ACCOUNTS |
Dianne Hackborn | bef28fe | 2015-10-29 17:57:11 -0700 | [diff] [blame] | 2028 | null, // RUN_IN_BACKGROUND |
Jean-Michel Trivi | 3f0945a | 2016-11-11 10:05:18 -0800 | [diff] [blame] | 2029 | UserManager.DISALLOW_ADJUST_VOLUME, //AUDIO_ACCESSIBILITY_VOLUME |
Chad Brubaker | 0c1651f | 2017-03-30 16:29:10 -0700 | [diff] [blame] | 2030 | null, // READ_PHONE_NUMBERS |
Suprabh Shukla | 2f34b1a | 2016-12-16 14:47:25 -0800 | [diff] [blame] | 2031 | null, // REQUEST_INSTALL_PACKAGES |
Winson Chung | 59fda9e | 2017-01-20 16:14:51 -0800 | [diff] [blame] | 2032 | null, // ENTER_PICTURE_IN_PICTURE_ON_HIDE |
Chad Brubaker | 97b383f | 2017-02-02 15:04:35 -0800 | [diff] [blame] | 2033 | null, // INSTANT_APP_START_FOREGROUND |
Eugene Susla | cae3d3e | 2017-01-31 11:08:11 -0800 | [diff] [blame] | 2034 | null, // ANSWER_PHONE_CALLS |
Suprabh Shukla | 3ac1daa | 2017-07-14 12:15:27 -0700 | [diff] [blame] | 2035 | null, // OP_RUN_ANY_IN_BACKGROUND |
Peter Visontay | 1246d9e | 2017-10-17 17:02:45 +0100 | [diff] [blame] | 2036 | null, // OP_CHANGE_WIFI_STATE |
Peter Visontay | f2e3836 | 2017-11-27 15:27:16 +0000 | [diff] [blame] | 2037 | null, // REQUEST_DELETE_PACKAGES |
Peter Visontay | 1195083 | 2017-11-14 19:34:59 +0000 | [diff] [blame] | 2038 | null, // OP_BIND_ACCESSIBILITY_SERVICE |
Tyler Gunn | 79bc1ec | 2018-01-22 15:17:54 -0800 | [diff] [blame] | 2039 | null, // ACCEPT_HANDOVER |
Nathan Harold | 1bb42067 | 2018-03-14 17:08:53 -0700 | [diff] [blame] | 2040 | null, // MANAGE_IPSEC_TUNNELS |
Dianne Hackborn | e9d9b4b | 2018-03-28 13:51:46 -0700 | [diff] [blame] | 2041 | null, // START_FOREGROUND |
Dianne Hackborn | e04f13d | 2018-05-02 12:51:52 -0700 | [diff] [blame] | 2042 | null, // maybe should be UserManager.DISALLOW_SHARE_LOCATION, //BLUETOOTH_SCAN |
Kevin Chyn | b3c05aa | 2018-09-21 16:50:32 -0700 | [diff] [blame] | 2043 | null, // USE_BIOMETRIC |
Zimuzo | 6cbf9cc | 2018-10-05 12:05:58 +0100 | [diff] [blame] | 2044 | null, // ACTIVITY_RECOGNITION |
Hongming Jin | 228cd01 | 2018-11-09 14:47:50 -0800 | [diff] [blame] | 2045 | UserManager.DISALLOW_SMS, // SMS_FINANCIAL_TRANSACTIONS |
Jeff Sharkey | d2a1f0d | 2018-11-19 10:32:52 -0700 | [diff] [blame] | 2046 | null, // READ_MEDIA_AUDIO |
| 2047 | null, // WRITE_MEDIA_AUDIO |
| 2048 | null, // READ_MEDIA_VIDEO |
| 2049 | null, // WRITE_MEDIA_VIDEO |
| 2050 | null, // READ_MEDIA_IMAGES |
| 2051 | null, // WRITE_MEDIA_IMAGES |
Jeff Sharkey | e82cbb1 | 2018-12-06 15:53:11 -0700 | [diff] [blame] | 2052 | null, // LEGACY_STORAGE |
Jackal Guo | 8dc791e | 2019-01-14 10:26:42 +0800 | [diff] [blame] | 2053 | null, // ACCESS_ACCESSIBILITY |
Michael Groover | 656ef91 | 2019-04-09 17:09:57 -0700 | [diff] [blame] | 2054 | null, // READ_DEVICE_IDENTIFIERS |
Philip P. Moltmann | 89b044f | 2019-09-13 15:12:34 -0700 | [diff] [blame] | 2055 | null, // ACCESS_MEDIA_LOCATION |
Patrick Baumann | 6c1c809 | 2019-06-27 14:55:44 -0700 | [diff] [blame] | 2056 | null, // QUERY_ALL_PACKAGES |
Philip P. Moltmann | b43dfe3 | 2019-11-11 14:14:49 -0800 | [diff] [blame] | 2057 | null, // MANAGE_EXTERNAL_STORAGE |
kholoud mohamed | 20ded1f | 2019-12-03 17:52:38 +0000 | [diff] [blame] | 2058 | null, // INTERACT_ACROSS_PROFILES |
Benedict Wong | 3eb9520 | 2019-11-05 12:50:59 -0800 | [diff] [blame] | 2059 | null, // ACTIVATE_PLATFORM_VPN |
Todd Kennedy | b0948d4 | 2020-01-27 15:20:07 -0800 | [diff] [blame] | 2060 | null, // LOADER_USAGE_STATS |
Ricardo Correa | acdc827 | 2020-03-24 11:02:54 -0700 | [diff] [blame] | 2061 | null, // deprecated operation |
Eugene Susla | 5fc2d76 | 2020-03-04 13:53:10 -0800 | [diff] [blame] | 2062 | null, // AUTO_REVOKE_PERMISSIONS_IF_UNUSED |
Eugene Susla | 1d7a791 | 2020-03-14 09:16:29 -0700 | [diff] [blame] | 2063 | null, // AUTO_REVOKE_MANAGED_BY_INSTALLER |
Nikita Ioffe | ac095e5 | 2020-06-08 22:24:06 +0100 | [diff] [blame] | 2064 | null, // NO_ISOLATED_STORAGE |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 2065 | }; |
| 2066 | |
| 2067 | /** |
Philip P. Moltmann | ad787aa | 2020-03-10 09:49:22 -0700 | [diff] [blame] | 2068 | * In which cases should an app be allowed to bypass the {@link #setUserRestriction user |
| 2069 | * restriction} for a certain app-op. |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 2070 | */ |
Philip P. Moltmann | ad787aa | 2020-03-10 09:49:22 -0700 | [diff] [blame] | 2071 | private static RestrictionBypass[] sOpAllowSystemRestrictionBypass = new RestrictionBypass[] { |
| 2072 | new RestrictionBypass(true, false), //COARSE_LOCATION |
| 2073 | new RestrictionBypass(true, false), //FINE_LOCATION |
| 2074 | null, //GPS |
| 2075 | null, //VIBRATE |
| 2076 | null, //READ_CONTACTS |
| 2077 | null, //WRITE_CONTACTS |
| 2078 | null, //READ_CALL_LOG |
| 2079 | null, //WRITE_CALL_LOG |
| 2080 | null, //READ_CALENDAR |
| 2081 | null, //WRITE_CALENDAR |
| 2082 | new RestrictionBypass(true, false), //WIFI_SCAN |
| 2083 | null, //POST_NOTIFICATION |
| 2084 | null, //NEIGHBORING_CELLS |
| 2085 | null, //CALL_PHONE |
| 2086 | null, //READ_SMS |
| 2087 | null, //WRITE_SMS |
| 2088 | null, //RECEIVE_SMS |
| 2089 | null, //RECEIVE_EMERGECY_SMS |
| 2090 | null, //RECEIVE_MMS |
| 2091 | null, //RECEIVE_WAP_PUSH |
| 2092 | null, //SEND_SMS |
| 2093 | null, //READ_ICC_SMS |
| 2094 | null, //WRITE_ICC_SMS |
| 2095 | null, //WRITE_SETTINGS |
| 2096 | new RestrictionBypass(true, false), //SYSTEM_ALERT_WINDOW |
| 2097 | null, //ACCESS_NOTIFICATIONS |
| 2098 | null, //CAMERA |
| 2099 | new RestrictionBypass(false, true), //RECORD_AUDIO |
| 2100 | null, //PLAY_AUDIO |
| 2101 | null, //READ_CLIPBOARD |
| 2102 | null, //WRITE_CLIPBOARD |
| 2103 | null, //TAKE_MEDIA_BUTTONS |
| 2104 | null, //TAKE_AUDIO_FOCUS |
| 2105 | null, //AUDIO_MASTER_VOLUME |
| 2106 | null, //AUDIO_VOICE_VOLUME |
| 2107 | null, //AUDIO_RING_VOLUME |
| 2108 | null, //AUDIO_MEDIA_VOLUME |
| 2109 | null, //AUDIO_ALARM_VOLUME |
| 2110 | null, //AUDIO_NOTIFICATION_VOLUME |
| 2111 | null, //AUDIO_BLUETOOTH_VOLUME |
| 2112 | null, //WAKE_LOCK |
| 2113 | null, //MONITOR_LOCATION |
| 2114 | null, //MONITOR_HIGH_POWER_LOCATION |
| 2115 | null, //GET_USAGE_STATS |
| 2116 | null, //MUTE_MICROPHONE |
| 2117 | new RestrictionBypass(true, false), //TOAST_WINDOW |
| 2118 | null, //PROJECT_MEDIA |
| 2119 | null, //ACTIVATE_VPN |
| 2120 | null, //WALLPAPER |
| 2121 | null, //ASSIST_STRUCTURE |
| 2122 | null, //ASSIST_SCREENSHOT |
| 2123 | null, //READ_PHONE_STATE |
| 2124 | null, //ADD_VOICEMAIL |
| 2125 | null, // USE_SIP |
| 2126 | null, // PROCESS_OUTGOING_CALLS |
| 2127 | null, // USE_FINGERPRINT |
| 2128 | null, // BODY_SENSORS |
| 2129 | null, // READ_CELL_BROADCASTS |
| 2130 | null, // MOCK_LOCATION |
| 2131 | null, // READ_EXTERNAL_STORAGE |
| 2132 | null, // WRITE_EXTERNAL_STORAGE |
| 2133 | null, // TURN_ON_SCREEN |
| 2134 | null, // GET_ACCOUNTS |
| 2135 | null, // RUN_IN_BACKGROUND |
| 2136 | null, // AUDIO_ACCESSIBILITY_VOLUME |
| 2137 | null, // READ_PHONE_NUMBERS |
| 2138 | null, // REQUEST_INSTALL_PACKAGES |
| 2139 | null, // ENTER_PICTURE_IN_PICTURE_ON_HIDE |
| 2140 | null, // INSTANT_APP_START_FOREGROUND |
| 2141 | null, // ANSWER_PHONE_CALLS |
| 2142 | null, // OP_RUN_ANY_IN_BACKGROUND |
| 2143 | null, // OP_CHANGE_WIFI_STATE |
| 2144 | null, // OP_REQUEST_DELETE_PACKAGES |
| 2145 | null, // OP_BIND_ACCESSIBILITY_SERVICE |
| 2146 | null, // ACCEPT_HANDOVER |
| 2147 | null, // MANAGE_IPSEC_HANDOVERS |
| 2148 | null, // START_FOREGROUND |
| 2149 | new RestrictionBypass(true, false), // BLUETOOTH_SCAN |
| 2150 | null, // USE_BIOMETRIC |
| 2151 | null, // ACTIVITY_RECOGNITION |
| 2152 | null, // SMS_FINANCIAL_TRANSACTIONS |
| 2153 | null, // READ_MEDIA_AUDIO |
| 2154 | null, // WRITE_MEDIA_AUDIO |
| 2155 | null, // READ_MEDIA_VIDEO |
| 2156 | null, // WRITE_MEDIA_VIDEO |
| 2157 | null, // READ_MEDIA_IMAGES |
| 2158 | null, // WRITE_MEDIA_IMAGES |
| 2159 | null, // LEGACY_STORAGE |
| 2160 | null, // ACCESS_ACCESSIBILITY |
| 2161 | null, // READ_DEVICE_IDENTIFIERS |
| 2162 | null, // ACCESS_MEDIA_LOCATION |
| 2163 | null, // QUERY_ALL_PACKAGES |
| 2164 | null, // MANAGE_EXTERNAL_STORAGE |
| 2165 | null, // INTERACT_ACROSS_PROFILES |
| 2166 | null, // ACTIVATE_PLATFORM_VPN |
| 2167 | null, // LOADER_USAGE_STATS |
Ricardo Correa | acdc827 | 2020-03-24 11:02:54 -0700 | [diff] [blame] | 2168 | null, // deprecated operation |
Philip P. Moltmann | ad787aa | 2020-03-10 09:49:22 -0700 | [diff] [blame] | 2169 | null, // AUTO_REVOKE_PERMISSIONS_IF_UNUSED |
Eugene Susla | 1d7a791 | 2020-03-14 09:16:29 -0700 | [diff] [blame] | 2170 | null, // AUTO_REVOKE_MANAGED_BY_INSTALLER |
Nikita Ioffe | ac095e5 | 2020-06-08 22:24:06 +0100 | [diff] [blame] | 2171 | null, // NO_ISOLATED_STORAGE |
Jason Monk | 6206299 | 2014-05-06 09:55:28 -0400 | [diff] [blame] | 2172 | }; |
| 2173 | |
| 2174 | /** |
David Braun | f5d8319 | 2013-09-16 13:43:51 -0700 | [diff] [blame] | 2175 | * This specifies the default mode for each operation. |
| 2176 | */ |
| 2177 | private static int[] sOpDefaultMode = new int[] { |
Eugene Susla | 9351985 | 2018-06-13 16:44:31 -0700 | [diff] [blame] | 2178 | AppOpsManager.MODE_ALLOWED, // COARSE_LOCATION |
| 2179 | AppOpsManager.MODE_ALLOWED, // FINE_LOCATION |
| 2180 | AppOpsManager.MODE_ALLOWED, // GPS |
| 2181 | AppOpsManager.MODE_ALLOWED, // VIBRATE |
| 2182 | AppOpsManager.MODE_ALLOWED, // READ_CONTACTS |
| 2183 | AppOpsManager.MODE_ALLOWED, // WRITE_CONTACTS |
Svet Ganov | d563e93 | 2019-04-14 13:07:41 -0700 | [diff] [blame] | 2184 | AppOpsManager.MODE_ALLOWED, // READ_CALL_LOG |
| 2185 | AppOpsManager.MODE_ALLOWED, // WRITE_CALL_LOG |
Eugene Susla | 9351985 | 2018-06-13 16:44:31 -0700 | [diff] [blame] | 2186 | AppOpsManager.MODE_ALLOWED, // READ_CALENDAR |
| 2187 | AppOpsManager.MODE_ALLOWED, // WRITE_CALENDAR |
| 2188 | AppOpsManager.MODE_ALLOWED, // WIFI_SCAN |
| 2189 | AppOpsManager.MODE_ALLOWED, // POST_NOTIFICATION |
| 2190 | AppOpsManager.MODE_ALLOWED, // NEIGHBORING_CELLS |
| 2191 | AppOpsManager.MODE_ALLOWED, // CALL_PHONE |
Svet Ganov | d563e93 | 2019-04-14 13:07:41 -0700 | [diff] [blame] | 2192 | AppOpsManager.MODE_ALLOWED, // READ_SMS |
Eugene Susla | aaff007 | 2018-10-30 13:35:03 -0700 | [diff] [blame] | 2193 | AppOpsManager.MODE_IGNORED, // WRITE_SMS |
Svet Ganov | d563e93 | 2019-04-14 13:07:41 -0700 | [diff] [blame] | 2194 | AppOpsManager.MODE_ALLOWED, // RECEIVE_SMS |
Eugene Susla | 9351985 | 2018-06-13 16:44:31 -0700 | [diff] [blame] | 2195 | AppOpsManager.MODE_ALLOWED, // RECEIVE_EMERGENCY_BROADCAST |
Svet Ganov | d563e93 | 2019-04-14 13:07:41 -0700 | [diff] [blame] | 2196 | AppOpsManager.MODE_ALLOWED, // RECEIVE_MMS |
| 2197 | AppOpsManager.MODE_ALLOWED, // RECEIVE_WAP_PUSH |
| 2198 | AppOpsManager.MODE_ALLOWED, // SEND_SMS |
Eugene Susla | 9351985 | 2018-06-13 16:44:31 -0700 | [diff] [blame] | 2199 | AppOpsManager.MODE_ALLOWED, // READ_ICC_SMS |
| 2200 | AppOpsManager.MODE_ALLOWED, // WRITE_ICC_SMS |
| 2201 | AppOpsManager.MODE_DEFAULT, // WRITE_SETTINGS |
Ng Zhi An | 65a99b6 | 2018-10-01 11:57:53 -0700 | [diff] [blame] | 2202 | getSystemAlertWindowDefault(), // SYSTEM_ALERT_WINDOW |
Eugene Susla | 9351985 | 2018-06-13 16:44:31 -0700 | [diff] [blame] | 2203 | AppOpsManager.MODE_ALLOWED, // ACCESS_NOTIFICATIONS |
| 2204 | AppOpsManager.MODE_ALLOWED, // CAMERA |
| 2205 | AppOpsManager.MODE_ALLOWED, // RECORD_AUDIO |
| 2206 | AppOpsManager.MODE_ALLOWED, // PLAY_AUDIO |
| 2207 | AppOpsManager.MODE_ALLOWED, // READ_CLIPBOARD |
| 2208 | AppOpsManager.MODE_ALLOWED, // WRITE_CLIPBOARD |
| 2209 | AppOpsManager.MODE_ALLOWED, // TAKE_MEDIA_BUTTONS |
| 2210 | AppOpsManager.MODE_ALLOWED, // TAKE_AUDIO_FOCUS |
| 2211 | AppOpsManager.MODE_ALLOWED, // AUDIO_MASTER_VOLUME |
| 2212 | AppOpsManager.MODE_ALLOWED, // AUDIO_VOICE_VOLUME |
| 2213 | AppOpsManager.MODE_ALLOWED, // AUDIO_RING_VOLUME |
| 2214 | AppOpsManager.MODE_ALLOWED, // AUDIO_MEDIA_VOLUME |
| 2215 | AppOpsManager.MODE_ALLOWED, // AUDIO_ALARM_VOLUME |
| 2216 | AppOpsManager.MODE_ALLOWED, // AUDIO_NOTIFICATION_VOLUME |
| 2217 | AppOpsManager.MODE_ALLOWED, // AUDIO_BLUETOOTH_VOLUME |
| 2218 | AppOpsManager.MODE_ALLOWED, // WAKE_LOCK |
| 2219 | AppOpsManager.MODE_ALLOWED, // MONITOR_LOCATION |
| 2220 | AppOpsManager.MODE_ALLOWED, // MONITOR_HIGH_POWER_LOCATION |
| 2221 | AppOpsManager.MODE_DEFAULT, // GET_USAGE_STATS |
| 2222 | AppOpsManager.MODE_ALLOWED, // MUTE_MICROPHONE |
| 2223 | AppOpsManager.MODE_ALLOWED, // TOAST_WINDOW |
| 2224 | AppOpsManager.MODE_IGNORED, // PROJECT_MEDIA |
| 2225 | AppOpsManager.MODE_IGNORED, // ACTIVATE_VPN |
| 2226 | AppOpsManager.MODE_ALLOWED, // WRITE_WALLPAPER |
| 2227 | AppOpsManager.MODE_ALLOWED, // ASSIST_STRUCTURE |
| 2228 | AppOpsManager.MODE_ALLOWED, // ASSIST_SCREENSHOT |
| 2229 | AppOpsManager.MODE_ALLOWED, // READ_PHONE_STATE |
| 2230 | AppOpsManager.MODE_ALLOWED, // ADD_VOICEMAIL |
| 2231 | AppOpsManager.MODE_ALLOWED, // USE_SIP |
Svet Ganov | d563e93 | 2019-04-14 13:07:41 -0700 | [diff] [blame] | 2232 | AppOpsManager.MODE_ALLOWED, // PROCESS_OUTGOING_CALLS |
Eugene Susla | 9351985 | 2018-06-13 16:44:31 -0700 | [diff] [blame] | 2233 | AppOpsManager.MODE_ALLOWED, // USE_FINGERPRINT |
| 2234 | AppOpsManager.MODE_ALLOWED, // BODY_SENSORS |
Svet Ganov | d563e93 | 2019-04-14 13:07:41 -0700 | [diff] [blame] | 2235 | AppOpsManager.MODE_ALLOWED, // READ_CELL_BROADCASTS |
Eugene Susla | 9351985 | 2018-06-13 16:44:31 -0700 | [diff] [blame] | 2236 | AppOpsManager.MODE_ERRORED, // MOCK_LOCATION |
| 2237 | AppOpsManager.MODE_ALLOWED, // READ_EXTERNAL_STORAGE |
| 2238 | AppOpsManager.MODE_ALLOWED, // WRITE_EXTERNAL_STORAGE |
| 2239 | AppOpsManager.MODE_ALLOWED, // TURN_SCREEN_ON |
| 2240 | AppOpsManager.MODE_ALLOWED, // GET_ACCOUNTS |
| 2241 | AppOpsManager.MODE_ALLOWED, // RUN_IN_BACKGROUND |
| 2242 | AppOpsManager.MODE_ALLOWED, // AUDIO_ACCESSIBILITY_VOLUME |
| 2243 | AppOpsManager.MODE_ALLOWED, // READ_PHONE_NUMBERS |
| 2244 | AppOpsManager.MODE_DEFAULT, // REQUEST_INSTALL_PACKAGES |
| 2245 | AppOpsManager.MODE_ALLOWED, // PICTURE_IN_PICTURE |
| 2246 | AppOpsManager.MODE_DEFAULT, // INSTANT_APP_START_FOREGROUND |
| 2247 | AppOpsManager.MODE_ALLOWED, // ANSWER_PHONE_CALLS |
| 2248 | AppOpsManager.MODE_ALLOWED, // RUN_ANY_IN_BACKGROUND |
| 2249 | AppOpsManager.MODE_ALLOWED, // CHANGE_WIFI_STATE |
| 2250 | AppOpsManager.MODE_ALLOWED, // REQUEST_DELETE_PACKAGES |
| 2251 | AppOpsManager.MODE_ALLOWED, // BIND_ACCESSIBILITY_SERVICE |
| 2252 | AppOpsManager.MODE_ALLOWED, // ACCEPT_HANDOVER |
| 2253 | AppOpsManager.MODE_ERRORED, // MANAGE_IPSEC_TUNNELS |
| 2254 | AppOpsManager.MODE_ALLOWED, // START_FOREGROUND |
| 2255 | AppOpsManager.MODE_ALLOWED, // BLUETOOTH_SCAN |
| 2256 | AppOpsManager.MODE_ALLOWED, // USE_BIOMETRIC |
Zimuzo | 6cbf9cc | 2018-10-05 12:05:58 +0100 | [diff] [blame] | 2257 | AppOpsManager.MODE_ALLOWED, // ACTIVITY_RECOGNITION |
Hongming Jin | 228cd01 | 2018-11-09 14:47:50 -0800 | [diff] [blame] | 2258 | AppOpsManager.MODE_DEFAULT, // SMS_FINANCIAL_TRANSACTIONS |
Jeff Sharkey | d2a1f0d | 2018-11-19 10:32:52 -0700 | [diff] [blame] | 2259 | AppOpsManager.MODE_ALLOWED, // READ_MEDIA_AUDIO |
Jeff Sharkey | 9787a945 | 2018-11-18 17:53:02 -0700 | [diff] [blame] | 2260 | AppOpsManager.MODE_ERRORED, // WRITE_MEDIA_AUDIO |
Jeff Sharkey | d2a1f0d | 2018-11-19 10:32:52 -0700 | [diff] [blame] | 2261 | AppOpsManager.MODE_ALLOWED, // READ_MEDIA_VIDEO |
Jeff Sharkey | 9787a945 | 2018-11-18 17:53:02 -0700 | [diff] [blame] | 2262 | AppOpsManager.MODE_ERRORED, // WRITE_MEDIA_VIDEO |
Jeff Sharkey | d2a1f0d | 2018-11-19 10:32:52 -0700 | [diff] [blame] | 2263 | AppOpsManager.MODE_ALLOWED, // READ_MEDIA_IMAGES |
Jeff Sharkey | 9787a945 | 2018-11-18 17:53:02 -0700 | [diff] [blame] | 2264 | AppOpsManager.MODE_ERRORED, // WRITE_MEDIA_IMAGES |
Jeff Sharkey | e82cbb1 | 2018-12-06 15:53:11 -0700 | [diff] [blame] | 2265 | AppOpsManager.MODE_DEFAULT, // LEGACY_STORAGE |
Jackal Guo | 8dc791e | 2019-01-14 10:26:42 +0800 | [diff] [blame] | 2266 | AppOpsManager.MODE_ALLOWED, // ACCESS_ACCESSIBILITY |
Michael Groover | 656ef91 | 2019-04-09 17:09:57 -0700 | [diff] [blame] | 2267 | AppOpsManager.MODE_ERRORED, // READ_DEVICE_IDENTIFIERS |
Philip P. Moltmann | 89b044f | 2019-09-13 15:12:34 -0700 | [diff] [blame] | 2268 | AppOpsManager.MODE_ALLOWED, // ALLOW_MEDIA_LOCATION |
Patrick Baumann | 6c1c809 | 2019-06-27 14:55:44 -0700 | [diff] [blame] | 2269 | AppOpsManager.MODE_DEFAULT, // QUERY_ALL_PACKAGES |
Philip P. Moltmann | b43dfe3 | 2019-11-11 14:14:49 -0800 | [diff] [blame] | 2270 | AppOpsManager.MODE_DEFAULT, // MANAGE_EXTERNAL_STORAGE |
kholoud mohamed | 20ded1f | 2019-12-03 17:52:38 +0000 | [diff] [blame] | 2271 | AppOpsManager.MODE_DEFAULT, // INTERACT_ACROSS_PROFILES |
Benedict Wong | 3eb9520 | 2019-11-05 12:50:59 -0800 | [diff] [blame] | 2272 | AppOpsManager.MODE_IGNORED, // ACTIVATE_PLATFORM_VPN |
Todd Kennedy | b0948d4 | 2020-01-27 15:20:07 -0800 | [diff] [blame] | 2273 | AppOpsManager.MODE_DEFAULT, // LOADER_USAGE_STATS |
Ricardo Correa | acdc827 | 2020-03-24 11:02:54 -0700 | [diff] [blame] | 2274 | AppOpsManager.MODE_IGNORED, // deprecated operation |
Eugene Susla | 5fc2d76 | 2020-03-04 13:53:10 -0800 | [diff] [blame] | 2275 | AppOpsManager.MODE_DEFAULT, // OP_AUTO_REVOKE_PERMISSIONS_IF_UNUSED |
Eugene Susla | 922cd08 | 2020-03-11 12:38:17 -0700 | [diff] [blame] | 2276 | AppOpsManager.MODE_ALLOWED, // OP_AUTO_REVOKE_MANAGED_BY_INSTALLER |
Nikita Ioffe | ac095e5 | 2020-06-08 22:24:06 +0100 | [diff] [blame] | 2277 | AppOpsManager.MODE_ERRORED, // OP_NO_ISOLATED_STORAGE |
David Braun | f5d8319 | 2013-09-16 13:43:51 -0700 | [diff] [blame] | 2278 | }; |
| 2279 | |
Dianne Hackborn | 8828d3a | 2013-09-25 16:47:10 -0700 | [diff] [blame] | 2280 | /** |
| 2281 | * This specifies whether each option is allowed to be reset |
| 2282 | * when resetting all app preferences. Disable reset for |
| 2283 | * app ops that are under strong control of some part of the |
| 2284 | * system (such as OP_WRITE_SMS, which should be allowed only |
| 2285 | * for whichever app is selected as the current SMS app). |
| 2286 | */ |
| 2287 | private static boolean[] sOpDisableReset = new boolean[] { |
Eugene Susla | 9351985 | 2018-06-13 16:44:31 -0700 | [diff] [blame] | 2288 | false, // COARSE_LOCATION |
| 2289 | false, // FINE_LOCATION |
| 2290 | false, // GPS |
| 2291 | false, // VIBRATE |
| 2292 | false, // READ_CONTACTS |
| 2293 | false, // WRITE_CONTACTS |
| 2294 | false, // READ_CALL_LOG |
| 2295 | false, // WRITE_CALL_LOG |
| 2296 | false, // READ_CALENDAR |
| 2297 | false, // WRITE_CALENDAR |
| 2298 | false, // WIFI_SCAN |
| 2299 | false, // POST_NOTIFICATION |
| 2300 | false, // NEIGHBORING_CELLS |
| 2301 | false, // CALL_PHONE |
| 2302 | true, // READ_SMS |
| 2303 | true, // WRITE_SMS |
| 2304 | true, // RECEIVE_SMS |
| 2305 | false, // RECEIVE_EMERGENCY_BROADCAST |
| 2306 | false, // RECEIVE_MMS |
| 2307 | true, // RECEIVE_WAP_PUSH |
| 2308 | true, // SEND_SMS |
| 2309 | false, // READ_ICC_SMS |
| 2310 | false, // WRITE_ICC_SMS |
| 2311 | false, // WRITE_SETTINGS |
| 2312 | false, // SYSTEM_ALERT_WINDOW |
| 2313 | false, // ACCESS_NOTIFICATIONS |
| 2314 | false, // CAMERA |
| 2315 | false, // RECORD_AUDIO |
| 2316 | false, // PLAY_AUDIO |
| 2317 | false, // READ_CLIPBOARD |
| 2318 | false, // WRITE_CLIPBOARD |
| 2319 | false, // TAKE_MEDIA_BUTTONS |
| 2320 | false, // TAKE_AUDIO_FOCUS |
| 2321 | false, // AUDIO_MASTER_VOLUME |
| 2322 | false, // AUDIO_VOICE_VOLUME |
| 2323 | false, // AUDIO_RING_VOLUME |
| 2324 | false, // AUDIO_MEDIA_VOLUME |
| 2325 | false, // AUDIO_ALARM_VOLUME |
| 2326 | false, // AUDIO_NOTIFICATION_VOLUME |
| 2327 | false, // AUDIO_BLUETOOTH_VOLUME |
| 2328 | false, // WAKE_LOCK |
| 2329 | false, // MONITOR_LOCATION |
| 2330 | false, // MONITOR_HIGH_POWER_LOCATION |
| 2331 | false, // GET_USAGE_STATS |
| 2332 | false, // MUTE_MICROPHONE |
| 2333 | false, // TOAST_WINDOW |
| 2334 | false, // PROJECT_MEDIA |
| 2335 | false, // ACTIVATE_VPN |
| 2336 | false, // WRITE_WALLPAPER |
| 2337 | false, // ASSIST_STRUCTURE |
| 2338 | false, // ASSIST_SCREENSHOT |
| 2339 | false, // READ_PHONE_STATE |
| 2340 | false, // ADD_VOICEMAIL |
| 2341 | false, // USE_SIP |
| 2342 | false, // PROCESS_OUTGOING_CALLS |
| 2343 | false, // USE_FINGERPRINT |
| 2344 | false, // BODY_SENSORS |
| 2345 | true, // READ_CELL_BROADCASTS |
| 2346 | false, // MOCK_LOCATION |
| 2347 | false, // READ_EXTERNAL_STORAGE |
| 2348 | false, // WRITE_EXTERNAL_STORAGE |
| 2349 | false, // TURN_SCREEN_ON |
| 2350 | false, // GET_ACCOUNTS |
| 2351 | false, // RUN_IN_BACKGROUND |
| 2352 | false, // AUDIO_ACCESSIBILITY_VOLUME |
| 2353 | false, // READ_PHONE_NUMBERS |
| 2354 | false, // REQUEST_INSTALL_PACKAGES |
| 2355 | false, // PICTURE_IN_PICTURE |
| 2356 | false, // INSTANT_APP_START_FOREGROUND |
Eugene Susla | cae3d3e | 2017-01-31 11:08:11 -0800 | [diff] [blame] | 2357 | false, // ANSWER_PHONE_CALLS |
Eugene Susla | 9351985 | 2018-06-13 16:44:31 -0700 | [diff] [blame] | 2358 | false, // RUN_ANY_IN_BACKGROUND |
| 2359 | false, // CHANGE_WIFI_STATE |
| 2360 | false, // REQUEST_DELETE_PACKAGES |
| 2361 | false, // BIND_ACCESSIBILITY_SERVICE |
Tyler Gunn | 79bc1ec | 2018-01-22 15:17:54 -0800 | [diff] [blame] | 2362 | false, // ACCEPT_HANDOVER |
Nathan Harold | 1bb42067 | 2018-03-14 17:08:53 -0700 | [diff] [blame] | 2363 | false, // MANAGE_IPSEC_TUNNELS |
Dianne Hackborn | e9d9b4b | 2018-03-28 13:51:46 -0700 | [diff] [blame] | 2364 | false, // START_FOREGROUND |
Dianne Hackborn | e04f13d | 2018-05-02 12:51:52 -0700 | [diff] [blame] | 2365 | false, // BLUETOOTH_SCAN |
Kevin Chyn | b3c05aa | 2018-09-21 16:50:32 -0700 | [diff] [blame] | 2366 | false, // USE_BIOMETRIC |
Zimuzo | 6cbf9cc | 2018-10-05 12:05:58 +0100 | [diff] [blame] | 2367 | false, // ACTIVITY_RECOGNITION |
Hongming Jin | 228cd01 | 2018-11-09 14:47:50 -0800 | [diff] [blame] | 2368 | false, // SMS_FINANCIAL_TRANSACTIONS |
Jeff Sharkey | d2a1f0d | 2018-11-19 10:32:52 -0700 | [diff] [blame] | 2369 | false, // READ_MEDIA_AUDIO |
| 2370 | false, // WRITE_MEDIA_AUDIO |
| 2371 | false, // READ_MEDIA_VIDEO |
| 2372 | false, // WRITE_MEDIA_VIDEO |
| 2373 | false, // READ_MEDIA_IMAGES |
| 2374 | false, // WRITE_MEDIA_IMAGES |
Zim | c72c9d1 | 2019-11-27 15:49:33 +0000 | [diff] [blame] | 2375 | true, // LEGACY_STORAGE |
Jackal Guo | 8dc791e | 2019-01-14 10:26:42 +0800 | [diff] [blame] | 2376 | false, // ACCESS_ACCESSIBILITY |
Michael Groover | 656ef91 | 2019-04-09 17:09:57 -0700 | [diff] [blame] | 2377 | false, // READ_DEVICE_IDENTIFIERS |
Philip P. Moltmann | 89b044f | 2019-09-13 15:12:34 -0700 | [diff] [blame] | 2378 | false, // ACCESS_MEDIA_LOCATION |
Patrick Baumann | 6c1c809 | 2019-06-27 14:55:44 -0700 | [diff] [blame] | 2379 | false, // QUERY_ALL_PACKAGES |
Philip P. Moltmann | b43dfe3 | 2019-11-11 14:14:49 -0800 | [diff] [blame] | 2380 | false, // MANAGE_EXTERNAL_STORAGE |
kholoud mohamed | 20ded1f | 2019-12-03 17:52:38 +0000 | [diff] [blame] | 2381 | false, // INTERACT_ACROSS_PROFILES |
Benedict Wong | 3eb9520 | 2019-11-05 12:50:59 -0800 | [diff] [blame] | 2382 | false, // ACTIVATE_PLATFORM_VPN |
Todd Kennedy | b0948d4 | 2020-01-27 15:20:07 -0800 | [diff] [blame] | 2383 | false, // LOADER_USAGE_STATS |
Ricardo Correa | acdc827 | 2020-03-24 11:02:54 -0700 | [diff] [blame] | 2384 | false, // deprecated operation |
Eugene Susla | 5fc2d76 | 2020-03-04 13:53:10 -0800 | [diff] [blame] | 2385 | false, // AUTO_REVOKE_PERMISSIONS_IF_UNUSED |
Eugene Susla | 1d7a791 | 2020-03-14 09:16:29 -0700 | [diff] [blame] | 2386 | false, // AUTO_REVOKE_MANAGED_BY_INSTALLER |
Nikita Ioffe | ac095e5 | 2020-06-08 22:24:06 +0100 | [diff] [blame] | 2387 | true, // NO_ISOLATED_STORAGE |
Dianne Hackborn | 8828d3a | 2013-09-25 16:47:10 -0700 | [diff] [blame] | 2388 | }; |
| 2389 | |
Svet Ganov | fbf01f7 | 2015-04-28 18:39:06 -0700 | [diff] [blame] | 2390 | /** |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 2391 | * Mapping from an app op name to the app op code. |
Svet Ganov | fbf01f7 | 2015-04-28 18:39:06 -0700 | [diff] [blame] | 2392 | */ |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 2393 | private static HashMap<String, Integer> sOpStrToOp = new HashMap<>(); |
Svet Ganov | fbf01f7 | 2015-04-28 18:39:06 -0700 | [diff] [blame] | 2394 | |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 2395 | /** |
| 2396 | * Mapping from a permission to the corresponding app op. |
| 2397 | */ |
Svet Ganov | da0acdf | 2017-02-15 10:28:51 -0800 | [diff] [blame] | 2398 | private static HashMap<String, Integer> sPermToOp = new HashMap<>(); |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 2399 | |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 2400 | /** |
| 2401 | * Set to the uid of the caller if this thread is currently executing a two-way binder |
| 2402 | * transaction. Not set if this thread is currently not executing a two way binder transaction. |
| 2403 | * |
| 2404 | * @see #startNotedAppOpsCollection |
Philip P. Moltmann | da554e4 | 2019-12-20 11:21:02 -0800 | [diff] [blame] | 2405 | * @see #getNotedOpCollectionMode |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 2406 | */ |
| 2407 | private static final ThreadLocal<Integer> sBinderThreadCallingUid = new ThreadLocal<>(); |
| 2408 | |
| 2409 | /** |
| 2410 | * If a thread is currently executing a two-way binder transaction, this stores the op-codes of |
| 2411 | * the app-ops that were noted during this transaction. |
| 2412 | * |
Philip P. Moltmann | da554e4 | 2019-12-20 11:21:02 -0800 | [diff] [blame] | 2413 | * @see #getNotedOpCollectionMode |
| 2414 | * @see #collectNotedOpSync |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 2415 | */ |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 2416 | private static final ThreadLocal<ArrayMap<String, long[]>> sAppOpsNotedInThisBinderTransaction = |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 2417 | new ThreadLocal<>(); |
| 2418 | |
| 2419 | /** Whether noting for an appop should be collected */ |
| 2420 | private static final @ShouldCollectNoteOp byte[] sAppOpsToNote = new byte[_NUM_OP]; |
| 2421 | |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 2422 | static { |
| 2423 | if (sOpToSwitch.length != _NUM_OP) { |
Dianne Hackborn | 8828d3a | 2013-09-25 16:47:10 -0700 | [diff] [blame] | 2424 | throw new IllegalStateException("sOpToSwitch length " + sOpToSwitch.length |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 2425 | + " should be " + _NUM_OP); |
| 2426 | } |
| 2427 | if (sOpToString.length != _NUM_OP) { |
Dianne Hackborn | 8828d3a | 2013-09-25 16:47:10 -0700 | [diff] [blame] | 2428 | throw new IllegalStateException("sOpToString length " + sOpToString.length |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 2429 | + " should be " + _NUM_OP); |
| 2430 | } |
| 2431 | if (sOpNames.length != _NUM_OP) { |
Dianne Hackborn | 8828d3a | 2013-09-25 16:47:10 -0700 | [diff] [blame] | 2432 | throw new IllegalStateException("sOpNames length " + sOpNames.length |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 2433 | + " should be " + _NUM_OP); |
| 2434 | } |
| 2435 | if (sOpPerms.length != _NUM_OP) { |
Dianne Hackborn | 8828d3a | 2013-09-25 16:47:10 -0700 | [diff] [blame] | 2436 | throw new IllegalStateException("sOpPerms length " + sOpPerms.length |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 2437 | + " should be " + _NUM_OP); |
| 2438 | } |
| 2439 | if (sOpDefaultMode.length != _NUM_OP) { |
Dianne Hackborn | 8828d3a | 2013-09-25 16:47:10 -0700 | [diff] [blame] | 2440 | throw new IllegalStateException("sOpDefaultMode length " + sOpDefaultMode.length |
| 2441 | + " should be " + _NUM_OP); |
| 2442 | } |
| 2443 | if (sOpDisableReset.length != _NUM_OP) { |
| 2444 | throw new IllegalStateException("sOpDisableReset length " + sOpDisableReset.length |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 2445 | + " should be " + _NUM_OP); |
| 2446 | } |
Jason Monk | 6206299 | 2014-05-06 09:55:28 -0400 | [diff] [blame] | 2447 | if (sOpRestrictions.length != _NUM_OP) { |
| 2448 | throw new IllegalStateException("sOpRestrictions length " + sOpRestrictions.length |
| 2449 | + " should be " + _NUM_OP); |
| 2450 | } |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 2451 | if (sOpAllowSystemRestrictionBypass.length != _NUM_OP) { |
| 2452 | throw new IllegalStateException("sOpAllowSYstemRestrictionsBypass length " |
| 2453 | + sOpRestrictions.length + " should be " + _NUM_OP); |
| 2454 | } |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 2455 | for (int i=0; i<_NUM_OP; i++) { |
| 2456 | if (sOpToString[i] != null) { |
| 2457 | sOpStrToOp.put(sOpToString[i], i); |
| 2458 | } |
| 2459 | } |
Svet Ganov | da0acdf | 2017-02-15 10:28:51 -0800 | [diff] [blame] | 2460 | for (int op : RUNTIME_AND_APPOP_PERMISSIONS_OPS) { |
Svetoslav Ganov | eaca4c5 | 2016-05-05 18:08:00 -0700 | [diff] [blame] | 2461 | if (sOpPerms[op] != null) { |
Svet Ganov | da0acdf | 2017-02-15 10:28:51 -0800 | [diff] [blame] | 2462 | sPermToOp.put(sOpPerms[op], op); |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 2463 | } |
| 2464 | } |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 2465 | |
| 2466 | if ((_NUM_OP + Long.SIZE - 1) / Long.SIZE != 2) { |
| 2467 | // The code currently assumes that the length of sAppOpsNotedInThisBinderTransaction is |
| 2468 | // two longs |
| 2469 | throw new IllegalStateException("notedAppOps collection code assumes < 128 appops"); |
| 2470 | } |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 2471 | } |
| 2472 | |
Stanislav Zholnin | 90516b9 | 2020-01-20 14:03:06 +0000 | [diff] [blame] | 2473 | /** Config used to control app ops access messages sampling */ |
| 2474 | private static MessageSamplingConfig sConfig = |
| 2475 | new MessageSamplingConfig(OP_NONE, 0, 0); |
| 2476 | |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 2477 | /** @hide */ |
| 2478 | public static final String KEY_HISTORICAL_OPS = "historical_ops"; |
| 2479 | |
Chad Brubaker | 7c6dba6 | 2019-01-23 15:51:43 -0800 | [diff] [blame] | 2480 | /** System properties for debug logging of noteOp call sites */ |
| 2481 | private static final String DEBUG_LOGGING_ENABLE_PROP = "appops.logging_enabled"; |
| 2482 | private static final String DEBUG_LOGGING_PACKAGES_PROP = "appops.logging_packages"; |
| 2483 | private static final String DEBUG_LOGGING_OPS_PROP = "appops.logging_ops"; |
| 2484 | private static final String DEBUG_LOGGING_TAG = "AppOpsManager"; |
| 2485 | |
David Braun | f5d8319 | 2013-09-16 13:43:51 -0700 | [diff] [blame] | 2486 | /** |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 2487 | * Retrieve the op switch that controls the given operation. |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 2488 | * @hide |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 2489 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 2490 | @UnsupportedAppUsage |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 2491 | public static int opToSwitch(int op) { |
| 2492 | return sOpToSwitch[op]; |
| 2493 | } |
| 2494 | |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 2495 | /** |
| 2496 | * Retrieve a non-localized name for the operation, for debugging output. |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 2497 | * @hide |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 2498 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 2499 | @UnsupportedAppUsage |
Dianne Hackborn | 5e45ee6 | 2013-01-24 19:13:44 -0800 | [diff] [blame] | 2500 | public static String opToName(int op) { |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 2501 | if (op == OP_NONE) return "NONE"; |
Dianne Hackborn | 5e45ee6 | 2013-01-24 19:13:44 -0800 | [diff] [blame] | 2502 | return op < sOpNames.length ? sOpNames[op] : ("Unknown(" + op + ")"); |
| 2503 | } |
| 2504 | |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 2505 | /** |
Svet Ganov | 65f1b9e | 2019-01-17 19:19:40 -0800 | [diff] [blame] | 2506 | * Retrieve a non-localized public name for the operation. |
| 2507 | * |
| 2508 | * @hide |
| 2509 | */ |
| 2510 | public static @NonNull String opToPublicName(int op) { |
| 2511 | return sOpToString[op]; |
| 2512 | } |
| 2513 | |
| 2514 | /** |
Dianne Hackborn | 7b7c58b | 2014-12-02 18:32:20 -0800 | [diff] [blame] | 2515 | * @hide |
| 2516 | */ |
| 2517 | public static int strDebugOpToOp(String op) { |
| 2518 | for (int i=0; i<sOpNames.length; i++) { |
| 2519 | if (sOpNames[i].equals(op)) { |
| 2520 | return i; |
| 2521 | } |
| 2522 | } |
| 2523 | throw new IllegalArgumentException("Unknown operation string: " + op); |
| 2524 | } |
| 2525 | |
| 2526 | /** |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 2527 | * 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] | 2528 | * @hide |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 2529 | */ |
Artur Satayev | f0b7d0b | 2019-11-04 11:16:45 +0000 | [diff] [blame] | 2530 | @UnsupportedAppUsage |
Philip P. Moltmann | 3311515 | 2018-04-11 13:39:36 -0700 | [diff] [blame] | 2531 | @TestApi |
Dianne Hackborn | 5e45ee6 | 2013-01-24 19:13:44 -0800 | [diff] [blame] | 2532 | public static String opToPermission(int op) { |
| 2533 | return sOpPerms[op]; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 2534 | } |
| 2535 | |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 2536 | /** |
Hai Zhang | b777668 | 2018-09-25 15:10:57 -0700 | [diff] [blame] | 2537 | * Retrieve the permission associated with an operation, or null if there is not one. |
| 2538 | * |
| 2539 | * @param op The operation name. |
| 2540 | * |
| 2541 | * @hide |
| 2542 | */ |
| 2543 | @Nullable |
| 2544 | @SystemApi |
| 2545 | public static String opToPermission(@NonNull String op) { |
| 2546 | return opToPermission(strOpToOp(op)); |
| 2547 | } |
| 2548 | |
| 2549 | /** |
Jason Monk | 6206299 | 2014-05-06 09:55:28 -0400 | [diff] [blame] | 2550 | * Retrieve the user restriction associated with an operation, or null if there is not one. |
| 2551 | * @hide |
| 2552 | */ |
| 2553 | public static String opToRestriction(int op) { |
| 2554 | return sOpRestrictions[op]; |
| 2555 | } |
| 2556 | |
| 2557 | /** |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 2558 | * 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] | 2559 | * This API is intended to be used for mapping runtime or appop permissions |
| 2560 | * to the corresponding app op. |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 2561 | * @hide |
| 2562 | */ |
Artur Satayev | f0b7d0b | 2019-11-04 11:16:45 +0000 | [diff] [blame] | 2563 | @UnsupportedAppUsage |
Philip P. Moltmann | 3311515 | 2018-04-11 13:39:36 -0700 | [diff] [blame] | 2564 | @TestApi |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 2565 | public static int permissionToOpCode(String permission) { |
Svet Ganov | da0acdf | 2017-02-15 10:28:51 -0800 | [diff] [blame] | 2566 | Integer boxedOpCode = sPermToOp.get(permission); |
Svet Ganov | 019d230 | 2015-05-04 11:07:38 -0700 | [diff] [blame] | 2567 | return boxedOpCode != null ? boxedOpCode : OP_NONE; |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 2568 | } |
| 2569 | |
| 2570 | /** |
Philip P. Moltmann | ad787aa | 2020-03-10 09:49:22 -0700 | [diff] [blame] | 2571 | * Retrieve whether the op allows to bypass the user restriction. |
| 2572 | * |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 2573 | * @hide |
| 2574 | */ |
Philip P. Moltmann | ad787aa | 2020-03-10 09:49:22 -0700 | [diff] [blame] | 2575 | public static RestrictionBypass opAllowSystemBypassRestriction(int op) { |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 2576 | return sOpAllowSystemRestrictionBypass[op]; |
| 2577 | } |
| 2578 | |
| 2579 | /** |
David Braun | f5d8319 | 2013-09-16 13:43:51 -0700 | [diff] [blame] | 2580 | * Retrieve the default mode for the operation. |
| 2581 | * @hide |
| 2582 | */ |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 2583 | public static @Mode int opToDefaultMode(int op) { |
David Braun | f5d8319 | 2013-09-16 13:43:51 -0700 | [diff] [blame] | 2584 | return sOpDefaultMode[op]; |
| 2585 | } |
| 2586 | |
| 2587 | /** |
Hai Zhang | c595f11 | 2018-11-06 14:20:38 -0800 | [diff] [blame] | 2588 | * Retrieve the default mode for the app op. |
| 2589 | * |
| 2590 | * @param appOp The app op name |
| 2591 | * |
| 2592 | * @return the default mode for the app op |
| 2593 | * |
| 2594 | * @hide |
| 2595 | */ |
Svet Ganov | 8e5bf96 | 2019-03-19 23:59:03 -0700 | [diff] [blame] | 2596 | @TestApi |
Hai Zhang | c595f11 | 2018-11-06 14:20:38 -0800 | [diff] [blame] | 2597 | @SystemApi |
| 2598 | public static int opToDefaultMode(@NonNull String appOp) { |
| 2599 | return opToDefaultMode(strOpToOp(appOp)); |
| 2600 | } |
| 2601 | |
| 2602 | /** |
Svet Ganov | 82f09bc | 2018-01-12 22:08:40 -0800 | [diff] [blame] | 2603 | * Retrieve the human readable mode. |
| 2604 | * @hide |
| 2605 | */ |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 2606 | public static String modeToName(@Mode int mode) { |
Dianne Hackborn | c216a26 | 2018-04-26 13:46:22 -0700 | [diff] [blame] | 2607 | if (mode >= 0 && mode < MODE_NAMES.length) { |
| 2608 | return MODE_NAMES[mode]; |
Svet Ganov | 82f09bc | 2018-01-12 22:08:40 -0800 | [diff] [blame] | 2609 | } |
Dianne Hackborn | c216a26 | 2018-04-26 13:46:22 -0700 | [diff] [blame] | 2610 | return "mode=" + mode; |
Svet Ganov | 82f09bc | 2018-01-12 22:08:40 -0800 | [diff] [blame] | 2611 | } |
| 2612 | |
| 2613 | /** |
Dianne Hackborn | 8828d3a | 2013-09-25 16:47:10 -0700 | [diff] [blame] | 2614 | * Retrieve whether the op allows itself to be reset. |
| 2615 | * @hide |
| 2616 | */ |
| 2617 | public static boolean opAllowsReset(int op) { |
| 2618 | return !sOpDisableReset[op]; |
| 2619 | } |
| 2620 | |
| 2621 | /** |
Soonil Nagarkar | 4523f96 | 2020-04-14 19:04:41 -0700 | [diff] [blame] | 2622 | * Returns a listenerId suitable for use with {@link #noteOp(int, int, String, String, String)}. |
| 2623 | * |
| 2624 | * This is intended for use client side, when the receiver id must be created before the |
| 2625 | * associated call is made to the system server. If using {@link PendingIntent} as the receiver, |
| 2626 | * avoid using this method as it will include a pointless additional x-process call. Instead to |
| 2627 | * prefer passing the PendingIntent to the system server, and then invoking |
| 2628 | * {@link #toReceiverId(PendingIntent)} instead. |
| 2629 | * |
| 2630 | * @param obj the receiver in use |
| 2631 | * @return a string representation of the receiver suitable for app ops use |
| 2632 | * @hide |
| 2633 | */ |
| 2634 | // TODO: this should probably be @SystemApi as well |
| 2635 | public static @NonNull String toReceiverId(@NonNull Object obj) { |
| 2636 | if (obj instanceof PendingIntent) { |
| 2637 | return toReceiverId((PendingIntent) obj); |
| 2638 | } else { |
| 2639 | return obj.getClass().getName() + "@" + System.identityHashCode(obj); |
| 2640 | } |
| 2641 | } |
| 2642 | |
| 2643 | /** |
| 2644 | * Returns a listenerId suitable for use with {@link #noteOp(int, int, String, String, String)}. |
| 2645 | * |
| 2646 | * This is intended for use server side, where ActivityManagerService can be referenced without |
| 2647 | * an additional x-process call. |
| 2648 | * |
| 2649 | * @param pendingIntent the pendingIntent in use |
| 2650 | * @return a string representation of the pending intent suitable for app ops use |
| 2651 | * @see #toReceiverId(Object) |
| 2652 | * @hide |
| 2653 | */ |
| 2654 | // TODO: this should probably be @SystemApi as well |
| 2655 | public static @NonNull String toReceiverId(@NonNull PendingIntent pendingIntent) { |
| 2656 | return pendingIntent.getTag(""); |
| 2657 | } |
| 2658 | |
| 2659 | /** |
Philip P. Moltmann | ad787aa | 2020-03-10 09:49:22 -0700 | [diff] [blame] | 2660 | * When to not enforce {@link #setUserRestriction restrictions}. |
| 2661 | * |
| 2662 | * @hide |
| 2663 | */ |
| 2664 | public static class RestrictionBypass { |
| 2665 | /** Does the app need to be privileged to bypass the restriction */ |
| 2666 | public boolean isPrivileged; |
| 2667 | |
| 2668 | /** |
| 2669 | * Does the app need to have the EXEMPT_FROM_AUDIO_RESTRICTIONS permission to bypass the |
| 2670 | * restriction |
| 2671 | */ |
| 2672 | public boolean isRecordAudioRestrictionExcept; |
| 2673 | |
| 2674 | public RestrictionBypass(boolean isPrivileged, boolean isRecordAudioRestrictionExcept) { |
| 2675 | this.isPrivileged = isPrivileged; |
| 2676 | this.isRecordAudioRestrictionExcept = isRecordAudioRestrictionExcept; |
| 2677 | } |
| 2678 | |
| 2679 | public static RestrictionBypass UNRESTRICTED = new RestrictionBypass(true, true); |
| 2680 | } |
| 2681 | |
| 2682 | /** |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 2683 | * Class holding all of the operation information associated with an app. |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 2684 | * @hide |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 2685 | */ |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 2686 | @TestApi |
Dianne Hackborn | f0c322a | 2018-06-13 15:24:04 -0700 | [diff] [blame] | 2687 | @SystemApi |
| 2688 | public static final class PackageOps implements Parcelable { |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 2689 | private final String mPackageName; |
| 2690 | private final int mUid; |
| 2691 | private final List<OpEntry> mEntries; |
| 2692 | |
Dianne Hackborn | f0c322a | 2018-06-13 15:24:04 -0700 | [diff] [blame] | 2693 | /** |
| 2694 | * @hide |
| 2695 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 2696 | @UnsupportedAppUsage |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 2697 | public PackageOps(String packageName, int uid, List<OpEntry> entries) { |
| 2698 | mPackageName = packageName; |
| 2699 | mUid = uid; |
| 2700 | mEntries = entries; |
| 2701 | } |
| 2702 | |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 2703 | /** |
| 2704 | * @return The name of the package. |
| 2705 | */ |
| 2706 | public @NonNull String getPackageName() { |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 2707 | return mPackageName; |
| 2708 | } |
| 2709 | |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 2710 | /** |
| 2711 | * @return The uid of the package. |
| 2712 | */ |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 2713 | public int getUid() { |
| 2714 | return mUid; |
| 2715 | } |
| 2716 | |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 2717 | /** |
| 2718 | * @return The ops of the package. |
| 2719 | */ |
Dianne Hackborn | 6287849 | 2019-03-11 15:57:07 -0700 | [diff] [blame] | 2720 | public @NonNull List<OpEntry> getOps() { |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 2721 | return mEntries; |
| 2722 | } |
| 2723 | |
| 2724 | @Override |
| 2725 | public int describeContents() { |
| 2726 | return 0; |
| 2727 | } |
| 2728 | |
| 2729 | @Override |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 2730 | public void writeToParcel(@NonNull Parcel dest, int flags) { |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 2731 | dest.writeString(mPackageName); |
| 2732 | dest.writeInt(mUid); |
| 2733 | dest.writeInt(mEntries.size()); |
| 2734 | for (int i=0; i<mEntries.size(); i++) { |
| 2735 | mEntries.get(i).writeToParcel(dest, flags); |
| 2736 | } |
| 2737 | } |
| 2738 | |
| 2739 | PackageOps(Parcel source) { |
| 2740 | mPackageName = source.readString(); |
| 2741 | mUid = source.readInt(); |
| 2742 | mEntries = new ArrayList<OpEntry>(); |
| 2743 | final int N = source.readInt(); |
| 2744 | for (int i=0; i<N; i++) { |
| 2745 | mEntries.add(OpEntry.CREATOR.createFromParcel(source)); |
| 2746 | } |
| 2747 | } |
| 2748 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 2749 | public static final @android.annotation.NonNull Creator<PackageOps> CREATOR = new Creator<PackageOps>() { |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 2750 | @Override public PackageOps createFromParcel(Parcel source) { |
| 2751 | return new PackageOps(source); |
| 2752 | } |
| 2753 | |
| 2754 | @Override public PackageOps[] newArray(int size) { |
| 2755 | return new PackageOps[size]; |
| 2756 | } |
| 2757 | }; |
| 2758 | } |
| 2759 | |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 2760 | /** |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 2761 | * Proxy information for a {@link #noteOp} event |
| 2762 | * |
| 2763 | * @hide |
| 2764 | */ |
| 2765 | @TestApi |
| 2766 | @SystemApi |
Philip P. Moltmann | d8c0bda | 2019-12-19 19:55:35 -0800 | [diff] [blame] | 2767 | // @DataClass(genHiddenConstructor = true, genHiddenCopyConstructor = true) |
| 2768 | // genHiddenCopyConstructor does not work for @hide @SystemApi classes |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 2769 | public static final class OpEventProxyInfo implements Parcelable { |
| 2770 | /** UID of the proxy app that noted the op */ |
Philip P. Moltmann | d8c0bda | 2019-12-19 19:55:35 -0800 | [diff] [blame] | 2771 | private @IntRange(from = 0) int mUid; |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 2772 | /** Package of the proxy that noted the op */ |
Philip P. Moltmann | d8c0bda | 2019-12-19 19:55:35 -0800 | [diff] [blame] | 2773 | private @Nullable String mPackageName; |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 2774 | /** Attribution tag of the proxy that noted the op */ |
| 2775 | private @Nullable String mAttributionTag; |
Philip P. Moltmann | d8c0bda | 2019-12-19 19:55:35 -0800 | [diff] [blame] | 2776 | |
| 2777 | /** |
| 2778 | * Reinit existing object with new state. |
| 2779 | * |
| 2780 | * @param uid UID of the proxy app that noted the op |
| 2781 | * @param packageName Package of the proxy that noted the op |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 2782 | * @param attributionTag attribution tag of the proxy that noted the op |
Philip P. Moltmann | d8c0bda | 2019-12-19 19:55:35 -0800 | [diff] [blame] | 2783 | * |
| 2784 | * @hide |
| 2785 | */ |
| 2786 | public void reinit(@IntRange(from = 0) int uid, @Nullable String packageName, |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 2787 | @Nullable String attributionTag) { |
Philip P. Moltmann | d8c0bda | 2019-12-19 19:55:35 -0800 | [diff] [blame] | 2788 | mUid = Preconditions.checkArgumentNonnegative(uid); |
| 2789 | mPackageName = packageName; |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 2790 | mAttributionTag = attributionTag; |
Philip P. Moltmann | d8c0bda | 2019-12-19 19:55:35 -0800 | [diff] [blame] | 2791 | } |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 2792 | |
| 2793 | |
| 2794 | |
| 2795 | // Code below generated by codegen v1.0.14. |
| 2796 | // |
| 2797 | // DO NOT MODIFY! |
| 2798 | // CHECKSTYLE:OFF Generated code |
| 2799 | // |
| 2800 | // To regenerate run: |
| 2801 | // $ codegen $ANDROID_BUILD_TOP/frameworks/base/core/java/android/app/AppOpsManager.java |
| 2802 | // |
| 2803 | // To exclude the generated code from IntelliJ auto-formatting enable (one-time): |
| 2804 | // Settings > Editor > Code Style > Formatter Control |
| 2805 | //@formatter:off |
| 2806 | |
| 2807 | |
| 2808 | /** |
| 2809 | * Creates a new OpEventProxyInfo. |
| 2810 | * |
| 2811 | * @param uid |
| 2812 | * UID of the proxy app that noted the op |
| 2813 | * @param packageName |
| 2814 | * Package of the proxy that noted the op |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 2815 | * @param attributionTag |
| 2816 | * Attribution tag of the proxy that noted the op |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 2817 | * @hide |
| 2818 | */ |
| 2819 | @DataClass.Generated.Member |
| 2820 | public OpEventProxyInfo( |
| 2821 | @IntRange(from = 0) int uid, |
| 2822 | @Nullable String packageName, |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 2823 | @Nullable String attributionTag) { |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 2824 | this.mUid = uid; |
| 2825 | com.android.internal.util.AnnotationValidations.validate( |
| 2826 | IntRange.class, null, mUid, |
| 2827 | "from", 0); |
| 2828 | this.mPackageName = packageName; |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 2829 | this.mAttributionTag = attributionTag; |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 2830 | |
| 2831 | // onConstructed(); // You can define this method to get a callback |
| 2832 | } |
| 2833 | |
| 2834 | /** |
Philip P. Moltmann | d8c0bda | 2019-12-19 19:55:35 -0800 | [diff] [blame] | 2835 | * Copy constructor |
| 2836 | * |
| 2837 | * @hide |
| 2838 | */ |
| 2839 | @DataClass.Generated.Member |
| 2840 | public OpEventProxyInfo(@NonNull OpEventProxyInfo orig) { |
| 2841 | mUid = orig.mUid; |
| 2842 | mPackageName = orig.mPackageName; |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 2843 | mAttributionTag = orig.mAttributionTag; |
Philip P. Moltmann | d8c0bda | 2019-12-19 19:55:35 -0800 | [diff] [blame] | 2844 | } |
| 2845 | |
| 2846 | /** |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 2847 | * UID of the proxy app that noted the op |
| 2848 | */ |
| 2849 | @DataClass.Generated.Member |
| 2850 | public @IntRange(from = 0) int getUid() { |
| 2851 | return mUid; |
| 2852 | } |
| 2853 | |
| 2854 | /** |
| 2855 | * Package of the proxy that noted the op |
| 2856 | */ |
| 2857 | @DataClass.Generated.Member |
| 2858 | public @Nullable String getPackageName() { |
| 2859 | return mPackageName; |
| 2860 | } |
| 2861 | |
| 2862 | /** |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 2863 | * Attribution tag of the proxy that noted the op |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 2864 | */ |
| 2865 | @DataClass.Generated.Member |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 2866 | public @Nullable String getAttributionTag() { |
| 2867 | return mAttributionTag; |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 2868 | } |
| 2869 | |
| 2870 | @Override |
| 2871 | @DataClass.Generated.Member |
| 2872 | public void writeToParcel(@NonNull Parcel dest, int flags) { |
| 2873 | // You can override field parcelling by defining methods like: |
| 2874 | // void parcelFieldName(Parcel dest, int flags) { ... } |
| 2875 | |
| 2876 | byte flg = 0; |
| 2877 | if (mPackageName != null) flg |= 0x2; |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 2878 | if (mAttributionTag != null) flg |= 0x4; |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 2879 | dest.writeByte(flg); |
| 2880 | dest.writeInt(mUid); |
| 2881 | if (mPackageName != null) dest.writeString(mPackageName); |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 2882 | if (mAttributionTag != null) dest.writeString(mAttributionTag); |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 2883 | } |
| 2884 | |
| 2885 | @Override |
| 2886 | @DataClass.Generated.Member |
| 2887 | public int describeContents() { return 0; } |
| 2888 | |
| 2889 | /** @hide */ |
| 2890 | @SuppressWarnings({"unchecked", "RedundantCast"}) |
| 2891 | @DataClass.Generated.Member |
| 2892 | /* package-private */ OpEventProxyInfo(@NonNull Parcel in) { |
| 2893 | // You can override field unparcelling by defining methods like: |
| 2894 | // static FieldType unparcelFieldName(Parcel in) { ... } |
| 2895 | |
| 2896 | byte flg = in.readByte(); |
| 2897 | int uid = in.readInt(); |
| 2898 | String packageName = (flg & 0x2) == 0 ? null : in.readString(); |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 2899 | String attributionTag = (flg & 0x4) == 0 ? null : in.readString(); |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 2900 | |
| 2901 | this.mUid = uid; |
| 2902 | com.android.internal.util.AnnotationValidations.validate( |
| 2903 | IntRange.class, null, mUid, |
| 2904 | "from", 0); |
| 2905 | this.mPackageName = packageName; |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 2906 | this.mAttributionTag = attributionTag; |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 2907 | |
| 2908 | // onConstructed(); // You can define this method to get a callback |
| 2909 | } |
| 2910 | |
| 2911 | @DataClass.Generated.Member |
| 2912 | public static final @NonNull Parcelable.Creator<OpEventProxyInfo> CREATOR |
| 2913 | = new Parcelable.Creator<OpEventProxyInfo>() { |
| 2914 | @Override |
| 2915 | public OpEventProxyInfo[] newArray(int size) { |
| 2916 | return new OpEventProxyInfo[size]; |
| 2917 | } |
| 2918 | |
| 2919 | @Override |
| 2920 | public OpEventProxyInfo createFromParcel(@NonNull Parcel in) { |
| 2921 | return new OpEventProxyInfo(in); |
| 2922 | } |
| 2923 | }; |
| 2924 | |
Philip P. Moltmann | d8c0bda | 2019-12-19 19:55:35 -0800 | [diff] [blame] | 2925 | /* |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 2926 | @DataClass.Generated( |
Philip P. Moltmann | d8c0bda | 2019-12-19 19:55:35 -0800 | [diff] [blame] | 2927 | time = 1576814974615L, |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 2928 | codegenVersion = "1.0.14", |
| 2929 | sourceFile = "frameworks/base/core/java/android/app/AppOpsManager.java", |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 2930 | 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] | 2931 | @Deprecated |
| 2932 | private void __metadata() {} |
Philip P. Moltmann | d8c0bda | 2019-12-19 19:55:35 -0800 | [diff] [blame] | 2933 | */ |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 2934 | |
| 2935 | //@formatter:on |
| 2936 | // End of generated code |
| 2937 | |
| 2938 | } |
| 2939 | |
| 2940 | /** |
| 2941 | * Description of a {@link #noteOp} or {@link #startOp} event |
| 2942 | * |
| 2943 | * @hide |
| 2944 | */ |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 2945 | //@DataClass codegen verifier is broken |
| 2946 | public static final class NoteOpEvent implements Parcelable { |
| 2947 | /** Time of noteOp event */ |
Philip P. Moltmann | d8c0bda | 2019-12-19 19:55:35 -0800 | [diff] [blame] | 2948 | private @IntRange(from = 0) long mNoteTime; |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 2949 | /** 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] | 2950 | private @IntRange(from = -1) long mDuration; |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 2951 | /** Proxy information of the noteOp event */ |
Philip P. Moltmann | d8c0bda | 2019-12-19 19:55:35 -0800 | [diff] [blame] | 2952 | private @Nullable OpEventProxyInfo mProxy; |
| 2953 | |
| 2954 | /** |
| 2955 | * Reinit existing object with new state. |
| 2956 | * |
| 2957 | * @param noteTime Time of noteOp event |
| 2958 | * @param duration The duration of this event (in case this is a startOp event, |
| 2959 | * -1 otherwise). |
| 2960 | * @param proxy Proxy information of the noteOp event |
| 2961 | * @param proxyPool The pool to release previous {@link OpEventProxyInfo} to |
| 2962 | */ |
| 2963 | public void reinit(@IntRange(from = 0) long noteTime, |
| 2964 | @IntRange(from = -1) long duration, |
| 2965 | @Nullable OpEventProxyInfo proxy, |
| 2966 | @NonNull Pools.Pool<OpEventProxyInfo> proxyPool) { |
| 2967 | mNoteTime = Preconditions.checkArgumentNonnegative(noteTime); |
| 2968 | mDuration = Preconditions.checkArgumentInRange(duration, -1L, Long.MAX_VALUE, |
| 2969 | "duration"); |
| 2970 | |
| 2971 | if (mProxy != null) { |
| 2972 | proxyPool.release(mProxy); |
| 2973 | } |
| 2974 | mProxy = proxy; |
| 2975 | } |
| 2976 | |
| 2977 | /** |
| 2978 | * Copy constructor |
| 2979 | * |
| 2980 | * @hide |
| 2981 | */ |
| 2982 | public NoteOpEvent(@NonNull NoteOpEvent original) { |
| 2983 | this(original.mNoteTime, original.mDuration, |
| 2984 | original.mProxy != null ? new OpEventProxyInfo(original.mProxy) : null); |
| 2985 | } |
| 2986 | |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 2987 | |
| 2988 | |
| 2989 | // Code below generated by codegen v1.0.14. |
| 2990 | // |
| 2991 | // DO NOT MODIFY! |
| 2992 | // CHECKSTYLE:OFF Generated code |
| 2993 | // |
| 2994 | // To regenerate run: |
| 2995 | // $ codegen $ANDROID_BUILD_TOP/frameworks/base/core/java/android/app/AppOpsManager.java |
| 2996 | // |
| 2997 | // To exclude the generated code from IntelliJ auto-formatting enable (one-time): |
| 2998 | // Settings > Editor > Code Style > Formatter Control |
| 2999 | //@formatter:off |
| 3000 | |
| 3001 | |
| 3002 | /** |
| 3003 | * Creates a new NoteOpEvent. |
| 3004 | * |
| 3005 | * @param noteTime |
| 3006 | * Time of noteOp event |
| 3007 | * @param duration |
| 3008 | * The duration of this event (in case this is a startOp event, -1 otherwise). |
| 3009 | * @param proxy |
| 3010 | * Proxy information of the noteOp event |
| 3011 | */ |
| 3012 | @DataClass.Generated.Member |
| 3013 | public NoteOpEvent( |
| 3014 | @IntRange(from = 0) long noteTime, |
| 3015 | @IntRange(from = -1) long duration, |
| 3016 | @Nullable OpEventProxyInfo proxy) { |
Philip P. Moltmann | d8c0bda | 2019-12-19 19:55:35 -0800 | [diff] [blame] | 3017 | this.mNoteTime = noteTime; |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3018 | com.android.internal.util.AnnotationValidations.validate( |
Philip P. Moltmann | d8c0bda | 2019-12-19 19:55:35 -0800 | [diff] [blame] | 3019 | IntRange.class, null, mNoteTime, |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3020 | "from", 0); |
Philip P. Moltmann | d8c0bda | 2019-12-19 19:55:35 -0800 | [diff] [blame] | 3021 | this.mDuration = duration; |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3022 | com.android.internal.util.AnnotationValidations.validate( |
Philip P. Moltmann | d8c0bda | 2019-12-19 19:55:35 -0800 | [diff] [blame] | 3023 | IntRange.class, null, mDuration, |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3024 | "from", -1); |
Philip P. Moltmann | d8c0bda | 2019-12-19 19:55:35 -0800 | [diff] [blame] | 3025 | this.mProxy = proxy; |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3026 | |
| 3027 | // onConstructed(); // You can define this method to get a callback |
| 3028 | } |
| 3029 | |
Philip P. Moltmann | d8c0bda | 2019-12-19 19:55:35 -0800 | [diff] [blame] | 3030 | /** |
| 3031 | * Time of noteOp event |
| 3032 | */ |
| 3033 | @DataClass.Generated.Member |
| 3034 | public @IntRange(from = 0) long getNoteTime() { |
| 3035 | return mNoteTime; |
| 3036 | } |
| 3037 | |
| 3038 | /** |
| 3039 | * The duration of this event (in case this is a startOp event, -1 otherwise). |
| 3040 | */ |
| 3041 | @DataClass.Generated.Member |
| 3042 | public @IntRange(from = -1) long getDuration() { |
| 3043 | return mDuration; |
| 3044 | } |
| 3045 | |
| 3046 | /** |
| 3047 | * Proxy information of the noteOp event |
| 3048 | */ |
| 3049 | @DataClass.Generated.Member |
| 3050 | public @Nullable OpEventProxyInfo getProxy() { |
| 3051 | return mProxy; |
| 3052 | } |
| 3053 | |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3054 | @Override |
| 3055 | @DataClass.Generated.Member |
| 3056 | public void writeToParcel(@NonNull Parcel dest, int flags) { |
| 3057 | // You can override field parcelling by defining methods like: |
| 3058 | // void parcelFieldName(Parcel dest, int flags) { ... } |
| 3059 | |
| 3060 | byte flg = 0; |
Philip P. Moltmann | d8c0bda | 2019-12-19 19:55:35 -0800 | [diff] [blame] | 3061 | if (mProxy != null) flg |= 0x4; |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3062 | dest.writeByte(flg); |
Philip P. Moltmann | d8c0bda | 2019-12-19 19:55:35 -0800 | [diff] [blame] | 3063 | dest.writeLong(mNoteTime); |
| 3064 | dest.writeLong(mDuration); |
| 3065 | if (mProxy != null) dest.writeTypedObject(mProxy, flags); |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3066 | } |
| 3067 | |
| 3068 | @Override |
| 3069 | @DataClass.Generated.Member |
| 3070 | public int describeContents() { return 0; } |
| 3071 | |
| 3072 | /** @hide */ |
| 3073 | @SuppressWarnings({"unchecked", "RedundantCast"}) |
| 3074 | @DataClass.Generated.Member |
| 3075 | /* package-private */ NoteOpEvent(@NonNull Parcel in) { |
| 3076 | // You can override field unparcelling by defining methods like: |
| 3077 | // static FieldType unparcelFieldName(Parcel in) { ... } |
| 3078 | |
| 3079 | byte flg = in.readByte(); |
Philip P. Moltmann | d8c0bda | 2019-12-19 19:55:35 -0800 | [diff] [blame] | 3080 | long noteTime = in.readLong(); |
| 3081 | long duration = in.readLong(); |
| 3082 | OpEventProxyInfo proxy = (flg & 0x4) == 0 ? null : (OpEventProxyInfo) in.readTypedObject(OpEventProxyInfo.CREATOR); |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3083 | |
Philip P. Moltmann | d8c0bda | 2019-12-19 19:55:35 -0800 | [diff] [blame] | 3084 | this.mNoteTime = noteTime; |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3085 | com.android.internal.util.AnnotationValidations.validate( |
Philip P. Moltmann | d8c0bda | 2019-12-19 19:55:35 -0800 | [diff] [blame] | 3086 | IntRange.class, null, mNoteTime, |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3087 | "from", 0); |
Philip P. Moltmann | d8c0bda | 2019-12-19 19:55:35 -0800 | [diff] [blame] | 3088 | this.mDuration = duration; |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3089 | com.android.internal.util.AnnotationValidations.validate( |
Philip P. Moltmann | d8c0bda | 2019-12-19 19:55:35 -0800 | [diff] [blame] | 3090 | IntRange.class, null, mDuration, |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3091 | "from", -1); |
Philip P. Moltmann | d8c0bda | 2019-12-19 19:55:35 -0800 | [diff] [blame] | 3092 | this.mProxy = proxy; |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3093 | |
| 3094 | // onConstructed(); // You can define this method to get a callback |
| 3095 | } |
| 3096 | |
| 3097 | @DataClass.Generated.Member |
| 3098 | public static final @NonNull Parcelable.Creator<NoteOpEvent> CREATOR |
| 3099 | = new Parcelable.Creator<NoteOpEvent>() { |
| 3100 | @Override |
| 3101 | public NoteOpEvent[] newArray(int size) { |
| 3102 | return new NoteOpEvent[size]; |
| 3103 | } |
| 3104 | |
| 3105 | @Override |
| 3106 | public NoteOpEvent createFromParcel(@NonNull Parcel in) { |
| 3107 | return new NoteOpEvent(in); |
| 3108 | } |
| 3109 | }; |
| 3110 | |
| 3111 | /* |
| 3112 | @DataClass.Generated( |
Philip P. Moltmann | d8c0bda | 2019-12-19 19:55:35 -0800 | [diff] [blame] | 3113 | time = 1576811792274L, |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3114 | codegenVersion = "1.0.14", |
| 3115 | sourceFile = "frameworks/base/core/java/android/app/AppOpsManager.java", |
Philip P. Moltmann | d8c0bda | 2019-12-19 19:55:35 -0800 | [diff] [blame] | 3116 | 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] | 3117 | @Deprecated |
| 3118 | private void __metadata() {} |
| 3119 | */ |
| 3120 | |
| 3121 | |
| 3122 | //@formatter:on |
| 3123 | // End of generated code |
| 3124 | |
| 3125 | } |
| 3126 | |
| 3127 | /** |
| 3128 | * 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] | 3129 | * {@link Context#createAttributionContext(String) attribution} for all uidModes and opFlags. |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3130 | * |
| 3131 | * @hide |
| 3132 | */ |
| 3133 | @TestApi |
| 3134 | @SystemApi |
| 3135 | @Immutable |
| 3136 | // @DataClass(genHiddenConstructor = true) codegen verifier is broken |
| 3137 | @DataClass.Suppress({"getAccessEvents", "getRejectEvents", "getOp"}) |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 3138 | public static final class AttributedOpEntry implements Parcelable { |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3139 | /** The code of the op */ |
| 3140 | private final @IntRange(from = 0, to = _NUM_OP - 1) int mOp; |
| 3141 | /** Whether the op is running */ |
| 3142 | private final boolean mRunning; |
| 3143 | /** The access events */ |
| 3144 | @DataClass.ParcelWith(LongSparseArrayParceling.class) |
| 3145 | private final @Nullable LongSparseArray<NoteOpEvent> mAccessEvents; |
| 3146 | /** The rejection events */ |
| 3147 | @DataClass.ParcelWith(LongSparseArrayParceling.class) |
| 3148 | private final @Nullable LongSparseArray<NoteOpEvent> mRejectEvents; |
| 3149 | |
| 3150 | /** |
| 3151 | * Returns all keys for which we have events. |
| 3152 | * |
| 3153 | * @hide |
| 3154 | */ |
| 3155 | public @NonNull ArraySet<Long> collectKeys() { |
| 3156 | ArraySet<Long> keys = new ArraySet<>(); |
| 3157 | |
| 3158 | if (mAccessEvents != null) { |
| 3159 | int numEvents = mAccessEvents.size(); |
| 3160 | for (int i = 0; i < numEvents; i++) { |
| 3161 | keys.add(mAccessEvents.keyAt(i)); |
| 3162 | } |
| 3163 | } |
| 3164 | |
| 3165 | if (mRejectEvents != null) { |
| 3166 | int numEvents = mRejectEvents.size(); |
| 3167 | for (int i = 0; i < numEvents; i++) { |
| 3168 | keys.add(mRejectEvents.keyAt(i)); |
| 3169 | } |
| 3170 | } |
| 3171 | |
| 3172 | return keys; |
| 3173 | } |
| 3174 | |
| 3175 | /** |
| 3176 | * Return the last access time. |
| 3177 | * |
| 3178 | * @param flags The op flags |
| 3179 | * |
| 3180 | * @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] | 3181 | * 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] | 3182 | * |
| 3183 | * @see #getLastAccessForegroundTime(int) |
| 3184 | * @see #getLastAccessBackgroundTime(int) |
| 3185 | * @see #getLastAccessTime(int, int, int) |
| 3186 | * @see OpEntry#getLastAccessTime(int) |
| 3187 | */ |
| 3188 | public long getLastAccessTime(@OpFlags int flags) { |
| 3189 | return getLastAccessTime(MAX_PRIORITY_UID_STATE, MIN_PRIORITY_UID_STATE, flags); |
| 3190 | } |
| 3191 | |
| 3192 | /** |
| 3193 | * Return the last foreground access time. |
| 3194 | * |
| 3195 | * @param flags The op flags |
| 3196 | * |
| 3197 | * @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] | 3198 | * 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] | 3199 | * |
| 3200 | * @see #getLastAccessTime(int) |
| 3201 | * @see #getLastAccessBackgroundTime(int) |
| 3202 | * @see #getLastAccessTime(int, int, int) |
| 3203 | * @see OpEntry#getLastAccessForegroundTime(int) |
| 3204 | */ |
| 3205 | public long getLastAccessForegroundTime(@OpFlags int flags) { |
| 3206 | return getLastAccessTime(MAX_PRIORITY_UID_STATE, resolveFirstUnrestrictedUidState(mOp), |
| 3207 | flags); |
| 3208 | } |
| 3209 | |
| 3210 | /** |
| 3211 | * Return the last background access time. |
| 3212 | * |
| 3213 | * @param flags The op flags |
| 3214 | * |
| 3215 | * @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] | 3216 | * 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] | 3217 | * |
| 3218 | * @see #getLastAccessTime(int) |
| 3219 | * @see #getLastAccessForegroundTime(int) |
| 3220 | * @see #getLastAccessTime(int, int, int) |
| 3221 | * @see OpEntry#getLastAccessBackgroundTime(int) |
| 3222 | */ |
| 3223 | public long getLastAccessBackgroundTime(@OpFlags int flags) { |
| 3224 | return getLastAccessTime(resolveLastRestrictedUidState(mOp), MIN_PRIORITY_UID_STATE, |
| 3225 | flags); |
| 3226 | } |
| 3227 | |
| 3228 | /** |
| 3229 | * Return the last access event. |
| 3230 | * |
| 3231 | * @param flags The op flags |
| 3232 | * |
Philip P. Moltmann | 7c0524f | 2020-02-06 09:21:31 -0800 | [diff] [blame] | 3233 | * @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] | 3234 | */ |
| 3235 | private @Nullable NoteOpEvent getLastAccessEvent(@UidState int fromUidState, |
| 3236 | @UidState int toUidState, @OpFlags int flags) { |
| 3237 | return getLastEvent(mAccessEvents, fromUidState, toUidState, flags); |
| 3238 | } |
| 3239 | |
| 3240 | /** |
| 3241 | * Return the last access time. |
| 3242 | * |
| 3243 | * @param fromUidState The lowest UID state for which to query |
| 3244 | * @param toUidState The highest UID state for which to query (inclusive) |
| 3245 | * @param flags The op flags |
| 3246 | * |
| 3247 | * @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] | 3248 | * 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] | 3249 | * |
| 3250 | * @see #getLastAccessTime(int) |
| 3251 | * @see #getLastAccessForegroundTime(int) |
| 3252 | * @see #getLastAccessBackgroundTime(int) |
| 3253 | * @see OpEntry#getLastAccessTime(int, int, int) |
| 3254 | */ |
| 3255 | public long getLastAccessTime(@UidState int fromUidState, @UidState int toUidState, |
| 3256 | @OpFlags int flags) { |
| 3257 | NoteOpEvent lastEvent = getLastAccessEvent(fromUidState, toUidState, flags); |
| 3258 | if (lastEvent == null) { |
| 3259 | return -1; |
| 3260 | } |
| 3261 | |
Philip P. Moltmann | d8c0bda | 2019-12-19 19:55:35 -0800 | [diff] [blame] | 3262 | return lastEvent.getNoteTime(); |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3263 | } |
| 3264 | |
| 3265 | /** |
| 3266 | * Return the last rejection time. |
| 3267 | * |
| 3268 | * @param flags The op flags |
| 3269 | * |
| 3270 | * @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] | 3271 | * 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] | 3272 | * |
| 3273 | * @see #getLastRejectForegroundTime(int) |
| 3274 | * @see #getLastRejectBackgroundTime(int) |
| 3275 | * @see #getLastRejectTime(int, int, int) |
| 3276 | * @see OpEntry#getLastRejectTime(int) |
| 3277 | */ |
| 3278 | public long getLastRejectTime(@OpFlags int flags) { |
| 3279 | return getLastRejectTime(MAX_PRIORITY_UID_STATE, MIN_PRIORITY_UID_STATE, flags); |
| 3280 | } |
| 3281 | |
| 3282 | /** |
| 3283 | * Return the last foreground rejection time. |
| 3284 | * |
| 3285 | * @param flags The op flags |
| 3286 | * |
| 3287 | * @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] | 3288 | * 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] | 3289 | * |
| 3290 | * @see #getLastRejectTime(int) |
| 3291 | * @see #getLastRejectBackgroundTime(int) |
| 3292 | * @see #getLastRejectTime(int, int, int) |
| 3293 | * @see OpEntry#getLastRejectForegroundTime(int) |
| 3294 | */ |
| 3295 | public long getLastRejectForegroundTime(@OpFlags int flags) { |
| 3296 | return getLastRejectTime(MAX_PRIORITY_UID_STATE, resolveFirstUnrestrictedUidState(mOp), |
| 3297 | flags); |
| 3298 | } |
| 3299 | |
| 3300 | /** |
| 3301 | * Return the last background rejection time. |
| 3302 | * |
| 3303 | * @param flags The op flags |
| 3304 | * |
| 3305 | * @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] | 3306 | * 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] | 3307 | * |
| 3308 | * @see #getLastRejectTime(int) |
| 3309 | * @see #getLastRejectForegroundTime(int) |
| 3310 | * @see #getLastRejectTime(int, int, int) |
| 3311 | * @see OpEntry#getLastRejectBackgroundTime(int) |
| 3312 | */ |
| 3313 | public long getLastRejectBackgroundTime(@OpFlags int flags) { |
| 3314 | return getLastRejectTime(resolveLastRestrictedUidState(mOp), MIN_PRIORITY_UID_STATE, |
| 3315 | flags); |
| 3316 | } |
| 3317 | |
| 3318 | /** |
| 3319 | * Return the last background rejection event. |
| 3320 | * |
| 3321 | * @param flags The op flags |
| 3322 | * |
Philip P. Moltmann | 7c0524f | 2020-02-06 09:21:31 -0800 | [diff] [blame] | 3323 | * @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] | 3324 | * |
| 3325 | * @see #getLastRejectTime(int) |
| 3326 | * @see #getLastRejectForegroundTime(int) |
| 3327 | * @see #getLastRejectBackgroundTime(int) |
| 3328 | * @see OpEntry#getLastRejectTime(int, int, int) |
| 3329 | */ |
| 3330 | private @Nullable NoteOpEvent getLastRejectEvent(@UidState int fromUidState, |
| 3331 | @UidState int toUidState, @OpFlags int flags) { |
| 3332 | return getLastEvent(mRejectEvents, fromUidState, toUidState, flags); |
| 3333 | } |
| 3334 | |
| 3335 | /** |
| 3336 | * Return the last rejection time. |
| 3337 | * |
| 3338 | * @param fromUidState The lowest UID state for which to query |
| 3339 | * @param toUidState The highest UID state for which to query (inclusive) |
| 3340 | * @param flags The op flags |
| 3341 | * |
Philip P. Moltmann | 7c0524f | 2020-02-06 09:21:31 -0800 | [diff] [blame] | 3342 | * @return the last access time (in milliseconds since epoch) or {@code -1} if there was no |
| 3343 | * rejection |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3344 | * |
| 3345 | * @see #getLastRejectTime(int) |
| 3346 | * @see #getLastRejectForegroundTime(int) |
| 3347 | * @see #getLastRejectForegroundTime(int) |
| 3348 | * @see #getLastRejectTime(int, int, int) |
| 3349 | * @see OpEntry#getLastRejectTime(int, int, int) |
| 3350 | */ |
| 3351 | public long getLastRejectTime(@UidState int fromUidState, @UidState int toUidState, |
| 3352 | @OpFlags int flags) { |
| 3353 | NoteOpEvent lastEvent = getLastRejectEvent(fromUidState, toUidState, flags); |
| 3354 | if (lastEvent == null) { |
| 3355 | return -1; |
| 3356 | } |
| 3357 | |
Philip P. Moltmann | d8c0bda | 2019-12-19 19:55:35 -0800 | [diff] [blame] | 3358 | return lastEvent.getNoteTime(); |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3359 | } |
| 3360 | |
| 3361 | /** |
| 3362 | * Return the duration in milliseconds of the last the access. |
| 3363 | * |
| 3364 | * @param flags The op flags |
| 3365 | * |
Philip P. Moltmann | 7c0524f | 2020-02-06 09:21:31 -0800 | [diff] [blame] | 3366 | * @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] | 3367 | * |
| 3368 | * @see #getLastForegroundDuration(int) |
| 3369 | * @see #getLastBackgroundDuration(int) |
| 3370 | * @see #getLastDuration(int, int, int) |
| 3371 | * @see OpEntry#getLastDuration(int) |
| 3372 | */ |
| 3373 | public long getLastDuration(@OpFlags int flags) { |
| 3374 | return getLastDuration(MAX_PRIORITY_UID_STATE, MIN_PRIORITY_UID_STATE, flags); |
| 3375 | } |
| 3376 | |
| 3377 | /** |
| 3378 | * Return the duration in milliseconds of the last foreground access. |
| 3379 | * |
| 3380 | * @param flags The op flags |
| 3381 | * |
Philip P. Moltmann | 7c0524f | 2020-02-06 09:21:31 -0800 | [diff] [blame] | 3382 | * @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] | 3383 | * |
| 3384 | * @see #getLastDuration(int) |
| 3385 | * @see #getLastBackgroundDuration(int) |
| 3386 | * @see #getLastDuration(int, int, int) |
| 3387 | * @see OpEntry#getLastForegroundDuration(int) |
| 3388 | */ |
| 3389 | public long getLastForegroundDuration(@OpFlags int flags) { |
| 3390 | return getLastDuration(MAX_PRIORITY_UID_STATE, resolveFirstUnrestrictedUidState(mOp), |
| 3391 | flags); |
| 3392 | } |
| 3393 | |
| 3394 | /** |
| 3395 | * Return the duration in milliseconds of the last background access. |
| 3396 | * |
| 3397 | * @param flags The op flags |
| 3398 | * |
Philip P. Moltmann | 7c0524f | 2020-02-06 09:21:31 -0800 | [diff] [blame] | 3399 | * @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] | 3400 | * |
| 3401 | * @see #getLastDuration(int) |
| 3402 | * @see #getLastForegroundDuration(int) |
| 3403 | * @see #getLastDuration(int, int, int) |
| 3404 | * @see OpEntry#getLastBackgroundDuration(int) |
| 3405 | */ |
| 3406 | public long getLastBackgroundDuration(@OpFlags int flags) { |
| 3407 | return getLastDuration(resolveLastRestrictedUidState(mOp), MIN_PRIORITY_UID_STATE, |
| 3408 | flags); |
| 3409 | } |
| 3410 | |
| 3411 | /** |
| 3412 | * Return the duration in milliseconds of the last access. |
| 3413 | * |
| 3414 | * @param fromUidState The lowest UID state for which to query |
| 3415 | * @param toUidState The highest UID state for which to query (inclusive) |
| 3416 | * @param flags The op flags |
| 3417 | * |
Philip P. Moltmann | 7c0524f | 2020-02-06 09:21:31 -0800 | [diff] [blame] | 3418 | * @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] | 3419 | * |
| 3420 | * @see #getLastDuration(int) |
| 3421 | * @see #getLastForegroundDuration(int) |
| 3422 | * @see #getLastBackgroundDuration(int) |
| 3423 | * @see #getLastDuration(int, int, int) |
| 3424 | * @see OpEntry#getLastDuration(int, int, int) |
| 3425 | */ |
| 3426 | public long getLastDuration(@UidState int fromUidState, @UidState int toUidState, |
| 3427 | @OpFlags int flags) { |
| 3428 | NoteOpEvent lastEvent = getLastAccessEvent(fromUidState, toUidState, flags);; |
| 3429 | if (lastEvent == null) { |
| 3430 | return -1; |
| 3431 | } |
| 3432 | |
Philip P. Moltmann | d8c0bda | 2019-12-19 19:55:35 -0800 | [diff] [blame] | 3433 | return lastEvent.getDuration(); |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3434 | } |
| 3435 | |
| 3436 | /** |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 3437 | * Gets the proxy info of the app that performed the last access on behalf of this |
| 3438 | * attribution and as a result blamed the op on this attribution. |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3439 | * |
| 3440 | * @param flags The op flags |
| 3441 | * |
Philip P. Moltmann | 7c0524f | 2020-02-06 09:21:31 -0800 | [diff] [blame] | 3442 | * @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] | 3443 | * |
| 3444 | * @see #getLastForegroundProxyInfo(int) |
| 3445 | * @see #getLastBackgroundProxyInfo(int) |
| 3446 | * @see #getLastProxyInfo(int, int, int) |
| 3447 | * @see OpEntry#getLastProxyInfo(int) |
| 3448 | */ |
| 3449 | public @Nullable OpEventProxyInfo getLastProxyInfo(@OpFlags int flags) { |
| 3450 | return getLastProxyInfo(MAX_PRIORITY_UID_STATE, MIN_PRIORITY_UID_STATE, flags); |
| 3451 | } |
| 3452 | |
| 3453 | /** |
| 3454 | * 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] | 3455 | * 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] | 3456 | * |
| 3457 | * @param flags The op flags |
| 3458 | * |
Philip P. Moltmann | 7c0524f | 2020-02-06 09:21:31 -0800 | [diff] [blame] | 3459 | * @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] | 3460 | * |
| 3461 | * @see #getLastProxyInfo(int) |
| 3462 | * @see #getLastBackgroundProxyInfo(int) |
| 3463 | * @see #getLastProxyInfo(int, int, int) |
| 3464 | * @see OpEntry#getLastForegroundProxyInfo(int) |
| 3465 | */ |
| 3466 | public @Nullable OpEventProxyInfo getLastForegroundProxyInfo(@OpFlags int flags) { |
| 3467 | return getLastProxyInfo(MAX_PRIORITY_UID_STATE, resolveFirstUnrestrictedUidState(mOp), |
| 3468 | flags); |
| 3469 | } |
| 3470 | |
| 3471 | /** |
| 3472 | * 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] | 3473 | * 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] | 3474 | * |
| 3475 | * @param flags The op flags |
| 3476 | * |
Philip P. Moltmann | 7c0524f | 2020-02-06 09:21:31 -0800 | [diff] [blame] | 3477 | * @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] | 3478 | * |
| 3479 | * @see #getLastProxyInfo(int) |
| 3480 | * @see #getLastForegroundProxyInfo(int) |
| 3481 | * @see #getLastProxyInfo(int, int, int) |
| 3482 | * @see OpEntry#getLastBackgroundProxyInfo(int) |
| 3483 | */ |
| 3484 | public @Nullable OpEventProxyInfo getLastBackgroundProxyInfo(@OpFlags int flags) { |
| 3485 | return getLastProxyInfo(resolveLastRestrictedUidState(mOp), MIN_PRIORITY_UID_STATE, |
| 3486 | flags); |
| 3487 | } |
| 3488 | |
| 3489 | /** |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 3490 | * Gets the proxy info of the app that performed the last access on behalf of this |
| 3491 | * attribution and as a result blamed the op on this attribution. |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3492 | * |
| 3493 | * @param fromUidState The lowest UID state for which to query |
| 3494 | * @param toUidState The highest UID state for which to query (inclusive) |
| 3495 | * @param flags The op flags |
| 3496 | * |
Philip P. Moltmann | 7c0524f | 2020-02-06 09:21:31 -0800 | [diff] [blame] | 3497 | * @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] | 3498 | * |
| 3499 | * @see #getLastProxyInfo(int) |
| 3500 | * @see #getLastForegroundProxyInfo(int) |
| 3501 | * @see #getLastBackgroundProxyInfo(int) |
| 3502 | * @see OpEntry#getLastProxyInfo(int, int, int) |
| 3503 | */ |
| 3504 | public @Nullable OpEventProxyInfo getLastProxyInfo(@UidState int fromUidState, |
| 3505 | @UidState int toUidState, @OpFlags int flags) { |
| 3506 | NoteOpEvent lastEvent = getLastAccessEvent(fromUidState, toUidState, flags); |
| 3507 | if (lastEvent == null) { |
| 3508 | return null; |
| 3509 | } |
| 3510 | |
Philip P. Moltmann | d8c0bda | 2019-12-19 19:55:35 -0800 | [diff] [blame] | 3511 | return lastEvent.getProxy(); |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3512 | } |
| 3513 | |
| 3514 | private static class LongSparseArrayParceling implements |
| 3515 | Parcelling<LongSparseArray<NoteOpEvent>> { |
| 3516 | @Override |
| 3517 | public void parcel(@Nullable LongSparseArray<NoteOpEvent> array, @NonNull Parcel dest, |
| 3518 | int parcelFlags) { |
| 3519 | if (array == null) { |
| 3520 | dest.writeInt(-1); |
| 3521 | return; |
| 3522 | } |
| 3523 | |
| 3524 | int numEntries = array.size(); |
| 3525 | dest.writeInt(numEntries); |
| 3526 | |
| 3527 | for (int i = 0; i < numEntries; i++) { |
| 3528 | dest.writeLong(array.keyAt(i)); |
| 3529 | dest.writeParcelable(array.valueAt(i), parcelFlags); |
| 3530 | } |
| 3531 | } |
| 3532 | |
| 3533 | @Override |
| 3534 | public @Nullable LongSparseArray<NoteOpEvent> unparcel(@NonNull Parcel source) { |
| 3535 | int numEntries = source.readInt(); |
| 3536 | if (numEntries == -1) { |
| 3537 | return null; |
| 3538 | } |
| 3539 | |
| 3540 | LongSparseArray<NoteOpEvent> array = new LongSparseArray<>(numEntries); |
| 3541 | |
| 3542 | for (int i = 0; i < numEntries; i++) { |
| 3543 | array.put(source.readLong(), source.readParcelable(null)); |
| 3544 | } |
| 3545 | |
| 3546 | return array; |
| 3547 | } |
| 3548 | } |
| 3549 | |
| 3550 | |
| 3551 | |
| 3552 | // Code below generated by codegen v1.0.14. |
| 3553 | // |
| 3554 | // DO NOT MODIFY! |
| 3555 | // CHECKSTYLE:OFF Generated code |
| 3556 | // |
| 3557 | // To regenerate run: |
| 3558 | // $ codegen $ANDROID_BUILD_TOP/frameworks/base/core/java/android/app/AppOpsManager.java |
| 3559 | // |
| 3560 | // To exclude the generated code from IntelliJ auto-formatting enable (one-time): |
| 3561 | // Settings > Editor > Code Style > Formatter Control |
| 3562 | //@formatter:off |
| 3563 | |
| 3564 | |
| 3565 | /** |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 3566 | * Creates a new OpAttributionEntry. |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3567 | * |
| 3568 | * @param op |
| 3569 | * The code of the op |
| 3570 | * @param running |
| 3571 | * Whether the op is running |
| 3572 | * @param accessEvents |
| 3573 | * The access events |
| 3574 | * @param rejectEvents |
| 3575 | * The rejection events |
| 3576 | * @hide |
| 3577 | */ |
| 3578 | @DataClass.Generated.Member |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 3579 | public AttributedOpEntry( |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3580 | @IntRange(from = 0, to = _NUM_OP - 1) int op, |
| 3581 | boolean running, |
| 3582 | @Nullable LongSparseArray<NoteOpEvent> accessEvents, |
| 3583 | @Nullable LongSparseArray<NoteOpEvent> rejectEvents) { |
| 3584 | this.mOp = op; |
| 3585 | com.android.internal.util.AnnotationValidations.validate( |
| 3586 | IntRange.class, null, mOp, |
| 3587 | "from", 0, |
| 3588 | "to", _NUM_OP - 1); |
| 3589 | this.mRunning = running; |
| 3590 | this.mAccessEvents = accessEvents; |
| 3591 | this.mRejectEvents = rejectEvents; |
| 3592 | |
| 3593 | // onConstructed(); // You can define this method to get a callback |
| 3594 | } |
| 3595 | |
| 3596 | /** |
| 3597 | * Whether the op is running |
| 3598 | */ |
| 3599 | @DataClass.Generated.Member |
| 3600 | public boolean isRunning() { |
| 3601 | return mRunning; |
| 3602 | } |
| 3603 | |
| 3604 | @DataClass.Generated.Member |
| 3605 | static Parcelling<LongSparseArray<NoteOpEvent>> sParcellingForAccessEvents = |
| 3606 | Parcelling.Cache.get( |
| 3607 | LongSparseArrayParceling.class); |
| 3608 | static { |
| 3609 | if (sParcellingForAccessEvents == null) { |
| 3610 | sParcellingForAccessEvents = Parcelling.Cache.put( |
| 3611 | new LongSparseArrayParceling()); |
| 3612 | } |
| 3613 | } |
| 3614 | |
| 3615 | @DataClass.Generated.Member |
| 3616 | static Parcelling<LongSparseArray<NoteOpEvent>> sParcellingForRejectEvents = |
| 3617 | Parcelling.Cache.get( |
| 3618 | LongSparseArrayParceling.class); |
| 3619 | static { |
| 3620 | if (sParcellingForRejectEvents == null) { |
| 3621 | sParcellingForRejectEvents = Parcelling.Cache.put( |
| 3622 | new LongSparseArrayParceling()); |
| 3623 | } |
| 3624 | } |
| 3625 | |
| 3626 | @Override |
| 3627 | @DataClass.Generated.Member |
| 3628 | public void writeToParcel(@NonNull Parcel dest, int flags) { |
| 3629 | // You can override field parcelling by defining methods like: |
| 3630 | // void parcelFieldName(Parcel dest, int flags) { ... } |
| 3631 | |
| 3632 | byte flg = 0; |
| 3633 | if (mRunning) flg |= 0x2; |
| 3634 | if (mAccessEvents != null) flg |= 0x4; |
| 3635 | if (mRejectEvents != null) flg |= 0x8; |
| 3636 | dest.writeByte(flg); |
| 3637 | dest.writeInt(mOp); |
| 3638 | sParcellingForAccessEvents.parcel(mAccessEvents, dest, flags); |
| 3639 | sParcellingForRejectEvents.parcel(mRejectEvents, dest, flags); |
| 3640 | } |
| 3641 | |
| 3642 | @Override |
| 3643 | @DataClass.Generated.Member |
| 3644 | public int describeContents() { return 0; } |
| 3645 | |
| 3646 | /** @hide */ |
| 3647 | @SuppressWarnings({"unchecked", "RedundantCast"}) |
| 3648 | @DataClass.Generated.Member |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 3649 | /* package-private */ AttributedOpEntry(@NonNull Parcel in) { |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3650 | // You can override field unparcelling by defining methods like: |
| 3651 | // static FieldType unparcelFieldName(Parcel in) { ... } |
| 3652 | |
| 3653 | byte flg = in.readByte(); |
| 3654 | boolean running = (flg & 0x2) != 0; |
| 3655 | int op = in.readInt(); |
| 3656 | LongSparseArray<NoteOpEvent> accessEvents = sParcellingForAccessEvents.unparcel(in); |
| 3657 | LongSparseArray<NoteOpEvent> rejectEvents = sParcellingForRejectEvents.unparcel(in); |
| 3658 | |
| 3659 | this.mOp = op; |
| 3660 | com.android.internal.util.AnnotationValidations.validate( |
| 3661 | IntRange.class, null, mOp, |
| 3662 | "from", 0, |
| 3663 | "to", _NUM_OP - 1); |
| 3664 | this.mRunning = running; |
| 3665 | this.mAccessEvents = accessEvents; |
| 3666 | this.mRejectEvents = rejectEvents; |
| 3667 | |
| 3668 | // onConstructed(); // You can define this method to get a callback |
| 3669 | } |
| 3670 | |
| 3671 | @DataClass.Generated.Member |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 3672 | public static final @NonNull Parcelable.Creator<AttributedOpEntry> CREATOR |
| 3673 | = new Parcelable.Creator<AttributedOpEntry>() { |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3674 | @Override |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 3675 | public AttributedOpEntry[] newArray(int size) { |
| 3676 | return new AttributedOpEntry[size]; |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3677 | } |
| 3678 | |
| 3679 | @Override |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 3680 | public AttributedOpEntry createFromParcel(@NonNull Parcel in) { |
| 3681 | return new AttributedOpEntry(in); |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3682 | } |
| 3683 | }; |
| 3684 | |
| 3685 | /* |
| 3686 | @DataClass.Generated( |
| 3687 | time = 1574809856239L, |
| 3688 | codegenVersion = "1.0.14", |
| 3689 | sourceFile = "frameworks/base/core/java/android/app/AppOpsManager.java", |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 3690 | 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] | 3691 | @Deprecated |
| 3692 | private void __metadata() {} |
| 3693 | */ |
| 3694 | |
| 3695 | |
| 3696 | //@formatter:on |
| 3697 | // End of generated code |
| 3698 | |
| 3699 | } |
| 3700 | |
| 3701 | /** |
| 3702 | * Last {@link #noteOp} and {@link #startOp} events performed for a single op for all uidModes |
| 3703 | * and opFlags. |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3704 | * |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 3705 | * @hide |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 3706 | */ |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 3707 | @TestApi |
| 3708 | @Immutable |
Dianne Hackborn | f0c322a | 2018-06-13 15:24:04 -0700 | [diff] [blame] | 3709 | @SystemApi |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3710 | // @DataClass(genHiddenConstructor = true) codegen verifier is broken |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3711 | public static final class OpEntry implements Parcelable { |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3712 | /** The code of the op */ |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3713 | private final @IntRange(from = 0, to = _NUM_OP - 1) int mOp; |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3714 | /** The mode of the op */ |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3715 | private final @Mode int mMode; |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 3716 | /** The attributed entries by attribution tag */ |
| 3717 | private final @NonNull Map<String, AttributedOpEntry> mAttributedOpEntries; |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3718 | |
| 3719 | /** |
| 3720 | * @hide |
| 3721 | */ |
Philip P. Moltmann | ac44350 | 2020-05-11 13:15:12 -0700 | [diff] [blame] | 3722 | @UnsupportedAppUsage(/*maxTargetSdk = Build.VERSION_CODES.R,*/ publicAlternatives = "{@code " |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3723 | + "#getOpStr()}") |
| 3724 | public int getOp() { |
| 3725 | return mOp; |
| 3726 | } |
| 3727 | |
| 3728 | /** |
| 3729 | * @return This entry's op string name, such as {@link #OPSTR_COARSE_LOCATION}. |
| 3730 | */ |
| 3731 | public @NonNull String getOpStr() { |
| 3732 | return sOpToString[mOp]; |
| 3733 | } |
| 3734 | |
| 3735 | /** |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3736 | * @hide |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3737 | * |
| 3738 | * @deprecated Use {@link #getLastAccessTime(int)} instead |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3739 | */ |
| 3740 | @Deprecated |
Philip P. Moltmann | ac44350 | 2020-05-11 13:15:12 -0700 | [diff] [blame] | 3741 | @UnsupportedAppUsage(/*maxTargetSdk = Build.VERSION_CODES.R,*/ publicAlternatives = "{@code " |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3742 | + "#getLastAccessTime(int)}") |
| 3743 | public long getTime() { |
| 3744 | return getLastAccessTime(OP_FLAGS_ALL); |
| 3745 | } |
| 3746 | |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3747 | /** |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3748 | * Return the last access time. |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3749 | * |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3750 | * @param flags The op flags |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3751 | * |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3752 | * @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] | 3753 | * 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] | 3754 | * |
| 3755 | * @see #getLastAccessForegroundTime(int) |
| 3756 | * @see #getLastAccessBackgroundTime(int) |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3757 | * @see #getLastAccessTime(int, int, int) |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 3758 | * @see AttributedOpEntry#getLastAccessTime(int) |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3759 | */ |
| 3760 | public long getLastAccessTime(@OpFlags int flags) { |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3761 | return getLastAccessTime(MAX_PRIORITY_UID_STATE, MIN_PRIORITY_UID_STATE, flags); |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3762 | } |
| 3763 | |
| 3764 | /** |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3765 | * Return the last foreground access time. |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3766 | * |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3767 | * @param flags The op flags |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3768 | * |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3769 | * @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] | 3770 | * 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] | 3771 | * |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3772 | * @see #getLastAccessTime(int) |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3773 | * @see #getLastAccessBackgroundTime(int) |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3774 | * @see #getLastAccessTime(int, int, int) |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 3775 | * @see AttributedOpEntry#getLastAccessForegroundTime(int) |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3776 | */ |
| 3777 | public long getLastAccessForegroundTime(@OpFlags int flags) { |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3778 | return getLastAccessTime(MAX_PRIORITY_UID_STATE, resolveFirstUnrestrictedUidState(mOp), |
| 3779 | flags); |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3780 | } |
| 3781 | |
| 3782 | /** |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3783 | * Return the last background access time. |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3784 | * |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3785 | * @param flags The op flags |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3786 | * |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3787 | * @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] | 3788 | * 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] | 3789 | * |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3790 | * @see #getLastAccessTime(int) |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3791 | * @see #getLastAccessForegroundTime(int) |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3792 | * @see #getLastAccessTime(int, int, int) |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 3793 | * @see AttributedOpEntry#getLastAccessBackgroundTime(int) |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3794 | */ |
| 3795 | public long getLastAccessBackgroundTime(@OpFlags int flags) { |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3796 | return getLastAccessTime(resolveLastRestrictedUidState(mOp), MIN_PRIORITY_UID_STATE, |
| 3797 | flags); |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3798 | } |
| 3799 | |
| 3800 | /** |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3801 | * Return the last access event. |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3802 | * |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3803 | * @param flags The op flags |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3804 | * |
Philip P. Moltmann | 7c0524f | 2020-02-06 09:21:31 -0800 | [diff] [blame] | 3805 | * @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] | 3806 | */ |
| 3807 | private @Nullable NoteOpEvent getLastAccessEvent(@UidState int fromUidState, |
| 3808 | @UidState int toUidState, @OpFlags int flags) { |
| 3809 | NoteOpEvent lastAccessEvent = null; |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 3810 | for (AttributedOpEntry attributionEntry : mAttributedOpEntries.values()) { |
| 3811 | NoteOpEvent lastAttributionAccessEvent = attributionEntry.getLastAccessEvent( |
| 3812 | fromUidState, toUidState, flags); |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3813 | |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 3814 | if (lastAccessEvent == null || (lastAttributionAccessEvent != null |
| 3815 | && lastAttributionAccessEvent.getNoteTime() |
| 3816 | > lastAccessEvent.getNoteTime())) { |
| 3817 | lastAccessEvent = lastAttributionAccessEvent; |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3818 | } |
| 3819 | } |
| 3820 | |
| 3821 | return lastAccessEvent; |
| 3822 | } |
| 3823 | |
| 3824 | /** |
| 3825 | * Return the last access time. |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3826 | * |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3827 | * @param fromUidState the lowest uid state to query |
| 3828 | * @param toUidState the highest uid state to query (inclusive) |
| 3829 | * @param flags The op flags |
| 3830 | * |
| 3831 | * @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] | 3832 | * 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] | 3833 | * |
| 3834 | * @see #getLastAccessTime(int) |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3835 | * @see #getLastAccessForegroundTime(int) |
| 3836 | * @see #getLastAccessBackgroundTime(int) |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 3837 | * @see AttributedOpEntry#getLastAccessTime(int, int, int) |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3838 | */ |
| 3839 | public long getLastAccessTime(@UidState int fromUidState, @UidState int toUidState, |
| 3840 | @OpFlags int flags) { |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3841 | NoteOpEvent lastEvent = getLastAccessEvent(fromUidState, toUidState, flags);; |
| 3842 | |
| 3843 | if (lastEvent == null) { |
| 3844 | return -1; |
| 3845 | } |
| 3846 | |
Philip P. Moltmann | d8c0bda | 2019-12-19 19:55:35 -0800 | [diff] [blame] | 3847 | return lastEvent.getNoteTime(); |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3848 | } |
| 3849 | |
| 3850 | /** |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3851 | * @hide |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3852 | * |
| 3853 | * @deprecated Use {@link #getLastRejectTime(int)} instead |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3854 | */ |
| 3855 | @Deprecated |
Philip P. Moltmann | ac44350 | 2020-05-11 13:15:12 -0700 | [diff] [blame] | 3856 | @UnsupportedAppUsage(/*maxTargetSdk = Build.VERSION_CODES.R,*/ publicAlternatives = "{@code " |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3857 | + "#getLastRejectTime(int)}") |
| 3858 | public long getRejectTime() { |
| 3859 | return getLastRejectTime(OP_FLAGS_ALL); |
| 3860 | } |
| 3861 | |
| 3862 | /** |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3863 | * Return the last rejection time. |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3864 | * |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3865 | * @param flags The op flags |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3866 | * |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3867 | * @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] | 3868 | * 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] | 3869 | * |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3870 | * @see #getLastRejectForegroundTime(int) |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3871 | * @see #getLastRejectBackgroundTime(int) |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3872 | * @see #getLastRejectTime(int, int, int) |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 3873 | * @see AttributedOpEntry#getLastRejectTime(int) |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3874 | */ |
| 3875 | public long getLastRejectTime(@OpFlags int flags) { |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3876 | return getLastRejectTime(MAX_PRIORITY_UID_STATE, MIN_PRIORITY_UID_STATE, flags); |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3877 | } |
| 3878 | |
| 3879 | /** |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3880 | * Return the last foreground rejection time. |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3881 | * |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3882 | * @param flags The op flags |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3883 | * |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3884 | * @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] | 3885 | * 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] | 3886 | * |
| 3887 | * @see #getLastRejectTime(int) |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3888 | * @see #getLastRejectBackgroundTime(int) |
| 3889 | * @see #getLastRejectTime(int, int, int) |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 3890 | * @see AttributedOpEntry#getLastRejectForegroundTime(int) |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3891 | */ |
| 3892 | public long getLastRejectForegroundTime(@OpFlags int flags) { |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3893 | return getLastRejectTime(MAX_PRIORITY_UID_STATE, resolveFirstUnrestrictedUidState(mOp), |
| 3894 | flags); |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3895 | } |
| 3896 | |
| 3897 | /** |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3898 | * Return the last background rejection time. |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3899 | * |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3900 | * @param flags The op flags |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3901 | * |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3902 | * @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] | 3903 | * 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] | 3904 | * |
| 3905 | * @see #getLastRejectTime(int) |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3906 | * @see #getLastRejectForegroundTime(int) |
| 3907 | * @see #getLastRejectTime(int, int, int) |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 3908 | * @see AttributedOpEntry#getLastRejectBackgroundTime(int) |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3909 | */ |
| 3910 | public long getLastRejectBackgroundTime(@OpFlags int flags) { |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3911 | return getLastRejectTime(resolveLastRestrictedUidState(mOp), MIN_PRIORITY_UID_STATE, |
| 3912 | flags); |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3913 | } |
| 3914 | |
| 3915 | /** |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3916 | * Return the last rejection event. |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3917 | * |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3918 | * @param flags The op flags |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3919 | * |
Philip P. Moltmann | 7c0524f | 2020-02-06 09:21:31 -0800 | [diff] [blame] | 3920 | * @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] | 3921 | */ |
| 3922 | private @Nullable NoteOpEvent getLastRejectEvent(@UidState int fromUidState, |
| 3923 | @UidState int toUidState, @OpFlags int flags) { |
| 3924 | NoteOpEvent lastAccessEvent = null; |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 3925 | for (AttributedOpEntry attributionEntry : mAttributedOpEntries.values()) { |
| 3926 | NoteOpEvent lastAttributionAccessEvent = attributionEntry.getLastRejectEvent( |
| 3927 | fromUidState, toUidState, flags); |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3928 | |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 3929 | if (lastAccessEvent == null || (lastAttributionAccessEvent != null |
| 3930 | && lastAttributionAccessEvent.getNoteTime() |
| 3931 | > lastAccessEvent.getNoteTime())) { |
| 3932 | lastAccessEvent = lastAttributionAccessEvent; |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3933 | } |
| 3934 | } |
| 3935 | |
| 3936 | return lastAccessEvent; |
| 3937 | } |
| 3938 | |
| 3939 | /** |
| 3940 | * Return the last rejection time. |
| 3941 | * |
| 3942 | * @param fromUidState the lowest uid state to query |
| 3943 | * @param toUidState the highest uid state to query (inclusive) |
| 3944 | * @param flags The op flags |
| 3945 | * |
| 3946 | * @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] | 3947 | * 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] | 3948 | * |
| 3949 | * @see #getLastRejectTime(int) |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3950 | * @see #getLastRejectForegroundTime(int) |
| 3951 | * @see #getLastRejectBackgroundTime(int) |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3952 | * @see #getLastRejectTime(int, int, int) |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 3953 | * @see AttributedOpEntry#getLastRejectTime(int, int, int) |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3954 | */ |
| 3955 | public long getLastRejectTime(@UidState int fromUidState, @UidState int toUidState, |
| 3956 | @OpFlags int flags) { |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3957 | NoteOpEvent lastEvent = getLastRejectEvent(fromUidState, toUidState, flags); |
| 3958 | if (lastEvent == null) { |
| 3959 | return -1; |
| 3960 | } |
| 3961 | |
Philip P. Moltmann | d8c0bda | 2019-12-19 19:55:35 -0800 | [diff] [blame] | 3962 | return lastEvent.getNoteTime(); |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3963 | } |
| 3964 | |
| 3965 | /** |
| 3966 | * @return Whether the operation is running. |
| 3967 | */ |
| 3968 | public boolean isRunning() { |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 3969 | for (AttributedOpEntry opAttributionEntry : mAttributedOpEntries.values()) { |
| 3970 | if (opAttributionEntry.isRunning()) { |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3971 | return true; |
| 3972 | } |
| 3973 | } |
| 3974 | |
| 3975 | return false; |
| 3976 | } |
| 3977 | |
| 3978 | /** |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3979 | * @deprecated Use {@link #getLastDuration(int)} instead |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3980 | */ |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3981 | @Deprecated |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3982 | public long getDuration() { |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3983 | return getLastDuration(OP_FLAGS_ALL); |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3984 | } |
| 3985 | |
| 3986 | /** |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3987 | * Return the duration in milliseconds of the last the access. |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3988 | * |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3989 | * @param flags The op flags |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3990 | * |
Philip P. Moltmann | 7c0524f | 2020-02-06 09:21:31 -0800 | [diff] [blame] | 3991 | * @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] | 3992 | * |
| 3993 | * @see #getLastForegroundDuration(int) |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3994 | * @see #getLastBackgroundDuration(int) |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3995 | * @see #getLastDuration(int, int, int) |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 3996 | * @see AttributedOpEntry#getLastDuration(int) |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 3997 | */ |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 3998 | public long getLastDuration(@OpFlags int flags) { |
| 3999 | return getLastDuration(MAX_PRIORITY_UID_STATE, MIN_PRIORITY_UID_STATE, flags); |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 4000 | } |
| 4001 | |
| 4002 | /** |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 4003 | * Return the duration in milliseconds of the last foreground access. |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 4004 | * |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 4005 | * @param flags The op flags |
| 4006 | * |
Philip P. Moltmann | 7c0524f | 2020-02-06 09:21:31 -0800 | [diff] [blame] | 4007 | * @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] | 4008 | * |
| 4009 | * @see #getLastDuration(int) |
| 4010 | * @see #getLastBackgroundDuration(int) |
| 4011 | * @see #getLastDuration(int, int, int) |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 4012 | * @see AttributedOpEntry#getLastForegroundDuration(int) |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 4013 | */ |
| 4014 | public long getLastForegroundDuration(@OpFlags int flags) { |
| 4015 | return getLastDuration(MAX_PRIORITY_UID_STATE, resolveFirstUnrestrictedUidState(mOp), |
| 4016 | flags); |
| 4017 | } |
| 4018 | |
| 4019 | /** |
| 4020 | * Return the duration in milliseconds of the last background access. |
| 4021 | * |
| 4022 | * @param flags The op flags |
| 4023 | * |
Philip P. Moltmann | 7c0524f | 2020-02-06 09:21:31 -0800 | [diff] [blame] | 4024 | * @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] | 4025 | * |
| 4026 | * @see #getLastDuration(int) |
| 4027 | * @see #getLastForegroundDuration(int) |
| 4028 | * @see #getLastDuration(int, int, int) |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 4029 | * @see AttributedOpEntry#getLastBackgroundDuration(int) |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 4030 | */ |
| 4031 | public long getLastBackgroundDuration(@OpFlags int flags) { |
| 4032 | return getLastDuration(resolveLastRestrictedUidState(mOp), MIN_PRIORITY_UID_STATE, |
| 4033 | flags); |
| 4034 | } |
| 4035 | |
| 4036 | /** |
| 4037 | * Return the duration in milliseconds of the last access. |
| 4038 | * |
| 4039 | * @param fromUidState The lowest UID state for which to query |
| 4040 | * @param toUidState The highest UID state for which to query (inclusive) |
| 4041 | * @param flags The op flags |
| 4042 | * |
Philip P. Moltmann | 7c0524f | 2020-02-06 09:21:31 -0800 | [diff] [blame] | 4043 | * @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] | 4044 | * |
| 4045 | * @see #getLastDuration(int) |
| 4046 | * @see #getLastForegroundDuration(int) |
| 4047 | * @see #getLastBackgroundDuration(int) |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 4048 | * @see AttributedOpEntry#getLastDuration(int, int, int) |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 4049 | */ |
| 4050 | public long getLastDuration(@UidState int fromUidState, @UidState int toUidState, |
| 4051 | @OpFlags int flags) { |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 4052 | NoteOpEvent lastEvent = getLastAccessEvent(fromUidState, toUidState, flags); |
| 4053 | if (lastEvent == null) { |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 4054 | return -1; |
| 4055 | } |
| 4056 | |
Philip P. Moltmann | d8c0bda | 2019-12-19 19:55:35 -0800 | [diff] [blame] | 4057 | return lastEvent.getDuration(); |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 4058 | } |
| 4059 | |
| 4060 | /** |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 4061 | * @deprecated Use {@link #getLastProxyInfo(int)} instead |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 4062 | */ |
| 4063 | @Deprecated |
| 4064 | public int getProxyUid() { |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 4065 | OpEventProxyInfo proxy = getLastProxyInfo(OP_FLAGS_ALL); |
| 4066 | if (proxy == null) { |
| 4067 | return Process.INVALID_UID; |
| 4068 | } |
| 4069 | |
| 4070 | return proxy.getUid(); |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 4071 | } |
| 4072 | |
| 4073 | /** |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 4074 | * @deprecated Use {@link #getLastProxyInfo(int)} instead |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 4075 | */ |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 4076 | @Deprecated |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 4077 | public int getProxyUid(@UidState int uidState, @OpFlags int flags) { |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 4078 | OpEventProxyInfo proxy = getLastProxyInfo(uidState, uidState, flags); |
| 4079 | if (proxy == null) { |
| 4080 | return Process.INVALID_UID; |
| 4081 | } |
| 4082 | |
| 4083 | return proxy.getUid(); |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 4084 | } |
| 4085 | |
| 4086 | /** |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 4087 | * @deprecated Use {@link #getLastProxyInfo(int)} instead |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 4088 | */ |
| 4089 | @Deprecated |
| 4090 | public @Nullable String getProxyPackageName() { |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 4091 | OpEventProxyInfo proxy = getLastProxyInfo(OP_FLAGS_ALL); |
| 4092 | if (proxy == null) { |
| 4093 | return null; |
| 4094 | } |
| 4095 | |
| 4096 | return proxy.getPackageName(); |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 4097 | } |
| 4098 | |
| 4099 | /** |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 4100 | * @deprecated Use {@link #getLastProxyInfo(int)} instead |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 4101 | */ |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 4102 | @Deprecated |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 4103 | public @Nullable String getProxyPackageName(@UidState int uidState, @OpFlags int flags) { |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 4104 | OpEventProxyInfo proxy = getLastProxyInfo(uidState, uidState, flags); |
| 4105 | if (proxy == null) { |
| 4106 | return null; |
| 4107 | } |
| 4108 | |
| 4109 | return proxy.getPackageName(); |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 4110 | } |
| 4111 | |
| 4112 | /** |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 4113 | * Gets the proxy info of the app that performed the last access on behalf of this app and |
| 4114 | * as a result blamed the op on this app. |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 4115 | * |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 4116 | * @param flags The op flags |
| 4117 | * |
Philip P. Moltmann | 7c0524f | 2020-02-06 09:21:31 -0800 | [diff] [blame] | 4118 | * @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] | 4119 | * |
| 4120 | * @see #getLastForegroundProxyInfo(int) |
| 4121 | * @see #getLastBackgroundProxyInfo(int) |
| 4122 | * @see #getLastProxyInfo(int, int, int) |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 4123 | * @see AttributedOpEntry#getLastProxyInfo(int) |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 4124 | */ |
| 4125 | public @Nullable OpEventProxyInfo getLastProxyInfo(@OpFlags int flags) { |
| 4126 | return getLastProxyInfo(MAX_PRIORITY_UID_STATE, MIN_PRIORITY_UID_STATE, flags); |
| 4127 | } |
| 4128 | |
| 4129 | /** |
| 4130 | * Gets the proxy info of the app that performed the last foreground access on behalf of |
| 4131 | * this app and as a result blamed the op on this app. |
| 4132 | * |
| 4133 | * @param flags The op flags |
| 4134 | * |
Philip P. Moltmann | 7c0524f | 2020-02-06 09:21:31 -0800 | [diff] [blame] | 4135 | * @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] | 4136 | * |
| 4137 | * @see #getLastProxyInfo(int) |
| 4138 | * @see #getLastBackgroundProxyInfo(int) |
| 4139 | * @see #getLastProxyInfo(int, int, int) |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 4140 | * @see AttributedOpEntry#getLastForegroundProxyInfo(int) |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 4141 | */ |
| 4142 | public @Nullable OpEventProxyInfo getLastForegroundProxyInfo(@OpFlags int flags) { |
| 4143 | return getLastProxyInfo(MAX_PRIORITY_UID_STATE, resolveFirstUnrestrictedUidState(mOp), |
| 4144 | flags); |
| 4145 | } |
| 4146 | |
| 4147 | /** |
| 4148 | * Gets the proxy info of the app that performed the last background access on behalf of |
| 4149 | * this app and as a result blamed the op on this app. |
| 4150 | * |
| 4151 | * @param flags The op flags |
| 4152 | * |
Philip P. Moltmann | 7c0524f | 2020-02-06 09:21:31 -0800 | [diff] [blame] | 4153 | * @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] | 4154 | * |
| 4155 | * @see #getLastProxyInfo(int) |
| 4156 | * @see #getLastForegroundProxyInfo(int) |
| 4157 | * @see #getLastProxyInfo(int, int, int) |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 4158 | * @see AttributedOpEntry#getLastBackgroundProxyInfo(int) |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 4159 | */ |
| 4160 | public @Nullable OpEventProxyInfo getLastBackgroundProxyInfo(@OpFlags int flags) { |
| 4161 | return getLastProxyInfo(resolveLastRestrictedUidState(mOp), MIN_PRIORITY_UID_STATE, |
| 4162 | flags); |
| 4163 | } |
| 4164 | |
| 4165 | /** |
| 4166 | * Gets the proxy info of the app that performed the last access on behalf of this app and |
| 4167 | * as a result blamed the op on this app. |
| 4168 | * |
| 4169 | * @param fromUidState The lowest UID state for which to query |
| 4170 | * @param toUidState The highest UID state for which to query (inclusive) |
| 4171 | * @param flags The op flags |
| 4172 | * |
Philip P. Moltmann | 7c0524f | 2020-02-06 09:21:31 -0800 | [diff] [blame] | 4173 | * @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] | 4174 | * |
| 4175 | * @see #getLastProxyInfo(int) |
| 4176 | * @see #getLastForegroundProxyInfo(int) |
| 4177 | * @see #getLastBackgroundProxyInfo(int) |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 4178 | * @see AttributedOpEntry#getLastProxyInfo(int, int, int) |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 4179 | */ |
| 4180 | public @Nullable OpEventProxyInfo getLastProxyInfo(@UidState int fromUidState, |
| 4181 | @UidState int toUidState, @OpFlags int flags) { |
| 4182 | NoteOpEvent lastEvent = getLastAccessEvent(fromUidState, toUidState, flags); |
| 4183 | if (lastEvent == null) { |
| 4184 | return null; |
| 4185 | } |
| 4186 | |
Philip P. Moltmann | d8c0bda | 2019-12-19 19:55:35 -0800 | [diff] [blame] | 4187 | return lastEvent.getProxy(); |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 4188 | } |
| 4189 | |
| 4190 | |
| 4191 | |
| 4192 | // Code below generated by codegen v1.0.14. |
| 4193 | // |
| 4194 | // DO NOT MODIFY! |
| 4195 | // CHECKSTYLE:OFF Generated code |
| 4196 | // |
| 4197 | // To regenerate run: |
| 4198 | // $ codegen $ANDROID_BUILD_TOP/frameworks/base/core/java/android/app/AppOpsManager.java |
| 4199 | // |
| 4200 | // To exclude the generated code from IntelliJ auto-formatting enable (one-time): |
| 4201 | // Settings > Editor > Code Style > Formatter Control |
| 4202 | //@formatter:off |
| 4203 | |
| 4204 | |
| 4205 | /** |
| 4206 | * Creates a new OpEntry. |
| 4207 | * |
| 4208 | * @param op |
| 4209 | * The code of the op |
| 4210 | * @param mode |
| 4211 | * The mode of the op |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 4212 | * @param attributedOpEntries |
| 4213 | * The attributions that have been used when noting the op |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 4214 | * @hide |
| 4215 | */ |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 4216 | @DataClass.Generated.Member |
| 4217 | public OpEntry( |
| 4218 | @IntRange(from = 0, to = _NUM_OP - 1) int op, |
| 4219 | @Mode int mode, |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 4220 | @NonNull Map<String, AttributedOpEntry> attributedOpEntries) { |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 4221 | this.mOp = op; |
| 4222 | com.android.internal.util.AnnotationValidations.validate( |
| 4223 | IntRange.class, null, mOp, |
| 4224 | "from", 0, |
| 4225 | "to", _NUM_OP - 1); |
| 4226 | this.mMode = mode; |
| 4227 | com.android.internal.util.AnnotationValidations.validate( |
| 4228 | Mode.class, null, mMode); |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 4229 | this.mAttributedOpEntries = attributedOpEntries; |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 4230 | com.android.internal.util.AnnotationValidations.validate( |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 4231 | NonNull.class, null, mAttributedOpEntries); |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 4232 | |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 4233 | // onConstructed(); // You can define this method to get a callback |
| 4234 | } |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 4235 | |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 4236 | /** |
| 4237 | * The mode of the op |
| 4238 | */ |
| 4239 | @DataClass.Generated.Member |
| 4240 | public @Mode int getMode() { |
| 4241 | return mMode; |
| 4242 | } |
| 4243 | |
| 4244 | /** |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 4245 | * The attributed entries keyed by attribution tag. |
Philip P. Moltmann | 3f9ee36 | 2020-02-06 09:32:28 -0800 | [diff] [blame] | 4246 | * |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 4247 | * @see Context#createAttributionContext(String) |
Philip P. Moltmann | 3f9ee36 | 2020-02-06 09:32:28 -0800 | [diff] [blame] | 4248 | * @see #noteOp(String, int, String, String, String) |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 4249 | */ |
| 4250 | @DataClass.Generated.Member |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 4251 | public @NonNull Map<String, AttributedOpEntry> getAttributedOpEntries() { |
| 4252 | return mAttributedOpEntries; |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 4253 | } |
| 4254 | |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 4255 | @Override |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 4256 | @DataClass.Generated.Member |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 4257 | public void writeToParcel(Parcel dest, int flags) { |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 4258 | // You can override field parcelling by defining methods like: |
| 4259 | // void parcelFieldName(Parcel dest, int flags) { ... } |
| 4260 | |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 4261 | dest.writeInt(mOp); |
Dianne Hackborn | 5e45ee6 | 2013-01-24 19:13:44 -0800 | [diff] [blame] | 4262 | dest.writeInt(mMode); |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 4263 | dest.writeMap(mAttributedOpEntries); |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 4264 | } |
| 4265 | |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 4266 | @Override |
| 4267 | @DataClass.Generated.Member |
| 4268 | public int describeContents() { return 0; } |
| 4269 | |
| 4270 | /** @hide */ |
| 4271 | @SuppressWarnings({"unchecked", "RedundantCast"}) |
| 4272 | @DataClass.Generated.Member |
| 4273 | /* package-private */ OpEntry(@NonNull Parcel in) { |
| 4274 | // You can override field unparcelling by defining methods like: |
| 4275 | // static FieldType unparcelFieldName(Parcel in) { ... } |
| 4276 | |
| 4277 | int op = in.readInt(); |
| 4278 | int mode = in.readInt(); |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 4279 | Map<String, AttributedOpEntry> attributions = new java.util.LinkedHashMap<>(); |
| 4280 | in.readMap(attributions, AttributedOpEntry.class.getClassLoader()); |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 4281 | |
| 4282 | this.mOp = op; |
| 4283 | com.android.internal.util.AnnotationValidations.validate( |
| 4284 | IntRange.class, null, mOp, |
| 4285 | "from", 0, |
| 4286 | "to", _NUM_OP - 1); |
| 4287 | this.mMode = mode; |
| 4288 | com.android.internal.util.AnnotationValidations.validate( |
| 4289 | Mode.class, null, mMode); |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 4290 | this.mAttributedOpEntries = attributions; |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 4291 | com.android.internal.util.AnnotationValidations.validate( |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 4292 | NonNull.class, null, mAttributedOpEntries); |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 4293 | |
| 4294 | // onConstructed(); // You can define this method to get a callback |
| 4295 | } |
| 4296 | |
| 4297 | @DataClass.Generated.Member |
| 4298 | public static final @NonNull Parcelable.Creator<OpEntry> CREATOR |
| 4299 | = new Parcelable.Creator<OpEntry>() { |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 4300 | @Override |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 4301 | public OpEntry[] newArray(int size) { |
| 4302 | return new OpEntry[size]; |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 4303 | } |
| 4304 | |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 4305 | @Override |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 4306 | public OpEntry createFromParcel(@NonNull Parcel in) { |
| 4307 | return new OpEntry(in); |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 4308 | } |
| 4309 | }; |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 4310 | |
| 4311 | /* |
| 4312 | @DataClass.Generated( |
| 4313 | time = 1574809856259L, |
| 4314 | codegenVersion = "1.0.14", |
| 4315 | sourceFile = "frameworks/base/core/java/android/app/AppOpsManager.java", |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 4316 | 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] | 4317 | @Deprecated |
| 4318 | private void __metadata() {} |
| 4319 | */ |
| 4320 | |
| 4321 | |
| 4322 | //@formatter:on |
| 4323 | // End of generated code |
| 4324 | |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 4325 | } |
| 4326 | |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 4327 | /** @hide */ |
| 4328 | public interface HistoricalOpsVisitor { |
| 4329 | void visitHistoricalOps(@NonNull HistoricalOps ops); |
| 4330 | void visitHistoricalUidOps(@NonNull HistoricalUidOps ops); |
| 4331 | void visitHistoricalPackageOps(@NonNull HistoricalPackageOps ops); |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 4332 | void visitHistoricalAttributionOps(@NonNull AttributedHistoricalOps ops); |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 4333 | void visitHistoricalOp(@NonNull HistoricalOp ops); |
| 4334 | } |
| 4335 | |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 4336 | /** |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 4337 | * Specifies what parameters to filter historical appop requests for |
| 4338 | * |
| 4339 | * @hide |
| 4340 | */ |
| 4341 | @Retention(RetentionPolicy.SOURCE) |
| 4342 | @IntDef(flag = true, prefix = { "FILTER_BY_" }, value = { |
| 4343 | FILTER_BY_UID, |
| 4344 | FILTER_BY_PACKAGE_NAME, |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 4345 | FILTER_BY_ATTRIBUTION_TAG, |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 4346 | FILTER_BY_OP_NAMES |
| 4347 | }) |
| 4348 | public @interface HistoricalOpsRequestFilter {} |
| 4349 | |
| 4350 | /** |
| 4351 | * Filter historical appop request by uid. |
| 4352 | * |
| 4353 | * @hide |
| 4354 | */ |
| 4355 | public static final int FILTER_BY_UID = 1<<0; |
| 4356 | |
| 4357 | /** |
| 4358 | * Filter historical appop request by package name. |
| 4359 | * |
| 4360 | * @hide |
| 4361 | */ |
| 4362 | public static final int FILTER_BY_PACKAGE_NAME = 1<<1; |
| 4363 | |
| 4364 | /** |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 4365 | * Filter historical appop request by attribution tag. |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 4366 | * |
| 4367 | * @hide |
| 4368 | */ |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 4369 | public static final int FILTER_BY_ATTRIBUTION_TAG = 1<<2; |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 4370 | |
| 4371 | /** |
| 4372 | * Filter historical appop request by op names. |
| 4373 | * |
| 4374 | * @hide |
| 4375 | */ |
| 4376 | public static final int FILTER_BY_OP_NAMES = 1<<3; |
| 4377 | |
| 4378 | /** |
Svet Ganov | 23c88db | 2019-01-22 20:38:11 -0800 | [diff] [blame] | 4379 | * Request for getting historical app op usage. The request acts |
| 4380 | * as a filtering criteria when querying historical op usage. |
| 4381 | * |
| 4382 | * @hide |
| 4383 | */ |
| 4384 | @Immutable |
| 4385 | @TestApi |
| 4386 | @SystemApi |
| 4387 | public static final class HistoricalOpsRequest { |
| 4388 | private final int mUid; |
| 4389 | private final @Nullable String mPackageName; |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 4390 | private final @Nullable String mAttributionTag; |
Svet Ganov | 23c88db | 2019-01-22 20:38:11 -0800 | [diff] [blame] | 4391 | private final @Nullable List<String> mOpNames; |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 4392 | private final @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 final @OpFlags int mFlags; |
Svet Ganov | 23c88db | 2019-01-22 20:38:11 -0800 | [diff] [blame] | 4396 | |
| 4397 | private HistoricalOpsRequest(int uid, @Nullable String packageName, |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 4398 | @Nullable String attributionTag, @Nullable List<String> opNames, |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 4399 | @HistoricalOpsRequestFilter int filter, long beginTimeMillis, |
| 4400 | long endTimeMillis, @OpFlags int flags) { |
Svet Ganov | 23c88db | 2019-01-22 20:38:11 -0800 | [diff] [blame] | 4401 | mUid = uid; |
| 4402 | mPackageName = packageName; |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 4403 | mAttributionTag = attributionTag; |
Svet Ganov | 23c88db | 2019-01-22 20:38:11 -0800 | [diff] [blame] | 4404 | mOpNames = opNames; |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 4405 | mFilter = filter; |
Svet Ganov | 23c88db | 2019-01-22 20:38:11 -0800 | [diff] [blame] | 4406 | mBeginTimeMillis = beginTimeMillis; |
| 4407 | mEndTimeMillis = endTimeMillis; |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 4408 | mFlags = flags; |
Svet Ganov | 23c88db | 2019-01-22 20:38:11 -0800 | [diff] [blame] | 4409 | } |
| 4410 | |
| 4411 | /** |
| 4412 | * Builder for creating a {@link HistoricalOpsRequest}. |
| 4413 | * |
| 4414 | * @hide |
| 4415 | */ |
| 4416 | @TestApi |
| 4417 | @SystemApi |
| 4418 | public static final class Builder { |
| 4419 | private int mUid = Process.INVALID_UID; |
| 4420 | private @Nullable String mPackageName; |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 4421 | private @Nullable String mAttributionTag; |
Svet Ganov | 23c88db | 2019-01-22 20:38:11 -0800 | [diff] [blame] | 4422 | private @Nullable List<String> mOpNames; |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 4423 | private @HistoricalOpsRequestFilter int mFilter; |
Svet Ganov | 23c88db | 2019-01-22 20:38:11 -0800 | [diff] [blame] | 4424 | private final long mBeginTimeMillis; |
| 4425 | private final long mEndTimeMillis; |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 4426 | private @OpFlags int mFlags = OP_FLAGS_ALL; |
Svet Ganov | 23c88db | 2019-01-22 20:38:11 -0800 | [diff] [blame] | 4427 | |
| 4428 | /** |
| 4429 | * Creates a new builder. |
| 4430 | * |
| 4431 | * @param beginTimeMillis The beginning of the interval in milliseconds since |
| 4432 | * epoch start (January 1, 1970 00:00:00.000 GMT - Gregorian). Must be non |
| 4433 | * negative. |
| 4434 | * @param endTimeMillis The end of the interval in milliseconds since |
| 4435 | * epoch start (January 1, 1970 00:00:00.000 GMT - Gregorian). Must be after |
| 4436 | * {@code beginTimeMillis}. Pass {@link Long#MAX_VALUE} to get the most recent |
| 4437 | * history including ops that happen while this call is in flight. |
| 4438 | */ |
| 4439 | public Builder(long beginTimeMillis, long endTimeMillis) { |
| 4440 | Preconditions.checkArgument(beginTimeMillis >= 0 && beginTimeMillis < endTimeMillis, |
| 4441 | "beginTimeMillis must be non negative and lesser than endTimeMillis"); |
| 4442 | mBeginTimeMillis = beginTimeMillis; |
| 4443 | mEndTimeMillis = endTimeMillis; |
| 4444 | } |
| 4445 | |
| 4446 | /** |
| 4447 | * Sets the UID to query for. |
| 4448 | * |
| 4449 | * @param uid The uid. Pass {@link android.os.Process#INVALID_UID} for any uid. |
| 4450 | * @return This builder. |
| 4451 | */ |
| 4452 | public @NonNull Builder setUid(int uid) { |
| 4453 | Preconditions.checkArgument(uid == Process.INVALID_UID || uid >= 0, |
| 4454 | "uid must be " + Process.INVALID_UID + " or non negative"); |
| 4455 | mUid = uid; |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 4456 | |
| 4457 | if (uid == Process.INVALID_UID) { |
| 4458 | mFilter &= ~FILTER_BY_UID; |
| 4459 | } else { |
| 4460 | mFilter |= FILTER_BY_UID; |
| 4461 | } |
| 4462 | |
Svet Ganov | 23c88db | 2019-01-22 20:38:11 -0800 | [diff] [blame] | 4463 | return this; |
| 4464 | } |
| 4465 | |
| 4466 | /** |
| 4467 | * Sets the package to query for. |
| 4468 | * |
| 4469 | * @param packageName The package name. <code>Null</code> for any package. |
| 4470 | * @return This builder. |
| 4471 | */ |
| 4472 | public @NonNull Builder setPackageName(@Nullable String packageName) { |
| 4473 | mPackageName = packageName; |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 4474 | |
| 4475 | if (packageName == null) { |
| 4476 | mFilter &= ~FILTER_BY_PACKAGE_NAME; |
| 4477 | } else { |
| 4478 | mFilter |= FILTER_BY_PACKAGE_NAME; |
| 4479 | } |
| 4480 | |
| 4481 | return this; |
| 4482 | } |
| 4483 | |
| 4484 | /** |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 4485 | * Sets the attribution tag to query for. |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 4486 | * |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 4487 | * @param attributionTag attribution tag |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 4488 | * @return This builder. |
| 4489 | */ |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 4490 | public @NonNull Builder setAttributionTag(@Nullable String attributionTag) { |
| 4491 | mAttributionTag = attributionTag; |
| 4492 | mFilter |= FILTER_BY_ATTRIBUTION_TAG; |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 4493 | |
Svet Ganov | 23c88db | 2019-01-22 20:38:11 -0800 | [diff] [blame] | 4494 | return this; |
| 4495 | } |
| 4496 | |
| 4497 | /** |
| 4498 | * Sets the op names to query for. |
| 4499 | * |
| 4500 | * @param opNames The op names. <code>Null</code> for any op. |
| 4501 | * @return This builder. |
| 4502 | */ |
| 4503 | public @NonNull Builder setOpNames(@Nullable List<String> opNames) { |
| 4504 | if (opNames != null) { |
| 4505 | final int opCount = opNames.size(); |
| 4506 | for (int i = 0; i < opCount; i++) { |
| 4507 | Preconditions.checkArgument(AppOpsManager.strOpToOp( |
| 4508 | opNames.get(i)) != AppOpsManager.OP_NONE); |
| 4509 | } |
| 4510 | } |
| 4511 | mOpNames = opNames; |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 4512 | |
| 4513 | if (mOpNames == null) { |
| 4514 | mFilter &= ~FILTER_BY_OP_NAMES; |
| 4515 | } else { |
| 4516 | mFilter |= FILTER_BY_OP_NAMES; |
| 4517 | } |
| 4518 | |
Svet Ganov | 23c88db | 2019-01-22 20:38:11 -0800 | [diff] [blame] | 4519 | return this; |
| 4520 | } |
| 4521 | |
| 4522 | /** |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 4523 | * Sets the op flags to query for. The flags specify the type of |
| 4524 | * op data being queried. |
| 4525 | * |
| 4526 | * @param flags The flags which are any combination of |
| 4527 | * {@link #OP_FLAG_SELF}, {@link #OP_FLAG_TRUSTED_PROXY}, |
| 4528 | * {@link #OP_FLAG_UNTRUSTED_PROXY}, {@link #OP_FLAG_TRUSTED_PROXIED}, |
| 4529 | * {@link #OP_FLAG_UNTRUSTED_PROXIED}. You can use {@link #OP_FLAGS_ALL} |
| 4530 | * for any flag. |
| 4531 | * @return This builder. |
| 4532 | */ |
| 4533 | public @NonNull Builder setFlags(@OpFlags int flags) { |
| 4534 | Preconditions.checkFlagsArgument(flags, OP_FLAGS_ALL); |
| 4535 | mFlags = flags; |
| 4536 | return this; |
| 4537 | } |
| 4538 | |
| 4539 | /** |
Svet Ganov | 23c88db | 2019-01-22 20:38:11 -0800 | [diff] [blame] | 4540 | * @return a new {@link HistoricalOpsRequest}. |
| 4541 | */ |
| 4542 | public @NonNull HistoricalOpsRequest build() { |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 4543 | return new HistoricalOpsRequest(mUid, mPackageName, mAttributionTag, mOpNames, |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 4544 | mFilter, mBeginTimeMillis, mEndTimeMillis, mFlags); |
Svet Ganov | 23c88db | 2019-01-22 20:38:11 -0800 | [diff] [blame] | 4545 | } |
| 4546 | } |
| 4547 | } |
| 4548 | |
| 4549 | /** |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 4550 | * This class represents historical app op state of all UIDs for a given time interval. |
| 4551 | * |
| 4552 | * @hide |
| 4553 | */ |
| 4554 | @TestApi |
| 4555 | @SystemApi |
| 4556 | public static final class HistoricalOps implements Parcelable { |
| 4557 | private long mBeginTimeMillis; |
| 4558 | private long mEndTimeMillis; |
| 4559 | private @Nullable SparseArray<HistoricalUidOps> mHistoricalUidOps; |
| 4560 | |
| 4561 | /** @hide */ |
| 4562 | @TestApi |
| 4563 | public HistoricalOps(long beginTimeMillis, long endTimeMillis) { |
| 4564 | Preconditions.checkState(beginTimeMillis <= endTimeMillis); |
| 4565 | mBeginTimeMillis = beginTimeMillis; |
| 4566 | mEndTimeMillis = endTimeMillis; |
| 4567 | } |
| 4568 | |
| 4569 | /** @hide */ |
| 4570 | public HistoricalOps(@NonNull HistoricalOps other) { |
| 4571 | mBeginTimeMillis = other.mBeginTimeMillis; |
| 4572 | mEndTimeMillis = other.mEndTimeMillis; |
| 4573 | Preconditions.checkState(mBeginTimeMillis <= mEndTimeMillis); |
| 4574 | if (other.mHistoricalUidOps != null) { |
| 4575 | final int opCount = other.getUidCount(); |
| 4576 | for (int i = 0; i < opCount; i++) { |
| 4577 | final HistoricalUidOps origOps = other.getUidOpsAt(i); |
| 4578 | final HistoricalUidOps clonedOps = new HistoricalUidOps(origOps); |
| 4579 | if (mHistoricalUidOps == null) { |
| 4580 | mHistoricalUidOps = new SparseArray<>(opCount); |
| 4581 | } |
| 4582 | mHistoricalUidOps.put(clonedOps.getUid(), clonedOps); |
| 4583 | } |
| 4584 | } |
| 4585 | } |
| 4586 | |
| 4587 | private HistoricalOps(Parcel parcel) { |
| 4588 | mBeginTimeMillis = parcel.readLong(); |
| 4589 | mEndTimeMillis = parcel.readLong(); |
| 4590 | final int[] uids = parcel.createIntArray(); |
| 4591 | if (!ArrayUtils.isEmpty(uids)) { |
| 4592 | final ParceledListSlice<HistoricalUidOps> listSlice = parcel.readParcelable( |
| 4593 | HistoricalOps.class.getClassLoader()); |
| 4594 | final List<HistoricalUidOps> uidOps = (listSlice != null) |
| 4595 | ? listSlice.getList() : null; |
| 4596 | if (uidOps == null) { |
| 4597 | return; |
| 4598 | } |
| 4599 | for (int i = 0; i < uids.length; i++) { |
| 4600 | if (mHistoricalUidOps == null) { |
| 4601 | mHistoricalUidOps = new SparseArray<>(); |
| 4602 | } |
| 4603 | mHistoricalUidOps.put(uids[i], uidOps.get(i)); |
| 4604 | } |
| 4605 | } |
| 4606 | } |
| 4607 | |
| 4608 | /** |
| 4609 | * Splice a piece from the beginning of these ops. |
| 4610 | * |
| 4611 | * @param splicePoint The fraction of the data to be spliced off. |
| 4612 | * |
| 4613 | * @hide |
| 4614 | */ |
| 4615 | public @NonNull HistoricalOps spliceFromBeginning(double splicePoint) { |
| 4616 | return splice(splicePoint, true); |
| 4617 | } |
| 4618 | |
| 4619 | /** |
| 4620 | * Splice a piece from the end of these ops. |
| 4621 | * |
| 4622 | * @param fractionToRemove The fraction of the data to be spliced off. |
| 4623 | * |
| 4624 | * @hide |
| 4625 | */ |
| 4626 | public @NonNull HistoricalOps spliceFromEnd(double fractionToRemove) { |
| 4627 | return splice(fractionToRemove, false); |
| 4628 | } |
| 4629 | |
| 4630 | /** |
| 4631 | * Splice a piece from the beginning or end of these ops. |
| 4632 | * |
| 4633 | * @param fractionToRemove The fraction of the data to be spliced off. |
| 4634 | * @param beginning Whether to splice off the beginning or the end. |
| 4635 | * |
| 4636 | * @return The spliced off part. |
| 4637 | * |
| 4638 | * @hide |
| 4639 | */ |
| 4640 | private @Nullable HistoricalOps splice(double fractionToRemove, boolean beginning) { |
| 4641 | final long spliceBeginTimeMills; |
| 4642 | final long spliceEndTimeMills; |
| 4643 | if (beginning) { |
| 4644 | spliceBeginTimeMills = mBeginTimeMillis; |
| 4645 | spliceEndTimeMills = (long) (mBeginTimeMillis |
| 4646 | + getDurationMillis() * fractionToRemove); |
| 4647 | mBeginTimeMillis = spliceEndTimeMills; |
| 4648 | } else { |
| 4649 | spliceBeginTimeMills = (long) (mEndTimeMillis |
| 4650 | - getDurationMillis() * fractionToRemove); |
| 4651 | spliceEndTimeMills = mEndTimeMillis; |
| 4652 | mEndTimeMillis = spliceBeginTimeMills; |
| 4653 | } |
| 4654 | |
| 4655 | HistoricalOps splice = null; |
| 4656 | final int uidCount = getUidCount(); |
| 4657 | for (int i = 0; i < uidCount; i++) { |
| 4658 | final HistoricalUidOps origOps = getUidOpsAt(i); |
| 4659 | final HistoricalUidOps spliceOps = origOps.splice(fractionToRemove); |
| 4660 | if (spliceOps != null) { |
| 4661 | if (splice == null) { |
| 4662 | splice = new HistoricalOps(spliceBeginTimeMills, spliceEndTimeMills); |
| 4663 | } |
| 4664 | if (splice.mHistoricalUidOps == null) { |
| 4665 | splice.mHistoricalUidOps = new SparseArray<>(); |
| 4666 | } |
| 4667 | splice.mHistoricalUidOps.put(spliceOps.getUid(), spliceOps); |
| 4668 | } |
| 4669 | } |
| 4670 | return splice; |
| 4671 | } |
| 4672 | |
| 4673 | /** |
| 4674 | * Merge the passed ops into the current ones. The time interval is a |
| 4675 | * union of the current and passed in one and the passed in data is |
| 4676 | * folded into the data of this instance. |
| 4677 | * |
| 4678 | * @hide |
| 4679 | */ |
| 4680 | public void merge(@NonNull HistoricalOps other) { |
| 4681 | mBeginTimeMillis = Math.min(mBeginTimeMillis, other.mBeginTimeMillis); |
| 4682 | mEndTimeMillis = Math.max(mEndTimeMillis, other.mEndTimeMillis); |
| 4683 | final int uidCount = other.getUidCount(); |
| 4684 | for (int i = 0; i < uidCount; i++) { |
| 4685 | final HistoricalUidOps otherUidOps = other.getUidOpsAt(i); |
| 4686 | final HistoricalUidOps thisUidOps = getUidOps(otherUidOps.getUid()); |
| 4687 | if (thisUidOps != null) { |
| 4688 | thisUidOps.merge(otherUidOps); |
| 4689 | } else { |
| 4690 | if (mHistoricalUidOps == null) { |
| 4691 | mHistoricalUidOps = new SparseArray<>(); |
| 4692 | } |
| 4693 | mHistoricalUidOps.put(otherUidOps.getUid(), otherUidOps); |
| 4694 | } |
| 4695 | } |
| 4696 | } |
| 4697 | |
| 4698 | /** |
| 4699 | * AppPermissionUsage the ops to leave only the data we filter for. |
| 4700 | * |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 4701 | * @param uid Uid to filter for. |
| 4702 | * @param packageName Package to filter for. |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 4703 | * @param attributionTag attribution tag to filter for |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 4704 | * @param opNames Ops to filter for. |
| 4705 | * @param filter Which parameters to filter on. |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 4706 | * @param beginTimeMillis The begin time to filter for or {@link Long#MIN_VALUE} for all. |
| 4707 | * @param endTimeMillis The end time to filter for or {@link Long#MAX_VALUE} for all. |
| 4708 | * |
| 4709 | * @hide |
| 4710 | */ |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 4711 | public void filter(int uid, @Nullable String packageName, @Nullable String attributionTag, |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 4712 | @Nullable String[] opNames, @HistoricalOpsRequestFilter int filter, |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 4713 | long beginTimeMillis, long endTimeMillis) { |
| 4714 | final long durationMillis = getDurationMillis(); |
| 4715 | mBeginTimeMillis = Math.max(mBeginTimeMillis, beginTimeMillis); |
| 4716 | mEndTimeMillis = Math.min(mEndTimeMillis, endTimeMillis); |
| 4717 | final double scaleFactor = Math.min((double) (endTimeMillis - beginTimeMillis) |
| 4718 | / (double) durationMillis, 1); |
| 4719 | final int uidCount = getUidCount(); |
| 4720 | for (int i = uidCount - 1; i >= 0; i--) { |
| 4721 | final HistoricalUidOps uidOp = mHistoricalUidOps.valueAt(i); |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 4722 | if ((filter & FILTER_BY_UID) != 0 && uid != uidOp.getUid()) { |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 4723 | mHistoricalUidOps.removeAt(i); |
| 4724 | } else { |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 4725 | uidOp.filter(packageName, attributionTag, opNames, filter, scaleFactor); |
Stanislav Zholnin | 0d9499c | 2020-01-16 13:39:50 +0000 | [diff] [blame] | 4726 | if (uidOp.getPackageCount() == 0) { |
| 4727 | mHistoricalUidOps.removeAt(i); |
| 4728 | } |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 4729 | } |
| 4730 | } |
| 4731 | } |
| 4732 | |
| 4733 | /** @hide */ |
| 4734 | public boolean isEmpty() { |
| 4735 | if (getBeginTimeMillis() >= getEndTimeMillis()) { |
| 4736 | return true; |
| 4737 | } |
| 4738 | final int uidCount = getUidCount(); |
| 4739 | for (int i = uidCount - 1; i >= 0; i--) { |
| 4740 | final HistoricalUidOps uidOp = mHistoricalUidOps.valueAt(i); |
| 4741 | if (!uidOp.isEmpty()) { |
| 4742 | return false; |
| 4743 | } |
| 4744 | } |
| 4745 | return true; |
| 4746 | } |
| 4747 | |
| 4748 | /** @hide */ |
| 4749 | public long getDurationMillis() { |
| 4750 | return mEndTimeMillis - mBeginTimeMillis; |
| 4751 | } |
| 4752 | |
| 4753 | /** @hide */ |
| 4754 | @TestApi |
| 4755 | public void increaseAccessCount(int opCode, int uid, @NonNull String packageName, |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 4756 | @Nullable String attributionTag, @UidState int uidState, @OpFlags int flags, |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 4757 | long increment) { |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 4758 | getOrCreateHistoricalUidOps(uid).increaseAccessCount(opCode, |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 4759 | packageName, attributionTag, uidState, flags, increment); |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 4760 | } |
| 4761 | |
| 4762 | /** @hide */ |
| 4763 | @TestApi |
| 4764 | public void increaseRejectCount(int opCode, int uid, @NonNull String packageName, |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 4765 | @Nullable String attributionTag, @UidState int uidState, @OpFlags int flags, |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 4766 | long increment) { |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 4767 | getOrCreateHistoricalUidOps(uid).increaseRejectCount(opCode, |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 4768 | packageName, attributionTag, uidState, flags, increment); |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 4769 | } |
| 4770 | |
| 4771 | /** @hide */ |
| 4772 | @TestApi |
| 4773 | public void increaseAccessDuration(int opCode, int uid, @NonNull String packageName, |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 4774 | @Nullable String attributionTag, @UidState int uidState, @OpFlags int flags, |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 4775 | long increment) { |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 4776 | getOrCreateHistoricalUidOps(uid).increaseAccessDuration(opCode, |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 4777 | packageName, attributionTag, uidState, flags, increment); |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 4778 | } |
| 4779 | |
| 4780 | /** @hide */ |
| 4781 | @TestApi |
| 4782 | public void offsetBeginAndEndTime(long offsetMillis) { |
| 4783 | mBeginTimeMillis += offsetMillis; |
| 4784 | mEndTimeMillis += offsetMillis; |
| 4785 | } |
| 4786 | |
| 4787 | /** @hide */ |
| 4788 | public void setBeginAndEndTime(long beginTimeMillis, long endTimeMillis) { |
| 4789 | mBeginTimeMillis = beginTimeMillis; |
| 4790 | mEndTimeMillis = endTimeMillis; |
| 4791 | } |
| 4792 | |
| 4793 | /** @hide */ |
| 4794 | public void setBeginTime(long beginTimeMillis) { |
| 4795 | mBeginTimeMillis = beginTimeMillis; |
| 4796 | } |
| 4797 | |
| 4798 | /** @hide */ |
| 4799 | public void setEndTime(long endTimeMillis) { |
| 4800 | mEndTimeMillis = endTimeMillis; |
| 4801 | } |
| 4802 | |
| 4803 | /** |
| 4804 | * @return The beginning of the interval in milliseconds since |
| 4805 | * epoch start (January 1, 1970 00:00:00.000 GMT - Gregorian). |
| 4806 | */ |
| 4807 | public long getBeginTimeMillis() { |
| 4808 | return mBeginTimeMillis; |
| 4809 | } |
| 4810 | |
| 4811 | /** |
| 4812 | * @return The end of the interval in milliseconds since |
| 4813 | * epoch start (January 1, 1970 00:00:00.000 GMT - Gregorian). |
| 4814 | */ |
| 4815 | public long getEndTimeMillis() { |
| 4816 | return mEndTimeMillis; |
| 4817 | } |
| 4818 | |
| 4819 | /** |
| 4820 | * Gets number of UIDs with historical ops. |
| 4821 | * |
| 4822 | * @return The number of UIDs with historical ops. |
| 4823 | * |
| 4824 | * @see #getUidOpsAt(int) |
| 4825 | */ |
Svet Ganov | 00a46ef | 2019-03-29 21:13:03 -0700 | [diff] [blame] | 4826 | public @IntRange(from = 0) int getUidCount() { |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 4827 | if (mHistoricalUidOps == null) { |
| 4828 | return 0; |
| 4829 | } |
| 4830 | return mHistoricalUidOps.size(); |
| 4831 | } |
| 4832 | |
| 4833 | /** |
| 4834 | * Gets the historical UID ops at a given index. |
| 4835 | * |
| 4836 | * @param index The index. |
| 4837 | * |
| 4838 | * @return The historical UID ops at the given index. |
| 4839 | * |
| 4840 | * @see #getUidCount() |
| 4841 | */ |
Svet Ganov | 00a46ef | 2019-03-29 21:13:03 -0700 | [diff] [blame] | 4842 | public @NonNull HistoricalUidOps getUidOpsAt(@IntRange(from = 0) int index) { |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 4843 | if (mHistoricalUidOps == null) { |
| 4844 | throw new IndexOutOfBoundsException(); |
| 4845 | } |
| 4846 | return mHistoricalUidOps.valueAt(index); |
| 4847 | } |
| 4848 | |
| 4849 | /** |
| 4850 | * Gets the historical UID ops for a given UID. |
| 4851 | * |
| 4852 | * @param uid The UID. |
| 4853 | * |
| 4854 | * @return The historical ops for the UID. |
| 4855 | */ |
| 4856 | public @Nullable HistoricalUidOps getUidOps(int uid) { |
| 4857 | if (mHistoricalUidOps == null) { |
| 4858 | return null; |
| 4859 | } |
| 4860 | return mHistoricalUidOps.get(uid); |
| 4861 | } |
| 4862 | |
Winson | 4e3b435 | 2019-05-07 16:29:59 -0700 | [diff] [blame] | 4863 | /** @hide */ |
| 4864 | public void clearHistory(int uid, @NonNull String packageName) { |
| 4865 | HistoricalUidOps historicalUidOps = getOrCreateHistoricalUidOps(uid); |
| 4866 | historicalUidOps.clearHistory(packageName); |
| 4867 | if (historicalUidOps.isEmpty()) { |
| 4868 | mHistoricalUidOps.remove(uid); |
| 4869 | } |
| 4870 | } |
| 4871 | |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 4872 | @Override |
| 4873 | public int describeContents() { |
| 4874 | return 0; |
| 4875 | } |
| 4876 | |
| 4877 | @Override |
| 4878 | public void writeToParcel(Parcel parcel, int flags) { |
| 4879 | parcel.writeLong(mBeginTimeMillis); |
| 4880 | parcel.writeLong(mEndTimeMillis); |
| 4881 | if (mHistoricalUidOps != null) { |
| 4882 | final int uidCount = mHistoricalUidOps.size(); |
| 4883 | parcel.writeInt(uidCount); |
| 4884 | for (int i = 0; i < uidCount; i++) { |
| 4885 | parcel.writeInt(mHistoricalUidOps.keyAt(i)); |
| 4886 | } |
| 4887 | final List<HistoricalUidOps> opsList = new ArrayList<>(uidCount); |
| 4888 | for (int i = 0; i < uidCount; i++) { |
| 4889 | opsList.add(mHistoricalUidOps.valueAt(i)); |
| 4890 | } |
| 4891 | parcel.writeParcelable(new ParceledListSlice<>(opsList), flags); |
| 4892 | } else { |
| 4893 | parcel.writeInt(-1); |
| 4894 | } |
| 4895 | } |
| 4896 | |
| 4897 | /** |
| 4898 | * Accepts a visitor to traverse the ops tree. |
| 4899 | * |
| 4900 | * @param visitor The visitor. |
| 4901 | * |
| 4902 | * @hide |
| 4903 | */ |
| 4904 | public void accept(@NonNull HistoricalOpsVisitor visitor) { |
| 4905 | visitor.visitHistoricalOps(this); |
| 4906 | final int uidCount = getUidCount(); |
| 4907 | for (int i = 0; i < uidCount; i++) { |
| 4908 | getUidOpsAt(i).accept(visitor); |
| 4909 | } |
| 4910 | } |
| 4911 | |
| 4912 | private @NonNull HistoricalUidOps getOrCreateHistoricalUidOps(int uid) { |
| 4913 | if (mHistoricalUidOps == null) { |
| 4914 | mHistoricalUidOps = new SparseArray<>(); |
| 4915 | } |
| 4916 | HistoricalUidOps historicalUidOp = mHistoricalUidOps.get(uid); |
| 4917 | if (historicalUidOp == null) { |
| 4918 | historicalUidOp = new HistoricalUidOps(uid); |
| 4919 | mHistoricalUidOps.put(uid, historicalUidOp); |
| 4920 | } |
| 4921 | return historicalUidOp; |
| 4922 | } |
| 4923 | |
| 4924 | /** |
| 4925 | * @return Rounded value up at the 0.5 boundary. |
| 4926 | * |
| 4927 | * @hide |
| 4928 | */ |
| 4929 | public static double round(double value) { |
| 4930 | final BigDecimal decimalScale = new BigDecimal(value); |
| 4931 | return decimalScale.setScale(0, RoundingMode.HALF_UP).doubleValue(); |
| 4932 | } |
| 4933 | |
| 4934 | @Override |
Aurimas Liutikas | 4d1699d | 2019-08-28 13:01:05 -0700 | [diff] [blame] | 4935 | public boolean equals(@Nullable Object obj) { |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 4936 | if (this == obj) { |
| 4937 | return true; |
| 4938 | } |
| 4939 | if (obj == null || getClass() != obj.getClass()) { |
| 4940 | return false; |
| 4941 | } |
| 4942 | final HistoricalOps other = (HistoricalOps) obj; |
| 4943 | if (mBeginTimeMillis != other.mBeginTimeMillis) { |
| 4944 | return false; |
| 4945 | } |
| 4946 | if (mEndTimeMillis != other.mEndTimeMillis) { |
| 4947 | return false; |
| 4948 | } |
| 4949 | if (mHistoricalUidOps == null) { |
| 4950 | if (other.mHistoricalUidOps != null) { |
| 4951 | return false; |
| 4952 | } |
| 4953 | } else if (!mHistoricalUidOps.equals(other.mHistoricalUidOps)) { |
| 4954 | return false; |
| 4955 | } |
| 4956 | return true; |
| 4957 | } |
| 4958 | |
| 4959 | @Override |
| 4960 | public int hashCode() { |
| 4961 | int result = (int) (mBeginTimeMillis ^ (mBeginTimeMillis >>> 32)); |
| 4962 | result = 31 * result + mHistoricalUidOps.hashCode(); |
| 4963 | return result; |
| 4964 | } |
| 4965 | |
Aurimas Liutikas | 4d1699d | 2019-08-28 13:01:05 -0700 | [diff] [blame] | 4966 | @NonNull |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 4967 | @Override |
| 4968 | public String toString() { |
| 4969 | return getClass().getSimpleName() + "[from:" |
| 4970 | + mBeginTimeMillis + " to:" + mEndTimeMillis + "]"; |
| 4971 | } |
| 4972 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 4973 | public static final @android.annotation.NonNull Creator<HistoricalOps> CREATOR = new Creator<HistoricalOps>() { |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 4974 | @Override |
| 4975 | public @NonNull HistoricalOps createFromParcel(@NonNull Parcel parcel) { |
| 4976 | return new HistoricalOps(parcel); |
| 4977 | } |
| 4978 | |
| 4979 | @Override |
| 4980 | public @NonNull HistoricalOps[] newArray(int size) { |
| 4981 | return new HistoricalOps[size]; |
| 4982 | } |
| 4983 | }; |
| 4984 | } |
| 4985 | |
| 4986 | /** |
| 4987 | * This class represents historical app op state for a UID. |
| 4988 | * |
| 4989 | * @hide |
| 4990 | */ |
| 4991 | @TestApi |
| 4992 | @SystemApi |
| 4993 | public static final class HistoricalUidOps implements Parcelable { |
| 4994 | private final int mUid; |
| 4995 | private @Nullable ArrayMap<String, HistoricalPackageOps> mHistoricalPackageOps; |
| 4996 | |
| 4997 | /** @hide */ |
| 4998 | public HistoricalUidOps(int uid) { |
| 4999 | mUid = uid; |
| 5000 | } |
| 5001 | |
| 5002 | private HistoricalUidOps(@NonNull HistoricalUidOps other) { |
| 5003 | mUid = other.mUid; |
| 5004 | final int opCount = other.getPackageCount(); |
| 5005 | for (int i = 0; i < opCount; i++) { |
| 5006 | final HistoricalPackageOps origOps = other.getPackageOpsAt(i); |
| 5007 | final HistoricalPackageOps cloneOps = new HistoricalPackageOps(origOps); |
| 5008 | if (mHistoricalPackageOps == null) { |
| 5009 | mHistoricalPackageOps = new ArrayMap<>(opCount); |
| 5010 | } |
| 5011 | mHistoricalPackageOps.put(cloneOps.getPackageName(), cloneOps); |
| 5012 | } |
| 5013 | } |
| 5014 | |
| 5015 | private HistoricalUidOps(@NonNull Parcel parcel) { |
| 5016 | // No arg check since we always read from a trusted source. |
| 5017 | mUid = parcel.readInt(); |
| 5018 | mHistoricalPackageOps = parcel.createTypedArrayMap(HistoricalPackageOps.CREATOR); |
| 5019 | } |
| 5020 | |
| 5021 | private @Nullable HistoricalUidOps splice(double fractionToRemove) { |
| 5022 | HistoricalUidOps splice = null; |
| 5023 | final int packageCount = getPackageCount(); |
| 5024 | for (int i = 0; i < packageCount; i++) { |
| 5025 | final HistoricalPackageOps origOps = getPackageOpsAt(i); |
| 5026 | final HistoricalPackageOps spliceOps = origOps.splice(fractionToRemove); |
| 5027 | if (spliceOps != null) { |
| 5028 | if (splice == null) { |
| 5029 | splice = new HistoricalUidOps(mUid); |
| 5030 | } |
| 5031 | if (splice.mHistoricalPackageOps == null) { |
| 5032 | splice.mHistoricalPackageOps = new ArrayMap<>(); |
| 5033 | } |
| 5034 | splice.mHistoricalPackageOps.put(spliceOps.getPackageName(), spliceOps); |
| 5035 | } |
| 5036 | } |
| 5037 | return splice; |
| 5038 | } |
| 5039 | |
| 5040 | private void merge(@NonNull HistoricalUidOps other) { |
| 5041 | final int packageCount = other.getPackageCount(); |
| 5042 | for (int i = 0; i < packageCount; i++) { |
| 5043 | final HistoricalPackageOps otherPackageOps = other.getPackageOpsAt(i); |
| 5044 | final HistoricalPackageOps thisPackageOps = getPackageOps( |
| 5045 | otherPackageOps.getPackageName()); |
| 5046 | if (thisPackageOps != null) { |
| 5047 | thisPackageOps.merge(otherPackageOps); |
| 5048 | } else { |
| 5049 | if (mHistoricalPackageOps == null) { |
| 5050 | mHistoricalPackageOps = new ArrayMap<>(); |
| 5051 | } |
| 5052 | mHistoricalPackageOps.put(otherPackageOps.getPackageName(), otherPackageOps); |
| 5053 | } |
| 5054 | } |
| 5055 | } |
| 5056 | |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5057 | private void filter(@Nullable String packageName, @Nullable String attributionTag, |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5058 | @Nullable String[] opNames, @HistoricalOpsRequestFilter int filter, |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5059 | double fractionToRemove) { |
| 5060 | final int packageCount = getPackageCount(); |
| 5061 | for (int i = packageCount - 1; i >= 0; i--) { |
| 5062 | final HistoricalPackageOps packageOps = getPackageOpsAt(i); |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5063 | if ((filter & FILTER_BY_PACKAGE_NAME) != 0 && !packageName.equals( |
| 5064 | packageOps.getPackageName())) { |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5065 | mHistoricalPackageOps.removeAt(i); |
| 5066 | } else { |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5067 | packageOps.filter(attributionTag, opNames, filter, fractionToRemove); |
| 5068 | if (packageOps.getAttributedOpsCount() == 0) { |
Stanislav Zholnin | 0d9499c | 2020-01-16 13:39:50 +0000 | [diff] [blame] | 5069 | mHistoricalPackageOps.removeAt(i); |
| 5070 | } |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5071 | } |
| 5072 | } |
| 5073 | } |
| 5074 | |
| 5075 | private boolean isEmpty() { |
| 5076 | final int packageCount = getPackageCount(); |
| 5077 | for (int i = packageCount - 1; i >= 0; i--) { |
| 5078 | final HistoricalPackageOps packageOps = mHistoricalPackageOps.valueAt(i); |
| 5079 | if (!packageOps.isEmpty()) { |
| 5080 | return false; |
| 5081 | } |
| 5082 | } |
| 5083 | return true; |
| 5084 | } |
| 5085 | |
| 5086 | private void increaseAccessCount(int opCode, @NonNull String packageName, |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5087 | @Nullable String attributionTag, @UidState int uidState, @OpFlags int flags, |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5088 | long increment) { |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5089 | getOrCreateHistoricalPackageOps(packageName).increaseAccessCount( |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5090 | opCode, attributionTag, uidState, flags, increment); |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5091 | } |
| 5092 | |
| 5093 | private void increaseRejectCount(int opCode, @NonNull String packageName, |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5094 | @Nullable String attributionTag, @UidState int uidState, @OpFlags int flags, |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5095 | long increment) { |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5096 | getOrCreateHistoricalPackageOps(packageName).increaseRejectCount( |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5097 | opCode, attributionTag, uidState, flags, increment); |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5098 | } |
| 5099 | |
| 5100 | private void increaseAccessDuration(int opCode, @NonNull String packageName, |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5101 | @Nullable String attributionTag, @UidState int uidState, @OpFlags int flags, |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5102 | long increment) { |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5103 | getOrCreateHistoricalPackageOps(packageName).increaseAccessDuration( |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5104 | opCode, attributionTag, uidState, flags, increment); |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5105 | } |
| 5106 | |
| 5107 | /** |
| 5108 | * @return The UID for which the data is related. |
| 5109 | */ |
| 5110 | public int getUid() { |
| 5111 | return mUid; |
| 5112 | } |
| 5113 | |
| 5114 | /** |
| 5115 | * Gets number of packages with historical ops. |
| 5116 | * |
| 5117 | * @return The number of packages with historical ops. |
| 5118 | * |
| 5119 | * @see #getPackageOpsAt(int) |
| 5120 | */ |
Svet Ganov | 00a46ef | 2019-03-29 21:13:03 -0700 | [diff] [blame] | 5121 | public @IntRange(from = 0) int getPackageCount() { |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5122 | if (mHistoricalPackageOps == null) { |
| 5123 | return 0; |
| 5124 | } |
| 5125 | return mHistoricalPackageOps.size(); |
| 5126 | } |
| 5127 | |
| 5128 | /** |
| 5129 | * Gets the historical package ops at a given index. |
| 5130 | * |
| 5131 | * @param index The index. |
| 5132 | * |
| 5133 | * @return The historical package ops at the given index. |
| 5134 | * |
| 5135 | * @see #getPackageCount() |
| 5136 | */ |
Svet Ganov | 00a46ef | 2019-03-29 21:13:03 -0700 | [diff] [blame] | 5137 | public @NonNull HistoricalPackageOps getPackageOpsAt(@IntRange(from = 0) int index) { |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5138 | if (mHistoricalPackageOps == null) { |
| 5139 | throw new IndexOutOfBoundsException(); |
| 5140 | } |
| 5141 | return mHistoricalPackageOps.valueAt(index); |
| 5142 | } |
| 5143 | |
| 5144 | /** |
| 5145 | * Gets the historical package ops for a given package. |
| 5146 | * |
| 5147 | * @param packageName The package. |
| 5148 | * |
| 5149 | * @return The historical ops for the package. |
| 5150 | */ |
| 5151 | public @Nullable HistoricalPackageOps getPackageOps(@NonNull String packageName) { |
| 5152 | if (mHistoricalPackageOps == null) { |
| 5153 | return null; |
| 5154 | } |
| 5155 | return mHistoricalPackageOps.get(packageName); |
| 5156 | } |
| 5157 | |
Winson | 4e3b435 | 2019-05-07 16:29:59 -0700 | [diff] [blame] | 5158 | private void clearHistory(@NonNull String packageName) { |
| 5159 | if (mHistoricalPackageOps != null) { |
| 5160 | mHistoricalPackageOps.remove(packageName); |
| 5161 | } |
| 5162 | } |
| 5163 | |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5164 | @Override |
| 5165 | public int describeContents() { |
| 5166 | return 0; |
| 5167 | } |
| 5168 | |
| 5169 | @Override |
| 5170 | public void writeToParcel(Parcel parcel, int flags) { |
| 5171 | parcel.writeInt(mUid); |
| 5172 | parcel.writeTypedArrayMap(mHistoricalPackageOps, flags); |
| 5173 | } |
| 5174 | |
| 5175 | private void accept(@NonNull HistoricalOpsVisitor visitor) { |
| 5176 | visitor.visitHistoricalUidOps(this); |
| 5177 | final int packageCount = getPackageCount(); |
| 5178 | for (int i = 0; i < packageCount; i++) { |
| 5179 | getPackageOpsAt(i).accept(visitor); |
| 5180 | } |
| 5181 | } |
| 5182 | |
| 5183 | private @NonNull HistoricalPackageOps getOrCreateHistoricalPackageOps( |
| 5184 | @NonNull String packageName) { |
| 5185 | if (mHistoricalPackageOps == null) { |
| 5186 | mHistoricalPackageOps = new ArrayMap<>(); |
| 5187 | } |
| 5188 | HistoricalPackageOps historicalPackageOp = mHistoricalPackageOps.get(packageName); |
| 5189 | if (historicalPackageOp == null) { |
| 5190 | historicalPackageOp = new HistoricalPackageOps(packageName); |
| 5191 | mHistoricalPackageOps.put(packageName, historicalPackageOp); |
| 5192 | } |
| 5193 | return historicalPackageOp; |
| 5194 | } |
| 5195 | |
| 5196 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 5197 | public static final @android.annotation.NonNull Creator<HistoricalUidOps> CREATOR = new Creator<HistoricalUidOps>() { |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5198 | @Override |
| 5199 | public @NonNull HistoricalUidOps createFromParcel(@NonNull Parcel parcel) { |
| 5200 | return new HistoricalUidOps(parcel); |
| 5201 | } |
| 5202 | |
| 5203 | @Override |
| 5204 | public @NonNull HistoricalUidOps[] newArray(int size) { |
| 5205 | return new HistoricalUidOps[size]; |
| 5206 | } |
| 5207 | }; |
| 5208 | |
| 5209 | @Override |
Aurimas Liutikas | 4d1699d | 2019-08-28 13:01:05 -0700 | [diff] [blame] | 5210 | public boolean equals(@Nullable Object obj) { |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5211 | if (this == obj) { |
| 5212 | return true; |
| 5213 | } |
| 5214 | if (obj == null || getClass() != obj.getClass()) { |
| 5215 | return false; |
| 5216 | } |
| 5217 | final HistoricalUidOps other = (HistoricalUidOps) obj; |
| 5218 | if (mUid != other.mUid) { |
| 5219 | return false; |
| 5220 | } |
| 5221 | if (mHistoricalPackageOps == null) { |
| 5222 | if (other.mHistoricalPackageOps != null) { |
| 5223 | return false; |
| 5224 | } |
| 5225 | } else if (!mHistoricalPackageOps.equals(other.mHistoricalPackageOps)) { |
| 5226 | return false; |
| 5227 | } |
| 5228 | return true; |
| 5229 | } |
| 5230 | |
| 5231 | @Override |
| 5232 | public int hashCode() { |
| 5233 | int result = mUid; |
| 5234 | result = 31 * result + (mHistoricalPackageOps != null |
| 5235 | ? mHistoricalPackageOps.hashCode() : 0); |
| 5236 | return result; |
| 5237 | } |
| 5238 | } |
| 5239 | |
| 5240 | /** |
| 5241 | * This class represents historical app op information about a package. |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 5242 | * |
| 5243 | * @hide |
| 5244 | */ |
| 5245 | @TestApi |
| 5246 | @SystemApi |
| 5247 | public static final class HistoricalPackageOps implements Parcelable { |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 5248 | private final @NonNull String mPackageName; |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5249 | private @Nullable ArrayMap<String, AttributedHistoricalOps> mAttributedHistoricalOps; |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 5250 | |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5251 | /** @hide */ |
| 5252 | public HistoricalPackageOps(@NonNull String packageName) { |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 5253 | mPackageName = packageName; |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 5254 | } |
| 5255 | |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5256 | private HistoricalPackageOps(@NonNull HistoricalPackageOps other) { |
| 5257 | mPackageName = other.mPackageName; |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5258 | final int opCount = other.getAttributedOpsCount(); |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5259 | for (int i = 0; i < opCount; i++) { |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5260 | final AttributedHistoricalOps origOps = other.getAttributedOpsAt(i); |
| 5261 | final AttributedHistoricalOps cloneOps = new AttributedHistoricalOps(origOps); |
| 5262 | if (mAttributedHistoricalOps == null) { |
| 5263 | mAttributedHistoricalOps = new ArrayMap<>(opCount); |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5264 | } |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5265 | mAttributedHistoricalOps.put(cloneOps.getTag(), cloneOps); |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5266 | } |
| 5267 | } |
| 5268 | |
| 5269 | private HistoricalPackageOps(@NonNull Parcel parcel) { |
| 5270 | mPackageName = parcel.readString(); |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5271 | mAttributedHistoricalOps = parcel.createTypedArrayMap(AttributedHistoricalOps.CREATOR); |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5272 | } |
| 5273 | |
| 5274 | private @Nullable HistoricalPackageOps splice(double fractionToRemove) { |
| 5275 | HistoricalPackageOps splice = null; |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5276 | final int attributionCount = getAttributedOpsCount(); |
| 5277 | for (int i = 0; i < attributionCount; i++) { |
| 5278 | final AttributedHistoricalOps origOps = getAttributedOpsAt(i); |
| 5279 | final AttributedHistoricalOps spliceOps = origOps.splice(fractionToRemove); |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5280 | if (spliceOps != null) { |
| 5281 | if (splice == null) { |
| 5282 | splice = new HistoricalPackageOps(mPackageName); |
| 5283 | } |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5284 | if (splice.mAttributedHistoricalOps == null) { |
| 5285 | splice.mAttributedHistoricalOps = new ArrayMap<>(); |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5286 | } |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5287 | splice.mAttributedHistoricalOps.put(spliceOps.getTag(), spliceOps); |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5288 | } |
| 5289 | } |
| 5290 | return splice; |
| 5291 | } |
| 5292 | |
| 5293 | private void merge(@NonNull HistoricalPackageOps other) { |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5294 | final int attributionCount = other.getAttributedOpsCount(); |
| 5295 | for (int i = 0; i < attributionCount; i++) { |
| 5296 | final AttributedHistoricalOps otherAttributionOps = other.getAttributedOpsAt(i); |
| 5297 | final AttributedHistoricalOps thisAttributionOps = getAttributedOps( |
| 5298 | otherAttributionOps.getTag()); |
| 5299 | if (thisAttributionOps != null) { |
| 5300 | thisAttributionOps.merge(otherAttributionOps); |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5301 | } else { |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5302 | if (mAttributedHistoricalOps == null) { |
| 5303 | mAttributedHistoricalOps = new ArrayMap<>(); |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5304 | } |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5305 | mAttributedHistoricalOps.put(otherAttributionOps.getTag(), |
| 5306 | otherAttributionOps); |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5307 | } |
| 5308 | } |
| 5309 | } |
| 5310 | |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5311 | private void filter(@Nullable String attributionTag, @Nullable String[] opNames, |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5312 | @HistoricalOpsRequestFilter int filter, double fractionToRemove) { |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5313 | final int attributionCount = getAttributedOpsCount(); |
| 5314 | for (int i = attributionCount - 1; i >= 0; i--) { |
| 5315 | final AttributedHistoricalOps attributionOps = getAttributedOpsAt(i); |
| 5316 | if ((filter & FILTER_BY_ATTRIBUTION_TAG) != 0 && !Objects.equals(attributionTag, |
| 5317 | attributionOps.getTag())) { |
| 5318 | mAttributedHistoricalOps.removeAt(i); |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5319 | } else { |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5320 | attributionOps.filter(opNames, filter, fractionToRemove); |
| 5321 | if (attributionOps.getOpCount() == 0) { |
| 5322 | mAttributedHistoricalOps.removeAt(i); |
Stanislav Zholnin | 0d9499c | 2020-01-16 13:39:50 +0000 | [diff] [blame] | 5323 | } |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5324 | } |
| 5325 | } |
| 5326 | } |
| 5327 | |
| 5328 | private void accept(@NonNull HistoricalOpsVisitor visitor) { |
| 5329 | visitor.visitHistoricalPackageOps(this); |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5330 | final int attributionCount = getAttributedOpsCount(); |
| 5331 | for (int i = 0; i < attributionCount; i++) { |
| 5332 | getAttributedOpsAt(i).accept(visitor); |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5333 | } |
| 5334 | } |
| 5335 | |
| 5336 | private boolean isEmpty() { |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5337 | final int attributionCount = getAttributedOpsCount(); |
| 5338 | for (int i = attributionCount - 1; i >= 0; i--) { |
| 5339 | final AttributedHistoricalOps attributionOps = mAttributedHistoricalOps.valueAt(i); |
| 5340 | if (!attributionOps.isEmpty()) { |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5341 | return false; |
| 5342 | } |
| 5343 | } |
| 5344 | return true; |
| 5345 | } |
| 5346 | |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5347 | private void increaseAccessCount(int opCode, @Nullable String attributionTag, |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5348 | @UidState int uidState, @OpFlags int flags, long increment) { |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5349 | getOrCreateAttributedHistoricalOps(attributionTag).increaseAccessCount( |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5350 | opCode, uidState, flags, increment); |
| 5351 | } |
| 5352 | |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5353 | private void increaseRejectCount(int opCode, @Nullable String attributionTag, |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5354 | @UidState int uidState, @OpFlags int flags, long increment) { |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5355 | getOrCreateAttributedHistoricalOps(attributionTag).increaseRejectCount( |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5356 | opCode, uidState, flags, increment); |
| 5357 | } |
| 5358 | |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5359 | private void increaseAccessDuration(int opCode, @Nullable String attributionTag, |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5360 | @UidState int uidState, @OpFlags int flags, long increment) { |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5361 | getOrCreateAttributedHistoricalOps(attributionTag).increaseAccessDuration( |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5362 | opCode, uidState, flags, increment); |
| 5363 | } |
| 5364 | |
| 5365 | /** |
| 5366 | * Gets the package name which the data represents. |
| 5367 | * |
| 5368 | * @return The package name which the data represents. |
| 5369 | */ |
| 5370 | public @NonNull String getPackageName() { |
| 5371 | return mPackageName; |
| 5372 | } |
| 5373 | |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5374 | private @NonNull AttributedHistoricalOps getOrCreateAttributedHistoricalOps( |
| 5375 | @Nullable String attributionTag) { |
| 5376 | if (mAttributedHistoricalOps == null) { |
| 5377 | mAttributedHistoricalOps = new ArrayMap<>(); |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5378 | } |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5379 | AttributedHistoricalOps historicalAttributionOp = mAttributedHistoricalOps.get( |
| 5380 | attributionTag); |
| 5381 | if (historicalAttributionOp == null) { |
| 5382 | historicalAttributionOp = new AttributedHistoricalOps(attributionTag); |
| 5383 | mAttributedHistoricalOps.put(attributionTag, historicalAttributionOp); |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5384 | } |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5385 | return historicalAttributionOp; |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5386 | } |
| 5387 | |
| 5388 | /** |
| 5389 | * Gets number historical app ops. |
| 5390 | * |
| 5391 | * @return The number historical app ops. |
| 5392 | * @see #getOpAt(int) |
| 5393 | */ |
| 5394 | public @IntRange(from = 0) int getOpCount() { |
| 5395 | int numOps = 0; |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5396 | int numAttributions = getAttributedOpsCount(); |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5397 | |
| 5398 | for (int code = 0; code < _NUM_OP; code++) { |
| 5399 | String opName = opToPublicName(code); |
| 5400 | |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5401 | for (int attributionNum = 0; attributionNum < numAttributions; attributionNum++) { |
| 5402 | if (getAttributedOpsAt(attributionNum).getOp(opName) != null) { |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5403 | numOps++; |
| 5404 | break; |
| 5405 | } |
| 5406 | } |
| 5407 | } |
| 5408 | |
| 5409 | return numOps; |
| 5410 | } |
| 5411 | |
| 5412 | /** |
| 5413 | * Gets the historical op at a given index. |
| 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 index The index to lookup. |
| 5418 | * @return The op at the given index. |
| 5419 | * @see #getOpCount() |
| 5420 | */ |
| 5421 | public @NonNull HistoricalOp getOpAt(@IntRange(from = 0) int index) { |
| 5422 | int numOpsFound = 0; |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5423 | int numAttributions = getAttributedOpsCount(); |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5424 | |
| 5425 | for (int code = 0; code < _NUM_OP; code++) { |
| 5426 | String opName = opToPublicName(code); |
| 5427 | |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5428 | for (int attributionNum = 0; attributionNum < numAttributions; attributionNum++) { |
| 5429 | if (getAttributedOpsAt(attributionNum).getOp(opName) != null) { |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5430 | if (numOpsFound == index) { |
| 5431 | return getOp(opName); |
| 5432 | } else { |
| 5433 | numOpsFound++; |
| 5434 | break; |
| 5435 | } |
| 5436 | } |
| 5437 | } |
| 5438 | } |
| 5439 | |
| 5440 | throw new IndexOutOfBoundsException(); |
| 5441 | } |
| 5442 | |
| 5443 | /** |
| 5444 | * Gets the historical entry for a given op name. |
| 5445 | * |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5446 | * <p>This combines the counts from all attributions. |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5447 | * |
| 5448 | * @param opName The op name. |
| 5449 | * @return The historical entry for that op name. |
| 5450 | */ |
| 5451 | public @Nullable HistoricalOp getOp(@NonNull String opName) { |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5452 | if (mAttributedHistoricalOps == null) { |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5453 | return null; |
| 5454 | } |
| 5455 | |
| 5456 | HistoricalOp combinedOp = null; |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5457 | int numAttributions = getAttributedOpsCount(); |
| 5458 | for (int i = 0; i < numAttributions; i++) { |
| 5459 | HistoricalOp attributionOp = getAttributedOpsAt(i).getOp(opName); |
| 5460 | if (attributionOp != null) { |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5461 | if (combinedOp == null) { |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5462 | combinedOp = new HistoricalOp(attributionOp); |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5463 | } else { |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5464 | combinedOp.merge(attributionOp); |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5465 | } |
| 5466 | } |
| 5467 | } |
| 5468 | |
| 5469 | return combinedOp; |
| 5470 | } |
| 5471 | |
| 5472 | @Override |
| 5473 | public int describeContents() { |
| 5474 | return 0; |
| 5475 | } |
| 5476 | |
| 5477 | @Override |
| 5478 | public void writeToParcel(@NonNull Parcel parcel, int flags) { |
| 5479 | parcel.writeString(mPackageName); |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5480 | parcel.writeTypedArrayMap(mAttributedHistoricalOps, flags); |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5481 | } |
| 5482 | |
| 5483 | public static final @android.annotation.NonNull Creator<HistoricalPackageOps> CREATOR = |
| 5484 | new Creator<HistoricalPackageOps>() { |
| 5485 | @Override |
| 5486 | public @NonNull HistoricalPackageOps createFromParcel(@NonNull Parcel parcel) { |
| 5487 | return new HistoricalPackageOps(parcel); |
| 5488 | } |
| 5489 | |
| 5490 | @Override |
| 5491 | public @NonNull HistoricalPackageOps[] newArray(int size) { |
| 5492 | return new HistoricalPackageOps[size]; |
| 5493 | } |
| 5494 | }; |
| 5495 | |
| 5496 | @Override |
| 5497 | public boolean equals(@Nullable Object obj) { |
| 5498 | if (this == obj) { |
| 5499 | return true; |
| 5500 | } |
| 5501 | if (obj == null || getClass() != obj.getClass()) { |
| 5502 | return false; |
| 5503 | } |
| 5504 | final HistoricalPackageOps other = (HistoricalPackageOps) obj; |
| 5505 | if (!mPackageName.equals(other.mPackageName)) { |
| 5506 | return false; |
| 5507 | } |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5508 | if (mAttributedHistoricalOps == null) { |
| 5509 | if (other.mAttributedHistoricalOps != null) { |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5510 | return false; |
| 5511 | } |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5512 | } else if (!mAttributedHistoricalOps.equals(other.mAttributedHistoricalOps)) { |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5513 | return false; |
| 5514 | } |
| 5515 | return true; |
| 5516 | } |
| 5517 | |
| 5518 | @Override |
| 5519 | public int hashCode() { |
| 5520 | int result = mPackageName != null ? mPackageName.hashCode() : 0; |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5521 | result = 31 * result + (mAttributedHistoricalOps != null |
| 5522 | ? mAttributedHistoricalOps.hashCode() : 0); |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5523 | return result; |
| 5524 | } |
| 5525 | |
| 5526 | /** |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5527 | * Gets number of attributed historical ops. |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5528 | * |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5529 | * @return The number of attribution with historical ops. |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5530 | * |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5531 | * @see #getAttributedOpsAt(int) |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5532 | */ |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5533 | public @IntRange(from = 0) int getAttributedOpsCount() { |
| 5534 | if (mAttributedHistoricalOps == null) { |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5535 | return 0; |
| 5536 | } |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5537 | return mAttributedHistoricalOps.size(); |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5538 | } |
| 5539 | |
| 5540 | /** |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5541 | * Gets the attributed historical ops at a given index. |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5542 | * |
| 5543 | * @param index The index. |
| 5544 | * |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5545 | * @return The historical attribution ops at the given index. |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5546 | * |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5547 | * @see #getAttributedOpsCount() |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5548 | */ |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5549 | public @NonNull AttributedHistoricalOps getAttributedOpsAt(@IntRange(from = 0) int index) { |
| 5550 | if (mAttributedHistoricalOps == null) { |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5551 | throw new IndexOutOfBoundsException(); |
| 5552 | } |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5553 | return mAttributedHistoricalOps.valueAt(index); |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5554 | } |
| 5555 | |
| 5556 | /** |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5557 | * Gets the attributed historical ops for a given attribution tag. |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5558 | * |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5559 | * @param attributionTag The attribution tag. |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5560 | * |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5561 | * @return The historical ops for the attribution. |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5562 | */ |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5563 | public @Nullable AttributedHistoricalOps getAttributedOps(@NonNull String attributionTag) { |
| 5564 | if (mAttributedHistoricalOps == null) { |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5565 | return null; |
| 5566 | } |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5567 | return mAttributedHistoricalOps.get(attributionTag); |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5568 | } |
| 5569 | } |
| 5570 | |
| 5571 | /** |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5572 | * 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] | 5573 | * |
| 5574 | * @hide |
| 5575 | */ |
| 5576 | @TestApi |
| 5577 | @SystemApi |
| 5578 | /* codegen verifier cannot deal with nested class parameters |
| 5579 | @DataClass(genHiddenConstructor = true, |
| 5580 | genEqualsHashCode = true, genHiddenCopyConstructor = true) */ |
| 5581 | @DataClass.Suppress("getHistoricalOps") |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5582 | public static final class AttributedHistoricalOps implements Parcelable { |
| 5583 | /** {@link Context#createAttributionContext attribution} tag */ |
| 5584 | private final @Nullable String mTag; |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5585 | |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5586 | /** Ops for this attribution */ |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5587 | private @Nullable ArrayMap<String, HistoricalOp> mHistoricalOps; |
| 5588 | |
| 5589 | /** @hide */ |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5590 | public AttributedHistoricalOps(@NonNull String tag) { |
| 5591 | mTag = tag; |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5592 | } |
| 5593 | |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5594 | private AttributedHistoricalOps(@NonNull AttributedHistoricalOps other) { |
| 5595 | mTag = other.mTag; |
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 origOp = other.getOpAt(i); |
| 5599 | final HistoricalOp cloneOp = new HistoricalOp(origOp); |
| 5600 | if (mHistoricalOps == null) { |
| 5601 | mHistoricalOps = new ArrayMap<>(opCount); |
| 5602 | } |
| 5603 | mHistoricalOps.put(cloneOp.getOpName(), cloneOp); |
| 5604 | } |
| 5605 | } |
| 5606 | |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5607 | private @Nullable AttributedHistoricalOps splice(double fractionToRemove) { |
| 5608 | AttributedHistoricalOps splice = null; |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5609 | final int opCount = getOpCount(); |
| 5610 | for (int i = 0; i < opCount; i++) { |
| 5611 | final HistoricalOp origOps = getOpAt(i); |
| 5612 | final HistoricalOp spliceOps = origOps.splice(fractionToRemove); |
| 5613 | if (spliceOps != null) { |
| 5614 | if (splice == null) { |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5615 | splice = new AttributedHistoricalOps(mTag, null); |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5616 | } |
| 5617 | if (splice.mHistoricalOps == null) { |
| 5618 | splice.mHistoricalOps = new ArrayMap<>(); |
| 5619 | } |
| 5620 | splice.mHistoricalOps.put(spliceOps.getOpName(), spliceOps); |
| 5621 | } |
| 5622 | } |
| 5623 | return splice; |
| 5624 | } |
| 5625 | |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5626 | private void merge(@NonNull AttributedHistoricalOps other) { |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5627 | final int opCount = other.getOpCount(); |
| 5628 | for (int i = 0; i < opCount; i++) { |
| 5629 | final HistoricalOp otherOp = other.getOpAt(i); |
| 5630 | final HistoricalOp thisOp = getOp(otherOp.getOpName()); |
| 5631 | if (thisOp != null) { |
| 5632 | thisOp.merge(otherOp); |
| 5633 | } else { |
| 5634 | if (mHistoricalOps == null) { |
| 5635 | mHistoricalOps = new ArrayMap<>(); |
| 5636 | } |
| 5637 | mHistoricalOps.put(otherOp.getOpName(), otherOp); |
| 5638 | } |
| 5639 | } |
| 5640 | } |
| 5641 | |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5642 | private void filter(@Nullable String[] opNames, @HistoricalOpsRequestFilter int filter, |
| 5643 | double scaleFactor) { |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5644 | final int opCount = getOpCount(); |
| 5645 | for (int i = opCount - 1; i >= 0; i--) { |
| 5646 | final HistoricalOp op = mHistoricalOps.valueAt(i); |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5647 | if ((filter & FILTER_BY_OP_NAMES) != 0 && !ArrayUtils.contains(opNames, |
| 5648 | op.getOpName())) { |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5649 | mHistoricalOps.removeAt(i); |
| 5650 | } else { |
| 5651 | op.filter(scaleFactor); |
| 5652 | } |
| 5653 | } |
| 5654 | } |
| 5655 | |
| 5656 | private boolean isEmpty() { |
| 5657 | final int opCount = getOpCount(); |
| 5658 | for (int i = opCount - 1; i >= 0; i--) { |
| 5659 | final HistoricalOp op = mHistoricalOps.valueAt(i); |
| 5660 | if (!op.isEmpty()) { |
| 5661 | return false; |
| 5662 | } |
| 5663 | } |
| 5664 | return true; |
| 5665 | } |
| 5666 | |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 5667 | private void increaseAccessCount(int opCode, @UidState int uidState, |
| 5668 | @OpFlags int flags, long increment) { |
| 5669 | getOrCreateHistoricalOp(opCode).increaseAccessCount(uidState, flags, increment); |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5670 | } |
| 5671 | |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 5672 | private void increaseRejectCount(int opCode, @UidState int uidState, |
| 5673 | @OpFlags int flags, long increment) { |
| 5674 | getOrCreateHistoricalOp(opCode).increaseRejectCount(uidState, flags, increment); |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5675 | } |
| 5676 | |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 5677 | private void increaseAccessDuration(int opCode, @UidState int uidState, |
| 5678 | @OpFlags int flags, long increment) { |
| 5679 | getOrCreateHistoricalOp(opCode).increaseAccessDuration(uidState, flags, increment); |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 5680 | } |
| 5681 | |
| 5682 | /** |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5683 | * Gets number historical app ops. |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 5684 | * |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5685 | * @return The number historical app ops. |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5686 | * @see #getOpAt(int) |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 5687 | */ |
Svet Ganov | 00a46ef | 2019-03-29 21:13:03 -0700 | [diff] [blame] | 5688 | public @IntRange(from = 0) int getOpCount() { |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5689 | if (mHistoricalOps == null) { |
| 5690 | return 0; |
| 5691 | } |
| 5692 | return mHistoricalOps.size(); |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 5693 | } |
| 5694 | |
| 5695 | /** |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5696 | * Gets the historical op at a given index. |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 5697 | * |
| 5698 | * @param index The index to lookup. |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5699 | * @return The op at the given index. |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5700 | * @see #getOpCount() |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 5701 | */ |
Svet Ganov | 00a46ef | 2019-03-29 21:13:03 -0700 | [diff] [blame] | 5702 | public @NonNull HistoricalOp getOpAt(@IntRange(from = 0) int index) { |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5703 | if (mHistoricalOps == null) { |
| 5704 | throw new IndexOutOfBoundsException(); |
| 5705 | } |
| 5706 | return mHistoricalOps.valueAt(index); |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 5707 | } |
| 5708 | |
| 5709 | /** |
| 5710 | * Gets the historical entry for a given op name. |
| 5711 | * |
| 5712 | * @param opName The op name. |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 5713 | * @return The historical entry for that op name. |
| 5714 | */ |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5715 | public @Nullable HistoricalOp getOp(@NonNull String opName) { |
| 5716 | if (mHistoricalOps == null) { |
| 5717 | return null; |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 5718 | } |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5719 | return mHistoricalOps.get(opName); |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 5720 | } |
| 5721 | |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5722 | private void accept(@NonNull HistoricalOpsVisitor visitor) { |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5723 | visitor.visitHistoricalAttributionOps(this); |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5724 | final int opCount = getOpCount(); |
| 5725 | for (int i = 0; i < opCount; i++) { |
| 5726 | getOpAt(i).accept(visitor); |
| 5727 | } |
| 5728 | } |
| 5729 | |
| 5730 | private @NonNull HistoricalOp getOrCreateHistoricalOp(int opCode) { |
| 5731 | if (mHistoricalOps == null) { |
| 5732 | mHistoricalOps = new ArrayMap<>(); |
| 5733 | } |
| 5734 | final String opStr = sOpToString[opCode]; |
| 5735 | HistoricalOp op = mHistoricalOps.get(opStr); |
| 5736 | if (op == null) { |
| 5737 | op = new HistoricalOp(opCode); |
| 5738 | mHistoricalOps.put(opStr, op); |
| 5739 | } |
| 5740 | return op; |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 5741 | } |
| 5742 | |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5743 | |
| 5744 | |
| 5745 | // Code below generated by codegen v1.0.14. |
| 5746 | // |
| 5747 | // DO NOT MODIFY! |
| 5748 | // CHECKSTYLE:OFF Generated code |
| 5749 | // |
| 5750 | // To regenerate run: |
| 5751 | // $ codegen $ANDROID_BUILD_TOP/frameworks/base/core/java/android/app/AppOpsManager.java |
| 5752 | // |
| 5753 | // To exclude the generated code from IntelliJ auto-formatting enable (one-time): |
| 5754 | // Settings > Editor > Code Style > Formatter Control |
| 5755 | //@formatter:off |
| 5756 | |
| 5757 | |
| 5758 | /** |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5759 | * Creates a new HistoricalAttributionOps. |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5760 | * |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5761 | * @param tag |
| 5762 | * {@link Context#createAttributionContext attribution} tag |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5763 | * @param historicalOps |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5764 | * Ops for this attribution |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5765 | * @hide |
| 5766 | */ |
| 5767 | @DataClass.Generated.Member |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5768 | public AttributedHistoricalOps( |
| 5769 | @Nullable String tag, |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5770 | @Nullable ArrayMap<String,HistoricalOp> historicalOps) { |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5771 | this.mTag = tag; |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5772 | this.mHistoricalOps = historicalOps; |
| 5773 | |
| 5774 | // onConstructed(); // You can define this method to get a callback |
| 5775 | } |
| 5776 | |
| 5777 | /** |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5778 | * {@link Context#createAttributionContext attribution} tag |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5779 | */ |
| 5780 | @DataClass.Generated.Member |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5781 | public @Nullable String getTag() { |
| 5782 | return mTag; |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5783 | } |
| 5784 | |
| 5785 | @Override |
| 5786 | @DataClass.Generated.Member |
| 5787 | public boolean equals(@Nullable Object o) { |
| 5788 | // 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] | 5789 | // boolean fieldNameEquals(HistoricalAttributionOps other) { ... } |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5790 | // boolean fieldNameEquals(FieldType otherValue) { ... } |
| 5791 | |
| 5792 | if (this == o) return true; |
| 5793 | if (o == null || getClass() != o.getClass()) return false; |
| 5794 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5795 | AttributedHistoricalOps that = (AttributedHistoricalOps) o; |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5796 | //noinspection PointlessBooleanExpression |
| 5797 | return true |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5798 | && Objects.equals(mTag, that.mTag) |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5799 | && Objects.equals(mHistoricalOps, that.mHistoricalOps); |
| 5800 | } |
| 5801 | |
| 5802 | @Override |
| 5803 | @DataClass.Generated.Member |
| 5804 | public int hashCode() { |
| 5805 | // You can override field hashCode logic by defining methods like: |
| 5806 | // int fieldNameHashCode() { ... } |
| 5807 | |
| 5808 | int _hash = 1; |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5809 | _hash = 31 * _hash + Objects.hashCode(mTag); |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5810 | _hash = 31 * _hash + Objects.hashCode(mHistoricalOps); |
| 5811 | return _hash; |
| 5812 | } |
| 5813 | |
| 5814 | @Override |
| 5815 | @DataClass.Generated.Member |
| 5816 | public void writeToParcel(@NonNull Parcel dest, int flags) { |
| 5817 | // You can override field parcelling by defining methods like: |
| 5818 | // void parcelFieldName(Parcel dest, int flags) { ... } |
| 5819 | |
| 5820 | byte flg = 0; |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5821 | if (mTag != null) flg |= 0x1; |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5822 | if (mHistoricalOps != null) flg |= 0x2; |
| 5823 | dest.writeByte(flg); |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5824 | if (mTag != null) dest.writeString(mTag); |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5825 | if (mHistoricalOps != null) dest.writeMap(mHistoricalOps); |
| 5826 | } |
| 5827 | |
| 5828 | @Override |
| 5829 | @DataClass.Generated.Member |
| 5830 | public int describeContents() { return 0; } |
| 5831 | |
| 5832 | /** @hide */ |
| 5833 | @SuppressWarnings({"unchecked", "RedundantCast"}) |
| 5834 | @DataClass.Generated.Member |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5835 | /* package-private */ AttributedHistoricalOps(@NonNull Parcel in) { |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5836 | // You can override field unparcelling by defining methods like: |
| 5837 | // static FieldType unparcelFieldName(Parcel in) { ... } |
| 5838 | |
| 5839 | byte flg = in.readByte(); |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5840 | String attributionTag = (flg & 0x1) == 0 ? null : in.readString(); |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5841 | ArrayMap<String,HistoricalOp> historicalOps = null; |
| 5842 | if ((flg & 0x2) != 0) { |
| 5843 | historicalOps = new ArrayMap(); |
| 5844 | in.readMap(historicalOps, HistoricalOp.class.getClassLoader()); |
| 5845 | } |
| 5846 | |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5847 | this.mTag = attributionTag; |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5848 | this.mHistoricalOps = historicalOps; |
| 5849 | |
| 5850 | // onConstructed(); // You can define this method to get a callback |
| 5851 | } |
| 5852 | |
| 5853 | @DataClass.Generated.Member |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5854 | public static final @NonNull Parcelable.Creator<AttributedHistoricalOps> CREATOR |
| 5855 | = new Parcelable.Creator<AttributedHistoricalOps>() { |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 5856 | @Override |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5857 | public AttributedHistoricalOps[] newArray(int size) { |
| 5858 | return new AttributedHistoricalOps[size]; |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 5859 | } |
| 5860 | |
| 5861 | @Override |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5862 | public AttributedHistoricalOps createFromParcel(@NonNull Parcel in) { |
| 5863 | return new AttributedHistoricalOps(in); |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 5864 | } |
| 5865 | }; |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5866 | |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5867 | /* |
| 5868 | @DataClass.Generated( |
| 5869 | time = 1578113234821L, |
| 5870 | codegenVersion = "1.0.14", |
| 5871 | sourceFile = "frameworks/base/core/java/android/app/AppOpsManager.java", |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 5872 | 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] | 5873 | @Deprecated |
| 5874 | private void __metadata() {} |
| 5875 | */ |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5876 | |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 5877 | //@formatter:on |
| 5878 | // End of generated code |
| 5879 | |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 5880 | } |
| 5881 | |
| 5882 | /** |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5883 | * This class represents historical information about an app op. |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 5884 | * |
| 5885 | * @hide |
| 5886 | */ |
| 5887 | @TestApi |
| 5888 | @SystemApi |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5889 | public static final class HistoricalOp implements Parcelable { |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 5890 | private final int mOp; |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 5891 | private @Nullable LongSparseLongArray mAccessCount; |
| 5892 | private @Nullable LongSparseLongArray mRejectCount; |
| 5893 | private @Nullable LongSparseLongArray mAccessDuration; |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 5894 | |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5895 | /** @hide */ |
| 5896 | public HistoricalOp(int op) { |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 5897 | mOp = op; |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 5898 | } |
| 5899 | |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5900 | private HistoricalOp(@NonNull HistoricalOp other) { |
| 5901 | mOp = other.mOp; |
| 5902 | if (other.mAccessCount != null) { |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 5903 | mAccessCount = other.mAccessCount.clone(); |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5904 | } |
| 5905 | if (other.mRejectCount != null) { |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 5906 | mRejectCount = other.mRejectCount.clone(); |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5907 | } |
| 5908 | if (other.mAccessDuration != null) { |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 5909 | mAccessDuration = other.mAccessDuration.clone(); |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5910 | } |
| 5911 | } |
| 5912 | |
| 5913 | private HistoricalOp(@NonNull Parcel parcel) { |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 5914 | mOp = parcel.readInt(); |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 5915 | mAccessCount = readLongSparseLongArrayFromParcel(parcel); |
| 5916 | mRejectCount = readLongSparseLongArrayFromParcel(parcel); |
| 5917 | mAccessDuration = readLongSparseLongArrayFromParcel(parcel); |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 5918 | } |
| 5919 | |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5920 | private void filter(double scaleFactor) { |
| 5921 | scale(mAccessCount, scaleFactor); |
| 5922 | scale(mRejectCount, scaleFactor); |
| 5923 | scale(mAccessDuration, scaleFactor); |
| 5924 | } |
| 5925 | |
| 5926 | private boolean isEmpty() { |
| 5927 | return !hasData(mAccessCount) |
| 5928 | && !hasData(mRejectCount) |
| 5929 | && !hasData(mAccessDuration); |
| 5930 | } |
| 5931 | |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 5932 | private boolean hasData(@NonNull LongSparseLongArray array) { |
| 5933 | return (array != null && array.size() > 0); |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5934 | } |
| 5935 | |
| 5936 | private @Nullable HistoricalOp splice(double fractionToRemove) { |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 5937 | final HistoricalOp splice = new HistoricalOp(mOp); |
| 5938 | splice(mAccessCount, splice::getOrCreateAccessCount, fractionToRemove); |
| 5939 | splice(mRejectCount, splice::getOrCreateRejectCount, fractionToRemove); |
| 5940 | splice(mAccessDuration, splice::getOrCreateAccessDuration, fractionToRemove); |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5941 | return splice; |
| 5942 | } |
| 5943 | |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 5944 | private static void splice(@Nullable LongSparseLongArray sourceContainer, |
| 5945 | @NonNull Supplier<LongSparseLongArray> destContainerProvider, |
| 5946 | double fractionToRemove) { |
| 5947 | if (sourceContainer != null) { |
| 5948 | final int size = sourceContainer.size(); |
| 5949 | for (int i = 0; i < size; i++) { |
| 5950 | final long key = sourceContainer.keyAt(i); |
| 5951 | final long value = sourceContainer.valueAt(i); |
| 5952 | final long removedFraction = Math.round(value * fractionToRemove); |
| 5953 | if (removedFraction > 0) { |
| 5954 | destContainerProvider.get().put(key, removedFraction); |
| 5955 | sourceContainer.put(key, value - removedFraction); |
| 5956 | } |
| 5957 | } |
| 5958 | } |
| 5959 | } |
| 5960 | |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5961 | private void merge(@NonNull HistoricalOp other) { |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 5962 | merge(this::getOrCreateAccessCount, other.mAccessCount); |
| 5963 | merge(this::getOrCreateRejectCount, other.mRejectCount); |
| 5964 | merge(this::getOrCreateAccessDuration, other.mAccessDuration); |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5965 | } |
| 5966 | |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 5967 | private void increaseAccessCount(@UidState int uidState, @OpFlags int flags, |
| 5968 | long increment) { |
| 5969 | increaseCount(getOrCreateAccessCount(), uidState, flags, increment); |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5970 | } |
| 5971 | |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 5972 | private void increaseRejectCount(@UidState int uidState, @OpFlags int flags, |
| 5973 | long increment) { |
| 5974 | increaseCount(getOrCreateRejectCount(), uidState, flags, increment); |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5975 | } |
| 5976 | |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 5977 | private void increaseAccessDuration(@UidState int uidState, @OpFlags int flags, |
| 5978 | long increment) { |
| 5979 | increaseCount(getOrCreateAccessDuration(), uidState, flags, increment); |
| 5980 | } |
| 5981 | |
| 5982 | private void increaseCount(@NonNull LongSparseLongArray counts, |
| 5983 | @UidState int uidState, @OpFlags int flags, long increment) { |
| 5984 | while (flags != 0) { |
| 5985 | final int flag = 1 << Integer.numberOfTrailingZeros(flags); |
| 5986 | flags &= ~flag; |
| 5987 | final long key = makeKey(uidState, flag); |
| 5988 | counts.put(key, counts.get(key) + increment); |
| 5989 | } |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 5990 | } |
| 5991 | |
| 5992 | /** |
| 5993 | * Gets the op name. |
| 5994 | * |
| 5995 | * @return The op name. |
| 5996 | */ |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5997 | public @NonNull String getOpName() { |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 5998 | return sOpToString[mOp]; |
| 5999 | } |
| 6000 | |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 6001 | /** @hide */ |
| 6002 | public int getOpCode() { |
| 6003 | return mOp; |
| 6004 | } |
| 6005 | |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 6006 | /** |
| 6007 | * Gets the number times the op was accessed (performed) in the foreground. |
| 6008 | * |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 6009 | * @param flags The flags which are any combination of |
| 6010 | * {@link #OP_FLAG_SELF}, {@link #OP_FLAG_TRUSTED_PROXY}, |
| 6011 | * {@link #OP_FLAG_UNTRUSTED_PROXY}, {@link #OP_FLAG_TRUSTED_PROXIED}, |
| 6012 | * {@link #OP_FLAG_UNTRUSTED_PROXIED}. You can use {@link #OP_FLAGS_ALL} |
| 6013 | * for any flag. |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 6014 | * @return The times the op was accessed in the foreground. |
| 6015 | * |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 6016 | * @see #getBackgroundAccessCount(int) |
| 6017 | * @see #getAccessCount(int, int, int) |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 6018 | */ |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 6019 | public long getForegroundAccessCount(@OpFlags int flags) { |
| 6020 | return sumForFlagsInStates(mAccessCount, MAX_PRIORITY_UID_STATE, |
| 6021 | resolveFirstUnrestrictedUidState(mOp), flags); |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 6022 | } |
| 6023 | |
| 6024 | /** |
| 6025 | * Gets the number times the op was accessed (performed) in the background. |
| 6026 | * |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 6027 | * @param flags The flags which are any combination of |
| 6028 | * {@link #OP_FLAG_SELF}, {@link #OP_FLAG_TRUSTED_PROXY}, |
| 6029 | * {@link #OP_FLAG_UNTRUSTED_PROXY}, {@link #OP_FLAG_TRUSTED_PROXIED}, |
| 6030 | * {@link #OP_FLAG_UNTRUSTED_PROXIED}. You can use {@link #OP_FLAGS_ALL} |
| 6031 | * for any flag. |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 6032 | * @return The times the op was accessed in the background. |
| 6033 | * |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 6034 | * @see #getForegroundAccessCount(int) |
| 6035 | * @see #getAccessCount(int, int, int) |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 6036 | */ |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 6037 | public long getBackgroundAccessCount(@OpFlags int flags) { |
| 6038 | return sumForFlagsInStates(mAccessCount, resolveLastRestrictedUidState(mOp), |
| 6039 | MIN_PRIORITY_UID_STATE, flags); |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 6040 | } |
| 6041 | |
| 6042 | /** |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 6043 | * Gets the number times the op was accessed (performed) for a |
| 6044 | * range of uid states. |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 6045 | * |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 6046 | * @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] | 6047 | * {@link #UID_STATE_PERSISTENT}, {@link #UID_STATE_TOP}, |
| 6048 | * {@link #UID_STATE_FOREGROUND_SERVICE}, {@link #UID_STATE_FOREGROUND}, |
| 6049 | * {@link #UID_STATE_BACKGROUND}, {@link #UID_STATE_CACHED}. |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 6050 | * @param toUidState The UID state to which to query. |
| 6051 | * @param flags The flags which are any combination of |
| 6052 | * {@link #OP_FLAG_SELF}, {@link #OP_FLAG_TRUSTED_PROXY}, |
| 6053 | * {@link #OP_FLAG_UNTRUSTED_PROXY}, {@link #OP_FLAG_TRUSTED_PROXIED}, |
| 6054 | * {@link #OP_FLAG_UNTRUSTED_PROXIED}. You can use {@link #OP_FLAGS_ALL} |
| 6055 | * for any flag. |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 6056 | * |
| 6057 | * @return The times the op was accessed for the given UID state. |
| 6058 | * |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 6059 | * @see #getForegroundAccessCount(int) |
| 6060 | * @see #getBackgroundAccessCount(int) |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 6061 | */ |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 6062 | public long getAccessCount(@UidState int fromUidState, @UidState int toUidState, |
| 6063 | @OpFlags int flags) { |
| 6064 | return sumForFlagsInStates(mAccessCount, fromUidState, toUidState, flags); |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 6065 | } |
| 6066 | |
| 6067 | /** |
| 6068 | * Gets the number times the op was rejected in the foreground. |
| 6069 | * |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 6070 | * @param flags The flags which are any combination of |
| 6071 | * {@link #OP_FLAG_SELF}, {@link #OP_FLAG_TRUSTED_PROXY}, |
| 6072 | * {@link #OP_FLAG_UNTRUSTED_PROXY}, {@link #OP_FLAG_TRUSTED_PROXIED}, |
| 6073 | * {@link #OP_FLAG_UNTRUSTED_PROXIED}. You can use {@link #OP_FLAGS_ALL} |
| 6074 | * for any flag. |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 6075 | * @return The times the op was rejected in the foreground. |
| 6076 | * |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 6077 | * @see #getBackgroundRejectCount(int) |
| 6078 | * @see #getRejectCount(int, int, int) |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 6079 | */ |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 6080 | public long getForegroundRejectCount(@OpFlags int flags) { |
| 6081 | return sumForFlagsInStates(mRejectCount, MAX_PRIORITY_UID_STATE, |
| 6082 | resolveFirstUnrestrictedUidState(mOp), flags); |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 6083 | } |
| 6084 | |
| 6085 | /** |
| 6086 | * Gets the number times the op was rejected in the background. |
| 6087 | * |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 6088 | * @param flags The flags which are any combination of |
| 6089 | * {@link #OP_FLAG_SELF}, {@link #OP_FLAG_TRUSTED_PROXY}, |
| 6090 | * {@link #OP_FLAG_UNTRUSTED_PROXY}, {@link #OP_FLAG_TRUSTED_PROXIED}, |
| 6091 | * {@link #OP_FLAG_UNTRUSTED_PROXIED}. You can use {@link #OP_FLAGS_ALL} |
| 6092 | * for any flag. |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 6093 | * @return The times the op was rejected in the background. |
| 6094 | * |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 6095 | * @see #getForegroundRejectCount(int) |
| 6096 | * @see #getRejectCount(int, int, int) |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 6097 | */ |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 6098 | public long getBackgroundRejectCount(@OpFlags int flags) { |
| 6099 | return sumForFlagsInStates(mRejectCount, resolveLastRestrictedUidState(mOp), |
| 6100 | MIN_PRIORITY_UID_STATE, flags); |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 6101 | } |
| 6102 | |
| 6103 | /** |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 6104 | * 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] | 6105 | * |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 6106 | * @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] | 6107 | * {@link #UID_STATE_PERSISTENT}, {@link #UID_STATE_TOP}, |
| 6108 | * {@link #UID_STATE_FOREGROUND_SERVICE}, {@link #UID_STATE_FOREGROUND}, |
| 6109 | * {@link #UID_STATE_BACKGROUND}, {@link #UID_STATE_CACHED}. |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 6110 | * @param toUidState The UID state to which to query. |
| 6111 | * @param flags The flags which are any combination of |
| 6112 | * {@link #OP_FLAG_SELF}, {@link #OP_FLAG_TRUSTED_PROXY}, |
| 6113 | * {@link #OP_FLAG_UNTRUSTED_PROXY}, {@link #OP_FLAG_TRUSTED_PROXIED}, |
| 6114 | * {@link #OP_FLAG_UNTRUSTED_PROXIED}. You can use {@link #OP_FLAGS_ALL} |
| 6115 | * for any flag. |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 6116 | * |
| 6117 | * @return The times the op was rejected for the given UID state. |
| 6118 | * |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 6119 | * @see #getForegroundRejectCount(int) |
| 6120 | * @see #getBackgroundRejectCount(int) |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 6121 | */ |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 6122 | public long getRejectCount(@UidState int fromUidState, @UidState int toUidState, |
| 6123 | @OpFlags int flags) { |
| 6124 | return sumForFlagsInStates(mRejectCount, fromUidState, toUidState, flags); |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 6125 | } |
| 6126 | |
| 6127 | /** |
| 6128 | * 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] | 6129 | * The duration is in wall time. |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 6130 | * |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 6131 | * @param flags The flags which are any combination of |
| 6132 | * {@link #OP_FLAG_SELF}, {@link #OP_FLAG_TRUSTED_PROXY}, |
| 6133 | * {@link #OP_FLAG_UNTRUSTED_PROXY}, {@link #OP_FLAG_TRUSTED_PROXIED}, |
| 6134 | * {@link #OP_FLAG_UNTRUSTED_PROXIED}. You can use {@link #OP_FLAGS_ALL} |
| 6135 | * for any flag. |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 6136 | * @return The total duration the app op was accessed in the foreground. |
| 6137 | * |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 6138 | * @see #getBackgroundAccessDuration(int) |
| 6139 | * @see #getAccessDuration(int, int, int) |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 6140 | */ |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 6141 | public long getForegroundAccessDuration(@OpFlags int flags) { |
| 6142 | return sumForFlagsInStates(mAccessDuration, MAX_PRIORITY_UID_STATE, |
| 6143 | resolveFirstUnrestrictedUidState(mOp), flags); |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 6144 | } |
| 6145 | |
| 6146 | /** |
| 6147 | * 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] | 6148 | * The duration is in wall time. |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 6149 | * |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 6150 | * @param flags The flags which are any combination of |
| 6151 | * {@link #OP_FLAG_SELF}, {@link #OP_FLAG_TRUSTED_PROXY}, |
| 6152 | * {@link #OP_FLAG_UNTRUSTED_PROXY}, {@link #OP_FLAG_TRUSTED_PROXIED}, |
| 6153 | * {@link #OP_FLAG_UNTRUSTED_PROXIED}. You can use {@link #OP_FLAGS_ALL} |
| 6154 | * for any flag. |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 6155 | * @return The total duration the app op was accessed in the background. |
| 6156 | * |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 6157 | * @see #getForegroundAccessDuration(int) |
| 6158 | * @see #getAccessDuration(int, int, int) |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 6159 | */ |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 6160 | public long getBackgroundAccessDuration(@OpFlags int flags) { |
| 6161 | return sumForFlagsInStates(mAccessDuration, resolveLastRestrictedUidState(mOp), |
| 6162 | MIN_PRIORITY_UID_STATE, flags); |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 6163 | } |
| 6164 | |
| 6165 | /** |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 6166 | * 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] | 6167 | * range of UID states. The duration is in wall time. |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 6168 | * |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 6169 | * @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] | 6170 | * {@link #UID_STATE_PERSISTENT}, {@link #UID_STATE_TOP}, |
| 6171 | * {@link #UID_STATE_FOREGROUND_SERVICE}, {@link #UID_STATE_FOREGROUND}, |
| 6172 | * {@link #UID_STATE_BACKGROUND}, {@link #UID_STATE_CACHED}. |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 6173 | * @param toUidState The UID state from which to query. |
| 6174 | * @param flags The flags which are any combination of |
| 6175 | * {@link #OP_FLAG_SELF}, {@link #OP_FLAG_TRUSTED_PROXY}, |
| 6176 | * {@link #OP_FLAG_UNTRUSTED_PROXY}, {@link #OP_FLAG_TRUSTED_PROXIED}, |
| 6177 | * {@link #OP_FLAG_UNTRUSTED_PROXIED}. You can use {@link #OP_FLAGS_ALL} |
| 6178 | * for any flag. |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 6179 | * |
| 6180 | * @return The total duration the app op was accessed for the given UID state. |
| 6181 | * |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 6182 | * @see #getForegroundAccessDuration(int) |
| 6183 | * @see #getBackgroundAccessDuration(int) |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 6184 | */ |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 6185 | public long getAccessDuration(@UidState int fromUidState, @UidState int toUidState, |
| 6186 | @OpFlags int flags) { |
| 6187 | return sumForFlagsInStates(mAccessDuration, fromUidState, toUidState, flags); |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 6188 | } |
| 6189 | |
| 6190 | @Override |
| 6191 | public int describeContents() { |
| 6192 | return 0; |
| 6193 | } |
| 6194 | |
| 6195 | @Override |
| 6196 | public void writeToParcel(Parcel parcel, int flags) { |
| 6197 | parcel.writeInt(mOp); |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 6198 | writeLongSparseLongArrayToParcel(mAccessCount, parcel); |
| 6199 | writeLongSparseLongArrayToParcel(mRejectCount, parcel); |
| 6200 | writeLongSparseLongArrayToParcel(mAccessDuration, parcel); |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 6201 | } |
| 6202 | |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 6203 | @Override |
Aurimas Liutikas | 4d1699d | 2019-08-28 13:01:05 -0700 | [diff] [blame] | 6204 | public boolean equals(@Nullable Object obj) { |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 6205 | if (this == obj) { |
| 6206 | return true; |
| 6207 | } |
| 6208 | if (obj == null || getClass() != obj.getClass()) { |
| 6209 | return false; |
| 6210 | } |
| 6211 | final HistoricalOp other = (HistoricalOp) obj; |
| 6212 | if (mOp != other.mOp) { |
| 6213 | return false; |
| 6214 | } |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 6215 | if (!equalsLongSparseLongArray(mAccessCount, other.mAccessCount)) { |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 6216 | return false; |
| 6217 | } |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 6218 | if (!equalsLongSparseLongArray(mRejectCount, other.mRejectCount)) { |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 6219 | return false; |
| 6220 | } |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 6221 | return equalsLongSparseLongArray(mAccessDuration, other.mAccessDuration); |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 6222 | } |
| 6223 | |
| 6224 | @Override |
| 6225 | public int hashCode() { |
| 6226 | int result = mOp; |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 6227 | result = 31 * result + Objects.hashCode(mAccessCount); |
| 6228 | result = 31 * result + Objects.hashCode(mRejectCount); |
| 6229 | result = 31 * result + Objects.hashCode(mAccessDuration); |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 6230 | return result; |
| 6231 | } |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 6232 | |
| 6233 | private void accept(@NonNull HistoricalOpsVisitor visitor) { |
| 6234 | visitor.visitHistoricalOp(this); |
| 6235 | } |
| 6236 | |
| 6237 | private @NonNull LongSparseLongArray getOrCreateAccessCount() { |
| 6238 | if (mAccessCount == null) { |
| 6239 | mAccessCount = new LongSparseLongArray(); |
| 6240 | } |
| 6241 | return mAccessCount; |
| 6242 | } |
| 6243 | |
| 6244 | private @NonNull LongSparseLongArray getOrCreateRejectCount() { |
| 6245 | if (mRejectCount == null) { |
| 6246 | mRejectCount = new LongSparseLongArray(); |
| 6247 | } |
| 6248 | return mRejectCount; |
| 6249 | } |
| 6250 | |
| 6251 | private @NonNull LongSparseLongArray getOrCreateAccessDuration() { |
| 6252 | if (mAccessDuration == null) { |
| 6253 | mAccessDuration = new LongSparseLongArray(); |
| 6254 | } |
| 6255 | return mAccessDuration; |
| 6256 | } |
| 6257 | |
| 6258 | /** |
| 6259 | * Multiplies the entries in the array with the passed in scale factor and |
| 6260 | * rounds the result at up 0.5 boundary. |
| 6261 | * |
| 6262 | * @param data The data to scale. |
| 6263 | * @param scaleFactor The scale factor. |
| 6264 | */ |
| 6265 | private static void scale(@NonNull LongSparseLongArray data, double scaleFactor) { |
| 6266 | if (data != null) { |
| 6267 | final int size = data.size(); |
| 6268 | for (int i = 0; i < size; i++) { |
| 6269 | data.put(data.keyAt(i), (long) HistoricalOps.round( |
| 6270 | (double) data.valueAt(i) * scaleFactor)); |
| 6271 | } |
| 6272 | } |
| 6273 | } |
| 6274 | |
| 6275 | /** |
| 6276 | * Merges two arrays while lazily acquiring the destination. |
| 6277 | * |
| 6278 | * @param thisSupplier The destination supplier. |
| 6279 | * @param other The array to merge in. |
| 6280 | */ |
| 6281 | private static void merge(@NonNull Supplier<LongSparseLongArray> thisSupplier, |
| 6282 | @Nullable LongSparseLongArray other) { |
| 6283 | if (other != null) { |
| 6284 | final int otherSize = other.size(); |
| 6285 | for (int i = 0; i < otherSize; i++) { |
| 6286 | final LongSparseLongArray that = thisSupplier.get(); |
| 6287 | final long otherKey = other.keyAt(i); |
| 6288 | final long otherValue = other.valueAt(i); |
| 6289 | that.put(otherKey, that.get(otherKey) + otherValue); |
| 6290 | } |
| 6291 | } |
| 6292 | } |
| 6293 | |
| 6294 | /** @hide */ |
| 6295 | public @Nullable LongSparseArray<Object> collectKeys() { |
| 6296 | LongSparseArray<Object> result = AppOpsManager.collectKeys(mAccessCount, |
| 6297 | null /*result*/); |
| 6298 | result = AppOpsManager.collectKeys(mRejectCount, result); |
| 6299 | result = AppOpsManager.collectKeys(mAccessDuration, result); |
| 6300 | return result; |
| 6301 | } |
| 6302 | |
| 6303 | public static final @android.annotation.NonNull Creator<HistoricalOp> CREATOR = |
| 6304 | new Creator<HistoricalOp>() { |
| 6305 | @Override |
| 6306 | public @NonNull HistoricalOp createFromParcel(@NonNull Parcel source) { |
| 6307 | return new HistoricalOp(source); |
| 6308 | } |
| 6309 | |
| 6310 | @Override |
| 6311 | public @NonNull HistoricalOp[] newArray(int size) { |
| 6312 | return new HistoricalOp[size]; |
| 6313 | } |
| 6314 | }; |
| 6315 | } |
| 6316 | |
| 6317 | /** |
| 6318 | * Computes the sum of the counts for the given flags in between the begin and |
| 6319 | * end UID states. |
| 6320 | * |
| 6321 | * @param counts The data array. |
Philip P. Moltmann | 4052d36 | 2019-09-19 14:52:38 -0700 | [diff] [blame] | 6322 | * @param beginUidState The beginning UID state (inclusive). |
| 6323 | * @param endUidState The end UID state (inclusive). |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 6324 | * @param flags The UID flags. |
| 6325 | * @return The sum. |
| 6326 | */ |
| 6327 | private static long sumForFlagsInStates(@Nullable LongSparseLongArray counts, |
| 6328 | @UidState int beginUidState, @UidState int endUidState, @OpFlags int flags) { |
| 6329 | if (counts == null) { |
| 6330 | return 0; |
| 6331 | } |
| 6332 | long sum = 0; |
| 6333 | while (flags != 0) { |
| 6334 | final int flag = 1 << Integer.numberOfTrailingZeros(flags); |
| 6335 | flags &= ~flag; |
| 6336 | for (int uidState : UID_STATES) { |
| 6337 | if (uidState < beginUidState || uidState > endUidState) { |
| 6338 | continue; |
| 6339 | } |
| 6340 | final long key = makeKey(uidState, flag); |
| 6341 | sum += counts.get(key); |
| 6342 | } |
| 6343 | } |
| 6344 | return sum; |
| 6345 | } |
| 6346 | |
| 6347 | /** |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 6348 | * Callback for notification of changes to operation state. |
| 6349 | */ |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 6350 | public interface OnOpChangedListener { |
| 6351 | public void onOpChanged(String op, String packageName); |
| 6352 | } |
| 6353 | |
| 6354 | /** |
Svetoslav Ganov | 2d20fb4 | 2018-02-08 15:52:10 -0800 | [diff] [blame] | 6355 | * Callback for notification of changes to operation active state. |
Svetoslav Ganov | 2d20fb4 | 2018-02-08 15:52:10 -0800 | [diff] [blame] | 6356 | */ |
| 6357 | public interface OnOpActiveChangedListener { |
| 6358 | /** |
Philip P. Moltmann | a04b9ab | 2020-02-13 09:54:04 -0800 | [diff] [blame] | 6359 | * Called when the active state of an app-op changes. |
Svetoslav Ganov | 2d20fb4 | 2018-02-08 15:52:10 -0800 | [diff] [blame] | 6360 | * |
Jeff Sharkey | 7095ab9 | 2019-08-20 16:50:28 -0600 | [diff] [blame] | 6361 | * @param op The operation that changed. |
Svetoslav Ganov | 2d20fb4 | 2018-02-08 15:52:10 -0800 | [diff] [blame] | 6362 | * @param packageName The package performing the operation. |
| 6363 | * @param active Whether the operation became active or inactive. |
| 6364 | */ |
Jeff Sharkey | 7095ab9 | 2019-08-20 16:50:28 -0600 | [diff] [blame] | 6365 | void onOpActiveChanged(@NonNull String op, int uid, @NonNull String packageName, |
| 6366 | boolean active); |
Svetoslav Ganov | 2d20fb4 | 2018-02-08 15:52:10 -0800 | [diff] [blame] | 6367 | } |
| 6368 | |
| 6369 | /** |
Svet Ganov | b3d2ae2 | 2018-12-17 22:06:15 -0800 | [diff] [blame] | 6370 | * Callback for notification of an op being noted. |
| 6371 | * |
| 6372 | * @hide |
| 6373 | */ |
| 6374 | public interface OnOpNotedListener { |
| 6375 | /** |
| 6376 | * Called when an op was noted. |
| 6377 | * |
| 6378 | * @param code The op code. |
| 6379 | * @param uid The UID performing the operation. |
| 6380 | * @param packageName The package performing the operation. |
| 6381 | * @param result The result of the note. |
| 6382 | */ |
Fabian Kozynski | 0b4592c | 2018-12-20 12:58:45 -0500 | [diff] [blame] | 6383 | void onOpNoted(int code, int uid, String packageName, int result); |
Svet Ganov | b3d2ae2 | 2018-12-17 22:06:15 -0800 | [diff] [blame] | 6384 | } |
| 6385 | |
| 6386 | /** |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 6387 | * Callback for notification of changes to operation state. |
| 6388 | * This allows you to see the raw op codes instead of strings. |
| 6389 | * @hide |
| 6390 | */ |
| 6391 | public static class OnOpChangedInternalListener implements OnOpChangedListener { |
| 6392 | public void onOpChanged(String op, String packageName) { } |
| 6393 | public void onOpChanged(int op, String packageName) { } |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 6394 | } |
| 6395 | |
Jeff Sharkey | 7095ab9 | 2019-08-20 16:50:28 -0600 | [diff] [blame] | 6396 | /** |
| 6397 | * Callback for notification of changes to operation state. |
| 6398 | * This allows you to see the raw op codes instead of strings. |
| 6399 | * @hide |
| 6400 | */ |
| 6401 | public interface OnOpActiveChangedInternalListener extends OnOpActiveChangedListener { |
| 6402 | default void onOpActiveChanged(String op, int uid, String packageName, boolean active) { } |
| 6403 | default void onOpActiveChanged(int op, int uid, String packageName, boolean active) { } |
| 6404 | } |
| 6405 | |
Adam Bookatz | 182862e | 2020-04-27 21:58:22 -0700 | [diff] [blame] | 6406 | /** |
| 6407 | * Callback for notification of an op being started. |
| 6408 | * |
| 6409 | * @hide |
| 6410 | */ |
| 6411 | public interface OnOpStartedListener { |
| 6412 | /** |
| 6413 | * Called when an op was started. |
| 6414 | * |
| 6415 | * Note: This is only for op starts. It is not called when an op is noted or stopped. |
| 6416 | * |
| 6417 | * @param op The op code. |
| 6418 | * @param uid The UID performing the operation. |
| 6419 | * @param packageName The package performing the operation. |
| 6420 | * @param result The result of the start. |
| 6421 | */ |
| 6422 | void onOpStarted(int op, int uid, String packageName, int result); |
| 6423 | } |
| 6424 | |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 6425 | AppOpsManager(Context context, IAppOpsService service) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 6426 | mContext = context; |
| 6427 | mService = service; |
| 6428 | } |
| 6429 | |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 6430 | /** |
| 6431 | * Retrieve current operation state for all applications. |
| 6432 | * |
Winson | 6a864b5 | 2019-05-10 10:34:14 -0700 | [diff] [blame] | 6433 | * The mode of the ops returned are set for the package but may not reflect their effective |
| 6434 | * state due to UID policy or because it's controlled by a different master op. |
| 6435 | * |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 6436 | * Use {@link #unsafeCheckOp(String, int, String)}} or |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 6437 | * {@link #noteOp(String, int, String, String, String)} if the effective mode is needed. |
Winson | 6a864b5 | 2019-05-10 10:34:14 -0700 | [diff] [blame] | 6438 | * |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 6439 | * @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] | 6440 | * @hide |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 6441 | */ |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 6442 | @SystemApi |
| 6443 | @RequiresPermission(android.Manifest.permission.GET_APP_OPS_STATS) |
| 6444 | public @NonNull List<AppOpsManager.PackageOps> getPackagesForOps(@Nullable String[] ops) { |
| 6445 | final int opCount = ops.length; |
| 6446 | final int[] opCodes = new int[opCount]; |
| 6447 | for (int i = 0; i < opCount; i++) { |
| 6448 | opCodes[i] = sOpStrToOp.get(ops[i]); |
| 6449 | } |
| 6450 | final List<AppOpsManager.PackageOps> result = getPackagesForOps(opCodes); |
| 6451 | return (result != null) ? result : Collections.emptyList(); |
| 6452 | } |
| 6453 | |
| 6454 | /** |
| 6455 | * Retrieve current operation state for all applications. |
| 6456 | * |
Winson | 6a864b5 | 2019-05-10 10:34:14 -0700 | [diff] [blame] | 6457 | * The mode of the ops returned are set for the package but may not reflect their effective |
| 6458 | * state due to UID policy or because it's controlled by a different master op. |
| 6459 | * |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 6460 | * Use {@link #unsafeCheckOp(String, int, String)}} or |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 6461 | * {@link #noteOp(String, int, String, String, String)} if the effective mode is needed. |
Winson | 6a864b5 | 2019-05-10 10:34:14 -0700 | [diff] [blame] | 6462 | * |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 6463 | * @param ops The set of operations you are interested in, or null if you want all of them. |
| 6464 | * @hide |
| 6465 | */ |
Dianne Hackborn | c216a26 | 2018-04-26 13:46:22 -0700 | [diff] [blame] | 6466 | @RequiresPermission(android.Manifest.permission.GET_APP_OPS_STATS) |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 6467 | @UnsupportedAppUsage |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 6468 | public List<AppOpsManager.PackageOps> getPackagesForOps(int[] ops) { |
| 6469 | try { |
| 6470 | return mService.getPackagesForOps(ops); |
| 6471 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 6472 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 6473 | } |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 6474 | } |
| 6475 | |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 6476 | /** |
| 6477 | * Retrieve current operation state for one application. |
| 6478 | * |
Winson | 6a864b5 | 2019-05-10 10:34:14 -0700 | [diff] [blame] | 6479 | * The mode of the ops returned are set for the package but may not reflect their effective |
| 6480 | * state due to UID policy or because it's controlled by a different master op. |
| 6481 | * |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 6482 | * Use {@link #unsafeCheckOp(String, int, String)}} or |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 6483 | * {@link #noteOp(String, int, String, String, String)} if the effective mode is needed. |
Winson | 6a864b5 | 2019-05-10 10:34:14 -0700 | [diff] [blame] | 6484 | * |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 6485 | * @param uid The uid of the application of interest. |
| 6486 | * @param packageName The name of the application of interest. |
| 6487 | * @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] | 6488 | * |
| 6489 | * @deprecated The int op codes are not stable and you should use the string based op |
| 6490 | * names which are stable and namespaced. Use |
| 6491 | * {@link #getOpsForPackage(int, String, String...)})}. |
| 6492 | * |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 6493 | * @hide |
Suprabh Shukla | 169bed7 | 2019-05-13 13:54:58 -0700 | [diff] [blame] | 6494 | * @removed |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 6495 | */ |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 6496 | @Deprecated |
Dianne Hackborn | f0c322a | 2018-06-13 15:24:04 -0700 | [diff] [blame] | 6497 | @SystemApi |
Dianne Hackborn | c216a26 | 2018-04-26 13:46:22 -0700 | [diff] [blame] | 6498 | @RequiresPermission(android.Manifest.permission.GET_APP_OPS_STATS) |
Dianne Hackborn | 6287849 | 2019-03-11 15:57:07 -0700 | [diff] [blame] | 6499 | public @NonNull List<PackageOps> getOpsForPackage(int uid, @NonNull String packageName, |
| 6500 | @Nullable int[] ops) { |
Dianne Hackborn | 72e3983 | 2013-01-18 18:36:09 -0800 | [diff] [blame] | 6501 | try { |
| 6502 | return mService.getOpsForPackage(uid, packageName, ops); |
| 6503 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 6504 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 72e3983 | 2013-01-18 18:36:09 -0800 | [diff] [blame] | 6505 | } |
Dianne Hackborn | 72e3983 | 2013-01-18 18:36:09 -0800 | [diff] [blame] | 6506 | } |
| 6507 | |
Svet Ganov | ae0e03a | 2016-02-25 18:22:10 -0800 | [diff] [blame] | 6508 | /** |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 6509 | * Retrieve current operation state for one application. The UID and the |
| 6510 | * package must match. |
| 6511 | * |
Winson | 6a864b5 | 2019-05-10 10:34:14 -0700 | [diff] [blame] | 6512 | * The mode of the ops returned are set for the package but may not reflect their effective |
| 6513 | * state due to UID policy or because it's controlled by a different master op. |
| 6514 | * |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 6515 | * Use {@link #unsafeCheckOp(String, int, String)}} or |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 6516 | * {@link #noteOp(String, int, String, String, String)} if the effective mode is needed. |
Winson | 6a864b5 | 2019-05-10 10:34:14 -0700 | [diff] [blame] | 6517 | * |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 6518 | * @param uid The uid of the application of interest. |
| 6519 | * @param packageName The name of the application of interest. |
| 6520 | * @param ops The set of operations you are interested in, or null if you want all of them. |
| 6521 | * |
| 6522 | * @hide |
| 6523 | */ |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 6524 | @TestApi |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 6525 | @SystemApi |
| 6526 | @RequiresPermission(android.Manifest.permission.GET_APP_OPS_STATS) |
| 6527 | public @NonNull List<AppOpsManager.PackageOps> getOpsForPackage(int uid, |
| 6528 | @NonNull String packageName, @Nullable String... ops) { |
| 6529 | int[] opCodes = null; |
| 6530 | if (ops != null) { |
| 6531 | opCodes = new int[ops.length]; |
| 6532 | for (int i = 0; i < ops.length; i++) { |
| 6533 | opCodes[i] = strOpToOp(ops[i]); |
| 6534 | } |
| 6535 | } |
| 6536 | try { |
| 6537 | final List<PackageOps> result = mService.getOpsForPackage(uid, packageName, opCodes); |
| 6538 | if (result == null) { |
| 6539 | return Collections.emptyList(); |
| 6540 | } |
| 6541 | return result; |
| 6542 | } catch (RemoteException e) { |
| 6543 | throw e.rethrowFromSystemServer(); |
| 6544 | } |
| 6545 | } |
| 6546 | |
| 6547 | /** |
| 6548 | * Retrieve historical app op stats for a period. |
| 6549 | * |
Svet Ganov | 23c88db | 2019-01-22 20:38:11 -0800 | [diff] [blame] | 6550 | * @param request A request object describing the data being queried for. |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 6551 | * @param executor Executor on which to run the callback. If <code>null</code> |
| 6552 | * the callback is executed on the default executor running on the main thread. |
| 6553 | * @param callback Callback on which to deliver the result. |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 6554 | * |
| 6555 | * @throws IllegalArgumentException If any of the argument contracts is violated. |
| 6556 | * |
| 6557 | * @hide |
| 6558 | */ |
| 6559 | @TestApi |
| 6560 | @SystemApi |
| 6561 | @RequiresPermission(android.Manifest.permission.GET_APP_OPS_STATS) |
Svet Ganov | 23c88db | 2019-01-22 20:38:11 -0800 | [diff] [blame] | 6562 | public void getHistoricalOps(@NonNull HistoricalOpsRequest request, |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 6563 | @NonNull Executor executor, @NonNull Consumer<HistoricalOps> callback) { |
Daulet Zhanguzin | 0af97d6 | 2019-12-30 15:41:28 +0000 | [diff] [blame] | 6564 | Objects.requireNonNull(executor, "executor cannot be null"); |
| 6565 | Objects.requireNonNull(callback, "callback cannot be null"); |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 6566 | try { |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 6567 | mService.getHistoricalOps(request.mUid, request.mPackageName, request.mAttributionTag, |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 6568 | request.mOpNames, request.mFilter, request.mBeginTimeMillis, |
| 6569 | request.mEndTimeMillis, request.mFlags, new RemoteCallback((result) -> { |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 6570 | final HistoricalOps ops = result.getParcelable(KEY_HISTORICAL_OPS); |
| 6571 | final long identity = Binder.clearCallingIdentity(); |
| 6572 | try { |
| 6573 | executor.execute(() -> callback.accept(ops)); |
| 6574 | } finally { |
| 6575 | Binder.restoreCallingIdentity(identity); |
| 6576 | } |
| 6577 | })); |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 6578 | } catch (RemoteException e) { |
| 6579 | throw e.rethrowFromSystemServer(); |
| 6580 | } |
| 6581 | } |
| 6582 | |
| 6583 | /** |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 6584 | * Retrieve historical app op stats for a period. |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 6585 | * <p> |
| 6586 | * This method queries only the on disk state and the returned ops are raw, |
| 6587 | * which is their times are relative to the history start as opposed to the |
| 6588 | * epoch start. |
| 6589 | * |
Svet Ganov | 23c88db | 2019-01-22 20:38:11 -0800 | [diff] [blame] | 6590 | * @param request A request object describing the data being queried for. |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 6591 | * @param executor Executor on which to run the callback. If <code>null</code> |
| 6592 | * the callback is executed on the default executor running on the main thread. |
| 6593 | * @param callback Callback on which to deliver the result. |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 6594 | * |
| 6595 | * @throws IllegalArgumentException If any of the argument contracts is violated. |
| 6596 | * |
| 6597 | * @hide |
| 6598 | */ |
| 6599 | @TestApi |
Svet Ganov | 8e5bf96 | 2019-03-19 23:59:03 -0700 | [diff] [blame] | 6600 | @RequiresPermission(Manifest.permission.MANAGE_APPOPS) |
Svet Ganov | 23c88db | 2019-01-22 20:38:11 -0800 | [diff] [blame] | 6601 | public void getHistoricalOpsFromDiskRaw(@NonNull HistoricalOpsRequest request, |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 6602 | @Nullable Executor executor, @NonNull Consumer<HistoricalOps> callback) { |
Daulet Zhanguzin | 0af97d6 | 2019-12-30 15:41:28 +0000 | [diff] [blame] | 6603 | Objects.requireNonNull(executor, "executor cannot be null"); |
| 6604 | Objects.requireNonNull(callback, "callback cannot be null"); |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 6605 | try { |
Svet Ganov | 23c88db | 2019-01-22 20:38:11 -0800 | [diff] [blame] | 6606 | mService.getHistoricalOpsFromDiskRaw(request.mUid, request.mPackageName, |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 6607 | request.mAttributionTag, request.mOpNames, request.mFilter, |
| 6608 | request.mBeginTimeMillis, request.mEndTimeMillis, request.mFlags, |
| 6609 | new RemoteCallback((result) -> { |
Svet Ganov | 23c88db | 2019-01-22 20:38:11 -0800 | [diff] [blame] | 6610 | final HistoricalOps ops = result.getParcelable(KEY_HISTORICAL_OPS); |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 6611 | final long identity = Binder.clearCallingIdentity(); |
| 6612 | try { |
| 6613 | executor.execute(() -> callback.accept(ops)); |
| 6614 | } finally { |
| 6615 | Binder.restoreCallingIdentity(identity); |
| 6616 | } |
| 6617 | })); |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 6618 | } catch (RemoteException e) { |
| 6619 | throw e.rethrowFromSystemServer(); |
| 6620 | } |
| 6621 | } |
| 6622 | |
| 6623 | /** |
Svet Ganov | 8e5bf96 | 2019-03-19 23:59:03 -0700 | [diff] [blame] | 6624 | * Reloads the non historical state to allow testing the read/write path. |
| 6625 | * |
| 6626 | * @hide |
| 6627 | */ |
| 6628 | @TestApi |
| 6629 | @RequiresPermission(Manifest.permission.MANAGE_APPOPS) |
| 6630 | public void reloadNonHistoricalState() { |
| 6631 | try { |
| 6632 | mService.reloadNonHistoricalState(); |
| 6633 | } catch (RemoteException e) { |
| 6634 | throw e.rethrowFromSystemServer(); |
| 6635 | } |
| 6636 | } |
| 6637 | |
| 6638 | /** |
Svet Ganov | ae0e03a | 2016-02-25 18:22:10 -0800 | [diff] [blame] | 6639 | * Sets given app op in the specified mode for app ops in the UID. |
| 6640 | * This applies to all apps currently in the UID or installed in |
| 6641 | * this UID in the future. |
| 6642 | * |
| 6643 | * @param code The app op. |
| 6644 | * @param uid The UID for which to set the app. |
| 6645 | * @param mode The app op mode to set. |
| 6646 | * @hide |
| 6647 | */ |
Dianne Hackborn | bf1b57d | 2018-03-07 12:42:47 -0800 | [diff] [blame] | 6648 | @RequiresPermission(android.Manifest.permission.MANAGE_APP_OPS_MODES) |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 6649 | public void setUidMode(int code, int uid, @Mode int mode) { |
Svet Ganov | 2af5708 | 2015-07-30 08:44:20 -0700 | [diff] [blame] | 6650 | try { |
| 6651 | mService.setUidMode(code, uid, mode); |
| 6652 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 6653 | throw e.rethrowFromSystemServer(); |
Svet Ganov | 2af5708 | 2015-07-30 08:44:20 -0700 | [diff] [blame] | 6654 | } |
| 6655 | } |
| 6656 | |
Svet Ganov | ae0e03a | 2016-02-25 18:22:10 -0800 | [diff] [blame] | 6657 | /** |
| 6658 | * Sets given app op in the specified mode for app ops in the UID. |
| 6659 | * This applies to all apps currently in the UID or installed in |
| 6660 | * this UID in the future. |
| 6661 | * |
| 6662 | * @param appOp The app op. |
| 6663 | * @param uid The UID for which to set the app. |
| 6664 | * @param mode The app op mode to set. |
| 6665 | * @hide |
| 6666 | */ |
| 6667 | @SystemApi |
Eugene Susla | 9351985 | 2018-06-13 16:44:31 -0700 | [diff] [blame] | 6668 | @TestApi |
Dianne Hackborn | bf1b57d | 2018-03-07 12:42:47 -0800 | [diff] [blame] | 6669 | @RequiresPermission(android.Manifest.permission.MANAGE_APP_OPS_MODES) |
Philip P. Moltmann | a04b9ab | 2020-02-13 09:54:04 -0800 | [diff] [blame] | 6670 | public void setUidMode(@NonNull String appOp, int uid, @Mode int mode) { |
Svet Ganov | ae0e03a | 2016-02-25 18:22:10 -0800 | [diff] [blame] | 6671 | try { |
| 6672 | mService.setUidMode(AppOpsManager.strOpToOp(appOp), uid, mode); |
| 6673 | } catch (RemoteException e) { |
| 6674 | throw e.rethrowFromSystemServer(); |
| 6675 | } |
| 6676 | } |
| 6677 | |
Svet Ganov | 2af5708 | 2015-07-30 08:44:20 -0700 | [diff] [blame] | 6678 | /** @hide */ |
Svet Ganov | 9cea80cd | 2016-02-16 11:47:00 -0800 | [diff] [blame] | 6679 | public void setUserRestriction(int code, boolean restricted, IBinder token) { |
Ruben Brunk | 29931bc | 2016-03-11 00:24:26 -0800 | [diff] [blame] | 6680 | setUserRestriction(code, restricted, token, /*exceptionPackages*/null); |
| 6681 | } |
| 6682 | |
| 6683 | /** @hide */ |
| 6684 | public void setUserRestriction(int code, boolean restricted, IBinder token, |
| 6685 | String[] exceptionPackages) { |
Svetoslav Ganov | e33f613 | 2016-06-01 16:25:31 -0700 | [diff] [blame] | 6686 | setUserRestrictionForUser(code, restricted, token, exceptionPackages, mContext.getUserId()); |
| 6687 | } |
| 6688 | |
| 6689 | /** @hide */ |
| 6690 | public void setUserRestrictionForUser(int code, boolean restricted, IBinder token, |
| 6691 | String[] exceptionPackages, int userId) { |
Svet Ganov | 9cea80cd | 2016-02-16 11:47:00 -0800 | [diff] [blame] | 6692 | try { |
Svetoslav Ganov | e33f613 | 2016-06-01 16:25:31 -0700 | [diff] [blame] | 6693 | mService.setUserRestriction(code, restricted, token, userId, exceptionPackages); |
Svet Ganov | 9cea80cd | 2016-02-16 11:47:00 -0800 | [diff] [blame] | 6694 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 6695 | throw e.rethrowFromSystemServer(); |
Svet Ganov | 9cea80cd | 2016-02-16 11:47:00 -0800 | [diff] [blame] | 6696 | } |
| 6697 | } |
| 6698 | |
| 6699 | /** @hide */ |
Artur Satayev | f0b7d0b | 2019-11-04 11:16:45 +0000 | [diff] [blame] | 6700 | @UnsupportedAppUsage |
Peter Visontay | b97fbc8 | 2017-12-21 16:23:55 +0000 | [diff] [blame] | 6701 | @TestApi |
Dianne Hackborn | bf1b57d | 2018-03-07 12:42:47 -0800 | [diff] [blame] | 6702 | @RequiresPermission(android.Manifest.permission.MANAGE_APP_OPS_MODES) |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 6703 | public void setMode(int code, int uid, String packageName, @Mode int mode) { |
Dianne Hackborn | 5e45ee6 | 2013-01-24 19:13:44 -0800 | [diff] [blame] | 6704 | try { |
| 6705 | mService.setMode(code, uid, packageName, mode); |
| 6706 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 6707 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 5e45ee6 | 2013-01-24 19:13:44 -0800 | [diff] [blame] | 6708 | } |
| 6709 | } |
| 6710 | |
John Spurlock | 1af30c7 | 2014-03-10 08:33:35 -0400 | [diff] [blame] | 6711 | /** |
Dianne Hackborn | bf1b57d | 2018-03-07 12:42:47 -0800 | [diff] [blame] | 6712 | * Change the operating mode for the given op in the given app package. You must pass |
| 6713 | * in both the uid and name of the application whose mode is being modified; if these |
| 6714 | * do not match, the modification will not be applied. |
| 6715 | * |
| 6716 | * @param op The operation to modify. One of the OPSTR_* constants. |
| 6717 | * @param uid The user id of the application whose mode will be changed. |
| 6718 | * @param packageName The name of the application package name whose mode will |
| 6719 | * be changed. |
| 6720 | * @hide |
| 6721 | */ |
Svet Ganov | 8e5bf96 | 2019-03-19 23:59:03 -0700 | [diff] [blame] | 6722 | @TestApi |
Dianne Hackborn | bf1b57d | 2018-03-07 12:42:47 -0800 | [diff] [blame] | 6723 | @SystemApi |
| 6724 | @RequiresPermission(android.Manifest.permission.MANAGE_APP_OPS_MODES) |
Philip P. Moltmann | a04b9ab | 2020-02-13 09:54:04 -0800 | [diff] [blame] | 6725 | public void setMode(@NonNull String op, int uid, @Nullable String packageName, |
| 6726 | @Mode int mode) { |
Dianne Hackborn | bf1b57d | 2018-03-07 12:42:47 -0800 | [diff] [blame] | 6727 | try { |
| 6728 | mService.setMode(strOpToOp(op), uid, packageName, mode); |
| 6729 | } catch (RemoteException e) { |
| 6730 | throw e.rethrowFromSystemServer(); |
| 6731 | } |
| 6732 | } |
| 6733 | |
| 6734 | /** |
John Spurlock | 1af30c7 | 2014-03-10 08:33:35 -0400 | [diff] [blame] | 6735 | * Set a non-persisted restriction on an audio operation at a stream-level. |
| 6736 | * Restrictions are temporary additional constraints imposed on top of the persisted rules |
| 6737 | * defined by {@link #setMode}. |
| 6738 | * |
| 6739 | * @param code The operation to restrict. |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame] | 6740 | * @param usage The {@link android.media.AudioAttributes} usage value. |
John Spurlock | 1af30c7 | 2014-03-10 08:33:35 -0400 | [diff] [blame] | 6741 | * @param mode The restriction mode (MODE_IGNORED,MODE_ERRORED) or MODE_ALLOWED to unrestrict. |
| 6742 | * @param exceptionPackages Optional list of packages to exclude from the restriction. |
| 6743 | * @hide |
| 6744 | */ |
Dianne Hackborn | bf1b57d | 2018-03-07 12:42:47 -0800 | [diff] [blame] | 6745 | @RequiresPermission(android.Manifest.permission.MANAGE_APP_OPS_MODES) |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 6746 | @UnsupportedAppUsage |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 6747 | public void setRestriction(int code, @AttributeUsage int usage, @Mode int mode, |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame] | 6748 | String[] exceptionPackages) { |
John Spurlock | 1af30c7 | 2014-03-10 08:33:35 -0400 | [diff] [blame] | 6749 | try { |
| 6750 | final int uid = Binder.getCallingUid(); |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame] | 6751 | mService.setAudioRestriction(code, usage, uid, mode, exceptionPackages); |
John Spurlock | 1af30c7 | 2014-03-10 08:33:35 -0400 | [diff] [blame] | 6752 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 6753 | throw e.rethrowFromSystemServer(); |
John Spurlock | 1af30c7 | 2014-03-10 08:33:35 -0400 | [diff] [blame] | 6754 | } |
| 6755 | } |
| 6756 | |
Dianne Hackborn | 607b414 | 2013-08-02 18:10:10 -0700 | [diff] [blame] | 6757 | /** @hide */ |
Dianne Hackborn | bf1b57d | 2018-03-07 12:42:47 -0800 | [diff] [blame] | 6758 | @RequiresPermission(android.Manifest.permission.MANAGE_APP_OPS_MODES) |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 6759 | @UnsupportedAppUsage |
Dianne Hackborn | 607b414 | 2013-08-02 18:10:10 -0700 | [diff] [blame] | 6760 | public void resetAllModes() { |
| 6761 | try { |
Jeff Sharkey | ad357d1 | 2018-02-02 13:25:31 -0700 | [diff] [blame] | 6762 | mService.resetAllModes(mContext.getUserId(), null); |
Dianne Hackborn | 607b414 | 2013-08-02 18:10:10 -0700 | [diff] [blame] | 6763 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 6764 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 607b414 | 2013-08-02 18:10:10 -0700 | [diff] [blame] | 6765 | } |
| 6766 | } |
| 6767 | |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 6768 | /** |
Philip P. Moltmann | a04b9ab | 2020-02-13 09:54:04 -0800 | [diff] [blame] | 6769 | * Gets the app-op name associated with a given permission. |
| 6770 | * |
| 6771 | * <p>The app-op name is one of the public constants defined |
Svet Ganov | fbf01f7 | 2015-04-28 18:39:06 -0700 | [diff] [blame] | 6772 | * in this class such as {@link #OPSTR_COARSE_LOCATION}. |
Svetoslav Ganov | eaca4c5 | 2016-05-05 18:08:00 -0700 | [diff] [blame] | 6773 | * This API is intended to be used for mapping runtime |
Philip P. Moltmann | a04b9ab | 2020-02-13 09:54:04 -0800 | [diff] [blame] | 6774 | * permissions to the corresponding app-op. |
Svet Ganov | fbf01f7 | 2015-04-28 18:39:06 -0700 | [diff] [blame] | 6775 | * |
| 6776 | * @param permission The permission. |
Philip P. Moltmann | a04b9ab | 2020-02-13 09:54:04 -0800 | [diff] [blame] | 6777 | * @return The app-op associated with the permission or {@code null}. |
Svet Ganov | fbf01f7 | 2015-04-28 18:39:06 -0700 | [diff] [blame] | 6778 | */ |
Philip P. Moltmann | a04b9ab | 2020-02-13 09:54:04 -0800 | [diff] [blame] | 6779 | public static @Nullable String permissionToOp(@NonNull String permission) { |
Svet Ganov | da0acdf | 2017-02-15 10:28:51 -0800 | [diff] [blame] | 6780 | final Integer opCode = sPermToOp.get(permission); |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 6781 | if (opCode == null) { |
| 6782 | return null; |
| 6783 | } |
| 6784 | return sOpToString[opCode]; |
Svet Ganov | fbf01f7 | 2015-04-28 18:39:06 -0700 | [diff] [blame] | 6785 | } |
| 6786 | |
| 6787 | /** |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 6788 | * 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] | 6789 | * You can watch op changes only for your UID. |
| 6790 | * |
Dianne Hackborn | e4cb66f | 2013-10-02 10:34:02 -0700 | [diff] [blame] | 6791 | * @param op The operation to monitor, one of OPSTR_*. |
| 6792 | * @param packageName The name of the application to monitor. |
| 6793 | * @param callback Where to report changes. |
| 6794 | */ |
Dianne Hackborn | 6287849 | 2019-03-11 15:57:07 -0700 | [diff] [blame] | 6795 | public void startWatchingMode(@NonNull String op, @Nullable String packageName, |
| 6796 | @NonNull final OnOpChangedListener callback) { |
Dianne Hackborn | e4cb66f | 2013-10-02 10:34:02 -0700 | [diff] [blame] | 6797 | startWatchingMode(strOpToOp(op), packageName, callback); |
| 6798 | } |
| 6799 | |
| 6800 | /** |
| 6801 | * 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] | 6802 | * You can watch op changes only for your UID. |
| 6803 | * |
| 6804 | * @param op The operation to monitor, one of OPSTR_*. |
| 6805 | * @param packageName The name of the application to monitor. |
| 6806 | * @param flags Option flags: any combination of {@link #WATCH_FOREGROUND_CHANGES} or 0. |
| 6807 | * @param callback Where to report changes. |
Dianne Hackborn | 65a4f25 | 2018-05-08 17:30:48 -0700 | [diff] [blame] | 6808 | */ |
Dianne Hackborn | 6287849 | 2019-03-11 15:57:07 -0700 | [diff] [blame] | 6809 | public void startWatchingMode(@NonNull String op, @Nullable String packageName, int flags, |
| 6810 | @NonNull final OnOpChangedListener callback) { |
Dianne Hackborn | 65a4f25 | 2018-05-08 17:30:48 -0700 | [diff] [blame] | 6811 | startWatchingMode(strOpToOp(op), packageName, flags, callback); |
| 6812 | } |
| 6813 | |
| 6814 | /** |
| 6815 | * 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] | 6816 | * |
| 6817 | * <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] | 6818 | * you can watch changes only for your UID. |
Svetoslav Ganov | 2d20fb4 | 2018-02-08 15:52:10 -0800 | [diff] [blame] | 6819 | * |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 6820 | * @param op The operation to monitor, one of OP_*. |
| 6821 | * @param packageName The name of the application to monitor. |
| 6822 | * @param callback Where to report changes. |
Dianne Hackborn | e4cb66f | 2013-10-02 10:34:02 -0700 | [diff] [blame] | 6823 | * @hide |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 6824 | */ |
Jeff Sharkey | bf6b213 | 2018-02-27 11:16:37 -0700 | [diff] [blame] | 6825 | @RequiresPermission(value=android.Manifest.permission.WATCH_APPOPS, conditional=true) |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 6826 | public void startWatchingMode(int op, String packageName, final OnOpChangedListener callback) { |
Dianne Hackborn | 65a4f25 | 2018-05-08 17:30:48 -0700 | [diff] [blame] | 6827 | startWatchingMode(op, packageName, 0, callback); |
| 6828 | } |
| 6829 | |
| 6830 | /** |
| 6831 | * Monitor for changes to the operating mode for the given op in the given app package. |
| 6832 | * |
| 6833 | * <p> If you don't hold the {@link android.Manifest.permission#WATCH_APPOPS} permission |
| 6834 | * you can watch changes only for your UID. |
| 6835 | * |
| 6836 | * @param op The operation to monitor, one of OP_*. |
| 6837 | * @param packageName The name of the application to monitor. |
| 6838 | * @param flags Option flags: any combination of {@link #WATCH_FOREGROUND_CHANGES} or 0. |
| 6839 | * @param callback Where to report changes. |
| 6840 | * @hide |
| 6841 | */ |
| 6842 | @RequiresPermission(value=android.Manifest.permission.WATCH_APPOPS, conditional=true) |
| 6843 | public void startWatchingMode(int op, String packageName, int flags, |
| 6844 | final OnOpChangedListener callback) { |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 6845 | synchronized (mModeWatchers) { |
| 6846 | IAppOpsCallback cb = mModeWatchers.get(callback); |
| 6847 | if (cb == null) { |
| 6848 | cb = new IAppOpsCallback.Stub() { |
Dianne Hackborn | bef28fe | 2015-10-29 17:57:11 -0700 | [diff] [blame] | 6849 | public void opChanged(int op, int uid, String packageName) { |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 6850 | if (callback instanceof OnOpChangedInternalListener) { |
| 6851 | ((OnOpChangedInternalListener)callback).onOpChanged(op, packageName); |
| 6852 | } |
| 6853 | if (sOpToString[op] != null) { |
| 6854 | callback.onOpChanged(sOpToString[op], packageName); |
| 6855 | } |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 6856 | } |
| 6857 | }; |
| 6858 | mModeWatchers.put(callback, cb); |
| 6859 | } |
Philip P. Moltmann | 7641cd0 | 2020-03-11 14:42:43 -0700 | [diff] [blame] | 6860 | |
| 6861 | // See CALL_BACK_ON_CHANGED_LISTENER_WITH_SWITCHED_OP_CHANGE |
| 6862 | if (!Compatibility.isChangeEnabled( |
| 6863 | CALL_BACK_ON_CHANGED_LISTENER_WITH_SWITCHED_OP_CHANGE)) { |
| 6864 | flags |= CALL_BACK_ON_SWITCHED_OP; |
| 6865 | } |
| 6866 | |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 6867 | try { |
Dianne Hackborn | 65a4f25 | 2018-05-08 17:30:48 -0700 | [diff] [blame] | 6868 | mService.startWatchingModeWithFlags(op, packageName, flags, cb); |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 6869 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 6870 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 6871 | } |
| 6872 | } |
| 6873 | } |
| 6874 | |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 6875 | /** |
| 6876 | * Stop monitoring that was previously started with {@link #startWatchingMode}. All |
| 6877 | * monitoring associated with this callback will be removed. |
| 6878 | */ |
Dianne Hackborn | 6287849 | 2019-03-11 15:57:07 -0700 | [diff] [blame] | 6879 | public void stopWatchingMode(@NonNull OnOpChangedListener callback) { |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 6880 | synchronized (mModeWatchers) { |
Svet Ganov | b3d2ae2 | 2018-12-17 22:06:15 -0800 | [diff] [blame] | 6881 | IAppOpsCallback cb = mModeWatchers.remove(callback); |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 6882 | if (cb != null) { |
| 6883 | try { |
| 6884 | mService.stopWatchingMode(cb); |
| 6885 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 6886 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 6887 | } |
| 6888 | } |
| 6889 | } |
| 6890 | } |
| 6891 | |
Jeff Sharkey | 7095ab9 | 2019-08-20 16:50:28 -0600 | [diff] [blame] | 6892 | /** {@hide} */ |
| 6893 | @Deprecated |
| 6894 | public void startWatchingActive(@NonNull int[] ops, |
| 6895 | @NonNull OnOpActiveChangedListener callback) { |
| 6896 | final String[] strOps = new String[ops.length]; |
| 6897 | for (int i = 0; i < ops.length; i++) { |
| 6898 | strOps[i] = opToPublicName(ops[i]); |
| 6899 | } |
| 6900 | startWatchingActive(strOps, mContext.getMainExecutor(), callback); |
| 6901 | } |
| 6902 | |
Svetoslav Ganov | 2d20fb4 | 2018-02-08 15:52:10 -0800 | [diff] [blame] | 6903 | /** |
Philip P. Moltmann | a04b9ab | 2020-02-13 09:54:04 -0800 | [diff] [blame] | 6904 | * 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] | 6905 | * long running and it has a clear start and stop delimiters. If an op is being |
| 6906 | * started or stopped by any package you will get a callback. To change the |
| 6907 | * watched ops for a registered callback you need to unregister and register it |
| 6908 | * again. |
| 6909 | * |
Jeff Sharkey | 7095ab9 | 2019-08-20 16:50:28 -0600 | [diff] [blame] | 6910 | * <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] | 6911 | * you can watch changes only for your UID. |
| 6912 | * |
Jeff Sharkey | 7095ab9 | 2019-08-20 16:50:28 -0600 | [diff] [blame] | 6913 | * @param ops The operations to watch. |
Svetoslav Ganov | 2d20fb4 | 2018-02-08 15:52:10 -0800 | [diff] [blame] | 6914 | * @param callback Where to report changes. |
| 6915 | * |
Jeff Sharkey | 7095ab9 | 2019-08-20 16:50:28 -0600 | [diff] [blame] | 6916 | * @see #stopWatchingActive |
Svetoslav Ganov | 2d20fb4 | 2018-02-08 15:52:10 -0800 | [diff] [blame] | 6917 | */ |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 6918 | // TODO: Uncomment below annotation once b/73559440 is fixed |
| 6919 | // @RequiresPermission(value=Manifest.permission.WATCH_APPOPS, conditional=true) |
Jeff Sharkey | 7095ab9 | 2019-08-20 16:50:28 -0600 | [diff] [blame] | 6920 | public void startWatchingActive(@NonNull String[] ops, |
| 6921 | @CallbackExecutor @NonNull Executor executor, |
Svetoslav Ganov | 2d20fb4 | 2018-02-08 15:52:10 -0800 | [diff] [blame] | 6922 | @NonNull OnOpActiveChangedListener callback) { |
Jeff Sharkey | 7095ab9 | 2019-08-20 16:50:28 -0600 | [diff] [blame] | 6923 | Objects.requireNonNull(ops); |
| 6924 | Objects.requireNonNull(executor); |
| 6925 | Objects.requireNonNull(callback); |
Svetoslav Ganov | 2d20fb4 | 2018-02-08 15:52:10 -0800 | [diff] [blame] | 6926 | IAppOpsActiveCallback cb; |
| 6927 | synchronized (mActiveWatchers) { |
| 6928 | cb = mActiveWatchers.get(callback); |
| 6929 | if (cb != null) { |
| 6930 | return; |
| 6931 | } |
| 6932 | cb = new IAppOpsActiveCallback.Stub() { |
| 6933 | @Override |
| 6934 | public void opActiveChanged(int op, int uid, String packageName, boolean active) { |
Jeff Sharkey | 7095ab9 | 2019-08-20 16:50:28 -0600 | [diff] [blame] | 6935 | executor.execute(() -> { |
| 6936 | if (callback instanceof OnOpActiveChangedInternalListener) { |
| 6937 | ((OnOpActiveChangedInternalListener) callback).onOpActiveChanged(op, |
| 6938 | uid, packageName, active); |
| 6939 | } |
| 6940 | if (sOpToString[op] != null) { |
| 6941 | callback.onOpActiveChanged(sOpToString[op], uid, packageName, active); |
| 6942 | } |
| 6943 | }); |
Svetoslav Ganov | 2d20fb4 | 2018-02-08 15:52:10 -0800 | [diff] [blame] | 6944 | } |
| 6945 | }; |
| 6946 | mActiveWatchers.put(callback, cb); |
| 6947 | } |
Jeff Sharkey | 7095ab9 | 2019-08-20 16:50:28 -0600 | [diff] [blame] | 6948 | final int[] rawOps = new int[ops.length]; |
| 6949 | for (int i = 0; i < ops.length; i++) { |
| 6950 | rawOps[i] = strOpToOp(ops[i]); |
| 6951 | } |
Svetoslav Ganov | 2d20fb4 | 2018-02-08 15:52:10 -0800 | [diff] [blame] | 6952 | try { |
Jeff Sharkey | 7095ab9 | 2019-08-20 16:50:28 -0600 | [diff] [blame] | 6953 | mService.startWatchingActive(rawOps, cb); |
Svetoslav Ganov | 2d20fb4 | 2018-02-08 15:52:10 -0800 | [diff] [blame] | 6954 | } catch (RemoteException e) { |
| 6955 | throw e.rethrowFromSystemServer(); |
| 6956 | } |
| 6957 | } |
| 6958 | |
| 6959 | /** |
Philip P. Moltmann | a04b9ab | 2020-02-13 09:54:04 -0800 | [diff] [blame] | 6960 | * 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] | 6961 | * long running and it has a clear start and stop delimiters. Unregistering a |
| 6962 | * non-registered callback has no effect. |
| 6963 | * |
Jeff Sharkey | 7095ab9 | 2019-08-20 16:50:28 -0600 | [diff] [blame] | 6964 | * @see #startWatchingActive |
Svetoslav Ganov | 2d20fb4 | 2018-02-08 15:52:10 -0800 | [diff] [blame] | 6965 | */ |
| 6966 | public void stopWatchingActive(@NonNull OnOpActiveChangedListener callback) { |
| 6967 | synchronized (mActiveWatchers) { |
Svet Ganov | b3d2ae2 | 2018-12-17 22:06:15 -0800 | [diff] [blame] | 6968 | final IAppOpsActiveCallback cb = mActiveWatchers.remove(callback); |
Svetoslav Ganov | 2d20fb4 | 2018-02-08 15:52:10 -0800 | [diff] [blame] | 6969 | if (cb != null) { |
| 6970 | try { |
| 6971 | mService.stopWatchingActive(cb); |
| 6972 | } catch (RemoteException e) { |
| 6973 | throw e.rethrowFromSystemServer(); |
| 6974 | } |
| 6975 | } |
| 6976 | } |
| 6977 | } |
| 6978 | |
Svet Ganov | b3d2ae2 | 2018-12-17 22:06:15 -0800 | [diff] [blame] | 6979 | /** |
Adam Bookatz | 182862e | 2020-04-27 21:58:22 -0700 | [diff] [blame] | 6980 | * Start watching for started app-ops. |
| 6981 | * An app-op may be long running and it has a clear start delimiter. |
| 6982 | * If an op start is attempted by any package, you will get a callback. |
| 6983 | * To change the watched ops for a registered callback you need to unregister and register it |
| 6984 | * again. |
| 6985 | * |
| 6986 | * <p> If you don't hold the {@code android.Manifest.permission#WATCH_APPOPS} permission |
| 6987 | * you can watch changes only for your UID. |
| 6988 | * |
| 6989 | * @param ops The operations to watch. |
| 6990 | * @param callback Where to report changes. |
| 6991 | * |
| 6992 | * @see #stopWatchingStarted(OnOpStartedListener) |
| 6993 | * @see #startWatchingActive(int[], OnOpActiveChangedListener) |
| 6994 | * @see #startWatchingNoted(int[], OnOpNotedListener) |
| 6995 | * @see #startOp(int, int, String, boolean, String, String) |
| 6996 | * @see #finishOp(int, int, String, String) |
| 6997 | * |
| 6998 | * @hide |
| 6999 | */ |
| 7000 | @RequiresPermission(value=Manifest.permission.WATCH_APPOPS, conditional=true) |
| 7001 | public void startWatchingStarted(@NonNull int[] ops, @NonNull OnOpStartedListener callback) { |
| 7002 | IAppOpsStartedCallback cb; |
| 7003 | synchronized (mStartedWatchers) { |
| 7004 | if (mStartedWatchers.containsKey(callback)) { |
| 7005 | return; |
| 7006 | } |
| 7007 | cb = new IAppOpsStartedCallback.Stub() { |
| 7008 | @Override |
| 7009 | public void opStarted(int op, int uid, String packageName, int mode) { |
| 7010 | callback.onOpStarted(op, uid, packageName, mode); |
| 7011 | } |
| 7012 | }; |
| 7013 | mStartedWatchers.put(callback, cb); |
| 7014 | } |
| 7015 | try { |
| 7016 | mService.startWatchingStarted(ops, cb); |
| 7017 | } catch (RemoteException e) { |
| 7018 | throw e.rethrowFromSystemServer(); |
| 7019 | } |
| 7020 | } |
| 7021 | |
| 7022 | /** |
| 7023 | * Stop watching for started app-ops. |
| 7024 | * An app-op may be long running and it has a clear start delimiter. |
| 7025 | * Henceforth, if an op start is attempted by any package, you will not get a callback. |
| 7026 | * Unregistering a non-registered callback has no effect. |
| 7027 | * |
| 7028 | * @see #startWatchingStarted(int[], OnOpStartedListener) |
| 7029 | * @see #startOp(int, int, String, boolean, String, String) |
| 7030 | * |
| 7031 | * @hide |
| 7032 | */ |
| 7033 | public void stopWatchingStarted(@NonNull OnOpStartedListener callback) { |
| 7034 | synchronized (mStartedWatchers) { |
| 7035 | final IAppOpsStartedCallback cb = mStartedWatchers.remove(callback); |
| 7036 | if (cb != null) { |
| 7037 | try { |
| 7038 | mService.stopWatchingStarted(cb); |
| 7039 | } catch (RemoteException e) { |
| 7040 | throw e.rethrowFromSystemServer(); |
| 7041 | } |
| 7042 | } |
| 7043 | } |
| 7044 | } |
| 7045 | |
| 7046 | /** |
Svet Ganov | b3d2ae2 | 2018-12-17 22:06:15 -0800 | [diff] [blame] | 7047 | * Start watching for noted app ops. An app op may be immediate or long running. |
| 7048 | * Immediate ops are noted while long running ones are started and stopped. This |
| 7049 | * method allows registering a listener to be notified when an app op is noted. If |
| 7050 | * an op is being noted by any package you will get a callback. To change the |
| 7051 | * watched ops for a registered callback you need to unregister and register it again. |
| 7052 | * |
| 7053 | * <p> If you don't hold the {@link android.Manifest.permission#WATCH_APPOPS} permission |
| 7054 | * you can watch changes only for your UID. |
| 7055 | * |
| 7056 | * @param ops The ops to watch. |
| 7057 | * @param callback Where to report changes. |
| 7058 | * |
| 7059 | * @see #startWatchingActive(int[], OnOpActiveChangedListener) |
Adam Bookatz | 182862e | 2020-04-27 21:58:22 -0700 | [diff] [blame] | 7060 | * @see #startWatchingStarted(int[], OnOpStartedListener) |
Svet Ganov | b3d2ae2 | 2018-12-17 22:06:15 -0800 | [diff] [blame] | 7061 | * @see #stopWatchingNoted(OnOpNotedListener) |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7062 | * @see #noteOp(String, int, String, String, String) |
Svet Ganov | b3d2ae2 | 2018-12-17 22:06:15 -0800 | [diff] [blame] | 7063 | * |
| 7064 | * @hide |
| 7065 | */ |
| 7066 | @RequiresPermission(value=Manifest.permission.WATCH_APPOPS, conditional=true) |
Fabian Kozynski | 0b4592c | 2018-12-20 12:58:45 -0500 | [diff] [blame] | 7067 | public void startWatchingNoted(@NonNull int[] ops, @NonNull OnOpNotedListener callback) { |
Svet Ganov | b3d2ae2 | 2018-12-17 22:06:15 -0800 | [diff] [blame] | 7068 | IAppOpsNotedCallback cb; |
| 7069 | synchronized (mNotedWatchers) { |
| 7070 | cb = mNotedWatchers.get(callback); |
| 7071 | if (cb != null) { |
| 7072 | return; |
| 7073 | } |
| 7074 | cb = new IAppOpsNotedCallback.Stub() { |
| 7075 | @Override |
| 7076 | public void opNoted(int op, int uid, String packageName, int mode) { |
Fabian Kozynski | 0b4592c | 2018-12-20 12:58:45 -0500 | [diff] [blame] | 7077 | callback.onOpNoted(op, uid, packageName, mode); |
Svet Ganov | b3d2ae2 | 2018-12-17 22:06:15 -0800 | [diff] [blame] | 7078 | } |
| 7079 | }; |
| 7080 | mNotedWatchers.put(callback, cb); |
| 7081 | } |
| 7082 | try { |
Fabian Kozynski | 0b4592c | 2018-12-20 12:58:45 -0500 | [diff] [blame] | 7083 | mService.startWatchingNoted(ops, cb); |
Svet Ganov | b3d2ae2 | 2018-12-17 22:06:15 -0800 | [diff] [blame] | 7084 | } catch (RemoteException e) { |
| 7085 | throw e.rethrowFromSystemServer(); |
| 7086 | } |
| 7087 | } |
| 7088 | |
| 7089 | /** |
| 7090 | * Stop watching for noted app ops. An app op may be immediate or long running. |
| 7091 | * Unregistering a non-registered callback has no effect. |
| 7092 | * |
Fabian Kozynski | 0b4592c | 2018-12-20 12:58:45 -0500 | [diff] [blame] | 7093 | * @see #startWatchingNoted(int[], OnOpNotedListener) |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7094 | * @see #noteOp(String, int, String, String, String) |
Svet Ganov | b3d2ae2 | 2018-12-17 22:06:15 -0800 | [diff] [blame] | 7095 | * |
| 7096 | * @hide |
| 7097 | */ |
| 7098 | public void stopWatchingNoted(@NonNull OnOpNotedListener callback) { |
| 7099 | synchronized (mNotedWatchers) { |
Adam Bookatz | 182862e | 2020-04-27 21:58:22 -0700 | [diff] [blame] | 7100 | final IAppOpsNotedCallback cb = mNotedWatchers.remove(callback); |
Svet Ganov | b3d2ae2 | 2018-12-17 22:06:15 -0800 | [diff] [blame] | 7101 | if (cb != null) { |
| 7102 | try { |
| 7103 | mService.stopWatchingNoted(cb); |
| 7104 | } catch (RemoteException e) { |
| 7105 | throw e.rethrowFromSystemServer(); |
| 7106 | } |
| 7107 | } |
| 7108 | } |
| 7109 | } |
| 7110 | |
Dianne Hackborn | 95d7853 | 2013-09-11 09:51:14 -0700 | [diff] [blame] | 7111 | private String buildSecurityExceptionMsg(int op, int uid, String packageName) { |
| 7112 | return packageName + " from uid " + uid + " not allowed to perform " + sOpNames[op]; |
| 7113 | } |
| 7114 | |
Adam Lesinski | b5cf61b | 2014-08-18 16:10:28 -0700 | [diff] [blame] | 7115 | /** |
| 7116 | * {@hide} |
| 7117 | */ |
Artur Satayev | f0b7d0b | 2019-11-04 11:16:45 +0000 | [diff] [blame] | 7118 | @UnsupportedAppUsage |
Philip P. Moltmann | 3311515 | 2018-04-11 13:39:36 -0700 | [diff] [blame] | 7119 | @TestApi |
Dianne Hackborn | 6287849 | 2019-03-11 15:57:07 -0700 | [diff] [blame] | 7120 | public static int strOpToOp(@NonNull String op) { |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 7121 | Integer val = sOpStrToOp.get(op); |
| 7122 | if (val == null) { |
| 7123 | throw new IllegalArgumentException("Unknown operation string: " + op); |
| 7124 | } |
| 7125 | return val; |
| 7126 | } |
| 7127 | |
| 7128 | /** |
| 7129 | * 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] | 7130 | * 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] | 7131 | * String, String)} or {@link #startOp(String, int, String, String, String)} for your actual |
| 7132 | * security checks, which also ensure that the given uid and package name are consistent. This |
| 7133 | * function can just be used for a quick check to see if an operation has been disabled for the |
| 7134 | * application, as an early reject of some work. This does not modify the time stamp or other |
| 7135 | * data about the operation. |
Dianne Hackborn | c216a26 | 2018-04-26 13:46:22 -0700 | [diff] [blame] | 7136 | * |
| 7137 | * <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] | 7138 | * {@link #noteOp(String, int, String, String, String)} or |
| 7139 | * {@link #startOp(String, int, String, String, String)} to cover):</p> |
Dianne Hackborn | c216a26 | 2018-04-26 13:46:22 -0700 | [diff] [blame] | 7140 | * <ul> |
| 7141 | * <li>Verifying the uid and package are consistent, so callers can't spoof |
| 7142 | * their identity.</li> |
| 7143 | * <li>Taking into account the current foreground/background state of the |
| 7144 | * app; apps whose mode varies by this state will always be reported |
| 7145 | * as {@link #MODE_ALLOWED}.</li> |
| 7146 | * </ul> |
| 7147 | * |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 7148 | * @param op The operation to check. One of the OPSTR_* constants. |
| 7149 | * @param uid The user id of the application attempting to perform the operation. |
| 7150 | * @param packageName The name of the application attempting to perform the operation. |
| 7151 | * @return Returns {@link #MODE_ALLOWED} if the operation is allowed, or |
| 7152 | * {@link #MODE_IGNORED} if it is not allowed and should be silently ignored (without |
| 7153 | * causing the app to crash). |
| 7154 | * @throws SecurityException If the app has been configured to crash on this op. |
| 7155 | */ |
Dianne Hackborn | 6287849 | 2019-03-11 15:57:07 -0700 | [diff] [blame] | 7156 | public int unsafeCheckOp(@NonNull String op, int uid, @NonNull String packageName) { |
Dianne Hackborn | f0c322a | 2018-06-13 15:24:04 -0700 | [diff] [blame] | 7157 | return checkOp(strOpToOp(op), uid, packageName); |
| 7158 | } |
| 7159 | |
| 7160 | /** |
| 7161 | * @deprecated Renamed to {@link #unsafeCheckOp(String, int, String)}. |
| 7162 | */ |
| 7163 | @Deprecated |
Dianne Hackborn | 6287849 | 2019-03-11 15:57:07 -0700 | [diff] [blame] | 7164 | public int checkOp(@NonNull String op, int uid, @NonNull String packageName) { |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 7165 | return checkOp(strOpToOp(op), uid, packageName); |
| 7166 | } |
| 7167 | |
| 7168 | /** |
John Spurlock | 925b85e | 2014-03-10 16:52:11 -0400 | [diff] [blame] | 7169 | * Like {@link #checkOp} but instead of throwing a {@link SecurityException} it |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 7170 | * returns {@link #MODE_ERRORED}. |
| 7171 | */ |
Dianne Hackborn | 6287849 | 2019-03-11 15:57:07 -0700 | [diff] [blame] | 7172 | public int unsafeCheckOpNoThrow(@NonNull String op, int uid, @NonNull String packageName) { |
Dianne Hackborn | f0c322a | 2018-06-13 15:24:04 -0700 | [diff] [blame] | 7173 | return checkOpNoThrow(strOpToOp(op), uid, packageName); |
| 7174 | } |
| 7175 | |
| 7176 | /** |
| 7177 | * @deprecated Renamed to {@link #unsafeCheckOpNoThrow(String, int, String)}. |
| 7178 | */ |
| 7179 | @Deprecated |
Dianne Hackborn | 6287849 | 2019-03-11 15:57:07 -0700 | [diff] [blame] | 7180 | public int checkOpNoThrow(@NonNull String op, int uid, @NonNull String packageName) { |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 7181 | return checkOpNoThrow(strOpToOp(op), uid, packageName); |
| 7182 | } |
| 7183 | |
| 7184 | /** |
Dianne Hackborn | 65a4f25 | 2018-05-08 17:30:48 -0700 | [diff] [blame] | 7185 | * Like {@link #checkOp} but returns the <em>raw</em> mode associated with the op. |
| 7186 | * Does not throw a security exception, does not translate {@link #MODE_FOREGROUND}. |
Dianne Hackborn | 65a4f25 | 2018-05-08 17:30:48 -0700 | [diff] [blame] | 7187 | */ |
Dianne Hackborn | 6287849 | 2019-03-11 15:57:07 -0700 | [diff] [blame] | 7188 | public int unsafeCheckOpRaw(@NonNull String op, int uid, @NonNull String packageName) { |
Adam Bookatz | 3876793 | 2020-02-05 12:13:40 -0800 | [diff] [blame] | 7189 | return unsafeCheckOpRawNoThrow(op, uid, packageName); |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 7190 | } |
| 7191 | |
| 7192 | /** |
| 7193 | * Like {@link #unsafeCheckOpNoThrow(String, int, String)} but returns the <em>raw</em> |
| 7194 | * mode associated with the op. Does not throw a security exception, does not translate |
| 7195 | * {@link #MODE_FOREGROUND}. |
| 7196 | */ |
| 7197 | public int unsafeCheckOpRawNoThrow(@NonNull String op, int uid, @NonNull String packageName) { |
Adam Bookatz | 3876793 | 2020-02-05 12:13:40 -0800 | [diff] [blame] | 7198 | return unsafeCheckOpRawNoThrow(strOpToOp(op), uid, packageName); |
| 7199 | } |
| 7200 | |
| 7201 | /** |
| 7202 | * Returns the <em>raw</em> mode associated with the op. |
| 7203 | * Does not throw a security exception, does not translate {@link #MODE_FOREGROUND}. |
| 7204 | * @hide |
| 7205 | */ |
| 7206 | public int unsafeCheckOpRawNoThrow(int op, int uid, @NonNull String packageName) { |
Dianne Hackborn | 65a4f25 | 2018-05-08 17:30:48 -0700 | [diff] [blame] | 7207 | try { |
Adam Bookatz | 3876793 | 2020-02-05 12:13:40 -0800 | [diff] [blame] | 7208 | return mService.checkOperationRaw(op, uid, packageName); |
Dianne Hackborn | 65a4f25 | 2018-05-08 17:30:48 -0700 | [diff] [blame] | 7209 | } catch (RemoteException e) { |
| 7210 | throw e.rethrowFromSystemServer(); |
| 7211 | } |
| 7212 | } |
| 7213 | |
| 7214 | /** |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7215 | * @deprecated Use {@link #noteOp(String, int, String, String, String)} instead |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7216 | */ |
| 7217 | @Deprecated |
| 7218 | public int noteOp(@NonNull String op, int uid, @NonNull String packageName) { |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7219 | return noteOp(op, uid, packageName, null, null); |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7220 | } |
| 7221 | |
| 7222 | /** |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7223 | * @deprecated Use {@link #noteOp(String, int, String, String, String)} instead |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7224 | * |
| 7225 | * @hide |
| 7226 | */ |
| 7227 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.Q, publicAlternatives = "Use {@link " |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7228 | + "#noteOp(java.lang.String, int, java.lang.String, java.lang.String, " |
| 7229 | + "java.lang.String)} instead") |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7230 | @Deprecated |
| 7231 | public int noteOp(int op) { |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7232 | return noteOp(op, Process.myUid(), mContext.getOpPackageName(), null, null); |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7233 | } |
| 7234 | |
| 7235 | /** |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7236 | * @deprecated Use {@link #noteOp(String, int, String, String, String)} instead |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7237 | * |
| 7238 | * @hide |
| 7239 | */ |
| 7240 | @Deprecated |
| 7241 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.Q, publicAlternatives = "Use {@link " |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7242 | + "#noteOp(java.lang.String, int, java.lang.String, java.lang.String, " |
| 7243 | + "java.lang.String)} instead") |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7244 | public int noteOp(int op, int uid, @Nullable String packageName) { |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7245 | return noteOp(op, uid, packageName, null, null); |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7246 | } |
| 7247 | |
| 7248 | /** |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 7249 | * Make note of an application performing an operation. Note that you must pass |
| 7250 | * in both the uid and name of the application to be checked; this function will verify |
| 7251 | * that these two match, and if not, return {@link #MODE_IGNORED}. If this call |
| 7252 | * succeeds, the last execution time of the operation for this app will be updated to |
| 7253 | * the current time. |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7254 | * |
Philip P. Moltmann | 9e36700 | 2020-02-03 17:01:05 -0800 | [diff] [blame] | 7255 | * <p>If this is a check that is not preceding the protected operation, use |
| 7256 | * {@link #unsafeCheckOp} instead. |
| 7257 | * |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 7258 | * @param op The operation to note. One of the OPSTR_* constants. |
| 7259 | * @param uid The user id of the application attempting to perform the operation. |
| 7260 | * @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] | 7261 | * @param attributionTag The {@link Context#createAttributionContext attribution tag} or {@code |
| 7262 | * null} for default attribution |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7263 | * @param message A message describing the reason the op was noted |
Philip P. Moltmann | 0d05e48 | 2019-02-08 13:05:25 -0800 | [diff] [blame] | 7264 | * |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7265 | * @return Returns {@link #MODE_ALLOWED} if the operation is allowed, or |
| 7266 | * {@link #MODE_IGNORED} if it is not allowed and should be silently ignored (without |
| 7267 | * causing the app to crash). |
| 7268 | * |
| 7269 | * @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] | 7270 | */ |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7271 | public int noteOp(@NonNull String op, int uid, @Nullable String packageName, |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 7272 | @Nullable String attributionTag, @Nullable String message) { |
| 7273 | return noteOp(strOpToOp(op), uid, packageName, attributionTag, message); |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 7274 | } |
| 7275 | |
| 7276 | /** |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7277 | * Make note of an application performing an operation. Note that you must pass |
| 7278 | * in both the uid and name of the application to be checked; this function will verify |
| 7279 | * that these two match, and if not, return {@link #MODE_IGNORED}. If this call |
| 7280 | * succeeds, the last execution time of the operation for this app will be updated to |
| 7281 | * the current time. |
| 7282 | * |
Philip P. Moltmann | 9e36700 | 2020-02-03 17:01:05 -0800 | [diff] [blame] | 7283 | * <p>If this is a check that is not preceding the protected operation, use |
| 7284 | * {@link #unsafeCheckOp} instead. |
| 7285 | * |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7286 | * @param op The operation to note. One of the OP_* constants. |
| 7287 | * @param uid The user id of the application attempting to perform the operation. |
| 7288 | * @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] | 7289 | * @param attributionTag The {@link Context#createAttributionContext attribution tag} or {@code |
| 7290 | * null} for default attribution |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7291 | * @param message A message describing the reason the op was noted |
| 7292 | * |
| 7293 | * @return Returns {@link #MODE_ALLOWED} if the operation is allowed, or |
| 7294 | * {@link #MODE_IGNORED} if it is not allowed and should be silently ignored (without |
| 7295 | * causing the app to crash). |
| 7296 | * |
| 7297 | * @throws SecurityException If the app has been configured to crash on this op. |
| 7298 | * |
| 7299 | * @hide |
| 7300 | */ |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 7301 | public int noteOp(int op, int uid, @Nullable String packageName, |
| 7302 | @Nullable String attributionTag, @Nullable String message) { |
| 7303 | final int mode = noteOpNoThrow(op, uid, packageName, attributionTag, message); |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7304 | if (mode == MODE_ERRORED) { |
| 7305 | throw new SecurityException(buildSecurityExceptionMsg(op, uid, packageName)); |
| 7306 | } |
| 7307 | return mode; |
| 7308 | } |
| 7309 | |
| 7310 | /** |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7311 | * @deprecated Use {@link #noteOpNoThrow(String, int, String, String, String)} instead |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7312 | */ |
| 7313 | @Deprecated |
| 7314 | public int noteOpNoThrow(@NonNull String op, int uid, @NonNull String packageName) { |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7315 | return noteOpNoThrow(op, uid, packageName, null, null); |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7316 | } |
| 7317 | |
| 7318 | /** |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7319 | * @deprecated Use {@link #noteOpNoThrow(int, int, String, String, String)} instead |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7320 | * |
| 7321 | * @hide |
| 7322 | */ |
| 7323 | @Deprecated |
| 7324 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.Q, publicAlternatives = "Use {@link " |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7325 | + "#noteOpNoThrow(java.lang.String, int, java.lang.String, java.lang.String, " |
| 7326 | + "java.lang.String)} instead") |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7327 | public int noteOpNoThrow(int op, int uid, String packageName) { |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7328 | return noteOpNoThrow(op, uid, packageName, null, null); |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7329 | } |
| 7330 | |
| 7331 | /** |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7332 | * 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] | 7333 | * {@link SecurityException} it returns {@link #MODE_ERRORED}. |
| 7334 | * |
| 7335 | * @param op The operation to note. One of the OPSTR_* constants. |
| 7336 | * @param uid The user id of the application attempting to perform the operation. |
| 7337 | * @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] | 7338 | * @param attributionTag The {@link Context#createAttributionContext attribution tag} or {@code |
| 7339 | * null} for default attribution |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7340 | * @param message A message describing the reason the op was noted |
| 7341 | * |
| 7342 | * @return Returns {@link #MODE_ALLOWED} if the operation is allowed, or |
| 7343 | * {@link #MODE_IGNORED} if it is not allowed and should be silently ignored (without |
| 7344 | * causing the app to crash). |
| 7345 | */ |
| 7346 | public int noteOpNoThrow(@NonNull String op, int uid, @NonNull String packageName, |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 7347 | @Nullable String attributionTag, @Nullable String message) { |
| 7348 | return noteOpNoThrow(strOpToOp(op), uid, packageName, attributionTag, message); |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7349 | } |
| 7350 | |
| 7351 | /** |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7352 | * 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] | 7353 | * {@link SecurityException} it returns {@link #MODE_ERRORED}. |
| 7354 | * |
| 7355 | * @param op The operation to note. One of the OP_* constants. |
| 7356 | * @param uid The user id of the application attempting to perform the operation. |
| 7357 | * @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] | 7358 | * @param attributionTag The {@link Context#createAttributionContext attribution tag} or {@code |
| 7359 | * null} for default attribution |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7360 | * @param message A message describing the reason the op was noted |
| 7361 | * |
| 7362 | * @return Returns {@link #MODE_ALLOWED} if the operation is allowed, or |
| 7363 | * {@link #MODE_IGNORED} if it is not allowed and should be silently ignored (without |
| 7364 | * causing the app to crash). |
| 7365 | * |
| 7366 | * @hide |
| 7367 | */ |
| 7368 | public int noteOpNoThrow(int op, int uid, @Nullable String packageName, |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 7369 | @Nullable String attributionTag, @Nullable String message) { |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7370 | try { |
David Cheung | 2ead966 | 2020-02-19 16:11:06 -0800 | [diff] [blame] | 7371 | collectNoteOpCallsForValidation(op); |
Philip P. Moltmann | da554e4 | 2019-12-20 11:21:02 -0800 | [diff] [blame] | 7372 | int collectionMode = getNotedOpCollectionMode(uid, packageName, op); |
Stanislav Zholnin | 54762b2 | 2020-06-19 13:20:48 +0100 | [diff] [blame] | 7373 | boolean shouldCollectMessage = Process.myUid() == Process.SYSTEM_UID ? true : false; |
Philip P. Moltmann | da554e4 | 2019-12-20 11:21:02 -0800 | [diff] [blame] | 7374 | if (collectionMode == COLLECT_ASYNC) { |
| 7375 | if (message == null) { |
| 7376 | // Set stack trace as default message |
| 7377 | message = getFormattedStackTrace(); |
Stanislav Zholnin | 54762b2 | 2020-06-19 13:20:48 +0100 | [diff] [blame] | 7378 | shouldCollectMessage = true; |
Philip P. Moltmann | da554e4 | 2019-12-20 11:21:02 -0800 | [diff] [blame] | 7379 | } |
| 7380 | } |
| 7381 | |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 7382 | int mode = mService.noteOperation(op, uid, packageName, attributionTag, |
Stanislav Zholnin | 54762b2 | 2020-06-19 13:20:48 +0100 | [diff] [blame] | 7383 | collectionMode == COLLECT_ASYNC, message, shouldCollectMessage); |
Philip P. Moltmann | da554e4 | 2019-12-20 11:21:02 -0800 | [diff] [blame] | 7384 | |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7385 | if (mode == MODE_ALLOWED) { |
Philip P. Moltmann | da554e4 | 2019-12-20 11:21:02 -0800 | [diff] [blame] | 7386 | if (collectionMode == COLLECT_SELF) { |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 7387 | collectNotedOpForSelf(op, attributionTag); |
Philip P. Moltmann | da554e4 | 2019-12-20 11:21:02 -0800 | [diff] [blame] | 7388 | } else if (collectionMode == COLLECT_SYNC) { |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 7389 | collectNotedOpSync(op, attributionTag); |
Philip P. Moltmann | da554e4 | 2019-12-20 11:21:02 -0800 | [diff] [blame] | 7390 | } |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7391 | } |
| 7392 | |
| 7393 | return mode; |
| 7394 | } catch (RemoteException e) { |
| 7395 | throw e.rethrowFromSystemServer(); |
| 7396 | } |
| 7397 | } |
| 7398 | |
| 7399 | /** |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7400 | * @deprecated Use {@link #noteProxyOp(String, String, int, String, String)} instead |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7401 | */ |
| 7402 | @Deprecated |
| 7403 | public int noteProxyOp(@NonNull String op, @NonNull String proxiedPackageName) { |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7404 | return noteProxyOp(op, proxiedPackageName, Binder.getCallingUid(), null, null); |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7405 | } |
| 7406 | |
| 7407 | /** |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7408 | * @deprecated Use {@link #noteProxyOp(String, String, int, String, String)} instead |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7409 | * |
| 7410 | * @hide |
| 7411 | */ |
| 7412 | @Deprecated |
| 7413 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.Q, publicAlternatives = "Use {@link " |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7414 | + "#noteProxyOp(java.lang.String, java.lang.String, int, java.lang.String, " |
| 7415 | + "java.lang.String)} instead") |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7416 | public int noteProxyOp(int op, @Nullable String proxiedPackageName) { |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7417 | return noteProxyOp(op, proxiedPackageName, Binder.getCallingUid(), null, null); |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 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 OP_* 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 | * @hide |
| 7440 | */ |
| 7441 | public int noteProxyOp(int op, @Nullable String proxiedPackageName, int proxiedUid, |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 7442 | @Nullable String proxiedAttributionTag, @Nullable String message) { |
| 7443 | int mode = noteProxyOpNoThrow(op, proxiedPackageName, proxiedUid, proxiedAttributionTag, |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7444 | message); |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7445 | if (mode == MODE_ERRORED) { |
| 7446 | throw new SecurityException("Proxy package " + mContext.getOpPackageName() |
| 7447 | + " from uid " + Process.myUid() + " or calling package " + proxiedPackageName |
| 7448 | + " from uid " + proxiedUid + " not allowed to perform " + sOpNames[op]); |
| 7449 | } |
| 7450 | return mode; |
| 7451 | } |
| 7452 | |
| 7453 | /** |
| 7454 | * Make note of an application performing an operation on behalf of another application when |
| 7455 | * handling an IPC. This function will verify that the calling uid and proxied package name |
| 7456 | * match, and if not, return {@link #MODE_IGNORED}. If this call succeeds, the last execution |
| 7457 | * time of the operation for the proxied app and your app will be updated to the current time. |
| 7458 | * |
| 7459 | * @param op The operation to note. One of the OPSTR_* constants. |
| 7460 | * @param proxiedPackageName The name of the application calling into the proxy application. |
| 7461 | * @param proxiedUid The uid of the proxied application |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 7462 | * @param proxiedAttributionTag The proxied {@link Context#createAttributionContext |
| 7463 | * attribution tag} or {@code null} for default attribution |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7464 | * @param message A message describing the reason the op was noted |
| 7465 | * |
| 7466 | * @return Returns {@link #MODE_ALLOWED} if the operation is allowed, or {@link #MODE_IGNORED} |
| 7467 | * if it is not allowed and should be silently ignored (without causing the app to crash). |
| 7468 | * |
| 7469 | * @throws SecurityException If the proxy or proxied app has been configured to crash on this |
| 7470 | * op. |
| 7471 | */ |
| 7472 | public int noteProxyOp(@NonNull String op, @Nullable String proxiedPackageName, int proxiedUid, |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 7473 | @Nullable String proxiedAttributionTag, @Nullable String message) { |
| 7474 | return noteProxyOp(strOpToOp(op), proxiedPackageName, proxiedUid, proxiedAttributionTag, |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7475 | message); |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7476 | } |
| 7477 | |
| 7478 | /** |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7479 | * @deprecated Use {@link #noteProxyOpNoThrow(String, String, int, String, String)} instead |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7480 | */ |
| 7481 | @Deprecated |
| 7482 | public int noteProxyOpNoThrow(@NonNull String op, @NonNull String proxiedPackageName) { |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7483 | return noteProxyOpNoThrow(op, proxiedPackageName, Binder.getCallingUid(), null, null); |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7484 | } |
| 7485 | |
| 7486 | /** |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7487 | * @deprecated Use {@link #noteProxyOpNoThrow(String, String, int, String, String)} instead |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7488 | */ |
| 7489 | @Deprecated |
| 7490 | public int noteProxyOpNoThrow(@NonNull String op, @Nullable String proxiedPackageName, |
| 7491 | int proxiedUid) { |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7492 | return noteProxyOpNoThrow(op, proxiedPackageName, proxiedUid, null, null); |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7493 | } |
| 7494 | |
| 7495 | /** |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7496 | * Like {@link #noteProxyOp(String, String, int, String, String)} but instead |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7497 | * of throwing a {@link SecurityException} it returns {@link #MODE_ERRORED}. |
Philip P. Moltmann | 0d05e48 | 2019-02-08 13:05:25 -0800 | [diff] [blame] | 7498 | * |
| 7499 | * <p>This API requires package with the {@code proxiedPackageName} to belong to |
| 7500 | * {@code proxiedUid}. |
| 7501 | * |
| 7502 | * @param op The op to note |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7503 | * @param proxiedPackageName The package to note the op for |
| 7504 | * @param proxiedUid The uid the package belongs to |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 7505 | * @param proxiedAttributionTag The proxied {@link Context#createAttributionContext |
| 7506 | * attribution tag} or {@code null} for default attribution |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7507 | * @param message A message describing the reason the op was noted |
| 7508 | */ |
| 7509 | public int noteProxyOpNoThrow(@NonNull String op, @Nullable String proxiedPackageName, |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 7510 | int proxiedUid, @Nullable String proxiedAttributionTag, @Nullable String message) { |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7511 | return noteProxyOpNoThrow(strOpToOp(op), proxiedPackageName, proxiedUid, |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 7512 | proxiedAttributionTag, message); |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7513 | } |
| 7514 | |
| 7515 | /** |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7516 | * Like {@link #noteProxyOp(int, String, int, String, String)} but instead |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7517 | * of throwing a {@link SecurityException} it returns {@link #MODE_ERRORED}. |
| 7518 | * |
| 7519 | * @param op The op to note |
Philip P. Moltmann | 0d05e48 | 2019-02-08 13:05:25 -0800 | [diff] [blame] | 7520 | * @param proxiedPackageName The package to note the op for or {@code null} if the op should be |
| 7521 | * noted for the "android" package |
| 7522 | * @param proxiedUid The uid the package belongs to |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 7523 | * @param proxiedAttributionTag The proxied {@link Context#createAttributionContext |
| 7524 | * attribution tag} or {@code null} for default attribution |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7525 | * @param message A message describing the reason the op was noted |
| 7526 | * |
| 7527 | * @hide |
Philip P. Moltmann | 0d05e48 | 2019-02-08 13:05:25 -0800 | [diff] [blame] | 7528 | */ |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7529 | public int noteProxyOpNoThrow(int op, @Nullable String proxiedPackageName, int proxiedUid, |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 7530 | @Nullable String proxiedAttributionTag, @Nullable String message) { |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7531 | int myUid = Process.myUid(); |
Philip P. Moltmann | 0d05e48 | 2019-02-08 13:05:25 -0800 | [diff] [blame] | 7532 | |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7533 | try { |
David Cheung | 2ead966 | 2020-02-19 16:11:06 -0800 | [diff] [blame] | 7534 | collectNoteOpCallsForValidation(op); |
Philip P. Moltmann | da554e4 | 2019-12-20 11:21:02 -0800 | [diff] [blame] | 7535 | int collectionMode = getNotedOpCollectionMode(proxiedUid, proxiedPackageName, op); |
Stanislav Zholnin | 54762b2 | 2020-06-19 13:20:48 +0100 | [diff] [blame] | 7536 | boolean shouldCollectMessage = myUid == Process.SYSTEM_UID ? true : false; |
Philip P. Moltmann | da554e4 | 2019-12-20 11:21:02 -0800 | [diff] [blame] | 7537 | if (collectionMode == COLLECT_ASYNC) { |
| 7538 | if (message == null) { |
| 7539 | // Set stack trace as default message |
| 7540 | message = getFormattedStackTrace(); |
Stanislav Zholnin | 54762b2 | 2020-06-19 13:20:48 +0100 | [diff] [blame] | 7541 | shouldCollectMessage = true; |
Philip P. Moltmann | da554e4 | 2019-12-20 11:21:02 -0800 | [diff] [blame] | 7542 | } |
| 7543 | } |
| 7544 | |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7545 | int mode = mService.noteProxyOperation(op, proxiedUid, proxiedPackageName, |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 7546 | proxiedAttributionTag, myUid, mContext.getOpPackageName(), |
Stanislav Zholnin | 54762b2 | 2020-06-19 13:20:48 +0100 | [diff] [blame] | 7547 | mContext.getAttributionTag(), collectionMode == COLLECT_ASYNC, message, |
| 7548 | shouldCollectMessage); |
Philip P. Moltmann | da554e4 | 2019-12-20 11:21:02 -0800 | [diff] [blame] | 7549 | |
| 7550 | if (mode == MODE_ALLOWED) { |
| 7551 | if (collectionMode == COLLECT_SELF) { |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 7552 | collectNotedOpForSelf(op, proxiedAttributionTag); |
Philip P. Moltmann | da554e4 | 2019-12-20 11:21:02 -0800 | [diff] [blame] | 7553 | } else if (collectionMode == COLLECT_SYNC |
| 7554 | // Only collect app-ops when the proxy is trusted |
| 7555 | && mContext.checkPermission(Manifest.permission.UPDATE_APP_OPS_STATS, -1, |
| 7556 | myUid) == PackageManager.PERMISSION_GRANTED) { |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 7557 | collectNotedOpSync(op, proxiedAttributionTag); |
Philip P. Moltmann | da554e4 | 2019-12-20 11:21:02 -0800 | [diff] [blame] | 7558 | } |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7559 | } |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 7560 | |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7561 | return mode; |
| 7562 | } catch (RemoteException e) { |
| 7563 | throw e.rethrowFromSystemServer(); |
| 7564 | } |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 7565 | } |
| 7566 | |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 7567 | /** |
| 7568 | * 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] | 7569 | * 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] | 7570 | * String, String)} or {@link #startOp(int, int, String, boolean, String, String)} for your |
| 7571 | * actual security checks, which also ensure that the given uid and package name are consistent. |
| 7572 | * This function can just be used for a quick check to see if an operation has been disabled for |
| 7573 | * the application, as an early reject of some work. This does not modify the time stamp or |
| 7574 | * other data about the operation. |
Dianne Hackborn | c216a26 | 2018-04-26 13:46:22 -0700 | [diff] [blame] | 7575 | * |
| 7576 | * <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] | 7577 | * {@link #noteOp(String, int, String, String, String)} or |
| 7578 | * {@link #startOp(int, int, String, boolean, String, String)} to cover):</p> |
Dianne Hackborn | c216a26 | 2018-04-26 13:46:22 -0700 | [diff] [blame] | 7579 | * <ul> |
| 7580 | * <li>Verifying the uid and package are consistent, so callers can't spoof |
| 7581 | * their identity.</li> |
| 7582 | * <li>Taking into account the current foreground/background state of the |
| 7583 | * app; apps whose mode varies by this state will always be reported |
| 7584 | * as {@link #MODE_ALLOWED}.</li> |
| 7585 | * </ul> |
| 7586 | * |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 7587 | * @param op The operation to check. One of the OP_* constants. |
| 7588 | * @param uid The user id of the application attempting to perform the operation. |
| 7589 | * @param packageName The name of the application attempting to perform the operation. |
| 7590 | * @return Returns {@link #MODE_ALLOWED} if the operation is allowed, or |
| 7591 | * {@link #MODE_IGNORED} if it is not allowed and should be silently ignored (without |
| 7592 | * causing the app to crash). |
| 7593 | * @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] | 7594 | * @hide |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 7595 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 7596 | @UnsupportedAppUsage |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 7597 | public int checkOp(int op, int uid, String packageName) { |
| 7598 | try { |
| 7599 | int mode = mService.checkOperation(op, uid, packageName); |
| 7600 | if (mode == MODE_ERRORED) { |
Dianne Hackborn | 95d7853 | 2013-09-11 09:51:14 -0700 | [diff] [blame] | 7601 | throw new SecurityException(buildSecurityExceptionMsg(op, uid, packageName)); |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 7602 | } |
| 7603 | return mode; |
| 7604 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 7605 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 7606 | } |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 7607 | } |
| 7608 | |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 7609 | /** |
| 7610 | * Like {@link #checkOp} but instead of throwing a {@link SecurityException} it |
| 7611 | * returns {@link #MODE_ERRORED}. |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 7612 | * @hide |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 7613 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 7614 | @UnsupportedAppUsage |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 7615 | public int checkOpNoThrow(int op, int uid, String packageName) { |
| 7616 | try { |
Dianne Hackborn | 65a4f25 | 2018-05-08 17:30:48 -0700 | [diff] [blame] | 7617 | int mode = mService.checkOperation(op, uid, packageName); |
| 7618 | return mode == AppOpsManager.MODE_FOREGROUND ? AppOpsManager.MODE_ALLOWED : mode; |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 7619 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 7620 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 7621 | } |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 7622 | } |
| 7623 | |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 7624 | /** |
Philip P. Moltmann | a04b9ab | 2020-02-13 09:54:04 -0800 | [diff] [blame] | 7625 | * @deprecated Use {@link PackageManager#getPackageUid} instead |
Jeff Sharkey | 911d7f4 | 2013-09-05 18:11:45 -0700 | [diff] [blame] | 7626 | */ |
Philip P. Moltmann | a04b9ab | 2020-02-13 09:54:04 -0800 | [diff] [blame] | 7627 | @Deprecated |
Dianne Hackborn | 6287849 | 2019-03-11 15:57:07 -0700 | [diff] [blame] | 7628 | public void checkPackage(int uid, @NonNull String packageName) { |
Jeff Sharkey | 911d7f4 | 2013-09-05 18:11:45 -0700 | [diff] [blame] | 7629 | try { |
| 7630 | if (mService.checkPackage(uid, packageName) != MODE_ALLOWED) { |
| 7631 | throw new SecurityException( |
| 7632 | "Package " + packageName + " does not belong to " + uid); |
| 7633 | } |
| 7634 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 7635 | throw e.rethrowFromSystemServer(); |
Jeff Sharkey | 911d7f4 | 2013-09-05 18:11:45 -0700 | [diff] [blame] | 7636 | } |
| 7637 | } |
| 7638 | |
| 7639 | /** |
John Spurlock | 1af30c7 | 2014-03-10 08:33:35 -0400 | [diff] [blame] | 7640 | * Like {@link #checkOp} but at a stream-level for audio operations. |
| 7641 | * @hide |
| 7642 | */ |
| 7643 | public int checkAudioOp(int op, int stream, int uid, String packageName) { |
| 7644 | try { |
| 7645 | final int mode = mService.checkAudioOperation(op, stream, uid, packageName); |
| 7646 | if (mode == MODE_ERRORED) { |
| 7647 | throw new SecurityException(buildSecurityExceptionMsg(op, uid, packageName)); |
| 7648 | } |
| 7649 | return mode; |
| 7650 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 7651 | throw e.rethrowFromSystemServer(); |
John Spurlock | 1af30c7 | 2014-03-10 08:33:35 -0400 | [diff] [blame] | 7652 | } |
John Spurlock | 1af30c7 | 2014-03-10 08:33:35 -0400 | [diff] [blame] | 7653 | } |
| 7654 | |
| 7655 | /** |
| 7656 | * Like {@link #checkAudioOp} but instead of throwing a {@link SecurityException} it |
| 7657 | * returns {@link #MODE_ERRORED}. |
| 7658 | * @hide |
| 7659 | */ |
| 7660 | public int checkAudioOpNoThrow(int op, int stream, int uid, String packageName) { |
| 7661 | try { |
| 7662 | return mService.checkAudioOperation(op, stream, uid, packageName); |
| 7663 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 7664 | throw e.rethrowFromSystemServer(); |
John Spurlock | 1af30c7 | 2014-03-10 08:33:35 -0400 | [diff] [blame] | 7665 | } |
John Spurlock | 1af30c7 | 2014-03-10 08:33:35 -0400 | [diff] [blame] | 7666 | } |
| 7667 | |
Philip P. Moltmann | 6c6403e | 2019-12-09 10:08:29 -0800 | [diff] [blame] | 7668 | /** |
| 7669 | * @deprecated Use own local {@link android.os.Binder#Binder()} |
| 7670 | * |
| 7671 | * @hide |
| 7672 | */ |
| 7673 | @Deprecated |
| 7674 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.Q, publicAlternatives = "Create own " |
| 7675 | + "local {@link android.os.Binder}") |
Dianne Hackborn | e98f5db | 2013-07-17 17:23:25 -0700 | [diff] [blame] | 7676 | public static IBinder getToken(IAppOpsService service) { |
Philip P. Moltmann | 6c6403e | 2019-12-09 10:08:29 -0800 | [diff] [blame] | 7677 | return getClientId(); |
Dianne Hackborn | e98f5db | 2013-07-17 17:23:25 -0700 | [diff] [blame] | 7678 | } |
| 7679 | |
Philip P. Moltmann | 6c6403e | 2019-12-09 10:08:29 -0800 | [diff] [blame] | 7680 | /** @hide */ |
| 7681 | public static IBinder getClientId() { |
| 7682 | synchronized (AppOpsManager.class) { |
| 7683 | if (sClientId == null) { |
| 7684 | sClientId = new Binder(); |
| 7685 | } |
| 7686 | |
| 7687 | return sClientId; |
| 7688 | } |
| 7689 | } |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7690 | |
Stanislav Zholnin | 90516b9 | 2020-01-20 14:03:06 +0000 | [diff] [blame] | 7691 | /** @hide */ |
| 7692 | private static IAppOpsService getService() { |
| 7693 | synchronized (sLock) { |
| 7694 | if (sService == null) { |
| 7695 | sService = IAppOpsService.Stub.asInterface( |
| 7696 | ServiceManager.getService(Context.APP_OPS_SERVICE)); |
| 7697 | } |
| 7698 | return sService; |
| 7699 | } |
| 7700 | } |
| 7701 | |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7702 | /** |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7703 | * @deprecated use {@link #startOp(String, int, String, String, String)} instead |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7704 | */ |
| 7705 | @Deprecated |
| 7706 | public int startOp(@NonNull String op, int uid, @NonNull String packageName) { |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7707 | return startOp(op, uid, packageName, null, null); |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 7708 | } |
| 7709 | |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 7710 | /** |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7711 | * @deprecated Use {@link #startOp(int, int, String, boolean, String, String)} instead |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 7712 | * |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 7713 | * @hide |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 7714 | */ |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7715 | @Deprecated |
| 7716 | public int startOp(int op) { |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7717 | return startOp(op, Process.myUid(), mContext.getOpPackageName(), false, null, null); |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 7718 | } |
| 7719 | |
| 7720 | /** |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7721 | * @deprecated Use {@link #startOp(int, int, String, boolean, String, String)} instead |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7722 | * |
| 7723 | * @hide |
| 7724 | */ |
| 7725 | @Deprecated |
| 7726 | public int startOp(int op, int uid, String packageName) { |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7727 | return startOp(op, uid, packageName, false, null, null); |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7728 | } |
| 7729 | |
| 7730 | /** |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7731 | * @deprecated Use {@link #startOp(int, int, String, boolean, String, String)} instead |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7732 | * |
| 7733 | * @hide |
| 7734 | */ |
| 7735 | @Deprecated |
| 7736 | public int startOp(int op, int uid, String packageName, boolean startIfModeDefault) { |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7737 | return startOp(op, uid, packageName, startIfModeDefault, null, null); |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7738 | } |
| 7739 | |
| 7740 | /** |
| 7741 | * Report that an application has started executing a long-running operation. |
| 7742 | * |
| 7743 | * @param op The operation to start. One of the OPSTR_* constants. |
| 7744 | * @param uid The user id of the application attempting to perform the operation. |
| 7745 | * @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] | 7746 | * @param attributionTag The {@link Context#createAttributionContext attribution tag} or |
| 7747 | * {@code null} for default attribution |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7748 | * @param message Description why op was started |
| 7749 | * |
| 7750 | * @return Returns {@link #MODE_ALLOWED} if the operation is allowed, or |
| 7751 | * {@link #MODE_IGNORED} if it is not allowed and should be silently ignored (without |
| 7752 | * causing the app to crash). |
| 7753 | * |
| 7754 | * @throws SecurityException If the app has been configured to crash on this op or |
| 7755 | * the package is not in the passed in UID. |
| 7756 | */ |
| 7757 | public int startOp(@NonNull String op, int uid, @Nullable String packageName, |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 7758 | @Nullable String attributionTag, @Nullable String message) { |
| 7759 | return startOp(strOpToOp(op), uid, packageName, false, attributionTag, message); |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7760 | } |
| 7761 | |
| 7762 | /** |
| 7763 | * Report that an application has started executing a long-running operation. |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 7764 | * |
| 7765 | * @param op The operation to start. One of the OP_* constants. |
| 7766 | * @param uid The user id of the application attempting to perform the operation. |
| 7767 | * @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] | 7768 | * @param attributionTag The {@link Context#createAttributionContext attribution tag} or |
| 7769 | * {@code null} for default attribution |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7770 | * @param startIfModeDefault Whether to start if mode is {@link #MODE_DEFAULT}. |
| 7771 | * @param message Description why op was started |
| 7772 | * |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 7773 | * @return Returns {@link #MODE_ALLOWED} if the operation is allowed, or |
| 7774 | * {@link #MODE_IGNORED} if it is not allowed and should be silently ignored (without |
| 7775 | * causing the app to crash). |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 7776 | * |
| 7777 | * @throws SecurityException If the app has been configured to crash on this op or |
| 7778 | * the package is not in the passed in UID. |
| 7779 | * |
| 7780 | * @hide |
| 7781 | */ |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7782 | 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] | 7783 | @Nullable String attributionTag, @Nullable String message) { |
| 7784 | final int mode = startOpNoThrow(op, uid, packageName, startIfModeDefault, attributionTag, |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7785 | message); |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 7786 | if (mode == MODE_ERRORED) { |
| 7787 | throw new SecurityException(buildSecurityExceptionMsg(op, uid, packageName)); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 7788 | } |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 7789 | return mode; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 7790 | } |
| 7791 | |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 7792 | /** |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7793 | * @deprecated use {@link #startOpNoThrow(String, int, String, String, String)} instead |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 7794 | */ |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7795 | @Deprecated |
| 7796 | public int startOpNoThrow(@NonNull String op, int uid, @NonNull String packageName) { |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7797 | return startOpNoThrow(op, uid, packageName, null, null); |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 7798 | } |
| 7799 | |
| 7800 | /** |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7801 | * @deprecated Use {@link #startOpNoThrow(int, int, String, boolean, String, String} instead |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7802 | * |
| 7803 | * @hide |
| 7804 | */ |
| 7805 | @Deprecated |
| 7806 | public int startOpNoThrow(int op, int uid, String packageName) { |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7807 | return startOpNoThrow(op, uid, packageName, false, null, null); |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7808 | } |
| 7809 | |
| 7810 | /** |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7811 | * @deprecated Use {@link #startOpNoThrow(int, int, String, boolean, String, String} instead |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7812 | * |
| 7813 | * @hide |
| 7814 | */ |
| 7815 | @Deprecated |
| 7816 | public int startOpNoThrow(int op, int uid, String packageName, boolean startIfModeDefault) { |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7817 | return startOpNoThrow(op, uid, packageName, startIfModeDefault, null, null); |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7818 | } |
| 7819 | |
| 7820 | /** |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7821 | * 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] | 7822 | * {@link SecurityException} it returns {@link #MODE_ERRORED}. |
| 7823 | * |
| 7824 | * @param op The operation to start. One of the OP_* constants. |
| 7825 | * @param uid The user id of the application attempting to perform the operation. |
| 7826 | * @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] | 7827 | * @param attributionTag The {@link Context#createAttributionContext attribution tag} or |
| 7828 | * {@code null} for default attribution |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7829 | * @param message Description why op was started |
| 7830 | * |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 7831 | * @return Returns {@link #MODE_ALLOWED} if the operation is allowed, or |
| 7832 | * {@link #MODE_IGNORED} if it is not allowed and should be silently ignored (without |
| 7833 | * causing the app to crash). |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7834 | */ |
| 7835 | public int startOpNoThrow(@NonNull String op, int uid, @NonNull String packageName, |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 7836 | @NonNull String attributionTag, @Nullable String message) { |
| 7837 | return startOpNoThrow(strOpToOp(op), uid, packageName, false, attributionTag, message); |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7838 | } |
| 7839 | |
| 7840 | /** |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7841 | * 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] | 7842 | * {@link SecurityException} it returns {@link #MODE_ERRORED}. |
| 7843 | * |
| 7844 | * @param op The operation to start. One of the OP_* constants. |
| 7845 | * @param uid The user id of the application attempting to perform the operation. |
| 7846 | * @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] | 7847 | * @param attributionTag The {@link Context#createAttributionContext attribution tag} or |
| 7848 | * {@code null} for default attribution |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 7849 | * @param startIfModeDefault Whether to start if mode is {@link #MODE_DEFAULT}. |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7850 | * @param message Description why op was started |
| 7851 | * |
| 7852 | * @return Returns {@link #MODE_ALLOWED} if the operation is allowed, or |
| 7853 | * {@link #MODE_IGNORED} if it is not allowed and should be silently ignored (without |
| 7854 | * causing the app to crash). |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 7855 | * |
| 7856 | * @hide |
| 7857 | */ |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7858 | public int startOpNoThrow(int op, int uid, @NonNull String packageName, |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 7859 | boolean startIfModeDefault, @Nullable String attributionTag, @Nullable String message) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 7860 | try { |
David Cheung | 2ead966 | 2020-02-19 16:11:06 -0800 | [diff] [blame] | 7861 | collectNoteOpCallsForValidation(op); |
Philip P. Moltmann | da554e4 | 2019-12-20 11:21:02 -0800 | [diff] [blame] | 7862 | int collectionMode = getNotedOpCollectionMode(uid, packageName, op); |
Stanislav Zholnin | 54762b2 | 2020-06-19 13:20:48 +0100 | [diff] [blame] | 7863 | boolean shouldCollectMessage = Process.myUid() == Process.SYSTEM_UID ? true : false; |
Philip P. Moltmann | da554e4 | 2019-12-20 11:21:02 -0800 | [diff] [blame] | 7864 | if (collectionMode == COLLECT_ASYNC) { |
| 7865 | if (message == null) { |
| 7866 | // Set stack trace as default message |
| 7867 | message = getFormattedStackTrace(); |
Stanislav Zholnin | 54762b2 | 2020-06-19 13:20:48 +0100 | [diff] [blame] | 7868 | shouldCollectMessage = true; |
Philip P. Moltmann | da554e4 | 2019-12-20 11:21:02 -0800 | [diff] [blame] | 7869 | } |
| 7870 | } |
| 7871 | |
Philip P. Moltmann | 6c6403e | 2019-12-09 10:08:29 -0800 | [diff] [blame] | 7872 | int mode = mService.startOperation(getClientId(), op, uid, packageName, |
Stanislav Zholnin | 54762b2 | 2020-06-19 13:20:48 +0100 | [diff] [blame] | 7873 | attributionTag, startIfModeDefault, collectionMode == COLLECT_ASYNC, message, |
| 7874 | shouldCollectMessage); |
Philip P. Moltmann | da554e4 | 2019-12-20 11:21:02 -0800 | [diff] [blame] | 7875 | |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7876 | if (mode == MODE_ALLOWED) { |
Philip P. Moltmann | da554e4 | 2019-12-20 11:21:02 -0800 | [diff] [blame] | 7877 | if (collectionMode == COLLECT_SELF) { |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 7878 | collectNotedOpForSelf(op, attributionTag); |
Philip P. Moltmann | da554e4 | 2019-12-20 11:21:02 -0800 | [diff] [blame] | 7879 | } else if (collectionMode == COLLECT_SYNC) { |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 7880 | collectNotedOpSync(op, attributionTag); |
Philip P. Moltmann | da554e4 | 2019-12-20 11:21:02 -0800 | [diff] [blame] | 7881 | } |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7882 | } |
| 7883 | |
| 7884 | return mode; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 7885 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 7886 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 7887 | } |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 7888 | } |
| 7889 | |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 7890 | /** |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7891 | * @deprecated Use {@link #finishOp(String, int, String, String)} instead |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7892 | * |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 7893 | * @hide |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 7894 | */ |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7895 | @Deprecated |
| 7896 | public void finishOp(int op) { |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7897 | finishOp(op, Process.myUid(), mContext.getOpPackageName(), null); |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7898 | } |
| 7899 | |
| 7900 | /** |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7901 | * @deprecated Use {@link #finishOp(String, int, String, String)} instead |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7902 | */ |
| 7903 | public void finishOp(@NonNull String op, int uid, @NonNull String packageName) { |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7904 | finishOp(strOpToOp(op), uid, packageName, null); |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7905 | } |
| 7906 | |
| 7907 | /** |
| 7908 | * 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] | 7909 | * been started with {@link #startOp(String, int, String, String, String)}. There is no |
| 7910 | * validation of input or result; the parameters supplied here must be the exact same ones |
| 7911 | * previously passed in when starting the operation. |
| 7912 | */ |
| 7913 | public void finishOp(@NonNull String op, int uid, @NonNull String packageName, |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 7914 | @Nullable String attributionTag) { |
| 7915 | finishOp(strOpToOp(op), uid, packageName, attributionTag); |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7916 | } |
| 7917 | |
| 7918 | /** |
| 7919 | * @deprecated Use {@link #finishOp(int, int, String, String)} instead |
| 7920 | * |
| 7921 | * @hide |
| 7922 | */ |
| 7923 | public void finishOp(int op, int uid, @NonNull String packageName) { |
| 7924 | finishOp(op, uid, packageName, null); |
| 7925 | } |
| 7926 | |
| 7927 | /** |
| 7928 | * Report that an application is no longer performing an operation that had previously |
| 7929 | * 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] | 7930 | * validation of input or result; the parameters supplied here must be the exact same ones |
| 7931 | * previously passed in when starting the operation. |
| 7932 | * |
| 7933 | * @hide |
| 7934 | */ |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7935 | public void finishOp(int op, int uid, @NonNull String packageName, |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 7936 | @Nullable String attributionTag) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 7937 | try { |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 7938 | mService.finishOperation(getClientId(), op, uid, packageName, attributionTag); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 7939 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 7940 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 7941 | } |
| 7942 | } |
| 7943 | |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 7944 | /** |
Philip P. Moltmann | a04b9ab | 2020-02-13 09:54:04 -0800 | [diff] [blame] | 7945 | * Checks whether the given op for a package is active, i.e. did someone call {@link #startOp} |
| 7946 | * without {@link #finishOp} yet. |
Jeff Sharkey | 7095ab9 | 2019-08-20 16:50:28 -0600 | [diff] [blame] | 7947 | * <p> |
| 7948 | * If you don't hold the {@code android.Manifest.permission#WATCH_APPOPS} |
| 7949 | * permission you can query only for your UID. |
| 7950 | * |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7951 | * @see #finishOp(String, int, String, String) |
| 7952 | * @see #startOp(String, int, String, String, String) |
Jeff Sharkey | 7095ab9 | 2019-08-20 16:50:28 -0600 | [diff] [blame] | 7953 | */ |
| 7954 | public boolean isOpActive(@NonNull String op, int uid, @NonNull String packageName) { |
| 7955 | return isOperationActive(strOpToOp(op), uid, packageName); |
| 7956 | } |
| 7957 | |
| 7958 | /** |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7959 | * Start collection of noted appops on this thread. |
| 7960 | * |
| 7961 | * <p>Called at the beginning of a two way binder transaction. |
| 7962 | * |
| 7963 | * @see #finishNotedAppOpsCollection() |
| 7964 | * |
| 7965 | * @hide |
| 7966 | */ |
| 7967 | public static void startNotedAppOpsCollection(int callingUid) { |
| 7968 | sBinderThreadCallingUid.set(callingUid); |
| 7969 | } |
| 7970 | |
| 7971 | /** |
| 7972 | * State of a temporarily paused noted app-ops collection. |
| 7973 | * |
| 7974 | * @see #pauseNotedAppOpsCollection() |
| 7975 | * |
| 7976 | * @hide |
| 7977 | */ |
| 7978 | public static class PausedNotedAppOpsCollection { |
| 7979 | final int mUid; |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7980 | final @Nullable ArrayMap<String, long[]> mCollectedNotedAppOps; |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7981 | |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 7982 | PausedNotedAppOpsCollection(int uid, @Nullable ArrayMap<String, |
| 7983 | long[]> collectedNotedAppOps) { |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 7984 | mUid = uid; |
| 7985 | mCollectedNotedAppOps = collectedNotedAppOps; |
| 7986 | } |
| 7987 | } |
| 7988 | |
| 7989 | /** |
| 7990 | * Temporarily suspend collection of noted app-ops when binder-thread calls into the other |
| 7991 | * process. During such a call there might be call-backs coming back on the same thread which |
| 7992 | * should not be accounted to the current collection. |
| 7993 | * |
| 7994 | * @return a state needed to resume the collection |
| 7995 | * |
| 7996 | * @hide |
| 7997 | */ |
| 7998 | public static @Nullable PausedNotedAppOpsCollection pauseNotedAppOpsCollection() { |
| 7999 | Integer previousUid = sBinderThreadCallingUid.get(); |
| 8000 | if (previousUid != null) { |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 8001 | ArrayMap<String, long[]> previousCollectedNotedAppOps = |
| 8002 | sAppOpsNotedInThisBinderTransaction.get(); |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8003 | |
| 8004 | sBinderThreadCallingUid.remove(); |
| 8005 | sAppOpsNotedInThisBinderTransaction.remove(); |
| 8006 | |
| 8007 | return new PausedNotedAppOpsCollection(previousUid, previousCollectedNotedAppOps); |
| 8008 | } |
| 8009 | |
| 8010 | return null; |
| 8011 | } |
| 8012 | |
| 8013 | /** |
| 8014 | * Resume a collection paused via {@link #pauseNotedAppOpsCollection}. |
| 8015 | * |
| 8016 | * @param prevCollection The state of the previous collection |
| 8017 | * |
| 8018 | * @hide |
| 8019 | */ |
| 8020 | public static void resumeNotedAppOpsCollection( |
| 8021 | @Nullable PausedNotedAppOpsCollection prevCollection) { |
| 8022 | if (prevCollection != null) { |
| 8023 | sBinderThreadCallingUid.set(prevCollection.mUid); |
| 8024 | |
| 8025 | if (prevCollection.mCollectedNotedAppOps != null) { |
| 8026 | sAppOpsNotedInThisBinderTransaction.set(prevCollection.mCollectedNotedAppOps); |
| 8027 | } |
| 8028 | } |
| 8029 | } |
| 8030 | |
| 8031 | /** |
| 8032 | * Finish collection of noted appops on this thread. |
| 8033 | * |
| 8034 | * <p>Called at the end of a two way binder transaction. |
| 8035 | * |
| 8036 | * @see #startNotedAppOpsCollection(int) |
| 8037 | * |
| 8038 | * @hide |
| 8039 | */ |
| 8040 | public static void finishNotedAppOpsCollection() { |
| 8041 | sBinderThreadCallingUid.remove(); |
| 8042 | sAppOpsNotedInThisBinderTransaction.remove(); |
| 8043 | } |
| 8044 | |
| 8045 | /** |
Philip P. Moltmann | da554e4 | 2019-12-20 11:21:02 -0800 | [diff] [blame] | 8046 | * Collect a noted op for the current process. |
| 8047 | * |
| 8048 | * @param op The noted op |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 8049 | * @param attributionTag The attribution tag the op is noted for |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8050 | */ |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 8051 | private void collectNotedOpForSelf(int op, @Nullable String attributionTag) { |
Philip P. Moltmann | da554e4 | 2019-12-20 11:21:02 -0800 | [diff] [blame] | 8052 | synchronized (sLock) { |
Philip P. Moltmann | 5892a8f | 2020-03-03 12:05:55 -0800 | [diff] [blame] | 8053 | if (sOnOpNotedCallback != null) { |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 8054 | sOnOpNotedCallback.onSelfNoted(new SyncNotedAppOp(op, attributionTag)); |
Philip P. Moltmann | da554e4 | 2019-12-20 11:21:02 -0800 | [diff] [blame] | 8055 | } |
| 8056 | } |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 8057 | sMessageCollector.onSelfNoted(new SyncNotedAppOp(op, attributionTag)); |
Philip P. Moltmann | da554e4 | 2019-12-20 11:21:02 -0800 | [diff] [blame] | 8058 | } |
| 8059 | |
| 8060 | /** |
| 8061 | * Collect a noted op when inside of a two-way binder call. |
| 8062 | * |
| 8063 | * <p> Delivered to caller via {@link #prefixParcelWithAppOpsIfNeeded} |
| 8064 | * |
| 8065 | * @param op The noted op |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 8066 | * @param attributionTag The attribution tag the op is noted for |
Philip P. Moltmann | da554e4 | 2019-12-20 11:21:02 -0800 | [diff] [blame] | 8067 | */ |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 8068 | private void collectNotedOpSync(int op, @Nullable String attributionTag) { |
Philip P. Moltmann | da554e4 | 2019-12-20 11:21:02 -0800 | [diff] [blame] | 8069 | // If this is inside of a two-way binder call: |
| 8070 | // We are inside of a two-way binder call. Delivered to caller via |
| 8071 | // {@link #prefixParcelWithAppOpsIfNeeded} |
| 8072 | ArrayMap<String, long[]> appOpsNoted = sAppOpsNotedInThisBinderTransaction.get(); |
| 8073 | if (appOpsNoted == null) { |
| 8074 | appOpsNoted = new ArrayMap<>(1); |
| 8075 | sAppOpsNotedInThisBinderTransaction.set(appOpsNoted); |
| 8076 | } |
| 8077 | |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 8078 | long[] appOpsNotedForAttribution = appOpsNoted.get(attributionTag); |
| 8079 | if (appOpsNotedForAttribution == null) { |
| 8080 | appOpsNotedForAttribution = new long[2]; |
| 8081 | appOpsNoted.put(attributionTag, appOpsNotedForAttribution); |
Philip P. Moltmann | da554e4 | 2019-12-20 11:21:02 -0800 | [diff] [blame] | 8082 | } |
| 8083 | |
| 8084 | if (op < 64) { |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 8085 | appOpsNotedForAttribution[0] |= 1L << op; |
Philip P. Moltmann | da554e4 | 2019-12-20 11:21:02 -0800 | [diff] [blame] | 8086 | } else { |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 8087 | appOpsNotedForAttribution[1] |= 1L << (op - 64); |
Philip P. Moltmann | da554e4 | 2019-12-20 11:21:02 -0800 | [diff] [blame] | 8088 | } |
| 8089 | } |
| 8090 | |
| 8091 | /** @hide */ |
| 8092 | @Retention(RetentionPolicy.SOURCE) |
| 8093 | @IntDef(value = { |
| 8094 | DONT_COLLECT, |
| 8095 | COLLECT_SELF, |
| 8096 | COLLECT_SYNC, |
| 8097 | COLLECT_ASYNC |
| 8098 | }) |
| 8099 | private @interface NotedOpCollectionMode {} |
| 8100 | private static final int DONT_COLLECT = 0; |
| 8101 | private static final int COLLECT_SELF = 1; |
| 8102 | private static final int COLLECT_SYNC = 2; |
| 8103 | private static final int COLLECT_ASYNC = 3; |
| 8104 | |
| 8105 | /** |
| 8106 | * Mark an app-op as noted. |
| 8107 | */ |
| 8108 | private @NotedOpCollectionMode int getNotedOpCollectionMode(int uid, |
| 8109 | @Nullable String packageName, int op) { |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 8110 | if (packageName == null) { |
| 8111 | packageName = "android"; |
| 8112 | } |
| 8113 | |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8114 | // check it the appops needs to be collected and cache result |
Philip P. Moltmann | da554e4 | 2019-12-20 11:21:02 -0800 | [diff] [blame] | 8115 | if (sAppOpsToNote[op] == SHOULD_COLLECT_NOTE_OP_NOT_INITIALIZED) { |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8116 | boolean shouldCollectNotes; |
| 8117 | try { |
Philip P. Moltmann | da554e4 | 2019-12-20 11:21:02 -0800 | [diff] [blame] | 8118 | shouldCollectNotes = mService.shouldCollectNotes(op); |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8119 | } catch (RemoteException e) { |
Philip P. Moltmann | da554e4 | 2019-12-20 11:21:02 -0800 | [diff] [blame] | 8120 | return DONT_COLLECT; |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8121 | } |
| 8122 | |
| 8123 | if (shouldCollectNotes) { |
Philip P. Moltmann | da554e4 | 2019-12-20 11:21:02 -0800 | [diff] [blame] | 8124 | sAppOpsToNote[op] = SHOULD_COLLECT_NOTE_OP; |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8125 | } else { |
Philip P. Moltmann | da554e4 | 2019-12-20 11:21:02 -0800 | [diff] [blame] | 8126 | sAppOpsToNote[op] = SHOULD_NOT_COLLECT_NOTE_OP; |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8127 | } |
| 8128 | } |
| 8129 | |
Philip P. Moltmann | da554e4 | 2019-12-20 11:21:02 -0800 | [diff] [blame] | 8130 | if (sAppOpsToNote[op] != SHOULD_COLLECT_NOTE_OP) { |
| 8131 | return DONT_COLLECT; |
| 8132 | } |
| 8133 | |
| 8134 | synchronized (sLock) { |
| 8135 | if (uid == Process.myUid() |
| 8136 | && packageName.equals(ActivityThread.currentOpPackageName())) { |
| 8137 | return COLLECT_SELF; |
| 8138 | } |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8139 | } |
| 8140 | |
| 8141 | Integer binderUid = sBinderThreadCallingUid.get(); |
| 8142 | |
Philip P. Moltmann | 9bcc406 | 2019-09-06 12:27:59 -0700 | [diff] [blame] | 8143 | if (binderUid != null && binderUid == uid) { |
Philip P. Moltmann | da554e4 | 2019-12-20 11:21:02 -0800 | [diff] [blame] | 8144 | return COLLECT_SYNC; |
Philip P. Moltmann | 9bcc406 | 2019-09-06 12:27:59 -0700 | [diff] [blame] | 8145 | } else { |
Philip P. Moltmann | da554e4 | 2019-12-20 11:21:02 -0800 | [diff] [blame] | 8146 | return COLLECT_ASYNC; |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8147 | } |
| 8148 | } |
| 8149 | |
| 8150 | /** |
| 8151 | * Append app-ops noted in the current two-way binder transaction to parcel. |
| 8152 | * |
| 8153 | * <p>This is called on the callee side of a two way binder transaction just before the |
| 8154 | * transaction returns. |
| 8155 | * |
| 8156 | * @param p the parcel to append the noted app-ops to |
| 8157 | * |
| 8158 | * @hide |
| 8159 | */ |
| 8160 | public static void prefixParcelWithAppOpsIfNeeded(@NonNull Parcel p) { |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 8161 | ArrayMap<String, long[]> notedAppOps = sAppOpsNotedInThisBinderTransaction.get(); |
| 8162 | if (notedAppOps == null) { |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8163 | return; |
| 8164 | } |
| 8165 | |
| 8166 | p.writeInt(Parcel.EX_HAS_NOTED_APPOPS_REPLY_HEADER); |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 8167 | |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 8168 | int numAttributionWithNotesAppOps = notedAppOps.size(); |
| 8169 | p.writeInt(numAttributionWithNotesAppOps); |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 8170 | |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 8171 | for (int i = 0; i < numAttributionWithNotesAppOps; i++) { |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 8172 | p.writeString(notedAppOps.keyAt(i)); |
| 8173 | p.writeLong(notedAppOps.valueAt(i)[0]); |
| 8174 | p.writeLong(notedAppOps.valueAt(i)[1]); |
| 8175 | } |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8176 | } |
| 8177 | |
| 8178 | /** |
| 8179 | * Read app-ops noted during a two-way binder transaction from parcel. |
| 8180 | * |
| 8181 | * <p>This is called on the calling side of a two way binder transaction just after the |
| 8182 | * transaction returns. |
| 8183 | * |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8184 | * @param p The parcel to read from |
| 8185 | * |
| 8186 | * @hide |
| 8187 | */ |
| 8188 | public static void readAndLogNotedAppops(@NonNull Parcel p) { |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 8189 | int numAttributionsWithNotedAppOps = p.readInt(); |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8190 | |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 8191 | for (int i = 0; i < numAttributionsWithNotedAppOps; i++) { |
| 8192 | String attributionTag = p.readString(); |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 8193 | long[] rawNotedAppOps = new long[2]; |
| 8194 | rawNotedAppOps[0] = p.readLong(); |
| 8195 | rawNotedAppOps[1] = p.readLong(); |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8196 | |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 8197 | if (rawNotedAppOps[0] != 0 || rawNotedAppOps[1] != 0) { |
| 8198 | BitSet notedAppOps = BitSet.valueOf(rawNotedAppOps); |
| 8199 | |
| 8200 | synchronized (sLock) { |
| 8201 | for (int code = notedAppOps.nextSetBit(0); code != -1; |
| 8202 | code = notedAppOps.nextSetBit(code + 1)) { |
Philip P. Moltmann | 5892a8f | 2020-03-03 12:05:55 -0800 | [diff] [blame] | 8203 | if (sOnOpNotedCallback != null) { |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 8204 | sOnOpNotedCallback.onNoted(new SyncNotedAppOp(code, attributionTag)); |
Stanislav Zholnin | e44f134 | 2020-06-02 20:26:20 +0100 | [diff] [blame] | 8205 | } else { |
Stanislav Zholnin | 456b496 | 2020-06-18 16:52:50 +0100 | [diff] [blame] | 8206 | String message = getFormattedStackTrace(); |
| 8207 | sUnforwardedOps.add( |
| 8208 | new AsyncNotedAppOp(code, Process.myUid(), attributionTag, |
| 8209 | message, System.currentTimeMillis())); |
Stanislav Zholnin | e44f134 | 2020-06-02 20:26:20 +0100 | [diff] [blame] | 8210 | if (sUnforwardedOps.size() > MAX_UNFORWARDED_OPS) { |
| 8211 | sUnforwardedOps.remove(0); |
| 8212 | } |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 8213 | } |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8214 | } |
| 8215 | } |
Stanislav Zholnin | 90516b9 | 2020-01-20 14:03:06 +0000 | [diff] [blame] | 8216 | for (int code = notedAppOps.nextSetBit(0); code != -1; |
| 8217 | code = notedAppOps.nextSetBit(code + 1)) { |
Philip P. Moltmann | 12ac3f4 | 2020-03-05 15:01:29 -0800 | [diff] [blame] | 8218 | sMessageCollector.onNoted(new SyncNotedAppOp(code, attributionTag)); |
Stanislav Zholnin | 90516b9 | 2020-01-20 14:03:06 +0000 | [diff] [blame] | 8219 | } |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8220 | } |
| 8221 | } |
| 8222 | } |
| 8223 | |
| 8224 | /** |
Philip P. Moltmann | 5892a8f | 2020-03-03 12:05:55 -0800 | [diff] [blame] | 8225 | * Set a new {@link OnOpNotedCallback}. |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8226 | * |
Philip P. Moltmann | 5892a8f | 2020-03-03 12:05:55 -0800 | [diff] [blame] | 8227 | * <p>There can only ever be one collector per process. If there currently is another callback |
| 8228 | * set, this will fail. |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8229 | * |
Philip P. Moltmann | 5892a8f | 2020-03-03 12:05:55 -0800 | [diff] [blame] | 8230 | * @param asyncExecutor executor to execute {@link OnOpNotedCallback#onAsyncNoted} on, {@code |
| 8231 | * null} to unset |
| 8232 | * @param callback listener to set, {@code null} to unset |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8233 | * |
Philip P. Moltmann | 5892a8f | 2020-03-03 12:05:55 -0800 | [diff] [blame] | 8234 | * @throws IllegalStateException If another callback is already registered |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8235 | */ |
Philip P. Moltmann | 5892a8f | 2020-03-03 12:05:55 -0800 | [diff] [blame] | 8236 | public void setOnOpNotedCallback(@Nullable @CallbackExecutor Executor asyncExecutor, |
| 8237 | @Nullable OnOpNotedCallback callback) { |
| 8238 | Preconditions.checkState((callback == null) == (asyncExecutor == null)); |
| 8239 | |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8240 | synchronized (sLock) { |
Philip P. Moltmann | 5892a8f | 2020-03-03 12:05:55 -0800 | [diff] [blame] | 8241 | if (callback == null) { |
| 8242 | Preconditions.checkState(sOnOpNotedCallback != null, |
| 8243 | "No callback is currently registered"); |
| 8244 | |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8245 | try { |
| 8246 | mService.stopWatchingAsyncNoted(mContext.getPackageName(), |
Philip P. Moltmann | 5892a8f | 2020-03-03 12:05:55 -0800 | [diff] [blame] | 8247 | sOnOpNotedCallback.mAsyncCb); |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8248 | } catch (RemoteException e) { |
| 8249 | e.rethrowFromSystemServer(); |
| 8250 | } |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8251 | |
Philip P. Moltmann | 5892a8f | 2020-03-03 12:05:55 -0800 | [diff] [blame] | 8252 | sOnOpNotedCallback = null; |
| 8253 | } else { |
| 8254 | Preconditions.checkState(sOnOpNotedCallback == null, |
| 8255 | "Another callback is already registered"); |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8256 | |
Philip P. Moltmann | 5892a8f | 2020-03-03 12:05:55 -0800 | [diff] [blame] | 8257 | callback.mAsyncExecutor = asyncExecutor; |
| 8258 | sOnOpNotedCallback = callback; |
| 8259 | |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8260 | List<AsyncNotedAppOp> missedAsyncOps = null; |
| 8261 | try { |
| 8262 | mService.startWatchingAsyncNoted(mContext.getPackageName(), |
Philip P. Moltmann | 5892a8f | 2020-03-03 12:05:55 -0800 | [diff] [blame] | 8263 | sOnOpNotedCallback.mAsyncCb); |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8264 | missedAsyncOps = mService.extractAsyncOps(mContext.getPackageName()); |
| 8265 | } catch (RemoteException e) { |
| 8266 | e.rethrowFromSystemServer(); |
| 8267 | } |
| 8268 | |
| 8269 | if (missedAsyncOps != null) { |
| 8270 | int numMissedAsyncOps = missedAsyncOps.size(); |
| 8271 | for (int i = 0; i < numMissedAsyncOps; i++) { |
| 8272 | final AsyncNotedAppOp asyncNotedAppOp = missedAsyncOps.get(i); |
Philip P. Moltmann | 5892a8f | 2020-03-03 12:05:55 -0800 | [diff] [blame] | 8273 | if (sOnOpNotedCallback != null) { |
| 8274 | sOnOpNotedCallback.getAsyncNotedExecutor().execute( |
| 8275 | () -> sOnOpNotedCallback.onAsyncNoted(asyncNotedAppOp)); |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8276 | } |
| 8277 | } |
| 8278 | } |
Stanislav Zholnin | e44f134 | 2020-06-02 20:26:20 +0100 | [diff] [blame] | 8279 | synchronized (this) { |
| 8280 | int numMissedSyncOps = sUnforwardedOps.size(); |
| 8281 | for (int i = 0; i < numMissedSyncOps; i++) { |
Stanislav Zholnin | 456b496 | 2020-06-18 16:52:50 +0100 | [diff] [blame] | 8282 | final AsyncNotedAppOp syncNotedAppOp = sUnforwardedOps.get(i); |
Stanislav Zholnin | e44f134 | 2020-06-02 20:26:20 +0100 | [diff] [blame] | 8283 | if (sOnOpNotedCallback != null) { |
| 8284 | sOnOpNotedCallback.getAsyncNotedExecutor().execute( |
Stanislav Zholnin | 456b496 | 2020-06-18 16:52:50 +0100 | [diff] [blame] | 8285 | () -> sOnOpNotedCallback.onAsyncNoted(syncNotedAppOp)); |
Stanislav Zholnin | e44f134 | 2020-06-02 20:26:20 +0100 | [diff] [blame] | 8286 | } |
| 8287 | } |
| 8288 | sUnforwardedOps.clear(); |
| 8289 | } |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8290 | } |
| 8291 | } |
| 8292 | } |
| 8293 | |
Philip P. Moltmann | 5892a8f | 2020-03-03 12:05:55 -0800 | [diff] [blame] | 8294 | // TODO moltmann: Remove |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8295 | /** |
Philip P. Moltmann | 5892a8f | 2020-03-03 12:05:55 -0800 | [diff] [blame] | 8296 | * 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] | 8297 | * |
Philip P. Moltmann | 5892a8f | 2020-03-03 12:05:55 -0800 | [diff] [blame] | 8298 | * @removed |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8299 | * |
| 8300 | * @hide |
| 8301 | */ |
Philip P. Moltmann | 5892a8f | 2020-03-03 12:05:55 -0800 | [diff] [blame] | 8302 | @SystemApi |
| 8303 | @Deprecated |
| 8304 | public void setNotedAppOpsCollector(@Nullable AppOpsCollector collector) { |
| 8305 | synchronized (sLock) { |
| 8306 | if (collector != null) { |
| 8307 | if (isListeningForOpNoted()) { |
| 8308 | setOnOpNotedCallback(null, null); |
| 8309 | } |
| 8310 | setOnOpNotedCallback(new HandlerExecutor(Handler.getMain()), collector); |
| 8311 | } else if (sOnOpNotedCallback != null) { |
| 8312 | setOnOpNotedCallback(null, null); |
| 8313 | } |
| 8314 | } |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8315 | } |
| 8316 | |
| 8317 | /** |
Philip P. Moltmann | 5892a8f | 2020-03-03 12:05:55 -0800 | [diff] [blame] | 8318 | * @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] | 8319 | * |
Philip P. Moltmann | 5892a8f | 2020-03-03 12:05:55 -0800 | [diff] [blame] | 8320 | * @see #setOnOpNotedCallback |
| 8321 | * |
| 8322 | * @hide |
| 8323 | */ |
| 8324 | public static boolean isListeningForOpNoted() { |
Stanislav Zholnin | d4968a0 | 2020-04-18 21:01:13 +0100 | [diff] [blame] | 8325 | return sOnOpNotedCallback != null || isCollectingStackTraces(); |
| 8326 | } |
| 8327 | |
| 8328 | /** |
| 8329 | * @return {@code true} iff the process is currently sampled for stacktrace collection. |
| 8330 | * |
| 8331 | * @see #setOnOpNotedCallback |
| 8332 | * |
| 8333 | * @hide |
| 8334 | */ |
| 8335 | private static boolean isCollectingStackTraces() { |
| 8336 | if (sConfig.getSampledOpCode() == OP_NONE && |
| 8337 | sConfig.getExpirationTimeSinceBootMillis() >= SystemClock.elapsedRealtime()) { |
| 8338 | return false; |
| 8339 | } |
| 8340 | return true; |
Philip P. Moltmann | 5892a8f | 2020-03-03 12:05:55 -0800 | [diff] [blame] | 8341 | } |
| 8342 | |
| 8343 | /** |
| 8344 | * Callback an app can {@link #setOnOpNotedCallback set} to monitor the app-ops the |
| 8345 | * system has tracked for it. I.e. each time any app calls {@link #noteOp} or {@link #startOp} |
| 8346 | * one of a method of this object is called. |
| 8347 | * |
| 8348 | * <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] | 8349 | * necessarily for all other app-ops. |
Philip P. Moltmann | 9e36700 | 2020-02-03 17:01:05 -0800 | [diff] [blame] | 8350 | * |
| 8351 | * <pre> |
Philip P. Moltmann | 5892a8f | 2020-03-03 12:05:55 -0800 | [diff] [blame] | 8352 | * setOnOpNotedCallback(getMainExecutor(), new OnOpNotedCallback() { |
Philip P. Moltmann | 9e36700 | 2020-02-03 17:01:05 -0800 | [diff] [blame] | 8353 | * ArraySet<Pair<String, String>> opsNotedForThisProcess = new ArraySet<>(); |
| 8354 | * |
| 8355 | * private synchronized void addAccess(String op, String accessLocation) { |
Philip P. Moltmann | a04b9ab | 2020-02-13 09:54:04 -0800 | [diff] [blame] | 8356 | * // Ops are often noted when runtime permission protected APIs were called. |
Philip P. Moltmann | 9e36700 | 2020-02-03 17:01:05 -0800 | [diff] [blame] | 8357 | * // In this case permissionToOp() allows to resolve the permission<->op |
| 8358 | * opsNotedForThisProcess.add(new Pair(accessType, accessLocation)); |
| 8359 | * } |
| 8360 | * |
| 8361 | * public void onNoted(SyncNotedAppOp op) { |
| 8362 | * // Accesses is currently happening, hence stack trace describes location of access |
| 8363 | * addAccess(op.getOp(), Arrays.toString(Thread.currentThread().getStackTrace())); |
| 8364 | * } |
| 8365 | * |
| 8366 | * public void onSelfNoted(SyncNotedAppOp op) { |
| 8367 | * onNoted(op); |
| 8368 | * } |
| 8369 | * |
| 8370 | * public void onAsyncNoted(AsyncNotedAppOp asyncOp) { |
| 8371 | * // Stack trace is not useful for async ops as accessed happened on different thread |
| 8372 | * addAccess(asyncOp.getOp(), asyncOp.getMessage()); |
| 8373 | * } |
| 8374 | * }); |
| 8375 | * </pre> |
| 8376 | * |
Philip P. Moltmann | 5892a8f | 2020-03-03 12:05:55 -0800 | [diff] [blame] | 8377 | * @see #setOnOpNotedCallback |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8378 | */ |
Philip P. Moltmann | 5892a8f | 2020-03-03 12:05:55 -0800 | [diff] [blame] | 8379 | public abstract static class OnOpNotedCallback { |
| 8380 | private @NonNull Executor mAsyncExecutor; |
| 8381 | |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8382 | /** Callback registered with the system. This will receive the async notes ops */ |
| 8383 | private final IAppOpsAsyncNotedCallback mAsyncCb = new IAppOpsAsyncNotedCallback.Stub() { |
| 8384 | @Override |
| 8385 | public void opNoted(AsyncNotedAppOp op) { |
Daulet Zhanguzin | 0af97d6 | 2019-12-30 15:41:28 +0000 | [diff] [blame] | 8386 | Objects.requireNonNull(op); |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8387 | |
Philip P. Moltmann | 5892a8f | 2020-03-03 12:05:55 -0800 | [diff] [blame] | 8388 | long token = Binder.clearCallingIdentity(); |
| 8389 | try { |
| 8390 | getAsyncNotedExecutor().execute(() -> onAsyncNoted(op)); |
| 8391 | } finally { |
| 8392 | Binder.restoreCallingIdentity(token); |
| 8393 | } |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8394 | } |
| 8395 | }; |
| 8396 | |
Philip P. Moltmann | 5892a8f | 2020-03-03 12:05:55 -0800 | [diff] [blame] | 8397 | // TODO moltmann: Remove |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8398 | /** |
Philip P. Moltmann | 5892a8f | 2020-03-03 12:05:55 -0800 | [diff] [blame] | 8399 | * Will be removed before R ships. |
| 8400 | * |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8401 | * @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] | 8402 | * |
| 8403 | * @hide |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8404 | */ |
Philip P. Moltmann | 5892a8f | 2020-03-03 12:05:55 -0800 | [diff] [blame] | 8405 | protected @NonNull Executor getAsyncNotedExecutor() { |
| 8406 | return mAsyncExecutor; |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8407 | } |
| 8408 | |
| 8409 | /** |
Philip P. Moltmann | a04b9ab | 2020-02-13 09:54:04 -0800 | [diff] [blame] | 8410 | * Called when an app-op was {@link #noteOp noted} for this package inside of a synchronous |
| 8411 | * 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] | 8412 | * |
Philip P. Moltmann | a04b9ab | 2020-02-13 09:54:04 -0800 | [diff] [blame] | 8413 | * <p>Called on the calling thread before the API returns. This allows the app to e.g. |
| 8414 | * collect stack traces to figure out where the access came from. |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8415 | * |
Philip P. Moltmann | 5892a8f | 2020-03-03 12:05:55 -0800 | [diff] [blame] | 8416 | * @param op op noted |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8417 | */ |
| 8418 | public abstract void onNoted(@NonNull SyncNotedAppOp op); |
| 8419 | |
| 8420 | /** |
Philip P. Moltmann | a04b9ab | 2020-02-13 09:54:04 -0800 | [diff] [blame] | 8421 | * 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] | 8422 | * |
Philip P. Moltmann | a04b9ab | 2020-02-13 09:54:04 -0800 | [diff] [blame] | 8423 | * <p>This is very similar to {@link #onNoted} only that the tracking was not caused by the |
| 8424 | * 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] | 8425 | * |
Philip P. Moltmann | 5892a8f | 2020-03-03 12:05:55 -0800 | [diff] [blame] | 8426 | * @param op op noted |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8427 | */ |
| 8428 | public abstract void onSelfNoted(@NonNull SyncNotedAppOp op); |
| 8429 | |
| 8430 | /** |
| 8431 | * Called when an app-op was noted for this package which cannot be delivered via the other |
| 8432 | * two mechanisms. |
| 8433 | * |
| 8434 | * <p>Called as soon as possible after the app-op was noted, but the delivery delay is not |
| 8435 | * guaranteed. Due to how async calls work in Android this might even be delivered slightly |
| 8436 | * before the private data is delivered to the app. |
| 8437 | * |
Philip P. Moltmann | 5892a8f | 2020-03-03 12:05:55 -0800 | [diff] [blame] | 8438 | * <p>If the app is not running or no {@link OnOpNotedCallback} is registered a small amount |
| 8439 | * 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] | 8440 | * |
Philip P. Moltmann | 5892a8f | 2020-03-03 12:05:55 -0800 | [diff] [blame] | 8441 | * @param asyncOp op noted |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8442 | */ |
| 8443 | public abstract void onAsyncNoted(@NonNull AsyncNotedAppOp asyncOp); |
| 8444 | } |
| 8445 | |
Philip P. Moltmann | 5892a8f | 2020-03-03 12:05:55 -0800 | [diff] [blame] | 8446 | // TODO moltmann: Remove |
| 8447 | /** |
| 8448 | * Will be removed before R ships, leave it just to not break apps immediately. |
| 8449 | * |
| 8450 | * @removed |
| 8451 | * |
| 8452 | * @hide |
| 8453 | */ |
| 8454 | @SystemApi |
| 8455 | @Deprecated |
| 8456 | public abstract static class AppOpsCollector extends OnOpNotedCallback { |
| 8457 | public @NonNull Executor getAsyncNotedExecutor() { |
| 8458 | return new HandlerExecutor(Handler.getMain()); |
| 8459 | } |
| 8460 | }; |
| 8461 | |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8462 | /** |
| 8463 | * Generate a stack trace used for noted app-ops logging. |
| 8464 | * |
| 8465 | * <p>This strips away the first few and last few stack trace elements as they are not |
| 8466 | * interesting to apps. |
| 8467 | */ |
| 8468 | private static String getFormattedStackTrace() { |
| 8469 | StackTraceElement[] trace = new Exception().getStackTrace(); |
| 8470 | |
| 8471 | int firstInteresting = 0; |
| 8472 | for (int i = 0; i < trace.length; i++) { |
| 8473 | if (trace[i].getClassName().startsWith(AppOpsManager.class.getName()) |
| 8474 | || trace[i].getClassName().startsWith(Parcel.class.getName()) |
| 8475 | || trace[i].getClassName().contains("$Stub$Proxy") |
| 8476 | || trace[i].getClassName().startsWith(DatabaseUtils.class.getName()) |
| 8477 | || trace[i].getClassName().startsWith("android.content.ContentProviderProxy") |
| 8478 | || trace[i].getClassName().startsWith(ContentResolver.class.getName())) { |
| 8479 | firstInteresting = i; |
| 8480 | } else { |
| 8481 | break; |
| 8482 | } |
| 8483 | } |
| 8484 | |
| 8485 | int lastInteresting = trace.length - 1; |
| 8486 | for (int i = trace.length - 1; i >= 0; i--) { |
| 8487 | if (trace[i].getClassName().startsWith(HandlerThread.class.getName()) |
| 8488 | || trace[i].getClassName().startsWith(Handler.class.getName()) |
| 8489 | || trace[i].getClassName().startsWith(Looper.class.getName()) |
| 8490 | || trace[i].getClassName().startsWith(Binder.class.getName()) |
| 8491 | || trace[i].getClassName().startsWith(RuntimeInit.class.getName()) |
| 8492 | || trace[i].getClassName().startsWith(ZygoteInit.class.getName()) |
| 8493 | || trace[i].getClassName().startsWith(ActivityThread.class.getName()) |
| 8494 | || trace[i].getClassName().startsWith(Method.class.getName()) |
| 8495 | || trace[i].getClassName().startsWith("com.android.server.SystemServer")) { |
| 8496 | lastInteresting = i; |
| 8497 | } else { |
| 8498 | break; |
| 8499 | } |
| 8500 | } |
| 8501 | |
| 8502 | StringBuilder sb = new StringBuilder(); |
| 8503 | for (int i = firstInteresting; i <= lastInteresting; i++) { |
Stanislav Zholnin | 90516b9 | 2020-01-20 14:03:06 +0000 | [diff] [blame] | 8504 | if (i != firstInteresting) { |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8505 | sb.append('\n'); |
| 8506 | } |
Stanislav Zholnin | 90516b9 | 2020-01-20 14:03:06 +0000 | [diff] [blame] | 8507 | if (sb.length() + trace[i].toString().length() > 600) { |
| 8508 | break; |
| 8509 | } |
| 8510 | sb.append(trace[i]); |
Philip P. Moltmann | 2b08aaf | 2019-06-10 08:49:11 -0700 | [diff] [blame] | 8511 | } |
| 8512 | |
| 8513 | return sb.toString(); |
| 8514 | } |
| 8515 | |
| 8516 | /** |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 8517 | * Checks whether the given op for a UID and package is active. |
| 8518 | * |
| 8519 | * <p> If you don't hold the {@link android.Manifest.permission#WATCH_APPOPS} permission |
| 8520 | * you can query only for your UID. |
| 8521 | * |
| 8522 | * @see #startWatchingActive(int[], OnOpActiveChangedListener) |
| 8523 | * @see #stopWatchingMode(OnOpChangedListener) |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 8524 | * @see #finishOp(int, int, String, String) |
| 8525 | * @see #startOp(int, int, String, boolean, String, String) |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 8526 | * |
| 8527 | * @hide */ |
| 8528 | @TestApi |
| 8529 | // TODO: Uncomment below annotation once b/73559440 is fixed |
| 8530 | // @RequiresPermission(value=Manifest.permission.WATCH_APPOPS, conditional=true) |
Jeff Sharkey | 35e46d2 | 2017-06-09 10:01:20 -0600 | [diff] [blame] | 8531 | public boolean isOperationActive(int code, int uid, String packageName) { |
| 8532 | try { |
| 8533 | return mService.isOperationActive(code, uid, packageName); |
| 8534 | } catch (RemoteException e) { |
| 8535 | throw e.rethrowFromSystemServer(); |
| 8536 | } |
| 8537 | } |
Peter Visontay | 5a2a1ef | 2017-12-18 20:34:03 +0000 | [diff] [blame] | 8538 | |
| 8539 | /** |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 8540 | * Configures the app ops persistence for testing. |
| 8541 | * |
| 8542 | * @param mode The mode in which the historical registry operates. |
| 8543 | * @param baseSnapshotInterval The base interval on which we would be persisting a snapshot of |
| 8544 | * the historical data. The history is recursive where every subsequent step encompasses |
| 8545 | * {@code compressionStep} longer interval with {@code compressionStep} distance between |
| 8546 | * snapshots. |
| 8547 | * @param compressionStep The compression step in every iteration. |
| 8548 | * |
| 8549 | * @see #HISTORICAL_MODE_DISABLED |
| 8550 | * @see #HISTORICAL_MODE_ENABLED_ACTIVE |
| 8551 | * @see #HISTORICAL_MODE_ENABLED_PASSIVE |
| 8552 | * |
| 8553 | * @hide |
| 8554 | */ |
| 8555 | @TestApi |
| 8556 | @RequiresPermission(Manifest.permission.MANAGE_APPOPS) |
| 8557 | public void setHistoryParameters(@HistoricalMode int mode, long baseSnapshotInterval, |
| 8558 | int compressionStep) { |
| 8559 | try { |
| 8560 | mService.setHistoryParameters(mode, baseSnapshotInterval, compressionStep); |
| 8561 | } catch (RemoteException e) { |
| 8562 | throw e.rethrowFromSystemServer(); |
| 8563 | } |
| 8564 | } |
| 8565 | |
| 8566 | /** |
| 8567 | * Offsets the history by the given duration. |
| 8568 | * |
| 8569 | * @param offsetMillis The offset duration. |
| 8570 | * |
| 8571 | * @hide |
| 8572 | */ |
| 8573 | @TestApi |
| 8574 | @RequiresPermission(Manifest.permission.MANAGE_APPOPS) |
| 8575 | public void offsetHistory(long offsetMillis) { |
| 8576 | try { |
| 8577 | mService.offsetHistory(offsetMillis); |
| 8578 | } catch (RemoteException e) { |
| 8579 | throw e.rethrowFromSystemServer(); |
| 8580 | } |
| 8581 | } |
| 8582 | |
| 8583 | /** |
| 8584 | * Adds ops to the history directly. This could be useful for testing especially |
| 8585 | * when the historical registry operates in {@link #HISTORICAL_MODE_ENABLED_PASSIVE} |
| 8586 | * mode. |
| 8587 | * |
| 8588 | * @param ops The ops to add to the history. |
| 8589 | * |
| 8590 | * @see #setHistoryParameters(int, long, int) |
| 8591 | * @see #HISTORICAL_MODE_ENABLED_PASSIVE |
| 8592 | * |
| 8593 | * @hide |
| 8594 | */ |
| 8595 | @TestApi |
| 8596 | @RequiresPermission(Manifest.permission.MANAGE_APPOPS) |
| 8597 | public void addHistoricalOps(@NonNull HistoricalOps ops) { |
| 8598 | try { |
| 8599 | mService.addHistoricalOps(ops); |
| 8600 | } catch (RemoteException e) { |
| 8601 | throw e.rethrowFromSystemServer(); |
| 8602 | } |
| 8603 | } |
| 8604 | |
| 8605 | /** |
| 8606 | * Resets the app ops persistence for testing. |
| 8607 | * |
| 8608 | * @see #setHistoryParameters(int, long, int) |
| 8609 | * |
| 8610 | * @hide |
| 8611 | */ |
| 8612 | @TestApi |
| 8613 | @RequiresPermission(Manifest.permission.MANAGE_APPOPS) |
| 8614 | public void resetHistoryParameters() { |
| 8615 | try { |
| 8616 | mService.resetHistoryParameters(); |
| 8617 | } catch (RemoteException e) { |
| 8618 | throw e.rethrowFromSystemServer(); |
| 8619 | } |
| 8620 | } |
| 8621 | |
| 8622 | /** |
| 8623 | * Clears all app ops history. |
| 8624 | * |
| 8625 | * @hide |
| 8626 | */ |
| 8627 | @TestApi |
| 8628 | @RequiresPermission(Manifest.permission.MANAGE_APPOPS) |
| 8629 | public void clearHistory() { |
| 8630 | try { |
| 8631 | mService.clearHistory(); |
| 8632 | } catch (RemoteException e) { |
| 8633 | throw e.rethrowFromSystemServer(); |
| 8634 | } |
| 8635 | } |
| 8636 | |
| 8637 | /** |
Svet Ganov | 185ddf6 | 2020-06-04 21:40:26 -0700 | [diff] [blame] | 8638 | * Reboots the ops history. |
| 8639 | * |
| 8640 | * @param offlineDurationMillis The duration to wait between |
| 8641 | * tearing down and initializing the history. Must be greater |
| 8642 | * than or equal to zero. |
| 8643 | * |
| 8644 | * @hide |
| 8645 | */ |
| 8646 | @TestApi |
| 8647 | @RequiresPermission(Manifest.permission.MANAGE_APPOPS) |
| 8648 | public void rebootHistory(long offlineDurationMillis) { |
| 8649 | try { |
| 8650 | mService.rebootHistory(offlineDurationMillis); |
| 8651 | } catch (RemoteException e) { |
| 8652 | throw e.rethrowFromSystemServer(); |
| 8653 | } |
| 8654 | } |
| 8655 | |
| 8656 | /** |
Stanislav Zholnin | 90516b9 | 2020-01-20 14:03:06 +0000 | [diff] [blame] | 8657 | * 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] | 8658 | * Returns null if no reports were collected since last call. There is no guarantee of report |
| 8659 | * collection, hence this method should be called periodically even if no report was collected |
| 8660 | * to pick different package and op to watch. |
Stanislav Zholnin | 90516b9 | 2020-01-20 14:03:06 +0000 | [diff] [blame] | 8661 | * @hide |
| 8662 | */ |
| 8663 | @SystemApi |
| 8664 | @TestApi |
| 8665 | @RequiresPermission(Manifest.permission.GET_APP_OPS_STATS) |
| 8666 | public @Nullable RuntimeAppOpAccessMessage collectRuntimeAppOpAccessMessage() { |
| 8667 | try { |
| 8668 | return mService.collectRuntimeAppOpAccessMessage(); |
| 8669 | } catch (RemoteException e) { |
| 8670 | throw e.rethrowFromSystemServer(); |
| 8671 | } |
| 8672 | } |
| 8673 | |
| 8674 | /** |
Peter Visontay | 5a2a1ef | 2017-12-18 20:34:03 +0000 | [diff] [blame] | 8675 | * Returns all supported operation names. |
| 8676 | * @hide |
| 8677 | */ |
| 8678 | @SystemApi |
| 8679 | @TestApi |
| 8680 | public static String[] getOpStrs() { |
| 8681 | return Arrays.copyOf(sOpToString, sOpToString.length); |
| 8682 | } |
Dianne Hackborn | c216a26 | 2018-04-26 13:46:22 -0700 | [diff] [blame] | 8683 | |
Philip P. Moltmann | 2457681 | 2018-05-07 10:42:05 -0700 | [diff] [blame] | 8684 | |
| 8685 | /** |
| 8686 | * @return number of App ops |
| 8687 | * @hide |
| 8688 | */ |
| 8689 | @TestApi |
| 8690 | public static int getNumOps() { |
| 8691 | return _NUM_OP; |
| 8692 | } |
| 8693 | |
Dianne Hackborn | c216a26 | 2018-04-26 13:46:22 -0700 | [diff] [blame] | 8694 | /** |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 8695 | * Gets the last of the event. |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 8696 | * |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 8697 | * @param events The events |
| 8698 | * @param flags The UID flags |
| 8699 | * @param beginUidState The maximum UID state (inclusive) |
| 8700 | * @param endUidState The minimum UID state (inclusive) |
| 8701 | * |
| 8702 | * @return The last event of {@code null} |
Dianne Hackborn | c216a26 | 2018-04-26 13:46:22 -0700 | [diff] [blame] | 8703 | */ |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 8704 | private static @Nullable NoteOpEvent getLastEvent( |
| 8705 | @Nullable LongSparseArray<NoteOpEvent> events, @UidState int beginUidState, |
| 8706 | @UidState int endUidState, @OpFlags int flags) { |
| 8707 | if (events == null) { |
| 8708 | return null; |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 8709 | } |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 8710 | |
| 8711 | NoteOpEvent lastEvent = null; |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 8712 | while (flags != 0) { |
| 8713 | final int flag = 1 << Integer.numberOfTrailingZeros(flags); |
| 8714 | flags &= ~flag; |
| 8715 | for (int uidState : UID_STATES) { |
| 8716 | if (uidState < beginUidState || uidState > endUidState) { |
| 8717 | continue; |
| 8718 | } |
| 8719 | final long key = makeKey(uidState, flag); |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 8720 | |
| 8721 | NoteOpEvent event = events.get(key); |
Philip P. Moltmann | d8c0bda | 2019-12-19 19:55:35 -0800 | [diff] [blame] | 8722 | if (lastEvent == null |
| 8723 | || event != null && event.getNoteTime() > lastEvent.getNoteTime()) { |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 8724 | lastEvent = event; |
| 8725 | } |
Dianne Hackborn | c216a26 | 2018-04-26 13:46:22 -0700 | [diff] [blame] | 8726 | } |
| 8727 | } |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 8728 | |
Philip P. Moltmann | 49bd9e1 | 2019-11-26 15:18:16 -0800 | [diff] [blame] | 8729 | return lastEvent; |
| 8730 | } |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 8731 | |
Philip P. Moltmann | 4aacd71 | 2020-01-03 12:32:20 -0800 | [diff] [blame] | 8732 | private static boolean equalsLongSparseLongArray(@Nullable LongSparseLongArray a, |
| 8733 | @Nullable LongSparseLongArray b) { |
| 8734 | if (a == b) { |
| 8735 | return true; |
| 8736 | } |
| 8737 | |
| 8738 | if (a == null || b == null) { |
| 8739 | return false; |
| 8740 | } |
| 8741 | |
| 8742 | if (a.size() != b.size()) { |
| 8743 | return false; |
| 8744 | } |
| 8745 | |
| 8746 | int numEntries = a.size(); |
| 8747 | for (int i = 0; i < numEntries; i++) { |
| 8748 | if (a.keyAt(i) != b.keyAt(i) || a.valueAt(i) != b.valueAt(i)) { |
| 8749 | return false; |
| 8750 | } |
| 8751 | } |
| 8752 | |
| 8753 | return true; |
| 8754 | } |
| 8755 | |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 8756 | private static void writeLongSparseLongArrayToParcel( |
| 8757 | @Nullable LongSparseLongArray array, @NonNull Parcel parcel) { |
| 8758 | if (array != null) { |
| 8759 | final int size = array.size(); |
| 8760 | parcel.writeInt(size); |
| 8761 | for (int i = 0; i < size; i++) { |
| 8762 | parcel.writeLong(array.keyAt(i)); |
| 8763 | parcel.writeLong(array.valueAt(i)); |
| 8764 | } |
| 8765 | } else { |
| 8766 | parcel.writeInt(-1); |
| 8767 | } |
| 8768 | } |
| 8769 | |
| 8770 | private static @Nullable LongSparseLongArray readLongSparseLongArrayFromParcel( |
| 8771 | @NonNull Parcel parcel) { |
| 8772 | final int size = parcel.readInt(); |
| 8773 | if (size < 0) { |
| 8774 | return null; |
| 8775 | } |
| 8776 | final LongSparseLongArray array = new LongSparseLongArray(size); |
| 8777 | for (int i = 0; i < size; i++) { |
| 8778 | array.append(parcel.readLong(), parcel.readLong()); |
| 8779 | } |
| 8780 | return array; |
| 8781 | } |
| 8782 | |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 8783 | /** |
| 8784 | * Collects the keys from an array to the result creating the result if needed. |
| 8785 | * |
| 8786 | * @param array The array whose keys to collect. |
| 8787 | * @param result The optional result store collected keys. |
| 8788 | * @return The result collected keys array. |
| 8789 | */ |
| 8790 | private static LongSparseArray<Object> collectKeys(@Nullable LongSparseLongArray array, |
| 8791 | @Nullable LongSparseArray<Object> result) { |
| 8792 | if (array != null) { |
| 8793 | if (result == null) { |
| 8794 | result = new LongSparseArray<>(); |
| 8795 | } |
| 8796 | final int accessSize = array.size(); |
| 8797 | for (int i = 0; i < accessSize; i++) { |
| 8798 | result.put(array.keyAt(i), null); |
| 8799 | } |
| 8800 | } |
| 8801 | return result; |
Dianne Hackborn | c216a26 | 2018-04-26 13:46:22 -0700 | [diff] [blame] | 8802 | } |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 8803 | |
| 8804 | /** @hide */ |
| 8805 | public static String uidStateToString(@UidState int uidState) { |
| 8806 | switch (uidState) { |
| 8807 | case UID_STATE_PERSISTENT: { |
| 8808 | return "UID_STATE_PERSISTENT"; |
| 8809 | } |
| 8810 | case UID_STATE_TOP: { |
| 8811 | return "UID_STATE_TOP"; |
| 8812 | } |
Amith Yamasani | a0a30a1 | 2019-01-22 11:38:06 -0800 | [diff] [blame] | 8813 | case UID_STATE_FOREGROUND_SERVICE_LOCATION: { |
| 8814 | return "UID_STATE_FOREGROUND_SERVICE_LOCATION"; |
| 8815 | } |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 8816 | case UID_STATE_FOREGROUND_SERVICE: { |
| 8817 | return "UID_STATE_FOREGROUND_SERVICE"; |
| 8818 | } |
| 8819 | case UID_STATE_FOREGROUND: { |
| 8820 | return "UID_STATE_FOREGROUND"; |
| 8821 | } |
| 8822 | case UID_STATE_BACKGROUND: { |
| 8823 | return "UID_STATE_BACKGROUND"; |
| 8824 | } |
| 8825 | case UID_STATE_CACHED: { |
| 8826 | return "UID_STATE_CACHED"; |
| 8827 | } |
| 8828 | default: { |
| 8829 | return "UNKNOWN"; |
| 8830 | } |
| 8831 | } |
| 8832 | } |
| 8833 | |
| 8834 | /** @hide */ |
| 8835 | public static int parseHistoricalMode(@NonNull String mode) { |
| 8836 | switch (mode) { |
| 8837 | case "HISTORICAL_MODE_ENABLED_ACTIVE": { |
| 8838 | return HISTORICAL_MODE_ENABLED_ACTIVE; |
| 8839 | } |
| 8840 | case "HISTORICAL_MODE_ENABLED_PASSIVE": { |
| 8841 | return HISTORICAL_MODE_ENABLED_PASSIVE; |
| 8842 | } |
| 8843 | default: { |
| 8844 | return HISTORICAL_MODE_DISABLED; |
| 8845 | } |
| 8846 | } |
| 8847 | } |
| 8848 | |
| 8849 | /** @hide */ |
| 8850 | public static String historicalModeToString(@HistoricalMode int mode) { |
| 8851 | switch (mode) { |
| 8852 | case HISTORICAL_MODE_DISABLED: { |
| 8853 | return "HISTORICAL_MODE_DISABLED"; |
| 8854 | } |
| 8855 | case HISTORICAL_MODE_ENABLED_ACTIVE: { |
| 8856 | return "HISTORICAL_MODE_ENABLED_ACTIVE"; |
| 8857 | } |
| 8858 | case HISTORICAL_MODE_ENABLED_PASSIVE: { |
| 8859 | return "HISTORICAL_MODE_ENABLED_PASSIVE"; |
| 8860 | } |
| 8861 | default: { |
| 8862 | return "UNKNOWN"; |
| 8863 | } |
| 8864 | } |
| 8865 | } |
Ng Zhi An | 65a99b6 | 2018-10-01 11:57:53 -0700 | [diff] [blame] | 8866 | |
| 8867 | private static int getSystemAlertWindowDefault() { |
| 8868 | final Context context = ActivityThread.currentApplication(); |
| 8869 | if (context == null) { |
| 8870 | return AppOpsManager.MODE_DEFAULT; |
| 8871 | } |
| 8872 | |
| 8873 | // system alert window is disable on low ram phones starting from Q |
| 8874 | final PackageManager pm = context.getPackageManager(); |
| 8875 | // TVs are constantly plugged in and has less concern for memory/power |
| 8876 | if (ActivityManager.isLowRamDeviceStatic() |
| 8877 | && !pm.hasSystemFeature(PackageManager.FEATURE_LEANBACK, 0)) { |
| 8878 | return AppOpsManager.MODE_IGNORED; |
| 8879 | } |
| 8880 | |
| 8881 | return AppOpsManager.MODE_DEFAULT; |
| 8882 | } |
Stanislav Zholnin | 90516b9 | 2020-01-20 14:03:06 +0000 | [diff] [blame] | 8883 | |
| 8884 | /** |
| 8885 | * Calculate left circular distance for two numbers modulo size. |
| 8886 | * @hide |
| 8887 | */ |
| 8888 | public static int leftCircularDistance(int from, int to, int size) { |
| 8889 | return (to + size - from) % size; |
| 8890 | } |
David Cheung | 2ead966 | 2020-02-19 16:11:06 -0800 | [diff] [blame] | 8891 | |
| 8892 | /** |
| 8893 | * Helper method for noteOp, startOp and noteProxyOp to call AppOpsService to collect/log |
| 8894 | * stack traces |
| 8895 | * |
| 8896 | * <p> For each call, the stacktrace op code, package name and long version code will be |
| 8897 | * passed along where it will be logged/collected |
| 8898 | * |
| 8899 | * @param op The operation to note |
| 8900 | */ |
| 8901 | private void collectNoteOpCallsForValidation(int op) { |
| 8902 | if (NOTE_OP_COLLECTION_ENABLED) { |
| 8903 | try { |
| 8904 | mService.collectNoteOpCallsForValidation(getFormattedStackTrace(), |
| 8905 | op, mContext.getOpPackageName(), mContext.getApplicationInfo().longVersionCode); |
| 8906 | } catch (RemoteException e) { |
| 8907 | // Swallow error, only meant for logging ops, should not affect flow of the code |
| 8908 | } |
| 8909 | } |
| 8910 | } |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 8911 | } |