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

Commit 7daf9b1c authored by Xiao Zhang's avatar Xiao Zhang
Browse files

Set timeout for binding service to avoid thread blocking

In the case of catching AssertionError, such as in Bug: 351757602, this fix can prevent android.bg thread blocking;In other cases where AssertionError is not catched, this fix can expose the problem as early as possible instead of waiting for the thread to block

Bug: 351757602
Test: Manual

Change-Id: Id2a2a960b28c77532e05c88ce9267762610f9119
parent b54b9b52
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -66,6 +66,7 @@ import java.util.Collection;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;

import javax.security.auth.x500.X500Principal;
@@ -376,6 +377,8 @@ public final class KeyChain {
     */
    public static final int KEY_ATTESTATION_FAILURE = 4;

    private static final int BIND_KEY_CHAIN_SERVICE_TIMEOUT_MS = 30 * 1000;

    /**
     * Used by DPC or delegated app in
     * {@link android.app.admin.DeviceAdminReceiver#onChoosePrivateKeyAlias} or
@@ -1120,7 +1123,10 @@ public final class KeyChain {
            context.unbindService(keyChainServiceConnection);
            throw new AssertionError("could not bind to KeyChainService");
        }
        countDownLatch.await();
        if (!countDownLatch.await(BIND_KEY_CHAIN_SERVICE_TIMEOUT_MS, TimeUnit.MILLISECONDS)) {
            context.unbindService(keyChainServiceConnection);
            throw new AssertionError("binding to KeyChainService timeout");
        }
        IKeyChainService service = keyChainService.get();
        if (service != null) {
            return new KeyChainConnection(context, keyChainServiceConnection, service);