Change text of auto-silenced alarm notification.

Show "Missed Alarm" as the title.

Bug: 10516179
Change-Id: I860cbab622df0be7c4c8e0763c3e6be231f8a09f
diff --git a/res/values/strings.xml b/res/values/strings.xml
index f767b0d..562a2ed 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -85,7 +85,8 @@
     <!-- Alarm Alert screen: this message is shown after an alarm rung
          unattended for a number of minutes.  It tells the user that
          the alarm has been silenced.-->
-    <string name="alarm_alert_alert_silenced">Alarm silenced after <xliff:g id="minutes">%d</xliff:g> minutes.</string>
+    <string name="alarm_missed_title">Missed alarm</string>
+    <string name="alarm_missed_text"><xliff:g id="alarm_time">%s</xliff:g> - <xliff:g id="alarm_label">%s</xliff:g></string>
 
     <!-- Button labels on the alarm dialog: Snooze -->
     <string name="alarm_alert_snooze_text">Snooze</string>
diff --git a/src/com/android/deskclock/AlarmReceiver.java b/src/com/android/deskclock/AlarmReceiver.java
index 30099a2..1e3e6df 100644
--- a/src/com/android/deskclock/AlarmReceiver.java
+++ b/src/com/android/deskclock/AlarmReceiver.java
@@ -24,6 +24,7 @@
 import android.content.Intent;
 import android.os.Parcel;
 import android.os.PowerManager.WakeLock;
+import android.text.TextUtils;
 
 import com.android.deskclock.provider.Alarm;
 
@@ -235,13 +236,22 @@
 
         // Update the notification to indicate that the alert has been
         // silenced.
-        String label = alarm.getLabelOrDefault(context);
-        Notification n = new Notification(R.drawable.stat_notify_alarm,
-                label, alarm.calculateAlarmTime());
-        n.setLatestEventInfo(context, label,
-                context.getString(R.string.alarm_alert_alert_silenced, timeout),
-                intent);
-        n.flags |= Notification.FLAG_AUTO_CANCEL;
+        String title = context.getString(R.string.alarm_missed_title);
+        String label = alarm.label;
+        String alarmTime = Alarms.formatTime(context, alarm.calculateAlarmCalendar());
+        // If the label is null, just show the alarm time. If not, show "time - label".
+        String text = TextUtils.isEmpty(label)? alarmTime :
+            context.getString(R.string.alarm_missed_text, alarmTime, label);
+
+        Notification n = new Notification.Builder(context)
+        .setContentTitle(title)
+        .setContentText(text)
+        .setSmallIcon(R.drawable.stat_notify_alarm)
+        .setAutoCancel(true)
+        .setPriority(Notification.PRIORITY_HIGH)
+        .setDefaults(Notification.DEFAULT_ALL)
+        .build();
+        n.contentIntent = intent;
         // We have to cancel the original notification since it is in the
         // ongoing section and we want the "killed" notification to be a plain
         // notification.
diff --git a/src/com/android/deskclock/provider/Alarm.java b/src/com/android/deskclock/provider/Alarm.java
index 70acb04..27cc5e4 100644
--- a/src/com/android/deskclock/provider/Alarm.java
+++ b/src/com/android/deskclock/provider/Alarm.java
@@ -287,6 +287,11 @@
     }
 
     public long calculateAlarmTime() {
+        Calendar c = calculateAlarmCalendar();
+        return c.getTimeInMillis();
+    }
+
+    public Calendar calculateAlarmCalendar() {
         // start with now
         Calendar c = Calendar.getInstance();
         c.setTimeInMillis(System.currentTimeMillis());
@@ -307,7 +312,7 @@
         if (addDays > 0) {
             c.add(Calendar.DAY_OF_WEEK, addDays);
         }
-        return c.getTimeInMillis();
+        return c;
     }
 
     @Override