Commit graph

550 commits

Author SHA1 Message Date
Romain Vimont
8a121cdf59 Add shortcut to open keyboard settings
The keyboard settings can be opened by:

    adb shell am start -a android.settings.HARD_KEYBOARD_SETTINGS

Add a shortcut (MOD+k) for convenience if the current keyboard is HID.
2024-03-01 00:12:10 +01:00
Romain Vimont
58fba407b3 Fix startActivity() for supporting API < 30
Call the older startActivityAsUser() instead of
startActivityAsUserWithFeature() so that it also works on older Android
versions.

Fixes #4704 <https://github.com/Genymobile/scrcpy/issues/4704>
2024-03-01 00:12:10 +01:00
Romain Vimont
9be51bc129 Create UhidManager only on first use
There is no need to create a UhidManager instance (with its thread) if
no UHID is used.
2024-03-01 00:12:10 +01:00
Simon Chan
7d8cfa5be0 Handle UHID output
Use UHID output reports to synchronize CapsLock and VerrNum states.

Co-authored-by: Romain Vimont <rom@rom1v.com>
Signed-off-by: Romain Vimont <rom@rom1v.com>
2024-03-01 00:12:10 +01:00
Romain Vimont
c713868005 Refactor DeviceMessageSender
Refactor DeviceMessage as a queue of message. This will allow to add
other message types.
2024-03-01 00:12:10 +01:00
Simon Chan
0b9fa9d760 Add UHID keyboard support
Use the following command:

    scrcpy --keyboard=uhid

Co-authored-by: Romain Vimont <rom@rom1v.com>
Signed-off-by: Romain Vimont <rom@rom1v.com>
2024-03-01 00:12:10 +01:00
Romain Vimont
185d6263cf Log controller handling errors
On close, the controller is expected to throw an IOException because the
socket is closed, so the exception was ignored.

However, message handling actions may also throw IOException, and they
must not be silently ignored.
2024-03-01 00:12:10 +01:00
eiyooooo
d894e270a7 Add rotation support for non-default display
Use new methods introduced by this commit:
<90c9005e68%5E%21/>

PR #4698 <https://github.com/Genymobile/scrcpy/pull/4698>

Signed-off-by: Romain Vimont <rom@rom1v.com>
2024-02-26 20:26:56 +01:00
Romain Vimont
746eaea556 Add missing clipboard workaround for IQOO device
The first part of the workaround fixed getPrimaryClip(). This part fixes
setPrimaryClip().

Fixes #4703 <https://github.com/Genymobile/scrcpy/issues/4703>
Refs 5ce8672ebc
Refs #4492 <https://github.com/Genymobile/scrcpy/issues/4492>
2024-02-26 08:36:18 +01:00
Romain Vimont
25f1e703b7 Extract ControlChannel class
This prevents many components from depending on the whole
DesktopConnection.
2024-02-23 20:07:16 +01:00
Romain Vimont
9efa162949 Configure clean up actions dynamically
Some actions may be performed when scrcpy exits, currently:
 - disable "show touches"
 - restore "stay on while plugged in"
 - power off screen
 - restore "power mode" (to disable "turn screen off")

They are performed from a separate process so that they can be executed
even when scrcpy-server is killed (e.g. if the device is unplugged).

The clean up actions to perform were configured when scrcpy started.
Given that there is no method to read the current "power mode" in
Android, and that "turn screen off" can be applied at any time using an
scrcpy shortcut, there was no way to determine if "power mode" had to be
restored on exit. Therefore, it was always restored to "normal", even
when not necessary.

However, setting the "power mode" is quite fragile on some devices, and
may cause some issues, so it is preferable to call it only when
necessary (when "turn screen off" has actually been called).

For that purpose, make the scrcpy-server main process and the clean up
process communicate the actions to perform over a pipe (stdin/stdout),
so that they can be changed dynamically. In particular, when the power
mode is changed at runtime, notify the clean up process.

