mirror of
https://github.com/topjohnwu/libsu.git
synced 2024-11-23 03:59:43 +00:00
Add a timeout when waiting for client respond
The client process can be killed before it had a chance to connect to the root process with binder. Add a 10 second timeout before any client has connected.
This commit is contained in:
parent
655f5ff340
commit
d3cafdb50d
Binary file not shown.
@ -89,7 +89,7 @@ class RootServerMain extends ContextWrapper implements Callable<Object[]> {
|
||||
System.out.close();
|
||||
System.err.close();
|
||||
if (args.length < 3)
|
||||
System.exit(0);
|
||||
System.exit(1);
|
||||
|
||||
Looper.prepareMainLooper();
|
||||
|
||||
@ -102,7 +102,7 @@ class RootServerMain extends ContextWrapper implements Callable<Object[]> {
|
||||
|
||||
// Main thread event loop
|
||||
Looper.loop();
|
||||
System.exit(0);
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
private final int uid;
|
||||
|
@ -53,7 +53,7 @@ import java.util.Set;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
@RestrictTo(RestrictTo.Scope.LIBRARY)
|
||||
public class RootServiceServer extends IRootServiceManager.Stub {
|
||||
public class RootServiceServer extends IRootServiceManager.Stub implements Runnable {
|
||||
|
||||
private static RootServiceServer mInstance;
|
||||
|
||||
@ -107,6 +107,18 @@ public class RootServiceServer extends IRootServiceManager.Stub {
|
||||
} else {
|
||||
throw new IllegalArgumentException("Expected Context to be Callable");
|
||||
}
|
||||
|
||||
if (!isDaemon) {
|
||||
// Terminate the process if idle for 10 seconds,
|
||||
UiThreadHandler.handler.postDelayed(this, 10 * 1000);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (clients.size() == 0) {
|
||||
exit("No active clients");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -122,9 +134,9 @@ public class RootServiceServer extends IRootServiceManager.Stub {
|
||||
try {
|
||||
c = new ClientProcess(binder, uid);
|
||||
clients.put(c.mUid, c);
|
||||
UiThreadHandler.handler.removeCallbacks(this);
|
||||
} catch (RemoteException e) {
|
||||
Utils.err(TAG, e);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@ -255,8 +267,7 @@ public class RootServiceServer extends IRootServiceManager.Stub {
|
||||
}
|
||||
}
|
||||
if (activeServices.isEmpty()) {
|
||||
// Terminate root process
|
||||
System.exit(0);
|
||||
exit("No active services");
|
||||
}
|
||||
}
|
||||
|
||||
@ -281,6 +292,11 @@ public class RootServiceServer extends IRootServiceManager.Stub {
|
||||
}
|
||||
}
|
||||
|
||||
private void exit(String reason) {
|
||||
Utils.log(TAG, "Terminate process: " + reason);
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
class AppObserver extends FileObserver {
|
||||
|
||||
private final String name;
|
||||
@ -295,11 +311,7 @@ public class RootServiceServer extends IRootServiceManager.Stub {
|
||||
public void onEvent(int event, @Nullable String path) {
|
||||
// App APK update, force close the root process
|
||||
if (event == DELETE_SELF || name.equals(path)) {
|
||||
UiThreadHandler.run(() -> {
|
||||
Utils.log(TAG, "App updated, terminate");
|
||||
unbindServices(-1);
|
||||
System.exit(0);
|
||||
});
|
||||
exit("Package updated");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user