mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-01-17 11:28:06 +00:00
Ask for full screen intent if not granted
This commit is contained in:
parent
10f2d7cd78
commit
d6494cd27c
4 changed files with 56 additions and 18 deletions
|
|
@ -120,12 +120,23 @@ class MainActivity : GenericActivity() {
|
|||
) { isGranted ->
|
||||
if (isGranted) {
|
||||
Log.i("$TAG POST_NOTIFICATIONS permission has been granted")
|
||||
viewModel.updatePostNotificationsPermission()
|
||||
viewModel.updateMissingPermissionAlert()
|
||||
} else {
|
||||
Log.w("$TAG POST_NOTIFICATIONS permission has been denied!")
|
||||
}
|
||||
}
|
||||
|
||||
private val fullScreenIntentPermissionLauncher = registerForActivityResult(
|
||||
ActivityResultContracts.RequestPermission()
|
||||
) { isGranted ->
|
||||
if (isGranted) {
|
||||
Log.i("$TAG USE_FULL_SCREEN_INTENT permission has been granted")
|
||||
viewModel.updateMissingPermissionAlert()
|
||||
} else {
|
||||
Log.w("$TAG USE_FULL_SCREEN_INTENT permission has been denied!")
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("InlinedApi")
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
// Must be done before the setContentView
|
||||
|
|
@ -204,6 +215,18 @@ class MainActivity : GenericActivity() {
|
|||
}
|
||||
}
|
||||
|
||||
viewModel.askFullScreenIntentPermissionEvent.observe(this) {
|
||||
it.consume {
|
||||
if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.USE_FULL_SCREEN_INTENT)) {
|
||||
Log.w("$TAG Asking for USE_FULL_SCREEN_INTENT permission")
|
||||
fullScreenIntentPermissionLauncher.launch(Manifest.permission.USE_FULL_SCREEN_INTENT)
|
||||
} else {
|
||||
Log.i("$TAG Permission request for USE_FULL_SCREEN_INTENT will be automatically denied, go to manage app full screen intent android settings instead")
|
||||
Compatibility.requestFullScreenIntentPermission(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
viewModel.defaultAccountRegistrationErrorEvent.observe(this) {
|
||||
it.consume { error ->
|
||||
val tag = "DEFAULT_ACCOUNT_REGISTRATION_ERROR"
|
||||
|
|
@ -397,7 +420,7 @@ class MainActivity : GenericActivity() {
|
|||
viewModel.enableAccountMonitoring(true)
|
||||
viewModel.checkForNewAccount()
|
||||
viewModel.updateNetworkReachability()
|
||||
viewModel.updatePostNotificationsPermission()
|
||||
viewModel.updateMissingPermissionAlert()
|
||||
}
|
||||
|
||||
override fun onNewIntent(intent: Intent) {
|
||||
|
|
|
|||
|
|
@ -19,13 +19,10 @@
|
|||
*/
|
||||
package org.linphone.ui.main.viewmodel
|
||||
|
||||
import android.Manifest
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Build
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.annotation.UiThread
|
||||
import androidx.annotation.WorkerThread
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
|
|
@ -33,6 +30,7 @@ import kotlinx.coroutines.launch
|
|||
import org.linphone.LinphoneApplication.Companion.coreContext
|
||||
import org.linphone.LinphoneApplication.Companion.corePreferences
|
||||
import org.linphone.R
|
||||
import org.linphone.compatibility.Compatibility
|
||||
import org.linphone.core.Account
|
||||
import org.linphone.core.Call
|
||||
import org.linphone.core.ChatMessage
|
||||
|
|
@ -60,6 +58,7 @@ class MainViewModel
|
|||
const val MWI_MESSAGES_WAITING = 4
|
||||
const val NON_DEFAULT_ACCOUNT_NOTIFICATIONS = 5
|
||||
const val NON_DEFAULT_ACCOUNT_NOT_CONNECTED = 10
|
||||
const val FULL_SCREEN_INTENTS_PERMISSION_NOT_GRANTED = 16
|
||||
const val SEND_NOTIFICATIONS_PERMISSION_NOT_GRANTED = 17
|
||||
const val NETWORK_NOT_REACHABLE = 19
|
||||
const val SINGLE_CALL = 20
|
||||
|
|
@ -94,6 +93,10 @@ class MainViewModel
|
|||
MutableLiveData<Event<Boolean>>()
|
||||
}
|
||||
|
||||
val askFullScreenIntentPermissionEvent: MutableLiveData<Event<Boolean>> by lazy {
|
||||
MutableLiveData<Event<Boolean>>()
|
||||
}
|
||||
|
||||
val showNewAccountToastEvent: MutableLiveData<Event<Boolean>> by lazy {
|
||||
MutableLiveData<Event<Boolean>>()
|
||||
}
|
||||
|
|
@ -350,7 +353,7 @@ class MainViewModel
|
|||
}
|
||||
}
|
||||
|
||||
updatePostNotificationsPermission()
|
||||
updateMissingPermissionAlert()
|
||||
|
||||
if (VFS.isEnabled(coreContext.context)) {
|
||||
val cache = corePreferences.vfsCachePath
|
||||
|
|
@ -383,8 +386,13 @@ class MainViewModel
|
|||
}
|
||||
|
||||
@UiThread
|
||||
fun updatePostNotificationsPermission() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||
fun updateMissingPermissionAlert() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
|
||||
coreContext.postOnCoreThread {
|
||||
checkFullScreenIntentNotificationPermission()
|
||||
checkPostNotificationsPermission()
|
||||
}
|
||||
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||
coreContext.postOnCoreThread {
|
||||
checkPostNotificationsPermission()
|
||||
}
|
||||
|
|
@ -418,7 +426,9 @@ class MainViewModel
|
|||
fun onTopBarClicked() {
|
||||
if (atLeastOneCall.value == true) {
|
||||
goBackToCallEvent.value = Event(true)
|
||||
} else if (!isPostNotificationsPermissionGranted()) {
|
||||
} else if (!Compatibility.hasFullScreenIntentPermission(coreContext.context)) {
|
||||
askFullScreenIntentPermissionEvent.value = Event(true)
|
||||
} else if (!Compatibility.isPostNotificationsPermissionGranted(coreContext.context)) {
|
||||
askPostNotificationsPermissionEvent.value = Event(true)
|
||||
} else {
|
||||
openDrawerEvent.value = Event(true)
|
||||
|
|
@ -554,7 +564,7 @@ class MainViewModel
|
|||
NETWORK_NOT_REACHABLE -> {
|
||||
alertIcon.postValue(R.drawable.wifi_slash)
|
||||
}
|
||||
SEND_NOTIFICATIONS_PERMISSION_NOT_GRANTED -> {
|
||||
SEND_NOTIFICATIONS_PERMISSION_NOT_GRANTED, FULL_SCREEN_INTENTS_PERMISSION_NOT_GRANTED -> {
|
||||
alertIcon.postValue(R.drawable.bell_simple_slash)
|
||||
}
|
||||
SINGLE_CALL, MULTIPLE_CALLS -> {
|
||||
|
|
@ -598,21 +608,24 @@ class MainViewModel
|
|||
}
|
||||
}
|
||||
|
||||
private fun isPostNotificationsPermissionGranted(): Boolean {
|
||||
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||
ContextCompat.checkSelfPermission(
|
||||
coreContext.context,
|
||||
Manifest.permission.POST_NOTIFICATIONS
|
||||
) == PackageManager.PERMISSION_GRANTED
|
||||
@RequiresApi(Build.VERSION_CODES.UPSIDE_DOWN_CAKE)
|
||||
@WorkerThread
|
||||
private fun checkFullScreenIntentNotificationPermission() {
|
||||
if (!Compatibility.hasFullScreenIntentPermission(coreContext.context)) {
|
||||
Log.w("$TAG USE_FULL_SCREEN_INTENT seems to be not granted!")
|
||||
val label = AppUtils.getString(R.string.full_screen_intent_permission_not_granted)
|
||||
coreContext.postOnCoreThread {
|
||||
addAlert(FULL_SCREEN_INTENTS_PERMISSION_NOT_GRANTED, label)
|
||||
}
|
||||
} else {
|
||||
true
|
||||
removeAlert(FULL_SCREEN_INTENTS_PERMISSION_NOT_GRANTED)
|
||||
}
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.TIRAMISU)
|
||||
@WorkerThread
|
||||
private fun checkPostNotificationsPermission() {
|
||||
if (!isPostNotificationsPermissionGranted()) {
|
||||
if (!Compatibility.isPostNotificationsPermissionGranted(coreContext.context)) {
|
||||
Log.w("$TAG POST_NOTIFICATIONS seems to be not granted!")
|
||||
val label = AppUtils.getString(R.string.post_notifications_permission_not_granted)
|
||||
coreContext.postOnCoreThread {
|
||||
|
|
|
|||
|
|
@ -790,6 +790,7 @@
|
|||
<string name="generic_address_picker_favorites_list_title">Favoris</string>
|
||||
<string name="generic_address_picker_suggestions_list_title">Suggestions</string>
|
||||
<string name="post_notifications_permission_not_granted">La permission de poster des notifications n\'est pas donnée !</string>
|
||||
<string name="full_screen_intent_permission_not_granted">La permission d\'afficher les appels entrants n\'est pas donnée !</string>
|
||||
<plurals name="mwi_messages_are_waiting" tools:ignore="MissingQuantity">
|
||||
<item quantity="one">%s message vocal en attente</item>
|
||||
<item quantity="other">%s messages vocaux en attente</item>
|
||||
|
|
|
|||
|
|
@ -831,6 +831,7 @@
|
|||
<string name="generic_address_picker_favorites_list_title">Favorites</string>
|
||||
<string name="generic_address_picker_suggestions_list_title">Suggestions</string>
|
||||
<string name="post_notifications_permission_not_granted">Post notifications permission not granted!</string>
|
||||
<string name="full_screen_intent_permission_not_granted">Show incoming call permission not granted!</string>
|
||||
<plurals name="mwi_messages_are_waiting">
|
||||
<item quantity="one">%s new voice message</item>
|
||||
<item quantity="other">%s new voice messages</item>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue