Merge pull request #6967 from vector-im/feature/bma/fix_crashes

Fix crashes
This commit is contained in:
Benoit Marty 2022-08-31 15:25:57 +02:00 committed by GitHub
commit 0950e41526
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 27 additions and 9 deletions

1
changelog.d/6967.bugfix Normal file
View File

@ -0,0 +1 @@
Fix low occurrence crashes.

View File

@ -16,6 +16,7 @@
package im.vector.app.core.error package im.vector.app.core.error
import android.content.ActivityNotFoundException
import im.vector.app.R import im.vector.app.R
import im.vector.app.core.resources.StringProvider import im.vector.app.core.resources.StringProvider
import im.vector.app.features.call.dialpad.DialPadLookup import im.vector.app.features.call.dialpad.DialPadLookup
@ -134,6 +135,8 @@ class DefaultErrorFormatter @Inject constructor(
is MatrixIdFailure.InvalidMatrixId -> is MatrixIdFailure.InvalidMatrixId ->
stringProvider.getString(R.string.login_signin_matrix_id_error_invalid_matrix_id) stringProvider.getString(R.string.login_signin_matrix_id_error_invalid_matrix_id)
is VoiceFailure -> voiceMessageError(throwable) is VoiceFailure -> voiceMessageError(throwable)
is ActivityNotFoundException ->
stringProvider.getString(R.string.error_no_external_application_found)
else -> throwable.localizedMessage else -> throwable.localizedMessage
} }
?: stringProvider.getString(R.string.unknown_error) ?: stringProvider.getString(R.string.unknown_error)

View File

