From 4cc083ced0f8b7191a231b7489fe4a331da71f76 Mon Sep 17 00:00:00 2001 From: codeskyblue Date: Thu, 9 May 2024 12:56:21 +0800 Subject: [PATCH] change back to old ways forward --- README.md | 4 +++- adbutils/_adb.py | 6 +----- adbutils/_device.py | 12 +----------- docs/PROTOCOL.md | 20 ++++++++++++++------ 4 files changed, 19 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 61ec8c1..5cbe1c2 100644 --- a/README.md +++ b/README.md @@ -543,10 +543,12 @@ gh-md-toc --insert README.md - [swind pure-python-adb](https://github.com/Swind/pure-python-adb) - [openstf/adbkit](https://github.com/openstf/adbkit) - [ADB Source Code](https://android.googlesource.com/platform/system/core/+/android-4.4_r1/adb/adb.c) -- ADB Protocols [OVERVIEW.TXT](https://cs.android.com/android/platform/superproject/+/master:packages/modules/adb/OVERVIEW.TXT) [SERVICES.TXT](https://cs.android.com/android/platform/superproject/+/master:packages/modules/adb/SERVICES.TXT) [SYNC.TXT](https://cs.android.com/android/platform/superproject/+/master:packages/modules/adb/SYNC.TXT) - [Awesome ADB](https://github.com/mzlogin/awesome-adb) - [JakeWharton/pidcat](https://github.com/JakeWharton/pidcat) +# Develop +[PROTOCOL.md](docs/PROTOCOL.md) + # Alternative - https://github.com/Swind/pure-python-adb diff --git a/adbutils/_adb.py b/adbutils/_adb.py index d8c2de6..c389b57 100644 --- a/adbutils/_adb.py +++ b/adbutils/_adb.py @@ -342,10 +342,6 @@ def forward_list(self, serial: Union[None, str] = None) -> List[ForwardItem]: items.append(ForwardItem(*parts)) return items - @deprecated(deprecated_in="0.15.0", - removed_in="1.0.0", - details="use Device.forward instead", - current_version=__version__) def forward(self, serial, local, remote, norebind=False): """ Args: @@ -357,7 +353,7 @@ def forward(self, serial, local, remote, norebind=False): AdbError """ with self.make_connection() as c: - cmds = ["host-serial", serial, "forward"] + cmds = ["host-serial", serial, "forward"] # host-prefix:forward:norebind:; if norebind: cmds.append("norebind") cmds.append(local + ";" + remote) diff --git a/adbutils/_device.py b/adbutils/_device.py index 5ddb9f4..9006801 100644 --- a/adbutils/_device.py +++ b/adbutils/_device.py @@ -235,17 +235,7 @@ def shell2( return ShellReturn(command=cmdargs, returncode=returncoode, output=output) def forward(self, local: str, remote: str, norebind: bool = False): - c = self.open_transport() - args = ["host:forward"] - if norebind: - args.append("norebind") - args.append(local + ";" + remote) - c.send_command(":".join(args)) - c.check_okay() # this OKAY means message was received - c.check_okay() # check reponse - # when successfully forwarded, port string will response, eg: "00041237" - # here we just read it and ignore - c.read_until_close() + self._client.forward(self._serial, local, remote, norebind) def forward_port(self, remote: Union[int, str]) -> int: """forward remote port to local random port""" diff --git a/docs/PROTOCOL.md b/docs/PROTOCOL.md index e0c3f5d..f145116 100644 --- a/docs/PROTOCOL.md +++ b/docs/PROTOCOL.md @@ -11,8 +11,14 @@ TCP Local(5555) -> Remote(localhost:5037) execute adb command, e.g. `adb -P 5555 devices`, now data should be seen in charles. +ADB Protocols from Android Source Code + +- [OVERVIEW.TXT](https://cs.android.com/android/platform/superproject/+/main:packages/modules/adb/OVERVIEW.TXT) +- [SERVICES.TXT](https://cs.android.com/android/platform/superproject/+/main:packages/modules/adb/SERVICES.TXT) +- [SYNC.TXT](https://cs.android.com/android/platform/superproject/+/main:packages/modules/adb/SYNC.TXT) + ## host version -``` +```bash >send 000chost:version @@ -21,7 +27,7 @@ execute adb command, e.g. `adb -P 5555 devices`, now data should be seen in char ``` ## host tport device not found -``` +```bash >send 0026host:tport:serial:GBG5T197110027690014 @@ -32,7 +38,7 @@ execute adb command, e.g. `adb -P 5555 devices`, now data should be seen in char ``` ## forward -``` +```bash $ adb forward --list >send 0011host:list-forward @@ -42,7 +48,8 @@ OKAY0020emulator-5554 tcp:5678 tcp:8765 $ adb forward --remove-all >send -000ehost:tport:any0014host:killforward-all +000ehost:tport:any +0014host:killforward-all send -001fhost:tport:serial:emulator-5554001ehost:forward:tcp:1234;tcp:4321 +001fhost:tport:serial:emulator-5554 +001ehost:forward:tcp:1234;tcp:4321 send 0022host:tport:serial:GBG5T197110027690014