Search in sources :

Example 1 with CallException

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

the class GroupConnectedActionProcessor method handleSetEnableVideo.

@Override
@NonNull
protected WebRtcServiceState handleSetEnableVideo(@NonNull WebRtcServiceState currentState, boolean enable) {
    Log.i(TAG, "handleSetEnableVideo():");
    GroupCall groupCall = currentState.getCallInfoState().requireGroupCall();
    Camera camera = currentState.getVideoState().requireCamera();
    try {
        groupCall.setOutgoingVideoMuted(!enable);
    } catch (CallException e) {
        return groupCallFailure(currentState, "Unable set video muted", e);
    }
    camera.setEnabled(enable);
    currentState = currentState.builder().changeLocalDeviceState().cameraState(camera.getCameraState()).build();
    WebRtcUtil.enableSpeakerPhoneIfNeeded(webRtcInteractor, currentState);
    return currentState;
}
Also used : CallException(org.signal.ringrtc.CallException) GroupCall(org.signal.ringrtc.GroupCall) Camera(org.thoughtcrime.securesms.ringrtc.Camera) NonNull(androidx.annotation.NonNull)

Example 2 with CallException

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

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 3 with CallException

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

the class IncomingGroupCallActionProcessor method handleAcceptCall.

@Override
@NonNull
protected WebRtcServiceState handleAcceptCall(@NonNull WebRtcServiceState currentState, boolean answerWithVideo) {
    byte[] groupId = currentState.getCallInfoState().getCallRecipient().requireGroupId().getDecodedId();
    GroupCall groupCall = webRtcInteractor.getCallManager().createGroupCall(groupId, SignalStore.internalValues().groupCallingServer(), new byte[0], null, AudioProcessingMethodSelector.get(), webRtcInteractor.getGroupCallObserver());
    try {
        groupCall.setOutgoingAudioMuted(true);
        groupCall.setOutgoingVideoMuted(true);
        groupCall.setBandwidthMode(NetworkUtil.getCallingBandwidthMode(context, groupCall.getLocalDeviceState().getNetworkRoute().getLocalAdapterType()));
        Log.i(TAG, "Connecting to group call: " + currentState.getCallInfoState().getCallRecipient().getId());
        groupCall.connect();
    } catch (CallException e) {
        return groupCallFailure(currentState, "Unable to connect to group call", e);
    }
    currentState = currentState.builder().changeCallInfoState().groupCall(groupCall).groupCallState(WebRtcViewModel.GroupCallState.DISCONNECTED).commit().changeCallSetupState(RemotePeer.GROUP_CALL_ID).isRemoteVideoOffer(false).enableVideoOnCreate(answerWithVideo).build();
    webRtcInteractor.setCallInProgressNotification(TYPE_INCOMING_CONNECTING, currentState.getCallInfoState().getCallRecipient());
    webRtcInteractor.updatePhoneState(WebRtcUtil.getInCallPhoneState(context));
    webRtcInteractor.initializeAudioForCall();
    try {
        groupCall.setOutgoingVideoSource(currentState.getVideoState().requireLocalSink(), currentState.getVideoState().requireCamera());
        groupCall.setOutgoingVideoMuted(answerWithVideo);
        groupCall.setOutgoingAudioMuted(!currentState.getLocalDeviceState().isMicrophoneEnabled());
        groupCall.setBandwidthMode(NetworkUtil.getCallingBandwidthMode(context, groupCall.getLocalDeviceState().getNetworkRoute().getLocalAdapterType()));
        groupCall.join();
    } catch (CallException e) {
        return groupCallFailure(currentState, "Unable to join group call", e);
    }
    return currentState.builder().actionProcessor(new GroupJoiningActionProcessor(webRtcInteractor)).changeCallInfoState().callState(WebRtcViewModel.State.CALL_OUTGOING).groupCallState(WebRtcViewModel.GroupCallState.CONNECTED_AND_JOINING).commit().changeLocalDeviceState().build();
}
Also used : CallException(org.signal.ringrtc.CallException) GroupCall(org.signal.ringrtc.GroupCall) NonNull(androidx.annotation.NonNull)

Example 4 with CallException

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

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 5 with CallException

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

the class IncomingGroupCallActionProcessor method handleDenyCall.

@Override
@NonNull
protected WebRtcServiceState handleDenyCall(@NonNull WebRtcServiceState currentState) {
    Recipient recipient = currentState.getCallInfoState().getCallRecipient();
    Optional<GroupId> groupId = recipient.getGroupId();
    long ringId = currentState.getCallSetupState(RemotePeer.GROUP_CALL_ID).getRingId();
    SignalDatabase.groupCallRings().insertOrUpdateGroupRing(ringId, System.currentTimeMillis(), CallManager.RingUpdate.DECLINED_ON_ANOTHER_DEVICE);
    try {
        webRtcInteractor.getCallManager().cancelGroupRing(groupId.get().getDecodedId(), ringId, CallManager.RingCancelReason.DeclinedByUser);
    } catch (CallException e) {
        Log.w(TAG, "Error while trying to cancel ring " + ringId, e);
    }
    webRtcInteractor.updatePhoneState(LockManager.PhoneState.PROCESSING);
    webRtcInteractor.stopAudio(false);
    webRtcInteractor.updatePhoneState(LockManager.PhoneState.IDLE);
    webRtcInteractor.stopForegroundService();
    currentState = WebRtcVideoUtil.deinitializeVideo(currentState);
    EglBaseWrapper.releaseEglBase(RemotePeer.GROUP_CALL_ID.longValue());
    return currentState.builder().actionProcessor(new IdleActionProcessor(webRtcInteractor)).terminate(RemotePeer.GROUP_CALL_ID).build();
}
Also used : CallException(org.signal.ringrtc.CallException) Recipient(org.thoughtcrime.securesms.recipients.Recipient) GroupId(org.thoughtcrime.securesms.groups.GroupId) 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