Compare commits
10 Commits
orientatio
...
turnscreen
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
67fa766f09 | ||
|
|
890ba529c3 | ||
|
|
798727aa58 | ||
|
|
e76ff25e31 | ||
|
|
ec80be1eda | ||
|
|
cdd78273dc | ||
|
|
c546293f35 | ||
|
|
70baf3c384 | ||
|
|
dac0d54c5c | ||
|
|
878bfb1d8b |
@@ -2138,7 +2138,7 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],
|
|||||||
opts->display_orientation = SC_ORIENTATION_180;
|
opts->display_orientation = SC_ORIENTATION_180;
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
// rotation 3 was 270° counterclockwise, but orientation
|
// rotation 1 was 270° counterclockwise, but orientation
|
||||||
// is expressed clockwise
|
// is expressed clockwise
|
||||||
opts->display_orientation = SC_ORIENTATION_90;
|
opts->display_orientation = SC_ORIENTATION_90;
|
||||||
break;
|
break;
|
||||||
@@ -2531,8 +2531,7 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],
|
|||||||
if (opts->record_orientation != SC_ORIENTATION_0) {
|
if (opts->record_orientation != SC_ORIENTATION_0) {
|
||||||
if (sc_orientation_is_mirror(opts->record_orientation)) {
|
if (sc_orientation_is_mirror(opts->record_orientation)) {
|
||||||
LOGE("Record orientation only supports rotation, not "
|
LOGE("Record orientation only supports rotation, not "
|
||||||
"flipping: %s",
|
"flipping: %s", optarg);
|
||||||
sc_orientation_get_name(opts->record_orientation));
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -113,10 +113,10 @@ sc_orientation_apply(enum sc_orientation src, enum sc_orientation transform) {
|
|||||||
// In the final result, we want all the hflips then all the rotations,
|
// In the final result, we want all the hflips then all the rotations,
|
||||||
// so we must move hflip2 to the left:
|
// so we must move hflip2 to the left:
|
||||||
//
|
//
|
||||||
// hflip1 × hflip2 × rotate1' × rotate2
|
// hflip1 × hflip2 × f(rotate1) × rotate2
|
||||||
//
|
//
|
||||||
// with rotate1' = | rotate1 if src is 0° or 180°
|
// with f(rotate1) = | rotate1 if src is 0 or 180
|
||||||
// | rotate1 + 180° if src is 90° or 270°
|
// | rotate1 + 180 if src is 90 or 270
|
||||||
|
|
||||||
src_rotation += 2;
|
src_rotation += 2;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,6 @@
|
|||||||
#define SC_SERVER_FILENAME "scrcpy-server"
|
#define SC_SERVER_FILENAME "scrcpy-server"
|
||||||
|
|
||||||
#define SC_SERVER_PATH_DEFAULT PREFIX "/share/scrcpy/" SC_SERVER_FILENAME
|
#define SC_SERVER_PATH_DEFAULT PREFIX "/share/scrcpy/" SC_SERVER_FILENAME
|
||||||
#define SC_DEVICE_SERVER_PATH "/data/local/tmp/scrcpy-server.jar"
|
|
||||||
|
|
||||||
#define SC_ADB_PORT_DEFAULT 5555
|
#define SC_ADB_PORT_DEFAULT 5555
|
||||||
#define SC_SOCKET_NAME_PREFIX "scrcpy_"
|
#define SC_SOCKET_NAME_PREFIX "scrcpy_"
|
||||||
@@ -117,7 +116,7 @@ error:
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
push_server(struct sc_intr *intr, const char *serial) {
|
push_server(struct sc_intr *intr, uint32_t scid, const char *serial) {
|
||||||
char *server_path = get_server_path();
|
char *server_path = get_server_path();
|
||||||
if (!server_path) {
|
if (!server_path) {
|
||||||
return false;
|
return false;
|
||||||
@@ -127,7 +126,16 @@ push_server(struct sc_intr *intr, const char *serial) {
|
|||||||
free(server_path);
|
free(server_path);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
bool ok = sc_adb_push(intr, serial, server_path, SC_DEVICE_SERVER_PATH, 0);
|
|
||||||
|
char *device_server_path;
|
||||||
|
if (asprintf(&device_server_path, "/data/local/tmp/scrcpy-server-%08x.jar",
|
||||||
|
scid) == -1) {
|
||||||
|
LOG_OOM();
|
||||||
|
free(server_path);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
bool ok = sc_adb_push(intr, serial, server_path, device_server_path, 0);
|
||||||
|
free(device_server_path);
|
||||||
free(server_path);
|
free(server_path);
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
@@ -209,13 +217,20 @@ execute_server(struct sc_server *server,
|
|||||||
const char *serial = server->serial;
|
const char *serial = server->serial;
|
||||||
assert(serial);
|
assert(serial);
|
||||||
|
|
||||||
|
char *classpath;
|
||||||
|
if (asprintf(&classpath, "CLASSPATH=/data/local/tmp/scrcpy-server-%08x.jar",
|
||||||
|
params->scid) == -1) {
|
||||||
|
LOG_OOM();
|
||||||
|
return SC_PROCESS_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
const char *cmd[128];
|
const char *cmd[128];
|
||||||
unsigned count = 0;
|
unsigned count = 0;
|
||||||
cmd[count++] = sc_adb_get_executable();
|
cmd[count++] = sc_adb_get_executable();
|
||||||
cmd[count++] = "-s";
|
cmd[count++] = "-s";
|
||||||
cmd[count++] = serial;
|
cmd[count++] = serial;
|
||||||
cmd[count++] = "shell";
|
cmd[count++] = "shell";
|
||||||
cmd[count++] = "CLASSPATH=" SC_DEVICE_SERVER_PATH;
|
cmd[count++] = classpath;
|
||||||
cmd[count++] = "app_process";
|
cmd[count++] = "app_process";
|
||||||
|
|
||||||
#ifdef SERVER_DEBUGGER
|
#ifdef SERVER_DEBUGGER
|
||||||
@@ -388,6 +403,7 @@ end:
|
|||||||
for (unsigned i = dyn_idx; i < count; ++i) {
|
for (unsigned i = dyn_idx; i < count; ++i) {
|
||||||
free((char *) cmd[i]);
|
free((char *) cmd[i]);
|
||||||
}
|
}
|
||||||
|
free(classpath);
|
||||||
|
|
||||||
return pid;
|
return pid;
|
||||||
}
|
}
|
||||||
@@ -937,7 +953,7 @@ run_server(void *data) {
|
|||||||
assert(serial);
|
assert(serial);
|
||||||
LOGD("Device serial: %s", serial);
|
LOGD("Device serial: %s", serial);
|
||||||
|
|
||||||
ok = push_server(&server->intr, serial);
|
ok = push_server(&server->intr, params->scid, serial);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
goto error_connection_failed;
|
goto error_connection_failed;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ c = 'i686-w64-mingw32-gcc'
|
|||||||
cpp = 'i686-w64-mingw32-g++'
|
cpp = 'i686-w64-mingw32-g++'
|
||||||
ar = 'i686-w64-mingw32-ar'
|
ar = 'i686-w64-mingw32-ar'
|
||||||
strip = 'i686-w64-mingw32-strip'
|
strip = 'i686-w64-mingw32-strip'
|
||||||
pkgconfig = 'i686-w64-mingw32-pkg-config'
|
pkg-config = 'i686-w64-mingw32-pkg-config'
|
||||||
windres = 'i686-w64-mingw32-windres'
|
windres = 'i686-w64-mingw32-windres'
|
||||||
|
|
||||||
[host_machine]
|
[host_machine]
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ c = 'x86_64-w64-mingw32-gcc'
|
|||||||
cpp = 'x86_64-w64-mingw32-g++'
|
cpp = 'x86_64-w64-mingw32-g++'
|
||||||
ar = 'x86_64-w64-mingw32-ar'
|
ar = 'x86_64-w64-mingw32-ar'
|
||||||
strip = 'x86_64-w64-mingw32-strip'
|
strip = 'x86_64-w64-mingw32-strip'
|
||||||
pkgconfig = 'x86_64-w64-mingw32-pkg-config'
|
pkg-config = 'x86_64-w64-mingw32-pkg-config'
|
||||||
windres = 'x86_64-w64-mingw32-windres'
|
windres = 'x86_64-w64-mingw32-windres'
|
||||||
|
|
||||||
[host_machine]
|
[host_machine]
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ scrcpy --orientation=270 # 270° clockwise
|
|||||||
scrcpy --orientation=flip0 # hflip
|
scrcpy --orientation=flip0 # hflip
|
||||||
scrcpy --orientation=flip90 # hflip + 90° clockwise
|
scrcpy --orientation=flip90 # hflip + 90° clockwise
|
||||||
scrcpy --orientation=flip180 # vflip (hflip + 180°)
|
scrcpy --orientation=flip180 # vflip (hflip + 180°)
|
||||||
scrcpy --orientation=flip270 # hflip + 270° clockwise
|
scrcpy --orientation=flip270 # hflip + 270°
|
||||||
```
|
```
|
||||||
|
|
||||||
The orientation can be set separately for display and record if necessary, via
|
The orientation can be set separately for display and record if necessary, via
|
||||||
|
|||||||
@@ -14,8 +14,6 @@ import java.io.IOException;
|
|||||||
*/
|
*/
|
||||||
public final class CleanUp {
|
public final class CleanUp {
|
||||||
|
|
||||||
public static final String SERVER_PATH = "/data/local/tmp/scrcpy-server.jar";
|
|
||||||
|
|
||||||
// A simple struct to be passed from the main process to the cleanup process
|
// A simple struct to be passed from the main process to the cleanup process
|
||||||
public static class Config implements Parcelable {
|
public static class Config implements Parcelable {
|
||||||
|
|
||||||
@@ -135,21 +133,19 @@ public final class CleanUp {
|
|||||||
String[] cmd = {"app_process", "/", CleanUp.class.getName(), config.toBase64()};
|
String[] cmd = {"app_process", "/", CleanUp.class.getName(), config.toBase64()};
|
||||||
|
|
||||||
ProcessBuilder builder = new ProcessBuilder(cmd);
|
ProcessBuilder builder = new ProcessBuilder(cmd);
|
||||||
builder.environment().put("CLASSPATH", SERVER_PATH);
|
builder.environment().put("CLASSPATH", Server.SERVER_PATH);
|
||||||
builder.start();
|
builder.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void unlinkSelf() {
|
public static void unlinkSelf() {
|
||||||
try {
|
try {
|
||||||
new File(SERVER_PATH).delete();
|
new File(Server.SERVER_PATH).delete();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Ln.e("Could not unlink server", e);
|
Ln.e("Could not unlink server", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String... args) {
|
public static void main(String... args) {
|
||||||
unlinkSelf();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Wait for the server to die
|
// Wait for the server to die
|
||||||
System.in.read();
|
System.in.read();
|
||||||
@@ -187,7 +183,11 @@ public final class CleanUp {
|
|||||||
} else if (config.restoreNormalPowerMode) {
|
} else if (config.restoreNormalPowerMode) {
|
||||||
Ln.i("Restoring normal power mode");
|
Ln.i("Restoring normal power mode");
|
||||||
Device.setScreenPowerMode(Device.POWER_MODE_NORMAL);
|
Device.setScreenPowerMode(Device.POWER_MODE_NORMAL);
|
||||||
|
// Make sure the request is performed before exiting
|
||||||
|
DisplayPowerMode.stopAndJoin();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unlinkSelf();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -315,6 +315,14 @@ public final class Device {
|
|||||||
*/
|
*/
|
||||||
public static boolean setScreenPowerMode(int mode) {
|
public static boolean setScreenPowerMode(int mode) {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE && !SurfaceControl.hasPhysicalDisplayIdsMethod()) {
|
||||||
|
// On Android 14+, these internal methods have been moved to system server classes.
|
||||||
|
// Run a separate process with the correct classpath and LD_PRELOAD to change the display power mode.
|
||||||
|
DisplayPowerMode.setRemoteDisplayPowerMode(mode);
|
||||||
|
// The call is asynchronous (we don't want to block)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// Change the power mode for all physical displays
|
// Change the power mode for all physical displays
|
||||||
long[] physicalDisplayIds = SurfaceControl.getPhysicalDisplayIds();
|
long[] physicalDisplayIds = SurfaceControl.getPhysicalDisplayIds();
|
||||||
if (physicalDisplayIds == null) {
|
if (physicalDisplayIds == null) {
|
||||||
|
|||||||
161
server/src/main/java/com/genymobile/scrcpy/DisplayPowerMode.java
Normal file
161
server/src/main/java/com/genymobile/scrcpy/DisplayPowerMode.java
Normal file
@@ -0,0 +1,161 @@
|
|||||||
|
package com.genymobile.scrcpy;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
|
import android.os.IBinder;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* On Android 14, the methods used to turn the device screen off have been moved from SurfaceControl (in framework.jar) to DisplayControl (a system
|
||||||
|
* server class). As a consequence, they could not be called directly. See {@url https://github.com/Genymobile/scrcpy/issues/3927}.
|
||||||
|
* <p>
|
||||||
|
* Instead, run a separate process with a different classpath and LD_PRELOAD just to set the display power mode.
|
||||||
|
* <p>
|
||||||
|
* Since the client must not block, and calling/joining a process is blocking (this specific one takes a few hundred milliseconds to complete),
|
||||||
|
* this class uses an internal thread to execute the requests asynchronously, and serialize them (so that two successive requests are guaranteed to
|
||||||
|
* be executed in order). In addition, it only executes the last pending request (setting power mode to value X then to value Y is equivalent to
|
||||||
|
* just setting it to value Y).
|
||||||
|
*/
|
||||||
|
public final class DisplayPowerMode {
|
||||||
|
|
||||||
|
private static final Proxy PROXY = new Proxy();
|
||||||
|
|
||||||
|
private static final class Proxy implements Runnable {
|
||||||
|
|
||||||
|
private Thread thread;
|
||||||
|
private int requestedMode = -1;
|
||||||
|
private boolean stopped;
|
||||||
|
|
||||||
|
synchronized void requestMode(int mode) {
|
||||||
|
if (thread == null) {
|
||||||
|
thread = new Thread(this, "DisplayPowerModeProxy");
|
||||||
|
thread.setDaemon(true);
|
||||||
|
thread.start();
|
||||||
|
}
|
||||||
|
requestedMode = mode;
|
||||||
|
notify();
|
||||||
|
}
|
||||||
|
|
||||||
|
void stopAndJoin() {
|
||||||
|
boolean hasThread;
|
||||||
|
synchronized (this) {
|
||||||
|
hasThread = thread != null;
|
||||||
|
if (thread != null) {
|
||||||
|
stopped = true;
|
||||||
|
notify();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasThread) {
|
||||||
|
// Join the thread without holding the mutex (that would cause a deadlock)
|
||||||
|
try {
|
||||||
|
thread.join();
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
Ln.e("Thread join interrupted", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
int mode;
|
||||||
|
while (true) {
|
||||||
|
synchronized (this) {
|
||||||
|
while (!stopped && requestedMode == -1) {
|
||||||
|
wait();
|
||||||
|
}
|
||||||
|
mode = requestedMode;
|
||||||
|
requestedMode = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Even if stopped, the last request must be executed to restore the display power mode to normal
|
||||||
|
if (mode == -1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
Process process = executeSystemServerSetDisplayPowerMode(mode);
|
||||||
|
int status = process.waitFor();
|
||||||
|
if (status != 0) {
|
||||||
|
Ln.e("Set display power mode failed remotely: status=" + status);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
Ln.e("Failed to execute process", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
// end of thread
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private DisplayPowerMode() {
|
||||||
|
// not instantiable
|
||||||
|
}
|
||||||
|
|
||||||
|
// Called from the scrcpy process
|
||||||
|
public static void setRemoteDisplayPowerMode(int mode) {
|
||||||
|
PROXY.requestMode(mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void stopAndJoin() {
|
||||||
|
PROXY.stopAndJoin();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Called from the proxy thread in the scrcpy process
|
||||||
|
private static Process executeSystemServerSetDisplayPowerMode(int mode) throws IOException {
|
||||||
|
String[] ldPreloadLibs = {"/system/lib64/libandroid_servers.so"};
|
||||||
|
String[] cmd = {"app_process", "/", DisplayPowerMode.class.getName(), String.valueOf(mode)};
|
||||||
|
|
||||||
|
ProcessBuilder builder = new ProcessBuilder(cmd);
|
||||||
|
builder.environment().put("LD_PRELOAD", String.join(" ", ldPreloadLibs));
|
||||||
|
builder.environment().put("CLASSPATH", Server.SERVER_PATH + ":/system/framework/services.jar");
|
||||||
|
return builder.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Executed in the DisplayPowerMode-specific process
|
||||||
|
@SuppressLint({"PrivateApi", "SoonBlockedPrivateApi"})
|
||||||
|
private static void setDisplayPowerModeUsingDisplayControl(int mode) throws Exception {
|
||||||
|
System.loadLibrary("android_servers");
|
||||||
|
|
||||||
|
@SuppressLint("PrivateApi")
|
||||||
|
Class<?> displayControlClass = Class.forName("com.android.server.display.DisplayControl");
|
||||||
|
Method getPhysicalDisplayIdsMethod = displayControlClass.getDeclaredMethod("getPhysicalDisplayIds");
|
||||||
|
Method getPhysicalDisplayTokenMethod = displayControlClass.getDeclaredMethod("getPhysicalDisplayToken", long.class);
|
||||||
|
|
||||||
|
Class<?> surfaceControlClass = Class.forName("android.view.SurfaceControl");
|
||||||
|
Method setDisplayPowerModeMethod = surfaceControlClass.getDeclaredMethod("setDisplayPowerMode", IBinder.class, int.class);
|
||||||
|
|
||||||
|
long[] displayIds = (long[]) getPhysicalDisplayIdsMethod.invoke(null);
|
||||||
|
for (long displayId : displayIds) {
|
||||||
|
Object token = getPhysicalDisplayTokenMethod.invoke(null, displayId);
|
||||||
|
setDisplayPowerModeMethod.invoke(null, token, mode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String... args) {
|
||||||
|
Ln.disableSystemStreams();
|
||||||
|
Ln.initLogLevel(Ln.Level.DEBUG);
|
||||||
|
|
||||||
|
int status = run(args) ? 0 : 1;
|
||||||
|
System.exit(status);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean run(String... args) {
|
||||||
|
if (args.length != 1) {
|
||||||
|
Ln.e("Exactly one argument expected: the value of one of the SurfaceControl.POWER_MODE_* constants (typically 0 or 2)");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
int mode = Integer.parseInt(args[0]);
|
||||||
|
setDisplayPowerModeUsingDisplayControl(mode);
|
||||||
|
return true;
|
||||||
|
} catch (Throwable e) {
|
||||||
|
Ln.e("Could not set display power mode", e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,12 +3,20 @@ package com.genymobile.scrcpy;
|
|||||||
import android.os.BatteryManager;
|
import android.os.BatteryManager;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public final class Server {
|
public final class Server {
|
||||||
|
|
||||||
|
public static final String SERVER_PATH;
|
||||||
|
static {
|
||||||
|
String[] classPaths = System.getProperty("java.class.path").split(File.pathSeparator);
|
||||||
|
// By convention, scrcpy is always executed with the absolute path of scrcpy-server.jar as the first item in the classpath
|
||||||
|
SERVER_PATH = classPaths[0];
|
||||||
|
}
|
||||||
|
|
||||||
private static class Completion {
|
private static class Completion {
|
||||||
private int running;
|
private int running;
|
||||||
private boolean fatalError;
|
private boolean fatalError;
|
||||||
|
|||||||
@@ -139,6 +139,15 @@ public final class SurfaceControl {
|
|||||||
return getPhysicalDisplayIdsMethod;
|
return getPhysicalDisplayIdsMethod;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean hasPhysicalDisplayIdsMethod() {
|
||||||
|
try {
|
||||||
|
getGetPhysicalDisplayIdsMethod();
|
||||||
|
return true;
|
||||||
|
} catch (NoSuchMethodException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static long[] getPhysicalDisplayIds() {
|
public static long[] getPhysicalDisplayIds() {
|
||||||
try {
|
try {
|
||||||
Method method = getGetPhysicalDisplayIdsMethod();
|
Method method = getGetPhysicalDisplayIdsMethod();
|
||||||
|
|||||||
Reference in New Issue
Block a user