-
-
Notifications
You must be signed in to change notification settings - Fork 11k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <#2671> Fixes #2788 <#2788>
- Loading branch information
Showing
2 changed files
with
87 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.genymobile.scrcpy; | ||
|
||
import java.io.IOException; | ||
import java.util.Arrays; | ||
import java.util.Scanner; | ||
|
||
public final class Command { | ||
private Command() { | ||
// not instantiable | ||
} | ||
|
||
public static void exec(String... cmd) throws IOException, InterruptedException { | ||
Process process = Runtime.getRuntime().exec(cmd); | ||
int exitCode = process.waitFor(); | ||
if (exitCode != 0) { | ||
throw new IOException("Command " + Arrays.toString(cmd) + " returned with value " + exitCode); | ||
} | ||
} | ||
|
||
public static String execReadLine(String... cmd) throws IOException, InterruptedException { | ||
String result = null; | ||
Process process = Runtime.getRuntime().exec(cmd); | ||
Scanner scanner = new Scanner(process.getInputStream()); | ||
if (scanner.hasNextLine()) { | ||
result = scanner.nextLine(); | ||
} | ||
int exitCode = process.waitFor(); | ||
if (exitCode != 0) { | ||
throw new IOException("Command " + Arrays.toString(cmd) + " returned with value " + exitCode); | ||
} | ||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters