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

Commit 1b6ba01d authored by Annie Chin's avatar Annie Chin Committed by Android (Google) Code Review
Browse files

Merge "Add unregistration to deleteOtherInstances() and fixAlarmInstances()"...

Merge "Add unregistration to deleteOtherInstances() and fixAlarmInstances()" into ub-deskclock-dazzle
parents 7a7048e4 47807edd
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -444,7 +444,8 @@ public final class AlarmStateManager extends BroadcastReceiver {
        if (instance.mAlarmId != null) {
            // if the time changed *backward* and pushed an instance from missed back to fired,
            // remove any other scheduled instances that may exist
            AlarmInstance.deleteOtherInstances(contentResolver, instance.mAlarmId, instance.mId);
            AlarmInstance.deleteOtherInstances(context, contentResolver, instance.mAlarmId,
                    instance.mId);
        }

        // Start the alarm and schedule timeout timer for it
@@ -607,13 +608,14 @@ public final class AlarmStateManager extends BroadcastReceiver {
    }

    /**
     * This will not change the state of instance, but remove it's notifications and
     * This will not change the state of instance, but remove its notifications and
     * alarm timers.
     *
     * @param context application context
     * @param instance to unregister
     */
    public static void unregisterInstance(Context context, AlarmInstance instance) {
        LogUtils.i("Unregistering instance " + instance.mId);
        // Stop alarm if this instance is firing it
        AlarmService.stopAlarm(context, instance);
        AlarmNotifications.clearNotification(context, instance);
@@ -784,6 +786,7 @@ public final class AlarmStateManager extends BroadcastReceiver {
        for (AlarmInstance instance : AlarmInstance.getInstances(contentResolver, null)) {
            final Alarm alarm = Alarm.getAlarm(contentResolver, instance.mAlarmId);
            if (alarm == null) {
                unregisterInstance(context, instance);
                AlarmInstance.deleteInstance(contentResolver, instance.mId);
                LogUtils.e("Found instance without matching alarm; deleting instance %s", instance);
                continue;
@@ -881,7 +884,6 @@ public final class AlarmStateManager extends BroadcastReceiver {
            AlarmInstance instance = AlarmInstance.getInstance(context.getContentResolver(),
                    AlarmInstance.getId(uri));
            if (instance == null) {
                // Not a big deal, but it shouldn't happen
                LogUtils.e("Can not change state for unknown instance: " + uri);
                return;
            }
+5 −2
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.preference.PreferenceManager;

import com.android.deskclock.LogUtils;
import com.android.deskclock.R;
import com.android.deskclock.alarms.AlarmStateManager;
import com.android.deskclock.settings.SettingsActivity;

import java.util.Calendar;
@@ -263,15 +264,17 @@ public final class AlarmInstance implements ClockContract.InstancesColumns {
    }

    /**
     * @param context
     * @param contentResolver to access the content provider
     * @param alarmId identifies the alarm in question
     * @param instanceId identifies the instance to keep; all other instances will be removed
     */
    public static void deleteOtherInstances(ContentResolver contentResolver, long alarmId,
            long instanceId) {
    public static void deleteOtherInstances(Context context, ContentResolver contentResolver,
            long alarmId, long instanceId) {
        final List<AlarmInstance> instances = getInstancesByAlarmId(contentResolver, alarmId);
        for (AlarmInstance instance : instances) {
            if (instance.mId != instanceId) {
                AlarmStateManager.unregisterInstance(context, instance);
                deleteInstance(contentResolver, instance.mId);
            }
        }