From 326e7338d3885f19b6abfb7aa8766b4ca612a47b Mon Sep 17 00:00:00 2001 From: Winson Date: Tue, 30 Aug 2022 09:45:56 -0700 Subject: [PATCH] Move nested package dir checking to PackageParser2 As part of Ib05b187dc006272603709a95534c40744cd62f0c, /data/app APKs were nested one directory further down. This makes the cacher and parsing disagree on the actual file path representing a package. The AndroidPackage and thus public API representation remained correct by using the immediate parent folder containing the APKs, usually /data/app/~~random/packageName-random. But because PMS doesn't search its scan directories any further than the first directory level, when it scanned /data/app, it would submit /data/app/~~random, one parent level higher than previous pre-R platform levels expected. Unfortunately since this behavior is now handled by the system gracefully, it's hard to migrate back and enforce that the right dir is passed to PackageParser2, as several system components call into it. Instead, this moves the deeper child check up from the parsing internals to PackageParser2#parsePackage, which will transform its input packageFile to the deeper level as necessary, which preserves the internal parsing API behavior while also ensuring that any deeper parsing infrastucture works on a single equivalent path to represent a package. Bug: 243912163 Bug: 242639590 Test: presubmit Change-Id: I089b915a7751407dbe456a32b0c6eae315d193f5 --- .../java/com/android/server/pm/parsing/PackageParser2.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/services/core/java/com/android/server/pm/parsing/PackageParser2.java b/services/core/java/com/android/server/pm/parsing/PackageParser2.java index e0d5aec65ae7e..6caddaf430dcc 100644 --- a/services/core/java/com/android/server/pm/parsing/PackageParser2.java +++ b/services/core/java/com/android/server/pm/parsing/PackageParser2.java @@ -34,6 +34,7 @@ import android.util.DisplayMetrics; import android.util.Slog; import com.android.internal.compat.IPlatformCompat; +import com.android.internal.util.ArrayUtils; import com.android.server.pm.PackageManagerException; import com.android.server.pm.PackageManagerService; import com.android.server.pm.parsing.pkg.PackageImpl; @@ -151,6 +152,12 @@ public class PackageParser2 implements AutoCloseable { @AnyThread public ParsedPackage parsePackage(File packageFile, int flags, boolean useCaches, List frameworkSplits) throws PackageManagerException { + var files = packageFile.listFiles(); + // Apk directory is directly nested under the current directory + if (ArrayUtils.size(files) == 1 && files[0].isDirectory()) { + packageFile = files[0]; + } + if (useCaches && mCacher != null) { ParsedPackage parsed = mCacher.getCachedResult(packageFile, flags); if (parsed != null) {