Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read/write settings via command on Android >= 12 #2802

Merged
merged 7 commits into from
Nov 18, 2021
Merged

Read/write settings via command on Android >= 12 #2802

merged 7 commits into from
Nov 18, 2021

Conversation

rom1v
Copy link
Collaborator

@rom1v rom1v commented Nov 17, 2021

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
Fixes #2788


Replace these binaries in your v1.20 release:

  • scrcpy.exe sha256:df6ecfdf3f423fb6303f696934f569e8c03dbfeb69be9d06abeaf85093c63b78
  • scrcpy-server sha256:d6c14fdb94c0a3509da5c850271cb0cdfd7df5c072f605e6c09f0353a590c6c8

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.

PR #2802 <#2802>
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.

PR #2802 <#2802>
When an exception occurs, we might want to log a warning instead of an
error.

PR #2802 <#2802>
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 <#2671>
Fixes #2788 <#2788>
PR #2802 <#2802>
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.

PR #2802 <#2802>
Accessing the settings (like --show-touches) on start should not delay
screen mirroring.

PR #2802 <#2802>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant