ConfigActivity: Avoid crash when started while locked

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Samuel Holland 2017-08-14 10:44:29 -05:00
parent 5e55d196be
commit d5ede015cf

View File

@ -15,11 +15,12 @@ import com.wireguard.config.Config;
*/ */
public class ConfigActivity extends BaseConfigActivity { public class ConfigActivity extends BaseConfigActivity {
private boolean canAddFragments;
private int containerId; private int containerId;
private final FragmentManager fm = getFragmentManager(); private final FragmentManager fm = getFragmentManager();
private boolean isEditing; private boolean isEditing;
private boolean isServiceAvailable;
private boolean isSplitLayout; private boolean isSplitLayout;
private boolean isStateSaved;
@Override @Override
public void onBackPressed() { public void onBackPressed() {
@ -44,7 +45,7 @@ public class ConfigActivity extends BaseConfigActivity {
@Override @Override
protected void onCurrentConfigChanged(final Config config) { protected void onCurrentConfigChanged(final Config config) {
if (!canAddFragments) if (!isServiceAvailable || isStateSaved)
return; return;
final Fragment currentFragment = fm.findFragmentById(containerId); final Fragment currentFragment = fm.findFragmentById(containerId);
Log.d(getClass().getSimpleName(), "onCurrentConfigChanged config=" + Log.d(getClass().getSimpleName(), "onCurrentConfigChanged config=" +
@ -134,6 +135,13 @@ public class ConfigActivity extends BaseConfigActivity {
} }
} }
@Override
public void onPostResume() {
super.onPostResume();
isStateSaved = false;
onCurrentConfigChanged(getCurrentConfig());
}
@Override @Override
public void onSaveInstanceState(final Bundle outState) { public void onSaveInstanceState(final Bundle outState) {
// We cannot save fragments that might switch between containers if the layout changes. // We cannot save fragments that might switch between containers if the layout changes.
@ -146,13 +154,14 @@ public class ConfigActivity extends BaseConfigActivity {
if (oldFragment != null) if (oldFragment != null)
fm.beginTransaction().remove(oldFragment).commit(); fm.beginTransaction().remove(oldFragment).commit();
} }
isStateSaved = true;
super.onSaveInstanceState(outState); super.onSaveInstanceState(outState);
} }
@Override @Override
protected void onServiceAvailable() { protected void onServiceAvailable() {
// Create the initial fragment set. // Create the initial fragment set.
canAddFragments = true; isServiceAvailable = true;
onCurrentConfigChanged(getCurrentConfig()); onCurrentConfigChanged(getCurrentConfig());
} }
} }