- 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:
@@ -354,6 +354,7 @@ class BaresipService: Service() {
|
|||||||
status[account_index] = R.drawable.dot_yellow
|
status[account_index] = R.drawable.dot_yellow
|
||||||
else
|
else
|
||||||
status[account_index] = R.drawable.dot_green
|
status[account_index] = R.drawable.dot_green
|
||||||
|
ua.registrationFailed = false
|
||||||
updateStatusNotification()
|
updateStatusNotification()
|
||||||
if (!Utils.isVisible())
|
if (!Utils.isVisible())
|
||||||
return
|
return
|
||||||
@@ -361,25 +362,31 @@ class BaresipService: Service() {
|
|||||||
"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 ((ev.size > 1) && (ev[1] == "Invalid argument")) {
|
||||||
// Most likely this error is due to DNS lookup failure
|
// Most likely this error is due to DNS lookup failure
|
||||||
newEvent = "registering failed,DNS lookup failed"
|
newEvent = "registering failed,DNS lookup failed"
|
||||||
Api.net_dns_debug()
|
Api.net_dns_debug()
|
||||||
if (dynDns)
|
if (dynDns)
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
val activeNetwork = cm.activeNetwork
|
val activeNetwork = cm.activeNetwork
|
||||||
if (activeNetwork != null) {
|
if (activeNetwork != null) {
|
||||||
val dnsServers = cm.getLinkProperties(activeNetwork).dnsServers
|
val dnsServers = cm.getLinkProperties(activeNetwork).dnsServers
|
||||||
Log.d(LOG_TAG, "Updating DNS Servers = $dnsServers")
|
Log.d(LOG_TAG, "Updating DNS Servers = $dnsServers")
|
||||||
if (Config.updateDnsServers(dnsServers) != 0)
|
if (Config.updateDnsServers(dnsServers) != 0) {
|
||||||
Log.w(LOG_TAG, "Failed to update DNS servers '$dnsServers'")
|
Log.w(LOG_TAG, "Failed to update DNS servers '$dnsServers'")
|
||||||
else
|
|
||||||
Api.net_dns_debug()
|
|
||||||
} else {
|
} 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())
|
if (!Utils.isVisible())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -683,7 +690,7 @@ class BaresipService: Service() {
|
|||||||
|
|
||||||
@Keep
|
@Keep
|
||||||
fun stopped(error: String) {
|
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
|
isServiceRunning = false
|
||||||
if (error == "ua_init") {
|
if (error == "ua_init") {
|
||||||
Config.remove("sip_listen")
|
Config.remove("sip_listen")
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ object Config {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (write) {
|
if (write) {
|
||||||
Log.e("Baresip", "Writing '$config'")
|
Log.e("Baresip", "Writing config '$config'")
|
||||||
Utils.putFileContents(file, config)
|
Utils.putFileContents(file, config)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ package com.tutpro.baresip
|
|||||||
import android.Manifest
|
import android.Manifest
|
||||||
import android.app.KeyguardManager
|
import android.app.KeyguardManager
|
||||||
import android.app.NotificationManager
|
import android.app.NotificationManager
|
||||||
|
import android.app.AlarmManager
|
||||||
|
import android.app.PendingIntent
|
||||||
import android.content.*
|
import android.content.*
|
||||||
import android.support.v4.app.ActivityCompat
|
import android.support.v4.app.ActivityCompat
|
||||||
import android.support.v4.content.ContextCompat
|
import android.support.v4.content.ContextCompat
|
||||||
@@ -50,6 +52,8 @@ class MainActivity : AppCompatActivity() {
|
|||||||
internal lateinit var stopState: String
|
internal lateinit var stopState: String
|
||||||
internal lateinit var speakerIcon: MenuItem
|
internal lateinit var speakerIcon: MenuItem
|
||||||
|
|
||||||
|
internal var restart = false
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
@@ -583,7 +587,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (event == "stopped") {
|
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] != "") {
|
if (params[0] != "") {
|
||||||
val alertDialog = AlertDialog.Builder(this).create()
|
val alertDialog = AlertDialog.Builder(this).create()
|
||||||
alertDialog.setTitle(getString(R.string.notice))
|
alertDialog.setTitle(getString(R.string.notice))
|
||||||
@@ -599,6 +603,14 @@ class MainActivity : AppCompatActivity() {
|
|||||||
} else {
|
} else {
|
||||||
quitTimer.cancel()
|
quitTimer.cancel()
|
||||||
finishAndRemoveTask()
|
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)
|
System.exit(0)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -894,10 +906,11 @@ class MainActivity : AppCompatActivity() {
|
|||||||
startActivityForResult(i, ABOUT_CODE)
|
startActivityForResult(i, ABOUT_CODE)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
R.id.quit -> {
|
R.id.restart, R.id.quit -> {
|
||||||
if (stopState == "initial") {
|
if (stopState == "initial") {
|
||||||
Log.d("Baresip", "Quiting")
|
Log.d("Baresip", "Quiting")
|
||||||
if (BaresipService.isServiceRunning) {
|
if (BaresipService.isServiceRunning) {
|
||||||
|
if (item.itemId == R.id.restart) restart = true
|
||||||
baresipService.setAction("Stop");
|
baresipService.setAction("Stop");
|
||||||
startService(baresipService)
|
startService(baresipService)
|
||||||
quitTimer.start()
|
quitTimer.start()
|
||||||
@@ -1189,6 +1202,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
const val MESSAGE_CODE = 9
|
const val MESSAGE_CODE = 9
|
||||||
|
|
||||||
const val PERMISSION_REQUEST_CODE = 1
|
const val PERMISSION_REQUEST_CODE = 1
|
||||||
|
const val RESTART_REQUEST_CODE = 2
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import java.io.File
|
|||||||
class RunOnStartup : BroadcastReceiver() {
|
class RunOnStartup : BroadcastReceiver() {
|
||||||
|
|
||||||
override fun onReceive(context: Context, intent: Intent) {
|
override fun onReceive(context: Context, intent: Intent) {
|
||||||
|
Log.i("Baresip", "RunOnStartup received intent ${intent.action}")
|
||||||
if ((intent.action == Intent.ACTION_BOOT_COMPLETED) or
|
if ((intent.action == Intent.ACTION_BOOT_COMPLETED) or
|
||||||
(intent.action == "com.tutpro.baresip.Restart")) {
|
(intent.action == "com.tutpro.baresip.Restart")) {
|
||||||
val configFile = File(context.filesDir.absolutePath + "/config")
|
val configFile = File(context.filesDir.absolutePath + "/config")
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.tutpro.baresip
|
|||||||
class UserAgent (val uap: String) {
|
class UserAgent (val uap: String) {
|
||||||
|
|
||||||
val account = Account(Api.ua_account(uap))
|
val account = Account(Api.ua_account(uap))
|
||||||
|
var registrationFailed = false
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,9 @@
|
|||||||
<item android:id="@+id/about"
|
<item android:id="@+id/about"
|
||||||
android:title="@string/about" />
|
android:title="@string/about" />
|
||||||
|
|
||||||
|
<item android:id="@+id/restart"
|
||||||
|
android:title="@string/restart" />
|
||||||
|
|
||||||
<item android:id="@+id/quit"
|
<item android:id="@+id/quit"
|
||||||
android:title="@string/quit" />
|
android:title="@string/quit" />
|
||||||
|
|
||||||
|
|||||||
@@ -275,6 +275,7 @@
|
|||||||
<string name="error">Virhe</string>
|
<string name="error">Virhe</string>
|
||||||
<!-- Main Activity -->
|
<!-- Main Activity -->
|
||||||
<string name="about">Tietoja</string>
|
<string name="about">Tietoja</string>
|
||||||
|
<string name="restart">Käynnistä uudelleen</string>
|
||||||
<string name="quit">Lopeta</string>
|
<string name="quit">Lopeta</string>
|
||||||
<string name="outgoing_call_to_dots">Lähtevä puhelu …</string>
|
<string name="outgoing_call_to_dots">Lähtevä puhelu …</string>
|
||||||
<string name="incoming_call_from_dots">Tuleva puhelu …</string>
|
<string name="incoming_call_from_dots">Tuleva puhelu …</string>
|
||||||
|
|||||||
@@ -251,6 +251,7 @@ Check Apps → baresip → Permissions → Storage and that file \'accounts.bs\'
|
|||||||
|
|
||||||
<!-- Main Activity -->
|
<!-- Main Activity -->
|
||||||
<string name="about">About</string>
|
<string name="about">About</string>
|
||||||
|
<string name="restart">Restart</string>
|
||||||
<string name="quit">Quit</string>
|
<string name="quit">Quit</string>
|
||||||
<string name="outgoing_call_to_dots">Outgoing call to …</string>
|
<string name="outgoing_call_to_dots">Outgoing call to …</string>
|
||||||
<string name="incoming_call_from_dots">Incoming call from …</string>
|
<string name="incoming_call_from_dots">Incoming call from …</string>
|
||||||
|
|||||||
Reference in New Issue
Block a user