diff --git a/src/client/adb_client.cpp b/src/client/adb_client.cpp index f724cb5..7f77c0a 100644 --- a/src/client/adb_client.cpp +++ b/src/client/adb_client.cpp @@ -229,7 +229,7 @@ std::optional adb_get_server_executable_path() { } #endif -static bool __adb_check_server_version(std::string* error) { +static bool __adb_check_server_version(std::string* error, bool start_server) { unique_fd fd(_adb_connect("host:version", nullptr, error)); bool local = is_local_socket_spec(__adb_server_socket_spec); @@ -239,6 +239,13 @@ static bool __adb_check_server_version(std::string* error) { return false; } else if (fd == -2) { fprintf(stderr, "* daemon not running; starting now at %s\n", __adb_server_socket_spec); +#if 1 //DISABLE_AUTO_LAUNCH + // The adb server should only started with 'adb start-server' in systemd + if (!start_server) { + *error = "daemon not running!"; + return -1; + } +#endif start_server: if (launch_server(__adb_server_socket_spec)) { fprintf(stderr, "* failed to start daemon\n"); @@ -311,14 +318,14 @@ static bool __adb_check_server_version(std::string* error) { return true; } -bool adb_check_server_version(std::string* error) { +bool adb_check_server_version(std::string* error, bool start_server) { // Only check the version once per process, since this isn't atomic anyway. static std::once_flag once; static bool result; static std::string* err; - std::call_once(once, []() { + std::call_once(once, [start_server]() { err = new std::string(); - result = __adb_check_server_version(err); + result = __adb_check_server_version(err, start_server); }); *error = *err; return result; @@ -329,7 +336,7 @@ int adb_connect(TransportId* transport, std::string_view service, std::string* e LOG(DEBUG) << "adb_connect: service: " << service; // Query the adb server's version. - if (!adb_check_server_version(error)) { + if (!adb_check_server_version(error, service == "host:start-server")) { return -1; } diff --git a/src/client/adb_client.h b/src/client/adb_client.h index ba53041..4e4424c 100644 --- a/src/client/adb_client.h +++ b/src/client/adb_client.h @@ -27,7 +27,7 @@ // Explicitly check the adb server version. // All of the commands below do this implicitly. // Only the first invocation of this function will check the server version. -bool adb_check_server_version(std::string* _Nonnull error); +bool adb_check_server_version(std::string* _Nonnull error, bool start_server); // Connect to adb, connect to the named service, and return a valid fd for // interacting with that service upon success or a negative number on failure. diff --git a/src/client/commandline.cpp b/src/client/commandline.cpp index ae4f6e9..4d1477d 100644 --- a/src/client/commandline.cpp +++ b/src/client/commandline.cpp @@ -1619,7 +1619,7 @@ int adb_commandline(int argc, const char** argv) { std::string query = android::base::StringPrintf("host:%s%s", argv[0], listopt); std::string error; - if (!adb_check_server_version(&error)) { + if (!adb_check_server_version(&error, false)) { error_exit("failed to check server version: %s", error.c_str()); } printf("List of devices attached\n");