Search in sources :

Example 1 with SettableFuture

use of org.whispersystems.signalservice.internal.util.concurrent.SettableFuture in project Signal-Android by WhisperSystems.

the class WebRtcCallService method isCallActive.

@WorkerThread
public static boolean isCallActive(Context context) {
    Log.w(TAG, "isCallActive()");
    HandlerThread handlerThread = null;
    try {
        handlerThread = new HandlerThread("webrtc-callback");
        handlerThread.start();
        final SettableFuture<Boolean> future = new SettableFuture<>();
        ResultReceiver resultReceiver = new ResultReceiver(new Handler(handlerThread.getLooper())) {

            protected void onReceiveResult(int resultCode, Bundle resultData) {
                Log.w(TAG, "Got result...");
                future.set(resultCode == 1);
            }
        };
        Intent intent = new Intent(context, WebRtcCallService.class);
        intent.setAction(ACTION_IS_IN_CALL_QUERY);
        intent.putExtra(EXTRA_RESULT_RECEIVER, resultReceiver);
        context.startService(intent);
        Log.w(TAG, "Blocking on result...");
        return future.get();
    } catch (InterruptedException | ExecutionException e) {
        Log.w(TAG, e);
        return false;
    } finally {
        if (handlerThread != null)
            handlerThread.quit();
    }
}
Also used : SettableFuture(org.whispersystems.signalservice.internal.util.concurrent.SettableFuture) HandlerThread(android.os.HandlerThread) Bundle(android.os.Bundle) Handler(android.os.Handler) Intent(android.content.Intent) ExecutionException(java.util.concurrent.ExecutionException) ResultReceiver(android.os.ResultReceiver) WorkerThread(android.support.annotation.WorkerThread)

Aggregations

Intent (android.content.Intent)1 Bundle (android.os.Bundle)1 Handler (android.os.Handler)1 HandlerThread (android.os.HandlerThread)1 ResultReceiver (android.os.ResultReceiver)1 WorkerThread (android.support.annotation.WorkerThread)1 ExecutionException (java.util.concurrent.ExecutionException)1 SettableFuture (org.whispersystems.signalservice.internal.util.concurrent.SettableFuture)1