瀏覽代碼

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 {
         lifecycleScope.launch {
             ensureEuiccChannelManager()
             ensureEuiccChannelManager()
             euiccChannelManagerService.waitForForegroundTask()
             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, "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()
         }.last()
 
 
-        (res as? EuiccChannelManagerService.ForegroundTaskState.Done)?.error?.let { throw it }
+        res as? EuiccChannelManagerService.ForegroundTaskState.Done
     }
     }
 
 
     override fun onDismiss(dialog: DialogInterface) {
     override fun onDismiss(dialog: DialogInterface) {