More permissions cleaning
This commit is contained in:
@@ -669,12 +669,12 @@ class MainActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
requestPermissionLauncher =
|
requestPermissionLauncher =
|
||||||
registerForActivityResult(ActivityResultContracts.RequestPermission()) {}
|
registerForActivityResult(ActivityResultContracts.RequestPermission()) {}
|
||||||
|
|
||||||
requestPermissionsLauncher =
|
requestPermissionsLauncher =
|
||||||
registerForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) {
|
registerForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) {
|
||||||
val denied = mutableListOf<String>()
|
val denied = mutableListOf<String>()
|
||||||
val shouldShow = mutableListOf<String>()
|
val shouldShow = mutableListOf<String>()
|
||||||
it.forEach { permission ->
|
it.forEach { permission ->
|
||||||
Log.e(TAG, "${permission.key} : ${permission.value}")
|
|
||||||
if (!permission.value) {
|
if (!permission.value) {
|
||||||
denied.add(permission.key)
|
denied.add(permission.key)
|
||||||
if (ActivityCompat.shouldShowRequestPermissionRationale(this,
|
if (ActivityCompat.shouldShowRequestPermissionRationale(this,
|
||||||
@@ -685,8 +685,8 @@ class MainActivity : AppCompatActivity() {
|
|||||||
if (denied.contains(POST_NOTIFICATIONS) &&
|
if (denied.contains(POST_NOTIFICATIONS) &&
|
||||||
!shouldShow.contains(POST_NOTIFICATIONS)) {
|
!shouldShow.contains(POST_NOTIFICATIONS)) {
|
||||||
with(MaterialAlertDialogBuilder(this, R.style.AlertDialogTheme)) {
|
with(MaterialAlertDialogBuilder(this, R.style.AlertDialogTheme)) {
|
||||||
setTitle("Cannot start baresip")
|
setTitle(getString(R.string.notice))
|
||||||
setMessage("Notifications permission has not been granted")
|
setMessage(getString(R.string.no_notifications))
|
||||||
setPositiveButton(getString(R.string.ok)) { _, _ ->
|
setPositiveButton(getString(R.string.ok)) { _, _ ->
|
||||||
quitRestart(false)
|
quitRestart(false)
|
||||||
}
|
}
|
||||||
@@ -694,7 +694,9 @@ class MainActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (shouldShow.isNotEmpty())
|
if (shouldShow.isNotEmpty())
|
||||||
askPermissions(permissions)
|
Utils.alertView(this, getString(R.string.permissions_rationale),
|
||||||
|
getString(R.string.audio_permissions)
|
||||||
|
) { requestPermissionsLauncher.launch(permissions) }
|
||||||
else
|
else
|
||||||
startBaresip()
|
startBaresip()
|
||||||
}
|
}
|
||||||
@@ -709,7 +711,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
askPasswords(accounts)
|
askPasswords(accounts)
|
||||||
} else {
|
} else {
|
||||||
// Baresip is started for the first time
|
// Baresip is started for the first time
|
||||||
askPermissions(permissions)
|
requestPermissionsLauncher.launch(permissions)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -723,7 +725,6 @@ class MainActivity : AppCompatActivity() {
|
|||||||
override fun onStart() {
|
override fun onStart() {
|
||||||
super.onStart()
|
super.onStart()
|
||||||
Log.e(TAG, "Main onStart")
|
Log.e(TAG, "Main onStart")
|
||||||
|
|
||||||
val action = intent.getStringExtra("action")
|
val action = intent.getStringExtra("action")
|
||||||
if (action != null) {
|
if (action != null) {
|
||||||
// MainActivity was not visible when call, message, or transfer request came in
|
// MainActivity was not visible when call, message, or transfer request came in
|
||||||
@@ -836,18 +837,6 @@ class MainActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun askPermissions(permissions: Array<String>) {
|
|
||||||
with(MaterialAlertDialogBuilder(this, R.style.AlertDialogTheme)) {
|
|
||||||
setTitle(getString(R.string.permissions_rationale))
|
|
||||||
setMessage(getString(R.string.audio_permissions))
|
|
||||||
setPositiveButton(getString(R.string.ok)) { dialog, _ ->
|
|
||||||
requestPermissionsLauncher.launch(permissions)
|
|
||||||
dialog.dismiss()
|
|
||||||
}
|
|
||||||
show()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun callAction(intent: Intent) {
|
private fun callAction(intent: Intent) {
|
||||||
if (Call.calls().isNotEmpty() || BaresipService.uas.size == 0)
|
if (Call.calls().isNotEmpty() || BaresipService.uas.size == 0)
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user