Fix ellapsed call timer restarting between activity restarts.

This commit is contained in:
Alex Hart 2020-05-15 16:24:53 -03:00
parent fa5729bac6
commit e2ac55e9ac
3 changed files with 31 additions and 10 deletions

View File

@ -14,9 +14,7 @@ import org.thoughtcrime.securesms.events.WebRtcViewModel;
import org.thoughtcrime.securesms.recipients.LiveRecipient; import org.thoughtcrime.securesms.recipients.LiveRecipient;
import org.thoughtcrime.securesms.recipients.Recipient; import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.ringrtc.CameraState; import org.thoughtcrime.securesms.ringrtc.CameraState;
import org.thoughtcrime.securesms.service.WebRtcCallService;
import org.thoughtcrime.securesms.util.SingleLiveEvent; import org.thoughtcrime.securesms.util.SingleLiveEvent;
import org.thoughtcrime.securesms.util.livedata.LiveDataPair;
import org.thoughtcrime.securesms.util.livedata.LiveDataUtil; import org.thoughtcrime.securesms.util.livedata.LiveDataUtil;
public class WebRtcCallViewModel extends ViewModel { public class WebRtcCallViewModel extends ViewModel {
@ -134,11 +132,11 @@ public class WebRtcCallViewModel extends ViewModel {
updateWebRtcControls(webRtcViewModel.getState(), webRtcViewModel.isRemoteVideoOffer()); updateWebRtcControls(webRtcViewModel.getState(), webRtcViewModel.isRemoteVideoOffer());
if (webRtcViewModel.getState() == WebRtcViewModel.State.CALL_CONNECTED && callConnectedTime == -1) { if (webRtcViewModel.getState() == WebRtcViewModel.State.CALL_CONNECTED && callConnectedTime == -1) {
callConnectedTime = System.currentTimeMillis(); callConnectedTime = webRtcViewModel.getCallConnectedTime();
startTimer(); startTimer();
} else if (webRtcViewModel.getState() != WebRtcViewModel.State.CALL_CONNECTED) { } else if (webRtcViewModel.getState() != WebRtcViewModel.State.CALL_CONNECTED) {
callConnectedTime = -1;
cancelTimer(); cancelTimer();
callConnectedTime = -1;
} }
if (webRtcViewModel.getLocalCameraState().isEnabled()) { if (webRtcViewModel.getLocalCameraState().isEnabled()) {

View File

@ -46,6 +46,8 @@ public class WebRtcViewModel {
private final SurfaceViewRenderer localRenderer; private final SurfaceViewRenderer localRenderer;
private final SurfaceViewRenderer remoteRenderer; private final SurfaceViewRenderer remoteRenderer;
private final long callConnectedTime;
public WebRtcViewModel(@NonNull State state, public WebRtcViewModel(@NonNull State state,
@NonNull Recipient recipient, @NonNull Recipient recipient,
@NonNull CameraState localCameraState, @NonNull CameraState localCameraState,
@ -54,7 +56,8 @@ public class WebRtcViewModel {
boolean remoteVideoEnabled, boolean remoteVideoEnabled,
boolean isBluetoothAvailable, boolean isBluetoothAvailable,
boolean isMicrophoneEnabled, boolean isMicrophoneEnabled,
boolean isRemoteVideoOffer) boolean isRemoteVideoOffer,
long callConnectedTime)
{ {
this(state, this(state,
recipient, recipient,
@ -65,7 +68,8 @@ public class WebRtcViewModel {
remoteVideoEnabled, remoteVideoEnabled,
isBluetoothAvailable, isBluetoothAvailable,
isMicrophoneEnabled, isMicrophoneEnabled,
isRemoteVideoOffer); isRemoteVideoOffer,
callConnectedTime);
} }
public WebRtcViewModel(@NonNull State state, public WebRtcViewModel(@NonNull State state,
@ -77,7 +81,8 @@ public class WebRtcViewModel {
boolean remoteVideoEnabled, boolean remoteVideoEnabled,
boolean isBluetoothAvailable, boolean isBluetoothAvailable,
boolean isMicrophoneEnabled, boolean isMicrophoneEnabled,
boolean isRemoteVideoOffer) boolean isRemoteVideoOffer,
long callConnectedTime)
{ {
this.state = state; this.state = state;
this.recipient = recipient; this.recipient = recipient;
@ -89,6 +94,7 @@ public class WebRtcViewModel {
this.isBluetoothAvailable = isBluetoothAvailable; this.isBluetoothAvailable = isBluetoothAvailable;
this.isMicrophoneEnabled = isMicrophoneEnabled; this.isMicrophoneEnabled = isMicrophoneEnabled;
this.isRemoteVideoOffer = isRemoteVideoOffer; this.isRemoteVideoOffer = isRemoteVideoOffer;
this.callConnectedTime = callConnectedTime;
} }
public @NonNull State getState() { public @NonNull State getState() {
@ -131,7 +137,18 @@ public class WebRtcViewModel {
return remoteRenderer; return remoteRenderer;
} }
public long getCallConnectedTime() {
return callConnectedTime;
}
public @NonNull String toString() { public @NonNull String toString() {
return "[State: " + state + ", recipient: " + recipient.getId().serialize() + ", identity: " + identityKey + ", remoteVideo: " + remoteVideoEnabled + ", localVideo: " + localCameraState.isEnabled() + ", isRemoteVideoOffer: " + isRemoteVideoOffer + "]"; return "[State: " + state +
", recipient: " + recipient.getId().serialize() +
", identity: " + identityKey +
", remoteVideo: " + remoteVideoEnabled +
", localVideo: " + localCameraState.isEnabled() +
", isRemoteVideoOffer: " + isRemoteVideoOffer +
", callConnectedTime: " + callConnectedTime +
"]";
} }
} }

View File

@ -167,6 +167,8 @@ public class WebRtcCallService extends Service implements CallManager.Observer,
private boolean isRemoteVideoOffer = false; private boolean isRemoteVideoOffer = false;
private boolean acceptWithVideo = false; private boolean acceptWithVideo = false;
private long callConnectedTime = -1;
private SignalServiceMessageSender messageSender; private SignalServiceMessageSender messageSender;
private SignalServiceAccountManager accountManager; private SignalServiceAccountManager accountManager;
private SignalAudioManager audioManager; private SignalAudioManager audioManager;
@ -925,6 +927,8 @@ public class WebRtcCallService extends Service implements CallManager.Observer,
lockManager.updatePhoneState(getInCallPhoneState()); lockManager.updatePhoneState(getInCallPhoneState());
} }
callConnectedTime = System.currentTimeMillis();
sendMessage(WebRtcViewModel.State.CALL_CONNECTED, activePeer, localCameraState, remoteVideoEnabled, bluetoothAvailable, microphoneEnabled, isRemoteVideoOffer); sendMessage(WebRtcViewModel.State.CALL_CONNECTED, activePeer, localCameraState, remoteVideoEnabled, bluetoothAvailable, microphoneEnabled, isRemoteVideoOffer);
unregisterPowerButtonReceiver(); unregisterPowerButtonReceiver();
@ -1277,7 +1281,8 @@ public class WebRtcCallService extends Service implements CallManager.Observer,
remoteVideoEnabled, remoteVideoEnabled,
bluetoothAvailable, bluetoothAvailable,
microphoneEnabled, microphoneEnabled,
isRemoteVideoOffer)); isRemoteVideoOffer,
callConnectedTime));
} }
private void sendMessage(@NonNull WebRtcViewModel.State state, private void sendMessage(@NonNull WebRtcViewModel.State state,
@ -1298,7 +1303,8 @@ public class WebRtcCallService extends Service implements CallManager.Observer,
remoteVideoEnabled, remoteVideoEnabled,
bluetoothAvailable, bluetoothAvailable,
microphoneEnabled, microphoneEnabled,
isRemoteVideoOffer)); isRemoteVideoOffer,
callConnectedTime));
} }
private ListenableFutureTask<Boolean> sendMessage(@NonNull final RemotePeer remotePeer, private ListenableFutureTask<Boolean> sendMessage(@NonNull final RemotePeer remotePeer,