summaryrefslogtreecommitdiff
path: root/keystore/java/android
diff options
context:
space:
mode:
authorMax Bires <jbires@google.com>2021-08-13 08:59:29 -0700
committerMax Bires <jbires@google.com>2021-08-13 08:59:29 -0700
commit9b1e1c4c08904110ab78fde50b97e0d61243c46f (patch)
treed83eb92bd1d6fcf04505c16666ac11260e41a440 /keystore/java/android
parentc97285abb59a18d5e357cdbc9c9473f791e68f53 (diff)
Fixing a condition that can cause deadlock
Callbacks on ServiceConnection happen on the main UI thread for an application. Since the thread that calls bindService then immediately blocks to wait for the service to be connected, this will cause a deadlock if key operations are happening on the main UI thread. This bug has likely not been detected yet since key operations are not supposed to be performed on the main UI thread, however it was uncovered in a similar application during other testing. This fix ensures the ServiceConnection object's callbacks will be triggered from a separate thread from the calling thread. Bug: 196571032 Test: Apps that run key operations on the UI thread don't hang. Change-Id: I630a0ef2560a8ebd962de54c65e3d6277133a1cb
Diffstat (limited to 'keystore/java/android')
-rw-r--r--keystore/java/android/security/GenerateRkpKey.java5
1 files changed, 4 insertions, 1 deletions
diff --git a/keystore/java/android/security/GenerateRkpKey.java b/keystore/java/android/security/GenerateRkpKey.java
index 053bec74405e..2e54e63a5b7a 100644
--- a/keystore/java/android/security/GenerateRkpKey.java
+++ b/keystore/java/android/security/GenerateRkpKey.java
@@ -25,6 +25,8 @@ import android.os.RemoteException;
import android.util.Log;
import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.Executor;
+import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
/**
@@ -88,7 +90,8 @@ public class GenerateRkpKey {
}
intent.setComponent(comp);
mCountDownLatch = new CountDownLatch(1);
- if (!mContext.bindService(intent, mConnection, Context.BIND_AUTO_CREATE)) {
+ Executor executor = Executors.newCachedThreadPool();
+ if (!mContext.bindService(intent, Context.BIND_AUTO_CREATE, executor, mConnection)) {
throw new RemoteException("Failed to bind to GenerateRkpKeyService");
}
try {