浏览代码

ProfileDownloadFragment: Stop catching all exceptions

..instead, use the error value returned in the foreground task result.

Catching all exceptions will result in cancellation being ignored when
the fragment is destroyed.
Peter Cai 1 年之前
父节点
当前提交
7197501cca
共有 1 个文件被更改,包括 14 次插入10 次删除
  1. 14 10
      app-common/src/main/java/im/angry/openeuicc/ui/ProfileDownloadFragment.kt

+ 14 - 10
app-common/src/main/java/im/angry/openeuicc/ui/ProfileDownloadFragment.kt

@@ -215,18 +215,22 @@ class ProfileDownloadFragment : BaseMaterialDialogFragment(),
         lifecycleScope.launch {
             ensureEuiccChannelManager()
             euiccChannelManagerService.waitForForegroundTask()
-            try {
-                doDownloadProfile(server, code, confirmationCode, imei)
-            } catch (e: Exception) {
+            val res = doDownloadProfile(server, code, confirmationCode, imei)
+
+            if (res == null || res.error != null) {
                 Log.d(TAG, "Error downloading profile")
-                Log.d(TAG, Log.getStackTraceString(e))
-                Toast.makeText(context, R.string.profile_download_failed, Toast.LENGTH_LONG).show()
-            } finally {
-                if (parentFragment is EuiccProfilesChangedListener) {
-                    (parentFragment as EuiccProfilesChangedListener).onEuiccProfilesChanged()
+
+                if (res?.error != null) {
+                    Log.d(TAG, Log.getStackTraceString(res.error))
                 }
-                dismiss()
+
+                Toast.makeText(requireContext(), R.string.profile_download_failed, Toast.LENGTH_LONG).show()
+            }
+
+            if (parentFragment is EuiccProfilesChangedListener) {
+                (parentFragment as EuiccProfilesChangedListener).onEuiccProfilesChanged()
             }
+            dismiss()
         }
     }
 
@@ -254,7 +258,7 @@ class ProfileDownloadFragment : BaseMaterialDialogFragment(),
             }
         }.last()
 
-        (res as? EuiccChannelManagerService.ForegroundTaskState.Done)?.error?.let { throw it }
+        res as? EuiccChannelManagerService.ForegroundTaskState.Done
     }
 
     override fun onDismiss(dialog: DialogInterface) {