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