Handle "show touches" on the device-side
Now that the server can access the Android settings and clean up properly, handle the "show touches" option from the server. The initial state is now correctly restored, even on device disconnection.
This commit is contained in:
@@ -19,19 +19,18 @@ public final class CleanUp {
|
||||
// not instantiable
|
||||
}
|
||||
|
||||
public static void configure() throws IOException {
|
||||
// TODO
|
||||
boolean needProcess = false;
|
||||
public static void configure(boolean disableShowTouches) throws IOException {
|
||||
boolean needProcess = disableShowTouches;
|
||||
if (needProcess) {
|
||||
startProcess();
|
||||
startProcess(disableShowTouches);
|
||||
} else {
|
||||
// There is no additional clean up to do when scrcpy dies
|
||||
unlinkSelf();
|
||||
}
|
||||
}
|
||||
|
||||
private static void startProcess() throws IOException {
|
||||
String[] cmd = {"app_process", "/", CleanUp.class.getName()};
|
||||
private static void startProcess(boolean disableShowTouches) throws IOException {
|
||||
String[] cmd = {"app_process", "/", CleanUp.class.getName(), String.valueOf(disableShowTouches)};
|
||||
|
||||
ProcessBuilder builder = new ProcessBuilder(cmd);
|
||||
builder.environment().put("CLASSPATH", SERVER_PATH);
|
||||
@@ -57,6 +56,15 @@ public final class CleanUp {
|
||||
}
|
||||
|
||||
Ln.i("Cleaning up");
|
||||
// TODO
|
||||
|
||||
boolean disableShowTouches = Boolean.parseBoolean(args[0]);
|
||||
|
||||
if (disableShowTouches) {
|
||||
ServiceManager serviceManager = new ServiceManager();
|
||||
try (ContentProvider settings = serviceManager.getActivityManager().createSettingsProvider()) {
|
||||
Ln.i("Disabling \"show touches\"");
|
||||
settings.putValue(ContentProvider.TABLE_SYSTEM, "show_touches", "0");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ public class Options {
|
||||
private boolean sendFrameMeta; // send PTS so that the client may record properly
|
||||
private boolean control;
|
||||
private int displayId;
|
||||
private boolean showTouches;
|
||||
|
||||
public int getMaxSize() {
|
||||
return maxSize;
|
||||
@@ -84,4 +85,12 @@ public class Options {
|
||||
public void setDisplayId(int displayId) {
|
||||
this.displayId = displayId;
|
||||
}
|
||||
|
||||
public boolean getShowTouches() {
|
||||
return showTouches;
|
||||
}
|
||||
|
||||
public void setShowTouches(boolean showTouches) {
|
||||
this.showTouches = showTouches;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.genymobile.scrcpy;
|
||||
|
||||
import com.genymobile.scrcpy.wrappers.ContentProvider;
|
||||
|
||||
import android.graphics.Rect;
|
||||
import android.media.MediaCodec;
|
||||
import android.os.Build;
|
||||
@@ -17,7 +19,16 @@ public final class Server {
|
||||
Ln.i("Device: " + Build.MANUFACTURER + " " + Build.MODEL + " (Android " + Build.VERSION.RELEASE + ")");
|
||||
final Device device = new Device(options);
|
||||
|
||||
CleanUp.configure();
|
||||
boolean mustDisableShowTouchesOnCleanUp = false;
|
||||
if (options.getShowTouches()) {
|
||||
try (ContentProvider settings = device.createSettingsProvider()) {
|
||||
String oldValue = settings.getAndPutValue(ContentProvider.TABLE_SYSTEM, "show_touches", "1");
|
||||
// If "show touches" was disabled, it must be disabled back on clean up
|
||||
mustDisableShowTouchesOnCleanUp = !"1".equals(oldValue);
|
||||
}
|
||||
}
|
||||
|
||||
CleanUp.configure(mustDisableShowTouchesOnCleanUp);
|
||||
|
||||
boolean tunnelForward = options.isTunnelForward();
|
||||
try (DesktopConnection connection = DesktopConnection.open(device, tunnelForward)) {
|
||||
@@ -80,8 +91,9 @@ public final class Server {
|
||||
"The server version (" + BuildConfig.VERSION_NAME + ") does not match the client " + "(" + clientVersion + ")");
|
||||
}
|
||||
|
||||
if (args.length != 10) {
|
||||
throw new IllegalArgumentException("Expecting 10 parameters");
|
||||
final int expectedParameters = 11;
|
||||
if (args.length != expectedParameters) {
|
||||
throw new IllegalArgumentException("Expecting " + expectedParameters + " parameters");
|
||||
}
|
||||
|
||||
Options options = new Options();
|
||||
@@ -114,6 +126,9 @@ public final class Server {
|
||||
int displayId = Integer.parseInt(args[9]);
|
||||
options.setDisplayId(displayId);
|
||||
|
||||
boolean showTouches = Boolean.parseBoolean(args[10]);
|
||||
options.setShowTouches(showTouches);
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user