diff --git a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt index 01ab1601..dfac417d 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt @@ -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") diff --git a/app/src/main/kotlin/com/tutpro/baresip/Config.kt b/app/src/main/kotlin/com/tutpro/baresip/Config.kt index 4290a881..cd906a7f 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/Config.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/Config.kt @@ -92,7 +92,7 @@ object Config { } } if (write) { - Log.e("Baresip", "Writing '$config'") + Log.e("Baresip", "Writing config '$config'") Utils.putFileContents(file, config) } } diff --git a/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt b/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt index 80ff1e1e..92669315 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt @@ -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 } diff --git a/app/src/main/kotlin/com/tutpro/baresip/RunOnStartup.kt b/app/src/main/kotlin/com/tutpro/baresip/RunOnStartup.kt index 775722da..8e1adbdf 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/RunOnStartup.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/RunOnStartup.kt @@ -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") diff --git a/app/src/main/kotlin/com/tutpro/baresip/UserAgent.kt b/app/src/main/kotlin/com/tutpro/baresip/UserAgent.kt index 343cc952..8eec47c4 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/UserAgent.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/UserAgent.kt @@ -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 { diff --git a/app/src/main/res/menu/main_menu.xml b/app/src/main/res/menu/main_menu.xml index 6c413ff7..226e56d4 100644 --- a/app/src/main/res/menu/main_menu.xml +++ b/app/src/main/res/menu/main_menu.xml @@ -9,6 +9,9 @@ + + diff --git a/app/src/main/res/values-fi/strings.xml b/app/src/main/res/values-fi/strings.xml index 307bb94a..c400fb3e 100644 --- a/app/src/main/res/values-fi/strings.xml +++ b/app/src/main/res/values-fi/strings.xml @@ -275,6 +275,7 @@ Virhe Tietoja + Käynnistä uudelleen Lopeta Lähtevä puhelu … Tuleva puhelu … diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4e55fcf5..5c87760c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -251,6 +251,7 @@ Check Apps → baresip → Permissions → Storage and that file \'accounts.bs\' About + Restart Quit Outgoing call to … Incoming call from …