]> glassweightruler.freedombox.rocks Git - waydroid.git/blob - tools/helpers/net.py
Remove unused python imports
[waydroid.git] / tools / helpers / net.py
1 # Copyright 2023 Maximilian Wende
2 # SPDX-License-Identifier: GPL-3.0-or-later
3 from shutil import which
4 import tools.helpers.run
5 import logging
6 import re
7
8 def adb_connect(args):
9 """
10 Creates an android debugging connection from the host system to the
11 Waydroid device, if ADB is found on the host system and the device
12 has booted.
13 """
14 # Check if adb exists on the system.
15 if not which("adb"):
16 return
17
18 # Start and 'warm up' the adb server
19 tools.helpers.run.user(args, ["adb", "start-server"])
20
21 ip = get_device_ip_address()
22 if not ip:
23 return
24
25 tools.helpers.run.user(args, ["adb", "connect", ip])
26 logging.info("Established ADB connection to Waydroid device at {}.".format(ip))
27
28 def get_device_ip_address():
29 # The IP address is queried from the DHCP lease file.
30 lease_file = "/var/lib/misc/dnsmasq.waydroid0.leases"
31
32 try:
33 with open(lease_file) as f:
34 return re.search(r"(\d{1,3}\.){3}\d{1,3}\s", f.read()).group().strip()
35 except:
36 pass