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

Commit 0c5c944a authored by Alexandru Chircu's avatar Alexandru Chircu Committed by Romain Hunault
Browse files

unbindService() in order to let RemoteDroidGuardService process die, as...

unbindService() in order to let RemoteDroidGuardService process die, as opposed to living as zombie.
parent 821d6319
Loading
Loading
Loading
Loading
+21 −2
Original line number Diff line number Diff line
@@ -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;
    }