- Added "Restart" Main Activity menu option.

- When registration fails due to DNS lookup failure, try
  registration once more after updating DNS servers.
- Small logging improvements.
This commit is contained in:
Juha Heinanen
2019-09-19 15:04:08 +03:00
parent d3c0e2688a
commit 465f943198
8 changed files with 48 additions and 20 deletions

View File

@ -354,6 +354,7 @@ class BaresipService: Service() {
status[account_index] = R.drawable.dot_yellow
else
status[account_index] = R.drawable.dot_green
ua.registrationFailed = false
updateStatusNotification()
if (!Utils.isVisible())
return
@ -361,25 +362,31 @@ class BaresipService: Service() {
"registering failed" -> {
status[account_index] = R.drawable.dot_red
updateStatusNotification()
if ((ev.size > 1) && (ev[1] == "Invalid argument")) {
// Most likely this error is due to DNS lookup failure
newEvent = "registering failed,DNS lookup failed"
Api.net_dns_debug()
if (dynDns)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
val activeNetwork = cm.activeNetwork
if (activeNetwork != null) {
val dnsServers = cm.getLinkProperties(activeNetwork).dnsServers
Log.d(LOG_TAG, "Updating DNS Servers = $dnsServers")
if (Config.updateDnsServers(dnsServers) != 0)
Log.w(LOG_TAG, "Failed to update DNS servers '$dnsServers'")
else
Api.net_dns_debug()
if ((ev.size > 1) && (ev[1] == "Invalid argument")) {
// Most likely this error is due to DNS lookup failure
newEvent = "registering failed,DNS lookup failed"
Api.net_dns_debug()
if (dynDns)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
val activeNetwork = cm.activeNetwork
if (activeNetwork != null) {
val dnsServers = cm.getLinkProperties(activeNetwork).dnsServers
Log.d(LOG_TAG, "Updating DNS Servers = $dnsServers")
if (Config.updateDnsServers(dnsServers) != 0) {
Log.w(LOG_TAG, "Failed to update DNS servers '$dnsServers'")
} else {
Log.d(LOG_TAG, "No active network!")
Api.net_dns_debug()
if (!ua.registrationFailed) {
ua.registrationFailed = true
Api.ua_register(uap)
}
}
} else {
Log.d(LOG_TAG, "No active network!")
}
}
}
}
if (!Utils.isVisible())
return
}
@ -683,7 +690,7 @@ class BaresipService: Service() {
@Keep
fun stopped(error: String) {
Log.d(LOG_TAG, "'stopped' from baresip with error $error")
Log.d(LOG_TAG, "Received 'stopped' from baresip with param '$error'")
isServiceRunning = false
if (error == "ua_init") {
Config.remove("sip_listen")

View File

@ -92,7 +92,7 @@ object Config {
}
}
if (write) {
Log.e("Baresip", "Writing '$config'")
Log.e("Baresip", "Writing config '$config'")
Utils.putFileContents(file, config)
}
}

View File

@ -3,6 +3,8 @@ package com.tutpro.baresip
import android.Manifest
import android.app.KeyguardManager
import android.app.NotificationManager
import android.app.AlarmManager
import android.app.PendingIntent
import android.content.*
import android.support.v4.app.ActivityCompat
import android.support.v4.content.ContextCompat
@ -50,6 +52,8 @@ class MainActivity : AppCompatActivity() {
internal lateinit var stopState: String
internal lateinit var speakerIcon: MenuItem
internal var restart = false
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@ -583,7 +587,7 @@ class MainActivity : AppCompatActivity() {
return
}
if (event == "stopped") {
Log.d("Baresip", "Handling service event 'stopped' with param ${params[0]}")
Log.d("Baresip", "Handling service event 'stopped' with param '${params[0]}'")
if (params[0] != "") {
val alertDialog = AlertDialog.Builder(this).create()
alertDialog.setTitle(getString(R.string.notice))
@ -599,6 +603,14 @@ class MainActivity : AppCompatActivity() {
} else {
quitTimer.cancel()
finishAndRemoveTask()
if (restart) {
Log.d("Baresip", "Trigger restart")
val restartActivity = Intent(applicationContext, MainActivity::class.java)
val restartIntent = PendingIntent.getActivity(applicationContext,
RESTART_REQUEST_CODE, restartActivity, PendingIntent.FLAG_CANCEL_CURRENT)
val am = applicationContext.getSystemService(Context.ALARM_SERVICE) as AlarmManager
am.set(AlarmManager.RTC,System.currentTimeMillis() + 1000, restartIntent)
}
System.exit(0)
return
}
@ -894,10 +906,11 @@ class MainActivity : AppCompatActivity() {
startActivityForResult(i, ABOUT_CODE)
return true
}
R.id.quit -> {
R.id.restart, R.id.quit -> {
if (stopState == "initial") {
Log.d("Baresip", "Quiting")
if (BaresipService.isServiceRunning) {
if (item.itemId == R.id.restart) restart = true
baresipService.setAction("Stop");
startService(baresipService)
quitTimer.start()
@ -1189,6 +1202,7 @@ class MainActivity : AppCompatActivity() {
const val MESSAGE_CODE = 9
const val PERMISSION_REQUEST_CODE = 1
const val RESTART_REQUEST_CODE = 2
}

View File

@ -10,6 +10,7 @@ import java.io.File
class RunOnStartup : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
Log.i("Baresip", "RunOnStartup received intent ${intent.action}")
if ((intent.action == Intent.ACTION_BOOT_COMPLETED) or
(intent.action == "com.tutpro.baresip.Restart")) {
val configFile = File(context.filesDir.absolutePath + "/config")

View File

@ -3,6 +3,7 @@ package com.tutpro.baresip
class UserAgent (val uap: String) {
val account = Account(Api.ua_account(uap))
var registrationFailed = false
companion object {

View File

@ -9,6 +9,9 @@
<item android:id="@+id/about"
android:title="@string/about" />
<item android:id="@+id/restart"
android:title="@string/restart" />
<item android:id="@+id/quit"
android:title="@string/quit" />

View File

@ -275,6 +275,7 @@
<string name="error">Virhe</string>
<!-- Main Activity -->
<string name="about">Tietoja</string>
<string name="restart">Käynnistä uudelleen</string>
<string name="quit">Lopeta</string>
<string name="outgoing_call_to_dots">Lähtevä puhelu …</string>
<string name="incoming_call_from_dots">Tuleva puhelu …</string>

View File

@ -251,6 +251,7 @@ Check Apps → baresip → Permissions → Storage and that file \'accounts.bs\'
<!-- Main Activity -->
<string name="about">About</string>
<string name="restart">Restart</string>
<string name="quit">Quit</string>
<string name="outgoing_call_to_dots">Outgoing call to &#8230;</string>
<string name="incoming_call_from_dots">Incoming call from &#8230;</string>