When registering fails, toast it from baresip service to any activity
This commit is contained in:
@@ -36,6 +36,8 @@ import kotlin.concurrent.schedule
|
|||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
import android.media.MediaPlayer
|
import android.media.MediaPlayer
|
||||||
import android.telecom.TelecomManager
|
import android.telecom.TelecomManager
|
||||||
|
import android.widget.Toast
|
||||||
|
import android.os.Looper
|
||||||
|
|
||||||
class BaresipService: Service() {
|
class BaresipService: Service() {
|
||||||
|
|
||||||
@@ -572,22 +574,29 @@ class BaresipService: Service() {
|
|||||||
else
|
else
|
||||||
status[account_index] = R.drawable.dot_green
|
status[account_index] = R.drawable.dot_green
|
||||||
updateStatusNotification()
|
updateStatusNotification()
|
||||||
if (!Utils.isVisible())
|
if (!isMainVisible)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
"registering failed" -> {
|
"registering failed" -> {
|
||||||
status[account_index] = R.drawable.dot_red
|
status[account_index] = R.drawable.dot_red
|
||||||
updateStatusNotification()
|
updateStatusNotification()
|
||||||
if (ev.size > 1 && ev[1] == "Invalid argument")
|
if (Utils.isVisible()) {
|
||||||
// Likely due to DNS lookup failure
|
val reason = if (ev.size > 1) {
|
||||||
newEvent = "registering failed,DNS lookup failed"
|
if (ev[1] == "Invalid argument") // Likely due to DNS lookup failure
|
||||||
if (!Utils.isVisible())
|
": DNS lookup failed"
|
||||||
|
else
|
||||||
|
": ${ev[1]}"
|
||||||
|
} else
|
||||||
|
""
|
||||||
|
toast(String.format(getString(R.string.registering_failed), aor) + reason)
|
||||||
|
}
|
||||||
|
if (!isMainVisible)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
"unregistering" -> {
|
"unregistering" -> {
|
||||||
status[account_index] = R.drawable.dot_white
|
status[account_index] = R.drawable.dot_white
|
||||||
updateStatusNotification()
|
updateStatusNotification()
|
||||||
if (!Utils.isVisible())
|
if (!isMainVisible)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
"call outgoing" -> {
|
"call outgoing" -> {
|
||||||
@@ -1071,6 +1080,12 @@ class BaresipService: Service() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun toast(message: String) {
|
||||||
|
Handler(Looper.getMainLooper()).post {
|
||||||
|
Toast.makeText(this@BaresipService.applicationContext, message, Toast.LENGTH_LONG).show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun getActionText(@StringRes stringRes: Int, @ColorRes colorRes: Int): Spannable {
|
private fun getActionText(@StringRes stringRes: Int, @ColorRes colorRes: Int): Spannable {
|
||||||
val spannable: Spannable = SpannableString(applicationContext.getText(stringRes))
|
val spannable: Spannable = SpannableString(applicationContext.getText(stringRes))
|
||||||
if (VERSION.SDK_INT >= 25) {
|
if (VERSION.SDK_INT >= 25) {
|
||||||
|
|||||||
@@ -939,16 +939,9 @@ class MainActivity : AppCompatActivity() {
|
|||||||
for (account_index in UserAgent.uas().indices) {
|
for (account_index in UserAgent.uas().indices) {
|
||||||
if (UserAgent.uas()[account_index].account.aor == aor) {
|
if (UserAgent.uas()[account_index].account.aor == aor) {
|
||||||
when (ev[0]) {
|
when (ev[0]) {
|
||||||
"registered", "unregistering" -> {
|
"registered", "unregistering", "registering failed" -> {
|
||||||
uaAdapter.notifyDataSetChanged()
|
uaAdapter.notifyDataSetChanged()
|
||||||
}
|
}
|
||||||
"registering failed" -> {
|
|
||||||
uaAdapter.notifyDataSetChanged()
|
|
||||||
Toast.makeText(applicationContext,
|
|
||||||
String.format(getString(R.string.registering_failed), aor) +
|
|
||||||
": ${ev[1]}",
|
|
||||||
Toast.LENGTH_LONG).show()
|
|
||||||
}
|
|
||||||
"call rejected" -> {
|
"call rejected" -> {
|
||||||
if (aor == aorSpinner.tag) {
|
if (aor == aorSpinner.tag) {
|
||||||
callsButton.setImageResource(R.drawable.calls_missed)
|
callsButton.setImageResource(R.drawable.calls_missed)
|
||||||
|
|||||||
Reference in New Issue
Block a user