Merge "Updated toggles in Date and time settings page" into main
This commit is contained in:
committed by
Android (Google) Code Review
commit
d7f7417a1e
@@ -40,12 +40,17 @@ import android.app.time.TimeZoneConfiguration;
|
||||
import android.app.time.TimeZoneDetectorStatus;
|
||||
import android.content.Context;
|
||||
import android.os.UserHandle;
|
||||
import android.platform.test.annotations.DisableFlags;
|
||||
import android.platform.test.annotations.EnableFlags;
|
||||
import android.platform.test.flag.junit.SetFlagsRule;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.flags.Flags;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
@@ -57,6 +62,9 @@ import org.robolectric.RuntimeEnvironment;
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class AutoTimeZonePreferenceControllerTest {
|
||||
|
||||
@Rule
|
||||
public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
|
||||
|
||||
@Mock
|
||||
private UpdateTimeAndDateCallback mCallback;
|
||||
private Context mContext;
|
||||
@@ -238,8 +246,53 @@ public class AutoTimeZonePreferenceControllerTest {
|
||||
mContext.getString(R.string.auto_zone_requires_location_summary));
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnableFlags({Flags.FLAG_REVAMP_TOGGLES})
|
||||
public void toggleOff_revampFlagOn_shouldToggleOffUseLocation() {
|
||||
TimeZoneCapabilitiesAndConfig capabilitiesAndConfig = createCapabilitiesAndConfig(
|
||||
/* autoSupported= */ true,
|
||||
/* autoEnabled= */ true,
|
||||
/* telephonySupported= */ true,
|
||||
/* locationSupported= */ true);
|
||||
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
|
||||
|
||||
mController.setChecked(false);
|
||||
|
||||
TimeZoneConfiguration configuration = new TimeZoneConfiguration.Builder()
|
||||
.setAutoDetectionEnabled(false)
|
||||
.setGeoDetectionEnabled(false)
|
||||
.build();
|
||||
|
||||
verify(mTimeManager).updateTimeZoneConfiguration(configuration);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisableFlags({Flags.FLAG_REVAMP_TOGGLES})
|
||||
public void toggleOff_revampFlagOff_shouldToggleOffUseLocation() {
|
||||
TimeZoneCapabilitiesAndConfig capabilitiesAndConfig = createCapabilitiesAndConfig(
|
||||
/* autoSupported= */ true,
|
||||
/* autoEnabled= */ true,
|
||||
/* telephonySupported= */ true,
|
||||
/* locationSupported= */ true);
|
||||
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
|
||||
|
||||
mController.setChecked(false);
|
||||
|
||||
TimeZoneConfiguration configuration = new TimeZoneConfiguration.Builder()
|
||||
.setAutoDetectionEnabled(false)
|
||||
.build();
|
||||
|
||||
verify(mTimeManager).updateTimeZoneConfiguration(configuration);
|
||||
}
|
||||
|
||||
private static TimeZoneCapabilitiesAndConfig createCapabilitiesAndConfig(
|
||||
boolean autoSupported, boolean autoEnabled, boolean telephonySupported) {
|
||||
return createCapabilitiesAndConfig(autoSupported, autoEnabled, telephonySupported, false);
|
||||
}
|
||||
|
||||
private static TimeZoneCapabilitiesAndConfig createCapabilitiesAndConfig(
|
||||
boolean autoSupported, boolean autoEnabled, boolean telephonySupported,
|
||||
boolean locationSupported) {
|
||||
TimeZoneDetectorStatus status = new TimeZoneDetectorStatus(DETECTOR_STATUS_RUNNING,
|
||||
new TelephonyTimeZoneAlgorithmStatus(
|
||||
telephonySupported ? DETECTION_ALGORITHM_STATUS_RUNNING
|
||||
@@ -253,12 +306,14 @@ public class AutoTimeZonePreferenceControllerTest {
|
||||
TimeZoneCapabilities capabilities = new TimeZoneCapabilities.Builder(UserHandle.SYSTEM)
|
||||
.setConfigureAutoDetectionEnabledCapability(configureAutoDetectionEnabledCapability)
|
||||
.setUseLocationEnabled(true)
|
||||
.setConfigureGeoDetectionEnabledCapability(Capabilities.CAPABILITY_NOT_SUPPORTED)
|
||||
.setConfigureGeoDetectionEnabledCapability(
|
||||
locationSupported ? Capabilities.CAPABILITY_POSSESSED
|
||||
: Capabilities.CAPABILITY_NOT_SUPPORTED)
|
||||
.setSetManualTimeZoneCapability(Capabilities.CAPABILITY_POSSESSED)
|
||||
.build();
|
||||
TimeZoneConfiguration config = new TimeZoneConfiguration.Builder()
|
||||
.setAutoDetectionEnabled(autoEnabled)
|
||||
.setGeoDetectionEnabled(false)
|
||||
.setGeoDetectionEnabled(locationSupported)
|
||||
.build();
|
||||
return new TimeZoneCapabilitiesAndConfig(status, capabilities, config);
|
||||
}
|
||||
|
@@ -25,6 +25,8 @@ import static android.app.time.DetectorStatusTypes.DETECTOR_STATUS_RUNNING;
|
||||
import static android.app.time.LocationTimeZoneAlgorithmStatus.PROVIDER_STATUS_NOT_PRESENT;
|
||||
import static android.app.time.LocationTimeZoneAlgorithmStatus.PROVIDER_STATUS_NOT_READY;
|
||||
|
||||
import static com.android.settings.core.BasePreferenceController.DISABLED_DEPENDENT_SETTING;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
@@ -43,11 +45,17 @@ import android.app.time.TimeZoneConfiguration;
|
||||
import android.app.time.TimeZoneDetectorStatus;
|
||||
import android.content.Context;
|
||||
import android.os.UserHandle;
|
||||
import android.platform.test.annotations.EnableFlags;
|
||||
import android.platform.test.flag.junit.SetFlagsRule;
|
||||
|
||||
import androidx.preference.SwitchPreference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.InstrumentedPreferenceFragment;
|
||||
import com.android.settings.flags.Flags;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Answers;
|
||||
@@ -62,9 +70,14 @@ import org.robolectric.annotation.Config;
|
||||
com.android.settings.testutils.shadow.ShadowFragment.class,
|
||||
})
|
||||
public class LocationTimeZoneDetectionPreferenceControllerTest {
|
||||
|
||||
@Rule
|
||||
public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
|
||||
|
||||
@Mock
|
||||
private TimeManager mTimeManager;
|
||||
private Context mContext;
|
||||
private SwitchPreference mPreference;
|
||||
private LocationTimeZoneDetectionPreferenceController mController;
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private InstrumentedPreferenceFragment mFragment;
|
||||
@@ -76,6 +89,9 @@ public class LocationTimeZoneDetectionPreferenceControllerTest {
|
||||
when(mContext.getSystemService(TimeManager.class)).thenReturn(mTimeManager);
|
||||
mController = new LocationTimeZoneDetectionPreferenceController(mContext);
|
||||
mController.setFragment(mFragment);
|
||||
|
||||
mPreference = new SwitchPreference(mContext);
|
||||
mPreference.setKey("location_time_zone_detection");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -114,6 +130,17 @@ public class LocationTimeZoneDetectionPreferenceControllerTest {
|
||||
verify(mTimeManager, never()).updateTimeZoneConfiguration(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnableFlags({Flags.FLAG_REVAMP_TOGGLES})
|
||||
public void flagRevampTogglesOn_toggleOff_automaticTimeZone_disablesLocationToggle() {
|
||||
TimeZoneCapabilitiesAndConfig capabilitiesAndConfig =
|
||||
createTimeZoneCapabilitiesAndConfig(/* useLocationEnabled= */ true,
|
||||
CAPABILITY_POSSESSED, /* setAutoDetectionEnabled= */ false);
|
||||
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(DISABLED_DEPENDENT_SETTING);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setChecked_withFalse_shouldUpdateSetting() {
|
||||
boolean useLocationEnabled = false;
|
||||
@@ -181,7 +208,14 @@ public class LocationTimeZoneDetectionPreferenceControllerTest {
|
||||
private static TimeZoneCapabilitiesAndConfig createTimeZoneCapabilitiesAndConfig(
|
||||
boolean useLocationEnabled,
|
||||
@CapabilityState int configureGeoDetectionEnabledCapability) {
|
||||
return createTimeZoneCapabilitiesAndConfig(useLocationEnabled,
|
||||
configureGeoDetectionEnabledCapability, /* setAutoDetectionEnabled= */ true);
|
||||
}
|
||||
|
||||
private static TimeZoneCapabilitiesAndConfig createTimeZoneCapabilitiesAndConfig(
|
||||
boolean useLocationEnabled,
|
||||
@CapabilityState int configureGeoDetectionEnabledCapability,
|
||||
boolean setAutoDetectionEnabled) {
|
||||
// Create a status that matches the user's capability state.
|
||||
LocationTimeZoneAlgorithmStatus locationAlgorithmStatus;
|
||||
switch (configureGeoDetectionEnabledCapability) {
|
||||
@@ -213,7 +247,7 @@ public class LocationTimeZoneDetectionPreferenceControllerTest {
|
||||
.build();
|
||||
|
||||
TimeZoneConfiguration configuration = new TimeZoneConfiguration.Builder()
|
||||
.setAutoDetectionEnabled(true)
|
||||
.setAutoDetectionEnabled(setAutoDetectionEnabled)
|
||||
.setGeoDetectionEnabled(true)
|
||||
.build();
|
||||
|
||||
|
@@ -23,11 +23,16 @@ import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.platform.test.annotations.DisableFlags;
|
||||
import android.platform.test.flag.junit.SetFlagsRule;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.preference.SwitchPreference;
|
||||
|
||||
import com.android.settings.flags.Flags;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
@@ -41,6 +46,9 @@ import java.util.List;
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class TimeFormatPreferenceControllerTest {
|
||||
|
||||
@Rule
|
||||
public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
|
||||
|
||||
@Mock
|
||||
private UpdateTimeAndDateCallback mCallback;
|
||||
|
||||
@@ -97,6 +105,7 @@ public class TimeFormatPreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisableFlags({Flags.FLAG_REVAMP_TOGGLES})
|
||||
public void updateState_autoSet_shouldNotEnablePreference() {
|
||||
Settings.System.putString(mContext.getContentResolver(), Settings.System.TIME_12_24, null);
|
||||
|
||||
|
Reference in New Issue
Block a user