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; |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 20 | import android.annotation.IntDef; |
Svet Ganov | 00a46ef | 2019-03-29 21:13:03 -0700 | [diff] [blame] | 21 | import android.annotation.IntRange; |
Svetoslav Ganov | 2d20fb4 | 2018-02-08 15:52:10 -0800 | [diff] [blame] | 22 | import android.annotation.NonNull; |
Hai Zhang | b777668 | 2018-09-25 15:10:57 -0700 | [diff] [blame] | 23 | import android.annotation.Nullable; |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 24 | import android.annotation.RequiresPermission; |
Jeff Davidson | 0554260 | 2014-08-11 14:07:27 -0700 | [diff] [blame] | 25 | import android.annotation.SystemApi; |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 26 | import android.annotation.SystemService; |
Peter Visontay | 5a2a1ef | 2017-12-18 20:34:03 +0000 | [diff] [blame] | 27 | import android.annotation.TestApi; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 28 | import android.annotation.UnsupportedAppUsage; |
Jeff Davidson | 0554260 | 2014-08-11 14:07:27 -0700 | [diff] [blame] | 29 | import android.app.usage.UsageStatsManager; |
| 30 | import android.content.Context; |
Ng Zhi An | 65a99b6 | 2018-10-01 11:57:53 -0700 | [diff] [blame] | 31 | import android.content.pm.PackageManager; |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 32 | import android.content.pm.ParceledListSlice; |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame] | 33 | import android.media.AudioAttributes.AttributeUsage; |
Dianne Hackborn | e98f5db | 2013-07-17 17:23:25 -0700 | [diff] [blame] | 34 | import android.os.Binder; |
| 35 | import android.os.IBinder; |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 36 | import android.os.Parcel; |
| 37 | import android.os.Parcelable; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 38 | import android.os.Process; |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 39 | import android.os.RemoteCallback; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 40 | import android.os.RemoteException; |
Jeff Davidson | 0554260 | 2014-08-11 14:07:27 -0700 | [diff] [blame] | 41 | import android.os.UserManager; |
| 42 | import android.util.ArrayMap; |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 43 | import android.util.LongSparseArray; |
| 44 | import android.util.LongSparseLongArray; |
Ng Zhi An | 65a99b6 | 2018-10-01 11:57:53 -0700 | [diff] [blame] | 45 | import android.util.SparseArray; |
Jeff Davidson | 0554260 | 2014-08-11 14:07:27 -0700 | [diff] [blame] | 46 | |
Svet Ganov | b3d2ae2 | 2018-12-17 22:06:15 -0800 | [diff] [blame] | 47 | import com.android.internal.annotations.GuardedBy; |
Svet Ganov | 23c88db | 2019-01-22 20:38:11 -0800 | [diff] [blame] | 48 | import com.android.internal.annotations.Immutable; |
Svetoslav Ganov | 2d20fb4 | 2018-02-08 15:52:10 -0800 | [diff] [blame] | 49 | import com.android.internal.app.IAppOpsActiveCallback; |
Jeff Davidson | 0554260 | 2014-08-11 14:07:27 -0700 | [diff] [blame] | 50 | import com.android.internal.app.IAppOpsCallback; |
Svet Ganov | b3d2ae2 | 2018-12-17 22:06:15 -0800 | [diff] [blame] | 51 | import com.android.internal.app.IAppOpsNotedCallback; |
Jeff Davidson | 0554260 | 2014-08-11 14:07:27 -0700 | [diff] [blame] | 52 | import com.android.internal.app.IAppOpsService; |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 53 | import com.android.internal.util.ArrayUtils; |
Svetoslav Ganov | 2d20fb4 | 2018-02-08 15:52:10 -0800 | [diff] [blame] | 54 | import com.android.internal.util.Preconditions; |
Jeff Davidson | 0554260 | 2014-08-11 14:07:27 -0700 | [diff] [blame] | 55 | |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 56 | import java.lang.annotation.ElementType; |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 57 | import java.lang.annotation.Retention; |
| 58 | import java.lang.annotation.RetentionPolicy; |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 59 | import java.lang.annotation.Target; |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 60 | import java.math.BigDecimal; |
| 61 | import java.math.RoundingMode; |
Jeff Davidson | 0554260 | 2014-08-11 14:07:27 -0700 | [diff] [blame] | 62 | import java.util.ArrayList; |
Peter Visontay | 5a2a1ef | 2017-12-18 20:34:03 +0000 | [diff] [blame] | 63 | import java.util.Arrays; |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 64 | import java.util.Collections; |
Jeff Davidson | 0554260 | 2014-08-11 14:07:27 -0700 | [diff] [blame] | 65 | import java.util.HashMap; |
| 66 | import java.util.List; |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 67 | import java.util.Objects; |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 68 | import java.util.concurrent.Executor; |
| 69 | import java.util.function.Consumer; |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 70 | import java.util.function.Supplier; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 71 | |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 72 | /** |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 73 | * API for interacting with "application operation" tracking. |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 74 | * |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 75 | * <p>This API is not generally intended for third party application developers; most |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 76 | * features are only available to system applications. |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 77 | */ |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 78 | @SystemService(Context.APP_OPS_SERVICE) |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 79 | public class AppOpsManager { |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 80 | /** |
| 81 | * <p>App ops allows callers to:</p> |
| 82 | * |
| 83 | * <ul> |
| 84 | * <li> Note when operations are happening, and find out if they are allowed for the current |
| 85 | * caller.</li> |
| 86 | * <li> Disallow specific apps from doing specific operations.</li> |
| 87 | * <li> Collect all of the current information about operations that have been executed or |
| 88 | * are not being allowed.</li> |
| 89 | * <li> Monitor for changes in whether an operation is allowed.</li> |
| 90 | * </ul> |
| 91 | * |
| 92 | * <p>Each operation is identified by a single integer; these integers are a fixed set of |
| 93 | * operations, enumerated by the OP_* constants. |
| 94 | * |
| 95 | * <p></p>When checking operations, the result is a "mode" integer indicating the current |
| 96 | * setting for the operation under that caller: MODE_ALLOWED, MODE_IGNORED (don't execute |
| 97 | * the operation but fake its behavior enough so that the caller doesn't crash), |
| 98 | * MODE_ERRORED (throw a SecurityException back to the caller; the normal operation calls |
| 99 | * will do this for you). |
| 100 | */ |
| 101 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 102 | final Context mContext; |
Svet Ganov | b3d2ae2 | 2018-12-17 22:06:15 -0800 | [diff] [blame] | 103 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 104 | @UnsupportedAppUsage |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 105 | final IAppOpsService mService; |
Svet Ganov | b3d2ae2 | 2018-12-17 22:06:15 -0800 | [diff] [blame] | 106 | |
| 107 | @GuardedBy("mModeWatchers") |
| 108 | private final ArrayMap<OnOpChangedListener, IAppOpsCallback> mModeWatchers = |
| 109 | new ArrayMap<>(); |
| 110 | |
| 111 | @GuardedBy("mActiveWatchers") |
| 112 | private final ArrayMap<OnOpActiveChangedListener, IAppOpsActiveCallback> mActiveWatchers = |
| 113 | new ArrayMap<>(); |
| 114 | |
| 115 | @GuardedBy("mNotedWatchers") |
| 116 | private final ArrayMap<OnOpNotedListener, IAppOpsNotedCallback> mNotedWatchers = |
Svetoslav Ganov | 2d20fb4 | 2018-02-08 15:52:10 -0800 | [diff] [blame] | 117 | new ArrayMap<>(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 118 | |
Dianne Hackborn | e98f5db | 2013-07-17 17:23:25 -0700 | [diff] [blame] | 119 | static IBinder sToken; |
| 120 | |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 121 | /** @hide */ |
| 122 | @Retention(RetentionPolicy.SOURCE) |
| 123 | @IntDef(flag = true, prefix = { "HISTORICAL_MODE_" }, value = { |
| 124 | HISTORICAL_MODE_DISABLED, |
| 125 | HISTORICAL_MODE_ENABLED_ACTIVE, |
| 126 | HISTORICAL_MODE_ENABLED_PASSIVE |
| 127 | }) |
| 128 | public @interface HistoricalMode {} |
| 129 | |
| 130 | /** |
| 131 | * Mode in which app op history is completely disabled. |
| 132 | * @hide |
| 133 | */ |
| 134 | @TestApi |
| 135 | public static final int HISTORICAL_MODE_DISABLED = 0; |
| 136 | |
| 137 | /** |
| 138 | * Mode in which app op history is enabled and app ops performed by apps would |
| 139 | * be tracked. This is the mode in which the feature is completely enabled. |
| 140 | * @hide |
| 141 | */ |
| 142 | @TestApi |
| 143 | public static final int HISTORICAL_MODE_ENABLED_ACTIVE = 1; |
| 144 | |
| 145 | /** |
| 146 | * Mode in which app op history is enabled but app ops performed by apps would |
| 147 | * not be tracked and the only way to add ops to the history is via explicit calls |
| 148 | * to dedicated APIs. This mode is useful for testing to allow full control of |
| 149 | * the historical content. |
| 150 | * @hide |
| 151 | */ |
| 152 | @TestApi |
| 153 | public static final int HISTORICAL_MODE_ENABLED_PASSIVE = 2; |
| 154 | |
| 155 | /** @hide */ |
| 156 | @Retention(RetentionPolicy.SOURCE) |
| 157 | @IntDef(flag = true, prefix = { "MODE_" }, value = { |
| 158 | MODE_ALLOWED, |
| 159 | MODE_IGNORED, |
| 160 | MODE_ERRORED, |
| 161 | MODE_DEFAULT, |
| 162 | MODE_FOREGROUND |
| 163 | }) |
| 164 | public @interface Mode {} |
| 165 | |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 166 | /** |
| 167 | * Result from {@link #checkOp}, {@link #noteOp}, {@link #startOp}: the given caller is |
| 168 | * allowed to perform the given operation. |
| 169 | */ |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 170 | public static final int MODE_ALLOWED = 0; |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 171 | |
| 172 | /** |
| 173 | * Result from {@link #checkOp}, {@link #noteOp}, {@link #startOp}: the given caller is |
| 174 | * not allowed to perform the given operation, and this attempt should |
| 175 | * <em>silently fail</em> (it should not cause the app to crash). |
| 176 | */ |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 177 | public static final int MODE_IGNORED = 1; |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 178 | |
| 179 | /** |
| 180 | * Result from {@link #checkOpNoThrow}, {@link #noteOpNoThrow}, {@link #startOpNoThrow}: the |
| 181 | * given caller is not allowed to perform the given operation, and this attempt should |
| 182 | * cause it to have a fatal error, typically a {@link SecurityException}. |
| 183 | */ |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 184 | public static final int MODE_ERRORED = 2; |
| 185 | |
Dianne Hackborn | 33f5ddd | 2014-07-21 15:35:45 -0700 | [diff] [blame] | 186 | /** |
| 187 | * Result from {@link #checkOp}, {@link #noteOp}, {@link #startOp}: the given caller should |
| 188 | * use its default security check. This mode is not normally used; it should only be used |
| 189 | * with appop permissions, and callers must explicitly check for it and deal with it. |
| 190 | */ |
| 191 | public static final int MODE_DEFAULT = 3; |
| 192 | |
Dianne Hackborn | cd1f30b | 2018-04-23 17:38:09 -0700 | [diff] [blame] | 193 | /** |
Dianne Hackborn | c216a26 | 2018-04-26 13:46:22 -0700 | [diff] [blame] | 194 | * 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] | 195 | * returned from {@link #unsafeCheckOp}, {@link #noteOp}, {@link #startOp}. Rather, |
| 196 | * {@link #unsafeCheckOp} will always return {@link #MODE_ALLOWED} (because it is always |
| 197 | * possible for it to be ultimately allowed, depending on the app's background state), |
| 198 | * and {@link #noteOp} and {@link #startOp} will return {@link #MODE_ALLOWED} when the app |
| 199 | * being checked is currently in the foreground, otherwise {@link #MODE_IGNORED}. |
| 200 | * |
| 201 | * <p>The only place you will this normally see this value is through |
| 202 | * {@link #unsafeCheckOpRaw}, which returns the actual raw mode of the op. Note that because |
| 203 | * you can't know the current state of the app being checked (and it can change at any |
| 204 | * point), you can only treat the result here as an indication that it will vary between |
| 205 | * {@link #MODE_ALLOWED} and {@link #MODE_IGNORED} depending on changes in the background |
| 206 | * state of the app. You thus must always use {@link #noteOp} or {@link #startOp} to do |
| 207 | * the actual check for access to the op.</p> |
Dianne Hackborn | c216a26 | 2018-04-26 13:46:22 -0700 | [diff] [blame] | 208 | */ |
| 209 | public static final int MODE_FOREGROUND = 4; |
| 210 | |
Dianne Hackborn | 65a4f25 | 2018-05-08 17:30:48 -0700 | [diff] [blame] | 211 | /** |
| 212 | * Flag for {@link #startWatchingMode(String, String, int, OnOpChangedListener)}: |
| 213 | * Also get reports if the foreground state of an op's uid changes. This only works |
| 214 | * when watching a particular op, not when watching a package. |
Dianne Hackborn | 65a4f25 | 2018-05-08 17:30:48 -0700 | [diff] [blame] | 215 | */ |
| 216 | public static final int WATCH_FOREGROUND_CHANGES = 1 << 0; |
Dianne Hackborn | c216a26 | 2018-04-26 13:46:22 -0700 | [diff] [blame] | 217 | |
| 218 | /** |
| 219 | * @hide |
| 220 | */ |
| 221 | public static final String[] MODE_NAMES = new String[] { |
| 222 | "allow", // MODE_ALLOWED |
| 223 | "ignore", // MODE_IGNORED |
| 224 | "deny", // MODE_ERRORED |
| 225 | "default", // MODE_DEFAULT |
| 226 | "foreground", // MODE_FOREGROUND |
| 227 | }; |
| 228 | |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 229 | /** @hide */ |
| 230 | @Retention(RetentionPolicy.SOURCE) |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 231 | @IntDef(prefix = { "UID_STATE_" }, value = { |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 232 | UID_STATE_PERSISTENT, |
| 233 | UID_STATE_TOP, |
Amith Yamasani | a0a30a1 | 2019-01-22 11:38:06 -0800 | [diff] [blame] | 234 | UID_STATE_FOREGROUND_SERVICE_LOCATION, |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 235 | UID_STATE_FOREGROUND_SERVICE, |
| 236 | UID_STATE_FOREGROUND, |
| 237 | UID_STATE_BACKGROUND, |
| 238 | UID_STATE_CACHED |
| 239 | }) |
| 240 | public @interface UidState {} |
| 241 | |
Dianne Hackborn | c216a26 | 2018-04-26 13:46:22 -0700 | [diff] [blame] | 242 | /** |
Svet Ganov | 05fcd22 | 2019-07-08 16:30:45 -0700 | [diff] [blame] | 243 | * Uid state: The UID is a foreground persistent app. The lower the UID |
| 244 | * state the more important the UID is for the user. |
Dianne Hackborn | cd1f30b | 2018-04-23 17:38:09 -0700 | [diff] [blame] | 245 | * @hide |
| 246 | */ |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 247 | @TestApi |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 248 | @SystemApi |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 249 | public static final int UID_STATE_PERSISTENT = 100; |
Dianne Hackborn | cd1f30b | 2018-04-23 17:38:09 -0700 | [diff] [blame] | 250 | |
| 251 | /** |
Svet Ganov | 05fcd22 | 2019-07-08 16:30:45 -0700 | [diff] [blame] | 252 | * Uid state: The UID is top foreground app. The lower the UID |
| 253 | * state the more important the UID is for the user. |
Dianne Hackborn | cd1f30b | 2018-04-23 17:38:09 -0700 | [diff] [blame] | 254 | * @hide |
| 255 | */ |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 256 | @TestApi |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 257 | @SystemApi |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 258 | public static final int UID_STATE_TOP = 200; |
Dianne Hackborn | cd1f30b | 2018-04-23 17:38:09 -0700 | [diff] [blame] | 259 | |
| 260 | /** |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 261 | * Uid state: The UID is running a foreground service of location type. |
Svet Ganov | 05fcd22 | 2019-07-08 16:30:45 -0700 | [diff] [blame] | 262 | * The lower the UID state the more important the UID is for the user. |
Amith Yamasani | a0a30a1 | 2019-01-22 11:38:06 -0800 | [diff] [blame] | 263 | * @hide |
| 264 | */ |
| 265 | @TestApi |
| 266 | @SystemApi |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 267 | public static final int UID_STATE_FOREGROUND_SERVICE_LOCATION = 300; |
Amith Yamasani | a0a30a1 | 2019-01-22 11:38:06 -0800 | [diff] [blame] | 268 | |
| 269 | /** |
Svet Ganov | 05fcd22 | 2019-07-08 16:30:45 -0700 | [diff] [blame] | 270 | * Uid state: The UID is running a foreground service. The lower the UID |
| 271 | * state the more important the UID is for the user. |
Dianne Hackborn | cd1f30b | 2018-04-23 17:38:09 -0700 | [diff] [blame] | 272 | * @hide |
| 273 | */ |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 274 | @TestApi |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 275 | @SystemApi |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 276 | public static final int UID_STATE_FOREGROUND_SERVICE = 400; |
Dianne Hackborn | cd1f30b | 2018-04-23 17:38:09 -0700 | [diff] [blame] | 277 | |
| 278 | /** |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 279 | * The max, which is min priority, UID state for which any app op |
| 280 | * would be considered as performed in the foreground. |
Dianne Hackborn | e93ab41 | 2018-05-14 17:52:30 -0700 | [diff] [blame] | 281 | * @hide |
| 282 | */ |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 283 | public static final int UID_STATE_MAX_LAST_NON_RESTRICTED = UID_STATE_FOREGROUND_SERVICE; |
Dianne Hackborn | e93ab41 | 2018-05-14 17:52:30 -0700 | [diff] [blame] | 284 | |
| 285 | /** |
Svet Ganov | 05fcd22 | 2019-07-08 16:30:45 -0700 | [diff] [blame] | 286 | * Uid state: The UID is a foreground app. The lower the UID |
| 287 | * state the more important the UID is for the user. |
Dianne Hackborn | cd1f30b | 2018-04-23 17:38:09 -0700 | [diff] [blame] | 288 | * @hide |
| 289 | */ |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 290 | @TestApi |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 291 | @SystemApi |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 292 | public static final int UID_STATE_FOREGROUND = 500; |
Dianne Hackborn | cd1f30b | 2018-04-23 17:38:09 -0700 | [diff] [blame] | 293 | |
| 294 | /** |
Svet Ganov | 05fcd22 | 2019-07-08 16:30:45 -0700 | [diff] [blame] | 295 | * Uid state: The UID is a background app. The lower the UID |
| 296 | * state the more important the UID is for the user. |
Dianne Hackborn | cd1f30b | 2018-04-23 17:38:09 -0700 | [diff] [blame] | 297 | * @hide |
| 298 | */ |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 299 | @TestApi |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 300 | @SystemApi |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 301 | public static final int UID_STATE_BACKGROUND = 600; |
Dianne Hackborn | cd1f30b | 2018-04-23 17:38:09 -0700 | [diff] [blame] | 302 | |
| 303 | /** |
Svet Ganov | 05fcd22 | 2019-07-08 16:30:45 -0700 | [diff] [blame] | 304 | * Uid state: The UID is a cached app. The lower the UID |
| 305 | * state the more important the UID is for the user. |
Dianne Hackborn | cd1f30b | 2018-04-23 17:38:09 -0700 | [diff] [blame] | 306 | * @hide |
| 307 | */ |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 308 | @TestApi |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 309 | @SystemApi |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 310 | public static final int UID_STATE_CACHED = 700; |
Dianne Hackborn | cd1f30b | 2018-04-23 17:38:09 -0700 | [diff] [blame] | 311 | |
| 312 | /** |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 313 | * Uid state: The UID state with the highest priority. |
Dianne Hackborn | cd1f30b | 2018-04-23 17:38:09 -0700 | [diff] [blame] | 314 | * @hide |
| 315 | */ |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 316 | public static final int MAX_PRIORITY_UID_STATE = UID_STATE_PERSISTENT; |
| 317 | |
| 318 | /** |
| 319 | * Uid state: The UID state with the lowest priority. |
| 320 | * @hide |
| 321 | */ |
| 322 | public static final int MIN_PRIORITY_UID_STATE = UID_STATE_CACHED; |
| 323 | |
| 324 | /** |
| 325 | * Resolves the first unrestricted state given an app op. Location is |
| 326 | * special as we want to allow its access only if a dedicated location |
| 327 | * foreground service is running. For other ops we consider any foreground |
| 328 | * service as a foreground state. |
| 329 | * |
| 330 | * @param op The op to resolve. |
| 331 | * @return The last restricted UID state. |
| 332 | * |
| 333 | * @hide |
| 334 | */ |
| 335 | public static int resolveFirstUnrestrictedUidState(int op) { |
| 336 | switch (op) { |
| 337 | case OP_FINE_LOCATION: |
Wei Wang | e1f864e | 2019-03-28 18:12:18 -0700 | [diff] [blame] | 338 | case OP_COARSE_LOCATION: |
| 339 | case OP_MONITOR_LOCATION: |
| 340 | case OP_MONITOR_HIGH_POWER_LOCATION: { |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 341 | return UID_STATE_FOREGROUND_SERVICE_LOCATION; |
| 342 | } |
| 343 | } |
| 344 | return UID_STATE_FOREGROUND_SERVICE; |
| 345 | } |
| 346 | |
| 347 | /** |
| 348 | * Resolves the last restricted state given an app op. Location is |
| 349 | * special as we want to allow its access only if a dedicated location |
| 350 | * foreground service is running. For other ops we consider any foreground |
| 351 | * service as a foreground state. |
| 352 | * |
| 353 | * @param op The op to resolve. |
| 354 | * @return The last restricted UID state. |
| 355 | * |
| 356 | * @hide |
| 357 | */ |
| 358 | public static int resolveLastRestrictedUidState(int op) { |
| 359 | switch (op) { |
| 360 | case OP_FINE_LOCATION: |
| 361 | case OP_COARSE_LOCATION: { |
| 362 | return UID_STATE_FOREGROUND_SERVICE; |
| 363 | } |
| 364 | } |
| 365 | return UID_STATE_FOREGROUND; |
| 366 | } |
| 367 | |
| 368 | /** @hide Note: Keep these sorted */ |
| 369 | public static final int[] UID_STATES = { |
| 370 | UID_STATE_PERSISTENT, |
| 371 | UID_STATE_TOP, |
| 372 | UID_STATE_FOREGROUND_SERVICE_LOCATION, |
| 373 | UID_STATE_FOREGROUND_SERVICE, |
| 374 | UID_STATE_FOREGROUND, |
| 375 | UID_STATE_BACKGROUND, |
| 376 | UID_STATE_CACHED |
| 377 | }; |
| 378 | |
| 379 | /** @hide */ |
| 380 | public static String getUidStateName(@UidState int uidState) { |
| 381 | switch (uidState) { |
| 382 | case UID_STATE_PERSISTENT: |
| 383 | return "pers"; |
| 384 | case UID_STATE_TOP: |
| 385 | return "top"; |
| 386 | case UID_STATE_FOREGROUND_SERVICE_LOCATION: |
| 387 | return "fgsvcl"; |
| 388 | case UID_STATE_FOREGROUND_SERVICE: |
| 389 | return "fgsvc"; |
| 390 | case UID_STATE_FOREGROUND: |
| 391 | return "fg"; |
| 392 | case UID_STATE_BACKGROUND: |
| 393 | return "bg"; |
| 394 | case UID_STATE_CACHED: |
| 395 | return "cch"; |
| 396 | default: |
| 397 | return "unknown"; |
| 398 | } |
| 399 | } |
| 400 | |
| 401 | /** |
| 402 | * Flag: non proxy operations. These are operations |
| 403 | * performed on behalf of the app itself and not on behalf of |
| 404 | * another one. |
| 405 | * |
| 406 | * @hide |
| 407 | */ |
| 408 | @TestApi |
| 409 | @SystemApi |
| 410 | public static final int OP_FLAG_SELF = 0x1; |
| 411 | |
| 412 | /** |
| 413 | * Flag: trusted proxy operations. These are operations |
| 414 | * performed on behalf of another app by a trusted app. |
| 415 | * Which is work a trusted app blames on another app. |
| 416 | * |
| 417 | * @hide |
| 418 | */ |
| 419 | @TestApi |
| 420 | @SystemApi |
| 421 | public static final int OP_FLAG_TRUSTED_PROXY = 0x2; |
| 422 | |
| 423 | /** |
| 424 | * Flag: untrusted proxy operations. These are operations |
| 425 | * performed on behalf of another app by an untrusted app. |
| 426 | * Which is work an untrusted app blames on another app. |
| 427 | * |
| 428 | * @hide |
| 429 | */ |
| 430 | @TestApi |
| 431 | @SystemApi |
| 432 | public static final int OP_FLAG_UNTRUSTED_PROXY = 0x4; |
| 433 | |
| 434 | /** |
| 435 | * Flag: trusted proxied operations. These are operations |
| 436 | * performed by a trusted other app on behalf of an app. |
| 437 | * Which is work an app was blamed for by a trusted app. |
| 438 | * |
| 439 | * @hide |
| 440 | */ |
| 441 | @TestApi |
| 442 | @SystemApi |
| 443 | public static final int OP_FLAG_TRUSTED_PROXIED = 0x8; |
| 444 | |
| 445 | /** |
| 446 | * Flag: untrusted proxied operations. These are operations |
| 447 | * performed by an untrusted other app on behalf of an app. |
| 448 | * Which is work an app was blamed for by an untrusted app. |
| 449 | * |
| 450 | * @hide |
| 451 | */ |
| 452 | @TestApi |
| 453 | @SystemApi |
| 454 | public static final int OP_FLAG_UNTRUSTED_PROXIED = 0x10; |
| 455 | |
| 456 | /** |
| 457 | * Flags: all operations. These include operations matched |
| 458 | * by {@link #OP_FLAG_SELF}, {@link #OP_FLAG_TRUSTED_PROXIED}, |
| 459 | * {@link #OP_FLAG_UNTRUSTED_PROXIED}, {@link #OP_FLAG_TRUSTED_PROXIED}, |
| 460 | * {@link #OP_FLAG_UNTRUSTED_PROXIED}. |
| 461 | * |
| 462 | * @hide |
| 463 | */ |
| 464 | @TestApi |
| 465 | @SystemApi |
| 466 | public static final int OP_FLAGS_ALL = |
| 467 | OP_FLAG_SELF |
| 468 | | OP_FLAG_TRUSTED_PROXY |
| 469 | | OP_FLAG_UNTRUSTED_PROXY |
| 470 | | OP_FLAG_TRUSTED_PROXIED |
| 471 | | OP_FLAG_UNTRUSTED_PROXIED; |
| 472 | |
| 473 | /** |
| 474 | * Flags: all trusted operations which is ones either the app did {@link #OP_FLAG_SELF}, |
| 475 | * or it was blamed for by a trusted app {@link #OP_FLAG_TRUSTED_PROXIED}, or ones the |
| 476 | * app if untrusted blamed on other apps {@link #OP_FLAG_UNTRUSTED_PROXY}. |
| 477 | * |
| 478 | * @hide |
| 479 | */ |
| 480 | @SystemApi |
| 481 | public static final int OP_FLAGS_ALL_TRUSTED = AppOpsManager.OP_FLAG_SELF |
| 482 | | AppOpsManager.OP_FLAG_UNTRUSTED_PROXY |
| 483 | | AppOpsManager.OP_FLAG_TRUSTED_PROXIED; |
| 484 | |
| 485 | /** @hide */ |
| 486 | @Retention(RetentionPolicy.SOURCE) |
| 487 | @IntDef(flag = true, prefix = { "FLAG_" }, value = { |
| 488 | OP_FLAG_SELF, |
| 489 | OP_FLAG_TRUSTED_PROXY, |
| 490 | OP_FLAG_UNTRUSTED_PROXY, |
| 491 | OP_FLAG_TRUSTED_PROXIED, |
| 492 | OP_FLAG_UNTRUSTED_PROXIED |
| 493 | }) |
| 494 | public @interface OpFlags {} |
| 495 | |
| 496 | |
| 497 | /** @hide */ |
| 498 | public static final String getFlagName(@OpFlags int flag) { |
| 499 | switch (flag) { |
| 500 | case OP_FLAG_SELF: |
| 501 | return "s"; |
| 502 | case OP_FLAG_TRUSTED_PROXY: |
| 503 | return "tp"; |
| 504 | case OP_FLAG_UNTRUSTED_PROXY: |
| 505 | return "up"; |
| 506 | case OP_FLAG_TRUSTED_PROXIED: |
| 507 | return "tpd"; |
| 508 | case OP_FLAG_UNTRUSTED_PROXIED: |
| 509 | return "upd"; |
| 510 | default: |
| 511 | return "unknown"; |
| 512 | } |
| 513 | } |
| 514 | |
| 515 | private static final int UID_STATE_OFFSET = 31; |
| 516 | private static final int FLAGS_MASK = 0xFFFFFFFF; |
| 517 | |
| 518 | /** |
| 519 | * Key for a data bucket storing app op state. The bucket |
| 520 | * is composed of the uid state and state flags. This way |
| 521 | * we can query data for given uid state and a set of flags where |
| 522 | * the flags control which type of data to get. For example, |
| 523 | * one can get the ops an app did on behalf of other apps |
| 524 | * while in the background. |
| 525 | * |
| 526 | * @hide |
| 527 | */ |
| 528 | @Retention(RetentionPolicy.SOURCE) |
| 529 | @Target({ElementType.METHOD, ElementType.PARAMETER, ElementType.FIELD}) |
| 530 | public @interface DataBucketKey { |
| 531 | } |
| 532 | |
| 533 | /** @hide */ |
| 534 | public static String keyToString(@DataBucketKey long key) { |
| 535 | final int uidState = extractUidStateFromKey(key); |
| 536 | final int flags = extractFlagsFromKey(key); |
| 537 | return "[" + getUidStateName(uidState) + "-" + flagsToString(flags) + "]"; |
| 538 | } |
| 539 | |
| 540 | /** @hide */ |
| 541 | public static @DataBucketKey long makeKey(@UidState int uidState, @OpFlags int flags) { |
| 542 | return ((long) uidState << UID_STATE_OFFSET) | flags; |
| 543 | } |
| 544 | |
| 545 | /** @hide */ |
| 546 | public static int extractUidStateFromKey(@DataBucketKey long key) { |
| 547 | return (int) (key >> UID_STATE_OFFSET); |
| 548 | } |
| 549 | |
| 550 | /** @hide */ |
| 551 | public static int extractFlagsFromKey(@DataBucketKey long key) { |
| 552 | return (int) (key & FLAGS_MASK); |
| 553 | } |
| 554 | |
| 555 | /** @hide */ |
| 556 | public static String flagsToString(@OpFlags int flags) { |
| 557 | final StringBuilder flagsBuilder = new StringBuilder(); |
| 558 | while (flags != 0) { |
| 559 | final int flag = 1 << Integer.numberOfTrailingZeros(flags); |
| 560 | flags &= ~flag; |
| 561 | if (flagsBuilder.length() > 0) { |
| 562 | flagsBuilder.append('|'); |
| 563 | } |
| 564 | flagsBuilder.append(getFlagName(flag)); |
| 565 | } |
| 566 | return flagsBuilder.toString(); |
| 567 | } |
Dianne Hackborn | cd1f30b | 2018-04-23 17:38:09 -0700 | [diff] [blame] | 568 | |
Daniel Sandler | fde19b1 | 2013-01-17 00:21:05 -0500 | [diff] [blame] | 569 | // when adding one of these: |
| 570 | // - increment _NUM_OP |
Peter Visontay | 5a2a1ef | 2017-12-18 20:34:03 +0000 | [diff] [blame] | 571 | // - define an OPSTR_* constant (marked as @SystemApi) |
Svetoslav Ganov | eaca4c5 | 2016-05-05 18:08:00 -0700 | [diff] [blame] | 572 | // - add rows to sOpToSwitch, sOpToString, sOpNames, sOpToPerms, sOpDefault |
Daniel Sandler | fde19b1 | 2013-01-17 00:21:05 -0500 | [diff] [blame] | 573 | // - add descriptive strings to Settings/res/values/arrays.xml |
David Christie | 0b83745 | 2013-07-29 16:02:13 -0700 | [diff] [blame] | 574 | // - add the op to the appropriate template in AppOpsState.OpsTemplate (settings app) |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 575 | |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 576 | /** @hide No operation specified. */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 577 | @UnsupportedAppUsage |
Dianne Hackborn | f51f612 | 2013-02-04 18:23:34 -0800 | [diff] [blame] | 578 | public static final int OP_NONE = -1; |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 579 | /** @hide Access to coarse location information. */ |
Artur Satayev | 5a52585 | 2019-10-31 15:15:50 +0000 | [diff] [blame] | 580 | @UnsupportedAppUsage |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 581 | @TestApi |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 582 | public static final int OP_COARSE_LOCATION = 0; |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 583 | /** @hide Access to fine location information. */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 584 | @UnsupportedAppUsage |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 585 | public static final int OP_FINE_LOCATION = 1; |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 586 | /** @hide Causing GPS to run. */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 587 | @UnsupportedAppUsage |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 588 | public static final int OP_GPS = 2; |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 589 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 590 | @UnsupportedAppUsage |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 591 | public static final int OP_VIBRATE = 3; |
| 592 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 593 | @UnsupportedAppUsage |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 594 | public static final int OP_READ_CONTACTS = 4; |
| 595 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 596 | @UnsupportedAppUsage |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 597 | public static final int OP_WRITE_CONTACTS = 5; |
| 598 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 599 | @UnsupportedAppUsage |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 600 | public static final int OP_READ_CALL_LOG = 6; |
| 601 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 602 | @UnsupportedAppUsage |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 603 | public static final int OP_WRITE_CALL_LOG = 7; |
| 604 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 605 | @UnsupportedAppUsage |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 606 | public static final int OP_READ_CALENDAR = 8; |
| 607 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 608 | @UnsupportedAppUsage |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 609 | public static final int OP_WRITE_CALENDAR = 9; |
| 610 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 611 | @UnsupportedAppUsage |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 612 | public static final int OP_WIFI_SCAN = 10; |
| 613 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 614 | @UnsupportedAppUsage |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 615 | public static final int OP_POST_NOTIFICATION = 11; |
| 616 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 617 | @UnsupportedAppUsage |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 618 | public static final int OP_NEIGHBORING_CELLS = 12; |
| 619 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 620 | @UnsupportedAppUsage |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 621 | public static final int OP_CALL_PHONE = 13; |
| 622 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 623 | @UnsupportedAppUsage |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 624 | public static final int OP_READ_SMS = 14; |
| 625 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 626 | @UnsupportedAppUsage |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 627 | public static final int OP_WRITE_SMS = 15; |
| 628 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 629 | @UnsupportedAppUsage |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 630 | public static final int OP_RECEIVE_SMS = 16; |
| 631 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 632 | @UnsupportedAppUsage |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 633 | public static final int OP_RECEIVE_EMERGECY_SMS = 17; |
| 634 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 635 | @UnsupportedAppUsage |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 636 | public static final int OP_RECEIVE_MMS = 18; |
| 637 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 638 | @UnsupportedAppUsage |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 639 | public static final int OP_RECEIVE_WAP_PUSH = 19; |
| 640 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 641 | @UnsupportedAppUsage |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 642 | public static final int OP_SEND_SMS = 20; |
| 643 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 644 | @UnsupportedAppUsage |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 645 | public static final int OP_READ_ICC_SMS = 21; |
| 646 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 647 | @UnsupportedAppUsage |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 648 | public static final int OP_WRITE_ICC_SMS = 22; |
| 649 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 650 | @UnsupportedAppUsage |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 651 | public static final int OP_WRITE_SETTINGS = 23; |
Peter Visontay | 96449f6 | 2017-12-11 18:50:03 +0000 | [diff] [blame] | 652 | /** @hide Required to draw on top of other apps. */ |
Artur Satayev | 5a52585 | 2019-10-31 15:15:50 +0000 | [diff] [blame] | 653 | @UnsupportedAppUsage |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 654 | @TestApi |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 655 | public static final int OP_SYSTEM_ALERT_WINDOW = 24; |
| 656 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 657 | @UnsupportedAppUsage |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 658 | public static final int OP_ACCESS_NOTIFICATIONS = 25; |
| 659 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 660 | @UnsupportedAppUsage |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 661 | public static final int OP_CAMERA = 26; |
| 662 | /** @hide */ |
Artur Satayev | 5a52585 | 2019-10-31 15:15:50 +0000 | [diff] [blame] | 663 | @UnsupportedAppUsage |
Svet Ganov | a7a0db6 | 2018-02-27 20:08:01 -0800 | [diff] [blame] | 664 | @TestApi |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 665 | public static final int OP_RECORD_AUDIO = 27; |
| 666 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 667 | @UnsupportedAppUsage |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 668 | public static final int OP_PLAY_AUDIO = 28; |
| 669 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 670 | @UnsupportedAppUsage |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 671 | public static final int OP_READ_CLIPBOARD = 29; |
| 672 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 673 | @UnsupportedAppUsage |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 674 | public static final int OP_WRITE_CLIPBOARD = 30; |
| 675 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 676 | @UnsupportedAppUsage |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 677 | public static final int OP_TAKE_MEDIA_BUTTONS = 31; |
| 678 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 679 | @UnsupportedAppUsage |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 680 | public static final int OP_TAKE_AUDIO_FOCUS = 32; |
| 681 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 682 | @UnsupportedAppUsage |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 683 | public static final int OP_AUDIO_MASTER_VOLUME = 33; |
| 684 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 685 | @UnsupportedAppUsage |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 686 | public static final int OP_AUDIO_VOICE_VOLUME = 34; |
| 687 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 688 | @UnsupportedAppUsage |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 689 | public static final int OP_AUDIO_RING_VOLUME = 35; |
| 690 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 691 | @UnsupportedAppUsage |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 692 | public static final int OP_AUDIO_MEDIA_VOLUME = 36; |
| 693 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 694 | @UnsupportedAppUsage |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 695 | public static final int OP_AUDIO_ALARM_VOLUME = 37; |
| 696 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 697 | @UnsupportedAppUsage |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 698 | public static final int OP_AUDIO_NOTIFICATION_VOLUME = 38; |
| 699 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 700 | @UnsupportedAppUsage |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 701 | public static final int OP_AUDIO_BLUETOOTH_VOLUME = 39; |
| 702 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 703 | @UnsupportedAppUsage |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 704 | public static final int OP_WAKE_LOCK = 40; |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 705 | /** @hide Continually monitoring location data. */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 706 | @UnsupportedAppUsage |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 707 | public static final int OP_MONITOR_LOCATION = 41; |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 708 | /** @hide Continually monitoring location data with a relatively high power request. */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 709 | @UnsupportedAppUsage |
David Christie | 0b83745 | 2013-07-29 16:02:13 -0700 | [diff] [blame] | 710 | public static final int OP_MONITOR_HIGH_POWER_LOCATION = 42; |
Dianne Hackborn | e22b3b1 | 2014-05-07 18:06:44 -0700 | [diff] [blame] | 711 | /** @hide Retrieve current usage stats via {@link UsageStatsManager}. */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 712 | @UnsupportedAppUsage |
Dianne Hackborn | e22b3b1 | 2014-05-07 18:06:44 -0700 | [diff] [blame] | 713 | public static final int OP_GET_USAGE_STATS = 43; |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 714 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 715 | @UnsupportedAppUsage |
Emily Bernier | 22c921a | 2014-05-28 11:01:32 -0400 | [diff] [blame] | 716 | public static final int OP_MUTE_MICROPHONE = 44; |
| 717 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 718 | @UnsupportedAppUsage |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 719 | public static final int OP_TOAST_WINDOW = 45; |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 720 | /** @hide Capture the device's display contents and/or audio */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 721 | @UnsupportedAppUsage |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 722 | public static final int OP_PROJECT_MEDIA = 46; |
Jeff Davidson | 0554260 | 2014-08-11 14:07:27 -0700 | [diff] [blame] | 723 | /** @hide Activate a VPN connection without user intervention. */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 724 | @UnsupportedAppUsage |
Jeff Davidson | 0554260 | 2014-08-11 14:07:27 -0700 | [diff] [blame] | 725 | public static final int OP_ACTIVATE_VPN = 47; |
Benjamin Franz | f3ece36 | 2015-02-11 10:51:10 +0000 | [diff] [blame] | 726 | /** @hide Access the WallpaperManagerAPI to write wallpapers. */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 727 | @UnsupportedAppUsage |
Benjamin Franz | f3ece36 | 2015-02-11 10:51:10 +0000 | [diff] [blame] | 728 | public static final int OP_WRITE_WALLPAPER = 48; |
Dianne Hackborn | d59a5d5 | 2015-04-04 14:52:14 -0700 | [diff] [blame] | 729 | /** @hide Received the assist structure from an app. */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 730 | @UnsupportedAppUsage |
Dianne Hackborn | d59a5d5 | 2015-04-04 14:52:14 -0700 | [diff] [blame] | 731 | public static final int OP_ASSIST_STRUCTURE = 49; |
| 732 | /** @hide Received a screenshot from assist. */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 733 | @UnsupportedAppUsage |
Dianne Hackborn | d59a5d5 | 2015-04-04 14:52:14 -0700 | [diff] [blame] | 734 | public static final int OP_ASSIST_SCREENSHOT = 50; |
Svet Ganov | 16a1689 | 2015-04-16 10:32:04 -0700 | [diff] [blame] | 735 | /** @hide Read the phone state. */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 736 | @UnsupportedAppUsage |
Svet Ganov | 16a1689 | 2015-04-16 10:32:04 -0700 | [diff] [blame] | 737 | public static final int OP_READ_PHONE_STATE = 51; |
Svet Ganov | c330009 | 2015-04-17 09:07:22 -0700 | [diff] [blame] | 738 | /** @hide Add voicemail messages to the voicemail content provider. */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 739 | @UnsupportedAppUsage |
Svet Ganov | c330009 | 2015-04-17 09:07:22 -0700 | [diff] [blame] | 740 | public static final int OP_ADD_VOICEMAIL = 52; |
Svetoslav | 5335b67 | 2015-04-29 12:00:51 -0700 | [diff] [blame] | 741 | /** @hide Access APIs for SIP calling over VOIP or WiFi. */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 742 | @UnsupportedAppUsage |
Svetoslav | 5335b67 | 2015-04-29 12:00:51 -0700 | [diff] [blame] | 743 | public static final int OP_USE_SIP = 53; |
Svetoslav | c656e6f | 2015-04-29 14:08:16 -0700 | [diff] [blame] | 744 | /** @hide Intercept outgoing calls. */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 745 | @UnsupportedAppUsage |
Svetoslav | c656e6f | 2015-04-29 14:08:16 -0700 | [diff] [blame] | 746 | public static final int OP_PROCESS_OUTGOING_CALLS = 54; |
Svetoslav | 4af76a5 | 2015-04-29 15:29:46 -0700 | [diff] [blame] | 747 | /** @hide User the fingerprint API. */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 748 | @UnsupportedAppUsage |
Svetoslav | 4af76a5 | 2015-04-29 15:29:46 -0700 | [diff] [blame] | 749 | public static final int OP_USE_FINGERPRINT = 55; |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 750 | /** @hide Access to body sensors such as heart rate, etc. */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 751 | @UnsupportedAppUsage |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 752 | public static final int OP_BODY_SENSORS = 56; |
Svet Ganov | ede4316 | 2015-05-02 17:42:44 -0700 | [diff] [blame] | 753 | /** @hide Read previously received cell broadcast messages. */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 754 | @UnsupportedAppUsage |
Svet Ganov | ede4316 | 2015-05-02 17:42:44 -0700 | [diff] [blame] | 755 | public static final int OP_READ_CELL_BROADCASTS = 57; |
Svet Ganov | f7e9cf4 | 2015-05-13 10:40:31 -0700 | [diff] [blame] | 756 | /** @hide Inject mock location into the system. */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 757 | @UnsupportedAppUsage |
Svet Ganov | f7e9cf4 | 2015-05-13 10:40:31 -0700 | [diff] [blame] | 758 | public static final int OP_MOCK_LOCATION = 58; |
Svet Ganov | 921c7df | 2015-06-29 21:51:41 -0700 | [diff] [blame] | 759 | /** @hide Read external storage. */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 760 | @UnsupportedAppUsage |
Svet Ganov | 921c7df | 2015-06-29 21:51:41 -0700 | [diff] [blame] | 761 | public static final int OP_READ_EXTERNAL_STORAGE = 59; |
| 762 | /** @hide Write external storage. */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 763 | @UnsupportedAppUsage |
Svet Ganov | 921c7df | 2015-06-29 21:51:41 -0700 | [diff] [blame] | 764 | public static final int OP_WRITE_EXTERNAL_STORAGE = 60; |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 765 | /** @hide Turned on the screen. */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 766 | @UnsupportedAppUsage |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 767 | public static final int OP_TURN_SCREEN_ON = 61; |
Svetoslav | f3f02ac | 2015-09-08 14:36:35 -0700 | [diff] [blame] | 768 | /** @hide Get device accounts. */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 769 | @UnsupportedAppUsage |
Svetoslav | f3f02ac | 2015-09-08 14:36:35 -0700 | [diff] [blame] | 770 | public static final int OP_GET_ACCOUNTS = 62; |
Dianne Hackborn | bef28fe | 2015-10-29 17:57:11 -0700 | [diff] [blame] | 771 | /** @hide Control whether an application is allowed to run in the background. */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 772 | @UnsupportedAppUsage |
Dianne Hackborn | bef28fe | 2015-10-29 17:57:11 -0700 | [diff] [blame] | 773 | public static final int OP_RUN_IN_BACKGROUND = 63; |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 774 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 775 | @UnsupportedAppUsage |
Jean-Michel Trivi | 3f0945a | 2016-11-11 10:05:18 -0800 | [diff] [blame] | 776 | public static final int OP_AUDIO_ACCESSIBILITY_VOLUME = 64; |
Chad Brubaker | 73ec8f9 | 2016-11-10 11:24:40 -0800 | [diff] [blame] | 777 | /** @hide Read the phone number. */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 778 | @UnsupportedAppUsage |
Chad Brubaker | 0c1651f | 2017-03-30 16:29:10 -0700 | [diff] [blame] | 779 | public static final int OP_READ_PHONE_NUMBERS = 65; |
Suprabh Shukla | 2f34b1a | 2016-12-16 14:47:25 -0800 | [diff] [blame] | 780 | /** @hide Request package installs through package installer */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 781 | @UnsupportedAppUsage |
Suprabh Shukla | 2f34b1a | 2016-12-16 14:47:25 -0800 | [diff] [blame] | 782 | public static final int OP_REQUEST_INSTALL_PACKAGES = 66; |
Winson Chung | f4ac063 | 2017-03-17 12:34:12 -0700 | [diff] [blame] | 783 | /** @hide Enter picture-in-picture. */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 784 | @UnsupportedAppUsage |
Winson Chung | f4ac063 | 2017-03-17 12:34:12 -0700 | [diff] [blame] | 785 | public static final int OP_PICTURE_IN_PICTURE = 67; |
Chad Brubaker | 97b383f | 2017-02-02 15:04:35 -0800 | [diff] [blame] | 786 | /** @hide Instant app start foreground service. */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 787 | @UnsupportedAppUsage |
Chad Brubaker | 97b383f | 2017-02-02 15:04:35 -0800 | [diff] [blame] | 788 | public static final int OP_INSTANT_APP_START_FOREGROUND = 68; |
Eugene Susla | cae3d3e | 2017-01-31 11:08:11 -0800 | [diff] [blame] | 789 | /** @hide Answer incoming phone calls */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 790 | @UnsupportedAppUsage |
Eugene Susla | cae3d3e | 2017-01-31 11:08:11 -0800 | [diff] [blame] | 791 | public static final int OP_ANSWER_PHONE_CALLS = 69; |
Suprabh Shukla | 3ac1daa | 2017-07-14 12:15:27 -0700 | [diff] [blame] | 792 | /** @hide Run jobs when in background */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 793 | @UnsupportedAppUsage |
Suprabh Shukla | 3ac1daa | 2017-07-14 12:15:27 -0700 | [diff] [blame] | 794 | public static final int OP_RUN_ANY_IN_BACKGROUND = 70; |
Peter Visontay | 1246d9e | 2017-10-17 17:02:45 +0100 | [diff] [blame] | 795 | /** @hide Change Wi-Fi connectivity state */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 796 | @UnsupportedAppUsage |
Peter Visontay | 1246d9e | 2017-10-17 17:02:45 +0100 | [diff] [blame] | 797 | public static final int OP_CHANGE_WIFI_STATE = 71; |
Peter Visontay | f2e3836 | 2017-11-27 15:27:16 +0000 | [diff] [blame] | 798 | /** @hide Request package deletion through package installer */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 799 | @UnsupportedAppUsage |
Peter Visontay | f2e3836 | 2017-11-27 15:27:16 +0000 | [diff] [blame] | 800 | public static final int OP_REQUEST_DELETE_PACKAGES = 72; |
Peter Visontay | 1195083 | 2017-11-14 19:34:59 +0000 | [diff] [blame] | 801 | /** @hide Bind an accessibility service. */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 802 | @UnsupportedAppUsage |
Peter Visontay | 1195083 | 2017-11-14 19:34:59 +0000 | [diff] [blame] | 803 | public static final int OP_BIND_ACCESSIBILITY_SERVICE = 73; |
Tyler Gunn | 79bc1ec | 2018-01-22 15:17:54 -0800 | [diff] [blame] | 804 | /** @hide Continue handover of a call from another app */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 805 | @UnsupportedAppUsage |
Tyler Gunn | 79bc1ec | 2018-01-22 15:17:54 -0800 | [diff] [blame] | 806 | public static final int OP_ACCEPT_HANDOVER = 74; |
Nathan Harold | 1bb42067 | 2018-03-14 17:08:53 -0700 | [diff] [blame] | 807 | /** @hide Create and Manage IPsec Tunnels */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 808 | @UnsupportedAppUsage |
Nathan Harold | 1bb42067 | 2018-03-14 17:08:53 -0700 | [diff] [blame] | 809 | public static final int OP_MANAGE_IPSEC_TUNNELS = 75; |
Dianne Hackborn | e9d9b4b | 2018-03-28 13:51:46 -0700 | [diff] [blame] | 810 | /** @hide Any app start foreground service. */ |
Artur Satayev | 5a52585 | 2019-10-31 15:15:50 +0000 | [diff] [blame] | 811 | @UnsupportedAppUsage |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 812 | @TestApi |
Dianne Hackborn | e9d9b4b | 2018-03-28 13:51:46 -0700 | [diff] [blame] | 813 | public static final int OP_START_FOREGROUND = 76; |
Jean-Michel Trivi | 3f0945a | 2016-11-11 10:05:18 -0800 | [diff] [blame] | 814 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 815 | @UnsupportedAppUsage |
Dianne Hackborn | e04f13d | 2018-05-02 12:51:52 -0700 | [diff] [blame] | 816 | public static final int OP_BLUETOOTH_SCAN = 77; |
Kevin Chyn | b3c05aa | 2018-09-21 16:50:32 -0700 | [diff] [blame] | 817 | /** @hide Use the BiometricPrompt/BiometricManager APIs. */ |
| 818 | public static final int OP_USE_BIOMETRIC = 78; |
Zimuzo | 6cbf9cc | 2018-10-05 12:05:58 +0100 | [diff] [blame] | 819 | /** @hide Physical activity recognition. */ |
| 820 | public static final int OP_ACTIVITY_RECOGNITION = 79; |
Hongming Jin | 228cd01 | 2018-11-09 14:47:50 -0800 | [diff] [blame] | 821 | /** @hide Financial app sms read. */ |
| 822 | public static final int OP_SMS_FINANCIAL_TRANSACTIONS = 80; |
Jeff Sharkey | d2a1f0d | 2018-11-19 10:32:52 -0700 | [diff] [blame] | 823 | /** @hide Read media of audio type. */ |
| 824 | public static final int OP_READ_MEDIA_AUDIO = 81; |
| 825 | /** @hide Write media of audio type. */ |
| 826 | public static final int OP_WRITE_MEDIA_AUDIO = 82; |
| 827 | /** @hide Read media of video type. */ |
| 828 | public static final int OP_READ_MEDIA_VIDEO = 83; |
| 829 | /** @hide Write media of video type. */ |
| 830 | public static final int OP_WRITE_MEDIA_VIDEO = 84; |
| 831 | /** @hide Read media of image type. */ |
| 832 | public static final int OP_READ_MEDIA_IMAGES = 85; |
| 833 | /** @hide Write media of image type. */ |
| 834 | public static final int OP_WRITE_MEDIA_IMAGES = 86; |
Jeff Sharkey | e82cbb1 | 2018-12-06 15:53:11 -0700 | [diff] [blame] | 835 | /** @hide Has a legacy (non-isolated) view of storage. */ |
| 836 | public static final int OP_LEGACY_STORAGE = 87; |
Jackal Guo | 8dc791e | 2019-01-14 10:26:42 +0800 | [diff] [blame] | 837 | /** @hide Accessing accessibility features */ |
| 838 | public static final int OP_ACCESS_ACCESSIBILITY = 88; |
Michael Groover | 656ef91 | 2019-04-09 17:09:57 -0700 | [diff] [blame] | 839 | /** @hide Read the device identifiers (IMEI / MEID, IMSI, SIM / Build serial) */ |
| 840 | public static final int OP_READ_DEVICE_IDENTIFIERS = 89; |
Philip P. Moltmann | ac7b10c | 2019-09-13 15:12:34 -0700 | [diff] [blame] | 841 | /** @hide Read location metadata from media */ |
| 842 | public static final int OP_ACCESS_MEDIA_LOCATION = 90; |
| 843 | |
Dianne Hackborn | e04f13d | 2018-05-02 12:51:52 -0700 | [diff] [blame] | 844 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 845 | @UnsupportedAppUsage |
Philip P. Moltmann | ac7b10c | 2019-09-13 15:12:34 -0700 | [diff] [blame] | 846 | public static final int _NUM_OP = 91; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 847 | |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 848 | /** Access to coarse location information. */ |
Svet Ganov | 6e8f67c | 2015-04-29 17:35:19 -0700 | [diff] [blame] | 849 | public static final String OPSTR_COARSE_LOCATION = "android:coarse_location"; |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 850 | /** Access to fine location information. */ |
| 851 | public static final String OPSTR_FINE_LOCATION = |
| 852 | "android:fine_location"; |
| 853 | /** Continually monitoring location data. */ |
| 854 | public static final String OPSTR_MONITOR_LOCATION |
| 855 | = "android:monitor_location"; |
| 856 | /** Continually monitoring location data with a relatively high power request. */ |
| 857 | public static final String OPSTR_MONITOR_HIGH_POWER_LOCATION |
| 858 | = "android:monitor_location_high_power"; |
Dianne Hackborn | 5064e7c | 2014-09-02 10:57:16 -0700 | [diff] [blame] | 859 | /** Access to {@link android.app.usage.UsageStatsManager}. */ |
| 860 | public static final String OPSTR_GET_USAGE_STATS |
| 861 | = "android:get_usage_stats"; |
Jeff Davidson | 0554260 | 2014-08-11 14:07:27 -0700 | [diff] [blame] | 862 | /** Activate a VPN connection without user intervention. @hide */ |
Peter Visontay | 5a2a1ef | 2017-12-18 20:34:03 +0000 | [diff] [blame] | 863 | @SystemApi @TestApi |
Svet Ganov | 6e8f67c | 2015-04-29 17:35:19 -0700 | [diff] [blame] | 864 | public static final String OPSTR_ACTIVATE_VPN |
| 865 | = "android:activate_vpn"; |
Svet Ganov | 715cf2a | 2015-06-13 17:31:29 -0700 | [diff] [blame] | 866 | /** Allows an application to read the user's contacts data. */ |
Svet Ganov | 6e8f67c | 2015-04-29 17:35:19 -0700 | [diff] [blame] | 867 | public static final String OPSTR_READ_CONTACTS |
| 868 | = "android:read_contacts"; |
Svet Ganov | 715cf2a | 2015-06-13 17:31:29 -0700 | [diff] [blame] | 869 | /** Allows an application to write to the user's contacts data. */ |
Svet Ganov | 6e8f67c | 2015-04-29 17:35:19 -0700 | [diff] [blame] | 870 | public static final String OPSTR_WRITE_CONTACTS |
| 871 | = "android:write_contacts"; |
Svet Ganov | 715cf2a | 2015-06-13 17:31:29 -0700 | [diff] [blame] | 872 | /** Allows an application to read the user's call log. */ |
Svet Ganov | 6e8f67c | 2015-04-29 17:35:19 -0700 | [diff] [blame] | 873 | public static final String OPSTR_READ_CALL_LOG |
| 874 | = "android:read_call_log"; |
Svet Ganov | 715cf2a | 2015-06-13 17:31:29 -0700 | [diff] [blame] | 875 | /** Allows an application to write to the user's call log. */ |
Svet Ganov | 6e8f67c | 2015-04-29 17:35:19 -0700 | [diff] [blame] | 876 | public static final String OPSTR_WRITE_CALL_LOG |
| 877 | = "android:write_call_log"; |
Svet Ganov | 715cf2a | 2015-06-13 17:31:29 -0700 | [diff] [blame] | 878 | /** Allows an application to read the user's calendar data. */ |
Svet Ganov | 6e8f67c | 2015-04-29 17:35:19 -0700 | [diff] [blame] | 879 | public static final String OPSTR_READ_CALENDAR |
| 880 | = "android:read_calendar"; |
Svet Ganov | 715cf2a | 2015-06-13 17:31:29 -0700 | [diff] [blame] | 881 | /** Allows an application to write to the user's calendar data. */ |
Svet Ganov | 6e8f67c | 2015-04-29 17:35:19 -0700 | [diff] [blame] | 882 | public static final String OPSTR_WRITE_CALENDAR |
| 883 | = "android:write_calendar"; |
Svet Ganov | 715cf2a | 2015-06-13 17:31:29 -0700 | [diff] [blame] | 884 | /** Allows an application to initiate a phone call. */ |
Svet Ganov | 6e8f67c | 2015-04-29 17:35:19 -0700 | [diff] [blame] | 885 | public static final String OPSTR_CALL_PHONE |
| 886 | = "android:call_phone"; |
Svet Ganov | 715cf2a | 2015-06-13 17:31:29 -0700 | [diff] [blame] | 887 | /** Allows an application to read SMS messages. */ |
Svet Ganov | 6e8f67c | 2015-04-29 17:35:19 -0700 | [diff] [blame] | 888 | public static final String OPSTR_READ_SMS |
| 889 | = "android:read_sms"; |
Svet Ganov | 715cf2a | 2015-06-13 17:31:29 -0700 | [diff] [blame] | 890 | /** Allows an application to receive SMS messages. */ |
Svet Ganov | 6e8f67c | 2015-04-29 17:35:19 -0700 | [diff] [blame] | 891 | public static final String OPSTR_RECEIVE_SMS |
| 892 | = "android:receive_sms"; |
Svet Ganov | 715cf2a | 2015-06-13 17:31:29 -0700 | [diff] [blame] | 893 | /** Allows an application to receive MMS messages. */ |
Svet Ganov | 6e8f67c | 2015-04-29 17:35:19 -0700 | [diff] [blame] | 894 | public static final String OPSTR_RECEIVE_MMS |
| 895 | = "android:receive_mms"; |
Svet Ganov | 715cf2a | 2015-06-13 17:31:29 -0700 | [diff] [blame] | 896 | /** Allows an application to receive WAP push messages. */ |
Svet Ganov | 6e8f67c | 2015-04-29 17:35:19 -0700 | [diff] [blame] | 897 | public static final String OPSTR_RECEIVE_WAP_PUSH |
| 898 | = "android:receive_wap_push"; |
Svet Ganov | 715cf2a | 2015-06-13 17:31:29 -0700 | [diff] [blame] | 899 | /** Allows an application to send SMS messages. */ |
Svet Ganov | 6e8f67c | 2015-04-29 17:35:19 -0700 | [diff] [blame] | 900 | public static final String OPSTR_SEND_SMS |
| 901 | = "android:send_sms"; |
Svet Ganov | 715cf2a | 2015-06-13 17:31:29 -0700 | [diff] [blame] | 902 | /** Required to be able to access the camera device. */ |
Svet Ganov | 6e8f67c | 2015-04-29 17:35:19 -0700 | [diff] [blame] | 903 | public static final String OPSTR_CAMERA |
| 904 | = "android:camera"; |
Svet Ganov | 715cf2a | 2015-06-13 17:31:29 -0700 | [diff] [blame] | 905 | /** Required to be able to access the microphone device. */ |
Svet Ganov | 6e8f67c | 2015-04-29 17:35:19 -0700 | [diff] [blame] | 906 | public static final String OPSTR_RECORD_AUDIO |
| 907 | = "android:record_audio"; |
Svet Ganov | 715cf2a | 2015-06-13 17:31:29 -0700 | [diff] [blame] | 908 | /** Required to access phone state related information. */ |
Svet Ganov | 6e8f67c | 2015-04-29 17:35:19 -0700 | [diff] [blame] | 909 | public static final String OPSTR_READ_PHONE_STATE |
| 910 | = "android:read_phone_state"; |
Svet Ganov | 715cf2a | 2015-06-13 17:31:29 -0700 | [diff] [blame] | 911 | /** Required to access phone state related information. */ |
Svet Ganov | 6e8f67c | 2015-04-29 17:35:19 -0700 | [diff] [blame] | 912 | public static final String OPSTR_ADD_VOICEMAIL |
| 913 | = "android:add_voicemail"; |
Svet Ganov | 715cf2a | 2015-06-13 17:31:29 -0700 | [diff] [blame] | 914 | /** Access APIs for SIP calling over VOIP or WiFi */ |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 915 | public static final String OPSTR_USE_SIP |
| 916 | = "android:use_sip"; |
Svet Ganov | e8e8942 | 2016-09-22 19:56:50 -0700 | [diff] [blame] | 917 | /** Access APIs for diverting outgoing calls */ |
Svet Ganov | 824ad6e | 2016-09-22 19:36:53 -0700 | [diff] [blame] | 918 | public static final String OPSTR_PROCESS_OUTGOING_CALLS |
| 919 | = "android:process_outgoing_calls"; |
Svet Ganov | 715cf2a | 2015-06-13 17:31:29 -0700 | [diff] [blame] | 920 | /** Use the fingerprint API. */ |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 921 | public static final String OPSTR_USE_FINGERPRINT |
| 922 | = "android:use_fingerprint"; |
Svet Ganov | 715cf2a | 2015-06-13 17:31:29 -0700 | [diff] [blame] | 923 | /** Access to body sensors such as heart rate, etc. */ |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 924 | public static final String OPSTR_BODY_SENSORS |
| 925 | = "android:body_sensors"; |
Svet Ganov | 715cf2a | 2015-06-13 17:31:29 -0700 | [diff] [blame] | 926 | /** Read previously received cell broadcast messages. */ |
Svet Ganov | ede4316 | 2015-05-02 17:42:44 -0700 | [diff] [blame] | 927 | public static final String OPSTR_READ_CELL_BROADCASTS |
| 928 | = "android:read_cell_broadcasts"; |
Svet Ganov | f7e9cf4 | 2015-05-13 10:40:31 -0700 | [diff] [blame] | 929 | /** Inject mock location into the system. */ |
| 930 | public static final String OPSTR_MOCK_LOCATION |
| 931 | = "android:mock_location"; |
Svet Ganov | 921c7df | 2015-06-29 21:51:41 -0700 | [diff] [blame] | 932 | /** Read external storage. */ |
| 933 | public static final String OPSTR_READ_EXTERNAL_STORAGE |
| 934 | = "android:read_external_storage"; |
| 935 | /** Write external storage. */ |
| 936 | public static final String OPSTR_WRITE_EXTERNAL_STORAGE |
| 937 | = "android:write_external_storage"; |
Billy Lau | 24b9c83 | 2015-07-20 17:34:09 +0100 | [diff] [blame] | 938 | /** Required to draw on top of other apps. */ |
| 939 | public static final String OPSTR_SYSTEM_ALERT_WINDOW |
| 940 | = "android:system_alert_window"; |
| 941 | /** Required to write/modify/update system settingss. */ |
| 942 | public static final String OPSTR_WRITE_SETTINGS |
| 943 | = "android:write_settings"; |
Svetoslav | f3f02ac | 2015-09-08 14:36:35 -0700 | [diff] [blame] | 944 | /** @hide Get device accounts. */ |
Peter Visontay | 5a2a1ef | 2017-12-18 20:34:03 +0000 | [diff] [blame] | 945 | @SystemApi @TestApi |
Svetoslav | f3f02ac | 2015-09-08 14:36:35 -0700 | [diff] [blame] | 946 | public static final String OPSTR_GET_ACCOUNTS |
| 947 | = "android:get_accounts"; |
Chad Brubaker | 0c1651f | 2017-03-30 16:29:10 -0700 | [diff] [blame] | 948 | public static final String OPSTR_READ_PHONE_NUMBERS |
| 949 | = "android:read_phone_numbers"; |
Winson Chung | f4ac063 | 2017-03-17 12:34:12 -0700 | [diff] [blame] | 950 | /** Access to picture-in-picture. */ |
| 951 | public static final String OPSTR_PICTURE_IN_PICTURE |
| 952 | = "android:picture_in_picture"; |
Chad Brubaker | 97b383f | 2017-02-02 15:04:35 -0800 | [diff] [blame] | 953 | /** @hide */ |
Peter Visontay | 5a2a1ef | 2017-12-18 20:34:03 +0000 | [diff] [blame] | 954 | @SystemApi @TestApi |
Chad Brubaker | 97b383f | 2017-02-02 15:04:35 -0800 | [diff] [blame] | 955 | public static final String OPSTR_INSTANT_APP_START_FOREGROUND |
| 956 | = "android:instant_app_start_foreground"; |
Eugene Susla | cae3d3e | 2017-01-31 11:08:11 -0800 | [diff] [blame] | 957 | /** Answer incoming phone calls */ |
| 958 | public static final String OPSTR_ANSWER_PHONE_CALLS |
| 959 | = "android:answer_phone_calls"; |
Tyler Gunn | 79bc1ec | 2018-01-22 15:17:54 -0800 | [diff] [blame] | 960 | /** |
| 961 | * Accept call handover |
| 962 | * @hide |
| 963 | */ |
| 964 | @SystemApi @TestApi |
| 965 | public static final String OPSTR_ACCEPT_HANDOVER |
| 966 | = "android:accept_handover"; |
Peter Visontay | 5a2a1ef | 2017-12-18 20:34:03 +0000 | [diff] [blame] | 967 | /** @hide */ |
| 968 | @SystemApi @TestApi |
| 969 | public static final String OPSTR_GPS = "android:gps"; |
| 970 | /** @hide */ |
| 971 | @SystemApi @TestApi |
| 972 | public static final String OPSTR_VIBRATE = "android:vibrate"; |
| 973 | /** @hide */ |
| 974 | @SystemApi @TestApi |
| 975 | public static final String OPSTR_WIFI_SCAN = "android:wifi_scan"; |
| 976 | /** @hide */ |
| 977 | @SystemApi @TestApi |
| 978 | public static final String OPSTR_POST_NOTIFICATION = "android:post_notification"; |
| 979 | /** @hide */ |
| 980 | @SystemApi @TestApi |
| 981 | public static final String OPSTR_NEIGHBORING_CELLS = "android:neighboring_cells"; |
| 982 | /** @hide */ |
| 983 | @SystemApi @TestApi |
| 984 | public static final String OPSTR_WRITE_SMS = "android:write_sms"; |
| 985 | /** @hide */ |
| 986 | @SystemApi @TestApi |
| 987 | public static final String OPSTR_RECEIVE_EMERGENCY_BROADCAST = |
| 988 | "android:receive_emergency_broadcast"; |
| 989 | /** @hide */ |
| 990 | @SystemApi @TestApi |
| 991 | public static final String OPSTR_READ_ICC_SMS = "android:read_icc_sms"; |
| 992 | /** @hide */ |
| 993 | @SystemApi @TestApi |
| 994 | public static final String OPSTR_WRITE_ICC_SMS = "android:write_icc_sms"; |
| 995 | /** @hide */ |
| 996 | @SystemApi @TestApi |
| 997 | public static final String OPSTR_ACCESS_NOTIFICATIONS = "android:access_notifications"; |
| 998 | /** @hide */ |
| 999 | @SystemApi @TestApi |
| 1000 | public static final String OPSTR_PLAY_AUDIO = "android:play_audio"; |
| 1001 | /** @hide */ |
| 1002 | @SystemApi @TestApi |
| 1003 | public static final String OPSTR_READ_CLIPBOARD = "android:read_clipboard"; |
| 1004 | /** @hide */ |
| 1005 | @SystemApi @TestApi |
| 1006 | public static final String OPSTR_WRITE_CLIPBOARD = "android:write_clipboard"; |
| 1007 | /** @hide */ |
| 1008 | @SystemApi @TestApi |
| 1009 | public static final String OPSTR_TAKE_MEDIA_BUTTONS = "android:take_media_buttons"; |
| 1010 | /** @hide */ |
| 1011 | @SystemApi @TestApi |
| 1012 | public static final String OPSTR_TAKE_AUDIO_FOCUS = "android:take_audio_focus"; |
| 1013 | /** @hide */ |
| 1014 | @SystemApi @TestApi |
| 1015 | public static final String OPSTR_AUDIO_MASTER_VOLUME = "android:audio_master_volume"; |
| 1016 | /** @hide */ |
| 1017 | @SystemApi @TestApi |
| 1018 | public static final String OPSTR_AUDIO_VOICE_VOLUME = "android:audio_voice_volume"; |
| 1019 | /** @hide */ |
| 1020 | @SystemApi @TestApi |
| 1021 | public static final String OPSTR_AUDIO_RING_VOLUME = "android:audio_ring_volume"; |
| 1022 | /** @hide */ |
| 1023 | @SystemApi @TestApi |
| 1024 | public static final String OPSTR_AUDIO_MEDIA_VOLUME = "android:audio_media_volume"; |
| 1025 | /** @hide */ |
| 1026 | @SystemApi @TestApi |
| 1027 | public static final String OPSTR_AUDIO_ALARM_VOLUME = "android:audio_alarm_volume"; |
| 1028 | /** @hide */ |
| 1029 | @SystemApi @TestApi |
| 1030 | public static final String OPSTR_AUDIO_NOTIFICATION_VOLUME = |
| 1031 | "android:audio_notification_volume"; |
| 1032 | /** @hide */ |
| 1033 | @SystemApi @TestApi |
| 1034 | public static final String OPSTR_AUDIO_BLUETOOTH_VOLUME = "android:audio_bluetooth_volume"; |
| 1035 | /** @hide */ |
| 1036 | @SystemApi @TestApi |
| 1037 | public static final String OPSTR_WAKE_LOCK = "android:wake_lock"; |
| 1038 | /** @hide */ |
| 1039 | @SystemApi @TestApi |
| 1040 | public static final String OPSTR_MUTE_MICROPHONE = "android:mute_microphone"; |
| 1041 | /** @hide */ |
| 1042 | @SystemApi @TestApi |
| 1043 | public static final String OPSTR_TOAST_WINDOW = "android:toast_window"; |
| 1044 | /** @hide */ |
| 1045 | @SystemApi @TestApi |
| 1046 | public static final String OPSTR_PROJECT_MEDIA = "android:project_media"; |
| 1047 | /** @hide */ |
| 1048 | @SystemApi @TestApi |
| 1049 | public static final String OPSTR_WRITE_WALLPAPER = "android:write_wallpaper"; |
| 1050 | /** @hide */ |
| 1051 | @SystemApi @TestApi |
| 1052 | public static final String OPSTR_ASSIST_STRUCTURE = "android:assist_structure"; |
| 1053 | /** @hide */ |
| 1054 | @SystemApi @TestApi |
| 1055 | public static final String OPSTR_ASSIST_SCREENSHOT = "android:assist_screenshot"; |
| 1056 | /** @hide */ |
| 1057 | @SystemApi @TestApi |
| 1058 | public static final String OPSTR_TURN_SCREEN_ON = "android:turn_screen_on"; |
| 1059 | /** @hide */ |
| 1060 | @SystemApi @TestApi |
| 1061 | public static final String OPSTR_RUN_IN_BACKGROUND = "android:run_in_background"; |
| 1062 | /** @hide */ |
| 1063 | @SystemApi @TestApi |
| 1064 | public static final String OPSTR_AUDIO_ACCESSIBILITY_VOLUME = |
| 1065 | "android:audio_accessibility_volume"; |
| 1066 | /** @hide */ |
| 1067 | @SystemApi @TestApi |
| 1068 | public static final String OPSTR_REQUEST_INSTALL_PACKAGES = "android:request_install_packages"; |
| 1069 | /** @hide */ |
| 1070 | @SystemApi @TestApi |
| 1071 | public static final String OPSTR_RUN_ANY_IN_BACKGROUND = "android:run_any_in_background"; |
| 1072 | /** @hide */ |
| 1073 | @SystemApi @TestApi |
Peter Visontay | a382a8e | 2018-03-16 16:06:57 +0000 | [diff] [blame] | 1074 | public static final String OPSTR_CHANGE_WIFI_STATE = "android:change_wifi_state"; |
Peter Visontay | 5a2a1ef | 2017-12-18 20:34:03 +0000 | [diff] [blame] | 1075 | /** @hide */ |
| 1076 | @SystemApi @TestApi |
Peter Visontay | a382a8e | 2018-03-16 16:06:57 +0000 | [diff] [blame] | 1077 | public static final String OPSTR_REQUEST_DELETE_PACKAGES = "android:request_delete_packages"; |
Peter Visontay | 5a2a1ef | 2017-12-18 20:34:03 +0000 | [diff] [blame] | 1078 | /** @hide */ |
| 1079 | @SystemApi @TestApi |
Peter Visontay | a382a8e | 2018-03-16 16:06:57 +0000 | [diff] [blame] | 1080 | public static final String OPSTR_BIND_ACCESSIBILITY_SERVICE = |
| 1081 | "android:bind_accessibility_service"; |
Nathan Harold | 1bb42067 | 2018-03-14 17:08:53 -0700 | [diff] [blame] | 1082 | /** @hide */ |
| 1083 | @SystemApi @TestApi |
| 1084 | public static final String OPSTR_MANAGE_IPSEC_TUNNELS = "android:manage_ipsec_tunnels"; |
Dianne Hackborn | e9d9b4b | 2018-03-28 13:51:46 -0700 | [diff] [blame] | 1085 | /** @hide */ |
| 1086 | @SystemApi @TestApi |
| 1087 | public static final String OPSTR_START_FOREGROUND = "android:start_foreground"; |
Dianne Hackborn | e04f13d | 2018-05-02 12:51:52 -0700 | [diff] [blame] | 1088 | /** @hide */ |
| 1089 | public static final String OPSTR_BLUETOOTH_SCAN = "android:bluetooth_scan"; |
Peter Visontay | 5a2a1ef | 2017-12-18 20:34:03 +0000 | [diff] [blame] | 1090 | |
Kevin Chyn | b3c05aa | 2018-09-21 16:50:32 -0700 | [diff] [blame] | 1091 | /** @hide Use the BiometricPrompt/BiometricManager APIs. */ |
| 1092 | public static final String OPSTR_USE_BIOMETRIC = "android:use_biometric"; |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 1093 | |
Zimuzo | 6cbf9cc | 2018-10-05 12:05:58 +0100 | [diff] [blame] | 1094 | /** @hide Recognize physical activity. */ |
| 1095 | public static final String OPSTR_ACTIVITY_RECOGNITION = "android:activity_recognition"; |
| 1096 | |
Hongming Jin | 228cd01 | 2018-11-09 14:47:50 -0800 | [diff] [blame] | 1097 | /** @hide Financial app read sms. */ |
| 1098 | public static final String OPSTR_SMS_FINANCIAL_TRANSACTIONS = |
| 1099 | "android:sms_financial_transactions"; |
| 1100 | |
Jeff Sharkey | d2a1f0d | 2018-11-19 10:32:52 -0700 | [diff] [blame] | 1101 | /** @hide Read media of audio type. */ |
| 1102 | public static final String OPSTR_READ_MEDIA_AUDIO = "android:read_media_audio"; |
| 1103 | /** @hide Write media of audio type. */ |
| 1104 | public static final String OPSTR_WRITE_MEDIA_AUDIO = "android:write_media_audio"; |
| 1105 | /** @hide Read media of video type. */ |
| 1106 | public static final String OPSTR_READ_MEDIA_VIDEO = "android:read_media_video"; |
| 1107 | /** @hide Write media of video type. */ |
| 1108 | public static final String OPSTR_WRITE_MEDIA_VIDEO = "android:write_media_video"; |
| 1109 | /** @hide Read media of image type. */ |
| 1110 | public static final String OPSTR_READ_MEDIA_IMAGES = "android:read_media_images"; |
| 1111 | /** @hide Write media of image type. */ |
| 1112 | public static final String OPSTR_WRITE_MEDIA_IMAGES = "android:write_media_images"; |
Jeff Sharkey | e82cbb1 | 2018-12-06 15:53:11 -0700 | [diff] [blame] | 1113 | /** @hide Has a legacy (non-isolated) view of storage. */ |
Philip P. Moltmann | c94ba82 | 2019-03-04 16:48:22 -0800 | [diff] [blame] | 1114 | @TestApi |
| 1115 | @SystemApi |
Jeff Sharkey | e82cbb1 | 2018-12-06 15:53:11 -0700 | [diff] [blame] | 1116 | public static final String OPSTR_LEGACY_STORAGE = "android:legacy_storage"; |
Philip P. Moltmann | ac7b10c | 2019-09-13 15:12:34 -0700 | [diff] [blame] | 1117 | /** @hide Read location metadata from media */ |
| 1118 | public static final String OPSTR_ACCESS_MEDIA_LOCATION = "android:access_media_location"; |
| 1119 | |
Jackal Guo | 8dc791e | 2019-01-14 10:26:42 +0800 | [diff] [blame] | 1120 | /** @hide Interact with accessibility. */ |
Joel Galenson | ff4fe20 | 2019-02-06 14:43:58 -0800 | [diff] [blame] | 1121 | @SystemApi |
Jackal Guo | 8dc791e | 2019-01-14 10:26:42 +0800 | [diff] [blame] | 1122 | public static final String OPSTR_ACCESS_ACCESSIBILITY = "android:access_accessibility"; |
Michael Groover | 656ef91 | 2019-04-09 17:09:57 -0700 | [diff] [blame] | 1123 | /** @hide Read device identifiers */ |
| 1124 | public static final String OPSTR_READ_DEVICE_IDENTIFIERS = "android:read_device_identifiers"; |
Jeff Sharkey | d2a1f0d | 2018-11-19 10:32:52 -0700 | [diff] [blame] | 1125 | |
Philip P. Moltmann | e56c08e | 2017-03-15 12:46:04 -0700 | [diff] [blame] | 1126 | // Warning: If an permission is added here it also has to be added to |
| 1127 | // com.android.packageinstaller.permission.utils.EventLogger |
Svet Ganov | da0acdf | 2017-02-15 10:28:51 -0800 | [diff] [blame] | 1128 | private static final int[] RUNTIME_AND_APPOP_PERMISSIONS_OPS = { |
| 1129 | // RUNTIME PERMISSIONS |
Svetoslav Ganov | eaca4c5 | 2016-05-05 18:08:00 -0700 | [diff] [blame] | 1130 | // Contacts |
| 1131 | OP_READ_CONTACTS, |
| 1132 | OP_WRITE_CONTACTS, |
| 1133 | OP_GET_ACCOUNTS, |
| 1134 | // Calendar |
| 1135 | OP_READ_CALENDAR, |
| 1136 | OP_WRITE_CALENDAR, |
| 1137 | // SMS |
| 1138 | OP_SEND_SMS, |
| 1139 | OP_RECEIVE_SMS, |
| 1140 | OP_READ_SMS, |
| 1141 | OP_RECEIVE_WAP_PUSH, |
| 1142 | OP_RECEIVE_MMS, |
| 1143 | OP_READ_CELL_BROADCASTS, |
| 1144 | // Storage |
| 1145 | OP_READ_EXTERNAL_STORAGE, |
| 1146 | OP_WRITE_EXTERNAL_STORAGE, |
Philip P. Moltmann | ac7b10c | 2019-09-13 15:12:34 -0700 | [diff] [blame] | 1147 | OP_ACCESS_MEDIA_LOCATION, |
Svetoslav Ganov | eaca4c5 | 2016-05-05 18:08:00 -0700 | [diff] [blame] | 1148 | // Location |
| 1149 | OP_COARSE_LOCATION, |
| 1150 | OP_FINE_LOCATION, |
| 1151 | // Phone |
| 1152 | OP_READ_PHONE_STATE, |
Chad Brubaker | 0c1651f | 2017-03-30 16:29:10 -0700 | [diff] [blame] | 1153 | OP_READ_PHONE_NUMBERS, |
Svetoslav Ganov | eaca4c5 | 2016-05-05 18:08:00 -0700 | [diff] [blame] | 1154 | OP_CALL_PHONE, |
| 1155 | OP_READ_CALL_LOG, |
| 1156 | OP_WRITE_CALL_LOG, |
| 1157 | OP_ADD_VOICEMAIL, |
| 1158 | OP_USE_SIP, |
| 1159 | OP_PROCESS_OUTGOING_CALLS, |
Eugene Susla | cae3d3e | 2017-01-31 11:08:11 -0800 | [diff] [blame] | 1160 | OP_ANSWER_PHONE_CALLS, |
Tyler Gunn | 79bc1ec | 2018-01-22 15:17:54 -0800 | [diff] [blame] | 1161 | OP_ACCEPT_HANDOVER, |
Svetoslav Ganov | eaca4c5 | 2016-05-05 18:08:00 -0700 | [diff] [blame] | 1162 | // Microphone |
| 1163 | OP_RECORD_AUDIO, |
| 1164 | // Camera |
| 1165 | OP_CAMERA, |
| 1166 | // Body sensors |
Svet Ganov | da0acdf | 2017-02-15 10:28:51 -0800 | [diff] [blame] | 1167 | OP_BODY_SENSORS, |
Zimuzo | 6cbf9cc | 2018-10-05 12:05:58 +0100 | [diff] [blame] | 1168 | // Activity recognition |
| 1169 | OP_ACTIVITY_RECOGNITION, |
Jeff Sharkey | d2a1f0d | 2018-11-19 10:32:52 -0700 | [diff] [blame] | 1170 | // Aural |
| 1171 | OP_READ_MEDIA_AUDIO, |
| 1172 | OP_WRITE_MEDIA_AUDIO, |
| 1173 | // Visual |
| 1174 | OP_READ_MEDIA_VIDEO, |
| 1175 | OP_WRITE_MEDIA_VIDEO, |
| 1176 | OP_READ_MEDIA_IMAGES, |
| 1177 | OP_WRITE_MEDIA_IMAGES, |
Svet Ganov | da0acdf | 2017-02-15 10:28:51 -0800 | [diff] [blame] | 1178 | |
| 1179 | // APPOP PERMISSIONS |
| 1180 | OP_ACCESS_NOTIFICATIONS, |
| 1181 | OP_SYSTEM_ALERT_WINDOW, |
| 1182 | OP_WRITE_SETTINGS, |
| 1183 | OP_REQUEST_INSTALL_PACKAGES, |
Dianne Hackborn | e9d9b4b | 2018-03-28 13:51:46 -0700 | [diff] [blame] | 1184 | OP_START_FOREGROUND, |
Hongming Jin | 228cd01 | 2018-11-09 14:47:50 -0800 | [diff] [blame] | 1185 | OP_SMS_FINANCIAL_TRANSACTIONS, |
Svetoslav Ganov | eaca4c5 | 2016-05-05 18:08:00 -0700 | [diff] [blame] | 1186 | }; |
| 1187 | |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 1188 | /** |
| 1189 | * This maps each operation to the operation that serves as the |
| 1190 | * switch to determine whether it is allowed. Generally this is |
| 1191 | * a 1:1 mapping, but for some things (like location) that have |
| 1192 | * multiple low-level operations being tracked that should be |
David Christie | 0b83745 | 2013-07-29 16:02:13 -0700 | [diff] [blame] | 1193 | * 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] | 1194 | * make them all controlled by the same single operation. |
| 1195 | */ |
| 1196 | private static int[] sOpToSwitch = new int[] { |
Dianne Hackborn | c216a26 | 2018-04-26 13:46:22 -0700 | [diff] [blame] | 1197 | OP_COARSE_LOCATION, // COARSE_LOCATION |
| 1198 | OP_COARSE_LOCATION, // FINE_LOCATION |
| 1199 | OP_COARSE_LOCATION, // GPS |
| 1200 | OP_VIBRATE, // VIBRATE |
| 1201 | OP_READ_CONTACTS, // READ_CONTACTS |
| 1202 | OP_WRITE_CONTACTS, // WRITE_CONTACTS |
| 1203 | OP_READ_CALL_LOG, // READ_CALL_LOG |
| 1204 | OP_WRITE_CALL_LOG, // WRITE_CALL_LOG |
| 1205 | OP_READ_CALENDAR, // READ_CALENDAR |
| 1206 | OP_WRITE_CALENDAR, // WRITE_CALENDAR |
| 1207 | OP_COARSE_LOCATION, // WIFI_SCAN |
| 1208 | OP_POST_NOTIFICATION, // POST_NOTIFICATION |
| 1209 | OP_COARSE_LOCATION, // NEIGHBORING_CELLS |
| 1210 | OP_CALL_PHONE, // CALL_PHONE |
| 1211 | OP_READ_SMS, // READ_SMS |
| 1212 | OP_WRITE_SMS, // WRITE_SMS |
| 1213 | OP_RECEIVE_SMS, // RECEIVE_SMS |
| 1214 | OP_RECEIVE_SMS, // RECEIVE_EMERGECY_SMS |
| 1215 | OP_RECEIVE_MMS, // RECEIVE_MMS |
| 1216 | OP_RECEIVE_WAP_PUSH, // RECEIVE_WAP_PUSH |
| 1217 | OP_SEND_SMS, // SEND_SMS |
| 1218 | OP_READ_SMS, // READ_ICC_SMS |
| 1219 | OP_WRITE_SMS, // WRITE_ICC_SMS |
| 1220 | OP_WRITE_SETTINGS, // WRITE_SETTINGS |
| 1221 | OP_SYSTEM_ALERT_WINDOW, // SYSTEM_ALERT_WINDOW |
| 1222 | OP_ACCESS_NOTIFICATIONS, // ACCESS_NOTIFICATIONS |
| 1223 | OP_CAMERA, // CAMERA |
| 1224 | OP_RECORD_AUDIO, // RECORD_AUDIO |
| 1225 | OP_PLAY_AUDIO, // PLAY_AUDIO |
| 1226 | OP_READ_CLIPBOARD, // READ_CLIPBOARD |
| 1227 | OP_WRITE_CLIPBOARD, // WRITE_CLIPBOARD |
| 1228 | OP_TAKE_MEDIA_BUTTONS, // TAKE_MEDIA_BUTTONS |
| 1229 | OP_TAKE_AUDIO_FOCUS, // TAKE_AUDIO_FOCUS |
| 1230 | OP_AUDIO_MASTER_VOLUME, // AUDIO_MASTER_VOLUME |
| 1231 | OP_AUDIO_VOICE_VOLUME, // AUDIO_VOICE_VOLUME |
| 1232 | OP_AUDIO_RING_VOLUME, // AUDIO_RING_VOLUME |
| 1233 | OP_AUDIO_MEDIA_VOLUME, // AUDIO_MEDIA_VOLUME |
| 1234 | OP_AUDIO_ALARM_VOLUME, // AUDIO_ALARM_VOLUME |
| 1235 | OP_AUDIO_NOTIFICATION_VOLUME, // AUDIO_NOTIFICATION_VOLUME |
| 1236 | OP_AUDIO_BLUETOOTH_VOLUME, // AUDIO_BLUETOOTH_VOLUME |
| 1237 | OP_WAKE_LOCK, // WAKE_LOCK |
| 1238 | OP_COARSE_LOCATION, // MONITOR_LOCATION |
| 1239 | OP_COARSE_LOCATION, // MONITOR_HIGH_POWER_LOCATION |
| 1240 | OP_GET_USAGE_STATS, // GET_USAGE_STATS |
| 1241 | OP_MUTE_MICROPHONE, // MUTE_MICROPHONE |
| 1242 | OP_TOAST_WINDOW, // TOAST_WINDOW |
| 1243 | OP_PROJECT_MEDIA, // PROJECT_MEDIA |
| 1244 | OP_ACTIVATE_VPN, // ACTIVATE_VPN |
| 1245 | OP_WRITE_WALLPAPER, // WRITE_WALLPAPER |
| 1246 | OP_ASSIST_STRUCTURE, // ASSIST_STRUCTURE |
| 1247 | OP_ASSIST_SCREENSHOT, // ASSIST_SCREENSHOT |
| 1248 | OP_READ_PHONE_STATE, // READ_PHONE_STATE |
| 1249 | OP_ADD_VOICEMAIL, // ADD_VOICEMAIL |
| 1250 | OP_USE_SIP, // USE_SIP |
| 1251 | OP_PROCESS_OUTGOING_CALLS, // PROCESS_OUTGOING_CALLS |
| 1252 | OP_USE_FINGERPRINT, // USE_FINGERPRINT |
| 1253 | OP_BODY_SENSORS, // BODY_SENSORS |
| 1254 | OP_READ_CELL_BROADCASTS, // READ_CELL_BROADCASTS |
| 1255 | OP_MOCK_LOCATION, // MOCK_LOCATION |
| 1256 | OP_READ_EXTERNAL_STORAGE, // READ_EXTERNAL_STORAGE |
| 1257 | OP_WRITE_EXTERNAL_STORAGE, // WRITE_EXTERNAL_STORAGE |
| 1258 | OP_TURN_SCREEN_ON, // TURN_SCREEN_ON |
| 1259 | OP_GET_ACCOUNTS, // GET_ACCOUNTS |
| 1260 | OP_RUN_IN_BACKGROUND, // RUN_IN_BACKGROUND |
| 1261 | OP_AUDIO_ACCESSIBILITY_VOLUME, // AUDIO_ACCESSIBILITY_VOLUME |
| 1262 | OP_READ_PHONE_NUMBERS, // READ_PHONE_NUMBERS |
| 1263 | OP_REQUEST_INSTALL_PACKAGES, // REQUEST_INSTALL_PACKAGES |
| 1264 | OP_PICTURE_IN_PICTURE, // ENTER_PICTURE_IN_PICTURE_ON_HIDE |
| 1265 | OP_INSTANT_APP_START_FOREGROUND, // INSTANT_APP_START_FOREGROUND |
| 1266 | OP_ANSWER_PHONE_CALLS, // ANSWER_PHONE_CALLS |
| 1267 | OP_RUN_ANY_IN_BACKGROUND, // OP_RUN_ANY_IN_BACKGROUND |
| 1268 | OP_CHANGE_WIFI_STATE, // OP_CHANGE_WIFI_STATE |
| 1269 | OP_REQUEST_DELETE_PACKAGES, // OP_REQUEST_DELETE_PACKAGES |
| 1270 | OP_BIND_ACCESSIBILITY_SERVICE, // OP_BIND_ACCESSIBILITY_SERVICE |
| 1271 | OP_ACCEPT_HANDOVER, // ACCEPT_HANDOVER |
| 1272 | OP_MANAGE_IPSEC_TUNNELS, // MANAGE_IPSEC_HANDOVERS |
| 1273 | OP_START_FOREGROUND, // START_FOREGROUND |
Dianne Hackborn | e04f13d | 2018-05-02 12:51:52 -0700 | [diff] [blame] | 1274 | OP_COARSE_LOCATION, // BLUETOOTH_SCAN |
Kevin Chyn | b3c05aa | 2018-09-21 16:50:32 -0700 | [diff] [blame] | 1275 | OP_USE_BIOMETRIC, // BIOMETRIC |
Zimuzo | 6cbf9cc | 2018-10-05 12:05:58 +0100 | [diff] [blame] | 1276 | OP_ACTIVITY_RECOGNITION, // ACTIVITY_RECOGNITION |
Hongming Jin | 228cd01 | 2018-11-09 14:47:50 -0800 | [diff] [blame] | 1277 | OP_SMS_FINANCIAL_TRANSACTIONS, // SMS_FINANCIAL_TRANSACTIONS |
Jeff Sharkey | d2a1f0d | 2018-11-19 10:32:52 -0700 | [diff] [blame] | 1278 | OP_READ_MEDIA_AUDIO, // READ_MEDIA_AUDIO |
| 1279 | OP_WRITE_MEDIA_AUDIO, // WRITE_MEDIA_AUDIO |
| 1280 | OP_READ_MEDIA_VIDEO, // READ_MEDIA_VIDEO |
| 1281 | OP_WRITE_MEDIA_VIDEO, // WRITE_MEDIA_VIDEO |
| 1282 | OP_READ_MEDIA_IMAGES, // READ_MEDIA_IMAGES |
| 1283 | OP_WRITE_MEDIA_IMAGES, // WRITE_MEDIA_IMAGES |
Jeff Sharkey | e82cbb1 | 2018-12-06 15:53:11 -0700 | [diff] [blame] | 1284 | OP_LEGACY_STORAGE, // LEGACY_STORAGE |
Jackal Guo | 8dc791e | 2019-01-14 10:26:42 +0800 | [diff] [blame] | 1285 | OP_ACCESS_ACCESSIBILITY, // ACCESS_ACCESSIBILITY |
Michael Groover | 656ef91 | 2019-04-09 17:09:57 -0700 | [diff] [blame] | 1286 | OP_READ_DEVICE_IDENTIFIERS, // READ_DEVICE_IDENTIFIERS |
Philip P. Moltmann | ac7b10c | 2019-09-13 15:12:34 -0700 | [diff] [blame] | 1287 | OP_ACCESS_MEDIA_LOCATION, // ACCESS_MEDIA_LOCATION |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 1288 | }; |
| 1289 | |
| 1290 | /** |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 1291 | * This maps each operation to the public string constant for it. |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 1292 | */ |
Peter Visontay | 5a2a1ef | 2017-12-18 20:34:03 +0000 | [diff] [blame] | 1293 | private static String[] sOpToString = new String[]{ |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 1294 | OPSTR_COARSE_LOCATION, |
| 1295 | OPSTR_FINE_LOCATION, |
Peter Visontay | 5a2a1ef | 2017-12-18 20:34:03 +0000 | [diff] [blame] | 1296 | OPSTR_GPS, |
| 1297 | OPSTR_VIBRATE, |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 1298 | OPSTR_READ_CONTACTS, |
| 1299 | OPSTR_WRITE_CONTACTS, |
| 1300 | OPSTR_READ_CALL_LOG, |
| 1301 | OPSTR_WRITE_CALL_LOG, |
| 1302 | OPSTR_READ_CALENDAR, |
| 1303 | OPSTR_WRITE_CALENDAR, |
Peter Visontay | 5a2a1ef | 2017-12-18 20:34:03 +0000 | [diff] [blame] | 1304 | OPSTR_WIFI_SCAN, |
| 1305 | OPSTR_POST_NOTIFICATION, |
| 1306 | OPSTR_NEIGHBORING_CELLS, |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 1307 | OPSTR_CALL_PHONE, |
| 1308 | OPSTR_READ_SMS, |
Peter Visontay | 5a2a1ef | 2017-12-18 20:34:03 +0000 | [diff] [blame] | 1309 | OPSTR_WRITE_SMS, |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 1310 | OPSTR_RECEIVE_SMS, |
Peter Visontay | 5a2a1ef | 2017-12-18 20:34:03 +0000 | [diff] [blame] | 1311 | OPSTR_RECEIVE_EMERGENCY_BROADCAST, |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 1312 | OPSTR_RECEIVE_MMS, |
| 1313 | OPSTR_RECEIVE_WAP_PUSH, |
| 1314 | OPSTR_SEND_SMS, |
Peter Visontay | 5a2a1ef | 2017-12-18 20:34:03 +0000 | [diff] [blame] | 1315 | OPSTR_READ_ICC_SMS, |
| 1316 | OPSTR_WRITE_ICC_SMS, |
Billy Lau | 24b9c83 | 2015-07-20 17:34:09 +0100 | [diff] [blame] | 1317 | OPSTR_WRITE_SETTINGS, |
| 1318 | OPSTR_SYSTEM_ALERT_WINDOW, |
Peter Visontay | 5a2a1ef | 2017-12-18 20:34:03 +0000 | [diff] [blame] | 1319 | OPSTR_ACCESS_NOTIFICATIONS, |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 1320 | OPSTR_CAMERA, |
| 1321 | OPSTR_RECORD_AUDIO, |
Peter Visontay | 5a2a1ef | 2017-12-18 20:34:03 +0000 | [diff] [blame] | 1322 | OPSTR_PLAY_AUDIO, |
| 1323 | OPSTR_READ_CLIPBOARD, |
| 1324 | OPSTR_WRITE_CLIPBOARD, |
| 1325 | OPSTR_TAKE_MEDIA_BUTTONS, |
| 1326 | OPSTR_TAKE_AUDIO_FOCUS, |
| 1327 | OPSTR_AUDIO_MASTER_VOLUME, |
| 1328 | OPSTR_AUDIO_VOICE_VOLUME, |
| 1329 | OPSTR_AUDIO_RING_VOLUME, |
| 1330 | OPSTR_AUDIO_MEDIA_VOLUME, |
| 1331 | OPSTR_AUDIO_ALARM_VOLUME, |
| 1332 | OPSTR_AUDIO_NOTIFICATION_VOLUME, |
| 1333 | OPSTR_AUDIO_BLUETOOTH_VOLUME, |
| 1334 | OPSTR_WAKE_LOCK, |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 1335 | OPSTR_MONITOR_LOCATION, |
| 1336 | OPSTR_MONITOR_HIGH_POWER_LOCATION, |
Dianne Hackborn | 5064e7c | 2014-09-02 10:57:16 -0700 | [diff] [blame] | 1337 | OPSTR_GET_USAGE_STATS, |
Peter Visontay | 5a2a1ef | 2017-12-18 20:34:03 +0000 | [diff] [blame] | 1338 | OPSTR_MUTE_MICROPHONE, |
| 1339 | OPSTR_TOAST_WINDOW, |
| 1340 | OPSTR_PROJECT_MEDIA, |
Jeff Davidson | 0554260 | 2014-08-11 14:07:27 -0700 | [diff] [blame] | 1341 | OPSTR_ACTIVATE_VPN, |
Peter Visontay | 5a2a1ef | 2017-12-18 20:34:03 +0000 | [diff] [blame] | 1342 | OPSTR_WRITE_WALLPAPER, |
| 1343 | OPSTR_ASSIST_STRUCTURE, |
| 1344 | OPSTR_ASSIST_SCREENSHOT, |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 1345 | OPSTR_READ_PHONE_STATE, |
| 1346 | OPSTR_ADD_VOICEMAIL, |
| 1347 | OPSTR_USE_SIP, |
Svet Ganov | 824ad6e | 2016-09-22 19:36:53 -0700 | [diff] [blame] | 1348 | OPSTR_PROCESS_OUTGOING_CALLS, |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 1349 | OPSTR_USE_FINGERPRINT, |
Svet Ganov | ede4316 | 2015-05-02 17:42:44 -0700 | [diff] [blame] | 1350 | OPSTR_BODY_SENSORS, |
Svet Ganov | f7e9cf4 | 2015-05-13 10:40:31 -0700 | [diff] [blame] | 1351 | OPSTR_READ_CELL_BROADCASTS, |
Svet Ganov | 921c7df | 2015-06-29 21:51:41 -0700 | [diff] [blame] | 1352 | OPSTR_MOCK_LOCATION, |
| 1353 | OPSTR_READ_EXTERNAL_STORAGE, |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 1354 | OPSTR_WRITE_EXTERNAL_STORAGE, |
Peter Visontay | 5a2a1ef | 2017-12-18 20:34:03 +0000 | [diff] [blame] | 1355 | OPSTR_TURN_SCREEN_ON, |
Dianne Hackborn | bef28fe | 2015-10-29 17:57:11 -0700 | [diff] [blame] | 1356 | OPSTR_GET_ACCOUNTS, |
Peter Visontay | 5a2a1ef | 2017-12-18 20:34:03 +0000 | [diff] [blame] | 1357 | OPSTR_RUN_IN_BACKGROUND, |
| 1358 | OPSTR_AUDIO_ACCESSIBILITY_VOLUME, |
Chad Brubaker | 0c1651f | 2017-03-30 16:29:10 -0700 | [diff] [blame] | 1359 | OPSTR_READ_PHONE_NUMBERS, |
Peter Visontay | 5a2a1ef | 2017-12-18 20:34:03 +0000 | [diff] [blame] | 1360 | OPSTR_REQUEST_INSTALL_PACKAGES, |
Winson Chung | f4ac063 | 2017-03-17 12:34:12 -0700 | [diff] [blame] | 1361 | OPSTR_PICTURE_IN_PICTURE, |
Chad Brubaker | 97b383f | 2017-02-02 15:04:35 -0800 | [diff] [blame] | 1362 | OPSTR_INSTANT_APP_START_FOREGROUND, |
Eugene Susla | cae3d3e | 2017-01-31 11:08:11 -0800 | [diff] [blame] | 1363 | OPSTR_ANSWER_PHONE_CALLS, |
Peter Visontay | 5a2a1ef | 2017-12-18 20:34:03 +0000 | [diff] [blame] | 1364 | OPSTR_RUN_ANY_IN_BACKGROUND, |
| 1365 | OPSTR_CHANGE_WIFI_STATE, |
| 1366 | OPSTR_REQUEST_DELETE_PACKAGES, |
| 1367 | OPSTR_BIND_ACCESSIBILITY_SERVICE, |
Tyler Gunn | 79bc1ec | 2018-01-22 15:17:54 -0800 | [diff] [blame] | 1368 | OPSTR_ACCEPT_HANDOVER, |
Nathan Harold | 1bb42067 | 2018-03-14 17:08:53 -0700 | [diff] [blame] | 1369 | OPSTR_MANAGE_IPSEC_TUNNELS, |
Dianne Hackborn | e9d9b4b | 2018-03-28 13:51:46 -0700 | [diff] [blame] | 1370 | OPSTR_START_FOREGROUND, |
Dianne Hackborn | e04f13d | 2018-05-02 12:51:52 -0700 | [diff] [blame] | 1371 | OPSTR_BLUETOOTH_SCAN, |
Kevin Chyn | b3c05aa | 2018-09-21 16:50:32 -0700 | [diff] [blame] | 1372 | OPSTR_USE_BIOMETRIC, |
Zimuzo | 6cbf9cc | 2018-10-05 12:05:58 +0100 | [diff] [blame] | 1373 | OPSTR_ACTIVITY_RECOGNITION, |
Hongming Jin | 228cd01 | 2018-11-09 14:47:50 -0800 | [diff] [blame] | 1374 | OPSTR_SMS_FINANCIAL_TRANSACTIONS, |
Jeff Sharkey | d2a1f0d | 2018-11-19 10:32:52 -0700 | [diff] [blame] | 1375 | OPSTR_READ_MEDIA_AUDIO, |
| 1376 | OPSTR_WRITE_MEDIA_AUDIO, |
| 1377 | OPSTR_READ_MEDIA_VIDEO, |
| 1378 | OPSTR_WRITE_MEDIA_VIDEO, |
| 1379 | OPSTR_READ_MEDIA_IMAGES, |
| 1380 | OPSTR_WRITE_MEDIA_IMAGES, |
Jeff Sharkey | e82cbb1 | 2018-12-06 15:53:11 -0700 | [diff] [blame] | 1381 | OPSTR_LEGACY_STORAGE, |
Jackal Guo | 8dc791e | 2019-01-14 10:26:42 +0800 | [diff] [blame] | 1382 | OPSTR_ACCESS_ACCESSIBILITY, |
Michael Groover | 656ef91 | 2019-04-09 17:09:57 -0700 | [diff] [blame] | 1383 | OPSTR_READ_DEVICE_IDENTIFIERS, |
Philip P. Moltmann | ac7b10c | 2019-09-13 15:12:34 -0700 | [diff] [blame] | 1384 | OPSTR_ACCESS_MEDIA_LOCATION, |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 1385 | }; |
| 1386 | |
| 1387 | /** |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 1388 | * This provides a simple name for each operation to be used |
| 1389 | * in debug output. |
| 1390 | */ |
Dianne Hackborn | 5e45ee6 | 2013-01-24 19:13:44 -0800 | [diff] [blame] | 1391 | private static String[] sOpNames = new String[] { |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 1392 | "COARSE_LOCATION", |
| 1393 | "FINE_LOCATION", |
| 1394 | "GPS", |
| 1395 | "VIBRATE", |
| 1396 | "READ_CONTACTS", |
| 1397 | "WRITE_CONTACTS", |
| 1398 | "READ_CALL_LOG", |
| 1399 | "WRITE_CALL_LOG", |
| 1400 | "READ_CALENDAR", |
| 1401 | "WRITE_CALENDAR", |
| 1402 | "WIFI_SCAN", |
| 1403 | "POST_NOTIFICATION", |
| 1404 | "NEIGHBORING_CELLS", |
| 1405 | "CALL_PHONE", |
Dianne Hackborn | f51f612 | 2013-02-04 18:23:34 -0800 | [diff] [blame] | 1406 | "READ_SMS", |
| 1407 | "WRITE_SMS", |
| 1408 | "RECEIVE_SMS", |
| 1409 | "RECEIVE_EMERGECY_SMS", |
| 1410 | "RECEIVE_MMS", |
| 1411 | "RECEIVE_WAP_PUSH", |
| 1412 | "SEND_SMS", |
| 1413 | "READ_ICC_SMS", |
| 1414 | "WRITE_ICC_SMS", |
Dianne Hackborn | 961321f | 2013-02-05 17:22:41 -0800 | [diff] [blame] | 1415 | "WRITE_SETTINGS", |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 1416 | "SYSTEM_ALERT_WINDOW", |
Daniel Sandler | fde19b1 | 2013-01-17 00:21:05 -0500 | [diff] [blame] | 1417 | "ACCESS_NOTIFICATIONS", |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 1418 | "CAMERA", |
| 1419 | "RECORD_AUDIO", |
| 1420 | "PLAY_AUDIO", |
Dianne Hackborn | efcc1a2 | 2013-02-25 18:02:35 -0800 | [diff] [blame] | 1421 | "READ_CLIPBOARD", |
| 1422 | "WRITE_CLIPBOARD", |
Dianne Hackborn | ba50b97c | 2013-04-30 15:04:46 -0700 | [diff] [blame] | 1423 | "TAKE_MEDIA_BUTTONS", |
| 1424 | "TAKE_AUDIO_FOCUS", |
| 1425 | "AUDIO_MASTER_VOLUME", |
| 1426 | "AUDIO_VOICE_VOLUME", |
| 1427 | "AUDIO_RING_VOLUME", |
| 1428 | "AUDIO_MEDIA_VOLUME", |
| 1429 | "AUDIO_ALARM_VOLUME", |
| 1430 | "AUDIO_NOTIFICATION_VOLUME", |
| 1431 | "AUDIO_BLUETOOTH_VOLUME", |
Dianne Hackborn | 713df15 | 2013-05-17 11:27:57 -0700 | [diff] [blame] | 1432 | "WAKE_LOCK", |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 1433 | "MONITOR_LOCATION", |
David Christie | 0b83745 | 2013-07-29 16:02:13 -0700 | [diff] [blame] | 1434 | "MONITOR_HIGH_POWER_LOCATION", |
Emily Bernier | 22c921a | 2014-05-28 11:01:32 -0400 | [diff] [blame] | 1435 | "GET_USAGE_STATS", |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 1436 | "MUTE_MICROPHONE", |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 1437 | "TOAST_WINDOW", |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 1438 | "PROJECT_MEDIA", |
Jeff Davidson | 0554260 | 2014-08-11 14:07:27 -0700 | [diff] [blame] | 1439 | "ACTIVATE_VPN", |
Benjamin Franz | f3ece36 | 2015-02-11 10:51:10 +0000 | [diff] [blame] | 1440 | "WRITE_WALLPAPER", |
Dianne Hackborn | d59a5d5 | 2015-04-04 14:52:14 -0700 | [diff] [blame] | 1441 | "ASSIST_STRUCTURE", |
Svet Ganov | 16a1689 | 2015-04-16 10:32:04 -0700 | [diff] [blame] | 1442 | "ASSIST_SCREENSHOT", |
Eugene Susla | e4ee2c2 | 2018-11-05 12:23:30 -0800 | [diff] [blame] | 1443 | "READ_PHONE_STATE", |
Svetoslav | 5335b67 | 2015-04-29 12:00:51 -0700 | [diff] [blame] | 1444 | "ADD_VOICEMAIL", |
Svetoslav | c656e6f | 2015-04-29 14:08:16 -0700 | [diff] [blame] | 1445 | "USE_SIP", |
Svetoslav | 4af76a5 | 2015-04-29 15:29:46 -0700 | [diff] [blame] | 1446 | "PROCESS_OUTGOING_CALLS", |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 1447 | "USE_FINGERPRINT", |
Svet Ganov | ede4316 | 2015-05-02 17:42:44 -0700 | [diff] [blame] | 1448 | "BODY_SENSORS", |
Svet Ganov | f7e9cf4 | 2015-05-13 10:40:31 -0700 | [diff] [blame] | 1449 | "READ_CELL_BROADCASTS", |
Svet Ganov | 921c7df | 2015-06-29 21:51:41 -0700 | [diff] [blame] | 1450 | "MOCK_LOCATION", |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 1451 | "READ_EXTERNAL_STORAGE", |
| 1452 | "WRITE_EXTERNAL_STORAGE", |
| 1453 | "TURN_ON_SCREEN", |
Svetoslav | f3f02ac | 2015-09-08 14:36:35 -0700 | [diff] [blame] | 1454 | "GET_ACCOUNTS", |
Dianne Hackborn | bef28fe | 2015-10-29 17:57:11 -0700 | [diff] [blame] | 1455 | "RUN_IN_BACKGROUND", |
Jean-Michel Trivi | 3f0945a | 2016-11-11 10:05:18 -0800 | [diff] [blame] | 1456 | "AUDIO_ACCESSIBILITY_VOLUME", |
Chad Brubaker | 0c1651f | 2017-03-30 16:29:10 -0700 | [diff] [blame] | 1457 | "READ_PHONE_NUMBERS", |
Suprabh Shukla | 2f34b1a | 2016-12-16 14:47:25 -0800 | [diff] [blame] | 1458 | "REQUEST_INSTALL_PACKAGES", |
Winson Chung | f4ac063 | 2017-03-17 12:34:12 -0700 | [diff] [blame] | 1459 | "PICTURE_IN_PICTURE", |
Chad Brubaker | 97b383f | 2017-02-02 15:04:35 -0800 | [diff] [blame] | 1460 | "INSTANT_APP_START_FOREGROUND", |
Eugene Susla | cae3d3e | 2017-01-31 11:08:11 -0800 | [diff] [blame] | 1461 | "ANSWER_PHONE_CALLS", |
Suprabh Shukla | 3ac1daa | 2017-07-14 12:15:27 -0700 | [diff] [blame] | 1462 | "RUN_ANY_IN_BACKGROUND", |
Peter Visontay | 1246d9e | 2017-10-17 17:02:45 +0100 | [diff] [blame] | 1463 | "CHANGE_WIFI_STATE", |
Peter Visontay | f2e3836 | 2017-11-27 15:27:16 +0000 | [diff] [blame] | 1464 | "REQUEST_DELETE_PACKAGES", |
Peter Visontay | 1195083 | 2017-11-14 19:34:59 +0000 | [diff] [blame] | 1465 | "BIND_ACCESSIBILITY_SERVICE", |
Tyler Gunn | 79bc1ec | 2018-01-22 15:17:54 -0800 | [diff] [blame] | 1466 | "ACCEPT_HANDOVER", |
Nathan Harold | 1bb42067 | 2018-03-14 17:08:53 -0700 | [diff] [blame] | 1467 | "MANAGE_IPSEC_TUNNELS", |
Dianne Hackborn | e9d9b4b | 2018-03-28 13:51:46 -0700 | [diff] [blame] | 1468 | "START_FOREGROUND", |
Dianne Hackborn | e04f13d | 2018-05-02 12:51:52 -0700 | [diff] [blame] | 1469 | "BLUETOOTH_SCAN", |
Kevin Chyn | b3c05aa | 2018-09-21 16:50:32 -0700 | [diff] [blame] | 1470 | "USE_BIOMETRIC", |
Zimuzo | 6cbf9cc | 2018-10-05 12:05:58 +0100 | [diff] [blame] | 1471 | "ACTIVITY_RECOGNITION", |
Hongming Jin | 228cd01 | 2018-11-09 14:47:50 -0800 | [diff] [blame] | 1472 | "SMS_FINANCIAL_TRANSACTIONS", |
Jeff Sharkey | d2a1f0d | 2018-11-19 10:32:52 -0700 | [diff] [blame] | 1473 | "READ_MEDIA_AUDIO", |
| 1474 | "WRITE_MEDIA_AUDIO", |
| 1475 | "READ_MEDIA_VIDEO", |
| 1476 | "WRITE_MEDIA_VIDEO", |
| 1477 | "READ_MEDIA_IMAGES", |
| 1478 | "WRITE_MEDIA_IMAGES", |
Jeff Sharkey | e82cbb1 | 2018-12-06 15:53:11 -0700 | [diff] [blame] | 1479 | "LEGACY_STORAGE", |
Jackal Guo | 8dc791e | 2019-01-14 10:26:42 +0800 | [diff] [blame] | 1480 | "ACCESS_ACCESSIBILITY", |
Michael Groover | 656ef91 | 2019-04-09 17:09:57 -0700 | [diff] [blame] | 1481 | "READ_DEVICE_IDENTIFIERS", |
Philip P. Moltmann | ac7b10c | 2019-09-13 15:12:34 -0700 | [diff] [blame] | 1482 | "ACCESS_MEDIA_LOCATION", |
Dianne Hackborn | 5e45ee6 | 2013-01-24 19:13:44 -0800 | [diff] [blame] | 1483 | }; |
| 1484 | |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 1485 | /** |
| 1486 | * This optionally maps a permission to an operation. If there |
| 1487 | * is no permission associated with an operation, it is null. |
| 1488 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 1489 | @UnsupportedAppUsage |
Dianne Hackborn | 5e45ee6 | 2013-01-24 19:13:44 -0800 | [diff] [blame] | 1490 | private static String[] sOpPerms = new String[] { |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 1491 | android.Manifest.permission.ACCESS_COARSE_LOCATION, |
| 1492 | android.Manifest.permission.ACCESS_FINE_LOCATION, |
| 1493 | null, |
| 1494 | android.Manifest.permission.VIBRATE, |
| 1495 | android.Manifest.permission.READ_CONTACTS, |
| 1496 | android.Manifest.permission.WRITE_CONTACTS, |
| 1497 | android.Manifest.permission.READ_CALL_LOG, |
| 1498 | android.Manifest.permission.WRITE_CALL_LOG, |
| 1499 | android.Manifest.permission.READ_CALENDAR, |
| 1500 | android.Manifest.permission.WRITE_CALENDAR, |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 1501 | android.Manifest.permission.ACCESS_WIFI_STATE, |
Robert Craig | f97616c | 2013-10-07 12:32:02 -0400 | [diff] [blame] | 1502 | null, // no permission required for notifications |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 1503 | null, // neighboring cells shares the coarse location perm |
| 1504 | android.Manifest.permission.CALL_PHONE, |
Dianne Hackborn | f51f612 | 2013-02-04 18:23:34 -0800 | [diff] [blame] | 1505 | android.Manifest.permission.READ_SMS, |
Svetoslav | 6c58957 | 2015-04-16 16:19:24 -0700 | [diff] [blame] | 1506 | null, // no permission required for writing sms |
Dianne Hackborn | f51f612 | 2013-02-04 18:23:34 -0800 | [diff] [blame] | 1507 | android.Manifest.permission.RECEIVE_SMS, |
| 1508 | android.Manifest.permission.RECEIVE_EMERGENCY_BROADCAST, |
| 1509 | android.Manifest.permission.RECEIVE_MMS, |
| 1510 | android.Manifest.permission.RECEIVE_WAP_PUSH, |
| 1511 | android.Manifest.permission.SEND_SMS, |
| 1512 | android.Manifest.permission.READ_SMS, |
Svetoslav | 6c58957 | 2015-04-16 16:19:24 -0700 | [diff] [blame] | 1513 | null, // no permission required for writing icc sms |
Dianne Hackborn | 961321f | 2013-02-05 17:22:41 -0800 | [diff] [blame] | 1514 | android.Manifest.permission.WRITE_SETTINGS, |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 1515 | android.Manifest.permission.SYSTEM_ALERT_WINDOW, |
Daniel Sandler | fde19b1 | 2013-01-17 00:21:05 -0500 | [diff] [blame] | 1516 | android.Manifest.permission.ACCESS_NOTIFICATIONS, |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 1517 | android.Manifest.permission.CAMERA, |
| 1518 | android.Manifest.permission.RECORD_AUDIO, |
| 1519 | null, // no permission for playing audio |
Dianne Hackborn | efcc1a2 | 2013-02-25 18:02:35 -0800 | [diff] [blame] | 1520 | null, // no permission for reading clipboard |
| 1521 | null, // no permission for writing clipboard |
Dianne Hackborn | ba50b97c | 2013-04-30 15:04:46 -0700 | [diff] [blame] | 1522 | null, // no permission for taking media buttons |
| 1523 | null, // no permission for taking audio focus |
| 1524 | null, // no permission for changing master volume |
| 1525 | null, // no permission for changing voice volume |
| 1526 | null, // no permission for changing ring volume |
| 1527 | null, // no permission for changing media volume |
| 1528 | null, // no permission for changing alarm volume |
| 1529 | null, // no permission for changing notification volume |
| 1530 | null, // no permission for changing bluetooth volume |
Dianne Hackborn | 713df15 | 2013-05-17 11:27:57 -0700 | [diff] [blame] | 1531 | android.Manifest.permission.WAKE_LOCK, |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 1532 | null, // no permission for generic location monitoring |
David Christie | 0b83745 | 2013-07-29 16:02:13 -0700 | [diff] [blame] | 1533 | null, // no permission for high power location monitoring |
Dianne Hackborn | e22b3b1 | 2014-05-07 18:06:44 -0700 | [diff] [blame] | 1534 | android.Manifest.permission.PACKAGE_USAGE_STATS, |
Emily Bernier | 22c921a | 2014-05-28 11:01:32 -0400 | [diff] [blame] | 1535 | null, // no permission for muting/unmuting microphone |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 1536 | null, // no permission for displaying toasts |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 1537 | null, // no permission for projecting media |
Jeff Davidson | 0554260 | 2014-08-11 14:07:27 -0700 | [diff] [blame] | 1538 | null, // no permission for activating vpn |
Benjamin Franz | f3ece36 | 2015-02-11 10:51:10 +0000 | [diff] [blame] | 1539 | null, // no permission for supporting wallpaper |
Dianne Hackborn | d59a5d5 | 2015-04-04 14:52:14 -0700 | [diff] [blame] | 1540 | null, // no permission for receiving assist structure |
| 1541 | null, // no permission for receiving assist screenshot |
Svet Ganov | c330009 | 2015-04-17 09:07:22 -0700 | [diff] [blame] | 1542 | Manifest.permission.READ_PHONE_STATE, |
Svetoslav | 5335b67 | 2015-04-29 12:00:51 -0700 | [diff] [blame] | 1543 | Manifest.permission.ADD_VOICEMAIL, |
Svetoslav | c656e6f | 2015-04-29 14:08:16 -0700 | [diff] [blame] | 1544 | Manifest.permission.USE_SIP, |
Svetoslav | 4af76a5 | 2015-04-29 15:29:46 -0700 | [diff] [blame] | 1545 | Manifest.permission.PROCESS_OUTGOING_CALLS, |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 1546 | Manifest.permission.USE_FINGERPRINT, |
Svet Ganov | ede4316 | 2015-05-02 17:42:44 -0700 | [diff] [blame] | 1547 | Manifest.permission.BODY_SENSORS, |
Svet Ganov | f7e9cf4 | 2015-05-13 10:40:31 -0700 | [diff] [blame] | 1548 | Manifest.permission.READ_CELL_BROADCASTS, |
Svet Ganov | 921c7df | 2015-06-29 21:51:41 -0700 | [diff] [blame] | 1549 | null, |
| 1550 | Manifest.permission.READ_EXTERNAL_STORAGE, |
| 1551 | Manifest.permission.WRITE_EXTERNAL_STORAGE, |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 1552 | null, // no permission for turning the screen on |
Dianne Hackborn | bef28fe | 2015-10-29 17:57:11 -0700 | [diff] [blame] | 1553 | Manifest.permission.GET_ACCOUNTS, |
| 1554 | null, // no permission for running in background |
Jean-Michel Trivi | 3f0945a | 2016-11-11 10:05:18 -0800 | [diff] [blame] | 1555 | null, // no permission for changing accessibility volume |
Chad Brubaker | 0c1651f | 2017-03-30 16:29:10 -0700 | [diff] [blame] | 1556 | Manifest.permission.READ_PHONE_NUMBERS, |
Suprabh Shukla | 2f34b1a | 2016-12-16 14:47:25 -0800 | [diff] [blame] | 1557 | Manifest.permission.REQUEST_INSTALL_PACKAGES, |
Winson Chung | 59fda9e | 2017-01-20 16:14:51 -0800 | [diff] [blame] | 1558 | null, // no permission for entering picture-in-picture on hide |
Chad Brubaker | 97b383f | 2017-02-02 15:04:35 -0800 | [diff] [blame] | 1559 | Manifest.permission.INSTANT_APP_FOREGROUND_SERVICE, |
Eugene Susla | cae3d3e | 2017-01-31 11:08:11 -0800 | [diff] [blame] | 1560 | Manifest.permission.ANSWER_PHONE_CALLS, |
Suprabh Shukla | 3ac1daa | 2017-07-14 12:15:27 -0700 | [diff] [blame] | 1561 | null, // no permission for OP_RUN_ANY_IN_BACKGROUND |
Peter Visontay | 1246d9e | 2017-10-17 17:02:45 +0100 | [diff] [blame] | 1562 | Manifest.permission.CHANGE_WIFI_STATE, |
Peter Visontay | f2e3836 | 2017-11-27 15:27:16 +0000 | [diff] [blame] | 1563 | Manifest.permission.REQUEST_DELETE_PACKAGES, |
Peter Visontay | 1195083 | 2017-11-14 19:34:59 +0000 | [diff] [blame] | 1564 | Manifest.permission.BIND_ACCESSIBILITY_SERVICE, |
Tyler Gunn | 79bc1ec | 2018-01-22 15:17:54 -0800 | [diff] [blame] | 1565 | Manifest.permission.ACCEPT_HANDOVER, |
Nathan Harold | 1bb42067 | 2018-03-14 17:08:53 -0700 | [diff] [blame] | 1566 | null, // no permission for OP_MANAGE_IPSEC_TUNNELS |
Dianne Hackborn | e9d9b4b | 2018-03-28 13:51:46 -0700 | [diff] [blame] | 1567 | Manifest.permission.FOREGROUND_SERVICE, |
Dianne Hackborn | e04f13d | 2018-05-02 12:51:52 -0700 | [diff] [blame] | 1568 | null, // no permission for OP_BLUETOOTH_SCAN |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 1569 | Manifest.permission.USE_BIOMETRIC, |
Zimuzo | 6cbf9cc | 2018-10-05 12:05:58 +0100 | [diff] [blame] | 1570 | Manifest.permission.ACTIVITY_RECOGNITION, |
Hongming Jin | 228cd01 | 2018-11-09 14:47:50 -0800 | [diff] [blame] | 1571 | Manifest.permission.SMS_FINANCIAL_TRANSACTIONS, |
Philip P. Moltmann | 129a0b0 | 2019-03-27 12:24:45 -0700 | [diff] [blame] | 1572 | null, |
Jeff Sharkey | 9787a945 | 2018-11-18 17:53:02 -0700 | [diff] [blame] | 1573 | null, // no permission for OP_WRITE_MEDIA_AUDIO |
Philip P. Moltmann | 129a0b0 | 2019-03-27 12:24:45 -0700 | [diff] [blame] | 1574 | null, |
Jeff Sharkey | 9787a945 | 2018-11-18 17:53:02 -0700 | [diff] [blame] | 1575 | null, // no permission for OP_WRITE_MEDIA_VIDEO |
Philip P. Moltmann | 129a0b0 | 2019-03-27 12:24:45 -0700 | [diff] [blame] | 1576 | null, |
Jeff Sharkey | 9787a945 | 2018-11-18 17:53:02 -0700 | [diff] [blame] | 1577 | null, // no permission for OP_WRITE_MEDIA_IMAGES |
Jeff Sharkey | e82cbb1 | 2018-12-06 15:53:11 -0700 | [diff] [blame] | 1578 | null, // no permission for OP_LEGACY_STORAGE |
Jackal Guo | 8dc791e | 2019-01-14 10:26:42 +0800 | [diff] [blame] | 1579 | null, // no permission for OP_ACCESS_ACCESSIBILITY |
Michael Groover | 656ef91 | 2019-04-09 17:09:57 -0700 | [diff] [blame] | 1580 | null, // no direct permission for OP_READ_DEVICE_IDENTIFIERS |
Philip P. Moltmann | ac7b10c | 2019-09-13 15:12:34 -0700 | [diff] [blame] | 1581 | Manifest.permission.ACCESS_MEDIA_LOCATION, |
Dianne Hackborn | 5e45ee6 | 2013-01-24 19:13:44 -0800 | [diff] [blame] | 1582 | }; |
| 1583 | |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 1584 | /** |
Jason Monk | 6206299 | 2014-05-06 09:55:28 -0400 | [diff] [blame] | 1585 | * Specifies whether an Op should be restricted by a user restriction. |
| 1586 | * Each Op should be filled with a restriction string from UserManager or |
| 1587 | * null to specify it is not affected by any user restriction. |
| 1588 | */ |
| 1589 | private static String[] sOpRestrictions = new String[] { |
Julia Reynolds | 9854d57 | 2014-07-02 14:46:02 -0400 | [diff] [blame] | 1590 | UserManager.DISALLOW_SHARE_LOCATION, //COARSE_LOCATION |
| 1591 | UserManager.DISALLOW_SHARE_LOCATION, //FINE_LOCATION |
| 1592 | UserManager.DISALLOW_SHARE_LOCATION, //GPS |
Jason Monk | 6206299 | 2014-05-06 09:55:28 -0400 | [diff] [blame] | 1593 | null, //VIBRATE |
| 1594 | null, //READ_CONTACTS |
| 1595 | null, //WRITE_CONTACTS |
Yorke Lee | 15f83c6 | 2014-08-13 14:14:29 -0700 | [diff] [blame] | 1596 | UserManager.DISALLOW_OUTGOING_CALLS, //READ_CALL_LOG |
| 1597 | UserManager.DISALLOW_OUTGOING_CALLS, //WRITE_CALL_LOG |
Jason Monk | 6206299 | 2014-05-06 09:55:28 -0400 | [diff] [blame] | 1598 | null, //READ_CALENDAR |
| 1599 | null, //WRITE_CALENDAR |
Julia Reynolds | 9854d57 | 2014-07-02 14:46:02 -0400 | [diff] [blame] | 1600 | UserManager.DISALLOW_SHARE_LOCATION, //WIFI_SCAN |
Jason Monk | 6206299 | 2014-05-06 09:55:28 -0400 | [diff] [blame] | 1601 | null, //POST_NOTIFICATION |
| 1602 | null, //NEIGHBORING_CELLS |
| 1603 | null, //CALL_PHONE |
Amith Yamasani | 41c1ded | 2014-08-05 11:15:05 -0700 | [diff] [blame] | 1604 | UserManager.DISALLOW_SMS, //READ_SMS |
| 1605 | UserManager.DISALLOW_SMS, //WRITE_SMS |
| 1606 | UserManager.DISALLOW_SMS, //RECEIVE_SMS |
| 1607 | null, //RECEIVE_EMERGENCY_SMS |
| 1608 | UserManager.DISALLOW_SMS, //RECEIVE_MMS |
Jason Monk | 6206299 | 2014-05-06 09:55:28 -0400 | [diff] [blame] | 1609 | null, //RECEIVE_WAP_PUSH |
Amith Yamasani | 41c1ded | 2014-08-05 11:15:05 -0700 | [diff] [blame] | 1610 | UserManager.DISALLOW_SMS, //SEND_SMS |
| 1611 | UserManager.DISALLOW_SMS, //READ_ICC_SMS |
| 1612 | UserManager.DISALLOW_SMS, //WRITE_ICC_SMS |
Jason Monk | 6206299 | 2014-05-06 09:55:28 -0400 | [diff] [blame] | 1613 | null, //WRITE_SETTINGS |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 1614 | UserManager.DISALLOW_CREATE_WINDOWS, //SYSTEM_ALERT_WINDOW |
Jason Monk | 6206299 | 2014-05-06 09:55:28 -0400 | [diff] [blame] | 1615 | null, //ACCESS_NOTIFICATIONS |
Makoto Onuki | 759a763 | 2015-10-28 16:43:10 -0700 | [diff] [blame] | 1616 | UserManager.DISALLOW_CAMERA, //CAMERA |
Fyodor Kupolov | b501330 | 2015-04-17 17:59:14 -0700 | [diff] [blame] | 1617 | UserManager.DISALLOW_RECORD_AUDIO, //RECORD_AUDIO |
Jason Monk | 6206299 | 2014-05-06 09:55:28 -0400 | [diff] [blame] | 1618 | null, //PLAY_AUDIO |
| 1619 | null, //READ_CLIPBOARD |
| 1620 | null, //WRITE_CLIPBOARD |
| 1621 | null, //TAKE_MEDIA_BUTTONS |
| 1622 | null, //TAKE_AUDIO_FOCUS |
Emily Bernier | 45775c4 | 2014-05-16 15:12:04 -0400 | [diff] [blame] | 1623 | UserManager.DISALLOW_ADJUST_VOLUME, //AUDIO_MASTER_VOLUME |
| 1624 | UserManager.DISALLOW_ADJUST_VOLUME, //AUDIO_VOICE_VOLUME |
| 1625 | UserManager.DISALLOW_ADJUST_VOLUME, //AUDIO_RING_VOLUME |
| 1626 | UserManager.DISALLOW_ADJUST_VOLUME, //AUDIO_MEDIA_VOLUME |
| 1627 | UserManager.DISALLOW_ADJUST_VOLUME, //AUDIO_ALARM_VOLUME |
| 1628 | UserManager.DISALLOW_ADJUST_VOLUME, //AUDIO_NOTIFICATION_VOLUME |
| 1629 | UserManager.DISALLOW_ADJUST_VOLUME, //AUDIO_BLUETOOTH_VOLUME |
Jason Monk | 6206299 | 2014-05-06 09:55:28 -0400 | [diff] [blame] | 1630 | null, //WAKE_LOCK |
Julia Reynolds | 9854d57 | 2014-07-02 14:46:02 -0400 | [diff] [blame] | 1631 | UserManager.DISALLOW_SHARE_LOCATION, //MONITOR_LOCATION |
| 1632 | UserManager.DISALLOW_SHARE_LOCATION, //MONITOR_HIGH_POWER_LOCATION |
Jason Monk | 6206299 | 2014-05-06 09:55:28 -0400 | [diff] [blame] | 1633 | null, //GET_USAGE_STATS |
Emily Bernier | 22c921a | 2014-05-28 11:01:32 -0400 | [diff] [blame] | 1634 | UserManager.DISALLOW_UNMUTE_MICROPHONE, // MUTE_MICROPHONE |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 1635 | UserManager.DISALLOW_CREATE_WINDOWS, // TOAST_WINDOW |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 1636 | null, //PROJECT_MEDIA |
Tony Mak | 33d03a9 | 2016-06-02 15:01:16 +0100 | [diff] [blame] | 1637 | null, // ACTIVATE_VPN |
Benjamin Franz | f3ece36 | 2015-02-11 10:51:10 +0000 | [diff] [blame] | 1638 | UserManager.DISALLOW_WALLPAPER, // WRITE_WALLPAPER |
Dianne Hackborn | d59a5d5 | 2015-04-04 14:52:14 -0700 | [diff] [blame] | 1639 | null, // ASSIST_STRUCTURE |
| 1640 | null, // ASSIST_SCREENSHOT |
Svet Ganov | c330009 | 2015-04-17 09:07:22 -0700 | [diff] [blame] | 1641 | null, // READ_PHONE_STATE |
Svetoslav | 5335b67 | 2015-04-29 12:00:51 -0700 | [diff] [blame] | 1642 | null, // ADD_VOICEMAIL |
Svetoslav | c656e6f | 2015-04-29 14:08:16 -0700 | [diff] [blame] | 1643 | null, // USE_SIP |
Svetoslav | 4af76a5 | 2015-04-29 15:29:46 -0700 | [diff] [blame] | 1644 | null, // PROCESS_OUTGOING_CALLS |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 1645 | null, // USE_FINGERPRINT |
Svet Ganov | ede4316 | 2015-05-02 17:42:44 -0700 | [diff] [blame] | 1646 | null, // BODY_SENSORS |
Svet Ganov | f7e9cf4 | 2015-05-13 10:40:31 -0700 | [diff] [blame] | 1647 | null, // READ_CELL_BROADCASTS |
Svet Ganov | 921c7df | 2015-06-29 21:51:41 -0700 | [diff] [blame] | 1648 | null, // MOCK_LOCATION |
| 1649 | null, // READ_EXTERNAL_STORAGE |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 1650 | null, // WRITE_EXTERNAL_STORAGE |
| 1651 | null, // TURN_ON_SCREEN |
Svetoslav | f3f02ac | 2015-09-08 14:36:35 -0700 | [diff] [blame] | 1652 | null, // GET_ACCOUNTS |
Dianne Hackborn | bef28fe | 2015-10-29 17:57:11 -0700 | [diff] [blame] | 1653 | null, // RUN_IN_BACKGROUND |
Jean-Michel Trivi | 3f0945a | 2016-11-11 10:05:18 -0800 | [diff] [blame] | 1654 | UserManager.DISALLOW_ADJUST_VOLUME, //AUDIO_ACCESSIBILITY_VOLUME |
Chad Brubaker | 0c1651f | 2017-03-30 16:29:10 -0700 | [diff] [blame] | 1655 | null, // READ_PHONE_NUMBERS |
Suprabh Shukla | 2f34b1a | 2016-12-16 14:47:25 -0800 | [diff] [blame] | 1656 | null, // REQUEST_INSTALL_PACKAGES |
Winson Chung | 59fda9e | 2017-01-20 16:14:51 -0800 | [diff] [blame] | 1657 | null, // ENTER_PICTURE_IN_PICTURE_ON_HIDE |
Chad Brubaker | 97b383f | 2017-02-02 15:04:35 -0800 | [diff] [blame] | 1658 | null, // INSTANT_APP_START_FOREGROUND |
Eugene Susla | cae3d3e | 2017-01-31 11:08:11 -0800 | [diff] [blame] | 1659 | null, // ANSWER_PHONE_CALLS |
Suprabh Shukla | 3ac1daa | 2017-07-14 12:15:27 -0700 | [diff] [blame] | 1660 | null, // OP_RUN_ANY_IN_BACKGROUND |
Peter Visontay | 1246d9e | 2017-10-17 17:02:45 +0100 | [diff] [blame] | 1661 | null, // OP_CHANGE_WIFI_STATE |
Peter Visontay | f2e3836 | 2017-11-27 15:27:16 +0000 | [diff] [blame] | 1662 | null, // REQUEST_DELETE_PACKAGES |
Peter Visontay | 1195083 | 2017-11-14 19:34:59 +0000 | [diff] [blame] | 1663 | null, // OP_BIND_ACCESSIBILITY_SERVICE |
Tyler Gunn | 79bc1ec | 2018-01-22 15:17:54 -0800 | [diff] [blame] | 1664 | null, // ACCEPT_HANDOVER |
Nathan Harold | 1bb42067 | 2018-03-14 17:08:53 -0700 | [diff] [blame] | 1665 | null, // MANAGE_IPSEC_TUNNELS |
Dianne Hackborn | e9d9b4b | 2018-03-28 13:51:46 -0700 | [diff] [blame] | 1666 | null, // START_FOREGROUND |
Dianne Hackborn | e04f13d | 2018-05-02 12:51:52 -0700 | [diff] [blame] | 1667 | null, // maybe should be UserManager.DISALLOW_SHARE_LOCATION, //BLUETOOTH_SCAN |
Kevin Chyn | b3c05aa | 2018-09-21 16:50:32 -0700 | [diff] [blame] | 1668 | null, // USE_BIOMETRIC |
Zimuzo | 6cbf9cc | 2018-10-05 12:05:58 +0100 | [diff] [blame] | 1669 | null, // ACTIVITY_RECOGNITION |
Hongming Jin | 228cd01 | 2018-11-09 14:47:50 -0800 | [diff] [blame] | 1670 | UserManager.DISALLOW_SMS, // SMS_FINANCIAL_TRANSACTIONS |
Jeff Sharkey | d2a1f0d | 2018-11-19 10:32:52 -0700 | [diff] [blame] | 1671 | null, // READ_MEDIA_AUDIO |
| 1672 | null, // WRITE_MEDIA_AUDIO |
| 1673 | null, // READ_MEDIA_VIDEO |
| 1674 | null, // WRITE_MEDIA_VIDEO |
| 1675 | null, // READ_MEDIA_IMAGES |
| 1676 | null, // WRITE_MEDIA_IMAGES |
Jeff Sharkey | e82cbb1 | 2018-12-06 15:53:11 -0700 | [diff] [blame] | 1677 | null, // LEGACY_STORAGE |
Jackal Guo | 8dc791e | 2019-01-14 10:26:42 +0800 | [diff] [blame] | 1678 | null, // ACCESS_ACCESSIBILITY |
Michael Groover | 656ef91 | 2019-04-09 17:09:57 -0700 | [diff] [blame] | 1679 | null, // READ_DEVICE_IDENTIFIERS |
Philip P. Moltmann | ac7b10c | 2019-09-13 15:12:34 -0700 | [diff] [blame] | 1680 | null, // ACCESS_MEDIA_LOCATION |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 1681 | }; |
| 1682 | |
| 1683 | /** |
| 1684 | * This specifies whether each option should allow the system |
| 1685 | * (and system ui) to bypass the user restriction when active. |
| 1686 | */ |
| 1687 | private static boolean[] sOpAllowSystemRestrictionBypass = new boolean[] { |
Fyodor Kupolov | 639e73d | 2016-02-25 11:58:21 -0800 | [diff] [blame] | 1688 | true, //COARSE_LOCATION |
| 1689 | true, //FINE_LOCATION |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 1690 | false, //GPS |
| 1691 | false, //VIBRATE |
| 1692 | false, //READ_CONTACTS |
| 1693 | false, //WRITE_CONTACTS |
| 1694 | false, //READ_CALL_LOG |
| 1695 | false, //WRITE_CALL_LOG |
| 1696 | false, //READ_CALENDAR |
| 1697 | false, //WRITE_CALENDAR |
Julia Reynolds | 9854d57 | 2014-07-02 14:46:02 -0400 | [diff] [blame] | 1698 | true, //WIFI_SCAN |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 1699 | false, //POST_NOTIFICATION |
| 1700 | false, //NEIGHBORING_CELLS |
| 1701 | false, //CALL_PHONE |
| 1702 | false, //READ_SMS |
| 1703 | false, //WRITE_SMS |
| 1704 | false, //RECEIVE_SMS |
| 1705 | false, //RECEIVE_EMERGECY_SMS |
| 1706 | false, //RECEIVE_MMS |
| 1707 | false, //RECEIVE_WAP_PUSH |
| 1708 | false, //SEND_SMS |
| 1709 | false, //READ_ICC_SMS |
| 1710 | false, //WRITE_ICC_SMS |
| 1711 | false, //WRITE_SETTINGS |
| 1712 | true, //SYSTEM_ALERT_WINDOW |
| 1713 | false, //ACCESS_NOTIFICATIONS |
| 1714 | false, //CAMERA |
| 1715 | false, //RECORD_AUDIO |
| 1716 | false, //PLAY_AUDIO |
| 1717 | false, //READ_CLIPBOARD |
| 1718 | false, //WRITE_CLIPBOARD |
| 1719 | false, //TAKE_MEDIA_BUTTONS |
| 1720 | false, //TAKE_AUDIO_FOCUS |
| 1721 | false, //AUDIO_MASTER_VOLUME |
| 1722 | false, //AUDIO_VOICE_VOLUME |
| 1723 | false, //AUDIO_RING_VOLUME |
| 1724 | false, //AUDIO_MEDIA_VOLUME |
| 1725 | false, //AUDIO_ALARM_VOLUME |
| 1726 | false, //AUDIO_NOTIFICATION_VOLUME |
| 1727 | false, //AUDIO_BLUETOOTH_VOLUME |
| 1728 | false, //WAKE_LOCK |
| 1729 | false, //MONITOR_LOCATION |
| 1730 | false, //MONITOR_HIGH_POWER_LOCATION |
| 1731 | false, //GET_USAGE_STATS |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 1732 | false, //MUTE_MICROPHONE |
| 1733 | true, //TOAST_WINDOW |
| 1734 | false, //PROJECT_MEDIA |
Jeff Davidson | 0554260 | 2014-08-11 14:07:27 -0700 | [diff] [blame] | 1735 | false, //ACTIVATE_VPN |
Benjamin Franz | f3ece36 | 2015-02-11 10:51:10 +0000 | [diff] [blame] | 1736 | false, //WALLPAPER |
Dianne Hackborn | d59a5d5 | 2015-04-04 14:52:14 -0700 | [diff] [blame] | 1737 | false, //ASSIST_STRUCTURE |
| 1738 | false, //ASSIST_SCREENSHOT |
Svet Ganov | 16a1689 | 2015-04-16 10:32:04 -0700 | [diff] [blame] | 1739 | false, //READ_PHONE_STATE |
Svetoslav | 5335b67 | 2015-04-29 12:00:51 -0700 | [diff] [blame] | 1740 | false, //ADD_VOICEMAIL |
Svetoslav | c656e6f | 2015-04-29 14:08:16 -0700 | [diff] [blame] | 1741 | false, // USE_SIP |
Svetoslav | 4af76a5 | 2015-04-29 15:29:46 -0700 | [diff] [blame] | 1742 | false, // PROCESS_OUTGOING_CALLS |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 1743 | false, // USE_FINGERPRINT |
Svet Ganov | ede4316 | 2015-05-02 17:42:44 -0700 | [diff] [blame] | 1744 | false, // BODY_SENSORS |
Svet Ganov | f7e9cf4 | 2015-05-13 10:40:31 -0700 | [diff] [blame] | 1745 | false, // READ_CELL_BROADCASTS |
Svet Ganov | 921c7df | 2015-06-29 21:51:41 -0700 | [diff] [blame] | 1746 | false, // MOCK_LOCATION |
| 1747 | false, // READ_EXTERNAL_STORAGE |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 1748 | false, // WRITE_EXTERNAL_STORAGE |
| 1749 | false, // TURN_ON_SCREEN |
Svetoslav | f3f02ac | 2015-09-08 14:36:35 -0700 | [diff] [blame] | 1750 | false, // GET_ACCOUNTS |
Dianne Hackborn | bef28fe | 2015-10-29 17:57:11 -0700 | [diff] [blame] | 1751 | false, // RUN_IN_BACKGROUND |
Jean-Michel Trivi | 3f0945a | 2016-11-11 10:05:18 -0800 | [diff] [blame] | 1752 | false, // AUDIO_ACCESSIBILITY_VOLUME |
Chad Brubaker | 0c1651f | 2017-03-30 16:29:10 -0700 | [diff] [blame] | 1753 | false, // READ_PHONE_NUMBERS |
Suprabh Shukla | 2f34b1a | 2016-12-16 14:47:25 -0800 | [diff] [blame] | 1754 | false, // REQUEST_INSTALL_PACKAGES |
Winson Chung | 59fda9e | 2017-01-20 16:14:51 -0800 | [diff] [blame] | 1755 | false, // ENTER_PICTURE_IN_PICTURE_ON_HIDE |
Chad Brubaker | 97b383f | 2017-02-02 15:04:35 -0800 | [diff] [blame] | 1756 | false, // INSTANT_APP_START_FOREGROUND |
Eugene Susla | cae3d3e | 2017-01-31 11:08:11 -0800 | [diff] [blame] | 1757 | false, // ANSWER_PHONE_CALLS |
Suprabh Shukla | 3ac1daa | 2017-07-14 12:15:27 -0700 | [diff] [blame] | 1758 | false, // OP_RUN_ANY_IN_BACKGROUND |
Peter Visontay | 1246d9e | 2017-10-17 17:02:45 +0100 | [diff] [blame] | 1759 | false, // OP_CHANGE_WIFI_STATE |
Peter Visontay | f2e3836 | 2017-11-27 15:27:16 +0000 | [diff] [blame] | 1760 | false, // OP_REQUEST_DELETE_PACKAGES |
Peter Visontay | 1195083 | 2017-11-14 19:34:59 +0000 | [diff] [blame] | 1761 | false, // OP_BIND_ACCESSIBILITY_SERVICE |
Tyler Gunn | 79bc1ec | 2018-01-22 15:17:54 -0800 | [diff] [blame] | 1762 | false, // ACCEPT_HANDOVER |
Nathan Harold | 1bb42067 | 2018-03-14 17:08:53 -0700 | [diff] [blame] | 1763 | false, // MANAGE_IPSEC_HANDOVERS |
Dianne Hackborn | e9d9b4b | 2018-03-28 13:51:46 -0700 | [diff] [blame] | 1764 | false, // START_FOREGROUND |
Dianne Hackborn | e04f13d | 2018-05-02 12:51:52 -0700 | [diff] [blame] | 1765 | true, // BLUETOOTH_SCAN |
Kevin Chyn | b3c05aa | 2018-09-21 16:50:32 -0700 | [diff] [blame] | 1766 | false, // USE_BIOMETRIC |
Zimuzo | 6cbf9cc | 2018-10-05 12:05:58 +0100 | [diff] [blame] | 1767 | false, // ACTIVITY_RECOGNITION |
Hongming Jin | 228cd01 | 2018-11-09 14:47:50 -0800 | [diff] [blame] | 1768 | false, // SMS_FINANCIAL_TRANSACTIONS |
Jeff Sharkey | d2a1f0d | 2018-11-19 10:32:52 -0700 | [diff] [blame] | 1769 | false, // READ_MEDIA_AUDIO |
| 1770 | false, // WRITE_MEDIA_AUDIO |
| 1771 | false, // READ_MEDIA_VIDEO |
| 1772 | false, // WRITE_MEDIA_VIDEO |
| 1773 | false, // READ_MEDIA_IMAGES |
| 1774 | false, // WRITE_MEDIA_IMAGES |
Jeff Sharkey | e82cbb1 | 2018-12-06 15:53:11 -0700 | [diff] [blame] | 1775 | false, // LEGACY_STORAGE |
Jackal Guo | 8dc791e | 2019-01-14 10:26:42 +0800 | [diff] [blame] | 1776 | false, // ACCESS_ACCESSIBILITY |
Michael Groover | 656ef91 | 2019-04-09 17:09:57 -0700 | [diff] [blame] | 1777 | false, // READ_DEVICE_IDENTIFIERS |
Philip P. Moltmann | ac7b10c | 2019-09-13 15:12:34 -0700 | [diff] [blame] | 1778 | false, // ACCESS_MEDIA_LOCATION |
Jason Monk | 6206299 | 2014-05-06 09:55:28 -0400 | [diff] [blame] | 1779 | }; |
| 1780 | |
| 1781 | /** |
David Braun | f5d8319 | 2013-09-16 13:43:51 -0700 | [diff] [blame] | 1782 | * This specifies the default mode for each operation. |
| 1783 | */ |
| 1784 | private static int[] sOpDefaultMode = new int[] { |
Eugene Susla | 9351985 | 2018-06-13 16:44:31 -0700 | [diff] [blame] | 1785 | AppOpsManager.MODE_ALLOWED, // COARSE_LOCATION |
| 1786 | AppOpsManager.MODE_ALLOWED, // FINE_LOCATION |
| 1787 | AppOpsManager.MODE_ALLOWED, // GPS |
| 1788 | AppOpsManager.MODE_ALLOWED, // VIBRATE |
| 1789 | AppOpsManager.MODE_ALLOWED, // READ_CONTACTS |
| 1790 | AppOpsManager.MODE_ALLOWED, // WRITE_CONTACTS |
Svet Ganov | d563e93 | 2019-04-14 13:07:41 -0700 | [diff] [blame] | 1791 | AppOpsManager.MODE_ALLOWED, // READ_CALL_LOG |
| 1792 | AppOpsManager.MODE_ALLOWED, // WRITE_CALL_LOG |
Eugene Susla | 9351985 | 2018-06-13 16:44:31 -0700 | [diff] [blame] | 1793 | AppOpsManager.MODE_ALLOWED, // READ_CALENDAR |
| 1794 | AppOpsManager.MODE_ALLOWED, // WRITE_CALENDAR |
| 1795 | AppOpsManager.MODE_ALLOWED, // WIFI_SCAN |
| 1796 | AppOpsManager.MODE_ALLOWED, // POST_NOTIFICATION |
| 1797 | AppOpsManager.MODE_ALLOWED, // NEIGHBORING_CELLS |
| 1798 | AppOpsManager.MODE_ALLOWED, // CALL_PHONE |
Svet Ganov | d563e93 | 2019-04-14 13:07:41 -0700 | [diff] [blame] | 1799 | AppOpsManager.MODE_ALLOWED, // READ_SMS |
Eugene Susla | aaff007 | 2018-10-30 13:35:03 -0700 | [diff] [blame] | 1800 | AppOpsManager.MODE_IGNORED, // WRITE_SMS |
Svet Ganov | d563e93 | 2019-04-14 13:07:41 -0700 | [diff] [blame] | 1801 | AppOpsManager.MODE_ALLOWED, // RECEIVE_SMS |
Eugene Susla | 9351985 | 2018-06-13 16:44:31 -0700 | [diff] [blame] | 1802 | AppOpsManager.MODE_ALLOWED, // RECEIVE_EMERGENCY_BROADCAST |
Svet Ganov | d563e93 | 2019-04-14 13:07:41 -0700 | [diff] [blame] | 1803 | AppOpsManager.MODE_ALLOWED, // RECEIVE_MMS |
| 1804 | AppOpsManager.MODE_ALLOWED, // RECEIVE_WAP_PUSH |
| 1805 | AppOpsManager.MODE_ALLOWED, // SEND_SMS |
Eugene Susla | 9351985 | 2018-06-13 16:44:31 -0700 | [diff] [blame] | 1806 | AppOpsManager.MODE_ALLOWED, // READ_ICC_SMS |
| 1807 | AppOpsManager.MODE_ALLOWED, // WRITE_ICC_SMS |
| 1808 | AppOpsManager.MODE_DEFAULT, // WRITE_SETTINGS |
Ng Zhi An | 65a99b6 | 2018-10-01 11:57:53 -0700 | [diff] [blame] | 1809 | getSystemAlertWindowDefault(), // SYSTEM_ALERT_WINDOW |
Eugene Susla | 9351985 | 2018-06-13 16:44:31 -0700 | [diff] [blame] | 1810 | AppOpsManager.MODE_ALLOWED, // ACCESS_NOTIFICATIONS |
| 1811 | AppOpsManager.MODE_ALLOWED, // CAMERA |
| 1812 | AppOpsManager.MODE_ALLOWED, // RECORD_AUDIO |
| 1813 | AppOpsManager.MODE_ALLOWED, // PLAY_AUDIO |
| 1814 | AppOpsManager.MODE_ALLOWED, // READ_CLIPBOARD |
| 1815 | AppOpsManager.MODE_ALLOWED, // WRITE_CLIPBOARD |
| 1816 | AppOpsManager.MODE_ALLOWED, // TAKE_MEDIA_BUTTONS |
| 1817 | AppOpsManager.MODE_ALLOWED, // TAKE_AUDIO_FOCUS |
| 1818 | AppOpsManager.MODE_ALLOWED, // AUDIO_MASTER_VOLUME |
| 1819 | AppOpsManager.MODE_ALLOWED, // AUDIO_VOICE_VOLUME |
| 1820 | AppOpsManager.MODE_ALLOWED, // AUDIO_RING_VOLUME |
| 1821 | AppOpsManager.MODE_ALLOWED, // AUDIO_MEDIA_VOLUME |
| 1822 | AppOpsManager.MODE_ALLOWED, // AUDIO_ALARM_VOLUME |
| 1823 | AppOpsManager.MODE_ALLOWED, // AUDIO_NOTIFICATION_VOLUME |
| 1824 | AppOpsManager.MODE_ALLOWED, // AUDIO_BLUETOOTH_VOLUME |
| 1825 | AppOpsManager.MODE_ALLOWED, // WAKE_LOCK |
| 1826 | AppOpsManager.MODE_ALLOWED, // MONITOR_LOCATION |
| 1827 | AppOpsManager.MODE_ALLOWED, // MONITOR_HIGH_POWER_LOCATION |
| 1828 | AppOpsManager.MODE_DEFAULT, // GET_USAGE_STATS |
| 1829 | AppOpsManager.MODE_ALLOWED, // MUTE_MICROPHONE |
| 1830 | AppOpsManager.MODE_ALLOWED, // TOAST_WINDOW |
| 1831 | AppOpsManager.MODE_IGNORED, // PROJECT_MEDIA |
| 1832 | AppOpsManager.MODE_IGNORED, // ACTIVATE_VPN |
| 1833 | AppOpsManager.MODE_ALLOWED, // WRITE_WALLPAPER |
| 1834 | AppOpsManager.MODE_ALLOWED, // ASSIST_STRUCTURE |
| 1835 | AppOpsManager.MODE_ALLOWED, // ASSIST_SCREENSHOT |
| 1836 | AppOpsManager.MODE_ALLOWED, // READ_PHONE_STATE |
| 1837 | AppOpsManager.MODE_ALLOWED, // ADD_VOICEMAIL |
| 1838 | AppOpsManager.MODE_ALLOWED, // USE_SIP |
Svet Ganov | d563e93 | 2019-04-14 13:07:41 -0700 | [diff] [blame] | 1839 | AppOpsManager.MODE_ALLOWED, // PROCESS_OUTGOING_CALLS |
Eugene Susla | 9351985 | 2018-06-13 16:44:31 -0700 | [diff] [blame] | 1840 | AppOpsManager.MODE_ALLOWED, // USE_FINGERPRINT |
| 1841 | AppOpsManager.MODE_ALLOWED, // BODY_SENSORS |
Svet Ganov | d563e93 | 2019-04-14 13:07:41 -0700 | [diff] [blame] | 1842 | AppOpsManager.MODE_ALLOWED, // READ_CELL_BROADCASTS |
Eugene Susla | 9351985 | 2018-06-13 16:44:31 -0700 | [diff] [blame] | 1843 | AppOpsManager.MODE_ERRORED, // MOCK_LOCATION |
| 1844 | AppOpsManager.MODE_ALLOWED, // READ_EXTERNAL_STORAGE |
| 1845 | AppOpsManager.MODE_ALLOWED, // WRITE_EXTERNAL_STORAGE |
| 1846 | AppOpsManager.MODE_ALLOWED, // TURN_SCREEN_ON |
| 1847 | AppOpsManager.MODE_ALLOWED, // GET_ACCOUNTS |
| 1848 | AppOpsManager.MODE_ALLOWED, // RUN_IN_BACKGROUND |
| 1849 | AppOpsManager.MODE_ALLOWED, // AUDIO_ACCESSIBILITY_VOLUME |
| 1850 | AppOpsManager.MODE_ALLOWED, // READ_PHONE_NUMBERS |
| 1851 | AppOpsManager.MODE_DEFAULT, // REQUEST_INSTALL_PACKAGES |
| 1852 | AppOpsManager.MODE_ALLOWED, // PICTURE_IN_PICTURE |
| 1853 | AppOpsManager.MODE_DEFAULT, // INSTANT_APP_START_FOREGROUND |
| 1854 | AppOpsManager.MODE_ALLOWED, // ANSWER_PHONE_CALLS |
| 1855 | AppOpsManager.MODE_ALLOWED, // RUN_ANY_IN_BACKGROUND |
| 1856 | AppOpsManager.MODE_ALLOWED, // CHANGE_WIFI_STATE |
| 1857 | AppOpsManager.MODE_ALLOWED, // REQUEST_DELETE_PACKAGES |
| 1858 | AppOpsManager.MODE_ALLOWED, // BIND_ACCESSIBILITY_SERVICE |
| 1859 | AppOpsManager.MODE_ALLOWED, // ACCEPT_HANDOVER |
| 1860 | AppOpsManager.MODE_ERRORED, // MANAGE_IPSEC_TUNNELS |
| 1861 | AppOpsManager.MODE_ALLOWED, // START_FOREGROUND |
| 1862 | AppOpsManager.MODE_ALLOWED, // BLUETOOTH_SCAN |
| 1863 | AppOpsManager.MODE_ALLOWED, // USE_BIOMETRIC |
Zimuzo | 6cbf9cc | 2018-10-05 12:05:58 +0100 | [diff] [blame] | 1864 | AppOpsManager.MODE_ALLOWED, // ACTIVITY_RECOGNITION |
Hongming Jin | 228cd01 | 2018-11-09 14:47:50 -0800 | [diff] [blame] | 1865 | AppOpsManager.MODE_DEFAULT, // SMS_FINANCIAL_TRANSACTIONS |
Jeff Sharkey | d2a1f0d | 2018-11-19 10:32:52 -0700 | [diff] [blame] | 1866 | AppOpsManager.MODE_ALLOWED, // READ_MEDIA_AUDIO |
Jeff Sharkey | 9787a945 | 2018-11-18 17:53:02 -0700 | [diff] [blame] | 1867 | AppOpsManager.MODE_ERRORED, // WRITE_MEDIA_AUDIO |
Jeff Sharkey | d2a1f0d | 2018-11-19 10:32:52 -0700 | [diff] [blame] | 1868 | AppOpsManager.MODE_ALLOWED, // READ_MEDIA_VIDEO |
Jeff Sharkey | 9787a945 | 2018-11-18 17:53:02 -0700 | [diff] [blame] | 1869 | AppOpsManager.MODE_ERRORED, // WRITE_MEDIA_VIDEO |
Jeff Sharkey | d2a1f0d | 2018-11-19 10:32:52 -0700 | [diff] [blame] | 1870 | AppOpsManager.MODE_ALLOWED, // READ_MEDIA_IMAGES |
Jeff Sharkey | 9787a945 | 2018-11-18 17:53:02 -0700 | [diff] [blame] | 1871 | AppOpsManager.MODE_ERRORED, // WRITE_MEDIA_IMAGES |
Jeff Sharkey | e82cbb1 | 2018-12-06 15:53:11 -0700 | [diff] [blame] | 1872 | AppOpsManager.MODE_DEFAULT, // LEGACY_STORAGE |
Jackal Guo | 8dc791e | 2019-01-14 10:26:42 +0800 | [diff] [blame] | 1873 | AppOpsManager.MODE_ALLOWED, // ACCESS_ACCESSIBILITY |
Michael Groover | 656ef91 | 2019-04-09 17:09:57 -0700 | [diff] [blame] | 1874 | AppOpsManager.MODE_ERRORED, // READ_DEVICE_IDENTIFIERS |
Philip P. Moltmann | ac7b10c | 2019-09-13 15:12:34 -0700 | [diff] [blame] | 1875 | AppOpsManager.MODE_ALLOWED, // ALLOW_MEDIA_LOCATION |
David Braun | f5d8319 | 2013-09-16 13:43:51 -0700 | [diff] [blame] | 1876 | }; |
| 1877 | |
Dianne Hackborn | 8828d3a | 2013-09-25 16:47:10 -0700 | [diff] [blame] | 1878 | /** |
| 1879 | * This specifies whether each option is allowed to be reset |
| 1880 | * when resetting all app preferences. Disable reset for |
| 1881 | * app ops that are under strong control of some part of the |
| 1882 | * system (such as OP_WRITE_SMS, which should be allowed only |
| 1883 | * for whichever app is selected as the current SMS app). |
| 1884 | */ |
| 1885 | private static boolean[] sOpDisableReset = new boolean[] { |
Eugene Susla | 9351985 | 2018-06-13 16:44:31 -0700 | [diff] [blame] | 1886 | false, // COARSE_LOCATION |
| 1887 | false, // FINE_LOCATION |
| 1888 | false, // GPS |
| 1889 | false, // VIBRATE |
| 1890 | false, // READ_CONTACTS |
| 1891 | false, // WRITE_CONTACTS |
| 1892 | false, // READ_CALL_LOG |
| 1893 | false, // WRITE_CALL_LOG |
| 1894 | false, // READ_CALENDAR |
| 1895 | false, // WRITE_CALENDAR |
| 1896 | false, // WIFI_SCAN |
| 1897 | false, // POST_NOTIFICATION |
| 1898 | false, // NEIGHBORING_CELLS |
| 1899 | false, // CALL_PHONE |
| 1900 | true, // READ_SMS |
| 1901 | true, // WRITE_SMS |
| 1902 | true, // RECEIVE_SMS |
| 1903 | false, // RECEIVE_EMERGENCY_BROADCAST |
| 1904 | false, // RECEIVE_MMS |
| 1905 | true, // RECEIVE_WAP_PUSH |
| 1906 | true, // SEND_SMS |
| 1907 | false, // READ_ICC_SMS |
| 1908 | false, // WRITE_ICC_SMS |
| 1909 | false, // WRITE_SETTINGS |
| 1910 | false, // SYSTEM_ALERT_WINDOW |
| 1911 | false, // ACCESS_NOTIFICATIONS |
| 1912 | false, // CAMERA |
| 1913 | false, // RECORD_AUDIO |
| 1914 | false, // PLAY_AUDIO |
| 1915 | false, // READ_CLIPBOARD |
| 1916 | false, // WRITE_CLIPBOARD |
| 1917 | false, // TAKE_MEDIA_BUTTONS |
| 1918 | false, // TAKE_AUDIO_FOCUS |
| 1919 | false, // AUDIO_MASTER_VOLUME |
| 1920 | false, // AUDIO_VOICE_VOLUME |
| 1921 | false, // AUDIO_RING_VOLUME |
| 1922 | false, // AUDIO_MEDIA_VOLUME |
| 1923 | false, // AUDIO_ALARM_VOLUME |
| 1924 | false, // AUDIO_NOTIFICATION_VOLUME |
| 1925 | false, // AUDIO_BLUETOOTH_VOLUME |
| 1926 | false, // WAKE_LOCK |
| 1927 | false, // MONITOR_LOCATION |
| 1928 | false, // MONITOR_HIGH_POWER_LOCATION |
| 1929 | false, // GET_USAGE_STATS |
| 1930 | false, // MUTE_MICROPHONE |
| 1931 | false, // TOAST_WINDOW |
| 1932 | false, // PROJECT_MEDIA |
| 1933 | false, // ACTIVATE_VPN |
| 1934 | false, // WRITE_WALLPAPER |
| 1935 | false, // ASSIST_STRUCTURE |
| 1936 | false, // ASSIST_SCREENSHOT |
| 1937 | false, // READ_PHONE_STATE |
| 1938 | false, // ADD_VOICEMAIL |
| 1939 | false, // USE_SIP |
| 1940 | false, // PROCESS_OUTGOING_CALLS |
| 1941 | false, // USE_FINGERPRINT |
| 1942 | false, // BODY_SENSORS |
| 1943 | true, // READ_CELL_BROADCASTS |
| 1944 | false, // MOCK_LOCATION |
| 1945 | false, // READ_EXTERNAL_STORAGE |
| 1946 | false, // WRITE_EXTERNAL_STORAGE |
| 1947 | false, // TURN_SCREEN_ON |
| 1948 | false, // GET_ACCOUNTS |
| 1949 | false, // RUN_IN_BACKGROUND |
| 1950 | false, // AUDIO_ACCESSIBILITY_VOLUME |
| 1951 | false, // READ_PHONE_NUMBERS |
| 1952 | false, // REQUEST_INSTALL_PACKAGES |
| 1953 | false, // PICTURE_IN_PICTURE |
| 1954 | false, // INSTANT_APP_START_FOREGROUND |
Eugene Susla | cae3d3e | 2017-01-31 11:08:11 -0800 | [diff] [blame] | 1955 | false, // ANSWER_PHONE_CALLS |
Eugene Susla | 9351985 | 2018-06-13 16:44:31 -0700 | [diff] [blame] | 1956 | false, // RUN_ANY_IN_BACKGROUND |
| 1957 | false, // CHANGE_WIFI_STATE |
| 1958 | false, // REQUEST_DELETE_PACKAGES |
| 1959 | false, // BIND_ACCESSIBILITY_SERVICE |
Tyler Gunn | 79bc1ec | 2018-01-22 15:17:54 -0800 | [diff] [blame] | 1960 | false, // ACCEPT_HANDOVER |
Nathan Harold | 1bb42067 | 2018-03-14 17:08:53 -0700 | [diff] [blame] | 1961 | false, // MANAGE_IPSEC_TUNNELS |
Dianne Hackborn | e9d9b4b | 2018-03-28 13:51:46 -0700 | [diff] [blame] | 1962 | false, // START_FOREGROUND |
Dianne Hackborn | e04f13d | 2018-05-02 12:51:52 -0700 | [diff] [blame] | 1963 | false, // BLUETOOTH_SCAN |
Kevin Chyn | b3c05aa | 2018-09-21 16:50:32 -0700 | [diff] [blame] | 1964 | false, // USE_BIOMETRIC |
Zimuzo | 6cbf9cc | 2018-10-05 12:05:58 +0100 | [diff] [blame] | 1965 | false, // ACTIVITY_RECOGNITION |
Hongming Jin | 228cd01 | 2018-11-09 14:47:50 -0800 | [diff] [blame] | 1966 | false, // SMS_FINANCIAL_TRANSACTIONS |
Jeff Sharkey | d2a1f0d | 2018-11-19 10:32:52 -0700 | [diff] [blame] | 1967 | false, // READ_MEDIA_AUDIO |
| 1968 | false, // WRITE_MEDIA_AUDIO |
| 1969 | false, // READ_MEDIA_VIDEO |
| 1970 | false, // WRITE_MEDIA_VIDEO |
| 1971 | false, // READ_MEDIA_IMAGES |
| 1972 | false, // WRITE_MEDIA_IMAGES |
Jeff Sharkey | e82cbb1 | 2018-12-06 15:53:11 -0700 | [diff] [blame] | 1973 | false, // LEGACY_STORAGE |
Jackal Guo | 8dc791e | 2019-01-14 10:26:42 +0800 | [diff] [blame] | 1974 | false, // ACCESS_ACCESSIBILITY |
Michael Groover | 656ef91 | 2019-04-09 17:09:57 -0700 | [diff] [blame] | 1975 | false, // READ_DEVICE_IDENTIFIERS |
Philip P. Moltmann | ac7b10c | 2019-09-13 15:12:34 -0700 | [diff] [blame] | 1976 | false, // ACCESS_MEDIA_LOCATION |
Dianne Hackborn | 8828d3a | 2013-09-25 16:47:10 -0700 | [diff] [blame] | 1977 | }; |
| 1978 | |
Svet Ganov | fbf01f7 | 2015-04-28 18:39:06 -0700 | [diff] [blame] | 1979 | /** |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 1980 | * Mapping from an app op name to the app op code. |
Svet Ganov | fbf01f7 | 2015-04-28 18:39:06 -0700 | [diff] [blame] | 1981 | */ |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 1982 | private static HashMap<String, Integer> sOpStrToOp = new HashMap<>(); |
Svet Ganov | fbf01f7 | 2015-04-28 18:39:06 -0700 | [diff] [blame] | 1983 | |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 1984 | /** |
| 1985 | * Mapping from a permission to the corresponding app op. |
| 1986 | */ |
Svet Ganov | da0acdf | 2017-02-15 10:28:51 -0800 | [diff] [blame] | 1987 | private static HashMap<String, Integer> sPermToOp = new HashMap<>(); |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 1988 | |
| 1989 | static { |
| 1990 | if (sOpToSwitch.length != _NUM_OP) { |
Dianne Hackborn | 8828d3a | 2013-09-25 16:47:10 -0700 | [diff] [blame] | 1991 | throw new IllegalStateException("sOpToSwitch length " + sOpToSwitch.length |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 1992 | + " should be " + _NUM_OP); |
| 1993 | } |
| 1994 | if (sOpToString.length != _NUM_OP) { |
Dianne Hackborn | 8828d3a | 2013-09-25 16:47:10 -0700 | [diff] [blame] | 1995 | throw new IllegalStateException("sOpToString length " + sOpToString.length |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 1996 | + " should be " + _NUM_OP); |
| 1997 | } |
| 1998 | if (sOpNames.length != _NUM_OP) { |
Dianne Hackborn | 8828d3a | 2013-09-25 16:47:10 -0700 | [diff] [blame] | 1999 | throw new IllegalStateException("sOpNames length " + sOpNames.length |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 2000 | + " should be " + _NUM_OP); |
| 2001 | } |
| 2002 | if (sOpPerms.length != _NUM_OP) { |
Dianne Hackborn | 8828d3a | 2013-09-25 16:47:10 -0700 | [diff] [blame] | 2003 | throw new IllegalStateException("sOpPerms length " + sOpPerms.length |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 2004 | + " should be " + _NUM_OP); |
| 2005 | } |
| 2006 | if (sOpDefaultMode.length != _NUM_OP) { |
Dianne Hackborn | 8828d3a | 2013-09-25 16:47:10 -0700 | [diff] [blame] | 2007 | throw new IllegalStateException("sOpDefaultMode length " + sOpDefaultMode.length |
| 2008 | + " should be " + _NUM_OP); |
| 2009 | } |
| 2010 | if (sOpDisableReset.length != _NUM_OP) { |
| 2011 | throw new IllegalStateException("sOpDisableReset length " + sOpDisableReset.length |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 2012 | + " should be " + _NUM_OP); |
| 2013 | } |
Jason Monk | 6206299 | 2014-05-06 09:55:28 -0400 | [diff] [blame] | 2014 | if (sOpRestrictions.length != _NUM_OP) { |
| 2015 | throw new IllegalStateException("sOpRestrictions length " + sOpRestrictions.length |
| 2016 | + " should be " + _NUM_OP); |
| 2017 | } |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 2018 | if (sOpAllowSystemRestrictionBypass.length != _NUM_OP) { |
| 2019 | throw new IllegalStateException("sOpAllowSYstemRestrictionsBypass length " |
| 2020 | + sOpRestrictions.length + " should be " + _NUM_OP); |
| 2021 | } |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 2022 | for (int i=0; i<_NUM_OP; i++) { |
| 2023 | if (sOpToString[i] != null) { |
| 2024 | sOpStrToOp.put(sOpToString[i], i); |
| 2025 | } |
| 2026 | } |
Svet Ganov | da0acdf | 2017-02-15 10:28:51 -0800 | [diff] [blame] | 2027 | for (int op : RUNTIME_AND_APPOP_PERMISSIONS_OPS) { |
Svetoslav Ganov | eaca4c5 | 2016-05-05 18:08:00 -0700 | [diff] [blame] | 2028 | if (sOpPerms[op] != null) { |
Svet Ganov | da0acdf | 2017-02-15 10:28:51 -0800 | [diff] [blame] | 2029 | sPermToOp.put(sOpPerms[op], op); |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 2030 | } |
| 2031 | } |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 2032 | } |
| 2033 | |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 2034 | /** @hide */ |
| 2035 | public static final String KEY_HISTORICAL_OPS = "historical_ops"; |
| 2036 | |
Chad Brubaker | 7c6dba6 | 2019-01-23 15:51:43 -0800 | [diff] [blame] | 2037 | /** System properties for debug logging of noteOp call sites */ |
| 2038 | private static final String DEBUG_LOGGING_ENABLE_PROP = "appops.logging_enabled"; |
| 2039 | private static final String DEBUG_LOGGING_PACKAGES_PROP = "appops.logging_packages"; |
| 2040 | private static final String DEBUG_LOGGING_OPS_PROP = "appops.logging_ops"; |
| 2041 | private static final String DEBUG_LOGGING_TAG = "AppOpsManager"; |
| 2042 | |
David Braun | f5d8319 | 2013-09-16 13:43:51 -0700 | [diff] [blame] | 2043 | /** |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 2044 | * Retrieve the op switch that controls the given operation. |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 2045 | * @hide |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 2046 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 2047 | @UnsupportedAppUsage |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 2048 | public static int opToSwitch(int op) { |
| 2049 | return sOpToSwitch[op]; |
| 2050 | } |
| 2051 | |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 2052 | /** |
| 2053 | * Retrieve a non-localized name for the operation, for debugging output. |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 2054 | * @hide |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 2055 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 2056 | @UnsupportedAppUsage |
Dianne Hackborn | 5e45ee6 | 2013-01-24 19:13:44 -0800 | [diff] [blame] | 2057 | public static String opToName(int op) { |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 2058 | if (op == OP_NONE) return "NONE"; |
Dianne Hackborn | 5e45ee6 | 2013-01-24 19:13:44 -0800 | [diff] [blame] | 2059 | return op < sOpNames.length ? sOpNames[op] : ("Unknown(" + op + ")"); |
| 2060 | } |
| 2061 | |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 2062 | /** |
Svet Ganov | 65f1b9e | 2019-01-17 19:19:40 -0800 | [diff] [blame] | 2063 | * Retrieve a non-localized public name for the operation. |
| 2064 | * |
| 2065 | * @hide |
| 2066 | */ |
| 2067 | public static @NonNull String opToPublicName(int op) { |
| 2068 | return sOpToString[op]; |
| 2069 | } |
| 2070 | |
| 2071 | /** |
Dianne Hackborn | 7b7c58b | 2014-12-02 18:32:20 -0800 | [diff] [blame] | 2072 | * @hide |
| 2073 | */ |
| 2074 | public static int strDebugOpToOp(String op) { |
| 2075 | for (int i=0; i<sOpNames.length; i++) { |
| 2076 | if (sOpNames[i].equals(op)) { |
| 2077 | return i; |
| 2078 | } |
| 2079 | } |
| 2080 | throw new IllegalArgumentException("Unknown operation string: " + op); |
| 2081 | } |
| 2082 | |
| 2083 | /** |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 2084 | * 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] | 2085 | * @hide |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 2086 | */ |
Artur Satayev | 5a52585 | 2019-10-31 15:15:50 +0000 | [diff] [blame] | 2087 | @UnsupportedAppUsage |
Philip P. Moltmann | 3311515 | 2018-04-11 13:39:36 -0700 | [diff] [blame] | 2088 | @TestApi |
Dianne Hackborn | 5e45ee6 | 2013-01-24 19:13:44 -0800 | [diff] [blame] | 2089 | public static String opToPermission(int op) { |
| 2090 | return sOpPerms[op]; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 2091 | } |
| 2092 | |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 2093 | /** |
Hai Zhang | b777668 | 2018-09-25 15:10:57 -0700 | [diff] [blame] | 2094 | * Retrieve the permission associated with an operation, or null if there is not one. |
| 2095 | * |
| 2096 | * @param op The operation name. |
| 2097 | * |
| 2098 | * @hide |
| 2099 | */ |
| 2100 | @Nullable |
| 2101 | @SystemApi |
| 2102 | public static String opToPermission(@NonNull String op) { |
| 2103 | return opToPermission(strOpToOp(op)); |
| 2104 | } |
| 2105 | |
| 2106 | /** |
Jason Monk | 6206299 | 2014-05-06 09:55:28 -0400 | [diff] [blame] | 2107 | * Retrieve the user restriction associated with an operation, or null if there is not one. |
| 2108 | * @hide |
| 2109 | */ |
| 2110 | public static String opToRestriction(int op) { |
| 2111 | return sOpRestrictions[op]; |
| 2112 | } |
| 2113 | |
| 2114 | /** |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 2115 | * 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] | 2116 | * This API is intended to be used for mapping runtime or appop permissions |
| 2117 | * to the corresponding app op. |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 2118 | * @hide |
| 2119 | */ |
Artur Satayev | 5a52585 | 2019-10-31 15:15:50 +0000 | [diff] [blame] | 2120 | @UnsupportedAppUsage |
Philip P. Moltmann | 3311515 | 2018-04-11 13:39:36 -0700 | [diff] [blame] | 2121 | @TestApi |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 2122 | public static int permissionToOpCode(String permission) { |
Svet Ganov | da0acdf | 2017-02-15 10:28:51 -0800 | [diff] [blame] | 2123 | Integer boxedOpCode = sPermToOp.get(permission); |
Svet Ganov | 019d230 | 2015-05-04 11:07:38 -0700 | [diff] [blame] | 2124 | return boxedOpCode != null ? boxedOpCode : OP_NONE; |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 2125 | } |
| 2126 | |
| 2127 | /** |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 2128 | * Retrieve whether the op allows the system (and system ui) to |
| 2129 | * bypass the user restriction. |
| 2130 | * @hide |
| 2131 | */ |
| 2132 | public static boolean opAllowSystemBypassRestriction(int op) { |
| 2133 | return sOpAllowSystemRestrictionBypass[op]; |
| 2134 | } |
| 2135 | |
| 2136 | /** |
David Braun | f5d8319 | 2013-09-16 13:43:51 -0700 | [diff] [blame] | 2137 | * Retrieve the default mode for the operation. |
| 2138 | * @hide |
| 2139 | */ |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 2140 | public static @Mode int opToDefaultMode(int op) { |
David Braun | f5d8319 | 2013-09-16 13:43:51 -0700 | [diff] [blame] | 2141 | return sOpDefaultMode[op]; |
| 2142 | } |
| 2143 | |
| 2144 | /** |
Hai Zhang | c595f11 | 2018-11-06 14:20:38 -0800 | [diff] [blame] | 2145 | * Retrieve the default mode for the app op. |
| 2146 | * |
| 2147 | * @param appOp The app op name |
| 2148 | * |
| 2149 | * @return the default mode for the app op |
| 2150 | * |
| 2151 | * @hide |
| 2152 | */ |
Svet Ganov | 8e5bf96 | 2019-03-19 23:59:03 -0700 | [diff] [blame] | 2153 | @TestApi |
Hai Zhang | c595f11 | 2018-11-06 14:20:38 -0800 | [diff] [blame] | 2154 | @SystemApi |
| 2155 | public static int opToDefaultMode(@NonNull String appOp) { |
| 2156 | return opToDefaultMode(strOpToOp(appOp)); |
| 2157 | } |
| 2158 | |
| 2159 | /** |
Svet Ganov | 82f09bc | 2018-01-12 22:08:40 -0800 | [diff] [blame] | 2160 | * Retrieve the human readable mode. |
| 2161 | * @hide |
| 2162 | */ |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 2163 | public static String modeToName(@Mode int mode) { |
Dianne Hackborn | c216a26 | 2018-04-26 13:46:22 -0700 | [diff] [blame] | 2164 | if (mode >= 0 && mode < MODE_NAMES.length) { |
| 2165 | return MODE_NAMES[mode]; |
Svet Ganov | 82f09bc | 2018-01-12 22:08:40 -0800 | [diff] [blame] | 2166 | } |
Dianne Hackborn | c216a26 | 2018-04-26 13:46:22 -0700 | [diff] [blame] | 2167 | return "mode=" + mode; |
Svet Ganov | 82f09bc | 2018-01-12 22:08:40 -0800 | [diff] [blame] | 2168 | } |
| 2169 | |
| 2170 | /** |
Dianne Hackborn | 8828d3a | 2013-09-25 16:47:10 -0700 | [diff] [blame] | 2171 | * Retrieve whether the op allows itself to be reset. |
| 2172 | * @hide |
| 2173 | */ |
| 2174 | public static boolean opAllowsReset(int op) { |
| 2175 | return !sOpDisableReset[op]; |
| 2176 | } |
| 2177 | |
| 2178 | /** |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 2179 | * Class holding all of the operation information associated with an app. |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 2180 | * @hide |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 2181 | */ |
Dianne Hackborn | f0c322a | 2018-06-13 15:24:04 -0700 | [diff] [blame] | 2182 | @SystemApi |
| 2183 | public static final class PackageOps implements Parcelable { |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 2184 | private final String mPackageName; |
| 2185 | private final int mUid; |
| 2186 | private final List<OpEntry> mEntries; |
| 2187 | |
Dianne Hackborn | f0c322a | 2018-06-13 15:24:04 -0700 | [diff] [blame] | 2188 | /** |
| 2189 | * @hide |
| 2190 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 2191 | @UnsupportedAppUsage |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 2192 | public PackageOps(String packageName, int uid, List<OpEntry> entries) { |
| 2193 | mPackageName = packageName; |
| 2194 | mUid = uid; |
| 2195 | mEntries = entries; |
| 2196 | } |
| 2197 | |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 2198 | /** |
| 2199 | * @return The name of the package. |
| 2200 | */ |
| 2201 | public @NonNull String getPackageName() { |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 2202 | return mPackageName; |
| 2203 | } |
| 2204 | |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 2205 | /** |
| 2206 | * @return The uid of the package. |
| 2207 | */ |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 2208 | public int getUid() { |
| 2209 | return mUid; |
| 2210 | } |
| 2211 | |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 2212 | /** |
| 2213 | * @return The ops of the package. |
| 2214 | */ |
Dianne Hackborn | 6287849 | 2019-03-11 15:57:07 -0700 | [diff] [blame] | 2215 | public @NonNull List<OpEntry> getOps() { |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 2216 | return mEntries; |
| 2217 | } |
| 2218 | |
| 2219 | @Override |
| 2220 | public int describeContents() { |
| 2221 | return 0; |
| 2222 | } |
| 2223 | |
| 2224 | @Override |
| 2225 | public void writeToParcel(Parcel dest, int flags) { |
| 2226 | dest.writeString(mPackageName); |
| 2227 | dest.writeInt(mUid); |
| 2228 | dest.writeInt(mEntries.size()); |
| 2229 | for (int i=0; i<mEntries.size(); i++) { |
| 2230 | mEntries.get(i).writeToParcel(dest, flags); |
| 2231 | } |
| 2232 | } |
| 2233 | |
| 2234 | PackageOps(Parcel source) { |
| 2235 | mPackageName = source.readString(); |
| 2236 | mUid = source.readInt(); |
| 2237 | mEntries = new ArrayList<OpEntry>(); |
| 2238 | final int N = source.readInt(); |
| 2239 | for (int i=0; i<N; i++) { |
| 2240 | mEntries.add(OpEntry.CREATOR.createFromParcel(source)); |
| 2241 | } |
| 2242 | } |
| 2243 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 2244 | public static final @android.annotation.NonNull Creator<PackageOps> CREATOR = new Creator<PackageOps>() { |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 2245 | @Override public PackageOps createFromParcel(Parcel source) { |
| 2246 | return new PackageOps(source); |
| 2247 | } |
| 2248 | |
| 2249 | @Override public PackageOps[] newArray(int size) { |
| 2250 | return new PackageOps[size]; |
| 2251 | } |
| 2252 | }; |
| 2253 | } |
| 2254 | |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 2255 | /** |
| 2256 | * Class holding the information about one unique operation of an application. |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 2257 | * @hide |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 2258 | */ |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 2259 | @TestApi |
| 2260 | @Immutable |
Dianne Hackborn | f0c322a | 2018-06-13 15:24:04 -0700 | [diff] [blame] | 2261 | @SystemApi |
| 2262 | public static final class OpEntry implements Parcelable { |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 2263 | private final int mOp; |
Amith Yamasani | a1ce963 | 2018-05-28 20:50:48 -0700 | [diff] [blame] | 2264 | private final boolean mRunning; |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 2265 | private final @Mode int mMode; |
| 2266 | private final @Nullable LongSparseLongArray mAccessTimes; |
| 2267 | private final @Nullable LongSparseLongArray mRejectTimes; |
| 2268 | private final @Nullable LongSparseLongArray mDurations; |
| 2269 | private final @Nullable LongSparseLongArray mProxyUids; |
| 2270 | private final @Nullable LongSparseArray<String> mProxyPackageNames; |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 2271 | |
Dianne Hackborn | f0c322a | 2018-06-13 15:24:04 -0700 | [diff] [blame] | 2272 | /** |
| 2273 | * @hide |
| 2274 | */ |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 2275 | public OpEntry(int op, boolean running, @Mode int mode, |
| 2276 | @Nullable LongSparseLongArray accessTimes, @Nullable LongSparseLongArray rejectTimes, |
| 2277 | @Nullable LongSparseLongArray durations, @Nullable LongSparseLongArray proxyUids, |
| 2278 | @Nullable LongSparseArray<String> proxyPackageNames) { |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 2279 | mOp = op; |
Amith Yamasani | a1ce963 | 2018-05-28 20:50:48 -0700 | [diff] [blame] | 2280 | mRunning = running; |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 2281 | mMode = mode; |
| 2282 | mAccessTimes = accessTimes; |
| 2283 | mRejectTimes = rejectTimes; |
| 2284 | mDurations = durations; |
| 2285 | mProxyUids = proxyUids; |
| 2286 | mProxyPackageNames = proxyPackageNames; |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 2287 | } |
| 2288 | |
Dianne Hackborn | f0c322a | 2018-06-13 15:24:04 -0700 | [diff] [blame] | 2289 | /** |
| 2290 | * @hide |
| 2291 | */ |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 2292 | public OpEntry(int op, @Mode int mode) { |
| 2293 | mOp = op; |
| 2294 | mMode = mode; |
| 2295 | mRunning = false; |
| 2296 | mAccessTimes = null; |
| 2297 | mRejectTimes = null; |
| 2298 | mDurations = null; |
| 2299 | mProxyUids = null; |
| 2300 | mProxyPackageNames = null; |
| 2301 | } |
| 2302 | |
| 2303 | /** |
| 2304 | * Returns all keys for which we have mapped state in any of the data buckets - |
| 2305 | * access time, reject time, duration. |
| 2306 | * @hide */ |
| 2307 | public @Nullable LongSparseArray<Object> collectKeys() { |
| 2308 | LongSparseArray<Object> result = AppOpsManager.collectKeys(mAccessTimes, null); |
| 2309 | result = AppOpsManager.collectKeys(mRejectTimes, result); |
| 2310 | result = AppOpsManager.collectKeys(mDurations, result); |
| 2311 | return result; |
Amith Yamasani | a1ce963 | 2018-05-28 20:50:48 -0700 | [diff] [blame] | 2312 | } |
| 2313 | |
Dianne Hackborn | f0c322a | 2018-06-13 15:24:04 -0700 | [diff] [blame] | 2314 | /** |
| 2315 | * @hide |
| 2316 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 2317 | @UnsupportedAppUsage |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 2318 | public int getOp() { |
| 2319 | return mOp; |
| 2320 | } |
| 2321 | |
Dianne Hackborn | f0c322a | 2018-06-13 15:24:04 -0700 | [diff] [blame] | 2322 | /** |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 2323 | * @return This entry's op string name, such as {@link #OPSTR_COARSE_LOCATION}. |
Dianne Hackborn | f0c322a | 2018-06-13 15:24:04 -0700 | [diff] [blame] | 2324 | */ |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 2325 | public @NonNull String getOpStr() { |
Dianne Hackborn | f0c322a | 2018-06-13 15:24:04 -0700 | [diff] [blame] | 2326 | return sOpToString[mOp]; |
| 2327 | } |
| 2328 | |
| 2329 | /** |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 2330 | * @return this entry's current mode, such as {@link #MODE_ALLOWED}. |
Dianne Hackborn | f0c322a | 2018-06-13 15:24:04 -0700 | [diff] [blame] | 2331 | */ |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 2332 | public @Mode int getMode() { |
Dianne Hackborn | 5e45ee6 | 2013-01-24 19:13:44 -0800 | [diff] [blame] | 2333 | return mMode; |
| 2334 | } |
| 2335 | |
Dianne Hackborn | f0c322a | 2018-06-13 15:24:04 -0700 | [diff] [blame] | 2336 | /** |
| 2337 | * @hide |
| 2338 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 2339 | @UnsupportedAppUsage |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 2340 | public long getTime() { |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 2341 | return getLastAccessTime(OP_FLAGS_ALL); |
Dianne Hackborn | cd1f30b | 2018-04-23 17:38:09 -0700 | [diff] [blame] | 2342 | } |
| 2343 | |
Dianne Hackborn | f0c322a | 2018-06-13 15:24:04 -0700 | [diff] [blame] | 2344 | /** |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 2345 | * Return the last wall clock time in milliseconds this op was accessed. |
| 2346 | * |
| 2347 | * @param flags The flags which are any combination of |
| 2348 | * {@link #OP_FLAG_SELF}, {@link #OP_FLAG_TRUSTED_PROXY}, |
| 2349 | * {@link #OP_FLAG_UNTRUSTED_PROXY}, {@link #OP_FLAG_TRUSTED_PROXIED}, |
| 2350 | * {@link #OP_FLAG_UNTRUSTED_PROXIED}. You can use {@link #OP_FLAGS_ALL} |
| 2351 | * for any flag. |
| 2352 | * @return the last access time in milliseconds since |
| 2353 | * epoch start (January 1, 1970 00:00:00.000 GMT - Gregorian). |
| 2354 | * |
| 2355 | * @see #getLastAccessForegroundTime(int) |
| 2356 | * @see #getLastAccessBackgroundTime(int) |
| 2357 | * @see #getLastAccessTime(int, int, int) |
Dianne Hackborn | f0c322a | 2018-06-13 15:24:04 -0700 | [diff] [blame] | 2358 | */ |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 2359 | public long getLastAccessTime(@OpFlags int flags) { |
| 2360 | return maxForFlagsInStates(mAccessTimes, MAX_PRIORITY_UID_STATE, |
| 2361 | MIN_PRIORITY_UID_STATE, flags); |
Dianne Hackborn | c216a26 | 2018-04-26 13:46:22 -0700 | [diff] [blame] | 2362 | } |
| 2363 | |
Dianne Hackborn | f0c322a | 2018-06-13 15:24:04 -0700 | [diff] [blame] | 2364 | /** |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 2365 | * Return the last wall clock time in milliseconds this op was accessed |
| 2366 | * by the app while in the foreground. |
| 2367 | * |
| 2368 | * @param flags The flags which are any combination of |
| 2369 | * {@link #OP_FLAG_SELF}, {@link #OP_FLAG_TRUSTED_PROXY}, |
| 2370 | * {@link #OP_FLAG_UNTRUSTED_PROXY}, {@link #OP_FLAG_TRUSTED_PROXIED}, |
| 2371 | * {@link #OP_FLAG_UNTRUSTED_PROXIED}. You can use {@link #OP_FLAGS_ALL} |
| 2372 | * for any flag. |
| 2373 | * @return the last foreground access time in milliseconds since |
| 2374 | * epoch start (January 1, 1970 00:00:00.000 GMT - Gregorian). |
| 2375 | * |
| 2376 | * @see #getLastAccessBackgroundTime(int) |
| 2377 | * @see #getLastAccessTime(int) |
| 2378 | * @see #getLastAccessTime(int, int, int) |
Dianne Hackborn | f0c322a | 2018-06-13 15:24:04 -0700 | [diff] [blame] | 2379 | */ |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 2380 | public long getLastAccessForegroundTime(@OpFlags int flags) { |
| 2381 | return maxForFlagsInStates(mAccessTimes, MAX_PRIORITY_UID_STATE, |
| 2382 | resolveFirstUnrestrictedUidState(mOp), flags); |
Dianne Hackborn | c216a26 | 2018-04-26 13:46:22 -0700 | [diff] [blame] | 2383 | } |
| 2384 | |
Dianne Hackborn | f0c322a | 2018-06-13 15:24:04 -0700 | [diff] [blame] | 2385 | /** |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 2386 | * Return the last wall clock time in milliseconds this op was accessed |
| 2387 | * by the app while in the background. |
| 2388 | * |
| 2389 | * @param flags The flags which are any combination of |
| 2390 | * {@link #OP_FLAG_SELF}, {@link #OP_FLAG_TRUSTED_PROXY}, |
| 2391 | * {@link #OP_FLAG_UNTRUSTED_PROXY}, {@link #OP_FLAG_TRUSTED_PROXIED}, |
| 2392 | * {@link #OP_FLAG_UNTRUSTED_PROXIED}. You can use {@link #OP_FLAGS_ALL} |
| 2393 | * for any flag. |
| 2394 | * @return the last foreground access time in milliseconds since |
| 2395 | * epoch start (January 1, 1970 00:00:00.000 GMT - Gregorian). |
| 2396 | * |
| 2397 | * @see #getLastAccessForegroundTime(int) |
| 2398 | * @see #getLastAccessTime(int) |
| 2399 | * @see #getLastAccessTime(int, int, int) |
Dianne Hackborn | f0c322a | 2018-06-13 15:24:04 -0700 | [diff] [blame] | 2400 | */ |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 2401 | public long getLastAccessBackgroundTime(@OpFlags int flags) { |
| 2402 | return maxForFlagsInStates(mAccessTimes, resolveLastRestrictedUidState(mOp), |
| 2403 | MIN_PRIORITY_UID_STATE, flags); |
Dianne Hackborn | c216a26 | 2018-04-26 13:46:22 -0700 | [diff] [blame] | 2404 | } |
| 2405 | |
Dianne Hackborn | f0c322a | 2018-06-13 15:24:04 -0700 | [diff] [blame] | 2406 | /** |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 2407 | * Return the last wall clock time in milliseconds this op was accessed |
| 2408 | * by the app for a given range of UID states. |
| 2409 | * |
| 2410 | * @param fromUidState The UID state for which to query. Could be one of |
| 2411 | * {@link #UID_STATE_PERSISTENT}, {@link #UID_STATE_TOP}, |
| 2412 | * {@link #UID_STATE_FOREGROUND_SERVICE}, {@link #UID_STATE_FOREGROUND}, |
| 2413 | * {@link #UID_STATE_BACKGROUND}, {@link #UID_STATE_CACHED}. |
| 2414 | * @param toUidState The UID state for which to query. |
| 2415 | * @param flags The flags which are any combination of |
| 2416 | * {@link #OP_FLAG_SELF}, {@link #OP_FLAG_TRUSTED_PROXY}, |
| 2417 | * {@link #OP_FLAG_UNTRUSTED_PROXY}, {@link #OP_FLAG_TRUSTED_PROXIED}, |
| 2418 | * {@link #OP_FLAG_UNTRUSTED_PROXIED}. You can use {@link #OP_FLAGS_ALL} |
| 2419 | * for any flag. |
| 2420 | * |
| 2421 | * @return the last foreground access time in milliseconds since |
| 2422 | * epoch start (January 1, 1970 00:00:00.000 GMT - Gregorian). |
| 2423 | * |
| 2424 | * @see #getLastAccessForegroundTime(int) |
| 2425 | * @see #getLastAccessBackgroundTime(int) |
| 2426 | * @see #getLastAccessTime(int) |
Dianne Hackborn | f0c322a | 2018-06-13 15:24:04 -0700 | [diff] [blame] | 2427 | */ |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 2428 | public long getLastAccessTime(@UidState int fromUidState, @UidState int toUidState, |
| 2429 | @OpFlags int flags) { |
| 2430 | return maxForFlagsInStates(mAccessTimes, fromUidState, toUidState, flags); |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 2431 | } |
| 2432 | |
Dianne Hackborn | f0c322a | 2018-06-13 15:24:04 -0700 | [diff] [blame] | 2433 | /** |
| 2434 | * @hide |
| 2435 | */ |
Andrei Onea | 2bbb654 | 2019-05-21 18:13:26 +0100 | [diff] [blame] | 2436 | @UnsupportedAppUsage |
Dianne Hackborn | 5e45ee6 | 2013-01-24 19:13:44 -0800 | [diff] [blame] | 2437 | public long getRejectTime() { |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 2438 | return getLastRejectTime(OP_FLAGS_ALL); |
Dianne Hackborn | cd1f30b | 2018-04-23 17:38:09 -0700 | [diff] [blame] | 2439 | } |
| 2440 | |
Dianne Hackborn | f0c322a | 2018-06-13 15:24:04 -0700 | [diff] [blame] | 2441 | /** |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 2442 | * Return the last wall clock time in milliseconds the app made an attempt |
| 2443 | * to access this op but was rejected. |
| 2444 | * |
| 2445 | * @param flags The flags which are any combination of |
| 2446 | * {@link #OP_FLAG_SELF}, {@link #OP_FLAG_TRUSTED_PROXY}, |
| 2447 | * {@link #OP_FLAG_UNTRUSTED_PROXY}, {@link #OP_FLAG_TRUSTED_PROXIED}, |
| 2448 | * {@link #OP_FLAG_UNTRUSTED_PROXIED}. You can use {@link #OP_FLAGS_ALL} |
| 2449 | * for any flag. |
| 2450 | * @return the last reject time in milliseconds since |
| 2451 | * epoch start (January 1, 1970 00:00:00.000 GMT - Gregorian). |
| 2452 | * |
| 2453 | * @see #getLastRejectBackgroundTime(int) |
| 2454 | * @see #getLastRejectForegroundTime(int) |
| 2455 | * @see #getLastRejectTime(int, int, int) |
Dianne Hackborn | f0c322a | 2018-06-13 15:24:04 -0700 | [diff] [blame] | 2456 | */ |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 2457 | public long getLastRejectTime(@OpFlags int flags) { |
| 2458 | return maxForFlagsInStates(mRejectTimes, MAX_PRIORITY_UID_STATE, |
| 2459 | MIN_PRIORITY_UID_STATE, flags); |
Dianne Hackborn | c216a26 | 2018-04-26 13:46:22 -0700 | [diff] [blame] | 2460 | } |
| 2461 | |
Dianne Hackborn | f0c322a | 2018-06-13 15:24:04 -0700 | [diff] [blame] | 2462 | /** |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 2463 | * Return the last wall clock time in milliseconds the app made an attempt |
| 2464 | * to access this op while in the foreground but was rejected. |
| 2465 | * |
| 2466 | * @param flags The flags which are any combination of |
| 2467 | * {@link #OP_FLAG_SELF}, {@link #OP_FLAG_TRUSTED_PROXY}, |
| 2468 | * {@link #OP_FLAG_UNTRUSTED_PROXY}, {@link #OP_FLAG_TRUSTED_PROXIED}, |
| 2469 | * {@link #OP_FLAG_UNTRUSTED_PROXIED}. You can use {@link #OP_FLAGS_ALL} |
| 2470 | * for any flag. |
| 2471 | * @return the last foreground reject time in milliseconds since |
| 2472 | * epoch start (January 1, 1970 00:00:00.000 GMT - Gregorian). |
| 2473 | * |
| 2474 | * @see #getLastRejectBackgroundTime(int) |
| 2475 | * @see #getLastRejectTime(int, int, int) |
| 2476 | * @see #getLastRejectTime(int) |
Dianne Hackborn | f0c322a | 2018-06-13 15:24:04 -0700 | [diff] [blame] | 2477 | */ |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 2478 | public long getLastRejectForegroundTime(@OpFlags int flags) { |
| 2479 | return maxForFlagsInStates(mRejectTimes, MAX_PRIORITY_UID_STATE, |
| 2480 | resolveFirstUnrestrictedUidState(mOp), flags); |
Dianne Hackborn | c216a26 | 2018-04-26 13:46:22 -0700 | [diff] [blame] | 2481 | } |
| 2482 | |
Dianne Hackborn | f0c322a | 2018-06-13 15:24:04 -0700 | [diff] [blame] | 2483 | /** |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 2484 | * Return the last wall clock time in milliseconds the app made an attempt |
| 2485 | * to access this op while in the background but was rejected. |
| 2486 | * |
| 2487 | * @param flags The flags which are any combination of |
| 2488 | * {@link #OP_FLAG_SELF}, {@link #OP_FLAG_TRUSTED_PROXY}, |
| 2489 | * {@link #OP_FLAG_UNTRUSTED_PROXY}, {@link #OP_FLAG_TRUSTED_PROXIED}, |
| 2490 | * {@link #OP_FLAG_UNTRUSTED_PROXIED}. You can use {@link #OP_FLAGS_ALL} |
| 2491 | * for any flag. |
| 2492 | * @return the last background reject time in milliseconds since |
| 2493 | * epoch start (January 1, 1970 00:00:00.000 GMT - Gregorian). |
| 2494 | * |
| 2495 | * @see #getLastRejectForegroundTime(int) |
| 2496 | * @see #getLastRejectTime(int, int, int) |
| 2497 | * @see #getLastRejectTime(int) |
Dianne Hackborn | f0c322a | 2018-06-13 15:24:04 -0700 | [diff] [blame] | 2498 | */ |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 2499 | public long getLastRejectBackgroundTime(@OpFlags int flags) { |
| 2500 | return maxForFlagsInStates(mRejectTimes, resolveLastRestrictedUidState(mOp), |
| 2501 | MIN_PRIORITY_UID_STATE, flags); |
Dianne Hackborn | c216a26 | 2018-04-26 13:46:22 -0700 | [diff] [blame] | 2502 | } |
| 2503 | |
Dianne Hackborn | f0c322a | 2018-06-13 15:24:04 -0700 | [diff] [blame] | 2504 | /** |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 2505 | * Return the last wall clock time state in milliseconds the app made an |
| 2506 | * attempt to access this op for a given range of UID states. |
| 2507 | * |
| 2508 | * @param fromUidState The UID state from which to query. Could be one of |
| 2509 | * {@link #UID_STATE_PERSISTENT}, {@link #UID_STATE_TOP}, |
| 2510 | * {@link #UID_STATE_FOREGROUND_SERVICE}, {@link #UID_STATE_FOREGROUND}, |
| 2511 | * {@link #UID_STATE_BACKGROUND}, {@link #UID_STATE_CACHED}. |
| 2512 | * @param toUidState The UID state to which to query. |
| 2513 | * @param flags The flags which are any combination of |
| 2514 | * {@link #OP_FLAG_SELF}, {@link #OP_FLAG_TRUSTED_PROXY}, |
| 2515 | * {@link #OP_FLAG_UNTRUSTED_PROXY}, {@link #OP_FLAG_TRUSTED_PROXIED}, |
| 2516 | * {@link #OP_FLAG_UNTRUSTED_PROXIED}. You can use {@link #OP_FLAGS_ALL} |
| 2517 | * for any flag. |
| 2518 | * @return the last foreground access time in milliseconds since |
| 2519 | * epoch start (January 1, 1970 00:00:00.000 GMT - Gregorian). |
| 2520 | * |
| 2521 | * @see #getLastRejectForegroundTime(int) |
| 2522 | * @see #getLastRejectBackgroundTime(int) |
| 2523 | * @see #getLastRejectTime(int) |
Dianne Hackborn | f0c322a | 2018-06-13 15:24:04 -0700 | [diff] [blame] | 2524 | */ |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 2525 | public long getLastRejectTime(@UidState int fromUidState, @UidState int toUidState, |
| 2526 | @OpFlags int flags) { |
| 2527 | return maxForFlagsInStates(mRejectTimes, fromUidState, toUidState, flags); |
Dianne Hackborn | 5e45ee6 | 2013-01-24 19:13:44 -0800 | [diff] [blame] | 2528 | } |
| 2529 | |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 2530 | /** |
| 2531 | * @return Whether the operation is running. |
| 2532 | */ |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 2533 | public boolean isRunning() { |
Amith Yamasani | a1ce963 | 2018-05-28 20:50:48 -0700 | [diff] [blame] | 2534 | return mRunning; |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 2535 | } |
| 2536 | |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 2537 | /** |
Svet Ganov | 6f672a3 | 2019-07-08 16:40:42 -0700 | [diff] [blame] | 2538 | * @return The duration of the operation in milliseconds. The duration is in wall time. |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 2539 | */ |
| 2540 | public long getDuration() { |
| 2541 | return getLastDuration(MAX_PRIORITY_UID_STATE, MIN_PRIORITY_UID_STATE, OP_FLAGS_ALL); |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 2542 | } |
| 2543 | |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 2544 | /** |
| 2545 | * Return the duration in milliseconds the app accessed this op while |
Svet Ganov | 6f672a3 | 2019-07-08 16:40:42 -0700 | [diff] [blame] | 2546 | * in the foreground. The duration is in wall time. |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 2547 | * |
| 2548 | * @param flags The flags which are any combination of |
| 2549 | * {@link #OP_FLAG_SELF}, {@link #OP_FLAG_TRUSTED_PROXY}, |
| 2550 | * {@link #OP_FLAG_UNTRUSTED_PROXY}, {@link #OP_FLAG_TRUSTED_PROXIED}, |
| 2551 | * {@link #OP_FLAG_UNTRUSTED_PROXIED}. You can use {@link #OP_FLAGS_ALL} |
| 2552 | * for any flag. |
| 2553 | * @return the foreground access duration in milliseconds. |
| 2554 | * |
| 2555 | * @see #getLastBackgroundDuration(int) |
| 2556 | * @see #getLastDuration(int, int, int) |
| 2557 | */ |
| 2558 | public long getLastForegroundDuration(@OpFlags int flags) { |
| 2559 | return sumForFlagsInStates(mDurations, MAX_PRIORITY_UID_STATE, |
| 2560 | resolveFirstUnrestrictedUidState(mOp), flags); |
| 2561 | } |
| 2562 | |
| 2563 | /** |
| 2564 | * Return the duration in milliseconds the app accessed this op while |
Svet Ganov | 6f672a3 | 2019-07-08 16:40:42 -0700 | [diff] [blame] | 2565 | * in the background. The duration is in wall time. |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 2566 | * |
| 2567 | * @param flags The flags which are any combination of |
| 2568 | * {@link #OP_FLAG_SELF}, {@link #OP_FLAG_TRUSTED_PROXY}, |
| 2569 | * {@link #OP_FLAG_UNTRUSTED_PROXY}, {@link #OP_FLAG_TRUSTED_PROXIED}, |
| 2570 | * {@link #OP_FLAG_UNTRUSTED_PROXIED}. You can use {@link #OP_FLAGS_ALL} |
| 2571 | * for any flag. |
| 2572 | * @return the background access duration in milliseconds. |
| 2573 | * |
| 2574 | * @see #getLastForegroundDuration(int) |
| 2575 | * @see #getLastDuration(int, int, int) |
| 2576 | */ |
| 2577 | public long getLastBackgroundDuration(@OpFlags int flags) { |
| 2578 | return sumForFlagsInStates(mDurations, resolveLastRestrictedUidState(mOp), |
| 2579 | MIN_PRIORITY_UID_STATE, flags); |
| 2580 | } |
| 2581 | |
| 2582 | /** |
| 2583 | * Return the duration in milliseconds the app accessed this op for |
Svet Ganov | 6f672a3 | 2019-07-08 16:40:42 -0700 | [diff] [blame] | 2584 | * a given range of UID states. The duration is in wall time. |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 2585 | * |
| 2586 | * @param fromUidState The UID state for which to query. Could be one of |
| 2587 | * {@link #UID_STATE_PERSISTENT}, {@link #UID_STATE_TOP}, |
| 2588 | * {@link #UID_STATE_FOREGROUND_SERVICE}, {@link #UID_STATE_FOREGROUND}, |
| 2589 | * {@link #UID_STATE_BACKGROUND}, {@link #UID_STATE_CACHED}. |
| 2590 | * @param toUidState The UID state for which to query. |
| 2591 | * @param flags The flags which are any combination of |
| 2592 | * {@link #OP_FLAG_SELF}, {@link #OP_FLAG_TRUSTED_PROXY}, |
| 2593 | * {@link #OP_FLAG_UNTRUSTED_PROXY}, {@link #OP_FLAG_TRUSTED_PROXIED}, |
| 2594 | * {@link #OP_FLAG_UNTRUSTED_PROXIED}. You can use {@link #OP_FLAGS_ALL} |
| 2595 | * for any flag. |
| 2596 | * @return the access duration in milliseconds. |
| 2597 | */ |
| 2598 | public long getLastDuration(@UidState int fromUidState, @UidState int toUidState, |
| 2599 | @OpFlags int flags) { |
| 2600 | return sumForFlagsInStates(mDurations, fromUidState, toUidState, flags); |
| 2601 | } |
| 2602 | |
| 2603 | /** |
| 2604 | * Gets the UID of the app that performed the op on behalf of this app and |
| 2605 | * as a result blamed the op on this app or {@link Process#INVALID_UID} if |
| 2606 | * there is no proxy. |
| 2607 | * |
| 2608 | * @return The proxy UID. |
| 2609 | */ |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 2610 | public int getProxyUid() { |
Philip P. Moltmann | 4052d36 | 2019-09-19 14:52:38 -0700 | [diff] [blame] | 2611 | return (int) findFirstNonNegativeForFlagsInStates(mProxyUids, |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 2612 | MAX_PRIORITY_UID_STATE, MIN_PRIORITY_UID_STATE, OP_FLAGS_ALL); |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 2613 | } |
| 2614 | |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 2615 | /** |
| 2616 | * Gets the UID of the app that performed the op on behalf of this app and |
| 2617 | * as a result blamed the op on this app or {@link Process#INVALID_UID} if |
| 2618 | * there is no proxy. |
| 2619 | * |
| 2620 | * @param uidState The UID state for which to query. Could be one of |
| 2621 | * {@link #UID_STATE_PERSISTENT}, {@link #UID_STATE_TOP}, |
| 2622 | * {@link #UID_STATE_FOREGROUND_SERVICE}, {@link #UID_STATE_FOREGROUND}, |
| 2623 | * {@link #UID_STATE_BACKGROUND}, {@link #UID_STATE_CACHED}. |
| 2624 | * @param flags The flags which are any combination of |
| 2625 | * {@link #OP_FLAG_SELF}, {@link #OP_FLAG_TRUSTED_PROXY}, |
| 2626 | * {@link #OP_FLAG_UNTRUSTED_PROXY}, {@link #OP_FLAG_TRUSTED_PROXIED}, |
| 2627 | * {@link #OP_FLAG_UNTRUSTED_PROXIED}. You can use {@link #OP_FLAGS_ALL} |
| 2628 | * for any flag. |
| 2629 | * |
| 2630 | * @return The proxy UID. |
| 2631 | */ |
| 2632 | public int getProxyUid(@UidState int uidState, @OpFlags int flags) { |
Philip P. Moltmann | 4052d36 | 2019-09-19 14:52:38 -0700 | [diff] [blame] | 2633 | return (int) findFirstNonNegativeForFlagsInStates(mProxyUids, |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 2634 | uidState, uidState, flags); |
| 2635 | } |
| 2636 | |
| 2637 | /** |
| 2638 | * Gets the package name of the app that performed the op on behalf of this |
| 2639 | * app and as a result blamed the op on this app or {@code null} |
| 2640 | * if there is no proxy. |
| 2641 | * |
| 2642 | * @return The proxy package name. |
| 2643 | */ |
| 2644 | public @Nullable String getProxyPackageName() { |
| 2645 | return findFirstNonNullForFlagsInStates(mProxyPackageNames, MAX_PRIORITY_UID_STATE, |
| 2646 | MIN_PRIORITY_UID_STATE, OP_FLAGS_ALL); |
| 2647 | } |
| 2648 | |
| 2649 | /** |
| 2650 | * Gets the package name of the app that performed the op on behalf of this |
| 2651 | * app and as a result blamed the op on this app for a UID state or |
| 2652 | * {@code null} if there is no proxy. |
| 2653 | * |
| 2654 | * @param uidState The UID state for which to query. Could be one of |
| 2655 | * {@link #UID_STATE_PERSISTENT}, {@link #UID_STATE_TOP}, |
| 2656 | * {@link #UID_STATE_FOREGROUND_SERVICE}, {@link #UID_STATE_FOREGROUND}, |
| 2657 | * {@link #UID_STATE_BACKGROUND}, {@link #UID_STATE_CACHED}. |
| 2658 | * @param flags The flags which are any combination of |
| 2659 | * {@link #OP_FLAG_SELF}, {@link #OP_FLAG_TRUSTED_PROXY}, |
| 2660 | * {@link #OP_FLAG_UNTRUSTED_PROXY}, {@link #OP_FLAG_TRUSTED_PROXIED}, |
| 2661 | * {@link #OP_FLAG_UNTRUSTED_PROXIED}. You can use {@link #OP_FLAGS_ALL} |
| 2662 | * for any flag. |
| 2663 | * @return The proxy package name. |
| 2664 | */ |
| 2665 | public @Nullable String getProxyPackageName(@UidState int uidState, @OpFlags int flags) { |
| 2666 | return findFirstNonNullForFlagsInStates(mProxyPackageNames, uidState, uidState, flags); |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 2667 | } |
| 2668 | |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 2669 | @Override |
| 2670 | public int describeContents() { |
| 2671 | return 0; |
| 2672 | } |
| 2673 | |
| 2674 | @Override |
| 2675 | public void writeToParcel(Parcel dest, int flags) { |
| 2676 | dest.writeInt(mOp); |
Dianne Hackborn | 5e45ee6 | 2013-01-24 19:13:44 -0800 | [diff] [blame] | 2677 | dest.writeInt(mMode); |
Amith Yamasani | a1ce963 | 2018-05-28 20:50:48 -0700 | [diff] [blame] | 2678 | dest.writeBoolean(mRunning); |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 2679 | writeLongSparseLongArrayToParcel(mAccessTimes, dest); |
| 2680 | writeLongSparseLongArrayToParcel(mRejectTimes, dest); |
| 2681 | writeLongSparseLongArrayToParcel(mDurations, dest); |
| 2682 | writeLongSparseLongArrayToParcel(mProxyUids, dest); |
| 2683 | writeLongSparseStringArrayToParcel(mProxyPackageNames, dest); |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 2684 | } |
| 2685 | |
| 2686 | OpEntry(Parcel source) { |
| 2687 | mOp = source.readInt(); |
Dianne Hackborn | 5e45ee6 | 2013-01-24 19:13:44 -0800 | [diff] [blame] | 2688 | mMode = source.readInt(); |
Amith Yamasani | a1ce963 | 2018-05-28 20:50:48 -0700 | [diff] [blame] | 2689 | mRunning = source.readBoolean(); |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 2690 | mAccessTimes = readLongSparseLongArrayFromParcel(source); |
| 2691 | mRejectTimes = readLongSparseLongArrayFromParcel(source); |
| 2692 | mDurations = readLongSparseLongArrayFromParcel(source); |
| 2693 | mProxyUids = readLongSparseLongArrayFromParcel(source); |
| 2694 | mProxyPackageNames = readLongSparseStringArrayFromParcel(source); |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 2695 | } |
| 2696 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 2697 | public static final @android.annotation.NonNull Creator<OpEntry> CREATOR = new Creator<OpEntry>() { |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 2698 | @Override public OpEntry createFromParcel(Parcel source) { |
| 2699 | return new OpEntry(source); |
| 2700 | } |
| 2701 | |
| 2702 | @Override public OpEntry[] newArray(int size) { |
| 2703 | return new OpEntry[size]; |
| 2704 | } |
| 2705 | }; |
| 2706 | } |
| 2707 | |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 2708 | /** @hide */ |
| 2709 | public interface HistoricalOpsVisitor { |
| 2710 | void visitHistoricalOps(@NonNull HistoricalOps ops); |
| 2711 | void visitHistoricalUidOps(@NonNull HistoricalUidOps ops); |
| 2712 | void visitHistoricalPackageOps(@NonNull HistoricalPackageOps ops); |
| 2713 | void visitHistoricalOp(@NonNull HistoricalOp ops); |
| 2714 | } |
| 2715 | |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 2716 | /** |
Svet Ganov | 23c88db | 2019-01-22 20:38:11 -0800 | [diff] [blame] | 2717 | * Request for getting historical app op usage. The request acts |
| 2718 | * as a filtering criteria when querying historical op usage. |
| 2719 | * |
| 2720 | * @hide |
| 2721 | */ |
| 2722 | @Immutable |
| 2723 | @TestApi |
| 2724 | @SystemApi |
| 2725 | public static final class HistoricalOpsRequest { |
| 2726 | private final int mUid; |
| 2727 | private final @Nullable String mPackageName; |
| 2728 | private final @Nullable List<String> mOpNames; |
| 2729 | private final long mBeginTimeMillis; |
| 2730 | private final long mEndTimeMillis; |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 2731 | private final @OpFlags int mFlags; |
Svet Ganov | 23c88db | 2019-01-22 20:38:11 -0800 | [diff] [blame] | 2732 | |
| 2733 | private HistoricalOpsRequest(int uid, @Nullable String packageName, |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 2734 | @Nullable List<String> opNames, long beginTimeMillis, long endTimeMillis, |
| 2735 | @OpFlags int flags) { |
Svet Ganov | 23c88db | 2019-01-22 20:38:11 -0800 | [diff] [blame] | 2736 | mUid = uid; |
| 2737 | mPackageName = packageName; |
| 2738 | mOpNames = opNames; |
| 2739 | mBeginTimeMillis = beginTimeMillis; |
| 2740 | mEndTimeMillis = endTimeMillis; |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 2741 | mFlags = flags; |
Svet Ganov | 23c88db | 2019-01-22 20:38:11 -0800 | [diff] [blame] | 2742 | } |
| 2743 | |
| 2744 | /** |
| 2745 | * Builder for creating a {@link HistoricalOpsRequest}. |
| 2746 | * |
| 2747 | * @hide |
| 2748 | */ |
| 2749 | @TestApi |
| 2750 | @SystemApi |
| 2751 | public static final class Builder { |
| 2752 | private int mUid = Process.INVALID_UID; |
| 2753 | private @Nullable String mPackageName; |
| 2754 | private @Nullable List<String> mOpNames; |
| 2755 | private final long mBeginTimeMillis; |
| 2756 | private final long mEndTimeMillis; |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 2757 | private @OpFlags int mFlags = OP_FLAGS_ALL; |
Svet Ganov | 23c88db | 2019-01-22 20:38:11 -0800 | [diff] [blame] | 2758 | |
| 2759 | /** |
| 2760 | * Creates a new builder. |
| 2761 | * |
| 2762 | * @param beginTimeMillis The beginning of the interval in milliseconds since |
| 2763 | * epoch start (January 1, 1970 00:00:00.000 GMT - Gregorian). Must be non |
| 2764 | * negative. |
| 2765 | * @param endTimeMillis The end of the interval in milliseconds since |
| 2766 | * epoch start (January 1, 1970 00:00:00.000 GMT - Gregorian). Must be after |
| 2767 | * {@code beginTimeMillis}. Pass {@link Long#MAX_VALUE} to get the most recent |
| 2768 | * history including ops that happen while this call is in flight. |
| 2769 | */ |
| 2770 | public Builder(long beginTimeMillis, long endTimeMillis) { |
| 2771 | Preconditions.checkArgument(beginTimeMillis >= 0 && beginTimeMillis < endTimeMillis, |
| 2772 | "beginTimeMillis must be non negative and lesser than endTimeMillis"); |
| 2773 | mBeginTimeMillis = beginTimeMillis; |
| 2774 | mEndTimeMillis = endTimeMillis; |
| 2775 | } |
| 2776 | |
| 2777 | /** |
| 2778 | * Sets the UID to query for. |
| 2779 | * |
| 2780 | * @param uid The uid. Pass {@link android.os.Process#INVALID_UID} for any uid. |
| 2781 | * @return This builder. |
| 2782 | */ |
| 2783 | public @NonNull Builder setUid(int uid) { |
| 2784 | Preconditions.checkArgument(uid == Process.INVALID_UID || uid >= 0, |
| 2785 | "uid must be " + Process.INVALID_UID + " or non negative"); |
| 2786 | mUid = uid; |
| 2787 | return this; |
| 2788 | } |
| 2789 | |
| 2790 | /** |
| 2791 | * Sets the package to query for. |
| 2792 | * |
| 2793 | * @param packageName The package name. <code>Null</code> for any package. |
| 2794 | * @return This builder. |
| 2795 | */ |
| 2796 | public @NonNull Builder setPackageName(@Nullable String packageName) { |
| 2797 | mPackageName = packageName; |
| 2798 | return this; |
| 2799 | } |
| 2800 | |
| 2801 | /** |
| 2802 | * Sets the op names to query for. |
| 2803 | * |
| 2804 | * @param opNames The op names. <code>Null</code> for any op. |
| 2805 | * @return This builder. |
| 2806 | */ |
| 2807 | public @NonNull Builder setOpNames(@Nullable List<String> opNames) { |
| 2808 | if (opNames != null) { |
| 2809 | final int opCount = opNames.size(); |
| 2810 | for (int i = 0; i < opCount; i++) { |
| 2811 | Preconditions.checkArgument(AppOpsManager.strOpToOp( |
| 2812 | opNames.get(i)) != AppOpsManager.OP_NONE); |
| 2813 | } |
| 2814 | } |
| 2815 | mOpNames = opNames; |
| 2816 | return this; |
| 2817 | } |
| 2818 | |
| 2819 | /** |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 2820 | * Sets the op flags to query for. The flags specify the type of |
| 2821 | * op data being queried. |
| 2822 | * |
| 2823 | * @param flags The flags which are any combination of |
| 2824 | * {@link #OP_FLAG_SELF}, {@link #OP_FLAG_TRUSTED_PROXY}, |
| 2825 | * {@link #OP_FLAG_UNTRUSTED_PROXY}, {@link #OP_FLAG_TRUSTED_PROXIED}, |
| 2826 | * {@link #OP_FLAG_UNTRUSTED_PROXIED}. You can use {@link #OP_FLAGS_ALL} |
| 2827 | * for any flag. |
| 2828 | * @return This builder. |
| 2829 | */ |
| 2830 | public @NonNull Builder setFlags(@OpFlags int flags) { |
| 2831 | Preconditions.checkFlagsArgument(flags, OP_FLAGS_ALL); |
| 2832 | mFlags = flags; |
| 2833 | return this; |
| 2834 | } |
| 2835 | |
| 2836 | /** |
Svet Ganov | 23c88db | 2019-01-22 20:38:11 -0800 | [diff] [blame] | 2837 | * @return a new {@link HistoricalOpsRequest}. |
| 2838 | */ |
| 2839 | public @NonNull HistoricalOpsRequest build() { |
| 2840 | return new HistoricalOpsRequest(mUid, mPackageName, mOpNames, |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 2841 | mBeginTimeMillis, mEndTimeMillis, mFlags); |
Svet Ganov | 23c88db | 2019-01-22 20:38:11 -0800 | [diff] [blame] | 2842 | } |
| 2843 | } |
| 2844 | } |
| 2845 | |
| 2846 | /** |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 2847 | * This class represents historical app op state of all UIDs for a given time interval. |
| 2848 | * |
| 2849 | * @hide |
| 2850 | */ |
| 2851 | @TestApi |
| 2852 | @SystemApi |
| 2853 | public static final class HistoricalOps implements Parcelable { |
| 2854 | private long mBeginTimeMillis; |
| 2855 | private long mEndTimeMillis; |
| 2856 | private @Nullable SparseArray<HistoricalUidOps> mHistoricalUidOps; |
| 2857 | |
| 2858 | /** @hide */ |
| 2859 | @TestApi |
| 2860 | public HistoricalOps(long beginTimeMillis, long endTimeMillis) { |
| 2861 | Preconditions.checkState(beginTimeMillis <= endTimeMillis); |
| 2862 | mBeginTimeMillis = beginTimeMillis; |
| 2863 | mEndTimeMillis = endTimeMillis; |
| 2864 | } |
| 2865 | |
| 2866 | /** @hide */ |
| 2867 | public HistoricalOps(@NonNull HistoricalOps other) { |
| 2868 | mBeginTimeMillis = other.mBeginTimeMillis; |
| 2869 | mEndTimeMillis = other.mEndTimeMillis; |
| 2870 | Preconditions.checkState(mBeginTimeMillis <= mEndTimeMillis); |
| 2871 | if (other.mHistoricalUidOps != null) { |
| 2872 | final int opCount = other.getUidCount(); |
| 2873 | for (int i = 0; i < opCount; i++) { |
| 2874 | final HistoricalUidOps origOps = other.getUidOpsAt(i); |
| 2875 | final HistoricalUidOps clonedOps = new HistoricalUidOps(origOps); |
| 2876 | if (mHistoricalUidOps == null) { |
| 2877 | mHistoricalUidOps = new SparseArray<>(opCount); |
| 2878 | } |
| 2879 | mHistoricalUidOps.put(clonedOps.getUid(), clonedOps); |
| 2880 | } |
| 2881 | } |
| 2882 | } |
| 2883 | |
| 2884 | private HistoricalOps(Parcel parcel) { |
| 2885 | mBeginTimeMillis = parcel.readLong(); |
| 2886 | mEndTimeMillis = parcel.readLong(); |
| 2887 | final int[] uids = parcel.createIntArray(); |
| 2888 | if (!ArrayUtils.isEmpty(uids)) { |
| 2889 | final ParceledListSlice<HistoricalUidOps> listSlice = parcel.readParcelable( |
| 2890 | HistoricalOps.class.getClassLoader()); |
| 2891 | final List<HistoricalUidOps> uidOps = (listSlice != null) |
| 2892 | ? listSlice.getList() : null; |
| 2893 | if (uidOps == null) { |
| 2894 | return; |
| 2895 | } |
| 2896 | for (int i = 0; i < uids.length; i++) { |
| 2897 | if (mHistoricalUidOps == null) { |
| 2898 | mHistoricalUidOps = new SparseArray<>(); |
| 2899 | } |
| 2900 | mHistoricalUidOps.put(uids[i], uidOps.get(i)); |
| 2901 | } |
| 2902 | } |
| 2903 | } |
| 2904 | |
| 2905 | /** |
| 2906 | * Splice a piece from the beginning of these ops. |
| 2907 | * |
| 2908 | * @param splicePoint The fraction of the data to be spliced off. |
| 2909 | * |
| 2910 | * @hide |
| 2911 | */ |
| 2912 | public @NonNull HistoricalOps spliceFromBeginning(double splicePoint) { |
| 2913 | return splice(splicePoint, true); |
| 2914 | } |
| 2915 | |
| 2916 | /** |
| 2917 | * Splice a piece from the end of these ops. |
| 2918 | * |
| 2919 | * @param fractionToRemove The fraction of the data to be spliced off. |
| 2920 | * |
| 2921 | * @hide |
| 2922 | */ |
| 2923 | public @NonNull HistoricalOps spliceFromEnd(double fractionToRemove) { |
| 2924 | return splice(fractionToRemove, false); |
| 2925 | } |
| 2926 | |
| 2927 | /** |
| 2928 | * Splice a piece from the beginning or end of these ops. |
| 2929 | * |
| 2930 | * @param fractionToRemove The fraction of the data to be spliced off. |
| 2931 | * @param beginning Whether to splice off the beginning or the end. |
| 2932 | * |
| 2933 | * @return The spliced off part. |
| 2934 | * |
| 2935 | * @hide |
| 2936 | */ |
| 2937 | private @Nullable HistoricalOps splice(double fractionToRemove, boolean beginning) { |
| 2938 | final long spliceBeginTimeMills; |
| 2939 | final long spliceEndTimeMills; |
| 2940 | if (beginning) { |
| 2941 | spliceBeginTimeMills = mBeginTimeMillis; |
| 2942 | spliceEndTimeMills = (long) (mBeginTimeMillis |
| 2943 | + getDurationMillis() * fractionToRemove); |
| 2944 | mBeginTimeMillis = spliceEndTimeMills; |
| 2945 | } else { |
| 2946 | spliceBeginTimeMills = (long) (mEndTimeMillis |
| 2947 | - getDurationMillis() * fractionToRemove); |
| 2948 | spliceEndTimeMills = mEndTimeMillis; |
| 2949 | mEndTimeMillis = spliceBeginTimeMills; |
| 2950 | } |
| 2951 | |
| 2952 | HistoricalOps splice = null; |
| 2953 | final int uidCount = getUidCount(); |
| 2954 | for (int i = 0; i < uidCount; i++) { |
| 2955 | final HistoricalUidOps origOps = getUidOpsAt(i); |
| 2956 | final HistoricalUidOps spliceOps = origOps.splice(fractionToRemove); |
| 2957 | if (spliceOps != null) { |
| 2958 | if (splice == null) { |
| 2959 | splice = new HistoricalOps(spliceBeginTimeMills, spliceEndTimeMills); |
| 2960 | } |
| 2961 | if (splice.mHistoricalUidOps == null) { |
| 2962 | splice.mHistoricalUidOps = new SparseArray<>(); |
| 2963 | } |
| 2964 | splice.mHistoricalUidOps.put(spliceOps.getUid(), spliceOps); |
| 2965 | } |
| 2966 | } |
| 2967 | return splice; |
| 2968 | } |
| 2969 | |
| 2970 | /** |
| 2971 | * Merge the passed ops into the current ones. The time interval is a |
| 2972 | * union of the current and passed in one and the passed in data is |
| 2973 | * folded into the data of this instance. |
| 2974 | * |
| 2975 | * @hide |
| 2976 | */ |
| 2977 | public void merge(@NonNull HistoricalOps other) { |
| 2978 | mBeginTimeMillis = Math.min(mBeginTimeMillis, other.mBeginTimeMillis); |
| 2979 | mEndTimeMillis = Math.max(mEndTimeMillis, other.mEndTimeMillis); |
| 2980 | final int uidCount = other.getUidCount(); |
| 2981 | for (int i = 0; i < uidCount; i++) { |
| 2982 | final HistoricalUidOps otherUidOps = other.getUidOpsAt(i); |
| 2983 | final HistoricalUidOps thisUidOps = getUidOps(otherUidOps.getUid()); |
| 2984 | if (thisUidOps != null) { |
| 2985 | thisUidOps.merge(otherUidOps); |
| 2986 | } else { |
| 2987 | if (mHistoricalUidOps == null) { |
| 2988 | mHistoricalUidOps = new SparseArray<>(); |
| 2989 | } |
| 2990 | mHistoricalUidOps.put(otherUidOps.getUid(), otherUidOps); |
| 2991 | } |
| 2992 | } |
| 2993 | } |
| 2994 | |
| 2995 | /** |
| 2996 | * AppPermissionUsage the ops to leave only the data we filter for. |
| 2997 | * |
| 2998 | * @param uid Uid to filter for or {@link android.os.Process#INCIDENTD_UID} for all. |
| 2999 | * @param packageName Package to filter for or null for all. |
| 3000 | * @param opNames Ops to filter for or null for all. |
| 3001 | * @param beginTimeMillis The begin time to filter for or {@link Long#MIN_VALUE} for all. |
| 3002 | * @param endTimeMillis The end time to filter for or {@link Long#MAX_VALUE} for all. |
| 3003 | * |
| 3004 | * @hide |
| 3005 | */ |
| 3006 | public void filter(int uid, @Nullable String packageName, @Nullable String[] opNames, |
| 3007 | long beginTimeMillis, long endTimeMillis) { |
| 3008 | final long durationMillis = getDurationMillis(); |
| 3009 | mBeginTimeMillis = Math.max(mBeginTimeMillis, beginTimeMillis); |
| 3010 | mEndTimeMillis = Math.min(mEndTimeMillis, endTimeMillis); |
| 3011 | final double scaleFactor = Math.min((double) (endTimeMillis - beginTimeMillis) |
| 3012 | / (double) durationMillis, 1); |
| 3013 | final int uidCount = getUidCount(); |
| 3014 | for (int i = uidCount - 1; i >= 0; i--) { |
| 3015 | final HistoricalUidOps uidOp = mHistoricalUidOps.valueAt(i); |
| 3016 | if (uid != Process.INVALID_UID && uid != uidOp.getUid()) { |
| 3017 | mHistoricalUidOps.removeAt(i); |
| 3018 | } else { |
| 3019 | uidOp.filter(packageName, opNames, scaleFactor); |
| 3020 | } |
| 3021 | } |
| 3022 | } |
| 3023 | |
| 3024 | /** @hide */ |
| 3025 | public boolean isEmpty() { |
| 3026 | if (getBeginTimeMillis() >= getEndTimeMillis()) { |
| 3027 | return true; |
| 3028 | } |
| 3029 | final int uidCount = getUidCount(); |
| 3030 | for (int i = uidCount - 1; i >= 0; i--) { |
| 3031 | final HistoricalUidOps uidOp = mHistoricalUidOps.valueAt(i); |
| 3032 | if (!uidOp.isEmpty()) { |
| 3033 | return false; |
| 3034 | } |
| 3035 | } |
| 3036 | return true; |
| 3037 | } |
| 3038 | |
| 3039 | /** @hide */ |
| 3040 | public long getDurationMillis() { |
| 3041 | return mEndTimeMillis - mBeginTimeMillis; |
| 3042 | } |
| 3043 | |
| 3044 | /** @hide */ |
| 3045 | @TestApi |
| 3046 | public void increaseAccessCount(int opCode, int uid, @NonNull String packageName, |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 3047 | @UidState int uidState, @OpFlags int flags, long increment) { |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 3048 | getOrCreateHistoricalUidOps(uid).increaseAccessCount(opCode, |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 3049 | packageName, uidState, flags, increment); |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 3050 | } |
| 3051 | |
| 3052 | /** @hide */ |
| 3053 | @TestApi |
| 3054 | public void increaseRejectCount(int opCode, int uid, @NonNull String packageName, |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 3055 | @UidState int uidState, @OpFlags int flags, long increment) { |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 3056 | getOrCreateHistoricalUidOps(uid).increaseRejectCount(opCode, |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 3057 | packageName, uidState, flags, increment); |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 3058 | } |
| 3059 | |
| 3060 | /** @hide */ |
| 3061 | @TestApi |
| 3062 | public void increaseAccessDuration(int opCode, int uid, @NonNull String packageName, |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 3063 | @UidState int uidState, @OpFlags int flags, long increment) { |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 3064 | getOrCreateHistoricalUidOps(uid).increaseAccessDuration(opCode, |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 3065 | packageName, uidState, flags, increment); |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 3066 | } |
| 3067 | |
| 3068 | /** @hide */ |
| 3069 | @TestApi |
| 3070 | public void offsetBeginAndEndTime(long offsetMillis) { |
| 3071 | mBeginTimeMillis += offsetMillis; |
| 3072 | mEndTimeMillis += offsetMillis; |
| 3073 | } |
| 3074 | |
| 3075 | /** @hide */ |
| 3076 | public void setBeginAndEndTime(long beginTimeMillis, long endTimeMillis) { |
| 3077 | mBeginTimeMillis = beginTimeMillis; |
| 3078 | mEndTimeMillis = endTimeMillis; |
| 3079 | } |
| 3080 | |
| 3081 | /** @hide */ |
| 3082 | public void setBeginTime(long beginTimeMillis) { |
| 3083 | mBeginTimeMillis = beginTimeMillis; |
| 3084 | } |
| 3085 | |
| 3086 | /** @hide */ |
| 3087 | public void setEndTime(long endTimeMillis) { |
| 3088 | mEndTimeMillis = endTimeMillis; |
| 3089 | } |
| 3090 | |
| 3091 | /** |
| 3092 | * @return The beginning of the interval in milliseconds since |
| 3093 | * epoch start (January 1, 1970 00:00:00.000 GMT - Gregorian). |
| 3094 | */ |
| 3095 | public long getBeginTimeMillis() { |
| 3096 | return mBeginTimeMillis; |
| 3097 | } |
| 3098 | |
| 3099 | /** |
| 3100 | * @return The end of the interval in milliseconds since |
| 3101 | * epoch start (January 1, 1970 00:00:00.000 GMT - Gregorian). |
| 3102 | */ |
| 3103 | public long getEndTimeMillis() { |
| 3104 | return mEndTimeMillis; |
| 3105 | } |
| 3106 | |
| 3107 | /** |
| 3108 | * Gets number of UIDs with historical ops. |
| 3109 | * |
| 3110 | * @return The number of UIDs with historical ops. |
| 3111 | * |
| 3112 | * @see #getUidOpsAt(int) |
| 3113 | */ |
Svet Ganov | 00a46ef | 2019-03-29 21:13:03 -0700 | [diff] [blame] | 3114 | public @IntRange(from = 0) int getUidCount() { |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 3115 | if (mHistoricalUidOps == null) { |
| 3116 | return 0; |
| 3117 | } |
| 3118 | return mHistoricalUidOps.size(); |
| 3119 | } |
| 3120 | |
| 3121 | /** |
| 3122 | * Gets the historical UID ops at a given index. |
| 3123 | * |
| 3124 | * @param index The index. |
| 3125 | * |
| 3126 | * @return The historical UID ops at the given index. |
| 3127 | * |
| 3128 | * @see #getUidCount() |
| 3129 | */ |
Svet Ganov | 00a46ef | 2019-03-29 21:13:03 -0700 | [diff] [blame] | 3130 | public @NonNull HistoricalUidOps getUidOpsAt(@IntRange(from = 0) int index) { |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 3131 | if (mHistoricalUidOps == null) { |
| 3132 | throw new IndexOutOfBoundsException(); |
| 3133 | } |
| 3134 | return mHistoricalUidOps.valueAt(index); |
| 3135 | } |
| 3136 | |
| 3137 | /** |
| 3138 | * Gets the historical UID ops for a given UID. |
| 3139 | * |
| 3140 | * @param uid The UID. |
| 3141 | * |
| 3142 | * @return The historical ops for the UID. |
| 3143 | */ |
| 3144 | public @Nullable HistoricalUidOps getUidOps(int uid) { |
| 3145 | if (mHistoricalUidOps == null) { |
| 3146 | return null; |
| 3147 | } |
| 3148 | return mHistoricalUidOps.get(uid); |
| 3149 | } |
| 3150 | |
Winson | 4e3b435 | 2019-05-07 16:29:59 -0700 | [diff] [blame] | 3151 | /** @hide */ |
| 3152 | public void clearHistory(int uid, @NonNull String packageName) { |
| 3153 | HistoricalUidOps historicalUidOps = getOrCreateHistoricalUidOps(uid); |
| 3154 | historicalUidOps.clearHistory(packageName); |
| 3155 | if (historicalUidOps.isEmpty()) { |
| 3156 | mHistoricalUidOps.remove(uid); |
| 3157 | } |
| 3158 | } |
| 3159 | |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 3160 | @Override |
| 3161 | public int describeContents() { |
| 3162 | return 0; |
| 3163 | } |
| 3164 | |
| 3165 | @Override |
| 3166 | public void writeToParcel(Parcel parcel, int flags) { |
| 3167 | parcel.writeLong(mBeginTimeMillis); |
| 3168 | parcel.writeLong(mEndTimeMillis); |
| 3169 | if (mHistoricalUidOps != null) { |
| 3170 | final int uidCount = mHistoricalUidOps.size(); |
| 3171 | parcel.writeInt(uidCount); |
| 3172 | for (int i = 0; i < uidCount; i++) { |
| 3173 | parcel.writeInt(mHistoricalUidOps.keyAt(i)); |
| 3174 | } |
| 3175 | final List<HistoricalUidOps> opsList = new ArrayList<>(uidCount); |
| 3176 | for (int i = 0; i < uidCount; i++) { |
| 3177 | opsList.add(mHistoricalUidOps.valueAt(i)); |
| 3178 | } |
| 3179 | parcel.writeParcelable(new ParceledListSlice<>(opsList), flags); |
| 3180 | } else { |
| 3181 | parcel.writeInt(-1); |
| 3182 | } |
| 3183 | } |
| 3184 | |
| 3185 | /** |
| 3186 | * Accepts a visitor to traverse the ops tree. |
| 3187 | * |
| 3188 | * @param visitor The visitor. |
| 3189 | * |
| 3190 | * @hide |
| 3191 | */ |
| 3192 | public void accept(@NonNull HistoricalOpsVisitor visitor) { |
| 3193 | visitor.visitHistoricalOps(this); |
| 3194 | final int uidCount = getUidCount(); |
| 3195 | for (int i = 0; i < uidCount; i++) { |
| 3196 | getUidOpsAt(i).accept(visitor); |
| 3197 | } |
| 3198 | } |
| 3199 | |
| 3200 | private @NonNull HistoricalUidOps getOrCreateHistoricalUidOps(int uid) { |
| 3201 | if (mHistoricalUidOps == null) { |
| 3202 | mHistoricalUidOps = new SparseArray<>(); |
| 3203 | } |
| 3204 | HistoricalUidOps historicalUidOp = mHistoricalUidOps.get(uid); |
| 3205 | if (historicalUidOp == null) { |
| 3206 | historicalUidOp = new HistoricalUidOps(uid); |
| 3207 | mHistoricalUidOps.put(uid, historicalUidOp); |
| 3208 | } |
| 3209 | return historicalUidOp; |
| 3210 | } |
| 3211 | |
| 3212 | /** |
| 3213 | * @return Rounded value up at the 0.5 boundary. |
| 3214 | * |
| 3215 | * @hide |
| 3216 | */ |
| 3217 | public static double round(double value) { |
| 3218 | final BigDecimal decimalScale = new BigDecimal(value); |
| 3219 | return decimalScale.setScale(0, RoundingMode.HALF_UP).doubleValue(); |
| 3220 | } |
| 3221 | |
| 3222 | @Override |
Aurimas Liutikas | 00be951 | 2019-08-28 13:01:05 -0700 | [diff] [blame] | 3223 | public boolean equals(@Nullable Object obj) { |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 3224 | if (this == obj) { |
| 3225 | return true; |
| 3226 | } |
| 3227 | if (obj == null || getClass() != obj.getClass()) { |
| 3228 | return false; |
| 3229 | } |
| 3230 | final HistoricalOps other = (HistoricalOps) obj; |
| 3231 | if (mBeginTimeMillis != other.mBeginTimeMillis) { |
| 3232 | return false; |
| 3233 | } |
| 3234 | if (mEndTimeMillis != other.mEndTimeMillis) { |
| 3235 | return false; |
| 3236 | } |
| 3237 | if (mHistoricalUidOps == null) { |
| 3238 | if (other.mHistoricalUidOps != null) { |
| 3239 | return false; |
| 3240 | } |
| 3241 | } else if (!mHistoricalUidOps.equals(other.mHistoricalUidOps)) { |
| 3242 | return false; |
| 3243 | } |
| 3244 | return true; |
| 3245 | } |
| 3246 | |
| 3247 | @Override |
| 3248 | public int hashCode() { |
| 3249 | int result = (int) (mBeginTimeMillis ^ (mBeginTimeMillis >>> 32)); |
| 3250 | result = 31 * result + mHistoricalUidOps.hashCode(); |
| 3251 | return result; |
| 3252 | } |
| 3253 | |
Aurimas Liutikas | 00be951 | 2019-08-28 13:01:05 -0700 | [diff] [blame] | 3254 | @NonNull |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 3255 | @Override |
| 3256 | public String toString() { |
| 3257 | return getClass().getSimpleName() + "[from:" |
| 3258 | + mBeginTimeMillis + " to:" + mEndTimeMillis + "]"; |
| 3259 | } |
| 3260 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 3261 | public static final @android.annotation.NonNull Creator<HistoricalOps> CREATOR = new Creator<HistoricalOps>() { |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 3262 | @Override |
| 3263 | public @NonNull HistoricalOps createFromParcel(@NonNull Parcel parcel) { |
| 3264 | return new HistoricalOps(parcel); |
| 3265 | } |
| 3266 | |
| 3267 | @Override |
| 3268 | public @NonNull HistoricalOps[] newArray(int size) { |
| 3269 | return new HistoricalOps[size]; |
| 3270 | } |
| 3271 | }; |
| 3272 | } |
| 3273 | |
| 3274 | /** |
| 3275 | * This class represents historical app op state for a UID. |
| 3276 | * |
| 3277 | * @hide |
| 3278 | */ |
| 3279 | @TestApi |
| 3280 | @SystemApi |
| 3281 | public static final class HistoricalUidOps implements Parcelable { |
| 3282 | private final int mUid; |
| 3283 | private @Nullable ArrayMap<String, HistoricalPackageOps> mHistoricalPackageOps; |
| 3284 | |
| 3285 | /** @hide */ |
| 3286 | public HistoricalUidOps(int uid) { |
| 3287 | mUid = uid; |
| 3288 | } |
| 3289 | |
| 3290 | private HistoricalUidOps(@NonNull HistoricalUidOps other) { |
| 3291 | mUid = other.mUid; |
| 3292 | final int opCount = other.getPackageCount(); |
| 3293 | for (int i = 0; i < opCount; i++) { |
| 3294 | final HistoricalPackageOps origOps = other.getPackageOpsAt(i); |
| 3295 | final HistoricalPackageOps cloneOps = new HistoricalPackageOps(origOps); |
| 3296 | if (mHistoricalPackageOps == null) { |
| 3297 | mHistoricalPackageOps = new ArrayMap<>(opCount); |
| 3298 | } |
| 3299 | mHistoricalPackageOps.put(cloneOps.getPackageName(), cloneOps); |
| 3300 | } |
| 3301 | } |
| 3302 | |
| 3303 | private HistoricalUidOps(@NonNull Parcel parcel) { |
| 3304 | // No arg check since we always read from a trusted source. |
| 3305 | mUid = parcel.readInt(); |
| 3306 | mHistoricalPackageOps = parcel.createTypedArrayMap(HistoricalPackageOps.CREATOR); |
| 3307 | } |
| 3308 | |
| 3309 | private @Nullable HistoricalUidOps splice(double fractionToRemove) { |
| 3310 | HistoricalUidOps splice = null; |
| 3311 | final int packageCount = getPackageCount(); |
| 3312 | for (int i = 0; i < packageCount; i++) { |
| 3313 | final HistoricalPackageOps origOps = getPackageOpsAt(i); |
| 3314 | final HistoricalPackageOps spliceOps = origOps.splice(fractionToRemove); |
| 3315 | if (spliceOps != null) { |
| 3316 | if (splice == null) { |
| 3317 | splice = new HistoricalUidOps(mUid); |
| 3318 | } |
| 3319 | if (splice.mHistoricalPackageOps == null) { |
| 3320 | splice.mHistoricalPackageOps = new ArrayMap<>(); |
| 3321 | } |
| 3322 | splice.mHistoricalPackageOps.put(spliceOps.getPackageName(), spliceOps); |
| 3323 | } |
| 3324 | } |
| 3325 | return splice; |
| 3326 | } |
| 3327 | |
| 3328 | private void merge(@NonNull HistoricalUidOps other) { |
| 3329 | final int packageCount = other.getPackageCount(); |
| 3330 | for (int i = 0; i < packageCount; i++) { |
| 3331 | final HistoricalPackageOps otherPackageOps = other.getPackageOpsAt(i); |
| 3332 | final HistoricalPackageOps thisPackageOps = getPackageOps( |
| 3333 | otherPackageOps.getPackageName()); |
| 3334 | if (thisPackageOps != null) { |
| 3335 | thisPackageOps.merge(otherPackageOps); |
| 3336 | } else { |
| 3337 | if (mHistoricalPackageOps == null) { |
| 3338 | mHistoricalPackageOps = new ArrayMap<>(); |
| 3339 | } |
| 3340 | mHistoricalPackageOps.put(otherPackageOps.getPackageName(), otherPackageOps); |
| 3341 | } |
| 3342 | } |
| 3343 | } |
| 3344 | |
| 3345 | private void filter(@Nullable String packageName, @Nullable String[] opNames, |
| 3346 | double fractionToRemove) { |
| 3347 | final int packageCount = getPackageCount(); |
| 3348 | for (int i = packageCount - 1; i >= 0; i--) { |
| 3349 | final HistoricalPackageOps packageOps = getPackageOpsAt(i); |
| 3350 | if (packageName != null && !packageName.equals(packageOps.getPackageName())) { |
| 3351 | mHistoricalPackageOps.removeAt(i); |
| 3352 | } else { |
| 3353 | packageOps.filter(opNames, fractionToRemove); |
| 3354 | } |
| 3355 | } |
| 3356 | } |
| 3357 | |
| 3358 | private boolean isEmpty() { |
| 3359 | final int packageCount = getPackageCount(); |
| 3360 | for (int i = packageCount - 1; i >= 0; i--) { |
| 3361 | final HistoricalPackageOps packageOps = mHistoricalPackageOps.valueAt(i); |
| 3362 | if (!packageOps.isEmpty()) { |
| 3363 | return false; |
| 3364 | } |
| 3365 | } |
| 3366 | return true; |
| 3367 | } |
| 3368 | |
| 3369 | private void increaseAccessCount(int opCode, @NonNull String packageName, |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 3370 | @UidState int uidState, @OpFlags int flags, long increment) { |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 3371 | getOrCreateHistoricalPackageOps(packageName).increaseAccessCount( |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 3372 | opCode, uidState, flags, increment); |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 3373 | } |
| 3374 | |
| 3375 | private void increaseRejectCount(int opCode, @NonNull String packageName, |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 3376 | @UidState int uidState, @OpFlags int flags, long increment) { |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 3377 | getOrCreateHistoricalPackageOps(packageName).increaseRejectCount( |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 3378 | opCode, uidState, flags, increment); |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 3379 | } |
| 3380 | |
| 3381 | private void increaseAccessDuration(int opCode, @NonNull String packageName, |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 3382 | @UidState int uidState, @OpFlags int flags, long increment) { |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 3383 | getOrCreateHistoricalPackageOps(packageName).increaseAccessDuration( |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 3384 | opCode, uidState, flags, increment); |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 3385 | } |
| 3386 | |
| 3387 | /** |
| 3388 | * @return The UID for which the data is related. |
| 3389 | */ |
| 3390 | public int getUid() { |
| 3391 | return mUid; |
| 3392 | } |
| 3393 | |
| 3394 | /** |
| 3395 | * Gets number of packages with historical ops. |
| 3396 | * |
| 3397 | * @return The number of packages with historical ops. |
| 3398 | * |
| 3399 | * @see #getPackageOpsAt(int) |
| 3400 | */ |
Svet Ganov | 00a46ef | 2019-03-29 21:13:03 -0700 | [diff] [blame] | 3401 | public @IntRange(from = 0) int getPackageCount() { |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 3402 | if (mHistoricalPackageOps == null) { |
| 3403 | return 0; |
| 3404 | } |
| 3405 | return mHistoricalPackageOps.size(); |
| 3406 | } |
| 3407 | |
| 3408 | /** |
| 3409 | * Gets the historical package ops at a given index. |
| 3410 | * |
| 3411 | * @param index The index. |
| 3412 | * |
| 3413 | * @return The historical package ops at the given index. |
| 3414 | * |
| 3415 | * @see #getPackageCount() |
| 3416 | */ |
Svet Ganov | 00a46ef | 2019-03-29 21:13:03 -0700 | [diff] [blame] | 3417 | public @NonNull HistoricalPackageOps getPackageOpsAt(@IntRange(from = 0) int index) { |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 3418 | if (mHistoricalPackageOps == null) { |
| 3419 | throw new IndexOutOfBoundsException(); |
| 3420 | } |
| 3421 | return mHistoricalPackageOps.valueAt(index); |
| 3422 | } |
| 3423 | |
| 3424 | /** |
| 3425 | * Gets the historical package ops for a given package. |
| 3426 | * |
| 3427 | * @param packageName The package. |
| 3428 | * |
| 3429 | * @return The historical ops for the package. |
| 3430 | */ |
| 3431 | public @Nullable HistoricalPackageOps getPackageOps(@NonNull String packageName) { |
| 3432 | if (mHistoricalPackageOps == null) { |
| 3433 | return null; |
| 3434 | } |
| 3435 | return mHistoricalPackageOps.get(packageName); |
| 3436 | } |
| 3437 | |
Winson | 4e3b435 | 2019-05-07 16:29:59 -0700 | [diff] [blame] | 3438 | private void clearHistory(@NonNull String packageName) { |
| 3439 | if (mHistoricalPackageOps != null) { |
| 3440 | mHistoricalPackageOps.remove(packageName); |
| 3441 | } |
| 3442 | } |
| 3443 | |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 3444 | @Override |
| 3445 | public int describeContents() { |
| 3446 | return 0; |
| 3447 | } |
| 3448 | |
| 3449 | @Override |
| 3450 | public void writeToParcel(Parcel parcel, int flags) { |
| 3451 | parcel.writeInt(mUid); |
| 3452 | parcel.writeTypedArrayMap(mHistoricalPackageOps, flags); |
| 3453 | } |
| 3454 | |
| 3455 | private void accept(@NonNull HistoricalOpsVisitor visitor) { |
| 3456 | visitor.visitHistoricalUidOps(this); |
| 3457 | final int packageCount = getPackageCount(); |
| 3458 | for (int i = 0; i < packageCount; i++) { |
| 3459 | getPackageOpsAt(i).accept(visitor); |
| 3460 | } |
| 3461 | } |
| 3462 | |
| 3463 | private @NonNull HistoricalPackageOps getOrCreateHistoricalPackageOps( |
| 3464 | @NonNull String packageName) { |
| 3465 | if (mHistoricalPackageOps == null) { |
| 3466 | mHistoricalPackageOps = new ArrayMap<>(); |
| 3467 | } |
| 3468 | HistoricalPackageOps historicalPackageOp = mHistoricalPackageOps.get(packageName); |
| 3469 | if (historicalPackageOp == null) { |
| 3470 | historicalPackageOp = new HistoricalPackageOps(packageName); |
| 3471 | mHistoricalPackageOps.put(packageName, historicalPackageOp); |
| 3472 | } |
| 3473 | return historicalPackageOp; |
| 3474 | } |
| 3475 | |
| 3476 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 3477 | public static final @android.annotation.NonNull Creator<HistoricalUidOps> CREATOR = new Creator<HistoricalUidOps>() { |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 3478 | @Override |
| 3479 | public @NonNull HistoricalUidOps createFromParcel(@NonNull Parcel parcel) { |
| 3480 | return new HistoricalUidOps(parcel); |
| 3481 | } |
| 3482 | |
| 3483 | @Override |
| 3484 | public @NonNull HistoricalUidOps[] newArray(int size) { |
| 3485 | return new HistoricalUidOps[size]; |
| 3486 | } |
| 3487 | }; |
| 3488 | |
| 3489 | @Override |
Aurimas Liutikas | 00be951 | 2019-08-28 13:01:05 -0700 | [diff] [blame] | 3490 | public boolean equals(@Nullable Object obj) { |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 3491 | if (this == obj) { |
| 3492 | return true; |
| 3493 | } |
| 3494 | if (obj == null || getClass() != obj.getClass()) { |
| 3495 | return false; |
| 3496 | } |
| 3497 | final HistoricalUidOps other = (HistoricalUidOps) obj; |
| 3498 | if (mUid != other.mUid) { |
| 3499 | return false; |
| 3500 | } |
| 3501 | if (mHistoricalPackageOps == null) { |
| 3502 | if (other.mHistoricalPackageOps != null) { |
| 3503 | return false; |
| 3504 | } |
| 3505 | } else if (!mHistoricalPackageOps.equals(other.mHistoricalPackageOps)) { |
| 3506 | return false; |
| 3507 | } |
| 3508 | return true; |
| 3509 | } |
| 3510 | |
| 3511 | @Override |
| 3512 | public int hashCode() { |
| 3513 | int result = mUid; |
| 3514 | result = 31 * result + (mHistoricalPackageOps != null |
| 3515 | ? mHistoricalPackageOps.hashCode() : 0); |
| 3516 | return result; |
| 3517 | } |
| 3518 | } |
| 3519 | |
| 3520 | /** |
| 3521 | * This class represents historical app op information about a package. |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 3522 | * |
| 3523 | * @hide |
| 3524 | */ |
| 3525 | @TestApi |
| 3526 | @SystemApi |
| 3527 | public static final class HistoricalPackageOps implements Parcelable { |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 3528 | private final @NonNull String mPackageName; |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 3529 | private @Nullable ArrayMap<String, HistoricalOp> mHistoricalOps; |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 3530 | |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 3531 | /** @hide */ |
| 3532 | public HistoricalPackageOps(@NonNull String packageName) { |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 3533 | mPackageName = packageName; |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 3534 | } |
| 3535 | |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 3536 | private HistoricalPackageOps(@NonNull HistoricalPackageOps other) { |
| 3537 | mPackageName = other.mPackageName; |
| 3538 | final int opCount = other.getOpCount(); |
| 3539 | for (int i = 0; i < opCount; i++) { |
| 3540 | final HistoricalOp origOp = other.getOpAt(i); |
| 3541 | final HistoricalOp cloneOp = new HistoricalOp(origOp); |
| 3542 | if (mHistoricalOps == null) { |
| 3543 | mHistoricalOps = new ArrayMap<>(opCount); |
| 3544 | } |
| 3545 | mHistoricalOps.put(cloneOp.getOpName(), cloneOp); |
| 3546 | } |
| 3547 | } |
| 3548 | |
| 3549 | private HistoricalPackageOps(@NonNull Parcel parcel) { |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 3550 | mPackageName = parcel.readString(); |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 3551 | mHistoricalOps = parcel.createTypedArrayMap(HistoricalOp.CREATOR); |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 3552 | } |
| 3553 | |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 3554 | private @Nullable HistoricalPackageOps splice(double fractionToRemove) { |
| 3555 | HistoricalPackageOps splice = null; |
| 3556 | final int opCount = getOpCount(); |
| 3557 | for (int i = 0; i < opCount; i++) { |
| 3558 | final HistoricalOp origOps = getOpAt(i); |
| 3559 | final HistoricalOp spliceOps = origOps.splice(fractionToRemove); |
| 3560 | if (spliceOps != null) { |
| 3561 | if (splice == null) { |
| 3562 | splice = new HistoricalPackageOps(mPackageName); |
| 3563 | } |
| 3564 | if (splice.mHistoricalOps == null) { |
| 3565 | splice.mHistoricalOps = new ArrayMap<>(); |
| 3566 | } |
| 3567 | splice.mHistoricalOps.put(spliceOps.getOpName(), spliceOps); |
| 3568 | } |
| 3569 | } |
| 3570 | return splice; |
| 3571 | } |
| 3572 | |
| 3573 | private void merge(@NonNull HistoricalPackageOps other) { |
| 3574 | final int opCount = other.getOpCount(); |
| 3575 | for (int i = 0; i < opCount; i++) { |
| 3576 | final HistoricalOp otherOp = other.getOpAt(i); |
| 3577 | final HistoricalOp thisOp = getOp(otherOp.getOpName()); |
| 3578 | if (thisOp != null) { |
| 3579 | thisOp.merge(otherOp); |
| 3580 | } else { |
| 3581 | if (mHistoricalOps == null) { |
| 3582 | mHistoricalOps = new ArrayMap<>(); |
| 3583 | } |
| 3584 | mHistoricalOps.put(otherOp.getOpName(), otherOp); |
| 3585 | } |
| 3586 | } |
| 3587 | } |
| 3588 | |
| 3589 | private void filter(@Nullable String[] opNames, double scaleFactor) { |
| 3590 | final int opCount = getOpCount(); |
| 3591 | for (int i = opCount - 1; i >= 0; i--) { |
| 3592 | final HistoricalOp op = mHistoricalOps.valueAt(i); |
| 3593 | if (opNames != null && !ArrayUtils.contains(opNames, op.getOpName())) { |
| 3594 | mHistoricalOps.removeAt(i); |
| 3595 | } else { |
| 3596 | op.filter(scaleFactor); |
| 3597 | } |
| 3598 | } |
| 3599 | } |
| 3600 | |
| 3601 | private boolean isEmpty() { |
| 3602 | final int opCount = getOpCount(); |
| 3603 | for (int i = opCount - 1; i >= 0; i--) { |
| 3604 | final HistoricalOp op = mHistoricalOps.valueAt(i); |
| 3605 | if (!op.isEmpty()) { |
| 3606 | return false; |
| 3607 | } |
| 3608 | } |
| 3609 | return true; |
| 3610 | } |
| 3611 | |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 3612 | private void increaseAccessCount(int opCode, @UidState int uidState, |
| 3613 | @OpFlags int flags, long increment) { |
| 3614 | getOrCreateHistoricalOp(opCode).increaseAccessCount(uidState, flags, increment); |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 3615 | } |
| 3616 | |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 3617 | private void increaseRejectCount(int opCode, @UidState int uidState, |
| 3618 | @OpFlags int flags, long increment) { |
| 3619 | getOrCreateHistoricalOp(opCode).increaseRejectCount(uidState, flags, increment); |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 3620 | } |
| 3621 | |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 3622 | private void increaseAccessDuration(int opCode, @UidState int uidState, |
| 3623 | @OpFlags int flags, long increment) { |
| 3624 | getOrCreateHistoricalOp(opCode).increaseAccessDuration(uidState, flags, increment); |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 3625 | } |
| 3626 | |
| 3627 | /** |
| 3628 | * Gets the package name which the data represents. |
| 3629 | * |
| 3630 | * @return The package name which the data represents. |
| 3631 | */ |
| 3632 | public @NonNull String getPackageName() { |
| 3633 | return mPackageName; |
| 3634 | } |
| 3635 | |
| 3636 | /** |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 3637 | * Gets number historical app ops. |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 3638 | * |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 3639 | * @return The number historical app ops. |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 3640 | * @see #getOpAt(int) |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 3641 | */ |
Svet Ganov | 00a46ef | 2019-03-29 21:13:03 -0700 | [diff] [blame] | 3642 | public @IntRange(from = 0) int getOpCount() { |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 3643 | if (mHistoricalOps == null) { |
| 3644 | return 0; |
| 3645 | } |
| 3646 | return mHistoricalOps.size(); |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 3647 | } |
| 3648 | |
| 3649 | /** |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 3650 | * Gets the historical op at a given index. |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 3651 | * |
| 3652 | * @param index The index to lookup. |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 3653 | * @return The op at the given index. |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 3654 | * @see #getOpCount() |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 3655 | */ |
Svet Ganov | 00a46ef | 2019-03-29 21:13:03 -0700 | [diff] [blame] | 3656 | public @NonNull HistoricalOp getOpAt(@IntRange(from = 0) int index) { |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 3657 | if (mHistoricalOps == null) { |
| 3658 | throw new IndexOutOfBoundsException(); |
| 3659 | } |
| 3660 | return mHistoricalOps.valueAt(index); |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 3661 | } |
| 3662 | |
| 3663 | /** |
| 3664 | * Gets the historical entry for a given op name. |
| 3665 | * |
| 3666 | * @param opName The op name. |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 3667 | * @return The historical entry for that op name. |
| 3668 | */ |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 3669 | public @Nullable HistoricalOp getOp(@NonNull String opName) { |
| 3670 | if (mHistoricalOps == null) { |
| 3671 | return null; |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 3672 | } |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 3673 | return mHistoricalOps.get(opName); |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 3674 | } |
| 3675 | |
| 3676 | @Override |
| 3677 | public int describeContents() { |
| 3678 | return 0; |
| 3679 | } |
| 3680 | |
| 3681 | @Override |
| 3682 | public void writeToParcel(@NonNull Parcel parcel, int flags) { |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 3683 | parcel.writeString(mPackageName); |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 3684 | parcel.writeTypedArrayMap(mHistoricalOps, flags); |
| 3685 | } |
| 3686 | |
| 3687 | private void accept(@NonNull HistoricalOpsVisitor visitor) { |
| 3688 | visitor.visitHistoricalPackageOps(this); |
| 3689 | final int opCount = getOpCount(); |
| 3690 | for (int i = 0; i < opCount; i++) { |
| 3691 | getOpAt(i).accept(visitor); |
| 3692 | } |
| 3693 | } |
| 3694 | |
| 3695 | private @NonNull HistoricalOp getOrCreateHistoricalOp(int opCode) { |
| 3696 | if (mHistoricalOps == null) { |
| 3697 | mHistoricalOps = new ArrayMap<>(); |
| 3698 | } |
| 3699 | final String opStr = sOpToString[opCode]; |
| 3700 | HistoricalOp op = mHistoricalOps.get(opStr); |
| 3701 | if (op == null) { |
| 3702 | op = new HistoricalOp(opCode); |
| 3703 | mHistoricalOps.put(opStr, op); |
| 3704 | } |
| 3705 | return op; |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 3706 | } |
| 3707 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 3708 | public static final @android.annotation.NonNull Creator<HistoricalPackageOps> CREATOR = |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 3709 | new Creator<HistoricalPackageOps>() { |
| 3710 | @Override |
| 3711 | public @NonNull HistoricalPackageOps createFromParcel(@NonNull Parcel parcel) { |
| 3712 | return new HistoricalPackageOps(parcel); |
| 3713 | } |
| 3714 | |
| 3715 | @Override |
| 3716 | public @NonNull HistoricalPackageOps[] newArray(int size) { |
| 3717 | return new HistoricalPackageOps[size]; |
| 3718 | } |
| 3719 | }; |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 3720 | |
| 3721 | @Override |
Aurimas Liutikas | 00be951 | 2019-08-28 13:01:05 -0700 | [diff] [blame] | 3722 | public boolean equals(@Nullable Object obj) { |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 3723 | if (this == obj) { |
| 3724 | return true; |
| 3725 | } |
| 3726 | if (obj == null || getClass() != obj.getClass()) { |
| 3727 | return false; |
| 3728 | } |
| 3729 | final HistoricalPackageOps other = (HistoricalPackageOps) obj; |
| 3730 | if (!mPackageName.equals(other.mPackageName)) { |
| 3731 | return false; |
| 3732 | } |
| 3733 | if (mHistoricalOps == null) { |
| 3734 | if (other.mHistoricalOps != null) { |
| 3735 | return false; |
| 3736 | } |
| 3737 | } else if (!mHistoricalOps.equals(other.mHistoricalOps)) { |
| 3738 | return false; |
| 3739 | } |
| 3740 | return true; |
| 3741 | } |
| 3742 | |
| 3743 | @Override |
| 3744 | public int hashCode() { |
| 3745 | int result = mPackageName != null ? mPackageName.hashCode() : 0; |
| 3746 | result = 31 * result + (mHistoricalOps != null ? mHistoricalOps.hashCode() : 0); |
| 3747 | return result; |
| 3748 | } |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 3749 | } |
| 3750 | |
| 3751 | /** |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 3752 | * This class represents historical information about an app op. |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 3753 | * |
| 3754 | * @hide |
| 3755 | */ |
| 3756 | @TestApi |
| 3757 | @SystemApi |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 3758 | public static final class HistoricalOp implements Parcelable { |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 3759 | private final int mOp; |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 3760 | private @Nullable LongSparseLongArray mAccessCount; |
| 3761 | private @Nullable LongSparseLongArray mRejectCount; |
| 3762 | private @Nullable LongSparseLongArray mAccessDuration; |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 3763 | |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 3764 | /** @hide */ |
| 3765 | public HistoricalOp(int op) { |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 3766 | mOp = op; |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 3767 | } |
| 3768 | |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 3769 | private HistoricalOp(@NonNull HistoricalOp other) { |
| 3770 | mOp = other.mOp; |
| 3771 | if (other.mAccessCount != null) { |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 3772 | mAccessCount = other.mAccessCount.clone(); |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 3773 | } |
| 3774 | if (other.mRejectCount != null) { |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 3775 | mRejectCount = other.mRejectCount.clone(); |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 3776 | } |
| 3777 | if (other.mAccessDuration != null) { |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 3778 | mAccessDuration = other.mAccessDuration.clone(); |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 3779 | } |
| 3780 | } |
| 3781 | |
| 3782 | private HistoricalOp(@NonNull Parcel parcel) { |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 3783 | mOp = parcel.readInt(); |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 3784 | mAccessCount = readLongSparseLongArrayFromParcel(parcel); |
| 3785 | mRejectCount = readLongSparseLongArrayFromParcel(parcel); |
| 3786 | mAccessDuration = readLongSparseLongArrayFromParcel(parcel); |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 3787 | } |
| 3788 | |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 3789 | private void filter(double scaleFactor) { |
| 3790 | scale(mAccessCount, scaleFactor); |
| 3791 | scale(mRejectCount, scaleFactor); |
| 3792 | scale(mAccessDuration, scaleFactor); |
| 3793 | } |
| 3794 | |
| 3795 | private boolean isEmpty() { |
| 3796 | return !hasData(mAccessCount) |
| 3797 | && !hasData(mRejectCount) |
| 3798 | && !hasData(mAccessDuration); |
| 3799 | } |
| 3800 | |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 3801 | private boolean hasData(@NonNull LongSparseLongArray array) { |
| 3802 | return (array != null && array.size() > 0); |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 3803 | } |
| 3804 | |
| 3805 | private @Nullable HistoricalOp splice(double fractionToRemove) { |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 3806 | final HistoricalOp splice = new HistoricalOp(mOp); |
| 3807 | splice(mAccessCount, splice::getOrCreateAccessCount, fractionToRemove); |
| 3808 | splice(mRejectCount, splice::getOrCreateRejectCount, fractionToRemove); |
| 3809 | splice(mAccessDuration, splice::getOrCreateAccessDuration, fractionToRemove); |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 3810 | return splice; |
| 3811 | } |
| 3812 | |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 3813 | private static void splice(@Nullable LongSparseLongArray sourceContainer, |
| 3814 | @NonNull Supplier<LongSparseLongArray> destContainerProvider, |
| 3815 | double fractionToRemove) { |
| 3816 | if (sourceContainer != null) { |
| 3817 | final int size = sourceContainer.size(); |
| 3818 | for (int i = 0; i < size; i++) { |
| 3819 | final long key = sourceContainer.keyAt(i); |
| 3820 | final long value = sourceContainer.valueAt(i); |
| 3821 | final long removedFraction = Math.round(value * fractionToRemove); |
| 3822 | if (removedFraction > 0) { |
| 3823 | destContainerProvider.get().put(key, removedFraction); |
| 3824 | sourceContainer.put(key, value - removedFraction); |
| 3825 | } |
| 3826 | } |
| 3827 | } |
| 3828 | } |
| 3829 | |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 3830 | private void merge(@NonNull HistoricalOp other) { |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 3831 | merge(this::getOrCreateAccessCount, other.mAccessCount); |
| 3832 | merge(this::getOrCreateRejectCount, other.mRejectCount); |
| 3833 | merge(this::getOrCreateAccessDuration, other.mAccessDuration); |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 3834 | } |
| 3835 | |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 3836 | private void increaseAccessCount(@UidState int uidState, @OpFlags int flags, |
| 3837 | long increment) { |
| 3838 | increaseCount(getOrCreateAccessCount(), uidState, flags, increment); |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 3839 | } |
| 3840 | |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 3841 | private void increaseRejectCount(@UidState int uidState, @OpFlags int flags, |
| 3842 | long increment) { |
| 3843 | increaseCount(getOrCreateRejectCount(), uidState, flags, increment); |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 3844 | } |
| 3845 | |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 3846 | private void increaseAccessDuration(@UidState int uidState, @OpFlags int flags, |
| 3847 | long increment) { |
| 3848 | increaseCount(getOrCreateAccessDuration(), uidState, flags, increment); |
| 3849 | } |
| 3850 | |
| 3851 | private void increaseCount(@NonNull LongSparseLongArray counts, |
| 3852 | @UidState int uidState, @OpFlags int flags, long increment) { |
| 3853 | while (flags != 0) { |
| 3854 | final int flag = 1 << Integer.numberOfTrailingZeros(flags); |
| 3855 | flags &= ~flag; |
| 3856 | final long key = makeKey(uidState, flag); |
| 3857 | counts.put(key, counts.get(key) + increment); |
| 3858 | } |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 3859 | } |
| 3860 | |
| 3861 | /** |
| 3862 | * Gets the op name. |
| 3863 | * |
| 3864 | * @return The op name. |
| 3865 | */ |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 3866 | public @NonNull String getOpName() { |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 3867 | return sOpToString[mOp]; |
| 3868 | } |
| 3869 | |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 3870 | /** @hide */ |
| 3871 | public int getOpCode() { |
| 3872 | return mOp; |
| 3873 | } |
| 3874 | |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 3875 | /** |
| 3876 | * Gets the number times the op was accessed (performed) in the foreground. |
| 3877 | * |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 3878 | * @param flags The flags which are any combination of |
| 3879 | * {@link #OP_FLAG_SELF}, {@link #OP_FLAG_TRUSTED_PROXY}, |
| 3880 | * {@link #OP_FLAG_UNTRUSTED_PROXY}, {@link #OP_FLAG_TRUSTED_PROXIED}, |
| 3881 | * {@link #OP_FLAG_UNTRUSTED_PROXIED}. You can use {@link #OP_FLAGS_ALL} |
| 3882 | * for any flag. |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 3883 | * @return The times the op was accessed in the foreground. |
| 3884 | * |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 3885 | * @see #getBackgroundAccessCount(int) |
| 3886 | * @see #getAccessCount(int, int, int) |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 3887 | */ |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 3888 | public long getForegroundAccessCount(@OpFlags int flags) { |
| 3889 | return sumForFlagsInStates(mAccessCount, MAX_PRIORITY_UID_STATE, |
| 3890 | resolveFirstUnrestrictedUidState(mOp), flags); |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 3891 | } |
| 3892 | |
| 3893 | /** |
| 3894 | * Gets the number times the op was accessed (performed) in the background. |
| 3895 | * |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 3896 | * @param flags The flags which are any combination of |
| 3897 | * {@link #OP_FLAG_SELF}, {@link #OP_FLAG_TRUSTED_PROXY}, |
| 3898 | * {@link #OP_FLAG_UNTRUSTED_PROXY}, {@link #OP_FLAG_TRUSTED_PROXIED}, |
| 3899 | * {@link #OP_FLAG_UNTRUSTED_PROXIED}. You can use {@link #OP_FLAGS_ALL} |
| 3900 | * for any flag. |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 3901 | * @return The times the op was accessed in the background. |
| 3902 | * |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 3903 | * @see #getForegroundAccessCount(int) |
| 3904 | * @see #getAccessCount(int, int, int) |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 3905 | */ |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 3906 | public long getBackgroundAccessCount(@OpFlags int flags) { |
| 3907 | return sumForFlagsInStates(mAccessCount, resolveLastRestrictedUidState(mOp), |
| 3908 | MIN_PRIORITY_UID_STATE, flags); |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 3909 | } |
| 3910 | |
| 3911 | /** |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 3912 | * Gets the number times the op was accessed (performed) for a |
| 3913 | * range of uid states. |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 3914 | * |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 3915 | * @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] | 3916 | * {@link #UID_STATE_PERSISTENT}, {@link #UID_STATE_TOP}, |
Amith Yamasani | a0a30a1 | 2019-01-22 11:38:06 -0800 | [diff] [blame] | 3917 | * {@link #UID_STATE_FOREGROUND_SERVICE_LOCATION}, |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 3918 | * {@link #UID_STATE_FOREGROUND_SERVICE}, {@link #UID_STATE_FOREGROUND}, |
| 3919 | * {@link #UID_STATE_BACKGROUND}, {@link #UID_STATE_CACHED}. |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 3920 | * @param toUidState The UID state to which to query. |
| 3921 | * @param flags The flags which are any combination of |
| 3922 | * {@link #OP_FLAG_SELF}, {@link #OP_FLAG_TRUSTED_PROXY}, |
| 3923 | * {@link #OP_FLAG_UNTRUSTED_PROXY}, {@link #OP_FLAG_TRUSTED_PROXIED}, |
| 3924 | * {@link #OP_FLAG_UNTRUSTED_PROXIED}. You can use {@link #OP_FLAGS_ALL} |
| 3925 | * for any flag. |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 3926 | * |
| 3927 | * @return The times the op was accessed for the given UID state. |
| 3928 | * |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 3929 | * @see #getForegroundAccessCount(int) |
| 3930 | * @see #getBackgroundAccessCount(int) |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 3931 | */ |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 3932 | public long getAccessCount(@UidState int fromUidState, @UidState int toUidState, |
| 3933 | @OpFlags int flags) { |
| 3934 | return sumForFlagsInStates(mAccessCount, fromUidState, toUidState, flags); |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 3935 | } |
| 3936 | |
| 3937 | /** |
| 3938 | * Gets the number times the op was rejected in the foreground. |
| 3939 | * |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 3940 | * @param flags The flags which are any combination of |
| 3941 | * {@link #OP_FLAG_SELF}, {@link #OP_FLAG_TRUSTED_PROXY}, |
| 3942 | * {@link #OP_FLAG_UNTRUSTED_PROXY}, {@link #OP_FLAG_TRUSTED_PROXIED}, |
| 3943 | * {@link #OP_FLAG_UNTRUSTED_PROXIED}. You can use {@link #OP_FLAGS_ALL} |
| 3944 | * for any flag. |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 3945 | * @return The times the op was rejected in the foreground. |
| 3946 | * |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 3947 | * @see #getBackgroundRejectCount(int) |
| 3948 | * @see #getRejectCount(int, int, int) |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 3949 | */ |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 3950 | public long getForegroundRejectCount(@OpFlags int flags) { |
| 3951 | return sumForFlagsInStates(mRejectCount, MAX_PRIORITY_UID_STATE, |
| 3952 | resolveFirstUnrestrictedUidState(mOp), flags); |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 3953 | } |
| 3954 | |
| 3955 | /** |
| 3956 | * Gets the number times the op was rejected in the background. |
| 3957 | * |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 3958 | * @param flags The flags which are any combination of |
| 3959 | * {@link #OP_FLAG_SELF}, {@link #OP_FLAG_TRUSTED_PROXY}, |
| 3960 | * {@link #OP_FLAG_UNTRUSTED_PROXY}, {@link #OP_FLAG_TRUSTED_PROXIED}, |
| 3961 | * {@link #OP_FLAG_UNTRUSTED_PROXIED}. You can use {@link #OP_FLAGS_ALL} |
| 3962 | * for any flag. |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 3963 | * @return The times the op was rejected in the background. |
| 3964 | * |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 3965 | * @see #getForegroundRejectCount(int) |
| 3966 | * @see #getRejectCount(int, int, int) |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 3967 | */ |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 3968 | public long getBackgroundRejectCount(@OpFlags int flags) { |
| 3969 | return sumForFlagsInStates(mRejectCount, resolveLastRestrictedUidState(mOp), |
| 3970 | MIN_PRIORITY_UID_STATE, flags); |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 3971 | } |
| 3972 | |
| 3973 | /** |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 3974 | * 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] | 3975 | * |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 3976 | * @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] | 3977 | * {@link #UID_STATE_PERSISTENT}, {@link #UID_STATE_TOP}, |
Amith Yamasani | a0a30a1 | 2019-01-22 11:38:06 -0800 | [diff] [blame] | 3978 | * {@link #UID_STATE_FOREGROUND_SERVICE_LOCATION}, |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 3979 | * {@link #UID_STATE_FOREGROUND_SERVICE}, {@link #UID_STATE_FOREGROUND}, |
| 3980 | * {@link #UID_STATE_BACKGROUND}, {@link #UID_STATE_CACHED}. |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 3981 | * @param toUidState The UID state to which to query. |
| 3982 | * @param flags The flags which are any combination of |
| 3983 | * {@link #OP_FLAG_SELF}, {@link #OP_FLAG_TRUSTED_PROXY}, |
| 3984 | * {@link #OP_FLAG_UNTRUSTED_PROXY}, {@link #OP_FLAG_TRUSTED_PROXIED}, |
| 3985 | * {@link #OP_FLAG_UNTRUSTED_PROXIED}. You can use {@link #OP_FLAGS_ALL} |
| 3986 | * for any flag. |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 3987 | * |
| 3988 | * @return The times the op was rejected for the given UID state. |
| 3989 | * |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 3990 | * @see #getForegroundRejectCount(int) |
| 3991 | * @see #getBackgroundRejectCount(int) |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 3992 | */ |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 3993 | public long getRejectCount(@UidState int fromUidState, @UidState int toUidState, |
| 3994 | @OpFlags int flags) { |
| 3995 | return sumForFlagsInStates(mRejectCount, fromUidState, toUidState, flags); |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 3996 | } |
| 3997 | |
| 3998 | /** |
| 3999 | * 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] | 4000 | * The duration is in wall time. |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 4001 | * |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 4002 | * @param flags The flags which are any combination of |
| 4003 | * {@link #OP_FLAG_SELF}, {@link #OP_FLAG_TRUSTED_PROXY}, |
| 4004 | * {@link #OP_FLAG_UNTRUSTED_PROXY}, {@link #OP_FLAG_TRUSTED_PROXIED}, |
| 4005 | * {@link #OP_FLAG_UNTRUSTED_PROXIED}. You can use {@link #OP_FLAGS_ALL} |
| 4006 | * for any flag. |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 4007 | * @return The total duration the app op was accessed in the foreground. |
| 4008 | * |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 4009 | * @see #getBackgroundAccessDuration(int) |
| 4010 | * @see #getAccessDuration(int, int, int) |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 4011 | */ |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 4012 | public long getForegroundAccessDuration(@OpFlags int flags) { |
| 4013 | return sumForFlagsInStates(mAccessDuration, MAX_PRIORITY_UID_STATE, |
| 4014 | resolveFirstUnrestrictedUidState(mOp), flags); |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 4015 | } |
| 4016 | |
| 4017 | /** |
| 4018 | * 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] | 4019 | * The duration is in wall time. |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 4020 | * |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 4021 | * @param flags The flags which are any combination of |
| 4022 | * {@link #OP_FLAG_SELF}, {@link #OP_FLAG_TRUSTED_PROXY}, |
| 4023 | * {@link #OP_FLAG_UNTRUSTED_PROXY}, {@link #OP_FLAG_TRUSTED_PROXIED}, |
| 4024 | * {@link #OP_FLAG_UNTRUSTED_PROXIED}. You can use {@link #OP_FLAGS_ALL} |
| 4025 | * for any flag. |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 4026 | * @return The total duration the app op was accessed in the background. |
| 4027 | * |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 4028 | * @see #getForegroundAccessDuration(int) |
| 4029 | * @see #getAccessDuration(int, int, int) |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 4030 | */ |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 4031 | public long getBackgroundAccessDuration(@OpFlags int flags) { |
| 4032 | return sumForFlagsInStates(mAccessDuration, resolveLastRestrictedUidState(mOp), |
| 4033 | MIN_PRIORITY_UID_STATE, flags); |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 4034 | } |
| 4035 | |
| 4036 | /** |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 4037 | * 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] | 4038 | * range of UID states. The duration is in wall time. |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 4039 | * |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 4040 | * @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] | 4041 | * {@link #UID_STATE_PERSISTENT}, {@link #UID_STATE_TOP}, |
Amith Yamasani | a0a30a1 | 2019-01-22 11:38:06 -0800 | [diff] [blame] | 4042 | * {@link #UID_STATE_FOREGROUND_SERVICE_LOCATION}, |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 4043 | * {@link #UID_STATE_FOREGROUND_SERVICE}, {@link #UID_STATE_FOREGROUND}, |
| 4044 | * {@link #UID_STATE_BACKGROUND}, {@link #UID_STATE_CACHED}. |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 4045 | * @param toUidState The UID state from which to query. |
| 4046 | * @param flags The flags which are any combination of |
| 4047 | * {@link #OP_FLAG_SELF}, {@link #OP_FLAG_TRUSTED_PROXY}, |
| 4048 | * {@link #OP_FLAG_UNTRUSTED_PROXY}, {@link #OP_FLAG_TRUSTED_PROXIED}, |
| 4049 | * {@link #OP_FLAG_UNTRUSTED_PROXIED}. You can use {@link #OP_FLAGS_ALL} |
| 4050 | * for any flag. |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 4051 | * |
| 4052 | * @return The total duration the app op was accessed for the given UID state. |
| 4053 | * |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 4054 | * @see #getForegroundAccessDuration(int) |
| 4055 | * @see #getBackgroundAccessDuration(int) |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 4056 | */ |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 4057 | public long getAccessDuration(@UidState int fromUidState, @UidState int toUidState, |
| 4058 | @OpFlags int flags) { |
| 4059 | return sumForFlagsInStates(mAccessDuration, fromUidState, toUidState, flags); |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 4060 | } |
| 4061 | |
| 4062 | @Override |
| 4063 | public int describeContents() { |
| 4064 | return 0; |
| 4065 | } |
| 4066 | |
| 4067 | @Override |
| 4068 | public void writeToParcel(Parcel parcel, int flags) { |
| 4069 | parcel.writeInt(mOp); |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 4070 | writeLongSparseLongArrayToParcel(mAccessCount, parcel); |
| 4071 | writeLongSparseLongArrayToParcel(mRejectCount, parcel); |
| 4072 | writeLongSparseLongArrayToParcel(mAccessDuration, parcel); |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 4073 | } |
| 4074 | |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 4075 | @Override |
Aurimas Liutikas | 00be951 | 2019-08-28 13:01:05 -0700 | [diff] [blame] | 4076 | public boolean equals(@Nullable Object obj) { |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 4077 | if (this == obj) { |
| 4078 | return true; |
| 4079 | } |
| 4080 | if (obj == null || getClass() != obj.getClass()) { |
| 4081 | return false; |
| 4082 | } |
| 4083 | final HistoricalOp other = (HistoricalOp) obj; |
| 4084 | if (mOp != other.mOp) { |
| 4085 | return false; |
| 4086 | } |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 4087 | if (!Objects.equals(mAccessCount, other.mAccessCount)) { |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 4088 | return false; |
| 4089 | } |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 4090 | if (!Objects.equals(mRejectCount, other.mRejectCount)) { |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 4091 | return false; |
| 4092 | } |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 4093 | return Objects.equals(mAccessDuration, other.mAccessDuration); |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 4094 | } |
| 4095 | |
| 4096 | @Override |
| 4097 | public int hashCode() { |
| 4098 | int result = mOp; |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 4099 | result = 31 * result + Objects.hashCode(mAccessCount); |
| 4100 | result = 31 * result + Objects.hashCode(mRejectCount); |
| 4101 | result = 31 * result + Objects.hashCode(mAccessDuration); |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 4102 | return result; |
| 4103 | } |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 4104 | |
| 4105 | private void accept(@NonNull HistoricalOpsVisitor visitor) { |
| 4106 | visitor.visitHistoricalOp(this); |
| 4107 | } |
| 4108 | |
| 4109 | private @NonNull LongSparseLongArray getOrCreateAccessCount() { |
| 4110 | if (mAccessCount == null) { |
| 4111 | mAccessCount = new LongSparseLongArray(); |
| 4112 | } |
| 4113 | return mAccessCount; |
| 4114 | } |
| 4115 | |
| 4116 | private @NonNull LongSparseLongArray getOrCreateRejectCount() { |
| 4117 | if (mRejectCount == null) { |
| 4118 | mRejectCount = new LongSparseLongArray(); |
| 4119 | } |
| 4120 | return mRejectCount; |
| 4121 | } |
| 4122 | |
| 4123 | private @NonNull LongSparseLongArray getOrCreateAccessDuration() { |
| 4124 | if (mAccessDuration == null) { |
| 4125 | mAccessDuration = new LongSparseLongArray(); |
| 4126 | } |
| 4127 | return mAccessDuration; |
| 4128 | } |
| 4129 | |
| 4130 | /** |
| 4131 | * Multiplies the entries in the array with the passed in scale factor and |
| 4132 | * rounds the result at up 0.5 boundary. |
| 4133 | * |
| 4134 | * @param data The data to scale. |
| 4135 | * @param scaleFactor The scale factor. |
| 4136 | */ |
| 4137 | private static void scale(@NonNull LongSparseLongArray data, double scaleFactor) { |
| 4138 | if (data != null) { |
| 4139 | final int size = data.size(); |
| 4140 | for (int i = 0; i < size; i++) { |
| 4141 | data.put(data.keyAt(i), (long) HistoricalOps.round( |
| 4142 | (double) data.valueAt(i) * scaleFactor)); |
| 4143 | } |
| 4144 | } |
| 4145 | } |
| 4146 | |
| 4147 | /** |
| 4148 | * Merges two arrays while lazily acquiring the destination. |
| 4149 | * |
| 4150 | * @param thisSupplier The destination supplier. |
| 4151 | * @param other The array to merge in. |
| 4152 | */ |
| 4153 | private static void merge(@NonNull Supplier<LongSparseLongArray> thisSupplier, |
| 4154 | @Nullable LongSparseLongArray other) { |
| 4155 | if (other != null) { |
| 4156 | final int otherSize = other.size(); |
| 4157 | for (int i = 0; i < otherSize; i++) { |
| 4158 | final LongSparseLongArray that = thisSupplier.get(); |
| 4159 | final long otherKey = other.keyAt(i); |
| 4160 | final long otherValue = other.valueAt(i); |
| 4161 | that.put(otherKey, that.get(otherKey) + otherValue); |
| 4162 | } |
| 4163 | } |
| 4164 | } |
| 4165 | |
| 4166 | /** @hide */ |
| 4167 | public @Nullable LongSparseArray<Object> collectKeys() { |
| 4168 | LongSparseArray<Object> result = AppOpsManager.collectKeys(mAccessCount, |
| 4169 | null /*result*/); |
| 4170 | result = AppOpsManager.collectKeys(mRejectCount, result); |
| 4171 | result = AppOpsManager.collectKeys(mAccessDuration, result); |
| 4172 | return result; |
| 4173 | } |
| 4174 | |
| 4175 | public static final @android.annotation.NonNull Creator<HistoricalOp> CREATOR = |
| 4176 | new Creator<HistoricalOp>() { |
| 4177 | @Override |
| 4178 | public @NonNull HistoricalOp createFromParcel(@NonNull Parcel source) { |
| 4179 | return new HistoricalOp(source); |
| 4180 | } |
| 4181 | |
| 4182 | @Override |
| 4183 | public @NonNull HistoricalOp[] newArray(int size) { |
| 4184 | return new HistoricalOp[size]; |
| 4185 | } |
| 4186 | }; |
| 4187 | } |
| 4188 | |
| 4189 | /** |
| 4190 | * Computes the sum of the counts for the given flags in between the begin and |
| 4191 | * end UID states. |
| 4192 | * |
| 4193 | * @param counts The data array. |
Philip P. Moltmann | 4052d36 | 2019-09-19 14:52:38 -0700 | [diff] [blame] | 4194 | * @param beginUidState The beginning UID state (inclusive). |
| 4195 | * @param endUidState The end UID state (inclusive). |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 4196 | * @param flags The UID flags. |
| 4197 | * @return The sum. |
| 4198 | */ |
| 4199 | private static long sumForFlagsInStates(@Nullable LongSparseLongArray counts, |
| 4200 | @UidState int beginUidState, @UidState int endUidState, @OpFlags int flags) { |
| 4201 | if (counts == null) { |
| 4202 | return 0; |
| 4203 | } |
| 4204 | long sum = 0; |
| 4205 | while (flags != 0) { |
| 4206 | final int flag = 1 << Integer.numberOfTrailingZeros(flags); |
| 4207 | flags &= ~flag; |
| 4208 | for (int uidState : UID_STATES) { |
| 4209 | if (uidState < beginUidState || uidState > endUidState) { |
| 4210 | continue; |
| 4211 | } |
| 4212 | final long key = makeKey(uidState, flag); |
| 4213 | sum += counts.get(key); |
| 4214 | } |
| 4215 | } |
| 4216 | return sum; |
| 4217 | } |
| 4218 | |
| 4219 | /** |
| 4220 | * Finds the first non-negative value for the given flags in between the begin and |
| 4221 | * end UID states. |
| 4222 | * |
| 4223 | * @param counts The data array. |
Philip P. Moltmann | 4052d36 | 2019-09-19 14:52:38 -0700 | [diff] [blame] | 4224 | * @param beginUidState The beginning UID state (inclusive). |
| 4225 | * @param endUidState The end UID state (inclusive). |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 4226 | * @param flags The UID flags. |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 4227 | * @return The non-negative value or -1. |
| 4228 | */ |
| 4229 | private static long findFirstNonNegativeForFlagsInStates(@Nullable LongSparseLongArray counts, |
Philip P. Moltmann | 4052d36 | 2019-09-19 14:52:38 -0700 | [diff] [blame] | 4230 | @UidState int beginUidState, @UidState int endUidState, @OpFlags int flags) { |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 4231 | if (counts == null) { |
| 4232 | return -1; |
| 4233 | } |
| 4234 | while (flags != 0) { |
| 4235 | final int flag = 1 << Integer.numberOfTrailingZeros(flags); |
| 4236 | flags &= ~flag; |
| 4237 | for (int uidState : UID_STATES) { |
| 4238 | if (uidState < beginUidState || uidState > endUidState) { |
| 4239 | continue; |
| 4240 | } |
| 4241 | final long key = makeKey(uidState, flag); |
| 4242 | final long value = counts.get(key); |
| 4243 | if (value >= 0) { |
| 4244 | return value; |
| 4245 | } |
| 4246 | } |
| 4247 | } |
| 4248 | return -1; |
| 4249 | } |
| 4250 | |
| 4251 | /** |
| 4252 | * Finds the first non-null value for the given flags in between the begin and |
| 4253 | * end UID states. |
| 4254 | * |
| 4255 | * @param counts The data array. |
Philip P. Moltmann | 4052d36 | 2019-09-19 14:52:38 -0700 | [diff] [blame] | 4256 | * @param beginUidState The beginning UID state (inclusive). |
| 4257 | * @param endUidState The end UID state (inclusive). |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 4258 | * @param flags The UID flags. |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 4259 | * @return The non-negative value or -1. |
| 4260 | */ |
| 4261 | private static @Nullable String findFirstNonNullForFlagsInStates( |
Philip P. Moltmann | 4052d36 | 2019-09-19 14:52:38 -0700 | [diff] [blame] | 4262 | @Nullable LongSparseArray<String> counts, @UidState int beginUidState, |
| 4263 | @UidState int endUidState, @OpFlags int flags) { |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 4264 | if (counts == null) { |
| 4265 | return null; |
| 4266 | } |
| 4267 | while (flags != 0) { |
| 4268 | final int flag = 1 << Integer.numberOfTrailingZeros(flags); |
| 4269 | flags &= ~flag; |
| 4270 | for (int uidState : UID_STATES) { |
| 4271 | if (uidState < beginUidState || uidState > endUidState) { |
| 4272 | continue; |
| 4273 | } |
| 4274 | final long key = makeKey(uidState, flag); |
| 4275 | final String value = counts.get(key); |
| 4276 | if (value != null) { |
| 4277 | return value; |
| 4278 | } |
| 4279 | } |
| 4280 | } |
| 4281 | return null; |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 4282 | } |
| 4283 | |
| 4284 | /** |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 4285 | * Callback for notification of changes to operation state. |
| 4286 | */ |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 4287 | public interface OnOpChangedListener { |
| 4288 | public void onOpChanged(String op, String packageName); |
| 4289 | } |
| 4290 | |
| 4291 | /** |
Svetoslav Ganov | 2d20fb4 | 2018-02-08 15:52:10 -0800 | [diff] [blame] | 4292 | * Callback for notification of changes to operation active state. |
| 4293 | * |
| 4294 | * @hide |
| 4295 | */ |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 4296 | @TestApi |
Svetoslav Ganov | 2d20fb4 | 2018-02-08 15:52:10 -0800 | [diff] [blame] | 4297 | public interface OnOpActiveChangedListener { |
| 4298 | /** |
| 4299 | * Called when the active state of an app op changes. |
| 4300 | * |
| 4301 | * @param code The op code. |
| 4302 | * @param uid The UID performing the operation. |
| 4303 | * @param packageName The package performing the operation. |
| 4304 | * @param active Whether the operation became active or inactive. |
| 4305 | */ |
| 4306 | void onOpActiveChanged(int code, int uid, String packageName, boolean active); |
| 4307 | } |
| 4308 | |
| 4309 | /** |
Svet Ganov | b3d2ae2 | 2018-12-17 22:06:15 -0800 | [diff] [blame] | 4310 | * Callback for notification of an op being noted. |
| 4311 | * |
| 4312 | * @hide |
| 4313 | */ |
| 4314 | public interface OnOpNotedListener { |
| 4315 | /** |
| 4316 | * Called when an op was noted. |
| 4317 | * |
| 4318 | * @param code The op code. |
| 4319 | * @param uid The UID performing the operation. |
| 4320 | * @param packageName The package performing the operation. |
| 4321 | * @param result The result of the note. |
| 4322 | */ |
Fabian Kozynski | 0b4592c | 2018-12-20 12:58:45 -0500 | [diff] [blame] | 4323 | void onOpNoted(int code, int uid, String packageName, int result); |
Svet Ganov | b3d2ae2 | 2018-12-17 22:06:15 -0800 | [diff] [blame] | 4324 | } |
| 4325 | |
| 4326 | /** |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 4327 | * Callback for notification of changes to operation state. |
| 4328 | * This allows you to see the raw op codes instead of strings. |
| 4329 | * @hide |
| 4330 | */ |
| 4331 | public static class OnOpChangedInternalListener implements OnOpChangedListener { |
| 4332 | public void onOpChanged(String op, String packageName) { } |
| 4333 | public void onOpChanged(int op, String packageName) { } |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 4334 | } |
| 4335 | |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 4336 | AppOpsManager(Context context, IAppOpsService service) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4337 | mContext = context; |
| 4338 | mService = service; |
| 4339 | } |
| 4340 | |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 4341 | /** |
| 4342 | * Retrieve current operation state for all applications. |
| 4343 | * |
Winson | 6a864b5 | 2019-05-10 10:34:14 -0700 | [diff] [blame] | 4344 | * The mode of the ops returned are set for the package but may not reflect their effective |
| 4345 | * state due to UID policy or because it's controlled by a different master op. |
| 4346 | * |
| 4347 | * Use {@link #unsafeCheckOp(String, int, String)}} or {@link #noteOp(String, int, String)} |
| 4348 | * if the effective mode is needed. |
| 4349 | * |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 4350 | * @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] | 4351 | * @hide |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 4352 | */ |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 4353 | @SystemApi |
| 4354 | @RequiresPermission(android.Manifest.permission.GET_APP_OPS_STATS) |
| 4355 | public @NonNull List<AppOpsManager.PackageOps> getPackagesForOps(@Nullable String[] ops) { |
| 4356 | final int opCount = ops.length; |
| 4357 | final int[] opCodes = new int[opCount]; |
| 4358 | for (int i = 0; i < opCount; i++) { |
| 4359 | opCodes[i] = sOpStrToOp.get(ops[i]); |
| 4360 | } |
| 4361 | final List<AppOpsManager.PackageOps> result = getPackagesForOps(opCodes); |
| 4362 | return (result != null) ? result : Collections.emptyList(); |
| 4363 | } |
| 4364 | |
| 4365 | /** |
| 4366 | * Retrieve current operation state for all applications. |
| 4367 | * |
Winson | 6a864b5 | 2019-05-10 10:34:14 -0700 | [diff] [blame] | 4368 | * The mode of the ops returned are set for the package but may not reflect their effective |
| 4369 | * state due to UID policy or because it's controlled by a different master op. |
| 4370 | * |
| 4371 | * Use {@link #unsafeCheckOp(String, int, String)}} or {@link #noteOp(String, int, String)} |
| 4372 | * if the effective mode is needed. |
| 4373 | * |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 4374 | * @param ops The set of operations you are interested in, or null if you want all of them. |
| 4375 | * @hide |
| 4376 | */ |
Dianne Hackborn | c216a26 | 2018-04-26 13:46:22 -0700 | [diff] [blame] | 4377 | @RequiresPermission(android.Manifest.permission.GET_APP_OPS_STATS) |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 4378 | @UnsupportedAppUsage |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 4379 | public List<AppOpsManager.PackageOps> getPackagesForOps(int[] ops) { |
| 4380 | try { |
| 4381 | return mService.getPackagesForOps(ops); |
| 4382 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 4383 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 4384 | } |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 4385 | } |
| 4386 | |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 4387 | /** |
| 4388 | * Retrieve current operation state for one application. |
| 4389 | * |
Winson | 6a864b5 | 2019-05-10 10:34:14 -0700 | [diff] [blame] | 4390 | * The mode of the ops returned are set for the package but may not reflect their effective |
| 4391 | * state due to UID policy or because it's controlled by a different master op. |
| 4392 | * |
| 4393 | * Use {@link #unsafeCheckOp(String, int, String)}} or {@link #noteOp(String, int, String)} |
| 4394 | * if the effective mode is needed. |
| 4395 | * |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 4396 | * @param uid The uid of the application of interest. |
| 4397 | * @param packageName The name of the application of interest. |
| 4398 | * @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] | 4399 | * |
| 4400 | * @deprecated The int op codes are not stable and you should use the string based op |
| 4401 | * names which are stable and namespaced. Use |
| 4402 | * {@link #getOpsForPackage(int, String, String...)})}. |
| 4403 | * |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 4404 | * @hide |
Suprabh Shukla | 169bed7 | 2019-05-13 13:54:58 -0700 | [diff] [blame] | 4405 | * @removed |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 4406 | */ |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 4407 | @Deprecated |
Dianne Hackborn | f0c322a | 2018-06-13 15:24:04 -0700 | [diff] [blame] | 4408 | @SystemApi |
Dianne Hackborn | c216a26 | 2018-04-26 13:46:22 -0700 | [diff] [blame] | 4409 | @RequiresPermission(android.Manifest.permission.GET_APP_OPS_STATS) |
Dianne Hackborn | 6287849 | 2019-03-11 15:57:07 -0700 | [diff] [blame] | 4410 | public @NonNull List<PackageOps> getOpsForPackage(int uid, @NonNull String packageName, |
| 4411 | @Nullable int[] ops) { |
Dianne Hackborn | 72e3983 | 2013-01-18 18:36:09 -0800 | [diff] [blame] | 4412 | try { |
| 4413 | return mService.getOpsForPackage(uid, packageName, ops); |
| 4414 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 4415 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 72e3983 | 2013-01-18 18:36:09 -0800 | [diff] [blame] | 4416 | } |
Dianne Hackborn | 72e3983 | 2013-01-18 18:36:09 -0800 | [diff] [blame] | 4417 | } |
| 4418 | |
Svet Ganov | ae0e03a | 2016-02-25 18:22:10 -0800 | [diff] [blame] | 4419 | /** |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 4420 | * Retrieve current operation state for one application. The UID and the |
| 4421 | * package must match. |
| 4422 | * |
Winson | 6a864b5 | 2019-05-10 10:34:14 -0700 | [diff] [blame] | 4423 | * The mode of the ops returned are set for the package but may not reflect their effective |
| 4424 | * state due to UID policy or because it's controlled by a different master op. |
| 4425 | * |
| 4426 | * Use {@link #unsafeCheckOp(String, int, String)}} or {@link #noteOp(String, int, String)} |
| 4427 | * if the effective mode is needed. |
| 4428 | * |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 4429 | * @param uid The uid of the application of interest. |
| 4430 | * @param packageName The name of the application of interest. |
| 4431 | * @param ops The set of operations you are interested in, or null if you want all of them. |
| 4432 | * |
| 4433 | * @hide |
| 4434 | */ |
| 4435 | @SystemApi |
| 4436 | @RequiresPermission(android.Manifest.permission.GET_APP_OPS_STATS) |
| 4437 | public @NonNull List<AppOpsManager.PackageOps> getOpsForPackage(int uid, |
| 4438 | @NonNull String packageName, @Nullable String... ops) { |
| 4439 | int[] opCodes = null; |
| 4440 | if (ops != null) { |
| 4441 | opCodes = new int[ops.length]; |
| 4442 | for (int i = 0; i < ops.length; i++) { |
| 4443 | opCodes[i] = strOpToOp(ops[i]); |
| 4444 | } |
| 4445 | } |
| 4446 | try { |
| 4447 | final List<PackageOps> result = mService.getOpsForPackage(uid, packageName, opCodes); |
| 4448 | if (result == null) { |
| 4449 | return Collections.emptyList(); |
| 4450 | } |
| 4451 | return result; |
| 4452 | } catch (RemoteException e) { |
| 4453 | throw e.rethrowFromSystemServer(); |
| 4454 | } |
| 4455 | } |
| 4456 | |
| 4457 | /** |
| 4458 | * Retrieve historical app op stats for a period. |
| 4459 | * |
Svet Ganov | 23c88db | 2019-01-22 20:38:11 -0800 | [diff] [blame] | 4460 | * @param request A request object describing the data being queried for. |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 4461 | * @param executor Executor on which to run the callback. If <code>null</code> |
| 4462 | * the callback is executed on the default executor running on the main thread. |
| 4463 | * @param callback Callback on which to deliver the result. |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 4464 | * |
| 4465 | * @throws IllegalArgumentException If any of the argument contracts is violated. |
| 4466 | * |
| 4467 | * @hide |
| 4468 | */ |
| 4469 | @TestApi |
| 4470 | @SystemApi |
| 4471 | @RequiresPermission(android.Manifest.permission.GET_APP_OPS_STATS) |
Svet Ganov | 23c88db | 2019-01-22 20:38:11 -0800 | [diff] [blame] | 4472 | public void getHistoricalOps(@NonNull HistoricalOpsRequest request, |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 4473 | @NonNull Executor executor, @NonNull Consumer<HistoricalOps> callback) { |
| 4474 | Preconditions.checkNotNull(executor, "executor cannot be null"); |
| 4475 | Preconditions.checkNotNull(callback, "callback cannot be null"); |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 4476 | try { |
Svet Ganov | 23c88db | 2019-01-22 20:38:11 -0800 | [diff] [blame] | 4477 | mService.getHistoricalOps(request.mUid, request.mPackageName, request.mOpNames, |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 4478 | request.mBeginTimeMillis, request.mEndTimeMillis, request.mFlags, |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 4479 | new RemoteCallback((result) -> { |
| 4480 | final HistoricalOps ops = result.getParcelable(KEY_HISTORICAL_OPS); |
| 4481 | final long identity = Binder.clearCallingIdentity(); |
| 4482 | try { |
| 4483 | executor.execute(() -> callback.accept(ops)); |
| 4484 | } finally { |
| 4485 | Binder.restoreCallingIdentity(identity); |
| 4486 | } |
| 4487 | })); |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 4488 | } catch (RemoteException e) { |
| 4489 | throw e.rethrowFromSystemServer(); |
| 4490 | } |
| 4491 | } |
| 4492 | |
| 4493 | /** |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 4494 | * Retrieve historical app op stats for a period. |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 4495 | * <p> |
| 4496 | * This method queries only the on disk state and the returned ops are raw, |
| 4497 | * which is their times are relative to the history start as opposed to the |
| 4498 | * epoch start. |
| 4499 | * |
Svet Ganov | 23c88db | 2019-01-22 20:38:11 -0800 | [diff] [blame] | 4500 | * @param request A request object describing the data being queried for. |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 4501 | * @param executor Executor on which to run the callback. If <code>null</code> |
| 4502 | * the callback is executed on the default executor running on the main thread. |
| 4503 | * @param callback Callback on which to deliver the result. |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 4504 | * |
| 4505 | * @throws IllegalArgumentException If any of the argument contracts is violated. |
| 4506 | * |
| 4507 | * @hide |
| 4508 | */ |
| 4509 | @TestApi |
Svet Ganov | 8e5bf96 | 2019-03-19 23:59:03 -0700 | [diff] [blame] | 4510 | @RequiresPermission(Manifest.permission.MANAGE_APPOPS) |
Svet Ganov | 23c88db | 2019-01-22 20:38:11 -0800 | [diff] [blame] | 4511 | public void getHistoricalOpsFromDiskRaw(@NonNull HistoricalOpsRequest request, |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 4512 | @Nullable Executor executor, @NonNull Consumer<HistoricalOps> callback) { |
| 4513 | Preconditions.checkNotNull(executor, "executor cannot be null"); |
| 4514 | Preconditions.checkNotNull(callback, "callback cannot be null"); |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 4515 | try { |
Svet Ganov | 23c88db | 2019-01-22 20:38:11 -0800 | [diff] [blame] | 4516 | mService.getHistoricalOpsFromDiskRaw(request.mUid, request.mPackageName, |
| 4517 | request.mOpNames, request.mBeginTimeMillis, request.mEndTimeMillis, |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 4518 | request.mFlags, new RemoteCallback((result) -> { |
Svet Ganov | 23c88db | 2019-01-22 20:38:11 -0800 | [diff] [blame] | 4519 | final HistoricalOps ops = result.getParcelable(KEY_HISTORICAL_OPS); |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 4520 | final long identity = Binder.clearCallingIdentity(); |
| 4521 | try { |
| 4522 | executor.execute(() -> callback.accept(ops)); |
| 4523 | } finally { |
| 4524 | Binder.restoreCallingIdentity(identity); |
| 4525 | } |
| 4526 | })); |
Svet Ganov | ad0a49b | 2018-10-29 10:07:08 -0700 | [diff] [blame] | 4527 | } catch (RemoteException e) { |
| 4528 | throw e.rethrowFromSystemServer(); |
| 4529 | } |
| 4530 | } |
| 4531 | |
| 4532 | /** |
Svet Ganov | 8e5bf96 | 2019-03-19 23:59:03 -0700 | [diff] [blame] | 4533 | * Reloads the non historical state to allow testing the read/write path. |
| 4534 | * |
| 4535 | * @hide |
| 4536 | */ |
| 4537 | @TestApi |
| 4538 | @RequiresPermission(Manifest.permission.MANAGE_APPOPS) |
| 4539 | public void reloadNonHistoricalState() { |
| 4540 | try { |
| 4541 | mService.reloadNonHistoricalState(); |
| 4542 | } catch (RemoteException e) { |
| 4543 | throw e.rethrowFromSystemServer(); |
| 4544 | } |
| 4545 | } |
| 4546 | |
| 4547 | /** |
Svet Ganov | ae0e03a | 2016-02-25 18:22:10 -0800 | [diff] [blame] | 4548 | * Sets given app op in the specified mode for app ops in the UID. |
| 4549 | * This applies to all apps currently in the UID or installed in |
| 4550 | * this UID in the future. |
| 4551 | * |
| 4552 | * @param code The app op. |
| 4553 | * @param uid The UID for which to set the app. |
| 4554 | * @param mode The app op mode to set. |
| 4555 | * @hide |
| 4556 | */ |
Dianne Hackborn | bf1b57d | 2018-03-07 12:42:47 -0800 | [diff] [blame] | 4557 | @RequiresPermission(android.Manifest.permission.MANAGE_APP_OPS_MODES) |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 4558 | public void setUidMode(int code, int uid, @Mode int mode) { |
Svet Ganov | 2af5708 | 2015-07-30 08:44:20 -0700 | [diff] [blame] | 4559 | try { |
| 4560 | mService.setUidMode(code, uid, mode); |
| 4561 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 4562 | throw e.rethrowFromSystemServer(); |
Svet Ganov | 2af5708 | 2015-07-30 08:44:20 -0700 | [diff] [blame] | 4563 | } |
| 4564 | } |
| 4565 | |
Svet Ganov | ae0e03a | 2016-02-25 18:22:10 -0800 | [diff] [blame] | 4566 | /** |
| 4567 | * Sets given app op in the specified mode for app ops in the UID. |
| 4568 | * This applies to all apps currently in the UID or installed in |
| 4569 | * this UID in the future. |
| 4570 | * |
| 4571 | * @param appOp The app op. |
| 4572 | * @param uid The UID for which to set the app. |
| 4573 | * @param mode The app op mode to set. |
| 4574 | * @hide |
| 4575 | */ |
| 4576 | @SystemApi |
Eugene Susla | 9351985 | 2018-06-13 16:44:31 -0700 | [diff] [blame] | 4577 | @TestApi |
Dianne Hackborn | bf1b57d | 2018-03-07 12:42:47 -0800 | [diff] [blame] | 4578 | @RequiresPermission(android.Manifest.permission.MANAGE_APP_OPS_MODES) |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 4579 | public void setUidMode(String appOp, int uid, @Mode int mode) { |
Svet Ganov | ae0e03a | 2016-02-25 18:22:10 -0800 | [diff] [blame] | 4580 | try { |
| 4581 | mService.setUidMode(AppOpsManager.strOpToOp(appOp), uid, mode); |
| 4582 | } catch (RemoteException e) { |
| 4583 | throw e.rethrowFromSystemServer(); |
| 4584 | } |
| 4585 | } |
| 4586 | |
Svet Ganov | 2af5708 | 2015-07-30 08:44:20 -0700 | [diff] [blame] | 4587 | /** @hide */ |
Svet Ganov | 9cea80cd | 2016-02-16 11:47:00 -0800 | [diff] [blame] | 4588 | public void setUserRestriction(int code, boolean restricted, IBinder token) { |
Ruben Brunk | 29931bc | 2016-03-11 00:24:26 -0800 | [diff] [blame] | 4589 | setUserRestriction(code, restricted, token, /*exceptionPackages*/null); |
| 4590 | } |
| 4591 | |
| 4592 | /** @hide */ |
| 4593 | public void setUserRestriction(int code, boolean restricted, IBinder token, |
| 4594 | String[] exceptionPackages) { |
Svetoslav Ganov | e33f613 | 2016-06-01 16:25:31 -0700 | [diff] [blame] | 4595 | setUserRestrictionForUser(code, restricted, token, exceptionPackages, mContext.getUserId()); |
| 4596 | } |
| 4597 | |
| 4598 | /** @hide */ |
| 4599 | public void setUserRestrictionForUser(int code, boolean restricted, IBinder token, |
| 4600 | String[] exceptionPackages, int userId) { |
Svet Ganov | 9cea80cd | 2016-02-16 11:47:00 -0800 | [diff] [blame] | 4601 | try { |
Svetoslav Ganov | e33f613 | 2016-06-01 16:25:31 -0700 | [diff] [blame] | 4602 | mService.setUserRestriction(code, restricted, token, userId, exceptionPackages); |
Svet Ganov | 9cea80cd | 2016-02-16 11:47:00 -0800 | [diff] [blame] | 4603 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 4604 | throw e.rethrowFromSystemServer(); |
Svet Ganov | 9cea80cd | 2016-02-16 11:47:00 -0800 | [diff] [blame] | 4605 | } |
| 4606 | } |
| 4607 | |
| 4608 | /** @hide */ |
Artur Satayev | 5a52585 | 2019-10-31 15:15:50 +0000 | [diff] [blame] | 4609 | @UnsupportedAppUsage |
Peter Visontay | b97fbc8 | 2017-12-21 16:23:55 +0000 | [diff] [blame] | 4610 | @TestApi |
Dianne Hackborn | bf1b57d | 2018-03-07 12:42:47 -0800 | [diff] [blame] | 4611 | @RequiresPermission(android.Manifest.permission.MANAGE_APP_OPS_MODES) |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 4612 | public void setMode(int code, int uid, String packageName, @Mode int mode) { |
Dianne Hackborn | 5e45ee6 | 2013-01-24 19:13:44 -0800 | [diff] [blame] | 4613 | try { |
| 4614 | mService.setMode(code, uid, packageName, mode); |
| 4615 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 4616 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 5e45ee6 | 2013-01-24 19:13:44 -0800 | [diff] [blame] | 4617 | } |
| 4618 | } |
| 4619 | |
John Spurlock | 1af30c7 | 2014-03-10 08:33:35 -0400 | [diff] [blame] | 4620 | /** |
Dianne Hackborn | bf1b57d | 2018-03-07 12:42:47 -0800 | [diff] [blame] | 4621 | * Change the operating mode for the given op in the given app package. You must pass |
| 4622 | * in both the uid and name of the application whose mode is being modified; if these |
| 4623 | * do not match, the modification will not be applied. |
| 4624 | * |
| 4625 | * @param op The operation to modify. One of the OPSTR_* constants. |
| 4626 | * @param uid The user id of the application whose mode will be changed. |
| 4627 | * @param packageName The name of the application package name whose mode will |
| 4628 | * be changed. |
| 4629 | * @hide |
| 4630 | */ |
Svet Ganov | 8e5bf96 | 2019-03-19 23:59:03 -0700 | [diff] [blame] | 4631 | @TestApi |
Dianne Hackborn | bf1b57d | 2018-03-07 12:42:47 -0800 | [diff] [blame] | 4632 | @SystemApi |
| 4633 | @RequiresPermission(android.Manifest.permission.MANAGE_APP_OPS_MODES) |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 4634 | public void setMode(String op, int uid, String packageName, @Mode int mode) { |
Dianne Hackborn | bf1b57d | 2018-03-07 12:42:47 -0800 | [diff] [blame] | 4635 | try { |
| 4636 | mService.setMode(strOpToOp(op), uid, packageName, mode); |
| 4637 | } catch (RemoteException e) { |
| 4638 | throw e.rethrowFromSystemServer(); |
| 4639 | } |
| 4640 | } |
| 4641 | |
| 4642 | /** |
John Spurlock | 1af30c7 | 2014-03-10 08:33:35 -0400 | [diff] [blame] | 4643 | * Set a non-persisted restriction on an audio operation at a stream-level. |
| 4644 | * Restrictions are temporary additional constraints imposed on top of the persisted rules |
| 4645 | * defined by {@link #setMode}. |
| 4646 | * |
| 4647 | * @param code The operation to restrict. |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame] | 4648 | * @param usage The {@link android.media.AudioAttributes} usage value. |
John Spurlock | 1af30c7 | 2014-03-10 08:33:35 -0400 | [diff] [blame] | 4649 | * @param mode The restriction mode (MODE_IGNORED,MODE_ERRORED) or MODE_ALLOWED to unrestrict. |
| 4650 | * @param exceptionPackages Optional list of packages to exclude from the restriction. |
| 4651 | * @hide |
| 4652 | */ |
Dianne Hackborn | bf1b57d | 2018-03-07 12:42:47 -0800 | [diff] [blame] | 4653 | @RequiresPermission(android.Manifest.permission.MANAGE_APP_OPS_MODES) |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 4654 | @UnsupportedAppUsage |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 4655 | public void setRestriction(int code, @AttributeUsage int usage, @Mode int mode, |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame] | 4656 | String[] exceptionPackages) { |
John Spurlock | 1af30c7 | 2014-03-10 08:33:35 -0400 | [diff] [blame] | 4657 | try { |
| 4658 | final int uid = Binder.getCallingUid(); |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame] | 4659 | mService.setAudioRestriction(code, usage, uid, mode, exceptionPackages); |
John Spurlock | 1af30c7 | 2014-03-10 08:33:35 -0400 | [diff] [blame] | 4660 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 4661 | throw e.rethrowFromSystemServer(); |
John Spurlock | 1af30c7 | 2014-03-10 08:33:35 -0400 | [diff] [blame] | 4662 | } |
| 4663 | } |
| 4664 | |
Dianne Hackborn | 607b414 | 2013-08-02 18:10:10 -0700 | [diff] [blame] | 4665 | /** @hide */ |
Dianne Hackborn | bf1b57d | 2018-03-07 12:42:47 -0800 | [diff] [blame] | 4666 | @RequiresPermission(android.Manifest.permission.MANAGE_APP_OPS_MODES) |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 4667 | @UnsupportedAppUsage |
Dianne Hackborn | 607b414 | 2013-08-02 18:10:10 -0700 | [diff] [blame] | 4668 | public void resetAllModes() { |
| 4669 | try { |
Jeff Sharkey | ad357d1 | 2018-02-02 13:25:31 -0700 | [diff] [blame] | 4670 | mService.resetAllModes(mContext.getUserId(), null); |
Dianne Hackborn | 607b414 | 2013-08-02 18:10:10 -0700 | [diff] [blame] | 4671 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 4672 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 607b414 | 2013-08-02 18:10:10 -0700 | [diff] [blame] | 4673 | } |
| 4674 | } |
| 4675 | |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 4676 | /** |
Svet Ganov | fbf01f7 | 2015-04-28 18:39:06 -0700 | [diff] [blame] | 4677 | * Gets the app op name associated with a given permission. |
| 4678 | * The app op name is one of the public constants defined |
| 4679 | * in this class such as {@link #OPSTR_COARSE_LOCATION}. |
Svetoslav Ganov | eaca4c5 | 2016-05-05 18:08:00 -0700 | [diff] [blame] | 4680 | * This API is intended to be used for mapping runtime |
| 4681 | * permissions to the corresponding app op. |
Svet Ganov | fbf01f7 | 2015-04-28 18:39:06 -0700 | [diff] [blame] | 4682 | * |
| 4683 | * @param permission The permission. |
| 4684 | * @return The app op associated with the permission or null. |
Svet Ganov | fbf01f7 | 2015-04-28 18:39:06 -0700 | [diff] [blame] | 4685 | */ |
Svet Ganov | fbf01f7 | 2015-04-28 18:39:06 -0700 | [diff] [blame] | 4686 | public static String permissionToOp(String permission) { |
Svet Ganov | da0acdf | 2017-02-15 10:28:51 -0800 | [diff] [blame] | 4687 | final Integer opCode = sPermToOp.get(permission); |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 4688 | if (opCode == null) { |
| 4689 | return null; |
| 4690 | } |
| 4691 | return sOpToString[opCode]; |
Svet Ganov | fbf01f7 | 2015-04-28 18:39:06 -0700 | [diff] [blame] | 4692 | } |
| 4693 | |
| 4694 | /** |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 4695 | * 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] | 4696 | * You can watch op changes only for your UID. |
| 4697 | * |
Dianne Hackborn | e4cb66f | 2013-10-02 10:34:02 -0700 | [diff] [blame] | 4698 | * @param op The operation to monitor, one of OPSTR_*. |
| 4699 | * @param packageName The name of the application to monitor. |
| 4700 | * @param callback Where to report changes. |
| 4701 | */ |
Dianne Hackborn | 6287849 | 2019-03-11 15:57:07 -0700 | [diff] [blame] | 4702 | public void startWatchingMode(@NonNull String op, @Nullable String packageName, |
| 4703 | @NonNull final OnOpChangedListener callback) { |
Dianne Hackborn | e4cb66f | 2013-10-02 10:34:02 -0700 | [diff] [blame] | 4704 | startWatchingMode(strOpToOp(op), packageName, callback); |
| 4705 | } |
| 4706 | |
| 4707 | /** |
| 4708 | * 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] | 4709 | * You can watch op changes only for your UID. |
| 4710 | * |
| 4711 | * @param op The operation to monitor, one of OPSTR_*. |
| 4712 | * @param packageName The name of the application to monitor. |
| 4713 | * @param flags Option flags: any combination of {@link #WATCH_FOREGROUND_CHANGES} or 0. |
| 4714 | * @param callback Where to report changes. |
Dianne Hackborn | 65a4f25 | 2018-05-08 17:30:48 -0700 | [diff] [blame] | 4715 | */ |
Dianne Hackborn | 6287849 | 2019-03-11 15:57:07 -0700 | [diff] [blame] | 4716 | public void startWatchingMode(@NonNull String op, @Nullable String packageName, int flags, |
| 4717 | @NonNull final OnOpChangedListener callback) { |
Dianne Hackborn | 65a4f25 | 2018-05-08 17:30:48 -0700 | [diff] [blame] | 4718 | startWatchingMode(strOpToOp(op), packageName, flags, callback); |
| 4719 | } |
| 4720 | |
| 4721 | /** |
| 4722 | * 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] | 4723 | * |
| 4724 | * <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] | 4725 | * you can watch changes only for your UID. |
Svetoslav Ganov | 2d20fb4 | 2018-02-08 15:52:10 -0800 | [diff] [blame] | 4726 | * |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 4727 | * @param op The operation to monitor, one of OP_*. |
| 4728 | * @param packageName The name of the application to monitor. |
| 4729 | * @param callback Where to report changes. |
Dianne Hackborn | e4cb66f | 2013-10-02 10:34:02 -0700 | [diff] [blame] | 4730 | * @hide |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 4731 | */ |
Jeff Sharkey | bf6b213 | 2018-02-27 11:16:37 -0700 | [diff] [blame] | 4732 | @RequiresPermission(value=android.Manifest.permission.WATCH_APPOPS, conditional=true) |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 4733 | public void startWatchingMode(int op, String packageName, final OnOpChangedListener callback) { |
Dianne Hackborn | 65a4f25 | 2018-05-08 17:30:48 -0700 | [diff] [blame] | 4734 | startWatchingMode(op, packageName, 0, callback); |
| 4735 | } |
| 4736 | |
| 4737 | /** |
| 4738 | * Monitor for changes to the operating mode for the given op in the given app package. |
| 4739 | * |
| 4740 | * <p> If you don't hold the {@link android.Manifest.permission#WATCH_APPOPS} permission |
| 4741 | * you can watch changes only for your UID. |
| 4742 | * |
| 4743 | * @param op The operation to monitor, one of OP_*. |
| 4744 | * @param packageName The name of the application to monitor. |
| 4745 | * @param flags Option flags: any combination of {@link #WATCH_FOREGROUND_CHANGES} or 0. |
| 4746 | * @param callback Where to report changes. |
| 4747 | * @hide |
| 4748 | */ |
| 4749 | @RequiresPermission(value=android.Manifest.permission.WATCH_APPOPS, conditional=true) |
| 4750 | public void startWatchingMode(int op, String packageName, int flags, |
| 4751 | final OnOpChangedListener callback) { |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 4752 | synchronized (mModeWatchers) { |
| 4753 | IAppOpsCallback cb = mModeWatchers.get(callback); |
| 4754 | if (cb == null) { |
| 4755 | cb = new IAppOpsCallback.Stub() { |
Dianne Hackborn | bef28fe | 2015-10-29 17:57:11 -0700 | [diff] [blame] | 4756 | public void opChanged(int op, int uid, String packageName) { |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 4757 | if (callback instanceof OnOpChangedInternalListener) { |
| 4758 | ((OnOpChangedInternalListener)callback).onOpChanged(op, packageName); |
| 4759 | } |
| 4760 | if (sOpToString[op] != null) { |
| 4761 | callback.onOpChanged(sOpToString[op], packageName); |
| 4762 | } |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 4763 | } |
| 4764 | }; |
| 4765 | mModeWatchers.put(callback, cb); |
| 4766 | } |
| 4767 | try { |
Dianne Hackborn | 65a4f25 | 2018-05-08 17:30:48 -0700 | [diff] [blame] | 4768 | mService.startWatchingModeWithFlags(op, packageName, flags, cb); |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 4769 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 4770 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 4771 | } |
| 4772 | } |
| 4773 | } |
| 4774 | |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 4775 | /** |
| 4776 | * Stop monitoring that was previously started with {@link #startWatchingMode}. All |
| 4777 | * monitoring associated with this callback will be removed. |
| 4778 | */ |
Dianne Hackborn | 6287849 | 2019-03-11 15:57:07 -0700 | [diff] [blame] | 4779 | public void stopWatchingMode(@NonNull OnOpChangedListener callback) { |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 4780 | synchronized (mModeWatchers) { |
Svet Ganov | b3d2ae2 | 2018-12-17 22:06:15 -0800 | [diff] [blame] | 4781 | IAppOpsCallback cb = mModeWatchers.remove(callback); |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 4782 | if (cb != null) { |
| 4783 | try { |
| 4784 | mService.stopWatchingMode(cb); |
| 4785 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 4786 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 4787 | } |
| 4788 | } |
| 4789 | } |
| 4790 | } |
| 4791 | |
Svetoslav Ganov | 2d20fb4 | 2018-02-08 15:52:10 -0800 | [diff] [blame] | 4792 | /** |
| 4793 | * Start watching for changes to the active state of app ops. An app op may be |
| 4794 | * long running and it has a clear start and stop delimiters. If an op is being |
| 4795 | * started or stopped by any package you will get a callback. To change the |
| 4796 | * watched ops for a registered callback you need to unregister and register it |
| 4797 | * again. |
| 4798 | * |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 4799 | * <p> If you don't hold the {@link android.Manifest.permission#WATCH_APPOPS} permission |
| 4800 | * you can watch changes only for your UID. |
| 4801 | * |
Svetoslav Ganov | 2d20fb4 | 2018-02-08 15:52:10 -0800 | [diff] [blame] | 4802 | * @param ops The ops to watch. |
| 4803 | * @param callback Where to report changes. |
| 4804 | * |
| 4805 | * @see #isOperationActive(int, int, String) |
| 4806 | * @see #stopWatchingActive(OnOpActiveChangedListener) |
| 4807 | * @see #startOp(int, int, String) |
| 4808 | * @see #finishOp(int, int, String) |
| 4809 | * |
| 4810 | * @hide |
| 4811 | */ |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 4812 | @TestApi |
| 4813 | // TODO: Uncomment below annotation once b/73559440 is fixed |
| 4814 | // @RequiresPermission(value=Manifest.permission.WATCH_APPOPS, conditional=true) |
Svetoslav Ganov | 2d20fb4 | 2018-02-08 15:52:10 -0800 | [diff] [blame] | 4815 | public void startWatchingActive(@NonNull int[] ops, |
| 4816 | @NonNull OnOpActiveChangedListener callback) { |
| 4817 | Preconditions.checkNotNull(ops, "ops cannot be null"); |
| 4818 | Preconditions.checkNotNull(callback, "callback cannot be null"); |
| 4819 | IAppOpsActiveCallback cb; |
| 4820 | synchronized (mActiveWatchers) { |
| 4821 | cb = mActiveWatchers.get(callback); |
| 4822 | if (cb != null) { |
| 4823 | return; |
| 4824 | } |
| 4825 | cb = new IAppOpsActiveCallback.Stub() { |
| 4826 | @Override |
| 4827 | public void opActiveChanged(int op, int uid, String packageName, boolean active) { |
| 4828 | callback.onOpActiveChanged(op, uid, packageName, active); |
| 4829 | } |
| 4830 | }; |
| 4831 | mActiveWatchers.put(callback, cb); |
| 4832 | } |
| 4833 | try { |
| 4834 | mService.startWatchingActive(ops, cb); |
| 4835 | } catch (RemoteException e) { |
| 4836 | throw e.rethrowFromSystemServer(); |
| 4837 | } |
| 4838 | } |
| 4839 | |
| 4840 | /** |
| 4841 | * Stop watching for changes to the active state of an app op. An app op may be |
| 4842 | * long running and it has a clear start and stop delimiters. Unregistering a |
| 4843 | * non-registered callback has no effect. |
| 4844 | * |
| 4845 | * @see #isOperationActive#(int, int, String) |
| 4846 | * @see #startWatchingActive(int[], OnOpActiveChangedListener) |
| 4847 | * @see #startOp(int, int, String) |
| 4848 | * @see #finishOp(int, int, String) |
| 4849 | * |
| 4850 | * @hide |
| 4851 | */ |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 4852 | @TestApi |
Svetoslav Ganov | 2d20fb4 | 2018-02-08 15:52:10 -0800 | [diff] [blame] | 4853 | public void stopWatchingActive(@NonNull OnOpActiveChangedListener callback) { |
| 4854 | synchronized (mActiveWatchers) { |
Svet Ganov | b3d2ae2 | 2018-12-17 22:06:15 -0800 | [diff] [blame] | 4855 | final IAppOpsActiveCallback cb = mActiveWatchers.remove(callback); |
Svetoslav Ganov | 2d20fb4 | 2018-02-08 15:52:10 -0800 | [diff] [blame] | 4856 | if (cb != null) { |
| 4857 | try { |
| 4858 | mService.stopWatchingActive(cb); |
| 4859 | } catch (RemoteException e) { |
| 4860 | throw e.rethrowFromSystemServer(); |
| 4861 | } |
| 4862 | } |
| 4863 | } |
| 4864 | } |
| 4865 | |
Svet Ganov | b3d2ae2 | 2018-12-17 22:06:15 -0800 | [diff] [blame] | 4866 | /** |
| 4867 | * Start watching for noted app ops. An app op may be immediate or long running. |
| 4868 | * Immediate ops are noted while long running ones are started and stopped. This |
| 4869 | * method allows registering a listener to be notified when an app op is noted. If |
| 4870 | * an op is being noted by any package you will get a callback. To change the |
| 4871 | * watched ops for a registered callback you need to unregister and register it again. |
| 4872 | * |
| 4873 | * <p> If you don't hold the {@link android.Manifest.permission#WATCH_APPOPS} permission |
| 4874 | * you can watch changes only for your UID. |
| 4875 | * |
| 4876 | * @param ops The ops to watch. |
| 4877 | * @param callback Where to report changes. |
| 4878 | * |
| 4879 | * @see #startWatchingActive(int[], OnOpActiveChangedListener) |
| 4880 | * @see #stopWatchingNoted(OnOpNotedListener) |
| 4881 | * @see #noteOp(String, int, String) |
| 4882 | * |
| 4883 | * @hide |
| 4884 | */ |
| 4885 | @RequiresPermission(value=Manifest.permission.WATCH_APPOPS, conditional=true) |
Fabian Kozynski | 0b4592c | 2018-12-20 12:58:45 -0500 | [diff] [blame] | 4886 | public void startWatchingNoted(@NonNull int[] ops, @NonNull OnOpNotedListener callback) { |
Svet Ganov | b3d2ae2 | 2018-12-17 22:06:15 -0800 | [diff] [blame] | 4887 | IAppOpsNotedCallback cb; |
| 4888 | synchronized (mNotedWatchers) { |
| 4889 | cb = mNotedWatchers.get(callback); |
| 4890 | if (cb != null) { |
| 4891 | return; |
| 4892 | } |
| 4893 | cb = new IAppOpsNotedCallback.Stub() { |
| 4894 | @Override |
| 4895 | public void opNoted(int op, int uid, String packageName, int mode) { |
Fabian Kozynski | 0b4592c | 2018-12-20 12:58:45 -0500 | [diff] [blame] | 4896 | callback.onOpNoted(op, uid, packageName, mode); |
Svet Ganov | b3d2ae2 | 2018-12-17 22:06:15 -0800 | [diff] [blame] | 4897 | } |
| 4898 | }; |
| 4899 | mNotedWatchers.put(callback, cb); |
| 4900 | } |
| 4901 | try { |
Fabian Kozynski | 0b4592c | 2018-12-20 12:58:45 -0500 | [diff] [blame] | 4902 | mService.startWatchingNoted(ops, cb); |
Svet Ganov | b3d2ae2 | 2018-12-17 22:06:15 -0800 | [diff] [blame] | 4903 | } catch (RemoteException e) { |
| 4904 | throw e.rethrowFromSystemServer(); |
| 4905 | } |
| 4906 | } |
| 4907 | |
| 4908 | /** |
| 4909 | * Stop watching for noted app ops. An app op may be immediate or long running. |
| 4910 | * Unregistering a non-registered callback has no effect. |
| 4911 | * |
Fabian Kozynski | 0b4592c | 2018-12-20 12:58:45 -0500 | [diff] [blame] | 4912 | * @see #startWatchingNoted(int[], OnOpNotedListener) |
Svet Ganov | b3d2ae2 | 2018-12-17 22:06:15 -0800 | [diff] [blame] | 4913 | * @see #noteOp(String, int, String) |
| 4914 | * |
| 4915 | * @hide |
| 4916 | */ |
| 4917 | public void stopWatchingNoted(@NonNull OnOpNotedListener callback) { |
| 4918 | synchronized (mNotedWatchers) { |
| 4919 | final IAppOpsNotedCallback cb = mNotedWatchers.get(callback); |
| 4920 | if (cb != null) { |
| 4921 | try { |
| 4922 | mService.stopWatchingNoted(cb); |
| 4923 | } catch (RemoteException e) { |
| 4924 | throw e.rethrowFromSystemServer(); |
| 4925 | } |
| 4926 | } |
| 4927 | } |
| 4928 | } |
| 4929 | |
Dianne Hackborn | 95d7853 | 2013-09-11 09:51:14 -0700 | [diff] [blame] | 4930 | private String buildSecurityExceptionMsg(int op, int uid, String packageName) { |
| 4931 | return packageName + " from uid " + uid + " not allowed to perform " + sOpNames[op]; |
| 4932 | } |
| 4933 | |
Adam Lesinski | b5cf61b | 2014-08-18 16:10:28 -0700 | [diff] [blame] | 4934 | /** |
| 4935 | * {@hide} |
| 4936 | */ |
Artur Satayev | 5a52585 | 2019-10-31 15:15:50 +0000 | [diff] [blame] | 4937 | @UnsupportedAppUsage |
Philip P. Moltmann | 3311515 | 2018-04-11 13:39:36 -0700 | [diff] [blame] | 4938 | @TestApi |
Dianne Hackborn | 6287849 | 2019-03-11 15:57:07 -0700 | [diff] [blame] | 4939 | public static int strOpToOp(@NonNull String op) { |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 4940 | Integer val = sOpStrToOp.get(op); |
| 4941 | if (val == null) { |
| 4942 | throw new IllegalArgumentException("Unknown operation string: " + op); |
| 4943 | } |
| 4944 | return val; |
| 4945 | } |
| 4946 | |
| 4947 | /** |
| 4948 | * Do a quick check for whether an application might be able to perform an operation. |
| 4949 | * This is <em>not</em> a security check; you must use {@link #noteOp(String, int, String)} |
| 4950 | * or {@link #startOp(String, int, String)} for your actual security checks, which also |
| 4951 | * ensure that the given uid and package name are consistent. This function can just be |
| 4952 | * used for a quick check to see if an operation has been disabled for the application, |
| 4953 | * as an early reject of some work. This does not modify the time stamp or other data |
| 4954 | * about the operation. |
Dianne Hackborn | c216a26 | 2018-04-26 13:46:22 -0700 | [diff] [blame] | 4955 | * |
| 4956 | * <p>Important things this will not do (which you need to ultimate use |
| 4957 | * {@link #noteOp(String, int, String)} or {@link #startOp(String, int, String)} to cover):</p> |
| 4958 | * <ul> |
| 4959 | * <li>Verifying the uid and package are consistent, so callers can't spoof |
| 4960 | * their identity.</li> |
| 4961 | * <li>Taking into account the current foreground/background state of the |
| 4962 | * app; apps whose mode varies by this state will always be reported |
| 4963 | * as {@link #MODE_ALLOWED}.</li> |
| 4964 | * </ul> |
| 4965 | * |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 4966 | * @param op The operation to check. One of the OPSTR_* constants. |
| 4967 | * @param uid The user id of the application attempting to perform the operation. |
| 4968 | * @param packageName The name of the application attempting to perform the operation. |
| 4969 | * @return Returns {@link #MODE_ALLOWED} if the operation is allowed, or |
| 4970 | * {@link #MODE_IGNORED} if it is not allowed and should be silently ignored (without |
| 4971 | * causing the app to crash). |
| 4972 | * @throws SecurityException If the app has been configured to crash on this op. |
| 4973 | */ |
Dianne Hackborn | 6287849 | 2019-03-11 15:57:07 -0700 | [diff] [blame] | 4974 | public int unsafeCheckOp(@NonNull String op, int uid, @NonNull String packageName) { |
Dianne Hackborn | f0c322a | 2018-06-13 15:24:04 -0700 | [diff] [blame] | 4975 | return checkOp(strOpToOp(op), uid, packageName); |
| 4976 | } |
| 4977 | |
| 4978 | /** |
| 4979 | * @deprecated Renamed to {@link #unsafeCheckOp(String, int, String)}. |
| 4980 | */ |
| 4981 | @Deprecated |
Dianne Hackborn | 6287849 | 2019-03-11 15:57:07 -0700 | [diff] [blame] | 4982 | public int checkOp(@NonNull String op, int uid, @NonNull String packageName) { |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 4983 | return checkOp(strOpToOp(op), uid, packageName); |
| 4984 | } |
| 4985 | |
| 4986 | /** |
John Spurlock | 925b85e | 2014-03-10 16:52:11 -0400 | [diff] [blame] | 4987 | * Like {@link #checkOp} but instead of throwing a {@link SecurityException} it |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 4988 | * returns {@link #MODE_ERRORED}. |
| 4989 | */ |
Dianne Hackborn | 6287849 | 2019-03-11 15:57:07 -0700 | [diff] [blame] | 4990 | public int unsafeCheckOpNoThrow(@NonNull String op, int uid, @NonNull String packageName) { |
Dianne Hackborn | f0c322a | 2018-06-13 15:24:04 -0700 | [diff] [blame] | 4991 | return checkOpNoThrow(strOpToOp(op), uid, packageName); |
| 4992 | } |
| 4993 | |
| 4994 | /** |
| 4995 | * @deprecated Renamed to {@link #unsafeCheckOpNoThrow(String, int, String)}. |
| 4996 | */ |
| 4997 | @Deprecated |
Dianne Hackborn | 6287849 | 2019-03-11 15:57:07 -0700 | [diff] [blame] | 4998 | public int checkOpNoThrow(@NonNull String op, int uid, @NonNull String packageName) { |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 4999 | return checkOpNoThrow(strOpToOp(op), uid, packageName); |
| 5000 | } |
| 5001 | |
| 5002 | /** |
Dianne Hackborn | 65a4f25 | 2018-05-08 17:30:48 -0700 | [diff] [blame] | 5003 | * Like {@link #checkOp} but returns the <em>raw</em> mode associated with the op. |
| 5004 | * Does not throw a security exception, does not translate {@link #MODE_FOREGROUND}. |
Dianne Hackborn | 65a4f25 | 2018-05-08 17:30:48 -0700 | [diff] [blame] | 5005 | */ |
Dianne Hackborn | 6287849 | 2019-03-11 15:57:07 -0700 | [diff] [blame] | 5006 | public int unsafeCheckOpRaw(@NonNull String op, int uid, @NonNull String packageName) { |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 5007 | try { |
| 5008 | return mService.checkOperationRaw(strOpToOp(op), uid, packageName); |
| 5009 | } catch (RemoteException e) { |
| 5010 | throw e.rethrowFromSystemServer(); |
| 5011 | } |
| 5012 | } |
| 5013 | |
| 5014 | /** |
| 5015 | * Like {@link #unsafeCheckOpNoThrow(String, int, String)} but returns the <em>raw</em> |
| 5016 | * mode associated with the op. Does not throw a security exception, does not translate |
| 5017 | * {@link #MODE_FOREGROUND}. |
| 5018 | */ |
| 5019 | public int unsafeCheckOpRawNoThrow(@NonNull String op, int uid, @NonNull String packageName) { |
Dianne Hackborn | 65a4f25 | 2018-05-08 17:30:48 -0700 | [diff] [blame] | 5020 | try { |
Svet Ganov | 9d528a1 | 2018-12-19 17:23:11 -0800 | [diff] [blame] | 5021 | return mService.checkOperationRaw(strOpToOp(op), uid, packageName); |
Dianne Hackborn | 65a4f25 | 2018-05-08 17:30:48 -0700 | [diff] [blame] | 5022 | } catch (RemoteException e) { |
| 5023 | throw e.rethrowFromSystemServer(); |
| 5024 | } |
| 5025 | } |
| 5026 | |
| 5027 | /** |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 5028 | * Make note of an application performing an operation. Note that you must pass |
| 5029 | * in both the uid and name of the application to be checked; this function will verify |
| 5030 | * that these two match, and if not, return {@link #MODE_IGNORED}. If this call |
| 5031 | * succeeds, the last execution time of the operation for this app will be updated to |
| 5032 | * the current time. |
| 5033 | * @param op The operation to note. One of the OPSTR_* constants. |
| 5034 | * @param uid The user id of the application attempting to perform the operation. |
| 5035 | * @param packageName The name of the application attempting to perform the operation. |
| 5036 | * @return Returns {@link #MODE_ALLOWED} if the operation is allowed, or |
| 5037 | * {@link #MODE_IGNORED} if it is not allowed and should be silently ignored (without |
| 5038 | * causing the app to crash). |
| 5039 | * @throws SecurityException If the app has been configured to crash on this op. |
| 5040 | */ |
Dianne Hackborn | 6287849 | 2019-03-11 15:57:07 -0700 | [diff] [blame] | 5041 | public int noteOp(@NonNull String op, int uid, @NonNull String packageName) { |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 5042 | return noteOp(strOpToOp(op), uid, packageName); |
| 5043 | } |
| 5044 | |
| 5045 | /** |
| 5046 | * Like {@link #noteOp} but instead of throwing a {@link SecurityException} it |
| 5047 | * returns {@link #MODE_ERRORED}. |
| 5048 | */ |
Dianne Hackborn | 6287849 | 2019-03-11 15:57:07 -0700 | [diff] [blame] | 5049 | public int noteOpNoThrow(@NonNull String op, int uid, @NonNull String packageName) { |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 5050 | return noteOpNoThrow(strOpToOp(op), uid, packageName); |
| 5051 | } |
| 5052 | |
| 5053 | /** |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 5054 | * Make note of an application performing an operation on behalf of another |
| 5055 | * application when handling an IPC. Note that you must pass the package name |
| 5056 | * of the application that is being proxied while its UID will be inferred from |
| 5057 | * the IPC state; this function will verify that the calling uid and proxied |
| 5058 | * package name match, and if not, return {@link #MODE_IGNORED}. If this call |
| 5059 | * succeeds, the last execution time of the operation for the proxied app and |
| 5060 | * your app will be updated to the current time. |
| 5061 | * @param op The operation to note. One of the OPSTR_* constants. |
| 5062 | * @param proxiedPackageName The name of the application calling into the proxy application. |
| 5063 | * @return Returns {@link #MODE_ALLOWED} if the operation is allowed, or |
| 5064 | * {@link #MODE_IGNORED} if it is not allowed and should be silently ignored (without |
| 5065 | * causing the app to crash). |
| 5066 | * @throws SecurityException If the app has been configured to crash on this op. |
| 5067 | */ |
Dianne Hackborn | 6287849 | 2019-03-11 15:57:07 -0700 | [diff] [blame] | 5068 | public int noteProxyOp(@NonNull String op, @NonNull String proxiedPackageName) { |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 5069 | return noteProxyOp(strOpToOp(op), proxiedPackageName); |
| 5070 | } |
| 5071 | |
| 5072 | /** |
| 5073 | * Like {@link #noteProxyOp(String, String)} but instead |
| 5074 | * of throwing a {@link SecurityException} it returns {@link #MODE_ERRORED}. |
Philip P. Moltmann | 0d05e48 | 2019-02-08 13:05:25 -0800 | [diff] [blame] | 5075 | * |
| 5076 | * <p>This API requires the package with the {@code proxiedPackageName} to belongs to |
| 5077 | * {@link Binder#getCallingUid()}. |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 5078 | */ |
Dianne Hackborn | 6287849 | 2019-03-11 15:57:07 -0700 | [diff] [blame] | 5079 | public int noteProxyOpNoThrow(@NonNull String op, @NonNull String proxiedPackageName) { |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 5080 | return noteProxyOpNoThrow(strOpToOp(op), proxiedPackageName); |
| 5081 | } |
| 5082 | |
| 5083 | /** |
Philip P. Moltmann | 7821931 | 2019-03-01 17:04:19 -0800 | [diff] [blame] | 5084 | * Like {@link #noteProxyOpNoThrow(String, String)} but allows to specify the proxied uid. |
Philip P. Moltmann | 0d05e48 | 2019-02-08 13:05:25 -0800 | [diff] [blame] | 5085 | * |
| 5086 | * <p>This API requires package with the {@code proxiedPackageName} to belong to |
| 5087 | * {@code proxiedUid}. |
| 5088 | * |
| 5089 | * @param op The op to note |
| 5090 | * @param proxiedPackageName The package to note the op for or {@code null} if the op should be |
| 5091 | * noted for the "android" package |
| 5092 | * @param proxiedUid The uid the package belongs to |
Philip P. Moltmann | 0d05e48 | 2019-02-08 13:05:25 -0800 | [diff] [blame] | 5093 | */ |
Philip P. Moltmann | 0d05e48 | 2019-02-08 13:05:25 -0800 | [diff] [blame] | 5094 | public int noteProxyOpNoThrow(@NonNull String op, @Nullable String proxiedPackageName, |
| 5095 | int proxiedUid) { |
| 5096 | return noteProxyOpNoThrow(strOpToOp(op), proxiedPackageName, proxiedUid); |
| 5097 | } |
| 5098 | |
| 5099 | /** |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 5100 | * Report that an application has started executing a long-running operation. Note that you |
| 5101 | * must pass in both the uid and name of the application to be checked; this function will |
| 5102 | * verify that these two match, and if not, return {@link #MODE_IGNORED}. If this call |
| 5103 | * succeeds, the last execution time of the operation for this app will be updated to |
| 5104 | * the current time and the operation will be marked as "running". In this case you must |
| 5105 | * later call {@link #finishOp(String, int, String)} to report when the application is no |
| 5106 | * longer performing the operation. |
| 5107 | * @param op The operation to start. One of the OPSTR_* constants. |
| 5108 | * @param uid The user id of the application attempting to perform the operation. |
| 5109 | * @param packageName The name of the application attempting to perform the operation. |
| 5110 | * @return Returns {@link #MODE_ALLOWED} if the operation is allowed, or |
| 5111 | * {@link #MODE_IGNORED} if it is not allowed and should be silently ignored (without |
| 5112 | * causing the app to crash). |
| 5113 | * @throws SecurityException If the app has been configured to crash on this op. |
| 5114 | */ |
Dianne Hackborn | 6287849 | 2019-03-11 15:57:07 -0700 | [diff] [blame] | 5115 | public int startOp(@NonNull String op, int uid, @NonNull String packageName) { |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 5116 | return startOp(strOpToOp(op), uid, packageName); |
| 5117 | } |
| 5118 | |
| 5119 | /** |
| 5120 | * Like {@link #startOp} but instead of throwing a {@link SecurityException} it |
| 5121 | * returns {@link #MODE_ERRORED}. |
| 5122 | */ |
Dianne Hackborn | 6287849 | 2019-03-11 15:57:07 -0700 | [diff] [blame] | 5123 | public int startOpNoThrow(@NonNull String op, int uid, @NonNull String packageName) { |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 5124 | return startOpNoThrow(strOpToOp(op), uid, packageName); |
| 5125 | } |
| 5126 | |
| 5127 | /** |
| 5128 | * Report that an application is no longer performing an operation that had previously |
| 5129 | * been started with {@link #startOp(String, int, String)}. There is no validation of input |
| 5130 | * or result; the parameters supplied here must be the exact same ones previously passed |
| 5131 | * in when starting the operation. |
| 5132 | */ |
Dianne Hackborn | 6287849 | 2019-03-11 15:57:07 -0700 | [diff] [blame] | 5133 | public void finishOp(@NonNull String op, int uid, @NonNull String packageName) { |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 5134 | finishOp(strOpToOp(op), uid, packageName); |
| 5135 | } |
| 5136 | |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 5137 | /** |
| 5138 | * Do a quick check for whether an application might be able to perform an operation. |
| 5139 | * This is <em>not</em> a security check; you must use {@link #noteOp(int, int, String)} |
| 5140 | * or {@link #startOp(int, int, String)} for your actual security checks, which also |
| 5141 | * ensure that the given uid and package name are consistent. This function can just be |
| 5142 | * used for a quick check to see if an operation has been disabled for the application, |
| 5143 | * as an early reject of some work. This does not modify the time stamp or other data |
| 5144 | * about the operation. |
Dianne Hackborn | c216a26 | 2018-04-26 13:46:22 -0700 | [diff] [blame] | 5145 | * |
| 5146 | * <p>Important things this will not do (which you need to ultimate use |
| 5147 | * {@link #noteOp(int, int, String)} or {@link #startOp(int, int, String)} to cover):</p> |
| 5148 | * <ul> |
| 5149 | * <li>Verifying the uid and package are consistent, so callers can't spoof |
| 5150 | * their identity.</li> |
| 5151 | * <li>Taking into account the current foreground/background state of the |
| 5152 | * app; apps whose mode varies by this state will always be reported |
| 5153 | * as {@link #MODE_ALLOWED}.</li> |
| 5154 | * </ul> |
| 5155 | * |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 5156 | * @param op The operation to check. One of the OP_* constants. |
| 5157 | * @param uid The user id of the application attempting to perform the operation. |
| 5158 | * @param packageName The name of the application attempting to perform the operation. |
| 5159 | * @return Returns {@link #MODE_ALLOWED} if the operation is allowed, or |
| 5160 | * {@link #MODE_IGNORED} if it is not allowed and should be silently ignored (without |
| 5161 | * causing the app to crash). |
| 5162 | * @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] | 5163 | * @hide |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 5164 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 5165 | @UnsupportedAppUsage |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 5166 | public int checkOp(int op, int uid, String packageName) { |
| 5167 | try { |
| 5168 | int mode = mService.checkOperation(op, uid, packageName); |
| 5169 | if (mode == MODE_ERRORED) { |
Dianne Hackborn | 95d7853 | 2013-09-11 09:51:14 -0700 | [diff] [blame] | 5170 | throw new SecurityException(buildSecurityExceptionMsg(op, uid, packageName)); |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 5171 | } |
| 5172 | return mode; |
| 5173 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 5174 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 5175 | } |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 5176 | } |
| 5177 | |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 5178 | /** |
| 5179 | * Like {@link #checkOp} but instead of throwing a {@link SecurityException} it |
| 5180 | * returns {@link #MODE_ERRORED}. |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 5181 | * @hide |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 5182 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 5183 | @UnsupportedAppUsage |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 5184 | public int checkOpNoThrow(int op, int uid, String packageName) { |
| 5185 | try { |
Dianne Hackborn | 65a4f25 | 2018-05-08 17:30:48 -0700 | [diff] [blame] | 5186 | int mode = mService.checkOperation(op, uid, packageName); |
| 5187 | return mode == AppOpsManager.MODE_FOREGROUND ? AppOpsManager.MODE_ALLOWED : mode; |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 5188 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 5189 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 5190 | } |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 5191 | } |
| 5192 | |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 5193 | /** |
Jeff Sharkey | 911d7f4 | 2013-09-05 18:11:45 -0700 | [diff] [blame] | 5194 | * Do a quick check to validate if a package name belongs to a UID. |
| 5195 | * |
| 5196 | * @throws SecurityException if the package name doesn't belong to the given |
| 5197 | * UID, or if ownership cannot be verified. |
| 5198 | */ |
Dianne Hackborn | 6287849 | 2019-03-11 15:57:07 -0700 | [diff] [blame] | 5199 | public void checkPackage(int uid, @NonNull String packageName) { |
Jeff Sharkey | 911d7f4 | 2013-09-05 18:11:45 -0700 | [diff] [blame] | 5200 | try { |
| 5201 | if (mService.checkPackage(uid, packageName) != MODE_ALLOWED) { |
| 5202 | throw new SecurityException( |
| 5203 | "Package " + packageName + " does not belong to " + uid); |
| 5204 | } |
| 5205 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 5206 | throw e.rethrowFromSystemServer(); |
Jeff Sharkey | 911d7f4 | 2013-09-05 18:11:45 -0700 | [diff] [blame] | 5207 | } |
| 5208 | } |
| 5209 | |
| 5210 | /** |
John Spurlock | 1af30c7 | 2014-03-10 08:33:35 -0400 | [diff] [blame] | 5211 | * Like {@link #checkOp} but at a stream-level for audio operations. |
| 5212 | * @hide |
| 5213 | */ |
| 5214 | public int checkAudioOp(int op, int stream, int uid, String packageName) { |
| 5215 | try { |
| 5216 | final int mode = mService.checkAudioOperation(op, stream, uid, packageName); |
| 5217 | if (mode == MODE_ERRORED) { |
| 5218 | throw new SecurityException(buildSecurityExceptionMsg(op, uid, packageName)); |
| 5219 | } |
| 5220 | return mode; |
| 5221 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 5222 | throw e.rethrowFromSystemServer(); |
John Spurlock | 1af30c7 | 2014-03-10 08:33:35 -0400 | [diff] [blame] | 5223 | } |
John Spurlock | 1af30c7 | 2014-03-10 08:33:35 -0400 | [diff] [blame] | 5224 | } |
| 5225 | |
| 5226 | /** |
| 5227 | * Like {@link #checkAudioOp} but instead of throwing a {@link SecurityException} it |
| 5228 | * returns {@link #MODE_ERRORED}. |
| 5229 | * @hide |
| 5230 | */ |
| 5231 | public int checkAudioOpNoThrow(int op, int stream, int uid, String packageName) { |
| 5232 | try { |
| 5233 | return mService.checkAudioOperation(op, stream, uid, packageName); |
| 5234 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 5235 | throw e.rethrowFromSystemServer(); |
John Spurlock | 1af30c7 | 2014-03-10 08:33:35 -0400 | [diff] [blame] | 5236 | } |
John Spurlock | 1af30c7 | 2014-03-10 08:33:35 -0400 | [diff] [blame] | 5237 | } |
| 5238 | |
| 5239 | /** |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 5240 | * Make note of an application performing an operation. Note that you must pass |
| 5241 | * in both the uid and name of the application to be checked; this function will verify |
| 5242 | * that these two match, and if not, return {@link #MODE_IGNORED}. If this call |
| 5243 | * succeeds, the last execution time of the operation for this app will be updated to |
| 5244 | * the current time. |
| 5245 | * @param op The operation to note. One of the OP_* constants. |
| 5246 | * @param uid The user id of the application attempting to perform the operation. |
| 5247 | * @param packageName The name of the application attempting to perform the operation. |
| 5248 | * @return Returns {@link #MODE_ALLOWED} if the operation is allowed, or |
| 5249 | * {@link #MODE_IGNORED} if it is not allowed and should be silently ignored (without |
| 5250 | * causing the app to crash). |
| 5251 | * @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] | 5252 | * @hide |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 5253 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 5254 | @UnsupportedAppUsage |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5255 | public int noteOp(int op, int uid, String packageName) { |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 5256 | final int mode = noteOpNoThrow(op, uid, packageName); |
| 5257 | if (mode == MODE_ERRORED) { |
| 5258 | throw new SecurityException(buildSecurityExceptionMsg(op, uid, packageName)); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5259 | } |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 5260 | return mode; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5261 | } |
| 5262 | |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 5263 | /** |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 5264 | * Make note of an application performing an operation on behalf of another |
| 5265 | * application when handling an IPC. Note that you must pass the package name |
| 5266 | * of the application that is being proxied while its UID will be inferred from |
| 5267 | * the IPC state; this function will verify that the calling uid and proxied |
| 5268 | * package name match, and if not, return {@link #MODE_IGNORED}. If this call |
| 5269 | * succeeds, the last execution time of the operation for the proxied app and |
| 5270 | * your app will be updated to the current time. |
| 5271 | * @param op The operation to note. One of the OPSTR_* constants. |
| 5272 | * @param proxiedPackageName The name of the application calling into the proxy application. |
| 5273 | * @return Returns {@link #MODE_ALLOWED} if the operation is allowed, or |
| 5274 | * {@link #MODE_IGNORED} if it is not allowed and should be silently ignored (without |
| 5275 | * causing the app to crash). |
| 5276 | * @throws SecurityException If the proxy or proxied app has been configured to |
| 5277 | * crash on this op. |
| 5278 | * |
| 5279 | * @hide |
| 5280 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 5281 | @UnsupportedAppUsage |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 5282 | public int noteProxyOp(int op, String proxiedPackageName) { |
| 5283 | int mode = noteProxyOpNoThrow(op, proxiedPackageName); |
| 5284 | if (mode == MODE_ERRORED) { |
| 5285 | throw new SecurityException("Proxy package " + mContext.getOpPackageName() |
| 5286 | + " from uid " + Process.myUid() + " or calling package " |
| 5287 | + proxiedPackageName + " from uid " + Binder.getCallingUid() |
| 5288 | + " not allowed to perform " + sOpNames[op]); |
| 5289 | } |
| 5290 | return mode; |
| 5291 | } |
| 5292 | |
| 5293 | /** |
| 5294 | * Like {@link #noteProxyOp(int, String)} but instead |
| 5295 | * of throwing a {@link SecurityException} it returns {@link #MODE_ERRORED}. |
| 5296 | * @hide |
| 5297 | */ |
Philip P. Moltmann | 0d05e48 | 2019-02-08 13:05:25 -0800 | [diff] [blame] | 5298 | public int noteProxyOpNoThrow(int op, String proxiedPackageName, int proxiedUid) { |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 5299 | try { |
Svet Ganov | d873ae6 | 2018-06-25 16:39:23 -0700 | [diff] [blame] | 5300 | return mService.noteProxyOperation(op, Process.myUid(), mContext.getOpPackageName(), |
Philip P. Moltmann | 0d05e48 | 2019-02-08 13:05:25 -0800 | [diff] [blame] | 5301 | proxiedUid, proxiedPackageName); |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 5302 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 5303 | throw e.rethrowFromSystemServer(); |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 5304 | } |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 5305 | } |
| 5306 | |
| 5307 | /** |
Philip P. Moltmann | 0d05e48 | 2019-02-08 13:05:25 -0800 | [diff] [blame] | 5308 | * Like {@link #noteProxyOp(int, String)} but instead |
| 5309 | * of throwing a {@link SecurityException} it returns {@link #MODE_ERRORED}. |
| 5310 | * |
| 5311 | * <p>This API requires the package with {@code proxiedPackageName} to belongs to |
| 5312 | * {@link Binder#getCallingUid()}. |
| 5313 | * |
| 5314 | * @hide |
| 5315 | */ |
| 5316 | public int noteProxyOpNoThrow(int op, String proxiedPackageName) { |
| 5317 | return noteProxyOpNoThrow(op, proxiedPackageName, Binder.getCallingUid()); |
| 5318 | } |
| 5319 | |
| 5320 | /** |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 5321 | * Like {@link #noteOp} but instead of throwing a {@link SecurityException} it |
| 5322 | * returns {@link #MODE_ERRORED}. |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 5323 | * @hide |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 5324 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 5325 | @UnsupportedAppUsage |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5326 | public int noteOpNoThrow(int op, int uid, String packageName) { |
| 5327 | try { |
| 5328 | return mService.noteOperation(op, uid, packageName); |
| 5329 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 5330 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5331 | } |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5332 | } |
| 5333 | |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 5334 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 5335 | @UnsupportedAppUsage |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5336 | public int noteOp(int op) { |
Dianne Hackborn | 95d7853 | 2013-09-11 09:51:14 -0700 | [diff] [blame] | 5337 | return noteOp(op, Process.myUid(), mContext.getOpPackageName()); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5338 | } |
| 5339 | |
Dianne Hackborn | e98f5db | 2013-07-17 17:23:25 -0700 | [diff] [blame] | 5340 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 5341 | @UnsupportedAppUsage |
Dianne Hackborn | e98f5db | 2013-07-17 17:23:25 -0700 | [diff] [blame] | 5342 | public static IBinder getToken(IAppOpsService service) { |
| 5343 | synchronized (AppOpsManager.class) { |
| 5344 | if (sToken != null) { |
| 5345 | return sToken; |
| 5346 | } |
| 5347 | try { |
| 5348 | sToken = service.getToken(new Binder()); |
| 5349 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 5350 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | e98f5db | 2013-07-17 17:23:25 -0700 | [diff] [blame] | 5351 | } |
| 5352 | return sToken; |
| 5353 | } |
| 5354 | } |
| 5355 | |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 5356 | /** @hide */ |
| 5357 | public int startOp(int op) { |
| 5358 | return startOp(op, Process.myUid(), mContext.getOpPackageName()); |
| 5359 | } |
| 5360 | |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 5361 | /** |
| 5362 | * Report that an application has started executing a long-running operation. Note that you |
| 5363 | * must pass in both the uid and name of the application to be checked; this function will |
| 5364 | * verify that these two match, and if not, return {@link #MODE_IGNORED}. If this call |
| 5365 | * succeeds, the last execution time of the operation for this app will be updated to |
| 5366 | * the current time and the operation will be marked as "running". In this case you must |
| 5367 | * later call {@link #finishOp(int, int, String)} to report when the application is no |
| 5368 | * longer performing the operation. |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 5369 | * |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 5370 | * @param op The operation to start. One of the OP_* constants. |
| 5371 | * @param uid The user id of the application attempting to perform the operation. |
| 5372 | * @param packageName The name of the application attempting to perform the operation. |
| 5373 | * @return Returns {@link #MODE_ALLOWED} if the operation is allowed, or |
| 5374 | * {@link #MODE_IGNORED} if it is not allowed and should be silently ignored (without |
| 5375 | * causing the app to crash). |
| 5376 | * @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] | 5377 | * @hide |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 5378 | */ |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5379 | public int startOp(int op, int uid, String packageName) { |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 5380 | return startOp(op, uid, packageName, false); |
| 5381 | } |
| 5382 | |
| 5383 | /** |
| 5384 | * Report that an application has started executing a long-running operation. Similar |
| 5385 | * to {@link #startOp(String, int, String) except that if the mode is {@link #MODE_DEFAULT} |
| 5386 | * the operation should succeed since the caller has performed its standard permission |
| 5387 | * checks which passed and would perform the protected operation for this mode. |
| 5388 | * |
| 5389 | * @param op The operation to start. One of the OP_* constants. |
| 5390 | * @param uid The user id of the application attempting to perform the operation. |
| 5391 | * @param packageName The name of the application attempting to perform the operation. |
| 5392 | * @return Returns {@link #MODE_ALLOWED} if the operation is allowed, or |
| 5393 | * {@link #MODE_IGNORED} if it is not allowed and should be silently ignored (without |
| 5394 | * causing the app to crash). |
| 5395 | * @param startIfModeDefault Whether to start if mode is {@link #MODE_DEFAULT}. |
| 5396 | * |
| 5397 | * @throws SecurityException If the app has been configured to crash on this op or |
| 5398 | * the package is not in the passed in UID. |
| 5399 | * |
| 5400 | * @hide |
| 5401 | */ |
| 5402 | public int startOp(int op, int uid, String packageName, boolean startIfModeDefault) { |
| 5403 | final int mode = startOpNoThrow(op, uid, packageName, startIfModeDefault); |
| 5404 | if (mode == MODE_ERRORED) { |
| 5405 | throw new SecurityException(buildSecurityExceptionMsg(op, uid, packageName)); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5406 | } |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 5407 | return mode; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5408 | } |
| 5409 | |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 5410 | /** |
| 5411 | * Like {@link #startOp} but instead of throwing a {@link SecurityException} it |
| 5412 | * returns {@link #MODE_ERRORED}. |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 5413 | * @hide |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 5414 | */ |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5415 | public int startOpNoThrow(int op, int uid, String packageName) { |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 5416 | return startOpNoThrow(op, uid, packageName, false); |
| 5417 | } |
| 5418 | |
| 5419 | /** |
| 5420 | * Like {@link #startOp(int, int, String, boolean)} but instead of throwing a |
| 5421 | * {@link SecurityException} it returns {@link #MODE_ERRORED}. |
| 5422 | * |
| 5423 | * @param op The operation to start. One of the OP_* constants. |
| 5424 | * @param uid The user id of the application attempting to perform the operation. |
| 5425 | * @param packageName The name of the application attempting to perform the operation. |
| 5426 | * @return Returns {@link #MODE_ALLOWED} if the operation is allowed, or |
| 5427 | * {@link #MODE_IGNORED} if it is not allowed and should be silently ignored (without |
| 5428 | * causing the app to crash). |
| 5429 | * @param startIfModeDefault Whether to start if mode is {@link #MODE_DEFAULT}. |
| 5430 | * |
| 5431 | * @hide |
| 5432 | */ |
| 5433 | public int startOpNoThrow(int op, int uid, String packageName, boolean startIfModeDefault) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5434 | try { |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 5435 | return mService.startOperation(getToken(mService), op, uid, packageName, |
| 5436 | startIfModeDefault); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5437 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 5438 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5439 | } |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5440 | } |
| 5441 | |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 5442 | /** |
| 5443 | * Report that an application is no longer performing an operation that had previously |
| 5444 | * been started with {@link #startOp(int, int, String)}. There is no validation of input |
| 5445 | * or result; the parameters supplied here must be the exact same ones previously passed |
| 5446 | * in when starting the operation. |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 5447 | * @hide |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 5448 | */ |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5449 | public void finishOp(int op, int uid, String packageName) { |
| 5450 | try { |
Dianne Hackborn | e98f5db | 2013-07-17 17:23:25 -0700 | [diff] [blame] | 5451 | mService.finishOperation(getToken(mService), op, uid, packageName); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5452 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 5453 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5454 | } |
| 5455 | } |
| 5456 | |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 5457 | /** @hide */ |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5458 | public void finishOp(int op) { |
Dianne Hackborn | 95d7853 | 2013-09-11 09:51:14 -0700 | [diff] [blame] | 5459 | finishOp(op, Process.myUid(), mContext.getOpPackageName()); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5460 | } |
Jeff Sharkey | 35e46d2 | 2017-06-09 10:01:20 -0600 | [diff] [blame] | 5461 | |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 5462 | /** |
| 5463 | * Checks whether the given op for a UID and package is active. |
| 5464 | * |
| 5465 | * <p> If you don't hold the {@link android.Manifest.permission#WATCH_APPOPS} permission |
| 5466 | * you can query only for your UID. |
| 5467 | * |
| 5468 | * @see #startWatchingActive(int[], OnOpActiveChangedListener) |
| 5469 | * @see #stopWatchingMode(OnOpChangedListener) |
| 5470 | * @see #finishOp(int) |
| 5471 | * @see #startOp(int) |
| 5472 | * |
| 5473 | * @hide */ |
| 5474 | @TestApi |
| 5475 | // TODO: Uncomment below annotation once b/73559440 is fixed |
| 5476 | // @RequiresPermission(value=Manifest.permission.WATCH_APPOPS, conditional=true) |
Jeff Sharkey | 35e46d2 | 2017-06-09 10:01:20 -0600 | [diff] [blame] | 5477 | public boolean isOperationActive(int code, int uid, String packageName) { |
| 5478 | try { |
| 5479 | return mService.isOperationActive(code, uid, packageName); |
| 5480 | } catch (RemoteException e) { |
| 5481 | throw e.rethrowFromSystemServer(); |
| 5482 | } |
| 5483 | } |
Peter Visontay | 5a2a1ef | 2017-12-18 20:34:03 +0000 | [diff] [blame] | 5484 | |
| 5485 | /** |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5486 | * Configures the app ops persistence for testing. |
| 5487 | * |
| 5488 | * @param mode The mode in which the historical registry operates. |
| 5489 | * @param baseSnapshotInterval The base interval on which we would be persisting a snapshot of |
| 5490 | * the historical data. The history is recursive where every subsequent step encompasses |
| 5491 | * {@code compressionStep} longer interval with {@code compressionStep} distance between |
| 5492 | * snapshots. |
| 5493 | * @param compressionStep The compression step in every iteration. |
| 5494 | * |
| 5495 | * @see #HISTORICAL_MODE_DISABLED |
| 5496 | * @see #HISTORICAL_MODE_ENABLED_ACTIVE |
| 5497 | * @see #HISTORICAL_MODE_ENABLED_PASSIVE |
| 5498 | * |
| 5499 | * @hide |
| 5500 | */ |
| 5501 | @TestApi |
| 5502 | @RequiresPermission(Manifest.permission.MANAGE_APPOPS) |
| 5503 | public void setHistoryParameters(@HistoricalMode int mode, long baseSnapshotInterval, |
| 5504 | int compressionStep) { |
| 5505 | try { |
| 5506 | mService.setHistoryParameters(mode, baseSnapshotInterval, compressionStep); |
| 5507 | } catch (RemoteException e) { |
| 5508 | throw e.rethrowFromSystemServer(); |
| 5509 | } |
| 5510 | } |
| 5511 | |
| 5512 | /** |
| 5513 | * Offsets the history by the given duration. |
| 5514 | * |
| 5515 | * @param offsetMillis The offset duration. |
| 5516 | * |
| 5517 | * @hide |
| 5518 | */ |
| 5519 | @TestApi |
| 5520 | @RequiresPermission(Manifest.permission.MANAGE_APPOPS) |
| 5521 | public void offsetHistory(long offsetMillis) { |
| 5522 | try { |
| 5523 | mService.offsetHistory(offsetMillis); |
| 5524 | } catch (RemoteException e) { |
| 5525 | throw e.rethrowFromSystemServer(); |
| 5526 | } |
| 5527 | } |
| 5528 | |
| 5529 | /** |
| 5530 | * Adds ops to the history directly. This could be useful for testing especially |
| 5531 | * when the historical registry operates in {@link #HISTORICAL_MODE_ENABLED_PASSIVE} |
| 5532 | * mode. |
| 5533 | * |
| 5534 | * @param ops The ops to add to the history. |
| 5535 | * |
| 5536 | * @see #setHistoryParameters(int, long, int) |
| 5537 | * @see #HISTORICAL_MODE_ENABLED_PASSIVE |
| 5538 | * |
| 5539 | * @hide |
| 5540 | */ |
| 5541 | @TestApi |
| 5542 | @RequiresPermission(Manifest.permission.MANAGE_APPOPS) |
| 5543 | public void addHistoricalOps(@NonNull HistoricalOps ops) { |
| 5544 | try { |
| 5545 | mService.addHistoricalOps(ops); |
| 5546 | } catch (RemoteException e) { |
| 5547 | throw e.rethrowFromSystemServer(); |
| 5548 | } |
| 5549 | } |
| 5550 | |
| 5551 | /** |
| 5552 | * Resets the app ops persistence for testing. |
| 5553 | * |
| 5554 | * @see #setHistoryParameters(int, long, int) |
| 5555 | * |
| 5556 | * @hide |
| 5557 | */ |
| 5558 | @TestApi |
| 5559 | @RequiresPermission(Manifest.permission.MANAGE_APPOPS) |
| 5560 | public void resetHistoryParameters() { |
| 5561 | try { |
| 5562 | mService.resetHistoryParameters(); |
| 5563 | } catch (RemoteException e) { |
| 5564 | throw e.rethrowFromSystemServer(); |
| 5565 | } |
| 5566 | } |
| 5567 | |
| 5568 | /** |
| 5569 | * Clears all app ops history. |
| 5570 | * |
| 5571 | * @hide |
| 5572 | */ |
| 5573 | @TestApi |
| 5574 | @RequiresPermission(Manifest.permission.MANAGE_APPOPS) |
| 5575 | public void clearHistory() { |
| 5576 | try { |
| 5577 | mService.clearHistory(); |
| 5578 | } catch (RemoteException e) { |
| 5579 | throw e.rethrowFromSystemServer(); |
| 5580 | } |
| 5581 | } |
| 5582 | |
| 5583 | /** |
Peter Visontay | 5a2a1ef | 2017-12-18 20:34:03 +0000 | [diff] [blame] | 5584 | * Returns all supported operation names. |
| 5585 | * @hide |
| 5586 | */ |
| 5587 | @SystemApi |
| 5588 | @TestApi |
| 5589 | public static String[] getOpStrs() { |
| 5590 | return Arrays.copyOf(sOpToString, sOpToString.length); |
| 5591 | } |
Dianne Hackborn | c216a26 | 2018-04-26 13:46:22 -0700 | [diff] [blame] | 5592 | |
Philip P. Moltmann | 2457681 | 2018-05-07 10:42:05 -0700 | [diff] [blame] | 5593 | |
| 5594 | /** |
| 5595 | * @return number of App ops |
| 5596 | * @hide |
| 5597 | */ |
| 5598 | @TestApi |
| 5599 | public static int getNumOps() { |
| 5600 | return _NUM_OP; |
| 5601 | } |
| 5602 | |
Dianne Hackborn | c216a26 | 2018-04-26 13:46:22 -0700 | [diff] [blame] | 5603 | /** |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 5604 | * Computes the max for the given flags in between the begin and |
| 5605 | * end UID states. |
| 5606 | * |
| 5607 | * @param counts The data array. |
| 5608 | * @param flags The UID flags. |
| 5609 | * @param beginUidState The beginning UID state (exclusive). |
| 5610 | * @param endUidState The end UID state. |
| 5611 | * @return The sum. |
Dianne Hackborn | c216a26 | 2018-04-26 13:46:22 -0700 | [diff] [blame] | 5612 | */ |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 5613 | private static long maxForFlagsInStates(@Nullable LongSparseLongArray counts, |
| 5614 | @UidState int beginUidState, @UidState int endUidState, |
| 5615 | @OpFlags int flags) { |
| 5616 | if (counts == null) { |
| 5617 | return 0; |
| 5618 | } |
| 5619 | long max = 0; |
| 5620 | while (flags != 0) { |
| 5621 | final int flag = 1 << Integer.numberOfTrailingZeros(flags); |
| 5622 | flags &= ~flag; |
| 5623 | for (int uidState : UID_STATES) { |
| 5624 | if (uidState < beginUidState || uidState > endUidState) { |
| 5625 | continue; |
| 5626 | } |
| 5627 | final long key = makeKey(uidState, flag); |
| 5628 | max = Math.max(max, counts.get(key)); |
Dianne Hackborn | c216a26 | 2018-04-26 13:46:22 -0700 | [diff] [blame] | 5629 | } |
| 5630 | } |
Svet Ganov | af189e3 | 2019-02-15 18:45:29 -0800 | [diff] [blame] | 5631 | return max; |
| 5632 | } |
| 5633 | |
| 5634 | |
| 5635 | private static void writeLongSparseLongArrayToParcel( |
| 5636 | @Nullable LongSparseLongArray array, @NonNull Parcel parcel) { |
| 5637 | if (array != null) { |
| 5638 | final int size = array.size(); |
| 5639 | parcel.writeInt(size); |
| 5640 | for (int i = 0; i < size; i++) { |
| 5641 | parcel.writeLong(array.keyAt(i)); |
| 5642 | parcel.writeLong(array.valueAt(i)); |
| 5643 | } |
| 5644 | } else { |
| 5645 | parcel.writeInt(-1); |
| 5646 | } |
| 5647 | } |
| 5648 | |
| 5649 | private static @Nullable LongSparseLongArray readLongSparseLongArrayFromParcel( |
| 5650 | @NonNull Parcel parcel) { |
| 5651 | final int size = parcel.readInt(); |
| 5652 | if (size < 0) { |
| 5653 | return null; |
| 5654 | } |
| 5655 | final LongSparseLongArray array = new LongSparseLongArray(size); |
| 5656 | for (int i = 0; i < size; i++) { |
| 5657 | array.append(parcel.readLong(), parcel.readLong()); |
| 5658 | } |
| 5659 | return array; |
| 5660 | } |
| 5661 | |
| 5662 | private static void writeLongSparseStringArrayToParcel( |
| 5663 | @Nullable LongSparseArray<String> array, @NonNull Parcel parcel) { |
| 5664 | if (array != null) { |
| 5665 | final int size = array.size(); |
| 5666 | parcel.writeInt(size); |
| 5667 | for (int i = 0; i < size; i++) { |
| 5668 | parcel.writeLong(array.keyAt(i)); |
| 5669 | parcel.writeString(array.valueAt(i)); |
| 5670 | } |
| 5671 | } else { |
| 5672 | parcel.writeInt(-1); |
| 5673 | } |
| 5674 | } |
| 5675 | |
| 5676 | private static @Nullable LongSparseArray<String> readLongSparseStringArrayFromParcel( |
| 5677 | @NonNull Parcel parcel) { |
| 5678 | final int size = parcel.readInt(); |
| 5679 | if (size < 0) { |
| 5680 | return null; |
| 5681 | } |
| 5682 | final LongSparseArray<String> array = new LongSparseArray<>(size); |
| 5683 | for (int i = 0; i < size; i++) { |
| 5684 | array.append(parcel.readLong(), parcel.readString()); |
| 5685 | } |
| 5686 | return array; |
| 5687 | } |
| 5688 | |
| 5689 | /** |
| 5690 | * Collects the keys from an array to the result creating the result if needed. |
| 5691 | * |
| 5692 | * @param array The array whose keys to collect. |
| 5693 | * @param result The optional result store collected keys. |
| 5694 | * @return The result collected keys array. |
| 5695 | */ |
| 5696 | private static LongSparseArray<Object> collectKeys(@Nullable LongSparseLongArray array, |
| 5697 | @Nullable LongSparseArray<Object> result) { |
| 5698 | if (array != null) { |
| 5699 | if (result == null) { |
| 5700 | result = new LongSparseArray<>(); |
| 5701 | } |
| 5702 | final int accessSize = array.size(); |
| 5703 | for (int i = 0; i < accessSize; i++) { |
| 5704 | result.put(array.keyAt(i), null); |
| 5705 | } |
| 5706 | } |
| 5707 | return result; |
Dianne Hackborn | c216a26 | 2018-04-26 13:46:22 -0700 | [diff] [blame] | 5708 | } |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5709 | |
| 5710 | /** @hide */ |
| 5711 | public static String uidStateToString(@UidState int uidState) { |
| 5712 | switch (uidState) { |
| 5713 | case UID_STATE_PERSISTENT: { |
| 5714 | return "UID_STATE_PERSISTENT"; |
| 5715 | } |
| 5716 | case UID_STATE_TOP: { |
| 5717 | return "UID_STATE_TOP"; |
| 5718 | } |
Amith Yamasani | a0a30a1 | 2019-01-22 11:38:06 -0800 | [diff] [blame] | 5719 | case UID_STATE_FOREGROUND_SERVICE_LOCATION: { |
| 5720 | return "UID_STATE_FOREGROUND_SERVICE_LOCATION"; |
| 5721 | } |
Svet Ganov | 8455ba2 | 2019-01-02 13:05:56 -0800 | [diff] [blame] | 5722 | case UID_STATE_FOREGROUND_SERVICE: { |
| 5723 | return "UID_STATE_FOREGROUND_SERVICE"; |
| 5724 | } |
| 5725 | case UID_STATE_FOREGROUND: { |
| 5726 | return "UID_STATE_FOREGROUND"; |
| 5727 | } |
| 5728 | case UID_STATE_BACKGROUND: { |
| 5729 | return "UID_STATE_BACKGROUND"; |
| 5730 | } |
| 5731 | case UID_STATE_CACHED: { |
| 5732 | return "UID_STATE_CACHED"; |
| 5733 | } |
| 5734 | default: { |
| 5735 | return "UNKNOWN"; |
| 5736 | } |
| 5737 | } |
| 5738 | } |
| 5739 | |
| 5740 | /** @hide */ |
| 5741 | public static int parseHistoricalMode(@NonNull String mode) { |
| 5742 | switch (mode) { |
| 5743 | case "HISTORICAL_MODE_ENABLED_ACTIVE": { |
| 5744 | return HISTORICAL_MODE_ENABLED_ACTIVE; |
| 5745 | } |
| 5746 | case "HISTORICAL_MODE_ENABLED_PASSIVE": { |
| 5747 | return HISTORICAL_MODE_ENABLED_PASSIVE; |
| 5748 | } |
| 5749 | default: { |
| 5750 | return HISTORICAL_MODE_DISABLED; |
| 5751 | } |
| 5752 | } |
| 5753 | } |
| 5754 | |
| 5755 | /** @hide */ |
| 5756 | public static String historicalModeToString(@HistoricalMode int mode) { |
| 5757 | switch (mode) { |
| 5758 | case HISTORICAL_MODE_DISABLED: { |
| 5759 | return "HISTORICAL_MODE_DISABLED"; |
| 5760 | } |
| 5761 | case HISTORICAL_MODE_ENABLED_ACTIVE: { |
| 5762 | return "HISTORICAL_MODE_ENABLED_ACTIVE"; |
| 5763 | } |
| 5764 | case HISTORICAL_MODE_ENABLED_PASSIVE: { |
| 5765 | return "HISTORICAL_MODE_ENABLED_PASSIVE"; |
| 5766 | } |
| 5767 | default: { |
| 5768 | return "UNKNOWN"; |
| 5769 | } |
| 5770 | } |
| 5771 | } |
Ng Zhi An | 65a99b6 | 2018-10-01 11:57:53 -0700 | [diff] [blame] | 5772 | |
| 5773 | private static int getSystemAlertWindowDefault() { |
| 5774 | final Context context = ActivityThread.currentApplication(); |
| 5775 | if (context == null) { |
| 5776 | return AppOpsManager.MODE_DEFAULT; |
| 5777 | } |
| 5778 | |
| 5779 | // system alert window is disable on low ram phones starting from Q |
| 5780 | final PackageManager pm = context.getPackageManager(); |
| 5781 | // TVs are constantly plugged in and has less concern for memory/power |
| 5782 | if (ActivityManager.isLowRamDeviceStatic() |
| 5783 | && !pm.hasSystemFeature(PackageManager.FEATURE_LEANBACK, 0)) { |
| 5784 | return AppOpsManager.MODE_IGNORED; |
| 5785 | } |
| 5786 | |
| 5787 | return AppOpsManager.MODE_DEFAULT; |
| 5788 | } |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5789 | } |