Merge pull request #660 from vector-im/feature/permission

Ask for permission to write external storage when uri comes from the keyboard (#658)
This commit is contained in:
Benoit Marty 2019-11-04 14:26:12 +01:00 committed by GitHub
commit 5d7efa7f8f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 46 additions and 20 deletions

View File

@ -14,6 +14,7 @@ Other changes:
Bugfix 🐛: Bugfix 🐛:
- Fix issues with some member events rendering (#498) - Fix issues with some member events rendering (#498)
- Passphrase does not match (Export room keys) (#644) - Passphrase does not match (Export room keys) (#644)
- Ask for permission to write external storage when uri comes from the keyboard (#658)
Translations 🗣: Translations 🗣:
- -

View File

@ -67,6 +67,7 @@ const val PERMISSION_REQUEST_CODE_EXPORT_KEYS = 573
const val PERMISSION_REQUEST_CODE_CHANGE_AVATAR = 574 const val PERMISSION_REQUEST_CODE_CHANGE_AVATAR = 574
const val PERMISSION_REQUEST_CODE_DOWNLOAD_FILE = 575 const val PERMISSION_REQUEST_CODE_DOWNLOAD_FILE = 575
const val PERMISSION_REQUEST_CODE_PICK_ATTACHMENT = 576 const val PERMISSION_REQUEST_CODE_PICK_ATTACHMENT = 576
const val PERMISSION_REQUEST_CODE_INCOMING_URI = 577
/** /**
* Log the used permissions statuses. * Log the used permissions statuses.

View File

@ -81,8 +81,6 @@ import im.vector.riotx.core.platform.VectorBaseFragment
import im.vector.riotx.core.ui.views.JumpToReadMarkerView import im.vector.riotx.core.ui.views.JumpToReadMarkerView
import im.vector.riotx.core.ui.views.NotificationAreaView import im.vector.riotx.core.ui.views.NotificationAreaView
import im.vector.riotx.core.utils.* import im.vector.riotx.core.utils.*
import im.vector.riotx.core.utils.Debouncer
import im.vector.riotx.core.utils.createUIHandler
import im.vector.riotx.features.attachments.AttachmentTypeSelectorView import im.vector.riotx.features.attachments.AttachmentTypeSelectorView
import im.vector.riotx.features.attachments.AttachmentsHelper import im.vector.riotx.features.attachments.AttachmentsHelper
import im.vector.riotx.features.attachments.ContactAttachment import im.vector.riotx.features.attachments.ContactAttachment
@ -619,18 +617,26 @@ class RoomDetailFragment :
} }
composerLayout.callback = object : TextComposerView.Callback { composerLayout.callback = object : TextComposerView.Callback {
override fun onRichContentSelected(contentUri: Uri): Boolean { override fun onRichContentSelected(contentUri: Uri): Boolean {
val shareIntent = Intent().apply { // We need WRITE_EXTERNAL permission
action = Intent.ACTION_SEND return if (checkPermissions(PERMISSIONS_FOR_WRITING_FILES, this@RoomDetailFragment, PERMISSION_REQUEST_CODE_INCOMING_URI)) {
data = contentUri sendUri(contentUri)
} else {
roomDetailViewModel.pendingUri = contentUri
// Always intercept when we request some permission
true
} }
}
}
}
private fun sendUri(uri: Uri): Boolean {
val shareIntent = Intent(Intent.ACTION_SEND, uri)
val isHandled = attachmentsHelper.handleShareIntent(shareIntent) val isHandled = attachmentsHelper.handleShareIntent(shareIntent)
if (!isHandled) { if (!isHandled) {
Toast.makeText(requireContext(), R.string.error_handling_incoming_share, Toast.LENGTH_SHORT).show() Toast.makeText(requireContext(), R.string.error_handling_incoming_share, Toast.LENGTH_SHORT).show()
} }
return isHandled return isHandled
} }
}
}
private fun setupAttachmentButton() { private fun setupAttachmentButton() {
composerLayout.attachmentButton.setOnClickListener { composerLayout.attachmentButton.setOnClickListener {
@ -906,13 +912,22 @@ class RoomDetailFragment :
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) { override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
if (allGranted(grantResults)) { if (allGranted(grantResults)) {
if (requestCode == PERMISSION_REQUEST_CODE_DOWNLOAD_FILE) { when (requestCode) {
PERMISSION_REQUEST_CODE_DOWNLOAD_FILE -> {
val action = roomDetailViewModel.pendingAction val action = roomDetailViewModel.pendingAction
if (action != null) { if (action != null) {
roomDetailViewModel.pendingAction = null roomDetailViewModel.pendingAction = null
roomDetailViewModel.process(action) roomDetailViewModel.process(action)
} }
} else if (requestCode == PERMISSION_REQUEST_CODE_PICK_ATTACHMENT) { }
PERMISSION_REQUEST_CODE_INCOMING_URI -> {
val pendingUri = roomDetailViewModel.pendingUri
if (pendingUri != null) {
roomDetailViewModel.pendingUri = null
sendUri(pendingUri)
}
}
PERMISSION_REQUEST_CODE_PICK_ATTACHMENT -> {
val pendingType = attachmentsHelper.pendingType val pendingType = attachmentsHelper.pendingType
if (pendingType != null) { if (pendingType != null) {
attachmentsHelper.pendingType = null attachmentsHelper.pendingType = null
@ -920,6 +935,12 @@ class RoomDetailFragment :
} }
} }
} }
} else {
// Reset all pending data
roomDetailViewModel.pendingAction = null
roomDetailViewModel.pendingUri = null
attachmentsHelper.pendingType = null
}
} }
override fun onAudioMessageClicked(messageAudioContent: MessageAudioContent) { override fun onAudioMessageClicked(messageAudioContent: MessageAudioContent) {

View File

@ -16,6 +16,7 @@
package im.vector.riotx.features.home.room.detail package im.vector.riotx.features.home.room.detail
import android.net.Uri
import androidx.annotation.IdRes import androidx.annotation.IdRes
import androidx.lifecycle.LiveData import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
@ -95,6 +96,8 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro
// Slot to keep a pending action during permission request // Slot to keep a pending action during permission request
var pendingAction: RoomDetailActions? = null var pendingAction: RoomDetailActions? = null
// Slot to keep a pending uri during permission request
var pendingUri: Uri? = null
@AssistedInject.Factory @AssistedInject.Factory
interface Factory { interface Factory {