Allow alternative time zone ID to be set device's zone.
If America/Godthab is set as device time zone, display it as if America/Nuuk is chosen. If time zone is known, but is not an alternative and not shown in time zone picker, region will de derived from user's locale. Bug: 155738410 Test: atest com.android.settings.datetime.timezone.model Test: set persist.sys.timezone via adb and checked Date & Time screen Change-Id: I168fb4319e144dbe9e2496d06a681d4c09b411c0
This commit is contained in:
@@ -71,14 +71,14 @@ public class RegionSearchPicker extends BaseTimeZonePicker {
|
||||
final FilteredCountryTimeZones countryTimeZones = mTimeZoneData.lookupCountryTimeZones(
|
||||
regionId);
|
||||
final Activity activity = getActivity();
|
||||
if (countryTimeZones == null || countryTimeZones.getTimeZoneIds().isEmpty()) {
|
||||
if (countryTimeZones == null || countryTimeZones.getPreferredTimeZoneIds().isEmpty()) {
|
||||
Log.e(TAG, "Region has no time zones: " + regionId);
|
||||
activity.setResult(Activity.RESULT_CANCELED);
|
||||
activity.finish();
|
||||
return;
|
||||
}
|
||||
|
||||
List<String> timeZoneIds = countryTimeZones.getTimeZoneIds();
|
||||
List<String> timeZoneIds = countryTimeZones.getPreferredTimeZoneIds();
|
||||
// Choose the time zone associated the region if there is only one time zone in that region
|
||||
if (timeZoneIds.size() == 1) {
|
||||
final Intent resultData = new Intent()
|
||||
|
@@ -103,7 +103,7 @@ public class RegionZonePicker extends BaseTimeZoneInfoPicker {
|
||||
// It could be a timely operations if there are many time zones. A region in time zone data
|
||||
// contains a maximum of 29 time zones currently. It may change in the future, but it's
|
||||
// unlikely to be changed drastically.
|
||||
return getRegionTimeZoneInfo(filteredCountryTimeZones.getTimeZoneIds());
|
||||
return getRegionTimeZoneInfo(filteredCountryTimeZones.getPreferredTimeZoneIds());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -214,10 +214,11 @@ public class TimeZoneSettings extends DashboardFragment {
|
||||
mTimeZoneData.lookupCountryTimeZones(regionId);
|
||||
|
||||
use(RegionZonePreferenceController.class).setTimeZoneInfo(tzInfo);
|
||||
// Only clickable when the region has more than 1 time zones or no time zone is selected.
|
||||
|
||||
// Only clickable when the region has more than 1 time zones or no time zone is selected.
|
||||
use(RegionZonePreferenceController.class).setClickable(tzInfo == null ||
|
||||
(countryTimeZones != null && countryTimeZones.getTimeZoneIds().size() > 1));
|
||||
(countryTimeZones != null
|
||||
&& countryTimeZones.getPreferredTimeZoneIds().size() > 1));
|
||||
use(TimeZoneInfoPreferenceController.class).setTimeZoneInfo(tzInfo);
|
||||
|
||||
updatePreferenceStates();
|
||||
@@ -244,7 +245,8 @@ public class TimeZoneSettings extends DashboardFragment {
|
||||
|
||||
FilteredCountryTimeZones countryTimeZones =
|
||||
timeZoneData.lookupCountryTimeZones(regionId);
|
||||
if (countryTimeZones == null || !countryTimeZones.getTimeZoneIds().contains(tzId)) {
|
||||
if (countryTimeZones == null
|
||||
|| !countryTimeZones.getPreferredTimeZoneIds().contains(tzId)) {
|
||||
Log.e(TAG, "Unknown time zone id is selected: " + tzId);
|
||||
return;
|
||||
}
|
||||
|
@@ -16,11 +16,15 @@
|
||||
|
||||
package com.android.settings.datetime.timezone.model;
|
||||
|
||||
import android.util.ArraySet;
|
||||
|
||||
import com.android.i18n.timezone.CountryTimeZones;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Wrap {@class CountryTimeZones} to filter time zone that are shown in the picker.
|
||||
@@ -39,31 +43,46 @@ public class FilteredCountryTimeZones {
|
||||
* a timestamp known to be in the recent past is used. This should be updated occasionally but
|
||||
* it doesn't have to be very often.
|
||||
*/
|
||||
private static final long MIN_USE_DATE_OF_TIMEZONE = 1546300800000L; // 1/1/2019 00:00 UTC
|
||||
private static final Instant MIN_USE_DATE_OF_TIMEZONE =
|
||||
Instant.ofEpochMilli(1546300800000L); // 1/1/2019 00:00 UTC
|
||||
|
||||
private final CountryTimeZones mCountryTimeZones;
|
||||
private final List<String> mTimeZoneIds;
|
||||
private final List<String> mPreferredTimeZoneIds;
|
||||
private final Set<String> mAlternativeTimeZoneIds;
|
||||
|
||||
public FilteredCountryTimeZones(CountryTimeZones countryTimeZones) {
|
||||
mCountryTimeZones = countryTimeZones;
|
||||
List<String> timeZoneIds = countryTimeZones.getTimeZoneMappings().stream()
|
||||
.filter(timeZoneMapping ->
|
||||
timeZoneMapping.isShownInPicker()
|
||||
&& (timeZoneMapping.getNotUsedAfter() == null
|
||||
|| timeZoneMapping.getNotUsedAfter() >= MIN_USE_DATE_OF_TIMEZONE))
|
||||
.map(timeZoneMapping -> timeZoneMapping.getTimeZoneId())
|
||||
.collect(Collectors.toList());
|
||||
mTimeZoneIds = Collections.unmodifiableList(timeZoneIds);
|
||||
List<String> timeZoneIds = new ArrayList<>();
|
||||
Set<String> alternativeTimeZoneIds = new ArraySet<>();
|
||||
for (CountryTimeZones.TimeZoneMapping timeZoneMapping :
|
||||
countryTimeZones.getTimeZoneMappings()) {
|
||||
if (timeZoneMapping.isShownInPickerAt(MIN_USE_DATE_OF_TIMEZONE)) {
|
||||
String timeZoneId = timeZoneMapping.getTimeZoneId();
|
||||
timeZoneIds.add(timeZoneId);
|
||||
alternativeTimeZoneIds.addAll(timeZoneMapping.getAlternativeIds());
|
||||
}
|
||||
}
|
||||
mPreferredTimeZoneIds = Collections.unmodifiableList(timeZoneIds);
|
||||
mAlternativeTimeZoneIds = Collections.unmodifiableSet(alternativeTimeZoneIds);
|
||||
}
|
||||
|
||||
public List<String> getTimeZoneIds() {
|
||||
return mTimeZoneIds;
|
||||
public List<String> getPreferredTimeZoneIds() {
|
||||
return mPreferredTimeZoneIds;
|
||||
}
|
||||
|
||||
public CountryTimeZones getCountryTimeZones() {
|
||||
return mCountryTimeZones;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether {@code timeZoneId} is currently used in the country or is an alternative
|
||||
* name of a currently used time zone.
|
||||
*/
|
||||
public boolean matches(String timeZoneId) {
|
||||
return mPreferredTimeZoneIds.contains(timeZoneId)
|
||||
|| mAlternativeTimeZoneIds.contains(timeZoneId);
|
||||
}
|
||||
|
||||
public String getRegionId() {
|
||||
return TimeZoneData.normalizeRegionId(mCountryTimeZones.getCountryIso());
|
||||
}
|
||||
|
@@ -71,7 +71,7 @@ public class TimeZoneData {
|
||||
Set<String> regionIds = new ArraySet<>();
|
||||
for (CountryTimeZones countryTimeZone : countryTimeZones) {
|
||||
FilteredCountryTimeZones filteredZones = new FilteredCountryTimeZones(countryTimeZone);
|
||||
if (filteredZones.getTimeZoneIds().contains(tzId)) {
|
||||
if (filteredZones.matches(tzId)) {
|
||||
regionIds.add(filteredZones.getRegionId());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user