From 233fe21f26b5b39f35b40235aac4ead3debd2304 Mon Sep 17 00:00:00 2001 From: Maxime NATUREL Date: Tue, 31 May 2022 11:04:48 +0200 Subject: [PATCH] Remove runtime permission request --- .../vector/app/core/utils/PermissionsTools.kt | 6 --- .../DefaultLocationSharingNavigator.kt | 10 ----- .../location/LocationSharingFragment.kt | 37 ++----------------- .../location/LocationSharingNavigator.kt | 2 - 4 files changed, 3 insertions(+), 52 deletions(-) diff --git a/vector/src/main/java/im/vector/app/core/utils/PermissionsTools.kt b/vector/src/main/java/im/vector/app/core/utils/PermissionsTools.kt index a41abba7ab..705f683d2e 100644 --- a/vector/src/main/java/im/vector/app/core/utils/PermissionsTools.kt +++ b/vector/src/main/java/im/vector/app/core/utils/PermissionsTools.kt @@ -19,7 +19,6 @@ package im.vector.app.core.utils import android.Manifest import android.app.Activity import android.content.pm.PackageManager -import android.os.Build import androidx.activity.ComponentActivity import androidx.activity.result.ActivityResultLauncher import androidx.activity.result.contract.ActivityResultContracts @@ -43,11 +42,6 @@ val PERMISSIONS_FOR_ROOM_AVATAR = listOf(Manifest.permission.CAMERA) val PERMISSIONS_FOR_WRITING_FILES = listOf(Manifest.permission.WRITE_EXTERNAL_STORAGE) val PERMISSIONS_FOR_PICKING_CONTACT = listOf(Manifest.permission.READ_CONTACTS) val PERMISSIONS_FOR_FOREGROUND_LOCATION_SHARING = listOf(Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION) -val PERMISSIONS_FOR_BACKGROUND_LOCATION_SHARING = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { - listOf(Manifest.permission.ACCESS_BACKGROUND_LOCATION) -} else { - PERMISSIONS_EMPTY -} // This is not ideal to store the value like that, but it works private var permissionDialogDisplayed = false diff --git a/vector/src/main/java/im/vector/app/features/location/DefaultLocationSharingNavigator.kt b/vector/src/main/java/im/vector/app/features/location/DefaultLocationSharingNavigator.kt index 8f424af9ec..ec8638fdbb 100644 --- a/vector/src/main/java/im/vector/app/features/location/DefaultLocationSharingNavigator.kt +++ b/vector/src/main/java/im/vector/app/features/location/DefaultLocationSharingNavigator.kt @@ -17,20 +17,10 @@ package im.vector.app.features.location import android.app.Activity -import im.vector.app.core.utils.openAppSettingsPage class DefaultLocationSharingNavigator constructor(val activity: Activity?) : LocationSharingNavigator { - override var goingToAppSettings: Boolean = false - override fun quit() { activity?.finish() } - - override fun goToAppSettings() { - activity?.let { - goingToAppSettings = true - openAppSettingsPage(it) - } - } } diff --git a/vector/src/main/java/im/vector/app/features/location/LocationSharingFragment.kt b/vector/src/main/java/im/vector/app/features/location/LocationSharingFragment.kt index 6de853519b..89aedf3aa9 100644 --- a/vector/src/main/java/im/vector/app/features/location/LocationSharingFragment.kt +++ b/vector/src/main/java/im/vector/app/features/location/LocationSharingFragment.kt @@ -32,9 +32,9 @@ import com.mapbox.mapboxsdk.maps.MapView import im.vector.app.R import im.vector.app.core.platform.VectorBaseBottomSheetDialogFragment import im.vector.app.core.platform.VectorBaseFragment -import im.vector.app.core.utils.PERMISSIONS_FOR_BACKGROUND_LOCATION_SHARING import im.vector.app.core.utils.PERMISSIONS_FOR_FOREGROUND_LOCATION_SHARING import im.vector.app.core.utils.checkPermissions +import im.vector.app.core.utils.onPermissionDeniedDialog import im.vector.app.core.utils.registerForPermissionsResult import im.vector.app.databinding.FragmentLocationSharingBinding import im.vector.app.features.home.AvatarRenderer @@ -100,11 +100,6 @@ class LocationSharingFragment @Inject constructor( override fun onResume() { super.onResume() views.mapView.onResume() - if (locationSharingNavigator.goingToAppSettings) { - locationSharingNavigator.goingToAppSettings = false - // retry to start live location - tryStartLiveLocationSharing() - } } override fun onPause() { @@ -162,18 +157,6 @@ class LocationSharingFragment @Inject constructor( .show() } - private fun handleMissingBackgroundLocationPermission() { - MaterialAlertDialogBuilder(requireActivity()) - .setTitle(R.string.location_in_background_missing_permission_dialog_title) - .setMessage(R.string.location_in_background_missing_permission_dialog_content) - .setPositiveButton(R.string.settings) { _, _ -> - locationSharingNavigator.goToAppSettings() - } - .setNegativeButton(R.string.action_not_now, null) - .setCancelable(false) - .show() - } - private fun initLocateButton() { views.mapView.locateButton.setOnClickListener { viewModel.handle(LocationSharingAction.ZoomToUserLocation) @@ -212,30 +195,16 @@ class LocationSharingFragment @Inject constructor( } private val foregroundLocationResultLauncher = registerForPermissionsResult { allGranted, deniedPermanently -> - if (allGranted && checkPermissions(PERMISSIONS_FOR_BACKGROUND_LOCATION_SHARING, requireActivity(), backgroundLocationResultLauncher)) { - startLiveLocationSharing() - } else if (deniedPermanently) { - handleMissingBackgroundLocationPermission() - } - } - - private val backgroundLocationResultLauncher = registerForPermissionsResult { allGranted, deniedPermanently -> if (allGranted) { startLiveLocationSharing() } else if (deniedPermanently) { - handleMissingBackgroundLocationPermission() + activity?.onPermissionDeniedDialog(R.string.denied_permission_generic) } } private fun tryStartLiveLocationSharing() { // we need to re-check foreground location to be sure it has not changed after landing on this screen - if (checkPermissions(PERMISSIONS_FOR_FOREGROUND_LOCATION_SHARING, requireActivity(), foregroundLocationResultLauncher) && - checkPermissions( - PERMISSIONS_FOR_BACKGROUND_LOCATION_SHARING, - requireActivity(), - backgroundLocationResultLauncher, - R.string.location_in_background_missing_permission_dialog_content - )) { + if (checkPermissions(PERMISSIONS_FOR_FOREGROUND_LOCATION_SHARING, requireActivity(), foregroundLocationResultLauncher)) { startLiveLocationSharing() } } diff --git a/vector/src/main/java/im/vector/app/features/location/LocationSharingNavigator.kt b/vector/src/main/java/im/vector/app/features/location/LocationSharingNavigator.kt index 8927da9239..6f4759a1e4 100644 --- a/vector/src/main/java/im/vector/app/features/location/LocationSharingNavigator.kt +++ b/vector/src/main/java/im/vector/app/features/location/LocationSharingNavigator.kt @@ -17,7 +17,5 @@ package im.vector.app.features.location interface LocationSharingNavigator { - var goingToAppSettings: Boolean fun quit() - fun goToAppSettings() }