Enable time zone preference on wifi-only device.

When auto time zone preference is not available, it should be considered
disabled, so that user can still select time zone.

Change-Id: I9b17205a11ff512da02694e3bce06cfbd21dd7db
Fix: 34203177
Test: make RunSettingsRoboTests
This commit is contained in:
Doris Ling
2017-01-13 10:52:53 -08:00
parent 78427d7467
commit 0e15fe8e4a
2 changed files with 20 additions and 1 deletions

View File

@@ -67,7 +67,7 @@ public class AutoTimeZonePreferenceController extends PreferenceController
} }
public boolean isEnabled() { public boolean isEnabled() {
return Settings.Global.getInt(mContext.getContentResolver(), return isAvailable() && Settings.Global.getInt(mContext.getContentResolver(),
Settings.Global.AUTO_TIME_ZONE, 0) > 0; Settings.Global.AUTO_TIME_ZONE, 0) > 0;
} }
} }

View File

@@ -55,6 +55,7 @@ public class AutoTimeZonePreferenceControllerTest {
@Before @Before
public void setUp() { public void setUp() {
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);
ShadowApplication.getInstance().setSystemService(Context.CONNECTIVITY_SERVICE, mCm);
mContext = ShadowApplication.getInstance().getApplicationContext(); mContext = ShadowApplication.getInstance().getApplicationContext();
mPreference = new Preference(mContext); mPreference = new Preference(mContext);
when(mMockContext.getSystemService(Context.CONNECTIVITY_SERVICE)).thenReturn(mCm); when(mMockContext.getSystemService(Context.CONNECTIVITY_SERVICE)).thenReturn(mCm);
@@ -87,6 +88,24 @@ public class AutoTimeZonePreferenceControllerTest {
assertThat(mController.isAvailable()).isFalse(); assertThat(mController.isAvailable()).isFalse();
} }
@Test
public void isFromSUW_notEnable() {
mController = new AutoTimeZonePreferenceController(
mMockContext, null /* callback */, true /* isFromSUW */);
assertThat(mController.isEnabled()).isFalse();
}
@Test
public void isWifiOnly_notEnable() {
when(mCm.isNetworkSupported(ConnectivityManager.TYPE_MOBILE)).thenReturn(false);
mController = new AutoTimeZonePreferenceController(
mMockContext, null /* callback */, false /* isFromSUW */);
assertThat(mController.isEnabled()).isFalse();
}
@Test @Test
public void testIsEnabled_shouldReadFromSettingsProvider() { public void testIsEnabled_shouldReadFromSettingsProvider() {
mController = new AutoTimeZonePreferenceController( mController = new AutoTimeZonePreferenceController(