From 4db3bf0cb091965a3fd7a56025e6d2820a01c276 Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Fri, 22 Jun 2018 11:22:23 +0200 Subject: [PATCH] android: Properly handle pressing home when VPN confirmation dialog is shown As documented, onActivityResult() is called right before onResume() when the activity is reactivated. However, if the system's VPN confirmation dialog is shown and the home button is pressed, the activity is stopped and not just paused, so its state is saved. And onActivityResult() is actually also called before onStart(). This means that no fragment transactions may be committed (i.e. no dialog may be shown) when the activity is later restarted (e.g. because there is another attempt to connect the VPN) until onStart() has been called. So if we'd try to show the error dialog in onActivityResult() after returning to the launcher it would result in an IllegalStateException. However, showing the dialog for the previous confirmation dialog is not ideal anyway, so we just ignore that result. --- .../strongswan/android/ui/VpnProfileControlActivity.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/frontends/android/app/src/main/java/org/strongswan/android/ui/VpnProfileControlActivity.java b/src/frontends/android/app/src/main/java/org/strongswan/android/ui/VpnProfileControlActivity.java index 09553bdff..a9d0791bf 100644 --- a/src/frontends/android/app/src/main/java/org/strongswan/android/ui/VpnProfileControlActivity.java +++ b/src/frontends/android/app/src/main/java/org/strongswan/android/ui/VpnProfileControlActivity.java @@ -183,6 +183,12 @@ public class VpnProfileControlActivity extends AppCompatActivity } else { /* this happens if the always-on VPN feature is activated by a different app or the user declined */ + if (getSupportFragmentManager().isStateSaved()) + { /* onActivityResult() might be called when we aren't active anymore e.g. if the + * user pressed the home button, if the activity is started again we land here + * before onNewIntent() is called */ + return; + } VpnNotSupportedError.showWithMessage(this, R.string.vpn_not_supported_no_permission); } break;