From 815bd21abce8a7dfabe630b301df54855ff65db3 Mon Sep 17 00:00:00 2001 From: Dario Freni Date: Wed, 20 Feb 2019 14:09:36 +0000 Subject: [PATCH] Support split APKs in staged installs. Fix: 123629153 Bug: 124807191 Test: installed a mainline module containing one base apk plus two splits. Change-Id: I8f6707370188fff9407dd00ff5d90bb83937657e --- .../java/com/android/server/pm/StagingManager.java | 30 ++++++++++++---------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/services/core/java/com/android/server/pm/StagingManager.java b/services/core/java/com/android/server/pm/StagingManager.java index d1ebc9400e4d..9dfd477a564d 100644 --- a/services/core/java/com/android/server/pm/StagingManager.java +++ b/services/core/java/com/android/server/pm/StagingManager.java @@ -295,30 +295,29 @@ public class StagingManager { } } - private String findFirstAPKInDir(File stageDir) { + private List findAPKsInDir(File stageDir) { + List ret = new ArrayList<>(); if (stageDir != null && stageDir.exists()) { for (File file : stageDir.listFiles()) { if (file.getAbsolutePath().toLowerCase().endsWith(".apk")) { - return file.getAbsolutePath(); + ret.add(file.getAbsolutePath()); } } } - return null; + return ret; } private PackageInstallerSession createAndWriteApkSession( @NonNull PackageInstallerSession originalSession) { - // TODO(b/123629153): support split APKs. if (originalSession.stageDir == null) { Slog.wtf(TAG, "Attempting to install a staged APK session with no staging dir"); return null; } - String apkFilePath = findFirstAPKInDir(originalSession.stageDir); - if (apkFilePath == null) { + List apkFilePaths = findAPKsInDir(originalSession.stageDir); + if (apkFilePaths.isEmpty()) { Slog.w(TAG, "Can't find staged APK in " + originalSession.stageDir.getAbsolutePath()); return null; } - File apkFile = new File(apkFilePath); PackageInstaller.SessionParams params = originalSession.params.copy(); params.isStaged = false; @@ -329,14 +328,17 @@ public class StagingManager { try { apkSession.open(); - ParcelFileDescriptor pfd = ParcelFileDescriptor.open(apkFile, - ParcelFileDescriptor.MODE_READ_ONLY); - long sizeBytes = pfd.getStatSize(); - if (sizeBytes < 0) { - Slog.e(TAG, "Unable to get size of: " + apkFilePath); - return null; + for (String apkFilePath : apkFilePaths) { + File apkFile = new File(apkFilePath); + ParcelFileDescriptor pfd = ParcelFileDescriptor.open(apkFile, + ParcelFileDescriptor.MODE_READ_ONLY); + long sizeBytes = pfd.getStatSize(); + if (sizeBytes < 0) { + Slog.e(TAG, "Unable to get size of: " + apkFilePath); + return null; + } + apkSession.write(apkFile.getName(), 0, sizeBytes, pfd); } - apkSession.write(apkFile.getName(), 0, sizeBytes, pfd); } catch (IOException e) { Slog.e(TAG, "Failure to install APK staged session " + originalSession.sessionId, e); return null; -- 2.11.0