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

Commit 89cce058 authored by Josh Gao's avatar Josh Gao Committed by Gerrit Code Review
Browse files

Merge changes from topic "adbd_lz4"

* changes:
  adb: add dry-run option to push/sync.
  adb: implement LZ4 compression.
  adb: fix use of wrong union variant.
  adb: fix front_size, front_data.
  adb: add interfaces for Encoder/Decoder.
parents edd77715 5949fccc
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -470,6 +470,7 @@ cc_library {
        "libadbd_core",
        "libbrotli",
        "libdiagnose_usb",
        "liblz4",
    ],

    shared_libs: [
@@ -571,6 +572,7 @@ cc_library {
        "libbrotli",
        "libcutils_sockets",
        "libdiagnose_usb",
        "liblz4",
        "libmdnssd",
    ],

@@ -605,6 +607,7 @@ cc_binary {
        "libadbd_services",
        "libasyncio",
        "libcap",
        "liblz4",
        "libminijail",
        "libssl",
    ],
+1 −1
Original line number Diff line number Diff line
@@ -290,7 +290,7 @@ static int install_app_legacy(int argc, const char** argv, bool use_fastdeploy)
        }
    }

    if (do_sync_push(apk_file, apk_dest.c_str(), false, true)) {
    if (do_sync_push(apk_file, apk_dest.c_str(), false, CompressionType::Any, false)) {
        result = pm_command(argc, argv);
        delete_device_file(apk_dest);
    }
+1 −1
Original line number Diff line number Diff line
@@ -282,5 +282,5 @@ int Bugreport::SendShellCommand(const std::string& command, bool disable_shell_p

bool Bugreport::DoSyncPull(const std::vector<const char*>& srcs, const char* dst, bool copy_attrs,
                           const char* name) {
    return do_sync_pull(srcs, dst, copy_attrs, false, name);
    return do_sync_pull(srcs, dst, copy_attrs, CompressionType::None, name);
}
+67 −31
Original line number Diff line number Diff line
@@ -129,20 +129,22 @@ static void help() {
        " reverse --remove-all     remove all reverse socket connections from device\n"
        "\n"
        "file transfer:\n"
        " push [--sync] [-zZ] LOCAL... REMOTE\n"
        " push [--sync] [-z ALGORITHM] [-Z] LOCAL... REMOTE\n"
        "     copy local files/directories to device\n"
        "     --sync: only push files that are newer on the host than the device\n"
        "     -z: enable compression\n"
        "     -n: dry run: push files to device without storing to the filesystem\n"
        "     -z: enable compression with a specified algorithm (any, none, brotli)\n"
        "     -Z: disable compression\n"
        " pull [-azZ] REMOTE... LOCAL\n"
        " pull [-a] [-z ALGORITHM] [-Z] REMOTE... LOCAL\n"
        "     copy files/dirs from device\n"
        "     -a: preserve file timestamp and mode\n"
        "     -z: enable compression\n"
        "     -z: enable compression with a specified algorithm (any, none, brotli)\n"
        "     -Z: disable compression\n"
        " sync [-lzZ] [all|data|odm|oem|product|system|system_ext|vendor]\n"
        " sync [-l] [-z ALGORITHM] [-Z] [all|data|odm|oem|product|system|system_ext|vendor]\n"
        "     sync a local build from $ANDROID_PRODUCT_OUT to the device (default all)\n"
        "     -n: dry run: push files to device without storing to the filesystem\n"
        "     -l: list files that would be copied, but don't copy them\n"
        "     -z: enable compression\n"
        "     -z: enable compression with a specified algorithm (any, none, brotli)\n"
        "     -Z: disable compression\n"
        "\n"
        "shell:\n"
@@ -1314,12 +1316,36 @@ static int restore(int argc, const char** argv) {
    return 0;
}

static CompressionType parse_compression_type(const std::string& str, bool allow_numbers) {
    if (allow_numbers) {
        if (str == "0") {
            return CompressionType::None;
        } else if (str == "1") {
            return CompressionType::Any;
        }
    }

    if (str == "any") {
        return CompressionType::Any;
    } else if (str == "none") {
        return CompressionType::None;
    }

    if (str == "brotli") {
        return CompressionType::Brotli;
    } else if (str == "lz4") {
        return CompressionType::LZ4;
    }

    error_exit("unexpected compression type %s", str.c_str());
}

static void parse_push_pull_args(const char** arg, int narg, std::vector<const char*>* srcs,
                                 const char** dst, bool* copy_attrs, bool* sync, bool* compressed) {
                                 const char** dst, bool* copy_attrs, bool* sync,
                                 CompressionType* compression, bool* dry_run) {
    *copy_attrs = false;
    const char* adb_compression = getenv("ADB_COMPRESSION");
    if (adb_compression && strcmp(adb_compression, "0") == 0) {
        *compressed = false;
    if (const char* adb_compression = getenv("ADB_COMPRESSION")) {
        *compression = parse_compression_type(adb_compression, true);
    }

    srcs->clear();
@@ -1333,13 +1359,15 @@ static void parse_push_pull_args(const char** arg, int narg, std::vector<const c
            } else if (!strcmp(*arg, "-a")) {
                *copy_attrs = true;
            } else if (!strcmp(*arg, "-z")) {
                if (compressed != nullptr) {
                    *compressed = true;
                if (narg < 2) {
                    error_exit("-z requires an argument");
                }
                *compression = parse_compression_type(*++arg, false);
                --narg;
            } else if (!strcmp(*arg, "-Z")) {
                if (compressed != nullptr) {
                    *compressed = false;
                }
                *compression = CompressionType::None;
            } else if (dry_run && !strcmp(*arg, "-n")) {
                *dry_run = true;
            } else if (!strcmp(*arg, "--sync")) {
                if (sync != nullptr) {
                    *sync = true;
@@ -1894,22 +1922,25 @@ int adb_commandline(int argc, const char** argv) {
    } else if (!strcmp(argv[0], "push")) {
        bool copy_attrs = false;
        bool sync = false;
        bool compressed = true;
        bool dry_run = false;
        CompressionType compression = CompressionType::Any;
        std::vector<const char*> srcs;
        const char* dst = nullptr;

        parse_push_pull_args(&argv[1], argc - 1, &srcs, &dst, &copy_attrs, &sync, &compressed);
        parse_push_pull_args(&argv[1], argc - 1, &srcs, &dst, &copy_attrs, &sync, &compression,
                             &dry_run);
        if (srcs.empty() || !dst) error_exit("push requires an argument");
        return do_sync_push(srcs, dst, sync, compressed) ? 0 : 1;
        return do_sync_push(srcs, dst, sync, compression, dry_run) ? 0 : 1;
    } else if (!strcmp(argv[0], "pull")) {
        bool copy_attrs = false;
        bool compressed = true;
        CompressionType compression = CompressionType::Any;
        std::vector<const char*> srcs;
        const char* dst = ".";

        parse_push_pull_args(&argv[1], argc - 1, &srcs, &dst, &copy_attrs, nullptr, &compressed);
        parse_push_pull_args(&argv[1], argc - 1, &srcs, &dst, &copy_attrs, nullptr, &compression,
                             nullptr);
        if (srcs.empty()) error_exit("pull requires an argument");
        return do_sync_pull(srcs, dst, copy_attrs, compressed) ? 0 : 1;
        return do_sync_pull(srcs, dst, copy_attrs, compression) ? 0 : 1;
    } else if (!strcmp(argv[0], "install")) {
        if (argc < 2) error_exit("install requires an argument");
        return install_app(argc, argv);
@@ -1925,27 +1956,30 @@ int adb_commandline(int argc, const char** argv) {
    } else if (!strcmp(argv[0], "sync")) {
        std::string src;
        bool list_only = false;
        bool compressed = true;
        bool dry_run = false;
        CompressionType compression = CompressionType::Any;

        const char* adb_compression = getenv("ADB_COMPRESSION");
        if (adb_compression && strcmp(adb_compression, "0") == 0) {
            compressed = false;
        if (const char* adb_compression = getenv("ADB_COMPRESSION"); adb_compression) {
            compression = parse_compression_type(adb_compression, true);
        }

        int opt;
        while ((opt = getopt(argc, const_cast<char**>(argv), "lzZ")) != -1) {
        while ((opt = getopt(argc, const_cast<char**>(argv), "lnz:Z")) != -1) {
            switch (opt) {
                case 'l':
                    list_only = true;
                    break;
                case 'n':
                    dry_run = true;
                    break;
                case 'z':
                    compressed = true;
                    compression = parse_compression_type(optarg, false);
                    break;
                case 'Z':
                    compressed = false;
                    compression = CompressionType::None;
                    break;
                default:
                    error_exit("usage: adb sync [-lzZ] [PARTITION]");
                    error_exit("usage: adb sync [-l] [-n]  [-z ALGORITHM] [-Z] [PARTITION]");
            }
        }

@@ -1954,7 +1988,7 @@ int adb_commandline(int argc, const char** argv) {
        } else if (optind + 1 == argc) {
            src = argv[optind];
        } else {
            error_exit("usage: adb sync [-lzZ] [PARTITION]");
            error_exit("usage: adb sync [-l] [-n] [-z ALGORITHM] [-Z] [PARTITION]");
        }

        std::vector<std::string> partitions{"data",   "odm",        "oem",   "product",
@@ -1965,7 +1999,9 @@ int adb_commandline(int argc, const char** argv) {
                std::string src_dir{product_file(partition)};
                if (!directory_exists(src_dir)) continue;
                found = true;
                if (!do_sync_sync(src_dir, "/" + partition, list_only, compressed)) return 1;
                if (!do_sync_sync(src_dir, "/" + partition, list_only, compression, dry_run)) {
                    return 1;
                }
            }
        }
        if (!found) error_exit("don't know how to sync %s partition", src.c_str());
+1 −1
Original line number Diff line number Diff line
@@ -112,7 +112,7 @@ static void push_to_device(const void* data, size_t byte_count, const char* dst,
    // but can't be removed until after the push.
    unix_close(tf.release());

    if (!do_sync_push(srcs, dst, sync, true)) {
    if (!do_sync_push(srcs, dst, sync, CompressionType::Any, false)) {
        error_exit("Failed to push fastdeploy agent to device.");
    }
}
Loading