org.whispersystems.signalservice.api.messages.calls.OfferMessage Java Examples

The following examples show how to use org.whispersystems.signalservice.api.messages.calls.OfferMessage. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WebRtcCallService.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
private void handleOutgoingCall(Intent intent) {
  RemotePeer remotePeer = getRemotePeer(intent);

  if (remotePeer.getState() != CallState.IDLE) {
    throw new IllegalStateException("Dialing from non-idle?");
  }

  Log.i(TAG, "handleOutgoingCall():");
  EventBus.getDefault().removeStickyEvent(WebRtcViewModel.class);

  initializeVideo();

  OfferMessage.Type         offerType     = OfferMessage.Type.fromCode(intent.getStringExtra(EXTRA_OFFER_TYPE));
  CallManager.CallMediaType callMediaType = getCallMediaTypeFromOfferType(offerType);

  try {
    callManager.call(remotePeer, callMediaType);
  } catch  (CallException e) {
    callFailure("Unable to create outgoing call: ", e);
  }
}
 
Example #2
Source File: WebRtcCallService.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
private void handleSendOffer(Intent intent) {
  RemotePeer        remotePeer   = getRemotePeer(intent);
  CallId            callId       = getCallId(intent);
  Integer           remoteDevice = intent.getIntExtra(EXTRA_REMOTE_DEVICE, -1);
  boolean           broadcast    = intent.getBooleanExtra(EXTRA_BROADCAST, false);
  String            offer        = intent.getStringExtra(EXTRA_OFFER_DESCRIPTION);
  OfferMessage.Type offerType    = OfferMessage.Type.fromCode(intent.getStringExtra(EXTRA_OFFER_TYPE));

  Log.i(TAG, "handleSendOffer: id: " + callId.format(remoteDevice));

  if (FeatureFlags.profileForCalling() && remotePeer.getRecipient().resolve().getProfileKey() == null) {
    offer     = "";
    offerType = OfferMessage.Type.NEED_PERMISSION;
  }

  OfferMessage             offerMessage        = new OfferMessage(callId.longValue(), offer, offerType);
  Integer                  destinationDeviceId = broadcast ? null : remoteDevice;
  SignalServiceCallMessage callMessage         = SignalServiceCallMessage.forOffer(offerMessage, true, destinationDeviceId);

  sendCallMessage(remotePeer, callMessage);
}
 
Example #3
Source File: PushProcessMessageJob.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
private void handleCallOfferMessage(@NonNull SignalServiceContent content,
                                    @NonNull OfferMessage message,
                                    @NonNull Optional<Long> smsMessageId)
{
  Log.i(TAG, "handleCallOfferMessage...");

  if (smsMessageId.isPresent()) {
    SmsDatabase database = DatabaseFactory.getSmsDatabase(context);
    database.markAsMissedCall(smsMessageId.get());
  } else {
    Intent     intent     = new Intent(context, WebRtcCallService.class);
    RemotePeer remotePeer = new RemotePeer(Recipient.externalPush(context, content.getSender()).getId());

    intent.setAction(WebRtcCallService.ACTION_RECEIVE_OFFER)
          .putExtra(WebRtcCallService.EXTRA_CALL_ID,           message.getId())
          .putExtra(WebRtcCallService.EXTRA_REMOTE_PEER,       remotePeer)
          .putExtra(WebRtcCallService.EXTRA_REMOTE_DEVICE,     content.getSenderDevice())
          .putExtra(WebRtcCallService.EXTRA_OFFER_DESCRIPTION, message.getDescription())
          .putExtra(WebRtcCallService.EXTRA_TIMESTAMP,         content.getTimestamp())
          .putExtra(WebRtcCallService.EXTRA_OFFER_TYPE,        message.getType().getCode())
          .putExtra(WebRtcCallService.EXTRA_MULTI_RING,        content.getCallMessage().get().isMultiRing());

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) context.startForegroundService(intent);
    else                                                context.startService(intent);
  }
}
 
