mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-12-25 00:18:51 -05:00
lock thread for user input
This commit is contained in:
parent
11103623c5
commit
8123fd6925
@ -57,10 +57,12 @@ public class CryptoService extends Service {
|
|||||||
|
|
||||||
// just one pool of 4 threads, pause on every user action needed
|
// just one pool of 4 threads, pause on every user action needed
|
||||||
final ArrayBlockingQueue<Runnable> mPoolQueue = new ArrayBlockingQueue<Runnable>(20);
|
final ArrayBlockingQueue<Runnable> mPoolQueue = new ArrayBlockingQueue<Runnable>(20);
|
||||||
// TODO: ? only one pool, -> one thread at a time
|
// TODO: Are these parameters okay?
|
||||||
PausableThreadPoolExecutor mThreadPool = new PausableThreadPoolExecutor(1, 1, 10,
|
PausableThreadPoolExecutor mThreadPool = new PausableThreadPoolExecutor(2, 4, 10,
|
||||||
TimeUnit.SECONDS, mPoolQueue);
|
TimeUnit.SECONDS, mPoolQueue);
|
||||||
|
|
||||||
|
final Object userInputLock = new Object();
|
||||||
|
|
||||||
public static final String ACTION_SERVICE_ACTIVITY = "org.sufficientlysecure.keychain.crypto_provider.IServiceActivityCallback";
|
public static final String ACTION_SERVICE_ACTIVITY = "org.sufficientlysecure.keychain.crypto_provider.IServiceActivityCallback";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -425,11 +427,15 @@ public class CryptoService extends Service {
|
|||||||
public void onCachedPassphrase(boolean success) throws RemoteException {
|
public void onCachedPassphrase(boolean success) throws RemoteException {
|
||||||
Log.d(Constants.TAG, "current therad id: " + Thread.currentThread().getId());
|
Log.d(Constants.TAG, "current therad id: " + Thread.currentThread().getId());
|
||||||
mThreadPool.resume();
|
mThreadPool.resume();
|
||||||
|
|
||||||
|
synchronized (userInputLock) {
|
||||||
|
userInputLock.notifyAll();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSelectedPublicKeys(long[] keyIds) throws RemoteException {
|
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);
|
intent.putExtras(extras);
|
||||||
}
|
}
|
||||||
getApplication().startActivity(intent);
|
getApplication().startActivity(intent);
|
||||||
}
|
|
||||||
|
|
||||||
|
// lock current thread for user input
|
||||||
|
synchronized (userInputLock) {
|
||||||
|
try {
|
||||||
|
userInputLock.wait();
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
Log.e(Constants.TAG, "CryptoService", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -268,15 +268,14 @@ public class CryptoServiceActivity extends SherlockFragmentActivity {
|
|||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
Log.e(Constants.TAG, "ServiceActivity", e);
|
Log.e(Constants.TAG, "ServiceActivity", e);
|
||||||
}
|
}
|
||||||
finish();
|
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
mServiceCallback.onCachedPassphrase(false);
|
mServiceCallback.onCachedPassphrase(false);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
Log.e(Constants.TAG, "ServiceActivity", e);
|
Log.e(Constants.TAG, "ServiceActivity", e);
|
||||||
}
|
}
|
||||||
finish();
|
|
||||||
}
|
}
|
||||||
|
finish();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user