lock thread for user input

This commit is contained in:
Dominik Schürmann 2013-09-08 19:24:47 +02:00
parent 11103623c5
commit 8123fd6925
2 changed files with 19 additions and 6 deletions

View File

@ -57,10 +57,12 @@ public class CryptoService extends Service {
// just one pool of 4 threads, pause on every user action needed
final ArrayBlockingQueue<Runnable> mPoolQueue = new ArrayBlockingQueue<Runnable>(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);
}
}
}
}

View File

@ -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();
}
};