Merge "Add "Use location" state to TimeZoneCapabilities"

This commit is contained in:
Neil Fuller
2023-01-31 15:57:43 +00:00
committed by Android (Google) Code Review
6 changed files with 150 additions and 92 deletions

View File

@@ -37,7 +37,6 @@ import android.app.time.TimeZoneCapabilitiesAndConfig;
import android.app.time.TimeZoneConfiguration;
import android.app.time.TimeZoneDetectorStatus;
import android.content.Context;
import android.location.LocationManager;
import android.os.UserHandle;
import androidx.preference.Preference;
@@ -62,8 +61,6 @@ public class AutoTimeZonePreferenceControllerTest {
private Preference mPreference;
@Mock
private TimeManager mTimeManager;
@Mock
private LocationManager mLocationManager;
@Before
public void setUp() {
@@ -73,9 +70,6 @@ public class AutoTimeZonePreferenceControllerTest {
mPreference = new Preference(mContext);
when(mContext.getSystemService(TimeManager.class)).thenReturn(mTimeManager);
when(mContext.getSystemService(LocationManager.class)).thenReturn(mLocationManager);
when(mLocationManager.isLocationEnabled()).thenReturn(true);
}
@Test
@@ -267,6 +261,7 @@ public class AutoTimeZonePreferenceControllerTest {
: Capabilities.CAPABILITY_NOT_SUPPORTED;
TimeZoneCapabilities capabilities = new TimeZoneCapabilities.Builder(UserHandle.SYSTEM)
.setConfigureAutoDetectionEnabledCapability(configureAutoDetectionEnabledCapability)
.setUseLocationEnabled(true)
.setConfigureGeoDetectionEnabledCapability(Capabilities.CAPABILITY_NOT_SUPPORTED)
.setSetManualTimeZoneCapability(Capabilities.CAPABILITY_POSSESSED)
.build();

View File

@@ -29,7 +29,9 @@ import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import android.app.time.Capabilities;
import android.app.time.Capabilities.CapabilityState;
import android.app.time.LocationTimeZoneAlgorithmStatus;
import android.app.time.LocationTimeZoneAlgorithmStatus.ProviderStatus;
import android.app.time.TelephonyTimeZoneAlgorithmStatus;
import android.app.time.TimeManager;
import android.app.time.TimeZoneCapabilities;
@@ -37,9 +39,9 @@ import android.app.time.TimeZoneCapabilitiesAndConfig;
import android.app.time.TimeZoneConfiguration;
import android.app.time.TimeZoneDetectorStatus;
import android.content.Context;
import android.location.LocationManager;
import android.os.UserHandle;
import android.service.timezone.TimeZoneProviderStatus;
import android.service.timezone.TimeZoneProviderStatus.DependencyStatus;
import androidx.annotation.Nullable;
@@ -60,8 +62,6 @@ public class LocationProviderStatusPreferenceControllerTest {
private Context mContext;
@Mock
private TimeManager mTimeManager;
@Mock
private LocationManager mLocationManager;
@Before
public void setUp() {
@@ -69,8 +69,6 @@ public class LocationProviderStatusPreferenceControllerTest {
mContext = spy(RuntimeEnvironment.application);
when(mContext.getSystemService(TimeManager.class)).thenReturn(mTimeManager);
when(mContext.getSystemService(LocationManager.class)).thenReturn(mLocationManager);
when(mLocationManager.isLocationEnabled()).thenReturn(true);
when(mContext.getString(
R.string.location_time_zone_detection_status_summary_blocked_by_settings))
.thenReturn("BBS");
@@ -78,11 +76,12 @@ public class LocationProviderStatusPreferenceControllerTest {
@Test
public void testCapabilityStatus() {
LocationProviderStatusPreferenceController controller =
new LocationProviderStatusPreferenceController(mContext, "LPSPC");
TimeZoneCapabilitiesAndConfig capabilitiesAndConfig = createCapabilitiesAndConfig(false,
DEPENDENCY_STATUS_OK, DEPENDENCY_STATUS_OK);
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
LocationProviderStatusPreferenceController controller =
new LocationProviderStatusPreferenceController(mContext, "LPSPC");
assertThat(controller.getAvailabilityStatus()).isEqualTo(
BasePreferenceController.CONDITIONALLY_UNAVAILABLE);
@@ -95,14 +94,16 @@ public class LocationProviderStatusPreferenceControllerTest {
BasePreferenceController.CONDITIONALLY_UNAVAILABLE);
capabilitiesAndConfig = createCapabilitiesAndConfig(false,
DEPENDENCY_STATUS_BLOCKED_BY_SETTINGS, DEPENDENCY_STATUS_OK);
PROVIDER_STATUS_IS_CERTAIN, DEPENDENCY_STATUS_BLOCKED_BY_SETTINGS,
PROVIDER_STATUS_IS_CERTAIN, DEPENDENCY_STATUS_OK);
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
assertThat(controller.getAvailabilityStatus()).isEqualTo(
BasePreferenceController.AVAILABLE_UNSEARCHABLE);
capabilitiesAndConfig = createCapabilitiesAndConfig(true,
DEPENDENCY_STATUS_BLOCKED_BY_SETTINGS, DEPENDENCY_STATUS_OK);
PROVIDER_STATUS_IS_CERTAIN, DEPENDENCY_STATUS_BLOCKED_BY_SETTINGS,
PROVIDER_STATUS_IS_CERTAIN, DEPENDENCY_STATUS_OK);
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
assertThat(controller.getAvailabilityStatus()).isEqualTo(
@@ -111,31 +112,36 @@ public class LocationProviderStatusPreferenceControllerTest {
@Test
public void testProviderStatus_primaryCertain() {
TimeZoneCapabilitiesAndConfig capabilitiesAndConfig = createCapabilitiesAndConfig(false,
DEPENDENCY_STATUS_OK, DEPENDENCY_STATUS_OK);
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
LocationProviderStatusPreferenceController controller =
new LocationProviderStatusPreferenceController(mContext, "LPSPC");
TimeZoneCapabilitiesAndConfig capabilitiesAndConfig = createCapabilitiesAndConfig(false,
PROVIDER_STATUS_IS_CERTAIN, DEPENDENCY_STATUS_OK,
PROVIDER_STATUS_IS_CERTAIN, DEPENDENCY_STATUS_OK);
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
assertThat(controller.getAvailabilityStatus()).isEqualTo(
BasePreferenceController.CONDITIONALLY_UNAVAILABLE);
capabilitiesAndConfig = createCapabilitiesAndConfig(false,
DEPENDENCY_STATUS_BLOCKED_BY_SETTINGS, DEPENDENCY_STATUS_OK);
PROVIDER_STATUS_IS_CERTAIN, DEPENDENCY_STATUS_BLOCKED_BY_SETTINGS,
PROVIDER_STATUS_IS_CERTAIN, DEPENDENCY_STATUS_OK);
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
assertThat(controller.getAvailabilityStatus()).isEqualTo(
BasePreferenceController.AVAILABLE_UNSEARCHABLE);
capabilitiesAndConfig = createCapabilitiesAndConfig(false, DEPENDENCY_STATUS_OK,
DEPENDENCY_STATUS_BLOCKED_BY_SETTINGS);
capabilitiesAndConfig = createCapabilitiesAndConfig(false,
PROVIDER_STATUS_IS_CERTAIN, DEPENDENCY_STATUS_OK,
PROVIDER_STATUS_IS_CERTAIN, DEPENDENCY_STATUS_BLOCKED_BY_SETTINGS);
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
assertThat(controller.getAvailabilityStatus()).isEqualTo(
BasePreferenceController.CONDITIONALLY_UNAVAILABLE);
capabilitiesAndConfig = createCapabilitiesAndConfig(false, DEPENDENCY_STATUS_OK,
DEPENDENCY_STATUS_BLOCKED_BY_SETTINGS);
capabilitiesAndConfig = createCapabilitiesAndConfig(false,
PROVIDER_STATUS_IS_CERTAIN, DEPENDENCY_STATUS_OK,
PROVIDER_STATUS_IS_CERTAIN, DEPENDENCY_STATUS_BLOCKED_BY_SETTINGS);
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
assertThat(controller.getAvailabilityStatus()).isEqualTo(
@@ -144,32 +150,36 @@ public class LocationProviderStatusPreferenceControllerTest {
@Test
public void testProviderStatus_primaryUncertain() {
TimeZoneCapabilitiesAndConfig capabilitiesAndConfig = createCapabilitiesAndConfig(false,
DEPENDENCY_STATUS_OK, DEPENDENCY_STATUS_OK, PROVIDER_STATUS_IS_CERTAIN);
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
LocationProviderStatusPreferenceController controller =
new LocationProviderStatusPreferenceController(mContext, "LPSPC");
TimeZoneCapabilitiesAndConfig capabilitiesAndConfig = createCapabilitiesAndConfig(false,
PROVIDER_STATUS_IS_CERTAIN, DEPENDENCY_STATUS_OK,
PROVIDER_STATUS_IS_CERTAIN, DEPENDENCY_STATUS_OK);
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
assertThat(controller.getAvailabilityStatus()).isEqualTo(
BasePreferenceController.CONDITIONALLY_UNAVAILABLE);
capabilitiesAndConfig = createCapabilitiesAndConfig(false,
DEPENDENCY_STATUS_BLOCKED_BY_SETTINGS, DEPENDENCY_STATUS_OK,
PROVIDER_STATUS_IS_CERTAIN);
PROVIDER_STATUS_IS_CERTAIN, DEPENDENCY_STATUS_BLOCKED_BY_SETTINGS,
PROVIDER_STATUS_IS_CERTAIN, DEPENDENCY_STATUS_OK);
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
assertThat(controller.getAvailabilityStatus()).isEqualTo(
BasePreferenceController.AVAILABLE_UNSEARCHABLE);
capabilitiesAndConfig = createCapabilitiesAndConfig(false, DEPENDENCY_STATUS_OK,
DEPENDENCY_STATUS_BLOCKED_BY_SETTINGS, PROVIDER_STATUS_IS_UNCERTAIN);
capabilitiesAndConfig = createCapabilitiesAndConfig(false,
PROVIDER_STATUS_IS_UNCERTAIN, DEPENDENCY_STATUS_OK,
PROVIDER_STATUS_IS_CERTAIN, DEPENDENCY_STATUS_BLOCKED_BY_SETTINGS);
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
assertThat(controller.getAvailabilityStatus()).isEqualTo(
BasePreferenceController.AVAILABLE_UNSEARCHABLE);
capabilitiesAndConfig = createCapabilitiesAndConfig(false, DEPENDENCY_STATUS_OK,
DEPENDENCY_STATUS_OK, PROVIDER_STATUS_IS_UNCERTAIN);
capabilitiesAndConfig = createCapabilitiesAndConfig(false,
PROVIDER_STATUS_IS_UNCERTAIN, DEPENDENCY_STATUS_OK,
PROVIDER_STATUS_IS_CERTAIN, DEPENDENCY_STATUS_OK);
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
assertThat(controller.getAvailabilityStatus()).isEqualTo(
@@ -177,18 +187,21 @@ public class LocationProviderStatusPreferenceControllerTest {
}
@Test
public void testProviderStatus_nullProviders() {
TimeZoneCapabilitiesAndConfig capabilitiesAndConfig = createCapabilitiesAndConfig(false,
null, null);
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
public void testProviderStatus_nullProviderStatuses() {
LocationProviderStatusPreferenceController controller =
new LocationProviderStatusPreferenceController(mContext, "LPSPC");
TimeZoneCapabilitiesAndConfig capabilitiesAndConfig = createCapabilitiesAndConfig(false,
PROVIDER_STATUS_IS_CERTAIN, null,
PROVIDER_STATUS_IS_CERTAIN, null);
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
assertThat(controller.getAvailabilityStatus()).isEqualTo(
BasePreferenceController.CONDITIONALLY_UNAVAILABLE);
capabilitiesAndConfig = createCapabilitiesAndConfig(false,
DEPENDENCY_STATUS_BLOCKED_BY_SETTINGS, null);
PROVIDER_STATUS_IS_CERTAIN, DEPENDENCY_STATUS_BLOCKED_BY_SETTINGS,
PROVIDER_STATUS_IS_CERTAIN, null);
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
assertThat(controller.getAvailabilityStatus()).isEqualTo(
@@ -200,39 +213,63 @@ public class LocationProviderStatusPreferenceControllerTest {
assertThat(controller.getAvailabilityStatus()).isEqualTo(
BasePreferenceController.CONDITIONALLY_UNAVAILABLE);
capabilitiesAndConfig = createCapabilitiesAndConfig(false, null,
DEPENDENCY_STATUS_BLOCKED_BY_SETTINGS);
capabilitiesAndConfig = createCapabilitiesAndConfig(false,
PROVIDER_STATUS_IS_CERTAIN, null,
PROVIDER_STATUS_IS_CERTAIN, DEPENDENCY_STATUS_BLOCKED_BY_SETTINGS);
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
assertThat(controller.getAvailabilityStatus()).isEqualTo(
BasePreferenceController.AVAILABLE_UNSEARCHABLE);
}
private TimeZoneCapabilitiesAndConfig createCapabilitiesAndConfig(boolean capabilitySupported,
@Nullable Integer primary, @Nullable Integer secondary) {
return createCapabilitiesAndConfig(capabilitySupported, primary, secondary,
PROVIDER_STATUS_IS_CERTAIN);
private static TimeZoneCapabilitiesAndConfig createCapabilitiesAndConfig(
boolean userCanConfigureGeoDetection,
@Nullable @DependencyStatus Integer primaryProviderLocationStatus,
@Nullable @DependencyStatus Integer secondaryProviderLocationStatus) {
return createCapabilitiesAndConfig(userCanConfigureGeoDetection,
PROVIDER_STATUS_IS_CERTAIN, primaryProviderLocationStatus,
PROVIDER_STATUS_IS_CERTAIN, secondaryProviderLocationStatus);
}
private TimeZoneCapabilitiesAndConfig createCapabilitiesAndConfig(boolean capabilitySupported,
@Nullable Integer primary, @Nullable Integer secondary, int primaryProviderStatus) {
TimeZoneDetectorStatus status = new TimeZoneDetectorStatus(DETECTOR_STATUS_RUNNING,
new TelephonyTimeZoneAlgorithmStatus(DETECTION_ALGORITHM_STATUS_RUNNING),
new LocationTimeZoneAlgorithmStatus(DETECTION_ALGORITHM_STATUS_RUNNING,
primaryProviderStatus, primary != null
? new TimeZoneProviderStatus.Builder().setLocationDetectionDependencyStatus(
primary).build() : null, PROVIDER_STATUS_IS_CERTAIN, secondary != null
? new TimeZoneProviderStatus.Builder().setLocationDetectionDependencyStatus(
secondary).build() : null));
private static TimeZoneCapabilitiesAndConfig createCapabilitiesAndConfig(
boolean userCanConfigureGeoDetection,
@ProviderStatus int primaryProviderStatus,
@Nullable @DependencyStatus Integer primaryProviderLocationStatus,
@ProviderStatus int secondaryProviderStatus,
@Nullable @DependencyStatus Integer secondaryProviderLocationStatus) {
TelephonyTimeZoneAlgorithmStatus telephonyTimeZoneAlgorithmStatus =
new TelephonyTimeZoneAlgorithmStatus(DETECTION_ALGORITHM_STATUS_RUNNING);
TimeZoneCapabilities capabilities = new TimeZoneCapabilities.Builder(
UserHandle.SYSTEM).setConfigureAutoDetectionEnabledCapability(
Capabilities.CAPABILITY_POSSESSED).setConfigureGeoDetectionEnabledCapability(
capabilitySupported ? Capabilities.CAPABILITY_POSSESSED
: Capabilities.CAPABILITY_NOT_SUPPORTED).setSetManualTimeZoneCapability(
Capabilities.CAPABILITY_POSSESSED).build();
LocationTimeZoneAlgorithmStatus locationTimeZoneAlgorithmStatus =
new LocationTimeZoneAlgorithmStatus(DETECTION_ALGORITHM_STATUS_RUNNING,
primaryProviderStatus,
createTimeZoneProviderStatusOrNull(primaryProviderLocationStatus),
secondaryProviderStatus,
createTimeZoneProviderStatusOrNull(secondaryProviderLocationStatus));
TimeZoneDetectorStatus status = new TimeZoneDetectorStatus(DETECTOR_STATUS_RUNNING,
telephonyTimeZoneAlgorithmStatus, locationTimeZoneAlgorithmStatus);
@CapabilityState int configureGeoDetectionEnabledCapability = userCanConfigureGeoDetection
? Capabilities.CAPABILITY_POSSESSED : Capabilities.CAPABILITY_NOT_SUPPORTED;
TimeZoneCapabilities capabilities = new TimeZoneCapabilities.Builder(UserHandle.SYSTEM)
.setConfigureAutoDetectionEnabledCapability(Capabilities.CAPABILITY_POSSESSED)
.setUseLocationEnabled(true)
.setConfigureGeoDetectionEnabledCapability(configureGeoDetectionEnabledCapability)
.setSetManualTimeZoneCapability(Capabilities.CAPABILITY_POSSESSED)
.build();
return new TimeZoneCapabilitiesAndConfig(status, capabilities,
new TimeZoneConfiguration.Builder().build());
}
private static TimeZoneProviderStatus createTimeZoneProviderStatusOrNull(
@Nullable @DependencyStatus Integer locationDependencyStatusOrNull) {
if (locationDependencyStatusOrNull == null) {
return null;
}
return new TimeZoneProviderStatus.Builder()
.setLocationDetectionDependencyStatus(locationDependencyStatusOrNull)
.build();
}
}

View File

@@ -27,9 +27,10 @@ import static android.app.time.LocationTimeZoneAlgorithmStatus.PROVIDER_STATUS_N
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.when;
import android.app.time.Capabilities.CapabilityState;
@@ -41,7 +42,6 @@ import android.app.time.TimeZoneCapabilitiesAndConfig;
import android.app.time.TimeZoneConfiguration;
import android.app.time.TimeZoneDetectorStatus;
import android.content.Context;
import android.location.LocationManager;
import android.os.UserHandle;
import com.android.settings.R;
@@ -60,8 +60,6 @@ import org.robolectric.RuntimeEnvironment;
public class LocationTimeZoneDetectionPreferenceControllerTest {
@Mock
private TimeManager mTimeManager;
@Mock
private LocationManager mLocationManager;
private Context mContext;
private LocationTimeZoneDetectionPreferenceController mController;
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
@@ -72,14 +70,16 @@ public class LocationTimeZoneDetectionPreferenceControllerTest {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
when(mContext.getSystemService(TimeManager.class)).thenReturn(mTimeManager);
when(mContext.getSystemService(LocationManager.class)).thenReturn(mLocationManager);
mController = new LocationTimeZoneDetectionPreferenceController(mContext);
mController.setFragment(mFragment);
}
@Test
public void setChecked_withTrue_shouldUpdateSetting_whenLocationIsEnabled() {
when(mLocationManager.isLocationEnabled()).thenReturn(true);
boolean useLocationEnabled = true;
TimeZoneCapabilitiesAndConfig capabilitiesAndConfig =
createTimeZoneCapabilitiesAndConfig(useLocationEnabled, CAPABILITY_POSSESSED);
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
// Simulate the UI being clicked.
mController.setChecked(true);
@@ -98,17 +98,25 @@ public class LocationTimeZoneDetectionPreferenceControllerTest {
@Test
public void setChecked_withTrue_shouldDoNothing_whenLocationIsDisabled() {
when(mLocationManager.isLocationEnabled()).thenReturn(false);
boolean useLocationEnabled = false;
TimeZoneCapabilitiesAndConfig capabilitiesAndConfig =
createTimeZoneCapabilitiesAndConfig(useLocationEnabled, CAPABILITY_POSSESSED);
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
// Simulate the UI being clicked.
mController.setChecked(true);
// Verify the TimeManager was not called.
verifyNoInteractions(mTimeManager);
// Verify the TimeManager was not updated.
verify(mTimeManager, never()).updateTimeZoneConfiguration(any());
}
@Test
public void setChecked_withFalse_shouldUpdateSetting() {
boolean useLocationEnabled = false;
TimeZoneCapabilitiesAndConfig capabilitiesAndConfig =
createTimeZoneCapabilitiesAndConfig(useLocationEnabled, CAPABILITY_POSSESSED);
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
// Simulate the UI being clicked.
mController.setChecked(false);
@@ -121,8 +129,9 @@ public class LocationTimeZoneDetectionPreferenceControllerTest {
@Test
public void testLocationTimeZoneDetection_supported_shouldBeShown() {
boolean useLocationEnabled = false;
TimeZoneCapabilitiesAndConfig capabilitiesAndConfig =
createTimeZoneCapabilitiesAndConfig(CAPABILITY_POSSESSED);
createTimeZoneCapabilitiesAndConfig(useLocationEnabled, CAPABILITY_POSSESSED);
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
assertThat(mController.isAvailable()).isTrue();
@@ -130,8 +139,9 @@ public class LocationTimeZoneDetectionPreferenceControllerTest {
@Test
public void testLocationTimeZoneDetection_unsupported_shouldNotBeShown() {
TimeZoneCapabilitiesAndConfig capabilitiesAndConfig =
createTimeZoneCapabilitiesAndConfig(CAPABILITY_NOT_SUPPORTED);
boolean useLocationEnabled = false;
TimeZoneCapabilitiesAndConfig capabilitiesAndConfig = createTimeZoneCapabilitiesAndConfig(
useLocationEnabled, CAPABILITY_NOT_SUPPORTED);
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
assertThat(mController.isAvailable()).isFalse();
@@ -142,8 +152,9 @@ public class LocationTimeZoneDetectionPreferenceControllerTest {
*/
@Test
public void testLocationTimeZoneDetection_summary_geoDetectionEnabled() {
boolean useLocationEnabled = false;
TimeZoneCapabilitiesAndConfig capabilitiesAndConfig =
createTimeZoneCapabilitiesAndConfig(CAPABILITY_POSSESSED);
createTimeZoneCapabilitiesAndConfig(useLocationEnabled, CAPABILITY_POSSESSED);
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
assertThat(mController.getSummary()).isEqualTo(
@@ -152,11 +163,11 @@ public class LocationTimeZoneDetectionPreferenceControllerTest {
@Test
public void testLocationTimeZoneDetection_toggleIsOn_whenGeoDetectionEnabledAnsMlsIsOff() {
TimeZoneCapabilitiesAndConfig capabilitiesAndConfig =
createTimeZoneCapabilitiesAndConfig(CAPABILITY_NOT_APPLICABLE);
boolean useLocationEnabled = false;
TimeZoneCapabilitiesAndConfig capabilitiesAndConfig = createTimeZoneCapabilitiesAndConfig(
useLocationEnabled, CAPABILITY_NOT_APPLICABLE);
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
when(mLocationManager.isLocationEnabled()).thenReturn(false);
assertThat(mController.isChecked()).isTrue();
assertThat(mController.getSummary()).isEqualTo(
@@ -164,6 +175,7 @@ public class LocationTimeZoneDetectionPreferenceControllerTest {
}
private static TimeZoneCapabilitiesAndConfig createTimeZoneCapabilitiesAndConfig(
boolean useLocationEnabled,
@CapabilityState int configureGeoDetectionEnabledCapability) {
// Create a status that matches the user's capability state.
@@ -191,6 +203,7 @@ public class LocationTimeZoneDetectionPreferenceControllerTest {
UserHandle arbitraryUserHandle = UserHandle.of(123);
TimeZoneCapabilities capabilities = new TimeZoneCapabilities.Builder(arbitraryUserHandle)
.setConfigureAutoDetectionEnabledCapability(CAPABILITY_POSSESSED)
.setUseLocationEnabled(useLocationEnabled)
.setConfigureGeoDetectionEnabledCapability(configureGeoDetectionEnabledCapability)
.setSetManualTimeZoneCapability(CAPABILITY_NOT_APPLICABLE)
.build();

View File

@@ -112,8 +112,10 @@ public class TimeZonePreferenceControllerTest {
PROVIDER_STATUS_NOT_PRESENT, null));
int suggestManualCapability = suggestManualAllowed ? Capabilities.CAPABILITY_POSSESSED
: Capabilities.CAPABILITY_NOT_SUPPORTED;
boolean useLocationEnabled = true;
TimeZoneCapabilities capabilities = new TimeZoneCapabilities.Builder(UserHandle.SYSTEM)
.setConfigureAutoDetectionEnabledCapability(Capabilities.CAPABILITY_POSSESSED)
.setUseLocationEnabled(useLocationEnabled)
.setConfigureGeoDetectionEnabledCapability(Capabilities.CAPABILITY_NOT_SUPPORTED)
.setSetManualTimeZoneCapability(suggestManualCapability)
.build();