Search in sources :

Example 21 with SettableFuture

use of org.thoughtcrime.securesms.util.concurrent.SettableFuture in project Signal-Android by WhisperSystems.

the class PeerConnectionWrapper method setRemoteDescription.

public void setRemoteDescription(SessionDescription sdp) throws PeerConnectionException {
    final SettableFuture<Boolean> future = new SettableFuture<>();
    peerConnection.setRemoteDescription(new SdpObserver() {

        @Override
        public void onCreateSuccess(SessionDescription sdp) {
        }

        @Override
        public void onCreateFailure(String error) {
        }

        @Override
        public void onSetSuccess() {
            future.set(true);
        }

        @Override
        public void onSetFailure(String error) {
            future.setException(new PeerConnectionException(error));
        }
    }, sdp);
    try {
        future.get();
    } catch (InterruptedException e) {
        throw new AssertionError(e);
    } catch (ExecutionException e) {
        throw new PeerConnectionException(e);
    }
}
Also used : SettableFuture(org.thoughtcrime.securesms.util.concurrent.SettableFuture) SessionDescription(org.webrtc.SessionDescription) ExecutionException(java.util.concurrent.ExecutionException) SdpObserver(org.webrtc.SdpObserver)

Example 22 with SettableFuture

use of org.thoughtcrime.securesms.util.concurrent.SettableFuture in project Signal-Android by WhisperSystems.

the class PeerConnectionWrapper method createAnswer.

public SessionDescription createAnswer(MediaConstraints mediaConstraints) throws PeerConnectionException {
    final SettableFuture<SessionDescription> future = new SettableFuture<>();
    peerConnection.createAnswer(new SdpObserver() {

        @Override
        public void onCreateSuccess(SessionDescription sdp) {
            future.set(sdp);
        }

        @Override
        public void onCreateFailure(String error) {
            future.setException(new PeerConnectionException(error));
        }

        @Override
        public void onSetSuccess() {
            throw new AssertionError();
        }

        @Override
        public void onSetFailure(String error) {
            throw new AssertionError();
        }
    }, mediaConstraints);
    try {
        return correctSessionDescription(future.get());
    } catch (InterruptedException e) {
        throw new AssertionError(e);
    } catch (ExecutionException e) {
        throw new PeerConnectionException(e);
    }
}
Also used : SettableFuture(org.thoughtcrime.securesms.util.concurrent.SettableFuture) SessionDescription(org.webrtc.SessionDescription) ExecutionException(java.util.concurrent.ExecutionException) SdpObserver(org.webrtc.SdpObserver)

Example 23 with SettableFuture

use of org.thoughtcrime.securesms.util.concurrent.SettableFuture in project Signal-Android by WhisperSystems.

the class ConversationActivity method sendMediaMessage.

private ListenableFuture<Void> sendMediaMessage(final boolean forceSms, String body, SlideDeck slideDeck, final long expiresIn, final int subscriptionId) throws InvalidMessageException {
    final SettableFuture<Void> future = new SettableFuture<>();
    final Context context = getApplicationContext();
    OutgoingMediaMessage outgoingMessage = new OutgoingMediaMessage(recipients, slideDeck, body, System.currentTimeMillis(), subscriptionId, expiresIn, distributionType);
    if (isSecureText && !forceSms) {
        outgoingMessage = new OutgoingSecureMediaMessage(outgoingMessage);
    }
    attachmentManager.clear();
    composeText.setText("");
    new AsyncTask<OutgoingMediaMessage, Void, Long>() {

        @Override
        protected Long doInBackground(OutgoingMediaMessage... messages) {
            return MessageSender.send(context, masterSecret, messages[0], threadId, forceSms);
        }

        @Override
        protected void onPostExecute(Long result) {
            sendComplete(result);
            future.set(null);
        }
    }.execute(outgoingMessage);
    return future;
}
Also used : SettableFuture(org.thoughtcrime.securesms.util.concurrent.SettableFuture) GroupContext(org.whispersystems.signalservice.internal.push.SignalServiceProtos.GroupContext) Context(android.content.Context) OutgoingSecureMediaMessage(org.thoughtcrime.securesms.mms.OutgoingSecureMediaMessage) OutgoingMediaMessage(org.thoughtcrime.securesms.mms.OutgoingMediaMessage)

Example 24 with SettableFuture

use of org.thoughtcrime.securesms.util.concurrent.SettableFuture in project Signal-Android by WhisperSystems.

the class ConversationActivity method saveDraft.

