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

Commit ce7574bf authored by Justin Klaassen's avatar Justin Klaassen
Browse files

Ensure city dates in widget update correctly

Bug: 31026720

- Update widgets and day change callback whenever a TIME_SET occurs
  since that may have resulted in a day change for some cities.
- Account for home clock timezone when scheduling day change callback.

Test: Manually tested day change for MT home clock using SYD timezone.

Change-Id: I896aec59fe3b89de7ad4384c7987c7535296e164
parent 463794db
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -280,12 +280,13 @@
            android:name="com.android.alarmclock.DigitalAppWidgetProvider"
            android:label="@string/digital_gadget">
            <intent-filter>
                <action android:name="android.intent.action.SCREEN_ON" />
                <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
                <action android:name="android.app.action.NEXT_ALARM_CLOCK_CHANGED" />
                <action android:name="android.intent.action.DATE_CHANGED" />
                <action android:name="android.intent.action.LOCALE_CHANGED" />
                <action android:name="android.intent.action.SCREEN_ON" />
                <action android:name="android.intent.action.TIME_SET" />
                <action android:name="android.intent.action.TIMEZONE_CHANGED" />
                <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
                <action android:name="android.app.action.NEXT_ALARM_CLOCK_CHANGED" />
                <action android:name="com.android.deskclock.ALARM_CHANGED" />
                <action android:name="com.android.deskclock.ON_DAY_CHANGE" />
                <action android:name="com.android.deskclock.WORLD_CITIES_CHANGED" />
+18 −10
Original line number Diff line number Diff line
@@ -65,6 +65,7 @@ import static android.content.Intent.ACTION_DATE_CHANGED;
import static android.content.Intent.ACTION_LOCALE_CHANGED;
import static android.content.Intent.ACTION_SCREEN_ON;
import static android.content.Intent.ACTION_TIMEZONE_CHANGED;
import static android.content.Intent.ACTION_TIME_CHANGED;
import static android.util.TypedValue.COMPLEX_UNIT_PX;
import static android.view.View.GONE;
import static android.view.View.MeasureSpec.UNSPECIFIED;
@@ -125,7 +126,7 @@ public class DigitalAppWidgetProvider extends AppWidgetProvider {

    @Override
    public void onReceive(@NonNull Context context, @NonNull Intent intent) {
        LOGGER.i("Digital Widget processing action %s", intent.getAction());
        LOGGER.i("onReceive: " + intent);
        super.onReceive(context, intent);

        final AppWidgetManager wm = AppWidgetManager.getInstance(context);
@@ -136,15 +137,17 @@ public class DigitalAppWidgetProvider extends AppWidgetProvider {
        final ComponentName provider = new ComponentName(context, getClass());
        final int[] widgetIds = wm.getAppWidgetIds(provider);

        switch (intent.getAction()) {
            case ACTION_SCREEN_ON:
        final String action = intent.getAction();
        switch (action) {
            case ACTION_NEXT_ALARM_CLOCK_CHANGED:
            case ACTION_DATE_CHANGED:
            case ACTION_ALARM_CHANGED:
            case ACTION_ON_DAY_CHANGE:
            case ACTION_LOCALE_CHANGED:
            case ACTION_SCREEN_ON:
            case ACTION_TIME_CHANGED:
            case ACTION_TIMEZONE_CHANGED:
            case ACTION_ALARM_CHANGED:
            case ACTION_ON_DAY_CHANGE:
            case ACTION_WORLD_CITIES_CHANGED:
            case ACTION_NEXT_ALARM_CLOCK_CHANGED:
                for (int widgetId : widgetIds) {
                    relayoutWidget(context, wm, widgetId, wm.getAppWidgetOptions(widgetId));
                }
@@ -343,16 +346,21 @@ public class DigitalAppWidgetProvider extends AppWidgetProvider {
     * Add the day-change callback if it is needed (selected cities exist).
     */
    private void updateDayChangeCallback(Context context) {
        final List<City> selectedCities = DataModel.getDataModel().getSelectedCities();
        if (selectedCities.isEmpty()) {
        final DataModel dm = DataModel.getDataModel();
        final List<City> selectedCities = dm.getSelectedCities();
        final boolean showHomeClock = dm.getShowHomeClock();
        if (selectedCities.isEmpty() && !showHomeClock) {
            // Remove the existing day-change callback.
            removeDayChangeCallback(context);
            return;
        }

        // Look up the time at which the next day change occurs across all timezones.
        final Set<TimeZone> zones = new ArraySet<>(selectedCities.size() + 1);
        final Set<TimeZone> zones = new ArraySet<>(selectedCities.size() + 2);
        zones.add(TimeZone.getDefault());
        if (showHomeClock) {
            zones.add(dm.getHomeCity().getTimeZone());
        }
        for (City city : selectedCities) {
            zones.add(city.getTimeZone());
        }