mirror of
https://github.com/oxen-io/session-android.git
synced 2025-10-27 14:30:42 +00:00
feat: add silenced notifications for call notification builder. check pre-offer and connecting state for pending connection
This commit is contained in:
@@ -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()")
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -54,8 +54,13 @@ public class IncomingTextMessage implements Parcelable {
|
||||
|
||||
public IncomingTextMessage(Address sender, int senderDeviceId, long sentTimestampMillis,
|
||||
String encodedBody, Optional<SignalServiceGroup> 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<SignalServiceGroup> 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<SignalServiceGroup> 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() {
|
||||
|
||||
Reference in New Issue
Block a user