Romain Vimont
b49f4e795e
Add missing error handling
...
If "adb get-serialno" fails, attempting to read from the uninitialized
pipe is incorrect.
2021-11-17 21:59:19 +01:00
Romain Vimont
3eb8202adf
Configure init and cleanup asynchronously
...
Accessing the settings (like --show-touches) on start should not delay
screen mirroring.
2021-11-17 20:09:22 +01:00
Romain Vimont
83f66ea06c
Do not quit on cleanup configuration failure
...
Cleanup is used for some options like --show-touches to restore the
state on exit.
If the configuration fails, do not crash the whole process. Just log an
error.
2021-11-17 20:09:22 +01:00
Romain Vimont
3cc0921e61
Move init and cleanup to a separate method
2021-11-17 20:09:22 +01:00
Romain Vimont
d8358ce857
Read/write settings via command on Android >= 12
...
Before Android 8, executing the "settings" command from a shell was
very slow (~1 second), because it spawned a new app_process to execute
Java code. Therefore, to access settings without performance issues,
scrcpy used private APIs to read from and write to settings.
However, since Android 12, this is not possible anymore, due to
permissions changes.
To make it work again, execute the "settings" command on Android 12 (or
on previous version if the other method failed). This method is faster
than before Android 8 (~100ms).
Fixes #2671 <https://github.com/Genymobile/scrcpy/issues/2671 >
Fixes #2788 <https://github.com/Genymobile/scrcpy/issues/2788 >
2021-11-17 20:08:54 +01:00
Romain Vimont
4bc5baeeb5
Add throwable parameter to Log.w()
...
When an exception occurs, we might want to log a warning instead of an
error.
2021-11-17 19:59:43 +01:00
Romain Vimont
0672f7e405
Report settings errors via Exceptions
...
Settings read/write errors were silently ignored. Report them via a
SettingsException so that the caller can handle them.
This allows to log a proper error message, and will also allow to
fallback to a different settings method in case of failure.
2021-11-17 19:59:27 +01:00
Romain Vimont
6d6a436563
Wrap settings management into a Settings class
...
Until now, the code that needed to read/write the Android settings had
to explicitly open and close a ContentProvider.
Wrap these details into a Settings class.
This paves the way to provide an alternative implementation of settings
read/write for Android >= 12.
2021-11-17 19:52:04 +01:00
Romain Vimont
9cb14b5166
Inherit only specific handles on Windows
...
To be able to communicate with a child process via stdin, stdout and
stderr, the CreateProcess() parameter bInheritHandles must be set to
TRUE. But this causes *all* handles to be inherited, including sockets.
As a result, the server socket was inherited by the process running adb
to execute the server on the device, so it could not be closed properly,
causing other scrcpy instances to fail.
To fix the issue, use an extended API to explicitly set the HANDLEs to
inherit:
- <https://stackoverflow.com/a/28185363/1987178 >
- <https://devblogs.microsoft.com/oldnewthing/20111216-00/?p=8873 >
Fixes #2779 <https://github.com/Genymobile/scrcpy/issues/2779 >
PR #2783 <https://github.com/Genymobile/scrcpy/pull/2783 >
2021-11-15 10:13:30 +01:00
Romain Vimont
9cb8766220
Factorize resource release after CreateProcess()
...
Free the wide characters string in all cases before checking for errors.
2021-11-15 07:49:01 +01:00
Romain Vimont
fd4ec784e0
Remove useless assignments on error
...
Leave the output parameter untouched on error.
2021-11-14 22:53:49 +01:00
Romain Vimont
52cebe1597
Fix Windows sc_pipe function names
...
The implementation name was incorrect (it was harmless, because they are
not used on Windows).
2021-11-14 22:41:38 +01:00
Romain Vimont
6a27062f48
Stop connection attempts if interrupted
...
If the interruptor is interrupted, every network call will fail, but the
retry-on-error mechanism must also be stopped.
2021-11-14 15:40:59 +01:00
Romain Vimont
739ff9dce0
Fix compilation errors with old SDL versions
...
SDL_PixelFormatEnum has been introduced in SDL 2.0.10:
<https://github.com/libsdl-org/SDL/commit/cc6a8ac87e41d0df68075081dbf5cd2ba46f8fd4 >
SDL_PIXELFORMAT_BGR444 has been introduced in SDL 2.0.12:
<https://github.com/libsdl-org/SDL/commit/a1c11854f28b7186a744df412aa6273862459c31 >
Fixes #2777 <https://github.com/Genymobile/scrcpy/issues/2777 >
PR #2781 <https://github.com/Genymobile/scrcpy/pull/2781 >
Reviewed-by: Yu-Chen Lin <npes87184@gmail.com >
2021-11-14 15:37:30 +01:00
Romain Vimont
65b023ac6d
Update links to v1.20
2021-11-14 01:51:32 +01:00
Romain Vimont
a045e28df8
Bump version to 1.20
2021-11-14 01:25:24 +01:00
Romain Vimont
52138fd921
Update script to build without gradle to SDK 31
...
Build tools 31.x.x do not ship dx anymore. Use d8 instead.
Refs 8bf28e9f53
2021-11-14 01:25:24 +01:00
Romain Vimont
1bb0df5da1
Extract ANDROID_JAR path in build script
...
This will allow to reuse it.
2021-11-14 01:25:24 +01:00
Romain Vimont
562ec6e9b3
Merge branch 'master' into dev
2021-11-14 01:25:00 +01:00
Romain Vimont
1be5daf999
Fix word order in README
2021-11-14 01:23:06 +01:00
Romain Vimont
57387fa707
Mention crash on Android 12 on old scrcpy in FAQ
2021-11-14 01:23:06 +01:00
Romain Vimont
4e811a4a68
Adapt icon in README
...
Use SVG format, align to the right, and reduce its size.
2021-11-14 01:23:06 +01:00
Romain Vimont
99a4a48477
Replace "connected on" to "connected via"
...
I'm not sure "connected on USB" is correct.
2021-11-14 01:23:06 +01:00
Romain Vimont
1d97d77032
Improve scrcpy presentation in README
2021-11-14 01:23:06 +01:00
Romain Vimont
45b0f8123a
Increase delay to inject HID on Ctrl+v
...
2 milliseconds turn out to be insufficient sometimes. It seems that 5
milliseconds is enough (and still not noticeable).
2021-11-14 01:23:06 +01:00
Romain Vimont
c1a34881d7
Use sc_ prefix for server
2021-11-14 01:23:05 +01:00
Romain Vimont
057c7a4df4
Move str_util to str
...
Simplify naming.
2021-11-14 01:22:22 +01:00
Romain Vimont
979ce64dc0
Improve string util API
...
Use prefixed names and improve documentation.
2021-11-14 01:22:22 +01:00
Romain Vimont
9a0bd545d5
Rename SC_INVALID_SOCKET to SC_SOCKET_NONE
...
For consistency with SC_PROCESS_NONE.
2021-11-14 01:22:22 +01:00
Romain Vimont
c4d008b96a
Extract adb tunnel to a separate component
...
This simplifies the server code.
2021-11-14 01:22:22 +01:00
Romain Vimont
0d45c29d13
Move IPV4_LOCALHOST to net.h
...
This constant will be used from several files.
2021-11-14 01:22:22 +01:00
Romain Vimont
37c840a4c8
Interrupt on process terminated
...
Interrupt any blocking call on process terminated, like on
server_stop().
This allows to interrupt any blocking accept() with correct
synchronization without additional complexity.
2021-11-14 01:22:22 +01:00
Romain Vimont
f488cbd7e7
Make server interruptible
...
Use an interruptor to immediately wake up blocking calls on
server_stop().
2021-11-14 01:22:20 +01:00
Romain Vimont
40340509d9
Add interruptor utilities
...
Expose wrapper functions for interrupting blocking calls, for process
and sockets.
2021-11-13 22:54:18 +01:00
Romain Vimont
e0896142db
Introduce interruptor tool
...
An interruptor instance will help to wake up a blocking call from
another thread (typically to terminate immediately on Ctrl+C).
2021-11-13 22:53:07 +01:00
Romain Vimont
0426708544
Run the server from a dedicated thread
...
Define server callbacks, start the server asynchronously and listen to
connection events to initialize scrcpy properly.
It will help to simplify the server code, and allows to run the UI event
loop while the server is connecting. In particular, this will allow to
receive SIGINT/Ctrl+C events during connection to interrupt immediately.
2021-11-13 10:19:52 +01:00
Romain Vimont
5b9c88693e
Wait using a condition variable in server
...
Currently, server_stop() is called from the same thread as
server_connect_to(), so interruption may never happen.
This is a step to prepare executing the server from a dedicated thread.
2021-11-13 10:17:51 +01:00
Romain Vimont
a54dc8212f
Reorder server functions
...
This will avoid forward declarations in future commits.
2021-11-13 10:16:35 +01:00
Romain Vimont
882e4cff5f
Copy server params
...
This is a preliminary step necessary to move the server to a separate
thread.
2021-11-13 10:05:20 +01:00
Romain Vimont
9fa4d1cd4a
Reorder server and server_params
...
This will allow to define a server_params field in server.
2021-11-13 10:05:20 +01:00
Romain Vimont
0bfa75a48b
Split socket creation and connect/listen
...
This will allow to assign the socket to a variable before connecting or
listening, so that it can be interrupted from another thread.
2021-11-13 10:05:20 +01:00
Romain Vimont
ed19901db1
Set video and control sockets only on success
...
Store the video and control sockets only if server_connect_to() returns
successfully.
2021-11-13 10:05:01 +01:00
Romain Vimont
e69356c550
Initialize tunnel_enabled flag internally
...
Set the flag from the inner methods, to avoid bypassing the assignment
by mistake (on error for example).
2021-11-13 10:03:03 +01:00
Romain Vimont
03de9224fc
Introduce process observer
...
Add a tool to easily observe process termination.
This allows to move this complexity out of the server code.
2021-11-13 10:02:23 +01:00
Romain Vimont
aa011832c1
Improve process API
...
Prefix symbols and constants names and improve documentation.
2021-11-12 22:44:37 +01:00
Romain Vimont
7e93abcf6d
Factorize common impl of process_execute()
...
Both implementations are the same. Move them to the common process.c.
2021-11-12 22:44:37 +01:00
Romain Vimont
e80e6631e4
Remove duplicate function declaration
...
The function process_terminate() was declared twice.
2021-11-12 22:44:37 +01:00
Romain Vimont
fcc04f967b
Improve file API
...
Prefix symbols and constants names and improve documentation.
2021-11-12 22:44:37 +01:00
Romain Vimont
d4c262301f
Move functions from process to file
...
Move filesystem-related functions from process.[ch] to file.[ch].
2021-11-12 22:44:37 +01:00
Romain Vimont
be55e250ca
Make screen_render() static
...
It is only used from screen.c.
2021-11-12 22:44:22 +01:00
Romain Vimont
c548f017bf
Upgrade junit to 4.13.1
2021-11-12 22:44:18 +01:00
Romain Vimont
7a733328bc
Adapt help to terminal size
...
If the error stream is a terminal, and we can retrieve the terminal
size, wrap the help content according to the terminal width.
2021-11-11 15:22:39 +01:00
Romain Vimont
38332f683c
Add util function to get terminal size
2021-11-11 15:22:39 +01:00
Romain Vimont
3f51a2ab43
Generate getopt params from option structures
...
Use the option descriptions to generate the optstring and longopts
parameters for the getopt_long() command.
That way, the options are completely described in a single place.
2021-11-11 14:59:34 +01:00
Romain Vimont
74ab0a4df8
Structure shortcuts help
2021-11-11 14:59:34 +01:00
Romain Vimont
f59e9e3cb0
Structure command line options help
...
It will allow to correctly print the help for the current terminal size
(even if for now it is hardcoded to 80 columns).
2021-11-11 14:59:34 +01:00
Romain Vimont
9ec3406568
Add line wrapper
...
Add a tool to wrap lines at words boundaries (spaces) to fit in a
specified number of columns, left-indented by a specified number of
spaces.
2021-11-11 14:55:53 +01:00
Romain Vimont
6dba1922c1
Add string buffer util
...
This will help to build strings incrementally.
2021-11-11 14:55:52 +01:00
Romain Vimont
570a003c39
Remove deprecated -T option
...
The short option -T is deprecated since v1.11. Only the long version
(--always-on-top) remains.
2021-11-07 21:35:57 +01:00
Romain Vimont
b62df7ee91
Remove deprecated -c option
...
The short option -c is deprecated since v1.11. Only the long version
(--crop) remains.
2021-11-07 21:35:53 +01:00
Romain Vimont
30d40f4e78
Document --power-off-on-close
...
The option was not documented.
Refs #824 <https://github.com/Genymobile/scrcpy/pull/824 >
2021-11-07 19:27:53 +01:00
Romain Vimont
f489f7fcad
Mention drag & drop for non-APK files in help
2021-11-07 18:51:22 +01:00
Romain Vimont
d72c7076f7
Mention drag & drop APK in README
...
For consistency with --help and manpage.
2021-11-07 18:50:29 +01:00
Romain Vimont
fc64445555
Remove extra space in README
2021-11-07 18:50:24 +01:00
Romain Vimont
f65c3fde69
Fix typos in help
2021-11-07 18:50:24 +01:00
Romain Vimont
48fcfa96ab
Add missing include "common.h"
2021-11-06 19:26:29 +01:00
Romain Vimont
676fa73d2c
Wrap device name and size in a struct
...
As a benefit, this avoids to take care of the device name length on the
caller side.
2021-11-02 11:08:58 +01:00
Romain Vimont
58ea238fb2
Remove unnecessary variable
...
Test directly if a record filename is provided, without an intermediate
boolean variable.
2021-10-31 12:45:59 +01:00
Romain Vimont
13c4aa1a3b
Disable synthetic mouse events from touch events
...
Touch events with id SDL_TOUCH_MOUSEID are ignored anyway, but it is
better not to generate them in the first place.
2021-10-31 12:45:59 +01:00
Romain Vimont
caf594c90e
Split SDL initialization
...
Initialize SDL_INIT_EVENTS first (very quick) and SDL_INIT_VIDEO after
the server (quite long).
2021-10-31 12:45:59 +01:00
Romain Vimont
688477ff65
Move SDL initialization
...
Inline SDL initialization in scrcpy(). This will allow to split
minimal initialization and video initialization.
2021-10-31 12:45:59 +01:00
Romain Vimont
ac539e1312
Set SDL hints before initialization
...
In theory, some SDL hints should be initialized before calling
SDL_Init().
2021-10-31 12:45:59 +01:00
Romain Vimont
a57c7d3a2b
Extract SDL hints
...
Set all SDL hints in a separate function.
2021-10-31 12:45:56 +01:00
Romain Vimont
d2d18466d4
Factorize SDL event push
...
Add a macro and inline function to call SDL_PushEvent() and log on error
(without actually handling the error, because there is nothing we could
do).
2021-10-30 22:36:56 +02:00
Romain Vimont
dae091e3ab
Handle SDL_PushEvent() errors
...
Pushing an event to the main thread may fail. If this happens, log an
error, and try to recover when possible.
2021-10-30 20:25:20 +02:00
Romain Vimont
4c4381de4c
Use sc_ prefix for size, position and point
2021-10-30 15:20:39 +02:00
Romain Vimont
db484d82db
Upgrade gradle build tools to 7.0.2
2021-10-30 11:32:48 +02:00
Romain Vimont
0c9666b733
Upgrade Android checkstyle to 9.0.1
...
Adapt checkstyle.xml to match the latest version, and remove a line
break between imports which trigger a checkstyle volation.
2021-10-30 11:23:51 +02:00
Romain Vimont
8bf28e9f53
Upgrade Android SDK to 31
2021-10-30 11:23:51 +02:00
Romain Vimont
06131ef634
Fix typo in clock comments
2021-10-29 12:21:34 +02:00
Romain Vimont
34eb10ea0b
Define v4l2 option field only if HAVE_V4L2
2021-10-27 18:43:47 +02:00
Romain Vimont
27fa23846d
Define default options as const struct
...
This is more readable than a macro, and we could ifdef some fields.
2021-10-27 18:43:47 +02:00
Romain Vimont
e4d5c1ce36
Move scrcpy option structs to options.h
...
This will allow to define symbols in options.c without all the
dependencies of scrcpy.c.
2021-10-27 18:43:47 +02:00
Romain Vimont
ac23bec144
Expose socket interruption
...
On Linux, socket functions are unblocked by shutdown(), but on Windows
they are unblocked by closesocket().
Expose net_interrupt() and net_close() to abstract these differences:
- net_interrupt() calls shutdown() on Linux and closesocket() on
Windows (if not already called);
- net_close() calls close() on Linux and closesocket() on Windows (if
not already called).
This simplifies the server code, and prevents a data race on close
(reported by TSAN) on Linux (but does not fix it on Windows):
WARNING: ThreadSanitizer: data race (pid=836124)
Write of size 8 at 0x7ba0000000d0 by main thread:
#0 close ../../../../src/libsanitizer/tsan/tsan_interceptors_posix.cpp:1690 (libtsan.so.0+0x359d8)
#1 net_close ../app/src/util/net.c:211 (scrcpy+0x1c76b)
#2 close_socket ../app/src/server.c:330 (scrcpy+0x19442)
#3 server_stop ../app/src/server.c:522 (scrcpy+0x19e33)
#4 scrcpy ../app/src/scrcpy.c:532 (scrcpy+0x156fc)
#5 main ../app/src/main.c:92 (scrcpy+0x622a)
Previous read of size 8 at 0x7ba0000000d0 by thread T6:
#0 recv ../../../../src/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:6603 (libtsan.so.0+0x4f4a6)
#1 net_recv ../app/src/util/net.c:167 (scrcpy+0x1c5a7)
#2 run_receiver ../app/src/receiver.c:76 (scrcpy+0x12819)
#3 <null> <null> (libSDL2-2.0.so.0+0x84f40)
2021-10-27 18:41:58 +02:00
Romain Vimont
e5ea13770b
Add socket wrapper
...
This paves the way to store an additional "closed" flag on Windows
to interrupt and close properly.
2021-10-26 22:49:57 +02:00
Romain Vimont
3eac212af1
Use net_send() from net_send_all()
...
This will make net_send_all() continue to work even if net_send()
behavior is changed.
2021-10-26 22:49:45 +02:00
Romain Vimont
3adff37c2d
Use sc_ prefix for sockets
...
Rename:
- socket_t to sc_socket
- INVALID_SOCKET to SC_INVALID_SOCKET
2021-10-26 22:49:45 +02:00
Romain Vimont
eb6afe7669
Move net_init() and net_cleanup() upwards
...
These two functions are global, define them at the top of the
implementation file. This is consistent with the header file.
2021-10-26 22:49:45 +02:00
Romain Vimont
5222f213f4
Update FAQ to mention HID keyboard
2021-10-26 21:30:04 +02:00
Romain Vimont
e4163321f0
Delay HID events on Ctrl+v
...
When Ctrl+v is pressed, a control is sent to the device to set the
device clipboard before injecting Ctrl+v.
With the InputManager method, it is guaranteed that the device
synchronization is executed before handling Ctrl+v, since the commands
are executed on the device in sequence.
However, HID are injected from the computer, so there is no such
guarantee. As a consequence, on Android, Ctrl+v triggers a paste with
the old clipboard content.
To workaround the issue, wait a bit (2 milliseconds) from the AOA
thread before injecting the event, to leave enough time for the
clipboard to be set before injecting Ctrl+v.
2021-10-26 21:30:04 +02:00
Romain Vimont
c96874b257
Synchronize HID keyboard state on first event
...
When an AOA HID keyboard is registered, CAPSLOCK and NUMLOCK are both
disabled, regardless of the state of the computer keyboard.
To synchronize the state, on first key event, inject CAPSLOCK and/or
NUMLOCK if necessary.
2021-10-26 21:30:04 +02:00
Romain Vimont
511356710d
Retrieve device serial for AOA
...
The serial is necessary to find the correct Android device for AOA.
If it is not explicitly provided by the user via -s, then execute "adb
getserialno" to retrieve it.
2021-10-26 21:30:04 +02:00
Romain Vimont
d55015e4cf
Expose function to get the device serial
...
Expose adb_get_serialno() to retrieve the device serial via the command
"adb getserialno".
2021-10-26 21:30:04 +02:00
Romain Vimont
0681480809
Add read_pipe_all()
...
Add a convenience function to read from a pipe until all requested data
has been read.
2021-10-26 21:30:04 +02:00
Romain Vimont
96b18dabaa
Expose adb execution with redirection
...
Expose the redirection feature to the adb API.
2021-10-26 21:30:04 +02:00
Romain Vimont
eaf4afaad9
Add command execution with redirection
...
Expose command execution with pipes to stdin, stdout and stderr.
This will allow to read the result of adb commands.
2021-10-26 21:30:04 +02:00
Romain Vimont
f7d1efdf1d
Extract mouse processor trait
...
Mainly for consistency with the keyboard processor trait.
This could allow to provide alternative mouse processors.
2021-10-26 21:30:04 +02:00
Romain Vimont
bcf5a9750f
Extract keyboard processor trait
...
This will allow to provide alternative key processors.
2021-10-26 21:30:04 +02:00
Romain Vimont
056d36ce4a
Fix trait header guards
2021-10-26 21:30:04 +02:00
Romain Vimont
bea3197c3f
Remove unused markdown link in README
2021-10-25 18:22:48 +02:00