Skip to content

Commit bb5a516

Browse files
committed
ui: do not crash if tunnel preparation fails
Signed-off-by: Jason A. Donenfeld <[email protected]>
1 parent 1f84341 commit bb5a516

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

ui/src/main/java/com/wireguard/android/fragment/BaseFragment.kt

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,20 @@ abstract class BaseFragment : Fragment(), OnSelectedTunnelChangedListener {
6767
val activity = activity ?: return
6868
activity.lifecycleScope.launch {
6969
if (Application.getBackend() is GoBackend) {
70-
val intent = GoBackend.VpnService.prepare(activity)
71-
if (intent != null) {
72-
pendingTunnel = tunnel
73-
pendingTunnelUp = checked
74-
permissionActivityResultLauncher.launch(intent)
75-
return@launch
70+
try {
71+
val intent = GoBackend.VpnService.prepare(activity)
72+
if (intent != null) {
73+
pendingTunnel = tunnel
74+
pendingTunnelUp = checked
75+
permissionActivityResultLauncher.launch(intent)
76+
return@launch
77+
}
78+
} catch (e: Throwable) {
79+
val message = activity.getString(R.string.error_prepare, ErrorMessages[e])
80+
Snackbar.make(view, message, Snackbar.LENGTH_LONG)
81+
.setAnchorView(view.findViewById(R.id.create_fab))
82+
.show()
83+
Log.e(TAG, message, e)
7684
}
7785
}
7886
setTunnelStateWithPermissionsResult(tunnel, checked)

ui/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@
120120
<string name="error_down">Error bringing down tunnel: %s</string>
121121
<string name="error_fetching_apps">Error fetching apps list: %s</string>
122122
<string name="error_root">Please obtain root access and try again</string>
123+
<string name="error_prepare">Error preparing tunnel: %s</string>
123124
<string name="error_up">Error bringing up tunnel: %s</string>
124125
<string name="exclude_private_ips">Exclude private IPs</string>
125126
<string name="generate_new_private_key">Generate new private key</string>

0 commit comments

Comments
 (0)