Refs 1beec99f82
Refs #4456 <https://github.com/Genymobile/scrcpy/issues/4456>
Refs #4624 <https://github.com/Genymobile/scrcpy/issues/4624>
PR #4649 <https://github.com/Genymobile/scrcpy/pull/4649>
2024-02-17 15:49:08 +01:00
wuderek
be3f949aa5 Adapt to display API changes
The method SurfaceControl.createDisplay() has been removed in AOSP.

Use DisplayManager to create a VirtualDisplay object instead.

Fixes #4646 <https://github.com/Genymobile/scrcpy/issues/4646>
Fixes #4656 <https://github.com/Genymobile/scrcpy/issues/4656>
PR #4657 <https://github.com/Genymobile/scrcpy/pull/4657>

Signed-off-by: Romain Vimont <rom@rom1v.com>
2024-02-10 10:01:22 +01:00
Romain Vimont
f7b4a18b43 Catch generic ReflectiveOperationException
This exception is a super-type of:
 - ClassNotFoundException
 - IllegalAccessException
 - InstantiationException
 - InvocationTargetException
 - NoSuchFieldException
 - NoSuchMethodException

Use it to simplify.
2024-02-10 10:00:28 +01:00
Romain Vimont
05b5deacad Move service managers creation
Create the service managers from each manager wrapper class rather than
from their getter in ServiceManager.

The way a wrapper retrieve the underlying service is an implementation
detail, and it must be consistent with the way it accesses it, so it is
better to write the creation in the wrapper.
2024-02-10 10:00:26 +01:00
Romain Vimont
d25cbc55f2 Remove unused field 2024-02-09 18:32:48 +01:00
Romain Vimont
5187f7254e Add another clipboard workaround for IQOO device
Fixes #4589 <https://github.com/Genymobile/scrcpy/issues/4589>
Refs 5ce8672ebc
Refs #4492 <https://github.com/Genymobile/scrcpy/issues/4492>
2024-01-17 10:15:00 +01:00
Romain Vimont
6a58891e13 Use current time as initial timestamp on error
If the initial timestamp could not be retrieved, use the current time as
returned by System.nanoTime(). In practice, it is the same time base as
AudioRecord timestamps.

Fixes #4536 <https://github.com/Genymobile/scrcpy/issues/4536>
2023-12-16 20:17:33 +01:00
Romain Vimont
ec41896c85 Fix integer overflow for audio packet duration
The result is assigned to a long (64-bit signed integer), but the
intermediate multiplication was stored in an int (32-bit signed
integer).

This value is only used as a fallback when no timestamp could be
retrieved, that's why it did not cause too much harm so far.

Fixes #4536 <https://github.com/Genymobile/scrcpy/issues/4536>
2023-12-16 20:16:31 +01:00
Romain Vimont
4cd61b5a90 Fix checkstyle violation
Reported by checkstyle:

> [ant:checkstyle] [INFO]
> scrcpy/server/src/main/java/com/genymobile/scrcpy/wrappers/ClipboardManager.java:48:
> Line is longer than 150 characters (found 167). [LineLength]
2023-12-16 20:12:58 +01:00
Romain Vimont
c9a4d2b38f Use up-to-date values on display fold change
When a display is folded or unfolded, the maxSize may have been updated
since the option was passed, and deviceSize must be updated.

Refs #4469 <https://github.com/Genymobile/scrcpy/pull/4469>
2023-12-04 08:50:12 +01:00
Romain Vimont
1beec99f82 Explicitly exit cleanup process
This avoids an internal crash reported in `adb logcat`.

Refs #4456 <https://github.com/Genymobile/scrcpy/pull/4456#issuecomment-1837427802>
2023-12-04 08:45:35 +01:00
Romain Vimont
5ce8672ebc Add clipboard workaround for IQOO device
Fixes #4492 <https://github.com/Genymobile/scrcpy/issues/4492>
2023-12-04 08:43:31 +01:00
Romain Vimont
3001f8a2d5 Adapt AudioRecord workaround to Android 14
Android 14 added a new int parameter "halInputFlags" to an internal
method:
<f6135d75db>

