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

Commit 6edd97ed authored by Henry Daitx's avatar Henry Daitx Committed by android-build-merger
Browse files

Merge "Change --fastdeploy behaviour"

am: 17d41711

Change-Id: Ic231992bac93fb28ca64b29e197b39e2e5a3ebb4
parents 9fff2fbe 17d41711
Loading
Loading
Loading
Loading
+7 −5
Original line number Diff line number Diff line
@@ -331,11 +331,6 @@ int install_app(int argc, const char** argv) {
        error_exit("Attempting to use streaming install on unsupported device");
    }

    if (use_fastdeploy == true && is_reinstall == false) {
        printf("Fast Deploy is only available with -r.\n");
        use_fastdeploy = false;
    }

    if (use_fastdeploy == true && get_device_api_level() < kFastDeployMinApi) {
        printf("Fast Deploy is only compatible with devices of API version %d or higher, "
               "ignoring.\n",
@@ -350,10 +345,17 @@ int install_app(int argc, const char** argv) {
            passthrough_argv.push_back(argv[i]);
        }
    }
    if (passthrough_argv.size() < 2) {
        error_exit("install requires an apk argument");
    }

    if (use_fastdeploy == true) {
        fastdeploy_set_local_agent(use_localagent);
        update_agent(agent_update_strategy);

        // The last argument must be the APK file
        const char* file = passthrough_argv.back();
        use_fastdeploy = find_package(file);
    }

    switch (installMode) {
+2 −2
Original line number Diff line number Diff line
@@ -154,8 +154,8 @@ static void help() {
        "     --instant: cause the app to be installed as an ephemeral install app\n"
        "     --no-streaming: always push APK to device and invoke Package Manager as separate steps\n"
        "     --streaming: force streaming APK directly into Package Manager\n"
        "     --fastdeploy: use fast deploy (only valid with -r)\n"
        "     --no-fastdeploy: prevent use of fast deploy (only valid with -r)\n"
        "     --fastdeploy: use fast deploy\n"
        "     --no-fastdeploy: prevent use of fast deploy\n"
        "     --force-agent: force update of deployment agent when using fast deploy\n"
        "     --date-check-agent: update deployment agent when local version is newer and using fast deploy\n"
        "     --version-check-agent: update deployment agent when local version has different version code and using fast deploy\n"
+15 −1
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

#include "fastdeploy.h"

#include <string.h>
#include <algorithm>
#include <array>
#include <memory>
@@ -31,7 +32,7 @@

#include "adb_utils.h"

static constexpr long kRequiredAgentVersion = 0x00000001;
static constexpr long kRequiredAgentVersion = 0x00000002;

static constexpr const char* kDeviceAgentPath = "/data/local/tmp/";

@@ -313,9 +314,16 @@ void install_patch(const char* apkPath, const char* patchPath, int argc, const c
    std::vector<unsigned char> applyErrorBuffer;
    std::string argsString;

    bool rSwitchPresent = false;
    for (int i = 0; i < argc; i++) {
        argsString.append(argv[i]);
        argsString.append(" ");
        if (!strcmp(argv[i], "-r")) {
            rSwitchPresent = true;
        }
    }
    if (!rSwitchPresent) {
        argsString.append("-r");
    }

    std::string applyPatchCommand =
@@ -326,3 +334,9 @@ void install_patch(const char* apkPath, const char* patchPath, int argc, const c
        error_exit("Executing %s returned %d", applyPatchCommand.c_str(), returnCode);
    }
}

bool find_package(const char* apkPath) {
    const std::string findCommand =
            "/data/local/tmp/deployagent find " + get_packagename_from_apk(apkPath);
    return !send_shell_command(findCommand);
}
+1 −0
Original line number Diff line number Diff line
@@ -32,3 +32,4 @@ void create_patch(const char* apkPath, const char* metadataPath, const char* pat
void apply_patch_on_device(const char* apkPath, const char* patchPath, const char* outputPath);
void install_patch(const char* apkPath, const char* patchPath, int argc, const char** argv);
std::string get_patch_path(const char* apkPath);
bool find_package(const char* apkPath);
+23 −4
Original line number Diff line number Diff line
@@ -35,7 +35,7 @@ import com.android.fastdeploy.PatchUtils;

public final class DeployAgent {
    private static final int BUFFER_SIZE = 128 * 1024;
    private static final int AGENT_VERSION = 0x00000001;
    private static final int AGENT_VERSION = 0x00000002;

    public static void main(String[] args) {
        int exitCode = 0;
@@ -53,6 +53,15 @@ public final class DeployAgent {

                String packageName = args[1];
                extractMetaData(packageName);
            } else if (commandString.equals("find")) {
                if (args.length != 2) {
                    showUsage(1);
                }

                String packageName = args[1];
                if (getFilenameFromPackageName(packageName) == null) {
                    exitCode = 3;
                }
            } else if (commandString.equals("apply")) {
                if (args.length < 4) {
                    showUsage(1);
@@ -112,6 +121,7 @@ public final class DeployAgent {
            "usage: deployagent <command> [<args>]\n\n" +
            "commands:\n" +
            "version                             get the version\n" +
            "find PKGNAME                        return zero if package found, else non-zero\n" +
            "extract PKGNAME                     extract an installed package's metadata\n" +
            "apply PKGNAME PATCHFILE [-o|-pm]    apply a patch from PATCHFILE (- for stdin) to an installed package\n" +
            " -o <FILE> directs output to FILE, default or - for stdout\n" +
@@ -134,7 +144,7 @@ public final class DeployAgent {
        return null;
    }

    private static File getFileFromPackageName(String packageName) throws IOException {
    private static String getFilenameFromPackageName(String packageName) throws IOException {
        StringBuilder commandBuilder = new StringBuilder();
        commandBuilder.append("pm list packages -f " + packageName);

@@ -153,11 +163,20 @@ public final class DeployAgent {
                int equalsIndex = line.lastIndexOf(packageSuffix);
                String fileName =
                    line.substring(packageIndex + packagePrefix.length(), equalsIndex);
                return new File(fileName);
                return fileName;
            }
        }
        return null;
    }

    private static File getFileFromPackageName(String packageName) throws IOException {
        String filename = getFilenameFromPackageName(packageName);
        if (filename == null) {
            // Should not happen (function is only called when we know the package exists)
            throw new IOException("package not found");
        }
        return new File(filename);
    }

    private static void extractMetaData(String packageName) throws IOException {
        File apkFile = getFileFromPackageName(packageName);