Merge "Check if boxes still available when restoring state" into pi-dev

am: 6fcce25b72

Change-Id: Ia85fbd3b5068f739254fae45403fdf2f4b45f595
This commit is contained in:
Salvador Martinez
2018-04-24 19:08:51 -07:00
committed by android-build-merger
2 changed files with 17 additions and 2 deletions

View File

@@ -118,8 +118,8 @@ public class HotspotApBandSelectionPreference extends CustomDialogPreference imp
SavedState myState = new SavedState(superState); SavedState myState = new SavedState(superState);
myState.shouldRestore = getDialog() != null; myState.shouldRestore = getDialog() != null;
myState.enabled2G = mBox2G.isChecked(); myState.enabled2G = mBox2G != null && mBox2G.isChecked();
myState.enabled5G = mBox5G.isChecked(); myState.enabled5G = mBox5G != null && mBox5G.isChecked();
return myState; return myState;
} }

View File

@@ -115,6 +115,21 @@ public class HotspotApBandSelectionPreferenceTest {
assertThat(mPreference.mShouldRestore).isFalse(); assertThat(mPreference.mShouldRestore).isFalse();
} }
@Test
public void onSaveInstanceState_doesNotCrashWhenViewGone() {
mPreference.setExistingConfigValue(WifiConfiguration.AP_BAND_2GHZ);
mPreference.onBindDialogView(mLayout);
// When the device dozes the view and dialog can become null
mPreference.mBox5G = null;
mPreference.mBox2G = null;
ReflectionHelpers.setField(mPreference, "mFragment", null);
// make sure it does not crash and state is not restored
Parcelable parcelable = mPreference.onSaveInstanceState();
mPreference.onRestoreInstanceState(parcelable);
assertThat(mPreference.mShouldRestore).isFalse();
}
@Test @Test
public void onSaveInstanceState_presentWhenDialogPresent() { public void onSaveInstanceState_presentWhenDialogPresent() {
mPreference.setExistingConfigValue(WifiConfiguration.AP_BAND_2GHZ); mPreference.setExistingConfigValue(WifiConfiguration.AP_BAND_2GHZ);