diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 176bd86c..f62d3ba9 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -1,6 +1,6 @@
+ xmlns:tools="http://schemas.android.com/tools" >
@@ -15,8 +15,7 @@
-
@@ -44,6 +43,7 @@
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:remove="android:appComponentFactory" >
+
+
+
+
+
+
@@ -63,26 +68,29 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ tools:ignore="ExportedReceiver" >
@@ -173,4 +209,4 @@
-
+
\ No newline at end of file
diff --git a/app/src/main/kotlin/com/tutpro/baresip/ConfigActivity.kt b/app/src/main/kotlin/com/tutpro/baresip/ConfigActivity.kt
index 8176cfb7..af2e345f 100644
--- a/app/src/main/kotlin/com/tutpro/baresip/ConfigActivity.kt
+++ b/app/src/main/kotlin/com/tutpro/baresip/ConfigActivity.kt
@@ -2,6 +2,7 @@ package com.tutpro.baresip
import android.Manifest
import android.app.Activity
+import android.app.role.RoleManager
import android.content.ActivityNotFoundException
import android.content.Context
import android.content.Intent
@@ -21,6 +22,7 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
+import androidx.transition.Visibility
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.snackbar.Snackbar
import com.tutpro.baresip.Utils.copyInputStreamToFile
@@ -36,7 +38,6 @@ class ConfigActivity : AppCompatActivity() {
private lateinit var layout: ScrollView
private lateinit var baresipService: Intent
private lateinit var autoStart: CheckBox
- private lateinit var batteryOptimizations: CheckBox
private lateinit var listenAddr: EditText
private lateinit var netAfSpinner: Spinner
private lateinit var netAf: String
@@ -49,6 +50,8 @@ class ConfigActivity : AppCompatActivity() {
private lateinit var contactsSpinner: Spinner
private lateinit var contactsMode: String
private lateinit var contactsModeKeys: ArrayList
+ private lateinit var batteryOptimizations: CheckBox
+ private lateinit var defaultDialer: CheckBox
private lateinit var debug: CheckBox
private lateinit var sipTrace: CheckBox
private lateinit var reset: CheckBox
@@ -74,6 +77,7 @@ class ConfigActivity : AppCompatActivity() {
goBack()
}
}
+
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@@ -109,6 +113,37 @@ class ConfigActivity : AppCompatActivity() {
}
}
+ if (Build.VERSION.SDK_INT >= 29) {
+ val roleManager = getSystemService(ROLE_SERVICE) as RoleManager
+ defaultDialer = binding.DefaultPhoneApp
+ defaultDialer.isChecked = roleManager.isRoleHeld(RoleManager.ROLE_DIALER)
+ val dialerRoleRequest = registerForActivityResult(
+ ActivityResultContracts.StartActivityForResult()
+ ) {
+ Log.d(TAG, "dialerRoleRequest succeeded: ${it.resultCode == Activity.RESULT_OK}")
+ defaultDialer.isChecked = roleManager.isRoleHeld(RoleManager.ROLE_DIALER)
+ }
+ defaultDialer.setOnCheckedChangeListener { _, isChecked ->
+ if (isChecked) {
+ if (!roleManager.isRoleAvailable(RoleManager.ROLE_DIALER))
+ Utils.alertView(this, getString(R.string.notice),
+ getString(R.string.dialer_role_not_available))
+ else
+ if (!roleManager.isRoleHeld(RoleManager.ROLE_DIALER))
+ dialerRoleRequest.launch(roleManager.createRequestRoleIntent(RoleManager.ROLE_DIALER))
+ } else {
+ try {
+ dialerRoleRequest.launch(Intent("android.settings.MANAGE_DEFAULT_APPS_SETTINGS"))
+ } catch (e: ActivityNotFoundException) {
+ Log.e(TAG, "ActivityNotFound exception: $e")
+
+ }
+ }
+ }
+ } else {
+ binding.PhoneApp.visibility = View.GONE
+ }
+
listenAddr = binding.ListenAddress
val laCv = Config.variable("sip_listen")
oldListenAddr = if (laCv.size == 0) "" else laCv[0]
@@ -642,10 +677,6 @@ class ConfigActivity : AppCompatActivity() {
Utils.alertView(this, getString(R.string.start_automatically),
getString(R.string.start_automatically_help))
}
- binding.BatteryOptimizationsTitle.setOnClickListener {
- Utils.alertView(this, getString(R.string.battery_optimizations),
- getString(R.string.battery_optimizations_help))
- }
binding.ListenAddressTitle.setOnClickListener {
Utils.alertView(this, getString(R.string.listen_address),
getString(R.string.listen_address_help))
@@ -681,6 +712,14 @@ class ConfigActivity : AppCompatActivity() {
Utils.alertView(this, getString(R.string.contacts),
getString(R.string.contacts_help))
}
+ binding.BatteryOptimizationsTitle.setOnClickListener {
+ Utils.alertView(this, getString(R.string.battery_optimizations),
+ getString(R.string.battery_optimizations_help))
+ }
+ binding.DefaultPhoneAppTitle.setOnClickListener {
+ Utils.alertView(this, getString(R.string.default_phone_app),
+ getString(R.string.default_phone_app_help))
+ }
binding.DebugTitle.setOnClickListener {
Utils.alertView(this, getString(R.string.debug), getString(R.string.debug_help))
}
diff --git a/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt b/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt
index 3658fdf9..cc7759cb 100644
--- a/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt
+++ b/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt
@@ -9,6 +9,7 @@ import android.app.NotificationManager
import android.content.*
import android.content.Intent.ACTION_CALL
import android.content.Intent.ACTION_DIAL
+import android.content.Intent.ACTION_VIEW
import android.content.pm.PackageManager
import android.content.res.Configuration.ORIENTATION_PORTRAIT
import android.media.AudioManager
@@ -40,6 +41,7 @@ import java.io.File
import java.net.URLDecoder
import kotlin.system.exitProcess
+
class MainActivity : AppCompatActivity() {
private lateinit var binding: ActivityMainBinding
@@ -653,11 +655,14 @@ class MainActivity : AppCompatActivity() {
atStartup = intent.hasExtra("onStartup")
- if (intent?.action == ACTION_CALL || intent?.action == ACTION_DIAL) {
- if (BaresipService.isServiceRunning)
- callAction(intent)
- else
- BaresipService.callActionUri = URLDecoder.decode(intent.data.toString(), "UTF-8")
+ when (intent?.action) {
+ ACTION_DIAL, ACTION_CALL, ACTION_VIEW ->
+ if (BaresipService.isServiceRunning)
+ callAction(intent)
+ else
+ BaresipService.callActionUri = URLDecoder.decode(intent.data.toString(), "UTF-8")
+ else ->
+ Log.d(TAG, "Unknown startup action ${intent?.action}")
}
permissions = if (Build.VERSION.SDK_INT >= 33)
@@ -824,10 +829,10 @@ class MainActivity : AppCompatActivity() {
resumeAction = ""
resumeUri = ""
- Log.d(TAG, "onNewIntent with intent.action '${intent.action}'")
+ Log.d(TAG, "onNewIntent with action/data '${intent.action}/${intent.data}'")
when (intent.action) {
- ACTION_DIAL, ACTION_CALL -> {
+ ACTION_DIAL, ACTION_CALL, ACTION_VIEW -> {
callAction(intent)
}
else -> {
diff --git a/app/src/main/res/layout/activity_config.xml b/app/src/main/res/layout/activity_config.xml
index 5e40dc1c..85c2ffd1 100644
--- a/app/src/main/res/layout/activity_config.xml
+++ b/app/src/main/res/layout/activity_config.xml
@@ -41,33 +41,6 @@
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Disable battery optimizations (recommended) if you want
to reduce likelihood that Android restricts baresip\'s access to network or enters baresip
to standby state.
+ Default Phone App
+ Dialer role is not available
+ If checked, baresip is the default phone app. Only choose
+ if your device never makes or receives calls or messages from telecom (cellular) network.
Listen Address
IP address and port of form \'address:port\' at which baresip listens
for incoming SIP requests. If IP address is an IPv6 address, it must be written inside