Fix crash when call concluded on non-existent remote peer.

This commit is contained in:
Cody Henthorne
2020-11-18 11:34:06 -05:00
committed by GitHub
parent 725d793b20
commit 3b7fbbaf6e
7 changed files with 34 additions and 18 deletions

View File

@@ -149,8 +149,13 @@ public class ActiveCallActionProcessorDelegate extends WebRtcActionProcessor {
} }
@Override @Override
protected @NonNull WebRtcServiceState handleCallConcluded(@NonNull WebRtcServiceState currentState, @NonNull RemotePeer remotePeer) { protected @NonNull WebRtcServiceState handleCallConcluded(@NonNull WebRtcServiceState currentState, @Nullable RemotePeer remotePeer) {
Log.i(tag, "handleCallConcluded():"); Log.i(tag, "handleCallConcluded():");
if (remotePeer == null) {
return currentState;
}
Log.i(tag, "delete remotePeer callId: " + remotePeer.getCallId() + " key: " + remotePeer.hashCode()); Log.i(tag, "delete remotePeer callId: " + remotePeer.getCallId() + " key: " + remotePeer.hashCode());
return currentState.builder() return currentState.builder()
.changeCallInfoState() .changeCallInfoState()

View File

@@ -6,7 +6,6 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import org.signal.ringrtc.CallException; import org.signal.ringrtc.CallException;
import org.thoughtcrime.securesms.events.CallParticipant;
import org.thoughtcrime.securesms.logging.Log; import org.thoughtcrime.securesms.logging.Log;
import org.thoughtcrime.securesms.ringrtc.IceCandidateParcel; import org.thoughtcrime.securesms.ringrtc.IceCandidateParcel;
import org.thoughtcrime.securesms.ringrtc.RemotePeer; import org.thoughtcrime.securesms.ringrtc.RemotePeer;
@@ -14,7 +13,6 @@ import org.thoughtcrime.securesms.service.webrtc.state.WebRtcServiceState;
import org.thoughtcrime.securesms.webrtc.locks.LockManager; import org.thoughtcrime.securesms.webrtc.locks.LockManager;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Objects;
/** /**
* Handles action for a connected/ongoing call. At this point it's mostly responding * Handles action for a connected/ongoing call. At this point it's mostly responding
@@ -121,7 +119,7 @@ public class ConnectedCallActionProcessor extends DeviceAwareActionProcessor {
} }
@Override @Override
protected @NonNull WebRtcServiceState handleCallConcluded(@NonNull WebRtcServiceState currentState, @NonNull RemotePeer remotePeer) { protected @NonNull WebRtcServiceState handleCallConcluded(@NonNull WebRtcServiceState currentState, @Nullable RemotePeer remotePeer) {
return activeCallDelegate.handleCallConcluded(currentState, remotePeer); return activeCallDelegate.handleCallConcluded(currentState, remotePeer);
} }
} }

View File

@@ -1,10 +1,12 @@
package org.thoughtcrime.securesms.service.webrtc; package org.thoughtcrime.securesms.service.webrtc;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.thoughtcrime.securesms.logging.Log; import org.thoughtcrime.securesms.logging.Log;
import org.thoughtcrime.securesms.ringrtc.RemotePeer; import org.thoughtcrime.securesms.ringrtc.RemotePeer;
import org.thoughtcrime.securesms.service.webrtc.state.WebRtcServiceState; import org.thoughtcrime.securesms.service.webrtc.state.WebRtcServiceState;
import org.thoughtcrime.securesms.service.webrtc.state.WebRtcServiceStateBuilder;
import org.whispersystems.signalservice.api.messages.calls.OfferMessage; import org.whispersystems.signalservice.api.messages.calls.OfferMessage;
/** /**
@@ -39,13 +41,20 @@ public class DisconnectingCallActionProcessor extends WebRtcActionProcessor {
} }
@Override @Override
protected @NonNull WebRtcServiceState handleCallConcluded(@NonNull WebRtcServiceState currentState, @NonNull RemotePeer remotePeer) { protected @NonNull WebRtcServiceState handleCallConcluded(@NonNull WebRtcServiceState currentState, @Nullable RemotePeer remotePeer) {
Log.i(TAG, "handleCallConcluded():"); Log.i(TAG, "handleCallConcluded():");
WebRtcServiceStateBuilder builder = currentState.builder()
.actionProcessor(new IdleActionProcessor(webRtcInteractor));
if (remotePeer != null) {
Log.i(TAG, "delete remotePeer callId: " + remotePeer.getCallId() + " key: " + remotePeer.hashCode()); Log.i(TAG, "delete remotePeer callId: " + remotePeer.getCallId() + " key: " + remotePeer.hashCode());
return currentState.builder()
.actionProcessor(new IdleActionProcessor(webRtcInteractor)) builder.changeCallInfoState()
.changeCallInfoState()
.removeRemotePeer(remotePeer) .removeRemotePeer(remotePeer)
.build(); .commit();
}
return builder.build();
} }
} }

View File

@@ -211,7 +211,7 @@ public class IncomingCallActionProcessor extends DeviceAwareActionProcessor {
} }
@Override @Override
protected @NonNull WebRtcServiceState handleCallConcluded(@NonNull WebRtcServiceState currentState, @NonNull RemotePeer remotePeer) { protected @NonNull WebRtcServiceState handleCallConcluded(@NonNull WebRtcServiceState currentState, @Nullable RemotePeer remotePeer) {
return activeCallDelegate.handleCallConcluded(currentState, remotePeer); return activeCallDelegate.handleCallConcluded(currentState, remotePeer);
} }

View File

@@ -211,7 +211,7 @@ public class OutgoingCallActionProcessor extends DeviceAwareActionProcessor {
} }
@Override @Override
protected @NonNull WebRtcServiceState handleCallConcluded(@NonNull WebRtcServiceState currentState, @NonNull RemotePeer remotePeer) { protected @NonNull WebRtcServiceState handleCallConcluded(@NonNull WebRtcServiceState currentState, @Nullable RemotePeer remotePeer) {
return activeCallDelegate.handleCallConcluded(currentState, remotePeer); return activeCallDelegate.handleCallConcluded(currentState, remotePeer);
} }

View File

@@ -119,6 +119,7 @@ import static org.thoughtcrime.securesms.service.webrtc.WebRtcIntentParser.getEr
import static org.thoughtcrime.securesms.service.webrtc.WebRtcIntentParser.getGroupMembershipToken; import static org.thoughtcrime.securesms.service.webrtc.WebRtcIntentParser.getGroupMembershipToken;
import static org.thoughtcrime.securesms.service.webrtc.WebRtcIntentParser.getIceCandidates; import static org.thoughtcrime.securesms.service.webrtc.WebRtcIntentParser.getIceCandidates;
import static org.thoughtcrime.securesms.service.webrtc.WebRtcIntentParser.getIceServers; import static org.thoughtcrime.securesms.service.webrtc.WebRtcIntentParser.getIceServers;
import static org.thoughtcrime.securesms.service.webrtc.WebRtcIntentParser.getNullableRemotePeerFromMap;
import static org.thoughtcrime.securesms.service.webrtc.WebRtcIntentParser.getOfferMessageType; import static org.thoughtcrime.securesms.service.webrtc.WebRtcIntentParser.getOfferMessageType;
import static org.thoughtcrime.securesms.service.webrtc.WebRtcIntentParser.getRemotePeer; import static org.thoughtcrime.securesms.service.webrtc.WebRtcIntentParser.getRemotePeer;
import static org.thoughtcrime.securesms.service.webrtc.WebRtcIntentParser.getRemotePeerFromMap; import static org.thoughtcrime.securesms.service.webrtc.WebRtcIntentParser.getRemotePeerFromMap;
@@ -180,7 +181,7 @@ public abstract class WebRtcActionProcessor {
case ACTION_CALL_CONNECTED: return handleCallConnected(currentState, getRemotePeerFromMap(intent, currentState)); case ACTION_CALL_CONNECTED: return handleCallConnected(currentState, getRemotePeerFromMap(intent, currentState));
case ACTION_RECEIVED_OFFER_WHILE_ACTIVE: return handleReceivedOfferWhileActive(currentState, getRemotePeerFromMap(intent, currentState)); case ACTION_RECEIVED_OFFER_WHILE_ACTIVE: return handleReceivedOfferWhileActive(currentState, getRemotePeerFromMap(intent, currentState));
case ACTION_SEND_BUSY: return handleSendBusy(currentState, CallMetadata.fromIntent(intent), getBroadcastFlag(intent)); case ACTION_SEND_BUSY: return handleSendBusy(currentState, CallMetadata.fromIntent(intent), getBroadcastFlag(intent));
case ACTION_CALL_CONCLUDED: return handleCallConcluded(currentState, getRemotePeerFromMap(intent, currentState)); case ACTION_CALL_CONCLUDED: return handleCallConcluded(currentState, getNullableRemotePeerFromMap(intent, currentState));
case ACTION_REMOTE_VIDEO_ENABLE: return handleRemoteVideoEnable(currentState, getEnable(intent)); case ACTION_REMOTE_VIDEO_ENABLE: return handleRemoteVideoEnable(currentState, getEnable(intent));
case ACTION_RECEIVE_HANGUP: return handleReceivedHangup(currentState, CallMetadata.fromIntent(intent), HangupMetadata.fromIntent(intent)); case ACTION_RECEIVE_HANGUP: return handleReceivedHangup(currentState, CallMetadata.fromIntent(intent), HangupMetadata.fromIntent(intent));
case ACTION_LOCAL_HANGUP: return handleLocalHangup(currentState); case ACTION_LOCAL_HANGUP: return handleLocalHangup(currentState);
@@ -425,7 +426,7 @@ public abstract class WebRtcActionProcessor {
return currentState; return currentState;
} }
protected @NonNull WebRtcServiceState handleCallConcluded(@NonNull WebRtcServiceState currentState, @NonNull RemotePeer remotePeer) { protected @NonNull WebRtcServiceState handleCallConcluded(@NonNull WebRtcServiceState currentState, @Nullable RemotePeer remotePeer) {
Log.i(tag, "handleCallConcluded not processed"); Log.i(tag, "handleCallConcluded not processed");
return currentState; return currentState;
} }

View File

@@ -75,16 +75,19 @@ public final class WebRtcIntentParser {
} }
public static @NonNull RemotePeer getRemotePeerFromMap(@NonNull Intent intent, @NonNull WebRtcServiceState currentState) { public static @NonNull RemotePeer getRemotePeerFromMap(@NonNull Intent intent, @NonNull WebRtcServiceState currentState) {
int remotePeerKey = getRemotePeerKey(intent); RemotePeer remotePeer = getNullableRemotePeerFromMap(intent, currentState);
RemotePeer remotePeer = currentState.getCallInfoState().getPeer(remotePeerKey);
if (remotePeer == null) { if (remotePeer == null) {
throw new AssertionError("No RemotePeer in map for key: " + remotePeerKey + "!"); throw new AssertionError("No RemotePeer in map for key: " + getRemotePeerKey(intent) + "!");
} }
return remotePeer; return remotePeer;
} }
public static @Nullable RemotePeer getNullableRemotePeerFromMap(@NonNull Intent intent, @NonNull WebRtcServiceState currentState) {
return currentState.getCallInfoState().getPeer(getRemotePeerKey(intent));
}
public static int getRemotePeerKey(@NonNull Intent intent) { public static int getRemotePeerKey(@NonNull Intent intent) {
if (!intent.hasExtra(EXTRA_REMOTE_PEER_KEY)) { if (!intent.hasExtra(EXTRA_REMOTE_PEER_KEY)) {
throw new AssertionError("No RemotePeer key in intent!"); throw new AssertionError("No RemotePeer key in intent!");