Fixes #4492 <https://github.com/Genymobile/scrcpy/issues/4492>
2023-12-03 18:01:11 +01:00
Romain Vimont
40f2560d98 Bump version to 2.3.1 2023-12-02 12:30:19 +01:00
Romain Vimont
140a49b8be Add workaround for Samsung devices issues
On some Samsung devices, DisplayManagerGlobal.getDisplayInfoLocked()
calls ActivityThread.currentActivityThread().getConfiguration(), which
requires a non-null ConfigurationController.

Fixes <https://github.com/Genymobile/scrcpy/issues/4467>
2023-11-27 09:29:06 +01:00
Romain Vimont
5f3fb843f5 Bump version to 2.3
The previous version bump to 2.2 was incorrect, it was updated by:

    ./bump_version v2.2

instead of:

    ./bump_version 2.2

Correctly bump to version 2.3.

Refs #4433 <https://github.com/Genymobile/scrcpy/issues/4433#issuecomment-1816830875>
2023-11-25 21:40:27 +01:00
Romain Vimont
5d4b8a7e6d Fix turn screen off on Android 14
On Android 14, the methods to access the display have been moved to
DisplayControl, which is not in the core framework. Use a specific
ClassLoader to access this class and its native dependencies.

Fixes #3927 <https://github.com/Genymobile/scrcpy/issues/3927>
Refs #3927 comment <https://github.com/Genymobile/scrcpy/issues/3927#issuecomment-1790031953>
Refs #4446 comment <https://github.com/Genymobile/scrcpy/pull/4446#issuecomment-1824660915>
PR #4456 <https://github.com/Genymobile/scrcpy/pull/4456>

Co-authored-by: Simon Chan <1330321+yume-chan@users.noreply.github.com>
Signed-off-by: Romain Vimont <rom@rom1v.com>
2023-11-25 21:25:26 +01:00
Romain Vimont
c573bd2a33 Fix java code style 2023-11-23 23:50:00 +01:00
sam80180
acb2988837 Do not hardcode server path on the device
The path can be retrieved from the classpath.

PR #4416 <https://github.com/Genymobile/scrcpy/pull/4416>

Co-authored-by: Romain Vimont <rom@rom1v.com>
Signed-off-by: Romain Vimont <rom@rom1v.com>
2023-11-23 23:39:40 +01:00
Romain Vimont
45a073a333 Do not create Device instance for camera
The device instance manages the display and the injection of input
events. It is not necessary for camera capture.
2023-11-16 09:10:28 +01:00
Romain Vimont
7e3b935932 Recreate the display on rotation
On Android 14 (Pixel 8), a device rotation while the camera app was
running resulted in an incorrect capture.

Destroying and recreating the display fixes the issue.
2023-11-16 08:56:04 +01:00
Romain Vimont
abcb100597 Upgrade Android SDK to 34 2023-11-15 21:13:12 +01:00
Romain Vimont
e8801cc3c0 Upgrade AGP (8.1.3) and Gradle to 8.4
Android Gradle Plugin 8.1.3.
Gradle 8.4.

From now on, Java 17 is required.
2023-11-15 21:13:12 +01:00
Romain Vimont
86808e8114 Upgrade Android checkstyle to 10.12.5
Upgrade to the latest version.
2023-11-15 21:13:12 +01:00
Romain Vimont
4b4f045e19 Fix audio PTS by the duration of 1 sample
If the difference of PTS between two consecutive blocks of audio is less
than 1 sample, then it will be considered as non-increasing by FFmpeg
muxers having a time_base of 1/sample_rate.

Increase the PTS by 1 sample instead.
2023-11-15 12:02:57 +01:00
Romain Vimont
a402eac7f2 Compute PTS of intermediate blocks
If several reads are performed for a single captured audio block (e.g.
if the read size is smaller than the captured block), then the provided
timestamp was the same for all packets.

