Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 815bd21a authored by Dario Freni's avatar Dario Freni
Browse files

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
parent 9599d067
Loading
Loading
Loading
Loading
+16 −14
Original line number Diff line number Diff line
@@ -295,30 +295,29 @@ public class StagingManager {
        }
    }

    private String findFirstAPKInDir(File stageDir) {
    private List<String> findAPKsInDir(File stageDir) {
        List<String> 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<String> 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,6 +328,8 @@ public class StagingManager {

        try {
            apkSession.open();
            for (String apkFilePath : apkFilePaths) {
                File apkFile = new File(apkFilePath);
                ParcelFileDescriptor pfd = ParcelFileDescriptor.open(apkFile,
                        ParcelFileDescriptor.MODE_READ_ONLY);
                long sizeBytes = pfd.getStatSize();
@@ -337,6 +338,7 @@ public class StagingManager {
                    return null;
                }
                apkSession.write(apkFile.getName(), 0, sizeBytes, pfd);
            }
        } catch (IOException e) {
            Slog.e(TAG, "Failure to install APK staged session " + originalSession.sessionId, e);
            return null;