Example #4
Source File: PushDecryptJob.java    From bcm-android with GNU General Public License v3.0 6 votes vote down vote up
private void handleCallOfferMessage(@NonNull SignalServiceProtos.Envelope envelope,
                                    @NonNull OfferMessage message) {
    ALog.logForSecret(TAG, "handleCallOfferMessage:" + message.getDescription());

    try {
        Intent intent = new Intent(context, WebRtcCallService.class);
        intent.setAction(WebRtcCallService.ACTION_INCOMING_CALL);
        intent.putExtra(WebRtcCallService.EXTRA_CALL_ID, message.getId());
        CameraState.Direction callType = message.callType()== SignalServiceProtos.CallMessage.Offer.CallType.VIDEO? CameraState.Direction.FRONT:CameraState.Direction.NONE;
        intent.putExtra(WebRtcCallService.EXTRA_CALL_TYPE, callType.toString());
        intent.putExtra(WebRtcCallService.EXTRA_REMOTE_ADDRESS, Address.from(accountContext, envelope.getSource()));
        intent.putExtra(WebRtcCallService.EXTRA_REMOTE_DESCRIPTION, message.getDescription());
        intent.putExtra(WebRtcCallService.EXTRA_TIMESTAMP, envelope.getTimestamp());
        intent.putExtra(ARouterConstants.PARAM.PARAM_ACCOUNT_CONTEXT, accountContext);
        AppUtilKotlinKt.startForegroundServiceCompat(context, intent);
    } catch (Exception ex) {
        ALog.e(TAG, "handleCallOfferMessage error", ex);
    }
}
 
Example #5
Source File: SignalServiceCipher.java    From libsignal-service-java with GNU General Public License v3.0 6 votes vote down vote up
private SignalServiceCallMessage createCallMessage(CallMessage content) {
  if (content.hasOffer()) {
    CallMessage.Offer offerContent = content.getOffer();
    return SignalServiceCallMessage.forOffer(new OfferMessage(offerContent.getId(), offerContent.getDescription()));
  } else if (content.hasAnswer()) {
    CallMessage.Answer answerContent = content.getAnswer();
    return SignalServiceCallMessage.forAnswer(new AnswerMessage(answerContent.getId(), answerContent.getDescription()));
  } else if (content.getIceUpdateCount() > 0) {
    List<IceUpdateMessage> iceUpdates = new LinkedList<>();

    for (CallMessage.IceUpdate iceUpdate : content.getIceUpdateList()) {
      iceUpdates.add(new IceUpdateMessage(iceUpdate.getId(), iceUpdate.getSdpMid(), iceUpdate.getSdpMLineIndex(), iceUpdate.getSdp()));
    }

    return SignalServiceCallMessage.forIceUpdates(iceUpdates);
  } else if (content.hasHangup()) {
    CallMessage.Hangup hangup = content.getHangup();
    return SignalServiceCallMessage.forHangup(new HangupMessage(hangup.getId()));
  } else if (content.hasBusy()) {
    CallMessage.Busy busy = content.getBusy();
    return SignalServiceCallMessage.forBusy(new BusyMessage(busy.getId()));
  }

  return SignalServiceCallMessage.empty();
}
 
