From ac3aece5c58bbbd83c79a53407c8d9e133e2f7f5 Mon Sep 17 00:00:00 2001 From: Alexandru Chircu Date: Mon, 30 Dec 2019 15:18:20 +0200 Subject: [PATCH] unbindService() in order to let RemoteDroidGuardService process die, as opposed to living as zombie. --- .../droidguard/RemoteDroidGuardConnector.java | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/remote-droid-guard-lib/src/main/java/org/microg/gms/droidguard/RemoteDroidGuardConnector.java b/remote-droid-guard-lib/src/main/java/org/microg/gms/droidguard/RemoteDroidGuardConnector.java index a96b31a..849e57c 100644 --- a/remote-droid-guard-lib/src/main/java/org/microg/gms/droidguard/RemoteDroidGuardConnector.java +++ b/remote-droid-guard-lib/src/main/java/org/microg/gms/droidguard/RemoteDroidGuardConnector.java @@ -87,14 +87,33 @@ public class RemoteDroidGuardConnector { private boolean connectForTask(Task todo) { CountDownLatch countDownLatch = new CountDownLatch(1); + Intent intent = new Intent("org.microg.gms.droidguard.REMOTE"); intent.setPackage("org.microg.gms.droidguard"); - boolean b = context.bindService(intent, new Connection(countDownLatch, todo), Context.BIND_AUTO_CREATE); - if (!b) return false; + + Connection c = new Connection(countDownLatch, todo); + + boolean b = context.bindService(intent, c, Context.BIND_AUTO_CREATE); + if (!b) { + return false; + } + try { countDownLatch.await(30, TimeUnit.SECONDS); + + // When calling DroidguardHelper.guard(), process com.google.android.gms.unstable dies often + // thanks to com.google.ccc.abuse.droidguard.DroidGuard + // However, because of the above bindService, the process persists for a while in zombie state, + // and only next SafetyNetClientService calls that touch RemoteDroidGuardService make the process + // really go away (onDestroy gets called on RemoteDroidGuardService), with logcat getting the + // "Service org.microg.gms.snet.SafetyNetClientService has leaked ServiceConnection + // org.microg.gms.droidguard.RemoteDroidGuardConnector$Connection" message + // By unbinding here, the process is terminated immediately, and no more leaks are happening + context.unbindService(c); } catch (InterruptedException e) { + } + return true; } -- GitLab