Try to restart zygote if injection fails (#1582)
Max #retrial=1 by default
This commit is contained in:
parent
5898667351
commit
40aebb5703
|
|
@ -327,7 +327,8 @@ val pushDaemonNative = task<Exec>("pushDaemonNative") {
|
|||
}
|
||||
val reRunDaemon = task<Exec>("reRunDaemon") {
|
||||
dependsOn(pushDaemon, pushDaemonNative, killLspd)
|
||||
commandLine(adb, "shell", "su", "-c", "sh `su -c magisk --path`/.magisk/modules/*_lsposed/service.sh&")
|
||||
// tricky to pass a minus number to avoid the injection warning
|
||||
commandLine(adb, "shell", "su", "-c", "sh `su -c magisk --path`/.magisk/modules/*_lsposed/service.sh --system-server-max-retry=-1&")
|
||||
isIgnoreExitValue = true
|
||||
}
|
||||
val tmpApk = "/data/local/tmp/lsp.apk"
|
||||
|
|
|
|||
|
|
@ -19,4 +19,4 @@
|
|||
|
||||
MODDIR=${0%/*}
|
||||
# post-fs-data.sh may be blocked by other modules. retry to start this
|
||||
unshare -m "$MODDIR/lspd" --from-service &
|
||||
unshare -m "$MODDIR/lspd" --from-service "$@"&
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ import android.os.IBinder;
|
|||
import android.os.IServiceCallback;
|
||||
import android.os.Parcel;
|
||||
import android.os.RemoteException;
|
||||
import android.os.SystemProperties;
|
||||
import android.util.Log;
|
||||
|
||||
public class LSPSystemServerService extends ILSPSystemServerService.Stub implements IBinder.DeathRecipient {
|
||||
|
|
@ -34,10 +35,10 @@ public class LSPSystemServerService extends ILSPSystemServerService.Stub impleme
|
|||
public static final String PROXY_SERVICE_NAME = "serial";
|
||||
|
||||
private IBinder originService = null;
|
||||
private boolean requested = false;
|
||||
private int requested;
|
||||
|
||||
public boolean systemServerRequested() {
|
||||
return requested;
|
||||
return requested > 0;
|
||||
}
|
||||
|
||||
public void putBinderForSystemServer() {
|
||||
|
|
@ -45,7 +46,8 @@ public class LSPSystemServerService extends ILSPSystemServerService.Stub impleme
|
|||
binderDied();
|
||||
}
|
||||
|
||||
public LSPSystemServerService() {
|
||||
public LSPSystemServerService(int maxRetry) {
|
||||
requested = -maxRetry;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||
var serviceCallback = new IServiceCallback.Stub() {
|
||||
@Override
|
||||
|
|
@ -72,7 +74,7 @@ public class LSPSystemServerService extends ILSPSystemServerService.Stub impleme
|
|||
|
||||
@Override
|
||||
public ILSPApplicationService requestApplicationService(int uid, int pid, String processName, IBinder heartBeat) {
|
||||
requested = true;
|
||||
requested = 1;
|
||||
if (ConfigManager.getInstance().shouldSkipSystemServer() || uid != 1000 || heartBeat == null || !"android".equals(processName))
|
||||
return null;
|
||||
else
|
||||
|
|
@ -102,6 +104,18 @@ public class LSPSystemServerService extends ILSPSystemServerService.Stub impleme
|
|||
originService.unlinkToDeath(this, 0);
|
||||
originService = null;
|
||||
}
|
||||
requested = false;
|
||||
}
|
||||
|
||||
public void maybeRetryInject() {
|
||||
if (requested < 0) {
|
||||
Log.w(TAG, "System server injection fails, trying a restart");
|
||||
++requested;
|
||||
if (Build.SUPPORTED_64_BIT_ABIS.length > 0 && Build.SUPPORTED_32_BIT_ABIS.length > 0) {
|
||||
// Only devices with both 32-bit and 64-bit support have zygote_secondary
|
||||
SystemProperties.set("ctl.restart", "zygote_secondary");
|
||||
} else {
|
||||
SystemProperties.set("ctl.restart", "zygote");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -75,9 +75,15 @@ public class ServiceManager {
|
|||
public static void start(String[] args) {
|
||||
if (!ConfigFileManager.tryLock()) System.exit(0);
|
||||
|
||||
int systemServerMaxRetry = 1;
|
||||
for (String arg : args) {
|
||||
if (arg.equals("--from-service")) {
|
||||
Log.w(TAG, "LSPosed daemon is not started properly. Try for a late start...");
|
||||
} else if (arg.startsWith("--system-server-max-retry=")) {
|
||||
try {
|
||||
systemServerMaxRetry = Integer.parseInt(arg.substring(arg.lastIndexOf('=') + 1));
|
||||
} catch (Throwable ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
Log.i(TAG, "starting server...");
|
||||
|
|
@ -96,7 +102,7 @@ public class ServiceManager {
|
|||
mainService = new LSPosedService();
|
||||
applicationService = new LSPApplicationService();
|
||||
managerService = new LSPManagerService();
|
||||
systemServerService = new LSPSystemServerService();
|
||||
systemServerService = new LSPSystemServerService(systemServerMaxRetry);
|
||||
|
||||
systemServerService.putBinderForSystemServer();
|
||||
|
||||
|
|
@ -127,6 +133,7 @@ public class ServiceManager {
|
|||
} else {
|
||||
Log.w(TAG, "no response from bridge");
|
||||
}
|
||||
systemServerService.maybeRetryInject();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
Loading…
Reference in New Issue