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

Commit 6c4cfd6a authored by Josh Gao's avatar Josh Gao Committed by Gerrit Code Review
Browse files

Merge changes I4d6bda45,I72576e1f

* changes:
  adb: fix transport acquisition for forward, reverse.
  adb: don't manually construct device selection prefix in forward.
parents ca94d797 3346339f
Loading
Loading
Loading
Loading
+1 −5
Original line number Diff line number Diff line
@@ -1243,11 +1243,7 @@ HostRequestResult handle_host_request(std::string_view service, TransportType ty
    // TODO: Switch handle_forward_request to string_view.
    std::string service_str(service);
    if (handle_forward_request(
                service_str.c_str(),
                [=](std::string* error) {
                    return acquire_one_transport(type, serial, transport_id, nullptr, error);
                },
                reply_fd)) {
                service_str.c_str(), [=](std::string* error) { return s->transport; }, reply_fd)) {
        return HostRequestResult::Handled;
    }

+6 −4
Original line number Diff line number Diff line
@@ -149,7 +149,8 @@ bool adb_status(borrowed_fd fd, std::string* error) {
    return false;
}

static int _adb_connect(std::string_view service, TransportId* transport, std::string* error) {
static int _adb_connect(std::string_view service, TransportId* transport, std::string* error,
                        bool force_switch = false) {
    LOG(DEBUG) << "_adb_connect: " << service;
    if (service.empty() || service.size() > MAX_PAYLOAD) {
        *error = android::base::StringPrintf("bad service name length (%zd)", service.size());
@@ -164,7 +165,7 @@ static int _adb_connect(std::string_view service, TransportId* transport, std::s
        return -2;
    }

    if (!service.starts_with("host")) {
    if (!service.starts_with("host") || force_switch) {
        std::optional<TransportId> transport_result = switch_socket_transport(fd.get(), error);
        if (!transport_result) {
            return -1;
@@ -323,7 +324,8 @@ bool adb_check_server_version(std::string* error) {
    return result;
}

int adb_connect(TransportId* transport, std::string_view service, std::string* error) {
int adb_connect(TransportId* transport, std::string_view service, std::string* error,
                bool force_switch_device) {
    LOG(DEBUG) << "adb_connect: service: " << service;

    // Query the adb server's version.
@@ -336,7 +338,7 @@ int adb_connect(TransportId* transport, std::string_view service, std::string* e
        return 0;
    }

    unique_fd fd(_adb_connect(service, transport, error));
    unique_fd fd(_adb_connect(service, transport, error, force_switch_device));
    if (fd == -1) {
        D("_adb_connect error: %s", error->c_str());
    } else if(fd == -2) {
+5 −1
Original line number Diff line number Diff line
@@ -34,7 +34,11 @@ bool adb_check_server_version(std::string* _Nonnull error);
int adb_connect(std::string_view service, std::string* _Nonnull error);

// Same as above, except returning the TransportId for the service that we've connected to.
int adb_connect(TransportId* _Nullable id, std::string_view service, std::string* _Nonnull error);
// force_switch_device forces the function to attempt to select a device, even if the service
// string appears to be a host: service (for use with host services that are device specific, like
// forward).
int adb_connect(TransportId* _Nullable id, std::string_view service, std::string* _Nonnull error,
                bool force_switch_device = false);

// Kill the currently running adb server, if it exists.
bool adb_kill_server();
+8 −16
Original line number Diff line number Diff line
@@ -1739,41 +1739,33 @@ int adb_commandline(int argc, const char** argv) {
        // Determine the <host-prefix> for this command.
        std::string host_prefix;
        if (reverse) {
            host_prefix = "reverse";
            host_prefix = "reverse:";
        } else {
            if (serial) {
                host_prefix = android::base::StringPrintf("host-serial:%s", serial);
            } else if (transport_type == kTransportUsb) {
                host_prefix = "host-usb";
            } else if (transport_type == kTransportLocal) {
                host_prefix = "host-local";
            } else {
                host_prefix = "host";
            }
            host_prefix = "host:";
        }

        std::string cmd, error_message;
        if (strcmp(argv[0], "--list") == 0) {
            if (argc != 1) error_exit("--list doesn't take any arguments");
            return adb_query_command(host_prefix + ":list-forward");
            return adb_query_command(host_prefix + "list-forward");
        } else if (strcmp(argv[0], "--remove-all") == 0) {
            if (argc != 1) error_exit("--remove-all doesn't take any arguments");
            cmd = host_prefix + ":killforward-all";
            cmd = "killforward-all";
        } else if (strcmp(argv[0], "--remove") == 0) {
            // forward --remove <local>
            if (argc != 2) error_exit("--remove requires an argument");
            cmd = host_prefix + ":killforward:" + argv[1];
            cmd = std::string("killforward:") + argv[1];
        } else if (strcmp(argv[0], "--no-rebind") == 0) {
            // forward --no-rebind <local> <remote>
            if (argc != 3) error_exit("--no-rebind takes two arguments");
            if (forward_targets_are_valid(argv[1], argv[2], &error_message)) {
                cmd = host_prefix + ":forward:norebind:" + argv[1] + ";" + argv[2];
                cmd = std::string("forward:norebind:") + argv[1] + ";" + argv[2];
            }
        } else {
            // forward <local> <remote>
            if (argc != 2) error_exit("forward takes two arguments");
            if (forward_targets_are_valid(argv[0], argv[1], &error_message)) {
                cmd = host_prefix + ":forward:" + argv[0] + ";" + argv[1];
                cmd = std::string("forward:") + argv[0] + ";" + argv[1];
            }
        }

@@ -1781,7 +1773,7 @@ int adb_commandline(int argc, const char** argv) {
            error_exit("error: %s", error_message.c_str());
        }

        unique_fd fd(adb_connect(cmd, &error_message));
        unique_fd fd(adb_connect(nullptr, host_prefix + cmd, &error_message, true));
        if (fd < 0 || !adb_status(fd.get(), &error_message)) {
            error_exit("error: %s", error_message.c_str());
        }