Search in sources :

Example 1 with OpaqueMessage

use of org.whispersystems.signalservice.api.messages.calls.OpaqueMessage in project Signal-Android by WhisperSystems.

the class SignalServiceContent method createCallMessage.

private static SignalServiceCallMessage createCallMessage(SignalServiceProtos.CallMessage content) {
    boolean isMultiRing = content.getMultiRing();
    Integer destinationDeviceId = content.hasDestinationDeviceId() ? content.getDestinationDeviceId() : null;
    if (content.hasOffer()) {
        SignalServiceProtos.CallMessage.Offer offerContent = content.getOffer();
        return SignalServiceCallMessage.forOffer(new OfferMessage(offerContent.getId(), offerContent.hasSdp() ? offerContent.getSdp() : null, OfferMessage.Type.fromProto(offerContent.getType()), offerContent.hasOpaque() ? offerContent.getOpaque().toByteArray() : null), isMultiRing, destinationDeviceId);
    } else if (content.hasAnswer()) {
        SignalServiceProtos.CallMessage.Answer answerContent = content.getAnswer();
        return SignalServiceCallMessage.forAnswer(new AnswerMessage(answerContent.getId(), answerContent.hasSdp() ? answerContent.getSdp() : null, answerContent.hasOpaque() ? answerContent.getOpaque().toByteArray() : null), isMultiRing, destinationDeviceId);
    } else if (content.getIceUpdateCount() > 0) {
        List<IceUpdateMessage> iceUpdates = new LinkedList<>();
        for (SignalServiceProtos.CallMessage.IceUpdate iceUpdate : content.getIceUpdateList()) {
            iceUpdates.add(new IceUpdateMessage(iceUpdate.getId(), iceUpdate.hasOpaque() ? iceUpdate.getOpaque().toByteArray() : null, iceUpdate.hasSdp() ? iceUpdate.getSdp() : null));
        }
        return SignalServiceCallMessage.forIceUpdates(iceUpdates, isMultiRing, destinationDeviceId);
    } else if (content.hasLegacyHangup()) {
        SignalServiceProtos.CallMessage.Hangup hangup = content.getLegacyHangup();
        return SignalServiceCallMessage.forHangup(new HangupMessage(hangup.getId(), HangupMessage.Type.fromProto(hangup.getType()), hangup.getDeviceId(), content.hasLegacyHangup()), isMultiRing, destinationDeviceId);
    } else if (content.hasHangup()) {
        SignalServiceProtos.CallMessage.Hangup hangup = content.getHangup();
        return SignalServiceCallMessage.forHangup(new HangupMessage(hangup.getId(), HangupMessage.Type.fromProto(hangup.getType()), hangup.getDeviceId(), content.hasLegacyHangup()), isMultiRing, destinationDeviceId);
    } else if (content.hasBusy()) {
        SignalServiceProtos.CallMessage.Busy busy = content.getBusy();
        return SignalServiceCallMessage.forBusy(new BusyMessage(busy.getId()), isMultiRing, destinationDeviceId);
    } else if (content.hasOpaque()) {
        SignalServiceProtos.CallMessage.Opaque opaque = content.getOpaque();
        return SignalServiceCallMessage.forOpaque(new OpaqueMessage(opaque.getData().toByteArray(), null), isMultiRing, destinationDeviceId);
    }
    return SignalServiceCallMessage.empty();
}
Also used : IceUpdateMessage(org.whispersystems.signalservice.api.messages.calls.IceUpdateMessage) SignalServiceCallMessage(org.whispersystems.signalservice.api.messages.calls.SignalServiceCallMessage) AnswerMessage(org.whispersystems.signalservice.api.messages.calls.AnswerMessage) LinkedList(java.util.LinkedList) SignalServiceProtos(org.whispersystems.signalservice.internal.push.SignalServiceProtos) HangupMessage(org.whispersystems.signalservice.api.messages.calls.HangupMessage) OfferMessage(org.whispersystems.signalservice.api.messages.calls.OfferMessage) BusyMessage(org.whispersystems.signalservice.api.messages.calls.BusyMessage) OpaqueMessage(org.whispersystems.signalservice.api.messages.calls.OpaqueMessage)

