Skip to content

Commit

Permalink
Disable auto deamon launch
Browse files Browse the repository at this point in the history
  • Loading branch information
prife committed Aug 29, 2024
1 parent 81b02a9 commit cc62886
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
17 changes: 12 additions & 5 deletions src/client/adb_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ std::optional<std::string> 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);
Expand All @@ -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");
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/client/adb_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/client/commandline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit cc62886

Please sign in to comment.