[core] Fix death receipent leak

This commit is contained in:
LoveSy 2021-02-18 04:55:16 +08:00 committed by tehcneko
parent b5cd5e303d
commit 7fcd689192
6 changed files with 42 additions and 37 deletions

View File

@ -188,11 +188,11 @@ public class ModulesActivity extends ListActivity implements ModuleUtil.ModuleLi
sb.append(getString(R.string.module_empty_description));
}
int installedXposedVersion = ConfigManager.getXposedApiVersion();
int installXposedVersion = ConfigManager.getXposedApiVersion();
String warningText = null;
if (item.minVersion == 0) {
warningText = getString(R.string.no_min_version_specified);
} else if (installedXposedVersion > 0 && item.minVersion > installedXposedVersion) {
} else if (installXposedVersion > 0 && item.minVersion > installXposedVersion) {
warningText = String.format(getString(R.string.warning_xposed_min_version), item.minVersion);
} else if (item.minVersion < ModuleUtil.MIN_MODULE_VERSION) {
warningText = String.format(getString(R.string.warning_min_version_too_low), item.minVersion, ModuleUtil.MIN_MODULE_VERSION);

View File

@ -43,7 +43,7 @@ public class Main implements KeepAll {
LSPApplicationServiceClient.Init(binder);
serviceClient.registerHeartBeat(heartBeatBinder);
final int variant = serviceClient.getVariant();
Impl lspd = getEdxpImpl(variant);
Impl lspd = getImpl(variant);
if (lspd == null || !lspd.isInitialized()) {
Utils.logE("Not started up");
return;
@ -55,18 +55,18 @@ public class Main implements KeepAll {
LSPApplicationServiceClient.Init(binder);
serviceClient.registerHeartBeat(heartBeatBinder);
final int variant = serviceClient.getVariant();
Impl lspd = getEdxpImpl(variant);
Impl lspd = getImpl(variant);
if (lspd == null || !lspd.isInitialized()) {
return;
}
lspd.getNormalProxy().forkSystemServerPost();
}
public static synchronized boolean setEdxpImpl(Impl lspd) {
public static synchronized boolean setImpl(Impl lspd) {
return lspdImplRef.compareAndSet(null, lspd);
}
public static synchronized Impl getEdxpImpl(int variant) {
public static synchronized Impl getImpl(int variant) {
Impl lspd = lspdImplRef.get();
if (lspd != null) {
return lspd;
@ -90,15 +90,10 @@ public class Main implements KeepAll {
return lspdImplRef.get();
}
public static synchronized Impl getEdxpImpl() {
public static synchronized Impl getImpl() {
return lspdImplRef.get();
}
@Impl.Variant
public static synchronized int getEdxpVariant() {
return getEdxpImpl().getVariant();
}
public static void main(String[] args) {
for (String arg : args) {
if (arg.equals("--debug")) {

View File

@ -44,7 +44,7 @@ public class SystemMainHooker extends XC_MethodHook {
systemServerCL = Thread.currentThread().getContextClassLoader();
// deopt methods in SYSTEMSERVERCLASSPATH
PrebuiltMethodsDeopter.deoptSystemServerMethods(systemServerCL);
Main.getEdxpImpl().getRouter().startSystemServerHook();
Main.getImpl().getRouter().startSystemServerHook();
} catch (Throwable t) {
Hookers.logE("error when hooking systemMain", t);
}

View File

@ -35,7 +35,7 @@ public class SandHookImpl extends BaseImpl {
static {
final Impl lspdImpl = new SandHookImpl();
if (Main.setEdxpImpl(lspdImpl)) {
if (Main.setImpl(lspdImpl)) {
lspdImpl.init();
}
}

View File

@ -37,30 +37,40 @@ public class BridgeService {
private static ILSPosedService service = null;
// for service
private static final IBinder.DeathRecipient BRIDGE_SERVICE_DEATH_RECIPIENT = () -> {
Log.i(TAG, "service " + SERVICE_NAME + " is dead. ");
static class BridgeServiceDeathRecipient implements IBinder.DeathRecipient {
private final IBinder bridgeService;
try {
@SuppressWarnings("JavaReflectionMemberAccess")
Field field = ServiceManager.class.getDeclaredField("sServiceManager");
field.setAccessible(true);
field.set(null, null);
//noinspection JavaReflectionMemberAccess
field = ServiceManager.class.getDeclaredField("sCache");
field.setAccessible(true);
Object sCache = field.get(null);
if (sCache instanceof Map) {
//noinspection rawtypes
((Map) sCache).clear();
}
Log.i(TAG, "clear ServiceManager");
} catch (Throwable e) {
Log.w(TAG, "clear ServiceManager: " + Log.getStackTraceString(e));
BridgeServiceDeathRecipient(IBinder bridgeService) throws RemoteException {
this.bridgeService = bridgeService;
bridgeService.linkToDeath(this, 0);
}
@Override
public void binderDied() {
Log.i(TAG, "service " + SERVICE_NAME + " is dead. ");
sendToBridge(serviceBinder, true);
};
try {
@SuppressWarnings("JavaReflectionMemberAccess")
Field field = ServiceManager.class.getDeclaredField("sServiceManager");
field.setAccessible(true);
field.set(null, null);
//noinspection JavaReflectionMemberAccess
field = ServiceManager.class.getDeclaredField("sCache");
field.setAccessible(true);
Object sCache = field.get(null);
if (sCache instanceof Map) {
//noinspection rawtypes
((Map) sCache).clear();
}
Log.i(TAG, "clear ServiceManager");
} catch (Throwable e) {
Log.w(TAG, "clear ServiceManager: " + Log.getStackTraceString(e));
}
bridgeService.unlinkToDeath(this, 0);
sendToBridge(serviceBinder, true);
}
}
// for client
private static final IBinder.DeathRecipient LSPSERVICE_DEATH_RECIPIENT = () -> {
@ -102,7 +112,7 @@ public class BridgeService {
}
try {
bridgeService.linkToDeath(BRIDGE_SERVICE_DEATH_RECIPIENT, 0);
new BridgeServiceDeathRecipient(bridgeService);
} catch (Throwable e) {
Log.w(TAG, "linkToDeath " + Log.getStackTraceString(e));
sendToBridge(binder, false);

View File

@ -34,7 +34,7 @@ public class YahfaImpl extends BaseImpl {
static {
final Impl lspdImpl = new YahfaImpl();
if (Main.setEdxpImpl(lspdImpl)) {
if (Main.setImpl(lspdImpl)) {
lspdImpl.init();
}
}