Example 2 with OpaqueMessage

use of org.whispersystems.signalservice.api.messages.calls.OpaqueMessage in project Signal-Android by WhisperSystems.

the class SignalCallManager method onSendCallMessageToGroup.

@Override
public void onSendCallMessageToGroup(@NonNull byte[] groupIdBytes, @NonNull byte[] message, @NonNull CallManager.CallMessageUrgency urgency) {
    Log.i(TAG, "onSendCallMessageToGroup():");
    networkExecutor.execute(() -> {
        try {
            GroupId groupId = GroupId.v2(new GroupIdentifier(groupIdBytes));
            List<Recipient> recipients = SignalDatabase.groups().getGroupMembers(groupId, GroupDatabase.MemberSet.FULL_MEMBERS_EXCLUDING_SELF);
            recipients = RecipientUtil.getEligibleForSending((recipients.stream().map(Recipient::resolve).filter(r -> !r.isBlocked()).collect(Collectors.toList())));
            OpaqueMessage opaqueMessage = new OpaqueMessage(message, getUrgencyFromCallUrgency(urgency));
            SignalServiceCallMessage callMessage = SignalServiceCallMessage.forOutgoingGroupOpaque(groupId.getDecodedId(), System.currentTimeMillis(), opaqueMessage, true, null);
            RecipientAccessList accessList = new RecipientAccessList(recipients);
            List<SendMessageResult> results = GroupSendUtil.sendCallMessage(context, groupId.requireV2(), recipients, callMessage);
            Set<RecipientId> identifyFailureRecipientIds = results.stream().filter(result -> result.getIdentityFailure() != null).map(result -> accessList.requireIdByAddress(result.getAddress())).collect(Collectors.toSet());
            if (Util.hasItems(identifyFailureRecipientIds)) {
                process((s, p) -> p.handleGroupMessageSentError(s, identifyFailureRecipientIds, UNTRUSTED_IDENTITY));
                RetrieveProfileJob.enqueue(identifyFailureRecipientIds);
            }
        } catch (UntrustedIdentityException | IOException | InvalidInputException e) {
            Log.w(TAG, "onSendCallMessageToGroup failed", e);
        }
    });
}
Also used : SignalStore(org.thoughtcrime.securesms.keyvalue.SignalStore) SignalAudioManager(org.thoughtcrime.securesms.webrtc.audio.SignalAudioManager) SignalServiceAccountManager(org.whispersystems.signalservice.api.SignalServiceAccountManager) NetworkRoute(org.signal.ringrtc.NetworkRoute) BubbleUtil(org.thoughtcrime.securesms.util.BubbleUtil) SendMessageResult(org.whispersystems.signalservice.api.messages.SendMessageResult) CallingResponse(org.whispersystems.signalservice.api.messages.calls.CallingResponse) TurnServerInfo(org.whispersystems.signalservice.api.messages.calls.TurnServerInfo) NonNull(androidx.annotation.NonNull) RecipientUtil(org.thoughtcrime.securesms.recipients.RecipientUtil) CallException(org.signal.ringrtc.CallException) WebRtcCallActivity(org.thoughtcrime.securesms.WebRtcCallActivity) CallManager(org.signal.ringrtc.CallManager) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) NetworkUtil(org.thoughtcrime.securesms.util.NetworkUtil) Recipient(org.thoughtcrime.securesms.recipients.Recipient) IDLE(org.thoughtcrime.securesms.events.WebRtcViewModel.GroupCallState.IDLE) SignalExecutors(org.signal.core.util.concurrent.SignalExecutors) WebRtcUtil.getUrgencyFromCallUrgency(org.thoughtcrime.securesms.service.webrtc.WebRtcUtil.getUrgencyFromCallUrgency) GroupExternalCredential(org.signal.storageservice.protos.groups.GroupExternalCredential) ACI(org.whispersystems.signalservice.api.push.ACI) HttpHeader(org.signal.ringrtc.HttpHeader) ApplicationDependencies(org.thoughtcrime.securesms.dependencies.ApplicationDependencies) Collection(java.util.Collection) GroupCallUpdateSendJob(org.thoughtcrime.securesms.jobs.GroupCallUpdateSendJob) Set(java.util.Set) UnidentifiedAccessUtil(org.thoughtcrime.securesms.crypto.UnidentifiedAccessUtil) UUID(java.util.UUID) GroupDatabase(org.thoughtcrime.securesms.database.GroupDatabase) UNTRUSTED_IDENTITY(org.thoughtcrime.securesms.events.WebRtcViewModel.State.UNTRUSTED_IDENTITY) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) InvalidInputException(org.signal.zkgroup.InvalidInputException) GroupCall(org.signal.ringrtc.GroupCall) Log(org.signal.core.util.logging.Log) List(java.util.List) Nullable(androidx.annotation.Nullable) Application(android.app.Application) GroupId(org.thoughtcrime.securesms.groups.GroupId) CallId(org.signal.ringrtc.CallId) CameraEventListener(org.thoughtcrime.securesms.ringrtc.CameraEventListener) Context(android.content.Context) RecipientAccessList(org.thoughtcrime.securesms.util.RecipientAccessList) SignalDatabase(org.thoughtcrime.securesms.database.SignalDatabase) RemotePeer(org.thoughtcrime.securesms.ringrtc.RemotePeer) Stream(com.annimon.stream.Stream) Remote(org.signal.ringrtc.Remote) Util(org.thoughtcrime.securesms.util.Util) VerificationFailedException(org.signal.zkgroup.VerificationFailedException) Intent(android.content.Intent) AppForegroundObserver(org.thoughtcrime.securesms.util.AppForegroundObserver) RetrieveProfileJob(org.thoughtcrime.securesms.jobs.RetrieveProfileJob) NETWORK_FAILURE(org.thoughtcrime.securesms.events.WebRtcViewModel.State.NETWORK_FAILURE) OfferMessage(org.whispersystems.signalservice.api.messages.calls.OfferMessage) LockManager(org.thoughtcrime.securesms.webrtc.locks.LockManager) TextSecurePreferences(org.thoughtcrime.securesms.util.TextSecurePreferences) OpaqueMessage(org.whispersystems.signalservice.api.messages.calls.OpaqueMessage) GroupManager(org.thoughtcrime.securesms.groups.GroupManager) CameraState(org.thoughtcrime.securesms.ringrtc.CameraState) Pair(org.whispersystems.libsignal.util.Pair) EventBus(org.greenrobot.eventbus.EventBus) SignalServiceCallMessage(org.whispersystems.signalservice.api.messages.calls.SignalServiceCallMessage) Build(android.os.Build) LinkedList(java.util.LinkedList) GroupSendUtil(org.thoughtcrime.securesms.messages.GroupSendUtil) WebRtcServiceState(org.thoughtcrime.securesms.service.webrtc.state.WebRtcServiceState) ExecutorService(java.util.concurrent.ExecutorService) SignalServiceMessageSender(org.whispersystems.signalservice.api.SignalServiceMessageSender) PeerConnection(org.webrtc.PeerConnection) Executor(java.util.concurrent.Executor) WebRtcViewModel(org.thoughtcrime.securesms.events.WebRtcViewModel) IOException(java.io.IOException) NO_SUCH_USER(org.thoughtcrime.securesms.events.WebRtcViewModel.State.NO_SUCH_USER) GroupCallPeekEvent(org.thoughtcrime.securesms.events.GroupCallPeekEvent) Optional(org.whispersystems.libsignal.util.guava.Optional) UnregisteredUserException(org.whispersystems.signalservice.api.push.exceptions.UnregisteredUserException) GroupIdentifier(org.signal.zkgroup.groups.GroupIdentifier) UntrustedIdentityException(org.whispersystems.signalservice.api.crypto.UntrustedIdentityException) CALL_INCOMING(org.thoughtcrime.securesms.events.WebRtcViewModel.State.CALL_INCOMING) ResultReceiver(android.os.ResultReceiver) Collections(java.util.Collections) InvalidInputException(org.signal.zkgroup.InvalidInputException) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) UntrustedIdentityException(org.whispersystems.signalservice.api.crypto.UntrustedIdentityException) Recipient(org.thoughtcrime.securesms.recipients.Recipient) IOException(java.io.IOException) SendMessageResult(org.whispersystems.signalservice.api.messages.SendMessageResult) GroupId(org.thoughtcrime.securesms.groups.GroupId) GroupIdentifier(org.signal.zkgroup.groups.GroupIdentifier) SignalServiceCallMessage(org.whispersystems.signalservice.api.messages.calls.SignalServiceCallMessage) RecipientAccessList(org.thoughtcrime.securesms.util.RecipientAccessList) OpaqueMessage(org.whispersystems.signalservice.api.messages.calls.OpaqueMessage)

