Merge "Show a warning if adb is not root before gdbclient.py" am: 84eeb1a8e6
Original change: https://android-review.googlesource.com/c/platform/development/+/1427154
Change-Id: Ifa7d06ba1e55f8dbff15b37a9a09bf1ac65c4b78
diff --git a/python-packages/gdbrunner/__init__.py b/python-packages/gdbrunner/__init__.py
index f399d73..d2a557f 100644
--- a/python-packages/gdbrunner/__init__.py
+++ b/python-packages/gdbrunner/__init__.py
@@ -197,8 +197,20 @@
stderr=gdbserver_output)
+def get_uid(device):
+ """Gets the uid adbd runs as."""
+ line, _ = device.shell(["id", "-u"])
+ return int(line.strip())
+
+
def forward_gdbserver_port(device, local, remote):
"""Forwards local TCP port `port` to `remote` via `adb forward`."""
+ if get_uid(device) != 0:
+ WARNING = '\033[93m'
+ ENDC = '\033[0m'
+ print(WARNING +
+ "Port forwarding may not work because adbd is not running as root. " +
+ " Run `adb root` to fix." + ENDC)
device.forward("tcp:{}".format(local), remote)
atexit.register(lambda: device.forward_remove("tcp:{}".format(local)))
@@ -370,4 +382,4 @@
except KeyboardInterrupt:
pass
- os.unlink(script_path)
\ No newline at end of file
+ os.unlink(script_path)