From dd038eddd7ec11c6fbe37f9082b6215291e0537f Mon Sep 17 00:00:00 2001 From: Alessandro Astone Date: Sun, 29 Jun 2025 21:45:53 +0200 Subject: [PATCH] net: Add "waydroid adb connect" action Now that auto_adb is off by default, we should provide a simple way to manually connect and disconnect adb using the container IP address. --- tools/__init__.py | 7 +++++++ tools/helpers/arguments.py | 8 ++++++++ tools/helpers/net.py | 14 ++++++++++++-- tools/services/user_manager.py | 5 ++++- 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/tools/__init__.py b/tools/__init__.py index 819d54a..e493d53 100644 --- a/tools/__init__.py +++ b/tools/__init__.py @@ -130,6 +130,13 @@ def main(): actions.app_manager.showFullUI(args) elif args.action == "status": actions.status.print_status(args) + elif args.action == "adb": + if args.subaction == "connect": + helpers.net.adb_connect(args) + elif args.subaction == "disconnect": + helpers.net.adb_disconnect(args) + else: + logging.info("Run waydroid {} -h for usage information.".format(args.action)) elif args.action == "log": if args.clear_log: helpers.run.user(args, ["truncate", "-s", "0", args.log]) diff --git a/tools/helpers/arguments.py b/tools/helpers/arguments.py index 2f3af66..b3182b9 100644 --- a/tools/helpers/arguments.py +++ b/tools/helpers/arguments.py @@ -123,6 +123,13 @@ def arguments_logcat(subparser): ret = subparser.add_parser("logcat", help="show android logcat") return ret +def arguments_adb(subparser): + ret = subparser.add_parser("adb", help="manage adb connection") + sub = ret.add_subparsers(title="subaction", dest="subaction") + sub.add_parser("connect", help="connect adb to the Android container") + sub.add_parser("disconnect", help="disconnect adb from the Android container") + return ret + def arguments(): parser = argparse.ArgumentParser(prog="waydroid") @@ -160,6 +167,7 @@ def arguments(): arguments_firstLaunch(sub) arguments_shell(sub) arguments_logcat(sub) + arguments_adb(sub) if argcomplete: argcomplete.autocomplete(parser, always_complete_options="long") diff --git a/tools/helpers/net.py b/tools/helpers/net.py index b267357..13723f3 100644 --- a/tools/helpers/net.py +++ b/tools/helpers/net.py @@ -13,18 +13,28 @@ def adb_connect(args): """ # Check if adb exists on the system. if not which("adb"): - return + raise RuntimeError("Could not find adb") # Start and 'warm up' the adb server tools.helpers.run.user(args, ["adb", "start-server"]) ip = get_device_ip_address() if not ip: - return + raise RuntimeError("Unknown container IP address. Is Waydroid running?") tools.helpers.run.user(args, ["adb", "connect", ip]) logging.info("Established ADB connection to Waydroid device at {}.".format(ip)) +def adb_disconnect(args): + if not which("adb"): + raise RuntimeError("Could not find adb") + + ip = get_device_ip_address() + if not ip: + raise RuntimeError("Unknown container IP address. Was Waydroid ever running?") + + tools.helpers.run.user(args, ["adb", "disconnect", ip]) + def get_device_ip_address(): # The IP address is queried from the DHCP lease file. lease_file = "/var/lib/misc/dnsmasq.waydroid0.leases" diff --git a/tools/services/user_manager.py b/tools/services/user_manager.py index 98cda79..9ab546a 100644 --- a/tools/services/user_manager.py +++ b/tools/services/user_manager.py @@ -72,7 +72,10 @@ NoDisplay={str(hide).lower()} logging.info("Android with user {} is ready".format(uid)) if cfg["waydroid"]["auto_adb"] == "True": - tools.helpers.net.adb_connect(args) + try: + tools.helpers.net.adb_connect(args) + except: + pass platformService = IPlatform.get_service(args) if platformService: -- 2.47.3