Recompute the timestamp for each of them.
2023-11-15 12:02:57 +01:00
Romain Vimont
3bb6b0cb9f Read audio by blocks of 1024 samples
In practice, the system captures audio samples by blocks of 1024
samples.

Remplace the hardcoded value of 5 milliseconds (240 samples), and let
AudioRecord fill the input buffer provided by MediaCodec (or by
AudioRawRecorder), with a maximum size of 1024 samples (just in case).
2023-11-15 12:02:57 +01:00
megapro17
4857c5dd59 Add support for FLAC audio codec
PR #4410 <#https://github.com/Genymobile/scrcpy/pull/4410>

Co-authored-by: Romain Vimont <rom@rom1v.com>
Signed-off-by: Romain Vimont <rom@rom1v.com>
2023-11-15 12:02:57 +01:00
Romain Vimont
783719c72e Fix OPUS packet in an endian-independent way
Reading the header id as an int assumed that the current endianness was
little endian. Read to a byte array to remove this assumption.
2023-11-15 12:02:57 +01:00
Romain Vimont
80defdd8aa Suppress private APIs lints to Workarounds class
The whole class need them (including the static block).
2023-11-15 12:01:10 +01:00
Romain Vimont
4eb33054cd Do not log EPIPE on close for raw audio
Handle EPIPE the same way in AudioRawRecorder as in AudioEncoder.

This prevents useless errors on close.
2023-11-11 11:24:47 +01:00
Romain Vimont
420d3a40dd Fix error handling in raw audio recorder
It is incorret to ever call:

    streamer.writeDisableStream(...);

after:

    streamer.writeAudioHeader();

Move the try-catch block so that it can never happen.
2023-11-11 11:24:47 +01:00
Romain Vimont
9d5f53caa7 Stop capture on any RAW audio error
The server was stopped only if an IOException occurred during RAW audio
capture, but it did not catch RuntimeExceptions.
2023-11-11 11:24:47 +01:00
Romain Vimont
11d738321f Recover on invalid camera FPS ranges
Some devices may provide invalid ranges, causing an
IllegalArgumentException "lower must be less than or equal to upper".

Catch the exception to list the cameras anyway.

Refs #4403 <https://github.com/Genymobile/scrcpy/issues/4403>
2023-11-05 21:45:15 +01:00
Romain Vimont
ccaa832f48 Simplify --list-cameras output
Remove --video-source=camera from the output of --list-cameras (this is
implicit).
2023-11-05 21:44:33 +01:00
Romain Vimont
4e4ddc499f Return the FakeContext as application context
This avoids getApplicationContext() to return null and cause
NullPointerException.

Fixes #4392 <https://github.com/Genymobile/scrcpy/issues/4392#issuecomment-1792806080>
2023-11-03 19:07:15 +01:00
Romain Vimont
8d76b3e06d Fill application context for camera
Using the camera fails on some devices without a proper application
context.

Fixes #4392 <https://github.com/Genymobile/scrcpy/issues/4392>
2023-11-03 19:07:08 +01:00
Romain Vimont
85a0b935c9 Always assign a system context as base context
FakeContext used ActivityThread.getSystemContext() as base context only
in some cases, because it caused problems on some devices:
 - warnings on Xiaomi devices [1], which are now fixed by
   b8c5853aa6
 - issues related to Looper [2], which are solved by just calling
   Looper.prepare*()

Therefore, we can now always assign a base context, which simplifies and
helps to solve camera issues on some devices (#4392).

[1] <https://github.com/Genymobile/scrcpy/issues/4015#issuecomment-1595382142>
[2] <https://github.com/Genymobile/scrcpy/issues/3805#issuecomment-1596148031>

Fixes #4392 <https://github.com/Genymobile/scrcpy/issues/4392>
2023-11-03 19:05:50 +01:00
Romain Vimont
8c3e2bae7b Simplify Application instantiation
The constructor is public.
2023-11-03 19:05:28 +01:00
Romain Vimont
c3c7bf7af3 Bump version to v2.2 2023-11-01 18:36:33 +01:00