From: Tobias Brunner Date: Fri, 22 Jun 2018 09:22:23 +0000 (+0200) Subject: android: Properly handle pressing home when VPN confirmation dialog is shown X-Git-Tag: 5.7.0dr5~20^2~9 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4db3bf0cb091965a3fd7a56025e6d2820a01c276;p=thirdparty%2Fstrongswan.git 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. --- 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 09553bdff4..a9d0791bf7 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;