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

Commit 2164699c authored by Adnan's avatar Adnan
Browse files

DeskClock: Snooze based on snooze interval set by user during call.

  - f3e68e slept on main thread and snoozed every second. Instead of
  doing that, we notify every n interval based on snooze settings.

Change-Id: I0b4ee8ce690ac3e21273eb338172c4179d59207e
parent f4598266
Loading
Loading
Loading
Loading
+26 −64
Original line number Diff line number Diff line
@@ -434,31 +434,6 @@ public final class AlarmStateManager extends BroadcastReceiver {

    }

    /**
     * This will set the alarm instance to the one minute late and update
     * the application notifications and schedule any state changes that need
     * to occur in the future.
     *
     * @param context application context
     * @param instance to set state to
     */
    public static void setOneminutelate(Context context, AlarmInstance instance) {
        AlarmService.stopAlarm(context, instance);
        int snoozeMinutes = 1;

        // Set alarm time to next minute.Update alarm state and new alarm time in db.
        Calendar newAlarmTime = Calendar.getInstance();
        newAlarmTime.add(Calendar.MINUTE, snoozeMinutes);
        instance.setAlarmTime(newAlarmTime);
        instance.mAlarmState = AlarmInstance.SNOOZE_STATE;
        AlarmInstance.updateInstance(context.getContentResolver(), instance);
        scheduleInstanceStateChange(context, instance.getAlarmTime(),
                instance, AlarmInstance.FIRED_STATE);

        // Instance time changed, so find next alarm that will fire and notify system
        updateNextAlarm(context);
    }

    /**
     * This will set the alarm instance to the MISSED_STATE and update
     * the application notifications and schedule any state changes that need
@@ -804,18 +779,11 @@ public final class AlarmStateManager extends BroadcastReceiver {
    }

    /**
     * Make the alarm snooze for one second.If the phone is still busy in call,
     * this method will be called again to snooze for another one second.
     * Make the alarm snooze based on the snooze interval in settings.
     * If the phone is not busy in call anymore, this method will not be
     * called, and the alarm will wake up within one second.
     * called, and the alarm will wake up based on snooze interval.
     */
    private void snooze(Context context, Intent intent, AlarmInstance instance) {
        Calendar currentTime = Calendar.getInstance();
        if ((currentTime.get(Calendar.SECOND) < 57)
                && (currentTime.get(Calendar.MINUTE) == instance.mMinute)) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException ex) {}
        Uri uri = intent.getData();
        AlarmInstance newInstance = AlarmInstance.getInstance(context.getContentResolver(),
                AlarmInstance.getId(uri));
@@ -840,13 +808,7 @@ public final class AlarmStateManager extends BroadcastReceiver {
                broadcast);
        n.flags |= Notification.FLAG_AUTO_CANCEL | Notification.FLAG_ONGOING_EVENT;
        nm.notify(instance.hashCode(), n);

            scheduleInstanceStateChange(context, newInstance.getAlarmTime(), newInstance,
                    AlarmInstance.FIRED_STATE);
        } else {
            // when alarm is about to overtime,let it snooze to next minute
            setOneminutelate(context, instance);
        }
        setAlarmState(context, instance, AlarmInstance.SNOOZE_STATE);
    }

    public static void setRtcPowerUp(Context context, boolean isRtcPowerUp) {