From 8123fd69255d3dda04311aea83f4c2735edd4ec5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Sch=C3=BCrmann?= Date: Sun, 8 Sep 2013 19:24:47 +0200 Subject: [PATCH] lock thread for user input --- .../keychain/remote_api/CryptoService.java | 22 +++++++++++++++---- .../remote_api/CryptoServiceActivity.java | 3 +-- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/remote_api/CryptoService.java b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/remote_api/CryptoService.java index 687da8a86..1a43b49c1 100644 --- a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/remote_api/CryptoService.java +++ b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/remote_api/CryptoService.java @@ -57,10 +57,12 @@ public class CryptoService extends Service { // just one pool of 4 threads, pause on every user action needed final ArrayBlockingQueue mPoolQueue = new ArrayBlockingQueue(20); - // TODO: ? only one pool, -> one thread at a time - PausableThreadPoolExecutor mThreadPool = new PausableThreadPoolExecutor(1, 1, 10, + // TODO: Are these parameters okay? + PausableThreadPoolExecutor mThreadPool = new PausableThreadPoolExecutor(2, 4, 10, TimeUnit.SECONDS, mPoolQueue); + final Object userInputLock = new Object(); + public static final String ACTION_SERVICE_ACTIVITY = "org.sufficientlysecure.keychain.crypto_provider.IServiceActivityCallback"; @Override @@ -425,11 +427,15 @@ public class CryptoService extends Service { public void onCachedPassphrase(boolean success) throws RemoteException { Log.d(Constants.TAG, "current therad id: " + Thread.currentThread().getId()); mThreadPool.resume(); + + synchronized (userInputLock) { + userInputLock.notifyAll(); + } } @Override public void onSelectedPublicKeys(long[] keyIds) throws RemoteException { - // TODO Auto-generated method stub + mThreadPool.resume(); } @@ -536,6 +542,14 @@ public class CryptoService extends Service { intent.putExtras(extras); } getApplication().startActivity(intent); - } + // lock current thread for user input + synchronized (userInputLock) { + try { + userInputLock.wait(); + } catch (InterruptedException e) { + Log.e(Constants.TAG, "CryptoService", e); + } + } + } } diff --git a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/remote_api/CryptoServiceActivity.java b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/remote_api/CryptoServiceActivity.java index 2ea3f530a..482f79728 100644 --- a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/remote_api/CryptoServiceActivity.java +++ b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/remote_api/CryptoServiceActivity.java @@ -268,15 +268,14 @@ public class CryptoServiceActivity extends SherlockFragmentActivity { } catch (RemoteException e) { Log.e(Constants.TAG, "ServiceActivity", e); } - finish(); } else { try { mServiceCallback.onCachedPassphrase(false); } catch (RemoteException e) { Log.e(Constants.TAG, "ServiceActivity", e); } - finish(); } + finish(); } };