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

Commit a59e9b4e authored by Alex Buynytskyy's avatar Alex Buynytskyy
Browse files

Using ABB for install-multi.

ABB uses single shared CMD for all operations which improves
reliability.

Bug: b/153486595
Test: atest adb_test adbd_test fastdeploy_test
Change-Id: I1e3da63882c980811ed2e9f5556732b24a041ce5
parent 524bc1fd
Loading
Loading
Loading
Loading
+40 −24
Original line number Original line Diff line number Diff line
@@ -154,6 +154,14 @@ static void read_status_line(int fd, char* buf, size_t count) {
    *buf = '\0';
    *buf = '\0';
}
}


static unique_fd send_command(const std::vector<std::string>& cmd_args, std::string* error) {
    if (is_abb_exec_supported()) {
        return send_abb_exec_command(cmd_args, error);
    } else {
        return unique_fd(adb_connect(android::base::Join(cmd_args, " "), error));
    }
}

static int install_app_streamed(int argc, const char** argv, bool use_fastdeploy) {
static int install_app_streamed(int argc, const char** argv, bool use_fastdeploy) {
    printf("Performing Streamed Install\n");
    printf("Performing Streamed Install\n");


@@ -226,12 +234,7 @@ static int install_app_streamed(int argc, const char** argv, bool use_fastdeploy
        cmd_args.push_back("--apex");
        cmd_args.push_back("--apex");
    }
    }


    unique_fd remote_fd;
    unique_fd remote_fd = send_command(cmd_args, &error);
    if (use_abb_exec) {
        remote_fd = send_abb_exec_command(cmd_args, &error);
    } else {
        remote_fd.reset(adb_connect(android::base::Join(cmd_args, " "), &error));
    }
    if (remote_fd < 0) {
    if (remote_fd < 0) {
        fprintf(stderr, "adb: connect error for write: %s\n", error.c_str());
        fprintf(stderr, "adb: connect error for write: %s\n", error.c_str());
        return 1;
        return 1;
@@ -547,24 +550,28 @@ int install_multiple_app(int argc, const char** argv) {


    if (first_apk == -1) error_exit("need APK file on command line");
    if (first_apk == -1) error_exit("need APK file on command line");


    std::string install_cmd;
    const bool use_abb_exec = is_abb_exec_supported();
    if (best_install_mode() == INSTALL_PUSH) {

        install_cmd = "exec:pm";
    const std::string install_cmd =
    } else {
            use_abb_exec ? "package"
        install_cmd = "exec:cmd package";
                         : best_install_mode() == INSTALL_PUSH ? "exec:pm" : "exec:cmd package";
    }


    std::string cmd = android::base::StringPrintf("%s install-create -S %" PRIu64,
    std::vector<std::string> cmd_args = {install_cmd, "install-create", "-S",
                                                  install_cmd.c_str(), total_size);
                                         std::to_string(total_size)};
    cmd_args.reserve(first_apk + 4);
    for (int i = 1; i < first_apk; i++) {
    for (int i = 1; i < first_apk; i++) {
        cmd += " " + escape_arg(argv[i]);
        if (use_abb_exec) {
            cmd_args.push_back(argv[i]);
        } else {
            cmd_args.push_back(escape_arg(argv[i]));
        }
    }
    }


    // Create install session
    // Create install session
    std::string error;
    std::string error;
    char buf[BUFSIZ];
    char buf[BUFSIZ];
    {
    {
        unique_fd fd(adb_connect(cmd, &error));
        unique_fd fd = send_command(cmd_args, &error);
        if (fd < 0) {
        if (fd < 0) {
            fprintf(stderr, "adb: connect error for create: %s\n", error.c_str());
            fprintf(stderr, "adb: connect error for create: %s\n", error.c_str());
            return EXIT_FAILURE;
            return EXIT_FAILURE;
@@ -586,6 +593,7 @@ int install_multiple_app(int argc, const char** argv) {
        fputs(buf, stderr);
        fputs(buf, stderr);
        return EXIT_FAILURE;
        return EXIT_FAILURE;
    }
    }
    const auto session_id_str = std::to_string(session_id);


    // Valid session, now stream the APKs
    // Valid session, now stream the APKs
    bool success = true;
    bool success = true;
@@ -598,10 +606,15 @@ int install_multiple_app(int argc, const char** argv) {
            goto finalize_session;
            goto finalize_session;
        }
        }


        std::string cmd =
        std::vector<std::string> cmd_args = {
                android::base::StringPrintf("%s install-write -S %" PRIu64 " %d %s -",
                install_cmd,
                                            install_cmd.c_str(), static_cast<uint64_t>(sb.st_size),
                "install-write",
                                            session_id, android::base::Basename(file).c_str());
                "-S",
                std::to_string(sb.st_size),
                session_id_str,
                android::base::Basename(file),
                "-",
        };


        unique_fd local_fd(adb_open(file, O_RDONLY | O_CLOEXEC));
        unique_fd local_fd(adb_open(file, O_RDONLY | O_CLOEXEC));
        if (local_fd < 0) {
        if (local_fd < 0) {
@@ -611,7 +624,7 @@ int install_multiple_app(int argc, const char** argv) {
        }
        }


        std::string error;
        std::string error;
        unique_fd remote_fd(adb_connect(cmd, &error));
        unique_fd remote_fd = send_command(cmd_args, &error);
        if (remote_fd < 0) {
        if (remote_fd < 0) {
            fprintf(stderr, "adb: connect error for write: %s\n", error.c_str());
            fprintf(stderr, "adb: connect error for write: %s\n", error.c_str());
            success = false;
            success = false;
@@ -636,10 +649,13 @@ int install_multiple_app(int argc, const char** argv) {


finalize_session:
finalize_session:
    // Commit session if we streamed everything okay; otherwise abandon.
    // Commit session if we streamed everything okay; otherwise abandon.
    std::string service = android::base::StringPrintf("%s install-%s %d", install_cmd.c_str(),
    std::vector<std::string> service_args = {
                                                      success ? "commit" : "abandon", session_id);
            install_cmd,
            success ? "install-commit" : "install-abandon",
            session_id_str,
    };
    {
    {
        unique_fd fd(adb_connect(service, &error));
        unique_fd fd = send_command(service_args, &error);
        if (fd < 0) {
        if (fd < 0) {
            fprintf(stderr, "adb: connect error for finalize: %s\n", error.c_str());
            fprintf(stderr, "adb: connect error for finalize: %s\n", error.c_str());
            return EXIT_FAILURE;
            return EXIT_FAILURE;