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

Commit cce61395 authored by Rubin Xu's avatar Rubin Xu Committed by Gerrit Code Review
Browse files

Merge "Set timeout for binding service to avoid thread blocking" into main

parents 94c9498b 7daf9b1c
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);