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

Commit 67f95bfd authored by Weng Su's avatar Weng Su
Browse files

Revert "Modify the privacy controller to be selectable in the next updateState()"

This reverts commit f7114991.

Reason for revert: Some unexpected code mixed in this CL.

Change-Id: I43574314554a9c62559f529e45f69c29ba6b5a77
parent f7114991
Loading
Loading
Loading
Loading
+0 −5
Original line number Diff line number Diff line
@@ -255,11 +255,6 @@ public class WifiNetworkDetailsFragment2 extends DashboardFragment implements
     * API call for refreshing the preferences in this fragment.
     */
    public void refreshPreferences() {
        updatePreferenceStates();
        displayPreferenceControllers();
    }

    protected void displayPreferenceControllers() {
        final PreferenceScreen screen = getPreferenceScreen();
        for (AbstractPreferenceController controller : mControllers) {
            // WifiDetailPreferenceController2 gets the callback WifiEntryCallback#onUpdated,
+5 −5
Original line number Diff line number Diff line
@@ -69,12 +69,12 @@ public class WifiPrivacyPreferenceController2 extends BasePreferenceController i
    public void updateState(Preference preference) {
        final DropDownPreference dropDownPreference = (DropDownPreference) preference;
        final int randomizationLevel = getRandomizationValue();
        final boolean isSelectable = mWifiEntry.canSetPrivacy();
        preference.setSelectable(isSelectable);
        dropDownPreference.setValue(Integer.toString(randomizationLevel));
        if (isSelectable) {
        updateSummary(dropDownPreference, randomizationLevel);
        } else {

        // Makes preference not selectable, when this is a ephemeral network.
        if (!mWifiEntry.canSetPrivacy()) {
            preference.setSelectable(false);
            dropDownPreference.setSummary(R.string.wifi_privacy_settings_ephemeral_summary);
        }
    }
+0 −42
Original line number Diff line number Diff line
@@ -73,46 +73,4 @@ public class WifiNetworkDetailsFragment2Test {

        verify(menuItem).setIcon(com.android.internal.R.drawable.ic_mode_edit);
    }

    @Test
    public void refreshPreferences_shouldUpdatePreferenceStates() {
        final FakeWifiNetworkDetailsFragment2 fakeFragment = new FakeWifiNetworkDetailsFragment2();

        fakeFragment.refreshPreferences();

        assertThat(fakeFragment.isUpdatePreferenceStatesCalled()).isTrue();
    }

    @Test
    public void refreshPreferences_shouldDisplayPreferenceControllers() {
        final FakeWifiNetworkDetailsFragment2 fakeFragment = new FakeWifiNetworkDetailsFragment2();

        fakeFragment.refreshPreferences();

        assertThat(fakeFragment.isDisplayPreferenceControllersCalled()).isTrue();
    }

    // Fake WifiNetworkDetailsFragment2 to verify the protected functions
    public class FakeWifiNetworkDetailsFragment2 extends WifiNetworkDetailsFragment2 {

        private boolean mUpdatePreferenceStatesCalled;
        private boolean mDisplayPreferenceControllersCalled;

        @Override
        protected void updatePreferenceStates() {
            mUpdatePreferenceStatesCalled = true;
        }

        @Override
        protected void displayPreferenceControllers() {
            mDisplayPreferenceControllersCalled = true;
        }

        public boolean isUpdatePreferenceStatesCalled() {
            return mUpdatePreferenceStatesCalled;
        }
        public boolean isDisplayPreferenceControllersCalled() {
            return mDisplayPreferenceControllersCalled;
        }
    }
}
+0 −34
Original line number Diff line number Diff line
@@ -105,38 +105,4 @@ public class WifiPrivacyPreferenceController2Test {

        assertThat(mDropDownPreference.isSelectable()).isFalse();
    }

    @Test
    public void testUpdateState_canSetPrivacyInNextUpdate_shouldBeSelectable() {
        // Return false in WifiEntry#canSetPrivacy to make preference un-selectable first.
        when(mMockWifiEntry.canSetPrivacy()).thenReturn(false);

        mPreferenceController.updateState(mDropDownPreference);

        assertThat(mDropDownPreference.isSelectable()).isFalse();

        // Return true in WifiEntry#canSetPrivacy to verify preference back to selectable.
        when(mMockWifiEntry.canSetPrivacy()).thenReturn(true);

        mPreferenceController.updateState(mDropDownPreference);

        assertThat(mDropDownPreference.isSelectable()).isTrue();
    }

    @Test
    public void testUpdateState_canNotSetPrivacyInNextUpdate_shouldNotSelectable() {
        // Return true in WifiEntry#canSetPrivacy to make preference selectable first.
        when(mMockWifiEntry.canSetPrivacy()).thenReturn(true);

        mPreferenceController.updateState(mDropDownPreference);

        assertThat(mDropDownPreference.isSelectable()).isTrue();

        // Return false in WifiEntry#canSetPrivacy to verify preference back to un-selectable.
        when(mMockWifiEntry.canSetPrivacy()).thenReturn(false);

        mPreferenceController.updateState(mDropDownPreference);

        assertThat(mDropDownPreference.isSelectable()).isFalse();
    }
}