Search in sources :

Example 6 with CallException

use of org.signal.ringrtc.CallException in project Signal-Android by WhisperSystems.

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)

Example 7 with CallException

use of org.signal.ringrtc.CallException in project Signal-Android by WhisperSystems.

the class WebRtcActionProcessor method groupCallFailure.

@NonNull
protected WebRtcServiceState groupCallFailure(@NonNull WebRtcServiceState currentState, @NonNull String message, @NonNull Throwable error) {
    Log.w(tag, "groupCallFailure(): " + message, error);
    GroupCall groupCall = currentState.getCallInfoState().getGroupCall();
    Recipient recipient = currentState.getCallInfoState().getCallRecipient();
    if (recipient != null && currentState.getCallInfoState().getGroupCallState().isConnected()) {
        webRtcInteractor.sendGroupCallMessage(recipient, WebRtcUtil.getGroupCallEraId(groupCall));
    }
    currentState = currentState.builder().changeCallInfoState().callState(WebRtcViewModel.State.CALL_DISCONNECTED).groupCallState(WebRtcViewModel.GroupCallState.DISCONNECTED).build();
    webRtcInteractor.postStateUpdate(currentState);
    try {
        if (groupCall != null) {
            groupCall.disconnect();
        }
        webRtcInteractor.getCallManager().reset();
    } catch (CallException e) {
        Log.w(tag, "Unable to reset call manager: ", e);
    }
    return terminateGroupCall(currentState);
}
Also used : CallException(org.signal.ringrtc.CallException) GroupCall(org.signal.ringrtc.GroupCall) Recipient(org.thoughtcrime.securesms.recipients.Recipient) NonNull(androidx.annotation.NonNull)

Example 8 with CallException

use of org.signal.ringrtc.CallException in project Signal-Android by WhisperSystems.

the class GroupPreJoinActionProcessor method handleCancelPreJoinCall.

@Override
@NonNull
protected WebRtcServiceState handleCancelPreJoinCall(@NonNull WebRtcServiceState currentState) {
    Log.i(TAG, "handleCancelPreJoinCall():");
    GroupCall groupCall = currentState.getCallInfoState().requireGroupCall();
    try {
        groupCall.disconnect();
    } catch (CallException e) {
        return groupCallFailure(currentState, "Unable to disconnect from group call", e);
    }
    WebRtcVideoUtil.deinitializeVideo(currentState);
    EglBaseWrapper.releaseEglBase(RemotePeer.GROUP_CALL_ID.longValue());
    return new WebRtcServiceState(new IdleActionProcessor(webRtcInteractor));
}
Also used : CallException(org.signal.ringrtc.CallException) WebRtcServiceState(org.thoughtcrime.securesms.service.webrtc.state.WebRtcServiceState) GroupCall(org.signal.ringrtc.GroupCall) NonNull(androidx.annotation.NonNull)

Example 9 with CallException

use of org.signal.ringrtc.CallException in project Signal-Android by WhisperSystems.

the class IncomingCallActionProcessor method handleDenyCall.

@NonNull
protected WebRtcServiceState handleDenyCall(@NonNull WebRtcServiceState currentState) {
    RemotePeer activePeer = currentState.getCallInfoState().requireActivePeer();
    if (activePeer.getState() != CallState.LOCAL_RINGING) {
        Log.w(TAG, "Can only deny from ringing!");
        return currentState;
    }
    Log.i(TAG, "handleDenyCall():");
    try {
        webRtcInteractor.getCallManager().hangup();
        SignalDatabase.sms().insertMissedCall(activePeer.getId(), System.currentTimeMillis(), currentState.getCallSetupState(activePeer).isRemoteVideoOffer());
        return terminate(currentState, activePeer);
    } catch (CallException e) {
        return callFailure(currentState, "hangup() failed: ", e);
    }
}
Also used : CallException(org.signal.ringrtc.CallException) RemotePeer(org.thoughtcrime.securesms.ringrtc.RemotePeer) NonNull(androidx.annotation.NonNull)

Example 10 with CallException

use of org.signal.ringrtc.CallException in project Signal-Android by WhisperSystems.

the class IncomingCallActionProcessor method handleTurnServerUpdate.

@Override
@NonNull
public WebRtcServiceState handleTurnServerUpdate(@NonNull WebRtcServiceState currentState, @NonNull List<PeerConnection.IceServer> iceServers, boolean isAlwaysTurn) {
    RemotePeer activePeer = currentState.getCallInfoState().requireActivePeer();
    boolean hideIp = !activePeer.getRecipient().isSystemContact() || isAlwaysTurn;
    VideoState videoState = currentState.getVideoState();
    CallParticipant callParticipant = Objects.requireNonNull(currentState.getCallInfoState().getRemoteCallParticipant(activePeer.getRecipient()));
    try {
        webRtcInteractor.getCallManager().proceed(activePeer.getCallId(), context, videoState.getLockableEglBase().require(), AudioProcessingMethodSelector.get(), videoState.requireLocalSink(), callParticipant.getVideoSink(), videoState.requireCamera(), iceServers, hideIp, NetworkUtil.getCallingBandwidthMode(context), null, false);
    } catch (CallException e) {
        return callFailure(currentState, "Unable to proceed with call: ", e);
    }
    webRtcInteractor.updatePhoneState(LockManager.PhoneState.PROCESSING);
    webRtcInteractor.postStateUpdate(currentState);
    return currentState;
}
Also used : CallException(org.signal.ringrtc.CallException) CallParticipant(org.thoughtcrime.securesms.events.CallParticipant) RemotePeer(org.thoughtcrime.securesms.ringrtc.RemotePeer) VideoState(org.thoughtcrime.securesms.service.webrtc.state.VideoState) NonNull(androidx.annotation.NonNull)

Aggregations

CallException (org.signal.ringrtc.CallException)70 NonNull (androidx.annotation.NonNull)62 RemotePeer (org.thoughtcrime.securesms.ringrtc.RemotePeer)36 GroupCall (org.signal.ringrtc.GroupCall)34 Recipient (org.thoughtcrime.securesms.recipients.Recipient)16 WebRtcServiceState (org.thoughtcrime.securesms.service.webrtc.state.WebRtcServiceState)12 CallParticipant (org.thoughtcrime.securesms.events.CallParticipant)10 Stream (com.annimon.stream.Stream)8 List (java.util.List)8 Log (org.signal.core.util.logging.Log)8 WebRtcViewModel (org.thoughtcrime.securesms.events.WebRtcViewModel)8 VideoState (org.thoughtcrime.securesms.service.webrtc.state.VideoState)8 ResultReceiver (android.os.ResultReceiver)6 Nullable (androidx.annotation.Nullable)6 Collection (java.util.Collection)6 Collections (java.util.Collections)6 Set (java.util.Set)6 UUID (java.util.UUID)6 CallManager (org.signal.ringrtc.CallManager)6 GroupManager (org.thoughtcrime.securesms.groups.GroupManager)6