mirror of
https://github.com/Genymobile/scrcpy.git
synced 2026-01-09 16:54:28 +01:00
Drop root privileges on startup
On rooted devices, switch to user 2000 during startup. Copy-paste does not work as root (user 0), so switching to 2000 fixes the issue. Fixes #6224 <https://github.com/Genymobile/scrcpy/issues/6224> Suggested-by: Simon Chan <1330321+yume-chan@users.noreply.github.com>
This commit is contained in:
@@ -27,6 +27,7 @@ import com.genymobile.scrcpy.video.VideoSource;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.os.Build;
|
||||
import android.os.Looper;
|
||||
import android.system.Os;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -233,6 +234,8 @@ public final class Server {
|
||||
}
|
||||
});
|
||||
|
||||
dropRootPrivileges();
|
||||
|
||||
prepareMainLooper();
|
||||
|
||||
Options options = Options.parse(args);
|
||||
@@ -273,4 +276,17 @@ public final class Server {
|
||||
// Do not print stack trace, a user-friendly error-message has already been logged
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private static void dropRootPrivileges() {
|
||||
try {
|
||||
if (Os.getuid() == 0) {
|
||||
// Copy-paste does not work with root user
|
||||
// <https://github.com/Genymobile/scrcpy/issues/6224>
|
||||
Os.setuid(2000);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Ln.w("Cannot set UID", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user