Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 6fd01e29 authored by Alexandru Chircu's avatar Alexandru Chircu Committed by GitHub
Browse files

Unbind service to prevent leak (#28)

parent 4cd4e55e
Loading
Loading
Loading
Loading
+24 −2
Original line number Diff line number Diff line
@@ -87,14 +87,36 @@ 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);

        try {
            if (!context.bindService(intent, c, Context.BIND_AUTO_CREATE)) {
                return false;
            }
        } catch (SecurityException e) {
            return false;
        }

        try {
            countDownLatch.await(30, TimeUnit.SECONDS);
        } catch (InterruptedException e) {

        }
        
        // 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);

        return true;
    }