Catima Import / Export: Move to background thread (ProgressDialog is deprecated, flow is buggy, crashes importing some online files)
The ProgressDialog with has been deprecated.
The Recommendation hint seems to be to use a Notification (can also show progress) and move the cancel option there.
That would also mean most imports go through cleanly without being ended by users, probably leaving cleaner Databases.
I think for the first version using indeterminate progress in the notification is fine :)
I've started working on this in #622, but it doesn't quite work as I'd like it yet.
The current flow can also crash, for example when importing a large file from NextCloud, because Android punishes doing network on the main thread by throwing a NetworkOnMainThreadException:
FATAL EXCEPTION: main
Process: me.hackerchick.catima.debug, PID: 31923
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=793836462, result=-1, data=Intent { dat=content://org.nextcloud.documents/... fl
g=0x1 }} to activity {me.hackerchick.catima.debug/protect.card_locker.ImportExportActivity}: android.os.NetworkOnMainThreadException
at android.app.ActivityThread.deliverResults(ActivityThread.java:5335)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:5374)
at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:67)
at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:45)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:138)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2303)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7884)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
Caused by: android.os.NetworkOnMainThreadException
at android.os.Parcel.createExceptionOrNull(Parcel.java:3021)
at android.os.Parcel.createException(Parcel.java:2995)
at android.os.Parcel.readException(Parcel.java:2978)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:190)
at android.database.DatabaseUtils.readExceptionWithFileNotFoundExceptionFromParcel(DatabaseUtils.java:153)
at android.content.ContentProviderProxy.openTypedAssetFile(ContentProviderNative.java:780)
at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:2027)
at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:1842)
at android.content.ContentResolver.openInputStream(ContentResolver.java:1518)
at protect.card_locker.ImportExportActivity.openFileForImport(ImportExportActivity.java:165)
at protect.card_locker.ImportExportActivity.lambda$onCreate$1$protect-card_locker-ImportExportActivity(ImportExportActivity.java:101)
at protect.card_locker.ImportExportActivity$$ExternalSyntheticLambda7.onActivityResult(Unknown Source:4)
at androidx.activity.result.ActivityResultRegistry.doDispatch(ActivityResultRegistry.java:418)
at androidx.activity.result.ActivityResultRegistry.dispatchResult(ActivityResultRegistry.java:375)
at androidx.activity.ComponentActivity.onActivityResult(ComponentActivity.java:793)
at androidx.fragment.app.FragmentActivity.onActivityResult(FragmentActivity.java:164)
at android.app.Activity.dispatchActivityResult(Activity.java:8664)
at android.app.ActivityThread.deliverResults(ActivityThread.java:5328)
... 13 more
Note: This only happens with bigger files, my example 544 byte import does not trigger this, but my 1.4MB of real data does. Clearly, Android has set a time limit on doing network on the main thread and the 1.4MB import hits the time limit.
Due to #2407 I'm bumping this severity to critical.