protected ListenableFuture<Long> saveDraft() {
    final SettableFuture<Long> future = new SettableFuture<>();
    if (this.recipients == null || this.recipients.isEmpty()) {
        future.set(threadId);
        return future;
    }
    final Drafts drafts = getDraftsForCurrentState();
    final long thisThreadId = this.threadId;
    final MasterSecret thisMasterSecret = this.masterSecret.parcelClone();
    final int thisDistributionType = this.distributionType;
    new AsyncTask<Long, Void, Long>() {

        @Override
        protected Long doInBackground(Long... params) {
            ThreadDatabase threadDatabase = DatabaseFactory.getThreadDatabase(ConversationActivity.this);
            DraftDatabase draftDatabase = DatabaseFactory.getDraftDatabase(ConversationActivity.this);
            long threadId = params[0];
            if (drafts.size() > 0) {
                if (threadId == -1)
                    threadId = threadDatabase.getThreadIdFor(getRecipients(), thisDistributionType);
                draftDatabase.insertDrafts(new MasterCipher(thisMasterSecret), threadId, drafts);
                threadDatabase.updateSnippet(threadId, drafts.getSnippet(ConversationActivity.this), drafts.getUriSnippet(ConversationActivity.this), System.currentTimeMillis(), Types.BASE_DRAFT_TYPE, true);
            } else if (threadId > 0) {
                threadDatabase.update(threadId, false);
            }
            return threadId;
        }

        @Override
        protected void onPostExecute(Long result) {
            future.set(result);
        }
    }.execute(thisThreadId);
    return future;
}
Also used : SettableFuture(org.thoughtcrime.securesms.util.concurrent.SettableFuture) MasterSecret(org.thoughtcrime.securesms.crypto.MasterSecret) DraftDatabase(org.thoughtcrime.securesms.database.DraftDatabase) MasterCipher(org.thoughtcrime.securesms.crypto.MasterCipher) ThreadDatabase(org.thoughtcrime.securesms.database.ThreadDatabase) Drafts(org.thoughtcrime.securesms.database.DraftDatabase.Drafts)

Example 25 with SettableFuture

use of org.thoughtcrime.securesms.util.concurrent.SettableFuture in project Signal-Android by WhisperSystems.

the class IdentityUtil method getRemoteIdentityKey.

@UiThread
public static ListenableFuture<Optional<IdentityKey>> getRemoteIdentityKey(final Context context, final MasterSecret masterSecret, final Recipient recipient) {
    final SettableFuture<Optional<IdentityKey>> future = new SettableFuture<>();
    new AsyncTask<Recipient, Void, Optional<IdentityKey>>() {

        @Override
        protected Optional<IdentityKey> doInBackground(Recipient... recipient) {
            SessionStore sessionStore = new TextSecureSessionStore(context, masterSecret);
            SignalProtocolAddress axolotlAddress = new SignalProtocolAddress(recipient[0].getNumber(), SignalServiceAddress.DEFAULT_DEVICE_ID);
            SessionRecord record = sessionStore.loadSession(axolotlAddress);
            if (record == null) {
                return Optional.absent();
            }
            return Optional.fromNullable(record.getSessionState().getRemoteIdentityKey());
        }

        @Override
        protected void onPostExecute(Optional<IdentityKey> result) {
            future.set(result);
        }
    }.execute(recipient);
    return future;
}
Also used : SettableFuture(org.thoughtcrime.securesms.util.concurrent.SettableFuture) IdentityKey(org.whispersystems.libsignal.IdentityKey) Optional(org.whispersystems.libsignal.util.guava.Optional) Recipient(org.thoughtcrime.securesms.recipients.Recipient) TextSecureSessionStore(org.thoughtcrime.securesms.crypto.storage.TextSecureSessionStore) SessionStore(org.whispersystems.libsignal.state.SessionStore) TextSecureSessionStore(org.thoughtcrime.securesms.crypto.storage.TextSecureSessionStore) SignalProtocolAddress(org.whispersystems.libsignal.SignalProtocolAddress) SessionRecord(org.whispersystems.libsignal.state.SessionRecord) UiThread(android.support.annotation.UiThread)

Aggregations

SettableFuture (org.thoughtcrime.securesms.util.concurrent.SettableFuture)37 Context (android.content.Context)9 Animation (android.view.animation.Animation)8 ExecutionException (java.util.concurrent.ExecutionException)8 SdpObserver (org.webrtc.SdpObserver)8 SessionDescription (org.webrtc.SessionDescription)8 ScaleAnimation (android.view.animation.ScaleAnimation)6 TranslateAnimation (android.view.animation.TranslateAnimation)6 Bitmap (android.graphics.Bitmap)4 NonNull (android.support.annotation.NonNull)4 OvershootInterpolator (android.view.animation.OvershootInterpolator)4 IOException (java.io.IOException)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 DraftDatabase (org.thoughtcrime.securesms.database.DraftDatabase)4 Drafts (org.thoughtcrime.securesms.database.DraftDatabase.Drafts)4 Recipient (org.thoughtcrime.securesms.recipients.Recipient)4 SuppressLint (android.annotation.SuppressLint)3 SpannableString (android.text.SpannableString)3 List (java.util.List)3 VoiceNoteDraft (org.thoughtcrime.securesms.components.voice.VoiceNoteDraft)3