Merge changes If1b263df,I95afbcf0
* changes:
Move instantiation-through-reflection method to controller
Minor cleanup in DashboardFragment: remove unused code
diff --git a/res/values/bools.xml b/res/values/bools.xml
index f20b93c..4665f2e 100644
--- a/res/values/bools.xml
+++ b/res/values/bools.xml
@@ -150,15 +150,6 @@
<!-- Whether default_home should be shown or not. -->
<bool name="config_show_default_home">true</bool>
- <!-- Whether color correction preference should be shown or not. -->
- <bool name="config_show_color_correction_preference">true</bool>
-
- <!-- Whether color inversion preference should be shown or not. -->
- <bool name="config_show_color_inversion_preference">true</bool>
-
- <!-- Whether accessibility shortcut preference should be shown or not. -->
- <bool name="config_show_accessibility_shortcut_preference">true</bool>
-
<!-- Whether assist_and_voice_input should be shown or not. -->
<bool name="config_show_assist_and_voice_input">true</bool>
diff --git a/src/com/android/settings/accessibility/AccessibilitySettings.java b/src/com/android/settings/accessibility/AccessibilitySettings.java
index bd63225..2292ca2 100644
--- a/src/com/android/settings/accessibility/AccessibilitySettings.java
+++ b/src/com/android/settings/accessibility/AccessibilitySettings.java
@@ -33,7 +33,6 @@
import android.os.Vibrator;
import android.provider.SearchIndexableResource;
import android.provider.Settings;
-import android.support.annotation.VisibleForTesting;
import android.support.v14.preference.SwitchPreference;
import android.support.v4.content.ContextCompat;
import android.support.v7.preference.ListPreference;
@@ -93,6 +92,8 @@
// Preferences
private static final String TOGGLE_HIGH_TEXT_CONTRAST_PREFERENCE =
"toggle_high_text_contrast_preference";
+ private static final String TOGGLE_INVERSION_PREFERENCE =
+ "toggle_inversion_preference";
private static final String TOGGLE_POWER_BUTTON_ENDS_CALL_PREFERENCE =
"toggle_power_button_ends_call_preference";
private static final String TOGGLE_LOCK_SCREEN_ROTATION_PREFERENCE =
@@ -104,6 +105,8 @@
"toggle_master_mono";
private static final String SELECT_LONG_PRESS_TIMEOUT_PREFERENCE =
"select_long_press_timeout_preference";
+ private static final String ACCESSIBILITY_SHORTCUT_PREFERENCE =
+ "accessibility_shortcut_preference";
private static final String CAPTIONING_PREFERENCE_SCREEN =
"captioning_preference_screen";
private static final String DISPLAY_MAGNIFICATION_PREFERENCE_SCREEN =
@@ -116,13 +119,8 @@
"autoclick_preference_screen";
private static final String VIBRATION_PREFERENCE_SCREEN =
"vibration_preference_screen";
-
- @VisibleForTesting static final String TOGGLE_INVERSION_PREFERENCE =
- "toggle_inversion_preference";
- @VisibleForTesting static final String DISPLAY_DALTONIZER_PREFERENCE_SCREEN =
+ private static final String DISPLAY_DALTONIZER_PREFERENCE_SCREEN =
"daltonizer_preference_screen";
- @VisibleForTesting static final String ACCESSIBILITY_SHORTCUT_PREFERENCE =
- "accessibility_shortcut_preference";
// Extras passed to sub-fragments.
static final String EXTRA_PREFERENCE_KEY = "preference_key";
@@ -627,8 +625,6 @@
displayCategory.addPreference(mToggleInversionPreference);
displayCategory.addPreference(mDisplayDaltonizerPreferenceScreen);
}
- checkColorCorrectionVisibility(mDisplayDaltonizerPreferenceScreen);
- checkColorInversionVisibility(mToggleInversionPreference);
// Text contrast.
mToggleHighTextContrastPreference.setChecked(
@@ -683,7 +679,6 @@
updateAutoclickSummary(mAutoclickPreferenceScreen);
updateAccessibilityShortcut(mAccessibilityShortcutPreferenceScreen);
- checkAccessibilityShortcutVisibility(mAccessibilityShortcutPreferenceScreen);
}
private void updateMagnificationSummary(Preference pref) {
@@ -804,27 +799,6 @@
}
}
- @VisibleForTesting void checkColorCorrectionVisibility(Preference preference) {
- if (!getContext().getResources().getBoolean(
- R.bool.config_show_color_correction_preference)) {
- removePreference(DISPLAY_DALTONIZER_PREFERENCE_SCREEN);
- }
- }
-
- @VisibleForTesting void checkColorInversionVisibility(Preference preference) {
- if (!getContext().getResources().getBoolean(
- R.bool.config_show_color_inversion_preference)) {
- removePreference(TOGGLE_INVERSION_PREFERENCE);
- }
- }
-
- @VisibleForTesting void checkAccessibilityShortcutVisibility(Preference preference) {
- if (!getContext().getResources().getBoolean(
- R.bool.config_show_accessibility_shortcut_preference)) {
- removePreference(ACCESSIBILITY_SHORTCUT_PREFERENCE);
- }
- }
-
private static void configureMagnificationPreferenceIfNeeded(Preference preference) {
// Some devices support only a single magnification mode. In these cases, we redirect to
// the magnification mode's UI directly, rather than showing a PreferenceScreen with a
@@ -860,12 +834,6 @@
keys.add(FONT_SIZE_PREFERENCE_SCREEN);
keys.add(KEY_DISPLAY_SIZE);
- // Remove Accessibility Shortcuts if it's not visible
- if (!context.getResources().getBoolean(
- R.bool.config_show_accessibility_shortcut_preference)) {
- keys.add(ACCESSIBILITY_SHORTCUT_PREFERENCE);
- }
-
// Duplicates in Language & Input
keys.add(TTS_SETTINGS_PREFERENCE);
diff --git a/src/com/android/settings/dashboard/conditional/WorkModeCondition.java b/src/com/android/settings/dashboard/conditional/WorkModeCondition.java
index 5c47be6..cb1b60a 100644
--- a/src/com/android/settings/dashboard/conditional/WorkModeCondition.java
+++ b/src/com/android/settings/dashboard/conditional/WorkModeCondition.java
@@ -85,7 +85,7 @@
@Override
public void onPrimaryClick() {
mManager.getContext().startActivity(new Intent(mManager.getContext(),
- Settings.UserSettingsActivity.class)
+ Settings.AccountDashboardActivity.class)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
}
diff --git a/src/com/android/settings/fuelgauge/batterysaver/AutoBatterySaverPreferenceController.java b/src/com/android/settings/fuelgauge/batterysaver/AutoBatterySaverPreferenceController.java
index 4d3dd31..bf8cd07 100644
--- a/src/com/android/settings/fuelgauge/batterysaver/AutoBatterySaverPreferenceController.java
+++ b/src/com/android/settings/fuelgauge/batterysaver/AutoBatterySaverPreferenceController.java
@@ -29,13 +29,15 @@
*/
public class AutoBatterySaverPreferenceController extends TogglePreferenceController implements
Preference.OnPreferenceChangeListener {
- private static final int LOW_POWER_MODE_TRIGGER_THRESHOLD = 15;
+ private final int mDefWarnLevel;
@VisibleForTesting
static final String KEY_AUTO_BATTERY_SAVER = "auto_battery_saver";
public AutoBatterySaverPreferenceController(Context context) {
super(context, KEY_AUTO_BATTERY_SAVER);
+ mDefWarnLevel = mContext.getResources().getInteger(
+ com.android.internal.R.integer.config_lowBatteryWarningLevel);
}
@Override
@@ -46,7 +48,7 @@
@Override
public boolean isChecked() {
return Settings.Global.getInt(mContext.getContentResolver(),
- Settings.Global.LOW_POWER_MODE_TRIGGER_LEVEL, 0) != 0;
+ Settings.Global.LOW_POWER_MODE_TRIGGER_LEVEL, mDefWarnLevel) != 0;
}
@Override
@@ -54,7 +56,7 @@
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.LOW_POWER_MODE_TRIGGER_LEVEL,
isChecked
- ? LOW_POWER_MODE_TRIGGER_THRESHOLD
+ ? mDefWarnLevel
: 0);
return true;
}
diff --git a/src/com/android/settings/fuelgauge/batterysaver/AutoBatterySeekBarPreferenceController.java b/src/com/android/settings/fuelgauge/batterysaver/AutoBatterySeekBarPreferenceController.java
index 1cc72a7..05b3503 100644
--- a/src/com/android/settings/fuelgauge/batterysaver/AutoBatterySeekBarPreferenceController.java
+++ b/src/com/android/settings/fuelgauge/batterysaver/AutoBatterySeekBarPreferenceController.java
@@ -42,12 +42,15 @@
LifecycleObserver, OnStart, OnStop, SeekBarPreference.OnPreferenceChangeListener {
@VisibleForTesting
static final String KEY_AUTO_BATTERY_SEEK_BAR = "battery_saver_seek_bar";
+ private final int mDefWarnLevel;
private SeekBarPreference mPreference;
private AutoBatterySaverSettingObserver mContentObserver;
public AutoBatterySeekBarPreferenceController(Context context, Lifecycle lifecycle) {
super(context, KEY_AUTO_BATTERY_SEEK_BAR);
mContentObserver = new AutoBatterySaverSettingObserver(new Handler(Looper.getMainLooper()));
+ mDefWarnLevel = mContext.getResources().getInteger(
+ com.android.internal.R.integer.config_lowBatteryWarningLevel);
if (lifecycle != null) {
lifecycle.addObserver(this);
}
@@ -94,7 +97,7 @@
void updatePreference(Preference preference) {
final ContentResolver contentResolver = mContext.getContentResolver();
final int level = Settings.Global.getInt(contentResolver,
- Settings.Global.LOW_POWER_MODE_TRIGGER_LEVEL, 0);
+ Settings.Global.LOW_POWER_MODE_TRIGGER_LEVEL, mDefWarnLevel);
if (level == 0) {
preference.setVisible(false);
} else {
diff --git a/src/com/android/settings/wifi/WifiConfigController.java b/src/com/android/settings/wifi/WifiConfigController.java
index 5e5d5ff..d7b4299 100644
--- a/src/com/android/settings/wifi/WifiConfigController.java
+++ b/src/com/android/settings/wifi/WifiConfigController.java
@@ -517,6 +517,7 @@
mAccessPoint.getSsidStr());
} else {
config.networkId = mAccessPoint.getConfig().networkId;
+ config.hiddenSSID = mAccessPoint.getConfig().hiddenSSID;
}
config.shared = mSharedCheckBox.isChecked();
diff --git a/src/com/android/settings/wifi/WifiSettings.java b/src/com/android/settings/wifi/WifiSettings.java
index 9fbeabe..3972b85 100644
--- a/src/com/android/settings/wifi/WifiSettings.java
+++ b/src/com/android/settings/wifi/WifiSettings.java
@@ -353,32 +353,6 @@
}
/**
- * Only update the AP list if there are not any APs currently shown.
- *
- * <p>Thus forceUpdate will only be called during cold start or when toggling between wifi on
- * and off. In other use cases, the previous APs will remain until the next update is received
- * from {@link WifiTracker}.
- */
- private void conditionallyForceUpdateAPs() {
- if (mAccessPointsPreferenceCategory.getPreferenceCount() > 0
- && mAccessPointsPreferenceCategory.getPreference(0) instanceof
- AccessPointPreference) {
- // Make sure we don't update due to callbacks initiated by sticky broadcasts in
- // WifiTracker.
- Log.d(TAG, "Did not force update APs due to existing APs displayed");
- getView().removeCallbacks(mUpdateAccessPointsRunnable);
- return;
- }
- setProgressBarVisible(true);
- mWifiTracker.forceUpdate();
- if (isVerboseLoggingEnabled()) {
- Log.i(TAG, "WifiSettings force update APs: " + mWifiTracker.getAccessPoints());
- }
- getView().removeCallbacks(mUpdateAccessPointsRunnable);
- updateAccessPointPreferences();
- }
-
- /**
* @return new WifiEnabler or null (as overridden by WifiSettingsForSetupWizard)
*/
private WifiEnabler createWifiEnabler() {
@@ -682,7 +656,7 @@
final int wifiState = mWifiManager.getWifiState();
switch (wifiState) {
case WifiManager.WIFI_STATE_ENABLED:
- conditionallyForceUpdateAPs();
+ updateAccessPointPreferences();
break;
case WifiManager.WIFI_STATE_ENABLING:
diff --git a/tests/robotests/res/values-mcc999/config.xml b/tests/robotests/res/values-mcc999/config.xml
index 01bfa51..788c593 100644
--- a/tests/robotests/res/values-mcc999/config.xml
+++ b/tests/robotests/res/values-mcc999/config.xml
@@ -47,7 +47,6 @@
<bool name="config_show_trust_agent_click_intent">false</bool>
<bool name="config_show_wallpaper_attribution">false</bool>
<bool name="config_show_default_home">false</bool>
- <bool name="config_show_accessibility_shortcut_preference">false</bool>
<bool name="config_show_assist_and_voice_input">false</bool>
<bool name="config_show_phone_language">false</bool>
<bool name="config_show_virtual_keyboard_pref">false</bool>
@@ -55,8 +54,6 @@
<bool name="config_show_tts_settings_summary">false</bool>
<bool name="config_show_pointer_speed">false</bool>
<bool name="config_show_vibrate_input_devices">false</bool>
- <bool name="config_show_color_correction_preference">false</bool>
- <bool name="config_show_color_inversion_preference">false</bool>
<bool name="config_show_system_update_settings">false</bool>
<bool name="config_wifi_support_connected_mac_randomization">false</bool>
<bool name="config_show_device_model">false</bool>
diff --git a/tests/robotests/src/com/android/internal/accessibility/AccessibilityShortcutController.java b/tests/robotests/src/com/android/internal/accessibility/AccessibilityShortcutController.java
deleted file mode 100644
index aae2f8d..0000000
--- a/tests/robotests/src/com/android/internal/accessibility/AccessibilityShortcutController.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.internal.accessibility;
-
-import android.content.ComponentName;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * Fake controller to make robolectric test compile. Should be removed when Robolectric supports
- * API 25.
- */
-public class AccessibilityShortcutController {
-
- public static Map<ComponentName, AccessibilityShortcutController.ToggleableFrameworkFeatureInfo>
- getFrameworkShortcutFeaturesMap() {
- return new HashMap<>();
- }
-
- public static class ToggleableFrameworkFeatureInfo {
- private String mSettingKey;
-
- public String getSettingKey() {
- return mSettingKey;
- }
- }
-}
diff --git a/tests/robotests/src/com/android/settings/accessibility/AccessibilitySettingsTest.java b/tests/robotests/src/com/android/settings/accessibility/AccessibilitySettingsTest.java
index 96ce183..fb32da1 100644
--- a/tests/robotests/src/com/android/settings/accessibility/AccessibilitySettingsTest.java
+++ b/tests/robotests/src/com/android/settings/accessibility/AccessibilitySettingsTest.java
@@ -16,137 +16,35 @@
package com.android.settings.accessibility;
-import static com.google.common.truth.Truth.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.spy;
-
import android.content.Context;
-import android.support.v7.preference.Preference;
import com.android.settings.R;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
import com.android.settings.testutils.XmlTestUtils;
-
-import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import java.util.ArrayList;
import java.util.List;
+import static com.google.common.truth.Truth.assertThat;
+
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class AccessibilitySettingsTest {
- private Context mContext;
- private AccessibilitySettings mFragment;
- private boolean mAccessibilityShortcutPreferenceRemoved;
- private boolean mColorInversionPreferenceRemoved;
- private boolean mColorCorrectionPreferenceRemoved;
-
- @Before
- public void setUp() {
- MockitoAnnotations.initMocks(this);
- mContext = spy(RuntimeEnvironment.application);
- mFragment = new AccessibilitySettings() {
- @Override
- public Context getContext() {
- return mContext;
- }
-
- @Override
- protected boolean removePreference(String key) {
- if (AccessibilitySettings.ACCESSIBILITY_SHORTCUT_PREFERENCE.equals(key)) {
- mAccessibilityShortcutPreferenceRemoved = true;
- return true;
- }
-
- if (AccessibilitySettings.TOGGLE_INVERSION_PREFERENCE.equals(key)) {
- mColorInversionPreferenceRemoved = true;
- return true;
- }
-
- if (AccessibilitySettings.DISPLAY_DALTONIZER_PREFERENCE_SCREEN.equals(key)) {
- mColorCorrectionPreferenceRemoved = true;
- return true;
- }
- return false;
- }
- };
- }
-
@Test
public void testNonIndexableKeys_existInXmlLayout() {
+ final Context context = RuntimeEnvironment.application;
final List<String> niks = AccessibilitySettings.SEARCH_INDEX_DATA_PROVIDER
- .getNonIndexableKeys(mContext);
+ .getNonIndexableKeys(context);
final List<String> keys = new ArrayList<>();
- keys.addAll(XmlTestUtils.getKeysFromPreferenceXml(mContext, R.xml.accessibility_settings));
+ keys.addAll(XmlTestUtils.getKeysFromPreferenceXml(context, R.xml.accessibility_settings));
assertThat(keys).containsAllIn(niks);
}
-
- @Test
- public void testAccessibilityShortcutPreference_byDefault_shouldBeShown() {
- final Preference preference = new Preference(mContext);
- mFragment.checkAccessibilityShortcutVisibility(preference);
-
- assertThat(mAccessibilityShortcutPreferenceRemoved).isFalse();
- }
-
- @Test
- @Config(qualifiers = "mcc999")
- public void testAccessibilityShortcutPreference_ifDisabled_shouldNotBeShown() {
- final Preference preference = new Preference(mContext);
- mFragment.checkAccessibilityShortcutVisibility(preference);
-
- assertThat(mAccessibilityShortcutPreferenceRemoved).isTrue();
- }
-
- @Test
- @Config(qualifiers = "mcc999")
- public void testNonIndexableKeys_ifAccessibilityShortcutNotVisible_containsKey() {
- final List<String> niks = AccessibilitySettings.SEARCH_INDEX_DATA_PROVIDER
- .getNonIndexableKeys(mContext);
-
- assertThat(niks).contains(AccessibilitySettings.ACCESSIBILITY_SHORTCUT_PREFERENCE);
- }
-
- @Test
- public void testColorInversionPreference_byDefault_shouldBeShown() {
- final Preference preference = new Preference(mContext);
- mFragment.checkColorInversionVisibility(preference);
-
- assertThat(mColorInversionPreferenceRemoved).isEqualTo(false);
- }
-
- @Test
- @Config(qualifiers = "mcc999")
- public void testColorInversionPreference_ifDisabled_shouldNotBeShown() {
- final Preference preference = new Preference(mContext);
- mFragment.checkColorInversionVisibility(preference);
-
- assertThat(mColorInversionPreferenceRemoved).isEqualTo(true);
- }
-
- @Test
- public void testColorCorrectionPreference_byDefault_shouldBeShown() {
- final Preference preference = new Preference(mContext);
- mFragment.checkColorCorrectionVisibility(preference);
-
- assertThat(mColorCorrectionPreferenceRemoved).isEqualTo(false);
- }
-
- @Test
- @Config(qualifiers = "mcc999")
- public void testColorCorrectionPreference_ifDisabled_shouldNotBeShown() {
- final Preference preference = new Preference(mContext);
- mFragment.checkColorCorrectionVisibility(preference);
-
- assertThat(mColorCorrectionPreferenceRemoved).isEqualTo(true);
- }
}
diff --git a/tests/robotests/src/com/android/settings/dashboard/conditional/WorkModeConditionTest.java b/tests/robotests/src/com/android/settings/dashboard/conditional/WorkModeConditionTest.java
new file mode 100644
index 0000000..dff7700
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/dashboard/conditional/WorkModeConditionTest.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+package com.android.settings.dashboard.conditional;
+
+import static org.mockito.ArgumentMatchers.argThat;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.content.ComponentName;
+import android.content.Context;
+
+import com.android.settings.Settings;
+import com.android.settings.TestConfig;
+import com.android.settings.testutils.FakeFeatureFactory;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+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;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class WorkModeConditionTest {
+
+ @Mock
+ private ConditionManager mConditionManager;
+
+ private Context mContext;
+ private WorkModeCondition mCondition;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mContext = spy(RuntimeEnvironment.application);
+ FakeFeatureFactory.setupForTest();
+ when(mConditionManager.getContext()).thenReturn(mContext);
+ mCondition = new WorkModeCondition(mConditionManager);
+ }
+
+ @Test
+ public void onPrimaryClick_shouldLaunchAccountsSetting() {
+ final ComponentName componentName =
+ new ComponentName(mContext, Settings.AccountDashboardActivity.class);
+
+ mCondition.onPrimaryClick();
+
+ verify(mContext).startActivity(
+ argThat(intent-> intent.getComponent().equals(componentName)));
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/batterysaver/AutoBatterySaverPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batterysaver/AutoBatterySaverPreferenceControllerTest.java
index cabcdcf..af0f855 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/batterysaver/AutoBatterySaverPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batterysaver/AutoBatterySaverPreferenceControllerTest.java
@@ -25,6 +25,7 @@
import com.android.settings.TestConfig;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settings.testutils.shadow.SettingsShadowResources;
import org.junit.Before;
import org.junit.Test;
@@ -34,7 +35,8 @@
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION, shadows =
+ SettingsShadowResources.class)
public class AutoBatterySaverPreferenceControllerTest {
private AutoBatterySaverPreferenceController mController;
@@ -45,6 +47,8 @@
public void setUp() {
MockitoAnnotations.initMocks(this);
+ SettingsShadowResources.overrideResource(
+ com.android.internal.R.integer.config_lowBatteryWarningLevel, 15);
mContext = RuntimeEnvironment.application;
mPreference = new SwitchPreference(mContext);
mController = new AutoBatterySaverPreferenceController(mContext);
@@ -84,4 +88,9 @@
Settings.Global.LOW_POWER_MODE_TRIGGER_LEVEL, 0)).isEqualTo(0);
}
+ @Test
+ public void testIsChecked_useDefaultValue_returnTrue() {
+ assertThat(mController.isChecked()).isTrue();
+ }
+
}
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/batterysaver/AutoBatterySeekBarPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batterysaver/AutoBatterySeekBarPreferenceControllerTest.java
index 32a4fac..d3c2752 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/batterysaver/AutoBatterySeekBarPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batterysaver/AutoBatterySeekBarPreferenceControllerTest.java
@@ -24,6 +24,7 @@
import com.android.settings.TestConfig;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settings.testutils.shadow.SettingsShadowResources;
import com.android.settings.widget.SeekBarPreference;
import com.android.settingslib.core.lifecycle.Lifecycle;
@@ -35,9 +36,11 @@
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION, shadows =
+ SettingsShadowResources.class)
public class AutoBatterySeekBarPreferenceControllerTest {
- private static final int TRIGGER_LEVEL = 15;
+ private static final int TRIGGER_LEVEL = 20;
+ private static final int DEFAULT_LEVEL = 15;
private AutoBatterySeekBarPreferenceController mController;
private Context mContext;
@@ -51,6 +54,8 @@
mLifecycleOwner = () -> mLifecycle;
mLifecycle = new Lifecycle(mLifecycleOwner);
+ SettingsShadowResources.overrideResource(
+ com.android.internal.R.integer.config_lowBatteryWarningLevel, DEFAULT_LEVEL);
mContext = RuntimeEnvironment.application;
mPreference = new SeekBarPreference(mContext);
mPreference.setMax(100);
@@ -68,13 +73,21 @@
}
@Test
+ public void testPreference_defaultValue_preferenceVisible() {
+ mController.updateState(mPreference);
+
+ assertThat(mPreference.isVisible()).isTrue();
+ assertThat(mPreference.getProgress()).isEqualTo(DEFAULT_LEVEL);
+ }
+
+ @Test
public void testPreference_lowPowerLevelNotZero_updatePreference() {
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.LOW_POWER_MODE_TRIGGER_LEVEL, TRIGGER_LEVEL);
mController.updateState(mPreference);
assertThat(mPreference.isVisible()).isTrue();
- assertThat(mPreference.getTitle()).isEqualTo("Turn on automatically at 15%");
+ assertThat(mPreference.getTitle()).isEqualTo("Turn on automatically at 20%");
assertThat(mPreference.getProgress()).isEqualTo(TRIGGER_LEVEL);
}
diff --git a/tests/unit/src/com/android/settings/wifi/WifiSettingsUiTest.java b/tests/unit/src/com/android/settings/wifi/WifiSettingsUiTest.java
index e44a596..e1005ea 100644
--- a/tests/unit/src/com/android/settings/wifi/WifiSettingsUiTest.java
+++ b/tests/unit/src/com/android/settings/wifi/WifiSettingsUiTest.java
@@ -51,6 +51,7 @@
import android.support.test.runner.AndroidJUnit4;
import com.android.settings.Settings.WifiSettingsActivity;
+import com.android.settingslib.utils.ThreadUtils;
import com.android.settingslib.wifi.AccessPoint;
import com.android.settingslib.wifi.TestAccessPointBuilder;
import com.android.settingslib.wifi.WifiTracker;
@@ -261,26 +262,6 @@
}
@Test
- public void resumingAp_shouldNotForceUpdateWhenExistingAPsAreListed() {
- setWifiState(WifiManager.WIFI_STATE_ENABLED);
- setupConnectedAccessPoint();
- when(mWifiTracker.isConnected()).thenReturn(true);
-
- launchActivity();
-
- onView(withText(resourceString(WIFI_DISPLAY_STATUS_CONNECTED))).check(
- matches(isDisplayed()));
- verify(mWifiTracker).forceUpdate();
-
- Activity activity = mActivityRule.getActivity();
- activity.finish();
- getInstrumentation().waitForIdleSync();
-
- getInstrumentation().callActivityOnStart(activity);
- verify(mWifiTracker, atMost(1)).forceUpdate();
- }
-
- @Test
public void changingSecurityStateOnApShouldNotCauseMultipleListItems() {
setWifiState(WifiManager.WIFI_STATE_ENABLED);
TestAccessPointBuilder builder = new TestAccessPointBuilder(mContext)
@@ -305,10 +286,10 @@
onView(withText(TEST_SSID)).check(matches(isDisplayed()));
- mWifiListener.onAccessPointsChanged();
+ ThreadUtils.postOnMainThread(() -> mWifiListener.onAccessPointsChanged());
onView(withText(TEST_SSID)).check(matches(isDisplayed()));
- mWifiListener.onAccessPointsChanged();
+ ThreadUtils.postOnMainThread(() -> mWifiListener.onAccessPointsChanged());
onView(withText(TEST_SSID)).check(matches(isDisplayed()));
}
@@ -367,7 +348,6 @@
launchActivity();
- verify(mWifiTracker, atMost(1)).forceUpdate();
verify(mWifiTracker, times(1)).getAccessPoints();
onView(withText(WIFI_DISPLAY_STATUS_CONNECTED)).check(matches(isDisplayed()));