summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Qin <yqin@codeaurora.org>2013-12-23 20:49:55 +0800
committerLinux Build Service Account <lnxbuild@localhost>2014-11-04 08:54:16 -0700
commitb26ef3565026e4919f3a64c5b098b888e14ac6f0 (patch)
tree82acdcb4571716c8dc642ebc24ed395295d5c6ad
parentd32875c29610d8a80b0031d43c0e9aab7d0542a5 (diff)
downloadandroid_packages_apps_DeskClock-b26ef3565026e4919f3a64c5b098b888e14ac6f0.tar.gz
android_packages_apps_DeskClock-b26ef3565026e4919f3a64c5b098b888e14ac6f0.tar.bz2
android_packages_apps_DeskClock-b26ef3565026e4919f3a64c5b098b888e14ac6f0.zip
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
-rw-r--r--src/com/android/deskclock/alarms/AlarmStateManager.java23
-rw-r--r--src/com/android/deskclock/provider/ClockContract.java6
2 files changed, 29 insertions, 0 deletions
diff --git a/src/com/android/deskclock/alarms/AlarmStateManager.java b/src/com/android/deskclock/alarms/AlarmStateManager.java
index 3e4001cb9..33a7e6adb 100644
--- a/src/com/android/deskclock/alarms/AlarmStateManager.java
+++ b/src/com/android/deskclock/alarms/AlarmStateManager.java
@@ -226,10 +226,19 @@ public final class AlarmStateManager extends BroadcastReceiver {
stateChangeIntent, PendingIntent.FLAG_UPDATE_CURRENT);
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);
}
}
@@ -247,7 +256,14 @@ public final class AlarmStateManager extends BroadcastReceiver {
createStateChangeIntent(context, ALARM_MANAGER_TAG, instance, null),
PendingIntent.FLAG_UPDATE_CURRENT);
+ PendingIntent pendingPowerOffIntent = PendingIntent.getBroadcast(context,
+ instance.hashCode(),
+ createStateChangeIntent(context, ALARM_MANAGER_TAG, instance, null),
+ PendingIntent.FLAG_ONE_SHOT);
+
AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
+
+ am.cancel(pendingPowerOffIntent);
am.cancel(pendingIntent);
}
@@ -715,6 +731,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)) {
diff --git a/src/com/android/deskclock/provider/ClockContract.java b/src/com/android/deskclock/provider/ClockContract.java
index 0cf1a17fd..158c9fcc7 100644
--- a/src/com/android/deskclock/provider/ClockContract.java
+++ b/src/com/android/deskclock/provider/ClockContract.java
@@ -136,6 +136,12 @@ 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.
*