From 80337f4f9d3d189b05b171db7f1d57a08cbfc7fa Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Mon, 19 Oct 2020 17:41:52 +0200 Subject: [PATCH] android: Prevent illegalStateException when showing power whitelist dialog 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()). --- .../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 c32c359620..5174cafb07 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 @@ -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;