diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2023-04-03 19:37:51 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2023-04-03 19:37:51 +0200 |
commit | 82c63930e1d9cb79a3dde6cd2a1065e475df2814 (patch) | |
tree | 4dc96bc903f1a7e89c667475e9aefad47be2d197 /ui/src/main | |
parent | 377c2165d331fefc50195a9271356808f6a80b0f (diff) |
ui: do not crash if tunnel preparation fails
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'ui/src/main')
-rw-r--r-- | ui/src/main/java/com/wireguard/android/fragment/BaseFragment.kt | 20 | ||||
-rw-r--r-- | ui/src/main/res/values/strings.xml | 1 |
2 files changed, 15 insertions, 6 deletions
diff --git a/ui/src/main/java/com/wireguard/android/fragment/BaseFragment.kt b/ui/src/main/java/com/wireguard/android/fragment/BaseFragment.kt index 569a6217..b70d53be 100644 --- a/ui/src/main/java/com/wireguard/android/fragment/BaseFragment.kt +++ b/ui/src/main/java/com/wireguard/android/fragment/BaseFragment.kt @@ -67,12 +67,20 @@ abstract class BaseFragment : Fragment(), OnSelectedTunnelChangedListener { val activity = activity ?: return activity.lifecycleScope.launch { if (Application.getBackend() is GoBackend) { - val intent = GoBackend.VpnService.prepare(activity) - if (intent != null) { - pendingTunnel = tunnel - pendingTunnelUp = checked - permissionActivityResultLauncher.launch(intent) - return@launch + try { + val intent = GoBackend.VpnService.prepare(activity) + if (intent != null) { + pendingTunnel = tunnel + pendingTunnelUp = checked + permissionActivityResultLauncher.launch(intent) + return@launch + } + } catch (e: Throwable) { + val message = activity.getString(R.string.error_prepare, ErrorMessages[e]) + Snackbar.make(view, message, Snackbar.LENGTH_LONG) + .setAnchorView(view.findViewById(R.id.create_fab)) + .show() + Log.e(TAG, message, e) } } setTunnelStateWithPermissionsResult(tunnel, checked) diff --git a/ui/src/main/res/values/strings.xml b/ui/src/main/res/values/strings.xml index 4952db51..bc85bdbf 100644 --- a/ui/src/main/res/values/strings.xml +++ b/ui/src/main/res/values/strings.xml @@ -120,6 +120,7 @@ <string name="error_down">Error bringing down tunnel: %s</string> <string name="error_fetching_apps">Error fetching apps list: %s</string> <string name="error_root">Please obtain root access and try again</string> + <string name="error_prepare">Error preparing tunnel: %s</string> <string name="error_up">Error bringing up tunnel: %s</string> <string name="exclude_private_ips">Exclude private IPs</string> <string name="generate_new_private_key">Generate new private key</string> |