Merge "Refactor Date & Time Settings" into main
This commit is contained in:
@@ -24,19 +24,22 @@
|
|||||||
android:key="auto_time"
|
android:key="auto_time"
|
||||||
android:title="@string/date_time_auto"
|
android:title="@string/date_time_auto"
|
||||||
settings:useAdditionalSummary="true"
|
settings:useAdditionalSummary="true"
|
||||||
settings:userRestriction="no_config_date_time"/>
|
settings:userRestriction="no_config_date_time"
|
||||||
|
settings:controller="com.android.settings.datetime.AutoTimePreferenceController" />
|
||||||
|
|
||||||
<com.android.settingslib.RestrictedPreference
|
<com.android.settingslib.RestrictedPreference
|
||||||
android:key="date"
|
android:key="date"
|
||||||
android:title="@string/date_time_set_date_title"
|
android:title="@string/date_time_set_date_title"
|
||||||
android:summary="@string/summary_placeholder"
|
android:summary="@string/summary_placeholder"
|
||||||
settings:userRestriction="no_config_date_time"/>
|
settings:userRestriction="no_config_date_time"
|
||||||
|
settings:controller="com.android.settings.datetime.DatePreferenceController" />
|
||||||
|
|
||||||
<com.android.settingslib.RestrictedPreference
|
<com.android.settingslib.RestrictedPreference
|
||||||
android:key="time"
|
android:key="time"
|
||||||
android:title="@string/date_time_set_time_title"
|
android:title="@string/date_time_set_time_title"
|
||||||
android:summary="@string/summary_placeholder"
|
android:summary="@string/summary_placeholder"
|
||||||
settings:userRestriction="no_config_date_time"/>
|
settings:userRestriction="no_config_date_time"
|
||||||
|
settings:controller="com.android.settings.datetime.TimePreferenceController" />
|
||||||
|
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
android:key="timezone_preference_category"
|
android:key="timezone_preference_category"
|
||||||
@@ -45,7 +48,8 @@
|
|||||||
<com.android.settingslib.RestrictedSwitchPreference
|
<com.android.settingslib.RestrictedSwitchPreference
|
||||||
android:key="auto_zone"
|
android:key="auto_zone"
|
||||||
android:title="@string/zone_auto_title"
|
android:title="@string/zone_auto_title"
|
||||||
settings:userRestriction="no_config_date_time"/>
|
settings:userRestriction="no_config_date_time"
|
||||||
|
settings:controller="com.android.settings.datetime.AutoTimeZonePreferenceController" />
|
||||||
|
|
||||||
<com.android.settingslib.widget.BannerMessagePreference
|
<com.android.settingslib.widget.BannerMessagePreference
|
||||||
android:key="location_time_zone_detection_status"
|
android:key="location_time_zone_detection_status"
|
||||||
@@ -53,7 +57,7 @@
|
|||||||
settings:controller="com.android.settings.datetime.LocationProviderStatusPreferenceController"/>
|
settings:controller="com.android.settings.datetime.LocationProviderStatusPreferenceController"/>
|
||||||
|
|
||||||
<!-- This preference gets removed if location-based time zone detection is not supported -->
|
<!-- This preference gets removed if location-based time zone detection is not supported -->
|
||||||
<SwitchPreferenceCompat
|
<SwitchPreference
|
||||||
android:key="location_time_zone_detection"
|
android:key="location_time_zone_detection"
|
||||||
android:title="@string/location_time_zone_detection_toggle_title"
|
android:title="@string/location_time_zone_detection_toggle_title"
|
||||||
settings:controller="com.android.settings.datetime.LocationTimeZoneDetectionPreferenceController"/>
|
settings:controller="com.android.settings.datetime.LocationTimeZoneDetectionPreferenceController"/>
|
||||||
@@ -64,7 +68,8 @@
|
|||||||
android:summary="@string/summary_placeholder"
|
android:summary="@string/summary_placeholder"
|
||||||
android:fragment="com.android.settings.datetime.timezone.TimeZoneSettings"
|
android:fragment="com.android.settings.datetime.timezone.TimeZoneSettings"
|
||||||
settings:userRestriction="no_config_date_time"
|
settings:userRestriction="no_config_date_time"
|
||||||
settings:keywords="@string/keywords_time_zone"/>
|
settings:keywords="@string/keywords_time_zone"
|
||||||
|
settings:controller="com.android.settings.datetime.TimeZonePreferenceController" />
|
||||||
|
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
||||||
@@ -72,13 +77,15 @@
|
|||||||
android:key="time_format_preference_category"
|
android:key="time_format_preference_category"
|
||||||
android:title="@string/time_format_category_title"
|
android:title="@string/time_format_category_title"
|
||||||
settings:keywords="@string/keywords_time_format">
|
settings:keywords="@string/keywords_time_format">
|
||||||
<SwitchPreferenceCompat
|
<SwitchPreference
|
||||||
android:key="auto_24hour"
|
android:key="auto_24hour"
|
||||||
android:title="@string/date_time_24hour_auto"/>
|
android:title="@string/date_time_24hour_auto"
|
||||||
|
settings:controller="com.android.settings.datetime.AutoTimeFormatPreferenceController" />
|
||||||
|
|
||||||
<SwitchPreferenceCompat
|
<SwitchPreference
|
||||||
android:key="24 hour"
|
android:key="24 hour"
|
||||||
android:title="@string/date_time_24hour" />
|
android:title="@string/date_time_24hour"
|
||||||
|
settings:controller="com.android.settings.datetime.TimeFormatPreferenceController" />
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
|
@@ -19,53 +19,33 @@ package com.android.settings.datetime;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.provider.Settings.System;
|
import android.provider.Settings.System;
|
||||||
import android.text.TextUtils;
|
|
||||||
import android.text.format.DateFormat;
|
import android.text.format.DateFormat;
|
||||||
|
|
||||||
import androidx.preference.Preference;
|
import com.android.settings.R;
|
||||||
import androidx.preference.TwoStatePreference;
|
import com.android.settings.core.TogglePreferenceController;
|
||||||
|
|
||||||
import com.android.settings.core.PreferenceControllerMixin;
|
|
||||||
import com.android.settingslib.core.AbstractPreferenceController;
|
|
||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
public class AutoTimeFormatPreferenceController extends AbstractPreferenceController
|
public class AutoTimeFormatPreferenceController extends TogglePreferenceController {
|
||||||
implements PreferenceControllerMixin {
|
|
||||||
|
|
||||||
private static final String KEY_AUTO_24_HOUR = "auto_24hour";
|
public AutoTimeFormatPreferenceController(Context context, String preferenceKey) {
|
||||||
|
super(context, preferenceKey);
|
||||||
public AutoTimeFormatPreferenceController(Context context, UpdateTimeAndDateCallback callback) {
|
|
||||||
super(context);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAvailable() {
|
public int getAvailabilityStatus() {
|
||||||
return true;
|
return AVAILABLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPreferenceKey() {
|
public boolean isChecked() {
|
||||||
return KEY_AUTO_24_HOUR;
|
return isAutoTimeFormatSelection(mContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateState(Preference preference) {
|
public boolean setChecked(boolean isChecked) {
|
||||||
if (!(preference instanceof TwoStatePreference)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
((TwoStatePreference) preference).setChecked(isAutoTimeFormatSelection(mContext));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean handlePreferenceTreeClick(Preference preference) {
|
|
||||||
if (!(preference instanceof TwoStatePreference)
|
|
||||||
|| !TextUtils.equals(KEY_AUTO_24_HOUR, preference.getKey())) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
boolean auto24HourEnabled = ((TwoStatePreference) preference).isChecked();
|
|
||||||
Boolean is24Hour;
|
Boolean is24Hour;
|
||||||
if (auto24HourEnabled) {
|
if (isChecked) {
|
||||||
is24Hour = null;
|
is24Hour = null;
|
||||||
} else {
|
} else {
|
||||||
is24Hour = is24HourLocale(mContext.getResources().getConfiguration().locale);
|
is24Hour = is24HourLocale(mContext.getResources().getConfiguration().locale);
|
||||||
@@ -74,6 +54,11 @@ public class AutoTimeFormatPreferenceController extends AbstractPreferenceContro
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getSliceHighlightMenuRes() {
|
||||||
|
return R.string.menu_key_system;
|
||||||
|
}
|
||||||
|
|
||||||
boolean is24HourLocale(Locale locale) {
|
boolean is24HourLocale(Locale locale) {
|
||||||
return DateFormat.is24HourLocale(locale);
|
return DateFormat.is24HourLocale(locale);
|
||||||
}
|
}
|
||||||
|
@@ -27,28 +27,26 @@ import android.app.time.TimeConfiguration;
|
|||||||
import android.app.time.TimeManager;
|
import android.app.time.TimeManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
import androidx.preference.Preference;
|
|
||||||
import androidx.preference.TwoStatePreference;
|
|
||||||
|
|
||||||
import com.android.internal.annotations.VisibleForTesting;
|
import com.android.internal.annotations.VisibleForTesting;
|
||||||
import com.android.settings.core.PreferenceControllerMixin;
|
import com.android.settings.R;
|
||||||
import com.android.settingslib.core.AbstractPreferenceController;
|
import com.android.settings.core.TogglePreferenceController;
|
||||||
|
|
||||||
public class AutoTimePreferenceController extends AbstractPreferenceController
|
public class AutoTimePreferenceController extends TogglePreferenceController {
|
||||||
implements PreferenceControllerMixin, Preference.OnPreferenceChangeListener {
|
|
||||||
|
|
||||||
private static final String KEY_AUTO_TIME = "auto_time";
|
private UpdateTimeAndDateCallback mCallback;
|
||||||
private final UpdateTimeAndDateCallback mCallback;
|
|
||||||
private final TimeManager mTimeManager;
|
private final TimeManager mTimeManager;
|
||||||
|
|
||||||
public AutoTimePreferenceController(Context context, UpdateTimeAndDateCallback callback) {
|
public AutoTimePreferenceController(Context context, String preferenceKey) {
|
||||||
super(context);
|
super(context, preferenceKey);
|
||||||
mTimeManager = context.getSystemService(TimeManager.class);
|
mTimeManager = context.getSystemService(TimeManager.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDateAndTimeCallback(UpdateTimeAndDateCallback callback) {
|
||||||
mCallback = callback;
|
mCallback = callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAvailable() {
|
public int getAvailabilityStatus() {
|
||||||
TimeCapabilities timeCapabilities =
|
TimeCapabilities timeCapabilities =
|
||||||
getTimeCapabilitiesAndConfig().getCapabilities();
|
getTimeCapabilitiesAndConfig().getCapabilities();
|
||||||
int capability = timeCapabilities.getConfigureAutoDetectionEnabledCapability();
|
int capability = timeCapabilities.getConfigureAutoDetectionEnabledCapability();
|
||||||
@@ -57,43 +55,31 @@ public class AutoTimePreferenceController extends AbstractPreferenceController
|
|||||||
// This method handles the "is visible?" check.
|
// This method handles the "is visible?" check.
|
||||||
switch (capability) {
|
switch (capability) {
|
||||||
case CAPABILITY_NOT_SUPPORTED:
|
case CAPABILITY_NOT_SUPPORTED:
|
||||||
return false;
|
return DISABLED_DEPENDENT_SETTING;
|
||||||
case CAPABILITY_POSSESSED:
|
case CAPABILITY_POSSESSED:
|
||||||
return true;
|
|
||||||
case CAPABILITY_NOT_ALLOWED:
|
case CAPABILITY_NOT_ALLOWED:
|
||||||
// This case is expected for enterprise restrictions, where the toggle should be
|
// This case is expected for enterprise restrictions, where the toggle should be
|
||||||
// present but disabled. Disabling is handled declaratively via the
|
// present but disabled. Disabling is handled declaratively via the
|
||||||
// settings:userRestriction attribute in .xml. The client-side logic is expected to
|
// settings:userRestriction attribute in .xml. The client-side logic is expected to
|
||||||
// concur with the capabilities logic in the system server.
|
// concur with the capabilities logic in the system server.
|
||||||
return true;
|
|
||||||
case CAPABILITY_NOT_APPLICABLE:
|
case CAPABILITY_NOT_APPLICABLE:
|
||||||
// CAPABILITY_NOT_APPLICABLE is not currently expected, so this is return value is
|
// CAPABILITY_NOT_APPLICABLE is not currently expected, so this is return value is
|
||||||
// arbitrary.
|
// arbitrary.
|
||||||
return true;
|
return AVAILABLE;
|
||||||
default:
|
default:
|
||||||
throw new IllegalStateException("Unknown capability=" + capability);
|
throw new IllegalStateException("Unknown capability=" + capability);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateState(Preference preference) {
|
public boolean isChecked() {
|
||||||
if (!(preference instanceof TwoStatePreference)) {
|
return isEnabled();
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
((TwoStatePreference) preference).setChecked(isEnabled());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPreferenceKey() {
|
public boolean setChecked(boolean isChecked) {
|
||||||
return KEY_AUTO_TIME;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
|
||||||
boolean autoTimeEnabled = (Boolean) newValue;
|
|
||||||
TimeConfiguration configuration = new TimeConfiguration.Builder()
|
TimeConfiguration configuration = new TimeConfiguration.Builder()
|
||||||
.setAutoDetectionEnabled(autoTimeEnabled)
|
.setAutoDetectionEnabled(isChecked)
|
||||||
.build();
|
.build();
|
||||||
boolean result = mTimeManager.updateTimeConfiguration(configuration);
|
boolean result = mTimeManager.updateTimeConfiguration(configuration);
|
||||||
|
|
||||||
@@ -101,6 +87,11 @@ public class AutoTimePreferenceController extends AbstractPreferenceController
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getSliceHighlightMenuRes() {
|
||||||
|
return R.string.menu_key_system;
|
||||||
|
}
|
||||||
|
|
||||||
/** Returns whether the preference should be "checked", i.e. set to the "on" position. */
|
/** Returns whether the preference should be "checked", i.e. set to the "on" position. */
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public boolean isEnabled() {
|
public boolean isEnabled() {
|
||||||
|
@@ -27,36 +27,42 @@ import android.app.time.TimeZoneCapabilitiesAndConfig;
|
|||||||
import android.app.time.TimeZoneConfiguration;
|
import android.app.time.TimeZoneConfiguration;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
import androidx.preference.Preference;
|
|
||||||
import androidx.preference.PreferenceScreen;
|
|
||||||
import androidx.preference.TwoStatePreference;
|
|
||||||
|
|
||||||
import com.android.internal.annotations.VisibleForTesting;
|
import com.android.internal.annotations.VisibleForTesting;
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.core.PreferenceControllerMixin;
|
import com.android.settings.core.TogglePreferenceController;
|
||||||
import com.android.settingslib.core.AbstractPreferenceController;
|
|
||||||
|
|
||||||
public class AutoTimeZonePreferenceController extends AbstractPreferenceController
|
public class AutoTimeZonePreferenceController extends TogglePreferenceController {
|
||||||
implements PreferenceControllerMixin, Preference.OnPreferenceChangeListener {
|
|
||||||
|
|
||||||
private static final String KEY_AUTO_TIME_ZONE = "auto_zone";
|
private boolean mIsFromSUW;
|
||||||
|
private UpdateTimeAndDateCallback mCallback;
|
||||||
private final boolean mIsFromSUW;
|
|
||||||
private final UpdateTimeAndDateCallback mCallback;
|
|
||||||
private final TimeManager mTimeManager;
|
private final TimeManager mTimeManager;
|
||||||
|
|
||||||
public AutoTimeZonePreferenceController(Context context, UpdateTimeAndDateCallback callback,
|
public AutoTimeZonePreferenceController(Context context, String preferenceKey) {
|
||||||
boolean isFromSUW) {
|
super(context, preferenceKey);
|
||||||
super(context);
|
|
||||||
mTimeManager = context.getSystemService(TimeManager.class);
|
mTimeManager = context.getSystemService(TimeManager.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the Time and Date callback
|
||||||
|
*/
|
||||||
|
public AutoTimeZonePreferenceController setTimeAndDateCallback(
|
||||||
|
UpdateTimeAndDateCallback callback) {
|
||||||
mCallback = callback;
|
mCallback = callback;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set if current fragment is launched via SUW
|
||||||
|
*/
|
||||||
|
public AutoTimeZonePreferenceController setFromSUW(boolean isFromSUW) {
|
||||||
mIsFromSUW = isFromSUW;
|
mIsFromSUW = isFromSUW;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAvailable() {
|
public int getAvailabilityStatus() {
|
||||||
if (mIsFromSUW) {
|
if (mIsFromSUW) {
|
||||||
return false;
|
return DISABLED_DEPENDENT_SETTING;
|
||||||
}
|
}
|
||||||
|
|
||||||
TimeZoneCapabilities timeZoneCapabilities =
|
TimeZoneCapabilities timeZoneCapabilities =
|
||||||
@@ -67,43 +73,31 @@ public class AutoTimeZonePreferenceController extends AbstractPreferenceControll
|
|||||||
// This method handles the "is visible?" check.
|
// This method handles the "is visible?" check.
|
||||||
switch (capability) {
|
switch (capability) {
|
||||||
case CAPABILITY_NOT_SUPPORTED:
|
case CAPABILITY_NOT_SUPPORTED:
|
||||||
return false;
|
return DISABLED_DEPENDENT_SETTING;
|
||||||
case CAPABILITY_POSSESSED:
|
case CAPABILITY_POSSESSED:
|
||||||
return true;
|
|
||||||
case CAPABILITY_NOT_ALLOWED:
|
case CAPABILITY_NOT_ALLOWED:
|
||||||
// This case is expected for enterprise restrictions, where the toggle should be
|
// This case is expected for enterprise restrictions, where the toggle should be
|
||||||
// present but disabled. Disabling is handled declaratively via the
|
// present but disabled. Disabling is handled declaratively via the
|
||||||
// settings:userRestriction attribute in .xml. The client-side logic is expected to
|
// settings:userRestriction attribute in .xml. The client-side logic is expected to
|
||||||
// concur with the capabilities logic in the system server.
|
// concur with the capabilities logic in the system server.
|
||||||
return true;
|
|
||||||
case CAPABILITY_NOT_APPLICABLE:
|
case CAPABILITY_NOT_APPLICABLE:
|
||||||
// CAPABILITY_NOT_APPLICABLE is not currently expected, so this is return value is
|
// CAPABILITY_NOT_APPLICABLE is not currently expected, so this is return value is
|
||||||
// arbitrary.
|
// arbitrary.
|
||||||
return true;
|
return AVAILABLE;
|
||||||
default:
|
default:
|
||||||
throw new IllegalStateException("Unknown capability=" + capability);
|
throw new IllegalStateException("Unknown capability=" + capability);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPreferenceKey() {
|
public boolean isChecked() {
|
||||||
return KEY_AUTO_TIME_ZONE;
|
return isEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateState(Preference preference) {
|
public boolean setChecked(boolean isChecked) {
|
||||||
if (!(preference instanceof TwoStatePreference)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
((TwoStatePreference) preference).setChecked(isEnabled());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
|
||||||
boolean autoZoneEnabled = (Boolean) newValue;
|
|
||||||
TimeZoneConfiguration configuration = new TimeZoneConfiguration.Builder()
|
TimeZoneConfiguration configuration = new TimeZoneConfiguration.Builder()
|
||||||
.setAutoDetectionEnabled(autoZoneEnabled)
|
.setAutoDetectionEnabled(isChecked)
|
||||||
.build();
|
.build();
|
||||||
boolean result = mTimeManager.updateTimeZoneConfiguration(configuration);
|
boolean result = mTimeManager.updateTimeZoneConfiguration(configuration);
|
||||||
|
|
||||||
@@ -111,6 +105,11 @@ public class AutoTimeZonePreferenceController extends AbstractPreferenceControll
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getSliceHighlightMenuRes() {
|
||||||
|
return R.string.menu_key_system;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CharSequence getSummary() {
|
public CharSequence getSummary() {
|
||||||
// If auto time zone cannot enable telephony fallback and is capable of location, then auto
|
// If auto time zone cannot enable telephony fallback and is capable of location, then auto
|
||||||
@@ -124,12 +123,6 @@ public class AutoTimeZonePreferenceController extends AbstractPreferenceControll
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void displayPreference(PreferenceScreen screen) {
|
|
||||||
super.displayPreference(screen);
|
|
||||||
refreshSummary(screen.findPreference(getPreferenceKey()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
boolean isEnabled() {
|
boolean isEnabled() {
|
||||||
TimeZoneConfiguration config = getTimeZoneCapabilitiesAndConfig().getConfiguration();
|
TimeZoneConfiguration config = getTimeZoneCapabilitiesAndConfig().getConfiguration();
|
||||||
|
@@ -33,14 +33,12 @@ import android.widget.DatePicker;
|
|||||||
import androidx.annotation.VisibleForTesting;
|
import androidx.annotation.VisibleForTesting;
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
|
|
||||||
import com.android.settings.core.PreferenceControllerMixin;
|
import com.android.settings.core.BasePreferenceController;
|
||||||
import com.android.settingslib.RestrictedPreference;
|
|
||||||
import com.android.settingslib.core.AbstractPreferenceController;
|
|
||||||
|
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
|
|
||||||
public class DatePreferenceController extends AbstractPreferenceController
|
public class DatePreferenceController extends BasePreferenceController
|
||||||
implements PreferenceControllerMixin, DatePickerDialog.OnDateSetListener {
|
implements DatePickerDialog.OnDateSetListener {
|
||||||
|
|
||||||
public interface DatePreferenceHost extends UpdateTimeAndDateCallback {
|
public interface DatePreferenceHost extends UpdateTimeAndDateCallback {
|
||||||
void showDatePicker();
|
void showDatePicker();
|
||||||
@@ -49,49 +47,45 @@ public class DatePreferenceController extends AbstractPreferenceController
|
|||||||
public static final int DIALOG_DATEPICKER = 0;
|
public static final int DIALOG_DATEPICKER = 0;
|
||||||
|
|
||||||
private static final String TAG = "DatePreferenceController";
|
private static final String TAG = "DatePreferenceController";
|
||||||
private static final String KEY_DATE = "date";
|
|
||||||
|
|
||||||
private final DatePreferenceHost mHost;
|
private DatePreferenceHost mHost;
|
||||||
private final TimeManager mTimeManager;
|
private final TimeManager mTimeManager;
|
||||||
|
|
||||||
public DatePreferenceController(Context context, DatePreferenceHost host) {
|
public DatePreferenceController(Context context, String preferenceKey) {
|
||||||
super(context);
|
super(context, preferenceKey);
|
||||||
mHost = host;
|
|
||||||
mTimeManager = context.getSystemService(TimeManager.class);
|
mTimeManager = context.getSystemService(TimeManager.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setHost(DatePreferenceHost host) {
|
||||||
|
mHost = host;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAvailable() {
|
public int getAvailabilityStatus() {
|
||||||
return true;
|
return isEnabled() ? AVAILABLE : DISABLED_DEPENDENT_SETTING;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateState(Preference preference) {
|
public void updateState(Preference preference) {
|
||||||
if (!(preference instanceof RestrictedPreference)) {
|
super.updateState(preference);
|
||||||
return;
|
preference.setEnabled(isEnabled());
|
||||||
}
|
}
|
||||||
final Calendar now = Calendar.getInstance();
|
|
||||||
preference.setSummary(DateFormat.getLongDateFormat(mContext).format(now.getTime()));
|
@Override
|
||||||
if (!((RestrictedPreference) preference).isDisabledByAdmin()) {
|
public CharSequence getSummary() {
|
||||||
boolean enableManualDateSelection = isEnabled();
|
Calendar now = Calendar.getInstance();
|
||||||
preference.setEnabled(enableManualDateSelection);
|
return DateFormat.getLongDateFormat(mContext).format(now.getTime());
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean handlePreferenceTreeClick(Preference preference) {
|
public boolean handlePreferenceTreeClick(Preference preference) {
|
||||||
if (!TextUtils.equals(preference.getKey(), KEY_DATE)) {
|
if (!TextUtils.equals(getPreferenceKey(), preference.getKey())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
mHost.showDatePicker();
|
mHost.showDatePicker();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getPreferenceKey() {
|
|
||||||
return KEY_DATE;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDateSet(DatePicker view, int year, int month, int day) {
|
public void onDateSet(DatePicker view, int year, int month, int day) {
|
||||||
setDate(year, month, day);
|
setDate(year, month, day);
|
||||||
|
@@ -16,21 +16,17 @@
|
|||||||
|
|
||||||
package com.android.settings.datetime;
|
package com.android.settings.datetime;
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.app.settings.SettingsEnums;
|
import android.app.settings.SettingsEnums;
|
||||||
import android.app.timedetector.TimeDetectorHelper;
|
import android.app.timedetector.TimeDetectorHelper;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.dashboard.DashboardFragment;
|
import com.android.settings.dashboard.DashboardFragment;
|
||||||
import com.android.settings.search.BaseSearchIndexProvider;
|
import com.android.settings.search.BaseSearchIndexProvider;
|
||||||
import com.android.settingslib.core.AbstractPreferenceController;
|
|
||||||
import com.android.settingslib.search.SearchIndexable;
|
import com.android.settingslib.search.SearchIndexable;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import com.google.android.setupcompat.util.WizardManagerHelper;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@SearchIndexable
|
@SearchIndexable
|
||||||
public class DateTimeSettings extends DashboardFragment implements
|
public class DateTimeSettings extends DashboardFragment implements
|
||||||
@@ -59,40 +55,19 @@ public class DateTimeSettings extends DashboardFragment implements
|
|||||||
@Override
|
@Override
|
||||||
public void onAttach(Context context) {
|
public void onAttach(Context context) {
|
||||||
super.onAttach(context);
|
super.onAttach(context);
|
||||||
|
boolean isFromSUW = WizardManagerHelper.isAnySetupWizard(getIntent());
|
||||||
getSettingsLifecycle().addObserver(new TimeChangeListenerMixin(context, this));
|
getSettingsLifecycle().addObserver(new TimeChangeListenerMixin(context, this));
|
||||||
use(LocationTimeZoneDetectionPreferenceController.class).setFragment(this);
|
use(LocationTimeZoneDetectionPreferenceController.class).setFragment(this);
|
||||||
}
|
use(AutoTimePreferenceController.class).setDateAndTimeCallback(this);
|
||||||
|
use(DatePreferenceController.class).setHost(this);
|
||||||
|
use(TimePreferenceController.class).setHost(this);
|
||||||
|
use(AutoTimeZonePreferenceController.class)
|
||||||
|
.setTimeAndDateCallback(this)
|
||||||
|
.setFromSUW(isFromSUW);
|
||||||
|
use(TimeFormatPreferenceController.class)
|
||||||
|
.setTimeAndDateCallback(this)
|
||||||
|
.setFromSUW(isFromSUW);
|
||||||
|
|
||||||
@Override
|
|
||||||
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
|
|
||||||
final List<AbstractPreferenceController> controllers = new ArrayList<>();
|
|
||||||
final Activity activity = getActivity();
|
|
||||||
final Intent intent = activity.getIntent();
|
|
||||||
final boolean isFromSUW = intent.getBooleanExtra(EXTRA_IS_FROM_SUW, false);
|
|
||||||
|
|
||||||
final AutoTimePreferenceController autoTimePreferenceController =
|
|
||||||
new AutoTimePreferenceController(
|
|
||||||
activity, this /* UpdateTimeAndDateCallback */);
|
|
||||||
controllers.add(autoTimePreferenceController);
|
|
||||||
DatePreferenceController datePreferenceController = new DatePreferenceController(
|
|
||||||
activity, this /* UpdateTimeAndDateCallback */);
|
|
||||||
controllers.add(datePreferenceController);
|
|
||||||
controllers.add(new TimePreferenceController(
|
|
||||||
activity, this /* UpdateTimeAndDateCallback */, datePreferenceController));
|
|
||||||
|
|
||||||
final AutoTimeZonePreferenceController autoTimeZonePreferenceController =
|
|
||||||
new AutoTimeZonePreferenceController(
|
|
||||||
activity, this /* UpdateTimeAndDateCallback */, isFromSUW);
|
|
||||||
controllers.add(autoTimeZonePreferenceController);
|
|
||||||
controllers.add(new TimeZonePreferenceController(activity));
|
|
||||||
|
|
||||||
final AutoTimeFormatPreferenceController autoTimeFormatPreferenceController =
|
|
||||||
new AutoTimeFormatPreferenceController(
|
|
||||||
activity, this /* UpdateTimeAndDateCallback */);
|
|
||||||
controllers.add(autoTimeFormatPreferenceController);
|
|
||||||
controllers.add(new TimeFormatPreferenceController(
|
|
||||||
activity, this /* UpdateTimeAndDateCallback */, isFromSUW));
|
|
||||||
return controllers;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -19,77 +19,93 @@ package com.android.settings.datetime;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.text.TextUtils;
|
|
||||||
import android.text.format.DateFormat;
|
import android.text.format.DateFormat;
|
||||||
|
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
import androidx.preference.TwoStatePreference;
|
|
||||||
|
|
||||||
import com.android.settings.core.PreferenceControllerMixin;
|
import com.android.settings.R;
|
||||||
import com.android.settingslib.core.AbstractPreferenceController;
|
import com.android.settings.core.TogglePreferenceController;
|
||||||
|
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
public class TimeFormatPreferenceController extends AbstractPreferenceController
|
public class TimeFormatPreferenceController extends TogglePreferenceController {
|
||||||
implements PreferenceControllerMixin {
|
|
||||||
|
|
||||||
static final String HOURS_12 = "12";
|
static final String HOURS_12 = "12";
|
||||||
static final String HOURS_24 = "24";
|
static final String HOURS_24 = "24";
|
||||||
|
|
||||||
private static final String KEY_TIME_FORMAT = "24 hour";
|
|
||||||
|
|
||||||
// Used for showing the current date format, which looks like "12/31/2010", "2010/12/13", etc.
|
// Used for showing the current date format, which looks like "12/31/2010", "2010/12/13", etc.
|
||||||
// The date value is stubs (independent of actual date).
|
// The date value is stubs (independent of actual date).
|
||||||
private final Calendar mDummyDate;
|
private final Calendar mDummyDate;
|
||||||
private final boolean mIsFromSUW;
|
private boolean mIsFromSUW;
|
||||||
private final UpdateTimeAndDateCallback mUpdateTimeAndDateCallback;
|
private UpdateTimeAndDateCallback mUpdateTimeAndDateCallback;
|
||||||
|
|
||||||
public TimeFormatPreferenceController(Context context, UpdateTimeAndDateCallback callback,
|
public TimeFormatPreferenceController(Context context, String key) {
|
||||||
boolean isFromSUW) {
|
super(context, key);
|
||||||
super(context);
|
|
||||||
mIsFromSUW = isFromSUW;
|
|
||||||
mDummyDate = Calendar.getInstance();
|
mDummyDate = Calendar.getInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the Time and Date callback
|
||||||
|
*/
|
||||||
|
public TimeFormatPreferenceController setTimeAndDateCallback(
|
||||||
|
UpdateTimeAndDateCallback callback) {
|
||||||
mUpdateTimeAndDateCallback = callback;
|
mUpdateTimeAndDateCallback = callback;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set if current fragment is launched via SUW
|
||||||
|
*/
|
||||||
|
public TimeFormatPreferenceController setFromSUW(boolean isFromSUW) {
|
||||||
|
mIsFromSUW = isFromSUW;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAvailable() {
|
public int getAvailabilityStatus() {
|
||||||
return !mIsFromSUW;
|
if (mIsFromSUW) {
|
||||||
|
return DISABLED_DEPENDENT_SETTING;
|
||||||
|
}
|
||||||
|
if (AutoTimeFormatPreferenceController.isAutoTimeFormatSelection(mContext)) {
|
||||||
|
return DISABLED_DEPENDENT_SETTING;
|
||||||
|
}
|
||||||
|
return AVAILABLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateState(Preference preference) {
|
public void updateState(Preference preference) {
|
||||||
if (!(preference instanceof TwoStatePreference)) {
|
super.updateState(preference);
|
||||||
return;
|
preference.setEnabled(getAvailabilityStatus() == AVAILABLE);
|
||||||
}
|
refreshSummary(preference);
|
||||||
preference.setEnabled(
|
}
|
||||||
!AutoTimeFormatPreferenceController.isAutoTimeFormatSelection(mContext));
|
|
||||||
((TwoStatePreference) preference).setChecked(is24Hour());
|
@Override
|
||||||
|
public boolean isChecked() {
|
||||||
|
return is24Hour();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean setChecked(boolean isChecked) {
|
||||||
|
update24HourFormat(mContext, isChecked);
|
||||||
|
mUpdateTimeAndDateCallback.updateTimeAndDateDisplay(mContext);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CharSequence getSummary() {
|
||||||
final Calendar now = Calendar.getInstance();
|
final Calendar now = Calendar.getInstance();
|
||||||
mDummyDate.setTimeZone(now.getTimeZone());
|
mDummyDate.setTimeZone(now.getTimeZone());
|
||||||
// We use December 31st because it's unambiguous when demonstrating the date format.
|
// We use December 31st because it's unambiguous when demonstrating the date format.
|
||||||
// We use 13:00 so we can demonstrate the 12/24 hour options.
|
// We use 13:00 so we can demonstrate the 12/24 hour options.
|
||||||
mDummyDate.set(now.get(Calendar.YEAR), 11, 31, 13, 0, 0);
|
mDummyDate.set(now.get(Calendar.YEAR), 11, 31, 13, 0, 0);
|
||||||
final Date dummyDate = mDummyDate.getTime();
|
final Date dummyDate = mDummyDate.getTime();
|
||||||
preference.setSummary(DateFormat.getTimeFormat(mContext).format(dummyDate));
|
return DateFormat.getTimeFormat(mContext).format(dummyDate);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean handlePreferenceTreeClick(Preference preference) {
|
public int getSliceHighlightMenuRes() {
|
||||||
if (!(preference instanceof TwoStatePreference)
|
return R.string.menu_key_system;
|
||||||
|| !TextUtils.equals(KEY_TIME_FORMAT, preference.getKey())) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
final boolean is24Hour = ((TwoStatePreference) preference).isChecked();
|
|
||||||
update24HourFormat(mContext, is24Hour);
|
|
||||||
mUpdateTimeAndDateCallback.updateTimeAndDateDisplay(mContext);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getPreferenceKey() {
|
|
||||||
return KEY_TIME_FORMAT;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean is24Hour() {
|
private boolean is24Hour() {
|
||||||
|
@@ -16,7 +16,11 @@
|
|||||||
|
|
||||||
package com.android.settings.datetime;
|
package com.android.settings.datetime;
|
||||||
|
|
||||||
|
import static android.app.time.Capabilities.CAPABILITY_POSSESSED;
|
||||||
|
|
||||||
import android.app.TimePickerDialog;
|
import android.app.TimePickerDialog;
|
||||||
|
import android.app.time.TimeCapabilities;
|
||||||
|
import android.app.time.TimeManager;
|
||||||
import android.app.timedetector.ManualTimeSuggestion;
|
import android.app.timedetector.ManualTimeSuggestion;
|
||||||
import android.app.timedetector.TimeDetector;
|
import android.app.timedetector.TimeDetector;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@@ -27,14 +31,12 @@ import android.widget.TimePicker;
|
|||||||
|
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
|
|
||||||
import com.android.settings.core.PreferenceControllerMixin;
|
import com.android.settings.core.BasePreferenceController;
|
||||||
import com.android.settingslib.RestrictedPreference;
|
|
||||||
import com.android.settingslib.core.AbstractPreferenceController;
|
|
||||||
|
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
|
|
||||||
public class TimePreferenceController extends AbstractPreferenceController
|
public class TimePreferenceController extends BasePreferenceController
|
||||||
implements PreferenceControllerMixin, TimePickerDialog.OnTimeSetListener {
|
implements TimePickerDialog.OnTimeSetListener {
|
||||||
|
|
||||||
public interface TimePreferenceHost extends UpdateTimeAndDateCallback {
|
public interface TimePreferenceHost extends UpdateTimeAndDateCallback {
|
||||||
void showTimePicker();
|
void showTimePicker();
|
||||||
@@ -43,52 +45,45 @@ public class TimePreferenceController extends AbstractPreferenceController
|
|||||||
public static final int DIALOG_TIMEPICKER = 1;
|
public static final int DIALOG_TIMEPICKER = 1;
|
||||||
|
|
||||||
private static final String TAG = "TimePreferenceController";
|
private static final String TAG = "TimePreferenceController";
|
||||||
private static final String KEY_TIME = "time";
|
|
||||||
|
|
||||||
private final DatePreferenceController mDatePreferenceController;
|
private TimePreferenceHost mHost;
|
||||||
private final TimePreferenceHost mHost;
|
private TimeManager mTimeManager;
|
||||||
|
|
||||||
|
public TimePreferenceController(Context context, String preferenceKey) {
|
||||||
|
super(context, preferenceKey);
|
||||||
|
mTimeManager = context.getSystemService(TimeManager.class);
|
||||||
|
}
|
||||||
|
|
||||||
public TimePreferenceController(Context context,
|
public void setHost(TimePreferenceHost host) {
|
||||||
TimePreferenceHost callback,
|
mHost = host;
|
||||||
DatePreferenceController datePreferenceController) {
|
|
||||||
super(context);
|
|
||||||
mHost = callback;
|
|
||||||
mDatePreferenceController = datePreferenceController;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAvailable() {
|
public int getAvailabilityStatus() {
|
||||||
return true;
|
return isEnabled() ? AVAILABLE : DISABLED_DEPENDENT_SETTING;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateState(Preference preference) {
|
public void updateState(Preference preference) {
|
||||||
if (!(preference instanceof RestrictedPreference)) {
|
super.updateState(preference);
|
||||||
return;
|
preference.setEnabled(isEnabled());
|
||||||
}
|
}
|
||||||
final Calendar now = Calendar.getInstance();
|
|
||||||
preference.setSummary(DateFormat.getTimeFormat(mContext).format(now.getTime()));
|
@Override
|
||||||
if (!((RestrictedPreference) preference).isDisabledByAdmin()) {
|
public CharSequence getSummary() {
|
||||||
boolean enableManualTimeSelection = mDatePreferenceController.isEnabled();
|
Calendar now = Calendar.getInstance();
|
||||||
preference.setEnabled(enableManualTimeSelection);
|
return DateFormat.getTimeFormat(mContext).format(now.getTime());
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean handlePreferenceTreeClick(Preference preference) {
|
public boolean handlePreferenceTreeClick(Preference preference) {
|
||||||
if (!TextUtils.equals(KEY_TIME, preference.getKey())) {
|
if (!TextUtils.equals(getPreferenceKey(), preference.getKey())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
mHost.showTimePicker();
|
mHost.showTimePicker();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getPreferenceKey() {
|
|
||||||
return KEY_TIME;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
|
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
|
||||||
if (mContext != null) {
|
if (mContext != null) {
|
||||||
@@ -132,4 +127,16 @@ public class TimePreferenceController extends AbstractPreferenceController
|
|||||||
Log.w(TAG, "Unable to set time with suggestion=" + manualTimeSuggestion);
|
Log.w(TAG, "Unable to set time with suggestion=" + manualTimeSuggestion);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether selecting the preference should prompt for the user to enter the date
|
||||||
|
* manually. Exposed as public so that the time controller can easily share the same logic as
|
||||||
|
* the rules are identical for time.
|
||||||
|
*/
|
||||||
|
public boolean isEnabled() {
|
||||||
|
TimeCapabilities timeZoneCapabilities =
|
||||||
|
mTimeManager.getTimeCapabilitiesAndConfig().getCapabilities();
|
||||||
|
int suggestManualTimeCapability = timeZoneCapabilities.getSetManualTimeCapability();
|
||||||
|
return suggestManualTimeCapability == CAPABILITY_POSSESSED;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -25,45 +25,34 @@ import android.content.Context;
|
|||||||
import androidx.annotation.VisibleForTesting;
|
import androidx.annotation.VisibleForTesting;
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
|
|
||||||
import com.android.settings.core.PreferenceControllerMixin;
|
import com.android.settings.core.BasePreferenceController;
|
||||||
import com.android.settingslib.RestrictedPreference;
|
|
||||||
import com.android.settingslib.core.AbstractPreferenceController;
|
|
||||||
import com.android.settingslib.datetime.ZoneGetter;
|
import com.android.settingslib.datetime.ZoneGetter;
|
||||||
|
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
|
|
||||||
public class TimeZonePreferenceController extends AbstractPreferenceController
|
public class TimeZonePreferenceController extends BasePreferenceController {
|
||||||
implements PreferenceControllerMixin {
|
|
||||||
|
|
||||||
private static final String KEY_TIMEZONE = "timezone";
|
|
||||||
|
|
||||||
private final TimeManager mTimeManager;
|
private final TimeManager mTimeManager;
|
||||||
|
|
||||||
public TimeZonePreferenceController(Context context) {
|
public TimeZonePreferenceController(Context context, String preferenceKey) {
|
||||||
super(context);
|
super(context, preferenceKey);
|
||||||
mTimeManager = context.getSystemService(TimeManager.class);
|
mTimeManager = context.getSystemService(TimeManager.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CharSequence getSummary() {
|
||||||
|
return getTimeZoneOffsetAndName();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getAvailabilityStatus() {
|
||||||
|
return shouldEnableManualTimeZoneSelection() ? AVAILABLE : DISABLED_DEPENDENT_SETTING;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateState(Preference preference) {
|
public void updateState(Preference preference) {
|
||||||
if (!(preference instanceof RestrictedPreference)) {
|
super.updateState(preference);
|
||||||
return;
|
preference.setEnabled(shouldEnableManualTimeZoneSelection());
|
||||||
}
|
|
||||||
preference.setSummary(getTimeZoneOffsetAndName());
|
|
||||||
if (!((RestrictedPreference) preference).isDisabledByAdmin()) {
|
|
||||||
boolean enableManualTimeZoneSelection = shouldEnableManualTimeZoneSelection();
|
|
||||||
preference.setEnabled(enableManualTimeZoneSelection);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isAvailable() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getPreferenceKey() {
|
|
||||||
return KEY_TIMEZONE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
|
@@ -53,13 +53,13 @@ public class AutoTimeFormatPreferenceControllerTest {
|
|||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
mApplication = ShadowApplication.getInstance();
|
mApplication = ShadowApplication.getInstance();
|
||||||
mContext = RuntimeEnvironment.application;
|
mContext = RuntimeEnvironment.application;
|
||||||
|
mController = new TestAutoTimeFormatPreferenceController(mContext, "test_key");
|
||||||
|
mPreference = new SwitchPreference(mContext);
|
||||||
|
mPreference.setKey("test_key");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void updateState_24HourSet_shouldCheckPreference() {
|
public void updateState_24HourSet_shouldCheckPreference() {
|
||||||
mController = new TestAutoTimeFormatPreferenceController(mContext, mCallback);
|
|
||||||
mPreference = new SwitchPreference(mContext);
|
|
||||||
mPreference.setKey(mController.getPreferenceKey());
|
|
||||||
Settings.System.putString(mContext.getContentResolver(), Settings.System.TIME_12_24,
|
Settings.System.putString(mContext.getContentResolver(), Settings.System.TIME_12_24,
|
||||||
TimeFormatPreferenceController.HOURS_24);
|
TimeFormatPreferenceController.HOURS_24);
|
||||||
|
|
||||||
@@ -70,9 +70,6 @@ public class AutoTimeFormatPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void updateState_12HourSet_shouldCheckPreference() {
|
public void updateState_12HourSet_shouldCheckPreference() {
|
||||||
mController = new TestAutoTimeFormatPreferenceController(mContext, mCallback);
|
|
||||||
mPreference = new SwitchPreference(mContext);
|
|
||||||
mPreference.setKey(mController.getPreferenceKey());
|
|
||||||
Settings.System.putString(mContext.getContentResolver(), Settings.System.TIME_12_24,
|
Settings.System.putString(mContext.getContentResolver(), Settings.System.TIME_12_24,
|
||||||
TimeFormatPreferenceController.HOURS_12);
|
TimeFormatPreferenceController.HOURS_12);
|
||||||
|
|
||||||
@@ -83,9 +80,6 @@ public class AutoTimeFormatPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void updateState_autoSet_shouldNotCheckPreference() {
|
public void updateState_autoSet_shouldNotCheckPreference() {
|
||||||
mController = new TestAutoTimeFormatPreferenceController(mContext, mCallback);
|
|
||||||
mPreference = new SwitchPreference(mContext);
|
|
||||||
mPreference.setKey(mController.getPreferenceKey());
|
|
||||||
Settings.System.putString(mContext.getContentResolver(), Settings.System.TIME_12_24, null);
|
Settings.System.putString(mContext.getContentResolver(), Settings.System.TIME_12_24, null);
|
||||||
|
|
||||||
mController.updateState(mPreference);
|
mController.updateState(mPreference);
|
||||||
@@ -95,14 +89,7 @@ public class AutoTimeFormatPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void updatePreference_autoSet_shouldSendIntent_12HourLocale() {
|
public void updatePreference_autoSet_shouldSendIntent_12HourLocale() {
|
||||||
mController = new TestAutoTimeFormatPreferenceController(mContext, mCallback);
|
mController.setChecked(false);
|
||||||
mPreference = new SwitchPreference(mContext);
|
|
||||||
mPreference.setKey(mController.getPreferenceKey());
|
|
||||||
mPreference.setChecked(false);
|
|
||||||
|
|
||||||
boolean result = mController.handlePreferenceTreeClick(mPreference);
|
|
||||||
|
|
||||||
assertThat(result).isTrue();
|
|
||||||
|
|
||||||
List<Intent> intentsFired = mApplication.getBroadcastIntents();
|
List<Intent> intentsFired = mApplication.getBroadcastIntents();
|
||||||
assertThat(intentsFired.size()).isEqualTo(1);
|
assertThat(intentsFired.size()).isEqualTo(1);
|
||||||
@@ -114,15 +101,9 @@ public class AutoTimeFormatPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void updatePreference_autoSet_shouldSendIntent_24HourLocale() {
|
public void updatePreference_autoSet_shouldSendIntent_24HourLocale() {
|
||||||
mController = new TestAutoTimeFormatPreferenceController(mContext, mCallback);
|
|
||||||
mPreference = new SwitchPreference(mContext);
|
|
||||||
mPreference.setKey(mController.getPreferenceKey());
|
|
||||||
mPreference.setChecked(false);
|
|
||||||
|
|
||||||
mController.setIs24HourLocale(true);
|
mController.setIs24HourLocale(true);
|
||||||
boolean result = mController.handlePreferenceTreeClick(mPreference);
|
|
||||||
|
|
||||||
assertThat(result).isTrue();
|
mController.setChecked(false);
|
||||||
|
|
||||||
List<Intent> intentsFired = mApplication.getBroadcastIntents();
|
List<Intent> intentsFired = mApplication.getBroadcastIntents();
|
||||||
assertThat(intentsFired.size()).isEqualTo(1);
|
assertThat(intentsFired.size()).isEqualTo(1);
|
||||||
@@ -134,15 +115,9 @@ public class AutoTimeFormatPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void updatePreference_24HourSet_shouldSendIntent() {
|
public void updatePreference_24HourSet_shouldSendIntent() {
|
||||||
mController = new TestAutoTimeFormatPreferenceController(mContext, mCallback);
|
|
||||||
mPreference = new SwitchPreference(mContext);
|
|
||||||
mPreference.setKey(mController.getPreferenceKey());
|
|
||||||
mPreference.setChecked(true);
|
|
||||||
|
|
||||||
mController.setIs24HourLocale(false);
|
mController.setIs24HourLocale(false);
|
||||||
boolean result = mController.handlePreferenceTreeClick(mPreference);
|
|
||||||
|
|
||||||
assertThat(result).isTrue();
|
mController.setChecked(true);
|
||||||
|
|
||||||
List<Intent> intentsFired = mApplication.getBroadcastIntents();
|
List<Intent> intentsFired = mApplication.getBroadcastIntents();
|
||||||
assertThat(intentsFired.size()).isEqualTo(1);
|
assertThat(intentsFired.size()).isEqualTo(1);
|
||||||
@@ -161,9 +136,8 @@ public class AutoTimeFormatPreferenceControllerTest {
|
|||||||
|
|
||||||
private boolean is24HourLocale = false;
|
private boolean is24HourLocale = false;
|
||||||
|
|
||||||
private TestAutoTimeFormatPreferenceController(Context context,
|
TestAutoTimeFormatPreferenceController(Context context, String preferenceKey) {
|
||||||
UpdateTimeAndDateCallback callback) {
|
super(context, preferenceKey);
|
||||||
super(context, callback);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setIs24HourLocale(boolean value) {
|
void setIs24HourLocale(boolean value) {
|
||||||
|
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
package com.android.settings.datetime;
|
package com.android.settings.datetime;
|
||||||
|
|
||||||
|
import static com.android.settings.core.BasePreferenceController.DISABLED_DEPENDENT_SETTING;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
@@ -59,7 +61,8 @@ public class AutoTimePreferenceControllerTest {
|
|||||||
mPreference = new Preference(mContext);
|
mPreference = new Preference(mContext);
|
||||||
when(mContext.getSystemService(TimeManager.class)).thenReturn(mTimeManager);
|
when(mContext.getSystemService(TimeManager.class)).thenReturn(mTimeManager);
|
||||||
|
|
||||||
mController = new AutoTimePreferenceController(mContext, mCallback);
|
mController = new AutoTimePreferenceController(mContext, "test_key");
|
||||||
|
mController.setDateAndTimeCallback(mCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -68,7 +71,7 @@ public class AutoTimePreferenceControllerTest {
|
|||||||
/* autoSupported= */false, /* autoEnabled= */false);
|
/* autoSupported= */false, /* autoEnabled= */false);
|
||||||
when(mTimeManager.getTimeCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
|
when(mTimeManager.getTimeCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
|
||||||
|
|
||||||
assertThat(mController.isAvailable()).isFalse();
|
assertThat(mController.getAvailabilityStatus()).isEqualTo(DISABLED_DEPENDENT_SETTING);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -81,24 +84,23 @@ public class AutoTimePreferenceControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsEnabled_shouldReadFromTimeManagerConfig() {
|
public void isEnabled_autoEnabledIsFalse_shouldReadFromTimeManagerConfig() {
|
||||||
{
|
// Disabled
|
||||||
// Disabled
|
TimeCapabilitiesAndConfig capabilitiesAndConfig = createCapabilitiesAndConfig(
|
||||||
TimeCapabilitiesAndConfig capabilitiesAndConfig = createCapabilitiesAndConfig(
|
/* autoSupported= */true, /* autoEnabled= */false);
|
||||||
/* autoSupported= */true, /* autoEnabled= */false);
|
when(mTimeManager.getTimeCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
|
||||||
when(mTimeManager.getTimeCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
|
|
||||||
|
|
||||||
assertThat(mController.isEnabled()).isFalse();
|
assertThat(mController.isEnabled()).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
@Test
|
||||||
// Enabled
|
public void isEnabled_autoEnabledIsTrue_shouldReadFromTimeManagerConfig() {
|
||||||
TimeCapabilitiesAndConfig capabilitiesAndConfig = createCapabilitiesAndConfig(
|
// Enabled
|
||||||
/* autoSupported= */true, /* autoEnabled= */true);
|
TimeCapabilitiesAndConfig capabilitiesAndConfig = createCapabilitiesAndConfig(
|
||||||
when(mTimeManager.getTimeCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
|
/* autoSupported= */true, /* autoEnabled= */true);
|
||||||
|
when(mTimeManager.getTimeCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
|
||||||
|
|
||||||
assertThat(mController.isEnabled()).isTrue();
|
assertThat(mController.isEnabled()).isTrue();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -118,10 +120,10 @@ public class AutoTimePreferenceControllerTest {
|
|||||||
verify(mTimeManager).updateTimeConfiguration(timeConfiguration);
|
verify(mTimeManager).updateTimeConfiguration(timeConfiguration);
|
||||||
|
|
||||||
// Update the mTimeManager mock so that it now returns the expected updated config.
|
// Update the mTimeManager mock so that it now returns the expected updated config.
|
||||||
TimeCapabilitiesAndConfig capabilitiesAndConfigAfterUpdate =
|
TimeCapabilitiesAndConfig capabilitiesAndConfigAfterUpdate = createCapabilitiesAndConfig(
|
||||||
createCapabilitiesAndConfig(/* autoSupported= */true, /* autoEnabled= */true);
|
/* autoSupported= */true, /* autoEnabled= */true);
|
||||||
when(mTimeManager.getTimeCapabilitiesAndConfig())
|
when(mTimeManager.getTimeCapabilitiesAndConfig()).thenReturn(
|
||||||
.thenReturn(capabilitiesAndConfigAfterUpdate);
|
capabilitiesAndConfigAfterUpdate);
|
||||||
|
|
||||||
assertThat(mController.isEnabled()).isTrue();
|
assertThat(mController.isEnabled()).isTrue();
|
||||||
}
|
}
|
||||||
@@ -145,14 +147,14 @@ public class AutoTimePreferenceControllerTest {
|
|||||||
// Update the mTimeManager mock so that it now returns the expected updated config.
|
// Update the mTimeManager mock so that it now returns the expected updated config.
|
||||||
TimeCapabilitiesAndConfig capabilitiesAndConfigAfterUpdate =
|
TimeCapabilitiesAndConfig capabilitiesAndConfigAfterUpdate =
|
||||||
createCapabilitiesAndConfig(/* autoSupported= */true, /* autoEnabled= */false);
|
createCapabilitiesAndConfig(/* autoSupported= */true, /* autoEnabled= */false);
|
||||||
when(mTimeManager.getTimeCapabilitiesAndConfig())
|
when(mTimeManager.getTimeCapabilitiesAndConfig()).thenReturn(
|
||||||
.thenReturn(capabilitiesAndConfigAfterUpdate);
|
capabilitiesAndConfigAfterUpdate);
|
||||||
|
|
||||||
assertThat(mController.isEnabled()).isFalse();
|
assertThat(mController.isEnabled()).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static TimeCapabilitiesAndConfig createCapabilitiesAndConfig(
|
private static TimeCapabilitiesAndConfig createCapabilitiesAndConfig(boolean autoSupported,
|
||||||
boolean autoSupported, boolean autoEnabled) {
|
boolean autoEnabled) {
|
||||||
int configureAutoDetectionEnabledCapability =
|
int configureAutoDetectionEnabledCapability =
|
||||||
autoSupported ? Capabilities.CAPABILITY_POSSESSED
|
autoSupported ? Capabilities.CAPABILITY_POSSESSED
|
||||||
: Capabilities.CAPABILITY_NOT_SUPPORTED;
|
: Capabilities.CAPABILITY_NOT_SUPPORTED;
|
||||||
|
@@ -22,6 +22,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_PRESENT;
|
||||||
import static android.app.time.LocationTimeZoneAlgorithmStatus.PROVIDER_STATUS_NOT_READY;
|
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 com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
@@ -62,6 +64,8 @@ public class AutoTimeZonePreferenceControllerTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private TimeManager mTimeManager;
|
private TimeManager mTimeManager;
|
||||||
|
|
||||||
|
private AutoTimeZonePreferenceController mController;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
@@ -70,6 +74,9 @@ public class AutoTimeZonePreferenceControllerTest {
|
|||||||
mPreference = new Preference(mContext);
|
mPreference = new Preference(mContext);
|
||||||
|
|
||||||
when(mContext.getSystemService(TimeManager.class)).thenReturn(mTimeManager);
|
when(mContext.getSystemService(TimeManager.class)).thenReturn(mTimeManager);
|
||||||
|
|
||||||
|
mController = new AutoTimeZonePreferenceController(mContext, "test_key");
|
||||||
|
mController.setFromSUW(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -78,10 +85,9 @@ public class AutoTimeZonePreferenceControllerTest {
|
|||||||
/* autoSupported= */true, /* autoEnabled= */false);
|
/* autoSupported= */true, /* autoEnabled= */false);
|
||||||
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
|
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
|
||||||
|
|
||||||
AutoTimeZonePreferenceController controller = new AutoTimeZonePreferenceController(
|
mController.setFromSUW(true);
|
||||||
mContext, null /* callback */, true /* isFromSUW */);
|
|
||||||
|
|
||||||
assertThat(controller.isAvailable()).isFalse();
|
assertThat(mController.getAvailabilityStatus()).isEqualTo(DISABLED_DEPENDENT_SETTING);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -90,10 +96,9 @@ public class AutoTimeZonePreferenceControllerTest {
|
|||||||
/* autoSupported= */true, /* autoEnabled= */false);
|
/* autoSupported= */true, /* autoEnabled= */false);
|
||||||
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
|
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
|
||||||
|
|
||||||
AutoTimeZonePreferenceController controller = new AutoTimeZonePreferenceController(
|
mController.setFromSUW(false);
|
||||||
mContext, null /* callback */, false /* isFromSUW */);
|
|
||||||
|
|
||||||
assertThat(controller.isAvailable()).isTrue();
|
assertThat(mController.isAvailable()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -102,10 +107,7 @@ public class AutoTimeZonePreferenceControllerTest {
|
|||||||
/* autoSupported= */false, /* autoEnabled= */false);
|
/* autoSupported= */false, /* autoEnabled= */false);
|
||||||
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
|
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
|
||||||
|
|
||||||
AutoTimeZonePreferenceController controller = new AutoTimeZonePreferenceController(
|
assertThat(mController.getAvailabilityStatus()).isEqualTo(DISABLED_DEPENDENT_SETTING);
|
||||||
mContext, null /* callback */, false /* fromSUW */);
|
|
||||||
|
|
||||||
assertThat(controller.isAvailable()).isFalse();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -114,10 +116,9 @@ public class AutoTimeZonePreferenceControllerTest {
|
|||||||
/* autoSupported= */false, /* autoEnabled= */false);
|
/* autoSupported= */false, /* autoEnabled= */false);
|
||||||
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
|
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
|
||||||
|
|
||||||
AutoTimeZonePreferenceController controller = new AutoTimeZonePreferenceController(
|
mController.setFromSUW(true);
|
||||||
mContext, null /* callback */, true /* fromSUW */);
|
|
||||||
|
|
||||||
assertThat(controller.isEnabled()).isFalse();
|
assertThat(mController.getAvailabilityStatus()).isEqualTo(DISABLED_DEPENDENT_SETTING);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -126,10 +127,9 @@ public class AutoTimeZonePreferenceControllerTest {
|
|||||||
/* autoSupported= */false, /* autoEnabled= */true);
|
/* autoSupported= */false, /* autoEnabled= */true);
|
||||||
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
|
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
|
||||||
|
|
||||||
AutoTimeZonePreferenceController controller = new AutoTimeZonePreferenceController(
|
mController.setFromSUW(true);
|
||||||
mContext, null /* callback */, true /* fromSUW */);
|
|
||||||
|
|
||||||
assertThat(controller.isEnabled()).isTrue();
|
assertThat(mController.isAvailable()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -138,34 +138,27 @@ public class AutoTimeZonePreferenceControllerTest {
|
|||||||
/* autoSupported= */false, /* autoEnabled= */false);
|
/* autoSupported= */false, /* autoEnabled= */false);
|
||||||
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
|
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
|
||||||
|
|
||||||
AutoTimeZonePreferenceController controller = new AutoTimeZonePreferenceController(
|
assertThat(mController.isEnabled()).isFalse();
|
||||||
mContext, null /* callback */, false /* fromSUW */);
|
|
||||||
|
|
||||||
assertThat(controller.isEnabled()).isFalse();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsEnabled_shouldReadFromTimeManagerConfig() {
|
public void isEnabled_autoEnabledIsFalse_shouldReadFromTimeManagerConfig() {
|
||||||
AutoTimeZonePreferenceController controller = new AutoTimeZonePreferenceController(
|
// Disabled
|
||||||
mContext, null /* callback */, false /* fromSUW */);
|
TimeZoneCapabilitiesAndConfig capabilitiesAndConfig = createCapabilitiesAndConfig(
|
||||||
|
/* autoSupported= */true, /* autoEnabled= */false);
|
||||||
|
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
|
||||||
|
|
||||||
{
|
assertThat(mController.isEnabled()).isFalse();
|
||||||
// Disabled
|
}
|
||||||
TimeZoneCapabilitiesAndConfig capabilitiesAndConfig = createCapabilitiesAndConfig(
|
|
||||||
/* autoSupported= */true, /* autoEnabled= */false);
|
|
||||||
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
|
|
||||||
|
|
||||||
assertThat(controller.isEnabled()).isFalse();
|
@Test
|
||||||
}
|
public void isEnabled_autoEnabledIsTrue_shouldReadFromTimeManagerConfig() {
|
||||||
|
// Enabled
|
||||||
|
TimeZoneCapabilitiesAndConfig capabilitiesAndConfig = createCapabilitiesAndConfig(
|
||||||
|
/* autoSupported= */true, /* autoEnabled= */true);
|
||||||
|
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
|
||||||
|
|
||||||
{
|
assertThat(mController.isEnabled()).isTrue();
|
||||||
// Enabled
|
|
||||||
TimeZoneCapabilitiesAndConfig capabilitiesAndConfig = createCapabilitiesAndConfig(
|
|
||||||
/* autoSupported= */true, /* autoEnabled= */true);
|
|
||||||
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
|
|
||||||
|
|
||||||
assertThat(controller.isEnabled()).isTrue();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -175,10 +168,9 @@ public class AutoTimeZonePreferenceControllerTest {
|
|||||||
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
|
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
|
||||||
when(mTimeManager.updateTimeZoneConfiguration(Mockito.any())).thenReturn(true);
|
when(mTimeManager.updateTimeZoneConfiguration(Mockito.any())).thenReturn(true);
|
||||||
|
|
||||||
AutoTimeZonePreferenceController controller = new AutoTimeZonePreferenceController(
|
mController.setTimeAndDateCallback(mCallback);
|
||||||
mContext, mCallback, false /* fromSUW */);
|
|
||||||
|
|
||||||
assertThat(controller.onPreferenceChange(mPreference, true)).isTrue();
|
assertThat(mController.onPreferenceChange(mPreference, true)).isTrue();
|
||||||
verify(mCallback).updateTimeAndDateDisplay(mContext);
|
verify(mCallback).updateTimeAndDateDisplay(mContext);
|
||||||
|
|
||||||
// Check the service was asked to change the configuration correctly.
|
// Check the service was asked to change the configuration correctly.
|
||||||
@@ -193,7 +185,7 @@ public class AutoTimeZonePreferenceControllerTest {
|
|||||||
when(mTimeManager.getTimeZoneCapabilitiesAndConfig())
|
when(mTimeManager.getTimeZoneCapabilitiesAndConfig())
|
||||||
.thenReturn(capabilitiesAndConfigAfterUpdate);
|
.thenReturn(capabilitiesAndConfigAfterUpdate);
|
||||||
|
|
||||||
assertThat(controller.isEnabled()).isTrue();
|
assertThat(mController.isEnabled()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -203,10 +195,9 @@ public class AutoTimeZonePreferenceControllerTest {
|
|||||||
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
|
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
|
||||||
when(mTimeManager.updateTimeZoneConfiguration(Mockito.any())).thenReturn(true);
|
when(mTimeManager.updateTimeZoneConfiguration(Mockito.any())).thenReturn(true);
|
||||||
|
|
||||||
AutoTimeZonePreferenceController controller = new AutoTimeZonePreferenceController(
|
mController.setTimeAndDateCallback(mCallback);
|
||||||
mContext, mCallback, false /* fromSUW */);
|
|
||||||
|
|
||||||
assertThat(controller.onPreferenceChange(mPreference, false)).isTrue();
|
assertThat(mController.onPreferenceChange(mPreference, false)).isTrue();
|
||||||
verify(mCallback).updateTimeAndDateDisplay(mContext);
|
verify(mCallback).updateTimeAndDateDisplay(mContext);
|
||||||
|
|
||||||
// Check the service was asked to change the configuration correctly.
|
// Check the service was asked to change the configuration correctly.
|
||||||
@@ -221,13 +212,12 @@ public class AutoTimeZonePreferenceControllerTest {
|
|||||||
when(mTimeManager.getTimeZoneCapabilitiesAndConfig())
|
when(mTimeManager.getTimeZoneCapabilitiesAndConfig())
|
||||||
.thenReturn(capabilitiesAndConfigAfterUpdate);
|
.thenReturn(capabilitiesAndConfigAfterUpdate);
|
||||||
|
|
||||||
assertThat(controller.isEnabled()).isFalse();
|
assertThat(mController.isEnabled()).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getSummary() {
|
public void getSummary() {
|
||||||
AutoTimeZonePreferenceController controller = new AutoTimeZonePreferenceController(
|
mController.setTimeAndDateCallback(mCallback);
|
||||||
mContext, mCallback, false /* fromSUW */);
|
|
||||||
|
|
||||||
TimeZoneCapabilitiesAndConfig capabilitiesAndConfig = createCapabilitiesAndConfig(
|
TimeZoneCapabilitiesAndConfig capabilitiesAndConfig = createCapabilitiesAndConfig(
|
||||||
/* autoSupported= */true, /* autoEnabled= */true, /* telephonySupported= */
|
/* autoSupported= */true, /* autoEnabled= */true, /* telephonySupported= */
|
||||||
@@ -235,7 +225,7 @@ public class AutoTimeZonePreferenceControllerTest {
|
|||||||
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
|
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
|
||||||
when(mTimeManager.updateTimeZoneConfiguration(Mockito.any())).thenReturn(true);
|
when(mTimeManager.updateTimeZoneConfiguration(Mockito.any())).thenReturn(true);
|
||||||
|
|
||||||
assertThat(controller.getSummary()).isEqualTo("");
|
assertThat(mController.getSummary()).isEqualTo("");
|
||||||
|
|
||||||
capabilitiesAndConfig = createCapabilitiesAndConfig(
|
capabilitiesAndConfig = createCapabilitiesAndConfig(
|
||||||
/* autoSupported= */true, /* autoEnabled= */true, /* telephonySupported= */
|
/* autoSupported= */true, /* autoEnabled= */true, /* telephonySupported= */
|
||||||
@@ -243,7 +233,7 @@ public class AutoTimeZonePreferenceControllerTest {
|
|||||||
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
|
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
|
||||||
when(mTimeManager.updateTimeZoneConfiguration(Mockito.any())).thenReturn(true);
|
when(mTimeManager.updateTimeZoneConfiguration(Mockito.any())).thenReturn(true);
|
||||||
|
|
||||||
assertThat(controller.getSummary()).isEqualTo(
|
assertThat(mController.getSummary()).isEqualTo(
|
||||||
mContext.getString(R.string.auto_zone_requires_location_summary));
|
mContext.getString(R.string.auto_zone_requires_location_summary));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -74,12 +74,8 @@ public class DatePreferenceControllerTest {
|
|||||||
when(mContext.getSystemService(TimeDetector.class)).thenReturn(mTimeDetector);
|
when(mContext.getSystemService(TimeDetector.class)).thenReturn(mTimeDetector);
|
||||||
when(mContext.getSystemService(TimeManager.class)).thenReturn(mTimeManager);
|
when(mContext.getSystemService(TimeManager.class)).thenReturn(mTimeManager);
|
||||||
mPreference = new RestrictedPreference(RuntimeEnvironment.application);
|
mPreference = new RestrictedPreference(RuntimeEnvironment.application);
|
||||||
mController = new DatePreferenceController(mContext, mHost);
|
mController = new DatePreferenceController(mContext, "test_key");
|
||||||
}
|
mController.setHost(mHost);
|
||||||
|
|
||||||
@Test
|
|
||||||
public void isAlwaysAvailable() {
|
|
||||||
assertThat(mController.isAvailable()).isTrue();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -147,7 +143,7 @@ public class DatePreferenceControllerTest {
|
|||||||
assertEquals(2020, calendar.get(Calendar.YEAR));
|
assertEquals(2020, calendar.get(Calendar.YEAR));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static TimeCapabilitiesAndConfig createCapabilitiesAndConfig(
|
static TimeCapabilitiesAndConfig createCapabilitiesAndConfig(
|
||||||
boolean suggestManualAllowed) {
|
boolean suggestManualAllowed) {
|
||||||
int suggestManualCapability = suggestManualAllowed ? Capabilities.CAPABILITY_POSSESSED
|
int suggestManualCapability = suggestManualAllowed ? Capabilities.CAPABILITY_POSSESSED
|
||||||
: Capabilities.CAPABILITY_NOT_SUPPORTED;
|
: Capabilities.CAPABILITY_NOT_SUPPORTED;
|
||||||
|
@@ -16,13 +16,15 @@
|
|||||||
|
|
||||||
package com.android.settings.datetime;
|
package com.android.settings.datetime;
|
||||||
|
|
||||||
|
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
|
||||||
|
import static com.android.settings.core.BasePreferenceController.DISABLED_DEPENDENT_SETTING;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
|
|
||||||
import androidx.preference.PreferenceScreen;
|
|
||||||
import androidx.preference.SwitchPreference;
|
import androidx.preference.SwitchPreference;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@@ -52,27 +54,30 @@ public class TimeFormatPreferenceControllerTest {
|
|||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
mApplication = ShadowApplication.getInstance();
|
mApplication = ShadowApplication.getInstance();
|
||||||
mContext = RuntimeEnvironment.application;
|
mContext = RuntimeEnvironment.application;
|
||||||
|
mController = new TimeFormatPreferenceController(mContext, "test_key");
|
||||||
|
mController.setTimeAndDateCallback(mCallback);
|
||||||
|
mController.setFromSUW(false);
|
||||||
|
|
||||||
|
mPreference = new SwitchPreference(mContext);
|
||||||
|
mPreference.setKey("test_key");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isCalledFromSUW_NotAvailable() {
|
public void isCalledFromSUW_NotAvailable() {
|
||||||
mController = new TimeFormatPreferenceController(mContext, mCallback, true);
|
mController.setFromSUW(true);
|
||||||
|
|
||||||
assertThat(mController.isAvailable()).isFalse();
|
assertThat(mController.getAvailabilityStatus()).isEqualTo(DISABLED_DEPENDENT_SETTING);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void notCalledFromSUW_shouldBeAvailable() {
|
public void notCalledFromSUW_shouldBeAvailable() {
|
||||||
mController = new TimeFormatPreferenceController(mContext, mCallback, false);
|
Settings.System.putString(mContext.getContentResolver(), Settings.System.TIME_12_24,
|
||||||
|
TimeFormatPreferenceController.HOURS_24);
|
||||||
assertThat(mController.isAvailable()).isTrue();
|
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void updateState_24HourSet_shouldCheckPreference() {
|
public void updateState_24HourSet_shouldCheckPreference() {
|
||||||
mController = new TimeFormatPreferenceController(mContext, mCallback, false);
|
|
||||||
mPreference = new SwitchPreference(mContext);
|
|
||||||
mPreference.setKey(mController.getPreferenceKey());
|
|
||||||
Settings.System.putString(mContext.getContentResolver(), Settings.System.TIME_12_24,
|
Settings.System.putString(mContext.getContentResolver(), Settings.System.TIME_12_24,
|
||||||
TimeFormatPreferenceController.HOURS_24);
|
TimeFormatPreferenceController.HOURS_24);
|
||||||
|
|
||||||
@@ -83,9 +88,6 @@ public class TimeFormatPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void updateState_12HourSet_shouldNotCheckPreference() {
|
public void updateState_12HourSet_shouldNotCheckPreference() {
|
||||||
mController = new TimeFormatPreferenceController(mContext, mCallback, false);
|
|
||||||
mPreference = new SwitchPreference(mContext);
|
|
||||||
mPreference.setKey(mController.getPreferenceKey());
|
|
||||||
Settings.System.putString(mContext.getContentResolver(), Settings.System.TIME_12_24,
|
Settings.System.putString(mContext.getContentResolver(), Settings.System.TIME_12_24,
|
||||||
TimeFormatPreferenceController.HOURS_12);
|
TimeFormatPreferenceController.HOURS_12);
|
||||||
|
|
||||||
@@ -96,10 +98,7 @@ public class TimeFormatPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void updateState_autoSet_shouldNotEnablePreference() {
|
public void updateState_autoSet_shouldNotEnablePreference() {
|
||||||
mController = new TimeFormatPreferenceController(mContext, mCallback, false);
|
|
||||||
Settings.System.putString(mContext.getContentResolver(), Settings.System.TIME_12_24, null);
|
Settings.System.putString(mContext.getContentResolver(), Settings.System.TIME_12_24, null);
|
||||||
mPreference = new SwitchPreference(mContext);
|
|
||||||
mPreference.setKey(mController.getPreferenceKey());
|
|
||||||
|
|
||||||
mController.updateState(mPreference);
|
mController.updateState(mPreference);
|
||||||
|
|
||||||
@@ -108,14 +107,7 @@ public class TimeFormatPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void updatePreference_12HourSet_shouldSendIntent() {
|
public void updatePreference_12HourSet_shouldSendIntent() {
|
||||||
mController = new TimeFormatPreferenceController(mContext, mCallback, false);
|
mController.setChecked(false);
|
||||||
mPreference = new SwitchPreference(mContext);
|
|
||||||
mPreference.setKey(mController.getPreferenceKey());
|
|
||||||
mPreference.setChecked(false);
|
|
||||||
|
|
||||||
boolean result = mController.handlePreferenceTreeClick(mPreference);
|
|
||||||
|
|
||||||
assertThat(result).isTrue();
|
|
||||||
|
|
||||||
List<Intent> intentsFired = mApplication.getBroadcastIntents();
|
List<Intent> intentsFired = mApplication.getBroadcastIntents();
|
||||||
assertThat(intentsFired.size()).isEqualTo(1);
|
assertThat(intentsFired.size()).isEqualTo(1);
|
||||||
@@ -127,14 +119,7 @@ public class TimeFormatPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void updatePreference_24HourSet_shouldSendIntent() {
|
public void updatePreference_24HourSet_shouldSendIntent() {
|
||||||
mController = new TimeFormatPreferenceController(mContext, mCallback, false);
|
mController.setChecked(true);
|
||||||
mPreference = new SwitchPreference(mContext);
|
|
||||||
mPreference.setKey(mController.getPreferenceKey());
|
|
||||||
mPreference.setChecked(true);
|
|
||||||
|
|
||||||
boolean result = mController.handlePreferenceTreeClick(mPreference);
|
|
||||||
|
|
||||||
assertThat(result).isTrue();
|
|
||||||
|
|
||||||
List<Intent> intentsFired = mApplication.getBroadcastIntents();
|
List<Intent> intentsFired = mApplication.getBroadcastIntents();
|
||||||
assertThat(intentsFired.size()).isEqualTo(1);
|
assertThat(intentsFired.size()).isEqualTo(1);
|
||||||
|
@@ -18,9 +18,12 @@ package com.android.settings.datetime;
|
|||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
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.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import android.app.time.TimeCapabilitiesAndConfig;
|
||||||
|
import android.app.time.TimeManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
import com.android.settingslib.RestrictedPreference;
|
import com.android.settingslib.RestrictedPreference;
|
||||||
@@ -40,7 +43,7 @@ public class TimePreferenceControllerTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private TimePreferenceController.TimePreferenceHost mHost;
|
private TimePreferenceController.TimePreferenceHost mHost;
|
||||||
@Mock
|
@Mock
|
||||||
private DatePreferenceController mDatePreferenceController;
|
private TimeManager mTimeManager;
|
||||||
|
|
||||||
private TimePreferenceController mController;
|
private TimePreferenceController mController;
|
||||||
private RestrictedPreference mPreference;
|
private RestrictedPreference mPreference;
|
||||||
@@ -48,14 +51,11 @@ public class TimePreferenceControllerTest {
|
|||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
mContext = RuntimeEnvironment.application;
|
mContext = spy(RuntimeEnvironment.application);
|
||||||
mPreference = new RestrictedPreference(RuntimeEnvironment.application);
|
when(mContext.getSystemService(TimeManager.class)).thenReturn(mTimeManager);
|
||||||
mController = new TimePreferenceController(mContext, mHost, mDatePreferenceController);
|
mPreference = new RestrictedPreference(mContext);
|
||||||
}
|
mController = new TimePreferenceController(mContext, "test_key");
|
||||||
|
mController.setHost(mHost);
|
||||||
@Test
|
|
||||||
public void isAlwaysAvailable() {
|
|
||||||
assertThat(mController.isAvailable()).isTrue();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -63,7 +63,10 @@ public class TimePreferenceControllerTest {
|
|||||||
// Make sure not disabled by admin.
|
// Make sure not disabled by admin.
|
||||||
mPreference.setDisabledByAdmin(null);
|
mPreference.setDisabledByAdmin(null);
|
||||||
|
|
||||||
when(mDatePreferenceController.isEnabled()).thenReturn(false);
|
TimeCapabilitiesAndConfig capabilitiesAndConfig =
|
||||||
|
DatePreferenceControllerTest.createCapabilitiesAndConfig(/* suggestManualAllowed= */
|
||||||
|
false);
|
||||||
|
when(mTimeManager.getTimeCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
|
||||||
mController.updateState(mPreference);
|
mController.updateState(mPreference);
|
||||||
|
|
||||||
assertThat(mPreference.isEnabled()).isFalse();
|
assertThat(mPreference.isEnabled()).isFalse();
|
||||||
@@ -74,7 +77,10 @@ public class TimePreferenceControllerTest {
|
|||||||
// Make sure not disabled by admin.
|
// Make sure not disabled by admin.
|
||||||
mPreference.setDisabledByAdmin(null);
|
mPreference.setDisabledByAdmin(null);
|
||||||
|
|
||||||
when(mDatePreferenceController.isEnabled()).thenReturn(true);
|
TimeCapabilitiesAndConfig capabilitiesAndConfig =
|
||||||
|
DatePreferenceControllerTest.createCapabilitiesAndConfig(/* suggestManualAllowed= */
|
||||||
|
true);
|
||||||
|
when(mTimeManager.getTimeCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
|
||||||
mController.updateState(mPreference);
|
mController.updateState(mPreference);
|
||||||
|
|
||||||
assertThat(mPreference.isEnabled()).isTrue();
|
assertThat(mPreference.isEnabled()).isTrue();
|
||||||
|
@@ -66,15 +66,10 @@ public class TimeZonePreferenceControllerTest {
|
|||||||
|
|
||||||
mPreference = new RestrictedPreference(mContext);
|
mPreference = new RestrictedPreference(mContext);
|
||||||
|
|
||||||
mController = spy(new TimeZonePreferenceController(mContext));
|
mController = spy(new TimeZonePreferenceController(mContext, "test_key"));
|
||||||
doReturn("test timezone").when(mController).getTimeZoneOffsetAndName();
|
doReturn("test timezone").when(mController).getTimeZoneOffsetAndName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void isAlwaysAvailable() {
|
|
||||||
assertThat(mController.isAvailable()).isTrue();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void updateState_suggestManualNotAllowed_shouldDisablePref() {
|
public void updateState_suggestManualNotAllowed_shouldDisablePref() {
|
||||||
// Make sure not disabled by admin.
|
// Make sure not disabled by admin.
|
||||||
|
Reference in New Issue
Block a user