android: Handle restarts of control activity with power whitelist dialog better

With the flag set, we basically ignore the resent intent, which is not
ideal if we have not yet actually started another activity.  The information
dialog we show first would disappear when closing and reopening the app
or even just rotating it (we hide all dialogs when receiving an intent),
but since the flag was restored, the dialog was not shown again even
when attempting to start other connections.
This commit is contained in:
Tobias Brunner 2020-10-19 16:46:22 +02:00
parent 21476a8d91
commit 264435f626
1 changed files with 4 additions and 3 deletions

View File

@ -206,7 +206,6 @@ public class VpnProfileControlActivity extends AppCompatActivity
!pref.getBoolean(Constants.PREF_IGNORE_POWER_WHITELIST, false))
{
PowerWhitelistRequired whitelist = new PowerWhitelistRequired();
mWaitingForResult = true;
whitelist.show(getSupportFragmentManager(), DIALOG_TAG);
return false;
}
@ -588,9 +587,11 @@ public class VpnProfileControlActivity extends AppCompatActivity
.setTitle(R.string.power_whitelist_title)
.setMessage(R.string.power_whitelist_text)
.setPositiveButton(android.R.string.ok, (dialog, id) -> {
VpnProfileControlActivity activity = (VpnProfileControlActivity)getActivity();
activity.mWaitingForResult = true;
Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS,
Uri.parse("package:" + getActivity().getPackageName()));
getActivity().startActivityForResult(intent, ADD_TO_POWER_WHITELIST);
Uri.parse("package:" + activity.getPackageName()));
activity.startActivityForResult(intent, ADD_TO_POWER_WHITELIST);
}).create();
}