Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why your adb shell cmd execute so fast? #231

Closed
SSSANTON opened this issue Aug 19, 2018 · 5 comments
Closed

Why your adb shell cmd execute so fast? #231

SSSANTON opened this issue Aug 19, 2018 · 5 comments
Labels

Comments

@SSSANTON
Copy link

While I execute an adb comand like("adb shell input tap 100 100") in Command prompt window, it almost have 1 second delay in my phone.

So could you tell me the key to improve the execution speed? Thanks.

@rom1v
Copy link
Collaborator

rom1v commented Aug 19, 2018

Why your adb shell cmd execute so fast?

Because I don't use adb shell commands for input events 😉

When you execute adb shell input ...:

  1. it executes a new process locally
  2. it connects to the local adb daemon
  3. the request is forwarded to the adb server on the device
  4. a shell is started
  5. the input command script is executed
  6. this starts a new java process to execute the public static void main() method of Input.java
  7. the arguments are parsed
  8. the events are injected by a simple method call (e.g. injectKeyEvent())

All of this is executed for every adb shell input ... command. The main delay is step 6 (starting the Java process).

In scrcpy, only 1 Java process is started (the server) for the whole session. This process opens a socket to communicate with the client.

The client sends every input event over this socket (using a custom protocol). The server receives and handle these events immediately.

@rom1v rom1v added the question label Aug 19, 2018
@SSSANTON
Copy link
Author

@rom1v
Thanks! I will learn more details from your achievement.

@rom1v rom1v closed this as completed Sep 24, 2018
@MemoryAndDream
Copy link

Why your adb shell cmd execute so fast?

Because I don't use adb shell commands for input events

When you execute adb shell input ...:

  1. it executes a new process locally
  2. it connects to the local adb daemon
  3. the request is forwarded to the adb server on the device
  4. a shell is started
  5. the input command script is executed
  6. this starts a new java process to execute the public static void main() method of Input.java
  7. the arguments are parsed
  8. the events are injected by a simple method call (e.g. injectKeyEvent())

All of this is executed for every adb shell input ... command. The main delay is step 6 (starting the Java process).

In scrcpy, only 1 Java process is started (the server) for the whole session. This process opens a socket to communicate with the client.

The client sends every input event over this socket (using a custom protocol). The server receives and handle these events immediately.

So how can I use ADB command to reuse the java process for the whole session ? I am using python to execute adb command and I search for a long time to solve the delay problem with ADB.

@npes87184
Copy link
Contributor

npes87184 commented Mar 22, 2019

Why your adb shell cmd execute so fast?

Because I don't use adb shell commands for input events
When you execute adb shell input ...:

  1. it executes a new process locally
  2. it connects to the local adb daemon
  3. the request is forwarded to the adb server on the device
  4. a shell is started
  5. the input command script is executed
  6. this starts a new java process to execute the public static void main() method of Input.java
  7. the arguments are parsed
  8. the events are injected by a simple method call (e.g. injectKeyEvent())

All of this is executed for every adb shell input ... command. The main delay is step 6 (starting the Java process).
In scrcpy, only 1 Java process is started (the server) for the whole session. This process opens a socket to communicate with the client.
The client sends every input event over this socket (using a custom protocol). The server receives and handle these events immediately.

So how can I use ADB command to reuse the java process for the whole session ? I am using python to execute adb command and I search for a long time to solve the delay problem with ADB.

You can use adb forward or adb reverse to create a tunnel between PC and Android. After it, create a process in Android which always live, listen to this tunnel and handle the request from PC.

@deniznehlyadyuk
Copy link

Why your adb shell cmd execute so fast?

Because I don't use adb shell commands for input events
When you execute adb shell input ...:

  1. it executes a new process locally
  2. it connects to the local adb daemon
  3. the request is forwarded to the adb server on the device
  4. a shell is started
  5. the input command script is executed
  6. this starts a new java process to execute the public static void main() method of Input.java
  7. the arguments are parsed
  8. the events are injected by a simple method call (e.g. injectKeyEvent())

All of this is executed for every adb shell input ... command. The main delay is step 6 (starting the Java process).
In scrcpy, only 1 Java process is started (the server) for the whole session. This process opens a socket to communicate with the client.
The client sends every input event over this socket (using a custom protocol). The server receives and handle these events immediately.

So how can I use ADB command to reuse the java process for the whole session ? I am using python to execute adb command and I search for a long time to solve the delay problem with ADB.

You can use adb forward or adb reverse to create a tunnel between PC and Android. After it, create a process in Android which always live, listen to this tunnel and handle the request from PC.

Can you please share code? Or some referances?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants