Added shouldStartRinging check to incoming call
This commit is contained in:
@@ -873,19 +873,19 @@ class BaresipService: Service() {
|
|||||||
Call(callp, ua, peerUri, "in", "incoming").add()
|
Call(callp, ua, peerUri, "in", "incoming").add()
|
||||||
if (speakerPhone && !Utils.isSpeakerPhoneOn(am))
|
if (speakerPhone && !Utils.isSpeakerPhoneOn(am))
|
||||||
Utils.toggleSpeakerPhone(ContextCompat.getMainExecutor(this), am)
|
Utils.toggleSpeakerPhone(ContextCompat.getMainExecutor(this), am)
|
||||||
if (ua.account.answerMode == Api.ANSWERMODE_MANUAL) {
|
if (ua.account.answerMode == Api.ANSWERMODE_AUTO) {
|
||||||
Log.d(TAG, "CurrentInterruptionFilter ${nm.currentInterruptionFilter}")
|
|
||||||
if (nm.currentInterruptionFilter <= NotificationManager.INTERRUPTION_FILTER_ALL)
|
|
||||||
startRinging()
|
|
||||||
} else {
|
|
||||||
val newIntent = Intent(this, MainActivity::class.java)
|
val newIntent = Intent(this, MainActivity::class.java)
|
||||||
newIntent.flags = Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP or
|
newIntent.flags =
|
||||||
|
Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP or
|
||||||
Intent.FLAG_ACTIVITY_NEW_TASK
|
Intent.FLAG_ACTIVITY_NEW_TASK
|
||||||
newIntent.putExtra("action", "call answer")
|
newIntent.putExtra("action", "call answer")
|
||||||
newIntent.putExtra("callp", callp)
|
newIntent.putExtra("callp", callp)
|
||||||
startActivity(newIntent)
|
startActivity(newIntent)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
val channelId = if (shouldVibrate()) MEDIUM_CHANNEL_ID else HIGH_CHANNEL_ID
|
||||||
|
if (shouldStartRinging(channelId))
|
||||||
|
startRinging()
|
||||||
if (!Utils.isVisible()) {
|
if (!Utils.isVisible()) {
|
||||||
val piFlags = PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
|
val piFlags = PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
|
||||||
val intent = Intent(applicationContext, MainActivity::class.java)
|
val intent = Intent(applicationContext, MainActivity::class.java)
|
||||||
@@ -894,8 +894,7 @@ class BaresipService: Service() {
|
|||||||
intent.flags = Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP or
|
intent.flags = Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP or
|
||||||
Intent.FLAG_ACTIVITY_NEW_TASK
|
Intent.FLAG_ACTIVITY_NEW_TASK
|
||||||
val pi = PendingIntent.getActivity(applicationContext, CALL_REQ_CODE, intent, piFlags)
|
val pi = PendingIntent.getActivity(applicationContext, CALL_REQ_CODE, intent, piFlags)
|
||||||
val nb = NotificationCompat.Builder(this,
|
val nb = NotificationCompat.Builder(this, channelId)
|
||||||
if (shouldVibrate()) MEDIUM_CHANNEL_ID else HIGH_CHANNEL_ID)
|
|
||||||
val caller = Utils.friendlyUri(this, peerUri, ua.account)
|
val caller = Utils.friendlyUri(this, peerUri, ua.account)
|
||||||
val person = Person.Builder().setName(caller).build()
|
val person = Person.Builder().setName(caller).build()
|
||||||
nb.setSmallIcon(R.drawable.ic_stat_call)
|
nb.setSmallIcon(R.drawable.ic_stat_call)
|
||||||
@@ -1293,6 +1292,7 @@ class BaresipService: Service() {
|
|||||||
private fun createNotificationChannels() {
|
private fun createNotificationChannels() {
|
||||||
val lowChannel = NotificationChannel(LOW_CHANNEL_ID, "No sound or vibrate",
|
val lowChannel = NotificationChannel(LOW_CHANNEL_ID, "No sound or vibrate",
|
||||||
NotificationManager.IMPORTANCE_LOW)
|
NotificationManager.IMPORTANCE_LOW)
|
||||||
|
lowChannel.enableVibration(false)
|
||||||
lowChannel.lockscreenVisibility = Notification.VISIBILITY_PUBLIC
|
lowChannel.lockscreenVisibility = Notification.VISIBILITY_PUBLIC
|
||||||
nm.createNotificationChannel(lowChannel)
|
nm.createNotificationChannel(lowChannel)
|
||||||
|
|
||||||
@@ -1304,8 +1304,8 @@ class BaresipService: Service() {
|
|||||||
|
|
||||||
val mediumChannel = NotificationChannel(MEDIUM_CHANNEL_ID, "Sound",
|
val mediumChannel = NotificationChannel(MEDIUM_CHANNEL_ID, "Sound",
|
||||||
NotificationManager.IMPORTANCE_HIGH)
|
NotificationManager.IMPORTANCE_HIGH)
|
||||||
highChannel.lockscreenVisibility = Notification.VISIBILITY_PUBLIC
|
mediumChannel.lockscreenVisibility = Notification.VISIBILITY_PUBLIC
|
||||||
highChannel.enableVibration(false)
|
mediumChannel.enableVibration(false)
|
||||||
nm.createNotificationChannel(mediumChannel)
|
nm.createNotificationChannel(mediumChannel)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1397,22 +1397,30 @@ class BaresipService: Service() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private fun shouldStartRinging(channelId: String): Boolean {
|
||||||
|
val currentFilter = nm.currentInterruptionFilter
|
||||||
|
val dndAllowsRinging = currentFilter == NotificationManager.INTERRUPTION_FILTER_ALL ||
|
||||||
|
currentFilter == NotificationManager.INTERRUPTION_FILTER_PRIORITY
|
||||||
|
if (dndAllowsRinging)
|
||||||
|
return true
|
||||||
|
val channel = nm.getNotificationChannel(channelId)
|
||||||
|
return channel != null && channel.canBypassDnd()
|
||||||
|
}
|
||||||
|
|
||||||
private fun shouldVibrate(): Boolean {
|
private fun shouldVibrate(): Boolean {
|
||||||
return if (am.ringerMode != RINGER_MODE_SILENT) {
|
return if (am.ringerMode != RINGER_MODE_SILENT)
|
||||||
if (am.ringerMode == AudioManager.RINGER_MODE_VIBRATE) {
|
if (am.ringerMode == AudioManager.RINGER_MODE_VIBRATE)
|
||||||
true
|
true
|
||||||
} else {
|
else
|
||||||
if (am.getStreamVolume(AudioManager.STREAM_RING) != 0) {
|
if (am.getStreamVolume(AudioManager.STREAM_RING) != 0)
|
||||||
@Suppress("DEPRECATION")
|
@Suppress("DEPRECATION")
|
||||||
Settings.System.getInt(contentResolver, Settings.System.VIBRATE_WHEN_RINGING, 0) == 1
|
Settings.System.getInt(contentResolver, Settings.System.VIBRATE_WHEN_RINGING, 0) != 0
|
||||||
} else {
|
else
|
||||||
false
|
false
|
||||||
}
|
else
|
||||||
}
|
|
||||||
} else {
|
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private fun stopRinging() {
|
private fun stopRinging() {
|
||||||
rt!!.stop()
|
rt!!.stop()
|
||||||
|
|||||||
Reference in New Issue
Block a user