]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
android: Prevent illegalStateException when showing power whitelist dialog
authorTobias Brunner <tobias@strongswan.org>
Mon, 19 Oct 2020 15:41:52 +0000 (17:41 +0200)
committerTobias Brunner <tobias@strongswan.org>
Thu, 29 Oct 2020 09:22:52 +0000 (10:22 +0100)
If the activity is not active when the service connection is
established and handleIntent() is called, the activity's state is already
saved and any fragment transaction would result in an illegalStateException
due to state loss.  We just ignore this and wait for another initiation
attempt (via onNewIntent()).

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

index c32c3596204b0bc00db16a7c1abb920d26764a22..5174cafb07500db4c8d80ca5ee45b5c82af99c0f 100644 (file)
@@ -205,6 +205,12 @@ public class VpnProfileControlActivity extends AppCompatActivity
                        if (!pm.isIgnoringBatteryOptimizations(this.getPackageName()) &&
                                !pref.getBoolean(Constants.PREF_IGNORE_POWER_WHITELIST, false))
                        {
+                               if (getSupportFragmentManager().isStateSaved())
+                               {       /* we might get called via service connection and manual onActivityResult()
+                                        * call when the activity is not active anymore and fragment transactions
+                                        * would cause an illegalStateException */
+                                       return false;
+                               }
                                PowerWhitelistRequired whitelist = new PowerWhitelistRequired();
                                whitelist.show(getSupportFragmentManager(), DIALOG_TAG);
                                return false;