1From 81f822f7b4faf670cb3b04adfb065ae411982226 Mon Sep 17 00:00:00 2001
2From: Jeffy Chen <jeffy.chen@rock-chips.com>
3Date: Tue, 7 Mar 2023 16:51:35 +0800
4Subject: [PATCH 18/20] adbd: Support setting TCP port with env ADB_TCP_PORT
5
6Tested on RK3588 EVB:
7ADB_TCP_PORT=3588 adbd
8
9Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com>
10---
11 core/adbd/adb.c | 16 ++++++----------
12 1 file changed, 6 insertions(+), 10 deletions(-)
13
14diff --git a/core/adbd/adb.c b/core/adbd/adb.c
15index c4c00d7..32173f2 100644
16--- a/core/adbd/adb.c
17+++ b/core/adbd/adb.c
18@@ -1314,17 +1314,13 @@ int adb_main(int is_daemon, int server_port)
19     // If one of these properties is set, also listen on that port
20     // If one of the properties isn't set and we couldn't listen on usb,
21     // listen on the default port.
22-    //property_get("service.adb.tcp.port", value, "");
23-    //if (!value[0]) {
24-        //property_get("persist.adb.tcp.port", value, "");
25-    //}
26-    //if (sscanf(value, "%d", &port) == 1 && port > 0) {
27-    //    printf("using port=%d\n", port);
28+    strcpy(value, getenv("ADB_TCP_PORT") ? : "");
29+    if (sscanf(value, "%d", &port) == 1 && port > 0) {
30+        printf("using port=%d\n", port);
31         // listen on TCP port specified by service.adb.tcp.port property
32-    //    local_init(port);
33-    //} else
34-    if (!usb) {
35-        printf("Using USB\n");
36+        local_init(port);
37+    } else if (!usb) {
38+        printf("Using TCP\n");
39         // listen on default port
40         local_init(DEFAULT_ADB_LOCAL_TRANSPORT_PORT);
41     }
42--
432.20.1
44
45