diff --git a/android/app/src/main/kotlin/deckers/thibault/aves/MainActivity.kt b/android/app/src/main/kotlin/deckers/thibault/aves/MainActivity.kt index 0bf7591ee..aa65da1c0 100644 --- a/android/app/src/main/kotlin/deckers/thibault/aves/MainActivity.kt +++ b/android/app/src/main/kotlin/deckers/thibault/aves/MainActivity.kt @@ -56,6 +56,7 @@ import deckers.thibault.aves.channel.streams.MediaStoreStreamHandler import deckers.thibault.aves.channel.streams.SettingsChangeStreamHandler import deckers.thibault.aves.model.FieldMap import deckers.thibault.aves.utils.LogUtils +import deckers.thibault.aves.utils.anyCauseIs import deckers.thibault.aves.utils.getParcelableExtraCompat import io.flutter.embedding.android.FlutterFragmentActivity import io.flutter.embedding.engine.FlutterEngine @@ -466,6 +467,7 @@ open class MainActivity : FlutterFragmentActivity() { setResult(RESULT_OK, intent) finish() } catch (e: Exception) { + setResult(RESULT_CANCELED) if (e is SecurityException && intent.flags and Intent.FLAG_GRANT_WRITE_URI_PERMISSION != 0) { // in some environments, providing the write flag yields a `SecurityException`: // "UID XXXX does not have permission to content://XXXX" @@ -473,7 +475,7 @@ open class MainActivity : FlutterFragmentActivity() { Log.i(LOG_TAG, "retry submitting picked items without FLAG_GRANT_WRITE_URI_PERMISSION") intent.flags = intent.flags and Intent.FLAG_GRANT_WRITE_URI_PERMISSION.inv() submitPickedItemsIntent(intent, result) - } else if (e is TransactionTooLargeException || e.cause is TransactionTooLargeException) { + } else if (e.anyCauseIs()) { result.error("submitPickedItems-large", "transaction too large with ${intent.clipData?.itemCount} URIs", e) } else { result.error("submitPickedItems-exception", "failed to pick ${intent.clipData?.itemCount} URIs", e) diff --git a/android/app/src/main/kotlin/deckers/thibault/aves/channel/calls/AppAdapterHandler.kt b/android/app/src/main/kotlin/deckers/thibault/aves/channel/calls/AppAdapterHandler.kt index c29b8718f..7825e084f 100644 --- a/android/app/src/main/kotlin/deckers/thibault/aves/channel/calls/AppAdapterHandler.kt +++ b/android/app/src/main/kotlin/deckers/thibault/aves/channel/calls/AppAdapterHandler.kt @@ -39,6 +39,7 @@ import deckers.thibault.aves.model.FieldMap import deckers.thibault.aves.utils.BitmapUtils import deckers.thibault.aves.utils.BitmapUtils.getBytes import deckers.thibault.aves.utils.LogUtils +import deckers.thibault.aves.utils.anyCauseIs import deckers.thibault.aves.utils.getApplicationInfoCompat import deckers.thibault.aves.utils.queryIntentActivitiesCompat import io.flutter.plugin.common.MethodCall @@ -307,7 +308,7 @@ class AppAdapterHandler(private val context: Context) : MethodCallHandler { val started = safeStartActivityChooser(title, intent) result.success(started) } catch (e: Exception) { - if (e is TransactionTooLargeException || e.cause is TransactionTooLargeException) { + if (e.anyCauseIs()) { result.error("share-large", "transaction too large with ${uriList.size} URIs", e) } else { result.error("share-exception", "failed to share ${uriList.size} URIs", e) diff --git a/android/app/src/main/kotlin/deckers/thibault/aves/utils/ExceptionUtils.kt b/android/app/src/main/kotlin/deckers/thibault/aves/utils/ExceptionUtils.kt new file mode 100644 index 000000000..f164c9760 --- /dev/null +++ b/android/app/src/main/kotlin/deckers/thibault/aves/utils/ExceptionUtils.kt @@ -0,0 +1,10 @@ +package deckers.thibault.aves.utils + +inline fun Exception.anyCauseIs(): Boolean { + var cause: Throwable? = this + while (cause != null) { + if (cause is T) return true + cause = cause.cause + } + return false +}