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

Commit 310ddbb7 authored by Varun Anand's avatar Varun Anand
Browse files

Fix the availability of UseOpenWifiPreferenceController.

Right now, it crashes if mEnableUseWifiComponentName is disabled by the
open wifi app.

Bug: 150773571
Test: manual - along with ag/10741759, verified that disabling
mEnableUseWifiComponentName hides the toggle instead of causing crash.
Test: make RunSettingsRoboTests ROBOTEST_FILTER=UseOpenWifiPreferenceControllerTest

Change-Id: I47e36fab411e4e4d1a23b7c91504139f124222e1
parent 6c9cad2c
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -100,6 +100,10 @@ public class UseOpenWifiPreferenceController extends TogglePreferenceController

    @Override
    public int getAvailabilityStatus() {
        // It is possible that mEnableUseWifiComponentName is no longer enabled by
        // USE_OPEN_WIFI_PACKAGE. So update this component to reflect correct availability.
        updateEnableUseWifiComponentName();
        checkForFeatureSupportedScorers();
        return mDoFeatureSupportedScorersExist ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
    }

+13 −1
Original line number Diff line number Diff line
@@ -39,7 +39,6 @@ import android.net.NetworkScorerAppData;
import android.provider.Settings;

import androidx.fragment.app.Fragment;
import androidx.preference.Preference;
import androidx.preference.SwitchPreference;

import com.android.settings.R;
@@ -143,6 +142,19 @@ public class UseOpenWifiPreferenceControllerTest {
        assertThat(mController.isAvailable()).isTrue();
    }

    @Test
    public void isAvailable_disableUseOpenWifiComponentBetweenCalls_returnsTrueThenReturnsFalse() {
        setupScorers(Lists.newArrayList(sAppData));
        createController();

        assertThat(mController.isAvailable()).isTrue();

        // Update NetworkScorerAppData so that it no longer has openWifiActivity.
        setupScorers(Lists.newArrayList(sAppDataNoActivity));

        assertThat(mController.isAvailable()).isFalse();
    }

    @Test
    public void setChecked_withTrue_enableShouldStartEnableActivity() {
        setupScorers(Lists.newArrayList(sAppData, sAppDataNoActivity));