mirror of
https://github.com/element-hq/element-android
synced 2024-11-23 18:05:36 +03:00
Better management of requested permissions (#2048)
This commit is contained in:
parent
1e5122f741
commit
fee7701d26
3 changed files with 18 additions and 7 deletions
|
@ -7,6 +7,7 @@ Features ✨:
|
|||
Improvements 🙌:
|
||||
- Add "show password" in import Megolm keys dialog
|
||||
- Visually disable call buttons in menu and prohibit calling when permissions are insufficient (#2112)
|
||||
- Better management of requested permissions (#2048)
|
||||
|
||||
Bugfix 🐛:
|
||||
- Long message cannot be sent/takes infinite time & blocks other messages #1397
|
||||
|
|
|
@ -42,16 +42,18 @@ const val PERMISSION_CAMERA = 0x1
|
|||
private const val PERMISSION_WRITE_EXTERNAL_STORAGE = 0x1 shl 1
|
||||
private const val PERMISSION_RECORD_AUDIO = 0x1 shl 2
|
||||
private const val PERMISSION_READ_CONTACTS = 0x1 shl 3
|
||||
private const val PERMISSION_READ_EXTERNAL_STORAGE = 0x1 shl 4
|
||||
|
||||
// Permissions sets
|
||||
const val PERMISSIONS_FOR_AUDIO_IP_CALL = PERMISSION_RECORD_AUDIO
|
||||
const val PERMISSIONS_FOR_VIDEO_IP_CALL = PERMISSION_CAMERA or PERMISSION_RECORD_AUDIO
|
||||
const val PERMISSIONS_FOR_TAKING_PHOTO = PERMISSION_CAMERA or PERMISSION_WRITE_EXTERNAL_STORAGE
|
||||
const val PERMISSIONS_FOR_TAKING_PHOTO = PERMISSION_CAMERA or PERMISSION_READ_EXTERNAL_STORAGE
|
||||
const val PERMISSIONS_FOR_MEMBERS_SEARCH = PERMISSION_READ_CONTACTS
|
||||
const val PERMISSIONS_FOR_MEMBER_DETAILS = PERMISSION_READ_CONTACTS
|
||||
const val PERMISSIONS_FOR_ROOM_AVATAR = PERMISSION_CAMERA
|
||||
const val PERMISSIONS_FOR_VIDEO_RECORDING = PERMISSION_CAMERA or PERMISSION_RECORD_AUDIO
|
||||
const val PERMISSIONS_FOR_WRITING_FILES = PERMISSION_WRITE_EXTERNAL_STORAGE
|
||||
const val PERMISSIONS_FOR_READING_FILES = PERMISSION_READ_EXTERNAL_STORAGE
|
||||
const val PERMISSIONS_FOR_PICKING_CONTACT = PERMISSION_READ_CONTACTS
|
||||
|
||||
const val PERMISSIONS_EMPTY = PERMISSION_BYPASSED
|
||||
|
@ -79,6 +81,7 @@ fun logPermissionStatuses(context: Context) {
|
|||
Manifest.permission.CAMERA,
|
||||
Manifest.permission.RECORD_AUDIO,
|
||||
Manifest.permission.WRITE_EXTERNAL_STORAGE,
|
||||
Manifest.permission.READ_EXTERNAL_STORAGE,
|
||||
Manifest.permission.READ_CONTACTS)
|
||||
|
||||
Timber.v("## logPermissionStatuses() : log the permissions status used by the app")
|
||||
|
@ -145,7 +148,7 @@ private fun checkPermissions(permissionsToBeGrantedBitMap: Int,
|
|||
fragment: Fragment?,
|
||||
requestCode: Int,
|
||||
@StringRes rationaleMessage: Int
|
||||
): Boolean {
|
||||
): Boolean {
|
||||
var isPermissionGranted = false
|
||||
|
||||
// sanity check
|
||||
|
@ -161,7 +164,8 @@ private fun checkPermissions(permissionsToBeGrantedBitMap: Int,
|
|||
&& PERMISSIONS_FOR_MEMBER_DETAILS != permissionsToBeGrantedBitMap
|
||||
&& PERMISSIONS_FOR_ROOM_AVATAR != permissionsToBeGrantedBitMap
|
||||
&& PERMISSIONS_FOR_VIDEO_RECORDING != permissionsToBeGrantedBitMap
|
||||
&& PERMISSIONS_FOR_WRITING_FILES != permissionsToBeGrantedBitMap) {
|
||||
&& PERMISSIONS_FOR_WRITING_FILES != permissionsToBeGrantedBitMap
|
||||
&& PERMISSIONS_FOR_READING_FILES != permissionsToBeGrantedBitMap) {
|
||||
Timber.w("## checkPermissions(): permissions to be granted are not supported")
|
||||
isPermissionGranted = false
|
||||
} else {
|
||||
|
@ -188,6 +192,12 @@ private fun checkPermissions(permissionsToBeGrantedBitMap: Int,
|
|||
updatePermissionsToBeGranted(activity, permissionListAlreadyDenied, permissionsListToBeGranted, permissionType)
|
||||
}
|
||||
|
||||
if (PERMISSION_READ_EXTERNAL_STORAGE == permissionsToBeGrantedBitMap and PERMISSION_READ_EXTERNAL_STORAGE) {
|
||||
val permissionType = Manifest.permission.READ_EXTERNAL_STORAGE
|
||||
isRequestPermissionRequired = isRequestPermissionRequired or
|
||||
updatePermissionsToBeGranted(activity, permissionListAlreadyDenied, permissionsListToBeGranted, permissionType)
|
||||
}
|
||||
|
||||
// the contact book access is requested for any android platforms
|
||||
// for android M, we use the system preferences
|
||||
// for android < M, we use a dedicated settings
|
||||
|
|
|
@ -41,8 +41,8 @@ import im.vector.app.R
|
|||
import im.vector.app.core.extensions.getMeasurements
|
||||
import im.vector.app.core.utils.PERMISSIONS_EMPTY
|
||||
import im.vector.app.core.utils.PERMISSIONS_FOR_PICKING_CONTACT
|
||||
import im.vector.app.core.utils.PERMISSIONS_FOR_READING_FILES
|
||||
import im.vector.app.core.utils.PERMISSIONS_FOR_TAKING_PHOTO
|
||||
import im.vector.app.core.utils.PERMISSIONS_FOR_WRITING_FILES
|
||||
import im.vector.app.features.attachments.AttachmentTypeSelectorView.Callback
|
||||
import kotlin.math.max
|
||||
|
||||
|
@ -215,10 +215,10 @@ class AttachmentTypeSelectorView(context: Context,
|
|||
*/
|
||||
enum class Type(val permissionsBit: Int) {
|
||||
CAMERA(PERMISSIONS_FOR_TAKING_PHOTO),
|
||||
GALLERY(PERMISSIONS_FOR_WRITING_FILES),
|
||||
FILE(PERMISSIONS_FOR_WRITING_FILES),
|
||||
GALLERY(PERMISSIONS_FOR_READING_FILES),
|
||||
FILE(PERMISSIONS_FOR_READING_FILES),
|
||||
STICKER(PERMISSIONS_EMPTY),
|
||||
AUDIO(PERMISSIONS_FOR_WRITING_FILES),
|
||||
AUDIO(PERMISSIONS_FOR_READING_FILES),
|
||||
CONTACT(PERMISSIONS_FOR_PICKING_CONTACT)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue