Change high/low bound logic for manual date/time
This commit moves knowledge of the upper / lower bounds for valid manual date suggestions to (internal) API calls. It adds a test to confirm the API calls are used to configure the date dialog. Further, it removes redundant filtering from the client that would prevent suggestion calls being made if the settings UI considers them invalid. Year bounds are already used to limit the UI entry, and the system server will return false from the service call if the suggestion is invalid, though the SettingsUI doesn't do anything (behaviorally) with the false before or after this change. After this change it is logged. The goal of this change is to allow users with devices that don't have the Y2038 issue to enter dates > 2037. This could have been done with a smaller change, but the use of the new internal class TimeDetectorHelper means that the bounds logic is in one place. The lower bound (on mobile devices) can now be changed relatively easily by touching one class. Bug: 228967927 Test: m RunSettingsRoboTests ROBOTEST_FILTER="com.android.settings.datetime" Change-Id: Iaf1ca8220e0e96773aa71b595da9c1ba1e50d59d
This commit is contained in:
@@ -18,15 +18,19 @@ package com.android.settings.datetime;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.DatePickerDialog;
|
||||
import android.app.time.Capabilities;
|
||||
import android.app.time.TimeCapabilities;
|
||||
import android.app.time.TimeCapabilitiesAndConfig;
|
||||
import android.app.time.TimeConfiguration;
|
||||
import android.app.time.TimeManager;
|
||||
import android.app.timedetector.TimeDetector;
|
||||
import android.app.timedetector.TimeDetectorHelper;
|
||||
import android.content.Context;
|
||||
import android.os.UserHandle;
|
||||
|
||||
@@ -40,17 +44,20 @@ import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.GregorianCalendar;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class DatePreferenceControllerTest {
|
||||
|
||||
@Mock
|
||||
private Context mContext;
|
||||
@Mock
|
||||
private TimeDetector mTimeDetector;
|
||||
private DatePreferenceController.DatePreferenceHost mHost;
|
||||
@Mock
|
||||
private TimeManager mTimeManager;
|
||||
@Mock
|
||||
private DatePreferenceController.DatePreferenceHost mHost;
|
||||
private TimeDetector mTimeDetector;
|
||||
|
||||
private RestrictedPreference mPreference;
|
||||
private DatePreferenceController mController;
|
||||
@@ -114,6 +121,26 @@ public class DatePreferenceControllerTest {
|
||||
verify(mHost).showDatePicker();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildDatePicker() {
|
||||
TimeDetectorHelper timeDetectorHelper = mock(TimeDetectorHelper.class);
|
||||
when(timeDetectorHelper.getManualDateSelectionYearMin()).thenReturn(2015);
|
||||
when(timeDetectorHelper.getManualDateSelectionYearMax()).thenReturn(2020);
|
||||
|
||||
Context context = RuntimeEnvironment.application;
|
||||
DatePickerDialog dialog = mController.buildDatePicker(context, timeDetectorHelper);
|
||||
|
||||
GregorianCalendar calendar = new GregorianCalendar();
|
||||
|
||||
long minDate = dialog.getDatePicker().getMinDate();
|
||||
calendar.setTimeInMillis(minDate);
|
||||
assertEquals(2015, calendar.get(Calendar.YEAR));
|
||||
|
||||
long maxDate = dialog.getDatePicker().getMaxDate();
|
||||
calendar.setTimeInMillis(maxDate);
|
||||
assertEquals(2020, calendar.get(Calendar.YEAR));
|
||||
}
|
||||
|
||||
private static TimeCapabilitiesAndConfig createCapabilitiesAndConfig(
|
||||
boolean suggestManualAllowed) {
|
||||
int suggestManualCapability = suggestManualAllowed ? Capabilities.CAPABILITY_POSSESSED
|
||||
|
Reference in New Issue
Block a user