diff --git a/core/java/android/app/AppOpsManager.java b/core/java/android/app/AppOpsManager.java index 9c51236e2997e..53502d4e933f7 100644 --- a/core/java/android/app/AppOpsManager.java +++ b/core/java/android/app/AppOpsManager.java @@ -3058,11 +3058,24 @@ public class AppOpsManager { */ public boolean isRecordAudioRestrictionExcept; + /** + * Is attribution tag not null and not contained in the package attributions + */ + public boolean isAttributionTagNotFound = false; + public RestrictionBypass(boolean isPrivileged, boolean isRecordAudioRestrictionExcept) { this.isPrivileged = isPrivileged; this.isRecordAudioRestrictionExcept = isRecordAudioRestrictionExcept; } + public void setIsAttributionTagNotFound(boolean isAttributionTagNotFound) { + this.isAttributionTagNotFound = isAttributionTagNotFound; + } + + public boolean getIsAttributionTagNotFound() { + return this.isAttributionTagNotFound; + } + public static RestrictionBypass UNRESTRICTED = new RestrictionBypass(true, true); } diff --git a/services/core/java/com/android/server/appop/AppOpsService.java b/services/core/java/com/android/server/appop/AppOpsService.java index b6aec8368ac09..c5582a0365493 100644 --- a/services/core/java/com/android/server/appop/AppOpsService.java +++ b/services/core/java/com/android/server/appop/AppOpsService.java @@ -3303,6 +3303,9 @@ public class AppOpsService extends IAppOpsService.Stub { RestrictionBypass bypass; try { bypass = verifyAndGetBypass(uid, packageName, attributionTag, proxyPackageName); + if (bypass != null && bypass.getIsAttributionTagNotFound()) { + attributionTag = null; + } } catch (SecurityException e) { Slog.e(TAG, "noteOperation", e); return new SyncNotedAppOp(AppOpsManager.MODE_ERRORED, code, attributionTag, @@ -3795,6 +3798,9 @@ public class AppOpsService extends IAppOpsService.Stub { RestrictionBypass bypass; try { bypass = verifyAndGetBypass(uid, packageName, attributionTag, proxyPackageName); + if (bypass != null && bypass.getIsAttributionTagNotFound()) { + attributionTag = null; + } } catch (SecurityException e) { Slog.e(TAG, "startOperation", e); return new SyncNotedAppOp(AppOpsManager.MODE_ERRORED, code, attributionTag, @@ -3942,6 +3948,9 @@ public class AppOpsService extends IAppOpsService.Stub { RestrictionBypass bypass; try { bypass = verifyAndGetBypass(uid, packageName, attributionTag); + if (bypass != null && bypass.getIsAttributionTagNotFound()) { + attributionTag = null; + } } catch (SecurityException e) { Slog.e(TAG, "Cannot finishOperation", e); return; @@ -4402,6 +4411,7 @@ public class AppOpsService extends IAppOpsService.Stub { } else if (pkg != null) { msg = "attributionTag " + attributionTag + " not declared in manifest of " + packageName; + bypass.setIsAttributionTagNotFound(true); } else { msg = "package " + packageName + " not found, can't check for " + "attributionTag " + attributionTag; @@ -4413,7 +4423,7 @@ public class AppOpsService extends IAppOpsService.Stub { userId) && mPlatformCompat.isChangeEnabledByUid( SECURITY_EXCEPTION_ON_INVALID_ATTRIBUTION_TAG_CHANGE, callingUid) && !foundInProxy) { - throw new SecurityException(msg); + Slog.e(TAG, msg); } else { Slog.e(TAG, msg); }