Romain Vimont
d74cfd5711
Silence DiscouragedPrivateApi lint warning
2025-06-13 09:40:45 +02:00
Romain Vimont
cd3a5d50b6
Create ClipboardManager from the main thread
...
The ClipboardManager is instantiated by the first call to
ServiceManager.getClipboardManager().
Now that scrcpy uses android.content.ClipboardManager directly, it must
ensure that it is created on the main thread (or at least on a thread
with a Looper), to avoid the following error:
> Can't create handler inside thread that has not called
> Looper.prepare()
Refs 8a02e3c2f58cffc3fdd8c08b26aae04bbf9d5a97
Fixes #6151 <https://github.com/Genymobile/scrcpy/issues/6151 >
2025-06-13 09:37:32 +02:00
Romain Vimont
772f42134a
Use Context.CLIPBOARD_SERVICE directly
...
The constant is defined in Context, not FakeContext.
2025-06-13 09:37:32 +02:00
Romain Vimont
4e1cf13a50
Run a main looper in the cleanup process
...
Since a main looper is explicitly run in the main process, the
initialization of workarounds no longer calls
Looper.prepareMainLooper(), leading to a crash:
java.lang.RuntimeException: Can't create handler inside thread
Thread[main,5,main] that has not called Looper.prepare()
As a result, --power-off-on-close was broken.
Refs 283326b2f6fa3fdaeecc181f69a3a4bcd429c06a
Fixes #6146 <https://github.com/Genymobile/scrcpy/issues/6146 >
2025-06-12 09:10:11 +02:00
Romain Vimont
dc169e425e
Bump version to 3.3
2025-06-11 19:39:48 +02:00
Romain Vimont
8a02e3c2f5
Simplify ClipboardManager wrapper
...
Use the public ClipboardManager API, with the FakeContext as context.
This requires a running main looper, otherwise clipboard changes are not
processed.
Refs #6009 <https://github.com/Genymobile/scrcpy/pull/6009 >
PR #6129 <https://github.com/Genymobile/scrcpy/pull/6129 >
Suggested by: Simon Chan <1330321+yume-chan@users.noreply.github.com>
2025-06-11 17:47:37 +02:00
Romain Vimont
283326b2f6
Run a main looper
...
Instead of blocking the main thread until completion, run a looper.
This will allow the main thread to process any event posted to the main
looper.
Refs #6009 comment <https://github.com/Genymobile/scrcpy/pull/6009#issuecomment-2940810736 >
PR #6129 <https://github.com/Genymobile/scrcpy/pull/6129 >
2025-06-11 17:47:07 +02:00
Simon Chan
ca4f50c5ef
Associate UHID devices to virtual displays
...
This allows the mouse pointer to appear on the correct display (only for
devices running Android 15+).
Fixes #5547 <https://github.com/Genymobile/scrcpy/issues/5547 >
PR #6009 <https://github.com/Genymobile/scrcpy/pull/6009 >
Signed-off-by: Romain Vimont <rom@rom1v.com>
2025-06-05 20:34:11 +02:00
Romain Vimont
7a3fe830d4
Synchronize access to DisplayManager
...
The DisplayManager and its method getDisplayInfo() may be used from both
the Controller thread and the video (main) thread.
PR #6009 <https://github.com/Genymobile/scrcpy/pull/6009 >
2025-06-05 20:34:11 +02:00
Romain Vimont
ee414231ed
Cache getDisplayInfo method
...
Do not use reflection to retrieve the method for every call.
PR #6009 <https://github.com/Genymobile/scrcpy/pull/6009 >
2025-06-05 20:34:11 +02:00
Simon Chan
41ed40f5f9
Simplify InputManager wrapper
...
Use the public InputManager API.
PR #6009 <https://github.com/Genymobile/scrcpy/pull/6009 >
Signed-off-by: Romain Vimont <rom@rom1v.com>
2025-06-05 20:34:11 +02:00
Romain Vimont
52f5d08d1f
Avoid calling wait(0)
...
Calling wait(0) results in waiting without a timeout, which is
unintended.
Refs #6009 comment <https://github.com/Genymobile/scrcpy/pull/6009#issuecomment-2935930294 >
2025-06-03 21:15:11 +02:00
Romain Vimont
8cd63cb63e
Report specific error for INJECT_EVENT permission
...
Some devices require a specific option to be enabled in Developer
Options to avoid a permission issue when injecting input events.
When this error occurs, hide the stack trace and print a human-readable
message explaining how to fix the issue.
PR #6080 <https://github.com/Genymobile/scrcpy/pull/6080 >
2025-05-15 19:52:52 +02:00
Romain Vimont
91a4a74641
Move regex pattern initialization
...
If text == null, then the Pattern is not used.
2025-04-25 10:24:07 +02:00
Romain Vimont
48f38c4bb6
Fix default locked capture orientation
...
The default landscape locked orientation was reversed.
Fixes #6010 <https://github.com/Genymobile/scrcpy/issues/6010 >
2025-04-24 16:12:28 +02:00
Romain Vimont
6875e9aa88
Revert "Fix AudioRecord package name for Android 16"
...
This reverts commit c27d116a662c87ee84963820669ee0d2ce60e6f1.
This commit breaks audio on Android 16 beta 4.
Refs #5960 comment <https://github.com/Genymobile/scrcpy/issues/5960#issuecomment-2816608015 >
Fixes #6021 <https://github.com/Genymobile/scrcpy/issues/6021 >
2025-04-24 16:05:13 +02:00
Romain Vimont
89b624770c
Bump version to 3.2
2025-03-29 15:45:28 +01:00
Romain Vimont
bef2d8473b
Add more audio sources
...
Expose more audio sources from MediaRecorder.AudioSource.
Refs <https://developer.android.com/reference/android/media/MediaRecorder.AudioSource >
Fixes #5412 <https://github.com/Genymobile/scrcpy/issues/5412 >
Fixes #5670 <https://github.com/Genymobile/scrcpy/issues/5670 >
PR #5870 <https://github.com/Genymobile/scrcpy/pull/5870 >
2025-03-29 14:54:35 +01:00
Romain Vimont
609719bde0
Refactor audio sources
...
Store the target audio source integer (one of the constants from
android.media.MediaRecorder.AudioSource) in the AudioSource enum (or -1
if not relevant).
This will simplify adding new audio sources.
PR #5870 <https://github.com/Genymobile/scrcpy/pull/5870 >
2025-03-29 14:54:35 +01:00
Romain Vimont
245981281e
Fix PTS produced by the default opus/flac encoders
...
The default OPUS and FLAC encoders on Android rewrite the input PTS so
that they exactly match the number of samples.
As a consequence:
- audio clock drift is not compensated
- implicit silences (without packets) are ignored
To work around this behavior, generate new PTS based on the current time
(after encoding) and the packet duration.
PR #5870 <https://github.com/Genymobile/scrcpy/pull/5870 >
2025-03-29 14:45:05 +01:00
Romain Vimont
c63d9e1803
Work around broken display listener on Android 15
...
A recent Android 15 upgrade broke the display listener (again). Use the
alternative method for Android >= 14.
Fixes #5908 <https://github.com/Genymobile/scrcpy/issues/5908 >
2025-03-07 18:40:28 +01:00
Romain Vimont
d892a9aac5
Disable checkstyle line length warning
...
Checkstyle reports a warning because the line containing a long URL is
more than 150 characters. But we can't split the URL, so disable the
warning.
2025-02-22 12:22:45 +01:00
chengjian.scj
fd8bef68b7
Add --display-ime-policy option
...
Add an option to select where the IME should be displayed.
Possible values are "local", "fallback" and "hide".
PR #5703 <https://github.com/Genymobile/scrcpy/pull/5703 >
Signed-off-by: Romain Vimont <rom@rom1v.com>
2025-02-22 11:05:22 +01:00
Simon Chan
c27d116a66
Fix AudioRecord package name for Android 16
...
Since commit 9f91a5eebb4520b9333576e946b3911d0f946a04 in frameworks/av
(AOSP), an AudioRecord can be created only if the declared package name
in the AttributionSource is "shell" (for the shell UID):
- <7c4e6991ac/services/audiopolicy/permission/NativePermissionController.cpp (129)
>
- <7c4e6991ac/services/audiopolicy/permission/NativePermissionController.cpp (40)
>
Refs <9f91a5eebb
%5E%21/>
Fixes #5698 <https://github.com/Genymobile/scrcpy/issues/5698 >
Signed-off-by: Romain Vimont <rom@rom1v.com>
2024-12-23 19:41:25 +01:00
Romain Vimont
eac711ace6
Remove unused rotation and fold listeners
...
IRotationWatcher and IDisplayFoldListener are no longer used since
commit 39d51ff2cc2f3e201ad433d48372b548e5dd11d3.
2024-12-23 12:51:27 +01:00
Romain Vimont
e0423653c8
Remove useless null check
...
The method CameraManager.getCameraIdList() is annotated with @NonNull.
This fixes a warning reported by Android Studio.
2024-12-23 10:58:59 +01:00
Romain Vimont
5387644160
Ignore low-FPS ranges if not available
...
Do not report an error if the returned FPS ranges array is null.
Refs #5669 <https://github.com/Genymobile/scrcpy/pull/5669 >
2024-12-22 21:17:51 +01:00
Simon Chan
2f44da76f4
Filter out non-backward-compatible cameras
...
PR #5669 <https://github.com/Genymobile/scrcpy/pull/5669 >
Signed-off-by: Romain Vimont <rom@rom1v.com>
2024-12-22 21:17:05 +01:00
Romain Vimont
dc2fcc46f5
Add workaround for Pico 4 Ultra
...
Make ActivityThread.isSystem() return true to avoid a
NullPointerException later.
Refs #5659 comment <https://github.com/Genymobile/scrcpy/issues/5659#issuecomment-2540963953 >
Fixes #5659 <https://github.com/Genymobile/scrcpy/issues/5659 >
2024-12-14 10:27:38 +01:00
Romain Vimont
69264703b1
Add missing comments in workarounds
...
The implementation of workarounds uses a lot of reflection code. For
better readability, always write the equivalent using direct Java code.
2024-12-14 10:27:38 +01:00
Colin Kinloch
ec4e826976
Set icon and server env paths for meson devenv
...
This allows users to compile and run the project in a dev environment.
meson setup x
meson compile -C x
meson devenv -C x
scrcpy
This is an alternative to `./run x`.
PR #5658 <https://github.com/Genymobile/scrcpy/pull/5658 >
Signed-off-by: Romain Vimont <rom@rom1v.com>
2024-12-12 18:15:26 +01:00
Romain Vimont
754f4fc6fe
Bump version to 3.1
2024-12-09 22:29:51 +01:00
Simon Chan
a507b4f559
Fix DisplayControl classpath
...
Use the full system server classpath to load DisplayControl, so that
turning the screen off on Android 14+ does not crash on certain devices.
Refs #4544 comment <https://github.com/Genymobile/scrcpy/issues/4544#issuecomment-2526999714 >
Fixes #4544 <https://github.com/Genymobile/scrcpy/issues/4544 >
Fixes #5274 <https://github.com/Genymobile/scrcpy/issues/5274 >
Signed-off-by: Romain Vimont <rom@rom1v.com>
2024-12-09 10:29:20 +01:00
Romain Vimont
a9aadc95df
Start cleanup process with setsid()
...
Reimplement c59a3c3169973abb4ce236e06990d58ae6567481 using Os.setsid().
Refs #5613 comment <https://github.com/Genymobile/scrcpy/pull/5613#issuecomment-2527045669 >
Suggested-by: Simon Chan <1330321+yume-chan@users.noreply.github.com>
2024-12-09 09:33:08 +01:00
Romain Vimont
28b5bfb90e
Revert "Start cleanup process with setsid or nohup"
...
This reverts commit c59a3c3169973abb4ce236e06990d58ae6567481.
The next commit will use Os.setsid() instead.
2024-12-09 09:29:29 +01:00
Withoutruless
7418fd0662
Use Xbox 360 gamepad name
...
Some games do not work without a known gamepad name.
Fixes #5362 <https://github.com/Genymobile/scrcpy/issues/5362 >
Refs #5623 comment <https://github.com/Genymobile/scrcpy/pull/5623#issuecomment-2525685323 >
PR #5623 <https://github.com/Genymobile/scrcpy/pull/5623 >
Signed-off-by: Romain Vimont <rom@rom1v.com>
2024-12-08 17:01:03 +01:00
Romain Vimont
27a5934a1d
Define UHID vendorId and productId from the client
...
Let the client choose the USB ids, that it transmits in UHID_CREATE
requests.
PR #5623 <https://github.com/Genymobile/scrcpy/pull/5623 >
2024-12-08 11:00:18 +01:00
Romain Vimont
c59a3c3169
Start cleanup process with setsid or nohup
...
If available, start the cleanup process in a new session to reduce the
likelihood of it being terminated along with the scrcpy server process
on some devices.
The binaries setsid and nohup are often available, but it is not
guaranteed.
Refs #5601 <https://github.com/Genymobile/scrcpy/issues/5601 >
PR #5613 <https://github.com/Genymobile/scrcpy/pull/5613 >
2024-12-08 10:58:22 +01:00
Romain Vimont
2780e0bd7b
Do not interrupt cleanup configuration
...
Some options, such as --show-touches or --stay-awake, modify Android
settings and must be restored upon exit.
If scrcpy terminates (e.g. due to an early error) in the middle of the
clean up configuration, the device may be left in an inconsistent state
(some settings might be changed but not restored).
This issue can be reproduced with high probability by forcing scrcpy to
fail:
scrcpy --show-touches --video-encoder=fail
To prevent this problem, ensure that the clean up thread is not
interrupted until the clean up process is started.
Refs #5601 <https://github.com/Genymobile/scrcpy/issues/5601 >
PR #5613 <https://github.com/Genymobile/scrcpy/pull/5613 >
2024-12-08 10:58:07 +01:00
Romain Vimont
6c6607d404
Add --no-vd-destroy-content
...
Add an option to disable the following flag for virtual displays:
DisplayManager.VIRTUAL_DISPLAY_FLAG_DESTROY_CONTENT_ON_REMOVAL
With this option, when the virtual display is closed, the running apps
are moved to the main display rather than being destroyed.
PR #5615 <https://github.com/Genymobile/scrcpy/pull/5615 >
2024-12-08 09:33:03 +01:00
Romain Vimont
f90dc216d1
Refactor virtual display properties initialization
...
Following the changes from the previous commit, the behavior is now
identical when mirroring the main display or using the SurfaceControl
API.
Factorize the code to perform the initialization in a single location.
Refs #5605 <https://github.com/Genymobile/scrcpy/issues/5605 >
PR #5614 <https://github.com/Genymobile/scrcpy/pull/5614 >
2024-12-07 20:09:14 +01:00
Romain Vimont
97fa77c76c
Inject main display events to the original display
...
When mirroring a secondary display, touch and scroll events must be sent
to the mirroring virtual display id (with coordinates relative to the
virtual display size), rather than to the original display (with
coordinates relative to the original display size).
This behavior, introduced by d19396718ee0c0ba7fb578f595a6553c0458da59,
was also applied for the main display for consistency. However, it
causes some UI elements to become unclickable.
To minimize inconveniences, restore the previous behavior when mirroring
the main display: send all events to the original display id (0) with
coordinates relative to the original display size.
Fixes #5545 <https://github.com/Genymobile/scrcpy/issues/5545 >
Fixes #5605 <https://github.com/Genymobile/scrcpy/issues/5605 >
Fixes #5616 <https://github.com/Genymobile/scrcpy/issues/5616 >
Refs #4598 <https://github.com/Genymobile/scrcpy/issues/4598 >
Refs #5137 <https://github.com/Genymobile/scrcpy/issues/5137 >
Refs #5370 <https://github.com/Genymobile/scrcpy/pull/5370 >
PR #5614 <https://github.com/Genymobile/scrcpy/pull/5614 >
2024-12-07 20:08:49 +01:00
Romain Vimont
2ed2247e8f
Bump version to 3.0.2
...
The version was not bumped for 3.0.1.
2024-12-04 22:35:25 +01:00
Romain Vimont
5c3626ed47
Handle broken pipe errors specifically
...
Since 9555d3a537a828731ad89ef5258ba537acf8cc11, a capture/encoding error
was sometimes logged on exit.
2024-12-04 18:38:23 +01:00
Romain Vimont
9555d3a537
Retry capture on IOException
...
If the capture fails with an IOException, retry with a lower resolution.
Fixes #5539 <https://github.com/Genymobile/scrcpy/issues/5539 >
2024-12-03 23:06:33 +01:00
Romain Vimont
3b2b3625e4
Accept positional control events without display
...
The position of touch and scroll must normally be "resolved" with a
"position mapper" associated to the display.
But to support the injection of such events with scrcpy-server alone
without video, handle the case where there is no display.
Fixes #5542 <https://github.com/Genymobile/scrcpy/issues/5542 >
2024-12-01 17:22:47 +01:00
Romain Vimont
b2cdaa4bdc
Factorize position mapper resolution
...
The code was duplicated for touch and scroll events. Extract it to a
private function.
Refs #5542 <https://github.com/Genymobile/scrcpy/issues/5542 >
2024-12-01 17:22:47 +01:00
Romain Vimont
3e689020ba
Fix null return value in DisplayManager.toString()
...
Ensure DisplayListener.toString() returns a non-null value to prevent a
NullPointerException on certain devices.
Fixes #5537 <https://github.com/Genymobile/scrcpy/issues/5537 >
2024-11-27 07:45:35 +01:00
Romain Vimont
3d1f036c04
Rollback to old --turn-screen-off for Android 15
...
When the screen is turned off with the new display power method
introduced in Android 15, video mirroring freezes.
Use the Android 14 method for Android 15.
Refs 58ba00fa060c9a1f439120f8869ed106e1c935f9
Refs #5418 <https://github.com/Genymobile/scrcpy/pull/5418 >
Fixes #5530 <https://github.com/Genymobile/scrcpy/issues/5530 >
2024-11-26 15:55:16 +01:00
Romain Vimont
3d5294c1e5
Set main display power for virtual display
...
Change the display power of the main display when mirroring a virtual
display, to make it possible to turn off the screen.
Fixes #5522 <https://github.com/Genymobile/scrcpy/issues/5522 >
Refs #5530 <https://github.com/Genymobile/scrcpy/issues/5530 >
2024-11-26 15:43:41 +01:00