Search in sources :

Example 6 with NotificationProfile

use of org.thoughtcrime.securesms.notifications.profiles.NotificationProfile in project Signal-Android by signalapp.

the class WebRtcActionProcessor method handleReceivedOffer.

// endregion Outgoing call
// region Incoming call
@NonNull
protected WebRtcServiceState handleReceivedOffer(@NonNull WebRtcServiceState currentState, @NonNull CallMetadata callMetadata, @NonNull OfferMetadata offerMetadata, @NonNull ReceivedOfferMetadata receivedOfferMetadata) {
    Log.i(tag, "handleReceivedOffer(): id: " + callMetadata.getCallId().format(callMetadata.getRemoteDevice()) + " offer_type:" + offerMetadata.getOfferType());
    if (TelephonyUtil.isAnyPstnLineBusy(context)) {
        Log.i(tag, "PSTN line is busy.");
        currentState = currentState.getActionProcessor().handleSendBusy(currentState, callMetadata, true);
        webRtcInteractor.insertMissedCall(callMetadata.getRemotePeer(), receivedOfferMetadata.getServerReceivedTimestamp(), offerMetadata.getOfferType() == OfferMessage.Type.VIDEO_CALL);
        return currentState;
    }
    if (!RecipientUtil.isCallRequestAccepted(context.getApplicationContext(), callMetadata.getRemotePeer().getRecipient())) {
        Log.w(tag, "Caller is untrusted.");
        currentState = currentState.getActionProcessor().handleSendHangup(currentState, callMetadata, WebRtcData.HangupMetadata.fromType(HangupMessage.Type.NEED_PERMISSION), true);
        webRtcInteractor.insertMissedCall(callMetadata.getRemotePeer(), receivedOfferMetadata.getServerReceivedTimestamp(), offerMetadata.getOfferType() == OfferMessage.Type.VIDEO_CALL);
        return currentState;
    }
    if (offerMetadata.getOpaque() == null) {
        Log.w(tag, "Opaque data is required.");
        currentState = currentState.getActionProcessor().handleSendHangup(currentState, callMetadata, WebRtcData.HangupMetadata.fromType(HangupMessage.Type.NORMAL), true);
        webRtcInteractor.insertMissedCall(callMetadata.getRemotePeer(), receivedOfferMetadata.getServerReceivedTimestamp(), offerMetadata.getOfferType() == OfferMessage.Type.VIDEO_CALL);
        return currentState;
    }
    NotificationProfile activeProfile = NotificationProfiles.getActiveProfile(SignalDatabase.notificationProfiles().getProfiles());
    if (activeProfile != null && !(activeProfile.isRecipientAllowed(callMetadata.getRemotePeer().getId()) || activeProfile.getAllowAllCalls())) {
        Log.w(tag, "Caller is excluded by notification profile.");
        currentState = currentState.getActionProcessor().handleSendHangup(currentState, callMetadata, WebRtcData.HangupMetadata.fromType(HangupMessage.Type.NORMAL), true);
        webRtcInteractor.insertMissedCall(callMetadata.getRemotePeer(), receivedOfferMetadata.getServerReceivedTimestamp(), offerMetadata.getOfferType() == OfferMessage.Type.VIDEO_CALL);
        return currentState;
    }
    Log.i(tag, "add remotePeer callId: " + callMetadata.getRemotePeer().getCallId() + " key: " + callMetadata.getRemotePeer().hashCode());
    callMetadata.getRemotePeer().setCallStartTimestamp(receivedOfferMetadata.getServerReceivedTimestamp());
    currentState = currentState.builder().changeCallSetupState(callMetadata.getCallId()).isRemoteVideoOffer(offerMetadata.getOfferType() == OfferMessage.Type.VIDEO_CALL).commit().changeCallInfoState().putRemotePeer(callMetadata.getRemotePeer()).build();
    long messageAgeSec = Math.max(receivedOfferMetadata.getServerDeliveredTimestamp() - receivedOfferMetadata.getServerReceivedTimestamp(), 0) / 1000;
    Log.i(tag, "messageAgeSec: " + messageAgeSec + ", serverReceivedTimestamp: " + receivedOfferMetadata.getServerReceivedTimestamp() + ", serverDeliveredTimestamp: " + receivedOfferMetadata.getServerDeliveredTimestamp());
    try {
        byte[] remoteIdentityKey = WebRtcUtil.getPublicKeyBytes(receivedOfferMetadata.getRemoteIdentityKey());
        byte[] localIdentityKey = WebRtcUtil.getPublicKeyBytes(SignalStore.account().getAciIdentityKey().getPublicKey().serialize());
        webRtcInteractor.getCallManager().receivedOffer(callMetadata.getCallId(), callMetadata.getRemotePeer(), callMetadata.getRemoteDevice(), offerMetadata.getOpaque(), messageAgeSec, WebRtcUtil.getCallMediaTypeFromOfferType(offerMetadata.getOfferType()), SignalStore.account().getDeviceId(), SignalStore.account().isPrimaryDevice(), remoteIdentityKey, localIdentityKey);
    } catch (CallException | InvalidKeyException e) {
        return callFailure(currentState, "Unable to process received offer: ", e);
    }
    return currentState;
}
Also used : CallException(org.signal.ringrtc.CallException) NotificationProfile(org.thoughtcrime.securesms.notifications.profiles.NotificationProfile) InvalidKeyException(org.whispersystems.libsignal.InvalidKeyException) NonNull(androidx.annotation.NonNull)

Aggregations

NotificationProfile (org.thoughtcrime.securesms.notifications.profiles.NotificationProfile)6 NonNull (androidx.annotation.NonNull)4 CallException (org.signal.ringrtc.CallException)4 View (android.view.View)2 ViewGroup (android.view.ViewGroup)2 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 ActionMenuView (androidx.appcompat.widget.ActionMenuView)2 DialogFragment (androidx.fragment.app.DialogFragment)2 Fragment (androidx.fragment.app.Fragment)2 RecyclerView (androidx.recyclerview.widget.RecyclerView)2 MainFragment (org.thoughtcrime.securesms.MainFragment)2 BadgeImageView (org.thoughtcrime.securesms.badges.BadgeImageView)2 CantProcessSubscriptionPaymentBottomSheetDialogFragment (org.thoughtcrime.securesms.badges.self.expired.CantProcessSubscriptionPaymentBottomSheetDialogFragment)2 ExpiredBadgeBottomSheetDialogFragment (org.thoughtcrime.securesms.badges.self.expired.ExpiredBadgeBottomSheetDialogFragment)2 UnreadPaymentsView (org.thoughtcrime.securesms.components.UnreadPaymentsView)2 ReminderView (org.thoughtcrime.securesms.components.reminder.ReminderView)2 NotificationProfileSelectionFragment (org.thoughtcrime.securesms.components.settings.app.notifications.manual.NotificationProfileSelectionFragment)2 VoiceNotePlayerView (org.thoughtcrime.securesms.components.voice.VoiceNotePlayerView)2 ConversationFragment (org.thoughtcrime.securesms.conversation.ConversationFragment)2