Add Calling Requests.

This commit is contained in:
Cody Henthorne 2020-07-06 16:27:03 -04:00 committed by Greyson Parrelli
parent 5a12eedc2c
commit 1e250ee95c
16 changed files with 192 additions and 182 deletions

View File

@ -304,7 +304,7 @@ dependencies {
implementation 'org.signal:argon2:13.1@aar'
implementation 'org.signal:ringrtc-android:2.2.0'
implementation 'org.signal:ringrtc-android:2.3.1'
implementation "me.leolin:ShortcutBadger:1.1.16"
implementation 'se.emilsjolander:stickylistheaders:2.7.0'

View File

@ -122,6 +122,12 @@
android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation"
android:launchMode="singleTask"/>
<activity android:name=".messagerequests.CalleeMustAcceptMessageRequestActivity"
android:theme="@style/TextSecure.DarkNoActionBar"
android:screenOrientation="portrait"
android:noHistory="true"
android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout|screenSize"/>
<activity android:name=".InviteActivity"
android:theme="@style/Signal.Light.NoActionBar.Invite"
android:windowSoftInputMode="stateHidden"

View File

@ -51,6 +51,7 @@ import org.thoughtcrime.securesms.components.webrtc.WebRtcCallViewModel;
import org.thoughtcrime.securesms.crypto.storage.TextSecureIdentityKeyStore;
import org.thoughtcrime.securesms.events.WebRtcViewModel;
import org.thoughtcrime.securesms.logging.Log;
import org.thoughtcrime.securesms.messagerequests.CalleeMustAcceptMessageRequestActivity;
import org.thoughtcrime.securesms.permissions.Permissions;
import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.ringrtc.RemotePeer;
@ -391,6 +392,9 @@ public class WebRtcCallActivity extends AppCompatActivity {
EventBus.getDefault().removeStickyEvent(WebRtcViewModel.class);
if (hangupType == HangupMessage.Type.NEED_PERMISSION) {
startActivity(CalleeMustAcceptMessageRequestActivity.createIntent(this, recipient.getId()));
}
delayedFinish();
}
@ -517,6 +521,7 @@ public class WebRtcCallActivity extends AppCompatActivity {
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 CALL_NEEDS_PERMISSION: handleTerminate(event.getRecipient(), HangupMessage.Type.NEED_PERMISSION); break;
case NO_SUCH_USER: handleNoSuchUser(event); break;
case RECIPIENT_UNAVAILABLE: handleRecipientUnavailable(event); break;
case CALL_INCOMING: handleIncomingCall(event); break;

View File

@ -286,6 +286,7 @@ public class WebRtcCallView extends FrameLayout {
public void setStatusFromHangupType(@NonNull HangupMessage.Type hangupType) {
switch (hangupType) {
case NORMAL:
case NEED_PERMISSION:
status.setText(R.string.RedPhone_ending_call);
break;
case ACCEPTED:

View File

@ -621,13 +621,13 @@ public class SmsDatabase extends MessagingDatabase {
long messageId = db.insert(TABLE_NAME, null, values);
DatabaseFactory.getThreadDatabase(context).update(threadId, true);
notifyConversationListeners(threadId);
ApplicationDependencies.getJobManager().add(new TrimThreadJob(threadId));
if (unread) {
DatabaseFactory.getThreadDatabase(context).incrementUnread(threadId, 1);
}
notifyConversationListeners(threadId);
ApplicationDependencies.getJobManager().add(new TrimThreadJob(threadId));
return new Pair<>(messageId, threadId);
}

View File

@ -311,7 +311,11 @@ public class ThreadDatabase extends Database {
}
public boolean hasCalledSince(@NonNull Recipient recipient, long timestamp) {
return DatabaseFactory.getMmsSmsDatabase(context).hasReceivedAnyCallsSince(getThreadIdFor(recipient), timestamp);
return hasReceivedAnyCallsSince(getThreadIdFor(recipient), timestamp);
}
public boolean hasReceivedAnyCallsSince(long threadId, long timestamp) {
return DatabaseFactory.getMmsSmsDatabase(context).hasReceivedAnyCallsSince(threadId, timestamp);
}
public List<MarkedMessageInfo> setEntireThreadRead(long threadId) {

View File

@ -19,6 +19,7 @@ public class WebRtcViewModel {
CALL_RINGING,
CALL_BUSY,
CALL_DISCONNECTED,
CALL_NEEDS_PERMISSION,
// Error states
NETWORK_FAILURE,

View File

@ -1,20 +1,18 @@
package org.thoughtcrime.securesms.messagerequests;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.DialogFragment;
import androidx.lifecycle.ViewModelProviders;
import org.thoughtcrime.securesms.BaseActivity;
import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.components.AvatarImageView;
import org.thoughtcrime.securesms.contacts.avatars.FallbackContactPhoto;
@ -25,56 +23,45 @@ import org.thoughtcrime.securesms.recipients.RecipientId;
import java.util.concurrent.TimeUnit;
public class CalleeMustAcceptMessageRequestDialogFragment extends DialogFragment {
import static android.content.Intent.FLAG_ACTIVITY_NO_ANIMATION;
public class CalleeMustAcceptMessageRequestActivity extends BaseActivity {
private static final long TIMEOUT_MS = TimeUnit.SECONDS.toMillis(10);
private static final String ARG_RECIPIENT_ID = "arg.recipient.id";
private static final String RECIPIENT_ID_EXTRA = "extra.recipient.id";
private TextView description;
private AvatarImageView avatar;
private View okay;
private final Handler handler = new Handler(Looper.getMainLooper());
private final Runnable dismisser = this::dismiss;
private final Runnable finisher = this::finish;
public static DialogFragment create(@NonNull RecipientId recipientId) {
DialogFragment fragment = new CalleeMustAcceptMessageRequestDialogFragment();
Bundle args = new Bundle();
args.putParcelable(ARG_RECIPIENT_ID, recipientId);
fragment.setArguments(args);
return fragment;
public static Intent createIntent(@NonNull Context context, @NonNull RecipientId recipientId) {
Intent intent = new Intent(context, CalleeMustAcceptMessageRequestActivity.class);
intent.setFlags(FLAG_ACTIVITY_NO_ANIMATION);
intent.putExtra(RECIPIENT_ID_EXTRA, recipientId);
return intent;
}
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.callee_must_accept_message_request_dialog_fragment);
setStyle(DialogFragment.STYLE_NO_FRAME, R.style.TextSecure_DarkNoActionBar);
}
@Override
public @Nullable View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.callee_must_accept_message_request_dialog_fragment, container, false);
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
description = view.findViewById(R.id.description);
avatar = view.findViewById(R.id.avatar);
okay = view.findViewById(R.id.okay);
description = findViewById(R.id.description);
avatar = findViewById(R.id.avatar);
okay = findViewById(R.id.okay);
avatar.setFallbackPhotoProvider(new FallbackPhotoProvider());
okay.setOnClickListener(v -> dismiss());
okay.setOnClickListener(v -> finish());
RecipientId recipientId = requireArguments().getParcelable(ARG_RECIPIENT_ID);
RecipientId recipientId = getIntent().getParcelableExtra(RECIPIENT_ID_EXTRA);
CalleeMustAcceptMessageRequestViewModel.Factory factory = new CalleeMustAcceptMessageRequestViewModel.Factory(recipientId);
CalleeMustAcceptMessageRequestViewModel viewModel = ViewModelProviders.of(this, factory).get(CalleeMustAcceptMessageRequestViewModel.class);
viewModel.getRecipient().observe(getViewLifecycleOwner(), recipient -> {
description.setText(getString(R.string.CalleeMustAcceptMessageRequestDialogFragment__s_will_get_a_message_request_from_you, recipient.getDisplayName(requireContext())));
viewModel.getRecipient().observe(this, recipient -> {
description.setText(getString(R.string.CalleeMustAcceptMessageRequestDialogFragment__s_will_get_a_message_request_from_you, recipient.getDisplayName(this)));
avatar.setAvatar(GlideApp.with(this), recipient, false);
});
}
@ -83,14 +70,14 @@ public class CalleeMustAcceptMessageRequestDialogFragment extends DialogFragment
public void onResume() {
super.onResume();
handler.postDelayed(dismisser, TIMEOUT_MS);
handler.postDelayed(finisher, TIMEOUT_MS);
}
@Override
public void onPause() {
super.onPause();
handler.removeCallbacks(dismisser);
handler.removeCallbacks(finisher);
}
private static class FallbackPhotoProvider extends Recipient.FallbackPhotoProvider {

View File

@ -190,7 +190,7 @@ public class RecipientUtil {
threadRecipient.isForceSmsSelection() ||
!threadRecipient.isRegistered() ||
hasSentMessageInThread(context, threadId) ||
noSecureMessagesInThread(context, threadId) ||
noSecureMessagesAndNoCallsInThread(context, threadId) ||
isPreMessageRequestThread(context, threadId);
}
@ -200,8 +200,9 @@ public class RecipientUtil {
}
@WorkerThread
private static boolean noSecureMessagesInThread(@NonNull Context context, long threadId) {
return DatabaseFactory.getMmsSmsDatabase(context).getSecureConversationCount(threadId) == 0;
private static boolean noSecureMessagesAndNoCallsInThread(@NonNull Context context, long threadId) {
return DatabaseFactory.getMmsSmsDatabase(context).getSecureConversationCount(threadId) == 0 &&
!DatabaseFactory.getThreadDatabase(context).hasReceivedAnyCallsSince(threadId, 0);
}
@WorkerThread

View File

@ -150,6 +150,7 @@ public class WebRtcCallService extends Service implements CallManager.Observer,
public static final String ACTION_ENDED_REMOTE_HANGUP_ACCEPTED = "ENDED_REMOTE_HANGUP_ACCEPTED";
public static final String ACTION_ENDED_REMOTE_HANGUP_DECLINED = "ENDED_REMOTE_HANGUP_DECLINED";
public static final String ACTION_ENDED_REMOTE_HANGUP_BUSY = "ENDED_REMOTE_HANGUP_BUSY";
public static final String ACTION_ENDED_REMOTE_HANGUP_NEED_PERMISSION = "ENDED_REMOTE_HANGUP_NEED_PERMISSION";
public static final String ACTION_ENDED_REMOTE_BUSY = "ENDED_REMOTE_BUSY";
public static final String ACTION_ENDED_REMOTE_GLARE = "ENDED_REMOTE_GLARE";
public static final String ACTION_ENDED_TIMEOUT = "ENDED_TIMEOUT";
@ -247,6 +248,7 @@ public class WebRtcCallService extends Service implements CallManager.Observer,
else if (intent.getAction().equals(ACTION_ENDED_REMOTE_HANGUP_BUSY)) handleEndedRemoteHangupBusy(intent);
else if (intent.getAction().equals(ACTION_ENDED_REMOTE_HANGUP_DECLINED)) handleEndedRemoteHangupDeclined(intent);
else if (intent.getAction().equals(ACTION_ENDED_REMOTE_BUSY)) handleEndedRemoteBusy(intent);
else if (intent.getAction().equals(ACTION_ENDED_REMOTE_HANGUP_NEED_PERMISSION)) handleEndedRemoteNeedPermission(intent);
else if (intent.getAction().equals(ACTION_ENDED_REMOTE_GLARE)) handleEndedRemoteGlare(intent);
else if (intent.getAction().equals(ACTION_ENDED_TIMEOUT)) handleEndedTimeout(intent);
else if (intent.getAction().equals(ACTION_ENDED_INTERNAL_FAILURE)) handleEndedInternalFailure(intent);
@ -403,9 +405,10 @@ public class WebRtcCallService extends Service implements CallManager.Observer,
return;
}
if (offerType == OfferMessage.Type.NEED_PERMISSION || FeatureFlags.profileForCalling() && !remotePeer.getRecipient().resolve().isProfileSharing()) {
if (FeatureFlags.profileForCalling() && (remotePeer.getRecipient() == null || !RecipientUtil.isMessageRequestAccepted(getApplicationContext(), remotePeer.getRecipient()))) {
Log.i(TAG, "handleReceivedOffer(): Caller is untrusted.");
intent.putExtra(EXTRA_BROADCAST, true);
intent.putExtra(EXTRA_HANGUP_TYPE, HangupMessage.Type.NEED_PERMISSION.getCode());
handleSendHangup(intent);
insertMissedCall(remotePeer, true);
return;
@ -706,11 +709,6 @@ public class WebRtcCallService extends Service implements CallManager.Observer,
Log.i(TAG, "handleSendOffer: id: " + callId.format(remoteDevice));
if (FeatureFlags.profileForCalling() && remotePeer.getRecipient().resolve().getProfileKey() == null) {
offer = "";
offerType = OfferMessage.Type.NEED_PERMISSION;
}
OfferMessage offerMessage = new OfferMessage(callId.longValue(), offer, offerType);
Integer destinationDeviceId = broadcast ? null : remoteDevice;
SignalServiceCallMessage callMessage = SignalServiceCallMessage.forOffer(offerMessage, true, destinationDeviceId);
@ -1137,6 +1135,16 @@ public class WebRtcCallService extends Service implements CallManager.Observer,
}, WebRtcCallActivity.BUSY_SIGNAL_DELAY_FINISH);
}
private void handleEndedRemoteNeedPermission(Intent intent) {
RemotePeer remotePeer = getRemotePeer(intent);
Log.i(TAG, "handleEndedRemoteNeedPermission(): call_id: " + remotePeer.getCallId());
if (remotePeer.callIdEquals(activePeer)) {
sendMessage(WebRtcViewModel.State.CALL_NEEDS_PERMISSION, remotePeer, localCameraState, remoteVideoEnabled, bluetoothAvailable, microphoneEnabled, isRemoteVideoOffer);
}
}
private void handleEndedRemoteGlare(Intent intent) {
RemotePeer remotePeer = getRemotePeer(intent);
@ -1386,6 +1394,8 @@ public class WebRtcCallService extends Service implements CallManager.Observer,
return CallManager.HangupType.NORMAL;
case DECLINED:
return CallManager.HangupType.DECLINED;
case NEED_PERMISSION:
return CallManager.HangupType.NEED_PERMISSION;
default:
throw new IllegalArgumentException("Unexpected hangup type: " + hangupType);
}
@ -1401,6 +1411,8 @@ public class WebRtcCallService extends Service implements CallManager.Observer,
return HangupMessage.Type.NORMAL;
case DECLINED:
return HangupMessage.Type.DECLINED;
case NEED_PERMISSION:
return HangupMessage.Type.NEED_PERMISSION;
default:
throw new IllegalArgumentException("Unexpected hangup type: " + hangupType);
}
@ -1723,6 +1735,9 @@ public class WebRtcCallService extends Service implements CallManager.Observer,
case ENDED_REMOTE_HANGUP:
intent.setAction(ACTION_ENDED_REMOTE_HANGUP);
break;
case ENDED_REMOTE_HANGUP_NEED_PERMISSION:
intent.setAction(ACTION_ENDED_REMOTE_HANGUP_NEED_PERMISSION);
break;
case ENDED_REMOTE_HANGUP_ACCEPTED:
intent.setAction(ACTION_ENDED_REMOTE_HANGUP_ACCEPTED);
break;

View File

@ -25,7 +25,6 @@ import org.thoughtcrime.securesms.WebRtcCallActivity;
import org.thoughtcrime.securesms.conversation.ConversationActivity;
import org.thoughtcrime.securesms.database.DatabaseFactory;
import org.thoughtcrime.securesms.logging.Log;
import org.thoughtcrime.securesms.messagerequests.CalleeMustAcceptMessageRequestDialogFragment;
import org.thoughtcrime.securesms.permissions.Permissions;
import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.ringrtc.RemotePeer;
@ -197,16 +196,11 @@ public class CommunicationActions {
MessageSender.onMessageSent();
if (FeatureFlags.profileForCalling() && recipient.resolve().getProfileKey() == null) {
CalleeMustAcceptMessageRequestDialogFragment.create(recipient.getId())
.show(activity.getSupportFragmentManager(), null);
} else {
Intent activityIntent = new Intent(activity, WebRtcCallActivity.class);
activityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
activity.startActivity(activityIntent);
}
})
.execute();
}
@ -228,17 +222,12 @@ public class CommunicationActions {
MessageSender.onMessageSent();
if (FeatureFlags.profileForCalling() && recipient.resolve().getProfileKey() == null) {
CalleeMustAcceptMessageRequestDialogFragment.create(recipient.getId())
.show(activity.getSupportFragmentManager(), null);
} else {
Intent activityIntent = new Intent(activity, WebRtcCallActivity.class);
activityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
.putExtra(WebRtcCallActivity.EXTRA_ENABLE_VIDEO_IF_AVAILABLE, true);
activity.startActivity(activityIntent);
}
})
.execute();
}

View File

@ -55,7 +55,7 @@ public final class FeatureFlags {
private static final String PINS_MEGAPHONE_KILL_SWITCH = "android.pinsMegaphoneKillSwitch";
private static final String ATTACHMENTS_V3 = "android.attachmentsV3";
private static final String REMOTE_DELETE = "android.remoteDelete";
private static final String PROFILE_FOR_CALLING = "android.profileForCalling";
private static final String PROFILE_FOR_CALLING = "android.profileForCalling.2";
private static final String CALLING_PIP = "android.callingPip";
private static final String VERSIONED_PROFILES_1 = "android.versionedProfiles";
private static final String VERSIONED_PROFILES_2 = "android.versionedProfiles.2";

View File

@ -432,8 +432,8 @@ dependencyVerification {
['org.signal:argon2:13.1',
'0f686ccff0d4842bfcc74d92e8dc780a5f159b9376e37a1189fabbcdac458bef'],
['org.signal:ringrtc-android:2.2.0',
'10da52bd63cb6c0ba45927928b0da3fd59621e3e698ef17f2dbbb1d3b293e80e'],
['org.signal:ringrtc-android:2.3.1',
'2860e38b3e01c25ff23abdb848bd3fd772ffddb4387ea7838b71e2400da1648d'],
['org.signal:signal-metadata-java:0.1.2',
'6aaeb6a33bf3161a3e6ac9db7678277f7a4cf5a2c96b84342e4007ee49bab1bd'],

View File

@ -37,7 +37,8 @@ public class HangupMessage {
NORMAL("normal", SignalServiceProtos.CallMessage.Hangup.Type.HANGUP_NORMAL),
ACCEPTED("accepted", SignalServiceProtos.CallMessage.Hangup.Type.HANGUP_ACCEPTED),
DECLINED("declined", SignalServiceProtos.CallMessage.Hangup.Type.HANGUP_DECLINED),
BUSY("busy", SignalServiceProtos.CallMessage.Hangup.Type.HANGUP_BUSY);
BUSY("busy", SignalServiceProtos.CallMessage.Hangup.Type.HANGUP_BUSY),
NEED_PERMISSION("need_permission", SignalServiceProtos.CallMessage.Hangup.Type.HANGUP_NEED_PERMISSION);
private final String code;
private final SignalServiceProtos.CallMessage.Hangup.Type protoType;

View File

@ -29,8 +29,7 @@ public class OfferMessage {
public enum Type {
AUDIO_CALL("audio_call", SignalServiceProtos.CallMessage.Offer.Type.OFFER_AUDIO_CALL),
VIDEO_CALL("video_call", SignalServiceProtos.CallMessage.Offer.Type.OFFER_VIDEO_CALL),
NEED_PERMISSION("need_permission", SignalServiceProtos.CallMessage.Offer.Type.OFFER_NEED_PERMISSION);
VIDEO_CALL("video_call", SignalServiceProtos.CallMessage.Offer.Type.OFFER_VIDEO_CALL);
private final String code;
private final SignalServiceProtos.CallMessage.Offer.Type protoType;

View File

@ -46,7 +46,7 @@ message CallMessage {
enum Type {
OFFER_AUDIO_CALL = 0;
OFFER_VIDEO_CALL = 1;
OFFER_NEED_PERMISSION = 2;
// 2 is reserved, removed OFFER_NEED_PERMISSION
}
optional uint64 id = 1;
@ -76,6 +76,7 @@ message CallMessage {
HANGUP_ACCEPTED = 1;
HANGUP_DECLINED = 2;
HANGUP_BUSY = 3;
HANGUP_NEED_PERMISSION = 4;
}
optional uint64 id = 1;