From b8488603d6932262e652b740cbf75b9d580caffb Mon Sep 17 00:00:00 2001 From: Guojing Yuan Date: Tue, 18 May 2021 18:12:40 +0000 Subject: [PATCH] Avoid a SecurityExcetion crash 1. Instead of throwing SecurityException, log the error. 2. Set isAttributionTagNotFound to true when the attributionTag is not null but not found in the package attributions. Fix: 188549667 Test: N/A Change-Id: I75a217893353ee5fe5d191e2b78ccf391847adb6 --- core/java/android/app/AppOpsManager.java | 13 +++++++++++++ .../com/android/server/appop/AppOpsService.java | 12 +++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/core/java/android/app/AppOpsManager.java b/core/java/android/app/AppOpsManager.java index 010f4e4c99513..5e64d095c9c3a 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 a23b5eb50b159..80340d137de98 100644 --- a/services/core/java/com/android/server/appop/AppOpsService.java +++ b/services/core/java/com/android/server/appop/AppOpsService.java @@ -3295,6 +3295,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, @@ -3787,6 +3790,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, @@ -3934,6 +3940,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; @@ -4394,6 +4403,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; @@ -4405,7 +4415,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); }