From 800ba33ff42be775a279e02deef4b655ec3e991f Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Thu, 25 Nov 2021 22:18:36 +0100 Subject: [PATCH] Add function to read an adb property This will allow to read the property "service.adb.tcp.port" to know if the TCP/IP mode is enabled on the device, and which listening port is used. PR #2827 --- app/src/adb.c | 31 +++++++++++++++++++++++++++++++ app/src/adb.h | 7 +++++++ 2 files changed, 38 insertions(+) diff --git a/app/src/adb.c b/app/src/adb.c index 747e5ac9..598b331f 100644 --- a/app/src/adb.c +++ b/app/src/adb.c @@ -373,6 +373,37 @@ adb_disconnect(struct sc_intr *intr, const char *ip_port, unsigned flags) { return process_check_success_intr(intr, pid, "adb disconnect", flags); } +char * +adb_getprop(struct sc_intr *intr, const char *serial, const char *prop, + unsigned flags) { + const char *const adb_cmd[] = {"shell", "getprop", prop}; + + sc_pipe pout; + sc_pid pid = + adb_execute_p(serial, adb_cmd, ARRAY_LEN(adb_cmd), flags, &pout); + if (pid == SC_PROCESS_NONE) { + LOGE("Could not execute \"adb getprop\""); + return NULL; + } + + char buf[128]; + ssize_t r = sc_pipe_read_all_intr(intr, pid, pout, buf, sizeof(buf)); + sc_pipe_close(pout); + + bool ok = process_check_success_intr(intr, pid, "adb getprop", flags); + if (!ok) { + return NULL; + } + + if (r == -1) { + return NULL; + } + + sc_str_truncate(buf, r, " \r\n"); + + return strdup(buf); +} + char * adb_get_serialno(struct sc_intr *intr, unsigned flags) { const char *const adb_cmd[] = {"get-serialno"}; diff --git a/app/src/adb.h b/app/src/adb.h index f56c98c4..8d7f3ea1 100644 --- a/app/src/adb.h +++ b/app/src/adb.h @@ -65,6 +65,13 @@ adb_connect(struct sc_intr *intr, const char *ip_port, unsigned flags); bool adb_disconnect(struct sc_intr *intr, const char *ip_port, unsigned flags); +/** + * Execute `adb getprop ` + */ +char * +adb_getprop(struct sc_intr *intr, const char *serial, const char *prop, + unsigned flags); + /** * Execute `adb get-serialno` *