Search in sources :

Example 56 with RemotePeer

use of org.thoughtcrime.securesms.ringrtc.RemotePeer in project Signal-Android by signalapp.

the class IdleActionProcessor method handleReceivedGroupCallPeekForRingingCheck.

@Override
@NonNull
protected WebRtcServiceState handleReceivedGroupCallPeekForRingingCheck(@NonNull WebRtcServiceState currentState, @NonNull GroupCallRingCheckInfo info, long deviceCount) {
    Log.i(tag, "handleReceivedGroupCallPeekForRingingCheck(): recipient: " + info.getRecipientId() + " ring: " + info.getRingId() + " deviceCount: " + deviceCount);
    if (SignalDatabase.groupCallRings().isCancelled(info.getRingId())) {
        try {
            Log.i(TAG, "Ring was cancelled while getting peek info ring: " + info.getRingId());
            webRtcInteractor.getCallManager().cancelGroupRing(info.getGroupId().getDecodedId(), info.getRingId(), null);
        } catch (CallException e) {
            Log.w(TAG, "Error while trying to cancel ring: " + info.getRingId(), e);
        }
        return currentState;
    }
    if (deviceCount == 0) {
        Log.i(TAG, "No one in the group call, mark as expired and do not ring");
        SignalDatabase.groupCallRings().insertOrUpdateGroupRing(info.getRingId(), System.currentTimeMillis(), CallManager.RingUpdate.EXPIRED_REQUEST);
        return currentState;
    }
    currentState = currentState.builder().actionProcessor(new IncomingGroupCallActionProcessor(webRtcInteractor)).build();
    return currentState.getActionProcessor().handleGroupCallRingUpdate(currentState, new RemotePeer(info.getRecipientId()), info.getGroupId(), info.getRingId(), info.getRingerUuid(), info.getRingUpdate());
}
Also used : CallException(org.signal.ringrtc.CallException) RemotePeer(org.thoughtcrime.securesms.ringrtc.RemotePeer) NonNull(androidx.annotation.NonNull)

Example 57 with RemotePeer

use of org.thoughtcrime.securesms.ringrtc.RemotePeer in project Signal-Android by signalapp.

the class IncomingGroupCallActionProcessor method handleGroupCallRingUpdate.

