]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
android: Properly handle pressing home when VPN confirmation dialog is shown
authorTobias Brunner <tobias@strongswan.org>
Fri, 22 Jun 2018 09:22:23 +0000 (11:22 +0200)
committerTobias Brunner <tobias@strongswan.org>
Tue, 3 Jul 2018 09:31:43 +0000 (11:31 +0200)
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.

src/frontends/android/app/src/main/java/org/strongswan/android/ui/VpnProfileControlActivity.java

index 09553bdff4aac47e9d01a776496fb8ebd60d7eaa..a9d0791bf719086d16b904f2c587e71505bde1eb 100644 (file)
@@ -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;