@ -16,6 +16,7 @@
package im.vector.app.features.attachments package im.vector.app.features.attachments
import android.app.Activity import android.app.Activity
import android.content.ActivityNotFoundException
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.net.Uri import android.net.Uri
@ -44,6 +45,7 @@ class AttachmentsHelper(
interface Callback { interface Callback {
fun onContactAttachmentReady(contactAttachment: ContactAttachment) fun onContactAttachmentReady(contactAttachment: ContactAttachment)
fun onContentAttachmentsReady(attachments: List<ContentAttachmentData>) fun onContentAttachmentsReady(attachments: List<ContentAttachmentData>)
fun onAttachmentError(throwable: Throwable)
} }
// Capture path allows to handle camera image picking. It must be restored if the activity gets killed. // Capture path allows to handle camera image picking. It must be restored if the activity gets killed.
@ -73,21 +75,21 @@ class AttachmentsHelper(
/** /**
* Starts the process for handling file picking. * Starts the process for handling file picking.
*/ */
fun selectFile(activityResultLauncher: ActivityResultLauncher<Intent>) { fun selectFile(activityResultLauncher: ActivityResultLauncher<Intent>) = doSafe {
MultiPicker.get(MultiPicker.FILE).startWith(activityResultLauncher) MultiPicker.get(MultiPicker.FILE).startWith(activityResultLauncher)
} }
/** /**
* Starts the process for handling image/video picking. * Starts the process for handling image/video picking.
*/ */
fun selectGallery(activityResultLauncher: ActivityResultLauncher<Intent>) { fun selectGallery(activityResultLauncher: ActivityResultLauncher<Intent>) = doSafe {
MultiPicker.get(MultiPicker.MEDIA).startWith(activityResultLauncher) MultiPicker.get(MultiPicker.MEDIA).startWith(activityResultLauncher)
} }
/** /**
* Starts the process for handling audio picking. * Starts the process for handling audio picking.
*/ */
fun selectAudio(activityResultLauncher: ActivityResultLauncher<Intent>) { fun selectAudio(activityResultLauncher: ActivityResultLauncher<Intent>) = doSafe {
MultiPicker.get(MultiPicker.AUDIO).startWith(activityResultLauncher) MultiPicker.get(MultiPicker.AUDIO).startWith(activityResultLauncher)
} }
@ -101,11 +103,11 @@ class AttachmentsHelper(
cameraVideoActivityResultLauncher: ActivityResultLauncher<Intent> cameraVideoActivityResultLauncher: ActivityResultLauncher<Intent>
) { ) {
PhotoOrVideoDialog(activity, vectorPreferences).show(object : PhotoOrVideoDialog.PhotoOrVideoDialogListener { PhotoOrVideoDialog(activity, vectorPreferences).show(object : PhotoOrVideoDialog.PhotoOrVideoDialogListener {
override fun takePhoto() { override fun takePhoto() = doSafe {
captureUri = MultiPicker.get(MultiPicker.CAMERA).startWithExpectingFile(context, cameraActivityResultLauncher) captureUri = MultiPicker.get(MultiPicker.CAMERA).startWithExpectingFile(context, cameraActivityResultLauncher)
} }
override fun takeVideo() { override fun takeVideo() = doSafe {
captureUri = MultiPicker.get(MultiPicker.CAMERA_VIDEO).startWithExpectingFile(context, cameraVideoActivityResultLauncher) captureUri = MultiPicker.get(MultiPicker.CAMERA_VIDEO).startWithExpectingFile(context, cameraVideoActivityResultLauncher)
} }
}) })
@ -114,10 +116,18 @@ class AttachmentsHelper(
/** /**
* Starts the process for handling contact picking. * Starts the process for handling contact picking.
*/ */
fun selectContact(activityResultLauncher: ActivityResultLauncher<Intent>) { fun selectContact(activityResultLauncher: ActivityResultLauncher<Intent>) = doSafe {
MultiPicker.get(MultiPicker.CONTACT).startWith(activityResultLauncher) MultiPicker.get(MultiPicker.CONTACT).startWith(activityResultLauncher)
} }
private fun doSafe(function: () -> Unit) {
try {
function()
} catch (activityNotFound: ActivityNotFoundException) {
callback.onAttachmentError(activityNotFound)
}
}
/** /**
* This methods aims to handle the result data. * This methods aims to handle the result data.
*/ */

View File

@ -2658,6 +2658,10 @@ class TimelineFragment :
messageComposerViewModel.handle(MessageComposerAction.SendMessage(formattedContact, false)) messageComposerViewModel.handle(MessageComposerAction.SendMessage(formattedContact, false))
} }
override fun onAttachmentError(throwable: Throwable) {
showFailure(throwable)
}
private fun onViewWidgetsClicked() { private fun onViewWidgetsClicked() {
RoomWidgetsBottomSheet.newInstance() RoomWidgetsBottomSheet.newInstance()
.show(childFragmentManager, "ROOM_WIDGETS_BOTTOM_SHEET") .show(childFragmentManager, "ROOM_WIDGETS_BOTTOM_SHEET")

View File

@ -1046,7 +1046,7 @@ class TimelineViewModel @AssistedInject constructor(
val event = try { val event = try {
room.reportingService().reportContent(action.eventId, -100, action.reason) room.reportingService().reportContent(action.eventId, -100, action.reason)
RoomDetailViewEvents.ActionSuccess(action) RoomDetailViewEvents.ActionSuccess(action)
} catch (failure: Exception) { } catch (failure: Throwable) {
RoomDetailViewEvents.ActionFailure(action, failure) RoomDetailViewEvents.ActionFailure(action, failure)
} }
_viewEvents.post(event) _viewEvents.post(event)

View File

@ -271,7 +271,7 @@ class RoomListViewModel @AssistedInject constructor(
viewModelScope.launch { viewModelScope.launch {
try { try {
room.roomPushRuleService().setRoomNotificationState(action.notificationState) room.roomPushRuleService().setRoomNotificationState(action.notificationState)
} catch (failure: Exception) { } catch (failure: Throwable) {
_viewEvents.post(RoomListViewEvents.Failure(failure)) _viewEvents.post(RoomListViewEvents.Failure(failure))
} }
} }

View File

@ -289,7 +289,7 @@ class HomeRoomListViewModel @AssistedInject constructor(
viewModelScope.launch { viewModelScope.launch {
try { try {
room.roomPushRuleService().setRoomNotificationState(action.notificationState) room.roomPushRuleService().setRoomNotificationState(action.notificationState)
} catch (failure: Exception) { } catch (failure: Throwable) {
_viewEvents.post(HomeRoomListViewEvents.Failure(failure)) _viewEvents.post(HomeRoomListViewEvents.Failure(failure))
} }
} }