@Override
@NonNull
protected WebRtcServiceState handleGroupCallRingUpdate(@NonNull WebRtcServiceState currentState, @NonNull RemotePeer remotePeerGroup, @NonNull GroupId.V2 groupId, long ringId, @NonNull UUID uuid, @NonNull CallManager.RingUpdate ringUpdate) {
    Log.i(TAG, "handleGroupCallRingUpdate(): recipient: " + remotePeerGroup.getId() + " ring: " + ringId + " update: " + ringUpdate);
    Recipient recipient = remotePeerGroup.getRecipient();
    boolean updateForCurrentRingId = ringId == currentState.getCallSetupState(RemotePeer.GROUP_CALL_ID).getRingId();
    boolean isCurrentlyRinging = currentState.getCallInfoState().getGroupCallState().isRinging();
    if (SignalDatabase.groupCallRings().isCancelled(ringId)) {
        try {
            Log.i(TAG, "Ignoring incoming ring request for already cancelled ring: " + ringId);
            webRtcInteractor.getCallManager().cancelGroupRing(groupId.getDecodedId(), ringId, null);
        } catch (CallException e) {
            Log.w(TAG, "Error while trying to cancel ring: " + ringId, e);
        }
        return currentState;
    }
    if (ringUpdate != CallManager.RingUpdate.REQUESTED) {
        SignalDatabase.groupCallRings().insertOrUpdateGroupRing(ringId, System.currentTimeMillis(), ringUpdate);
        if (updateForCurrentRingId && isCurrentlyRinging) {
            Log.i(TAG, "Cancelling current ring: " + ringId);
            currentState = currentState.builder().changeCallInfoState().callState(WebRtcViewModel.State.CALL_DISCONNECTED).build();
            webRtcInteractor.postStateUpdate(currentState);
            return terminateGroupCall(currentState);
        } else {
            return currentState;
        }
    }
    if (!updateForCurrentRingId && isCurrentlyRinging) {
        try {
            Log.i(TAG, "Already ringing so reply busy for new ring: " + ringId);
            webRtcInteractor.getCallManager().cancelGroupRing(groupId.getDecodedId(), ringId, CallManager.RingCancelReason.Busy);
        } catch (CallException e) {
            Log.w(TAG, "Error while trying to cancel ring: " + ringId, e);
        }
        return currentState;
    }
    if (updateForCurrentRingId) {
        Log.i(TAG, "Already ringing for ring: " + ringId);
        return currentState;
    }
    Log.i(TAG, "Requesting new ring: " + ringId);
    SignalDatabase.groupCallRings().insertGroupRing(ringId, System.currentTimeMillis(), ringUpdate);
    currentState = WebRtcVideoUtil.initializeVideo(context, webRtcInteractor.getCameraEventListener(), currentState, RemotePeer.GROUP_CALL_ID.longValue());
    webRtcInteractor.setCallInProgressNotification(TYPE_INCOMING_RINGING, remotePeerGroup);
    webRtcInteractor.updatePhoneState(LockManager.PhoneState.INTERACTIVE);
    webRtcInteractor.initializeAudioForCall();
    boolean shouldDisturbUserWithCall = DoNotDisturbUtil.shouldDisturbUserWithCall(context.getApplicationContext());
    if (shouldDisturbUserWithCall) {
        boolean started = webRtcInteractor.startWebRtcCallActivityIfPossible();
        if (!started) {
            Log.i(TAG, "Unable to start call activity due to OS version or not being in the foreground");
            ApplicationDependencies.getAppForegroundObserver().addListener(webRtcInteractor.getForegroundListener());
        }
    }
    if (shouldDisturbUserWithCall && SignalStore.settings().isCallNotificationsEnabled()) {
        Uri ringtone = recipient.resolve().getCallRingtone();
        RecipientDatabase.VibrateState vibrateState = recipient.resolve().getCallVibrate();
        if (ringtone == null) {
            ringtone = SignalStore.settings().getCallRingtone();
        }
        webRtcInteractor.startIncomingRinger(ringtone, vibrateState == RecipientDatabase.VibrateState.ENABLED || (vibrateState == RecipientDatabase.VibrateState.DEFAULT && SignalStore.settings().isCallVibrateEnabled()));
    }
    webRtcInteractor.registerPowerButtonReceiver();
    return currentState.builder().changeCallSetupState(RemotePeer.GROUP_CALL_ID).isRemoteVideoOffer(true).ringId(ringId).ringerRecipient(Recipient.externalPush(ACI.from(uuid), null, false)).commit().changeCallInfoState().activePeer(new RemotePeer(currentState.getCallInfoState().getCallRecipient().getId(), RemotePeer.GROUP_CALL_ID)).callRecipient(remotePeerGroup.getRecipient()).callState(WebRtcViewModel.State.CALL_INCOMING).groupCallState(WebRtcViewModel.GroupCallState.RINGING).putParticipant(remotePeerGroup.getRecipient(), CallParticipant.createRemote(new CallParticipantId(remotePeerGroup.getRecipient()), remotePeerGroup.getRecipient(), null, new BroadcastVideoSink(currentState.getVideoState().getLockableEglBase(), false, true, currentState.getLocalDeviceState().getOrientation().getDegrees()), true, false, 0, true, 0, false, CallParticipant.DeviceOrdinal.PRIMARY)).build();
}
Also used : RecipientDatabase(org.thoughtcrime.securesms.database.RecipientDatabase) CallException(org.signal.ringrtc.CallException) BroadcastVideoSink(org.thoughtcrime.securesms.components.webrtc.BroadcastVideoSink) RemotePeer(org.thoughtcrime.securesms.ringrtc.RemotePeer) Recipient(org.thoughtcrime.securesms.recipients.Recipient) CallParticipantId(org.thoughtcrime.securesms.events.CallParticipantId) Uri(android.net.Uri) NonNull(androidx.annotation.NonNull)

Example 58 with RemotePeer

use of org.thoughtcrime.securesms.ringrtc.RemotePeer in project Signal-Android by signalapp.

the class WebRtcActionProcessor method handleMessageSentError.

@NonNull
protected WebRtcServiceState handleMessageSentError(@NonNull WebRtcServiceState currentState, @NonNull CallId callId, @NonNull WebRtcViewModel.State errorCallState, @NonNull Optional<IdentityKey> identityKey) {
    Log.w(tag, "handleMessageSentError():");
    try {
        webRtcInteractor.getCallManager().messageSendFailure(callId);
    } catch (CallException e) {
        currentState = callFailure(currentState, "callManager.messageSendFailure() failed: ", e);
    }
    RemotePeer activePeer = currentState.getCallInfoState().getActivePeer();
    if (activePeer == null) {
        return currentState;
    }
    WebRtcServiceStateBuilder builder = currentState.builder();
    if (errorCallState == WebRtcViewModel.State.UNTRUSTED_IDENTITY) {
        CallParticipant participant = Objects.requireNonNull(currentState.getCallInfoState().getRemoteCallParticipant(activePeer.getRecipient()));
        CallParticipant untrusted = participant.withIdentityKey(identityKey.orNull());
        builder.changeCallInfoState().callState(WebRtcViewModel.State.UNTRUSTED_IDENTITY).putParticipant(activePeer.getRecipient(), untrusted).commit();
    } else {
        builder.changeCallInfoState().callState(errorCallState).commit();
    }
    return builder.build();
}
Also used : CallException(org.signal.ringrtc.CallException) CallParticipant(org.thoughtcrime.securesms.events.CallParticipant) WebRtcServiceStateBuilder(org.thoughtcrime.securesms.service.webrtc.state.WebRtcServiceStateBuilder) RemotePeer(org.thoughtcrime.securesms.ringrtc.RemotePeer) NonNull(androidx.annotation.NonNull)

