Skip to content

Commit 0950e41

Browse files
authored
Merge pull request #6967 from vector-im/feature/bma/fix_crashes
Fix crashes
2 parents 7a79032 + b18395f commit 0950e41

File tree

7 files changed

+27
-9
lines changed

7 files changed

+27
-9
lines changed

changelog.d/6967.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix low occurrence crashes.

vector/src/main/java/im/vector/app/core/error/ErrorFormatter.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package im.vector.app.core.error
1818

19+
import android.content.ActivityNotFoundException
1920
import im.vector.app.R
2021
import im.vector.app.core.resources.StringProvider
2122
import im.vector.app.features.call.dialpad.DialPadLookup
@@ -134,6 +135,8 @@ class DefaultErrorFormatter @Inject constructor(
134135
is MatrixIdFailure.InvalidMatrixId ->
135136
stringProvider.getString(R.string.login_signin_matrix_id_error_invalid_matrix_id)
136137
is VoiceFailure -> voiceMessageError(throwable)
138+
is ActivityNotFoundException ->
139+
stringProvider.getString(R.string.error_no_external_application_found)
137140
else -> throwable.localizedMessage
138141
}
139142
?: stringProvider.getString(R.string.unknown_error)

vector/src/main/java/im/vector/app/features/attachments/AttachmentsHelper.kt

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package im.vector.app.features.attachments
1717

1818
import android.app.Activity
19+
import android.content.ActivityNotFoundException
1920
import android.content.Context
2021
import android.content.Intent
2122
import android.net.Uri
@@ -44,6 +45,7 @@ class AttachmentsHelper(
4445
interface Callback {
4546
fun onContactAttachmentReady(contactAttachment: ContactAttachment)
4647
fun onContentAttachmentsReady(attachments: List<ContentAttachmentData>)
48+
fun onAttachmentError(throwable: Throwable)
4749
}
4850

4951
// Capture path allows to handle camera image picking. It must be restored if the activity gets killed.
@@ -73,21 +75,21 @@ class AttachmentsHelper(
7375
/**
7476
* Starts the process for handling file picking.
7577
*/
76-
fun selectFile(activityResultLauncher: ActivityResultLauncher<Intent>) {
78+
fun selectFile(activityResultLauncher: ActivityResultLauncher<Intent>) = doSafe {
7779
MultiPicker.get(MultiPicker.FILE).startWith(activityResultLauncher)
7880
}
7981

8082
/**
8183
* Starts the process for handling image/video picking.
8284
*/
83-
fun selectGallery(activityResultLauncher: ActivityResultLauncher<Intent>) {
85+
fun selectGallery(activityResultLauncher: ActivityResultLauncher<Intent>) = doSafe {
8486
MultiPicker.get(MultiPicker.MEDIA).startWith(activityResultLauncher)
8587
}
8688

8789
/**
8890
* Starts the process for handling audio picking.
8991
*/
90-
fun selectAudio(activityResultLauncher: ActivityResultLauncher<Intent>) {
92+
fun selectAudio(activityResultLauncher: ActivityResultLauncher<Intent>) = doSafe {
9193
MultiPicker.get(MultiPicker.AUDIO).startWith(activityResultLauncher)
9294
}
9395

@@ -101,11 +103,11 @@ class AttachmentsHelper(
101103
cameraVideoActivityResultLauncher: ActivityResultLauncher<Intent>
102104
) {
103105
PhotoOrVideoDialog(activity, vectorPreferences).show(object : PhotoOrVideoDialog.PhotoOrVideoDialogListener {
104-
override fun takePhoto() {
106+
override fun takePhoto() = doSafe {
105107
captureUri = MultiPicker.get(MultiPicker.CAMERA).startWithExpectingFile(context, cameraActivityResultLauncher)
106108
}
107109

108-
override fun takeVideo() {
110+
override fun takeVideo() = doSafe {
109111
captureUri = MultiPicker.get(MultiPicker.CAMERA_VIDEO).startWithExpectingFile(context, cameraVideoActivityResultLauncher)
110112
}
111113
})
@@ -114,10 +116,18 @@ class AttachmentsHelper(
114116
/**
115117
* Starts the process for handling contact picking.
116118
*/
117-
fun selectContact(activityResultLauncher: ActivityResultLauncher<Intent>) {
119+
fun selectContact(activityResultLauncher: ActivityResultLauncher<Intent>) = doSafe {
118120
MultiPicker.get(MultiPicker.CONTACT).startWith(activityResultLauncher)
119121
}
120122

123+
private fun doSafe(function: () -> Unit) {
124+
try {
125+
function()
126+
} catch (activityNotFound: ActivityNotFoundException) {
127+
callback.onAttachmentError(activityNotFound)
128+
}
129+
}
130+
121131
/**
122132
* This methods aims to handle the result data.
123133
*/

vector/src/main/java/im/vector/app/features/home/room/detail/TimelineFragment.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2658,6 +2658,10 @@ class TimelineFragment :
26582658
messageComposerViewModel.handle(MessageComposerAction.SendMessage(formattedContact, false))
26592659
}
26602660

2661+
override fun onAttachmentError(throwable: Throwable) {
2662+
showFailure(throwable)
2663+
}
2664+
26612665
private fun onViewWidgetsClicked() {
26622666
RoomWidgetsBottomSheet.newInstance()
26632667
.show(childFragmentManager, "ROOM_WIDGETS_BOTTOM_SHEET")

vector/src/main/java/im/vector/app/features/home/room/detail/TimelineViewModel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1046,7 +1046,7 @@ class TimelineViewModel @AssistedInject constructor(
10461046
val event = try {
10471047
room.reportingService().reportContent(action.eventId, -100, action.reason)
10481048
RoomDetailViewEvents.ActionSuccess(action)
1049-
} catch (failure: Exception) {
1049+
} catch (failure: Throwable) {
10501050
RoomDetailViewEvents.ActionFailure(action, failure)
10511051
}
10521052
_viewEvents.post(event)

vector/src/main/java/im/vector/app/features/home/room/list/RoomListViewModel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ class RoomListViewModel @AssistedInject constructor(
271271
viewModelScope.launch {
272272
try {
273273
room.roomPushRuleService().setRoomNotificationState(action.notificationState)
274-
} catch (failure: Exception) {
274+
} catch (failure: Throwable) {
275275
_viewEvents.post(RoomListViewEvents.Failure(failure))
276276
}
277277
}

vector/src/main/java/im/vector/app/features/home/room/list/home/HomeRoomListViewModel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ class HomeRoomListViewModel @AssistedInject constructor(
289289
viewModelScope.launch {
290290
try {
291291
room.roomPushRuleService().setRoomNotificationState(action.notificationState)
292-
} catch (failure: Exception) {
292+
} catch (failure: Throwable) {
293293
_viewEvents.post(HomeRoomListViewEvents.Failure(failure))
294294
}
295295
}

0 commit comments

Comments
 (0)