Scrcpy: Why your adb shell cmd execute so fast?

Created on 19 Aug 2018  路  5Comments  路  Source: Genymobile/scrcpy

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.

question

Most helpful comment

Why your adb shell cmd execute so fast?

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

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.

All 5 comments

Why your adb shell cmd execute so fast?

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

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
Thanks! I will learn more details from your achievement.

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.

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.

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?

Was this page helpful?
0 / 5 - 0 ratings