/*
* Copyright (C) 2012 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.app;
import static android.location.flags.Flags.FLAG_LOCATION_BYPASS;
import static android.media.audio.Flags.roForegroundAudioControl;
import static android.permission.flags.Flags.FLAG_OP_ENABLE_MOBILE_DATA_BY_USER;
import static android.service.notification.Flags.FLAG_REDACT_SENSITIVE_NOTIFICATIONS_FROM_UNTRUSTED_LISTENERS;
import static android.view.contentprotection.flags.Flags.FLAG_CREATE_ACCESSIBILITY_OVERLAY_APP_OP_ENABLED;
import static android.view.contentprotection.flags.Flags.FLAG_RAPID_CLEAR_NOTIFICATIONS_BY_LISTENER_APP_OP_ENABLED;
import static java.lang.Long.max;
import android.Manifest;
import android.annotation.CallbackExecutor;
import android.annotation.FlaggedApi;
import android.annotation.IntDef;
import android.annotation.IntRange;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.RequiresPermission;
import android.annotation.StringDef;
import android.annotation.SuppressLint;
import android.annotation.SystemApi;
import android.annotation.SystemService;
import android.annotation.TestApi;
import android.app.usage.UsageStatsManager;
import android.companion.virtual.VirtualDeviceManager;
import android.compat.Compatibility;
import android.compat.annotation.ChangeId;
import android.compat.annotation.EnabledAfter;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.AttributionSource;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.ParceledListSlice;
import android.database.DatabaseUtils;
import android.health.connect.HealthConnectManager;
import android.media.AudioAttributes.AttributeUsage;
import android.media.MediaRouter2;
import android.os.Binder;
import android.os.Build;
import android.os.Handler;
import android.os.HandlerExecutor;
import android.os.HandlerThread;
import android.os.IBinder;
import android.os.Looper;
import android.os.PackageTagsList;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.Process;
import android.os.RemoteCallback;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.SystemClock;
import android.os.UserHandle;
import android.os.UserManager;
import android.permission.PermissionGroupUsage;
import android.permission.PermissionUsageHelper;
import android.permission.flags.Flags;
import android.provider.DeviceConfig;
import android.util.ArrayMap;
import android.util.ArraySet;
import android.util.Log;
import android.util.LongSparseArray;
import android.util.LongSparseLongArray;
import android.util.Pools;
import android.util.SparseArray;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.Immutable;
import com.android.internal.app.IAppOpsActiveCallback;
import com.android.internal.app.IAppOpsAsyncNotedCallback;
import com.android.internal.app.IAppOpsCallback;
import com.android.internal.app.IAppOpsNotedCallback;
import com.android.internal.app.IAppOpsService;
import com.android.internal.app.IAppOpsStartedCallback;
import com.android.internal.app.MessageSamplingConfig;
import com.android.internal.os.RuntimeInit;
import com.android.internal.os.ZygoteInit;
import com.android.internal.util.ArrayUtils;
import com.android.internal.util.DataClass;
import com.android.internal.util.FrameworkStatsLog;
import com.android.internal.util.Parcelling;
import com.android.internal.util.Preconditions;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.Executor;
import java.util.function.Consumer;
import java.util.function.Supplier;
/**
* App-ops are used for two purposes: Access control and tracking.
*
*
App-ops cover a wide variety of functionality from helping with runtime permissions access
* control and tracking to battery consumption tracking.
*
*
Access control
*
*
App-ops can either be controlled for each uid or for each package. Which one is used depends
* on the API provider maintaining this app-op. For any security or privacy related app-op the
* provider needs to control the app-op for per uid as all security and privacy is based on uid in
* Android.
*
*
To control access the app-op can be set to a mode to:
*
*
{@link #MODE_DEFAULT}
*
Default behavior, might differ from app-op or app-op
*
{@link #MODE_ALLOWED}
*
Allow the access
*
{@link #MODE_IGNORED}
*
Don't allow the access, i.e. don't perform the requested action or return no or
* placeholder data
*
{@link #MODE_ERRORED}
*
Throw a {@link SecurityException} on access. This can be suppressed by using a
* {@code ...noThrow} method to check the mode
*
*
*
API providers need to check the mode returned by {@link #noteOp} if they are are allowing
* access to operations gated by the app-op. {@link #unsafeCheckOp} should be used to check the
* mode if no access is granted. E.g. this can be used for displaying app-op state in the UI or
* when checking the state before later calling {@link #noteOp} anyway.
*
*
If an operation refers to a time span (e.g. a audio-recording session) the API provider
* should use {@link #startOp} and {@link #finishOp} instead of {@link #noteOp}.
*
*
Runtime permissions and app-ops
*
*
Each platform defined runtime permission (beside background modifiers) has an associated app
* op which is used for tracking but also to allow for silent failures. I.e. if the runtime
* permission is denied the caller gets a {@link SecurityException}, but if the permission is
* granted and the app-op is {@link #MODE_IGNORED} then the callers gets placeholder behavior, e.g.
* location callbacks would not happen.
*
*
App-op permissions
*
*
App-ops permissions are platform defined permissions that can be overridden. The security
* check for app-op permissions should by {@link #MODE_DEFAULT default} check the permission grant
* state. If the app-op state is set to {@link #MODE_ALLOWED} or {@link #MODE_IGNORED} the app-op
* state should be checked instead of the permission grant state.
*
*
This functionality allows to grant access by default to apps fulfilling the requirements for
* a certain permission level. Still the behavior can be overridden when needed.
*
*
Tracking
*
*
App-ops track many important events, including all accesses to runtime permission protected
* APIs. This is done by tracking when an app-op was {@link #noteOp noted} or
* {@link #startOp started}. The tracked data can only be read by system components.
*
*
Only {@link #noteOp}/{@link #startOp} are tracked; {@link #unsafeCheckOp} is not tracked.
* Hence it is important to eventually call {@link #noteOp} or {@link #startOp} when providing
* access to protected operations or data.
*
*
Some apps are forwarding access to other apps. E.g. an app might get the location from the
* system's location provider and then send the location further to a 3rd app. In this case the
* app passing on the data needs to call {@link #noteProxyOp} to signal the access proxying. This
* might also make sense inside of a single app if the access is forwarded between two parts of
* the tagged with different attribution tags.
*
*
An app can register an {@link OnOpNotedCallback} to get informed about what accesses the
* system is tracking for it. As each runtime permission has an associated app-op this API is
* particularly useful for an app that want to find unexpected private data accesses.
*/
@SystemService(Context.APP_OPS_SERVICE)
public class AppOpsManager {
/**
* This is a subtle behavior change to {@link #startWatchingMode}.
*
* Before this change the system called back for the switched op. After the change the system
* will call back for the actually requested op or all switched ops if no op is specified.
*
* @hide
*/
@ChangeId
@EnabledAfter(targetSdkVersion = Build.VERSION_CODES.Q)
public static final long CALL_BACK_ON_CHANGED_LISTENER_WITH_SWITCHED_OP_CHANGE = 148180766L;
/**
* Enforce that all attributionTags send to {@link #noteOp}, {@link #noteProxyOp},
* and {@link #startOp} are defined in the manifest of the package that is specified as
* parameter to the methods.
*
*
To enable this change both the package calling {@link #noteOp} as well as the package
* specified as parameter to the method need to have this change enable.
*
* @hide
*/
@TestApi
@ChangeId
@EnabledAfter(targetSdkVersion = Build.VERSION_CODES.R)
public static final long SECURITY_EXCEPTION_ON_INVALID_ATTRIBUTION_TAG_CHANGE = 151105954L;
private static final String FULL_LOG = "privacy_attribution_tag_full_log_enabled";
private static final int MAX_UNFORWARDED_OPS = 10;
private static Boolean sFullLog = null;
final Context mContext;
private PermissionUsageHelper mUsageHelper;
@UnsupportedAppUsage
final IAppOpsService mService;
/**
* Service for the application context, to be used by static methods via
* {@link #getService()}
*/
@GuardedBy("sLock")
static IAppOpsService sService;
@GuardedBy("mModeWatchers")
private final ArrayMap mModeWatchers =
new ArrayMap<>();
@GuardedBy("mActiveWatchers")
private final ArrayMap mActiveWatchers =
new ArrayMap<>();
@GuardedBy("mStartedWatchers")
private final ArrayMap mStartedWatchers =
new ArrayMap<>();
@GuardedBy("mNotedWatchers")
private final ArrayMap mNotedWatchers =
new ArrayMap<>();
private static final Object sLock = new Object();
/** Current {@link OnOpNotedCallback}. Change via {@link #setOnOpNotedCallback} */
@GuardedBy("sLock")
private static @Nullable OnOpNotedCallback sOnOpNotedCallback;
/**
* Sync note-ops collected from {@link #readAndLogNotedAppops(Parcel)} that have not been
* delivered to a callback yet.
*
* Similar to {@link com.android.server.appop.AppOpsService#mUnforwardedAsyncNotedOps} for
* {@link COLLECT_ASYNC}. Used in situation when AppOpsManager asks to collect stacktrace with
* {@link #sMessageCollector}, which forces {@link COLLECT_SYNC} mode.
*/
@GuardedBy("sLock")
private static ArrayList sUnforwardedOps = new ArrayList<>();
/**
* Additional collector that collect accesses and forwards a few of them them via
* {@link IAppOpsService#reportRuntimeAppOpAccessMessageAndGetConfig}.
*/
private static OnOpNotedCallback sMessageCollector =
new OnOpNotedCallback() {
@Override
public void onNoted(@NonNull SyncNotedAppOp op) {
reportStackTraceIfNeeded(op);
}
@Override
public void onAsyncNoted(@NonNull AsyncNotedAppOp asyncOp) {
// collected directly in AppOpsService
}
@Override
public void onSelfNoted(@NonNull SyncNotedAppOp op) {
reportStackTraceIfNeeded(op);
}
private void reportStackTraceIfNeeded(@NonNull SyncNotedAppOp op) {
if (!isCollectingStackTraces()) {
return;
}
MessageSamplingConfig config = sConfig;
if (leftCircularDistance(strOpToOp(op.getOp()), config.getSampledOpCode(),
_NUM_OP) <= config.getAcceptableLeftDistance()
|| config.getExpirationTimeSinceBootMillis()
< SystemClock.elapsedRealtime()) {
String stackTrace = getFormattedStackTrace();
try {
String packageName = ActivityThread.currentOpPackageName();
sConfig = getService().reportRuntimeAppOpAccessMessageAndGetConfig(
packageName == null ? "" : packageName, op, stackTrace);
} catch (RemoteException e) {
e.rethrowFromSystemServer();
}
}
}
};
static IBinder sClientId;
/**
* How many seconds we want for a drop in uid state from top to settle before applying it.
*
* <>Set a parameter to {@link android.provider.Settings.Global#APP_OPS_CONSTANTS}
*
* @hide
*/
@TestApi
public static final String KEY_TOP_STATE_SETTLE_TIME = "top_state_settle_time";
/**
* How many second we want for a drop in uid state from foreground to settle before applying it.
*
* <>Set a parameter to {@link android.provider.Settings.Global#APP_OPS_CONSTANTS}
*
* @hide
*/
@TestApi
public static final String KEY_FG_SERVICE_STATE_SETTLE_TIME =
"fg_service_state_settle_time";
/**
* How many seconds we want for a drop in uid state from background to settle before applying
* it.
*
* <>Set a parameter to {@link android.provider.Settings.Global#APP_OPS_CONSTANTS}
*
* @hide
*/
@TestApi
public static final String KEY_BG_STATE_SETTLE_TIME = "bg_state_settle_time";
/** @hide */
@Retention(RetentionPolicy.SOURCE)
@IntDef(flag = true, prefix = { "HISTORICAL_MODE_" }, value = {
HISTORICAL_MODE_DISABLED,
HISTORICAL_MODE_ENABLED_ACTIVE,
HISTORICAL_MODE_ENABLED_PASSIVE
})
public @interface HistoricalMode {}
/**
* Mode in which app op history is completely disabled.
* @hide
*/
@TestApi
public static final int HISTORICAL_MODE_DISABLED = 0;
/**
* Mode in which app op history is enabled and app ops performed by apps would
* be tracked. This is the mode in which the feature is completely enabled.
* @hide
*/
@TestApi
public static final int HISTORICAL_MODE_ENABLED_ACTIVE = 1;
/**
* Mode in which app op history is enabled but app ops performed by apps would
* not be tracked and the only way to add ops to the history is via explicit calls
* to dedicated APIs. This mode is useful for testing to allow full control of
* the historical content.
* @hide
*/
@TestApi
public static final int HISTORICAL_MODE_ENABLED_PASSIVE = 2;
/** @hide */
@Retention(RetentionPolicy.SOURCE)
@IntDef(prefix = { "MODE_" }, value = {
MODE_ALLOWED,
MODE_IGNORED,
MODE_ERRORED,
MODE_DEFAULT,
MODE_FOREGROUND
})
public @interface Mode {}
/**
* Result from {@link #checkOp}, {@link #noteOp}, {@link #startOp}: the given caller is
* allowed to perform the given operation.
*/
public static final int MODE_ALLOWED = 0;
/**
* Result from {@link #checkOp}, {@link #noteOp}, {@link #startOp}: the given caller is
* not allowed to perform the given operation, and this attempt should
* silently fail (it should not cause the app to crash).
*/
public static final int MODE_IGNORED = 1;
/**
* Result from {@link #checkOpNoThrow}, {@link #noteOpNoThrow}, {@link #startOpNoThrow}: the
* given caller is not allowed to perform the given operation, and this attempt should
* cause it to have a fatal error, typically a {@link SecurityException}.
*/
public static final int MODE_ERRORED = 2;
/**
* Result from {@link #checkOp}, {@link #noteOp}, {@link #startOp}: the given caller should
* use its default security check. This mode is not normally used; it should only be used
* with appop permissions, and callers must explicitly check for it and deal with it.
*/
public static final int MODE_DEFAULT = 3;
/**
* Special mode that means "allow only when app is in foreground." This is not
* returned from {@link #unsafeCheckOp}, {@link #noteOp}, {@link #startOp}. Rather,
* {@link #unsafeCheckOp} will always return {@link #MODE_ALLOWED} (because it is always
* possible for it to be ultimately allowed, depending on the app's background state),
* and {@link #noteOp} and {@link #startOp} will return {@link #MODE_ALLOWED} when the app
* being checked is currently in the foreground, otherwise {@link #MODE_IGNORED}.
*
*
The only place you will this normally see this value is through
* {@link #unsafeCheckOpRaw}, which returns the actual raw mode of the op. Note that because
* you can't know the current state of the app being checked (and it can change at any
* point), you can only treat the result here as an indication that it will vary between
* {@link #MODE_ALLOWED} and {@link #MODE_IGNORED} depending on changes in the background
* state of the app. You thus must always use {@link #noteOp} or {@link #startOp} to do
* the actual check for access to the op.
*/
public static final int MODE_FOREGROUND = 4;
/**
* Flag for {@link #startWatchingMode(String, String, int, OnOpChangedListener)}:
* Also get reports if the foreground state of an op's uid changes. This only works
* when watching a particular op, not when watching a package.
*/
public static final int WATCH_FOREGROUND_CHANGES = 1 << 0;
/**
* Flag for {@link #startWatchingMode} that causes the callback to happen on the switch-op
* instead the op the callback was registered. (This simulates pre-R behavior).
*
* @hide
*/
public static final int CALL_BACK_ON_SWITCHED_OP = 1 << 1;
/**
* Flag to determine whether we should log noteOp/startOp calls to make sure they
* are correctly used
*
* @hide
*/
public static final boolean NOTE_OP_COLLECTION_ENABLED = false;
/**
* @hide
*/
public static final String[] MODE_NAMES = new String[] {
"allow", // MODE_ALLOWED
"ignore", // MODE_IGNORED
"deny", // MODE_ERRORED
"default", // MODE_DEFAULT
"foreground", // MODE_FOREGROUND
};
/** @hide */
@Retention(RetentionPolicy.SOURCE)
@IntDef(prefix = { "UID_STATE_" }, value = {
UID_STATE_PERSISTENT,
UID_STATE_TOP,
UID_STATE_FOREGROUND_SERVICE_LOCATION,
UID_STATE_FOREGROUND_SERVICE,
UID_STATE_FOREGROUND,
UID_STATE_BACKGROUND,
UID_STATE_CACHED,
UID_STATE_NONEXISTENT
})
public @interface UidState {}
/**
* Uid state: The UID is a foreground persistent app. The lower the UID
* state the more important the UID is for the user.
* @hide
*/
@SystemApi
public static final int UID_STATE_PERSISTENT = 100;
/**
* Uid state: The UID is top foreground app. The lower the UID
* state the more important the UID is for the user.
* @hide
*/
@SystemApi
public static final int UID_STATE_TOP = 200;
/**
* Uid state: The UID is running a foreground service of location type.
* The lower the UID state the more important the UID is for the user.
* This uid state is a counterpart to PROCESS_STATE_FOREGROUND_SERVICE_LOCATION which has been
* deprecated.
* @hide
* @deprecated
*/
@SystemApi
@Deprecated
public static final int UID_STATE_FOREGROUND_SERVICE_LOCATION = 300;
/**
* Uid state: The UID is running a foreground service. The lower the UID
* state the more important the UID is for the user.
* @hide
*/
@SystemApi
public static final int UID_STATE_FOREGROUND_SERVICE = 400;
/**
* Uid state: The UID is a foreground app. The lower the UID
* state the more important the UID is for the user.
* @hide
*/
@SystemApi
public static final int UID_STATE_FOREGROUND = 500;
/**
* The max, which is min priority, UID state for which any app op
* would be considered as performed in the foreground.
* @hide
*/
public static final int UID_STATE_MAX_LAST_NON_RESTRICTED = UID_STATE_FOREGROUND;
/**
* Uid state: The UID is a background app. The lower the UID
* state the more important the UID is for the user.
* @hide
*/
@SystemApi
public static final int UID_STATE_BACKGROUND = 600;
/**
* Uid state: The UID is a cached app. The lower the UID
* state the more important the UID is for the user.
* @hide
*/
@SystemApi
public static final int UID_STATE_CACHED = 700;
/**
* Uid state: The UID state with the highest priority.
* @hide
*/
public static final int MAX_PRIORITY_UID_STATE = UID_STATE_PERSISTENT;
/**
* Uid state: The UID state with the lowest priority.
* @hide
*/
public static final int MIN_PRIORITY_UID_STATE = UID_STATE_CACHED;
/**
* Special uid state: The UID is not running
* @hide
*/
public static final int UID_STATE_NONEXISTENT = Integer.MAX_VALUE;
/**
* Resolves the first unrestricted state given an app op.
* @param op The op to resolve.
* @return The last restricted UID state.
*
* @hide
*/
public static int resolveFirstUnrestrictedUidState(int op) {
return UID_STATE_MAX_LAST_NON_RESTRICTED;
}
/**
* Resolves the last restricted state given an app op.
* @param op The op to resolve.
* @return The last restricted UID state.
*
* @hide
*/
public static int resolveLastRestrictedUidState(int op) {
return UID_STATE_BACKGROUND;
}
/** @hide Note: Keep these sorted */
public static final int[] UID_STATES = {
UID_STATE_PERSISTENT,
UID_STATE_TOP,
UID_STATE_FOREGROUND_SERVICE_LOCATION,
UID_STATE_FOREGROUND_SERVICE,
UID_STATE_FOREGROUND,
UID_STATE_BACKGROUND,
UID_STATE_CACHED
// UID_STATE_NONEXISTENT isn't a real UID state, so it is excluded
};
/** @hide */
public static String getUidStateName(@UidState int uidState) {
switch (uidState) {
case UID_STATE_PERSISTENT:
return "pers";
case UID_STATE_TOP:
return "top";
case UID_STATE_FOREGROUND_SERVICE_LOCATION:
return "fgsvcl";
case UID_STATE_FOREGROUND_SERVICE:
return "fgsvc";
case UID_STATE_FOREGROUND:
return "fg";
case UID_STATE_BACKGROUND:
return "bg";
case UID_STATE_CACHED:
return "cch";
case UID_STATE_NONEXISTENT:
return "gone";
default:
return "unknown";
}
}
/**
* Flag: non proxy operations. These are operations
* performed on behalf of the app itself and not on behalf of
* another one.
*
* @hide
*/
@SystemApi
public static final int OP_FLAG_SELF = 0x1;
/**
* Flag: trusted proxy operations. These are operations
* performed on behalf of another app by a trusted app.
* Which is work a trusted app blames on another app.
*
* @hide
*/
@SystemApi
public static final int OP_FLAG_TRUSTED_PROXY = 0x2;
/**
* Flag: untrusted proxy operations. These are operations
* performed on behalf of another app by an untrusted app.
* Which is work an untrusted app blames on another app.
*
* @hide
*/
@SystemApi
public static final int OP_FLAG_UNTRUSTED_PROXY = 0x4;
/**
* Flag: trusted proxied operations. These are operations
* performed by a trusted other app on behalf of an app.
* Which is work an app was blamed for by a trusted app.
*
* @hide
*/
@SystemApi
public static final int OP_FLAG_TRUSTED_PROXIED = 0x8;
/**
* Flag: untrusted proxied operations. These are operations
* performed by an untrusted other app on behalf of an app.
* Which is work an app was blamed for by an untrusted app.
*
* @hide
*/
@SystemApi
public static final int OP_FLAG_UNTRUSTED_PROXIED = 0x10;
/**
* Flags: all operations. These include operations matched
* by {@link #OP_FLAG_SELF}, {@link #OP_FLAG_TRUSTED_PROXIED},
* {@link #OP_FLAG_UNTRUSTED_PROXIED}, {@link #OP_FLAG_TRUSTED_PROXIED},
* {@link #OP_FLAG_UNTRUSTED_PROXIED}.
*
* @hide
*/
@SystemApi
public static final int OP_FLAGS_ALL =
OP_FLAG_SELF
| OP_FLAG_TRUSTED_PROXY
| OP_FLAG_UNTRUSTED_PROXY
| OP_FLAG_TRUSTED_PROXIED
| OP_FLAG_UNTRUSTED_PROXIED;
/**
* Flags: all trusted operations which is ones either the app did {@link #OP_FLAG_SELF},
* or it was blamed for by a trusted app {@link #OP_FLAG_TRUSTED_PROXIED}, or ones the
* app if untrusted blamed on other apps {@link #OP_FLAG_UNTRUSTED_PROXY}.
*
* @hide
*/
@SystemApi
public static final int OP_FLAGS_ALL_TRUSTED = AppOpsManager.OP_FLAG_SELF
| AppOpsManager.OP_FLAG_UNTRUSTED_PROXY
| AppOpsManager.OP_FLAG_TRUSTED_PROXIED;
/** @hide */
@Retention(RetentionPolicy.SOURCE)
@IntDef(flag = true, prefix = { "FLAG_" }, value = {
OP_FLAG_SELF,
OP_FLAG_TRUSTED_PROXY,
OP_FLAG_UNTRUSTED_PROXY,
OP_FLAG_TRUSTED_PROXIED,
OP_FLAG_UNTRUSTED_PROXIED
})
public @interface OpFlags {}
/** @hide */
public static final String getFlagName(@OpFlags int flag) {
switch (flag) {
case OP_FLAG_SELF:
return "s";
case OP_FLAG_TRUSTED_PROXY:
return "tp";
case OP_FLAG_UNTRUSTED_PROXY:
return "up";
case OP_FLAG_TRUSTED_PROXIED:
return "tpd";
case OP_FLAG_UNTRUSTED_PROXIED:
return "upd";
default:
return "unknown";
}
}
/**
* Attribution chain flag: specifies that this is the accessor. When
* an app A accesses the data that is then passed to app B that is then
* passed to C, we call app A accessor, app B intermediary, and app C
* receiver. If A accesses the data for itself, then it is the accessor
* and the receiver.
* @hide
*/
@TestApi
public static final int ATTRIBUTION_FLAG_ACCESSOR = 0x1;
/**
* Attribution chain flag: specifies that this is the intermediary. When
* an app A accesses the data that is then passed to app B that is then
* passed to C, we call app A accessor, app B intermediary, and app C
* receiver. If A accesses the data for itself, then it is the accessor
* and the receiver.
* @hide
*/
@TestApi
public static final int ATTRIBUTION_FLAG_INTERMEDIARY = 0x2;
/**
* Attribution chain flag: specifies that this is the receiver. When
* an app A accesses the data that is then passed to app B that is then
* passed to C, we call app A accessor, app B intermediary, and app C
* receiver. If A accesses the data for itself, then it is the accessor
* and the receiver.
* @hide
*/
@TestApi
public static final int ATTRIBUTION_FLAG_RECEIVER = 0x4;
/**
* Attribution chain flag: Specifies that all attribution sources in the chain were trusted.
* Must only be set by system server.
* @hide
*/
public static final int ATTRIBUTION_FLAG_TRUSTED = 0x8;
/**
* No attribution flags.
* @hide
*/
@TestApi
public static final int ATTRIBUTION_FLAGS_NONE = 0x0;
/**
* No attribution chain id.
* @hide
*/
@TestApi
public static final int ATTRIBUTION_CHAIN_ID_NONE = -1;
/** @hide */
@Retention(RetentionPolicy.SOURCE)
@IntDef(flag = true, prefix = { "FLAG_" }, value = {
ATTRIBUTION_FLAG_ACCESSOR,
ATTRIBUTION_FLAG_INTERMEDIARY,
ATTRIBUTION_FLAG_RECEIVER,
ATTRIBUTION_FLAG_TRUSTED
})
public @interface AttributionFlags {}
// These constants are redefined here to work around a metalava limitation/bug where
// @IntDef is not able to see @hide symbols when they are hidden via package hiding:
// frameworks/base/core/java/com/android/internal/package.html
/** @hide */
public static final int SAMPLING_STRATEGY_DEFAULT =
FrameworkStatsLog.RUNTIME_APP_OP_ACCESS__SAMPLING_STRATEGY__DEFAULT;
/** @hide */
public static final int SAMPLING_STRATEGY_UNIFORM =
FrameworkStatsLog.RUNTIME_APP_OP_ACCESS__SAMPLING_STRATEGY__UNIFORM;
/** @hide */
public static final int SAMPLING_STRATEGY_RARELY_USED =
FrameworkStatsLog.RUNTIME_APP_OP_ACCESS__SAMPLING_STRATEGY__RARELY_USED;
/** @hide */
public static final int SAMPLING_STRATEGY_BOOT_TIME_SAMPLING =
FrameworkStatsLog.RUNTIME_APP_OP_ACCESS__SAMPLING_STRATEGY__BOOT_TIME_SAMPLING;
/** @hide */
public static final int SAMPLING_STRATEGY_UNIFORM_OPS =
FrameworkStatsLog.RUNTIME_APP_OP_ACCESS__SAMPLING_STRATEGY__UNIFORM_OPS;
/**
* Strategies used for message sampling
* @hide
*/
@Retention(RetentionPolicy.SOURCE)
@IntDef(prefix = {"SAMPLING_STRATEGY_"}, value = {
SAMPLING_STRATEGY_DEFAULT,
SAMPLING_STRATEGY_UNIFORM,
SAMPLING_STRATEGY_RARELY_USED,
SAMPLING_STRATEGY_BOOT_TIME_SAMPLING,
SAMPLING_STRATEGY_UNIFORM_OPS
})
public @interface SamplingStrategy {}
private static final int UID_STATE_OFFSET = 31;
private static final int FLAGS_MASK = 0xFFFFFFFF;
/**
* Key for a data bucket storing app op state. The bucket
* is composed of the uid state and state flags. This way
* we can query data for given uid state and a set of flags where
* the flags control which type of data to get. For example,
* one can get the ops an app did on behalf of other apps
* while in the background.
*
* @hide
*/
@Retention(RetentionPolicy.SOURCE)
@Target({ElementType.METHOD, ElementType.PARAMETER, ElementType.FIELD})
public @interface DataBucketKey {
}
/** @hide */
public static String keyToString(@DataBucketKey long key) {
final int uidState = extractUidStateFromKey(key);
final int flags = extractFlagsFromKey(key);
return "[" + getUidStateName(uidState) + "-" + flagsToString(flags) + "]";
}
/** @hide */
public static @DataBucketKey long makeKey(@UidState int uidState, @OpFlags int flags) {
return ((long) uidState << UID_STATE_OFFSET) | flags;
}
/** @hide */
public static int extractUidStateFromKey(@DataBucketKey long key) {
return (int) (key >> UID_STATE_OFFSET);
}
/** @hide */
public static int extractFlagsFromKey(@DataBucketKey long key) {
return (int) (key & FLAGS_MASK);
}
/** @hide */
public static String flagsToString(@OpFlags int flags) {
final StringBuilder flagsBuilder = new StringBuilder();
while (flags != 0) {
final int flag = 1 << Integer.numberOfTrailingZeros(flags);
flags &= ~flag;
if (flagsBuilder.length() > 0) {
flagsBuilder.append('|');
}
flagsBuilder.append(getFlagName(flag));
}
return flagsBuilder.toString();
}
// when adding one of these:
// - increment _NUM_OP
// - define an OPSTR_* constant (and mark as @SystemApi if needed)
// - add row to sAppOpInfos
// - add descriptive strings to Settings/res/values/arrays.xml
// - add the op to the appropriate template in AppOpsState.OpsTemplate (settings app)
/** @hide No operation specified. */
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
public static final int OP_NONE = AppProtoEnums.APP_OP_NONE;
/** @hide Access to coarse location information. */
@UnsupportedAppUsage
@TestApi
public static final int OP_COARSE_LOCATION = AppProtoEnums.APP_OP_COARSE_LOCATION;
/** @hide Access to fine location information. */
@UnsupportedAppUsage
public static final int OP_FINE_LOCATION = AppProtoEnums.APP_OP_FINE_LOCATION;
/** @hide Causing GPS to run. */
@UnsupportedAppUsage
public static final int OP_GPS = AppProtoEnums.APP_OP_GPS;
/** @hide */
@UnsupportedAppUsage
public static final int OP_VIBRATE = AppProtoEnums.APP_OP_VIBRATE;
/** @hide */
@UnsupportedAppUsage
public static final int OP_READ_CONTACTS = AppProtoEnums.APP_OP_READ_CONTACTS;
/** @hide */
@UnsupportedAppUsage
public static final int OP_WRITE_CONTACTS = AppProtoEnums.APP_OP_WRITE_CONTACTS;
/** @hide */
@UnsupportedAppUsage
public static final int OP_READ_CALL_LOG = AppProtoEnums.APP_OP_READ_CALL_LOG;
/** @hide */
@UnsupportedAppUsage
public static final int OP_WRITE_CALL_LOG = AppProtoEnums.APP_OP_WRITE_CALL_LOG;
/** @hide */
@UnsupportedAppUsage
public static final int OP_READ_CALENDAR = AppProtoEnums.APP_OP_READ_CALENDAR;
/** @hide */
@UnsupportedAppUsage
public static final int OP_WRITE_CALENDAR = AppProtoEnums.APP_OP_WRITE_CALENDAR;
/** @hide */
@UnsupportedAppUsage
public static final int OP_WIFI_SCAN = AppProtoEnums.APP_OP_WIFI_SCAN;
/** @hide */
@UnsupportedAppUsage
public static final int OP_POST_NOTIFICATION = AppProtoEnums.APP_OP_POST_NOTIFICATION;
/** @hide */
@UnsupportedAppUsage
public static final int OP_NEIGHBORING_CELLS = AppProtoEnums.APP_OP_NEIGHBORING_CELLS;
/** @hide */
@UnsupportedAppUsage
public static final int OP_CALL_PHONE = AppProtoEnums.APP_OP_CALL_PHONE;
/** @hide */
@UnsupportedAppUsage
public static final int OP_READ_SMS = AppProtoEnums.APP_OP_READ_SMS;
/** @hide */
@UnsupportedAppUsage
public static final int OP_WRITE_SMS = AppProtoEnums.APP_OP_WRITE_SMS;
/** @hide */
@UnsupportedAppUsage
public static final int OP_RECEIVE_SMS = AppProtoEnums.APP_OP_RECEIVE_SMS;
/** @hide */
@UnsupportedAppUsage
public static final int OP_RECEIVE_EMERGECY_SMS =
AppProtoEnums.APP_OP_RECEIVE_EMERGENCY_SMS;
/** @hide */
@UnsupportedAppUsage
public static final int OP_RECEIVE_MMS = AppProtoEnums.APP_OP_RECEIVE_MMS;
/** @hide */
@UnsupportedAppUsage
public static final int OP_RECEIVE_WAP_PUSH = AppProtoEnums.APP_OP_RECEIVE_WAP_PUSH;
/** @hide */
@UnsupportedAppUsage
public static final int OP_SEND_SMS = AppProtoEnums.APP_OP_SEND_SMS;
/** @hide */
public static final int OP_MANAGE_ONGOING_CALLS = AppProtoEnums.APP_OP_MANAGE_ONGOING_CALLS;
/** @hide */
@UnsupportedAppUsage
public static final int OP_READ_ICC_SMS = AppProtoEnums.APP_OP_READ_ICC_SMS;
/** @hide */
@UnsupportedAppUsage
public static final int OP_WRITE_ICC_SMS = AppProtoEnums.APP_OP_WRITE_ICC_SMS;
/** @hide */
@UnsupportedAppUsage
public static final int OP_WRITE_SETTINGS = AppProtoEnums.APP_OP_WRITE_SETTINGS;
/** @hide Required to draw on top of other apps. */
@UnsupportedAppUsage
@TestApi
public static final int OP_SYSTEM_ALERT_WINDOW = AppProtoEnums.APP_OP_SYSTEM_ALERT_WINDOW;
/** @hide */
@UnsupportedAppUsage
public static final int OP_ACCESS_NOTIFICATIONS =
AppProtoEnums.APP_OP_ACCESS_NOTIFICATIONS;
/** @hide */
@UnsupportedAppUsage
public static final int OP_CAMERA = AppProtoEnums.APP_OP_CAMERA;
/** @hide */
@UnsupportedAppUsage
@TestApi
public static final int OP_RECORD_AUDIO = AppProtoEnums.APP_OP_RECORD_AUDIO;
/** @hide */
@UnsupportedAppUsage
public static final int OP_PLAY_AUDIO = AppProtoEnums.APP_OP_PLAY_AUDIO;
/** @hide */
@UnsupportedAppUsage
public static final int OP_READ_CLIPBOARD = AppProtoEnums.APP_OP_READ_CLIPBOARD;
/** @hide */
@UnsupportedAppUsage
public static final int OP_WRITE_CLIPBOARD = AppProtoEnums.APP_OP_WRITE_CLIPBOARD;
/** @hide */
@UnsupportedAppUsage
public static final int OP_TAKE_MEDIA_BUTTONS = AppProtoEnums.APP_OP_TAKE_MEDIA_BUTTONS;
/** @hide */
@UnsupportedAppUsage
public static final int OP_TAKE_AUDIO_FOCUS = AppProtoEnums.APP_OP_TAKE_AUDIO_FOCUS;
/** @hide */
@UnsupportedAppUsage
public static final int OP_AUDIO_MASTER_VOLUME = AppProtoEnums.APP_OP_AUDIO_MASTER_VOLUME;
/** @hide */
@UnsupportedAppUsage
public static final int OP_AUDIO_VOICE_VOLUME = AppProtoEnums.APP_OP_AUDIO_VOICE_VOLUME;
/** @hide */
@UnsupportedAppUsage
public static final int OP_AUDIO_RING_VOLUME = AppProtoEnums.APP_OP_AUDIO_RING_VOLUME;
/** @hide */
@UnsupportedAppUsage
public static final int OP_AUDIO_MEDIA_VOLUME = AppProtoEnums.APP_OP_AUDIO_MEDIA_VOLUME;
/** @hide */
@UnsupportedAppUsage
public static final int OP_AUDIO_ALARM_VOLUME = AppProtoEnums.APP_OP_AUDIO_ALARM_VOLUME;
/** @hide */
@UnsupportedAppUsage
public static final int OP_AUDIO_NOTIFICATION_VOLUME =
AppProtoEnums.APP_OP_AUDIO_NOTIFICATION_VOLUME;
/** @hide */
@UnsupportedAppUsage
public static final int OP_AUDIO_BLUETOOTH_VOLUME =
AppProtoEnums.APP_OP_AUDIO_BLUETOOTH_VOLUME;
/** @hide */
@UnsupportedAppUsage
public static final int OP_WAKE_LOCK = AppProtoEnums.APP_OP_WAKE_LOCK;
/** @hide Continually monitoring location data. */
@UnsupportedAppUsage
public static final int OP_MONITOR_LOCATION =
AppProtoEnums.APP_OP_MONITOR_LOCATION;
/** @hide Continually monitoring location data with a relatively high power request. */
@UnsupportedAppUsage
public static final int OP_MONITOR_HIGH_POWER_LOCATION =
AppProtoEnums.APP_OP_MONITOR_HIGH_POWER_LOCATION;
/** @hide Retrieve current usage stats via {@link UsageStatsManager}. */
@UnsupportedAppUsage
public static final int OP_GET_USAGE_STATS = AppProtoEnums.APP_OP_GET_USAGE_STATS;
/** @hide */
@UnsupportedAppUsage
public static final int OP_MUTE_MICROPHONE = AppProtoEnums.APP_OP_MUTE_MICROPHONE;
/** @hide */
@UnsupportedAppUsage
public static final int OP_TOAST_WINDOW = AppProtoEnums.APP_OP_TOAST_WINDOW;
/** @hide Capture the device's display contents and/or audio */
@UnsupportedAppUsage
public static final int OP_PROJECT_MEDIA = AppProtoEnums.APP_OP_PROJECT_MEDIA;
/**
* Start (without additional user intervention) a VPN connection, as used by {@link
* android.net.VpnService} along with as Platform VPN connections, as used by {@link
* android.net.VpnManager}
*
*
This appop is granted to apps that have already been given user consent to start
* VpnService based VPN connections. As this is a superset of OP_ACTIVATE_PLATFORM_VPN, this
* appop also allows the starting of Platform VPNs.
*
* @hide
*/
@UnsupportedAppUsage
public static final int OP_ACTIVATE_VPN = AppProtoEnums.APP_OP_ACTIVATE_VPN;
/** @hide Access the WallpaperManagerAPI to write wallpapers. */
@UnsupportedAppUsage
public static final int OP_WRITE_WALLPAPER = AppProtoEnums.APP_OP_WRITE_WALLPAPER;
/** @hide Received the assist structure from an app. */
@UnsupportedAppUsage
public static final int OP_ASSIST_STRUCTURE = AppProtoEnums.APP_OP_ASSIST_STRUCTURE;
/** @hide Received a screenshot from assist. */
@UnsupportedAppUsage
public static final int OP_ASSIST_SCREENSHOT = AppProtoEnums.APP_OP_ASSIST_SCREENSHOT;
/** @hide Read the phone state. */
@UnsupportedAppUsage
public static final int OP_READ_PHONE_STATE = AppProtoEnums.APP_OP_READ_PHONE_STATE;
/** @hide Add voicemail messages to the voicemail content provider. */
@UnsupportedAppUsage
public static final int OP_ADD_VOICEMAIL = AppProtoEnums.APP_OP_ADD_VOICEMAIL;
/** @hide Access APIs for SIP calling over VOIP or WiFi. */
@UnsupportedAppUsage
public static final int OP_USE_SIP = AppProtoEnums.APP_OP_USE_SIP;
/** @hide Intercept outgoing calls. */
@UnsupportedAppUsage
public static final int OP_PROCESS_OUTGOING_CALLS =
AppProtoEnums.APP_OP_PROCESS_OUTGOING_CALLS;
/** @hide User the fingerprint API. */
@UnsupportedAppUsage
public static final int OP_USE_FINGERPRINT = AppProtoEnums.APP_OP_USE_FINGERPRINT;
/** @hide Access to body sensors such as heart rate, etc. */
@UnsupportedAppUsage
public static final int OP_BODY_SENSORS = AppProtoEnums.APP_OP_BODY_SENSORS;
/** @hide Read previously received cell broadcast messages. */
@UnsupportedAppUsage
public static final int OP_READ_CELL_BROADCASTS = AppProtoEnums.APP_OP_READ_CELL_BROADCASTS;
/** @hide Inject mock location into the system. */
@UnsupportedAppUsage
public static final int OP_MOCK_LOCATION = AppProtoEnums.APP_OP_MOCK_LOCATION;
/** @hide Read external storage. */
@UnsupportedAppUsage
public static final int OP_READ_EXTERNAL_STORAGE = AppProtoEnums.APP_OP_READ_EXTERNAL_STORAGE;
/** @hide Write external storage. */
@UnsupportedAppUsage
public static final int OP_WRITE_EXTERNAL_STORAGE =
AppProtoEnums.APP_OP_WRITE_EXTERNAL_STORAGE;
/** @hide Turned on the screen. */
@UnsupportedAppUsage
public static final int OP_TURN_SCREEN_ON = AppProtoEnums.APP_OP_TURN_SCREEN_ON;
/** @hide Get device accounts. */
@UnsupportedAppUsage
public static final int OP_GET_ACCOUNTS = AppProtoEnums.APP_OP_GET_ACCOUNTS;
/** @hide Control whether an application is allowed to run in the background. */
@UnsupportedAppUsage
public static final int OP_RUN_IN_BACKGROUND =
AppProtoEnums.APP_OP_RUN_IN_BACKGROUND;
/** @hide */
@UnsupportedAppUsage
public static final int OP_AUDIO_ACCESSIBILITY_VOLUME =
AppProtoEnums.APP_OP_AUDIO_ACCESSIBILITY_VOLUME;
/** @hide Read the phone number. */
@UnsupportedAppUsage
public static final int OP_READ_PHONE_NUMBERS = AppProtoEnums.APP_OP_READ_PHONE_NUMBERS;
/** @hide Request package installs through package installer */
@UnsupportedAppUsage
public static final int OP_REQUEST_INSTALL_PACKAGES =
AppProtoEnums.APP_OP_REQUEST_INSTALL_PACKAGES;
/** @hide Enter picture-in-picture. */
@UnsupportedAppUsage
public static final int OP_PICTURE_IN_PICTURE = AppProtoEnums.APP_OP_PICTURE_IN_PICTURE;
/** @hide Instant app start foreground service. */
@UnsupportedAppUsage
public static final int OP_INSTANT_APP_START_FOREGROUND =
AppProtoEnums.APP_OP_INSTANT_APP_START_FOREGROUND;
/** @hide Answer incoming phone calls */
@UnsupportedAppUsage
public static final int OP_ANSWER_PHONE_CALLS = AppProtoEnums.APP_OP_ANSWER_PHONE_CALLS;
/** @hide Run jobs when in background */
@UnsupportedAppUsage
public static final int OP_RUN_ANY_IN_BACKGROUND = AppProtoEnums.APP_OP_RUN_ANY_IN_BACKGROUND;
/** @hide Change Wi-Fi connectivity state */
@UnsupportedAppUsage
public static final int OP_CHANGE_WIFI_STATE = AppProtoEnums.APP_OP_CHANGE_WIFI_STATE;
/** @hide Request package deletion through package installer */
@UnsupportedAppUsage
public static final int OP_REQUEST_DELETE_PACKAGES =
AppProtoEnums.APP_OP_REQUEST_DELETE_PACKAGES;
/** @hide Bind an accessibility service. */
@UnsupportedAppUsage
public static final int OP_BIND_ACCESSIBILITY_SERVICE =
AppProtoEnums.APP_OP_BIND_ACCESSIBILITY_SERVICE;
/** @hide Continue handover of a call from another app */
@UnsupportedAppUsage
public static final int OP_ACCEPT_HANDOVER = AppProtoEnums.APP_OP_ACCEPT_HANDOVER;
/** @hide Create and Manage IPsec Tunnels */
@UnsupportedAppUsage
public static final int OP_MANAGE_IPSEC_TUNNELS = AppProtoEnums.APP_OP_MANAGE_IPSEC_TUNNELS;
/** @hide Any app start foreground service. */
@UnsupportedAppUsage
@TestApi
public static final int OP_START_FOREGROUND = AppProtoEnums.APP_OP_START_FOREGROUND;
/** @hide */
@UnsupportedAppUsage
public static final int OP_BLUETOOTH_SCAN = AppProtoEnums.APP_OP_BLUETOOTH_SCAN;
/** @hide */
public static final int OP_BLUETOOTH_CONNECT = AppProtoEnums.APP_OP_BLUETOOTH_CONNECT;
/** @hide */
public static final int OP_BLUETOOTH_ADVERTISE = AppProtoEnums.APP_OP_BLUETOOTH_ADVERTISE;
/** @hide Use the BiometricPrompt/BiometricManager APIs. */
public static final int OP_USE_BIOMETRIC = AppProtoEnums.APP_OP_USE_BIOMETRIC;
/** @hide Physical activity recognition. */
public static final int OP_ACTIVITY_RECOGNITION = AppProtoEnums.APP_OP_ACTIVITY_RECOGNITION;
/** @hide Financial app sms read. */
public static final int OP_SMS_FINANCIAL_TRANSACTIONS =
AppProtoEnums.APP_OP_SMS_FINANCIAL_TRANSACTIONS;
/** @hide Read media of audio type. */
public static final int OP_READ_MEDIA_AUDIO = AppProtoEnums.APP_OP_READ_MEDIA_AUDIO;
/** @hide Write media of audio type. */
public static final int OP_WRITE_MEDIA_AUDIO = AppProtoEnums.APP_OP_WRITE_MEDIA_AUDIO;
/** @hide Read media of video type. */
public static final int OP_READ_MEDIA_VIDEO = AppProtoEnums.APP_OP_READ_MEDIA_VIDEO;
/** @hide Write media of video type. */
public static final int OP_WRITE_MEDIA_VIDEO = AppProtoEnums.APP_OP_WRITE_MEDIA_VIDEO;
/** @hide Read media of image type. */
public static final int OP_READ_MEDIA_IMAGES = AppProtoEnums.APP_OP_READ_MEDIA_IMAGES;
/** @hide Write media of image type. */
public static final int OP_WRITE_MEDIA_IMAGES = AppProtoEnums.APP_OP_WRITE_MEDIA_IMAGES;
/** @hide Has a legacy (non-isolated) view of storage. */
public static final int OP_LEGACY_STORAGE = AppProtoEnums.APP_OP_LEGACY_STORAGE;
/** @hide Accessing accessibility features */
public static final int OP_ACCESS_ACCESSIBILITY = AppProtoEnums.APP_OP_ACCESS_ACCESSIBILITY;
/** @hide Read the device identifiers (IMEI / MEID, IMSI, SIM / Build serial) */
public static final int OP_READ_DEVICE_IDENTIFIERS =
AppProtoEnums.APP_OP_READ_DEVICE_IDENTIFIERS;
/** @hide Read location metadata from media */
public static final int OP_ACCESS_MEDIA_LOCATION = AppProtoEnums.APP_OP_ACCESS_MEDIA_LOCATION;
/** @hide Query all apps on device, regardless of declarations in the calling app manifest */
public static final int OP_QUERY_ALL_PACKAGES = AppProtoEnums.APP_OP_QUERY_ALL_PACKAGES;
/** @hide Access all external storage */
public static final int OP_MANAGE_EXTERNAL_STORAGE =
AppProtoEnums.APP_OP_MANAGE_EXTERNAL_STORAGE;
/** @hide Communicate cross-profile within the same profile group. */
public static final int OP_INTERACT_ACROSS_PROFILES =
AppProtoEnums.APP_OP_INTERACT_ACROSS_PROFILES;
/**
* Start (without additional user intervention) a Platform VPN connection, as used by {@link
* android.net.VpnManager}
*
*
This appop is granted to apps that have already been given user consent to start Platform
* VPN connections. This appop is insufficient to start VpnService based VPNs; OP_ACTIVATE_VPN
* is needed for that.
*
* @hide
*/
public static final int OP_ACTIVATE_PLATFORM_VPN = AppProtoEnums.APP_OP_ACTIVATE_PLATFORM_VPN;
/** @hide Controls whether or not read logs are available for incremental installations. */
public static final int OP_LOADER_USAGE_STATS = AppProtoEnums.APP_OP_LOADER_USAGE_STATS;
// App op deprecated/removed.
private static final int OP_DEPRECATED_1 = AppProtoEnums.APP_OP_DEPRECATED_1;
/** @hide Auto-revoke app permissions if app is unused for an extended period */
public static final int OP_AUTO_REVOKE_PERMISSIONS_IF_UNUSED =
AppProtoEnums.APP_OP_AUTO_REVOKE_PERMISSIONS_IF_UNUSED;
/**
* Whether {@link #OP_AUTO_REVOKE_PERMISSIONS_IF_UNUSED} is allowed to be changed by
* the installer
*
* @hide
*/
public static final int OP_AUTO_REVOKE_MANAGED_BY_INSTALLER =
AppProtoEnums.APP_OP_AUTO_REVOKE_MANAGED_BY_INSTALLER;
/** @hide */
public static final int OP_NO_ISOLATED_STORAGE = AppProtoEnums.APP_OP_NO_ISOLATED_STORAGE;
/**
* Phone call is using microphone
*
* @hide
*/
public static final int OP_PHONE_CALL_MICROPHONE = AppProtoEnums.APP_OP_PHONE_CALL_MICROPHONE;
/**
* Phone call is using camera
*
* @hide
*/
public static final int OP_PHONE_CALL_CAMERA = AppProtoEnums.APP_OP_PHONE_CALL_CAMERA;
/**
* Audio is being recorded for hotword detection.
*
* @hide
*/
public static final int OP_RECORD_AUDIO_HOTWORD = AppProtoEnums.APP_OP_RECORD_AUDIO_HOTWORD;
/**
* Manage credentials in the system KeyChain.
*
* @hide
*/
public static final int OP_MANAGE_CREDENTIALS = AppProtoEnums.APP_OP_MANAGE_CREDENTIALS;
/** @hide */
public static final int OP_USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER =
AppProtoEnums.APP_OP_USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER;
/**
* App output audio is being recorded
*
* @hide
*/
public static final int OP_RECORD_AUDIO_OUTPUT = AppProtoEnums.APP_OP_RECORD_AUDIO_OUTPUT;
/**
* App can schedule exact alarm to perform timing based background work
*
* @hide
*/
public static final int OP_SCHEDULE_EXACT_ALARM = AppProtoEnums.APP_OP_SCHEDULE_EXACT_ALARM;
/**
* Fine location being accessed by a location source, which is
* a component that already has location data since it is the one
* that produces location, which is it is a data source for
* location data.
*
* @hide
*/
public static final int OP_FINE_LOCATION_SOURCE = AppProtoEnums.APP_OP_FINE_LOCATION_SOURCE;
/**
* Coarse location being accessed by a location source, which is
* a component that already has location data since it is the one
* that produces location, which is it is a data source for
* location data.
*
* @hide
*/
public static final int OP_COARSE_LOCATION_SOURCE = AppProtoEnums.APP_OP_COARSE_LOCATION_SOURCE;
/**
* Allow apps to create the requests to manage the media files without user confirmation.
*
* @see android.Manifest.permission#MANAGE_MEDIA
* @see android.provider.MediaStore#createDeleteRequest(ContentResolver, Collection)
* @see android.provider.MediaStore#createTrashRequest(ContentResolver, Collection, boolean)
* @see android.provider.MediaStore#createWriteRequest(ContentResolver, Collection)
*
* @hide
*/
public static final int OP_MANAGE_MEDIA = AppProtoEnums.APP_OP_MANAGE_MEDIA;
/** @hide */
public static final int OP_UWB_RANGING = AppProtoEnums.APP_OP_UWB_RANGING;
/** @hide */
public static final int OP_NEARBY_WIFI_DEVICES = AppProtoEnums.APP_OP_NEARBY_WIFI_DEVICES;
/**
* Activity recognition being accessed by an activity recognition source, which
* is a component that already has access since it is the one that detects
* activity recognition.
*
* @hide
*/
public static final int OP_ACTIVITY_RECOGNITION_SOURCE =
AppProtoEnums.APP_OP_ACTIVITY_RECOGNITION_SOURCE;
/**
* Incoming phone audio is being recorded
*
* @hide
*/
public static final int OP_RECORD_INCOMING_PHONE_AUDIO =
AppProtoEnums.APP_OP_RECORD_INCOMING_PHONE_AUDIO;
/**
* VPN app establishes a connection through the VpnService API.
*
* @hide
*/
public static final int OP_ESTABLISH_VPN_SERVICE = AppProtoEnums.APP_OP_ESTABLISH_VPN_SERVICE;
/**
* VPN app establishes a connection through the VpnManager API.
*
* @hide
*/
public static final int OP_ESTABLISH_VPN_MANAGER = AppProtoEnums.APP_OP_ESTABLISH_VPN_MANAGER;
/**
* Access restricted settings.
*
* @hide
*/
public static final int OP_ACCESS_RESTRICTED_SETTINGS =
AppProtoEnums.APP_OP_ACCESS_RESTRICTED_SETTINGS;
/**
* Receive microphone audio from an ambient sound detection event
*
* @hide
*/
public static final int OP_RECEIVE_AMBIENT_TRIGGER_AUDIO =
AppProtoEnums.APP_OP_RECEIVE_AMBIENT_TRIGGER_AUDIO;
/**
* Receive audio from near-field mic (ie. TV remote)
* Allows audio recording regardless of sensor privacy state,
* as it is an intentional user interaction: hold-to-talk
*
* @hide
*/
public static final int OP_RECEIVE_EXPLICIT_USER_INTERACTION_AUDIO =
AppProtoEnums.APP_OP_RECEIVE_EXPLICIT_USER_INTERACTION_AUDIO;
/**
* App can schedule user-initiated jobs.
*
* @hide
*/
public static final int OP_RUN_USER_INITIATED_JOBS =
AppProtoEnums.APP_OP_RUN_USER_INITIATED_JOBS;
/**
* Notify apps that they have been granted URI permission photos
*
* @hide
*/
public static final int OP_READ_MEDIA_VISUAL_USER_SELECTED =
AppProtoEnums.APP_OP_READ_MEDIA_VISUAL_USER_SELECTED;
/**
* Prevent an app from being suspended.
*
* Only to be used by the system.
*
* @hide
*/
public static final int OP_SYSTEM_EXEMPT_FROM_SUSPENSION =
AppProtoEnums.APP_OP_SYSTEM_EXEMPT_FROM_SUSPENSION;
/**
* Prevent an app from dismissible notifications. Starting from Android U, notifications with
* the ongoing parameter can be dismissed by a user on an unlocked device. An app with
* this appop will be exempt and cannot be dismissed by a user.
*
* Only to be used by the system.
*
* @hide
*/
public static final int OP_SYSTEM_EXEMPT_FROM_DISMISSIBLE_NOTIFICATIONS =
AppProtoEnums.APP_OP_SYSTEM_EXEMPT_FROM_DISMISSIBLE_NOTIFICATIONS;
/**
* An app op for reading/writing health connect data.
*
* @hide
*/
public static final int OP_READ_WRITE_HEALTH_DATA = AppProtoEnums.APP_OP_READ_WRITE_HEALTH_DATA;
/**
* Use foreground service with the type
* {@link android.content.pm.ServiceInfo#FOREGROUND_SERVICE_TYPE_SPECIAL_USE}.
*
* @hide
*/
public static final int OP_FOREGROUND_SERVICE_SPECIAL_USE =
AppProtoEnums.APP_OP_FOREGROUND_SERVICE_SPECIAL_USE;
/**
* Exempt an app from all power-related restrictions, including app standby and doze.
* In addition, the app will be able to start foreground services from the background, and the
* user will not be able to stop foreground services run by the app.
*
* Only to be used by the system.
*
* @hide
*/
public static final int OP_SYSTEM_EXEMPT_FROM_POWER_RESTRICTIONS =
AppProtoEnums.APP_OP_SYSTEM_EXEMPT_FROM_POWER_RESTRICTIONS;
/**
* Prevent an app from being placed into hibernation.
*
* Only to be used by the system.
*
* @hide
*/
public static final int OP_SYSTEM_EXEMPT_FROM_HIBERNATION =
AppProtoEnums.APP_OP_SYSTEM_EXEMPT_FROM_HIBERNATION;
/**
* Allows an application to start an activity while running in the background.
*
* Only to be used by the system.
*
* @hide
*/
public static final int OP_SYSTEM_EXEMPT_FROM_ACTIVITY_BG_START_RESTRICTION =
AppProtoEnums.APP_OP_SYSTEM_EXEMPT_FROM_ACTIVITY_BG_START_RESTRICTION;
/**
* Allows an application to capture bugreport directly without consent dialog when using the
* bugreporting API on userdebug/eng build.
*
* @hide
*/
public static final int OP_CAPTURE_CONSENTLESS_BUGREPORT_ON_USERDEBUG_BUILD =
AppProtoEnums.APP_OP_CAPTURE_CONSENTLESS_BUGREPORT_ON_USERDEBUG_BUILD;
// App op deprecated/removed.
private static final int OP_DEPRECATED_2 = AppProtoEnums.APP_OP_BODY_SENSORS_WRIST_TEMPERATURE;
/**
* Send an intent to launch instead of posting the notification to the status bar.
*
* @hide
*/
public static final int OP_USE_FULL_SCREEN_INTENT = AppProtoEnums.APP_OP_USE_FULL_SCREEN_INTENT;
/**
* Hides camera indicator for sandboxed detection apps that directly access the service.
*
* @hide
*/
public static final int OP_CAMERA_SANDBOXED =
AppProtoEnums.APP_OP_CAMERA_SANDBOXED;
/**
* Hides microphone indicator for sandboxed detection apps that directly access the service.
*
* @hide
*/
public static final int OP_RECORD_AUDIO_SANDBOXED =
AppProtoEnums.APP_OP_RECORD_AUDIO_SANDBOXED;
/**
* Allows the assistant app to be voice-triggered by detected hotwords from a trusted detection
* service.
*
* @hide
*/
public static final int OP_RECEIVE_SANDBOX_TRIGGER_AUDIO =
AppProtoEnums.APP_OP_RECEIVE_SANDBOX_TRIGGER_AUDIO;
/**
* This op has been deprecated.
*
*/
private static final int OP_DEPRECATED_3 =
AppProtoEnums.APP_OP_RECEIVE_SANDBOXED_DETECTION_TRAINING_DATA;
/**
* Creation of an overlay using accessibility services
*
* @hide
*/
public static final int OP_CREATE_ACCESSIBILITY_OVERLAY =
AppProtoEnums.APP_OP_CREATE_ACCESSIBILITY_OVERLAY;
/**
* Indicate that the user has enabled or disabled mobile data
* @hide
*/
public static final int OP_ENABLE_MOBILE_DATA_BY_USER =
AppProtoEnums.APP_OP_ENABLE_MOBILE_DATA_BY_USER;
/**
* See {@link #OPSTR_MEDIA_ROUTING_CONTROL}.
* @hide
*/
public static final int OP_MEDIA_ROUTING_CONTROL = AppProtoEnums.APP_OP_MEDIA_ROUTING_CONTROL;
/**
* Op code for use by tests to avoid interfering history logs that the wider system might
* trigger.
*
* @hide
*/
public static final int OP_RESERVED_FOR_TESTING = AppProtoEnums.APP_OP_RESERVED_FOR_TESTING;
/**
* Rapid clearing of notifications by a notification listener
*
* @hide
*/
// See b/289080543 for more details
public static final int OP_RAPID_CLEAR_NOTIFICATIONS_BY_LISTENER =
AppProtoEnums.APP_OP_RAPID_CLEAR_NOTIFICATIONS_BY_LISTENER;
/**
* See {@link #OPSTR_READ_SYSTEM_GRAMMATICAL_GENDER}.
* @hide
*/
public static final int OP_READ_SYSTEM_GRAMMATICAL_GENDER =
AppProtoEnums.APP_OP_READ_SYSTEM_GRAMMATICAL_GENDER;
/**
* This app has been removed..
*
* @hide
*/
private static final int OP_DEPRECATED_4 = AppProtoEnums.APP_OP_RUN_BACKUP_JOBS;
/**
* Whether the app has enabled to receive the icon overlay for fetching archived apps.
*
* @hide
*/
public static final int OP_ARCHIVE_ICON_OVERLAY = AppProtoEnums.APP_OP_ARCHIVE_ICON_OVERLAY;
/**
* Whether the app has enabled compatibility support for unarchival.
*
* @hide
*/
public static final int OP_UNARCHIVAL_CONFIRMATION =
AppProtoEnums.APP_OP_UNARCHIVAL_CONFIRMATION;
/**
* Allows an app to access location without the traditional location permissions and while the
* user location setting is off, but only during pre-defined emergency sessions.
*
*
This op is only used for tracking, not for permissions, so it is still the client's
* responsibility to check the {@link Manifest.permission.LOCATION_BYPASS} permission
* appropriately.
*
* @hide
*/
public static final int OP_EMERGENCY_LOCATION = AppProtoEnums.APP_OP_EMERGENCY_LOCATION;
/**
* Allows apps with a NotificationListenerService to receive notifications with sensitive
* information
*
Apps with a NotificationListenerService without this permission will not be able
* to view certain types of sensitive information contained in notifications
* @hide
*/
public static final int OP_RECEIVE_SENSITIVE_NOTIFICATIONS =
AppProtoEnums.APP_OP_RECEIVE_SENSITIVE_NOTIFICATIONS;
/** @hide */
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
public static final int _NUM_OP = 149;
/**
* All app ops represented as strings.
*
* @hide
*/
@Retention(RetentionPolicy.SOURCE)
@StringDef(prefix = { "OPSTR_" }, value = {
OPSTR_COARSE_LOCATION,
OPSTR_FINE_LOCATION,
OPSTR_MONITOR_LOCATION,
OPSTR_MONITOR_HIGH_POWER_LOCATION,
OPSTR_GET_USAGE_STATS,
OPSTR_ACTIVATE_VPN,
OPSTR_READ_CONTACTS,
OPSTR_WRITE_CONTACTS,
OPSTR_READ_CALL_LOG,
OPSTR_WRITE_CALL_LOG,
OPSTR_READ_CALENDAR,
OPSTR_WRITE_CALENDAR,
OPSTR_CALL_PHONE,
OPSTR_READ_SMS,
OPSTR_RECEIVE_SMS,
OPSTR_RECEIVE_MMS,
OPSTR_RECEIVE_WAP_PUSH,
OPSTR_SEND_SMS,
OPSTR_CAMERA,
OPSTR_RECORD_AUDIO,
OPSTR_READ_PHONE_STATE,
OPSTR_ADD_VOICEMAIL,
OPSTR_USE_SIP,
OPSTR_PROCESS_OUTGOING_CALLS,
OPSTR_USE_FINGERPRINT,
OPSTR_BODY_SENSORS,
OPSTR_READ_CELL_BROADCASTS,
OPSTR_MOCK_LOCATION,
OPSTR_READ_EXTERNAL_STORAGE,
OPSTR_WRITE_EXTERNAL_STORAGE,
OPSTR_SYSTEM_ALERT_WINDOW,
OPSTR_WRITE_SETTINGS,
OPSTR_GET_ACCOUNTS,
OPSTR_READ_PHONE_NUMBERS,
OPSTR_PICTURE_IN_PICTURE,
OPSTR_INSTANT_APP_START_FOREGROUND,
OPSTR_ANSWER_PHONE_CALLS,
OPSTR_ACCEPT_HANDOVER,
OPSTR_GPS,
OPSTR_VIBRATE,
OPSTR_WIFI_SCAN,
OPSTR_POST_NOTIFICATION,
OPSTR_NEIGHBORING_CELLS,
OPSTR_WRITE_SMS,
OPSTR_RECEIVE_EMERGENCY_BROADCAST,
OPSTR_READ_ICC_SMS,
OPSTR_WRITE_ICC_SMS,
OPSTR_ACCESS_NOTIFICATIONS,
OPSTR_PLAY_AUDIO,
OPSTR_READ_CLIPBOARD,
OPSTR_WRITE_CLIPBOARD,
OPSTR_TAKE_MEDIA_BUTTONS,
OPSTR_TAKE_AUDIO_FOCUS,
OPSTR_AUDIO_MASTER_VOLUME,
OPSTR_AUDIO_VOICE_VOLUME,
OPSTR_AUDIO_RING_VOLUME,
OPSTR_AUDIO_MEDIA_VOLUME,
OPSTR_AUDIO_ALARM_VOLUME,
OPSTR_AUDIO_NOTIFICATION_VOLUME,
OPSTR_AUDIO_BLUETOOTH_VOLUME,
OPSTR_WAKE_LOCK,
OPSTR_MUTE_MICROPHONE,
OPSTR_TOAST_WINDOW,
OPSTR_PROJECT_MEDIA,
OPSTR_WRITE_WALLPAPER,
OPSTR_ASSIST_STRUCTURE,
OPSTR_ASSIST_SCREENSHOT,
OPSTR_TURN_SCREEN_ON,
OPSTR_RUN_IN_BACKGROUND,
OPSTR_AUDIO_ACCESSIBILITY_VOLUME,
OPSTR_REQUEST_INSTALL_PACKAGES,
OPSTR_RUN_ANY_IN_BACKGROUND,
OPSTR_CHANGE_WIFI_STATE,
OPSTR_REQUEST_DELETE_PACKAGES,
OPSTR_BIND_ACCESSIBILITY_SERVICE,
OPSTR_MANAGE_IPSEC_TUNNELS,
OPSTR_START_FOREGROUND,
OPSTR_BLUETOOTH_SCAN,
OPSTR_BLUETOOTH_CONNECT,
OPSTR_BLUETOOTH_ADVERTISE,
OPSTR_USE_BIOMETRIC,
OPSTR_ACTIVITY_RECOGNITION,
OPSTR_SMS_FINANCIAL_TRANSACTIONS,
OPSTR_READ_MEDIA_AUDIO,
OPSTR_WRITE_MEDIA_AUDIO,
OPSTR_READ_MEDIA_VIDEO,
OPSTR_WRITE_MEDIA_VIDEO,
OPSTR_READ_MEDIA_IMAGES,
OPSTR_WRITE_MEDIA_IMAGES,
OPSTR_LEGACY_STORAGE,
OPSTR_ACCESS_MEDIA_LOCATION,
OPSTR_ACCESS_ACCESSIBILITY,
OPSTR_READ_DEVICE_IDENTIFIERS,
OPSTR_QUERY_ALL_PACKAGES,
OPSTR_MANAGE_EXTERNAL_STORAGE,
OPSTR_AUTO_REVOKE_PERMISSIONS_IF_UNUSED,
OPSTR_AUTO_REVOKE_MANAGED_BY_INSTALLER,
OPSTR_INTERACT_ACROSS_PROFILES,
OPSTR_ACTIVATE_PLATFORM_VPN,
OPSTR_LOADER_USAGE_STATS,
OPSTR_MANAGE_ONGOING_CALLS,
OPSTR_NO_ISOLATED_STORAGE,
OPSTR_PHONE_CALL_MICROPHONE,
OPSTR_PHONE_CALL_CAMERA,
OPSTR_RECORD_AUDIO_HOTWORD,
OPSTR_MANAGE_CREDENTIALS,
OPSTR_USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER,
OPSTR_RECORD_AUDIO_OUTPUT,
OPSTR_SCHEDULE_EXACT_ALARM,
OPSTR_FINE_LOCATION_SOURCE,
OPSTR_COARSE_LOCATION_SOURCE,
OPSTR_MANAGE_MEDIA,
OPSTR_UWB_RANGING,
OPSTR_NEARBY_WIFI_DEVICES,
OPSTR_ACTIVITY_RECOGNITION_SOURCE,
OPSTR_RECORD_INCOMING_PHONE_AUDIO,
OPSTR_ESTABLISH_VPN_SERVICE,
OPSTR_ESTABLISH_VPN_MANAGER,
OPSTR_ACCESS_RESTRICTED_SETTINGS,
OPSTR_RECEIVE_AMBIENT_TRIGGER_AUDIO,
OPSTR_READ_MEDIA_VISUAL_USER_SELECTED,
OPSTR_READ_WRITE_HEALTH_DATA,
OPSTR_RECEIVE_EXPLICIT_USER_INTERACTION_AUDIO,
OPSTR_RUN_USER_INITIATED_JOBS,
OPSTR_SYSTEM_EXEMPT_FROM_SUSPENSION,
OPSTR_SYSTEM_EXEMPT_FROM_DISMISSIBLE_NOTIFICATIONS,
OPSTR_FOREGROUND_SERVICE_SPECIAL_USE,
OPSTR_SYSTEM_EXEMPT_FROM_POWER_RESTRICTIONS,
OPSTR_SYSTEM_EXEMPT_FROM_HIBERNATION,
OPSTR_SYSTEM_EXEMPT_FROM_ACTIVITY_BG_START_RESTRICTION,
OPSTR_CAPTURE_CONSENTLESS_BUGREPORT_ON_USERDEBUG_BUILD,
OPSTR_USE_FULL_SCREEN_INTENT,
OPSTR_CAMERA_SANDBOXED,
OPSTR_RECORD_AUDIO_SANDBOXED,
OPSTR_RECEIVE_SANDBOX_TRIGGER_AUDIO,
OPSTR_CREATE_ACCESSIBILITY_OVERLAY,
OPSTR_MEDIA_ROUTING_CONTROL,
OPSTR_ENABLE_MOBILE_DATA_BY_USER,
OPSTR_RESERVED_FOR_TESTING,
OPSTR_RAPID_CLEAR_NOTIFICATIONS_BY_LISTENER,
OPSTR_ARCHIVE_ICON_OVERLAY,
OPSTR_UNARCHIVAL_CONFIRMATION,
OPSTR_EMERGENCY_LOCATION,
OPSTR_RECEIVE_SENSITIVE_NOTIFICATIONS,
})
public @interface AppOpString {}
/** Access to coarse location information. */
public static final String OPSTR_COARSE_LOCATION = "android:coarse_location";
/** Access to fine location information. */
public static final String OPSTR_FINE_LOCATION =
"android:fine_location";
/** Continually monitoring location data. */
public static final String OPSTR_MONITOR_LOCATION
= "android:monitor_location";
/** Continually monitoring location data with a relatively high power request. */
public static final String OPSTR_MONITOR_HIGH_POWER_LOCATION
= "android:monitor_location_high_power";
/** Access to {@link android.app.usage.UsageStatsManager}. */
public static final String OPSTR_GET_USAGE_STATS
= "android:get_usage_stats";
/** Activate a VPN connection without user intervention. @hide */
@SystemApi
public static final String OPSTR_ACTIVATE_VPN
= "android:activate_vpn";
/** Allows an application to read the user's contacts data. */
public static final String OPSTR_READ_CONTACTS
= "android:read_contacts";
/** Allows an application to write to the user's contacts data. */
public static final String OPSTR_WRITE_CONTACTS
= "android:write_contacts";
/** Allows an application to read the user's call log. */
public static final String OPSTR_READ_CALL_LOG
= "android:read_call_log";
/** Allows an application to write to the user's call log. */
public static final String OPSTR_WRITE_CALL_LOG
= "android:write_call_log";
/** Allows an application to read the user's calendar data. */
public static final String OPSTR_READ_CALENDAR
= "android:read_calendar";
/** Allows an application to write to the user's calendar data. */
public static final String OPSTR_WRITE_CALENDAR
= "android:write_calendar";
/** Allows an application to initiate a phone call. */
public static final String OPSTR_CALL_PHONE
= "android:call_phone";
/** Allows an application to read SMS messages. */
public static final String OPSTR_READ_SMS
= "android:read_sms";
/** Allows an application to receive SMS messages. */
public static final String OPSTR_RECEIVE_SMS
= "android:receive_sms";
/** Allows an application to receive MMS messages. */
public static final String OPSTR_RECEIVE_MMS
= "android:receive_mms";
/** Allows an application to receive WAP push messages. */
public static final String OPSTR_RECEIVE_WAP_PUSH
= "android:receive_wap_push";
/** Allows an application to send SMS messages. */
public static final String OPSTR_SEND_SMS
= "android:send_sms";
/** Required to be able to access the camera device. */
public static final String OPSTR_CAMERA
= "android:camera";
/** Required to be able to access the microphone device. */
public static final String OPSTR_RECORD_AUDIO
= "android:record_audio";
/** Required to access phone state related information. */
public static final String OPSTR_READ_PHONE_STATE
= "android:read_phone_state";
/** Required to access phone state related information. */
public static final String OPSTR_ADD_VOICEMAIL
= "android:add_voicemail";
/** Access APIs for SIP calling over VOIP or WiFi */
public static final String OPSTR_USE_SIP
= "android:use_sip";
/** Access APIs for diverting outgoing calls */
public static final String OPSTR_PROCESS_OUTGOING_CALLS
= "android:process_outgoing_calls";
/** Use the fingerprint API. */
public static final String OPSTR_USE_FINGERPRINT
= "android:use_fingerprint";
/** Access to body sensors such as heart rate, etc. */
public static final String OPSTR_BODY_SENSORS
= "android:body_sensors";
/** Read previously received cell broadcast messages. */
public static final String OPSTR_READ_CELL_BROADCASTS
= "android:read_cell_broadcasts";
/** Inject mock location into the system. */
public static final String OPSTR_MOCK_LOCATION
= "android:mock_location";
/** Read external storage. */
public static final String OPSTR_READ_EXTERNAL_STORAGE
= "android:read_external_storage";
/** Write external storage. */
public static final String OPSTR_WRITE_EXTERNAL_STORAGE
= "android:write_external_storage";
/** Required to draw on top of other apps. */
public static final String OPSTR_SYSTEM_ALERT_WINDOW
= "android:system_alert_window";
/** Required to write/modify/update system settings. */
public static final String OPSTR_WRITE_SETTINGS
= "android:write_settings";
/** @hide Get device accounts. */
@SystemApi
public static final String OPSTR_GET_ACCOUNTS
= "android:get_accounts";
public static final String OPSTR_READ_PHONE_NUMBERS
= "android:read_phone_numbers";
/** Access to picture-in-picture. */
public static final String OPSTR_PICTURE_IN_PICTURE
= "android:picture_in_picture";
/** @hide */
@SystemApi
public static final String OPSTR_INSTANT_APP_START_FOREGROUND
= "android:instant_app_start_foreground";
/** Answer incoming phone calls */
public static final String OPSTR_ANSWER_PHONE_CALLS
= "android:answer_phone_calls";
/**
* Accept call handover
* @hide
*/
@SystemApi
public static final String OPSTR_ACCEPT_HANDOVER
= "android:accept_handover";
/** @hide */
@SystemApi
public static final String OPSTR_GPS = "android:gps";
/** @hide */
@SystemApi
public static final String OPSTR_VIBRATE = "android:vibrate";
/** @hide */
@SystemApi
public static final String OPSTR_WIFI_SCAN = "android:wifi_scan";
/** @hide */
@SystemApi
public static final String OPSTR_POST_NOTIFICATION = "android:post_notification";
/** @hide */
@SystemApi
public static final String OPSTR_NEIGHBORING_CELLS = "android:neighboring_cells";
/** @hide */
@SystemApi
public static final String OPSTR_WRITE_SMS = "android:write_sms";
/** @hide */
@SystemApi
public static final String OPSTR_RECEIVE_EMERGENCY_BROADCAST =
"android:receive_emergency_broadcast";
/** @hide */
@SystemApi
public static final String OPSTR_READ_ICC_SMS = "android:read_icc_sms";
/** @hide */
@SystemApi
public static final String OPSTR_WRITE_ICC_SMS = "android:write_icc_sms";
/** @hide */
@SystemApi
public static final String OPSTR_ACCESS_NOTIFICATIONS = "android:access_notifications";
/** @hide */
@SystemApi
public static final String OPSTR_PLAY_AUDIO = "android:play_audio";
/** @hide */
@SystemApi
public static final String OPSTR_READ_CLIPBOARD = "android:read_clipboard";
/** @hide */
@SystemApi
public static final String OPSTR_WRITE_CLIPBOARD = "android:write_clipboard";
/** @hide */
@SystemApi
public static final String OPSTR_TAKE_MEDIA_BUTTONS = "android:take_media_buttons";
/** @hide */
@SystemApi
public static final String OPSTR_TAKE_AUDIO_FOCUS = "android:take_audio_focus";
/** @hide */
@SystemApi
public static final String OPSTR_AUDIO_MASTER_VOLUME = "android:audio_master_volume";
/** @hide */
@SystemApi
public static final String OPSTR_AUDIO_VOICE_VOLUME = "android:audio_voice_volume";
/** @hide */
@SystemApi
public static final String OPSTR_AUDIO_RING_VOLUME = "android:audio_ring_volume";
/** @hide */
@SystemApi
public static final String OPSTR_AUDIO_MEDIA_VOLUME = "android:audio_media_volume";
/** @hide */
@SystemApi
public static final String OPSTR_AUDIO_ALARM_VOLUME = "android:audio_alarm_volume";
/** @hide */
@SystemApi
public static final String OPSTR_AUDIO_NOTIFICATION_VOLUME =
"android:audio_notification_volume";
/** @hide */
@SystemApi
public static final String OPSTR_AUDIO_BLUETOOTH_VOLUME = "android:audio_bluetooth_volume";
/** @hide */
@SystemApi
public static final String OPSTR_WAKE_LOCK = "android:wake_lock";
/** @hide */
@SystemApi
public static final String OPSTR_MUTE_MICROPHONE = "android:mute_microphone";
/** @hide */
@SystemApi
public static final String OPSTR_TOAST_WINDOW = "android:toast_window";
/** @hide */
@SystemApi
public static final String OPSTR_PROJECT_MEDIA = "android:project_media";
/** @hide */
@SystemApi
public static final String OPSTR_WRITE_WALLPAPER = "android:write_wallpaper";
/** @hide */
@SystemApi
public static final String OPSTR_ASSIST_STRUCTURE = "android:assist_structure";
/** @hide */
@SystemApi
public static final String OPSTR_ASSIST_SCREENSHOT = "android:assist_screenshot";
/** @hide */
@SystemApi
public static final String OPSTR_TURN_SCREEN_ON = "android:turn_screen_on";
/** @hide */
@SystemApi
public static final String OPSTR_RUN_IN_BACKGROUND = "android:run_in_background";
/** @hide */
@SystemApi
public static final String OPSTR_AUDIO_ACCESSIBILITY_VOLUME =
"android:audio_accessibility_volume";
/** @hide */
@SystemApi
public static final String OPSTR_REQUEST_INSTALL_PACKAGES = "android:request_install_packages";
/** @hide */
@SystemApi
public static final String OPSTR_RUN_ANY_IN_BACKGROUND = "android:run_any_in_background";
/** @hide */
@SystemApi
public static final String OPSTR_CHANGE_WIFI_STATE = "android:change_wifi_state";
/** @hide */
@SystemApi
public static final String OPSTR_REQUEST_DELETE_PACKAGES = "android:request_delete_packages";
/** @hide */
@SystemApi
public static final String OPSTR_BIND_ACCESSIBILITY_SERVICE =
"android:bind_accessibility_service";
/** @hide */
@SystemApi
public static final String OPSTR_MANAGE_IPSEC_TUNNELS = "android:manage_ipsec_tunnels";
/** @hide */
@SystemApi
public static final String OPSTR_START_FOREGROUND = "android:start_foreground";
/** @hide */
public static final String OPSTR_BLUETOOTH_SCAN = "android:bluetooth_scan";
/** @hide */
public static final String OPSTR_BLUETOOTH_CONNECT = "android:bluetooth_connect";
/** @hide */
public static final String OPSTR_BLUETOOTH_ADVERTISE = "android:bluetooth_advertise";
/** @hide Use the BiometricPrompt/BiometricManager APIs. */
public static final String OPSTR_USE_BIOMETRIC = "android:use_biometric";
/** @hide Recognize physical activity. */
@TestApi
public static final String OPSTR_ACTIVITY_RECOGNITION = "android:activity_recognition";
/** @hide Financial app read sms. */
public static final String OPSTR_SMS_FINANCIAL_TRANSACTIONS =
"android:sms_financial_transactions";
/** @hide Read media of audio type. */
@SystemApi
public static final String OPSTR_READ_MEDIA_AUDIO = "android:read_media_audio";
/** @hide Write media of audio type. */
@SystemApi
public static final String OPSTR_WRITE_MEDIA_AUDIO = "android:write_media_audio";
/** @hide Read media of video type. */
@SystemApi
public static final String OPSTR_READ_MEDIA_VIDEO = "android:read_media_video";
/** @hide Write media of video type. */
@SystemApi
public static final String OPSTR_WRITE_MEDIA_VIDEO = "android:write_media_video";
/** @hide Read media of image type. */
@SystemApi
public static final String OPSTR_READ_MEDIA_IMAGES = "android:read_media_images";
/** @hide Write media of image type. */
@SystemApi
public static final String OPSTR_WRITE_MEDIA_IMAGES = "android:write_media_images";
/** @hide Has a legacy (non-isolated) view of storage. */
@SystemApi
public static final String OPSTR_LEGACY_STORAGE = "android:legacy_storage";
/** @hide Read location metadata from media */
public static final String OPSTR_ACCESS_MEDIA_LOCATION = "android:access_media_location";
/** @hide Interact with accessibility. */
@SystemApi
public static final String OPSTR_ACCESS_ACCESSIBILITY = "android:access_accessibility";
/** @hide Read device identifiers */
public static final String OPSTR_READ_DEVICE_IDENTIFIERS = "android:read_device_identifiers";
/** @hide Query all packages on device */
public static final String OPSTR_QUERY_ALL_PACKAGES = "android:query_all_packages";
/** @hide Access all external storage */
@SystemApi
public static final String OPSTR_MANAGE_EXTERNAL_STORAGE =
"android:manage_external_storage";
/** @hide Auto-revoke app permissions if app is unused for an extended period */
@SystemApi
public static final String OPSTR_AUTO_REVOKE_PERMISSIONS_IF_UNUSED =
"android:auto_revoke_permissions_if_unused";
/** @hide Auto-revoke app permissions if app is unused for an extended period */
@SystemApi
public static final String OPSTR_AUTO_REVOKE_MANAGED_BY_INSTALLER =
"android:auto_revoke_managed_by_installer";
/** @hide Communicate cross-profile within the same profile group. */
@SystemApi
public static final String OPSTR_INTERACT_ACROSS_PROFILES = "android:interact_across_profiles";
/** @hide Start Platform VPN without user intervention */
@SystemApi
public static final String OPSTR_ACTIVATE_PLATFORM_VPN = "android:activate_platform_vpn";
/** @hide */
@SystemApi
public static final String OPSTR_LOADER_USAGE_STATS = "android:loader_usage_stats";
/**
* Grants an app access to the {@link android.telecom.InCallService} API to see
* information about ongoing calls and to enable control of calls.
* @hide
*/
@SystemApi
@TestApi
public static final String OPSTR_MANAGE_ONGOING_CALLS = "android:manage_ongoing_calls";
/**
* Allows apps holding this permission to control the routing of other apps via {@link
* MediaRouter2}.
*
*
For example, holding this permission allows watches (via companion apps) to control the
* routing of applications running on the phone.
*
* @hide
*/
@SystemApi
@FlaggedApi(com.android.media.flags.Flags
.FLAG_ENABLE_PRIVILEGED_ROUTING_FOR_MEDIA_ROUTING_CONTROL)
public static final String OPSTR_MEDIA_ROUTING_CONTROL = "android:media_routing_control";
/**
* Whether the app has enabled to receive the icon overlay for fetching archived apps.
*
* @hide
*/
public static final String OPSTR_ARCHIVE_ICON_OVERLAY = "android:archive_icon_overlay";
/**
* Whether the app has enabled compatibility support for unarchival.
*
* @hide
*/
public static final String OPSTR_UNARCHIVAL_CONFIRMATION = "android:unarchival_support";
/**
* AppOp granted to apps that we are started via {@code am instrument -e --no-isolated-storage}
*
*
MediaProvider is the only component (outside of system server) that should care about this
* app op, hence {@code SystemApi.Client.MODULE_LIBRARIES}.
*
* @hide
*/
@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
public static final String OPSTR_NO_ISOLATED_STORAGE = "android:no_isolated_storage";
/**
* Phone call is using microphone
*
* @hide
*/
@SystemApi
public static final String OPSTR_PHONE_CALL_MICROPHONE = "android:phone_call_microphone";
/**
* Phone call is using camera
*
* @hide
*/
@SystemApi
public static final String OPSTR_PHONE_CALL_CAMERA = "android:phone_call_camera";
/**
* Audio is being recorded for hotword detection.
*
* @hide
*/
@TestApi
public static final String OPSTR_RECORD_AUDIO_HOTWORD = "android:record_audio_hotword";
/**
* Manage credentials in the system KeyChain.
*
* @hide
*/
public static final String OPSTR_MANAGE_CREDENTIALS = "android:manage_credentials";
/**
* Allows to read device identifiers and use ICC based authentication like EAP-AKA.
*
* @hide
*/
@TestApi
public static final String OPSTR_USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER =
"android:use_icc_auth_with_device_identifier";
/**
* App output audio is being recorded
*
* @hide
*/
public static final String OPSTR_RECORD_AUDIO_OUTPUT = "android:record_audio_output";
/**
* App can schedule exact alarm to perform timing based background work.
*
* @hide
*/
public static final String OPSTR_SCHEDULE_EXACT_ALARM = "android:schedule_exact_alarm";
/**
* Fine location being accessed by a location source, which is
* a component that already has location since it is the one that
* produces location.
*
* @hide
*/
public static final String OPSTR_FINE_LOCATION_SOURCE = "android:fine_location_source";
/**
* Coarse location being accessed by a location source, which is
* a component that already has location since it is the one that
* produces location.
*
* @hide
*/
public static final String OPSTR_COARSE_LOCATION_SOURCE = "android:coarse_location_source";
/**
* Camera is being recorded in sandboxed detection process.
*
* @hide
*/
public static final String OPSTR_CAMERA_SANDBOXED = "android:camera_sandboxed";
/**
* Audio is being recorded in sandboxed detection process.
*
* @hide
*/
public static final String OPSTR_RECORD_AUDIO_SANDBOXED = "android:record_audio_sandboxed";
/**
* Allow apps to create the requests to manage the media files without user confirmation.
*
* @see android.Manifest.permission#MANAGE_MEDIA
* @see android.provider.MediaStore#createDeleteRequest(ContentResolver, Collection)
* @see android.provider.MediaStore#createTrashRequest(ContentResolver, Collection, boolean)
* @see android.provider.MediaStore#createWriteRequest(ContentResolver, Collection)
*
* @hide
*/
public static final String OPSTR_MANAGE_MEDIA = "android:manage_media";
/** @hide */
public static final String OPSTR_UWB_RANGING = "android:uwb_ranging";
/** @hide */
public static final String OPSTR_NEARBY_WIFI_DEVICES = "android:nearby_wifi_devices";
/**
* Activity recognition being accessed by an activity recognition source, which
* is a component that already has access since it is the one that detects
* activity recognition.
*
* @hide
*/
@TestApi
public static final String OPSTR_ACTIVITY_RECOGNITION_SOURCE =
"android:activity_recognition_source";
/**
* @hide
*/
public static final String OPSTR_RECORD_INCOMING_PHONE_AUDIO =
"android:record_incoming_phone_audio";
/**
* VPN app establishes a connection through the VpnService API.
*
* @hide
*/
@SystemApi
public static final String OPSTR_ESTABLISH_VPN_SERVICE = "android:establish_vpn_service";
/**
* VPN app establishes a connection through the VpnManager API.
*
* @hide
*/
@SystemApi
public static final String OPSTR_ESTABLISH_VPN_MANAGER = "android:establish_vpn_manager";
/**
* Limit user accessing restricted settings.
*
* @hide
*/
@FlaggedApi(Flags.FLAG_ENHANCED_CONFIRMATION_MODE_APIS_ENABLED)
@SystemApi
public static final String OPSTR_ACCESS_RESTRICTED_SETTINGS =
"android:access_restricted_settings";
/**
* Receive microphone audio from an ambient sound detection event
*
* @hide
*/
@SystemApi
public static final String OPSTR_RECEIVE_AMBIENT_TRIGGER_AUDIO =
"android:receive_ambient_trigger_audio";
/**
* Notify apps that they have been granted URI permission photos
*
* @hide
*/
@SystemApi
public static final String OPSTR_READ_MEDIA_VISUAL_USER_SELECTED =
"android:read_media_visual_user_selected";
/**
* An app op for reading/writing health connect data.
*
* @hide
*/
@SystemApi
public static final String OPSTR_READ_WRITE_HEALTH_DATA =
"android:read_write_health_data";
/**
* Record audio from near-field microphone (ie. TV remote)
* Allows audio recording regardless of sensor privacy state,
* as it is an intentional user interaction: hold-to-talk
*
* @hide
*/
@SystemApi
@SuppressLint("IntentName")
public static final String OPSTR_RECEIVE_EXPLICIT_USER_INTERACTION_AUDIO =
"android:receive_explicit_user_interaction_audio";
/**
* App can schedule user-initiated jobs.
*
* @hide
*/
public static final String OPSTR_RUN_USER_INITIATED_JOBS = "android:run_user_initiated_jobs";
/**
* Prevent an app from being suspended.
*
* Only to be used by the system.
*
* @hide
*/
public static final String OPSTR_SYSTEM_EXEMPT_FROM_SUSPENSION =
"android:system_exempt_from_suspension";
/**
* Allow an application to create non-dismissible notifications. Starting from Android U,
* notifications with the ongoing parameter can be dismissed by a user on an unlocked device
* unless the application that created the notification is exempt.
* An application with this appop will be made exempt.
*
* Only to be used by the system.
*
* @hide
*/
public static final String OPSTR_SYSTEM_EXEMPT_FROM_DISMISSIBLE_NOTIFICATIONS =
"android:system_exempt_from_dismissible_notifications";
/**
* Start a foreground service with the type "specialUse".
*
* @hide
*/
public static final String OPSTR_FOREGROUND_SERVICE_SPECIAL_USE =
"android:foreground_service_special_use";
/**
* Exempt an app from all power-related restrictions, including app standby and doze.
* In addition, the app will be able to start foreground services from the background, and the
* user will not be able to stop foreground services run by the app.
*
* Only to be used by the system.
*
* @hide
*/
public static final String OPSTR_SYSTEM_EXEMPT_FROM_POWER_RESTRICTIONS =
"android:system_exempt_from_power_restrictions";
/**
* Prevent an app from being placed into hibernation.
*
* Only to be used by the system.
*
* @hide
*/
@SystemApi
public static final String OPSTR_SYSTEM_EXEMPT_FROM_HIBERNATION =
"android:system_exempt_from_hibernation";
/**
* Allows an application to start an activity while running in the background.
*
* Only to be used by the system.
*
* @hide
*/
public static final String OPSTR_SYSTEM_EXEMPT_FROM_ACTIVITY_BG_START_RESTRICTION =
"android:system_exempt_from_activity_bg_start_restriction";
/**
* Allows an application to capture bugreport directly without consent dialog when using the
* bugreporting API on userdebug/eng build.
*
* @hide
*/
@SystemApi
public static final String OPSTR_CAPTURE_CONSENTLESS_BUGREPORT_ON_USERDEBUG_BUILD =
"android:capture_consentless_bugreport_on_userdebug_build";
/**
* App op deprecated/removed.
* @hide
*/
public static final String OPSTR_DEPRECATED_2 = "android:deprecated_2";
/**
* Send an intent to launch instead of posting the notification to the status bar.
*
* @hide
*/
public static final String OPSTR_USE_FULL_SCREEN_INTENT = "android:use_full_screen_intent";
/**
* Allows the assistant app to be voice-triggered by detected hotwords from a trusted detection
* service.
*
* @hide
*/
public static final String OPSTR_RECEIVE_SANDBOX_TRIGGER_AUDIO =
"android:receive_sandbox_trigger_audio";
/**
* App op has been deprecated.
* @hide
*/
public static final String OPSTR_DEPRECATED_3 = "android:deprecated_3";
/**
* Creation of an overlay using accessibility services
*
* @hide
*/
@SystemApi
@FlaggedApi(FLAG_CREATE_ACCESSIBILITY_OVERLAY_APP_OP_ENABLED)
public static final String OPSTR_CREATE_ACCESSIBILITY_OVERLAY =
"android:create_accessibility_overlay";
/**
* Indicate that the user has enabled or disabled mobile data
* @hide
*/
@SystemApi
@FlaggedApi(FLAG_OP_ENABLE_MOBILE_DATA_BY_USER)
public static final String OPSTR_ENABLE_MOBILE_DATA_BY_USER =
"android:enable_mobile_data_by_user";
/**
* Reserved for use by appop tests so that operations done legitimately by the platform don't
* interfere with expected results. Platform code should never use this.
*
* @hide
*/
@TestApi
@SuppressLint("UnflaggedApi")
public static final String OPSTR_RESERVED_FOR_TESTING =
"android:reserved_for_testing";
/**
* Rapid clearing of notifications by a notification listener
*
* @hide
*/
// See b/289080543 for more details
@SystemApi
@FlaggedApi(FLAG_RAPID_CLEAR_NOTIFICATIONS_BY_LISTENER_APP_OP_ENABLED)
public static final String OPSTR_RAPID_CLEAR_NOTIFICATIONS_BY_LISTENER =
"android:rapid_clear_notifications_by_listener";
/**
* Allows an application to read the system grammatical gender.
*
* @hide
*/
public static final String OPSTR_READ_SYSTEM_GRAMMATICAL_GENDER =
"android:read_system_grammatical_gender";
/**
* App op has been removed.
*
* @hide
*/
public static final String OPSTR_DEPRECATED_4 = "android:deprecated_4";
/**
* Allows an app to access location without the traditional location permissions and while the
* user location setting is off, but only during pre-defined emergency sessions.
*
*
This op is only used for tracking, not for permissions, so it is still the client's
* responsibility to check the {@link Manifest.permission.LOCATION_BYPASS} permission
* appropriately.
*
* @hide
*/
@SystemApi
@FlaggedApi(FLAG_LOCATION_BYPASS)
public static final String OPSTR_EMERGENCY_LOCATION = "android:emergency_location";
/**
* Allows apps with a NotificationListenerService to receive notifications with sensitive
* information
*
Apps with a NotificationListenerService without this permission will not be able
* to view certain types of sensitive information contained in notifications
* @hide
*/
@TestApi
@FlaggedApi(FLAG_REDACT_SENSITIVE_NOTIFICATIONS_FROM_UNTRUSTED_LISTENERS)
public static final String OPSTR_RECEIVE_SENSITIVE_NOTIFICATIONS =
"android:receive_sensitive_notifications";
/** {@link #sAppOpsToNote} not initialized yet for this op */
private static final byte SHOULD_COLLECT_NOTE_OP_NOT_INITIALIZED = 0;
/** Should not collect noting of this app-op in {@link #sAppOpsToNote} */
private static final byte SHOULD_NOT_COLLECT_NOTE_OP = 1;
/** Should collect noting of this app-op in {@link #sAppOpsToNote} */
private static final byte SHOULD_COLLECT_NOTE_OP = 2;
@Retention(RetentionPolicy.SOURCE)
@IntDef(flag = true, prefix = { "SHOULD_" }, value = {
SHOULD_COLLECT_NOTE_OP_NOT_INITIALIZED,
SHOULD_NOT_COLLECT_NOTE_OP,
SHOULD_COLLECT_NOTE_OP
})
private @interface ShouldCollectNoteOp {}
/** Whether noting for an appop should be collected */
private static final @ShouldCollectNoteOp byte[] sAppOpsToNote = new byte[_NUM_OP];
private static final int[] RUNTIME_PERMISSION_OPS = {
// Contacts
OP_READ_CONTACTS,
OP_WRITE_CONTACTS,
OP_GET_ACCOUNTS,
// Calendar
OP_READ_CALENDAR,
OP_WRITE_CALENDAR,
// SMS
OP_SEND_SMS,
OP_RECEIVE_SMS,
OP_READ_SMS,
OP_RECEIVE_WAP_PUSH,
OP_RECEIVE_MMS,
OP_READ_CELL_BROADCASTS,
// Storage
OP_READ_EXTERNAL_STORAGE,
OP_WRITE_EXTERNAL_STORAGE,
OP_ACCESS_MEDIA_LOCATION,
// Location
OP_COARSE_LOCATION,
OP_FINE_LOCATION,
// Phone
OP_READ_PHONE_STATE,
OP_READ_PHONE_NUMBERS,
OP_CALL_PHONE,
OP_READ_CALL_LOG,
OP_WRITE_CALL_LOG,
OP_ADD_VOICEMAIL,
OP_USE_SIP,
OP_PROCESS_OUTGOING_CALLS,
OP_ANSWER_PHONE_CALLS,
OP_ACCEPT_HANDOVER,
// Microphone
OP_RECORD_AUDIO,
// Camera
OP_CAMERA,
// Body sensors
OP_BODY_SENSORS,
// Activity recognition
OP_ACTIVITY_RECOGNITION,
// Aural
OP_READ_MEDIA_AUDIO,
// Visual
OP_READ_MEDIA_VIDEO,
OP_READ_MEDIA_IMAGES,
OP_READ_MEDIA_VISUAL_USER_SELECTED,
// Nearby devices
OP_BLUETOOTH_SCAN,
OP_BLUETOOTH_CONNECT,
OP_BLUETOOTH_ADVERTISE,
OP_UWB_RANGING,
OP_NEARBY_WIFI_DEVICES,
// Notifications
OP_POST_NOTIFICATION,
};
/**
* Ops for app op permissions that are setting the per-package mode for certain reasons. Most
* app op permissions should set the per-UID mode instead.
*/
private static final int[] APP_OP_PERMISSION_PACKAGE_OPS = {
OP_ACCESS_NOTIFICATIONS,
OP_SYSTEM_ALERT_WINDOW,
OP_WRITE_SETTINGS,
OP_GET_USAGE_STATS,
OP_REQUEST_INSTALL_PACKAGES,
OP_START_FOREGROUND,
OP_SMS_FINANCIAL_TRANSACTIONS,
OP_MANAGE_IPSEC_TUNNELS,
OP_INSTANT_APP_START_FOREGROUND,
OP_LOADER_USAGE_STATS
};
/**
* Ops for app op permissions that are setting the per-UID mode for certain reasons. This should
* be preferred over the per-package mode for new app op permissions.
*/
private static final int[] APP_OP_PERMISSION_UID_OPS = {
OP_MANAGE_EXTERNAL_STORAGE,
OP_INTERACT_ACROSS_PROFILES,
OP_MANAGE_ONGOING_CALLS,
OP_USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER,
OP_SCHEDULE_EXACT_ALARM,
OP_MANAGE_MEDIA,
OP_TURN_SCREEN_ON,
OP_RUN_USER_INITIATED_JOBS,
OP_FOREGROUND_SERVICE_SPECIAL_USE,
OP_CAPTURE_CONSENTLESS_BUGREPORT_ON_USERDEBUG_BUILD,
OP_USE_FULL_SCREEN_INTENT,
OP_RECEIVE_SANDBOX_TRIGGER_AUDIO,
OP_MEDIA_ROUTING_CONTROL,
OP_READ_SYSTEM_GRAMMATICAL_GENDER,
};
static final AppOpInfo[] sAppOpInfos = new AppOpInfo[]{
new AppOpInfo.Builder(OP_COARSE_LOCATION, OPSTR_COARSE_LOCATION, "COARSE_LOCATION")
.setPermission(android.Manifest.permission.ACCESS_COARSE_LOCATION)
.setRestriction(UserManager.DISALLOW_SHARE_LOCATION)
.setAllowSystemRestrictionBypass(new RestrictionBypass(true, false, false))
.setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_FINE_LOCATION, OPSTR_FINE_LOCATION, "FINE_LOCATION")
.setPermission(android.Manifest.permission.ACCESS_FINE_LOCATION)
.setRestriction(UserManager.DISALLOW_SHARE_LOCATION)
.setAllowSystemRestrictionBypass(new RestrictionBypass(true, false, false))
.setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_GPS, OPSTR_GPS, "GPS")
.setSwitchCode(OP_COARSE_LOCATION)
.setRestriction(UserManager.DISALLOW_SHARE_LOCATION)
.setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_VIBRATE, OPSTR_VIBRATE, "VIBRATE")
.setSwitchCode(OP_VIBRATE).setPermission(android.Manifest.permission.VIBRATE)
.setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_READ_CONTACTS, OPSTR_READ_CONTACTS, "READ_CONTACTS")
.setPermission(android.Manifest.permission.READ_CONTACTS)
.setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_WRITE_CONTACTS, OPSTR_WRITE_CONTACTS, "WRITE_CONTACTS")
.setPermission(android.Manifest.permission.WRITE_CONTACTS)
.setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_READ_CALL_LOG, OPSTR_READ_CALL_LOG, "READ_CALL_LOG")
.setPermission(android.Manifest.permission.READ_CALL_LOG)
.setRestriction(UserManager.DISALLOW_OUTGOING_CALLS)
.setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_WRITE_CALL_LOG, OPSTR_WRITE_CALL_LOG, "WRITE_CALL_LOG")
.setPermission(android.Manifest.permission.WRITE_CALL_LOG)
.setRestriction(UserManager.DISALLOW_OUTGOING_CALLS)
.setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_READ_CALENDAR, OPSTR_READ_CALENDAR, "READ_CALENDAR")
.setPermission(android.Manifest.permission.READ_CALENDAR)
.setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_WRITE_CALENDAR, OPSTR_WRITE_CALENDAR, "WRITE_CALENDAR")
.setPermission(android.Manifest.permission.WRITE_CALENDAR)
.setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_WIFI_SCAN, OPSTR_WIFI_SCAN, "WIFI_SCAN")
.setSwitchCode(OP_COARSE_LOCATION)
.setPermission(android.Manifest.permission.ACCESS_WIFI_STATE)
.setRestriction(UserManager.DISALLOW_SHARE_LOCATION)
.setAllowSystemRestrictionBypass(new RestrictionBypass(false, true, false))
.setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_POST_NOTIFICATION, OPSTR_POST_NOTIFICATION, "POST_NOTIFICATION")
.setPermission(android.Manifest.permission.POST_NOTIFICATIONS)
.setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_NEIGHBORING_CELLS, OPSTR_NEIGHBORING_CELLS, "NEIGHBORING_CELLS")
.setSwitchCode(OP_COARSE_LOCATION).setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_CALL_PHONE, OPSTR_CALL_PHONE, "CALL_PHONE")
.setSwitchCode(OP_CALL_PHONE).setPermission(android.Manifest.permission.CALL_PHONE)
.setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_READ_SMS, OPSTR_READ_SMS, "READ_SMS")
.setPermission(android.Manifest.permission.READ_SMS)
.setRestriction(UserManager.DISALLOW_SMS).setDefaultMode(AppOpsManager.MODE_ALLOWED)
.setDisableReset(true).build(),
new AppOpInfo.Builder(OP_WRITE_SMS, OPSTR_WRITE_SMS, "WRITE_SMS")
.setRestriction(UserManager.DISALLOW_SMS)
.setDefaultMode(AppOpsManager.MODE_IGNORED).setDisableReset(true).build(),
new AppOpInfo.Builder(OP_RECEIVE_SMS, OPSTR_RECEIVE_SMS, "RECEIVE_SMS")
.setPermission(android.Manifest.permission.RECEIVE_SMS)
.setRestriction(UserManager.DISALLOW_SMS)
.setDefaultMode(AppOpsManager.MODE_ALLOWED).setDisableReset(true).build(),
new AppOpInfo.Builder(OP_RECEIVE_EMERGECY_SMS, OPSTR_RECEIVE_EMERGENCY_BROADCAST,
"RECEIVE_EMERGENCY_BROADCAST").setSwitchCode(OP_RECEIVE_SMS)
.setPermission(android.Manifest.permission.RECEIVE_EMERGENCY_BROADCAST)
.setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_RECEIVE_MMS, OPSTR_RECEIVE_MMS, "RECEIVE_MMS")
.setPermission(android.Manifest.permission.RECEIVE_MMS)
.setRestriction(UserManager.DISALLOW_SMS).setDefaultMode(AppOpsManager.MODE_ALLOWED)
.build(),
new AppOpInfo.Builder(OP_RECEIVE_WAP_PUSH, OPSTR_RECEIVE_WAP_PUSH, "RECEIVE_WAP_PUSH")
.setPermission(android.Manifest.permission.RECEIVE_WAP_PUSH)
.setDefaultMode(AppOpsManager.MODE_ALLOWED).setDisableReset(true).build(),
new AppOpInfo.Builder(OP_SEND_SMS, OPSTR_SEND_SMS, "SEND_SMS")
.setPermission(android.Manifest.permission.SEND_SMS)
.setRestriction(UserManager.DISALLOW_SMS).setDefaultMode(AppOpsManager.MODE_ALLOWED)
.setDisableReset(true).build(),
new AppOpInfo.Builder(OP_READ_ICC_SMS, OPSTR_READ_ICC_SMS, "READ_ICC_SMS")
.setSwitchCode(OP_READ_SMS).setPermission(android.Manifest.permission.READ_SMS)
.setRestriction(UserManager.DISALLOW_SMS).setDefaultMode(AppOpsManager.MODE_ALLOWED)
.build(),
new AppOpInfo.Builder(OP_WRITE_ICC_SMS, OPSTR_WRITE_ICC_SMS, "WRITE_ICC_SMS")
.setSwitchCode(OP_WRITE_SMS).setRestriction(UserManager.DISALLOW_SMS)
.setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_WRITE_SETTINGS, OPSTR_WRITE_SETTINGS, "WRITE_SETTINGS")
.setPermission(android.Manifest.permission.WRITE_SETTINGS).build(),
new AppOpInfo.Builder(OP_SYSTEM_ALERT_WINDOW, OPSTR_SYSTEM_ALERT_WINDOW,
"SYSTEM_ALERT_WINDOW")
.setPermission(android.Manifest.permission.SYSTEM_ALERT_WINDOW)
.setRestriction(UserManager.DISALLOW_CREATE_WINDOWS)
.setAllowSystemRestrictionBypass(new RestrictionBypass(false, true, false))
.setDefaultMode(getSystemAlertWindowDefault()).build(),
new AppOpInfo.Builder(OP_ACCESS_NOTIFICATIONS, OPSTR_ACCESS_NOTIFICATIONS,
"ACCESS_NOTIFICATIONS")
.setPermission(android.Manifest.permission.ACCESS_NOTIFICATIONS).build(),
new AppOpInfo.Builder(OP_CAMERA, OPSTR_CAMERA, "CAMERA")
.setPermission(android.Manifest.permission.CAMERA)
.setRestriction(UserManager.DISALLOW_CAMERA)
.setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_RECORD_AUDIO, OPSTR_RECORD_AUDIO, "RECORD_AUDIO")
.setPermission(android.Manifest.permission.RECORD_AUDIO)
.setRestriction(UserManager.DISALLOW_RECORD_AUDIO)
.setAllowSystemRestrictionBypass(new RestrictionBypass(false, false, true))
.setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_PLAY_AUDIO, OPSTR_PLAY_AUDIO, "PLAY_AUDIO")
.setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_READ_CLIPBOARD, OPSTR_READ_CLIPBOARD, "READ_CLIPBOARD")
.setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_WRITE_CLIPBOARD, OPSTR_WRITE_CLIPBOARD, "WRITE_CLIPBOARD")
.setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_TAKE_MEDIA_BUTTONS, OPSTR_TAKE_MEDIA_BUTTONS, "TAKE_MEDIA_BUTTONS")
.setDefaultMode(AppOpsManager.MODE_ALLOWED)
.build(),
new AppOpInfo.Builder(OP_TAKE_AUDIO_FOCUS, OPSTR_TAKE_AUDIO_FOCUS, "TAKE_AUDIO_FOCUS")
.setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_AUDIO_MASTER_VOLUME, OPSTR_AUDIO_MASTER_VOLUME,
"AUDIO_MASTER_VOLUME").setSwitchCode(OP_AUDIO_MASTER_VOLUME)
.setRestriction(UserManager.DISALLOW_ADJUST_VOLUME)
.setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_AUDIO_VOICE_VOLUME, OPSTR_AUDIO_VOICE_VOLUME, "AUDIO_VOICE_VOLUME")
.setRestriction(UserManager.DISALLOW_ADJUST_VOLUME)
.setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_AUDIO_RING_VOLUME, OPSTR_AUDIO_RING_VOLUME, "AUDIO_RING_VOLUME")
.setRestriction(UserManager.DISALLOW_ADJUST_VOLUME)
.setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_AUDIO_MEDIA_VOLUME, OPSTR_AUDIO_MEDIA_VOLUME, "AUDIO_MEDIA_VOLUME")
.setRestriction(UserManager.DISALLOW_ADJUST_VOLUME)
.setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_AUDIO_ALARM_VOLUME, OPSTR_AUDIO_ALARM_VOLUME, "AUDIO_ALARM_VOLUME")
.setRestriction(UserManager.DISALLOW_ADJUST_VOLUME)
.setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_AUDIO_NOTIFICATION_VOLUME, OPSTR_AUDIO_NOTIFICATION_VOLUME,
"AUDIO_NOTIFICATION_VOLUME").setSwitchCode(OP_AUDIO_NOTIFICATION_VOLUME)
.setRestriction(UserManager.DISALLOW_ADJUST_VOLUME)
.setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_AUDIO_BLUETOOTH_VOLUME, OPSTR_AUDIO_BLUETOOTH_VOLUME,
"AUDIO_BLUETOOTH_VOLUME").setRestriction(UserManager.DISALLOW_ADJUST_VOLUME)
.setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_WAKE_LOCK, OPSTR_WAKE_LOCK, "WAKE_LOCK")
.setPermission(android.Manifest.permission.WAKE_LOCK)
.setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_MONITOR_LOCATION, OPSTR_MONITOR_LOCATION, "MONITOR_LOCATION")
.setSwitchCode(OP_COARSE_LOCATION)
.setRestriction(UserManager.DISALLOW_SHARE_LOCATION)
.setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_MONITOR_HIGH_POWER_LOCATION, OPSTR_MONITOR_HIGH_POWER_LOCATION,
"MONITOR_HIGH_POWER_LOCATION").setSwitchCode(OP_COARSE_LOCATION)
.setRestriction(UserManager.DISALLOW_SHARE_LOCATION)
.setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_GET_USAGE_STATS, OPSTR_GET_USAGE_STATS, "GET_USAGE_STATS")
.setPermission(android.Manifest.permission.PACKAGE_USAGE_STATS).build(),
new AppOpInfo.Builder(OP_MUTE_MICROPHONE, OPSTR_MUTE_MICROPHONE, "MUTE_MICROPHONE")
.setRestriction(UserManager.DISALLOW_UNMUTE_MICROPHONE)
.setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_TOAST_WINDOW, OPSTR_TOAST_WINDOW, "TOAST_WINDOW")
.setRestriction(UserManager.DISALLOW_CREATE_WINDOWS)
.setAllowSystemRestrictionBypass(new RestrictionBypass(false, true, false))
.setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_PROJECT_MEDIA, OPSTR_PROJECT_MEDIA, "PROJECT_MEDIA")
.setDefaultMode(AppOpsManager.MODE_IGNORED).build(),
new AppOpInfo.Builder(OP_ACTIVATE_VPN, OPSTR_ACTIVATE_VPN, "ACTIVATE_VPN")
.setDefaultMode(AppOpsManager.MODE_IGNORED).build(),
new AppOpInfo.Builder(OP_WRITE_WALLPAPER, OPSTR_WRITE_WALLPAPER, "WRITE_WALLPAPER")
.setRestriction(UserManager.DISALLOW_WALLPAPER)
.setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_ASSIST_STRUCTURE, OPSTR_ASSIST_STRUCTURE, "ASSIST_STRUCTURE")
.setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_ASSIST_SCREENSHOT, OPSTR_ASSIST_SCREENSHOT, "ASSIST_SCREENSHOT")
.setDefaultMode(AppOpsManager.MODE_ALLOWED)
.build(),
new AppOpInfo.Builder(OP_READ_PHONE_STATE, OPSTR_READ_PHONE_STATE, "READ_PHONE_STATE")
.setPermission(Manifest.permission.READ_PHONE_STATE)
.setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_ADD_VOICEMAIL, OPSTR_ADD_VOICEMAIL, "ADD_VOICEMAIL")
.setPermission(Manifest.permission.ADD_VOICEMAIL)
.setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_USE_SIP, OPSTR_USE_SIP, "USE_SIP")
.setPermission(Manifest.permission.USE_SIP)
.setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_PROCESS_OUTGOING_CALLS, OPSTR_PROCESS_OUTGOING_CALLS,
"PROCESS_OUTGOING_CALLS").setSwitchCode(OP_PROCESS_OUTGOING_CALLS)
.setPermission(Manifest.permission.PROCESS_OUTGOING_CALLS)
.setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_USE_FINGERPRINT, OPSTR_USE_FINGERPRINT, "USE_FINGERPRINT")
.setPermission(Manifest.permission.USE_FINGERPRINT)
.setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_BODY_SENSORS, OPSTR_BODY_SENSORS, "BODY_SENSORS")
.setPermission(Manifest.permission.BODY_SENSORS)
.setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_READ_CELL_BROADCASTS, OPSTR_READ_CELL_BROADCASTS,
"READ_CELL_BROADCASTS").setPermission(Manifest.permission.READ_CELL_BROADCASTS)
.setDefaultMode(AppOpsManager.MODE_ALLOWED).setDisableReset(true).build(),
new AppOpInfo.Builder(OP_MOCK_LOCATION, OPSTR_MOCK_LOCATION, "MOCK_LOCATION")
.setDefaultMode(AppOpsManager.MODE_ERRORED).build(),
new AppOpInfo.Builder(OP_READ_EXTERNAL_STORAGE, OPSTR_READ_EXTERNAL_STORAGE,
"READ_EXTERNAL_STORAGE").setPermission(Manifest.permission.READ_EXTERNAL_STORAGE)
.setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_WRITE_EXTERNAL_STORAGE, OPSTR_WRITE_EXTERNAL_STORAGE,
"WRITE_EXTERNAL_STORAGE").setPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)
.setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_TURN_SCREEN_ON, OPSTR_TURN_SCREEN_ON, "TURN_SCREEN_ON")
.setPermission(Manifest.permission.TURN_SCREEN_ON)
.setDefaultMode(AppOpsManager.MODE_DEFAULT).build(),
new AppOpInfo.Builder(OP_GET_ACCOUNTS, OPSTR_GET_ACCOUNTS, "GET_ACCOUNTS")
.setPermission(Manifest.permission.GET_ACCOUNTS)
.setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_RUN_IN_BACKGROUND, OPSTR_RUN_IN_BACKGROUND, "RUN_IN_BACKGROUND")
.setDefaultMode(AppOpsManager.MODE_ALLOWED)
.build(),
new AppOpInfo.Builder(OP_AUDIO_ACCESSIBILITY_VOLUME, OPSTR_AUDIO_ACCESSIBILITY_VOLUME,
"AUDIO_ACCESSIBILITY_VOLUME")
.setRestriction(UserManager.DISALLOW_ADJUST_VOLUME)
.setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_READ_PHONE_NUMBERS, OPSTR_READ_PHONE_NUMBERS, "READ_PHONE_NUMBERS")
.setPermission(Manifest.permission.READ_PHONE_NUMBERS)
.setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_REQUEST_INSTALL_PACKAGES, OPSTR_REQUEST_INSTALL_PACKAGES,
"REQUEST_INSTALL_PACKAGES").setSwitchCode(OP_REQUEST_INSTALL_PACKAGES)
.setPermission(Manifest.permission.REQUEST_INSTALL_PACKAGES).build(),
new AppOpInfo.Builder(OP_PICTURE_IN_PICTURE, OPSTR_PICTURE_IN_PICTURE, "PICTURE_IN_PICTURE")
.setSwitchCode(OP_PICTURE_IN_PICTURE).setDefaultMode(AppOpsManager.MODE_ALLOWED)
.build(),
new AppOpInfo.Builder(OP_INSTANT_APP_START_FOREGROUND, OPSTR_INSTANT_APP_START_FOREGROUND,
"INSTANT_APP_START_FOREGROUND")
.setPermission(Manifest.permission.INSTANT_APP_FOREGROUND_SERVICE).build(),
new AppOpInfo.Builder(OP_ANSWER_PHONE_CALLS, OPSTR_ANSWER_PHONE_CALLS, "ANSWER_PHONE_CALLS")
.setSwitchCode(OP_ANSWER_PHONE_CALLS)
.setPermission(Manifest.permission.ANSWER_PHONE_CALLS)
.setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_RUN_ANY_IN_BACKGROUND, OPSTR_RUN_ANY_IN_BACKGROUND,
"RUN_ANY_IN_BACKGROUND")
.setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_CHANGE_WIFI_STATE, OPSTR_CHANGE_WIFI_STATE, "CHANGE_WIFI_STATE")
.setSwitchCode(OP_CHANGE_WIFI_STATE)
.setPermission(Manifest.permission.CHANGE_WIFI_STATE)
.setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_REQUEST_DELETE_PACKAGES, OPSTR_REQUEST_DELETE_PACKAGES,
"REQUEST_DELETE_PACKAGES")
.setPermission(Manifest.permission.REQUEST_DELETE_PACKAGES)
.setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_BIND_ACCESSIBILITY_SERVICE, OPSTR_BIND_ACCESSIBILITY_SERVICE,
"BIND_ACCESSIBILITY_SERVICE")
.setPermission(Manifest.permission.BIND_ACCESSIBILITY_SERVICE)
.setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_ACCEPT_HANDOVER, OPSTR_ACCEPT_HANDOVER, "ACCEPT_HANDOVER")
.setSwitchCode(OP_ACCEPT_HANDOVER)
.setPermission(Manifest.permission.ACCEPT_HANDOVER)
.setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_MANAGE_IPSEC_TUNNELS, OPSTR_MANAGE_IPSEC_TUNNELS,
"MANAGE_IPSEC_TUNNELS")
.setPermission(Manifest.permission.MANAGE_IPSEC_TUNNELS)
.setDefaultMode(AppOpsManager.MODE_ERRORED).build(),
new AppOpInfo.Builder(OP_START_FOREGROUND, OPSTR_START_FOREGROUND, "START_FOREGROUND")
.setPermission(Manifest.permission.FOREGROUND_SERVICE)
.setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_BLUETOOTH_SCAN, OPSTR_BLUETOOTH_SCAN, "BLUETOOTH_SCAN")
.setPermission(Manifest.permission.BLUETOOTH_SCAN)
.setAllowSystemRestrictionBypass(new RestrictionBypass(false, true, false))
.setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_USE_BIOMETRIC, OPSTR_USE_BIOMETRIC, "USE_BIOMETRIC")
.setPermission(Manifest.permission.USE_BIOMETRIC)
.setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_ACTIVITY_RECOGNITION, OPSTR_ACTIVITY_RECOGNITION,
"ACTIVITY_RECOGNITION")
.setPermission(Manifest.permission.ACTIVITY_RECOGNITION)
.setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_SMS_FINANCIAL_TRANSACTIONS, OPSTR_SMS_FINANCIAL_TRANSACTIONS,
"SMS_FINANCIAL_TRANSACTIONS")
.setPermission(Manifest.permission.SMS_FINANCIAL_TRANSACTIONS)
.setRestriction(UserManager.DISALLOW_SMS).build(),
new AppOpInfo.Builder(OP_READ_MEDIA_AUDIO, OPSTR_READ_MEDIA_AUDIO, "READ_MEDIA_AUDIO")
.setPermission(Manifest.permission.READ_MEDIA_AUDIO)
.setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_WRITE_MEDIA_AUDIO, OPSTR_WRITE_MEDIA_AUDIO, "WRITE_MEDIA_AUDIO")
.setDefaultMode(AppOpsManager.MODE_ERRORED).build(),
new AppOpInfo.Builder(OP_READ_MEDIA_VIDEO, OPSTR_READ_MEDIA_VIDEO, "READ_MEDIA_VIDEO")
.setPermission(Manifest.permission.READ_MEDIA_VIDEO)
.setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_WRITE_MEDIA_VIDEO, OPSTR_WRITE_MEDIA_VIDEO, "WRITE_MEDIA_VIDEO")
.setDefaultMode(AppOpsManager.MODE_ERRORED).setDisableReset(true).build(),
new AppOpInfo.Builder(OP_READ_MEDIA_IMAGES, OPSTR_READ_MEDIA_IMAGES, "READ_MEDIA_IMAGES")
.setPermission(Manifest.permission.READ_MEDIA_IMAGES)
.setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_WRITE_MEDIA_IMAGES, OPSTR_WRITE_MEDIA_IMAGES, "WRITE_MEDIA_IMAGES")
.setDefaultMode(AppOpsManager.MODE_ERRORED).setDisableReset(true).build(),
new AppOpInfo.Builder(OP_LEGACY_STORAGE, OPSTR_LEGACY_STORAGE, "LEGACY_STORAGE")
.setDisableReset(true).build(),
new AppOpInfo.Builder(OP_ACCESS_ACCESSIBILITY, OPSTR_ACCESS_ACCESSIBILITY,
"ACCESS_ACCESSIBILITY").setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_READ_DEVICE_IDENTIFIERS, OPSTR_READ_DEVICE_IDENTIFIERS,
"READ_DEVICE_IDENTIFIERS").setDefaultMode(AppOpsManager.MODE_ERRORED).build(),
new AppOpInfo.Builder(OP_ACCESS_MEDIA_LOCATION, OPSTR_ACCESS_MEDIA_LOCATION,
"ACCESS_MEDIA_LOCATION").setPermission(Manifest.permission.ACCESS_MEDIA_LOCATION)
.setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_QUERY_ALL_PACKAGES, OPSTR_QUERY_ALL_PACKAGES, "QUERY_ALL_PACKAGES")
.build(),
new AppOpInfo.Builder(OP_MANAGE_EXTERNAL_STORAGE, OPSTR_MANAGE_EXTERNAL_STORAGE,
"MANAGE_EXTERNAL_STORAGE")
.setPermission(Manifest.permission.MANAGE_EXTERNAL_STORAGE).build(),
new AppOpInfo.Builder(OP_INTERACT_ACROSS_PROFILES, OPSTR_INTERACT_ACROSS_PROFILES,
"INTERACT_ACROSS_PROFILES")
.setPermission(android.Manifest.permission.INTERACT_ACROSS_PROFILES).build(),
new AppOpInfo.Builder(OP_ACTIVATE_PLATFORM_VPN, OPSTR_ACTIVATE_PLATFORM_VPN,
"ACTIVATE_PLATFORM_VPN").setDefaultMode(AppOpsManager.MODE_IGNORED).build(),
new AppOpInfo.Builder(OP_LOADER_USAGE_STATS, OPSTR_LOADER_USAGE_STATS, "LOADER_USAGE_STATS")
.setPermission(android.Manifest.permission.LOADER_USAGE_STATS).build(),
new AppOpInfo.Builder(OP_NONE, "", "").setDefaultMode(AppOpsManager.MODE_IGNORED).build(),
new AppOpInfo.Builder(OP_AUTO_REVOKE_PERMISSIONS_IF_UNUSED,
OPSTR_AUTO_REVOKE_PERMISSIONS_IF_UNUSED, "AUTO_REVOKE_PERMISSIONS_IF_UNUSED")
.build(),
new AppOpInfo.Builder(OP_AUTO_REVOKE_MANAGED_BY_INSTALLER,
OPSTR_AUTO_REVOKE_MANAGED_BY_INSTALLER, "AUTO_REVOKE_MANAGED_BY_INSTALLER")
.setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_NO_ISOLATED_STORAGE, OPSTR_NO_ISOLATED_STORAGE,
"NO_ISOLATED_STORAGE").setDefaultMode(AppOpsManager.MODE_ERRORED)
.setDisableReset(true).build(),
new AppOpInfo.Builder(OP_PHONE_CALL_MICROPHONE, OPSTR_PHONE_CALL_MICROPHONE,
"PHONE_CALL_MICROPHONE").setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_PHONE_CALL_CAMERA, OPSTR_PHONE_CALL_CAMERA, "PHONE_CALL_CAMERA")
.setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_RECORD_AUDIO_HOTWORD, OPSTR_RECORD_AUDIO_HOTWORD,
"RECORD_AUDIO_HOTWORD").setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_MANAGE_ONGOING_CALLS, OPSTR_MANAGE_ONGOING_CALLS,
"MANAGE_ONGOING_CALLS").setPermission(Manifest.permission.MANAGE_ONGOING_CALLS)
.setDisableReset(true).build(),
new AppOpInfo.Builder(OP_MANAGE_CREDENTIALS, OPSTR_MANAGE_CREDENTIALS, "MANAGE_CREDENTIALS")
.build(),
new AppOpInfo.Builder(OP_USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER,
OPSTR_USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER, "USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER")
.setPermission(Manifest.permission.USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER)
.setDisableReset(true).build(),
new AppOpInfo.Builder(OP_RECORD_AUDIO_OUTPUT, OPSTR_RECORD_AUDIO_OUTPUT,
"RECORD_AUDIO_OUTPUT").setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_SCHEDULE_EXACT_ALARM, OPSTR_SCHEDULE_EXACT_ALARM,
"SCHEDULE_EXACT_ALARM").setPermission(Manifest.permission.SCHEDULE_EXACT_ALARM)
.build(),
new AppOpInfo.Builder(OP_FINE_LOCATION_SOURCE, OPSTR_FINE_LOCATION_SOURCE,
"FINE_LOCATION_SOURCE").setSwitchCode(OP_FINE_LOCATION)
.setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_COARSE_LOCATION_SOURCE, OPSTR_COARSE_LOCATION_SOURCE,
"COARSE_LOCATION_SOURCE").setSwitchCode(OP_COARSE_LOCATION)
.setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_MANAGE_MEDIA, OPSTR_MANAGE_MEDIA, "MANAGE_MEDIA")
.setPermission(Manifest.permission.MANAGE_MEDIA).build(),
new AppOpInfo.Builder(OP_BLUETOOTH_CONNECT, OPSTR_BLUETOOTH_CONNECT, "BLUETOOTH_CONNECT")
.setPermission(Manifest.permission.BLUETOOTH_CONNECT)
.setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_UWB_RANGING, OPSTR_UWB_RANGING, "UWB_RANGING")
.setPermission(Manifest.permission.UWB_RANGING)
.setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_ACTIVITY_RECOGNITION_SOURCE, OPSTR_ACTIVITY_RECOGNITION_SOURCE,
"ACTIVITY_RECOGNITION_SOURCE")
.setSwitchCode(OP_ACTIVITY_RECOGNITION).setDefaultMode(AppOpsManager.MODE_ALLOWED)
.build(),
new AppOpInfo.Builder(OP_BLUETOOTH_ADVERTISE, OPSTR_BLUETOOTH_ADVERTISE,
"BLUETOOTH_ADVERTISE").setPermission(Manifest.permission.BLUETOOTH_ADVERTISE)
.setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_RECORD_INCOMING_PHONE_AUDIO, OPSTR_RECORD_INCOMING_PHONE_AUDIO,
"RECORD_INCOMING_PHONE_AUDIO").setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_NEARBY_WIFI_DEVICES, OPSTR_NEARBY_WIFI_DEVICES,
"NEARBY_WIFI_DEVICES").setPermission(Manifest.permission.NEARBY_WIFI_DEVICES)
.setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_ESTABLISH_VPN_SERVICE, OPSTR_ESTABLISH_VPN_SERVICE,
"ESTABLISH_VPN_SERVICE").setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_ESTABLISH_VPN_MANAGER, OPSTR_ESTABLISH_VPN_MANAGER,
"ESTABLISH_VPN_MANAGER").setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_ACCESS_RESTRICTED_SETTINGS, OPSTR_ACCESS_RESTRICTED_SETTINGS,
"ACCESS_RESTRICTED_SETTINGS").setDefaultMode(AppOpsManager.MODE_ALLOWED)
.setDisableReset(true).setRestrictRead(true).build(),
new AppOpInfo.Builder(OP_RECEIVE_AMBIENT_TRIGGER_AUDIO, OPSTR_RECEIVE_AMBIENT_TRIGGER_AUDIO,
"RECEIVE_SOUNDTRIGGER_AUDIO").setDefaultMode(AppOpsManager.MODE_ALLOWED)
.setForceCollectNotes(true).build(),
new AppOpInfo.Builder(OP_RECEIVE_EXPLICIT_USER_INTERACTION_AUDIO,
OPSTR_RECEIVE_EXPLICIT_USER_INTERACTION_AUDIO,
"RECEIVE_EXPLICIT_USER_INTERACTION_AUDIO").setDefaultMode(
AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_RUN_USER_INITIATED_JOBS, OPSTR_RUN_USER_INITIATED_JOBS,
"RUN_USER_INITIATED_JOBS").setDefaultMode(AppOpsManager.MODE_ALLOWED)
.build(),
new AppOpInfo.Builder(OP_READ_MEDIA_VISUAL_USER_SELECTED,
OPSTR_READ_MEDIA_VISUAL_USER_SELECTED, "READ_MEDIA_VISUAL_USER_SELECTED")
.setPermission(Manifest.permission.READ_MEDIA_VISUAL_USER_SELECTED)
.setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_SYSTEM_EXEMPT_FROM_SUSPENSION,
OPSTR_SYSTEM_EXEMPT_FROM_SUSPENSION,
"SYSTEM_EXEMPT_FROM_SUSPENSION")
.setDisableReset(true).build(),
new AppOpInfo.Builder(OP_SYSTEM_EXEMPT_FROM_DISMISSIBLE_NOTIFICATIONS,
OPSTR_SYSTEM_EXEMPT_FROM_DISMISSIBLE_NOTIFICATIONS,
"SYSTEM_EXEMPT_FROM_DISMISSIBLE_NOTIFICATIONS")
.setDisableReset(true).build(),
new AppOpInfo.Builder(OP_READ_WRITE_HEALTH_DATA, OPSTR_READ_WRITE_HEALTH_DATA,
"READ_WRITE_HEALTH_DATA").setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_FOREGROUND_SERVICE_SPECIAL_USE,
OPSTR_FOREGROUND_SERVICE_SPECIAL_USE, "FOREGROUND_SERVICE_SPECIAL_USE")
.setPermission(Manifest.permission.FOREGROUND_SERVICE_SPECIAL_USE).build(),
new AppOpInfo.Builder(OP_SYSTEM_EXEMPT_FROM_POWER_RESTRICTIONS,
OPSTR_SYSTEM_EXEMPT_FROM_POWER_RESTRICTIONS,
"SYSTEM_EXEMPT_FROM_POWER_RESTRICTIONS")
.setDisableReset(true).build(),
new AppOpInfo.Builder(OP_SYSTEM_EXEMPT_FROM_HIBERNATION,
OPSTR_SYSTEM_EXEMPT_FROM_HIBERNATION,
"SYSTEM_EXEMPT_FROM_HIBERNATION")
.setDisableReset(true).build(),
new AppOpInfo.Builder(OP_SYSTEM_EXEMPT_FROM_ACTIVITY_BG_START_RESTRICTION,
OPSTR_SYSTEM_EXEMPT_FROM_ACTIVITY_BG_START_RESTRICTION,
"SYSTEM_EXEMPT_FROM_ACTIVITY_BG_START_RESTRICTION")
.setDisableReset(true).build(),
new AppOpInfo.Builder(
OP_CAPTURE_CONSENTLESS_BUGREPORT_ON_USERDEBUG_BUILD,
OPSTR_CAPTURE_CONSENTLESS_BUGREPORT_ON_USERDEBUG_BUILD,
"CAPTURE_CONSENTLESS_BUGREPORT_ON_USERDEBUG_BUILD")
.setPermission(Manifest.permission.CAPTURE_CONSENTLESS_BUGREPORT_ON_USERDEBUG_BUILD)
.build(),
new AppOpInfo.Builder(OP_DEPRECATED_2, OPSTR_DEPRECATED_2, "DEPRECATED_2")
.setDefaultMode(AppOpsManager.MODE_IGNORED).build(),
new AppOpInfo.Builder(OP_USE_FULL_SCREEN_INTENT, OPSTR_USE_FULL_SCREEN_INTENT,
"USE_FULL_SCREEN_INTENT").setPermission(Manifest.permission.USE_FULL_SCREEN_INTENT)
.build(),
new AppOpInfo.Builder(OP_CAMERA_SANDBOXED, OPSTR_CAMERA_SANDBOXED,
"CAMERA_SANDBOXED").setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_RECORD_AUDIO_SANDBOXED, OPSTR_RECORD_AUDIO_SANDBOXED,
"RECORD_AUDIO_SANDBOXED").setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_RECEIVE_SANDBOX_TRIGGER_AUDIO,
OPSTR_RECEIVE_SANDBOX_TRIGGER_AUDIO,
"RECEIVE_SANDBOX_TRIGGER_AUDIO")
.setPermission(Manifest.permission.RECEIVE_SANDBOX_TRIGGER_AUDIO)
.setDefaultMode(AppOpsManager.MODE_DEFAULT).build(),
new AppOpInfo.Builder(OP_DEPRECATED_3, OPSTR_DEPRECATED_3, "DEPRECATED_3")
.setDefaultMode(AppOpsManager.MODE_IGNORED).build(),
new AppOpInfo.Builder(OP_CREATE_ACCESSIBILITY_OVERLAY,
OPSTR_CREATE_ACCESSIBILITY_OVERLAY,
"CREATE_ACCESSIBILITY_OVERLAY")
.setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_MEDIA_ROUTING_CONTROL, OPSTR_MEDIA_ROUTING_CONTROL,
"MEDIA_ROUTING_CONTROL")
.setPermission(Manifest.permission.MEDIA_ROUTING_CONTROL).build(),
new AppOpInfo.Builder(OP_ENABLE_MOBILE_DATA_BY_USER, OPSTR_ENABLE_MOBILE_DATA_BY_USER,
"ENABLE_MOBILE_DATA_BY_USER").setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_RESERVED_FOR_TESTING, OPSTR_RESERVED_FOR_TESTING,
"OP_RESERVED_FOR_TESTING").setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_RAPID_CLEAR_NOTIFICATIONS_BY_LISTENER,
OPSTR_RAPID_CLEAR_NOTIFICATIONS_BY_LISTENER,
"RAPID_CLEAR_NOTIFICATIONS_BY_LISTENER")
.setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_READ_SYSTEM_GRAMMATICAL_GENDER,
OPSTR_READ_SYSTEM_GRAMMATICAL_GENDER, "READ_SYSTEM_GRAMMATICAL_GENDER")
// will make it an app-op permission in the future.
// .setPermission(Manifest.permission.READ_SYSTEM_GRAMMATICAL_GENDER)
.build(),
new AppOpInfo.Builder(OP_DEPRECATED_4, OPSTR_DEPRECATED_4, "DEPRECATED_4")
.setDefaultMode(AppOpsManager.MODE_IGNORED).build(),
new AppOpInfo.Builder(OP_ARCHIVE_ICON_OVERLAY, OPSTR_ARCHIVE_ICON_OVERLAY,
"ARCHIVE_ICON_OVERLAY")
.setDefaultMode(MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_UNARCHIVAL_CONFIRMATION, OPSTR_UNARCHIVAL_CONFIRMATION,
"UNARCHIVAL_CONFIRMATION")
.setDefaultMode(MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_EMERGENCY_LOCATION, OPSTR_EMERGENCY_LOCATION, "EMERGENCY_LOCATION")
.setDefaultMode(MODE_ALLOWED)
// even though this has a permission associated, this op is only used for tracking,
// and the client is responsible for checking the LOCATION_BYPASS permission.
.setPermission(Manifest.permission.LOCATION_BYPASS).build(),
new AppOpInfo.Builder(OP_RECEIVE_SENSITIVE_NOTIFICATIONS,
OPSTR_RECEIVE_SENSITIVE_NOTIFICATIONS, "RECEIVE_SENSITIVE_NOTIFICATIONS")
.setDefaultMode(MODE_IGNORED).build(),
};
// The number of longs needed to form a full bitmask of app ops
private static final int BITMASK_LEN = ((_NUM_OP - 1) / Long.SIZE) + 1;
/**
* @hide
*/
public static boolean shouldForceCollectNoteForOp(int op) {
Preconditions.checkArgumentInRange(op, 0, _NUM_OP - 1, "opCode");
return sAppOpInfos[op].forceCollectNotes;
}
/**
* Mapping from an app op name to the app op code.
*/
private static HashMap sOpStrToOp = new HashMap<>();
/**
* Mapping from a permission to the corresponding app op.
*/
private static HashMap sPermToOp = new HashMap<>();
/**
* Set to the uid of the caller if this thread is currently executing a two-way binder
* transaction. Not set if this thread is currently not executing a two way binder transaction.
*
* @see #startNotedAppOpsCollection
* @see #getNotedOpCollectionMode
*/
private static final ThreadLocal sBinderThreadCallingUid = new ThreadLocal<>();
/**
* If a thread is currently executing a two-way binder transaction, this stores the op-codes of
* the app-ops that were noted during this transaction.
*
* @see #getNotedOpCollectionMode
* @see #collectNotedOpSync
*/
private static final ThreadLocal>
sAppOpsNotedInThisBinderTransaction = new ThreadLocal<>();
static {
if (sAppOpInfos.length != _NUM_OP) {
throw new IllegalStateException("mAppOpInfos length " + sAppOpInfos.length
+ " should be " + _NUM_OP);
}
for (int i=0; i<_NUM_OP; i++) {
if (sAppOpInfos[i].name != null) {
sOpStrToOp.put(sAppOpInfos[i].name, i);
}
}
for (int op : RUNTIME_PERMISSION_OPS) {
if (sAppOpInfos[op].permission != null) {
sPermToOp.put(sAppOpInfos[op].permission, op);
}
}
for (int op : APP_OP_PERMISSION_PACKAGE_OPS) {
if (sAppOpInfos[op].permission != null) {
sPermToOp.put(sAppOpInfos[op].permission, op);
}
}
for (int op : APP_OP_PERMISSION_UID_OPS) {
if (sAppOpInfos[op].permission != null) {
sPermToOp.put(sAppOpInfos[op].permission, op);
}
}
}
/** Config used to control app ops access messages sampling */
private static MessageSamplingConfig sConfig =
new MessageSamplingConfig(OP_NONE, 0, 0);
/** @hide */
public static final String KEY_HISTORICAL_OPS = "historical_ops";
/** System properties for debug logging of noteOp call sites */
private static final String DEBUG_LOGGING_ENABLE_PROP = "appops.logging_enabled";
private static final String DEBUG_LOGGING_PACKAGES_PROP = "appops.logging_packages";
private static final String DEBUG_LOGGING_OPS_PROP = "appops.logging_ops";
private static final String DEBUG_LOGGING_TAG = "AppOpsManager";
/**
* Retrieve the op switch that controls the given operation.
* @hide
*/
@UnsupportedAppUsage
public static int opToSwitch(int op) {
return sAppOpInfos[op].switchCode;
}
/**
* Retrieve a non-localized name for the operation, for debugging output.
* @hide
*/
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
public static String opToName(int op) {
if (op == OP_NONE) return "NONE";
return op < sAppOpInfos.length ? sAppOpInfos[op].simpleName : ("Unknown(" + op + ")");
}
/**
* Retrieve a non-localized public name for the operation.
*
* @hide
*/
public static @NonNull String opToPublicName(int op) {
return sAppOpInfos[op].name;
}
/**
* @hide
*/
public static int strDebugOpToOp(String op) {
for (int i = 0; i < sAppOpInfos.length; i++) {
if (sAppOpInfos[i].simpleName.equals(op)) {
return i;
}
}
throw new IllegalArgumentException("Unknown operation string: " + op);
}
/**
* Retrieve the permission associated with an operation, or null if there is not one.
* @hide
*/
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
@TestApi
public static String opToPermission(int op) {
return sAppOpInfos[op].permission;
}
/**
* Retrieve the permission associated with an operation, or null if there is not one.
* @param op The operation name.
*
* @hide
*/
@Nullable
@SystemApi
public static String opToPermission(@NonNull String op) {
return opToPermission(strOpToOp(op));
}
/**
* Retrieve the user restriction associated with an operation, or null if there is not one.
* @hide
*/
public static String opToRestriction(int op) {
return sAppOpInfos[op].restriction;
}
/**
* Retrieve the app op code for a permission, or null if there is not one.
* This API is intended to be used for mapping runtime or appop permissions
* to the corresponding app op.
* @hide
*/
@UnsupportedAppUsage
@TestApi
public static int permissionToOpCode(String permission) {
Integer boxedOpCode = sPermToOp.get(permission);
if (boxedOpCode != null) {
return boxedOpCode;
}
if (permission != null && HealthConnectManager.isHealthPermission(
ActivityThread.currentApplication(), permission)) {
return OP_READ_WRITE_HEALTH_DATA;
}
return OP_NONE;
}
/**
* Retrieve whether the op allows to bypass the user restriction.
*
* @hide
*/
public static RestrictionBypass opAllowSystemBypassRestriction(int op) {
return sAppOpInfos[op].allowSystemRestrictionBypass;
}
/**
* Retrieve the default mode for the operation.
* @hide
*/
public static @Mode int opToDefaultMode(int op) {
if (op == OP_TAKE_AUDIO_FOCUS && roForegroundAudioControl()) {
// when removing the flag, change the entry in sAppOpInfos for OP_TAKE_AUDIO_FOCUS
return AppOpsManager.MODE_FOREGROUND;
}
return sAppOpInfos[op].defaultMode;
}
/**
* Retrieve the default mode for the app op.
*
* @param appOp The app op name
*
* @return the default mode for the app op
*
* @hide
*/
@SystemApi
public static int opToDefaultMode(@NonNull String appOp) {
return opToDefaultMode(strOpToOp(appOp));
}
/**
* Retrieve the human readable mode.
* @hide
*/
public static String modeToName(@Mode int mode) {
if (mode >= 0 && mode < MODE_NAMES.length) {
return MODE_NAMES[mode];
}
return "mode=" + mode;
}
/**
* Retrieve whether the op can be read by apps with privileged appops permission.
* @hide
*/
public static boolean opRestrictsRead(int op) {
return sAppOpInfos[op].restrictRead;
}
/**
* Retrieve whether the op allows itself to be reset.
* @hide
*/
public static boolean opAllowsReset(int op) {
return !sAppOpInfos[op].disableReset;
}
/**
* Retrieve whether the op is a per-package op for an app op permission.
* @hide
*/
public static boolean opIsPackageAppOpPermission(int op) {
return ArrayUtils.contains(APP_OP_PERMISSION_PACKAGE_OPS, op);
}
/**
* Retrieve whether the op is a per-package op for an app op permission.
* @hide
*/
public static boolean opIsUidAppOpPermission(int op) {
return ArrayUtils.contains(APP_OP_PERMISSION_UID_OPS, op);
}
/**
* Returns a listenerId suitable for use with {@link #noteOp(int, int, String, String, String)}.
*
* This is intended for use client side, when the receiver id must be created before the
* associated call is made to the system server. If using {@link PendingIntent} as the receiver,
* avoid using this method as it will include a pointless additional x-process call. Instead
* prefer passing the PendingIntent to the system server, and then invoking
* {@link #toReceiverId(PendingIntent)}.
*
* @param obj the receiver in use
* @return a string representation of the receiver suitable for app ops use
* @hide
*/
// TODO: this should probably be @SystemApi as well
public static @NonNull String toReceiverId(@Nullable Object obj) {
if (obj == null) {
return "null";
} else if (obj instanceof PendingIntent) {
return toReceiverId((PendingIntent) obj);
} else {
return obj.getClass().getName() + "@" + System.identityHashCode(obj);
}
}
/**
* Returns a listenerId suitable for use with {@link #noteOp(int, int, String, String, String)}.
*
* This is intended for use server side, where ActivityManagerService can be referenced without
* an additional x-process call.
*
* @param pendingIntent the pendingIntent in use
* @return a string representation of the pending intent suitable for app ops use
* @see #toReceiverId(Object)
* @hide
*/
// TODO: this should probably be @SystemApi as well
public static @NonNull String toReceiverId(@NonNull PendingIntent pendingIntent) {
return pendingIntent.getTag("");
}
/**
* When to not enforce {@link #setUserRestriction restrictions}.
*
* @hide
*/
public static class RestrictionBypass {
/** Does the app need to be system uid to bypass the restriction */
public boolean isSystemUid;
/** Does the app need to be privileged to bypass the restriction */
public boolean isPrivileged;
/**
* Does the app need to have the EXEMPT_FROM_AUDIO_RESTRICTIONS permission to bypass the
* restriction
*/
public boolean isRecordAudioRestrictionExcept;
public RestrictionBypass(boolean isSystemUid, boolean isPrivileged,
boolean isRecordAudioRestrictionExcept) {
this.isSystemUid = isSystemUid;
this.isPrivileged = isPrivileged;
this.isRecordAudioRestrictionExcept = isRecordAudioRestrictionExcept;
}
public static RestrictionBypass UNRESTRICTED = new RestrictionBypass(false, true, true);
}
/**
* Class holding all of the operation information associated with an app.
* @hide
*/
@SystemApi
public static final class PackageOps implements Parcelable {
private final String mPackageName;
private final int mUid;
private final List mEntries;
/**
* @hide
*/
@UnsupportedAppUsage
public PackageOps(String packageName, int uid, List entries) {
mPackageName = packageName;
mUid = uid;
mEntries = entries;
}
/**
* @return The name of the package.
*/
public @NonNull String getPackageName() {
return mPackageName;
}
/**
* @return The uid of the package.
*/
public int getUid() {
return mUid;
}
/**
* @return The ops of the package.
*/
public @NonNull List getOps() {
return mEntries;
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(@NonNull Parcel dest, int flags) {
dest.writeString(mPackageName);
dest.writeInt(mUid);
dest.writeInt(mEntries.size());
for (int i=0; i();
final int N = source.readInt();
for (int i=0; i CREATOR =
new Creator() {
@Override public PackageOps createFromParcel(Parcel source) {
return new PackageOps(source);
}
@Override public PackageOps[] newArray(int size) {
return new PackageOps[size];
}
};
}
/**
* Proxy information for a {@link #noteOp} event
*
* @hide
*/
@SystemApi
// @DataClass(genHiddenConstructor = true, genHiddenCopyConstructor = true)
// genHiddenCopyConstructor does not work for @hide @SystemApi classes
public static final class OpEventProxyInfo implements Parcelable {
/** UID of the proxy app that noted the op */
private @IntRange(from = 0) int mUid;
/** Package of the proxy that noted the op */
private @Nullable String mPackageName;
/** Attribution tag of the proxy that noted the op */
private @Nullable String mAttributionTag;
/** Persistent device Id of the proxy that noted the op */
private @Nullable String mDeviceId;
/**
* Reinit existing object with new state.
*
* @param uid UID of the proxy app that noted the op
* @param packageName Package of the proxy that noted the op
* @param attributionTag attribution tag of the proxy that noted the op
* @param deviceId Persistent device Id of the proxy that noted the op
*
* @hide
*/
public void reinit(@IntRange(from = 0) int uid, @Nullable String packageName,
@Nullable String attributionTag, @Nullable String deviceId) {
mUid = Preconditions.checkArgumentNonnegative(uid);
mPackageName = packageName;
mAttributionTag = attributionTag;
mDeviceId = deviceId;
}
// Code below generated by codegen v1.0.14.
//
// DO NOT MODIFY!
// CHECKSTYLE:OFF Generated code
//
// To regenerate run:
// $ codegen $ANDROID_BUILD_TOP/frameworks/base/core/java/android/app/AppOpsManager.java
//
// To exclude the generated code from IntelliJ auto-formatting enable (one-time):
// Settings > Editor > Code Style > Formatter Control
//@formatter:off
/**
* Creates a new OpEventProxyInfo.
*
* @param uid
* UID of the proxy app that noted the op
* @param packageName
* Package of the proxy that noted the op
* @param attributionTag
* Attribution tag of the proxy that noted the op
* @hide
*/
@DataClass.Generated.Member
public OpEventProxyInfo(
@IntRange(from = 0) int uid,
@Nullable String packageName,
@Nullable String attributionTag) {
this(uid, packageName, attributionTag,
VirtualDeviceManager.PERSISTENT_DEVICE_ID_DEFAULT);
}
/**
* Creates a new OpEventProxyInfo.
*
* @param uid UID of the proxy app that noted the op
* @param packageName Package of the proxy that noted the op
* @param attributionTag Attribution tag of the proxy that noted the op
* @param deviceId Persistent device Id of the proxy that noted the op
*
* @hide
*/
public OpEventProxyInfo(
@IntRange(from = 0) int uid,
@Nullable String packageName,
@Nullable String attributionTag,
@Nullable String deviceId) {
this.mUid = uid;
com.android.internal.util.AnnotationValidations.validate(
IntRange.class, null, mUid,
"from", 0);
this.mPackageName = packageName;
this.mAttributionTag = attributionTag;
this.mDeviceId = deviceId;
}
/**
* Copy constructor
*
* @hide
*/
@DataClass.Generated.Member
public OpEventProxyInfo(@NonNull OpEventProxyInfo orig) {
mUid = orig.mUid;
mPackageName = orig.mPackageName;
mAttributionTag = orig.mAttributionTag;
mDeviceId = orig.mDeviceId;
}
/**
* UID of the proxy app that noted the op
*/
@DataClass.Generated.Member
public @IntRange(from = 0) int getUid() {
return mUid;
}
/**
* Package of the proxy that noted the op
*/
@DataClass.Generated.Member
public @Nullable String getPackageName() {
return mPackageName;
}
/**
* Attribution tag of the proxy that noted the op
*/
@DataClass.Generated.Member
public @Nullable String getAttributionTag() {
return mAttributionTag;
}
/**
* Persistent device Id of the proxy that noted the op
*/
@FlaggedApi(Flags.FLAG_DEVICE_ID_IN_OP_PROXY_INFO_ENABLED)
public @Nullable String getDeviceId() { return mDeviceId; }
@Override
@DataClass.Generated.Member
public void writeToParcel(@NonNull Parcel dest, int flags) {
// You can override field parcelling by defining methods like:
// void parcelFieldName(Parcel dest, int flags) { ... }
byte flg = 0;
if (mPackageName != null) flg |= 0x2;
if (mAttributionTag != null) flg |= 0x4;
if (mDeviceId != null) flg |= 0x8;
dest.writeByte(flg);
dest.writeInt(mUid);
if (mPackageName != null) dest.writeString(mPackageName);
if (mAttributionTag != null) dest.writeString(mAttributionTag);
if (mDeviceId != null) dest.writeString(mDeviceId);
}
@Override
@DataClass.Generated.Member
public int describeContents() { return 0; }
/** @hide */
@SuppressWarnings({"unchecked", "RedundantCast"})
@DataClass.Generated.Member
/* package-private */ OpEventProxyInfo(@NonNull Parcel in) {
// You can override field unparcelling by defining methods like:
// static FieldType unparcelFieldName(Parcel in) { ... }
byte flg = in.readByte();
int uid = in.readInt();
String packageName = (flg & 0x2) == 0 ? null : in.readString();
String attributionTag = (flg & 0x4) == 0 ? null : in.readString();
String deviceId = (flg & 0x8) == 0 ? null : in.readString();
this.mUid = uid;
com.android.internal.util.AnnotationValidations.validate(
IntRange.class, null, mUid,
"from", 0);
this.mPackageName = packageName;
this.mAttributionTag = attributionTag;
this.mDeviceId = deviceId;
// onConstructed(); // You can define this method to get a callback
}
@DataClass.Generated.Member
public static final @NonNull Parcelable.Creator CREATOR
= new Parcelable.Creator() {
@Override
public OpEventProxyInfo[] newArray(int size) {
return new OpEventProxyInfo[size];
}
@Override
public OpEventProxyInfo createFromParcel(@NonNull Parcel in) {
return new OpEventProxyInfo(in);
}
};
/*
@DataClass.Generated(
time = 1576814974615L,
codegenVersion = "1.0.14",
sourceFile = "frameworks/base/core/java/android/app/AppOpsManager.java",
inputSignatures = "private @android.annotation.IntRange(from=0L) int mUid\nprivate @android.annotation.Nullable java.lang.String mPackageName\nprivate @android.annotation.Nullable java.lang.String mAttributionTag\npublic void reinit(int,java.lang.String,java.lang.String)\nclass OpEventProxyInfo extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genHiddenConstructor=true, genHiddenCopyConstructor=true)")
@Deprecated
private void __metadata() {}
*/
//@formatter:on
// End of generated code
}
/**
* Description of a {@link #noteOp} or {@link #startOp} event
*
* @hide
*/
//@DataClass codegen verifier is broken
public static final class NoteOpEvent implements Parcelable {
/** Time of noteOp event */
private @IntRange(from = 0) long mNoteTime;
/** The duration of this event (in case this is a startOp event, -1 otherwise). */
private @IntRange(from = -1) long mDuration;
/** Proxy information of the noteOp event */
private @Nullable OpEventProxyInfo mProxy;
/**
* Reinit existing object with new state.
*
* @param noteTime Time of noteOp event
* @param duration The duration of this event (in case this is a startOp event,
* -1 otherwise).
* @param proxy Proxy information of the noteOp event
* @param proxyPool The pool to release previous {@link OpEventProxyInfo} to
*/
public void reinit(@IntRange(from = 0) long noteTime,
@IntRange(from = -1) long duration,
@Nullable OpEventProxyInfo proxy,
@NonNull Pools.Pool proxyPool) {
mNoteTime = Preconditions.checkArgumentNonnegative(noteTime);
mDuration = Preconditions.checkArgumentInRange(duration, -1L, Long.MAX_VALUE,
"duration");
if (mProxy != null) {
proxyPool.release(mProxy);
}
mProxy = proxy;
}
/**
* Copy constructor
*
* @hide
*/
public NoteOpEvent(@NonNull NoteOpEvent original) {
this(original.mNoteTime, original.mDuration,
original.mProxy != null ? new OpEventProxyInfo(original.mProxy) : null);
}
// Code below generated by codegen v1.0.14.
//
// DO NOT MODIFY!
// CHECKSTYLE:OFF Generated code
//
// To regenerate run:
// $ codegen $ANDROID_BUILD_TOP/frameworks/base/core/java/android/app/AppOpsManager.java
//
// To exclude the generated code from IntelliJ auto-formatting enable (one-time):
// Settings > Editor > Code Style > Formatter Control
//@formatter:off
/**
* Creates a new NoteOpEvent.
*
* @param noteTime
* Time of noteOp event
* @param duration
* The duration of this event (in case this is a startOp event, -1 otherwise).
* @param proxy
* Proxy information of the noteOp event
*/
@DataClass.Generated.Member
public NoteOpEvent(
@IntRange(from = 0) long noteTime,
@IntRange(from = -1) long duration,
@Nullable OpEventProxyInfo proxy) {
this.mNoteTime = noteTime;
com.android.internal.util.AnnotationValidations.validate(
IntRange.class, null, mNoteTime,
"from", 0);
this.mDuration = duration;
com.android.internal.util.AnnotationValidations.validate(
IntRange.class, null, mDuration,
"from", -1);
this.mProxy = proxy;
// onConstructed(); // You can define this method to get a callback
}
/**
* Time of noteOp event
*/
@DataClass.Generated.Member
public @IntRange(from = 0) long getNoteTime() {
return mNoteTime;
}
/**
* The duration of this event (in case this is a startOp event, -1 otherwise).
*/
@DataClass.Generated.Member
public @IntRange(from = -1) long getDuration() {
return mDuration;
}
/**
* Proxy information of the noteOp event
*/
@DataClass.Generated.Member
public @Nullable OpEventProxyInfo getProxy() {
return mProxy;
}
@Override
@DataClass.Generated.Member
public void writeToParcel(@NonNull Parcel dest, int flags) {
// You can override field parcelling by defining methods like:
// void parcelFieldName(Parcel dest, int flags) { ... }
byte flg = 0;
if (mProxy != null) flg |= 0x4;
dest.writeByte(flg);
dest.writeLong(mNoteTime);
dest.writeLong(mDuration);
if (mProxy != null) dest.writeTypedObject(mProxy, flags);
}
@Override
@DataClass.Generated.Member
public int describeContents() { return 0; }
/** @hide */
@SuppressWarnings({"unchecked", "RedundantCast"})
@DataClass.Generated.Member
/* package-private */ NoteOpEvent(@NonNull Parcel in) {
// You can override field unparcelling by defining methods like:
// static FieldType unparcelFieldName(Parcel in) { ... }
byte flg = in.readByte();
long noteTime = in.readLong();
long duration = in.readLong();
OpEventProxyInfo proxy = (flg & 0x4) == 0 ? null : (OpEventProxyInfo) in.readTypedObject(OpEventProxyInfo.CREATOR);
this.mNoteTime = noteTime;
com.android.internal.util.AnnotationValidations.validate(
IntRange.class, null, mNoteTime,
"from", 0);
this.mDuration = duration;
com.android.internal.util.AnnotationValidations.validate(
IntRange.class, null, mDuration,
"from", -1);
this.mProxy = proxy;
// onConstructed(); // You can define this method to get a callback
}
@DataClass.Generated.Member
public static final @NonNull Parcelable.Creator CREATOR
= new Parcelable.Creator() {
@Override
public NoteOpEvent[] newArray(int size) {
return new NoteOpEvent[size];
}
@Override
public NoteOpEvent createFromParcel(@NonNull Parcel in) {
return new NoteOpEvent(in);
}
};
/*
@DataClass.Generated(
time = 1576811792274L,
codegenVersion = "1.0.14",
sourceFile = "frameworks/base/core/java/android/app/AppOpsManager.java",
inputSignatures = "private @android.annotation.IntRange(from=0L) long mNoteTime\nprivate @android.annotation.IntRange(from=-1) long mDuration\nprivate @android.annotation.Nullable android.app.OpEventProxyInfo mProxy\npublic void reinit(long,long,android.app.OpEventProxyInfo,android.util.Pools.Pool)\npublic @java.lang.Override java.lang.Object clone()\nclass NoteOpEvent extends java.lang.Object implements [android.os.Parcelable, java.lang.Cloneable]\n@com.android.internal.util.DataClass")
@Deprecated
private void __metadata() {}
*/
//@formatter:on
// End of generated code
}
/**
* Last {@link #noteOp} and {@link #startOp} events performed for a single op and a specific
* {@link Context#createAttributionContext(String) attribution} for all uidModes and opFlags.
*
* @hide
*/
@SystemApi
@Immutable
// @DataClass(genHiddenConstructor = true) codegen verifier is broken
@DataClass.Suppress({"getAccessEvents", "getRejectEvents", "getOp"})
public static final class AttributedOpEntry implements Parcelable {
/** The code of the op */
private final @IntRange(from = 0, to = _NUM_OP - 1) int mOp;
/** Whether the op is running */
private final boolean mRunning;
/** The access events */
@DataClass.ParcelWith(LongSparseArrayParceling.class)
private final @Nullable LongSparseArray mAccessEvents;
/** The rejection events */
@DataClass.ParcelWith(LongSparseArrayParceling.class)
private final @Nullable LongSparseArray mRejectEvents;
private AttributedOpEntry(@NonNull AttributedOpEntry other) {
mOp = other.mOp;
mRunning = other.mRunning;
mAccessEvents = other.mAccessEvents == null ? null : other.mAccessEvents.clone();
mRejectEvents = other.mRejectEvents == null ? null : other.mRejectEvents.clone();
}
/**
* Returns all keys for which we have events.
*
* @hide
*/
public @NonNull ArraySet collectKeys() {
ArraySet keys = new ArraySet<>();
if (mAccessEvents != null) {
int numEvents = mAccessEvents.size();
for (int i = 0; i < numEvents; i++) {
keys.add(mAccessEvents.keyAt(i));
}
}
if (mRejectEvents != null) {
int numEvents = mRejectEvents.size();
for (int i = 0; i < numEvents; i++) {
keys.add(mRejectEvents.keyAt(i));
}
}
return keys;
}
/**
* Return the last access time.
*
* @param flags The op flags
*
* @return the last access time (in milliseconds since epoch start (January 1, 1970
* 00:00:00.000 GMT - Gregorian)) or {@code -1} if there was no access
*
* @see #getLastAccessForegroundTime(int)
* @see #getLastAccessBackgroundTime(int)
* @see #getLastAccessTime(int, int, int)
* @see OpEntry#getLastAccessTime(int)
*/
public long getLastAccessTime(@OpFlags int flags) {
return getLastAccessTime(MAX_PRIORITY_UID_STATE, MIN_PRIORITY_UID_STATE, flags);
}
/**
* Return the last foreground access time.
*
* @param flags The op flags
*
* @return the last access time (in milliseconds since epoch start (January 1, 1970
* 00:00:00.000 GMT - Gregorian)) or {@code -1} if there was no foreground access
*
* @see #getLastAccessTime(int)
* @see #getLastAccessBackgroundTime(int)
* @see #getLastAccessTime(int, int, int)
* @see OpEntry#getLastAccessForegroundTime(int)
*/
public long getLastAccessForegroundTime(@OpFlags int flags) {
return getLastAccessTime(MAX_PRIORITY_UID_STATE, resolveFirstUnrestrictedUidState(mOp),
flags);
}
/**
* Return the last background access time.
*
* @param flags The op flags
*
* @return the last access time (in milliseconds since epoch start (January 1, 1970
* 00:00:00.000 GMT - Gregorian)) or {@code -1} if there was no background access
*
* @see #getLastAccessTime(int)
* @see #getLastAccessForegroundTime(int)
* @see #getLastAccessTime(int, int, int)
* @see OpEntry#getLastAccessBackgroundTime(int)
*/
public long getLastAccessBackgroundTime(@OpFlags int flags) {
return getLastAccessTime(resolveLastRestrictedUidState(mOp), MIN_PRIORITY_UID_STATE,
flags);
}
/**
* Return the last access event.
*
* @param flags The op flags
*
* @return the last access event of {@code null} if there was no access
*/
private @Nullable NoteOpEvent getLastAccessEvent(@UidState int fromUidState,
@UidState int toUidState, @OpFlags int flags) {
return getLastEvent(mAccessEvents, fromUidState, toUidState, flags);
}
/**
* Return the last access time.
*
* @param fromUidState The lowest UID state for which to query
* @param toUidState The highest UID state for which to query (inclusive)
* @param flags The op flags
*
* @return the last access time (in milliseconds since epoch start (January 1, 1970
* 00:00:00.000 GMT - Gregorian)) or {@code -1} if there was no access
*
* @see #getLastAccessTime(int)
* @see #getLastAccessForegroundTime(int)
* @see #getLastAccessBackgroundTime(int)
* @see OpEntry#getLastAccessTime(int, int, int)
*/
public long getLastAccessTime(@UidState int fromUidState, @UidState int toUidState,
@OpFlags int flags) {
NoteOpEvent lastEvent = getLastAccessEvent(fromUidState, toUidState, flags);
if (lastEvent == null) {
return -1;
}
return lastEvent.getNoteTime();
}
/**
* Return the last rejection time.
*
* @param flags The op flags
*
* @return the last rejection time (in milliseconds since epoch start (January 1, 1970
* 00:00:00.000 GMT - Gregorian)) or {@code -1} if there was no rejection
*
* @see #getLastRejectForegroundTime(int)
* @see #getLastRejectBackgroundTime(int)
* @see #getLastRejectTime(int, int, int)
* @see OpEntry#getLastRejectTime(int)
*/
public long getLastRejectTime(@OpFlags int flags) {
return getLastRejectTime(MAX_PRIORITY_UID_STATE, MIN_PRIORITY_UID_STATE, flags);
}
/**
* Return the last foreground rejection time.
*
* @param flags The op flags
*
* @return the last rejection time (in milliseconds since epoch start (January 1, 1970
* 00:00:00.000 GMT - Gregorian)) or {@code -1} if there was no foreground rejection
*
* @see #getLastRejectTime(int)
* @see #getLastRejectBackgroundTime(int)
* @see #getLastRejectTime(int, int, int)
* @see OpEntry#getLastRejectForegroundTime(int)
*/
public long getLastRejectForegroundTime(@OpFlags int flags) {
return getLastRejectTime(MAX_PRIORITY_UID_STATE, resolveFirstUnrestrictedUidState(mOp),
flags);
}
/**
* Return the last background rejection time.
*
* @param flags The op flags
*
* @return the last rejection time (in milliseconds since epoch start (January 1, 1970
* 00:00:00.000 GMT - Gregorian)) or {@code -1} if there was no background rejection
*
* @see #getLastRejectTime(int)
* @see #getLastRejectForegroundTime(int)
* @see #getLastRejectTime(int, int, int)
* @see OpEntry#getLastRejectBackgroundTime(int)
*/
public long getLastRejectBackgroundTime(@OpFlags int flags) {
return getLastRejectTime(resolveLastRestrictedUidState(mOp), MIN_PRIORITY_UID_STATE,
flags);
}
/**
* Return the last background rejection event.
*
* @param flags The op flags
*
* @return the last rejection event of {@code null} if there was no rejection
*
* @see #getLastRejectTime(int)
* @see #getLastRejectForegroundTime(int)
* @see #getLastRejectBackgroundTime(int)
* @see OpEntry#getLastRejectTime(int, int, int)
*/
private @Nullable NoteOpEvent getLastRejectEvent(@UidState int fromUidState,
@UidState int toUidState, @OpFlags int flags) {
return getLastEvent(mRejectEvents, fromUidState, toUidState, flags);
}
/**
* Return the last rejection time.
*
* @param fromUidState The lowest UID state for which to query
* @param toUidState The highest UID state for which to query (inclusive)
* @param flags The op flags
*
* @return the last access time (in milliseconds since epoch) or {@code -1} if there was no
* rejection
*
* @see #getLastRejectTime(int)
* @see #getLastRejectForegroundTime(int)
* @see #getLastRejectForegroundTime(int)
* @see #getLastRejectTime(int, int, int)
* @see OpEntry#getLastRejectTime(int, int, int)
*/
public long getLastRejectTime(@UidState int fromUidState, @UidState int toUidState,
@OpFlags int flags) {
NoteOpEvent lastEvent = getLastRejectEvent(fromUidState, toUidState, flags);
if (lastEvent == null) {
return -1;
}
return lastEvent.getNoteTime();
}
/**
* Return the duration in milliseconds of the last the access.
*
* @param flags The op flags
*
* @return the duration in milliseconds or {@code -1} if there was no rejection
*
* @see #getLastForegroundDuration(int)
* @see #getLastBackgroundDuration(int)
* @see #getLastDuration(int, int, int)
* @see OpEntry#getLastDuration(int)
*/
public long getLastDuration(@OpFlags int flags) {
return getLastDuration(MAX_PRIORITY_UID_STATE, MIN_PRIORITY_UID_STATE, flags);
}
/**
* Return the duration in milliseconds of the last foreground access.
*
* @param flags The op flags
*
* @return the duration in milliseconds or {@code -1} if there was no foreground rejection
*
* @see #getLastDuration(int)
* @see #getLastBackgroundDuration(int)
* @see #getLastDuration(int, int, int)
* @see OpEntry#getLastForegroundDuration(int)
*/
public long getLastForegroundDuration(@OpFlags int flags) {
return getLastDuration(MAX_PRIORITY_UID_STATE, resolveFirstUnrestrictedUidState(mOp),
flags);
}
/**
* Return the duration in milliseconds of the last background access.
*
* @param flags The op flags
*
* @return the duration in milliseconds or {@code -1} if there was no background rejection
*
* @see #getLastDuration(int)
* @see #getLastForegroundDuration(int)
* @see #getLastDuration(int, int, int)
* @see OpEntry#getLastBackgroundDuration(int)
*/
public long getLastBackgroundDuration(@OpFlags int flags) {
return getLastDuration(resolveLastRestrictedUidState(mOp), MIN_PRIORITY_UID_STATE,
flags);
}
/**
* Return the duration in milliseconds of the last access.
*
* @param fromUidState The lowest UID state for which to query
* @param toUidState The highest UID state for which to query (inclusive)
* @param flags The op flags
*
* @return the duration in milliseconds or {@code -1} if there was no rejection
*
* @see #getLastDuration(int)
* @see #getLastForegroundDuration(int)
* @see #getLastBackgroundDuration(int)
* @see #getLastDuration(int, int, int)
* @see OpEntry#getLastDuration(int, int, int)
*/
public long getLastDuration(@UidState int fromUidState, @UidState int toUidState,
@OpFlags int flags) {
NoteOpEvent lastEvent = getLastAccessEvent(fromUidState, toUidState, flags);;
if (lastEvent == null) {
return -1;
}
return lastEvent.getDuration();
}
/**
* Gets the proxy info of the app that performed the last access on behalf of this
* attribution and as a result blamed the op on this attribution.
*
* @param flags The op flags
*
* @return The proxy info or {@code null} if there was no proxy access
*
* @see #getLastForegroundProxyInfo(int)
* @see #getLastBackgroundProxyInfo(int)
* @see #getLastProxyInfo(int, int, int)
* @see OpEntry#getLastProxyInfo(int)
*/
public @Nullable OpEventProxyInfo getLastProxyInfo(@OpFlags int flags) {
return getLastProxyInfo(MAX_PRIORITY_UID_STATE, MIN_PRIORITY_UID_STATE, flags);
}
/**
* Gets the proxy info of the app that performed the last foreground access on behalf of
* this attribution and as a result blamed the op on this attribution.
*
* @param flags The op flags
*
* @return The proxy info or {@code null} if there was no proxy access
*
* @see #getLastProxyInfo(int)
* @see #getLastBackgroundProxyInfo(int)
* @see #getLastProxyInfo(int, int, int)
* @see OpEntry#getLastForegroundProxyInfo(int)
*/
public @Nullable OpEventProxyInfo getLastForegroundProxyInfo(@OpFlags int flags) {
return getLastProxyInfo(MAX_PRIORITY_UID_STATE, resolveFirstUnrestrictedUidState(mOp),
flags);
}
/**
* Gets the proxy info of the app that performed the last background access on behalf of
* this attribution and as a result blamed the op on this attribution.
*
* @param flags The op flags
*
* @return The proxy info or {@code null} if there was no proxy background access
*
* @see #getLastProxyInfo(int)
* @see #getLastForegroundProxyInfo(int)
* @see #getLastProxyInfo(int, int, int)
* @see OpEntry#getLastBackgroundProxyInfo(int)
*/
public @Nullable OpEventProxyInfo getLastBackgroundProxyInfo(@OpFlags int flags) {
return getLastProxyInfo(resolveLastRestrictedUidState(mOp), MIN_PRIORITY_UID_STATE,
flags);
}
/**
* Gets the proxy info of the app that performed the last access on behalf of this
* attribution and as a result blamed the op on this attribution.
*
* @param fromUidState The lowest UID state for which to query
* @param toUidState The highest UID state for which to query (inclusive)
* @param flags The op flags
*
* @return The proxy info or {@code null} if there was no proxy foreground access
*
* @see #getLastProxyInfo(int)
* @see #getLastForegroundProxyInfo(int)
* @see #getLastBackgroundProxyInfo(int)
* @see OpEntry#getLastProxyInfo(int, int, int)
*/
public @Nullable OpEventProxyInfo getLastProxyInfo(@UidState int fromUidState,
@UidState int toUidState, @OpFlags int flags) {
NoteOpEvent lastEvent = getLastAccessEvent(fromUidState, toUidState, flags);
if (lastEvent == null) {
return null;
}
return lastEvent.getProxy();
}
@NonNull
String getOpName() {
return AppOpsManager.opToPublicName(mOp);
}
int getOp() {
return mOp;
}
private static class LongSparseArrayParceling implements
Parcelling> {
@Override
public void parcel(@Nullable LongSparseArray array, @NonNull Parcel dest,
int parcelFlags) {
if (array == null) {
dest.writeInt(-1);
return;
}
int numEntries = array.size();
dest.writeInt(numEntries);
for (int i = 0; i < numEntries; i++) {
dest.writeLong(array.keyAt(i));
dest.writeParcelable(array.valueAt(i), parcelFlags);
}
}
@Override
public @Nullable LongSparseArray unparcel(@NonNull Parcel source) {
int numEntries = source.readInt();
if (numEntries == -1) {
return null;
}
LongSparseArray array = new LongSparseArray<>(numEntries);
for (int i = 0; i < numEntries; i++) {
array.put(source.readLong(), source.readParcelable(null, android.app.AppOpsManager.NoteOpEvent.class));
}
return array;
}
}
// Code below generated by codegen v1.0.14.
//
// DO NOT MODIFY!
// CHECKSTYLE:OFF Generated code
//
// To regenerate run:
// $ codegen $ANDROID_BUILD_TOP/frameworks/base/core/java/android/app/AppOpsManager.java
//
// To exclude the generated code from IntelliJ auto-formatting enable (one-time):
// Settings > Editor > Code Style > Formatter Control
//@formatter:off
/**
* Creates a new OpAttributionEntry.
*
* @param op
* The code of the op
* @param running
* Whether the op is running
* @param accessEvents
* The access events
* @param rejectEvents
* The rejection events
* @hide
*/
@DataClass.Generated.Member
public AttributedOpEntry(
@IntRange(from = 0, to = _NUM_OP - 1) int op,
boolean running,
@Nullable LongSparseArray accessEvents,
@Nullable LongSparseArray rejectEvents) {
this.mOp = op;
com.android.internal.util.AnnotationValidations.validate(
IntRange.class, null, mOp,
"from", 0,
"to", _NUM_OP - 1);
this.mRunning = running;
this.mAccessEvents = accessEvents;
this.mRejectEvents = rejectEvents;
// onConstructed(); // You can define this method to get a callback
}
/**
* Whether the op is running
*/
@DataClass.Generated.Member
public boolean isRunning() {
return mRunning;
}
@DataClass.Generated.Member
static Parcelling> sParcellingForAccessEvents =
Parcelling.Cache.get(
LongSparseArrayParceling.class);
static {
if (sParcellingForAccessEvents == null) {
sParcellingForAccessEvents = Parcelling.Cache.put(
new LongSparseArrayParceling());
}
}
@DataClass.Generated.Member
static Parcelling> sParcellingForRejectEvents =
Parcelling.Cache.get(
LongSparseArrayParceling.class);
static {
if (sParcellingForRejectEvents == null) {
sParcellingForRejectEvents = Parcelling.Cache.put(
new LongSparseArrayParceling());
}
}
@Override
@DataClass.Generated.Member
public void writeToParcel(@NonNull Parcel dest, int flags) {
// You can override field parcelling by defining methods like:
// void parcelFieldName(Parcel dest, int flags) { ... }
byte flg = 0;
if (mRunning) flg |= 0x2;
if (mAccessEvents != null) flg |= 0x4;
if (mRejectEvents != null) flg |= 0x8;
dest.writeByte(flg);
dest.writeInt(mOp);
sParcellingForAccessEvents.parcel(mAccessEvents, dest, flags);
sParcellingForRejectEvents.parcel(mRejectEvents, dest, flags);
}
@Override
@DataClass.Generated.Member
public int describeContents() { return 0; }
/** @hide */
@SuppressWarnings({"unchecked", "RedundantCast"})
@DataClass.Generated.Member
/* package-private */ AttributedOpEntry(@NonNull Parcel in) {
// You can override field unparcelling by defining methods like:
// static FieldType unparcelFieldName(Parcel in) { ... }
byte flg = in.readByte();
boolean running = (flg & 0x2) != 0;
int op = in.readInt();
LongSparseArray accessEvents = sParcellingForAccessEvents.unparcel(in);
LongSparseArray rejectEvents = sParcellingForRejectEvents.unparcel(in);
this.mOp = op;
com.android.internal.util.AnnotationValidations.validate(
IntRange.class, null, mOp,
"from", 0,
"to", _NUM_OP - 1);
this.mRunning = running;
this.mAccessEvents = accessEvents;
this.mRejectEvents = rejectEvents;
// onConstructed(); // You can define this method to get a callback
}
@DataClass.Generated.Member
public static final @NonNull Parcelable.Creator CREATOR
= new Parcelable.Creator() {
@Override
public AttributedOpEntry[] newArray(int size) {
return new AttributedOpEntry[size];
}
@Override
public AttributedOpEntry createFromParcel(@NonNull Parcel in) {
return new AttributedOpEntry(in);
}
};
/*
@DataClass.Generated(
time = 1574809856239L,
codegenVersion = "1.0.14",
sourceFile = "frameworks/base/core/java/android/app/AppOpsManager.java",
inputSignatures = "private final @android.annotation.IntRange(from=0L, to=_NUM_OP - 1) int mOp\nprivate final boolean mRunning\nprivate final @com.android.internal.util.DataClass.ParcelWith(android.app.OpAttributionEntry.LongSparseArrayParceling.class) @android.annotation.Nullable android.util.LongSparseArray mAccessEvents\nprivate final @com.android.internal.util.DataClass.ParcelWith(android.app.OpAttributionEntry.LongSparseArrayParceling.class) @android.annotation.Nullable android.util.LongSparseArray mRejectEvents\npublic @android.annotation.NonNull android.util.ArraySet collectKeys()\npublic @android.app.UidState int getLastAccessUidState(int)\npublic @android.app.UidState int getLastForegroundAccessUidState(int)\npublic @android.app.UidState int getLastBackgroundAccessUidState(int)\npublic @android.app.UidState int getLastRejectUidState(int)\npublic @android.app.UidState int getLastForegroundRejectUidState(int)\npublic @android.app.UidState int getLastBackgroundRejectUidState(int)\npublic long getAccessTime(int,int)\npublic long getRejectTime(int,int)\npublic long getDuration(int,int)\npublic int getProxyUid(int,int)\npublic @android.annotation.Nullable java.lang.String getProxyPackageName(int,int)\npublic @android.annotation.Nullable java.lang.String getProxyAttributionTag(int,int)\nclass OpAttributionEntry extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genHiddenConstructor=true)")
@Deprecated
private void __metadata() {}
*/
//@formatter:on
// End of generated code
}
/**
* Last {@link #noteOp} and {@link #startOp} events performed for a single op for all uidModes
* and opFlags.
*
* @hide
*/
@Immutable
@SystemApi
// @DataClass(genHiddenConstructor = true) codegen verifier is broken
public static final class OpEntry implements Parcelable {
/** The code of the op */
private final @IntRange(from = 0, to = _NUM_OP - 1) int mOp;
/** The mode of the op */
private final @Mode int mMode;
/** The attributed entries by attribution tag */
private final @NonNull Map mAttributedOpEntries;
/**
* @hide
*/
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, publicAlternatives = "{@code "
+ "#getOpStr()}")
public int getOp() {
return mOp;
}
/**
* @return This entry's op string name, such as {@link #OPSTR_COARSE_LOCATION}.
*/
public @NonNull String getOpStr() {
return sAppOpInfos[mOp].name;
}
/**
* @hide
*
* @deprecated Use {@link #getLastAccessTime(int)} instead
*/
@Deprecated
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, publicAlternatives = "{@code "
+ "#getLastAccessTime(int)}")
public long getTime() {
return getLastAccessTime(OP_FLAGS_ALL);
}
/**
* Return the last access time.
*
* @param flags The op flags
*
* @return the last access time (in milliseconds since epoch start (January 1, 1970
* 00:00:00.000 GMT - Gregorian)) or {@code -1} if there was no access
*
* @see #getLastAccessForegroundTime(int)
* @see #getLastAccessBackgroundTime(int)
* @see #getLastAccessTime(int, int, int)
* @see AttributedOpEntry#getLastAccessTime(int)
*/
public long getLastAccessTime(@OpFlags int flags) {
return getLastAccessTime(MAX_PRIORITY_UID_STATE, MIN_PRIORITY_UID_STATE, flags);
}
/**
* Return the last foreground access time.
*
* @param flags The op flags
*
* @return the last access time (in milliseconds since epoch start (January 1, 1970
* 00:00:00.000 GMT - Gregorian)) or {@code -1} if there was no foreground access
*
* @see #getLastAccessTime(int)
* @see #getLastAccessBackgroundTime(int)
* @see #getLastAccessTime(int, int, int)
* @see AttributedOpEntry#getLastAccessForegroundTime(int)
*/
public long getLastAccessForegroundTime(@OpFlags int flags) {
return getLastAccessTime(MAX_PRIORITY_UID_STATE, resolveFirstUnrestrictedUidState(mOp),
flags);
}
/**
* Return the last background access time.
*
* @param flags The op flags
*
* @return the last access time (in milliseconds since epoch start (January 1, 1970
* 00:00:00.000 GMT - Gregorian)) or {@code -1} if there was no background access
*
* @see #getLastAccessTime(int)
* @see #getLastAccessForegroundTime(int)
* @see #getLastAccessTime(int, int, int)
* @see AttributedOpEntry#getLastAccessBackgroundTime(int)
*/
public long getLastAccessBackgroundTime(@OpFlags int flags) {
return getLastAccessTime(resolveLastRestrictedUidState(mOp), MIN_PRIORITY_UID_STATE,
flags);
}
/**
* Return the last access event.
*
* @param flags The op flags
*
* @return the last access event of {@code null} if there was no access
*/
private @Nullable NoteOpEvent getLastAccessEvent(@UidState int fromUidState,
@UidState int toUidState, @OpFlags int flags) {
NoteOpEvent lastAccessEvent = null;
for (AttributedOpEntry attributionEntry : mAttributedOpEntries.values()) {
NoteOpEvent lastAttributionAccessEvent = attributionEntry.getLastAccessEvent(
fromUidState, toUidState, flags);
if (lastAccessEvent == null || (lastAttributionAccessEvent != null
&& lastAttributionAccessEvent.getNoteTime()
> lastAccessEvent.getNoteTime())) {
lastAccessEvent = lastAttributionAccessEvent;
}
}
return lastAccessEvent;
}
/**
* Return the last access time.
*
* @param fromUidState the lowest uid state to query
* @param toUidState the highest uid state to query (inclusive)
* @param flags The op flags
*
* @return the last access time (in milliseconds since epoch start (January 1, 1970
* 00:00:00.000 GMT - Gregorian)) or {@code -1} if there was no access
*
* @see #getLastAccessTime(int)
* @see #getLastAccessForegroundTime(int)
* @see #getLastAccessBackgroundTime(int)
* @see AttributedOpEntry#getLastAccessTime(int, int, int)
*/
public long getLastAccessTime(@UidState int fromUidState, @UidState int toUidState,
@OpFlags int flags) {
NoteOpEvent lastEvent = getLastAccessEvent(fromUidState, toUidState, flags);;
if (lastEvent == null) {
return -1;
}
return lastEvent.getNoteTime();
}
/**
* @hide
*
* @deprecated Use {@link #getLastRejectTime(int)} instead
*/
@Deprecated
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, publicAlternatives = "{@code "
+ "#getLastRejectTime(int)}")
public long getRejectTime() {
return getLastRejectTime(OP_FLAGS_ALL);
}
/**
* Return the last rejection time.
*
* @param flags The op flags
*
* @return the last rejection time (in milliseconds since epoch start (January 1, 1970
* 00:00:00.000 GMT - Gregorian)) or {@code -1} if there was no rejection
*
* @see #getLastRejectForegroundTime(int)
* @see #getLastRejectBackgroundTime(int)
* @see #getLastRejectTime(int, int, int)
* @see AttributedOpEntry#getLastRejectTime(int)
*/
public long getLastRejectTime(@OpFlags int flags) {
return getLastRejectTime(MAX_PRIORITY_UID_STATE, MIN_PRIORITY_UID_STATE, flags);
}
/**
* Return the last foreground rejection time.
*
* @param flags The op flags
*
* @return the last rejection time (in milliseconds since epoch start (January 1, 1970
* 00:00:00.000 GMT - Gregorian)) or {@code -1} if there was no foreground rejection
*
* @see #getLastRejectTime(int)
* @see #getLastRejectBackgroundTime(int)
* @see #getLastRejectTime(int, int, int)
* @see AttributedOpEntry#getLastRejectForegroundTime(int)
*/
public long getLastRejectForegroundTime(@OpFlags int flags) {
return getLastRejectTime(MAX_PRIORITY_UID_STATE, resolveFirstUnrestrictedUidState(mOp),
flags);
}
/**
* Return the last background rejection time.
*
* @param flags The op flags
*
* @return the last rejection time (in milliseconds since epoch start (January 1, 1970
* 00:00:00.000 GMT - Gregorian)) or {@code -1} if there was no background rejection
*
* @see #getLastRejectTime(int)
* @see #getLastRejectForegroundTime(int)
* @see #getLastRejectTime(int, int, int)
* @see AttributedOpEntry#getLastRejectBackgroundTime(int)
*/
public long getLastRejectBackgroundTime(@OpFlags int flags) {
return getLastRejectTime(resolveLastRestrictedUidState(mOp), MIN_PRIORITY_UID_STATE,
flags);
}
/**
* Return the last rejection event.
*
* @param flags The op flags
*
* @return the last reject event of {@code null} if there was no rejection
*/
private @Nullable NoteOpEvent getLastRejectEvent(@UidState int fromUidState,
@UidState int toUidState, @OpFlags int flags) {
NoteOpEvent lastRejectEvent = null;
for (AttributedOpEntry attributionEntry : mAttributedOpEntries.values()) {
NoteOpEvent lastAttributionRejectEvent = attributionEntry.getLastRejectEvent(
fromUidState, toUidState, flags);
if (lastRejectEvent == null || (lastAttributionRejectEvent != null
&& lastAttributionRejectEvent.getNoteTime()
> lastRejectEvent.getNoteTime())) {
lastRejectEvent = lastAttributionRejectEvent;
}
}
return lastRejectEvent;
}
/**
* Return the last rejection time.
*
* @param fromUidState the lowest uid state to query
* @param toUidState the highest uid state to query (inclusive)
* @param flags The op flags
*
* @return the last rejection time (in milliseconds since epoch start (January 1, 1970
* 00:00:00.000 GMT - Gregorian)) or {@code -1} if there was no rejection
*
* @see #getLastRejectTime(int)
* @see #getLastRejectForegroundTime(int)
* @see #getLastRejectBackgroundTime(int)
* @see #getLastRejectTime(int, int, int)
* @see AttributedOpEntry#getLastRejectTime(int, int, int)
*/
public long getLastRejectTime(@UidState int fromUidState, @UidState int toUidState,
@OpFlags int flags) {
NoteOpEvent lastEvent = getLastRejectEvent(fromUidState, toUidState, flags);
if (lastEvent == null) {
return -1;
}
return lastEvent.getNoteTime();
}
/**
* @return Whether the operation is running.
*/
public boolean isRunning() {
for (AttributedOpEntry opAttributionEntry : mAttributedOpEntries.values()) {
if (opAttributionEntry.isRunning()) {
return true;
}
}
return false;
}
/**
* @deprecated Use {@link #getLastDuration(int)} instead
*/
@Deprecated
public long getDuration() {
return getLastDuration(OP_FLAGS_ALL);
}
/**
* Return the duration in milliseconds of the last the access.
*
* @param flags The op flags
*
* @return the duration in milliseconds or {@code -1} if there was no access
*
* @see #getLastForegroundDuration(int)
* @see #getLastBackgroundDuration(int)
* @see #getLastDuration(int, int, int)
* @see AttributedOpEntry#getLastDuration(int)
*/
public long getLastDuration(@OpFlags int flags) {
return getLastDuration(MAX_PRIORITY_UID_STATE, MIN_PRIORITY_UID_STATE, flags);
}
/**
* Return the duration in milliseconds of the last foreground access.
*
* @param flags The op flags
*
* @return the duration in milliseconds or {@code -1} if there was no foreground access
*
* @see #getLastDuration(int)
* @see #getLastBackgroundDuration(int)
* @see #getLastDuration(int, int, int)
* @see AttributedOpEntry#getLastForegroundDuration(int)
*/
public long getLastForegroundDuration(@OpFlags int flags) {
return getLastDuration(MAX_PRIORITY_UID_STATE, resolveFirstUnrestrictedUidState(mOp),
flags);
}
/**
* Return the duration in milliseconds of the last background access.
*
* @param flags The op flags
*
* @return the duration in milliseconds or {@code -1} if there was no background access
*
* @see #getLastDuration(int)
* @see #getLastForegroundDuration(int)
* @see #getLastDuration(int, int, int)
* @see AttributedOpEntry#getLastBackgroundDuration(int)
*/
public long getLastBackgroundDuration(@OpFlags int flags) {
return getLastDuration(resolveLastRestrictedUidState(mOp), MIN_PRIORITY_UID_STATE,
flags);
}
/**
* Return the duration in milliseconds of the last access.
*
* @param fromUidState The lowest UID state for which to query
* @param toUidState The highest UID state for which to query (inclusive)
* @param flags The op flags
*
* @return the duration in milliseconds or {@code -1} if there was no access
*
* @see #getLastDuration(int)
* @see #getLastForegroundDuration(int)
* @see #getLastBackgroundDuration(int)
* @see AttributedOpEntry#getLastDuration(int, int, int)
*/
public long getLastDuration(@UidState int fromUidState, @UidState int toUidState,
@OpFlags int flags) {
NoteOpEvent lastEvent = getLastAccessEvent(fromUidState, toUidState, flags);
if (lastEvent == null) {
return -1;
}
return lastEvent.getDuration();
}
/**
* @deprecated Use {@link #getLastProxyInfo(int)} instead
*/
@Deprecated
public int getProxyUid() {
OpEventProxyInfo proxy = getLastProxyInfo(OP_FLAGS_ALL);
if (proxy == null) {
return Process.INVALID_UID;
}
return proxy.getUid();
}
/**
* @deprecated Use {@link #getLastProxyInfo(int)} instead
*/
@Deprecated
public int getProxyUid(@UidState int uidState, @OpFlags int flags) {
OpEventProxyInfo proxy = getLastProxyInfo(uidState, uidState, flags);
if (proxy == null) {
return Process.INVALID_UID;
}
return proxy.getUid();
}
/**
* @deprecated Use {@link #getLastProxyInfo(int)} instead
*/
@Deprecated
public @Nullable String getProxyPackageName() {
OpEventProxyInfo proxy = getLastProxyInfo(OP_FLAGS_ALL);
if (proxy == null) {
return null;
}
return proxy.getPackageName();
}
/**
* @deprecated Use {@link #getLastProxyInfo(int)} instead
*/
@Deprecated
public @Nullable String getProxyPackageName(@UidState int uidState, @OpFlags int flags) {
OpEventProxyInfo proxy = getLastProxyInfo(uidState, uidState, flags);
if (proxy == null) {
return null;
}
return proxy.getPackageName();
}
/**
* Gets the proxy info of the app that performed the last access on behalf of this app and
* as a result blamed the op on this app.
*
* @param flags The op flags
*
* @return The proxy info or {@code null} if there was no proxy access
*
* @see #getLastForegroundProxyInfo(int)
* @see #getLastBackgroundProxyInfo(int)
* @see #getLastProxyInfo(int, int, int)
* @see AttributedOpEntry#getLastProxyInfo(int)
*/
public @Nullable OpEventProxyInfo getLastProxyInfo(@OpFlags int flags) {
return getLastProxyInfo(MAX_PRIORITY_UID_STATE, MIN_PRIORITY_UID_STATE, flags);
}
/**
* Gets the proxy info of the app that performed the last foreground access on behalf of
* this app and as a result blamed the op on this app.
*
* @param flags The op flags
*
* @return The proxy info or {@code null} if there was no foreground proxy access
*
* @see #getLastProxyInfo(int)
* @see #getLastBackgroundProxyInfo(int)
* @see #getLastProxyInfo(int, int, int)
* @see AttributedOpEntry#getLastForegroundProxyInfo(int)
*/
public @Nullable OpEventProxyInfo getLastForegroundProxyInfo(@OpFlags int flags) {
return getLastProxyInfo(MAX_PRIORITY_UID_STATE, resolveFirstUnrestrictedUidState(mOp),
flags);
}
/**
* Gets the proxy info of the app that performed the last background access on behalf of
* this app and as a result blamed the op on this app.
*
* @param flags The op flags
*
* @return The proxy info or {@code null} if there was no background proxy access
*
* @see #getLastProxyInfo(int)
* @see #getLastForegroundProxyInfo(int)
* @see #getLastProxyInfo(int, int, int)
* @see AttributedOpEntry#getLastBackgroundProxyInfo(int)
*/
public @Nullable OpEventProxyInfo getLastBackgroundProxyInfo(@OpFlags int flags) {
return getLastProxyInfo(resolveLastRestrictedUidState(mOp), MIN_PRIORITY_UID_STATE,
flags);
}
/**
* Gets the proxy info of the app that performed the last access on behalf of this app and
* as a result blamed the op on this app.
*
* @param fromUidState The lowest UID state for which to query
* @param toUidState The highest UID state for which to query (inclusive)
* @param flags The op flags
*
* @return The proxy info or {@code null} if there was no proxy access
*
* @see #getLastProxyInfo(int)
* @see #getLastForegroundProxyInfo(int)
* @see #getLastBackgroundProxyInfo(int)
* @see AttributedOpEntry#getLastProxyInfo(int, int, int)
*/
public @Nullable OpEventProxyInfo getLastProxyInfo(@UidState int fromUidState,
@UidState int toUidState, @OpFlags int flags) {
NoteOpEvent lastEvent = getLastAccessEvent(fromUidState, toUidState, flags);
if (lastEvent == null) {
return null;
}
return lastEvent.getProxy();
}
// Code below generated by codegen v1.0.14.
//
// DO NOT MODIFY!
// CHECKSTYLE:OFF Generated code
//
// To regenerate run:
// $ codegen $ANDROID_BUILD_TOP/frameworks/base/core/java/android/app/AppOpsManager.java
//
// To exclude the generated code from IntelliJ auto-formatting enable (one-time):
// Settings > Editor > Code Style > Formatter Control
//@formatter:off
/**
* Creates a new OpEntry.
*
* @param op
* The code of the op
* @param mode
* The mode of the op
* @param attributedOpEntries
* The attributions that have been used when noting the op
* @hide
*/
@DataClass.Generated.Member
public OpEntry(
@IntRange(from = 0, to = _NUM_OP - 1) int op,
@Mode int mode,
@NonNull Map attributedOpEntries) {
this.mOp = op;
com.android.internal.util.AnnotationValidations.validate(
IntRange.class, null, mOp,
"from", 0,
"to", _NUM_OP - 1);
this.mMode = mode;
com.android.internal.util.AnnotationValidations.validate(
Mode.class, null, mMode);
this.mAttributedOpEntries = attributedOpEntries;
com.android.internal.util.AnnotationValidations.validate(
NonNull.class, null, mAttributedOpEntries);
// onConstructed(); // You can define this method to get a callback
}
/**
* The mode of the op
*/
@DataClass.Generated.Member
public @Mode int getMode() {
return mMode;
}
/**
* The attributed entries keyed by attribution tag.
*
* @see Context#createAttributionContext(String)
* @see #noteOp(String, int, String, String, String)
*/
@DataClass.Generated.Member
public @NonNull Map getAttributedOpEntries() {
return mAttributedOpEntries;
}
@Override
@DataClass.Generated.Member
public void writeToParcel(Parcel dest, int flags) {
// You can override field parcelling by defining methods like:
// void parcelFieldName(Parcel dest, int flags) { ... }
dest.writeInt(mOp);
dest.writeInt(mMode);
dest.writeMap(mAttributedOpEntries);
}
@Override
@DataClass.Generated.Member
public int describeContents() { return 0; }
/** @hide */
@SuppressWarnings({"unchecked", "RedundantCast"})
@DataClass.Generated.Member
/* package-private */ OpEntry(@NonNull Parcel in) {
// You can override field unparcelling by defining methods like:
// static FieldType unparcelFieldName(Parcel in) { ... }
int op = in.readInt();
int mode = in.readInt();
Map attributions = new java.util.LinkedHashMap<>();
in.readMap(attributions, AttributedOpEntry.class.getClassLoader());
this.mOp = op;
com.android.internal.util.AnnotationValidations.validate(
IntRange.class, null, mOp,
"from", 0,
"to", _NUM_OP - 1);
this.mMode = mode;
com.android.internal.util.AnnotationValidations.validate(
Mode.class, null, mMode);
this.mAttributedOpEntries = attributions;
com.android.internal.util.AnnotationValidations.validate(
NonNull.class, null, mAttributedOpEntries);
// onConstructed(); // You can define this method to get a callback
}
@DataClass.Generated.Member
public static final @NonNull Parcelable.Creator CREATOR
= new Parcelable.Creator() {
@Override
public OpEntry[] newArray(int size) {
return new OpEntry[size];
}
@Override
public OpEntry createFromParcel(@NonNull Parcel in) {
return new OpEntry(in);
}
};
/*
@DataClass.Generated(
time = 1574809856259L,
codegenVersion = "1.0.14",
sourceFile = "frameworks/base/core/java/android/app/AppOpsManager.java",
inputSignatures = "private final @android.annotation.IntRange(from=0L, to=_NUM_OP - 1) int mOp\nprivate final @android.app.Mode int mMode\nprivate final @android.annotation.NonNull java.util.Map mAttributions\npublic @android.annotation.UnsupportedAppUsage(maxTargetSdk=Build.VERSION_CODES.Q, publicAlternatives=\"{@code \" + \"#getOpStr()}\") int getOp()\npublic @android.annotation.NonNull java.lang.String getOpStr()\npublic @java.lang.Deprecated @android.annotation.UnsupportedAppUsage(maxTargetSdk=Build.VERSION_CODES.Q, publicAlternatives=\"{@code \" + \"#getAccessTime(int, int)}\") long getTime()\npublic @java.lang.Deprecated long getLastAccessTime(int)\npublic @java.lang.Deprecated long getLastAccessForegroundTime(int)\npublic @java.lang.Deprecated long getLastAccessBackgroundTime(int)\npublic @java.lang.Deprecated long getLastAccessTime(int,int,int)\npublic @java.lang.Deprecated @android.annotation.UnsupportedAppUsage(maxTargetSdk=Build.VERSION_CODES.Q, publicAlternatives=\"{@code \" + \"#getLastRejectTime(int, int, int)}\") long getRejectTime()\npublic @java.lang.Deprecated long getLastRejectTime(int)\npublic @java.lang.Deprecated long getLastRejectForegroundTime(int)\npublic @java.lang.Deprecated long getLastRejectBackgroundTime(int)\npublic @java.lang.Deprecated long getLastRejectTime(int,int,int)\npublic long getAccessTime(int,int)\npublic long getRejectTime(int,int)\npublic boolean isRunning()\nprivate android.app.NoteOpEvent getLastAccessEvent(int,int,int)\npublic @java.lang.Deprecated long getDuration()\npublic @java.lang.Deprecated long getLastForegroundDuration(int)\npublic @java.lang.Deprecated long getLastBackgroundDuration(int)\npublic @java.lang.Deprecated long getLastDuration(int,int,int)\npublic @java.lang.Deprecated int getProxyUid()\npublic @java.lang.Deprecated @android.annotation.Nullable java.lang.String getProxyPackageName()\nprivate @android.app.UidState int getLastAccessUidStateForFlagsInStatesOfAllAttributions(int,int,int)\npublic @android.app.UidState int getLastAccessUidState(int)\npublic @android.app.UidState int getLastForegroundAccessUidState(int)\npublic @android.app.UidState int getLastBackgroundAccessUidState(int)\nprivate @android.app.UidState int getLastRejectUidStateForFlagsInStatesOfAllAttributions(int,int,int)\npublic @android.app.UidState int getLastRejectUidState(int)\npublic @android.app.UidState int getLastForegroundRejectUidState(int)\npublic @android.app.UidState int getLastBackgroundRejectUidState(int)\npublic long getDuration(int,int)\npublic int getProxyUid(int,int)\nprivate int getProxyUid(int,int,int)\npublic @android.annotation.Nullable java.lang.String getProxyPackageName(int,int)\nprivate @android.annotation.Nullable java.lang.String getProxyPackageName(int,int,int)\nclass OpEntry extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genHiddenConstructor=true)")
@Deprecated
private void __metadata() {}
*/
//@formatter:on
// End of generated code
}
/** @hide */
public interface HistoricalOpsVisitor {
void visitHistoricalOps(@NonNull HistoricalOps ops);
void visitHistoricalUidOps(@NonNull HistoricalUidOps ops);
void visitHistoricalPackageOps(@NonNull HistoricalPackageOps ops);
void visitHistoricalAttributionOps(@NonNull AttributedHistoricalOps ops);
void visitHistoricalOp(@NonNull HistoricalOp ops);
}
/**
* Flag for querying app op history: get only aggregate information (counts of events) and no
* discret accesses information - specific accesses with timestamp.
*
* @see #getHistoricalOps(HistoricalOpsRequest, Executor, Consumer)
*
* @hide
*/
@TestApi
@SystemApi
public static final int HISTORY_FLAG_AGGREGATE = 1 << 0;
/**
* Flag for querying app op history: get only discrete access information (only specific
* accesses with timestamps) and no aggregate information (counts over time).
*
* @see #getHistoricalOps(HistoricalOpsRequest, Executor, Consumer)
*
* @hide
*/
@TestApi
@SystemApi
public static final int HISTORY_FLAG_DISCRETE = 1 << 1;
/**
* Flag for querying app op history: assemble attribution chains, and attach the last visible
* node in the chain to the start as a proxy info. This only applies to discrete accesses.
*
* @hide
*/
@SystemApi
public static final int HISTORY_FLAG_GET_ATTRIBUTION_CHAINS = 1 << 2;
/**
* Flag for querying app op history: get all types of historical access information.
*
* @see #getHistoricalOps(HistoricalOpsRequest, Executor, Consumer)
*
* @hide
*/
@TestApi
@SystemApi
public static final int HISTORY_FLAGS_ALL = HISTORY_FLAG_AGGREGATE
| HISTORY_FLAG_DISCRETE;
/** @hide */
@Retention(RetentionPolicy.SOURCE)
@IntDef(flag = true, prefix = { "HISTORY_FLAG_" }, value = {
HISTORY_FLAG_AGGREGATE,
HISTORY_FLAG_DISCRETE,
HISTORY_FLAG_GET_ATTRIBUTION_CHAINS
})
public @interface OpHistoryFlags {}
/**
* Specifies what parameters to filter historical appop requests for
*
* @hide
*/
@Retention(RetentionPolicy.SOURCE)
@IntDef(flag = true, prefix = { "FILTER_BY_" }, value = {
FILTER_BY_UID,
FILTER_BY_PACKAGE_NAME,
FILTER_BY_ATTRIBUTION_TAG,
FILTER_BY_OP_NAMES
})
public @interface HistoricalOpsRequestFilter {}
/**
* Filter historical appop request by uid.
*
* @hide
*/
public static final int FILTER_BY_UID = 1<<0;
/**
* Filter historical appop request by package name.
*
* @hide
*/
public static final int FILTER_BY_PACKAGE_NAME = 1<<1;
/**
* Filter historical appop request by attribution tag.
*
* @hide
*/
public static final int FILTER_BY_ATTRIBUTION_TAG = 1<<2;
/**
* Filter historical appop request by op names.
*
* @hide
*/
public static final int FILTER_BY_OP_NAMES = 1<<3;
/**
* Request for getting historical app op usage. The request acts
* as a filtering criteria when querying historical op usage.
*
* @hide
*/
@Immutable
@SystemApi
public static final class HistoricalOpsRequest {
private final int mUid;
private final @Nullable String mPackageName;
private final @Nullable String mAttributionTag;
private final @Nullable List mOpNames;
private final @OpHistoryFlags int mHistoryFlags;
private final @HistoricalOpsRequestFilter int mFilter;
private final long mBeginTimeMillis;
private final long mEndTimeMillis;
private final @OpFlags int mFlags;
private HistoricalOpsRequest(int uid, @Nullable String packageName,
@Nullable String attributionTag, @Nullable List opNames,
@OpHistoryFlags int historyFlags, @HistoricalOpsRequestFilter int filter,
long beginTimeMillis, long endTimeMillis, @OpFlags int flags) {
mUid = uid;
mPackageName = packageName;
mAttributionTag = attributionTag;
mOpNames = opNames;
mHistoryFlags = historyFlags;
mFilter = filter;
mBeginTimeMillis = beginTimeMillis;
mEndTimeMillis = endTimeMillis;
mFlags = flags;
}
/**
* Builder for creating a {@link HistoricalOpsRequest}.
*
* @hide
*/
@SystemApi
public static final class Builder {
private int mUid = Process.INVALID_UID;
private @Nullable String mPackageName;
private @Nullable String mAttributionTag;
private @Nullable List mOpNames;
private @OpHistoryFlags int mHistoryFlags;
private @HistoricalOpsRequestFilter int mFilter;
private final long mBeginTimeMillis;
private final long mEndTimeMillis;
private @OpFlags int mFlags = OP_FLAGS_ALL;
/**
* Creates a new builder.
*
* @param beginTimeMillis The beginning of the interval in milliseconds since
* epoch start (January 1, 1970 00:00:00.000 GMT - Gregorian). Must be non
* negative.
* @param endTimeMillis The end of the interval in milliseconds since
* epoch start (January 1, 1970 00:00:00.000 GMT - Gregorian). Must be after
* {@code beginTimeMillis}. Pass {@link Long#MAX_VALUE} to get the most recent
* history including ops that happen while this call is in flight.
*/
public Builder(long beginTimeMillis, long endTimeMillis) {
Preconditions.checkArgument(beginTimeMillis >= 0 && beginTimeMillis < endTimeMillis,
"beginTimeMillis must be non negative and lesser than endTimeMillis");
mBeginTimeMillis = beginTimeMillis;
mEndTimeMillis = endTimeMillis;
mHistoryFlags = HISTORY_FLAG_AGGREGATE;
}
/**
* Sets the UID to query for.
*
* @param uid The uid. Pass {@link android.os.Process#INVALID_UID} for any uid.
* @return This builder.
*/
public @NonNull Builder setUid(int uid) {
Preconditions.checkArgument(uid == Process.INVALID_UID || uid >= 0,
"uid must be " + Process.INVALID_UID + " or non negative");
mUid = uid;
if (uid == Process.INVALID_UID) {
mFilter &= ~FILTER_BY_UID;
} else {
mFilter |= FILTER_BY_UID;
}
return this;
}
/**
* Sets the package to query for.
*
* @param packageName The package name. Null for any package.
* @return This builder.
*/
public @NonNull Builder setPackageName(@Nullable String packageName) {
mPackageName = packageName;
if (packageName == null) {
mFilter &= ~FILTER_BY_PACKAGE_NAME;
} else {
mFilter |= FILTER_BY_PACKAGE_NAME;
}
return this;
}
/**
* Sets the attribution tag to query for.
*
* @param attributionTag attribution tag
* @return This builder.
*/
public @NonNull Builder setAttributionTag(@Nullable String attributionTag) {
mAttributionTag = attributionTag;
mFilter |= FILTER_BY_ATTRIBUTION_TAG;
return this;
}
/**
* Sets the op names to query for.
*
* @param opNames The op names. Null for any op.
* @return This builder.
*/
public @NonNull Builder setOpNames(@Nullable List opNames) {
if (opNames != null) {
final int opCount = opNames.size();
for (int i = 0; i < opCount; i++) {
Preconditions.checkArgument(AppOpsManager.strOpToOp(
opNames.get(i)) != AppOpsManager.OP_NONE);
}
}
mOpNames = opNames;
if (mOpNames == null) {
mFilter &= ~FILTER_BY_OP_NAMES;
} else {
mFilter |= FILTER_BY_OP_NAMES;
}
return this;
}
/**
* Sets the op flags to query for. The flags specify the type of
* op data being queried.
*
* @param flags The flags which are any combination of
* {@link #OP_FLAG_SELF}, {@link #OP_FLAG_TRUSTED_PROXY},
* {@link #OP_FLAG_UNTRUSTED_PROXY}, {@link #OP_FLAG_TRUSTED_PROXIED},
* {@link #OP_FLAG_UNTRUSTED_PROXIED}. You can use {@link #OP_FLAGS_ALL}
* for any flag.
* @return This builder.
*/
public @NonNull Builder setFlags(@OpFlags int flags) {
Preconditions.checkFlagsArgument(flags, OP_FLAGS_ALL);
mFlags = flags;
return this;
}
/**
* Specifies what type of historical information to query.
*
* @param flags Flags for the historical types to fetch which are any
* combination of {@link #HISTORY_FLAG_AGGREGATE}, {@link #HISTORY_FLAG_DISCRETE},
* {@link #HISTORY_FLAGS_ALL}. The default is {@link #HISTORY_FLAG_AGGREGATE}.
* @return This builder.
*/
public @NonNull Builder setHistoryFlags(@OpHistoryFlags int flags) {
Preconditions.checkFlagsArgument(flags,
HISTORY_FLAGS_ALL | HISTORY_FLAG_GET_ATTRIBUTION_CHAINS);
mHistoryFlags = flags;
return this;
}
/**
* @return a new {@link HistoricalOpsRequest}.
*/
public @NonNull HistoricalOpsRequest build() {
return new HistoricalOpsRequest(mUid, mPackageName, mAttributionTag, mOpNames,
mHistoryFlags, mFilter, mBeginTimeMillis, mEndTimeMillis, mFlags);
}
}
}
/**
* This class represents historical app op state of all UIDs for a given time interval.
*
* @hide
*/
@SystemApi
public static final class HistoricalOps implements Parcelable {
private long mBeginTimeMillis;
private long mEndTimeMillis;
private @Nullable SparseArray mHistoricalUidOps;
/** @hide */
@TestApi
public HistoricalOps(long beginTimeMillis, long endTimeMillis) {
Preconditions.checkState(beginTimeMillis <= endTimeMillis);
mBeginTimeMillis = beginTimeMillis;
mEndTimeMillis = endTimeMillis;
}
/** @hide */
public HistoricalOps(@NonNull HistoricalOps other) {
mBeginTimeMillis = other.mBeginTimeMillis;
mEndTimeMillis = other.mEndTimeMillis;
Preconditions.checkState(mBeginTimeMillis <= mEndTimeMillis);
if (other.mHistoricalUidOps != null) {
final int opCount = other.getUidCount();
for (int i = 0; i < opCount; i++) {
final HistoricalUidOps origOps = other.getUidOpsAt(i);
final HistoricalUidOps clonedOps = new HistoricalUidOps(origOps);
if (mHistoricalUidOps == null) {
mHistoricalUidOps = new SparseArray<>(opCount);
}
mHistoricalUidOps.put(clonedOps.getUid(), clonedOps);
}
}
}
private HistoricalOps(Parcel parcel) {
mBeginTimeMillis = parcel.readLong();
mEndTimeMillis = parcel.readLong();
final int[] uids = parcel.createIntArray();
if (!ArrayUtils.isEmpty(uids)) {
final ParceledListSlice listSlice = parcel.readParcelable(
HistoricalOps.class.getClassLoader(), android.content.pm.ParceledListSlice.class);
final List uidOps = (listSlice != null)
? listSlice.getList() : null;
if (uidOps == null) {
return;
}
for (int i = 0; i < uids.length; i++) {
if (mHistoricalUidOps == null) {
mHistoricalUidOps = new SparseArray<>();
}
mHistoricalUidOps.put(uids[i], uidOps.get(i));
}
}
}
/**
* Splice a piece from the beginning of these ops.
*
* @param splicePoint The fraction of the data to be spliced off.
*
* @hide
*/
public @NonNull HistoricalOps spliceFromBeginning(double splicePoint) {
return splice(splicePoint, true);
}
/**
* Splice a piece from the end of these ops.
*
* @param fractionToRemove The fraction of the data to be spliced off.
*
* @hide
*/
public @NonNull HistoricalOps spliceFromEnd(double fractionToRemove) {
return splice(fractionToRemove, false);
}
/**
* Splice a piece from the beginning or end of these ops.
*
* @param fractionToRemove The fraction of the data to be spliced off.
* @param beginning Whether to splice off the beginning or the end.
*
* @return The spliced off part.
*
* @hide
*/
private @Nullable HistoricalOps splice(double fractionToRemove, boolean beginning) {
final long spliceBeginTimeMills;
final long spliceEndTimeMills;
if (beginning) {
spliceBeginTimeMills = mBeginTimeMillis;
spliceEndTimeMills = (long) (mBeginTimeMillis
+ getDurationMillis() * fractionToRemove);
mBeginTimeMillis = spliceEndTimeMills;
} else {
spliceBeginTimeMills = (long) (mEndTimeMillis
- getDurationMillis() * fractionToRemove);
spliceEndTimeMills = mEndTimeMillis;
mEndTimeMillis = spliceBeginTimeMills;
}
HistoricalOps splice = null;
final int uidCount = getUidCount();
for (int i = 0; i < uidCount; i++) {
final HistoricalUidOps origOps = getUidOpsAt(i);
final HistoricalUidOps spliceOps = origOps.splice(fractionToRemove);
if (spliceOps != null) {
if (splice == null) {
splice = new HistoricalOps(spliceBeginTimeMills, spliceEndTimeMills);
}
if (splice.mHistoricalUidOps == null) {
splice.mHistoricalUidOps = new SparseArray<>();
}
splice.mHistoricalUidOps.put(spliceOps.getUid(), spliceOps);
}
}
return splice;
}
/**
* Merge the passed ops into the current ones. The time interval is a
* union of the current and passed in one and the passed in data is
* folded into the data of this instance.
*
* @hide
*/
public void merge(@NonNull HistoricalOps other) {
mBeginTimeMillis = Math.min(mBeginTimeMillis, other.mBeginTimeMillis);
mEndTimeMillis = Math.max(mEndTimeMillis, other.mEndTimeMillis);
final int uidCount = other.getUidCount();
for (int i = 0; i < uidCount; i++) {
final HistoricalUidOps otherUidOps = other.getUidOpsAt(i);
final HistoricalUidOps thisUidOps = getUidOps(otherUidOps.getUid());
if (thisUidOps != null) {
thisUidOps.merge(otherUidOps);
} else {
if (mHistoricalUidOps == null) {
mHistoricalUidOps = new SparseArray<>();
}
mHistoricalUidOps.put(otherUidOps.getUid(), otherUidOps);
}
}
}
/**
* AppPermissionUsage the ops to leave only the data we filter for.
*
* @param uid Uid to filter for.
* @param packageName Package to filter for.
* @param attributionTag attribution tag to filter for
* @param opNames Ops to filter for.
* @param filter Which parameters to filter on.
* @param beginTimeMillis The begin time to filter for or {@link Long#MIN_VALUE} for all.
* @param endTimeMillis The end time to filter for or {@link Long#MAX_VALUE} for all.
*
* @hide
*/
public void filter(int uid, @Nullable String packageName, @Nullable String attributionTag,
@Nullable String[] opNames, @OpHistoryFlags int historyFilter,
@HistoricalOpsRequestFilter int filter,
long beginTimeMillis, long endTimeMillis) {
final long durationMillis = getDurationMillis();
mBeginTimeMillis = Math.max(mBeginTimeMillis, beginTimeMillis);
mEndTimeMillis = Math.min(mEndTimeMillis, endTimeMillis);
final double scaleFactor = Math.min((double) (endTimeMillis - beginTimeMillis)
/ (double) durationMillis, 1);
final int uidCount = getUidCount();
for (int i = uidCount - 1; i >= 0; i--) {
final HistoricalUidOps uidOp = mHistoricalUidOps.valueAt(i);
if ((filter & FILTER_BY_UID) != 0 && uid != uidOp.getUid()) {
mHistoricalUidOps.removeAt(i);
} else {
uidOp.filter(packageName, attributionTag, opNames, filter, historyFilter,
scaleFactor, mBeginTimeMillis, mEndTimeMillis);
if (uidOp.getPackageCount() == 0) {
mHistoricalUidOps.removeAt(i);
}
}
}
}
/** @hide */
public boolean isEmpty() {
if (getBeginTimeMillis() >= getEndTimeMillis()) {
return true;
}
final int uidCount = getUidCount();
for (int i = uidCount - 1; i >= 0; i--) {
final HistoricalUidOps uidOp = mHistoricalUidOps.valueAt(i);
if (!uidOp.isEmpty()) {
return false;
}
}
return true;
}
/** @hide */
public long getDurationMillis() {
return mEndTimeMillis - mBeginTimeMillis;
}
/** @hide */
@TestApi
public void increaseAccessCount(int opCode, int uid, @NonNull String packageName,
@Nullable String attributionTag, @UidState int uidState, @OpFlags int flags,
long increment) {
getOrCreateHistoricalUidOps(uid).increaseAccessCount(opCode,
packageName, attributionTag, uidState, flags, increment);
}
/** @hide */
@TestApi
public void increaseRejectCount(int opCode, int uid, @NonNull String packageName,
@Nullable String attributionTag, @UidState int uidState, @OpFlags int flags,
long increment) {
getOrCreateHistoricalUidOps(uid).increaseRejectCount(opCode,
packageName, attributionTag, uidState, flags, increment);
}
/** @hide */
@TestApi
public void increaseAccessDuration(int opCode, int uid, @NonNull String packageName,
@Nullable String attributionTag, @UidState int uidState, @OpFlags int flags,
long increment) {
getOrCreateHistoricalUidOps(uid).increaseAccessDuration(opCode,
packageName, attributionTag, uidState, flags, increment);
}
/** @hide */
@TestApi
public void addDiscreteAccess(int opCode, int uid, @NonNull String packageName,
@Nullable String attributionTag, @UidState int uidState, @OpFlags int opFlag,
long discreteAccessTime, long discreteAccessDuration) {
getOrCreateHistoricalUidOps(uid).addDiscreteAccess(opCode, packageName, attributionTag,
uidState, opFlag, discreteAccessTime, discreteAccessDuration, null);
}
/** @hide */
public void addDiscreteAccess(int opCode, int uid, @NonNull String packageName,
@Nullable String attributionTag, @UidState int uidState, @OpFlags int opFlag,
long discreteAccessTime, long discreteAccessDuration,
@Nullable OpEventProxyInfo proxy) {
getOrCreateHistoricalUidOps(uid).addDiscreteAccess(opCode, packageName, attributionTag,
uidState, opFlag, discreteAccessTime, discreteAccessDuration, proxy);
}
/** @hide */
@TestApi
public void offsetBeginAndEndTime(long offsetMillis) {
mBeginTimeMillis += offsetMillis;
mEndTimeMillis += offsetMillis;
}
/** @hide */
public void setBeginAndEndTime(long beginTimeMillis, long endTimeMillis) {
mBeginTimeMillis = beginTimeMillis;
mEndTimeMillis = endTimeMillis;
}
/** @hide */
public void setBeginTime(long beginTimeMillis) {
mBeginTimeMillis = beginTimeMillis;
}
/** @hide */
public void setEndTime(long endTimeMillis) {
mEndTimeMillis = endTimeMillis;
}
/**
* @return The beginning of the interval in milliseconds since
* epoch start (January 1, 1970 00:00:00.000 GMT - Gregorian).
*/
public long getBeginTimeMillis() {
return mBeginTimeMillis;
}
/**
* @return The end of the interval in milliseconds since
* epoch start (January 1, 1970 00:00:00.000 GMT - Gregorian).
*/
public long getEndTimeMillis() {
return mEndTimeMillis;
}
/**
* Gets number of UIDs with historical ops.
*
* @return The number of UIDs with historical ops.
*
* @see #getUidOpsAt(int)
*/
public @IntRange(from = 0) int getUidCount() {
if (mHistoricalUidOps == null) {
return 0;
}
return mHistoricalUidOps.size();
}
/**
* Gets the historical UID ops at a given index.
*
* @param index The index.
*
* @return The historical UID ops at the given index.
*
* @see #getUidCount()
*/
public @NonNull HistoricalUidOps getUidOpsAt(@IntRange(from = 0) int index) {
if (mHistoricalUidOps == null) {
throw new IndexOutOfBoundsException();
}
return mHistoricalUidOps.valueAt(index);
}
/**
* Gets the historical UID ops for a given UID.
*
* @param uid The UID.
*
* @return The historical ops for the UID.
*/
public @Nullable HistoricalUidOps getUidOps(int uid) {
if (mHistoricalUidOps == null) {
return null;
}
return mHistoricalUidOps.get(uid);
}
/** @hide */
public void clearHistory(int uid, @NonNull String packageName) {
HistoricalUidOps historicalUidOps = getOrCreateHistoricalUidOps(uid);
historicalUidOps.clearHistory(packageName);
if (historicalUidOps.isEmpty()) {
mHistoricalUidOps.remove(uid);
}
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel parcel, int flags) {
parcel.writeLong(mBeginTimeMillis);
parcel.writeLong(mEndTimeMillis);
if (mHistoricalUidOps != null) {
final int uidCount = mHistoricalUidOps.size();
parcel.writeInt(uidCount);
for (int i = 0; i < uidCount; i++) {
parcel.writeInt(mHistoricalUidOps.keyAt(i));
}
final List opsList = new ArrayList<>(uidCount);
for (int i = 0; i < uidCount; i++) {
opsList.add(mHistoricalUidOps.valueAt(i));
}
parcel.writeParcelable(new ParceledListSlice<>(opsList), flags);
} else {
parcel.writeInt(-1);
}
}
/**
* Accepts a visitor to traverse the ops tree.
*
* @param visitor The visitor.
*
* @hide
*/
public void accept(@NonNull HistoricalOpsVisitor visitor) {
visitor.visitHistoricalOps(this);
final int uidCount = getUidCount();
for (int i = 0; i < uidCount; i++) {
getUidOpsAt(i).accept(visitor);
}
}
private @NonNull HistoricalUidOps getOrCreateHistoricalUidOps(int uid) {
if (mHistoricalUidOps == null) {
mHistoricalUidOps = new SparseArray<>();
}
HistoricalUidOps historicalUidOp = mHistoricalUidOps.get(uid);
if (historicalUidOp == null) {
historicalUidOp = new HistoricalUidOps(uid);
mHistoricalUidOps.put(uid, historicalUidOp);
}
return historicalUidOp;
}
/**
* @return Rounded value up at the 0.5 boundary.
*
* @hide
*/
public static double round(double value) {
return Math.floor(value + 0.5);
}
@Override
public boolean equals(@Nullable Object obj) {
if (this == obj) {
return true;
}
if (obj == null || getClass() != obj.getClass()) {
return false;
}
final HistoricalOps other = (HistoricalOps) obj;
if (mBeginTimeMillis != other.mBeginTimeMillis) {
return false;
}
if (mEndTimeMillis != other.mEndTimeMillis) {
return false;
}
if (mHistoricalUidOps == null) {
if (other.mHistoricalUidOps != null) {
return false;
}
} else if (!mHistoricalUidOps.equals(other.mHistoricalUidOps)) {
return false;
}
return true;
}
@Override
public int hashCode() {
int result = (int) (mBeginTimeMillis ^ (mBeginTimeMillis >>> 32));
result = 31 * result + mHistoricalUidOps.hashCode();
return result;
}
@NonNull
@Override
public String toString() {
return getClass().getSimpleName() + "[from:"
+ mBeginTimeMillis + " to:" + mEndTimeMillis + "]";
}
public static final @android.annotation.NonNull Creator CREATOR = new Creator() {
@Override
public @NonNull HistoricalOps createFromParcel(@NonNull Parcel parcel) {
return new HistoricalOps(parcel);
}
@Override
public @NonNull HistoricalOps[] newArray(int size) {
return new HistoricalOps[size];
}
};
}
/**
* This class represents historical app op state for a UID.
*
* @hide
*/
@SystemApi
public static final class HistoricalUidOps implements Parcelable {
private final int mUid;
private @Nullable ArrayMap mHistoricalPackageOps;
/** @hide */
public HistoricalUidOps(int uid) {
mUid = uid;
}
private HistoricalUidOps(@NonNull HistoricalUidOps other) {
mUid = other.mUid;
final int opCount = other.getPackageCount();
for (int i = 0; i < opCount; i++) {
final HistoricalPackageOps origOps = other.getPackageOpsAt(i);
final HistoricalPackageOps cloneOps = new HistoricalPackageOps(origOps);
if (mHistoricalPackageOps == null) {
mHistoricalPackageOps = new ArrayMap<>(opCount);
}
mHistoricalPackageOps.put(cloneOps.getPackageName(), cloneOps);
}
}
private HistoricalUidOps(@NonNull Parcel parcel) {
// No arg check since we always read from a trusted source.
mUid = parcel.readInt();
mHistoricalPackageOps = parcel.createTypedArrayMap(HistoricalPackageOps.CREATOR);
}
private @Nullable HistoricalUidOps splice(double fractionToRemove) {
HistoricalUidOps splice = null;
final int packageCount = getPackageCount();
for (int i = 0; i < packageCount; i++) {
final HistoricalPackageOps origOps = getPackageOpsAt(i);
final HistoricalPackageOps spliceOps = origOps.splice(fractionToRemove);
if (spliceOps != null) {
if (splice == null) {
splice = new HistoricalUidOps(mUid);
}
if (splice.mHistoricalPackageOps == null) {
splice.mHistoricalPackageOps = new ArrayMap<>();
}
splice.mHistoricalPackageOps.put(spliceOps.getPackageName(), spliceOps);
}
}
return splice;
}
private void merge(@NonNull HistoricalUidOps other) {
final int packageCount = other.getPackageCount();
for (int i = 0; i < packageCount; i++) {
final HistoricalPackageOps otherPackageOps = other.getPackageOpsAt(i);
final HistoricalPackageOps thisPackageOps = getPackageOps(
otherPackageOps.getPackageName());
if (thisPackageOps != null) {
thisPackageOps.merge(otherPackageOps);
} else {
if (mHistoricalPackageOps == null) {
mHistoricalPackageOps = new ArrayMap<>();
}
mHistoricalPackageOps.put(otherPackageOps.getPackageName(), otherPackageOps);
}
}
}
private void filter(@Nullable String packageName, @Nullable String attributionTag,
@Nullable String[] opNames, @HistoricalOpsRequestFilter int filter,
@OpHistoryFlags int historyFilter, double fractionToRemove, long beginTimeMillis,
long endTimeMillis) {
final int packageCount = getPackageCount();
for (int i = packageCount - 1; i >= 0; i--) {
final HistoricalPackageOps packageOps = getPackageOpsAt(i);
if ((filter & FILTER_BY_PACKAGE_NAME) != 0 && !packageName.equals(
packageOps.getPackageName())) {
mHistoricalPackageOps.removeAt(i);
} else {
packageOps.filter(attributionTag, opNames, filter, historyFilter,
fractionToRemove, beginTimeMillis, endTimeMillis);
if (packageOps.getAttributedOpsCount() == 0) {
mHistoricalPackageOps.removeAt(i);
}
}
}
}
private boolean isEmpty() {
final int packageCount = getPackageCount();
for (int i = packageCount - 1; i >= 0; i--) {
final HistoricalPackageOps packageOps = mHistoricalPackageOps.valueAt(i);
if (!packageOps.isEmpty()) {
return false;
}
}
return true;
}
private void increaseAccessCount(int opCode, @NonNull String packageName,
@Nullable String attributionTag, @UidState int uidState, @OpFlags int flags,
long increment) {
getOrCreateHistoricalPackageOps(packageName).increaseAccessCount(
opCode, attributionTag, uidState, flags, increment);
}
private void increaseRejectCount(int opCode, @NonNull String packageName,
@Nullable String attributionTag, @UidState int uidState, @OpFlags int flags,
long increment) {
getOrCreateHistoricalPackageOps(packageName).increaseRejectCount(
opCode, attributionTag, uidState, flags, increment);
}
private void increaseAccessDuration(int opCode, @NonNull String packageName,
@Nullable String attributionTag, @UidState int uidState, @OpFlags int flags,
long increment) {
getOrCreateHistoricalPackageOps(packageName).increaseAccessDuration(
opCode, attributionTag, uidState, flags, increment);
}
private void addDiscreteAccess(int opCode, @NonNull String packageName,
@Nullable String attributionTag, @UidState int uidState,
@OpFlags int flag, long discreteAccessTime, long discreteAccessDuration,
@Nullable OpEventProxyInfo proxy) {
getOrCreateHistoricalPackageOps(packageName).addDiscreteAccess(opCode, attributionTag,
uidState, flag, discreteAccessTime, discreteAccessDuration, proxy);
};
/**
* @return The UID for which the data is related.
*/
public int getUid() {
return mUid;
}
/**
* Gets number of packages with historical ops.
*
* @return The number of packages with historical ops.
*
* @see #getPackageOpsAt(int)
*/
public @IntRange(from = 0) int getPackageCount() {
if (mHistoricalPackageOps == null) {
return 0;
}
return mHistoricalPackageOps.size();
}
/**
* Gets the historical package ops at a given index.
*
* @param index The index.
*
* @return The historical package ops at the given index.
*
* @see #getPackageCount()
*/
public @NonNull HistoricalPackageOps getPackageOpsAt(@IntRange(from = 0) int index) {
if (mHistoricalPackageOps == null) {
throw new IndexOutOfBoundsException();
}
return mHistoricalPackageOps.valueAt(index);
}
/**
* Gets the historical package ops for a given package.
*
* @param packageName The package.
*
* @return The historical ops for the package.
*/
public @Nullable HistoricalPackageOps getPackageOps(@NonNull String packageName) {
if (mHistoricalPackageOps == null) {
return null;
}
return mHistoricalPackageOps.get(packageName);
}
private void clearHistory(@NonNull String packageName) {
if (mHistoricalPackageOps != null) {
mHistoricalPackageOps.remove(packageName);
}
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel parcel, int flags) {
parcel.writeInt(mUid);
parcel.writeTypedArrayMap(mHistoricalPackageOps, flags);
}
private void accept(@NonNull HistoricalOpsVisitor visitor) {
visitor.visitHistoricalUidOps(this);
final int packageCount = getPackageCount();
for (int i = 0; i < packageCount; i++) {
getPackageOpsAt(i).accept(visitor);
}
}
private @NonNull HistoricalPackageOps getOrCreateHistoricalPackageOps(
@NonNull String packageName) {
if (mHistoricalPackageOps == null) {
mHistoricalPackageOps = new ArrayMap<>();
}
HistoricalPackageOps historicalPackageOp = mHistoricalPackageOps.get(packageName);
if (historicalPackageOp == null) {
historicalPackageOp = new HistoricalPackageOps(packageName);
mHistoricalPackageOps.put(packageName, historicalPackageOp);
}
return historicalPackageOp;
}
public static final @android.annotation.NonNull Creator CREATOR = new Creator() {
@Override
public @NonNull HistoricalUidOps createFromParcel(@NonNull Parcel parcel) {
return new HistoricalUidOps(parcel);
}
@Override
public @NonNull HistoricalUidOps[] newArray(int size) {
return new HistoricalUidOps[size];
}
};
@Override
public boolean equals(@Nullable Object obj) {
if (this == obj) {
return true;
}
if (obj == null || getClass() != obj.getClass()) {
return false;
}
final HistoricalUidOps other = (HistoricalUidOps) obj;
if (mUid != other.mUid) {
return false;
}
if (mHistoricalPackageOps == null) {
if (other.mHistoricalPackageOps != null) {
return false;
}
} else if (!mHistoricalPackageOps.equals(other.mHistoricalPackageOps)) {
return false;
}
return true;
}
@Override
public int hashCode() {
int result = mUid;
result = 31 * result + (mHistoricalPackageOps != null
? mHistoricalPackageOps.hashCode() : 0);
return result;
}
}
/**
* This class represents historical app op information about a package.
*
* @hide
*/
@SystemApi
public static final class HistoricalPackageOps implements Parcelable {
private final @NonNull String mPackageName;
private @Nullable ArrayMap mAttributedHistoricalOps;
/** @hide */
public HistoricalPackageOps(@NonNull String packageName) {
mPackageName = packageName;
}
private HistoricalPackageOps(@NonNull HistoricalPackageOps other) {
mPackageName = other.mPackageName;
final int opCount = other.getAttributedOpsCount();
for (int i = 0; i < opCount; i++) {
final AttributedHistoricalOps origOps = other.getAttributedOpsAt(i);
final AttributedHistoricalOps cloneOps = new AttributedHistoricalOps(origOps);
if (mAttributedHistoricalOps == null) {
mAttributedHistoricalOps = new ArrayMap<>(opCount);
}
mAttributedHistoricalOps.put(cloneOps.getTag(), cloneOps);
}
}
private HistoricalPackageOps(@NonNull Parcel parcel) {
mPackageName = parcel.readString();
mAttributedHistoricalOps = parcel.createTypedArrayMap(AttributedHistoricalOps.CREATOR);
}
private @Nullable HistoricalPackageOps splice(double fractionToRemove) {
HistoricalPackageOps splice = null;
final int attributionCount = getAttributedOpsCount();
for (int i = 0; i < attributionCount; i++) {
final AttributedHistoricalOps origOps = getAttributedOpsAt(i);
final AttributedHistoricalOps spliceOps = origOps.splice(fractionToRemove);
if (spliceOps != null) {
if (splice == null) {
splice = new HistoricalPackageOps(mPackageName);
}
if (splice.mAttributedHistoricalOps == null) {
splice.mAttributedHistoricalOps = new ArrayMap<>();
}
splice.mAttributedHistoricalOps.put(spliceOps.getTag(), spliceOps);
}
}
return splice;
}
private void merge(@NonNull HistoricalPackageOps other) {
final int attributionCount = other.getAttributedOpsCount();
for (int i = 0; i < attributionCount; i++) {
final AttributedHistoricalOps otherAttributionOps = other.getAttributedOpsAt(i);
final AttributedHistoricalOps thisAttributionOps = getAttributedOps(
otherAttributionOps.getTag());
if (thisAttributionOps != null) {
thisAttributionOps.merge(otherAttributionOps);
} else {
if (mAttributedHistoricalOps == null) {
mAttributedHistoricalOps = new ArrayMap<>();
}
mAttributedHistoricalOps.put(otherAttributionOps.getTag(),
otherAttributionOps);
}
}
}
private void filter(@Nullable String attributionTag, @Nullable String[] opNames,
@HistoricalOpsRequestFilter int filter, @OpHistoryFlags int historyFilter,
double fractionToRemove, long beginTimeMillis, long endTimeMillis) {
final int attributionCount = getAttributedOpsCount();
for (int i = attributionCount - 1; i >= 0; i--) {
final AttributedHistoricalOps attributionOps = getAttributedOpsAt(i);
if ((filter & FILTER_BY_ATTRIBUTION_TAG) != 0 && !Objects.equals(attributionTag,
attributionOps.getTag())) {
mAttributedHistoricalOps.removeAt(i);
} else {
attributionOps.filter(opNames, filter, historyFilter, fractionToRemove,
beginTimeMillis, endTimeMillis);
if (attributionOps.getOpCount() == 0) {
mAttributedHistoricalOps.removeAt(i);
}
}
}
}
private void accept(@NonNull HistoricalOpsVisitor visitor) {
visitor.visitHistoricalPackageOps(this);
final int attributionCount = getAttributedOpsCount();
for (int i = 0; i < attributionCount; i++) {
getAttributedOpsAt(i).accept(visitor);
}
}
private boolean isEmpty() {
final int attributionCount = getAttributedOpsCount();
for (int i = attributionCount - 1; i >= 0; i--) {
final AttributedHistoricalOps attributionOps = mAttributedHistoricalOps.valueAt(i);
if (!attributionOps.isEmpty()) {
return false;
}
}
return true;
}
private void increaseAccessCount(int opCode, @Nullable String attributionTag,
@UidState int uidState, @OpFlags int flags, long increment) {
getOrCreateAttributedHistoricalOps(attributionTag).increaseAccessCount(
opCode, uidState, flags, increment);
}
private void increaseRejectCount(int opCode, @Nullable String attributionTag,
@UidState int uidState, @OpFlags int flags, long increment) {
getOrCreateAttributedHistoricalOps(attributionTag).increaseRejectCount(
opCode, uidState, flags, increment);
}
private void increaseAccessDuration(int opCode, @Nullable String attributionTag,
@UidState int uidState, @OpFlags int flags, long increment) {
getOrCreateAttributedHistoricalOps(attributionTag).increaseAccessDuration(
opCode, uidState, flags, increment);
}
private void addDiscreteAccess(int opCode, @Nullable String attributionTag,
@UidState int uidState, @OpFlags int flag, long discreteAccessTime,
long discreteAccessDuration, @Nullable OpEventProxyInfo proxy) {
getOrCreateAttributedHistoricalOps(attributionTag).addDiscreteAccess(opCode, uidState,
flag, discreteAccessTime, discreteAccessDuration, proxy);
}
/**
* Gets the package name which the data represents.
*
* @return The package name which the data represents.
*/
public @NonNull String getPackageName() {
return mPackageName;
}
private @NonNull AttributedHistoricalOps getOrCreateAttributedHistoricalOps(
@Nullable String attributionTag) {
if (mAttributedHistoricalOps == null) {
mAttributedHistoricalOps = new ArrayMap<>();
}
AttributedHistoricalOps historicalAttributionOp = mAttributedHistoricalOps.get(
attributionTag);
if (historicalAttributionOp == null) {
historicalAttributionOp = new AttributedHistoricalOps(attributionTag);
mAttributedHistoricalOps.put(attributionTag, historicalAttributionOp);
}
return historicalAttributionOp;
}
/**
* Gets number historical app ops.
*
* @return The number historical app ops.
* @see #getOpAt(int)
*/
public @IntRange(from = 0) int getOpCount() {
int numOps = 0;
int numAttributions = getAttributedOpsCount();
for (int code = 0; code < _NUM_OP; code++) {
String opName = opToPublicName(code);
for (int attributionNum = 0; attributionNum < numAttributions; attributionNum++) {
if (getAttributedOpsAt(attributionNum).getOp(opName) != null) {
numOps++;
break;
}
}
}
return numOps;
}
/**
* Gets the historical op at a given index.
*
*
This combines the counts from all attributions.
*
* @param index The index to lookup.
* @return The op at the given index.
* @see #getOpCount()
*/
public @NonNull HistoricalOp getOpAt(@IntRange(from = 0) int index) {
int numOpsFound = 0;
int numAttributions = getAttributedOpsCount();
for (int code = 0; code < _NUM_OP; code++) {
String opName = opToPublicName(code);
for (int attributionNum = 0; attributionNum < numAttributions; attributionNum++) {
if (getAttributedOpsAt(attributionNum).getOp(opName) != null) {
if (numOpsFound == index) {
return getOp(opName);
} else {
numOpsFound++;
break;
}
}
}
}
throw new IndexOutOfBoundsException();
}
/**
* Gets the historical entry for a given op name.
*
*
This combines the counts from all attributions.
*
* @param opName The op name.
* @return The historical entry for that op name.
*/
public @Nullable HistoricalOp getOp(@NonNull String opName) {
if (mAttributedHistoricalOps == null) {
return null;
}
HistoricalOp combinedOp = null;
int numAttributions = getAttributedOpsCount();
for (int i = 0; i < numAttributions; i++) {
HistoricalOp attributionOp = getAttributedOpsAt(i).getOp(opName);
if (attributionOp != null) {
if (combinedOp == null) {
combinedOp = new HistoricalOp(attributionOp);
} else {
combinedOp.merge(attributionOp);
}
}
}
return combinedOp;
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(@NonNull Parcel parcel, int flags) {
parcel.writeString(mPackageName);
parcel.writeTypedArrayMap(mAttributedHistoricalOps, flags);
}
public static final @android.annotation.NonNull Creator CREATOR =
new Creator() {
@Override
public @NonNull HistoricalPackageOps createFromParcel(@NonNull Parcel parcel) {
return new HistoricalPackageOps(parcel);
}
@Override
public @NonNull HistoricalPackageOps[] newArray(int size) {
return new HistoricalPackageOps[size];
}
};
@Override
public boolean equals(@Nullable Object obj) {
if (this == obj) {
return true;
}
if (obj == null || getClass() != obj.getClass()) {
return false;
}
final HistoricalPackageOps other = (HistoricalPackageOps) obj;
if (!mPackageName.equals(other.mPackageName)) {
return false;
}
if (mAttributedHistoricalOps == null) {
if (other.mAttributedHistoricalOps != null) {
return false;
}
} else if (!mAttributedHistoricalOps.equals(other.mAttributedHistoricalOps)) {
return false;
}
return true;
}
@Override
public int hashCode() {
int result = mPackageName != null ? mPackageName.hashCode() : 0;
result = 31 * result + (mAttributedHistoricalOps != null
? mAttributedHistoricalOps.hashCode() : 0);
return result;
}
/**
* Gets number of attributed historical ops.
*
* @return The number of attribution with historical ops.
*
* @see #getAttributedOpsAt(int)
*/
public @IntRange(from = 0) int getAttributedOpsCount() {
if (mAttributedHistoricalOps == null) {
return 0;
}
return mAttributedHistoricalOps.size();
}
/**
* Gets the attributed historical ops at a given index.
*
* @param index The index.
*
* @return The historical attribution ops at the given index.
*
* @see #getAttributedOpsCount()
*/
public @NonNull AttributedHistoricalOps getAttributedOpsAt(@IntRange(from = 0) int index) {
if (mAttributedHistoricalOps == null) {
throw new IndexOutOfBoundsException();
}
return mAttributedHistoricalOps.valueAt(index);
}
/**
* Gets the attributed historical ops for a given attribution tag.
*
* @param attributionTag The attribution tag.
*
* @return The historical ops for the attribution.
*/
public @Nullable AttributedHistoricalOps getAttributedOps(@Nullable String attributionTag) {
if (mAttributedHistoricalOps == null) {
return null;
}
return mAttributedHistoricalOps.get(attributionTag);
}
}
/**
* This class represents historical app op information about a attribution in a package.
*
* @hide
*/
@SystemApi
/* codegen verifier cannot deal with nested class parameters
@DataClass(genHiddenConstructor = true,
genEqualsHashCode = true, genHiddenCopyConstructor = true) */
@DataClass.Suppress("getHistoricalOps")
public static final class AttributedHistoricalOps implements Parcelable {
/** {@link Context#createAttributionContext attribution} tag */
private final @Nullable String mTag;
/** Ops for this attribution */
private @Nullable ArrayMap mHistoricalOps;
/** @hide */
public AttributedHistoricalOps(@NonNull String tag) {
mTag = tag;
}
private AttributedHistoricalOps(@NonNull AttributedHistoricalOps other) {
mTag = other.mTag;
final int opCount = other.getOpCount();
for (int i = 0; i < opCount; i++) {
final HistoricalOp origOp = other.getOpAt(i);
final HistoricalOp cloneOp = new HistoricalOp(origOp);
if (mHistoricalOps == null) {
mHistoricalOps = new ArrayMap<>(opCount);
}
mHistoricalOps.put(cloneOp.getOpName(), cloneOp);
}
}
private @Nullable AttributedHistoricalOps splice(double fractionToRemove) {
AttributedHistoricalOps splice = null;
final int opCount = getOpCount();
for (int i = 0; i < opCount; i++) {
final HistoricalOp origOps = getOpAt(i);
final HistoricalOp spliceOps = origOps.splice(fractionToRemove);
if (spliceOps != null) {
if (splice == null) {
splice = new AttributedHistoricalOps(mTag, null);
}
if (splice.mHistoricalOps == null) {
splice.mHistoricalOps = new ArrayMap<>();
}
splice.mHistoricalOps.put(spliceOps.getOpName(), spliceOps);
}
}
return splice;
}
private void merge(@NonNull AttributedHistoricalOps other) {
final int opCount = other.getOpCount();
for (int i = 0; i < opCount; i++) {
final HistoricalOp otherOp = other.getOpAt(i);
final HistoricalOp thisOp = getOp(otherOp.getOpName());
if (thisOp != null) {
thisOp.merge(otherOp);
} else {
if (mHistoricalOps == null) {
mHistoricalOps = new ArrayMap<>();
}
mHistoricalOps.put(otherOp.getOpName(), otherOp);
}
}
}
private void filter(@Nullable String[] opNames, @HistoricalOpsRequestFilter int filter,
@OpHistoryFlags int historyFilter, double scaleFactor, long beginTimeMillis,
long endTimeMillis) {
final int opCount = getOpCount();
for (int i = opCount - 1; i >= 0; i--) {
final HistoricalOp op = mHistoricalOps.valueAt(i);
if ((filter & FILTER_BY_OP_NAMES) != 0 && !ArrayUtils.contains(opNames,
op.getOpName())) {
mHistoricalOps.removeAt(i);
} else {
op.filter(historyFilter, scaleFactor, beginTimeMillis, endTimeMillis);
}
}
}
private boolean isEmpty() {
final int opCount = getOpCount();
for (int i = opCount - 1; i >= 0; i--) {
final HistoricalOp op = mHistoricalOps.valueAt(i);
if (!op.isEmpty()) {
return false;
}
}
return true;
}
private void increaseAccessCount(int opCode, @UidState int uidState,
@OpFlags int flags, long increment) {
getOrCreateHistoricalOp(opCode).increaseAccessCount(uidState, flags, increment);
}
private void increaseRejectCount(int opCode, @UidState int uidState,
@OpFlags int flags, long increment) {
getOrCreateHistoricalOp(opCode).increaseRejectCount(uidState, flags, increment);
}
private void increaseAccessDuration(int opCode, @UidState int uidState,
@OpFlags int flags, long increment) {
getOrCreateHistoricalOp(opCode).increaseAccessDuration(uidState, flags, increment);
}
private void addDiscreteAccess(int opCode, @UidState int uidState, @OpFlags int flag,
long discreteAccessTime, long discreteAccessDuration,
@Nullable OpEventProxyInfo proxy) {
getOrCreateHistoricalOp(opCode).addDiscreteAccess(uidState,flag, discreteAccessTime,
discreteAccessDuration, proxy);
}
/**
* Gets number historical app ops.
*
* @return The number historical app ops.
* @see #getOpAt(int)
*/
public @IntRange(from = 0) int getOpCount() {
if (mHistoricalOps == null) {
return 0;
}
return mHistoricalOps.size();
}
/**
* Gets the historical op at a given index.
*
* @param index The index to lookup.
* @return The op at the given index.
* @see #getOpCount()
*/
public @NonNull HistoricalOp getOpAt(@IntRange(from = 0) int index) {
if (mHistoricalOps == null) {
throw new IndexOutOfBoundsException();
}
return mHistoricalOps.valueAt(index);
}
/**
* Gets the historical entry for a given op name.
*
* @param opName The op name.
* @return The historical entry for that op name.
*/
public @Nullable HistoricalOp getOp(@NonNull String opName) {
if (mHistoricalOps == null) {
return null;
}
return mHistoricalOps.get(opName);
}
private void accept(@NonNull HistoricalOpsVisitor visitor) {
visitor.visitHistoricalAttributionOps(this);
final int opCount = getOpCount();
for (int i = 0; i < opCount; i++) {
getOpAt(i).accept(visitor);
}
}
private @NonNull HistoricalOp getOrCreateHistoricalOp(int opCode) {
if (mHistoricalOps == null) {
mHistoricalOps = new ArrayMap<>();
}
final String opStr = sAppOpInfos[opCode].name;
HistoricalOp op = mHistoricalOps.get(opStr);
if (op == null) {
op = new HistoricalOp(opCode);
mHistoricalOps.put(opStr, op);
}
return op;
}
// Code below generated by codegen v1.0.14.
//
// DO NOT MODIFY!
// CHECKSTYLE:OFF Generated code
//
// To regenerate run:
// $ codegen $ANDROID_BUILD_TOP/frameworks/base/core/java/android/app/AppOpsManager.java
//
// To exclude the generated code from IntelliJ auto-formatting enable (one-time):
// Settings > Editor > Code Style > Formatter Control
//@formatter:off
/**
* Creates a new HistoricalAttributionOps.
*
* @param tag
* {@link Context#createAttributionContext attribution} tag
* @param historicalOps
* Ops for this attribution
* @hide
*/
@DataClass.Generated.Member
public AttributedHistoricalOps(
@Nullable String tag,
@Nullable ArrayMap historicalOps) {
this.mTag = tag;
this.mHistoricalOps = historicalOps;
// onConstructed(); // You can define this method to get a callback
}
/**
* {@link Context#createAttributionContext attribution} tag
*/
@DataClass.Generated.Member
public @Nullable String getTag() {
return mTag;
}
@Override
@DataClass.Generated.Member
public boolean equals(@Nullable Object o) {
// You can override field equality logic by defining either of the methods like:
// boolean fieldNameEquals(HistoricalAttributionOps other) { ... }
// boolean fieldNameEquals(FieldType otherValue) { ... }
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
@SuppressWarnings("unchecked")
AttributedHistoricalOps that = (AttributedHistoricalOps) o;
//noinspection PointlessBooleanExpression
return true
&& Objects.equals(mTag, that.mTag)
&& Objects.equals(mHistoricalOps, that.mHistoricalOps);
}
@Override
@DataClass.Generated.Member
public int hashCode() {
// You can override field hashCode logic by defining methods like:
// int fieldNameHashCode() { ... }
int _hash = 1;
_hash = 31 * _hash + Objects.hashCode(mTag);
_hash = 31 * _hash + Objects.hashCode(mHistoricalOps);
return _hash;
}
@Override
@DataClass.Generated.Member
public void writeToParcel(@NonNull Parcel dest, int flags) {
// You can override field parcelling by defining methods like:
// void parcelFieldName(Parcel dest, int flags) { ... }
byte flg = 0;
if (mTag != null) flg |= 0x1;
if (mHistoricalOps != null) flg |= 0x2;
dest.writeByte(flg);
if (mTag != null) dest.writeString(mTag);
if (mHistoricalOps != null) dest.writeMap(mHistoricalOps);
}
@Override
@DataClass.Generated.Member
public int describeContents() { return 0; }
/** @hide */
@SuppressWarnings({"unchecked", "RedundantCast"})
@DataClass.Generated.Member
/* package-private */ AttributedHistoricalOps(@NonNull Parcel in) {
// You can override field unparcelling by defining methods like:
// static FieldType unparcelFieldName(Parcel in) { ... }
byte flg = in.readByte();
String attributionTag = (flg & 0x1) == 0 ? null : in.readString();
ArrayMap historicalOps = null;
if ((flg & 0x2) != 0) {
historicalOps = new ArrayMap();
in.readMap(historicalOps, HistoricalOp.class.getClassLoader());
}
this.mTag = attributionTag;
this.mHistoricalOps = historicalOps;
// onConstructed(); // You can define this method to get a callback
}
@DataClass.Generated.Member
public static final @NonNull Parcelable.Creator CREATOR
= new Parcelable.Creator() {
@Override
public AttributedHistoricalOps[] newArray(int size) {
return new AttributedHistoricalOps[size];
}
@Override
public AttributedHistoricalOps createFromParcel(@NonNull Parcel in) {
return new AttributedHistoricalOps(in);
}
};
/*
@DataClass.Generated(
time = 1578113234821L,
codegenVersion = "1.0.14",
sourceFile = "frameworks/base/core/java/android/app/AppOpsManager.java",
inputSignatures = "private final @android.annotation.Nullable java.lang.String mAttributionTag\nprivate @android.annotation.Nullable android.util.ArrayMap mHistoricalOps\nprivate @android.annotation.Nullable android.app.HistoricalAttributionOps splice(double)\nprivate void merge(android.app.HistoricalAttributionOps)\nprivate void filter(java.lang.String[],int,double)\nprivate boolean isEmpty()\nprivate void increaseAccessCount(int,int,int,long)\nprivate void increaseRejectCount(int,int,int,long)\nprivate void increaseAccessDuration(int,int,int,long)\npublic @android.annotation.IntRange(from=0L) int getOpCount()\npublic @android.annotation.NonNull android.app.HistoricalOp getOpAt(int)\npublic @android.annotation.Nullable android.app.HistoricalOp getOp(java.lang.String)\nprivate void accept(android.app.HistoricalOpsVisitor)\nprivate @android.annotation.NonNull android.app.HistoricalOp getOrCreateHistoricalOp(int)\nclass HistoricalAttributionOps extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genHiddenConstructor=true, genEqualsHashCode=true, genHiddenCopyConstructor=true)")
@Deprecated
private void __metadata() {}
*/
//@formatter:on
// End of generated code
}
/**
* This class represents historical information about an app op.
*
* @hide
*/
@SystemApi
public static final class HistoricalOp implements Parcelable {
private final int mOp;
private @Nullable LongSparseLongArray mAccessCount;
private @Nullable LongSparseLongArray mRejectCount;
private @Nullable LongSparseLongArray mAccessDuration;
/** Discrete Ops for this Op */
private @Nullable List mDiscreteAccesses;
/** @hide */
public HistoricalOp(int op) {
mOp = op;
}
private HistoricalOp(@NonNull HistoricalOp other) {
mOp = other.mOp;
if (other.mAccessCount != null) {
mAccessCount = other.mAccessCount.clone();
}
if (other.mRejectCount != null) {
mRejectCount = other.mRejectCount.clone();
}
if (other.mAccessDuration != null) {
mAccessDuration = other.mAccessDuration.clone();
}
final int historicalOpCount = other.getDiscreteAccessCount();
for (int i = 0; i < historicalOpCount; i++) {
final AttributedOpEntry origOp = other.getDiscreteAccessAt(i);
final AttributedOpEntry cloneOp = new AttributedOpEntry(origOp);
getOrCreateDiscreteAccesses().add(cloneOp);
}
}
private HistoricalOp(@NonNull Parcel parcel) {
mOp = parcel.readInt();
mAccessCount = readLongSparseLongArrayFromParcel(parcel);
mRejectCount = readLongSparseLongArrayFromParcel(parcel);
mAccessDuration = readLongSparseLongArrayFromParcel(parcel);
mDiscreteAccesses = readDiscreteAccessArrayFromParcel(parcel);
}
private void filter(@OpHistoryFlags int historyFlag, double scaleFactor,
long beginTimeMillis, long endTimeMillis) {
if ((historyFlag & HISTORY_FLAG_AGGREGATE) == 0) {
mAccessCount = null;
mRejectCount = null;
mAccessDuration = null;
} else {
scale(mAccessCount, scaleFactor);
scale(mRejectCount, scaleFactor);
scale(mAccessDuration, scaleFactor);
}
if ((historyFlag & HISTORY_FLAG_DISCRETE) == 0) {
mDiscreteAccesses = null;
return;
}
final int discreteOpCount = getDiscreteAccessCount();
for (int i = discreteOpCount - 1; i >= 0; i--) {
final AttributedOpEntry op = mDiscreteAccesses.get(i);
long opBeginTime = op.getLastAccessTime(OP_FLAGS_ALL);
long opEndTime = opBeginTime + op.getLastDuration(OP_FLAGS_ALL);
opEndTime = max(opBeginTime, opEndTime);
if (opEndTime < beginTimeMillis || opBeginTime > endTimeMillis) {
mDiscreteAccesses.remove(i);
}
}
}
private boolean isEmpty() {
return !hasData(mAccessCount)
&& !hasData(mRejectCount)
&& !hasData(mAccessDuration)
&& (mDiscreteAccesses == null);
}
private boolean hasData(@NonNull LongSparseLongArray array) {
return array != null && array.size() > 0;
}
private @Nullable HistoricalOp splice(double fractionToRemove) {
final HistoricalOp splice = new HistoricalOp(mOp);
splice(mAccessCount, splice::getOrCreateAccessCount, fractionToRemove);
splice(mRejectCount, splice::getOrCreateRejectCount, fractionToRemove);
splice(mAccessDuration, splice::getOrCreateAccessDuration, fractionToRemove);
return splice;
}
private static void splice(@Nullable LongSparseLongArray sourceContainer,
@NonNull Supplier destContainerProvider,
double fractionToRemove) {
if (sourceContainer != null) {
final int size = sourceContainer.size();
for (int i = 0; i < size; i++) {
final long key = sourceContainer.keyAt(i);
final long value = sourceContainer.valueAt(i);
final long removedFraction = Math.round(value * fractionToRemove);
if (removedFraction > 0) {
destContainerProvider.get().put(key, removedFraction);
sourceContainer.put(key, value - removedFraction);
}
}
}
}
private void merge(@NonNull HistoricalOp other) {
merge(this::getOrCreateAccessCount, other.mAccessCount);
merge(this::getOrCreateRejectCount, other.mRejectCount);
merge(this::getOrCreateAccessDuration, other.mAccessDuration);
if (other.mDiscreteAccesses == null) {
return;
}
if (mDiscreteAccesses == null) {
mDiscreteAccesses = new ArrayList(other.mDiscreteAccesses);
return;
}
List historicalDiscreteAccesses = new ArrayList<>();
final int otherHistoricalOpCount = other.getDiscreteAccessCount();
final int historicalOpCount = getDiscreteAccessCount();
int i = 0;
int j = 0;
while (i < otherHistoricalOpCount || j < historicalOpCount) {
if (i == otherHistoricalOpCount) {
historicalDiscreteAccesses.add(mDiscreteAccesses.get(j++));
} else if (j == historicalOpCount) {
historicalDiscreteAccesses.add(other.mDiscreteAccesses.get(i++));
} else if (mDiscreteAccesses.get(j).getLastAccessTime(OP_FLAGS_ALL)
< other.mDiscreteAccesses.get(i).getLastAccessTime(OP_FLAGS_ALL)) {
historicalDiscreteAccesses.add(mDiscreteAccesses.get(j++));
} else {
historicalDiscreteAccesses.add(other.mDiscreteAccesses.get(i++));
}
}
mDiscreteAccesses = deduplicateDiscreteEvents(historicalDiscreteAccesses);
}
private void increaseAccessCount(@UidState int uidState, @OpFlags int flags,
long increment) {
increaseCount(getOrCreateAccessCount(), uidState, flags, increment);
}
private void increaseRejectCount(@UidState int uidState, @OpFlags int flags,
long increment) {
increaseCount(getOrCreateRejectCount(), uidState, flags, increment);
}
private void increaseAccessDuration(@UidState int uidState, @OpFlags int flags,
long increment) {
increaseCount(getOrCreateAccessDuration(), uidState, flags, increment);
}
private void increaseCount(@NonNull LongSparseLongArray counts,
@UidState int uidState, @OpFlags int flags, long increment) {
while (flags != 0) {
final int flag = 1 << Integer.numberOfTrailingZeros(flags);
flags &= ~flag;
final long key = makeKey(uidState, flag);
counts.put(key, counts.get(key) + increment);
}
}
private void addDiscreteAccess(@UidState int uidState, @OpFlags int flag,
long discreteAccessTime, long discreteAccessDuration,
@Nullable OpEventProxyInfo proxy) {
List discreteAccesses = getOrCreateDiscreteAccesses();
LongSparseArray accessEvents = new LongSparseArray<>();
long key = makeKey(uidState, flag);
NoteOpEvent note = new NoteOpEvent(discreteAccessTime, discreteAccessDuration, proxy);
accessEvents.append(key, note);
AttributedOpEntry access = new AttributedOpEntry(mOp, false, accessEvents, null);
int insertionPoint = discreteAccesses.size() - 1;
for (; insertionPoint >= 0; insertionPoint--) {
if (discreteAccesses.get(insertionPoint).getLastAccessTime(OP_FLAGS_ALL)
< discreteAccessTime) {
break;
}
}
insertionPoint++;
if (insertionPoint < discreteAccesses.size() && discreteAccesses.get(
insertionPoint).getLastAccessTime(OP_FLAGS_ALL) == discreteAccessTime) {
discreteAccesses.set(insertionPoint, mergeAttributedOpEntries(
Arrays.asList(discreteAccesses.get(insertionPoint), access)));
} else {
discreteAccesses.add(insertionPoint, access);
}
}
/**
* Gets the op name.
*
* @return The op name.
*/
public @NonNull String getOpName() {
return sAppOpInfos[mOp].name;
}
/** @hide */
public int getOpCode() {
return mOp;
}
/**
* Gets number of discrete historical app ops.
*
* @return The number historical app ops.
* @see #getDiscreteAccessAt(int)
*/
public @IntRange(from = 0) int getDiscreteAccessCount() {
if (mDiscreteAccesses == null) {
return 0;
}
return mDiscreteAccesses.size();
}
/**
* Gets the historical op at a given index.
*
* @param index The index to lookup.
* @return The op at the given index.
* @see #getDiscreteAccessCount()
*/
public @NonNull AttributedOpEntry getDiscreteAccessAt(@IntRange(from = 0) int index) {
if (mDiscreteAccesses == null) {
throw new IndexOutOfBoundsException();
}
return mDiscreteAccesses.get(index);
}
/**
* Gets the number times the op was accessed (performed) in the foreground.
*
* @param flags The flags which are any combination of
* {@link #OP_FLAG_SELF}, {@link #OP_FLAG_TRUSTED_PROXY},
* {@link #OP_FLAG_UNTRUSTED_PROXY}, {@link #OP_FLAG_TRUSTED_PROXIED},
* {@link #OP_FLAG_UNTRUSTED_PROXIED}. You can use {@link #OP_FLAGS_ALL}
* for any flag.
* @return The times the op was accessed in the foreground.
*
* @see #getBackgroundAccessCount(int)
* @see #getAccessCount(int, int, int)
*/
public long getForegroundAccessCount(@OpFlags int flags) {
return sumForFlagsInStates(mAccessCount, MAX_PRIORITY_UID_STATE,
resolveFirstUnrestrictedUidState(mOp), flags);
}
/**
* Gets the discrete events the op was accessed (performed) in the foreground.
*
* @param flags The flags which are any combination of
* {@link #OP_FLAG_SELF}, {@link #OP_FLAG_TRUSTED_PROXY},
* {@link #OP_FLAG_UNTRUSTED_PROXY}, {@link #OP_FLAG_TRUSTED_PROXIED},
* {@link #OP_FLAG_UNTRUSTED_PROXIED}. You can use {@link #OP_FLAGS_ALL}
* for any flag.
* @return The list of discrete ops accessed in the foreground.
*
* @see #getBackgroundDiscreteAccesses(int)
* @see #getDiscreteAccesses(int, int, int)
*/
@NonNull
public List getForegroundDiscreteAccesses(@OpFlags int flags) {
return listForFlagsInStates(mDiscreteAccesses, MAX_PRIORITY_UID_STATE,
resolveFirstUnrestrictedUidState(mOp), flags);
}
/**
* Gets the number times the op was accessed (performed) in the background.
*
* @param flags The flags which are any combination of
* {@link #OP_FLAG_SELF}, {@link #OP_FLAG_TRUSTED_PROXY},
* {@link #OP_FLAG_UNTRUSTED_PROXY}, {@link #OP_FLAG_TRUSTED_PROXIED},
* {@link #OP_FLAG_UNTRUSTED_PROXIED}. You can use {@link #OP_FLAGS_ALL}
* for any flag.
* @return The times the op was accessed in the background.
*
* @see #getForegroundAccessCount(int)
* @see #getAccessCount(int, int, int)
*/
public long getBackgroundAccessCount(@OpFlags int flags) {
return sumForFlagsInStates(mAccessCount, resolveLastRestrictedUidState(mOp),
MIN_PRIORITY_UID_STATE, flags);
}
/**
* Gets the discrete events the op was accessed (performed) in the background.
*
* @param flags The flags which are any combination of
* {@link #OP_FLAG_SELF}, {@link #OP_FLAG_TRUSTED_PROXY},
* {@link #OP_FLAG_UNTRUSTED_PROXY}, {@link #OP_FLAG_TRUSTED_PROXIED},
* {@link #OP_FLAG_UNTRUSTED_PROXIED}. You can use {@link #OP_FLAGS_ALL}
* for any flag.
* @return The list of discrete ops accessed in the background.
*
* @see #getForegroundDiscreteAccesses(int)
* @see #getDiscreteAccesses(int, int, int)
*/
@NonNull
public List getBackgroundDiscreteAccesses(@OpFlags int flags) {
return listForFlagsInStates(mDiscreteAccesses, resolveLastRestrictedUidState(mOp),
MIN_PRIORITY_UID_STATE, flags);
}
/**
* Gets the number times the op was accessed (performed) for a
* range of uid states.
*
* @param fromUidState The UID state from which to query. Could be one of
* {@link #UID_STATE_PERSISTENT}, {@link #UID_STATE_TOP},
* {@link #UID_STATE_FOREGROUND_SERVICE}, {@link #UID_STATE_FOREGROUND},
* {@link #UID_STATE_BACKGROUND}, {@link #UID_STATE_CACHED}.
* @param toUidState The UID state to which to query.
* @param flags The flags which are any combination of
* {@link #OP_FLAG_SELF}, {@link #OP_FLAG_TRUSTED_PROXY},
* {@link #OP_FLAG_UNTRUSTED_PROXY}, {@link #OP_FLAG_TRUSTED_PROXIED},
* {@link #OP_FLAG_UNTRUSTED_PROXIED}. You can use {@link #OP_FLAGS_ALL}
* for any flag.
*
* @return The times the op was accessed for the given UID state.
*
* @see #getForegroundAccessCount(int)
* @see #getBackgroundAccessCount(int)
*/
public long getAccessCount(@UidState int fromUidState, @UidState int toUidState,
@OpFlags int flags) {
return sumForFlagsInStates(mAccessCount, fromUidState, toUidState, flags);
}
/**
* Gets the discrete events the op was accessed (performed) for a
* range of uid states.
*
* @param flags The flags which are any combination of
* {@link #OP_FLAG_SELF}, {@link #OP_FLAG_TRUSTED_PROXY},
* {@link #OP_FLAG_UNTRUSTED_PROXY}, {@link #OP_FLAG_TRUSTED_PROXIED},
* {@link #OP_FLAG_UNTRUSTED_PROXIED}. You can use {@link #OP_FLAGS_ALL}
* for any flag.
* @return The discrete the op was accessed in the background.
*
* @see #getBackgroundDiscreteAccesses(int)
* @see #getForegroundDiscreteAccesses(int)
*/
@NonNull
public List getDiscreteAccesses(@UidState int fromUidState,
@UidState int toUidState, @OpFlags int flags) {
return listForFlagsInStates(mDiscreteAccesses, fromUidState, toUidState, flags);
}
/**
* Gets the number times the op was rejected in the foreground.
*
* @param flags The flags which are any combination of
* {@link #OP_FLAG_SELF}, {@link #OP_FLAG_TRUSTED_PROXY},
* {@link #OP_FLAG_UNTRUSTED_PROXY}, {@link #OP_FLAG_TRUSTED_PROXIED},
* {@link #OP_FLAG_UNTRUSTED_PROXIED}. You can use {@link #OP_FLAGS_ALL}
* for any flag.
* @return The times the op was rejected in the foreground.
*
* @see #getBackgroundRejectCount(int)
* @see #getRejectCount(int, int, int)
*/
public long getForegroundRejectCount(@OpFlags int flags) {
return sumForFlagsInStates(mRejectCount, MAX_PRIORITY_UID_STATE,
resolveFirstUnrestrictedUidState(mOp), flags);
}
/**
* Gets the number times the op was rejected in the background.
*
* @param flags The flags which are any combination of
* {@link #OP_FLAG_SELF}, {@link #OP_FLAG_TRUSTED_PROXY},
* {@link #OP_FLAG_UNTRUSTED_PROXY}, {@link #OP_FLAG_TRUSTED_PROXIED},
* {@link #OP_FLAG_UNTRUSTED_PROXIED}. You can use {@link #OP_FLAGS_ALL}
* for any flag.
* @return The times the op was rejected in the background.
*
* @see #getForegroundRejectCount(int)
* @see #getRejectCount(int, int, int)
*/
public long getBackgroundRejectCount(@OpFlags int flags) {
return sumForFlagsInStates(mRejectCount, resolveLastRestrictedUidState(mOp),
MIN_PRIORITY_UID_STATE, flags);
}
/**
* Gets the number times the op was rejected for a given range of UID states.
*
* @param fromUidState The UID state from which to query. Could be one of
* {@link #UID_STATE_PERSISTENT}, {@link #UID_STATE_TOP},
* {@link #UID_STATE_FOREGROUND_SERVICE}, {@link #UID_STATE_FOREGROUND},
* {@link #UID_STATE_BACKGROUND}, {@link #UID_STATE_CACHED}.
* @param toUidState The UID state to which to query.
* @param flags The flags which are any combination of
* {@link #OP_FLAG_SELF}, {@link #OP_FLAG_TRUSTED_PROXY},
* {@link #OP_FLAG_UNTRUSTED_PROXY}, {@link #OP_FLAG_TRUSTED_PROXIED},
* {@link #OP_FLAG_UNTRUSTED_PROXIED}. You can use {@link #OP_FLAGS_ALL}
* for any flag.
*
* @return The times the op was rejected for the given UID state.
*
* @see #getForegroundRejectCount(int)
* @see #getBackgroundRejectCount(int)
*/
public long getRejectCount(@UidState int fromUidState, @UidState int toUidState,
@OpFlags int flags) {
return sumForFlagsInStates(mRejectCount, fromUidState, toUidState, flags);
}
/**
* Gets the total duration the app op was accessed (performed) in the foreground.
* The duration is in wall time.
*
* @param flags The flags which are any combination of
* {@link #OP_FLAG_SELF}, {@link #OP_FLAG_TRUSTED_PROXY},
* {@link #OP_FLAG_UNTRUSTED_PROXY}, {@link #OP_FLAG_TRUSTED_PROXIED},
* {@link #OP_FLAG_UNTRUSTED_PROXIED}. You can use {@link #OP_FLAGS_ALL}
* for any flag.
* @return The total duration the app op was accessed in the foreground.
*
* @see #getBackgroundAccessDuration(int)
* @see #getAccessDuration(int, int, int)
*/
public long getForegroundAccessDuration(@OpFlags int flags) {
return sumForFlagsInStates(mAccessDuration, MAX_PRIORITY_UID_STATE,
resolveFirstUnrestrictedUidState(mOp), flags);
}
/**
* Gets the total duration the app op was accessed (performed) in the background.
* The duration is in wall time.
*
* @param flags The flags which are any combination of
* {@link #OP_FLAG_SELF}, {@link #OP_FLAG_TRUSTED_PROXY},
* {@link #OP_FLAG_UNTRUSTED_PROXY}, {@link #OP_FLAG_TRUSTED_PROXIED},
* {@link #OP_FLAG_UNTRUSTED_PROXIED}. You can use {@link #OP_FLAGS_ALL}
* for any flag.
* @return The total duration the app op was accessed in the background.
*
* @see #getForegroundAccessDuration(int)
* @see #getAccessDuration(int, int, int)
*/
public long getBackgroundAccessDuration(@OpFlags int flags) {
return sumForFlagsInStates(mAccessDuration, resolveLastRestrictedUidState(mOp),
MIN_PRIORITY_UID_STATE, flags);
}
/**
* Gets the total duration the app op was accessed (performed) for a given
* range of UID states. The duration is in wall time.
*
* @param fromUidState The UID state from which to query. Could be one of
* {@link #UID_STATE_PERSISTENT}, {@link #UID_STATE_TOP},
* {@link #UID_STATE_FOREGROUND_SERVICE}, {@link #UID_STATE_FOREGROUND},
* {@link #UID_STATE_BACKGROUND}, {@link #UID_STATE_CACHED}.
* @param toUidState The UID state from which to query.
* @param flags The flags which are any combination of
* {@link #OP_FLAG_SELF}, {@link #OP_FLAG_TRUSTED_PROXY},
* {@link #OP_FLAG_UNTRUSTED_PROXY}, {@link #OP_FLAG_TRUSTED_PROXIED},
* {@link #OP_FLAG_UNTRUSTED_PROXIED}. You can use {@link #OP_FLAGS_ALL}
* for any flag.
*
* @return The total duration the app op was accessed for the given UID state.
*
* @see #getForegroundAccessDuration(int)
* @see #getBackgroundAccessDuration(int)
*/
public long getAccessDuration(@UidState int fromUidState, @UidState int toUidState,
@OpFlags int flags) {
return sumForFlagsInStates(mAccessDuration, fromUidState, toUidState, flags);
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel parcel, int flags) {
parcel.writeInt(mOp);
writeLongSparseLongArrayToParcel(mAccessCount, parcel);
writeLongSparseLongArrayToParcel(mRejectCount, parcel);
writeLongSparseLongArrayToParcel(mAccessDuration, parcel);
writeDiscreteAccessArrayToParcel(mDiscreteAccesses, parcel, flags);
}
@Override
public boolean equals(@Nullable Object obj) {
if (this == obj) {
return true;
}
if (obj == null || getClass() != obj.getClass()) {
return false;
}
final HistoricalOp other = (HistoricalOp) obj;
if (mOp != other.mOp) {
return false;
}
if (!equalsLongSparseLongArray(mAccessCount, other.mAccessCount)) {
return false;
}
if (!equalsLongSparseLongArray(mRejectCount, other.mRejectCount)) {
return false;
}
if (!equalsLongSparseLongArray(mAccessDuration, other.mAccessDuration)) {
return false;
}
return mDiscreteAccesses == null ? (other.mDiscreteAccesses == null ? true
: false) : mDiscreteAccesses.equals(other.mDiscreteAccesses);
}
@Override
public int hashCode() {
int result = mOp;
result = 31 * result + Objects.hashCode(mAccessCount);
result = 31 * result + Objects.hashCode(mRejectCount);
result = 31 * result + Objects.hashCode(mAccessDuration);
result = 31 * result + Objects.hashCode(mDiscreteAccesses);
return result;
}
private void accept(@NonNull HistoricalOpsVisitor visitor) {
visitor.visitHistoricalOp(this);
}
private @NonNull LongSparseLongArray getOrCreateAccessCount() {
if (mAccessCount == null) {
mAccessCount = new LongSparseLongArray();
}
return mAccessCount;
}
private @NonNull LongSparseLongArray getOrCreateRejectCount() {
if (mRejectCount == null) {
mRejectCount = new LongSparseLongArray();
}
return mRejectCount;
}
private @NonNull LongSparseLongArray getOrCreateAccessDuration() {
if (mAccessDuration == null) {
mAccessDuration = new LongSparseLongArray();
}
return mAccessDuration;
}
private @NonNull List getOrCreateDiscreteAccesses() {
if (mDiscreteAccesses == null) {
mDiscreteAccesses = new ArrayList<>();
}
return mDiscreteAccesses;
}
/**
* Multiplies the entries in the array with the passed in scale factor and
* rounds the result at up 0.5 boundary.
*
* @param data The data to scale.
* @param scaleFactor The scale factor.
*/
private static void scale(@NonNull LongSparseLongArray data, double scaleFactor) {
if (data != null) {
final int size = data.size();
for (int i = 0; i < size; i++) {
data.put(data.keyAt(i), (long) HistoricalOps.round(
(double) data.valueAt(i) * scaleFactor));
}
}
}
/**
* Merges two arrays while lazily acquiring the destination.
*
* @param thisSupplier The destination supplier.
* @param other The array to merge in.
*/
private static void merge(@NonNull Supplier thisSupplier,
@Nullable LongSparseLongArray other) {
if (other != null) {
final int otherSize = other.size();
for (int i = 0; i < otherSize; i++) {
final LongSparseLongArray that = thisSupplier.get();
final long otherKey = other.keyAt(i);
final long otherValue = other.valueAt(i);
that.put(otherKey, that.get(otherKey) + otherValue);
}
}
}
/** @hide */
public @Nullable LongSparseArray