Revert "[DeviceAware] Use AttributionSourceState in AppOpsServic..."
Revert submission 24499968-appops-deviceid
Reason for revert: Causing perf regression b/308786093
Reverted changes: /q/submissionid:24499968-appops-deviceid
Change-Id: I211edc6b9bb9f59eb6259be54938000f9ad65c45
diff --git a/apex/jobscheduler/service/java/com/android/server/AppStateTrackerImpl.java b/apex/jobscheduler/service/java/com/android/server/AppStateTrackerImpl.java
index 5fc7745..e08200b 100644
--- a/apex/jobscheduler/service/java/com/android/server/AppStateTrackerImpl.java
+++ b/apex/jobscheduler/service/java/com/android/server/AppStateTrackerImpl.java
@@ -23,7 +23,6 @@
import android.app.AppOpsManager.PackageOps;
import android.app.IActivityManager;
import android.app.usage.UsageStatsManager;
-import android.content.AttributionSource;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
@@ -747,10 +746,8 @@
public void opChanged(int op, int uid, String packageName) throws RemoteException {
boolean restricted = false;
try {
- final AttributionSource attributionSource =
- new AttributionSource.Builder(uid).setPackageName(packageName).build();
- restricted = mAppOpsService.checkOperationWithState(TARGET_OP,
- attributionSource.asState()) != AppOpsManager.MODE_ALLOWED;
+ restricted = mAppOpsService.checkOperation(TARGET_OP,
+ uid, packageName) != AppOpsManager.MODE_ALLOWED;
} catch (RemoteException e) {
// Shouldn't happen
}
diff --git a/apex/jobscheduler/service/java/com/android/server/tare/InternalResourceService.java b/apex/jobscheduler/service/java/com/android/server/tare/InternalResourceService.java
index 95f901c..b8397d2 100644
--- a/apex/jobscheduler/service/java/com/android/server/tare/InternalResourceService.java
+++ b/apex/jobscheduler/service/java/com/android/server/tare/InternalResourceService.java
@@ -38,7 +38,6 @@
import android.app.tare.IEconomyManager;
import android.app.usage.UsageEvents;
import android.app.usage.UsageStatsManagerInternal;
-import android.content.AttributionSource;
import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.Context;
@@ -231,11 +230,8 @@
public void opChanged(int op, int uid, String packageName) {
boolean restricted = false;
try {
- final AttributionSource attributionSource = new AttributionSource.Builder(uid)
- .setPackageName(packageName)
- .build();
- restricted = mAppOpsService.checkOperationWithState(
- AppOpsManager.OP_RUN_ANY_IN_BACKGROUND, attributionSource.asState())
+ restricted = mAppOpsService.checkOperation(
+ AppOpsManager.OP_RUN_ANY_IN_BACKGROUND, uid, packageName)
!= AppOpsManager.MODE_ALLOWED;
} catch (RemoteException e) {
// Shouldn't happen
diff --git a/core/java/android/app/AppOpsManager.java b/core/java/android/app/AppOpsManager.java
index 7e84ceb..9a19d8e 100644
--- a/core/java/android/app/AppOpsManager.java
+++ b/core/java/android/app/AppOpsManager.java
@@ -8305,9 +8305,7 @@
*/
public int unsafeCheckOpRawNoThrow(int op, int uid, @NonNull String packageName) {
try {
- final AttributionSource attributionSource =
- new AttributionSource.Builder(uid).setPackageName(packageName).build();
- return mService.checkOperationWithStateRaw(op, attributionSource.asState());
+ return mService.checkOperationRaw(op, uid, packageName, null);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
@@ -8470,12 +8468,7 @@
}
}
- final AttributionSource attributionSource =
- new AttributionSource.Builder(uid)
- .setPackageName(packageName)
- .setAttributionTag(attributionTag)
- .build();
- SyncNotedAppOp syncOp = mService.noteOperationWithState(op, attributionSource.asState(),
+ SyncNotedAppOp syncOp = mService.noteOperation(op, uid, packageName, attributionTag,
collectionMode == COLLECT_ASYNC, message, shouldCollectMessage);
if (syncOp.getOpMode() == MODE_ALLOWED) {
@@ -8715,9 +8708,7 @@
@UnsupportedAppUsage
public int checkOp(int op, int uid, String packageName) {
try {
- final AttributionSource attributionSource =
- new AttributionSource.Builder(uid).setPackageName(packageName).build();
- int mode = mService.checkOperationWithState(op, attributionSource.asState());
+ int mode = mService.checkOperation(op, uid, packageName);
if (mode == MODE_ERRORED) {
throw new SecurityException(buildSecurityExceptionMsg(op, uid, packageName));
}
@@ -8738,9 +8729,7 @@
@UnsupportedAppUsage
public int checkOpNoThrow(int op, int uid, String packageName) {
try {
- final AttributionSource attributionSource =
- new AttributionSource.Builder(uid).setPackageName(packageName).build();
- int mode = mService.checkOperationWithState(op, attributionSource.asState());
+ int mode = mService.checkOperation(op, uid, packageName);
return mode == AppOpsManager.MODE_FOREGROUND ? AppOpsManager.MODE_ALLOWED : mode;
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
@@ -8985,14 +8974,8 @@
}
}
- final AttributionSource attributionSource =
- new AttributionSource.Builder(uid)
- .setPackageName(packageName)
- .setAttributionTag(attributionTag)
- .build();
- SyncNotedAppOp syncOp = mService.startOperationWithState(token, op,
- attributionSource.asState(), startIfModeDefault,
- collectionMode == COLLECT_ASYNC, message,
+ SyncNotedAppOp syncOp = mService.startOperation(token, op, uid, packageName,
+ attributionTag, startIfModeDefault, collectionMode == COLLECT_ASYNC, message,
shouldCollectMessage, attributionFlags, attributionChainId);
if (syncOp.getOpMode() == MODE_ALLOWED) {
@@ -9205,12 +9188,7 @@
public void finishOp(IBinder token, int op, int uid, @NonNull String packageName,
@Nullable String attributionTag) {
try {
- final AttributionSource attributionSource =
- new AttributionSource.Builder(uid)
- .setPackageName(packageName)
- .setAttributionTag(attributionTag)
- .build();
- mService.finishOperationWithState(token, op, attributionSource.asState());
+ mService.finishOperation(token, op, uid, packageName, attributionTag);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
diff --git a/core/java/android/app/AppOpsManagerInternal.java b/core/java/android/app/AppOpsManagerInternal.java
index a3de8fa..43023fe 100644
--- a/core/java/android/app/AppOpsManagerInternal.java
+++ b/core/java/android/app/AppOpsManagerInternal.java
@@ -26,12 +26,11 @@
import android.util.SparseIntArray;
import com.android.internal.app.IAppOpsCallback;
+import com.android.internal.util.function.HeptFunction;
import com.android.internal.util.function.HexFunction;
-import com.android.internal.util.function.NonaFunction;
import com.android.internal.util.function.QuadFunction;
+import com.android.internal.util.function.QuintConsumer;
import com.android.internal.util.function.QuintFunction;
-import com.android.internal.util.function.TriConsumer;
-import com.android.internal.util.function.TriFunction;
import com.android.internal.util.function.UndecFunction;
/**
@@ -46,13 +45,15 @@
* Allows overriding check operation behavior.
*
* @param code The op code to check.
- * @param attributionSource the {@link AttributionSource} responsible for data access
+ * @param uid The UID for which to check.
+ * @param packageName The package for which to check.
+ * @param attributionTag The attribution tag for which to check.
* @param raw Whether to check the raw op i.e. not interpret the mode based on UID state.
* @param superImpl The super implementation.
* @return The app op check result.
*/
- int checkOperation(int code, AttributionSource attributionSource,
- boolean raw, TriFunction<Integer, AttributionSource, Boolean, Integer>
+ int checkOperation(int code, int uid, String packageName, @Nullable String attributionTag,
+ boolean raw, QuintFunction<Integer, Integer, String, String, Boolean, Integer>
superImpl);
/**
@@ -72,23 +73,25 @@
* Allows overriding note operation behavior.
*
* @param code The op code to note.
- * @param attributionSource the {@link AttributionSource} responsible for data access
+ * @param uid The UID for which to note.
+ * @param packageName The package for which to note. {@code null} for system package.
+ * @param featureId Id of the feature in the package
* @param shouldCollectAsyncNotedOp If an {@link AsyncNotedAppOp} should be collected
* @param message The message in the async noted op
* @param superImpl The super implementation.
* @return The app op note result.
*/
- SyncNotedAppOp noteOperation(int code, AttributionSource attributionSource,
- boolean shouldCollectAsyncNotedOp,
+ SyncNotedAppOp noteOperation(int code, int uid, @Nullable String packageName,
+ @Nullable String featureId, boolean shouldCollectAsyncNotedOp,
@Nullable String message, boolean shouldCollectMessage,
- @NonNull QuintFunction<Integer, AttributionSource, Boolean, String, Boolean,
+ @NonNull HeptFunction<Integer, Integer, String, String, Boolean, String, Boolean,
SyncNotedAppOp> superImpl);
/**
* Allows overriding note proxy operation behavior.
*
* @param code The op code to note.
- * @param attributionSource the {@link AttributionSource} responsible for data access
+ * @param attributionSource The permission identity of the caller.
* @param shouldCollectAsyncNotedOp If an {@link AsyncNotedAppOp} should be collected
* @param message The message in the async noted op
* @param shouldCollectMessage whether to collect messages
@@ -107,7 +110,9 @@
*
* @param token The client state.
* @param code The op code to start.
- * @param attributionSource the {@link AttributionSource} responsible for data access
+ * @param uid The UID for which to note.
+ * @param packageName The package for which to note. {@code null} for system package.
+ * @param attributionTag the attribution tag.
* @param startIfModeDefault Whether to start the op of the mode is default.
* @param shouldCollectAsyncNotedOp If an {@link AsyncNotedAppOp} should be collected
* @param message The message in the async noted op
@@ -117,12 +122,12 @@
* @param superImpl The super implementation.
* @return The app op note result.
*/
- SyncNotedAppOp startOperation(IBinder token, int code,
- AttributionSource attributionSource,
+ SyncNotedAppOp startOperation(IBinder token, int code, int uid,
+ @Nullable String packageName, @Nullable String attributionTag,
boolean startIfModeDefault, boolean shouldCollectAsyncNotedOp,
@Nullable String message, boolean shouldCollectMessage,
@AttributionFlags int attributionFlags, int attributionChainId,
- @NonNull NonaFunction<IBinder, Integer, AttributionSource, Boolean,
+ @NonNull UndecFunction<IBinder, Integer, Integer, String, String, Boolean,
Boolean, String, Boolean, Integer, Integer, SyncNotedAppOp> superImpl);
/**
@@ -130,7 +135,7 @@
*
* @param clientId The client calling start, represented by an IBinder
* @param code The op code to start.
- * @param attributionSource the {@link AttributionSource} responsible for data access
+ * @param attributionSource The permission identity of the caller.
* @param startIfModeDefault Whether to start the op of the mode is default.
* @param shouldCollectAsyncNotedOp If an {@link AsyncNotedAppOp} should be collected
* @param message The message in the async noted op
@@ -156,19 +161,21 @@
*
* @param clientId The client state.
* @param code The op code to finish.
- * @param attributionSource the {@link AttributionSource} responsible for data access
+ * @param uid The UID for which the op was noted.
+ * @param packageName The package for which it was noted. {@code null} for system package.
+ * @param attributionTag the attribution tag.
*/
- default void finishOperation(IBinder clientId, int code,
- AttributionSource attributionSource,
- @NonNull TriConsumer<IBinder, Integer, AttributionSource> superImpl) {
- superImpl.accept(clientId, code, attributionSource);
+ default void finishOperation(IBinder clientId, int code, int uid, String packageName,
+ String attributionTag,
+ @NonNull QuintConsumer<IBinder, Integer, Integer, String, String> superImpl) {
+ superImpl.accept(clientId, code, uid, packageName, attributionTag);
}
/**
* Allows overriding finish proxy op.
*
* @param code The op code to finish.
- * @param attributionSource the {@link AttributionSource} responsible for data access
+ * @param attributionSource The permission identity of the caller.
* @param skipProxyOperation Whether to skip the proxy in the proxy/proxied operation
* @param clientId The client calling finishProxyOperation
* @param superImpl The "standard" implementation to potentially call
diff --git a/core/java/android/content/AttributionSource.java b/core/java/android/content/AttributionSource.java
index c2bc974..4b2cee6 100644
--- a/core/java/android/content/AttributionSource.java
+++ b/core/java/android/content/AttributionSource.java
@@ -235,12 +235,6 @@
}
/** @hide */
- public AttributionSource withUid(int uid) {
- return new AttributionSource(uid, getPid(), getPackageName(), getAttributionTag(),
- getToken(), mAttributionSourceState.renouncedPermissions, getDeviceId(), getNext());
- }
-
- /** @hide */
public AttributionSource withPid(int pid) {
return new AttributionSource(getUid(), pid, getPackageName(), getAttributionTag(),
getToken(), mAttributionSourceState.renouncedPermissions, getDeviceId(), getNext());
diff --git a/core/java/com/android/internal/app/IAppOpsService.aidl b/core/java/com/android/internal/app/IAppOpsService.aidl
index 1b05982..492e2ac 100644
--- a/core/java/com/android/internal/app/IAppOpsService.aidl
+++ b/core/java/com/android/internal/app/IAppOpsService.aidl
@@ -42,22 +42,18 @@
// frameworks/native/libs/permission/include/binder/IAppOpsService.h must match the order here.
// Please be careful to respect both these issues when modifying this file.
interface IAppOpsService {
- // Deprecated, use checkOperationWithState instead.
+ // These methods are also called by native code, so please be careful that the number in
+ // frameworks/native/libs/permission/include/binder/IAppOpsService.h matches the ordering here.
int checkOperation(int code, int uid, String packageName);
- // Deprecated, use noteOperationWithState instead.
SyncNotedAppOp noteOperation(int code, int uid, String packageName, @nullable String attributionTag,
boolean shouldCollectAsyncNotedOp, String message, boolean shouldCollectMessage);
- // Deprecated, use startOperationWithState instead.
SyncNotedAppOp startOperation(IBinder clientId, int code, int uid, String packageName,
@nullable String attributionTag, boolean startIfModeDefault,
boolean shouldCollectAsyncNotedOp, String message, boolean shouldCollectMessage,
int attributionFlags, int attributionChainId);
- // Deprecated, use finishOperationWithState instead.
@UnsupportedAppUsage
void finishOperation(IBinder clientId, int code, int uid, String packageName,
@nullable String attributionTag);
- // These methods are also called by native code, so please be careful that the number in
- // frameworks/native/libs/permission/include/binder/IAppOpsService.h matches the ordering here.
void startWatchingMode(int op, String packageName, IAppOpsCallback callback);
void stopWatchingMode(IAppOpsCallback callback);
int permissionToOpCode(String permission);
@@ -138,33 +134,20 @@
void stopWatchingAsyncNoted(String packageName, IAppOpsAsyncNotedCallback callback);
List<AsyncNotedAppOp> extractAsyncOps(String packageName);
- // Deprecated, use checkOperationWithStateRaw instead.
int checkOperationRaw(int code, int uid, String packageName, @nullable String attributionTag);
void reloadNonHistoricalState();
void collectNoteOpCallsForValidation(String stackTrace, int op, String packageName, long version);
- // These methods are also called by native code, so please be careful that the number in
- // frameworks/native/libs/permission/include/binder/IAppOpsService.h matches the ordering here.
- int checkOperationWithState(int code, in AttributionSourceState attributionSourceState);
- int checkOperationWithStateRaw(int code, in AttributionSourceState attributionSourceState);
- SyncNotedAppOp noteOperationWithState(int code, in AttributionSourceState attributionSourceState,
- boolean shouldCollectAsyncNotedOp, String message, boolean shouldCollectMessage);
- SyncNotedAppOp startOperationWithState(IBinder clientId, int code,
- in AttributionSourceState attributionSourceState, boolean startIfModeDefault,
- boolean shouldCollectAsyncNotedOp, String message, boolean shouldCollectMessage,
- int attributionFlags, int attributionChainId);
- void finishOperationWithState(IBinder clientId, int code, in AttributionSourceState attributionSourceState);
- // End of methods also called by native code (there may be more blocks like this of native
- // methods later in this file).
+
SyncNotedAppOp noteProxyOperationWithState(int code,
- in AttributionSourceState attributionSourceStateState,
- boolean shouldCollectAsyncNotedOp, String message, boolean shouldCollectMessage,
- boolean skipProxyOperation);
+ in AttributionSourceState attributionSourceStateState,
+ boolean shouldCollectAsyncNotedOp, String message, boolean shouldCollectMessage,
+ boolean skipProxyOperation);
SyncNotedAppOp startProxyOperationWithState(IBinder clientId, int code,
- in AttributionSourceState attributionSourceStateState, boolean startIfModeDefault,
- boolean shouldCollectAsyncNotedOp, String message, boolean shouldCollectMessage,
- boolean skipProxyOperation, int proxyAttributionFlags, int proxiedAttributionFlags,
- int attributionChainId);
+ in AttributionSourceState attributionSourceStateState, boolean startIfModeDefault,
+ boolean shouldCollectAsyncNotedOp, String message, boolean shouldCollectMessage,
+ boolean skipProxyOperation, int proxyAttributionFlags, int proxiedAttributionFlags,
+ int attributionChainId);
void finishProxyOperationWithState(IBinder clientId, int code,
- in AttributionSourceState attributionSourceStateState, boolean skipProxyOperation);
+ in AttributionSourceState attributionSourceStateState, boolean skipProxyOperation);
}
diff --git a/services/core/java/com/android/server/StorageManagerService.java b/services/core/java/com/android/server/StorageManagerService.java
index 0223509..15fc2dc 100644
--- a/services/core/java/com/android/server/StorageManagerService.java
+++ b/services/core/java/com/android/server/StorageManagerService.java
@@ -61,7 +61,6 @@
import android.app.PendingIntent;
import android.app.admin.SecurityLog;
import android.app.usage.StorageStatsManager;
-import android.content.AttributionSource;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
@@ -2139,13 +2138,8 @@
| MATCH_DIRECT_BOOT_UNAWARE | MATCH_UNINSTALLED_PACKAGES | MATCH_ANY_USER,
userId, Process.myUid())) {
try {
- final AttributionSource attributionSource = new AttributionSource.Builder(ai.uid)
- .setPackageName(ai.packageName)
- .build();
- boolean hasLegacy =
- mIAppOpsService.checkOperationWithState(
- OP_LEGACY_STORAGE, attributionSource.asState())
- == MODE_ALLOWED;
+ boolean hasLegacy = mIAppOpsService.checkOperation(OP_LEGACY_STORAGE, ai.uid,
+ ai.packageName) == MODE_ALLOWED;
updateLegacyStorageApps(ai.packageName, ai.uid, hasLegacy);
} catch (RemoteException e) {
Slog.e(TAG, "Failed to check legacy op for package " + ai.packageName, e);
@@ -4546,11 +4540,8 @@
// sharing the uid and allow same level of storage access for all packages even if
// one of the packages has the appop granted.
for (String uidPackageName : packagesForUid) {
- final AttributionSource attributionSource =
- new AttributionSource.Builder(uid).setPackageName(uidPackageName).build();
- if (mIAppOpsService.checkOperationWithState(
- OP_REQUEST_INSTALL_PACKAGES, attributionSource.asState())
- == MODE_ALLOWED) {
+ if (mIAppOpsService.checkOperation(
+ OP_REQUEST_INSTALL_PACKAGES, uid, uidPackageName) == MODE_ALLOWED) {
hasInstallOp = true;
break;
}
@@ -4847,11 +4838,8 @@
@Override
public boolean hasExternalStorageAccess(int uid, String packageName) {
try {
- final AttributionSource attributionSource =
- new AttributionSource.Builder(uid).setPackageName(packageName).build();
- final int opMode =
- mIAppOpsService.checkOperationWithState(
- OP_MANAGE_EXTERNAL_STORAGE, attributionSource.asState());
+ final int opMode = mIAppOpsService.checkOperation(
+ OP_MANAGE_EXTERNAL_STORAGE, uid, packageName);
if (opMode == AppOpsManager.MODE_DEFAULT) {
return mIPackageManager.checkUidPermission(
MANAGE_EXTERNAL_STORAGE, uid) == PERMISSION_GRANTED;
diff --git a/services/core/java/com/android/server/am/ActiveServices.java b/services/core/java/com/android/server/am/ActiveServices.java
index 4bdb4da..5f1a7e7 100644
--- a/services/core/java/com/android/server/am/ActiveServices.java
+++ b/services/core/java/com/android/server/am/ActiveServices.java
@@ -167,7 +167,6 @@
import android.compat.annotation.EnabledAfter;
import android.compat.annotation.EnabledSince;
import android.compat.annotation.Overridable;
-import android.content.AttributionSource;
import android.content.ComponentName;
import android.content.ComponentName.WithComponentName;
import android.content.Context;
@@ -1101,12 +1100,8 @@
SystemClock.uptimeMillis()); // Use current time, not lastActivity.
}
}
- final AttributionSource attributionSource = new AttributionSource.Builder(r.appInfo.uid)
- .setPackageName(r.packageName)
- .build();
- mAm.mAppOpsService.startOperationWithState(AppOpsManager.getToken(mAm.mAppOpsService),
- AppOpsManager.OP_START_FOREGROUND,
- attributionSource.asState(),
+ mAm.mAppOpsService.startOperation(AppOpsManager.getToken(mAm.mAppOpsService),
+ AppOpsManager.OP_START_FOREGROUND, r.appInfo.uid, r.packageName, null,
true, false, null, false, AppOpsManager.ATTRIBUTION_FLAGS_NONE,
AppOpsManager.ATTRIBUTION_CHAIN_ID_NONE);
}
@@ -2456,15 +2451,10 @@
stopProcStatsOp = false;
}
- final AttributionSource attributionSource = new AttributionSource
- .Builder(r.appInfo.uid)
- .setPackageName(r.packageName)
- .build();
- mAm.mAppOpsService.startOperationWithState(
+ mAm.mAppOpsService.startOperation(
AppOpsManager.getToken(mAm.mAppOpsService),
- AppOpsManager.OP_START_FOREGROUND, attributionSource.asState(),
- true, false, "", false,
- AppOpsManager.ATTRIBUTION_FLAGS_NONE,
+ AppOpsManager.OP_START_FOREGROUND, r.appInfo.uid, r.packageName,
+ null, true, false, "", false, AppOpsManager.ATTRIBUTION_FLAGS_NONE,
AppOpsManager.ATTRIBUTION_CHAIN_ID_NONE);
registerAppOpCallbackLocked(r);
mAm.updateForegroundServiceUsageStats(r.name, r.userId, true);
@@ -2524,13 +2514,10 @@
if (alreadyStartedOp) {
// If we had previously done a start op for direct foreground start,
// we have cleared the flag so can now drop it.
- final AttributionSource attributionSource = new AttributionSource
- .Builder(r.appInfo.uid)
- .setPackageName(r.packageName)
- .build();
- mAm.mAppOpsService.finishOperationWithState(
+ mAm.mAppOpsService.finishOperation(
AppOpsManager.getToken(mAm.mAppOpsService),
- AppOpsManager.OP_START_FOREGROUND, attributionSource.asState());
+ AppOpsManager.OP_START_FOREGROUND, r.appInfo.uid, r.packageName,
+ null);
}
}
} else {
@@ -2573,13 +2560,9 @@
SystemClock.uptimeMillis());
}
}
- final AttributionSource attributionSource =
- new AttributionSource.Builder(r.appInfo.uid)
- .setPackageName(r.packageName)
- .build();
- mAm.mAppOpsService.finishOperationWithState(
+ mAm.mAppOpsService.finishOperation(
AppOpsManager.getToken(mAm.mAppOpsService),
- AppOpsManager.OP_START_FOREGROUND, attributionSource.asState());
+ AppOpsManager.OP_START_FOREGROUND, r.appInfo.uid, r.packageName, null);
unregisterAppOpCallbackLocked(r);
logFGSStateChangeLocked(r,
FOREGROUND_SERVICE_STATE_CHANGED__STATE__EXIT,
@@ -5721,12 +5704,8 @@
SystemClock.uptimeMillis());
}
}
- final AttributionSource attributionSource = new AttributionSource
- .Builder(r.appInfo.uid)
- .setPackageName(r.packageName)
- .build();
- mAm.mAppOpsService.finishOperationWithState(AppOpsManager.getToken(mAm.mAppOpsService),
- AppOpsManager.OP_START_FOREGROUND, attributionSource.asState());
+ mAm.mAppOpsService.finishOperation(AppOpsManager.getToken(mAm.mAppOpsService),
+ AppOpsManager.OP_START_FOREGROUND, r.appInfo.uid, r.packageName, null);
mServiceFGAnrTimer.cancel(r);
if (r.app != null) {
Message msg = mAm.mHandler.obtainMessage(
@@ -5791,13 +5770,9 @@
SystemClock.uptimeMillis());
}
}
- final AttributionSource attributionSource = new AttributionSource
- .Builder(r.appInfo.uid)
- .setPackageName(r.packageName)
- .build();
- mAm.mAppOpsService.finishOperationWithState(
+ mAm.mAppOpsService.finishOperation(
AppOpsManager.getToken(mAm.mAppOpsService),
- AppOpsManager.OP_START_FOREGROUND, attributionSource.asState());
+ AppOpsManager.OP_START_FOREGROUND, r.appInfo.uid, r.packageName, null);
unregisterAppOpCallbackLocked(r);
r.mFgsExitTime = SystemClock.uptimeMillis();
logFGSStateChangeLocked(r,
@@ -8516,11 +8491,8 @@
mAm.mBatteryStatsService.noteServiceStartRunning(callingUid, callingPackage,
cn.getClassName());
- final AttributionSource attributionSource = new AttributionSource.Builder(r.appInfo.uid)
- .setPackageName(r.packageName)
- .build();
- mAm.mAppOpsService.startOperationWithState(AppOpsManager.getToken(mAm.mAppOpsService),
- AppOpsManager.OP_START_FOREGROUND, attributionSource.asState(),
+ mAm.mAppOpsService.startOperation(AppOpsManager.getToken(mAm.mAppOpsService),
+ AppOpsManager.OP_START_FOREGROUND, r.appInfo.uid, r.packageName, null,
true, false, null, false,
AppOpsManager.ATTRIBUTION_FLAGS_NONE, AppOpsManager.ATTRIBUTION_CHAIN_ID_NONE);
registerAppOpCallbackLocked(r);
diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java
index afc2356..e88d0c6 100644
--- a/services/core/java/com/android/server/am/ActivityManagerService.java
+++ b/services/core/java/com/android/server/am/ActivityManagerService.java
@@ -428,11 +428,10 @@
import com.android.internal.util.FrameworkStatsLog;
import com.android.internal.util.MemInfoReader;
import com.android.internal.util.Preconditions;
+import com.android.internal.util.function.HeptFunction;
import com.android.internal.util.function.HexFunction;
-import com.android.internal.util.function.NonaFunction;
import com.android.internal.util.function.QuadFunction;
import com.android.internal.util.function.QuintFunction;
-import com.android.internal.util.function.TriFunction;
import com.android.internal.util.function.UndecFunction;
import com.android.server.AlarmManagerInternal;
import com.android.server.BootReceiver;
@@ -3151,11 +3150,8 @@
}
private boolean hasUsageStatsPermission(String callingPackage, int callingUid, int callingPid) {
- final AttributionSource attributionSource = new AttributionSource.Builder(callingUid)
- .setPackageName(callingPackage)
- .build();
- final int mode = mAppOpsService.noteOperationWithState(AppOpsManager.OP_GET_USAGE_STATS,
- attributionSource.asState(), false, "", false).getOpMode();
+ final int mode = mAppOpsService.noteOperation(AppOpsManager.OP_GET_USAGE_STATS,
+ callingUid, callingPackage, null, false, "", false).getOpMode();
if (mode == AppOpsManager.MODE_DEFAULT) {
return checkPermission(Manifest.permission.PACKAGE_USAGE_STATS, callingPid, callingUid)
== PackageManager.PERMISSION_GRANTED;
@@ -5933,18 +5929,9 @@
@Override
public int noteOp(String op, int uid, String packageName) {
// TODO moltmann: Allow to specify featureId
- final AttributionSource attributionSource = new AttributionSource.Builder(uid)
- .setPackageName(packageName)
- .build();
- return mActivityManagerService
- .mAppOpsService
- .noteOperationWithState(
- AppOpsManager.strOpToOp(op),
- attributionSource.asState(),
- false,
- "",
- false)
- .getOpMode();
+ return mActivityManagerService.mAppOpsService
+ .noteOperation(AppOpsManager.strOpToOp(op), uid, packageName, null,
+ false, "", false).getOpMode();
}
@Override
@@ -20072,26 +20059,20 @@
}
@Override
- public int checkOperation(int code, AttributionSource attributionSource, boolean raw,
- TriFunction<Integer, AttributionSource, Boolean, Integer> superImpl) {
- final int uid = attributionSource.getUid();
-
+ public int checkOperation(int code, int uid, String packageName,
+ String attributionTag, boolean raw,
+ QuintFunction<Integer, Integer, String, String, Boolean, Integer> superImpl) {
if (uid == mTargetUid && isTargetOp(code)) {
final int shellUid = UserHandle.getUid(UserHandle.getUserId(uid),
Process.SHELL_UID);
- final AttributionSource shellAttributionSource =
- new AttributionSource.Builder(shellUid)
- .setPackageName("com.android.shell")
- .build();
-
final long identity = Binder.clearCallingIdentity();
try {
- return superImpl.apply(code, shellAttributionSource, raw);
+ return superImpl.apply(code, shellUid, "com.android.shell", null, raw);
} finally {
Binder.restoreCallingIdentity(identity);
}
}
- return superImpl.apply(code, attributionSource, raw);
+ return superImpl.apply(code, uid, packageName, attributionTag, raw);
}
@Override
@@ -20111,30 +20092,23 @@
}
@Override
- public SyncNotedAppOp noteOperation(int code, AttributionSource attributionSource,
- boolean shouldCollectAsyncNotedOp,
+ public SyncNotedAppOp noteOperation(int code, int uid, @Nullable String packageName,
+ @Nullable String featureId, boolean shouldCollectAsyncNotedOp,
@Nullable String message, boolean shouldCollectMessage,
- @NonNull QuintFunction<Integer, AttributionSource, Boolean, String, Boolean,
+ @NonNull HeptFunction<Integer, Integer, String, String, Boolean, String, Boolean,
SyncNotedAppOp> superImpl) {
- final int uid = attributionSource.getUid();
- final String attributionTag = attributionSource.getAttributionTag();
if (uid == mTargetUid && isTargetOp(code)) {
final int shellUid = UserHandle.getUid(UserHandle.getUserId(uid),
Process.SHELL_UID);
final long identity = Binder.clearCallingIdentity();
- final AttributionSource shellAttributionSource =
- new AttributionSource.Builder(shellUid)
- .setPackageName("com.android.shell")
- .setAttributionTag(attributionTag)
- .build();
try {
- return superImpl.apply(code, shellAttributionSource,
+ return superImpl.apply(code, shellUid, "com.android.shell", featureId,
shouldCollectAsyncNotedOp, message, shouldCollectMessage);
} finally {
Binder.restoreCallingIdentity(identity);
}
}
- return superImpl.apply(code, attributionSource, shouldCollectAsyncNotedOp,
+ return superImpl.apply(code, uid, packageName, featureId, shouldCollectAsyncNotedOp,
message, shouldCollectMessage);
}
@@ -20165,37 +20139,28 @@
}
@Override
- public SyncNotedAppOp startOperation(IBinder token, int code,
- AttributionSource attributionSource,
+ public SyncNotedAppOp startOperation(IBinder token, int code, int uid,
+ @Nullable String packageName, @Nullable String attributionTag,
boolean startIfModeDefault, boolean shouldCollectAsyncNotedOp,
@Nullable String message, boolean shouldCollectMessage,
@AttributionFlags int attributionFlags, int attributionChainId,
- @NonNull NonaFunction<IBinder, Integer, AttributionSource, Boolean,
+ @NonNull UndecFunction<IBinder, Integer, Integer, String, String, Boolean,
Boolean, String, Boolean, Integer, Integer, SyncNotedAppOp> superImpl) {
- final int uid = attributionSource.getUid();
- final String attributionTag = attributionSource.getAttributionTag();
-
if (uid == mTargetUid && isTargetOp(code)) {
final int shellUid = UserHandle.getUid(UserHandle.getUserId(uid),
Process.SHELL_UID);
final long identity = Binder.clearCallingIdentity();
try {
- final AttributionSource shellAttributionSource =
- new AttributionSource.Builder(shellUid)
- .setPackageName("com.android.shell")
- .setAttributionTag(attributionTag)
- .build();
-
- return superImpl.apply(token, code, shellAttributionSource,
- startIfModeDefault, shouldCollectAsyncNotedOp, message,
+ return superImpl.apply(token, code, shellUid, "com.android.shell",
+ attributionTag, startIfModeDefault, shouldCollectAsyncNotedOp, message,
shouldCollectMessage, attributionFlags, attributionChainId);
} finally {
Binder.restoreCallingIdentity(identity);
}
}
- return superImpl.apply(token, code, attributionSource, startIfModeDefault,
- shouldCollectAsyncNotedOp, message, shouldCollectMessage, attributionFlags,
- attributionChainId);
+ return superImpl.apply(token, code, uid, packageName, attributionTag,
+ startIfModeDefault, shouldCollectAsyncNotedOp, message, shouldCollectMessage,
+ attributionFlags, attributionChainId);
}
@Override
diff --git a/services/core/java/com/android/server/am/AppPermissionTracker.java b/services/core/java/com/android/server/am/AppPermissionTracker.java
index 947fcd3..18a9153 100644
--- a/services/core/java/com/android/server/am/AppPermissionTracker.java
+++ b/services/core/java/com/android/server/am/AppPermissionTracker.java
@@ -37,7 +37,6 @@
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.AppOpsManager;
-import android.content.AttributionSource;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager.OnPermissionsChangedListener;
@@ -193,11 +192,7 @@
if (DEBUG_PERMISSION_TRACKER) {
final IAppOpsService appOpsService = mInjector.getIAppOpsService();
try {
- final AttributionSource attributionSource = new AttributionSource.Builder(uid)
- .setPackageName(packageName)
- .build();
- final int mode =
- appOpsService.checkOperationWithState(op, attributionSource.asState());
+ final int mode = appOpsService.checkOperation(op, uid, packageName);
Slog.i(TAG, "onOpChanged: " + opToPublicName(op)
+ " " + UserHandle.formatUid(uid)
+ " " + packageName + " " + mode);
@@ -312,11 +307,7 @@
final IAppOpsService appOpsService = mInjector.getIAppOpsService();
for (String pkg : packages) {
try {
- final AttributionSource attributionSource =
- new AttributionSource.Builder(mUid).setPackageName(pkg).build();
- final int mode =
- appOpsService.checkOperationWithState(
- mAppOp, attributionSource.asState());
+ final int mode = appOpsService.checkOperation(mAppOp, mUid, pkg);
if (mode == AppOpsManager.MODE_ALLOWED) {
mAppOpAllowed = true;
return;
diff --git a/services/core/java/com/android/server/appop/AppOpsService.java b/services/core/java/com/android/server/appop/AppOpsService.java
index d6997da..052b0c2 100644
--- a/services/core/java/com/android/server/appop/AppOpsService.java
+++ b/services/core/java/com/android/server/appop/AppOpsService.java
@@ -1143,32 +1143,22 @@
}
}, RARELY_USED_PACKAGES_INITIALIZATION_DELAY_MILLIS);
- getPackageManagerInternal()
- .setExternalSourcesPolicy(
- new PackageManagerInternal.ExternalSourcesPolicy() {
- @Override
- public int getPackageTrustedToInstallApps(String packageName, int uid) {
- final AttributionSource attributionSource =
- new AttributionSource.Builder(uid)
- .setPackageName(packageName)
- .build();
- int appOpMode =
- checkOperationWithState(
- AppOpsManager.OP_REQUEST_INSTALL_PACKAGES,
- attributionSource.asState());
- switch (appOpMode) {
- case AppOpsManager.MODE_ALLOWED:
- return PackageManagerInternal.ExternalSourcesPolicy
- .USER_TRUSTED;
- case AppOpsManager.MODE_ERRORED:
- return PackageManagerInternal.ExternalSourcesPolicy
- .USER_BLOCKED;
- default:
- return PackageManagerInternal.ExternalSourcesPolicy
- .USER_DEFAULT;
- }
- }
- });
+ getPackageManagerInternal().setExternalSourcesPolicy(
+ new PackageManagerInternal.ExternalSourcesPolicy() {
+ @Override
+ public int getPackageTrustedToInstallApps(String packageName, int uid) {
+ int appOpMode = checkOperation(AppOpsManager.OP_REQUEST_INSTALL_PACKAGES,
+ uid, packageName);
+ switch (appOpMode) {
+ case AppOpsManager.MODE_ALLOWED:
+ return PackageManagerInternal.ExternalSourcesPolicy.USER_TRUSTED;
+ case AppOpsManager.MODE_ERRORED:
+ return PackageManagerInternal.ExternalSourcesPolicy.USER_BLOCKED;
+ default:
+ return PackageManagerInternal.ExternalSourcesPolicy.USER_DEFAULT;
+ }
+ }
+ });
}
@VisibleForTesting
@@ -2544,41 +2534,22 @@
}
}
- /** @deprecated Use {@link #checkOperationWithStateRaw} instead. */
@Override
public int checkOperationRaw(int code, int uid, String packageName,
- @Nullable String attributionTag) {
- final AttributionSource attributionSource = new AttributionSource.Builder(uid)
- .setPackageName(packageName).setAttributionTag(attributionTag).build();
- return mCheckOpsDelegateDispatcher.checkOperation(code, attributionSource, true /*raw*/);
+ @Nullable String attributionTag) {
+ return mCheckOpsDelegateDispatcher.checkOperation(code, uid, packageName, attributionTag,
+ true /*raw*/);
}
@Override
- public int checkOperationWithStateRaw(int code, AttributionSourceState attributionSourceState) {
- final AttributionSource attributionSource = new AttributionSource(attributionSourceState);
- return mCheckOpsDelegateDispatcher.checkOperation(code, attributionSource, true /*raw*/);
- }
-
- /** @deprecated Use {@link #checkOperationWithState} instead. */
- @Override
public int checkOperation(int code, int uid, String packageName) {
- final AttributionSource attributionSource = new AttributionSource.Builder(uid)
- .setPackageName(packageName)
- .build();
- return mCheckOpsDelegateDispatcher.checkOperation(code, attributionSource, false /*raw*/);
+ return mCheckOpsDelegateDispatcher.checkOperation(code, uid, packageName, null,
+ false /*raw*/);
}
- @Override
- public int checkOperationWithState(int code, AttributionSourceState attributionSourceState) {
- final AttributionSource attributionSource = new AttributionSource(attributionSourceState);
- return mCheckOpsDelegateDispatcher.checkOperation(code, attributionSource, false /*raw*/);
- }
-
- private int checkOperationImpl(int code, AttributionSource attributionSource, boolean raw) {
+ private int checkOperationImpl(int code, int uid, String packageName,
+ @Nullable String attributionTag, boolean raw) {
verifyIncomingOp(code);
- final String packageName = attributionSource.getPackageName();
- final int uid = attributionSource.getUid();
- final String attributionTag = attributionSource.getAttributionTag();
if (!isIncomingPackageValid(packageName, UserHandle.getUserId(uid))) {
return AppOpsManager.opToDefaultMode(code);
}
@@ -2643,10 +2614,7 @@
if (mode != AppOpsManager.MODE_ALLOWED) {
return mode;
}
- final AttributionSource attributionSource = new AttributionSource.Builder(uid)
- .setPackageName(packageName)
- .build();
- return checkOperationWithState(code, attributionSource.asState());
+ return checkOperation(code, uid, packageName);
}
@Override
@@ -2790,38 +2758,17 @@
proxiedFlags, shouldCollectAsyncNotedOp, message, shouldCollectMessage);
}
- /** @deprecated Use {@link #noteOperationWithState} instead. */
@Override
public SyncNotedAppOp noteOperation(int code, int uid, String packageName,
String attributionTag, boolean shouldCollectAsyncNotedOp, String message,
boolean shouldCollectMessage) {
- final AttributionSource attributionSource = new AttributionSource.Builder(uid)
- .setPackageName(packageName)
- .setAttributionTag(attributionTag)
- .build();
- return mCheckOpsDelegateDispatcher.noteOperation(code, attributionSource,
- shouldCollectAsyncNotedOp, message, shouldCollectMessage);
+ return mCheckOpsDelegateDispatcher.noteOperation(code, uid, packageName,
+ attributionTag, shouldCollectAsyncNotedOp, message, shouldCollectMessage);
}
- @Override
- public SyncNotedAppOp noteOperationWithState(
- int code,
- AttributionSourceState attributionSourceState,
- boolean shouldCollectAsyncNotedOp,
- String message,
- boolean shouldCollectMessage) {
- final AttributionSource attributionSource = new AttributionSource(attributionSourceState);
- return mCheckOpsDelegateDispatcher.noteOperation(
- code, attributionSource, shouldCollectAsyncNotedOp, message, shouldCollectMessage);
- }
-
- private SyncNotedAppOp noteOperationImpl(int code, AttributionSource attributionSource,
- boolean shouldCollectAsyncNotedOp,
+ private SyncNotedAppOp noteOperationImpl(int code, int uid, @Nullable String packageName,
+ @Nullable String attributionTag, boolean shouldCollectAsyncNotedOp,
@Nullable String message, boolean shouldCollectMessage) {
- final int uid = attributionSource.getUid();
- final String packageName = attributionSource.getPackageName();
- final String attributionTag = attributionSource.getAttributionTag();
-
verifyIncomingUid(uid);
verifyIncomingOp(code);
if (!isIncomingPackageValid(packageName, UserHandle.getUserId(uid))) {
@@ -3216,42 +3163,22 @@
}
}
- /** @deprecated Use {@link #startOperationWithState} instead. */
@Override
public SyncNotedAppOp startOperation(IBinder token, int code, int uid,
- @Nullable String packageName, @Nullable String attributionTag,
- boolean startIfModeDefault, boolean shouldCollectAsyncNotedOp,
- String message, boolean shouldCollectMessage, @AttributionFlags int attributionFlags,
- int attributionChainId) {
- final AttributionSource attributionSource = new AttributionSource.Builder(uid)
- .setPackageName(packageName)
- .setAttributionTag(attributionTag)
- .build();
- return mCheckOpsDelegateDispatcher.startOperation(token, code, attributionSource,
- startIfModeDefault, shouldCollectAsyncNotedOp, message, shouldCollectMessage,
- attributionFlags, attributionChainId);
- }
-
- @Override
- public SyncNotedAppOp startOperationWithState(IBinder token, int code,
- AttributionSourceState attributionSourceState,
+ @Nullable String packageName, @Nullable String attributionTag,
boolean startIfModeDefault, boolean shouldCollectAsyncNotedOp,
String message, boolean shouldCollectMessage, @AttributionFlags int attributionFlags,
int attributionChainId) {
- final AttributionSource attributionSource = new AttributionSource(attributionSourceState);
- return mCheckOpsDelegateDispatcher.startOperation(token, code, attributionSource,
- startIfModeDefault, shouldCollectAsyncNotedOp, message,
+ return mCheckOpsDelegateDispatcher.startOperation(token, code, uid, packageName,
+ attributionTag, startIfModeDefault, shouldCollectAsyncNotedOp, message,
shouldCollectMessage, attributionFlags, attributionChainId);
}
- private SyncNotedAppOp startOperationImpl(@NonNull IBinder clientId, int code,
- AttributionSource attributionSource, boolean startIfModeDefault,
- boolean shouldCollectAsyncNotedOp, @NonNull String message,
+ private SyncNotedAppOp startOperationImpl(@NonNull IBinder clientId, int code, int uid,
+ @Nullable String packageName, @Nullable String attributionTag,
+ boolean startIfModeDefault, boolean shouldCollectAsyncNotedOp, @NonNull String message,
boolean shouldCollectMessage, @AttributionFlags int attributionFlags,
int attributionChainId) {
- final String packageName = attributionSource.getPackageName();
- final int uid = attributionSource.getUid();
- final String attributionTag = attributionSource.getAttributionTag();
verifyIncomingUid(uid);
verifyIncomingOp(code);
if (!isIncomingPackageValid(packageName, UserHandle.getUserId(uid))) {
@@ -3273,7 +3200,7 @@
int result = MODE_DEFAULT;
if (code == OP_RECORD_AUDIO_HOTWORD || code == OP_RECEIVE_AMBIENT_TRIGGER_AUDIO
|| code == OP_RECORD_AUDIO_SANDBOXED) {
- result = checkOperationWithState(OP_RECORD_AUDIO, attributionSource.asState());
+ result = checkOperation(OP_RECORD_AUDIO, uid, packageName);
// Check result
if (result != AppOpsManager.MODE_ALLOWED) {
return new SyncNotedAppOp(result, code, attributionTag, packageName);
@@ -3281,7 +3208,7 @@
}
// As a special case for OP_CAMERA_SANDBOXED.
if (code == OP_CAMERA_SANDBOXED) {
- result = checkOperationWithState(OP_CAMERA, attributionSource.asState());
+ result = checkOperation(OP_CAMERA, uid, packageName);
// Check result
if (result != AppOpsManager.MODE_ALLOWED) {
return new SyncNotedAppOp(result, code, attributionTag, packageName);
@@ -3585,29 +3512,15 @@
packageName);
}
- /** @deprecated Use {@link #finishOperationWithState} instead. */
@Override
public void finishOperation(IBinder clientId, int code, int uid, String packageName,
String attributionTag) {
- final AttributionSource attributionSource = new AttributionSource.Builder(uid)
- .setPackageName(packageName)
- .setAttributionTag(attributionTag)
- .build();
- mCheckOpsDelegateDispatcher.finishOperation(clientId, code, attributionSource);
+ mCheckOpsDelegateDispatcher.finishOperation(clientId, code, uid, packageName,
+ attributionTag);
}
- @Override
- public void finishOperationWithState(IBinder clientId, int code,
- AttributionSourceState attributionSourceState) {
- final AttributionSource attributionSource = new AttributionSource(attributionSourceState);
- mCheckOpsDelegateDispatcher.finishOperation(clientId, code, attributionSource);
- }
-
- private void finishOperationImpl(IBinder clientId, int code,
- AttributionSource attributionSource) {
- final String packageName = attributionSource.getPackageName();
- final int uid = attributionSource.getUid();
- final String attributionTag = attributionSource.getAttributionTag();
+ private void finishOperationImpl(IBinder clientId, int code, int uid, String packageName,
+ String attributionTag) {
verifyIncomingUid(uid);
verifyIncomingOp(code);
if (!isIncomingPackageValid(packageName, UserHandle.getUserId(uid))) {
@@ -5190,13 +5103,8 @@
}
if (shell.packageName != null) {
- final AttributionSource shellAttributionSource =
- new AttributionSource.Builder(shell.packageUid)
- .setPackageName(shell.packageName)
- .setAttributionTag(shell.attributionTag)
- .build();
- shell.mInterface.startOperationWithState(shell.mToken, shell.op,
- shellAttributionSource.asState(), true, true,
+ shell.mInterface.startOperation(shell.mToken, shell.op, shell.packageUid,
+ shell.packageName, shell.attributionTag, true, true,
"appops start shell command", true,
AppOpsManager.ATTRIBUTION_FLAG_ACCESSOR, ATTRIBUTION_CHAIN_ID_NONE);
} else {
@@ -5211,13 +5119,8 @@
}
if (shell.packageName != null) {
- final AttributionSource shellAttributionSource =
- new AttributionSource.Builder(shell.packageUid)
- .setPackageName(shell.packageName)
- .setAttributionTag(shell.attributionTag)
- .build();
- shell.mInterface.finishOperationWithState(shell.mToken, shell.op,
- shellAttributionSource.asState());
+ shell.mInterface.finishOperation(shell.mToken, shell.op, shell.packageUid,
+ shell.packageName, shell.attributionTag);
} else {
return -1;
}
@@ -6763,24 +6666,25 @@
return mCheckOpsDelegate;
}
- public int checkOperation(int code, AttributionSource attributionSource, boolean raw) {
+ public int checkOperation(int code, int uid, String packageName,
+ @Nullable String attributionTag, boolean raw) {
if (mPolicy != null) {
if (mCheckOpsDelegate != null) {
- return mPolicy.checkOperation(code, attributionSource, raw,
+ return mPolicy.checkOperation(code, uid, packageName, attributionTag, raw,
this::checkDelegateOperationImpl);
} else {
- return mPolicy.checkOperation(code, attributionSource, raw,
+ return mPolicy.checkOperation(code, uid, packageName, attributionTag, raw,
AppOpsService.this::checkOperationImpl);
}
} else if (mCheckOpsDelegate != null) {
- return checkDelegateOperationImpl(code, attributionSource, raw);
+ return checkDelegateOperationImpl(code, uid, packageName, attributionTag, raw);
}
- return checkOperationImpl(code, attributionSource, raw);
+ return checkOperationImpl(code, uid, packageName, attributionTag, raw);
}
- private int checkDelegateOperationImpl(int code, AttributionSource attributionSource,
- boolean raw) {
- return mCheckOpsDelegate.checkOperation(code, attributionSource, raw,
+ private int checkDelegateOperationImpl(int code, int uid, String packageName,
+ @Nullable String attributionTag, boolean raw) {
+ return mCheckOpsDelegate.checkOperation(code, uid, packageName, attributionTag, raw,
AppOpsService.this::checkOperationImpl);
}
@@ -6805,32 +6709,32 @@
AppOpsService.this::checkAudioOperationImpl);
}
- public SyncNotedAppOp noteOperation(int code, AttributionSource attributionSource,
- boolean shouldCollectAsyncNotedOp, String message,
+ public SyncNotedAppOp noteOperation(int code, int uid, String packageName,
+ String attributionTag, boolean shouldCollectAsyncNotedOp, String message,
boolean shouldCollectMessage) {
if (mPolicy != null) {
if (mCheckOpsDelegate != null) {
- return mPolicy.noteOperation(code, attributionSource,
+ return mPolicy.noteOperation(code, uid, packageName, attributionTag,
shouldCollectAsyncNotedOp, message, shouldCollectMessage,
this::noteDelegateOperationImpl);
} else {
- return mPolicy.noteOperation(code, attributionSource,
+ return mPolicy.noteOperation(code, uid, packageName, attributionTag,
shouldCollectAsyncNotedOp, message, shouldCollectMessage,
AppOpsService.this::noteOperationImpl);
}
} else if (mCheckOpsDelegate != null) {
- return noteDelegateOperationImpl(code, attributionSource, shouldCollectAsyncNotedOp,
- message, shouldCollectMessage);
+ return noteDelegateOperationImpl(code, uid, packageName,
+ attributionTag, shouldCollectAsyncNotedOp, message, shouldCollectMessage);
}
- return noteOperationImpl(code, attributionSource,
+ return noteOperationImpl(code, uid, packageName, attributionTag,
shouldCollectAsyncNotedOp, message, shouldCollectMessage);
}
- private SyncNotedAppOp noteDelegateOperationImpl(int code,
- AttributionSource attributionSource,
+ private SyncNotedAppOp noteDelegateOperationImpl(int code, int uid,
+ @Nullable String packageName, @Nullable String featureId,
boolean shouldCollectAsyncNotedOp, @Nullable String message,
boolean shouldCollectMessage) {
- return mCheckOpsDelegate.noteOperation(code, attributionSource,
+ return mCheckOpsDelegate.noteOperation(code, uid, packageName, featureId,
shouldCollectAsyncNotedOp, message, shouldCollectMessage,
AppOpsService.this::noteOperationImpl);
}
@@ -6866,38 +6770,39 @@
AppOpsService.this::noteProxyOperationImpl);
}
- public SyncNotedAppOp startOperation(IBinder token, int code,
- AttributionSource attributionSource, boolean startIfModeDefault,
- boolean shouldCollectAsyncNotedOp, @Nullable String message,
- boolean shouldCollectMessage, @AttributionFlags int attributionFlags,
- int attributionChainId) {
+ public SyncNotedAppOp startOperation(IBinder token, int code, int uid,
+ @Nullable String packageName, @NonNull String attributionTag,
+ boolean startIfModeDefault, boolean shouldCollectAsyncNotedOp,
+ @Nullable String message, boolean shouldCollectMessage,
+ @AttributionFlags int attributionFlags, int attributionChainId) {
if (mPolicy != null) {
if (mCheckOpsDelegate != null) {
- return mPolicy.startOperation(token, code, attributionSource,
- startIfModeDefault, shouldCollectAsyncNotedOp, message,
+ return mPolicy.startOperation(token, code, uid, packageName,
+ attributionTag, startIfModeDefault, shouldCollectAsyncNotedOp, message,
shouldCollectMessage, attributionFlags, attributionChainId,
this::startDelegateOperationImpl);
} else {
- return mPolicy.startOperation(token, code, attributionSource,
+ return mPolicy.startOperation(token, code, uid, packageName, attributionTag,
startIfModeDefault, shouldCollectAsyncNotedOp, message,
shouldCollectMessage, attributionFlags, attributionChainId,
AppOpsService.this::startOperationImpl);
}
} else if (mCheckOpsDelegate != null) {
- return startDelegateOperationImpl(token, code, attributionSource,
+ return startDelegateOperationImpl(token, code, uid, packageName, attributionTag,
startIfModeDefault, shouldCollectAsyncNotedOp, message,
shouldCollectMessage, attributionFlags, attributionChainId);
}
- return startOperationImpl(token, code, attributionSource,
+ return startOperationImpl(token, code, uid, packageName, attributionTag,
startIfModeDefault, shouldCollectAsyncNotedOp, message, shouldCollectMessage,
attributionFlags, attributionChainId);
}
- private SyncNotedAppOp startDelegateOperationImpl(IBinder token, int code,
- AttributionSource attributionSource, boolean startIfModeDefault,
- boolean shouldCollectAsyncNotedOp, String message, boolean shouldCollectMessage,
- @AttributionFlags int attributionFlags, int attributionChainId) {
- return mCheckOpsDelegate.startOperation(token, code, attributionSource,
+ private SyncNotedAppOp startDelegateOperationImpl(IBinder token, int code, int uid,
+ @Nullable String packageName, @Nullable String attributionTag,
+ boolean startIfModeDefault, boolean shouldCollectAsyncNotedOp, String message,
+ boolean shouldCollectMessage, @AttributionFlags int attributionFlags,
+ int attributionChainId) {
+ return mCheckOpsDelegate.startOperation(token, code, uid, packageName, attributionTag,
startIfModeDefault, shouldCollectAsyncNotedOp, message, shouldCollectMessage,
attributionFlags, attributionChainId, AppOpsService.this::startOperationImpl);
}
@@ -6943,26 +6848,26 @@
attributionChainId, AppOpsService.this::startProxyOperationImpl);
}
- public void finishOperation(IBinder clientId, int code,
- AttributionSource attributionSource) {
+ public void finishOperation(IBinder clientId, int code, int uid, String packageName,
+ String attributionTag) {
if (mPolicy != null) {
if (mCheckOpsDelegate != null) {
- mPolicy.finishOperation(clientId, code, attributionSource,
+ mPolicy.finishOperation(clientId, code, uid, packageName, attributionTag,
this::finishDelegateOperationImpl);
} else {
- mPolicy.finishOperation(clientId, code, attributionSource,
+ mPolicy.finishOperation(clientId, code, uid, packageName, attributionTag,
AppOpsService.this::finishOperationImpl);
}
} else if (mCheckOpsDelegate != null) {
- finishDelegateOperationImpl(clientId, code, attributionSource);
+ finishDelegateOperationImpl(clientId, code, uid, packageName, attributionTag);
} else {
- finishOperationImpl(clientId, code, attributionSource);
+ finishOperationImpl(clientId, code, uid, packageName, attributionTag);
}
}
- private void finishDelegateOperationImpl(IBinder clientId, int code,
- AttributionSource attributionSource) {
- mCheckOpsDelegate.finishOperation(clientId, code, attributionSource,
+ private void finishDelegateOperationImpl(IBinder clientId, int code, int uid,
+ String packageName, String attributionTag) {
+ mCheckOpsDelegate.finishOperation(clientId, code, uid, packageName, attributionTag,
AppOpsService.this::finishOperationImpl);
}
diff --git a/services/core/java/com/android/server/policy/AppOpsPolicy.java b/services/core/java/com/android/server/policy/AppOpsPolicy.java
index c2821ae..b83421f 100644
--- a/services/core/java/com/android/server/policy/AppOpsPolicy.java
+++ b/services/core/java/com/android/server/policy/AppOpsPolicy.java
@@ -50,12 +50,11 @@
import android.util.SparseArray;
import com.android.internal.annotations.GuardedBy;
+import com.android.internal.util.function.HeptFunction;
import com.android.internal.util.function.HexFunction;
-import com.android.internal.util.function.NonaFunction;
import com.android.internal.util.function.QuadFunction;
+import com.android.internal.util.function.QuintConsumer;
import com.android.internal.util.function.QuintFunction;
-import com.android.internal.util.function.TriConsumer;
-import com.android.internal.util.function.TriFunction;
import com.android.internal.util.function.UndecFunction;
import com.android.server.LocalServices;
@@ -230,12 +229,10 @@
}
@Override
- public int checkOperation(int code, AttributionSource attributionSource, boolean raw,
- TriFunction<Integer, AttributionSource, Boolean, Integer> superImpl) {
- final int uid = attributionSource.getUid();
- final AttributionSource resolvedAttributionSource =
- attributionSource.withUid(resolveUid(code, uid));
- return superImpl.apply(code, resolvedAttributionSource, raw);
+ public int checkOperation(int code, int uid, String packageName,
+ @Nullable String attributionTag, boolean raw,
+ QuintFunction<Integer, Integer, String, String, Boolean, Integer> superImpl) {
+ return superImpl.apply(code, resolveUid(code, uid), packageName, attributionTag, raw);
}
@Override
@@ -245,25 +242,21 @@
}
@Override
- public SyncNotedAppOp noteOperation(int code, AttributionSource attributionSource,
- boolean shouldCollectAsyncNotedOp, @Nullable
- String message, boolean shouldCollectMessage,
- @NonNull QuintFunction<Integer, AttributionSource, Boolean, String, Boolean,
- SyncNotedAppOp> superImpl) {
- final int uid = attributionSource.getUid();
- final AttributionSource resolvedAttributionSource =
- attributionSource.withUid(resolveUid(code, uid));
- return superImpl.apply(resolveDatasourceOp(code, uid, attributionSource.getPackageName(),
- attributionSource.getAttributionTag()), resolvedAttributionSource,
- shouldCollectAsyncNotedOp, message, shouldCollectMessage);
+ public SyncNotedAppOp noteOperation(int code, int uid, @Nullable String packageName,
+ @Nullable String attributionTag, boolean shouldCollectAsyncNotedOp, @Nullable
+ String message, boolean shouldCollectMessage, @NonNull HeptFunction<Integer, Integer,
+ String, String, Boolean, String, Boolean, SyncNotedAppOp> superImpl) {
+ return superImpl.apply(resolveDatasourceOp(code, uid, packageName, attributionTag),
+ resolveUid(code, uid), packageName, attributionTag, shouldCollectAsyncNotedOp,
+ message, shouldCollectMessage);
}
@Override
public SyncNotedAppOp noteProxyOperation(int code, @NonNull AttributionSource attributionSource,
boolean shouldCollectAsyncNotedOp, @Nullable String message,
boolean shouldCollectMessage, boolean skipProxyOperation, @NonNull HexFunction<Integer,
- AttributionSource, Boolean, String, Boolean, Boolean,
- SyncNotedAppOp> superImpl) {
+ AttributionSource, Boolean, String, Boolean, Boolean,
+ SyncNotedAppOp> superImpl) {
return superImpl.apply(resolveDatasourceOp(code, attributionSource.getUid(),
attributionSource.getPackageName(), attributionSource.getAttributionTag()),
attributionSource, shouldCollectAsyncNotedOp, message, shouldCollectMessage,
@@ -271,21 +264,17 @@
}
@Override
- public SyncNotedAppOp startOperation(IBinder token, int code,
- AttributionSource attributionSource,
+ public SyncNotedAppOp startOperation(IBinder token, int code, int uid,
+ @Nullable String packageName, @Nullable String attributionTag,
boolean startIfModeDefault, boolean shouldCollectAsyncNotedOp, String message,
boolean shouldCollectMessage, @AttributionFlags int attributionFlags,
- int attributionChainId,
- @NonNull NonaFunction<IBinder, Integer, AttributionSource, Boolean, Boolean, String,
- Boolean, Integer, Integer,
- SyncNotedAppOp> superImpl) {
- final int uid = attributionSource.getUid();
- final AttributionSource resolvedAttributionSource =
- attributionSource.withUid(resolveUid(code, uid));
- return superImpl.apply(token, resolveDatasourceOp(code, uid,
- attributionSource.getPackageName(), attributionSource.getAttributionTag()),
- resolvedAttributionSource, startIfModeDefault, shouldCollectAsyncNotedOp, message,
- shouldCollectMessage, attributionFlags, attributionChainId);
+ int attributionChainId, @NonNull UndecFunction<IBinder, Integer, Integer, String,
+ String, Boolean, Boolean, String, Boolean, Integer, Integer,
+ SyncNotedAppOp> superImpl) {
+ return superImpl.apply(token, resolveDatasourceOp(code, uid, packageName, attributionTag),
+ resolveUid(code, uid), packageName, attributionTag, startIfModeDefault,
+ shouldCollectAsyncNotedOp, message, shouldCollectMessage, attributionFlags,
+ attributionChainId);
}
@Override
@@ -304,14 +293,11 @@
}
@Override
- public void finishOperation(IBinder clientId, int code, AttributionSource attributionSource,
- @NonNull TriConsumer<IBinder, Integer, AttributionSource> superImpl) {
- final int uid = attributionSource.getUid();
- final AttributionSource resolvedAttributionSource =
- attributionSource.withUid(resolveUid(code, uid));
- superImpl.accept(clientId, resolveDatasourceOp(code, uid,
- attributionSource.getPackageName(), attributionSource.getAttributionTag()),
- resolvedAttributionSource);
+ public void finishOperation(IBinder clientId, int code, int uid, String packageName,
+ String attributionTag,
+ @NonNull QuintConsumer<IBinder, Integer, Integer, String, String> superImpl) {
+ superImpl.accept(clientId, resolveDatasourceOp(code, uid, packageName, attributionTag),
+ resolveUid(code, uid), packageName, attributionTag);
}
@Override
diff --git a/services/tests/mockingservicestests/src/com/android/server/AppStateTrackerTest.java b/services/tests/mockingservicestests/src/com/android/server/AppStateTrackerTest.java
index 7ceccc5..47ae97f 100644
--- a/services/tests/mockingservicestests/src/com/android/server/AppStateTrackerTest.java
+++ b/services/tests/mockingservicestests/src/com/android/server/AppStateTrackerTest.java
@@ -44,7 +44,6 @@
import android.app.IActivityManager;
import android.app.IUidObserver;
import android.app.usage.UsageStatsManager;
-import android.content.AttributionSourceState;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
@@ -230,20 +229,12 @@
private AppStateTrackerTestable newInstance() throws Exception {
MockitoAnnotations.initMocks(this);
- when(mMockIAppOpsService.checkOperationWithState(eq(TARGET_OP), any()))
- .thenAnswer(
- (Answer<Integer>)
- invocation -> {
- AttributionSourceState attribution =
- (AttributionSourceState) invocation.getArguments()[1];
- return mRestrictedPackages.indexOf(
- Pair.create(
- attribution.uid,
- attribution.packageName))
- >= 0
- ? AppOpsManager.MODE_IGNORED
- : AppOpsManager.MODE_ALLOWED;
- });
+ when(mMockIAppOpsService.checkOperation(eq(TARGET_OP), anyInt(), anyString()))
+ .thenAnswer(inv -> {
+ return mRestrictedPackages.indexOf(
+ Pair.create(inv.getArgument(1), inv.getArgument(2))) >= 0 ?
+ AppOpsManager.MODE_IGNORED : AppOpsManager.MODE_ALLOWED;
+ });
final AppStateTrackerTestable instance = new AppStateTrackerTestable();
diff --git a/services/tests/mockingservicestests/src/com/android/server/am/ActivityManagerServiceTest.java b/services/tests/mockingservicestests/src/com/android/server/am/ActivityManagerServiceTest.java
index 3ee8050..40b5458 100644
--- a/services/tests/mockingservicestests/src/com/android/server/am/ActivityManagerServiceTest.java
+++ b/services/tests/mockingservicestests/src/com/android/server/am/ActivityManagerServiceTest.java
@@ -69,7 +69,6 @@
import android.app.IApplicationThread;
import android.app.IUidObserver;
import android.app.SyncNotedAppOp;
-import android.content.AttributionSourceState;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
@@ -224,16 +223,12 @@
assertThat(sProcessListSettingsListener).isNotNull();
}
- private void mockNoteOp() {
+ private void mockNoteOperation() {
SyncNotedAppOp allowed = new SyncNotedAppOp(AppOpsManager.MODE_ALLOWED,
AppOpsManager.OP_GET_USAGE_STATS, null, mContext.getPackageName());
- when(mAppOpsService.noteOperationWithState(
- eq(AppOpsManager.OP_GET_USAGE_STATS),
- any(AttributionSourceState.class),
- any(Boolean.class),
- nullable(String.class),
- any(Boolean.class)))
- .thenReturn(allowed);
+ when(mAppOpsService.noteOperation(eq(AppOpsManager.OP_GET_USAGE_STATS), eq(Process.myUid()),
+ nullable(String.class), nullable(String.class), any(Boolean.class),
+ nullable(String.class), any(Boolean.class))).thenReturn(allowed);
}
@After
@@ -614,7 +609,7 @@
*/
@Test
public void testDispatchUids_dispatchNeededChanges() throws RemoteException {
- mockNoteOp();
+ mockNoteOperation();
final int[] changesToObserve = {
ActivityManager.UID_OBSERVER_PROCSTATE,
@@ -823,7 +818,7 @@
*/
@Test
public void testDispatchUidChanges_procStateCutpoint() throws RemoteException {
- mockNoteOp();
+ mockNoteOperation();
final IUidObserver observer = mock(IUidObserver.Stub.class);
@@ -893,7 +888,7 @@
*/
@Test
public void testDispatchUidChanges_validateUidsUpdated() {
- mockNoteOp();
+ mockNoteOperation();
final int[] changesForPendingItems = UID_RECORD_CHANGES;
diff --git a/services/tests/mockingservicestests/src/com/android/server/am/BackgroundRestrictionTest.java b/services/tests/mockingservicestests/src/com/android/server/am/BackgroundRestrictionTest.java
index dcbee83..bb91939 100644
--- a/services/tests/mockingservicestests/src/com/android/server/am/BackgroundRestrictionTest.java
+++ b/services/tests/mockingservicestests/src/com/android/server/am/BackgroundRestrictionTest.java
@@ -113,8 +113,6 @@
import android.app.NotificationManager;
import android.app.role.RoleManager;
import android.app.usage.AppStandbyInfo;
-import android.content.AttributionSource;
-import android.content.AttributionSourceState;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
@@ -2456,12 +2454,9 @@
doReturn(granted ? MODE_ALLOWED : MODE_IGNORED)
.when(mAppOpsManager)
.checkOpNoThrow(op, uid, packageName);
- AttributionSource attributionSource =
- new AttributionSource.Builder(uid).setPackageName(packageName).build();
- AttributionSourceState attributionSourceState = attributionSource.asState();
doReturn(granted ? MODE_ALLOWED : MODE_IGNORED)
.when(mIAppOpsService)
- .checkOperationWithState(eq(op), eq(attributionSourceState));
+ .checkOperation(op, uid, packageName);
} catch (RemoteException e) {
// Ignore.
}
diff --git a/services/tests/mockingservicestests/src/com/android/server/appop/AppOpsServiceTest.java b/services/tests/mockingservicestests/src/com/android/server/appop/AppOpsServiceTest.java
index daed5df..646f486 100644
--- a/services/tests/mockingservicestests/src/com/android/server/appop/AppOpsServiceTest.java
+++ b/services/tests/mockingservicestests/src/com/android/server/appop/AppOpsServiceTest.java
@@ -49,7 +49,6 @@
import android.app.AppOpsManager;
import android.app.AppOpsManager.OpEntry;
import android.app.AppOpsManager.PackageOps;
-import android.content.AttributionSource;
import android.content.ContentResolver;
import android.content.Context;
import android.content.pm.PackageManagerInternal;
@@ -217,21 +216,18 @@
}
@Test
- public void testNoteOpAndGetOpsForPackage() {
+ public void testNoteOperationAndGetOpsForPackage() {
mAppOpsService.setMode(OP_READ_SMS, mMyUid, sMyPackageName, MODE_ALLOWED);
mAppOpsService.setMode(OP_WRITE_SMS, mMyUid, sMyPackageName, MODE_ERRORED);
- AttributionSource attributionSource =
- new AttributionSource.Builder(mMyUid).setPackageName(sMyPackageName).build();
// Note an op that's allowed.
- mAppOpsService.noteOperationWithState(OP_READ_SMS, attributionSource.asState(), false,
- null, false);
+ mAppOpsService.noteOperation(OP_READ_SMS, mMyUid, sMyPackageName, null, false, null, false);
List<PackageOps> loggedOps = getLoggedOps();
assertContainsOp(loggedOps, OP_READ_SMS, mTestStartMillis, -1, MODE_ALLOWED);
// Note another op that's not allowed.
- mAppOpsService.noteOperationWithState(OP_WRITE_SMS, attributionSource.asState(), false,
- null, false);
+ mAppOpsService.noteOperation(OP_WRITE_SMS, mMyUid, sMyPackageName, null, false, null,
+ false);
loggedOps = getLoggedOps();
assertContainsOp(loggedOps, OP_READ_SMS, mTestStartMillis, -1, MODE_ALLOWED);
assertContainsOp(loggedOps, OP_WRITE_SMS, -1, mTestStartMillis, MODE_ERRORED);
@@ -243,24 +239,20 @@
* ACCESS_COARSE_LOCATION op is used to check whether WIFI_SCAN is allowed.
*/
@Test
- public void testNoteOpAndGetOpsForPackage_controlledByDifferentOp() {
+ public void testNoteOperationAndGetOpsForPackage_controlledByDifferentOp() {
// This op controls WIFI_SCAN
mAppOpsService.setMode(OP_COARSE_LOCATION, mMyUid, sMyPackageName, MODE_ALLOWED);
- assertThat(mAppOpsService.noteOperationWithState(OP_WIFI_SCAN,
- new AttributionSource.Builder(mMyUid).setPackageName(sMyPackageName)
- .build().asState(), false, null, false).getOpMode())
- .isEqualTo(MODE_ALLOWED);
+ assertThat(mAppOpsService.noteOperation(OP_WIFI_SCAN, mMyUid, sMyPackageName, null, false,
+ null, false).getOpMode()).isEqualTo(MODE_ALLOWED);
assertContainsOp(getLoggedOps(), OP_WIFI_SCAN, mTestStartMillis, -1,
MODE_ALLOWED /* default for WIFI_SCAN; this is not changed or used in this test */);
// Now set COARSE_LOCATION to ERRORED -> this will make WIFI_SCAN disabled as well.
mAppOpsService.setMode(OP_COARSE_LOCATION, mMyUid, sMyPackageName, MODE_ERRORED);
- assertThat(mAppOpsService.noteOperationWithState(OP_WIFI_SCAN,
- new AttributionSource.Builder(mMyUid).setPackageName(sMyPackageName)
- .build().asState(), false, null, false)
- .getOpMode()).isEqualTo(MODE_ERRORED);
+ assertThat(mAppOpsService.noteOperation(OP_WIFI_SCAN, mMyUid, sMyPackageName, null, false,
+ null, false).getOpMode()).isEqualTo(MODE_ERRORED);
assertContainsOp(getLoggedOps(), OP_WIFI_SCAN, mTestStartMillis, mTestStartMillis,
MODE_ALLOWED /* default for WIFI_SCAN; this is not changed or used in this test */);
@@ -271,12 +263,9 @@
public void testStatePersistence() {
mAppOpsService.setMode(OP_READ_SMS, mMyUid, sMyPackageName, MODE_ALLOWED);
mAppOpsService.setMode(OP_WRITE_SMS, mMyUid, sMyPackageName, MODE_ERRORED);
- AttributionSource attributionSource =
- new AttributionSource.Builder(mMyUid).setPackageName(sMyPackageName).build();
- mAppOpsService.noteOperationWithState(OP_READ_SMS, attributionSource.asState(), false,
- null, false);
- mAppOpsService.noteOperationWithState(OP_WRITE_SMS, attributionSource.asState(), false,
- null, false);
+ mAppOpsService.noteOperation(OP_READ_SMS, mMyUid, sMyPackageName, null, false, null, false);
+ mAppOpsService.noteOperation(OP_WRITE_SMS, mMyUid, sMyPackageName, null, false, null,
+ false);
mAppOpsService.shutdown();
@@ -294,10 +283,7 @@
@Test
public void testShutdown() {
mAppOpsService.setMode(OP_READ_SMS, mMyUid, sMyPackageName, MODE_ALLOWED);
- AttributionSource attributionSource =
- new AttributionSource.Builder(mMyUid).setPackageName(sMyPackageName).build();
- mAppOpsService.noteOperationWithState(OP_READ_SMS, attributionSource.asState(), false,
- null, false);
+ mAppOpsService.noteOperation(OP_READ_SMS, mMyUid, sMyPackageName, null, false, null, false);
mAppOpsService.shutdown();
// Create a new app ops service which will initialize its state from XML.
@@ -311,10 +297,7 @@
@Test
public void testGetOpsForPackage() {
mAppOpsService.setMode(OP_READ_SMS, mMyUid, sMyPackageName, MODE_ALLOWED);
- AttributionSource attributionSource =
- new AttributionSource.Builder(mMyUid).setPackageName(sMyPackageName).build();
- mAppOpsService.noteOperationWithState(OP_READ_SMS, attributionSource.asState(), false,
- null, false);
+ mAppOpsService.noteOperation(OP_READ_SMS, mMyUid, sMyPackageName, null, false, null, false);
// Query all ops
List<PackageOps> loggedOps = mAppOpsService.getOpsForPackage(
@@ -343,10 +326,7 @@
@Test
public void testPackageRemoved() {
mAppOpsService.setMode(OP_READ_SMS, mMyUid, sMyPackageName, MODE_ALLOWED);
- AttributionSource attributionSource =
- new AttributionSource.Builder(mMyUid).setPackageName(sMyPackageName).build();
- mAppOpsService.noteOperationWithState(OP_READ_SMS, attributionSource.asState(), false,
- null, false);
+ mAppOpsService.noteOperation(OP_READ_SMS, mMyUid, sMyPackageName, null, false, null, false);
List<PackageOps> loggedOps = getLoggedOps();
assertContainsOp(loggedOps, OP_READ_SMS, mTestStartMillis, -1, MODE_ALLOWED);
@@ -361,8 +341,7 @@
@Test
public void testPackageRemovedHistoricalOps() throws InterruptedException {
mAppOpsService.setMode(OP_READ_SMS, mMyUid, sMyPackageName, MODE_ALLOWED);
- mAppOpsService.noteOperationWithState(OP_READ_SMS, mMyUid, sMyPackageName, null, false,
- null, false);
+ mAppOpsService.noteOperation(OP_READ_SMS, mMyUid, sMyPackageName, null, false, null, false);
AppOpsManager.HistoricalOps historicalOps = new AppOpsManager.HistoricalOps(0, 15000);
historicalOps.increaseAccessCount(OP_READ_SMS, mMyUid, sMyPackageName, null,
@@ -402,10 +381,7 @@
@Test
public void testUidRemoved() {
mAppOpsService.setMode(OP_READ_SMS, mMyUid, sMyPackageName, MODE_ALLOWED);
- AttributionSource attributionSource =
- new AttributionSource.Builder(mMyUid).setPackageName(sMyPackageName).build();
- mAppOpsService.noteOperationWithState(OP_READ_SMS, attributionSource.asState(),
- false, null, false);
+ mAppOpsService.noteOperation(OP_READ_SMS, mMyUid, sMyPackageName, null, false, null, false);
List<PackageOps> loggedOps = getLoggedOps();
assertContainsOp(loggedOps, OP_READ_SMS, mTestStartMillis, -1, MODE_ALLOWED);
@@ -417,10 +393,7 @@
@Test
public void testUidStateInitializationDoesntClearState() throws InterruptedException {
mAppOpsService.setMode(OP_READ_SMS, mMyUid, sMyPackageName, MODE_ALLOWED);
- AttributionSource attributionSource =
- new AttributionSource.Builder(mMyUid).setPackageName(sMyPackageName).build();
- mAppOpsService.noteOperationWithState(OP_READ_SMS, attributionSource.asState(), false,
- null, false);
+ mAppOpsService.noteOperation(OP_READ_SMS, mMyUid, sMyPackageName, null, false, null, false);
mAppOpsService.initializeUidStates();
List<PackageOps> ops = mAppOpsService.getOpsForPackage(mMyUid, sMyPackageName,
new int[]{OP_READ_SMS});
diff --git a/services/tests/servicestests/src/com/android/server/pm/SuspendPackagesTest.java b/services/tests/servicestests/src/com/android/server/pm/SuspendPackagesTest.java
index 01a91c1..398148f 100644
--- a/services/tests/servicestests/src/com/android/server/pm/SuspendPackagesTest.java
+++ b/services/tests/servicestests/src/com/android/server/pm/SuspendPackagesTest.java
@@ -30,7 +30,6 @@
import static org.junit.Assert.fail;
import android.app.AppGlobals;
-import android.content.AttributionSource;
import android.content.Context;
import android.content.pm.IPackageManager;
import android.content.pm.LauncherApps;
@@ -282,16 +281,12 @@
};
iAppOps.startWatchingMode(code, TEST_APP_PACKAGE_NAME, watcher);
final int testPackageUid = mPackageManager.getPackageUid(TEST_APP_PACKAGE_NAME, 0);
- AttributionSource attributionSource =
- new AttributionSource.Builder(testPackageUid)
- .setPackageName(TEST_APP_PACKAGE_NAME)
- .build();
- int opMode = iAppOps.checkOperationWithState(code, attributionSource.asState());
+ int opMode = iAppOps.checkOperation(code, testPackageUid, TEST_APP_PACKAGE_NAME);
assertEquals("Op " + opToName(code) + " disallowed for unsuspended package", MODE_ALLOWED,
opMode);
suspendTestPackage(null, null, null);
assertTrue("AppOpsWatcher did not callback", latch.await(5, TimeUnit.SECONDS));
- opMode = iAppOps.checkOperationWithState(code, attributionSource.asState());
+ opMode = iAppOps.checkOperation(code, testPackageUid, TEST_APP_PACKAGE_NAME);
assertEquals("Op " + opToName(code) + " allowed for suspended package", MODE_IGNORED,
opMode);
iAppOps.stopWatchingMode(watcher);