Example 3 with OpaqueMessage

use of org.whispersystems.signalservice.api.messages.calls.OpaqueMessage in project Signal-Android by WhisperSystems.

the class SignalCallManager method onSendCallMessage.

@Override
public void onSendCallMessage(@NonNull UUID uuid, @NonNull byte[] bytes, @NonNull CallManager.CallMessageUrgency urgency) {
    Log.i(TAG, "onSendCallMessage():");
    OpaqueMessage opaqueMessage = new OpaqueMessage(bytes, getUrgencyFromCallUrgency(urgency));
    SignalServiceCallMessage callMessage = SignalServiceCallMessage.forOpaque(opaqueMessage, true, null);
    networkExecutor.execute(() -> {
        Recipient recipient = Recipient.resolved(RecipientId.from(ACI.from(uuid), null));
        if (recipient.isBlocked()) {
            return;
        }
        try {
            messageSender.sendCallMessage(RecipientUtil.toSignalServiceAddress(context, recipient), recipient.isSelf() ? Optional.absent() : UnidentifiedAccessUtil.getAccessFor(context, recipient), callMessage);
        } catch (UntrustedIdentityException e) {
            Log.i(TAG, "sendOpaqueCallMessage onFailure: ", e);
            RetrieveProfileJob.enqueue(recipient.getId());
            process((s, p) -> p.handleGroupMessageSentError(s, Collections.singletonList(recipient.getId()), UNTRUSTED_IDENTITY));
        } catch (IOException e) {
            Log.i(TAG, "sendOpaqueCallMessage onFailure: ", e);
            process((s, p) -> p.handleGroupMessageSentError(s, Collections.singletonList(recipient.getId()), NETWORK_FAILURE));
        }
    });
}
Also used : SignalStore(org.thoughtcrime.securesms.keyvalue.SignalStore) SignalAudioManager(org.thoughtcrime.securesms.webrtc.audio.SignalAudioManager) SignalServiceAccountManager(org.whispersystems.signalservice.api.SignalServiceAccountManager) NetworkRoute(org.signal.ringrtc.NetworkRoute) BubbleUtil(org.thoughtcrime.securesms.util.BubbleUtil) SendMessageResult(org.whispersystems.signalservice.api.messages.SendMessageResult) CallingResponse(org.whispersystems.signalservice.api.messages.calls.CallingResponse) TurnServerInfo(org.whispersystems.signalservice.api.messages.calls.TurnServerInfo) NonNull(androidx.annotation.NonNull) RecipientUtil(org.thoughtcrime.securesms.recipients.RecipientUtil) CallException(org.signal.ringrtc.CallException) WebRtcCallActivity(org.thoughtcrime.securesms.WebRtcCallActivity) CallManager(org.signal.ringrtc.CallManager) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) NetworkUtil(org.thoughtcrime.securesms.util.NetworkUtil) Recipient(org.thoughtcrime.securesms.recipients.Recipient) IDLE(org.thoughtcrime.securesms.events.WebRtcViewModel.GroupCallState.IDLE) SignalExecutors(org.signal.core.util.concurrent.SignalExecutors) WebRtcUtil.getUrgencyFromCallUrgency(org.thoughtcrime.securesms.service.webrtc.WebRtcUtil.getUrgencyFromCallUrgency) GroupExternalCredential(org.signal.storageservice.protos.groups.GroupExternalCredential) ACI(org.whispersystems.signalservice.api.push.ACI) HttpHeader(org.signal.ringrtc.HttpHeader) ApplicationDependencies(org.thoughtcrime.securesms.dependencies.ApplicationDependencies) Collection(java.util.Collection) GroupCallUpdateSendJob(org.thoughtcrime.securesms.jobs.GroupCallUpdateSendJob) Set(java.util.Set) UnidentifiedAccessUtil(org.thoughtcrime.securesms.crypto.UnidentifiedAccessUtil) UUID(java.util.UUID) GroupDatabase(org.thoughtcrime.securesms.database.GroupDatabase) UNTRUSTED_IDENTITY(org.thoughtcrime.securesms.events.WebRtcViewModel.State.UNTRUSTED_IDENTITY) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) InvalidInputException(org.signal.zkgroup.InvalidInputException) GroupCall(org.signal.ringrtc.GroupCall) Log(org.signal.core.util.logging.Log) List(java.util.List) Nullable(androidx.annotation.Nullable) Application(android.app.Application) GroupId(org.thoughtcrime.securesms.groups.GroupId) CallId(org.signal.ringrtc.CallId) CameraEventListener(org.thoughtcrime.securesms.ringrtc.CameraEventListener) Context(android.content.Context) RecipientAccessList(org.thoughtcrime.securesms.util.RecipientAccessList) SignalDatabase(org.thoughtcrime.securesms.database.SignalDatabase) RemotePeer(org.thoughtcrime.securesms.ringrtc.RemotePeer) Stream(com.annimon.stream.Stream) Remote(org.signal.ringrtc.Remote) Util(org.thoughtcrime.securesms.util.Util) VerificationFailedException(org.signal.zkgroup.VerificationFailedException) Intent(android.content.Intent) AppForegroundObserver(org.thoughtcrime.securesms.util.AppForegroundObserver) RetrieveProfileJob(org.thoughtcrime.securesms.jobs.RetrieveProfileJob) NETWORK_FAILURE(org.thoughtcrime.securesms.events.WebRtcViewModel.State.NETWORK_FAILURE) OfferMessage(org.whispersystems.signalservice.api.messages.calls.OfferMessage) LockManager(org.thoughtcrime.securesms.webrtc.locks.LockManager) TextSecurePreferences(org.thoughtcrime.securesms.util.TextSecurePreferences) OpaqueMessage(org.whispersystems.signalservice.api.messages.calls.OpaqueMessage) GroupManager(org.thoughtcrime.securesms.groups.GroupManager) CameraState(org.thoughtcrime.securesms.ringrtc.CameraState) Pair(org.whispersystems.libsignal.util.Pair) EventBus(org.greenrobot.eventbus.EventBus) SignalServiceCallMessage(org.whispersystems.signalservice.api.messages.calls.SignalServiceCallMessage) Build(android.os.Build) LinkedList(java.util.LinkedList) GroupSendUtil(org.thoughtcrime.securesms.messages.GroupSendUtil) WebRtcServiceState(org.thoughtcrime.securesms.service.webrtc.state.WebRtcServiceState) ExecutorService(java.util.concurrent.ExecutorService) SignalServiceMessageSender(org.whispersystems.signalservice.api.SignalServiceMessageSender) PeerConnection(org.webrtc.PeerConnection) Executor(java.util.concurrent.Executor) WebRtcViewModel(org.thoughtcrime.securesms.events.WebRtcViewModel) IOException(java.io.IOException) NO_SUCH_USER(org.thoughtcrime.securesms.events.WebRtcViewModel.State.NO_SUCH_USER) GroupCallPeekEvent(org.thoughtcrime.securesms.events.GroupCallPeekEvent) Optional(org.whispersystems.libsignal.util.guava.Optional) UnregisteredUserException(org.whispersystems.signalservice.api.push.exceptions.UnregisteredUserException) GroupIdentifier(org.signal.zkgroup.groups.GroupIdentifier) UntrustedIdentityException(org.whispersystems.signalservice.api.crypto.UntrustedIdentityException) CALL_INCOMING(org.thoughtcrime.securesms.events.WebRtcViewModel.State.CALL_INCOMING) ResultReceiver(android.os.ResultReceiver) Collections(java.util.Collections) UntrustedIdentityException(org.whispersystems.signalservice.api.crypto.UntrustedIdentityException) SignalServiceCallMessage(org.whispersystems.signalservice.api.messages.calls.SignalServiceCallMessage) Recipient(org.thoughtcrime.securesms.recipients.Recipient) IOException(java.io.IOException) OpaqueMessage(org.whispersystems.signalservice.api.messages.calls.OpaqueMessage)

