diff options
author | Steven Laver <lavers@google.com> | 2019-11-25 11:11:20 -0800 |
---|---|---|
committer | Steven Laver <lavers@google.com> | 2019-11-27 13:21:24 -0800 |
commit | 5358a994b854c7a6627858c48d6947e8acff6ea9 (patch) | |
tree | e6a0a2ba4ef0338e9242026a59bbee04ee24b54f /keystore/java/android/security/KeyChain.java | |
parent | 8901573f5f8c960fe2686ae6a8b72557a660519a (diff) | |
parent | 52681ca440211aef63d6f09c86fccc612c78a0e4 (diff) |
Merge RP1A.191120.001
Change-Id: I861114a47121f0c4cfb375680e22b957bd9988fb
Diffstat (limited to 'keystore/java/android/security/KeyChain.java')
-rw-r--r-- | keystore/java/android/security/KeyChain.java | 24 |
1 files changed, 10 insertions, 14 deletions
diff --git a/keystore/java/android/security/KeyChain.java b/keystore/java/android/security/KeyChain.java index 538319c3f1d7..a7e17d13c9e1 100644 --- a/keystore/java/android/security/KeyChain.java +++ b/keystore/java/android/security/KeyChain.java @@ -55,8 +55,8 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Locale; -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.atomic.AtomicReference; import javax.security.auth.x500.X500Principal; @@ -811,27 +811,22 @@ public final class KeyChain { throw new NullPointerException("context == null"); } ensureNotOnMainThread(context); - final BlockingQueue<IKeyChainService> q = new LinkedBlockingQueue<IKeyChainService>(1); + final CountDownLatch countDownLatch = new CountDownLatch(1); + final AtomicReference<IKeyChainService> keyChainService = new AtomicReference<>(); ServiceConnection keyChainServiceConnection = new ServiceConnection() { volatile boolean mConnectedAtLeastOnce = false; @Override public void onServiceConnected(ComponentName name, IBinder service) { if (!mConnectedAtLeastOnce) { mConnectedAtLeastOnce = true; - try { - q.put(IKeyChainService.Stub.asInterface(Binder.allowBlocking(service))); - } catch (InterruptedException e) { - // will never happen, since the queue starts with one available slot - } + keyChainService.set( + IKeyChainService.Stub.asInterface(Binder.allowBlocking(service))); + countDownLatch.countDown(); } } @Override public void onBindingDied(ComponentName name) { if (!mConnectedAtLeastOnce) { mConnectedAtLeastOnce = true; - try { - q.put(null); - } catch (InterruptedException e) { - // will never happen, since the queue starts with one available slot - } + countDownLatch.countDown(); } } @Override public void onServiceDisconnected(ComponentName name) {} @@ -843,7 +838,8 @@ public final class KeyChain { intent, keyChainServiceConnection, Context.BIND_AUTO_CREATE, user)) { throw new AssertionError("could not bind to KeyChainService"); } - IKeyChainService service = q.take(); + countDownLatch.await(); + IKeyChainService service = keyChainService.get(); if (service != null) { return new KeyChainConnection(context, keyChainServiceConnection, service); } else { |