Toast reason when incoming call gets closed by baresip lib
This commit is contained in:
@ -1269,6 +1269,15 @@ Java_com_tutpro_baresip_Api_call_1replace_1transfer(JNIEnv *env, jobject thiz, j
|
||||
return res == 0 ? true : false;
|
||||
}
|
||||
|
||||
JNIEXPORT jstring JNICALL
|
||||
Java_com_tutpro_baresip_Api_call_1peer_1uri(JNIEnv *env, jobject thiz, jlong call)
|
||||
{
|
||||
const char *uri = call_peeruri((struct call *)call);
|
||||
if (uri)
|
||||
return (*env)->NewStringUTF(env, uri);
|
||||
return (*env)->NewStringUTF(env, "");
|
||||
}
|
||||
|
||||
JNIEXPORT jstring JNICALL
|
||||
Java_com_tutpro_baresip_Api_call_1diverter_1uri(JNIEnv *env, jobject thiz, jlong call)
|
||||
{
|
||||
|
||||
@ -79,6 +79,7 @@ object Api {
|
||||
external fun call_state(callp: Long): Int
|
||||
external fun call_replaces(callp: Long): Boolean
|
||||
external fun call_replace_transfer(xfer_callp: Long, callp: Long): Boolean
|
||||
external fun call_peer_uri(callp: Long): String
|
||||
external fun call_diverter_uri(callp: Long): String
|
||||
external fun call_destroy(callp: Long)
|
||||
|
||||
|
||||
@ -591,7 +591,8 @@ class BaresipService: Service() {
|
||||
Log.d(TAG, "got uaEvent $event/$aor/$callp")
|
||||
|
||||
val call = Call.ofCallp(callp)
|
||||
if (call == null && callp != 0L && ev[0] != "call incoming" && ev[0] != "call rejected") {
|
||||
if (call == null && callp != 0L && ev[0] != "call incoming" && ev[0] != "call rejected" &&
|
||||
ev[0] != "call closed") {
|
||||
Log.w(TAG, "uaEvent $event did not find call $callp")
|
||||
return
|
||||
}
|
||||
@ -865,93 +866,96 @@ class BaresipService: Service() {
|
||||
return
|
||||
}
|
||||
"call closed" -> {
|
||||
nm.cancel(CALL_NOTIFICATION_ID)
|
||||
Log.d(TAG, "AoR $aor call $callp is closed")
|
||||
stopRinging()
|
||||
stopMediaPlayer()
|
||||
val newCall = call!!.newCall
|
||||
if (newCall != null) {
|
||||
newCall.onHoldCall = null
|
||||
call.newCall = null
|
||||
}
|
||||
val onHoldCall = call.onHoldCall
|
||||
if (onHoldCall != null) {
|
||||
onHoldCall.newCall = null
|
||||
onHoldCall.referTo = ""
|
||||
call.onHoldCall = null
|
||||
}
|
||||
call.remove()
|
||||
if (Call.calls().size == 0) {
|
||||
resetCallVolume()
|
||||
am.isSpeakerphoneOn = false
|
||||
am.stopBluetoothSco()
|
||||
abandonAudioFocus()
|
||||
am.mode = AudioManager.MODE_NORMAL
|
||||
proximitySensing(false)
|
||||
}
|
||||
val missed = call.startTime == null && call.dir == "in" && !call.rejected
|
||||
if (ua.account.callHistory) {
|
||||
val history = NewCallHistory(aor, call.peerUri, call.dir)
|
||||
history.startTime = call.startTime
|
||||
history.stopTime = GregorianCalendar()
|
||||
NewCallHistory.add(history)
|
||||
NewCallHistory.save()
|
||||
ua.account.missedCalls = ua.account.missedCalls || missed
|
||||
}
|
||||
if (!Utils.isVisible()) {
|
||||
if (missed) {
|
||||
val caller = Utils.friendlyUri(this, call.peerUri, ua.account)
|
||||
val intent = Intent(applicationContext, MainActivity::class.java)
|
||||
intent.flags = Intent.FLAG_ACTIVITY_SINGLE_TOP or
|
||||
Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
intent.putExtra("action", "call missed")
|
||||
.putExtra("uap", uap)
|
||||
val pi = if (VERSION.SDK_INT >= 23)
|
||||
PendingIntent.getActivity(applicationContext, CALL_REQ_CODE, intent,
|
||||
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
else
|
||||
PendingIntent.getActivity(applicationContext, CALL_REQ_CODE, intent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
val nb = NotificationCompat.Builder(this, HIGH_CHANNEL_ID)
|
||||
nb.setSmallIcon(R.drawable.ic_stat_phone_missed)
|
||||
.setColor(ContextCompat.getColor(this, R.color.colorBaresip))
|
||||
.setContentIntent(pi)
|
||||
.setCategory(Notification.CATEGORY_CALL)
|
||||
.setAutoCancel(true)
|
||||
if (VERSION.SDK_INT < 23) {
|
||||
nb.setContentTitle(getString(R.string.missed_call_from))
|
||||
nb.setContentText(caller)
|
||||
} else {
|
||||
var missedCalls = 0
|
||||
for (notification in nm.activeNotifications)
|
||||
if (notification.id == CALL_MISSED_NOTIFICATION_ID)
|
||||
missedCalls++
|
||||
if (missedCalls == 0) {
|
||||
if (call != null) {
|
||||
nm.cancel(CALL_NOTIFICATION_ID)
|
||||
stopRinging()
|
||||
stopMediaPlayer()
|
||||
val newCall = call.newCall
|
||||
if (newCall != null) {
|
||||
newCall.onHoldCall = null
|
||||
call.newCall = null
|
||||
}
|
||||
val onHoldCall = call.onHoldCall
|
||||
if (onHoldCall != null) {
|
||||
onHoldCall.newCall = null
|
||||
onHoldCall.referTo = ""
|
||||
call.onHoldCall = null
|
||||
}
|
||||
call.remove()
|
||||
if (Call.calls().size == 0) {
|
||||
resetCallVolume()
|
||||
am.isSpeakerphoneOn = false
|
||||
am.stopBluetoothSco()
|
||||
abandonAudioFocus()
|
||||
am.mode = AudioManager.MODE_NORMAL
|
||||
proximitySensing(false)
|
||||
}
|
||||
val missed = call.startTime == null && call.dir == "in" && !call.rejected
|
||||
if (ua.account.callHistory) {
|
||||
val history = NewCallHistory(aor, call.peerUri, call.dir)
|
||||
history.startTime = call.startTime
|
||||
history.stopTime = GregorianCalendar()
|
||||
NewCallHistory.add(history)
|
||||
NewCallHistory.save()
|
||||
ua.account.missedCalls = ua.account.missedCalls || missed
|
||||
}
|
||||
if (!Utils.isVisible()) {
|
||||
if (missed) {
|
||||
val caller = Utils.friendlyUri(this, call.peerUri, ua.account)
|
||||
val intent = Intent(applicationContext, MainActivity::class.java)
|
||||
intent.flags = Intent.FLAG_ACTIVITY_SINGLE_TOP or
|
||||
Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
intent.putExtra("action", "call missed")
|
||||
.putExtra("uap", uap)
|
||||
val pi = if (VERSION.SDK_INT >= 23)
|
||||
PendingIntent.getActivity(applicationContext, CALL_REQ_CODE, intent,
|
||||
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
else
|
||||
PendingIntent.getActivity(applicationContext, CALL_REQ_CODE, intent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
val nb = NotificationCompat.Builder(this, HIGH_CHANNEL_ID)
|
||||
nb.setSmallIcon(R.drawable.ic_stat_phone_missed)
|
||||
.setColor(ContextCompat.getColor(this, R.color.colorBaresip))
|
||||
.setContentIntent(pi)
|
||||
.setCategory(Notification.CATEGORY_CALL)
|
||||
.setAutoCancel(true)
|
||||
if (VERSION.SDK_INT < 23) {
|
||||
nb.setContentTitle(getString(R.string.missed_call_from))
|
||||
nb.setContentText(caller)
|
||||
} else {
|
||||
nb.setContentTitle(getString(R.string.missed_calls))
|
||||
nb.setContentText(
|
||||
String.format(getString(R.string.missed_calls_count),
|
||||
missedCalls + 1))
|
||||
var missedCalls = 0
|
||||
for (notification in nm.activeNotifications)
|
||||
if (notification.id == CALL_MISSED_NOTIFICATION_ID)
|
||||
missedCalls++
|
||||
if (missedCalls == 0) {
|
||||
nb.setContentTitle(getString(R.string.missed_call_from))
|
||||
nb.setContentText(caller)
|
||||
} else {
|
||||
nb.setContentTitle(getString(R.string.missed_calls))
|
||||
nb.setContentText(
|
||||
String.format(getString(R.string.missed_calls_count),
|
||||
missedCalls + 1))
|
||||
}
|
||||
}
|
||||
if (VERSION.SDK_INT < 26) {
|
||||
@Suppress("DEPRECATION")
|
||||
nb.setVibrate(LongArray(0))
|
||||
.setVisibility(NotificationCompat.VISIBILITY_PRIVATE)
|
||||
.priority = Notification.PRIORITY_HIGH
|
||||
}
|
||||
nm.notify(CALL_MISSED_NOTIFICATION_ID, nb.build())
|
||||
}
|
||||
if (VERSION.SDK_INT < 26) {
|
||||
@Suppress("DEPRECATION")
|
||||
nb.setVibrate(LongArray(0))
|
||||
.setVisibility(NotificationCompat.VISIBILITY_PRIVATE)
|
||||
.priority = Notification.PRIORITY_HIGH
|
||||
}
|
||||
nm.notify(CALL_MISSED_NOTIFICATION_ID, nb.build())
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
val reason = ev[1].trim()
|
||||
if ((reason != "") && (ua.calls().isEmpty())) {
|
||||
if (reason[0].isDigit())
|
||||
toast("${getString(R.string.call_failed)}: $reason")
|
||||
else
|
||||
toast("${getString(R.string.call_closed)}: $reason")
|
||||
toast("${getString(R.string.call_closed)}: " +
|
||||
"$reason ${Api.call_peer_uri(callp)}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user