Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit be6a844a authored by Salvador Martinez's avatar Salvador Martinez
Browse files

Check if boxes still available when restoring state

Apparently when the device is idle long enough the system will clean
up the dialog view for the hotspot band preference. This will cause
restore state to fail once it decides to pause the activity. To avoid
this we should make sure the boxes are not null.

Test: robotest
Bug: 78445411
Change-Id: I2a82b01f894f62be6c5209c78faddc4089aa6301
parent ac951a69
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -118,8 +118,8 @@ public class HotspotApBandSelectionPreference extends CustomDialogPreference imp

        SavedState myState = new SavedState(superState);
        myState.shouldRestore = getDialog() != null;
        myState.enabled2G = mBox2G.isChecked();
        myState.enabled5G = mBox5G.isChecked();
        myState.enabled2G = mBox2G != null && mBox2G.isChecked();
        myState.enabled5G = mBox5G != null && mBox5G.isChecked();
        return myState;
    }

+15 −0
Original line number Diff line number Diff line
@@ -115,6 +115,21 @@ public class HotspotApBandSelectionPreferenceTest {
        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
    public void onSaveInstanceState_presentWhenDialogPresent() {
        mPreference.setExistingConfigValue(WifiConfiguration.AP_BAND_2GHZ);