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

Commit 78cc0462 authored by Mao Jinlong's avatar Mao Jinlong Committed by Steve Kondik
Browse files

Alarm: Use dedicated alarm type for poweroff alarm.

RTC_POWEROFF_WAKEUP is a new alarm type introduced by framework
to perform poweroff alarm. The time (RTC_WAKEUP) set to framework
is not the same as the alarm time set in deskclock.  In this case
the RTC register might not be correctly set. So both RTC_WAKEUP
and RTC_POWEROFF_WAKEUP types need to be set at the same time:
RTC_WAKEUP type will handle the normal alarm process, and
RTC_POWEROFF_WAKEUP is used to set the correct alarm time to RTC
register.

Change-Id: Ic03f87018e163adf6f6e6013963a497d340fbec7
parent b64e46b3
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -13,7 +13,6 @@ LOCAL_RESOURCE_DIR += prebuilts/sdk/current/support/v7/gridlayout/res
endif

LOCAL_MODULE_TAGS := optional
LOCAL_SDK_VERSION := current

LOCAL_PACKAGE_NAME := DeskClock
LOCAL_OVERRIDES_PACKAGES := AlarmClock
+23 −1
Original line number Diff line number Diff line
@@ -886,6 +886,13 @@ public final class AlarmStateManager extends BroadcastReceiver {
            if (alarmState >= 0) {
                setAlarmState(context, instance, alarmState);
            } else {
                // No need to register instance again when alarmState
                // equals POWER_OFF_ALARM_STATE. POWER_OFF_ALARM_STATE
                // is an invalid state for rtc power off alarm.
                if (alarmState == AlarmInstance.POWER_OFF_ALARM_STATE)
                {
                    return;
                }
                registerInstance(context, instance, true);
            }
        } else if (SHOW_AND_DISMISS_ALARM_ACTION.equals(action)) {
@@ -960,10 +967,18 @@ public final class AlarmStateManager extends BroadcastReceiver {
                    stateChangeIntent, PendingIntent.FLAG_UPDATE_CURRENT);

            final AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
            Intent stateChangePowerOffIntent = createStateChangeIntent(context, ALARM_MANAGER_TAG,
                instance, AlarmInstance.POWER_OFF_ALARM_STATE);
            PendingIntent pendingPowerOffIntent = PendingIntent.getBroadcast(context,
                instance.hashCode(), stateChangePowerOffIntent, PendingIntent.FLAG_ONE_SHOT);
            if (Utils.isKitKatOrLater()) {
                am.setExact(AlarmManager.RTC_WAKEUP, timeInMillis, pendingIntent);
                am.setExact(AlarmManager.RTC_POWEROFF_WAKEUP, instance.getAlarmTime().getTimeInMillis(),
                        pendingPowerOffIntent);
            } else {
                am.set(AlarmManager.RTC_WAKEUP, timeInMillis, pendingIntent);
                am.set(AlarmManager.RTC_POWEROFF_WAKEUP, instance.getAlarmTime().getTimeInMillis(),
                        pendingPowerOffIntent);
            }
        }

@@ -976,10 +991,17 @@ public final class AlarmStateManager extends BroadcastReceiver {
                    createStateChangeIntent(context, ALARM_MANAGER_TAG, instance, null),
                    PendingIntent.FLAG_NO_CREATE);

            if (pendingIntent != null) {
            PendingIntent pendingPowerOffIntent = PendingIntent.getBroadcast(context,
                    instance.hashCode(),
                    createStateChangeIntent(context, ALARM_MANAGER_TAG, instance, null),
                    PendingIntent.FLAG_ONE_SHOT);

            if (pendingIntent != null && pendingPowerOffIntent != null) {
                AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
                am.cancel(pendingIntent);
                am.cancel(pendingPowerOffIntent);
                pendingIntent.cancel();
                pendingPowerOffIntent.cancel();
            }
        }
    }
+5 −0
Original line number Diff line number Diff line
@@ -148,6 +148,11 @@ public final class ClockContract {
         */
        public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/instances");

        /**
         * Alarm state for rtc power off alarm
         */
        public static final int POWER_OFF_ALARM_STATE = -1;

        /**
         * Alarm state when to show no notification.
         *
+1 −1
Original line number Diff line number Diff line
@@ -426,7 +426,7 @@ public class StaggeredGridView extends ViewGroup {
     * @return boolean Boolean indicating whether the currently locale is RTL.
     */
    @SuppressLint("NewApi")
    private boolean isLayoutRtl() {
    public boolean isLayoutRtl() {
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) {
            return View.LAYOUT_DIRECTION_RTL == getLayoutDirection();
        } else {