Automatic timezone support on non-telephony devices

Adding to the Settings UI in order to simplify timezone on non-telephony devices.

Test: on-device testing, additional unit tests
Change-Id: I58ece9542a7b80823092bd082d4bd8c224b29634
Bug: 253015306
This commit is contained in:
David Gutierrez
2022-11-02 10:30:39 -05:00
parent b842f4c5fc
commit 9ebb2fce7a
6 changed files with 492 additions and 2 deletions

View File

@@ -16,6 +16,7 @@
package com.android.settings.datetime;
import static android.app.time.DetectorStatusTypes.DETECTION_ALGORITHM_STATUS_NOT_SUPPORTED;
import static android.app.time.DetectorStatusTypes.DETECTION_ALGORITHM_STATUS_RUNNING;
import static android.app.time.DetectorStatusTypes.DETECTOR_STATUS_RUNNING;
import static android.app.time.LocationTimeZoneAlgorithmStatus.PROVIDER_STATUS_NOT_PRESENT;
@@ -36,10 +37,13 @@ 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;
import com.android.settings.R;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -58,6 +62,8 @@ public class AutoTimeZonePreferenceControllerTest {
private Preference mPreference;
@Mock
private TimeManager mTimeManager;
@Mock
private LocationManager mLocationManager;
@Before
public void setUp() {
@@ -67,6 +73,9 @@ 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
@@ -221,10 +230,35 @@ public class AutoTimeZonePreferenceControllerTest {
assertThat(controller.isEnabled()).isFalse();
}
@Test
public void getSummary() {
AutoTimeZonePreferenceController controller = new AutoTimeZonePreferenceController(
mContext, mCallback, false /* fromSUW */);
TimeZoneCapabilitiesAndConfig capabilitiesAndConfig = createCapabilitiesAndConfig(
/* autoSupported= */true, /* autoEnabled= */true, /* telephonySupported= */
true);
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
when(mTimeManager.updateTimeZoneConfiguration(Mockito.any())).thenReturn(true);
assertThat(controller.getSummary()).isEqualTo("");
capabilitiesAndConfig = createCapabilitiesAndConfig(
/* autoSupported= */true, /* autoEnabled= */true, /* telephonySupported= */
false);
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
when(mTimeManager.updateTimeZoneConfiguration(Mockito.any())).thenReturn(true);
assertThat(controller.getSummary()).isEqualTo(
mContext.getString(R.string.auto_zone_requires_location_summary));
}
private static TimeZoneCapabilitiesAndConfig createCapabilitiesAndConfig(
boolean autoSupported, boolean autoEnabled) {
boolean autoSupported, boolean autoEnabled, boolean telephonySupported) {
TimeZoneDetectorStatus status = new TimeZoneDetectorStatus(DETECTOR_STATUS_RUNNING,
new TelephonyTimeZoneAlgorithmStatus(DETECTION_ALGORITHM_STATUS_RUNNING),
new TelephonyTimeZoneAlgorithmStatus(
telephonySupported ? DETECTION_ALGORITHM_STATUS_RUNNING
: DETECTION_ALGORITHM_STATUS_NOT_SUPPORTED),
new LocationTimeZoneAlgorithmStatus(DETECTION_ALGORITHM_STATUS_RUNNING,
PROVIDER_STATUS_NOT_READY, null,
PROVIDER_STATUS_NOT_PRESENT, null));
@@ -242,4 +276,9 @@ public class AutoTimeZonePreferenceControllerTest {
.build();
return new TimeZoneCapabilitiesAndConfig(status, capabilities, config);
}
private static TimeZoneCapabilitiesAndConfig createCapabilitiesAndConfig(
boolean autoSupported, boolean autoEnabled) {
return createCapabilitiesAndConfig(autoSupported, autoEnabled, false);
}
}