mirror of
https://github.com/moonlight-stream/moonlight-android.git
synced 2025-07-21 12:03:02 +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
|
// Requires root to chmod /dev/input/eventX
|
||||||
public static boolean setPermissions(int octalPermissions) {
|
public static boolean setPermissions(String[] files, int octalPermissions) {
|
||||||
String chmodString = String.format("chmod %o /dev/input/*\n", octalPermissions);
|
|
||||||
|
|
||||||
ProcessBuilder builder = new ProcessBuilder("su");
|
ProcessBuilder builder = new ProcessBuilder("su");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Process p = builder.start();
|
Process p = builder.start();
|
||||||
|
|
||||||
OutputStream stdin = p.getOutputStream();
|
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.write("exit\n".getBytes("UTF-8"));
|
||||||
stdin.flush();
|
stdin.flush();
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ public class EvdevWatcher {
|
|||||||
|
|
||||||
if (!init) {
|
if (!init) {
|
||||||
// If this a real new device, update permissions again so we can read it
|
// 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);
|
EvdevHandler handler = new EvdevHandler(PATH + "/" + fileName, listener);
|
||||||
@ -63,17 +63,29 @@ public class EvdevWatcher {
|
|||||||
this.listener = listener;
|
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() {
|
public void start() {
|
||||||
startThread = new Thread() {
|
startThread = new Thread() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
// Get permissions to read the eventX files
|
// List all files and allow us access
|
||||||
EvdevReader.setPermissions(0666);
|
File[] files = rundownWithPermissionsChange(0666);
|
||||||
init = true;
|
|
||||||
|
|
||||||
// Rundown existing files and generate synthetic events
|
init = true;
|
||||||
File devInputDir = new File(PATH);
|
|
||||||
File[] files = devInputDir.listFiles();
|
|
||||||
for (File f : files) {
|
for (File f : files) {
|
||||||
observer.onEvent(FileObserver.CREATE, f.getName());
|
observer.onEvent(FileObserver.CREATE, f.getName());
|
||||||
}
|
}
|
||||||
@ -92,7 +104,7 @@ public class EvdevWatcher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Giveup eventX permissions
|
// Giveup eventX permissions
|
||||||
EvdevReader.setPermissions(0066);
|
rundownWithPermissionsChange(066);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
startThread.start();
|
startThread.start();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user