From 9dd1b4ff8e5806d1d402472ba1ec65f70dde18f0 Mon Sep 17 00:00:00 2001 From: Milk <1871357815@qq.com> Date: Sun, 16 Jun 2024 13:46:08 +0800 Subject: [PATCH] linkToDeath BlackShadowService --- .../src/main/java/top/niunaijun/shadow/BlackShadow.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/black-shadow/src/main/java/top/niunaijun/shadow/BlackShadow.java b/black-shadow/src/main/java/top/niunaijun/shadow/BlackShadow.java index 4772189..65ac0f2 100644 --- a/black-shadow/src/main/java/top/niunaijun/shadow/BlackShadow.java +++ b/black-shadow/src/main/java/top/niunaijun/shadow/BlackShadow.java @@ -19,7 +19,6 @@ import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; -import top.niunaijun.shadow.R; import top.niunaijun.shadow.common.InstallResult; import top.niunaijun.shadow.common.InstalledPlugin; import top.niunaijun.shadow.common.RunningPlugin; @@ -99,7 +98,7 @@ public void init(Application application) { } private IBSManagerService getBlackShadowService() { - if (mBSManagerService != null && mBSManagerService.asBinder().isBinderAlive()) { + if (mBSManagerService != null && mBSManagerService.asBinder().isBinderAlive() && mBSManagerService.asBinder().pingBinder()) { return mBSManagerService; } Bundle call = ProviderCallCompat.callSafely(getContext().getPackageName() + ".BlackShadowContentProvider", "", null, null); @@ -108,6 +107,12 @@ private IBSManagerService getBlackShadowService() { } IBinder service = call.getBinder("service"); mBSManagerService = IBSManagerService.Stub.asInterface(service); + if (mBSManagerService != null) { + try { + mBSManagerService.asBinder().linkToDeath(() -> mBSManagerService = null, 0); + } catch (RemoteException ignored) { + } + } return getBlackShadowService(); }