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

Commit 964f9fdd authored by Songchun Fan's avatar Songchun Fan Committed by Android (Google) Code Review
Browse files

Merge "fix streaming installation for splits" into rvc-dev

parents 4cbd3b7a 5f911c85
Loading
Loading
Loading
Loading
+74 −65
Original line number Diff line number Diff line
@@ -2998,25 +2998,39 @@ class PackageManagerShellCommand extends ShellCommand {
            for (String arg : args) {
                final int delimLocation = arg.indexOf(':');

                // 2. File with specified size read from stdin.
                if (delimLocation != -1) {
                    // 2. File with specified size read from stdin.
                    if (processArgForStdin(arg, session) != 0) {
                        return 1;
                    }
                } else {
                    // 3. Local file.
                    processArgForLocalFile(arg, session);
                }
            }
            return 0;
        } finally {
            IoUtils.closeQuietly(session);
        }
    }

    private int processArgForStdin(String arg, PackageInstaller.Session session) {
        final String[] fileDesc = arg.split(":");
                    String name = null;
                    long sizeBytes = -1;
                    String metadata;
        String name, metadata;
        long sizeBytes;
        byte[] signature = null;

        try {
                        if (fileDesc.length > 0) {
                            name = fileDesc[0];
            if (fileDesc.length < 2) {
                getErrPrintWriter().println("Must specify file name and size");
                return 1;
            }
                        if (fileDesc.length > 1) {
            name = fileDesc[0];
            sizeBytes = Long.parseUnsignedLong(fileDesc[1]);
                        }
            metadata = name;

            if (fileDesc.length > 2 && !TextUtils.isEmpty(fileDesc[2])) {
                metadata = fileDesc[2];
                        } else {
                            metadata = name;
            }
            if (fileDesc.length > 3) {
                signature = Base64.getDecoder().decode(fileDesc[3]);
@@ -3035,27 +3049,27 @@ class PackageManagerShellCommand extends ShellCommand {
        if (signature != null) {
            // Streaming/adb mode.
            metadata = "+" + metadata;
                    } else {
                        // Singleshot read from stdin.
                        metadata = "-" + metadata;
                    }

            try {
                if (V4Signature.readFrom(signature) == null) {
                    getErrPrintWriter().println("V4 signature is invalid in: " + arg);
                    return 1;
                }
            } catch (Exception e) {
                        getErrPrintWriter().println("V4 signature is invalid: " + e + " in " + arg);
                getErrPrintWriter().println(
                        "V4 signature is invalid: " + e + " in " + arg);
                return 1;
            }
        } else {
            // Single-shot read from stdin.
            metadata = "-" + metadata;
        }

        session.addFile(LOCATION_DATA_APP, name, sizeBytes,
                metadata.getBytes(StandardCharsets.UTF_8), signature);
                    continue;
        return 0;
    }

                // 3. Local file.
    private void processArgForLocalFile(String arg, PackageInstaller.Session session) {
        final String inPath = arg;

        final File file = new File(inPath);
@@ -3071,11 +3085,6 @@ class PackageManagerShellCommand extends ShellCommand {

        session.addFile(LOCATION_DATA_APP, name, size, metadata, v4signatureBytes);
    }
            return 0;
        } finally {
            IoUtils.closeQuietly(session);
        }
    }

    private int doWriteSplits(int sessionId, ArrayList<String> splitPaths, long sessionSizeBytes,
            boolean isApex) throws RemoteException {