]> glassweightruler.freedombox.rocks Git - waydroid.git/commitdiff
Add device IP address to status, auto adb connect
authorMaximilian Wende <dasisdormax@mailbox.org>
Sun, 16 Apr 2023 07:24:03 +0000 (09:24 +0200)
committerAlessandro Astone <ales.astone@gmail.com>
Sun, 16 Apr 2023 17:27:59 +0000 (19:27 +0200)
tools/actions/status.py
tools/helpers/net.py [new file with mode: 0644]
tools/services/user_manager.py

index 32ad89931ae7960e75584ce856d2bba02d5d114f..bb2aac23a2581e993ff90de89f5cb72a78cbb236 100644 (file)
@@ -3,6 +3,7 @@
 import os
 import tools.config
 import tools.helpers.ipc
 import os
 import tools.config
 import tools.helpers.ipc
+import tools.helpers.net
 import dbus
 
 def print_status(args):
 import dbus
 
 def print_status(args):
@@ -17,6 +18,7 @@ def print_status(args):
             print("Session:\tRUNNING")
             print("Container:\t" + session["state"])
             print("Vendor type:\t" + cfg["waydroid"]["vendor_type"])
             print("Session:\tRUNNING")
             print("Container:\t" + session["state"])
             print("Vendor type:\t" + cfg["waydroid"]["vendor_type"])
+            print("IP address:\t" + (tools.helpers.net.get_device_ip_address() or "UNKNOWN"))
             print("Session user:\t{}({})".format(session["user_name"], session["user_id"]))
             print("Wayland display:\t" + session["wayland_display"])
         else:
             print("Session user:\t{}({})".format(session["user_name"], session["user_id"]))
             print("Wayland display:\t" + session["wayland_display"])
         else:
diff --git a/tools/helpers/net.py b/tools/helpers/net.py
new file mode 100644 (file)
index 0000000..c20a95b
--- /dev/null
@@ -0,0 +1,36 @@
+# Copyright 2023 Maximilian Wende
+# SPDX-License-Identifier: GPL-3.0-or-later
+from shutil import which
+import tools.helpers.run
+import logging
+import re
+
+def adb_connect(args):
+    """
+    Creates an android debugging connection from the host system to the
+    Waydroid device, if ADB is found on the host system and the device
+    has booted.
+    """
+    # Check if adb exists on the system.
+    if not which("adb"):
+        return
+
+    # Start and 'warm up' the adb server
+    tools.helpers.run.user(args, ["adb", "start-server"])
+
+    ip = get_device_ip_address()
+    if not ip:
+        return
+
+    tools.helpers.run.user(args, ["adb", "connect", ip])
+    logging.info("Established ADB connection to Waydroid device at {}.".format(ip))
+
+def get_device_ip_address():
+    # The IP address is queried from the DHCP lease file.
+    lease_file = "/var/lib/misc/dnsmasq.waydroid0.leases"
+
+    try:
+        with open(lease_file) as f:
+            return re.search("(\d{1,3}\.){3}\d{1,3}\s", f.read()).group().strip()
+    except:
+        pass
\ No newline at end of file
index 56160353a2b8d62b8da2e6dc4089e3879cab8b60..b8b985421cfb49679815997c04d051a942b54772 100644 (file)
@@ -4,6 +4,7 @@ import logging
 import os
 import threading
 import tools.config
 import os
 import threading
 import tools.config
+import tools.helpers.net
 from tools.interfaces import IUserMonitor
 from tools.interfaces import IPlatform
 
 from tools.interfaces import IUserMonitor
 from tools.interfaces import IPlatform
 
@@ -66,6 +67,8 @@ def start(args, session, unlocked_cb=None):
     def userUnlocked(uid):
         logging.info("Android with user {} is ready".format(uid))
 
     def userUnlocked(uid):
         logging.info("Android with user {} is ready".format(uid))
 
+        tools.helpers.net.adb_connect(args)
+
         platformService = IPlatform.get_service(args)
         if platformService:
             if not os.path.exists(apps_dir):
         platformService = IPlatform.get_service(args)
         if platformService:
             if not os.path.exists(apps_dir):