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.
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 ...:
input command script is executedpublic static void main() method of Input.javainjectKeyEvent())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 shellcommands for input eventsWhen you execute
adb shell input ...:
- it executes a new process locally
- it connects to the local adb daemon
- the request is forwarded to the adb server on the device
- a shell is started
- the
inputcommand script is executed- this starts a new java process to execute the
public static void main()method ofInput.java- the arguments are parsed
- 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 shellcommands for input events
When you executeadb shell input ...:
- it executes a new process locally
- it connects to the local adb daemon
- the request is forwarded to the adb server on the device
- a shell is started
- the
inputcommand script is executed- this starts a new java process to execute the
public static void main()method ofInput.java- the arguments are parsed
- 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 shellcommands for input events
When you executeadb shell input ...:
- it executes a new process locally
- it connects to the local adb daemon
- the request is forwarded to the adb server on the device
- a shell is started
- the
inputcommand script is executed- this starts a new java process to execute the
public static void main()method ofInput.java- the arguments are parsed
- 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 forwardoradb reverseto 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?
Most helpful comment
Because I don't use
adb shellcommands for input events :wink:When you execute
adb shell input ...:inputcommand script is executedpublic static void main()method ofInput.javainjectKeyEvent())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.