Skip to content

Commit

Permalink
Integrate RingRTC v2.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-signal committed May 14, 2020
1 parent ee92708 commit 26e582d
Show file tree
Hide file tree
Showing 13 changed files with 493 additions and 214 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ dependencies {

implementation 'org.signal:argon2:13.1@aar'

implementation 'org.signal:ringrtc-android:1.3.2'
implementation 'org.signal:ringrtc-android:2.0.1'

implementation "me.leolin:ShortcutBadger:1.1.16"
implementation 'se.emilsjolander:stickylistheaders:2.7.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import android.view.WindowManager;

import androidx.annotation.NonNull;
import androidx.annotation.StringRes;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.AppCompatTextView;
Expand Down Expand Up @@ -63,6 +64,7 @@
import org.webrtc.SurfaceViewRenderer;
import org.whispersystems.libsignal.IdentityKey;
import org.whispersystems.libsignal.SignalProtocolAddress;
import org.whispersystems.signalservice.api.messages.calls.HangupMessage;

import static org.whispersystems.libsignal.SessionCipher.SESSION_LOCK;

Expand Down Expand Up @@ -379,11 +381,12 @@ private void handleOutgoingCall(@NonNull WebRtcViewModel event) {
callScreen.setStatus(getString(R.string.WebRtcCallActivity__calling));
}

private void handleTerminate(@NonNull Recipient recipient, @NonNull SurfaceViewRenderer localRenderer /*, int terminationType */) {
Log.i(TAG, "handleTerminate called");
private void handleTerminate(@NonNull Recipient recipient, @NonNull HangupMessage.Type hangupType) {
Log.i(TAG, "handleTerminate called: " + hangupType.name());

callScreen.setRecipient(recipient);
callScreen.setStatus(getString(R.string.RedPhone_ending_call));
callScreen.setStatusFromHangupType(hangupType);

EventBus.getDefault().removeStickyEvent(WebRtcViewModel.class);

delayedFinish();
Expand Down Expand Up @@ -431,13 +434,13 @@ private void handleNoSuchUser(final @NonNull WebRtcViewModel event) {
dialog.setPositiveButton(R.string.RedPhone_got_it, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
WebRtcCallActivity.this.handleTerminate(event.getRecipient(), event.getLocalRenderer());
WebRtcCallActivity.this.handleTerminate(event.getRecipient(), HangupMessage.Type.NORMAL);
}
});
dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
WebRtcCallActivity.this.handleTerminate(event.getRecipient(), event.getLocalRenderer());
WebRtcCallActivity.this.handleTerminate(event.getRecipient(), HangupMessage.Type.NORMAL);
}
});
dialog.show();
Expand All @@ -448,7 +451,7 @@ private void handleUntrustedIdentity(@NonNull WebRtcViewModel event) {
final Recipient recipient = event.getRecipient();

if (theirKey == null) {
handleTerminate(recipient, event.getLocalRenderer());
handleTerminate(recipient, HangupMessage.Type.NORMAL);
}

String name = recipient.getDisplayName(this);
Expand Down Expand Up @@ -479,7 +482,7 @@ private void handleUntrustedIdentity(@NonNull WebRtcViewModel event) {
})
.setNegativeButton(R.string.WebRtcCallScreen_end_call, (d, w) -> {
d.dismiss();
handleTerminate(recipient, event.getLocalRenderer());
handleTerminate(recipient, HangupMessage.Type.NORMAL);
})
.show();
}
Expand All @@ -505,16 +508,19 @@ public void onEventMainThread(final WebRtcViewModel event) {
viewModel.setRecipient(event.getRecipient());

switch (event.getState()) {
case CALL_CONNECTED: handleCallConnected(event); break;
case NETWORK_FAILURE: handleServerFailure(event); break;
case CALL_RINGING: handleCallRinging(event); break;
case CALL_DISCONNECTED: handleTerminate(event.getRecipient(), event.getLocalRenderer()); break;
case NO_SUCH_USER: handleNoSuchUser(event); break;
case RECIPIENT_UNAVAILABLE: handleRecipientUnavailable(event); break;
case CALL_INCOMING: handleIncomingCall(event); break;
case CALL_OUTGOING: handleOutgoingCall(event); break;
case CALL_BUSY: handleCallBusy(event); break;
case UNTRUSTED_IDENTITY: handleUntrustedIdentity(event); break;
case CALL_CONNECTED: handleCallConnected(event); break;
case NETWORK_FAILURE: handleServerFailure(event); break;
case CALL_RINGING: handleCallRinging(event); break;
case CALL_DISCONNECTED: handleTerminate(event.getRecipient(), HangupMessage.Type.NORMAL); break;
case CALL_ACCEPTED_ELSEWHERE: handleTerminate(event.getRecipient(), HangupMessage.Type.ACCEPTED); break;
case CALL_DECLINED_ELSEWHERE: handleTerminate(event.getRecipient(), HangupMessage.Type.DECLINED); break;
case CALL_ONGOING_ELSEWHERE: handleTerminate(event.getRecipient(), HangupMessage.Type.BUSY); break;
case NO_SUCH_USER: handleNoSuchUser(event); break;
case RECIPIENT_UNAVAILABLE: handleRecipientUnavailable(event); break;
case CALL_INCOMING: handleIncomingCall(event); break;
case CALL_OUTGOING: handleOutgoingCall(event); break;
case CALL_BUSY: handleCallBusy(event); break;
case UNTRUSTED_IDENTITY: handleUntrustedIdentity(event); break;
}

callScreen.setLocalRenderer(event.getLocalRenderer());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.thoughtcrime.securesms.util.ViewUtil;
import org.webrtc.RendererCommon;
import org.webrtc.SurfaceViewRenderer;
import org.whispersystems.signalservice.api.messages.calls.HangupMessage;

public class WebRtcCallView extends FrameLayout {

Expand Down Expand Up @@ -290,6 +291,25 @@ public void setStatus(@NonNull String status) {
this.status.setText(status);
}

public void setStatusFromHangupType(@NonNull HangupMessage.Type hangupType) {
switch (hangupType) {
case NORMAL:
status.setText(R.string.RedPhone_ending_call);
break;
case ACCEPTED:
status.setText(R.string.WebRtcCallActivity__answered_on_a_linked_device);
break;
case DECLINED:
status.setText(R.string.WebRtcCallActivity__declined_on_a_linked_device);
break;
case BUSY:
status.setText(R.string.WebRtcCallActivity__busy_on_a_linked_device);
break;
default:
throw new IllegalStateException("Unknown hangup type: " + hangupType);
}
}

public void setWebRtcControls(WebRtcControls webRtcControls) {
answerWithVoiceGroup.setVisibility(View.GONE);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ public enum State {
RECIPIENT_UNAVAILABLE,
NO_SUCH_USER,
UNTRUSTED_IDENTITY,

// Multiring Hangup States
CALL_ACCEPTED_ELSEWHERE,
CALL_DECLINED_ELSEWHERE,
CALL_ONGOING_ELSEWHERE
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,14 @@ private void handleMessage(@Nullable SignalServiceContent content, @NonNull Opti
else Log.w(TAG, "Contains no known sync types...");
} else if (content.getCallMessage().isPresent()) {
Log.i(TAG, "Got call message...");
SignalServiceCallMessage message = content.getCallMessage().get();

SignalServiceCallMessage message = content.getCallMessage().get();
Optional<Integer> destinationDeviceId = message.getDestinationDeviceId();

if (destinationDeviceId.isPresent() && destinationDeviceId.get() != 1) {
Log.i(TAG, String.format(Locale.US, "Ignoring call message that is not for this device! intended: %d, this: %d", destinationDeviceId.get(), 1));
return;
}

if (message.getOfferMessage().isPresent()) handleCallOfferMessage(content, message.getOfferMessage().get(), smsMessageId);
else if (message.getAnswerMessage().isPresent()) handleCallAnswerMessage(content, message.getAnswerMessage().get());
Expand Down Expand Up @@ -454,7 +461,8 @@ private void handleCallOfferMessage(@NonNull SignalServiceContent content,
.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_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);
Expand All @@ -472,7 +480,8 @@ private void handleCallAnswerMessage(@NonNull SignalServiceContent content,
.putExtra(WebRtcCallService.EXTRA_CALL_ID, message.getId())
.putExtra(WebRtcCallService.EXTRA_REMOTE_PEER, remotePeer)
.putExtra(WebRtcCallService.EXTRA_REMOTE_DEVICE, content.getSenderDevice())
.putExtra(WebRtcCallService.EXTRA_ANSWER_DESCRIPTION, message.getDescription());
.putExtra(WebRtcCallService.EXTRA_ANSWER_DESCRIPTION, message.getDescription())
.putExtra(WebRtcCallService.EXTRA_MULTI_RING, content.getCallMessage().get().isMultiRing());

context.startService(intent);
}
Expand Down Expand Up @@ -513,9 +522,12 @@ private void handleCallHangupMessage(@NonNull SignalServiceContent content,
RemotePeer remotePeer = new RemotePeer(Recipient.externalPush(context, content.getSender()).getId());

intent.setAction(WebRtcCallService.ACTION_RECEIVE_HANGUP)
.putExtra(WebRtcCallService.EXTRA_CALL_ID, message.getId())
.putExtra(WebRtcCallService.EXTRA_REMOTE_PEER, remotePeer)
.putExtra(WebRtcCallService.EXTRA_REMOTE_DEVICE, content.getSenderDevice());
.putExtra(WebRtcCallService.EXTRA_CALL_ID, message.getId())
.putExtra(WebRtcCallService.EXTRA_REMOTE_PEER, remotePeer)
.putExtra(WebRtcCallService.EXTRA_REMOTE_DEVICE, content.getSenderDevice())
.putExtra(WebRtcCallService.EXTRA_HANGUP_IS_LEGACY, message.isLegacy())
.putExtra(WebRtcCallService.EXTRA_HANGUP_DEVICE_ID, message.getDeviceId())
.putExtra(WebRtcCallService.EXTRA_HANGUP_TYPE, message.getType().getCode());

context.startService(intent);
}
Expand Down

0 comments on commit 26e582d

Please sign in to comment.