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

Commit 71c83126 authored by David Pursell's avatar David Pursell
Browse files

adb: Fix missing shell protocol usage.

Some adb commands use the shell service but weren't using the
shell protocol, causing a protocol mismatch between the client and
the device. This CL uses the shell protocol whenever possible.

Change-Id: I4c9c75b7fd1d5bf3dc1f73900711840270527682
parent 76f4a653
Loading
Loading
Loading
Loading
+22 −19
Original line number Diff line number Diff line
@@ -524,6 +524,20 @@ static std::string format_host_command(const char* command, TransportType type,
    return android::base::StringPrintf("%s:%s", prefix, command);
}

// Checks whether the device indicated by |transport_type| and |serial| supports
// |feature|. Returns the response string, which will be empty if the device
// could not be found or the feature is not supported.
static std::string CheckFeature(const std::string& feature,
                                TransportType transport_type,
                                const char* serial) {
    std::string result, error, command("check-feature:" + feature);
    if (!adb_query(format_host_command(command.c_str(), transport_type, serial),
                   &result, &error)) {
        return "";
    }
    return result;
}

static int adb_download_buffer(const char *service, const char *fn, const void* data, unsigned sz,
                               bool show_progress)
{
@@ -783,12 +797,15 @@ static int send_shell_command(TransportType transport_type, const char* serial,
        wait_for_device("wait-for-device", transport_type, serial);
    }

    read_and_dump(fd);
    int rc = adb_close(fd);
    if (rc) {
        perror("close");
    bool use_shell_protocol = !CheckFeature(kFeatureShell2, transport_type,
                                            serial).empty();
    int exit_code = read_and_dump(fd, use_shell_protocol);

    if (adb_close(fd) < 0) {
        PLOG(ERROR) << "failure closing FD " << fd;
    }
    return rc;

    return exit_code;
}

static int logcat(TransportType transport, const char* serial, int argc, const char** argv) {
@@ -1013,20 +1030,6 @@ static bool _is_valid_ack_reply_fd(const int ack_reply_fd) {
#endif
}

// Checks whether the device indicated by |transport_type| and |serial| supports
// |feature|. Returns the response string, which will be empty if the device
// could not be found or the feature is not supported.
static std::string CheckFeature(const std::string& feature,
                                TransportType transport_type,
                                const char* serial) {
    std::string result, error, command("check-feature:" + feature);
    if (!adb_query(format_host_command(command.c_str(), transport_type, serial),
                   &result, &error)) {
        return "";
    }
    return result;
}

int adb_commandline(int argc, const char **argv) {
    int no_daemon = 0;
    int is_daemon = 0;