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()).
This commit is contained in:
Tobias Brunner 2020-10-19 17:41:52 +02:00
parent 264435f626
commit 80337f4f9d
1 changed files with 6 additions and 0 deletions

View 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;