Fix improper glare handling.

This commit is contained in:
Cody Henthorne
2021-11-03 13:07:16 -04:00
committed by Greyson Parrelli
parent 09dd2583b9
commit 49270e677e
10 changed files with 67 additions and 89 deletions

View File

@@ -484,6 +484,12 @@ public class WebRtcCallActivity extends BaseActivity implements SafetyNumberChan
delayedFinish();
}
private void handleGlare(@NonNull Recipient recipient) {
Log.i(TAG, "handleGlare: " + recipient.getId());
callScreen.setStatus("");
}
private void handleCallRinging() {
callScreen.setStatus(getString(R.string.RedPhone_ringing));
}
@@ -629,6 +635,8 @@ public class WebRtcCallActivity extends BaseActivity implements SafetyNumberChan
handleCallRinging(); break;
case CALL_DISCONNECTED:
handleTerminate(event.getRecipient(), HangupMessage.Type.NORMAL); break;
case CALL_DISCONNECTED_GLARE:
handleGlare(event.getRecipient()); break;
case CALL_ACCEPTED_ELSEWHERE:
handleTerminate(event.getRecipient(), HangupMessage.Type.ACCEPTED); break;
case CALL_DECLINED_ELSEWHERE:

View File

@@ -116,6 +116,7 @@ public class WebRtcCallView extends ConstraintLayout {
private View foldParticipantCountWrapper;
private TextView foldParticipantCount;
private AvatarImageView largeHeaderAvatar;
private ConstraintSet largeHeaderConstraints;
private ConstraintSet smallHeaderConstraints;
private Guideline statusBarGuideline;
private View fullScreenShade;
@@ -293,6 +294,9 @@ public class WebRtcCallView extends ConstraintLayout {
rotatableControls.add(smallLocalRender.findViewById(R.id.call_participant_mic_muted));
rotatableControls.add(ringToggle);
largeHeaderConstraints = new ConstraintSet();
largeHeaderConstraints.clone(getContext(), R.layout.webrtc_call_view_header_large);
smallHeaderConstraints = new ConstraintSet();
smallHeaderConstraints.clone(getContext(), R.layout.webrtc_call_view_header_small);
}
@@ -689,6 +693,7 @@ public class WebRtcCallView extends ConstraintLayout {
if (!visibleViewSet.equals(lastVisibleSet) ||
!controls.isFadeOutEnabled() ||
(webRtcControls.showSmallHeader() && largeHeaderAvatar.getVisibility() == View.VISIBLE) ||
(!webRtcControls.showSmallHeader() && largeHeaderAvatar.getVisibility() == View.GONE) ||
forceUpdate)
{
@@ -930,6 +935,8 @@ public class WebRtcCallView extends ConstraintLayout {
if (showSmallHeader) {
smallHeaderConstraints.applyTo(toolbar);
} else {
largeHeaderConstraints.applyTo(toolbar);
}
}

View File

@@ -343,6 +343,9 @@ public class WebRtcCallViewModel extends ViewModel {
case CALL_DISCONNECTED:
callState = WebRtcControls.CallState.ENDING;
break;
case CALL_DISCONNECTED_GLARE:
callState = WebRtcControls.CallState.INCOMING;
break;
case NETWORK_FAILURE:
callState = WebRtcControls.CallState.ERROR;
break;

View File

@@ -21,6 +21,7 @@ class WebRtcViewModel(state: WebRtcServiceState) {
CALL_RINGING,
CALL_BUSY,
CALL_DISCONNECTED,
CALL_DISCONNECTED_GLARE,
CALL_NEEDS_PERMISSION,
// Error states

View File

@@ -45,7 +45,7 @@ public class ActiveCallActionProcessorDelegate extends WebRtcActionProcessor {
put(CallEvent.ENDED_REMOTE_HANGUP_DECLINED, WebRtcViewModel.State.CALL_DECLINED_ELSEWHERE);
put(CallEvent.ENDED_REMOTE_BUSY, WebRtcViewModel.State.CALL_BUSY);
put(CallEvent.ENDED_REMOTE_HANGUP_NEED_PERMISSION, WebRtcViewModel.State.CALL_NEEDS_PERMISSION);
put(CallEvent.ENDED_REMOTE_GLARE, WebRtcViewModel.State.CALL_DISCONNECTED);
put(CallEvent.ENDED_REMOTE_GLARE, WebRtcViewModel.State.CALL_DISCONNECTED_GLARE);
}};
public ActiveCallActionProcessorDelegate(@NonNull WebRtcInteractor webRtcInteractor, @NonNull String tag) {
@@ -60,26 +60,6 @@ public class ActiveCallActionProcessorDelegate extends WebRtcActionProcessor {
return currentState;
}
@Override
protected @NonNull WebRtcServiceState handleSendIceCandidates(@NonNull WebRtcServiceState currentState,
@NonNull WebRtcData.CallMetadata callMetadata,
boolean broadcast,
@NonNull List<byte[]> iceCandidates)
{
Log.i(tag, "handleSendIceCandidates(): id: " + callMetadata.getCallId().format(callMetadata.getRemoteDevice()));
List<IceUpdateMessage> iceUpdateMessages = Stream.of(iceCandidates)
.map(c -> new IceUpdateMessage(callMetadata.getCallId().longValue(), c, null))
.toList();
Integer destinationDeviceId = broadcast ? null : callMetadata.getRemoteDevice();
SignalServiceCallMessage callMessage = SignalServiceCallMessage.forIceUpdates(iceUpdateMessages, true, destinationDeviceId);
webRtcInteractor.sendCallMessage(callMetadata.getRemotePeer(), callMessage);
return currentState;
}
@Override
protected @NonNull WebRtcServiceState handleRemoteVideoEnable(@NonNull WebRtcServiceState currentState, boolean enable) {
RemotePeer activePeer = currentState.getCallInfoState().requireActivePeer();

View File

@@ -86,15 +86,6 @@ public class ConnectedCallActionProcessor extends DeviceAwareActionProcessor {
return activeCallDelegate.handleScreenSharingEnable(currentState, enable);
}
@Override
protected @NonNull WebRtcServiceState handleSendIceCandidates(@NonNull WebRtcServiceState currentState,
@NonNull WebRtcData.CallMetadata callMetadata,
boolean broadcast,
@NonNull List<byte[]> iceCandidates)
{
return activeCallDelegate.handleSendIceCandidates(currentState, callMetadata, broadcast, iceCandidates);
}
@Override
protected @NonNull WebRtcServiceState handleLocalHangup(@NonNull WebRtcServiceState currentState) {
return activeCallDelegate.handleLocalHangup(currentState);

View File

@@ -56,23 +56,6 @@ public class IncomingCallActionProcessor extends DeviceAwareActionProcessor {
return activeCallDelegate.handleIsInCallQuery(currentState, resultReceiver);
}
@Override
protected @NonNull WebRtcServiceState handleSendAnswer(@NonNull WebRtcServiceState currentState,
@NonNull WebRtcData.CallMetadata callMetadata,
@NonNull WebRtcData.AnswerMetadata answerMetadata,
boolean broadcast)
{
Log.i(TAG, "handleSendAnswer(): id: " + callMetadata.getCallId().format(callMetadata.getRemoteDevice()));
AnswerMessage answerMessage = new AnswerMessage(callMetadata.getCallId().longValue(), answerMetadata.getSdp(), answerMetadata.getOpaque());
Integer destinationDeviceId = broadcast ? null : callMetadata.getRemoteDevice();
SignalServiceCallMessage callMessage = SignalServiceCallMessage.forAnswer(answerMessage, true, destinationDeviceId);
webRtcInteractor.sendCallMessage(callMetadata.getRemotePeer(), callMessage);
return currentState;
}
@Override
public @NonNull WebRtcServiceState handleTurnServerUpdate(@NonNull WebRtcServiceState currentState,
@NonNull List<PeerConnection.IceServer> iceServers,
@@ -226,15 +209,6 @@ public class IncomingCallActionProcessor extends DeviceAwareActionProcessor {
return activeCallDelegate.handleCallConcluded(currentState, remotePeer);
}
@Override
protected @NonNull WebRtcServiceState handleSendIceCandidates(@NonNull WebRtcServiceState currentState,
@NonNull WebRtcData.CallMetadata callMetadata,
boolean broadcast,
@NonNull List<byte[]> iceCandidates)
{
return activeCallDelegate.handleSendIceCandidates(currentState, callMetadata, broadcast, iceCandidates);
}
@Override
public @NonNull WebRtcServiceState handleCallConnected(@NonNull WebRtcServiceState currentState, @NonNull RemotePeer remotePeer) {
return callSetupDelegate.handleCallConnected(currentState, remotePeer);

View File

@@ -86,21 +86,6 @@ public class OutgoingCallActionProcessor extends DeviceAwareActionProcessor {
.build();
}
@Override
protected @NonNull WebRtcServiceState handleSendOffer(@NonNull WebRtcServiceState currentState, @NonNull CallMetadata callMetadata, @NonNull OfferMetadata offerMetadata, boolean broadcast) {
Log.i(TAG, "handleSendOffer(): id: " + callMetadata.getCallId().format(callMetadata.getRemoteDevice()));
OfferMessage offerMessage = new OfferMessage(callMetadata.getCallId().longValue(), offerMetadata.getSdp(), offerMetadata.getOfferType(), offerMetadata.getOpaque());
Integer destinationDeviceId = broadcast ? null : callMetadata.getRemoteDevice();
SignalServiceCallMessage callMessage = SignalServiceCallMessage.forOffer(offerMessage, true, destinationDeviceId);
Recipient callRecipient = currentState.getCallInfoState().getCallRecipient();
RecipientUtil.shareProfileIfFirstSecureMessage(context, callRecipient);
webRtcInteractor.sendCallMessage(callMetadata.getRemotePeer(), callMessage);
return currentState;
}
@Override
public @NonNull WebRtcServiceState handleTurnServerUpdate(@NonNull WebRtcServiceState currentState,
@NonNull List<PeerConnection.IceServer> iceServers,
@@ -227,15 +212,6 @@ public class OutgoingCallActionProcessor extends DeviceAwareActionProcessor {
return activeCallDelegate.handleCallConcluded(currentState, remotePeer);
}
@Override
protected @NonNull WebRtcServiceState handleSendIceCandidates(@NonNull WebRtcServiceState currentState,
@NonNull CallMetadata callMetadata,
boolean broadcast,
@NonNull List<byte[]> iceCandidates)
{
return activeCallDelegate.handleSendIceCandidates(currentState, callMetadata, broadcast, iceCandidates);
}
@Override
public @NonNull WebRtcServiceState handleCallConnected(@NonNull WebRtcServiceState currentState, @NonNull RemotePeer remotePeer) {
return callSetupDelegate.handleCallConnected(currentState, remotePeer);

View File

@@ -816,7 +816,15 @@ public final class SignalCallManager implements CallManager.Observer, GroupCall.
}
}
process((s, p) -> p.handleTurnServerUpdate(s, iceServers, TextSecurePreferences.isTurnOnly(context)));
process((s, p) -> {
RemotePeer activePeer = s.getCallInfoState().getActivePeer();
if (activePeer != null && activePeer.getCallId().equals(remotePeer.getCallId())) {
return p.handleTurnServerUpdate(s, iceServers, TextSecurePreferences.isTurnOnly(context));
}
Log.w(TAG, "Ignoring received turn servers for incorrect call id. requesting_call_id: " + remotePeer.getCallId() + " current_call_id: " + (activePeer != null ? activePeer.getCallId() : "null"));
return s;
});
} catch (IOException e) {
Log.w(TAG, "Unable to retrieve turn servers: ", e);
process((s, p) -> p.handleSetupFailure(s, remotePeer.getCallId()));

View File

@@ -6,6 +6,8 @@ import android.os.ResultReceiver;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.annimon.stream.Stream;
import org.signal.core.util.logging.Log;
import org.signal.ringrtc.CallException;
import org.signal.ringrtc.CallId;
@@ -41,8 +43,10 @@ import org.webrtc.PeerConnection;
import org.whispersystems.libsignal.IdentityKey;
import org.whispersystems.libsignal.InvalidKeyException;
import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.signalservice.api.messages.calls.AnswerMessage;
import org.whispersystems.signalservice.api.messages.calls.BusyMessage;
import org.whispersystems.signalservice.api.messages.calls.HangupMessage;
import org.whispersystems.signalservice.api.messages.calls.IceUpdateMessage;
import org.whispersystems.signalservice.api.messages.calls.OfferMessage;
import org.whispersystems.signalservice.api.messages.calls.SignalServiceCallMessage;
@@ -117,8 +121,17 @@ public abstract class WebRtcActionProcessor {
return currentState;
}
protected @NonNull WebRtcServiceState handleSendOffer(@NonNull WebRtcServiceState currentState, @NonNull CallMetadata callMetadata, @NonNull OfferMetadata offerMetadata, boolean broadcast) {
Log.i(tag, "handleSendOffer not processed");
protected final @NonNull WebRtcServiceState handleSendOffer(@NonNull WebRtcServiceState currentState, @NonNull CallMetadata callMetadata, @NonNull OfferMetadata offerMetadata, boolean broadcast) {
Log.i(tag, "handleSendOffer(): id: " + callMetadata.getCallId().format(callMetadata.getRemoteDevice()));
OfferMessage offerMessage = new OfferMessage(callMetadata.getCallId().longValue(), offerMetadata.getSdp(), offerMetadata.getOfferType(), offerMetadata.getOpaque());
Integer destinationDeviceId = broadcast ? null : callMetadata.getRemoteDevice();
SignalServiceCallMessage callMessage = SignalServiceCallMessage.forOffer(offerMessage, true, destinationDeviceId);
Recipient callRecipient = currentState.getCallInfoState().getCallRecipient();
RecipientUtil.shareProfileIfFirstSecureMessage(context, callRecipient);
webRtcInteractor.sendCallMessage(callMetadata.getRemotePeer(), callMessage);
return currentState;
}
@@ -240,12 +253,19 @@ public abstract class WebRtcActionProcessor {
return currentState;
}
protected @NonNull WebRtcServiceState handleSendAnswer(@NonNull WebRtcServiceState currentState,
protected final @NonNull WebRtcServiceState handleSendAnswer(@NonNull WebRtcServiceState currentState,
@NonNull CallMetadata callMetadata,
@NonNull AnswerMetadata answerMetadata,
boolean broadcast)
{
Log.i(tag, "handleSendAnswer not processed");
Log.i(tag, "handleSendAnswer(): id: " + callMetadata.getCallId().format(callMetadata.getRemoteDevice()));
AnswerMessage answerMessage = new AnswerMessage(callMetadata.getCallId().longValue(), answerMetadata.getSdp(), answerMetadata.getOpaque());
Integer destinationDeviceId = broadcast ? null : callMetadata.getRemoteDevice();
SignalServiceCallMessage callMessage = SignalServiceCallMessage.forAnswer(answerMessage, true, destinationDeviceId);
webRtcInteractor.sendCallMessage(callMetadata.getRemotePeer(), callMessage);
return currentState;
}
@@ -263,7 +283,7 @@ public abstract class WebRtcActionProcessor {
return currentState;
}
protected @NonNull WebRtcServiceState handleSendBusy(@NonNull WebRtcServiceState currentState, @NonNull CallMetadata callMetadata, boolean broadcast) {
protected final @NonNull WebRtcServiceState handleSendBusy(@NonNull WebRtcServiceState currentState, @NonNull CallMetadata callMetadata, boolean broadcast) {
Log.i(tag, "handleSendBusy(): id: " + callMetadata.getCallId().format(callMetadata.getRemoteDevice()));
BusyMessage busyMessage = new BusyMessage(callMetadata.getCallId().longValue());
@@ -310,7 +330,7 @@ public abstract class WebRtcActionProcessor {
return currentState;
}
protected @NonNull WebRtcServiceState handleSendHangup(@NonNull WebRtcServiceState currentState,
protected final @NonNull WebRtcServiceState handleSendHangup(@NonNull WebRtcServiceState currentState,
@NonNull CallMetadata callMetadata,
@NonNull HangupMetadata hangupMetadata,
boolean broadcast)
@@ -386,8 +406,18 @@ public abstract class WebRtcActionProcessor {
//region Call setup
protected @NonNull WebRtcServiceState handleSendIceCandidates(@NonNull WebRtcServiceState currentState, @NonNull CallMetadata callMetadata, boolean broadcast, @NonNull List<byte[]> iceCandidates) {
Log.i(tag, "handleSendIceCandidates not processed");
protected final @NonNull WebRtcServiceState handleSendIceCandidates(@NonNull WebRtcServiceState currentState, @NonNull CallMetadata callMetadata, boolean broadcast, @NonNull List<byte[]> iceCandidates) {
Log.i(tag, "handleSendIceCandidates(): id: " + callMetadata.getCallId().format(callMetadata.getRemoteDevice()));
List<IceUpdateMessage> iceUpdateMessages = Stream.of(iceCandidates)
.map(c -> new IceUpdateMessage(callMetadata.getCallId().longValue(), c, null))
.toList();
Integer destinationDeviceId = broadcast ? null : callMetadata.getRemoteDevice();
SignalServiceCallMessage callMessage = SignalServiceCallMessage.forIceUpdates(iceUpdateMessages, true, destinationDeviceId);
webRtcInteractor.sendCallMessage(callMetadata.getRemotePeer(), callMessage);
return currentState;
}