]> glassweightruler.freedombox.rocks Git - waydroid.git/commitdiff
net: Add "waydroid adb connect" action
authorAlessandro Astone <ales.astone@gmail.com>
Sun, 29 Jun 2025 19:45:53 +0000 (21:45 +0200)
committerAlessandro Astone <ales.astone@gmail.com>
Sun, 29 Jun 2025 19:45:55 +0000 (21:45 +0200)
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
tools/helpers/arguments.py
tools/helpers/net.py
tools/services/user_manager.py

index 819d54ac9a177d401c5cf4bcdbcc8e5c3507ef37..e493d53249565d3e422d03a5b6ffc3cdbce1895d 100644 (file)
@@ -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])
index 2f3af66f1a0476b619b03f7647a071abc6fe8088..b3182b936b3f666801279ad458c9b30779cd686e 100644 (file)
@@ -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")
index b267357af6863bf6aadd4ec51009e6e19f214c98..13723f3ebcc2f2b1eb7257e5e8273cde59ca3855 100644 (file)
@@ -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"
index 98cda79e06e03f5c3a0791f2bc043a8d42ff2d1d..9ab546a7ec6668d20767f8df19958e88d249b7c6 100644 (file)
@@ -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: