Retain call start timestamp per peer to prevent race conditions.

This commit is contained in:
Cody Henthorne 2020-09-24 10:43:39 -04:00
parent f9a9ee6b0c
commit 4cd433b6bc
2 changed files with 25 additions and 14 deletions

View file

@ -23,17 +23,20 @@ public final class RemotePeer implements Remote, Parcelable
@NonNull private final RecipientId recipientId;
@NonNull private CallState callState;
@NonNull private CallId callId;
private long callStartTimestamp;
public RemotePeer(@NonNull RecipientId recipientId) {
this.recipientId = recipientId;
this.callState = CallState.IDLE;
this.callId = new CallId(-1L);
this.recipientId = recipientId;
this.callState = CallState.IDLE;
this.callId = new CallId(-1L);
this.callStartTimestamp = 0;
}
private RemotePeer(@NonNull Parcel in) {
this.recipientId = RecipientId.CREATOR.createFromParcel(in);
this.callState = CallState.values()[in.readInt()];
this.callId = new CallId(in.readLong());
this.recipientId = RecipientId.CREATOR.createFromParcel(in);
this.callState = CallState.values()[in.readInt()];
this.callId = new CallId(in.readLong());
this.callStartTimestamp = in.readLong();
}
public @NonNull CallId getCallId() {
@ -44,6 +47,14 @@ public final class RemotePeer implements Remote, Parcelable
this.callId = callId;
}
public void setCallStartTimestamp(long callStartTimestamp) {
this.callStartTimestamp = callStartTimestamp;
}
public long getCallStartTimestamp() {
return callStartTimestamp;
}
public @NonNull CallState getState() {
return callState;
}
@ -135,6 +146,7 @@ public final class RemotePeer implements Remote, Parcelable
recipientId.writeToParcel(dest, flags);
dest.writeInt(callState.ordinal());
dest.writeLong(callId.longValue());
dest.writeLong(callStartTimestamp);
}
public static final Creator<RemotePeer> CREATOR = new Creator<RemotePeer>() {

View file

@ -201,7 +201,6 @@ public class WebRtcCallService extends Service implements CallManager.Observer,
@Nullable private RemotePeer busyPeer;
@Nullable private RemotePeer preJoinPeer;
@Nullable private SparseArray<RemotePeer> peerMap;
private long callStartTimestamp;
@Nullable private EglBase eglBase;
@Nullable private BroadcastVideoSink localSink;
@ -436,7 +435,7 @@ public class WebRtcCallService extends Service implements CallManager.Observer,
}
peerMap.append(remotePeer.hashCode(), remotePeer);
callStartTimestamp = serverReceivedTimestamp;
remotePeer.setCallStartTimestamp(serverReceivedTimestamp);
Log.i(TAG, "add remotePeer callId: " + remotePeer.getCallId() + " key: " + remotePeer.hashCode());
isRemoteVideoOffer = offerType == OfferMessage.Type.VIDEO_CALL;
@ -524,7 +523,7 @@ public class WebRtcCallService extends Service implements CallManager.Observer,
EventBus.getDefault().removeStickyEvent(WebRtcViewModel.class);
peerMap.append(remotePeer.hashCode(), remotePeer);
callStartTimestamp = System.currentTimeMillis();
remotePeer.setCallStartTimestamp(System.currentTimeMillis());
Log.i(TAG, "add remotePeer callId: " + remotePeer.getCallId() + " key: " + remotePeer.hashCode());
initializeVideo();
@ -1168,7 +1167,7 @@ public class WebRtcCallService extends Service implements CallManager.Observer,
Log.i(TAG, "handleReceivedOfferExpired(): call_id: " + remotePeer.getCallId());
insertMissedCall(remotePeer, true, callStartTimestamp);
insertMissedCall(remotePeer, true, remotePeer.getCallStartTimestamp());
terminate(remotePeer);
}
@ -1197,7 +1196,7 @@ public class WebRtcCallService extends Service implements CallManager.Observer,
stopForeground(true);
}
insertMissedCall(remotePeer, true, callStartTimestamp);
insertMissedCall(remotePeer, true, remotePeer.getCallStartTimestamp());
terminate(remotePeer);
}
@ -1218,7 +1217,7 @@ public class WebRtcCallService extends Service implements CallManager.Observer,
boolean incomingBeforeAccept = remotePeer.getState() == CallState.ANSWERING || remotePeer.getState() == CallState.LOCAL_RINGING;
if (incomingBeforeAccept) {
insertMissedCall(remotePeer, true, callStartTimestamp);
insertMissedCall(remotePeer, true, remotePeer.getCallStartTimestamp());
}
terminate(remotePeer);
@ -1305,7 +1304,7 @@ public class WebRtcCallService extends Service implements CallManager.Observer,
boolean incomingBeforeAccept = remotePeer.getState() == CallState.ANSWERING || remotePeer.getState() == CallState.LOCAL_RINGING;
if (incomingBeforeAccept) {
insertMissedCall(remotePeer, true, callStartTimestamp);
insertMissedCall(remotePeer, true, remotePeer.getCallStartTimestamp());
}
terminate(remotePeer);
@ -1321,7 +1320,7 @@ public class WebRtcCallService extends Service implements CallManager.Observer,
}
if (remotePeer.getState() == CallState.ANSWERING || remotePeer.getState() == CallState.LOCAL_RINGING) {
insertMissedCall(remotePeer, true, callStartTimestamp);
insertMissedCall(remotePeer, true, remotePeer.getCallStartTimestamp());
}
terminate(remotePeer);