summaryrefslogtreecommitdiffhomepage
path: root/ui/src/main/java/com/wireguard/android
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2023-04-03 19:37:51 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2023-04-04 15:31:52 +0200
commit9fa8ca8c77e0e9bec9818ee5e9505e821428e31e (patch)
tree8de142daf25b5bac5a100f226d0009ca2cc05ba1 /ui/src/main/java/com/wireguard/android
parent59da677c23aaed68c9a761ad4c7822ef27571f4a (diff)
ui: do not crash if tunnel preparation fails
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'ui/src/main/java/com/wireguard/android')
-rw-r--r--ui/src/main/java/com/wireguard/android/fragment/BaseFragment.kt20
1 files changed, 14 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)