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
This commit is contained in:
Varun Anand
2020-03-17 15:53:15 -07:00
parent 6c9cad2caf
commit 310ddbb79f
2 changed files with 17 additions and 1 deletions

View File

@@ -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;
}

View File

@@ -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));