Example 4 with OpaqueMessage

use of org.whispersystems.signalservice.api.messages.calls.OpaqueMessage in project Signal-Android by WhisperSystems.

the class SignalServiceMessageSender method createCallContent.

private Content createCallContent(SignalServiceCallMessage callMessage) {
    Content.Builder container = Content.newBuilder();
    CallMessage.Builder builder = CallMessage.newBuilder();
    if (callMessage.getOfferMessage().isPresent()) {
        OfferMessage offer = callMessage.getOfferMessage().get();
        CallMessage.Offer.Builder offerBuilder = CallMessage.Offer.newBuilder().setId(offer.getId()).setType(offer.getType().getProtoType());
        if (offer.getOpaque() != null) {
            offerBuilder.setOpaque(ByteString.copyFrom(offer.getOpaque()));
        }
        if (offer.getSdp() != null) {
            offerBuilder.setSdp(offer.getSdp());
        }
        builder.setOffer(offerBuilder);
    } else if (callMessage.getAnswerMessage().isPresent()) {
        AnswerMessage answer = callMessage.getAnswerMessage().get();
        CallMessage.Answer.Builder answerBuilder = CallMessage.Answer.newBuilder().setId(answer.getId());
        if (answer.getOpaque() != null) {
            answerBuilder.setOpaque(ByteString.copyFrom(answer.getOpaque()));
        }
        if (answer.getSdp() != null) {
            answerBuilder.setSdp(answer.getSdp());
        }
        builder.setAnswer(answerBuilder);
    } else if (callMessage.getIceUpdateMessages().isPresent()) {
        List<IceUpdateMessage> updates = callMessage.getIceUpdateMessages().get();
        for (IceUpdateMessage update : updates) {
            CallMessage.IceUpdate.Builder iceBuilder = CallMessage.IceUpdate.newBuilder().setId(update.getId()).setMid("audio").setLine(0);
            if (update.getOpaque() != null) {
                iceBuilder.setOpaque(ByteString.copyFrom(update.getOpaque()));
            }
            if (update.getSdp() != null) {
                iceBuilder.setSdp(update.getSdp());
            }
            builder.addIceUpdate(iceBuilder);
        }
    } else if (callMessage.getHangupMessage().isPresent()) {
        CallMessage.Hangup.Type protoType = callMessage.getHangupMessage().get().getType().getProtoType();
        CallMessage.Hangup.Builder builderForHangup = CallMessage.Hangup.newBuilder().setType(protoType).setId(callMessage.getHangupMessage().get().getId());
        if (protoType != CallMessage.Hangup.Type.HANGUP_NORMAL) {
            builderForHangup.setDeviceId(callMessage.getHangupMessage().get().getDeviceId());
        }
        if (callMessage.getHangupMessage().get().isLegacy()) {
            builder.setLegacyHangup(builderForHangup);
        } else {
            builder.setHangup(builderForHangup);
        }
    } else if (callMessage.getBusyMessage().isPresent()) {
        builder.setBusy(CallMessage.Busy.newBuilder().setId(callMessage.getBusyMessage().get().getId()));
    } else if (callMessage.getOpaqueMessage().isPresent()) {
        OpaqueMessage opaqueMessage = callMessage.getOpaqueMessage().get();
        ByteString data = ByteString.copyFrom(opaqueMessage.getOpaque());
        CallMessage.Opaque.Urgency urgency = opaqueMessage.getUrgency().toProto();
        builder.setOpaque(CallMessage.Opaque.newBuilder().setData(data).setUrgency(urgency));
    }
    builder.setMultiRing(callMessage.isMultiRing());
    if (callMessage.getDestinationDeviceId().isPresent()) {
        builder.setDestinationDeviceId(callMessage.getDestinationDeviceId().get());
    }
    container.setCallMessage(builder);
    return container.build();
}
Also used : IceUpdateMessage(org.whispersystems.signalservice.api.messages.calls.IceUpdateMessage) SignalServiceCallMessage(org.whispersystems.signalservice.api.messages.calls.SignalServiceCallMessage) CallMessage(org.whispersystems.signalservice.internal.push.SignalServiceProtos.CallMessage) ByteString(com.google.protobuf.ByteString) SignalGroupSessionBuilder(org.whispersystems.signalservice.api.crypto.SignalGroupSessionBuilder) GroupSessionBuilder(org.whispersystems.libsignal.groups.GroupSessionBuilder) SessionBuilder(org.whispersystems.libsignal.SessionBuilder) SignalSessionBuilder(org.whispersystems.signalservice.api.crypto.SignalSessionBuilder) AnswerMessage(org.whispersystems.signalservice.api.messages.calls.AnswerMessage) EnvelopeContent(org.whispersystems.signalservice.api.crypto.EnvelopeContent) PlaintextContent(org.whispersystems.libsignal.protocol.PlaintextContent) Content(org.whispersystems.signalservice.internal.push.SignalServiceProtos.Content) OfferMessage(org.whispersystems.signalservice.api.messages.calls.OfferMessage) OpaqueMessage(org.whispersystems.signalservice.api.messages.calls.OpaqueMessage)