Example #6
Source File: WebRtcCallService.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
private void handleReceivedOffer(Intent intent) {
  CallId            callId       = getCallId(intent);
  RemotePeer        remotePeer   = getRemotePeer(intent);
  Integer           remoteDevice = intent.getIntExtra(EXTRA_REMOTE_DEVICE, -1);
  String            offer        = intent.getStringExtra(EXTRA_OFFER_DESCRIPTION);
  Long              timeStamp    = intent.getLongExtra(EXTRA_TIMESTAMP, -1);
  OfferMessage.Type offerType    = OfferMessage.Type.fromCode(intent.getStringExtra(EXTRA_OFFER_TYPE));
  boolean           isMultiRing  = intent.getBooleanExtra(EXTRA_MULTI_RING, false);

  Log.i(TAG, "handleReceivedOffer(): id: " + callId.format(remoteDevice));

  if (TelephonyUtil.isAnyPstnLineBusy(this)) {
    Log.i(TAG, "handleReceivedOffer(): PSTN line is busy.");
    intent.putExtra(EXTRA_BROADCAST, true);
    handleSendBusy(intent);
    insertMissedCall(remotePeer, true);
    return;
  }

  if (offerType == OfferMessage.Type.NEED_PERMISSION || FeatureFlags.profileForCalling() && !remotePeer.getRecipient().resolve().isProfileSharing()) {
    Log.i(TAG, "handleReceivedOffer(): Caller is untrusted.");
    intent.putExtra(EXTRA_BROADCAST, true);
    handleSendHangup(intent);
    insertMissedCall(remotePeer, true);
    return;
  }

  isRemoteVideoOffer = offerType == OfferMessage.Type.VIDEO_CALL;

  CallManager.CallMediaType callType = getCallMediaTypeFromOfferType(offerType);

  try {
    callManager.receivedOffer(callId, remotePeer, remoteDevice, offer, timeStamp, callType, isMultiRing, true);
  } catch  (CallException e) {
    callFailure("Unable to process received offer: ", e);
  }
}
 
Example #7
Source File: CommunicationActions.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
private static void startAudioCallInternal(@NonNull FragmentActivity activity, @NonNull Recipient recipient) {
  Permissions.with(activity)
             .request(Manifest.permission.RECORD_AUDIO)
             .ifNecessary()
             .withRationaleDialog(activity.getString(R.string.ConversationActivity__to_call_s_signal_needs_access_to_your_microphone, recipient.getDisplayName(activity)),
                 R.drawable.ic_mic_solid_24)
             .withPermanentDenialDialog(activity.getString(R.string.ConversationActivity__to_call_s_signal_needs_access_to_your_microphone, recipient.getDisplayName(activity)))
             .onAllGranted(() -> {
               Intent intent = new Intent(activity, WebRtcCallService.class);
               intent.setAction(WebRtcCallService.ACTION_OUTGOING_CALL)
                     .putExtra(WebRtcCallService.EXTRA_REMOTE_PEER, new RemotePeer(recipient.getId()))
                     .putExtra(WebRtcCallService.EXTRA_OFFER_TYPE, OfferMessage.Type.AUDIO_CALL.getCode());
               activity.startService(intent);

               MessageSender.onMessageSent();

               if (FeatureFlags.profileForCalling() && recipient.resolve().getProfileKey() == null) {
                 CalleeMustAcceptMessageRequestDialogFragment.create(recipient.getId())
                                                             .show(activity.getSupportFragmentManager(), null);
               } else {
                 Intent activityIntent = new Intent(activity, WebRtcCallActivity.class);

                 activityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

                 activity.startActivity(activityIntent);
               }
             })
             .execute();
}
 
Example #8
Source File: CommunicationActions.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
private static void startVideoCallInternal(@NonNull FragmentActivity activity, @NonNull Recipient recipient) {
  Permissions.with(activity)
             .request(Manifest.permission.RECORD_AUDIO, Manifest.permission.CAMERA)
             .ifNecessary()
             .withRationaleDialog(activity.getString(R.string.ConversationActivity_signal_needs_the_microphone_and_camera_permissions_in_order_to_call_s, recipient.getDisplayName(activity)),
                                  R.drawable.ic_mic_solid_24,
                                  R.drawable.ic_video_solid_24_tinted)
             .withPermanentDenialDialog(activity.getString(R.string.ConversationActivity_signal_needs_the_microphone_and_camera_permissions_in_order_to_call_s, recipient.getDisplayName(activity)))
             .onAllGranted(() -> {
               Intent intent = new Intent(activity, WebRtcCallService.class);
               intent.setAction(WebRtcCallService.ACTION_OUTGOING_CALL)
                     .putExtra(WebRtcCallService.EXTRA_REMOTE_PEER, new RemotePeer(recipient.getId()))
                     .putExtra(WebRtcCallService.EXTRA_OFFER_TYPE, OfferMessage.Type.VIDEO_CALL.getCode());
               activity.startService(intent);

               MessageSender.onMessageSent();

               if (FeatureFlags.profileForCalling() && recipient.resolve().getProfileKey() == null) {
                 CalleeMustAcceptMessageRequestDialogFragment.create(recipient.getId())
                                                             .show(activity.getSupportFragmentManager(), null);
               } else {
                 Intent activityIntent = new Intent(activity, WebRtcCallActivity.class);

                 activityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
                     .putExtra(WebRtcCallActivity.EXTRA_ENABLE_VIDEO_IF_AVAILABLE, true);

                 activity.startActivity(activityIntent);
               }
             })
             .execute();
}
 
