diff options
author | Kiran Ramachandra <kiranmr@google.com> | 2023-12-19 21:33:56 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2024-02-08 05:19:37 +0000 |
commit | 6beb68ca17d1220f3f09a53cf0a0c541db4ead62 (patch) | |
tree | 507c00d32be0b7ed2284c72387412a9afdd7d204 | |
parent | f10085bfcaaac3ac0c4568703ad0e4f1febecb46 (diff) | |
download | base-6beb68ca17d1220f3f09a53cf0a0c541db4ead62.tar.gz |
RESTRICT AUTOMERGE Added limitations for attributions to handle invalid cases
Bug: 304983146
Test: Modified and introduced new tests to verify change -> atest CtsAppOpsTestCases:AttributionTest
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:2806d263c0b74da36d6d2bcc1583ea641266fd43)
Merged-In: Iee26fdb9cf1ca0fa8905e22732c32ec7d9b80fea
Change-Id: Iee26fdb9cf1ca0fa8905e22732c32ec7d9b80fea
-rw-r--r-- | services/core/java/com/android/server/appop/AppOpsService.java | 38 | ||||
-rw-r--r-- | services/core/java/com/android/server/pm/pkg/component/ParsedAttributionImpl.java | 2 |
2 files changed, 39 insertions, 1 deletions
diff --git a/services/core/java/com/android/server/appop/AppOpsService.java b/services/core/java/com/android/server/appop/AppOpsService.java index a110169ac8c2..33655f748230 100644 --- a/services/core/java/com/android/server/appop/AppOpsService.java +++ b/services/core/java/com/android/server/appop/AppOpsService.java @@ -2640,6 +2640,10 @@ public class AppOpsService extends IAppOpsService.Stub { return new SyncNotedAppOp(AppOpsManager.MODE_ERRORED, code, attributionTag, packageName); } + if (proxyAttributionTag != null + && !isAttributionTagDefined(packageName, proxyPackageName, proxyAttributionTag)) { + proxyAttributionTag = null; + } synchronized (this) { final Ops ops = getOpsLocked(uid, packageName, attributionTag, @@ -3177,6 +3181,10 @@ public class AppOpsService extends IAppOpsService.Stub { return new SyncNotedAppOp(AppOpsManager.MODE_ERRORED, code, attributionTag, packageName); } + if (proxyAttributionTag != null + && !isAttributionTagDefined(packageName, proxyPackageName, proxyAttributionTag)) { + proxyAttributionTag = null; + } boolean isRestricted = false; int startType = START_TYPE_FAILED; @@ -3910,6 +3918,36 @@ public class AppOpsService extends IAppOpsService.Stub { } /** + * Checks to see if the attribution tag is defined in either package or proxyPackage. + * This method is intended for ProxyAttributionTag validation and returns false + * if it does not exist in either one of them. + * + * @param packageName Name of the package + * @param proxyPackageName Name of the proxy package + * @param attributionTag attribution tag to be checked + * + * @return boolean specifying if attribution tag is valid or not + */ + private boolean isAttributionTagDefined(@Nullable String packageName, + @Nullable String proxyPackageName, + @Nullable String attributionTag) { + if (packageName == null) { + return false; + } else if (attributionTag == null) { + return true; + } + PackageManagerInternal pmInt = LocalServices.getService(PackageManagerInternal.class); + if (proxyPackageName != null) { + AndroidPackage proxyPkg = pmInt.getPackage(proxyPackageName); + if (proxyPkg != null && isAttributionInPackage(proxyPkg, attributionTag)) { + return true; + } + } + AndroidPackage pkg = pmInt.getPackage(packageName); + return isAttributionInPackage(pkg, attributionTag); + } + + /** * Get (and potentially create) ops. * * @param uid The uid the package belongs to diff --git a/services/core/java/com/android/server/pm/pkg/component/ParsedAttributionImpl.java b/services/core/java/com/android/server/pm/pkg/component/ParsedAttributionImpl.java index b59f511afa57..0917eb6ee43f 100644 --- a/services/core/java/com/android/server/pm/pkg/component/ParsedAttributionImpl.java +++ b/services/core/java/com/android/server/pm/pkg/component/ParsedAttributionImpl.java @@ -38,7 +38,7 @@ import java.util.List; public class ParsedAttributionImpl implements ParsedAttribution, Parcelable { /** Maximum amount of attributions per package */ - static final int MAX_NUM_ATTRIBUTIONS = 10000; + static final int MAX_NUM_ATTRIBUTIONS = 1000; /** Tag of the attribution */ private @NonNull String tag; |