Example 5 with OpaqueMessage

use of org.whispersystems.signalservice.api.messages.calls.OpaqueMessage in project Signal-Android by signalapp.

the class SignalServiceMessageSender method createCallContent.

private Content createCallContent(SignalServiceCallMessage callMessage) {
    Content.Builder container = Content.newBuilder();
    CallMessage.Builder builder = CallMessage.newBuilder();
    if (callMessage.getOfferMessage().isPresent()) {
        OfferMessage offer = callMessage.getOfferMessage().get();
        CallMessage.Offer.Builder offerBuilder = CallMessage.Offer.newBuilder().setId(offer.getId()).setType(offer.getType().getProtoType());
        if (offer.getOpaque() != null) {
            offerBuilder.setOpaque(ByteString.copyFrom(offer.getOpaque()));
        }
        if (offer.getSdp() != null) {
            offerBuilder.setSdp(offer.getSdp());
        }
        builder.setOffer(offerBuilder);
    } else if (callMessage.getAnswerMessage().isPresent()) {
        AnswerMessage answer = callMessage.getAnswerMessage().get();
        CallMessage.Answer.Builder answerBuilder = CallMessage.Answer.newBuilder().setId(answer.getId());
        if (answer.getOpaque() != null) {
            answerBuilder.setOpaque(ByteString.copyFrom(answer.getOpaque()));
        }
        if (answer.getSdp() != null) {
            answerBuilder.setSdp(answer.getSdp());
        }
        builder.setAnswer(answerBuilder);
    } else if (callMessage.getIceUpdateMessages().isPresent()) {
        List<IceUpdateMessage> updates = callMessage.getIceUpdateMessages().get();
        for (IceUpdateMessage update : updates) {
            CallMessage.IceUpdate.Builder iceBuilder = CallMessage.IceUpdate.newBuilder().setId(update.getId()).setMid("audio").setLine(0);
            if (update.getOpaque() != null) {
                iceBuilder.setOpaque(ByteString.copyFrom(update.getOpaque()));
            }
            if (update.getSdp() != null) {
                iceBuilder.setSdp(update.getSdp());
            }
            builder.addIceUpdate(iceBuilder);
        }
    } else if (callMessage.getHangupMessage().isPresent()) {
        CallMessage.Hangup.Type protoType = callMessage.getHangupMessage().get().getType().getProtoType();
        CallMessage.Hangup.Builder builderForHangup = CallMessage.Hangup.newBuilder().setType(protoType).setId(callMessage.getHangupMessage().get().getId());
        if (protoType != CallMessage.Hangup.Type.HANGUP_NORMAL) {
            builderForHangup.setDeviceId(callMessage.getHangupMessage().get().getDeviceId());
        }
        if (callMessage.getHangupMessage().get().isLegacy()) {
            builder.setLegacyHangup(builderForHangup);
        } else {
            builder.setHangup(builderForHangup);
        }
    } else if (callMessage.getBusyMessage().isPresent()) {
        builder.setBusy(CallMessage.Busy.newBuilder().setId(callMessage.getBusyMessage().get().getId()));
    } else if (callMessage.getOpaqueMessage().isPresent()) {
        OpaqueMessage opaqueMessage = callMessage.getOpaqueMessage().get();
        ByteString data = ByteString.copyFrom(opaqueMessage.getOpaque());
        CallMessage.Opaque.Urgency urgency = opaqueMessage.getUrgency().toProto();
        builder.setOpaque(CallMessage.Opaque.newBuilder().setData(data).setUrgency(urgency));
    }
    builder.setMultiRing(callMessage.isMultiRing());
    if (callMessage.getDestinationDeviceId().isPresent()) {
        builder.setDestinationDeviceId(callMessage.getDestinationDeviceId().get());
    }
    container.setCallMessage(builder);
    return container.build();
}
Also used : IceUpdateMessage(org.whispersystems.signalservice.api.messages.calls.IceUpdateMessage) SignalServiceCallMessage(org.whispersystems.signalservice.api.messages.calls.SignalServiceCallMessage) CallMessage(org.whispersystems.signalservice.internal.push.SignalServiceProtos.CallMessage) ByteString(com.google.protobuf.ByteString) SignalGroupSessionBuilder(org.whispersystems.signalservice.api.crypto.SignalGroupSessionBuilder) GroupSessionBuilder(org.whispersystems.libsignal.groups.GroupSessionBuilder) SessionBuilder(org.whispersystems.libsignal.SessionBuilder) SignalSessionBuilder(org.whispersystems.signalservice.api.crypto.SignalSessionBuilder) AnswerMessage(org.whispersystems.signalservice.api.messages.calls.AnswerMessage) EnvelopeContent(org.whispersystems.signalservice.api.crypto.EnvelopeContent) PlaintextContent(org.whispersystems.libsignal.protocol.PlaintextContent) Content(org.whispersystems.signalservice.internal.push.SignalServiceProtos.Content) OfferMessage(org.whispersystems.signalservice.api.messages.calls.OfferMessage) OpaqueMessage(org.whispersystems.signalservice.api.messages.calls.OpaqueMessage)

Aggregations

OfferMessage (org.whispersystems.signalservice.api.messages.calls.OfferMessage)8 OpaqueMessage (org.whispersystems.signalservice.api.messages.calls.OpaqueMessage)8 SignalServiceCallMessage (org.whispersystems.signalservice.api.messages.calls.SignalServiceCallMessage)8 LinkedList (java.util.LinkedList)6 Application (android.app.Application)4 Context (android.content.Context)4 Intent (android.content.Intent)4 Build (android.os.Build)4 ResultReceiver (android.os.ResultReceiver)4 NonNull (androidx.annotation.NonNull)4 Nullable (androidx.annotation.Nullable)4 Stream (com.annimon.stream.Stream)4 IOException (java.io.IOException)4 Collection (java.util.Collection)4 Collections (java.util.Collections)4 List (java.util.List)4 Set (java.util.Set)4 UUID (java.util.UUID)4 Executor (java.util.concurrent.Executor)4 ExecutorService (java.util.concurrent.ExecutorService)4