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 a96b31a2d104253d1786e530ccc7d5dd66c1dd1a..849e57c3c958cefa19158f2b638a395b3834f50e 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; }