Merge "Add XML attribute to toggle on/off LocationModePreferenceController."

This commit is contained in:
TreeHugger Robot
2017-12-05 22:53:21 +00:00
committed by Android (Google) Code Review
4 changed files with 22 additions and 0 deletions

View File

@@ -48,4 +48,7 @@
<!--Whether help links are defined. -->
<bool name="config_has_help">false</bool>
<!-- Whether location mode is available or not. -->
<bool name="config_location_mode_available">true</bool>
</resources>

View File

@@ -40,6 +40,11 @@ public class LocationModePreferenceController extends LocationBasePreferenceCont
return KEY_LOCATION_MODE;
}
@Override
public boolean isAvailable() {
return mContext.getResources().getBoolean(R.bool.config_location_mode_available);
}
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);

View File

@@ -20,4 +20,5 @@
<bool name="config_show_camera_laser_sensor">false</bool>
<bool name="config_show_connectivity_monitor">false</bool>
<bool name="config_display_recent_apps">false</bool>
<bool name="config_location_mode_available">false</bool>
</resources>

View File

@@ -15,6 +15,8 @@
*/
package com.android.settings.location;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
@@ -72,6 +74,17 @@ public class LocationModePreferenceControllerTest {
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
}
@Test
@Config(qualifiers = "mcc999")
public void locationModePreference_ifXmlSetToFalse_shouldNotBeAvailable() {
assertFalse(mController.isAvailable());
}
@Test
public void locationModePreference_ifXmlSetToTrue_shouldBeAvailable() {
assertTrue(mController.isAvailable());
}
@Test
public void onLocationModeChanged_locationOff_shouldDisablePreference() {
when(mUserManager.hasUserRestriction(any())).thenReturn(false);