From 7eae1404c5dbc6a67fe8276667efbe014762ae56 Mon Sep 17 00:00:00 2001 From: jubb Date: Mon, 13 Dec 2021 16:53:42 +1100 Subject: [PATCH] feat: add silenced notifications for call notification builder. check pre-offer and connecting state for pending connection --- .../securesms/service/WebRtcCallService.kt | 15 ++++++++++++--- .../securesms/util/CallNotificationBuilder.kt | 6 ++++-- .../thoughtcrime/securesms/webrtc/CallManager.kt | 7 +++++-- .../messages/signal/IncomingTextMessage.java | 13 +++++++++---- 4 files changed, 30 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/service/WebRtcCallService.kt b/app/src/main/java/org/thoughtcrime/securesms/service/WebRtcCallService.kt index db5da27818..5693e3ca81 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/service/WebRtcCallService.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/service/WebRtcCallService.kt @@ -349,12 +349,19 @@ class WebRtcCallService: Service(), CallManager.WebRtcListener { val callId = getCallId(intent) val recipient = getRemoteRecipient(intent) val sentTimestamp = intent.getLongExtra(EXTRA_TIMESTAMP, -1) - // TODO: check stale call info and don't proceed + + if (isIncomingMessageExpired(intent)) { + insertMissedCall(recipient, true) + terminate() + return + } + setCallInProgressNotification(TYPE_INCOMING_PRE_OFFER, recipient) callManager.onPreOffer(callId, recipient, sentTimestamp) callManager.postViewModelState(CallViewModel.State.CALL_PRE_INIT) callManager.initializeAudioForCall() callManager.startIncomingRinger() + callManager.setAudioEnabled(true) } private fun handleIncomingRing(intent: Intent) { @@ -401,6 +408,7 @@ class WebRtcCallService: Service(), CallManager.WebRtcListener { setCallInProgressNotification(TYPE_OUTGOING_RINGING, callManager.recipient) callManager.insertCallMessage(recipient.address.serialize(), CallMessageType.CALL_OUTGOING) timeoutExecutor.schedule(TimeoutRunnable(callId, this), TIMEOUT_SECONDS, TimeUnit.SECONDS) + callManager.setAudioEnabled(true) val expectedState = callManager.currentConnectionState val expectedCallId = callManager.callId @@ -470,6 +478,7 @@ class WebRtcCallService: Service(), CallManager.WebRtcListener { } } lockManager.updatePhoneState(LockManager.PhoneState.PROCESSING) + callManager.setAudioEnabled(true) } catch (e: Exception) { Log.e(TAG,e) terminate() @@ -588,7 +597,7 @@ class WebRtcCallService: Service(), CallManager.WebRtcListener { val callId = callManager.callId ?: return val callState = callManager.currentConnectionState - if (callId == getCallId(intent) && callState !in arrayOf(STATE_CONNECTED)) { // TODO: add check for ice state connecting + if (callId == getCallId(intent) && (callState !in arrayOf(STATE_CONNECTED) || callManager.iceState == CHECKING)) { Log.w(TAG, "Timing out call: $callId") handleLocalHangup(intent) } @@ -629,7 +638,7 @@ class WebRtcCallService: Service(), CallManager.WebRtcListener { } private fun isIncomingMessageExpired(intent: Intent) = - System.currentTimeMillis() - intent.getLongExtra(EXTRA_TIMESTAMP, -1) > TimeUnit.MINUTES.toMillis(2) + System.currentTimeMillis() - intent.getLongExtra(EXTRA_TIMESTAMP, -1) > TimeUnit.SECONDS.toMillis(TIMEOUT_SECONDS) override fun onDestroy() { Log.d(TAG,"onDestroy()") diff --git a/app/src/main/java/org/thoughtcrime/securesms/util/CallNotificationBuilder.kt b/app/src/main/java/org/thoughtcrime/securesms/util/CallNotificationBuilder.kt index 21cd7bfbf1..55b589f29f 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/util/CallNotificationBuilder.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/util/CallNotificationBuilder.kt @@ -61,6 +61,7 @@ class CallNotificationBuilder { .setOngoing(true) .setPriority(NotificationCompat.PRIORITY_MIN) + recipient?.name?.let { name -> builder.setContentTitle(name) } @@ -68,6 +69,7 @@ class CallNotificationBuilder { when (type) { TYPE_INCOMING_CONNECTING -> { builder.setContentText(context.getString(R.string.CallNotificationBuilder_connecting)) + .setNotificationSilent() } TYPE_INCOMING_PRE_OFFER, TYPE_INCOMING_RINGING -> { @@ -97,7 +99,7 @@ class CallNotificationBuilder { WebRtcCallService.ACTION_LOCAL_HANGUP, R.drawable.ic_call_end_grey600_32dp, R.string.NotificationBarManager__cancel_call - )) + )).setNotificationSilent() } else -> { builder.setContentText(context.getString(R.string.NotificationBarManager_call_in_progress)) @@ -106,7 +108,7 @@ class CallNotificationBuilder { WebRtcCallService.ACTION_LOCAL_HANGUP, R.drawable.ic_call_end_grey600_32dp, R.string.NotificationBarManager__end_call - )) + )).setNotificationSilent().setUsesChronometer(true) } } diff --git a/app/src/main/java/org/thoughtcrime/securesms/webrtc/CallManager.kt b/app/src/main/java/org/thoughtcrime/securesms/webrtc/CallManager.kt index ec4f0e1c04..4bdf06ee42 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/webrtc/CallManager.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/webrtc/CallManager.kt @@ -63,7 +63,8 @@ class CallManager(context: Context, audioManager: AudioManagerCompat, private va CallState.STATE_DIALING, CallState.STATE_ANSWERING, CallState.STATE_LOCAL_RINGING, - CallState.STATE_REMOTE_RINGING + CallState.STATE_REMOTE_RINGING, + CallState.STATE_PRE_OFFER, ) val OUTGOING_STATES = arrayOf( CallState.STATE_DIALING, @@ -108,6 +109,8 @@ class CallManager(context: Context, audioManager: AudioManagerCompat, private va val currentCallState get() = _callStateEvents.value + var iceState = IceConnectionState.CLOSED + private var eglBase: EglBase? = null var pendingOffer: String? = null @@ -215,6 +218,7 @@ class CallManager(context: Context, audioManager: AudioManagerCompat, private va } override fun onIceConnectionChange(newState: IceConnectionState) { + iceState = newState peerConnectionObservers.forEach { listener -> listener.onIceConnectionChange(newState) } if (newState == IceConnectionState.CONNECTED) { callStartTime = System.currentTimeMillis() @@ -421,7 +425,6 @@ class CallManager(context: Context, audioManager: AudioManagerCompat, private va connection.setRemoteDescription(SessionDescription(SessionDescription.Type.OFFER, offer)) val answer = connection.createAnswer(MediaConstraints()) connection.setLocalDescription(answer) - setAudioEnabled(true) val answerMessage = CallMessage.answer(answer.description, callId) val userAddress = storage.getUserPublicKey() ?: return Promise.ofFail(NullPointerException("No user public key")) MessageSender.sendNonDurably(answerMessage, Address.fromSerialized(userAddress)) diff --git a/libsession/src/main/java/org/session/libsession/messaging/messages/signal/IncomingTextMessage.java b/libsession/src/main/java/org/session/libsession/messaging/messages/signal/IncomingTextMessage.java index 789d04201c..93347f5276 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/messages/signal/IncomingTextMessage.java +++ b/libsession/src/main/java/org/session/libsession/messaging/messages/signal/IncomingTextMessage.java @@ -54,8 +54,13 @@ public class IncomingTextMessage implements Parcelable { public IncomingTextMessage(Address sender, int senderDeviceId, long sentTimestampMillis, String encodedBody, Optional group, - long expiresInMillis, boolean unidentified, int callType) - { + long expiresInMillis, boolean unidentified, int callType) { + this(sender, senderDeviceId, sentTimestampMillis, encodedBody, group, expiresInMillis, unidentified, callType, true); + } + + public IncomingTextMessage(Address sender, int senderDeviceId, long sentTimestampMillis, + String encodedBody, Optional group, + long expiresInMillis, boolean unidentified, int callType, boolean isPush) { this.message = encodedBody; this.sender = sender; this.senderDeviceId = senderDeviceId; @@ -64,7 +69,7 @@ public class IncomingTextMessage implements Parcelable { this.replyPathPresent = true; this.pseudoSubject = ""; this.sentTimestampMillis = sentTimestampMillis; - this.push = true; + this.push = isPush; this.subscriptionId = -1; this.expiresInMillis = expiresInMillis; this.unidentified = unidentified; @@ -137,7 +142,7 @@ public class IncomingTextMessage implements Parcelable { Address sender, Optional group, long sentTimestamp) { - return new IncomingTextMessage(sender, 1, sentTimestamp, null, group, 0, false, callMessageType.ordinal()); + return new IncomingTextMessage(sender, 1, sentTimestamp, null, group, 0, false, callMessageType.ordinal(), false); } public int getSubscriptionId() {