Honor shared users in visibility calculations
This change allows apps with the same app id to see each other (members
of the same shared uid, for example) and allows apps targetting an app
in a shared uid to see all of its members.
Bug: 136675067
Test: atest AppEnumerationTests
Change-Id: Ic56c3ff56780828af67210a54968ddaba3aff3d1
diff --git a/services/core/java/com/android/server/pm/AppsFilter.java b/services/core/java/com/android/server/pm/AppsFilter.java
index 31efed4..bb5b04a 100644
--- a/services/core/java/com/android/server/pm/AppsFilter.java
+++ b/services/core/java/com/android/server/pm/AppsFilter.java
@@ -445,8 +445,31 @@
private boolean shouldFilterApplicationInternal(
PackageSetting callingPkgSetting, PackageSetting targetPkgSetting, int userId) {
+ return shouldFilterApplicationInternal(callingPkgSetting, targetPkgSetting, userId,
+ true /*expandSharedUser*/);
+ }
+
+ /**
+ * @param expandSharedUser true if all members of the shared user a target may belong to should
+ * be considered
+ */
+ private boolean shouldFilterApplicationInternal(
+ PackageSetting callingPkgSetting, PackageSetting targetPkgSetting, int userId,
+ boolean expandSharedUser) {
Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "shouldFilterApplicationInternal");
try {
+ // special case shared user targets
+ if (expandSharedUser && targetPkgSetting.sharedUser != null) {
+ for (PackageSetting sharedMemberSetting : targetPkgSetting.sharedUser.packages) {
+ if (!shouldFilterApplicationInternal(
+ callingPkgSetting, sharedMemberSetting, userId,
+ false /*expandSharedUser*/)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
final String callingName = callingPkgSetting.pkg.packageName;
final PackageParser.Package targetPkg = targetPkgSetting.pkg;
@@ -471,6 +494,12 @@
}
return false;
}
+ if (callingPkgSetting.appId == targetPkgSetting.appId) {
+ if (DEBUG_LOGGING) {
+ log(callingPkgSetting, targetPkgSetting, "same app id");
+ }
+ return false;
+ }
if (isImplicitlyQueryableSystemApp(targetPkgSetting)) {
if (DEBUG_LOGGING) {
log(callingPkgSetting, targetPkgSetting, "implicitly queryable sys");