Merge "Avoid a SecurityExcetion crash" into sc-dev am: d0bcac4e41

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/14625639

Change-Id: I1b2e26f826f7947d210205cadecb6541df815516
This commit is contained in:
TreeHugger Robot
2021-05-21 00:40:42 +00:00
committed by Automerger Merge Worker
2 changed files with 24 additions and 1 deletions

View File

@@ -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);
}

View File

@@ -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);
}