Example #9
Source File: VoiceCallShare.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState, boolean ready) {
  super.onCreate(savedInstanceState, ready);

  if (getIntent().getData() != null && "content".equals(getIntent().getData().getScheme())) {
    Cursor cursor = null;
    
    try {
      cursor = getContentResolver().query(getIntent().getData(), null, null, null, null);

      if (cursor != null && cursor.moveToNext()) {
        String destination = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.RawContacts.Data.DATA1));

        SimpleTask.run(() -> Recipient.external(this, destination), recipient -> {
          if (!TextUtils.isEmpty(destination)) {
            Intent serviceIntent = new Intent(this, WebRtcCallService.class);
            serviceIntent.setAction(WebRtcCallService.ACTION_OUTGOING_CALL)
                         .putExtra(WebRtcCallService.EXTRA_REMOTE_PEER, new RemotePeer(recipient.getId()))
                         .putExtra(WebRtcCallService.EXTRA_OFFER_TYPE, OfferMessage.Type.AUDIO_CALL.getCode());
            startService(serviceIntent);

            Intent activityIntent = new Intent(this, WebRtcCallActivity.class);
            activityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(activityIntent);
          }
        });
      }
    } finally {
      if (cursor != null) cursor.close();
    }
  }
  
  finish();
}
 
Example #10
Source File: SignalServiceCipher.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
private SignalServiceCallMessage createCallMessage(CallMessage content) {
  if (content.hasOffer()) {
    CallMessage.Offer offerContent = content.getOffer();
    CallMessage.Offer.CallType callType = CallMessage.Offer.CallType.AUDIO;
    if (offerContent.hasType()) {
      callType = offerContent.getType();
    }
    return SignalServiceCallMessage.forOffer(new OfferMessage(offerContent.getId(), offerContent.getDescription(), callType));
  } else if (content.hasAnswer()) {
    CallMessage.Answer answerContent = content.getAnswer();
    return SignalServiceCallMessage.forAnswer(new AnswerMessage(answerContent.getId(), answerContent.getDescription()));
  } else if (content.getIceUpdateCount() > 0) {
    List<IceUpdateMessage> iceUpdates = new LinkedList<>();

    for (CallMessage.IceUpdate iceUpdate : content.getIceUpdateList()) {
      iceUpdates.add(new IceUpdateMessage(iceUpdate.getId(), iceUpdate.getSdpMid(), iceUpdate.getSdpMLineIndex(), iceUpdate.getSdp()));
    }

    return SignalServiceCallMessage.forIceUpdates(iceUpdates);
  } else if (content.hasHangup()) {
    CallMessage.Hangup hangup = content.getHangup();
    return SignalServiceCallMessage.forHangup(new HangupMessage(hangup.getId()));
  } else if (content.hasBusy()) {
    CallMessage.Busy busy = content.getBusy();
    return SignalServiceCallMessage.forBusy(new BusyMessage(busy.getId()));
  }

  return SignalServiceCallMessage.empty();
}
 
