mirror of
https://github.com/moonlight-stream/moonlight-android.git
synced 2025-07-20 19:42:45 +00:00
Fix a bug where an error change any permissions would cause the operation to fail and other files to not be changed
This commit is contained in:
parent
bb869a51fd
commit
6bae056e3a
@ -12,16 +12,16 @@ public class EvdevReader {
|
||||
}
|
||||
|
||||
// Requires root to chmod /dev/input/eventX
|
||||
public static boolean setPermissions(int octalPermissions) {
|
||||
String chmodString = String.format("chmod %o /dev/input/*\n", octalPermissions);
|
||||
|
||||
public static boolean setPermissions(String[] files, int octalPermissions) {
|
||||
ProcessBuilder builder = new ProcessBuilder("su");
|
||||
|
||||
try {
|
||||
Process p = builder.start();
|
||||
|
||||
OutputStream stdin = p.getOutputStream();
|
||||
stdin.write(chmodString.getBytes("UTF-8"));
|
||||
for (String file : files) {
|
||||
stdin.write(String.format("chmod %o %s\n", octalPermissions, file).getBytes("UTF-8"));
|
||||
}
|
||||
stdin.write("exit\n".getBytes("UTF-8"));
|
||||
stdin.flush();
|
||||
|
||||
|
@ -38,7 +38,7 @@ public class EvdevWatcher {
|
||||
|
||||
if (!init) {
|
||||
// If this a real new device, update permissions again so we can read it
|
||||
EvdevReader.setPermissions(0666);
|
||||
EvdevReader.setPermissions(new String[]{PATH + "/" + fileName}, 0666);
|
||||
}
|
||||
|
||||
EvdevHandler handler = new EvdevHandler(PATH + "/" + fileName, listener);
|
||||
@ -63,17 +63,29 @@ public class EvdevWatcher {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
private File[] rundownWithPermissionsChange(int newPermissions) {
|
||||
// Rundown existing files
|
||||
File devInputDir = new File(PATH);
|
||||
File[] files = devInputDir.listFiles();
|
||||
|
||||
// Set desired permissions
|
||||
String[] filePaths = new String[files.length];
|
||||
for (int i = 0; i < files.length; i++) {
|
||||
filePaths[i] = files[i].getAbsolutePath();
|
||||
}
|
||||
EvdevReader.setPermissions(filePaths, newPermissions);
|
||||
|
||||
return files;
|
||||
}
|
||||
|
||||
public void start() {
|
||||
startThread = new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
// Get permissions to read the eventX files
|
||||
EvdevReader.setPermissions(0666);
|
||||
init = true;
|
||||
// List all files and allow us access
|
||||
File[] files = rundownWithPermissionsChange(0666);
|
||||
|
||||
// Rundown existing files and generate synthetic events
|
||||
File devInputDir = new File(PATH);
|
||||
File[] files = devInputDir.listFiles();
|
||||
init = true;
|
||||
for (File f : files) {
|
||||
observer.onEvent(FileObserver.CREATE, f.getName());
|
||||
}
|
||||
@ -92,7 +104,7 @@ public class EvdevWatcher {
|
||||
}
|
||||
|
||||
// Giveup eventX permissions
|
||||
EvdevReader.setPermissions(0066);
|
||||
rundownWithPermissionsChange(066);
|
||||
}
|
||||
};
|
||||
startThread.start();
|
||||
|
Loading…
x
Reference in New Issue
Block a user