Example 59 with RemotePeer

use of org.thoughtcrime.securesms.ringrtc.RemotePeer in project Signal-Android by signalapp.

the class WebRtcActionProcessor method terminate.

@NonNull
public synchronized WebRtcServiceState terminate(@NonNull WebRtcServiceState currentState, @Nullable RemotePeer remotePeer) {
    Log.i(tag, "terminate():");
    RemotePeer activePeer = currentState.getCallInfoState().getActivePeer();
    if (activePeer == null) {
        Log.i(tag, "skipping with no active peer");
        return currentState;
    }
    if (!activePeer.callIdEquals(remotePeer)) {
        Log.i(tag, "skipping remotePeer is not active peer");
        return currentState;
    }
    ApplicationDependencies.getAppForegroundObserver().removeListener(webRtcInteractor.getForegroundListener());
    webRtcInteractor.updatePhoneState(LockManager.PhoneState.PROCESSING);
    boolean playDisconnectSound = (activePeer.getState() == CallState.DIALING) || (activePeer.getState() == CallState.REMOTE_RINGING) || (activePeer.getState() == CallState.RECEIVED_BUSY) || (activePeer.getState() == CallState.CONNECTED);
    webRtcInteractor.stopAudio(playDisconnectSound);
    webRtcInteractor.updatePhoneState(LockManager.PhoneState.IDLE);
    webRtcInteractor.stopForegroundService();
    return WebRtcVideoUtil.deinitializeVideo(currentState).builder().changeCallInfoState().activePeer(null).commit().changeLocalDeviceState().commit().actionProcessor(new IdleActionProcessor(webRtcInteractor)).terminate(remotePeer.getCallId()).build();
}
Also used : RemotePeer(org.thoughtcrime.securesms.ringrtc.RemotePeer) NonNull(androidx.annotation.NonNull)

Example 60 with RemotePeer

use of org.thoughtcrime.securesms.ringrtc.RemotePeer in project Signal-Android by signalapp.

the class ActiveCallActionProcessorDelegate method handleReceivedOfferWhileActive.

@Override
@NonNull
protected WebRtcServiceState handleReceivedOfferWhileActive(@NonNull WebRtcServiceState currentState, @NonNull RemotePeer remotePeer) {
    RemotePeer activePeer = currentState.getCallInfoState().requireActivePeer();
    Log.i(tag, "handleReceivedOfferWhileActive(): call_id: " + remotePeer.getCallId());
    switch(activePeer.getState()) {
        case DIALING:
        case REMOTE_RINGING:
            webRtcInteractor.setCallInProgressNotification(TYPE_OUTGOING_RINGING, activePeer);
            break;
        case IDLE:
        case ANSWERING:
            webRtcInteractor.setCallInProgressNotification(TYPE_INCOMING_CONNECTING, activePeer);
            break;
        case LOCAL_RINGING:
            webRtcInteractor.setCallInProgressNotification(TYPE_INCOMING_RINGING, activePeer);
            break;
        case CONNECTED:
            webRtcInteractor.setCallInProgressNotification(TYPE_ESTABLISHED, activePeer);
            break;
        default:
            throw new IllegalStateException();
    }
    if (activePeer.getState() == CallState.IDLE) {
        webRtcInteractor.stopForegroundService();
    }
    webRtcInteractor.insertMissedCall(remotePeer, remotePeer.getCallStartTimestamp(), currentState.getCallSetupState(remotePeer).isRemoteVideoOffer());
    return terminate(currentState, remotePeer);
}
Also used : RemotePeer(org.thoughtcrime.securesms.ringrtc.RemotePeer) NonNull(androidx.annotation.NonNull)

Aggregations

RemotePeer (org.thoughtcrime.securesms.ringrtc.RemotePeer)70 NonNull (androidx.annotation.NonNull)44 CallException (org.signal.ringrtc.CallException)32 CallId (org.signal.ringrtc.CallId)14 Recipient (org.thoughtcrime.securesms.recipients.Recipient)14 CallParticipant (org.thoughtcrime.securesms.events.CallParticipant)10 GroupId (org.thoughtcrime.securesms.groups.GroupId)10 WebRtcData (org.thoughtcrime.securesms.service.webrtc.WebRtcData)10 OfferMessage (org.whispersystems.signalservice.api.messages.calls.OfferMessage)10 Context (android.content.Context)8 Build (android.os.Build)8 Nullable (androidx.annotation.Nullable)8 Stream (com.annimon.stream.Stream)8 IOException (java.io.IOException)8 Collection (java.util.Collection)8 Collections (java.util.Collections)8 LinkedList (java.util.LinkedList)8 List (java.util.List)8 UUID (java.util.UUID)8 Log (org.signal.core.util.logging.Log)8