Example #11
Source File: SignalServiceMessageSender.java    From libsignal-service-java with GNU General Public License v3.0 5 votes vote down vote up
private byte[] createCallContent(SignalServiceCallMessage callMessage) {
  Content.Builder     container = Content.newBuilder();
  CallMessage.Builder builder   = CallMessage.newBuilder();

  if (callMessage.getOfferMessage().isPresent()) {
    OfferMessage offer = callMessage.getOfferMessage().get();
    builder.setOffer(CallMessage.Offer.newBuilder()
                                      .setId(offer.getId())
                                      .setDescription(offer.getDescription()));
  } else if (callMessage.getAnswerMessage().isPresent()) {
    AnswerMessage answer = callMessage.getAnswerMessage().get();
    builder.setAnswer(CallMessage.Answer.newBuilder()
                                        .setId(answer.getId())
                                        .setDescription(answer.getDescription()));
  } else if (callMessage.getIceUpdateMessages().isPresent()) {
    List<IceUpdateMessage> updates = callMessage.getIceUpdateMessages().get();

    for (IceUpdateMessage update : updates) {
      builder.addIceUpdate(CallMessage.IceUpdate.newBuilder()
                                                .setId(update.getId())
                                                .setSdp(update.getSdp())
                                                .setSdpMid(update.getSdpMid())
                                                .setSdpMLineIndex(update.getSdpMLineIndex()));
    }
  } else if (callMessage.getHangupMessage().isPresent()) {
    builder.setHangup(CallMessage.Hangup.newBuilder().setId(callMessage.getHangupMessage().get().getId()));
  } else if (callMessage.getBusyMessage().isPresent()) {
    builder.setBusy(CallMessage.Busy.newBuilder().setId(callMessage.getBusyMessage().get().getId()));
  }

  container.setCallMessage(builder);
  return container.build().toByteArray();
}
 
Example #12
Source File: SignalServiceMessageSender.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
private byte[] createCallContent(SignalServiceCallMessage callMessage) {
  Content.Builder     container = Content.newBuilder();
  CallMessage.Builder builder   = CallMessage.newBuilder();

  if (callMessage.getOfferMessage().isPresent()) {
    OfferMessage offer = callMessage.getOfferMessage().get();
    builder.setOffer(CallMessage.Offer.newBuilder()
                                      .setId(offer.getId())
                                      .setDescription(offer.getDescription())
                                      .setType(offer.getType().getProtoType()));
  } else if (callMessage.getAnswerMessage().isPresent()) {
    AnswerMessage answer = callMessage.getAnswerMessage().get();
    builder.setAnswer(CallMessage.Answer.newBuilder()
                                        .setId(answer.getId())
                                        .setDescription(answer.getDescription()));
  } else if (callMessage.getIceUpdateMessages().isPresent()) {
    List<IceUpdateMessage> updates = callMessage.getIceUpdateMessages().get();

    for (IceUpdateMessage update : updates) {
      builder.addIceUpdate(CallMessage.IceUpdate.newBuilder()
                                                .setId(update.getId())
                                                .setSdp(update.getSdp())
                                                .setSdpMid(update.getSdpMid())
                                                .setSdpMLineIndex(update.getSdpMLineIndex()));
    }
  } 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()));
  }

  builder.setMultiRing(callMessage.isMultiRing());

  if (callMessage.getDestinationDeviceId().isPresent()) {
    builder.setDestinationDeviceId(callMessage.getDestinationDeviceId().get());
  }

  container.setCallMessage(builder);
  return container.build().toByteArray();
}
 
Example #13
Source File: WebRtcCallService.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
private static @NonNull CallManager.CallMediaType getCallMediaTypeFromOfferType(@NonNull OfferMessage.Type offerType) {
  return offerType == OfferMessage.Type.VIDEO_CALL ? CallManager.CallMediaType.VIDEO_CALL : CallManager.CallMediaType.AUDIO_CALL;
}
 
Example #14
Source File: WebRtcCallService.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
private static @NonNull OfferMessage.Type getOfferTypeFromCallMediaType(@NonNull CallManager.CallMediaType mediaType) {
  return mediaType == CallManager.CallMediaType.VIDEO_CALL ? OfferMessage.Type.VIDEO_CALL : OfferMessage.Type.AUDIO_CALL;
}