Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d67600a4 authored by Luis Vidal's avatar Luis Vidal Committed by Gerrit Code Review
Browse files

Settings: update time zone strings on date change



If the user changes the date, most obvious case being from 1970, to a
current date, and the user's selected Locale's country time zones have
been changed (according to ICU), we must update the time zone strings in
the system.

Ref: CYNGNOS-453

Signed-off-by: default avatarRoman Birg <roman@cyngn.com>
(cherry picked from commit 926c3b0a)

Change-Id: I487c54cd4f933286c5004d24a3f8730ee2d4e4f6
parent d6709e61
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -529,6 +529,13 @@
                android:value="true" />
        </activity>

        <receiver android:name=".DateChangeReceiver">
            <intent-filter>
                <action android:name="android.intent.action.DATE_CHANGED"/>
                <action android:name="android.intent.action.LOCALE_CHANGED"/>
            </intent-filter>
        </receiver>

        <activity android:name="DateTimeSettingsSetupWizard"
                  android:label="@string/date_and_time"
                  android:theme="@style/Theme.DateTimeSettingsSetupWizard"
+28 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2016 The CyanogenMod Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.settings;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

public class DateChangeReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        DateTimeSettings.updateLocaleStrings();
    }
}
+13 −0
Original line number Diff line number Diff line
@@ -40,9 +40,12 @@ import android.widget.TimePicker;

import com.android.internal.logging.MetricsLogger;
import com.android.settingslib.datetime.ZoneGetter;
import libcore.icu.TimeZoneNames;

import java.text.DateFormatSymbols;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;

public class DateTimeSettings extends SettingsPreferenceFragment
        implements OnSharedPreferenceChangeListener,
@@ -329,6 +332,16 @@ public class DateTimeSettings extends SettingsPreferenceFragment
        if (when / 1000 < Integer.MAX_VALUE) {
            ((AlarmManager) context.getSystemService(Context.ALARM_SERVICE)).setTime(when);
        }
        updateLocaleStrings();
    }

    static void updateLocaleStrings() {
        // If a device was boot up with date 1970 and then date changes to some later time,
        // the wrong string might be cached if the country's zones have changed.
        // See external/icu/icu4c/source/data/misc/metaZones.txt for complete mapping
        TimeZoneNames.clearLocaleCache();
        Locale locale = Locale.getDefault();
        DateFormatSymbols.getInstance(locale).setZoneStrings(TimeZoneNames.getZoneStrings(locale));
    }

    /* package */ static void setTime(Context context, int hourOfDay, int minute) {