Merge "Avoid a SecurityExcetion crash" into sc-dev

This commit is contained in:
TreeHugger Robot
2021-05-21 00:38:53 +00:00
committed by Android (Google) Code Review
2 changed files with 24 additions and 1 deletions

View File

@@ -3058,11 +3058,24 @@ public class AppOpsManager {
*/ */
public boolean isRecordAudioRestrictionExcept; 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) { public RestrictionBypass(boolean isPrivileged, boolean isRecordAudioRestrictionExcept) {
this.isPrivileged = isPrivileged; this.isPrivileged = isPrivileged;
this.isRecordAudioRestrictionExcept = isRecordAudioRestrictionExcept; 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); public static RestrictionBypass UNRESTRICTED = new RestrictionBypass(true, true);
} }

View File

@@ -3303,6 +3303,9 @@ public class AppOpsService extends IAppOpsService.Stub {
RestrictionBypass bypass; RestrictionBypass bypass;
try { try {
bypass = verifyAndGetBypass(uid, packageName, attributionTag, proxyPackageName); bypass = verifyAndGetBypass(uid, packageName, attributionTag, proxyPackageName);
if (bypass != null && bypass.getIsAttributionTagNotFound()) {
attributionTag = null;
}
} catch (SecurityException e) { } catch (SecurityException e) {
Slog.e(TAG, "noteOperation", e); Slog.e(TAG, "noteOperation", e);
return new SyncNotedAppOp(AppOpsManager.MODE_ERRORED, code, attributionTag, return new SyncNotedAppOp(AppOpsManager.MODE_ERRORED, code, attributionTag,
@@ -3795,6 +3798,9 @@ public class AppOpsService extends IAppOpsService.Stub {
RestrictionBypass bypass; RestrictionBypass bypass;
try { try {
bypass = verifyAndGetBypass(uid, packageName, attributionTag, proxyPackageName); bypass = verifyAndGetBypass(uid, packageName, attributionTag, proxyPackageName);
if (bypass != null && bypass.getIsAttributionTagNotFound()) {
attributionTag = null;
}
} catch (SecurityException e) { } catch (SecurityException e) {
Slog.e(TAG, "startOperation", e); Slog.e(TAG, "startOperation", e);
return new SyncNotedAppOp(AppOpsManager.MODE_ERRORED, code, attributionTag, return new SyncNotedAppOp(AppOpsManager.MODE_ERRORED, code, attributionTag,
@@ -3942,6 +3948,9 @@ public class AppOpsService extends IAppOpsService.Stub {
RestrictionBypass bypass; RestrictionBypass bypass;
try { try {
bypass = verifyAndGetBypass(uid, packageName, attributionTag); bypass = verifyAndGetBypass(uid, packageName, attributionTag);
if (bypass != null && bypass.getIsAttributionTagNotFound()) {
attributionTag = null;
}
} catch (SecurityException e) { } catch (SecurityException e) {
Slog.e(TAG, "Cannot finishOperation", e); Slog.e(TAG, "Cannot finishOperation", e);
return; return;
@@ -4402,6 +4411,7 @@ public class AppOpsService extends IAppOpsService.Stub {
} else if (pkg != null) { } else if (pkg != null) {
msg = "attributionTag " + attributionTag + " not declared in manifest of " msg = "attributionTag " + attributionTag + " not declared in manifest of "
+ packageName; + packageName;
bypass.setIsAttributionTagNotFound(true);
} else { } else {
msg = "package " + packageName + " not found, can't check for " msg = "package " + packageName + " not found, can't check for "
+ "attributionTag " + attributionTag; + "attributionTag " + attributionTag;
@@ -4413,7 +4423,7 @@ public class AppOpsService extends IAppOpsService.Stub {
userId) && mPlatformCompat.isChangeEnabledByUid( userId) && mPlatformCompat.isChangeEnabledByUid(
SECURITY_EXCEPTION_ON_INVALID_ATTRIBUTION_TAG_CHANGE, SECURITY_EXCEPTION_ON_INVALID_ATTRIBUTION_TAG_CHANGE,
callingUid) && !foundInProxy) { callingUid) && !foundInProxy) {
throw new SecurityException(msg); Slog.e(TAG, msg);
} else { } else {
Slog.e(TAG, msg); Slog.e(TAG, msg);
} }