Show pop-up banner when Location is off and user tries to enable GeoTZ.

As of now GeoTZ state remains unchanged even if user enables
Location toggle.

Bug: 152746236
Test: m -j30 RunSettingsRoboTests ROBOTEST_FILTER="com.android.settings.datetime.LocationTimeZoneDetectionPreferenceControllerTest"
Test: checked manually that dialog opens Location settings page
Change-Id: I5fd3288e9d5a7aac3bc82da6944b4ccd6bb9e0f5
This commit is contained in:
Almaz Mingaleev
2021-03-18 10:30:04 +00:00
parent 8a2e489ac8
commit fcf1fcfe9b
5 changed files with 122 additions and 8 deletions

View File

@@ -24,6 +24,7 @@ import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.when;
import android.app.time.Capabilities;
@@ -36,10 +37,13 @@ import android.location.LocationManager;
import android.os.UserHandle;
import com.android.settings.R;
import com.android.settings.core.InstrumentedPreferenceFragment;
import com.android.settingslib.core.lifecycle.Lifecycle;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
@@ -53,6 +57,10 @@ public class LocationTimeZoneDetectionPreferenceControllerTest {
private LocationManager mLocationManager;
private Context mContext;
private LocationTimeZoneDetectionPreferenceController mController;
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private InstrumentedPreferenceFragment mFragment;
@Mock
private Lifecycle mLifecycle;
@Before
public void setUp() {
@@ -60,11 +68,14 @@ public class LocationTimeZoneDetectionPreferenceControllerTest {
mContext = spy(RuntimeEnvironment.application);
when(mContext.getSystemService(TimeManager.class)).thenReturn(mTimeManager);
when(mContext.getSystemService(LocationManager.class)).thenReturn(mLocationManager);
mController = new LocationTimeZoneDetectionPreferenceController(mContext, "key");
mController = new LocationTimeZoneDetectionPreferenceController(mContext);
mController.setFragment(mFragment);
}
@Test
public void setChecked_withTrue_shouldUpdateSetting() {
public void setChecked_withTrue_shouldUpdateSetting_whenLocationIsEnabled() {
when(mLocationManager.isLocationEnabled()).thenReturn(true);
// Simulate the UI being clicked.
mController.setChecked(true);
@@ -75,6 +86,17 @@ public class LocationTimeZoneDetectionPreferenceControllerTest {
verify(mTimeManager).updateTimeZoneConfiguration(expectedConfiguration);
}
@Test
public void setChecked_withTrue_shouldDoNothing_whenLocationIsDisabled() {
when(mLocationManager.isLocationEnabled()).thenReturn(false);
// Simulate the UI being clicked.
mController.setChecked(true);
// Verify the TimeManager was not called.
verifyZeroInteractions(mTimeManager);
}
@Test
public void setChecked_withFalse_shouldUpdateSetting() {
// Simulate the UI being clicked.