Adjust UX for toggles when active scorer is not set.
This change fixes two issues: when wakeup is not available, update the number of items to show above the fold in wifi preferences. When scorer is not set, grey out wakeup toggle and set summary to reflect the status. Bug: 62410973 Bug: 62343859 Test: make RunSettingsRoboTests -j40 Change-Id: I5f4131c6a86eab6c0fb03ea2b5101ba107a9189f
This commit is contained in:
@@ -23,6 +23,7 @@ import static android.provider.Settings.Global.WIFI_WAKEUP_ENABLED;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.provider.Settings;
|
||||
@@ -30,6 +31,7 @@ import android.support.v14.preference.SwitchPreference;
|
||||
import android.support.v7.preference.Preference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.network.NetworkScoreManagerWrapper;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
||||
@@ -39,6 +41,7 @@ import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
@@ -50,17 +53,23 @@ import org.robolectric.annotation.Config;
|
||||
shadows = { SettingsShadowResources.class })
|
||||
public class WifiWakeupPreferenceControllerTest {
|
||||
|
||||
private static final String TEST_SCORER_PACKAGE_NAME = "Test Scorer";
|
||||
|
||||
private Context mContext;
|
||||
@Mock
|
||||
private NetworkScoreManagerWrapper mNetworkScorer;
|
||||
private WifiWakeupPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mController = new WifiWakeupPreferenceController(mContext, mock(Lifecycle.class));
|
||||
mController = new WifiWakeupPreferenceController(
|
||||
mContext, mock(Lifecycle.class), mNetworkScorer);
|
||||
Settings.System.putInt(mContext.getContentResolver(), WIFI_SCAN_ALWAYS_AVAILABLE, 1);
|
||||
SettingsShadowResources.overrideResource(
|
||||
com.android.internal.R.integer.config_wifi_wakeup_available, 0);
|
||||
when(mNetworkScorer.getActiveScorerPackage()).thenReturn(TEST_SCORER_PACKAGE_NAME);
|
||||
}
|
||||
|
||||
@After
|
||||
@@ -145,4 +154,18 @@ public class WifiWakeupPreferenceControllerTest {
|
||||
verify(preference).setEnabled(false);
|
||||
verify(preference).setSummary(R.string.wifi_wakeup_summary_scanning_disabled);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_preferenceSetUncheckedAndSetDisabledWhenScoringDisabled() {
|
||||
final SwitchPreference preference = mock(SwitchPreference.class);
|
||||
Settings.System.putInt(mContext.getContentResolver(), NETWORK_RECOMMENDATIONS_ENABLED, 1);
|
||||
Settings.System.putInt(mContext.getContentResolver(), WIFI_WAKEUP_ENABLED, 1);
|
||||
when(mNetworkScorer.getActiveScorerPackage()).thenReturn(null);
|
||||
|
||||
mController.updateState(preference);
|
||||
|
||||
verify(preference).setChecked(true);
|
||||
verify(preference).setEnabled(false);
|
||||
verify(preference).setSummary(R.string.wifi_wakeup_summary_scoring_disabled);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user