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

Commit 9f3064f2 authored by Josh Gao's avatar Josh Gao
Browse files

adbd: avoid compiling more code in the daemon.

Strip out more code that has no meaning on device, to "improve"
coverage.

Test: test_device.py over TCP
Change-Id: Id8d9fa6cc6c6c30773f67303bcc89e6d60824700
parent a786f0a8
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -109,7 +109,9 @@ void handle_online(atransport *t)
{
    D("adb: online");
    t->online = 1;
#if ADB_HOST
    t->SetConnectionEstablished(true);
#endif
}

void handle_offline(atransport *t)
+10 −2
Original line number Diff line number Diff line
@@ -73,6 +73,7 @@ static auto& listener_list_mutex = *new std::mutex();
typedef std::list<std::unique_ptr<alistener>> ListenerList;
static ListenerList& listener_list GUARDED_BY(listener_list_mutex) = *new ListenerList();

#if ADB_HOST
static void ss_listener_event_func(int _fd, unsigned ev, void *_l) {
    if (ev & FDE_READ) {
        unique_fd fd(adb_socket_accept(_fd, nullptr, nullptr));
@@ -88,6 +89,7 @@ static void ss_listener_event_func(int _fd, unsigned ev, void *_l) {
        }
    }
}
#endif

static void listener_event_func(int _fd, unsigned ev, void* _l)
{
@@ -164,7 +166,7 @@ void remove_all_listeners() EXCLUDES(listener_list_mutex) {
    }
}

void enable_daemon_sockets() EXCLUDES(listener_list_mutex) {
void enable_server_sockets() EXCLUDES(listener_list_mutex) {
    std::lock_guard<std::mutex> lock(listener_list_mutex);
    for (auto& l : listener_list) {
        if (l->connect_to == "*smartsocket*") {
@@ -173,6 +175,7 @@ void enable_daemon_sockets() EXCLUDES(listener_list_mutex) {
    }
}

#if ADB_HOST
void close_smartsockets() EXCLUDES(listener_list_mutex) {
    std::lock_guard<std::mutex> lock(listener_list_mutex);
    auto pred = [](const std::unique_ptr<alistener>& listener) {
@@ -180,6 +183,7 @@ void close_smartsockets() EXCLUDES(listener_list_mutex) {
    };
    listener_list.remove_if(pred);
}
#endif

InstallStatus install_listener(const std::string& local_name, const char* connect_to,
                               atransport* transport, int flags, int* resolved_tcp_port,
@@ -227,7 +231,11 @@ InstallStatus install_listener(const std::string& local_name, const char* connec

    close_on_exec(listener->fd);
    if (listener->connect_to == "*smartsocket*") {
#if ADB_HOST
        listener->fde = fdevent_create(listener->fd, ss_listener_event_func, listener.get());
#else
        LOG(FATAL) << "attempted to connect to *smartsocket* in daemon";
#endif
    } else {
        listener->fde = fdevent_create(listener->fd, listener_event_func, listener.get());
    }
+4 −5
Original line number Diff line number Diff line
@@ -14,8 +14,7 @@
 * limitations under the License.
 */

#ifndef __ADB_LISTENERS_H
#define __ADB_LISTENERS_H
#pragma once

#include "adb.h"

@@ -44,7 +43,7 @@ std::string format_listeners();
InstallStatus remove_listener(const char* local_name, atransport* transport);
void remove_all_listeners(void);

void enable_daemon_sockets();
#if ADB_HOST
void enable_server_sockets();
void close_smartsockets();

#endif /* __ADB_LISTENERS_H */
#endif
+1 −1
Original line number Diff line number Diff line
@@ -206,7 +206,7 @@ int adb_server_main(int is_daemon, const std::string& socket_spec, int ack_reply
        // We don't accept() client connections until this point: this way, clients
        // can't see wonky state early in startup even if they're connecting directly
        // to the server instead of going through the adb program.
        fdevent_run_on_main_thread([] { enable_daemon_sockets(); });
        fdevent_run_on_main_thread([] { enable_server_sockets(); });
    });
    notify_thread.detach();

+0 −6
Original line number Diff line number Diff line
@@ -173,12 +173,6 @@ static void drop_privileges(int server_port) {
                LOG(FATAL) << "Could not set SELinux context";
            }
        }
        std::string error;
        std::string local_name =
            android::base::StringPrintf("tcp:%d", server_port);
        if (install_listener(local_name, "*smartsocket*", nullptr, 0, nullptr, &error)) {
            LOG(FATAL) << "Could not install *smartsocket* listener: " << error;
        }
    }
}
#endif
Loading