mirror of
https://github.com/oxen-io/session-android.git
synced 2025-10-28 08:21:23 +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 callId = getCallId(intent)
|
||||||
val recipient = getRemoteRecipient(intent)
|
val recipient = getRemoteRecipient(intent)
|
||||||
val sentTimestamp = intent.getLongExtra(EXTRA_TIMESTAMP, -1)
|
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)
|
setCallInProgressNotification(TYPE_INCOMING_PRE_OFFER, recipient)
|
||||||
callManager.onPreOffer(callId, recipient, sentTimestamp)
|
callManager.onPreOffer(callId, recipient, sentTimestamp)
|
||||||
callManager.postViewModelState(CallViewModel.State.CALL_PRE_INIT)
|
callManager.postViewModelState(CallViewModel.State.CALL_PRE_INIT)
|
||||||
callManager.initializeAudioForCall()
|
callManager.initializeAudioForCall()
|
||||||
callManager.startIncomingRinger()
|
callManager.startIncomingRinger()
|
||||||
|
callManager.setAudioEnabled(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleIncomingRing(intent: Intent) {
|
private fun handleIncomingRing(intent: Intent) {
|
||||||
@@ -401,6 +408,7 @@ class WebRtcCallService: Service(), CallManager.WebRtcListener {
|
|||||||
setCallInProgressNotification(TYPE_OUTGOING_RINGING, callManager.recipient)
|
setCallInProgressNotification(TYPE_OUTGOING_RINGING, callManager.recipient)
|
||||||
callManager.insertCallMessage(recipient.address.serialize(), CallMessageType.CALL_OUTGOING)
|
callManager.insertCallMessage(recipient.address.serialize(), CallMessageType.CALL_OUTGOING)
|
||||||
timeoutExecutor.schedule(TimeoutRunnable(callId, this), TIMEOUT_SECONDS, TimeUnit.SECONDS)
|
timeoutExecutor.schedule(TimeoutRunnable(callId, this), TIMEOUT_SECONDS, TimeUnit.SECONDS)
|
||||||
|
callManager.setAudioEnabled(true)
|
||||||
|
|
||||||
val expectedState = callManager.currentConnectionState
|
val expectedState = callManager.currentConnectionState
|
||||||
val expectedCallId = callManager.callId
|
val expectedCallId = callManager.callId
|
||||||
@@ -470,6 +478,7 @@ class WebRtcCallService: Service(), CallManager.WebRtcListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
lockManager.updatePhoneState(LockManager.PhoneState.PROCESSING)
|
lockManager.updatePhoneState(LockManager.PhoneState.PROCESSING)
|
||||||
|
callManager.setAudioEnabled(true)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.e(TAG,e)
|
Log.e(TAG,e)
|
||||||
terminate()
|
terminate()
|
||||||
@@ -588,7 +597,7 @@ class WebRtcCallService: Service(), CallManager.WebRtcListener {
|
|||||||
val callId = callManager.callId ?: return
|
val callId = callManager.callId ?: return
|
||||||
val callState = callManager.currentConnectionState
|
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")
|
Log.w(TAG, "Timing out call: $callId")
|
||||||
handleLocalHangup(intent)
|
handleLocalHangup(intent)
|
||||||
}
|
}
|
||||||
@@ -629,7 +638,7 @@ class WebRtcCallService: Service(), CallManager.WebRtcListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun isIncomingMessageExpired(intent: Intent) =
|
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() {
|
override fun onDestroy() {
|
||||||
Log.d(TAG,"onDestroy()")
|
Log.d(TAG,"onDestroy()")
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ class CallNotificationBuilder {
|
|||||||
.setOngoing(true)
|
.setOngoing(true)
|
||||||
.setPriority(NotificationCompat.PRIORITY_MIN)
|
.setPriority(NotificationCompat.PRIORITY_MIN)
|
||||||
|
|
||||||
|
|
||||||
recipient?.name?.let { name ->
|
recipient?.name?.let { name ->
|
||||||
builder.setContentTitle(name)
|
builder.setContentTitle(name)
|
||||||
}
|
}
|
||||||
@@ -68,6 +69,7 @@ class CallNotificationBuilder {
|
|||||||
when (type) {
|
when (type) {
|
||||||
TYPE_INCOMING_CONNECTING -> {
|
TYPE_INCOMING_CONNECTING -> {
|
||||||
builder.setContentText(context.getString(R.string.CallNotificationBuilder_connecting))
|
builder.setContentText(context.getString(R.string.CallNotificationBuilder_connecting))
|
||||||
|
.setNotificationSilent()
|
||||||
}
|
}
|
||||||
TYPE_INCOMING_PRE_OFFER,
|
TYPE_INCOMING_PRE_OFFER,
|
||||||
TYPE_INCOMING_RINGING -> {
|
TYPE_INCOMING_RINGING -> {
|
||||||
@@ -97,7 +99,7 @@ class CallNotificationBuilder {
|
|||||||
WebRtcCallService.ACTION_LOCAL_HANGUP,
|
WebRtcCallService.ACTION_LOCAL_HANGUP,
|
||||||
R.drawable.ic_call_end_grey600_32dp,
|
R.drawable.ic_call_end_grey600_32dp,
|
||||||
R.string.NotificationBarManager__cancel_call
|
R.string.NotificationBarManager__cancel_call
|
||||||
))
|
)).setNotificationSilent()
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
builder.setContentText(context.getString(R.string.NotificationBarManager_call_in_progress))
|
builder.setContentText(context.getString(R.string.NotificationBarManager_call_in_progress))
|
||||||
@@ -106,7 +108,7 @@ class CallNotificationBuilder {
|
|||||||
WebRtcCallService.ACTION_LOCAL_HANGUP,
|
WebRtcCallService.ACTION_LOCAL_HANGUP,
|
||||||
R.drawable.ic_call_end_grey600_32dp,
|
R.drawable.ic_call_end_grey600_32dp,
|
||||||
R.string.NotificationBarManager__end_call
|
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_DIALING,
|
||||||
CallState.STATE_ANSWERING,
|
CallState.STATE_ANSWERING,
|
||||||
CallState.STATE_LOCAL_RINGING,
|
CallState.STATE_LOCAL_RINGING,
|
||||||
CallState.STATE_REMOTE_RINGING
|
CallState.STATE_REMOTE_RINGING,
|
||||||
|
CallState.STATE_PRE_OFFER,
|
||||||
)
|
)
|
||||||
val OUTGOING_STATES = arrayOf(
|
val OUTGOING_STATES = arrayOf(
|
||||||
CallState.STATE_DIALING,
|
CallState.STATE_DIALING,
|
||||||
@@ -108,6 +109,8 @@ class CallManager(context: Context, audioManager: AudioManagerCompat, private va
|
|||||||
val currentCallState
|
val currentCallState
|
||||||
get() = _callStateEvents.value
|
get() = _callStateEvents.value
|
||||||
|
|
||||||
|
var iceState = IceConnectionState.CLOSED
|
||||||
|
|
||||||
private var eglBase: EglBase? = null
|
private var eglBase: EglBase? = null
|
||||||
|
|
||||||
var pendingOffer: String? = null
|
var pendingOffer: String? = null
|
||||||
@@ -215,6 +218,7 @@ class CallManager(context: Context, audioManager: AudioManagerCompat, private va
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onIceConnectionChange(newState: IceConnectionState) {
|
override fun onIceConnectionChange(newState: IceConnectionState) {
|
||||||
|
iceState = newState
|
||||||
peerConnectionObservers.forEach { listener -> listener.onIceConnectionChange(newState) }
|
peerConnectionObservers.forEach { listener -> listener.onIceConnectionChange(newState) }
|
||||||
if (newState == IceConnectionState.CONNECTED) {
|
if (newState == IceConnectionState.CONNECTED) {
|
||||||
callStartTime = System.currentTimeMillis()
|
callStartTime = System.currentTimeMillis()
|
||||||
@@ -421,7 +425,6 @@ class CallManager(context: Context, audioManager: AudioManagerCompat, private va
|
|||||||
connection.setRemoteDescription(SessionDescription(SessionDescription.Type.OFFER, offer))
|
connection.setRemoteDescription(SessionDescription(SessionDescription.Type.OFFER, offer))
|
||||||
val answer = connection.createAnswer(MediaConstraints())
|
val answer = connection.createAnswer(MediaConstraints())
|
||||||
connection.setLocalDescription(answer)
|
connection.setLocalDescription(answer)
|
||||||
setAudioEnabled(true)
|
|
||||||
val answerMessage = CallMessage.answer(answer.description, callId)
|
val answerMessage = CallMessage.answer(answer.description, callId)
|
||||||
val userAddress = storage.getUserPublicKey() ?: return Promise.ofFail(NullPointerException("No user public key"))
|
val userAddress = storage.getUserPublicKey() ?: return Promise.ofFail(NullPointerException("No user public key"))
|
||||||
MessageSender.sendNonDurably(answerMessage, Address.fromSerialized(userAddress))
|
MessageSender.sendNonDurably(answerMessage, Address.fromSerialized(userAddress))
|
||||||
|
|||||||
@@ -54,8 +54,13 @@ public class IncomingTextMessage implements Parcelable {
|
|||||||
|
|
||||||
public IncomingTextMessage(Address sender, int senderDeviceId, long sentTimestampMillis,
|
public IncomingTextMessage(Address sender, int senderDeviceId, long sentTimestampMillis,
|
||||||
String encodedBody, Optional<SignalServiceGroup> group,
|
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.message = encodedBody;
|
||||||
this.sender = sender;
|
this.sender = sender;
|
||||||
this.senderDeviceId = senderDeviceId;
|
this.senderDeviceId = senderDeviceId;
|
||||||
@@ -64,7 +69,7 @@ public class IncomingTextMessage implements Parcelable {
|
|||||||
this.replyPathPresent = true;
|
this.replyPathPresent = true;
|
||||||
this.pseudoSubject = "";
|
this.pseudoSubject = "";
|
||||||
this.sentTimestampMillis = sentTimestampMillis;
|
this.sentTimestampMillis = sentTimestampMillis;
|
||||||
this.push = true;
|
this.push = isPush;
|
||||||
this.subscriptionId = -1;
|
this.subscriptionId = -1;
|
||||||
this.expiresInMillis = expiresInMillis;
|
this.expiresInMillis = expiresInMillis;
|
||||||
this.unidentified = unidentified;
|
this.unidentified = unidentified;
|
||||||
@@ -137,7 +142,7 @@ public class IncomingTextMessage implements Parcelable {
|
|||||||
Address sender,
|
Address sender,
|
||||||
Optional<SignalServiceGroup> group,
|
Optional<SignalServiceGroup> group,
|
||||||
long sentTimestamp) {
|
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() {
|
public int getSubscriptionId() {
|
||||||
|
|||||||
Reference in New Issue
Block a user